[libcxx-commits] [libcxx] [libc++] Implement std::gcd using the binary version (PR #77747)

Daniel Lemire via libcxx-commits libcxx-commits at lists.llvm.org
Mon Apr 22 11:55:45 PDT 2024


lemire wrote:

> it's possible to create an example where the new GCD is hundred times slower

The algorithmic complexity of the binary GCD is the number of bits in the largest of the two integers

For the benchmark in question, it should go down as...

```
u: 1, v: 16777214
u: 1, v: 8388606
u: 1, v: 4194302
u: 1, v: 2097150
u: 1, v: 1048574
u: 1, v: 524286
u: 1, v: 262142
u: 1, v: 131070
u: 1, v: 65534
u: 1, v: 32766
u: 1, v: 16382
u: 1, v: 8190
u: 1, v: 4094
u: 1, v: 2046
u: 1, v: 1022
u: 1, v: 510
u: 1, v: 254
u: 1, v: 126
u: 1, v: 62
u: 1, v: 30
u: 1, v: 14
u: 1, v: 6
u: 1, v: 2
```

So it is difficult to imagine that that there could be gigantic differences.

https://github.com/llvm/llvm-project/pull/77747


More information about the libcxx-commits mailing list