aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Pall <mike>2016-12-07 09:42:43 +0100
committerMike Pall <mike>2016-12-07 09:42:43 +0100
commit22511fbe2b284d722f3a7ea901f1ae54992c9c5e (patch)
treeb96aec8323cae653a6fe9a8afe81aa4894ca4e46
parent3ad2bbf58600f8ba2918b56b0a7ab305df19cfe5 (diff)
downloadluajit-22511fbe2b284d722f3a7ea901f1ae54992c9c5e.tar.gz
luajit-22511fbe2b284d722f3a7ea901f1ae54992c9c5e.tar.bz2
luajit-22511fbe2b284d722f3a7ea901f1ae54992c9c5e.zip
ARM64: Fix pc-relative loads of consts. Cleanup branch codegen.
Thanks to Zhongwei Yao.
-rw-r--r--src/lj_emit_arm64.h30
1 files changed, 13 insertions, 17 deletions
diff --git a/src/lj_emit_arm64.h b/src/lj_emit_arm64.h
index 1eb14204..6686802b 100644
--- a/src/lj_emit_arm64.h
+++ b/src/lj_emit_arm64.h
@@ -234,7 +234,7 @@ static void emit_loadk(ASMState *as, Reg rd, uint64_t u64, int is64)
234#define glofs(as, k) \ 234#define glofs(as, k) \
235 ((intptr_t)((uintptr_t)(k) - (uintptr_t)&J2GG(as->J)->g)) 235 ((intptr_t)((uintptr_t)(k) - (uintptr_t)&J2GG(as->J)->g))
236#define mcpofs(as, k) \ 236#define mcpofs(as, k) \
237 ((intptr_t)((uintptr_t)(k) - (uintptr_t)as->mcp)) 237 ((intptr_t)((uintptr_t)(k) - (uintptr_t)(as->mcp - 1)))
238#define checkmcpofs(as, k) \ 238#define checkmcpofs(as, k) \
239 ((((mcpofs(as, k)>>2) + 0x00040000) >> 19) == 0) 239 ((((mcpofs(as, k)>>2) + 0x00040000) >> 19) == 0)
240 240
@@ -305,39 +305,35 @@ typedef MCode *MCLabel;
305 305
306static void emit_cond_branch(ASMState *as, A64CC cond, MCode *target) 306static void emit_cond_branch(ASMState *as, A64CC cond, MCode *target)
307{ 307{
308 MCode *p = as->mcp; 308 MCode *p = --as->mcp;
309 ptrdiff_t delta = target - (p - 1); 309 ptrdiff_t delta = target - p;
310 lua_assert(((delta + 0x40000) >> 19) == 0); 310 lua_assert(((delta + 0x40000) >> 19) == 0);
311 *--p = A64I_BCC | A64F_S19((uint32_t)delta & 0x7ffff) | cond; 311 *p = A64I_BCC | A64F_S19((uint32_t)delta & 0x7ffff) | cond;
312 as->mcp = p;
313} 312}
314 313
315static void emit_branch(ASMState *as, A64Ins ai, MCode *target) 314static void emit_branch(ASMState *as, A64Ins ai, MCode *target)
316{ 315{
317 MCode *p = as->mcp; 316 MCode *p = --as->mcp;
318 ptrdiff_t delta = target - (p - 1); 317 ptrdiff_t delta = target - p;
319 lua_assert(((delta + 0x02000000) >> 26) == 0); 318 lua_assert(((delta + 0x02000000) >> 26) == 0);
320 *--p = ai | ((uint32_t)delta & 0x03ffffffu); 319 *p = ai | ((uint32_t)delta & 0x03ffffffu);
321 as->mcp = p;
322} 320}
323 321
324static void emit_tnb(ASMState *as, A64Ins ai, Reg r, uint32_t bit, MCode *target) 322static void emit_tnb(ASMState *as, A64Ins ai, Reg r, uint32_t bit, MCode *target)
325{ 323{
326 MCode *p = as->mcp; 324 MCode *p = --as->mcp;
327 ptrdiff_t delta = target - (p - 1); 325 ptrdiff_t delta = target - p;
328 lua_assert(bit < 63 && ((delta + 0x2000) >> 14) == 0); 326 lua_assert(bit < 63 && ((delta + 0x2000) >> 14) == 0);
329 if (bit > 31) ai |= A64I_X; 327 if (bit > 31) ai |= A64I_X;
330 *--p = ai | A64F_BIT(bit & 31) | A64F_S14((uint32_t)delta & 0x3fffu) | r; 328 *p = ai | A64F_BIT(bit & 31) | A64F_S14((uint32_t)delta & 0x3fffu) | r;
331 as->mcp = p;
332} 329}
333 330
334static void emit_cnb(ASMState *as, A64Ins ai, Reg r, MCode *target) 331static void emit_cnb(ASMState *as, A64Ins ai, Reg r, MCode *target)
335{ 332{
336 MCode *p = as->mcp; 333 MCode *p = --as->mcp;
337 ptrdiff_t delta = target - (p - 1); 334 ptrdiff_t delta = target - p;
338 lua_assert(((delta + 0x40000) >> 19) == 0); 335 lua_assert(((delta + 0x40000) >> 19) == 0);
339 *--p = ai | A64F_S19((uint32_t)delta & 0x7ffff) | r; 336 *p = ai | A64F_S19((uint32_t)delta & 0x7ffff) | r;
340 as->mcp = p;
341} 337}
342 338
343#define emit_jmp(as, target) emit_branch(as, A64I_B, (target)) 339#define emit_jmp(as, target) emit_branch(as, A64I_B, (target))