summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-04-13 11:34:40 (GMT)
committerDenys Vlasenko <vda.linux@googlemail.com>2017-04-13 11:34:40 (GMT)
commit021d50405b5819df9e86a3f1354e45018885517e (patch)
tree1c47f569cd6bc2f165b183cde987d50907f1683b
parenta3de0b3b86deb37c2adc993c6357c1a31b7ecb5b (diff)
downloadbusybox-021d50405b5819df9e86a3f1354e45018885517e.zip
busybox-021d50405b5819df9e86a3f1354e45018885517e.tar.gz
busybox-021d50405b5819df9e86a3f1354e45018885517e.tar.bz2
factor: improve comments for sieving logic
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--coreutils/factor.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/coreutils/factor.c b/coreutils/factor.c
index 7adc238..5e23c6c 100644
--- a/coreutils/factor.c
+++ b/coreutils/factor.c
@@ -73,7 +73,7 @@ static NOINLINE void factorize(wide_t N)
MULTIPLE_OF_3 = 1 << 2,
MULTIPLE_OF_5 = 1 << 6,
MULTIPLE_OF_7 = 1 << 11,
- MULTIPLE_3_5_7 = MULTIPLE_OF_3 | MULTIPLE_OF_5 | MULTIPLE_OF_7,
+ MULTIPLE_DETECTED = MULTIPLE_OF_3 | MULTIPLE_OF_5 | MULTIPLE_OF_7,
};
unsigned sieve_word;
@@ -102,9 +102,13 @@ static NOINLINE void factorize(wide_t N)
// count5 = 6;
// count7 = 9;
sieve_word = 0
+ /* initial count for SHIFT_n is (n-1)/2*3: */
+ (MULTIPLE_OF_3 - 3 * SHIFT_3)
+ (MULTIPLE_OF_5 - 6 * SHIFT_5)
+ (MULTIPLE_OF_7 - 9 * SHIFT_7)
+ //+ (MULTIPLE_OF_11 - 15 * SHIFT_11)
+ //+ (MULTIPLE_OF_11 - 18 * SHIFT_13)
+ //+ (MULTIPLE_OF_11 - 24 * SHIFT_17)
;
factor = 3;
for (;;) {
@@ -133,7 +137,7 @@ static NOINLINE void factorize(wide_t N)
// if (count3 && count5 && count7)
// continue;
sieve_word += INCREMENT_EACH;
- if (!(sieve_word & MULTIPLE_3_5_7))
+ if (!(sieve_word & MULTIPLE_DETECTED))
continue;
/*
* "factor" is multiple of 3 33% of the time (count3 reached 0),