Skip to content

Commit

Permalink
Try just setting the implict shift as needed
Browse files Browse the repository at this point in the history
  • Loading branch information
brandtbucher committed Jul 14, 2023
1 parent 4110913 commit 2023452
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/jit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ jobs:
- true
# - false
llvm:
# - 14
- 14
# - 15
- 16
# - 16
include:
# - target: i686-pc-windows-msvc/msvc
# architecture: i686
Expand Down
37 changes: 25 additions & 12 deletions Python/jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,29 +67,42 @@ patch_one(unsigned char *location, HoleKind kind, uint64_t value, uint64_t adden
uint32_t instruction = *addr;
assert(((instruction & 0x3B000000) == 0x39000000) ||
((instruction & 0x11C00000) == 0x11000000));
if ((value + addend) & 0x7) { // XXX: Remote debugging info.
printf("PATCH_ABS_12: possibly unaligned value %lu + %lu (at %p)\n", value, addend, location);
};
value = (value + addend) & ((1 << 12) - 1);
int implicit_shift = 0;
if ((instruction & 0x3B000000) == 0x39000000) {
implicit_shift = ((instruction >> 30) & 0x3);
// XXX: We shouldn't have to rewrite these (we *should* be
// able to just assert the alignment), but something's up with
// aarch64 + ELF (at least with LLVM 14, I haven't tested 15
// and 16):
switch (implicit_shift) {
case 3:
if ((value & 0x7) == 0) {
break;
}
implicit_shift = 2;
instruction = (instruction & ~(0x3UL << 30)) | (implicit_shift << 30);
// Fall through...
case 2:
if ((value & 0x3) == 0) {
break;
}
implicit_shift = 1;
instruction = (instruction & ~(0x3UL << 30)) | (implicit_shift << 30);
// Fall through...
case 1:
if ((value & 0x1) == 0) {
break;
}
implicit_shift = 0;
instruction = (instruction & ~(0x3UL << 30)) | (implicit_shift << 30);
// Fall through...
case 0:
if ((instruction & 0x04800000) == 0x04800000) {
implicit_shift = 4;
assert(((value & 0xF) == 0));
}
break;
case 1:
assert(((value & 0x1) == 0));
break;
case 2:
assert(((value & 0x3) == 0));
break;
case 3:
assert(((value & 0x7) == 0));
break;
}
}
value >>= implicit_shift;
Expand Down

0 comments on commit 2023452

Please sign in to comment.