File tree Expand file tree Collapse file tree 1 file changed +12
-5
lines changed
tests/osaka/eip7939_count_leading_zeros Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -32,8 +32,10 @@ def clz_parameters():
32
32
"""Generate all test case parameters."""
33
33
test_cases = []
34
34
35
+ # Format 0x000...000: all zeros
36
+ test_cases .append (("zero" , 0 , 256 ))
37
+
35
38
# Format 0xb000...111: leading zeros followed by ones
36
- # Special case: bits=256 gives value=0 (all zeros)
37
39
for bits in range (257 ):
38
40
value = (2 ** 256 - 1 ) >> bits
39
41
expected_clz = bits
@@ -43,10 +45,15 @@ def clz_parameters():
43
45
)
44
46
test_cases .append ((f"leading_zeros_{ bits } " , value , expected_clz ))
45
47
46
- # Format 0xb010...000: single bit set
47
- for bits in range (256 ):
48
- value = 1 << bits
49
- expected_clz = 255 - bits
48
+ # Format 0xb010...000: single bit set (1 << N for N = 1…256)
49
+ for bits in range (1 , 257 ):
50
+ if bits == 256 :
51
+ # Special case: 1 << 256 = 0 in 256-bit arithmetic (overflow)
52
+ value = 0
53
+ expected_clz = 256
54
+ else :
55
+ value = 1 << bits
56
+ expected_clz = 255 - bits
50
57
assert expected_clz == Spec .calculate_clz (value ), (
51
58
f"CLZ calculation mismatch for single_bit_{ bits } : "
52
59
f"manual={ expected_clz } , spec={ Spec .calculate_clz (value )} , value={ hex (value )} "
You can’t perform that action at this time.
0 commit comments