diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2017-04-10 18:30:35 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-04-10 18:30:35 +0200 |
| commit | cc1f8ba489b809d2c859276ef10094df4bcc74ea (patch) | |
| tree | 2781afa04988916cb29e8e4c310d38c0fdd86d76 /coreutils | |
| parent | ad5394d591896fc1d025efff2fa6c8c580fb67e9 (diff) | |
| download | busybox-w32-cc1f8ba489b809d2c859276ef10094df4bcc74ea.tar.gz busybox-w32-cc1f8ba489b809d2c859276ef10094df4bcc74ea.tar.bz2 busybox-w32-cc1f8ba489b809d2c859276ef10094df4bcc74ea.zip | |
factor: don't be too clever in isqrt - be small instead
function old new delta
isqrt_odd 111 70 -41
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils')
| -rw-r--r-- | coreutils/factor.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/coreutils/factor.c b/coreutils/factor.c index 7400174a7..11097c12d 100644 --- a/coreutils/factor.c +++ b/coreutils/factor.c | |||
| @@ -47,25 +47,27 @@ typedef unsigned long half_t; | |||
| 47 | /* Returns such x that x+1 > sqrt(N) */ | 47 | /* Returns such x that x+1 > sqrt(N) */ |
| 48 | static inline half_t isqrt(wide_t N) | 48 | static inline half_t isqrt(wide_t N) |
| 49 | { | 49 | { |
| 50 | wide_t mask_2bits; | ||
| 51 | half_t x; | 50 | half_t x; |
| 52 | 51 | ||
| 53 | // Never called with N < 1 | 52 | // Never called with N < 1 |
| 54 | // if (N == 0) | 53 | //if (N == 0) |
| 55 | // return 0; | 54 | // return 0; |
| 56 | 55 | ||
| 56 | x = HALF_MAX; | ||
| 57 | /* First approximation of x+1 > sqrt(N) - all-ones, half as many bits: | 57 | /* First approximation of x+1 > sqrt(N) - all-ones, half as many bits: |
| 58 | * 1xxxxx -> 111 (six bits to three) | 58 | * 1xxxxx -> 111 (six bits to three) |
| 59 | * 01xxxx -> 111 | 59 | * 01xxxx -> 111 |
| 60 | * 001xxx -> 011 | 60 | * 001xxx -> 011 |
| 61 | * 0001xx -> 011 and so on. | 61 | * 0001xx -> 011 and so on. |
| 62 | */ | 62 | */ |
| 63 | x = HALF_MAX; | 63 | // It is actually not performance-critical at all. |
| 64 | mask_2bits = TOPMOST_WIDE_BIT | (TOPMOST_WIDE_BIT >> 1); | 64 | // Can simply start Newton loop with very conservative x=0xffffffff. |
| 65 | while (!(N & mask_2bits)) { | 65 | //wide_t mask_2bits; |
| 66 | x >>= 1; | 66 | //mask_2bits = TOPMOST_WIDE_BIT | (TOPMOST_WIDE_BIT >> 1); |
| 67 | mask_2bits >>= 2; | 67 | //while (!(N & mask_2bits)) { |
| 68 | } | 68 | // x >>= 1; |
| 69 | // mask_2bits >>= 2; | ||
| 70 | //} | ||
| 69 | dbg("x:%"HALF_FMT"x", x); | 71 | dbg("x:%"HALF_FMT"x", x); |
| 70 | 72 | ||
| 71 | for (;;) { | 73 | for (;;) { |
