diff options
| author | Paul Eggert <eggert@cs.ucla.edu> | 2024-09-25 17:50:09 -0700 |
|---|---|---|
| committer | Paul Eggert <eggert@cs.ucla.edu> | 2024-09-27 17:42:58 -0700 |
| commit | f678de6f0edfe2ccbafc453c2a1dfcbcd6b6ea47 (patch) | |
| tree | 691993097523ab152ce0d8a0f5876bfd8a8d65b2 | |
| parent | 9cc3e786e61fd9a3604beaf1b882e5c31a8592d1 (diff) | |
| download | coreutils-f678de6f0edfe2ccbafc453c2a1dfcbcd6b6ea47.tar.gz coreutils-f678de6f0edfe2ccbafc453c2a1dfcbcd6b6ea47.zip | |
factor: tweak gcd2_odd performance
* src/factor.c (gcd2_odd): Use stdc_trailing_zeros here too.
| -rw-r--r-- | src/factor.c | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/src/factor.c b/src/factor.c index 13fb92f8d..081bb0d57 100644 --- a/src/factor.c +++ b/src/factor.c @@ -441,9 +441,12 @@ gcd2_odd (uintmax_t *r1, uintmax_t a1, uintmax_t a0, uintmax_t b1, uintmax_t b0) *r1 = b1; return b0; } - - while ((a0 & 1) == 0) - rsh2 (a1, a0, a1, a0, 1); + if (!a0) + a0 = a1, a1 = 0; + assume (a0); + int ctz = stdc_trailing_zeros (a0); + if (ctz) + rsh2 (a1, a0, a1, a0, ctz); for (;;) { @@ -456,16 +459,22 @@ gcd2_odd (uintmax_t *r1, uintmax_t a1, uintmax_t a0, uintmax_t b1, uintmax_t b0) if (gt2 (a1, a0, b1, b0)) { sub_ddmmss (a1, a0, a1, a0, b1, b0); - do - rsh2 (a1, a0, a1, a0, 1); - while ((a0 & 1) == 0); + if (!a0) + a0 = a1, a1 = 0; + assume (a0); + ctz = stdc_trailing_zeros (a0); + if (ctz) + rsh2 (a1, a0, a1, a0, ctz); } else if (gt2 (b1, b0, a1, a0)) { sub_ddmmss (b1, b0, b1, b0, a1, a0); - do - rsh2 (b1, b0, b1, b0, 1); - while ((b0 & 1) == 0); + if (!b0) + b0 = b1, b1 = 0; + assume (b0); + ctz = stdc_trailing_zeros (b0); + if (ctz) + rsh2 (b1, b0, b1, b0, ctz); } else break; |
