|
13 | 13 |
|
14 | 14 | /* Configuration parameters for the signed-digit multi-comb algorithm:
|
15 | 15 | *
|
16 |
| - * - COMB_BLOCKS is the number of blocks the input is split into. Each |
17 |
| - * has a corresponding table. |
| 16 | + * - COMB_BLOCKS is the number of blocks the input is split into. Each has a corresponding table. |
18 | 17 | * - COMB_TEETH is the number of bits simultaneously covered by one table.
|
19 |
| - * |
20 |
| - * The comb's spacing (COMB_SPACING), or the distance between the teeth, |
21 |
| - * is defined as ceil(256 / (COMB_BLOCKS * COMB_TEETH)). Each block covers |
22 |
| - * COMB_SPACING * COMB_TEETH consecutive bits in the input. |
| 18 | + * - COMB_SPACING is the distance between the teeth. For production purposes, the only reasonable |
| 19 | + * value is ceil(256 / (COMB_BLOCKS * COMB_TEETH)), so unless explicitly configured otherwise, |
| 20 | + * that value will be used. COMB_BLOCKS * COMB_TEETH * COMB_SPACING needs to be at least 256. |
23 | 21 | *
|
24 | 22 | * The size of the precomputed table is COMB_BLOCKS * (1 << (COMB_TEETH - 1))
|
25 | 23 | * secp256k1_ge_storages.
|
|
36 | 34 | * doesn't support infinities) */
|
37 | 35 | # undef COMB_BLOCKS
|
38 | 36 | # undef COMB_TEETH
|
39 |
| -# if EXHAUSTIVE_TEST_ORDER > 32 |
40 |
| -# define COMB_BLOCKS 52 |
41 |
| -# define COMB_TEETH 5 |
42 |
| -# elif EXHAUSTIVE_TEST_ORDER > 16 |
43 |
| -# define COMB_BLOCKS 64 |
44 |
| -# define COMB_TEETH 4 |
45 |
| -# elif EXHAUSTIVE_TEST_ORDER > 8 |
46 |
| -# define COMB_BLOCKS 86 |
47 |
| -# define COMB_TEETH 3 |
48 |
| -# elif EXHAUSTIVE_TEST_ORDER > 4 |
49 |
| -# define COMB_BLOCKS 128 |
| 37 | +# undef COMB_SPACING |
| 38 | +# if EXHAUSTIVE_TEST_ORDER == 13 |
| 39 | +# define COMB_RANGE 4 |
| 40 | +# define COMB_BLOCKS 1 |
50 | 41 | # define COMB_TEETH 2
|
| 42 | +# define COMB_SPACING 2 |
| 43 | +# elif EXHAUSTIVE_TEST_ORDER == 199 |
| 44 | +# define COMB_RANGE 8 |
| 45 | +# define COMB_BLOCKS 2 |
| 46 | +# define COMB_TEETH 3 |
| 47 | +# define COMB_SPACING 2 |
51 | 48 | # else
|
52 |
| -# define COMB_BLOCKS 256 |
53 |
| -# define COMB_TEETH 1 |
| 49 | +# error "Unknown exhaustive test order" |
| 50 | +# endif |
| 51 | +# if (COMB_RANGE >= 32) || ((EXHAUSTIVE_TEST_ORDER >> (COMB_RANGE - 1)) != 1) |
| 52 | +# error "COMB_RANGE != ceil(log2(EXHAUSTIVE_TEST_ORDER+1))" |
54 | 53 | # endif
|
55 | 54 | #else /* !defined(EXHAUSTIVE_TEST_ORDER) */
|
| 55 | +# define COMB_RANGE 256 |
| 56 | +#endif /* defined(EXHAUSTIVE_TEST_ORDER) */ |
| 57 | + |
56 | 58 | /* Use (11, 6) as default configuration, which results in a 22 kB table. */
|
57 |
| -# ifndef COMB_BLOCKS |
58 |
| -# define COMB_BLOCKS 11 |
59 |
| -# ifdef DEBUG_CONFIG |
60 |
| -# pragma message DEBUG_CONFIG_MSG("COMB_BLOCKS undefined, assuming default value") |
61 |
| -# endif |
| 59 | +#ifndef COMB_BLOCKS |
| 60 | +# define COMB_BLOCKS 11 |
| 61 | +# ifdef DEBUG_CONFIG |
| 62 | +# pragma message DEBUG_CONFIG_MSG("COMB_BLOCKS undefined, assuming default value") |
62 | 63 | # endif
|
63 |
| -# ifndef COMB_TEETH |
64 |
| -# define COMB_TEETH 6 |
65 |
| -# ifdef DEBUG_CONFIG |
66 |
| -# pragma message DEBUG_CONFIG_MSG("COMB_TEETH undefined, assuming default value") |
67 |
| -# endif |
| 64 | +#endif |
| 65 | +#ifndef COMB_TEETH |
| 66 | +# define COMB_TEETH 6 |
| 67 | +# ifdef DEBUG_CONFIG |
| 68 | +# pragma message DEBUG_CONFIG_MSG("COMB_TEETH undefined, assuming default value") |
68 | 69 | # endif
|
69 |
| -#endif /* defined(EXHAUSTIVE_TEST_ORDER) */ |
| 70 | +#endif |
| 71 | +/* Use ceil(COMB_RANGE / (COMB_BLOCKS * COMB_TEETH)) as default COMB_SPACING. */ |
| 72 | +#ifndef COMB_SPACING |
| 73 | +# define COMB_SPACING ((COMB_RANGE + COMB_BLOCKS * COMB_TEETH) / (COMB_BLOCKS * COMB_TEETH)) |
| 74 | +# ifdef DEBUG_CONFIG |
| 75 | +# pragma message DEBUG_CONFIG_MSG("COMB_SPACING undefined, assuming default value") |
| 76 | +# endif |
| 77 | +#endif |
70 | 78 |
|
71 | 79 | /* Range checks on the parameters. */
|
| 80 | + |
| 81 | +/* The remaining COMB_* parameters are derived values, don't modify these. */ |
| 82 | +/* - The number of bits covered by all the blocks; must be at least COMB_RANGE. */ |
| 83 | +#define COMB_BITS (COMB_BLOCKS * COMB_TEETH * COMB_SPACING) |
| 84 | +/* - The number of entries per table. */ |
| 85 | +#define COMB_POINTS (1 << (COMB_TEETH - 1)) |
| 86 | + |
| 87 | +/* Sanity checks. */ |
72 | 88 | #if !(1 <= COMB_BLOCKS && COMB_BLOCKS <= 256)
|
73 | 89 | # error "COMB_BLOCKS must be in the range [1, 256]"
|
74 | 90 | #endif
|
75 | 91 | #if !(1 <= COMB_TEETH && COMB_TEETH <= 8)
|
76 | 92 | # error "COMB_TEETH must be in the range [1, 8]"
|
77 | 93 | #endif
|
| 94 | +#if COMB_BITS < COMB_RANGE |
| 95 | +# error "COMB_BLOCKS * COMB_TEETH * COMB_SPACING is too low" |
| 96 | +#endif |
78 | 97 |
|
79 |
| -/* The remaining COMB_* parameters are derived values, don't modify these. */ |
80 |
| -/* - The distance between the teeth of each comb. */ |
81 |
| -#define COMB_SPACING ((255 + COMB_BLOCKS * COMB_TEETH) / (COMB_BLOCKS * COMB_TEETH)) |
82 |
| -/* - The number of bits covered by all the blocks; must be at least 256. */ |
83 |
| -#define COMB_BITS (COMB_BLOCKS * COMB_TEETH * COMB_SPACING) |
84 |
| -/* - The number of entries per table. */ |
85 |
| -#define COMB_POINTS (1 << (COMB_TEETH - 1)) |
86 |
| - |
87 |
| -/* Additional sanity checks. */ |
| 98 | +/* These last 3 checks are not strictly required, but prevent gratuitously inefficient |
| 99 | + * configurations. Note that they compare with 256 rather than COMB_RANGE, so they do |
| 100 | + * permit somewhat excessive values for the exhaustive test case, where testing with |
| 101 | + * suboptimal parameters may be desirable. */ |
88 | 102 | #if (COMB_BLOCKS - 1) * COMB_TEETH * COMB_SPACING >= 256
|
89 | 103 | # error "COMB_BLOCKS can be reduced"
|
90 | 104 | #endif
|
91 | 105 | #if COMB_BLOCKS * (COMB_TEETH - 1) * COMB_SPACING >= 256
|
92 | 106 | # error "COMB_TEETH can be reduced"
|
93 | 107 | #endif
|
| 108 | +#if COMB_BLOCKS * COMB_TEETH * (COMB_SPACING - 1) >= 256 |
| 109 | +# error "COMB_SPACING can be reduced" |
| 110 | +#endif |
94 | 111 |
|
95 | 112 | #ifdef DEBUG_CONFIG
|
| 113 | +# pragma message DEBUG_CONFIG_DEF(COMB_RANGE) |
96 | 114 | # pragma message DEBUG_CONFIG_DEF(COMB_BLOCKS)
|
97 | 115 | # pragma message DEBUG_CONFIG_DEF(COMB_TEETH)
|
| 116 | +# pragma message DEBUG_CONFIG_DEF(COMB_SPACING) |
98 | 117 | #endif
|
99 | 118 |
|
100 | 119 | typedef struct {
|
|
0 commit comments