@@ -149,12 +149,12 @@ set_bits(uint32_t *loc, uint8_t loc_start, uint64_t value, uint8_t value_start,
149
149
// Fill all of stencil's holes in the memory pointed to by base, using the
150
150
// values in patches.
151
151
static void
152
- patch (unsigned char * base , const Stencil * stencil , uint64_t * patches )
152
+ patch (unsigned char * base , const Stencil * stencil , uintptr_t patches [] )
153
153
{
154
- for (uint64_t i = 0 ; i < stencil -> holes_size ; i ++ ) {
154
+ for (size_t i = 0 ; i < stencil -> holes_size ; i ++ ) {
155
155
const Hole * hole = & stencil -> holes [i ];
156
156
unsigned char * location = base + hole -> offset ;
157
- uint64_t value = patches [hole -> value ] + (uint64_t )hole -> symbol + hole -> addend ;
157
+ uint64_t value = patches [hole -> value ] + (uintptr_t )hole -> symbol + hole -> addend ;
158
158
uint8_t * loc8 = (uint8_t * )location ;
159
159
uint32_t * loc32 = (uint32_t * )location ;
160
160
uint64_t * loc64 = (uint64_t * )location ;
@@ -228,7 +228,7 @@ patch(unsigned char *base, const Stencil *stencil, uint64_t *patches)
228
228
case HoleKind_X86_64_RELOC_SIGNED :
229
229
case HoleKind_X86_64_RELOC_BRANCH :
230
230
// 32-bit relative address.
231
- value -= (uint64_t )location ;
231
+ value -= (uintptr_t )location ;
232
232
// Check that we're not out of range of 32 signed bits:
233
233
assert ((int64_t )value >= - (1LL << 31 ));
234
234
assert ((int64_t )value < (1LL << 31 ));
@@ -239,7 +239,7 @@ patch(unsigned char *base, const Stencil *stencil, uint64_t *patches)
239
239
case HoleKind_R_AARCH64_JUMP26 :
240
240
// 28-bit relative branch.
241
241
assert (IS_AARCH64_BRANCH (* loc32 ));
242
- value -= (uint64_t )location ;
242
+ value -= (uintptr_t )location ;
243
243
// Check that we're not out of range of 28 signed bits:
244
244
assert ((int64_t )value >= - (1 << 27 ));
245
245
assert ((int64_t )value < (1 << 27 ));
@@ -313,7 +313,7 @@ patch(unsigned char *base, const Stencil *stencil, uint64_t *patches)
313
313
i ++ ;
314
314
continue ;
315
315
}
316
- relaxed = ( uint64_t ) value - (uint64_t )location ;
316
+ relaxed = value - (uintptr_t )location ;
317
317
if ((relaxed & 0x3 ) == 0 &&
318
318
(int64_t )relaxed >= - (1L << 19 ) &&
319
319
(int64_t )relaxed < (1L << 19 ))
@@ -328,7 +328,7 @@ patch(unsigned char *base, const Stencil *stencil, uint64_t *patches)
328
328
// Fall through...
329
329
case HoleKind_ARM64_RELOC_PAGE21 :
330
330
// Number of pages between this page and the value's page:
331
- value = (value >> 12 ) - ((uint64_t )location >> 12 );
331
+ value = (value >> 12 ) - ((uintptr_t )location >> 12 );
332
332
// Check that we're not out of range of 21 signed bits:
333
333
assert ((int64_t )value >= - (1 << 20 ));
334
334
assert ((int64_t )value < (1 << 20 ));
@@ -363,14 +363,14 @@ patch(unsigned char *base, const Stencil *stencil, uint64_t *patches)
363
363
}
364
364
365
365
static void
366
- copy_and_patch (unsigned char * base , const Stencil * stencil , uint64_t * patches )
366
+ copy_and_patch (unsigned char * base , const Stencil * stencil , uintptr_t patches [] )
367
367
{
368
368
memcpy (base , stencil -> body , stencil -> body_size );
369
369
patch (base , stencil , patches );
370
370
}
371
371
372
372
static void
373
- emit (const StencilGroup * group , uint64_t patches [])
373
+ emit (const StencilGroup * group , uintptr_t patches [])
374
374
{
375
375
copy_and_patch ((unsigned char * )patches [HoleValue_DATA ], & group -> data , patches );
376
376
copy_and_patch ((unsigned char * )patches [HoleValue_CODE ], & group -> code , patches );
381
381
_PyJIT_Compile (_PyExecutorObject * executor , const _PyUOpInstruction * trace , size_t length )
382
382
{
383
383
// Loop once to find the total compiled size:
384
- uint32_t instruction_starts [UOP_MAX_TRACE_LENGTH ];
385
- uint32_t code_size = 0 ;
386
- uint32_t data_size = 0 ;
384
+ size_t instruction_starts [UOP_MAX_TRACE_LENGTH ];
385
+ size_t code_size = 0 ;
386
+ size_t data_size = 0 ;
387
387
for (size_t i = 0 ; i < length ; i ++ ) {
388
388
_PyUOpInstruction * instruction = (_PyUOpInstruction * )& trace [i ];
389
389
const StencilGroup * group = & stencil_groups [instruction -> opcode ];
@@ -409,14 +409,20 @@ _PyJIT_Compile(_PyExecutorObject *executor, const _PyUOpInstruction *trace, size
409
409
for (size_t i = 0 ; i < length ; i ++ ) {
410
410
_PyUOpInstruction * instruction = (_PyUOpInstruction * )& trace [i ];
411
411
const StencilGroup * group = & stencil_groups [instruction -> opcode ];
412
- // Think of patches as a dictionary mapping HoleValue to uint64_t :
413
- uint64_t patches [] = GET_PATCHES ();
414
- patches [HoleValue_CODE ] = (uint64_t )code ;
415
- patches [HoleValue_CONTINUE ] = (uint64_t )code + group -> code .body_size ;
416
- patches [HoleValue_DATA ] = (uint64_t )data ;
417
- patches [HoleValue_EXECUTOR ] = (uint64_t )executor ;
412
+ // Think of patches as a dictionary mapping HoleValue to uintptr_t :
413
+ uintptr_t patches [] = GET_PATCHES ();
414
+ patches [HoleValue_CODE ] = (uintptr_t )code ;
415
+ patches [HoleValue_CONTINUE ] = (uintptr_t )code + group -> code .body_size ;
416
+ patches [HoleValue_DATA ] = (uintptr_t )data ;
417
+ patches [HoleValue_EXECUTOR ] = (uintptr_t )executor ;
418
418
patches [HoleValue_OPARG ] = instruction -> oparg ;
419
+ #if SIZEOF_VOID_P == 8
419
420
patches [HoleValue_OPERAND ] = instruction -> operand ;
421
+ #else
422
+ assert (SIZEOF_VOID_P == 4 );
423
+ patches [HoleValue_OPERAND_HI ] = instruction -> operand >> 32 ;
424
+ patches [HoleValue_OPERAND_LO ] = instruction -> operand & UINT32_MAX ;
425
+ #endif
420
426
switch (instruction -> format ) {
421
427
case UOP_FORMAT_TARGET :
422
428
patches [HoleValue_TARGET ] = instruction -> target ;
@@ -425,34 +431,34 @@ _PyJIT_Compile(_PyExecutorObject *executor, const _PyUOpInstruction *trace, size
425
431
assert (instruction -> exit_index < executor -> exit_count );
426
432
patches [HoleValue_EXIT_INDEX ] = instruction -> exit_index ;
427
433
if (instruction -> error_target < length ) {
428
- patches [HoleValue_ERROR_TARGET ] = (uint64_t )memory + instruction_starts [instruction -> error_target ];
434
+ patches [HoleValue_ERROR_TARGET ] = (uintptr_t )memory + instruction_starts [instruction -> error_target ];
429
435
}
430
436
break ;
431
437
case UOP_FORMAT_JUMP :
432
438
assert (instruction -> jump_target < length );
433
- patches [HoleValue_JUMP_TARGET ] = (uint64_t )memory + instruction_starts [instruction -> jump_target ];
439
+ patches [HoleValue_JUMP_TARGET ] = (uintptr_t )memory + instruction_starts [instruction -> jump_target ];
434
440
if (instruction -> error_target < length ) {
435
- patches [HoleValue_ERROR_TARGET ] = (uint64_t )memory + instruction_starts [instruction -> error_target ];
441
+ patches [HoleValue_ERROR_TARGET ] = (uintptr_t )memory + instruction_starts [instruction -> error_target ];
436
442
}
437
443
break ;
438
444
default :
439
445
assert (0 );
440
446
Py_FatalError ("Illegal instruction format" );
441
447
}
442
- patches [HoleValue_TOP ] = (uint64_t )memory + instruction_starts [1 ];
448
+ patches [HoleValue_TOP ] = (uintptr_t )memory + instruction_starts [1 ];
443
449
patches [HoleValue_ZERO ] = 0 ;
444
450
emit (group , patches );
445
451
code += group -> code .body_size ;
446
452
data += group -> data .body_size ;
447
453
}
448
454
// Protect against accidental buffer overrun into data:
449
455
const StencilGroup * group = & stencil_groups [_FATAL_ERROR ];
450
- uint64_t patches [] = GET_PATCHES ();
451
- patches [HoleValue_CODE ] = (uint64_t )code ;
452
- patches [HoleValue_CONTINUE ] = (uint64_t )code ;
453
- patches [HoleValue_DATA ] = (uint64_t )data ;
454
- patches [HoleValue_EXECUTOR ] = (uint64_t )executor ;
455
- patches [HoleValue_TOP ] = (uint64_t )code ;
456
+ uintptr_t patches [] = GET_PATCHES ();
457
+ patches [HoleValue_CODE ] = (uintptr_t )code ;
458
+ patches [HoleValue_CONTINUE ] = (uintptr_t )code ;
459
+ patches [HoleValue_DATA ] = (uintptr_t )data ;
460
+ patches [HoleValue_EXECUTOR ] = (uintptr_t )executor ;
461
+ patches [HoleValue_TOP ] = (uintptr_t )code ;
456
462
patches [HoleValue_ZERO ] = 0 ;
457
463
emit (group , patches );
458
464
code += group -> code .body_size ;
0 commit comments