Skip to content

Commit e02ac1d

Browse files
authored
gh-148515: make optimizer_generator respect multiple caches (#148524)
1 parent c40e8b0 commit e02ac1d

File tree

4 files changed

+33
-4
lines changed

4 files changed

+33
-4
lines changed

Lib/test/test_generated_cases.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2696,5 +2696,30 @@ def test_replace_opocode_uop_reject_array_effects(self):
26962696
"Pure evaluation cannot take array-like inputs"):
26972697
self.run_cases_test(input, input2, output)
26982698

2699+
def test_overridden_abstract_with_multiple_caches(self):
2700+
input = """
2701+
op(OP, (version/1, unused/1, index/1, value -- res)) {
2702+
res = SPAM(version, index, value);
2703+
}
2704+
"""
2705+
input2 = """
2706+
op(OP, (value -- res)) {
2707+
res = eggs(version, index, value);
2708+
}
2709+
"""
2710+
output = """
2711+
case OP: {
2712+
JitOptRef value;
2713+
JitOptRef res;
2714+
value = stack_pointer[-1];
2715+
uint16_t version = (uint16_t)this_instr->operand0;
2716+
uint16_t index = (uint16_t)this_instr->operand1;
2717+
res = eggs(version, index, value);
2718+
stack_pointer[-1] = res;
2719+
break;
2720+
}
2721+
"""
2722+
self.run_cases_test(input, input2, output)
2723+
26992724
if __name__ == "__main__":
27002725
unittest.main()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a bug in the JIT optimizer reading operands for uops with multiple
2+
caches.

Python/optimizer_cases.c.h

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tools/cases_generator/optimizer_generator.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,14 +412,16 @@ def write_uop(
412412
args.append(input.name)
413413
out.emit(f'DEBUG_PRINTF({", ".join(args)});\n')
414414
if override:
415+
idx = 0
415416
for cache in uop.caches:
416417
if cache.name != "unused":
417418
if cache.size == 4:
418419
type = cast = "PyObject *"
419420
else:
420421
type = f"uint{cache.size*16}_t "
421422
cast = f"uint{cache.size*16}_t"
422-
out.emit(f"{type}{cache.name} = ({cast})this_instr->operand0;\n")
423+
out.emit(f"{type}{cache.name} = ({cast})this_instr->operand{idx};\n")
424+
idx += 1
423425
if override:
424426
emitter = OptimizerEmitter(out, {}, uop, stack.copy())
425427
# No reference management of inputs needed.

0 commit comments

Comments
 (0)