shithub: riscv

Download patch

ref: 85d0f0e1a2c05afee5a101c1e51a3ddd2ff2a5f6
parent: e4191b8d11ae31efe758abfa5b48bf0b99c912a4
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun Dec 10 18:51:54 EST 2023

7l: fix constant pool size for imm14 displacement for TBZ/TBNZ

The new TBZ/TBNZ instructions use imm14 displacement (±32K 4-byte
instruction aligned), so have to check constant pool more often.

Also, make the absolute pc value vlong.

--- a/sys/src/cmd/7l/pass.c
+++ b/sys/src/cmd/7l/pass.c
@@ -234,7 +234,7 @@
 			}
 			if(isbranch(a) || isreturn(a))
 				goto copy;
-			if(q->cond == nil || (q->cond->mark&FOLL))
+			if(q->cond == P || (q->cond->mark&FOLL))
 				continue;
 			if(a != ABEQ && a != ABNE)
 				continue;
--- a/sys/src/cmd/7l/span.c
+++ b/sys/src/cmd/7l/span.c
@@ -3,13 +3,13 @@
 #define	BIT(n)	((uvlong)1<<(n))
 
 static struct {
-	ulong	start;
-	ulong	size;
+	vlong	start;
+	vlong	size;
 } pool;
 
 static void	checkpool(Prog*, int);
 static void 	flushpool(Prog*, int);
-static int	ispcdisp(long);
+static int	ispcdisp(vlong);
 
 static Optab *badop;
 static Oprang	oprange[ALAST];
@@ -155,7 +155,7 @@
 
 /*
  * when the first reference to the literal pool threatens
- * to go out of range of a 1Mb PC-relative offset
+ * to go out of range of a 1MB PC-relative offset
  * drop the pool now, and branch round it.
  */
 static void
@@ -175,7 +175,7 @@
 	if(blitrl) {
 		if(skip){
 			if(debug['v'] && skip == 1)
-				print("note: flush literal pool at %#llux: len=%lud ref=%lux\n", p->pc+4, pool.size, pool.start);
+				print("note: flush literal pool at %#llux: len=%lld ref=%llx\n", p->pc+4, pool.size, pool.start);
 			q = prg();
 			q->as = AB;
 			q->to.type = D_BRANCH;
@@ -183,12 +183,12 @@
 			q->link = blitrl;
 			blitrl = q;
 		}
-		else if(p->pc+pool.size-pool.start < 1024*1024)
+		else if(p->pc+pool.size-pool.start < 0x100000)
 			return;
 		elitrl->link = p->link;
 		p->link = blitrl;
-		blitrl = 0;	/* BUG: should refer back to values until out-of-range */
-		elitrl = 0;
+		blitrl = P;	/* BUG: should refer back to values until out-of-range */
+		elitrl = P;
 		pool.size = 0;
 		pool.start = 0;
 	}
@@ -319,10 +319,10 @@
 }
 
 static int
-ispcdisp(long v)
+ispcdisp(vlong v)
 {
-	/* pc-relative addressing will reach? */
-	return v >= -0xfffff && v <= 0xfffff && (v&3) == 0;
+	/* pc-relative addressing (using TBZ imm14) will reach? */
+	return v >= -0x7fff && v <= 0x7fff && (v&3) == 0;
 }
 
 static int