@@ -71,17 +71,20 @@ static uint8_t cache_requirements[256] = { 0 };
71
71
* instruction index and oparg are related */
72
72
static int
73
73
oparg_from_instruction_and_update_offset (int index , int opcode , int original_oparg , int * cache_offset ) {
74
+ /* The instruction pointer in the interpreter points to the next
75
+ * instruction, so we compute the offset using nexti (index + 1) */
76
+ int nexti = index + 1 ;
74
77
uint8_t need = cache_requirements [opcode ];
75
78
if (need == 0 ) {
76
79
return original_oparg ;
77
80
}
78
81
assert (adaptive_opcodes [opcode ] != 0 );
79
- int oparg = oparg_from_offset_and_index (* cache_offset , index );
80
- assert (* cache_offset == offset_from_oparg_and_index (oparg , index ));
81
- /* Some cache space is wasted here as the minimum possible offset is (index >>1) */
82
+ int oparg = oparg_from_offset_and_nexti (* cache_offset , nexti );
83
+ assert (* cache_offset == offset_from_oparg_and_nexti (oparg , nexti ));
84
+ /* Some cache space is wasted here as the minimum possible offset is (nexti >>1) */
82
85
if (oparg < 0 ) {
83
86
oparg = 0 ;
84
- * cache_offset = offset_from_oparg_and_index (oparg , index );
87
+ * cache_offset = offset_from_oparg_and_nexti (oparg , nexti );
85
88
}
86
89
else if (oparg > 255 ) {
87
90
return -1 ;
@@ -105,7 +108,6 @@ entries_needed(_Py_CODEUNIT *code, int len)
105
108
return cache_offset + 1 ; // One extra for the count entry
106
109
}
107
110
108
-
109
111
static inline _Py_CODEUNIT *
110
112
first_instruction (SpecializedCacheOrInstruction * quickened )
111
113
{
@@ -125,15 +127,12 @@ optimize(SpecializedCacheOrInstruction *quickened, int len)
125
127
int cache_offset = 0 ;
126
128
int previous_opcode = -1 ;
127
129
for (int i = 0 ; i < len ; i ++ ) {
128
- /* The instruction pointer in the intperpreter points to the next
129
- * instruction. We want to use index+1 for efficiency. */
130
- int nexti = i + 1 ;
131
130
int opcode = _Py_OPCODE (instructions [i ]);
132
131
int oparg = _Py_OPARG (instructions [i ]);
133
132
uint8_t adaptive_opcode = adaptive_opcodes [opcode ];
134
133
if (adaptive_opcode && previous_opcode != EXTENDED_ARG ) {
135
134
int new_oparg = oparg_from_instruction_and_update_offset (
136
- nexti , opcode , oparg , & cache_offset
135
+ i , opcode , oparg , & cache_offset
137
136
);
138
137
if (new_oparg < 0 ) {
139
138
/* Not possible to allocate a cache for this instruction */
0 commit comments