From 7d3293c45db7412be87e67ba108065cfb261af5d Mon Sep 17 00:00:00 2001 From: Walter Bright Date: Sat, 15 Mar 2025 15:33:30 -0700 Subject: [PATCH] carith and more branch logic (#21002) * carith() function in exe1.c tests * more branch logic --- compiler/src/dmd/backend/arm/cod3.d | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/compiler/src/dmd/backend/arm/cod3.d b/compiler/src/dmd/backend/arm/cod3.d index d76484e31d..1060a296b3 100644 --- a/compiler/src/dmd/backend/arm/cod3.d +++ b/compiler/src/dmd/backend/arm/cod3.d @@ -109,7 +109,8 @@ void REGSAVE_restore(const ref REGSAVE regsave, ref CodeBuilder cdb, reg_t reg, // https://www.scs.stanford.edu/~zyedidia/arm64/b_cond.html -bool isBranch(uint ins) { return (ins & ((0xFF << 24) | (1 << 4))) == ((0x54 << 24) | (0 << 4)); } +// https://www.scs.stanford.edu/~zyedidia/arm64/bc_cond.html +bool isBranch(uint ins) { return (ins & 0xFF00_0000) == 0x5400_0000; } enum MARS = true; @@ -1496,7 +1497,7 @@ printf("offset: %lld localsize: %lld REGSIZE*2: %d\n", offset, localsize, REGSIZ break; default: - if (0) printf("FL: %s\n", fl_str(c.IFL1)); + if (1) printf("FL: %s\n", fl_str(c.IFL1)); assert(0); } } @@ -1517,10 +1518,10 @@ printf("offset: %lld localsize: %lld REGSIZE*2: %d\n", offset, localsize, REGSIZ @trusted void jmpaddr(code* c) { - code* ci,cn,ctarg,cstart; - targ_size_t ad; - //printf("jmpaddr()\n"); + + code* ci,cn,ctarg,cstart; + uint ad; cstart = c; /* remember start of code */ while (c) { @@ -1538,7 +1539,7 @@ void jmpaddr(code* c) } if (!ci) goto Lbackjmp; // couldn't find it - c.Iop |= cast(uint)(ad >> 2) << 5; + c.Iop |= (ad >> 2) << 5; c.IFL1 = FL.unde; } if (op == LOOP && c.IFL1 == FL.code) /* backwards refs */ @@ -1555,7 +1556,7 @@ void jmpaddr(code* c) ad += calccodsize(ci); ci = code_next(ci); } - c.Iop = cast(uint)(-(ad >> 2)) << 5; + c.Iop = (-(ad >> 2)) << 5; c.IFL1 = FL.unde; } c = code_next(c); @@ -1605,8 +1606,7 @@ uint calccodsize(code* c) @trusted uint codout(int seg, code* c, Barray!ubyte* disasmBuf, ref targ_size_t framehandleroffset) { - code* cn; - uint flags; + //printf("codout()\n"); debug if (debugc) printf("codout(%p), Coffset = x%llx\n",c,cast(ulong)Offset(seg)); @@ -1618,6 +1618,9 @@ uint codout(int seg, code* c, Barray!ubyte* disasmBuf, ref targ_size_t framehand ggen.framehandleroffset = framehandleroffset; ggen.disasmBuf = disasmBuf; + code* cn; + uint flags; + for (; c; c = code_next(c)) { debug @@ -1681,7 +1684,8 @@ uint codout(int seg, code* c, Barray!ubyte* disasmBuf, ref targ_size_t framehand if (ggen.available() < 4) ggen.flush(); - if (c.IFL1 == FL.block) // branch to a block - compute offset + if (isBranch(op) && c.IFL1 == FL.block) + { ggen.flush(); int ad = cast(int)(c.IEV1.Vblock.Boffset - ggen.offset);