Skip to content

test_shifts_beyond_word_size()

Documentation for tests/benchmark/compute/instruction/test_bitwise.py::test_shifts_beyond_word_size@26332146.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/benchmark/compute/instruction/test_bitwise.py::test_shifts_beyond_word_size --gas-benchmark-values 1

Benchmark shifts by at least the 256-bit word size.

Source code in tests/benchmark/compute/instruction/test_bitwise.py
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
@pytest.mark.parametrize(
    "opcode,initial_value",
    [
        pytest.param(Op.SHL, 2**256 - 1),
        pytest.param(Op.SHR, 2**256 - 1),
        pytest.param(Op.SAR, 2**255 - 1),
        pytest.param(Op.SAR, 2**256 - 1),
    ],
)
@pytest.mark.parametrize(
    "shift",
    [
        pytest.param(256, id="word size"),
        pytest.param(2**255, id="unrepresentable as a bit index"),
    ],
)
def test_shifts_beyond_word_size(
    benchmark_test: BenchmarkTestFiller,
    opcode: Op,
    shift: int,
    initial_value: int,
) -> None:
    """
    Benchmark shifts by at least the 256-bit word size.
    """
    benchmark_test(
        target_opcode=opcode,
        code_generator=JumpLoopGenerator(
            setup=Op.PUSH32[initial_value],
            attack_block=Op.PUSH32[shift] + opcode,
        ),
    )

Parametrized Test Cases

This test generates 8 parametrized test cases across 3 forks.