@@ -583,6 +583,12 @@ async def build(self) -> None:
583
583
task = self ._compile (opname , TOOLS_JIT_TEMPLATE , tempdir )
584
584
group .create_task (task )
585
585
586
+ def as_i64 (value : int , width : int = 0 ) -> str :
587
+ value %= 1 << 64
588
+ width = max (0 , width - 3 )
589
+ if value & (1 << 63 ):
590
+ return f"-0x{ (1 << 64 ) - value :0{width }x} "
591
+ return f"+0x{ value :0{width }x} "
586
592
587
593
def dump (stencils : dict [str , Stencil ]) -> typing .Generator [str , None , None ]:
588
594
yield f"// $ { sys .executable } { ' ' .join (sys .argv )} " # XXX
@@ -608,7 +614,7 @@ def dump(stencils: dict[str, Stencil]) -> typing.Generator[str, None, None]:
608
614
yield f" const HoleKind kind;"
609
615
yield f" const uint64_t offset;"
610
616
yield f" const uint64_t addend;"
611
- yield f" const int symbol;"
617
+ yield f" const uint64_t symbol;"
612
618
yield f"}} SymbolLoad;"
613
619
yield f""
614
620
yield f"typedef struct {{"
@@ -642,7 +648,7 @@ def dump(stencils: dict[str, Stencil]) -> typing.Generator[str, None, None]:
642
648
(len (f"{ hole .offset :x} " ) for hole in stencil .holes ), default = 0
643
649
)
644
650
addend_width = max (
645
- (len (f"{ hole .addend % ( 1 << 64 ):x } " ) for hole in stencil .holes ), default = 0
651
+ (len (f"{ as_i64 ( hole .addend ) } " ) for hole in stencil .holes ), default = 0
646
652
)
647
653
value_width = max (
648
654
(
@@ -654,7 +660,7 @@ def dump(stencils: dict[str, Stencil]) -> typing.Generator[str, None, None]:
654
660
)
655
661
symbol_width = max (
656
662
(
657
- len (f"{ symbols . index ( hole .symbol ) } " )
663
+ len (f"{ hole .symbol } " )
658
664
for hole in stencil .holes
659
665
if hole .symbol not in HoleValue .__members__
660
666
),
@@ -667,7 +673,7 @@ def dump(stencils: dict[str, Stencil]) -> typing.Generator[str, None, None]:
667
673
f" {{"
668
674
f".kind={ hole .kind :{kind_width }} , "
669
675
f".offset=0x{ hole .offset :0{offset_width }x} , "
670
- f".addend=0x { hole .addend % ( 1 << 64 ):0{ addend_width }x } , "
676
+ f".addend={ as_i64 ( hole .addend , addend_width ) } , "
671
677
f".value={ value .name :{value_width }} "
672
678
f"}},"
673
679
)
@@ -676,9 +682,9 @@ def dump(stencils: dict[str, Stencil]) -> typing.Generator[str, None, None]:
676
682
f" {{"
677
683
f".kind={ hole .kind :{kind_width }} , "
678
684
f".offset=0x{ hole .offset :0{offset_width }x} , "
679
- f".addend=0x { hole .addend % ( 1 << 64 ):0{ addend_width }x } , "
680
- f".symbol={ symbols . index ( hole .symbol ) :{symbol_width }} "
681
- f"}}, // { hole . symbol } "
685
+ f".addend={ as_i64 ( hole .addend , addend_width ) } , "
686
+ f".symbol=(uintptr_t)& { hole .symbol :{symbol_width }} "
687
+ f"}},"
682
688
)
683
689
if holes :
684
690
yield f"static const Hole { opname } _stencil_holes[{ len (holes ) + 1 } ] = {{"
@@ -695,14 +701,6 @@ def dump(stencils: dict[str, Stencil]) -> typing.Generator[str, None, None]:
695
701
else :
696
702
yield f"static const SymbolLoad { opname } _stencil_loads[{ len (loads ) + 1 } ];"
697
703
yield f""
698
- yield f""
699
- yield f"static const char *const symbols[{ len (symbols )} ] = {{"
700
- for symbol in symbols :
701
- yield f' "{ symbol } ",'
702
- yield f"}};"
703
- yield f""
704
- yield f"static uint64_t symbol_addresses[{ len (symbols )} ];"
705
- yield f""
706
704
yield f"#define INIT_STENCIL(OP) {{ \\ "
707
705
yield f" .nbytes = Py_ARRAY_LENGTH(OP##_stencil_bytes), \\ "
708
706
yield f" .bytes = OP##_stencil_bytes, \\ "
0 commit comments