Skip to content

Commit c39126b

Browse files
committed
Clarify code
1 parent ba7f233 commit c39126b

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

ext/opcache/jit/tls/zend_jit_tls_aarch64.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ TSRMLS_CACHE_EXTERN();
2828

2929
/* https://developer.arm.com/documentation/ddi0602/2025-03/Base-Instructions/ADRP--Form-PC-relative-address-to-4KB-page- */
3030
#define AARCH64_ADRP_IMM_MASK 0x60ffffe0 /* bits 30-29, 23-5 */
31+
#define AARCH64_ADRP_IMMHI_MASK 0x00ffffe0 /* bits 23-5 */
32+
#define AARCH64_ADRP_IMMLO_MASK 0x60000000 /* bits 30-29 */
33+
#define AARCH64_ADRP_IMMHI_START 5
34+
#define AARCH64_ADRP_IMMLO_START 29
35+
#define AARCH64_ADRP_IMMLO_WIDTH 2
36+
3137
#define AARCH64_LDR_UNSIGNED_IMM_MASK 0x003ffc00 /* bits 21-10 */
3238
#define AARCH64_ADD_IMM_MASK 0x003ffc00 /* bits 21-10 */
3339
#define AARCH64_MOVZ_IMM_MASK 0x001fffe0 /* bits 20-5 */
@@ -146,7 +152,9 @@ zend_result zend_jit_resolve_tsrm_ls_cache_offsets(
146152

147153
/* Code is intact, we can extract immediate values */
148154

149-
uint64_t adrp_imm = (uint64_t)( ((insn[0] & 0x00ffffe0) >> 3) | ((insn[0] & 0x60000000) >> 29) ) << 12;
155+
uint64_t adrp_immhi = (uint64_t)((insn[0] & AARCH64_ADRP_IMMHI_MASK) >> AARCH64_ADRP_IMMHI_START);
156+
uint64_t adrp_immlo = (uint64_t)((insn[0] & AARCH64_ADRP_IMMLO_MASK) >> AARCH64_ADRP_IMMLO_START);
157+
uint64_t adrp_imm = ((adrp_immhi << AARCH64_ADRP_IMMLO_WIDTH) | adrp_immlo) << 12;
150158
uint64_t add_imm = (uint64_t)(insn[2] & AARCH64_ADD_IMM_MASK) >> 10;
151159
uint64_t pc = (uint64_t)insn;
152160
uintptr_t **where = (uintptr_t**)((pc & ~(4096-1)) + adrp_imm + add_imm);

0 commit comments

Comments
 (0)