This was detected by compiling with MSVC; it triggers warning C4334.
I don't think this is necessary, as we know the maximum shift is a very small integer, but this makes the code more obviously correct.
This was detected by compiling with MSVC; it triggers warning C4334.
I don't think this is necessary, as we know the maximum shift is a very small integer, but this makes the code more obviously correct.
utACK 1b8e50570c7227d958989d16fafa40313073a462
Rationale:
Updated. Suggestion from IRC:
< gmaxwell> sipa: why multiply instead shifting the sizeof?
1062 | @@ -1063,7 +1063,7 @@ static size_t secp256k1_pippenger_max_points(secp256k1_scratch *scratch) { 1063 | #ifdef USE_ENDOMORPHISM 1064 | entry_size = 2*entry_size; 1065 | #endif 1066 | - space_overhead = ((1<<bucket_window) * sizeof(secp256k1_gej) + entry_size + sizeof(struct secp256k1_pippenger_state)); 1067 | + space_overhead = sizeof(secp256k1_gej) << bucket_window + entry_size + sizeof(struct secp256k1_pippenger_state);
Precedence is hard :-)
space_overhead = (sizeof(secp256k1_gej) << bucket_window) + entry_size + sizeof(struct secp256k1_pippenger_state);
FWIW, I believe that Greg's suggestion (with the precedence fix in place) will generate the same binary as 1b8e50570c7227d958989d16fafa40313073a462 under both clang and gcc given -O1.
959 | @@ -960,7 +960,7 @@ static size_t secp256k1_pippenger_scratch_size(size_t n_points, int bucket_windo 960 | size_t entries = n_points + 1; 961 | #endif 962 | size_t entry_size = sizeof(secp256k1_ge) + sizeof(secp256k1_scalar) + sizeof(struct secp256k1_pippenger_point_state) + (WNAF_SIZE(bucket_window+1)+1)*sizeof(int); 963 | - return ((1<<bucket_window) * sizeof(secp256k1_gej) + sizeof(struct secp256k1_pippenger_state) + entries * entry_size); 964 | + return sizeof(secp256k1_gej) << bucket_window + sizeof(struct secp256k1_pippenger_state) + entries * entry_size;
return (sizeof(secp256k1_gej) << bucket_window) + sizeof(struct secp256k1_pippenger_state) + entries * entry_size;
I don't think excessive parentheses help readability.
Except in this case they're not actually excessive; they're necessary for correctness. Sorry!
ACK. Has someone verified that this silences this particular warning from MSVC (e.g. did we get all the cases?)
< gmaxwell> sipa: why multiply instead shifting the sizeof?
The multiplication makes the purpose clearer, at least for stupid me.
Whatever, post-merge utACK. :)