@@ -138,6 +138,9 @@ def test_inst_no_args(self):
138
138
"""
139
139
output = """
140
140
TARGET(OP) {
141
+ frame->instr_ptr = next_instr;
142
+ next_instr += 1;
143
+ INSTRUCTION_STATS(OP);
141
144
spam();
142
145
DISPATCH();
143
146
}
@@ -152,6 +155,9 @@ def test_inst_one_pop(self):
152
155
"""
153
156
output = """
154
157
TARGET(OP) {
158
+ frame->instr_ptr = next_instr;
159
+ next_instr += 1;
160
+ INSTRUCTION_STATS(OP);
155
161
PyObject *value;
156
162
value = stack_pointer[-1];
157
163
spam();
@@ -169,6 +175,9 @@ def test_inst_one_push(self):
169
175
"""
170
176
output = """
171
177
TARGET(OP) {
178
+ frame->instr_ptr = next_instr;
179
+ next_instr += 1;
180
+ INSTRUCTION_STATS(OP);
172
181
PyObject *res;
173
182
spam();
174
183
STACK_GROW(1);
@@ -186,6 +195,9 @@ def test_inst_one_push_one_pop(self):
186
195
"""
187
196
output = """
188
197
TARGET(OP) {
198
+ frame->instr_ptr = next_instr;
199
+ next_instr += 1;
200
+ INSTRUCTION_STATS(OP);
189
201
PyObject *value;
190
202
PyObject *res;
191
203
value = stack_pointer[-1];
@@ -204,6 +216,9 @@ def test_binary_op(self):
204
216
"""
205
217
output = """
206
218
TARGET(OP) {
219
+ frame->instr_ptr = next_instr;
220
+ next_instr += 1;
221
+ INSTRUCTION_STATS(OP);
207
222
PyObject *right;
208
223
PyObject *left;
209
224
PyObject *res;
@@ -225,6 +240,9 @@ def test_overlap(self):
225
240
"""
226
241
output = """
227
242
TARGET(OP) {
243
+ frame->instr_ptr = next_instr;
244
+ next_instr += 1;
245
+ INSTRUCTION_STATS(OP);
228
246
PyObject *right;
229
247
PyObject *left;
230
248
PyObject *result;
@@ -249,6 +267,9 @@ def test_predictions_and_eval_breaker(self):
249
267
"""
250
268
output = """
251
269
TARGET(OP1) {
270
+ frame->instr_ptr = next_instr;
271
+ next_instr += 1;
272
+ INSTRUCTION_STATS(OP1);
252
273
PREDICTED(OP1);
253
274
static_assert(INLINE_CACHE_ENTRIES_OP1 == 0, "incorrect cache size");
254
275
PyObject *arg;
@@ -259,6 +280,9 @@ def test_predictions_and_eval_breaker(self):
259
280
}
260
281
261
282
TARGET(OP3) {
283
+ frame->instr_ptr = next_instr;
284
+ next_instr += 1;
285
+ INSTRUCTION_STATS(OP3);
262
286
PyObject *arg;
263
287
PyObject *res;
264
288
arg = stack_pointer[-1];
@@ -278,6 +302,9 @@ def test_error_if_plain(self):
278
302
"""
279
303
output = """
280
304
TARGET(OP) {
305
+ frame->instr_ptr = next_instr;
306
+ next_instr += 1;
307
+ INSTRUCTION_STATS(OP);
281
308
if (cond) goto label;
282
309
DISPATCH();
283
310
}
@@ -292,6 +319,9 @@ def test_error_if_plain_with_comment(self):
292
319
"""
293
320
output = """
294
321
TARGET(OP) {
322
+ frame->instr_ptr = next_instr;
323
+ next_instr += 1;
324
+ INSTRUCTION_STATS(OP);
295
325
if (cond) goto label;
296
326
DISPATCH();
297
327
}
@@ -306,6 +336,9 @@ def test_error_if_pop(self):
306
336
"""
307
337
output = """
308
338
TARGET(OP) {
339
+ frame->instr_ptr = next_instr;
340
+ next_instr += 1;
341
+ INSTRUCTION_STATS(OP);
309
342
PyObject *right;
310
343
PyObject *left;
311
344
PyObject *res;
@@ -326,12 +359,14 @@ def test_cache_effect(self):
326
359
"""
327
360
output = """
328
361
TARGET(OP) {
362
+ _Py_CODEUNIT *this_instr = frame->instr_ptr = next_instr;
363
+ next_instr += 4;
364
+ INSTRUCTION_STATS(OP);
329
365
PyObject *value;
330
366
value = stack_pointer[-1];
331
- uint16_t counter = read_u16(&next_instr[0 ].cache);
332
- uint32_t extra = read_u32(&next_instr[1 ].cache);
367
+ uint16_t counter = read_u16(&this_instr[1 ].cache);
368
+ uint32_t extra = read_u32(&this_instr[2 ].cache);
333
369
STACK_SHRINK(1);
334
- next_instr += 3;
335
370
DISPATCH();
336
371
}
337
372
"""
@@ -345,6 +380,9 @@ def test_suppress_dispatch(self):
345
380
"""
346
381
output = """
347
382
TARGET(OP) {
383
+ frame->instr_ptr = next_instr;
384
+ next_instr += 1;
385
+ INSTRUCTION_STATS(OP);
348
386
goto somewhere;
349
387
}
350
388
"""
@@ -366,18 +404,24 @@ def test_macro_instruction(self):
366
404
"""
367
405
output = """
368
406
TARGET(OP1) {
407
+ _Py_CODEUNIT *this_instr = frame->instr_ptr = next_instr;
408
+ next_instr += 2;
409
+ INSTRUCTION_STATS(OP1);
369
410
PyObject *right;
370
411
PyObject *left;
371
412
right = stack_pointer[-1];
372
413
left = stack_pointer[-2];
373
- uint16_t counter = read_u16(&next_instr[0 ].cache);
414
+ uint16_t counter = read_u16(&this_instr[1 ].cache);
374
415
op1(left, right);
375
- next_instr += 1;
376
416
DISPATCH();
377
417
}
378
418
379
419
TARGET(OP) {
420
+ frame->instr_ptr = next_instr;
421
+ next_instr += 6;
422
+ INSTRUCTION_STATS(OP);
380
423
PREDICTED(OP);
424
+ _Py_CODEUNIT *this_instr = next_instr - 6;
381
425
static_assert(INLINE_CACHE_ENTRIES_OP == 5, "incorrect cache size");
382
426
PyObject *right;
383
427
PyObject *left;
@@ -387,22 +431,24 @@ def test_macro_instruction(self):
387
431
right = stack_pointer[-1];
388
432
left = stack_pointer[-2];
389
433
{
390
- uint16_t counter = read_u16(&next_instr[0 ].cache);
434
+ uint16_t counter = read_u16(&this_instr[1 ].cache);
391
435
op1(left, right);
392
436
}
393
437
// OP2
394
438
arg2 = stack_pointer[-3];
395
439
{
396
- uint32_t extra = read_u32(&next_instr[3 ].cache);
440
+ uint32_t extra = read_u32(&this_instr[4 ].cache);
397
441
res = op2(arg2, left, right);
398
442
}
399
443
STACK_SHRINK(2);
400
444
stack_pointer[-1] = res;
401
- next_instr += 5;
402
445
DISPATCH();
403
446
}
404
447
405
448
TARGET(OP3) {
449
+ frame->instr_ptr = next_instr;
450
+ next_instr += 6;
451
+ INSTRUCTION_STATS(OP3);
406
452
PyObject *right;
407
453
PyObject *left;
408
454
PyObject *arg2;
@@ -413,7 +459,6 @@ def test_macro_instruction(self):
413
459
res = op3(arg2, left, right);
414
460
STACK_SHRINK(2);
415
461
stack_pointer[-1] = res;
416
- next_instr += 5;
417
462
DISPATCH();
418
463
}
419
464
"""
@@ -427,6 +472,9 @@ def test_array_input(self):
427
472
"""
428
473
output = """
429
474
TARGET(OP) {
475
+ frame->instr_ptr = next_instr;
476
+ next_instr += 1;
477
+ INSTRUCTION_STATS(OP);
430
478
PyObject *above;
431
479
PyObject **values;
432
480
PyObject *below;
@@ -449,6 +497,9 @@ def test_array_output(self):
449
497
"""
450
498
output = """
451
499
TARGET(OP) {
500
+ frame->instr_ptr = next_instr;
501
+ next_instr += 1;
502
+ INSTRUCTION_STATS(OP);
452
503
PyObject *below;
453
504
PyObject **values;
454
505
PyObject *above;
@@ -470,6 +521,9 @@ def test_array_input_output(self):
470
521
"""
471
522
output = """
472
523
TARGET(OP) {
524
+ frame->instr_ptr = next_instr;
525
+ next_instr += 1;
526
+ INSTRUCTION_STATS(OP);
473
527
PyObject **values;
474
528
PyObject *above;
475
529
values = stack_pointer - oparg;
@@ -489,6 +543,9 @@ def test_array_error_if(self):
489
543
"""
490
544
output = """
491
545
TARGET(OP) {
546
+ frame->instr_ptr = next_instr;
547
+ next_instr += 1;
548
+ INSTRUCTION_STATS(OP);
492
549
PyObject **values;
493
550
PyObject *extra;
494
551
values = stack_pointer - oparg;
@@ -509,6 +566,9 @@ def test_cond_effect(self):
509
566
"""
510
567
output = """
511
568
TARGET(OP) {
569
+ frame->instr_ptr = next_instr;
570
+ next_instr += 1;
571
+ INSTRUCTION_STATS(OP);
512
572
PyObject *cc;
513
573
PyObject *input = NULL;
514
574
PyObject *aa;
@@ -541,6 +601,9 @@ def test_macro_cond_effect(self):
541
601
"""
542
602
output = """
543
603
TARGET(M) {
604
+ frame->instr_ptr = next_instr;
605
+ next_instr += 1;
606
+ INSTRUCTION_STATS(M);
544
607
PyObject *right;
545
608
PyObject *middle;
546
609
PyObject *left;
@@ -580,6 +643,9 @@ def test_macro_push_push(self):
580
643
"""
581
644
output = """
582
645
TARGET(M) {
646
+ frame->instr_ptr = next_instr;
647
+ next_instr += 1;
648
+ INSTRUCTION_STATS(M);
583
649
PyObject *val1;
584
650
PyObject *val2;
585
651
// A
@@ -609,6 +675,9 @@ def test_override_inst(self):
609
675
"""
610
676
output = """
611
677
TARGET(OP) {
678
+ frame->instr_ptr = next_instr;
679
+ next_instr += 1;
680
+ INSTRUCTION_STATS(OP);
612
681
ham();
613
682
DISPATCH();
614
683
}
@@ -627,6 +696,9 @@ def test_override_op(self):
627
696
"""
628
697
output = """
629
698
TARGET(M) {
699
+ frame->instr_ptr = next_instr;
700
+ next_instr += 1;
701
+ INSTRUCTION_STATS(M);
630
702
ham();
631
703
DISPATCH();
632
704
}
0 commit comments