shithub: mc

Download patch

ref: 5bd859be6d2246db8a5ce28f2dbc25724590cb6f
parent: 49570fb00b851ce47c9b8d5280284cc44490e0e9
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Feb 13 11:25:00 EST 2016

Eliminate special case instructions.

    They're used rarely, and are clunky. If your types are big enough
    that you need to blit them regularly, just use memops code.

--- a/6/insns.def
+++ b/6/insns.def
@@ -46,31 +46,6 @@
     "\tMOV%1T%2TSX %X,%X\n",
     Use(.l={1}),
     Def(.l={2}))
-Insn(Irepstosb,
-    "\trep stosb\n",
-    "\tREP; STOSB\n",
-    Use(.r={Rrax,Rrcx,Rrsi,Rrdi}),
-    Def(.r={Rrax,Rrcx,Rrsi,Rrdi}))
-Insn(Irepmovsb,
-    "\trep movsb\n",
-    "\tREP; MOVSB\n",
-    Use(.r={Rrcx,Rrsi,Rrdi}),
-    Def(.r={Rrcx,Rrsi,Rrdi}))
-Insn(Irepmovsw,
-    "\trep movsw\n",
-    "\tREP; MOVSW\n",
-    Use(.r={Rrcx,Rrsi,Rrdi}),
-    Def(.r={Rrcx,Rrsi,Rrdi}))
-Insn(Irepmovsl,
-    "\trep movsl\n",
-    "\tREP; MOVSL\n",
-    Use(.r={Rrcx,Rrsi,Rrdi}),
-    Def(.r={Rrcx,Rrsi,Rrdi}))
-Insn(Irepmovsq,
-    "\trep movsq\n",
-    "\tREP; MOVSQ\n",
-    Use(.r={Rrcx,Rrsi,Rrdi}),
-    Def(.r={Rrcx,Rrsi,Rrdi}))
 Insn(Ilea,
     "\tlea%2t %m,%r\n",
     "\tLEA%2T %M,%R\n",
--- a/6/isel.c
+++ b/6/isel.c
@@ -405,8 +405,7 @@
 static void blit(Isel *s, Loc *to, Loc *from, size_t dstoff, size_t srcoff, size_t sz, size_t align)
 {
 	size_t i, modesz;
-	Loc *savsi, *savdi, *savcx; /* save the whales.. er, registers */
-	Loc *sp, *dp, *len; /* pointers to src, dst */
+	Loc *sp, *dp; /* pointers to src, dst */
 	Loc *tmp, *src, *dst; /* source memory, dst memory */
 
 	assert(szmodes[align] != ModeNone);   /* make sure we have a valid alignment */
@@ -418,45 +417,15 @@
 	i = 0;
 	if (align == 0)
 		align = 8;
-	if (sz <= 512) { /* arbitrary threshold; should be tuned */
-		for (modesz = align; szmodes[modesz] != ModeNone; modesz /= 2) {
-			tmp = locreg(szmodes[modesz]);
-			while (i + modesz <= sz) {
-				src = locmem(i + srcoff, sp, NULL, szmodes[modesz]);
-				dst = locmem(i + dstoff, dp, NULL, szmodes[modesz]);
-				g(s, Imov, src, tmp, NULL);
-				g(s, Imov, tmp, dst, NULL);
-				i += modesz;
-			}
+	for (modesz = align; szmodes[modesz] != ModeNone; modesz /= 2) {
+		tmp = locreg(szmodes[modesz]);
+		while (i + modesz <= sz) {
+			src = locmem(i + srcoff, sp, NULL, szmodes[modesz]);
+			dst = locmem(i + dstoff, dp, NULL, szmodes[modesz]);
+			g(s, Imov, src, tmp, NULL);
+			g(s, Imov, tmp, dst, NULL);
+			i += modesz;
 		}
-	} else {
-		savsi = locreg(ModeQ);
-		savdi = locreg(ModeQ);
-		savcx = locreg(ModeQ);
-		g(s, Imov, locphysreg(Rrsi), savsi, NULL);
-		g(s, Imov, locphysreg(Rrdi), savdi, NULL);
-		g(s, Imov, locphysreg(Rrcx), savcx, NULL);
-
-		len = loclit(sz, ModeQ);
-		sp = newr(s, from);
-		dp = newr(s, to);
-
-		/* length to blit */
-		g(s, Imov, len, locphysreg(Rrcx), NULL);
-		/* source address with offset */
-		if (srcoff)
-			g(s, Ilea, locmem(srcoff, sp, NULL, ModeQ), locphysreg(Rrsi), NULL);
-		else
-			g(s, Imov, sp, locphysreg(Rrsi), NULL);
-		/* dest address with offset */
-		if (dstoff)
-			g(s, Ilea, locmem(dstoff, dp, NULL, ModeQ), locphysreg(Rrdi), NULL);
-		else
-			g(s, Imov, dp, locphysreg(Rrdi), NULL);
-		g(s, Irepmovsb, NULL);
-		g(s, Imov, savsi, locphysreg(Rrsi), NULL);
-		g(s, Imov, savdi, locphysreg(Rrdi), NULL);
-		g(s, Imov, savcx, locphysreg(Rrcx), NULL);
 	}
 
 }
@@ -463,44 +432,21 @@
 
 static void clear(Isel *s, Loc *val, size_t sz, size_t align)
 {
-	Loc *savsi, *savdi, *savcx; /* save the whales.. er, registers */
-	Loc *dp, *len, *rax; /* pointers to src, dst */
-	Loc *zero, *dst; /* source memory, dst memory */
+	Loc *dp, *zero, *dst; /* source memory, dst memory */
 	size_t modesz, i;
 
 	i = 0;
 	dp = inr(s, val);
-	rax = locphysreg(Rrax);
-	g(s, Ixor,  rax, rax, NULL);
 	if (align == 0)
 		align = 8;
-	if (sz <= 128) { /* arbitrary threshold; should be tuned */
-		for (modesz = align; szmodes[modesz] != ModeNone; modesz /= 2) {
-			zero = loclit(0, szmodes[modesz]);
-			while (i + modesz <= sz) {
-				zero = coreg(Rrax, szmodes[modesz]);
-				dst = locmem(i, dp, NULL, szmodes[modesz]);
-				g(s, Imov, zero, dst, NULL);
-				i += modesz;
-			}
+	for (modesz = align; szmodes[modesz] != ModeNone; modesz /= 2) {
+		zero = locreg(szmodes[modesz]);
+		g(s, Ixor, zero, zero, NULL);
+		while (i + modesz <= sz) {
+			dst = locmem(i, dp, NULL, szmodes[modesz]);
+			g(s, Imov, zero, dst, NULL);
+			i += modesz;
 		}
-	} else {
-		savsi = locreg(ModeQ);
-		savdi = locreg(ModeQ);
-		savcx = locreg(ModeQ);
-		g(s, Imov, locphysreg(Rrsi), savsi, NULL);
-		g(s, Imov, locphysreg(Rrdi), savdi, NULL);
-		g(s, Imov, locphysreg(Rrcx), savcx, NULL);
-
-		len = loclit(sz, ModeQ);
-		/* length to blit */
-		g(s, Imov, len, locphysreg(Rrcx), NULL);
-		g(s, Imov, dp, locphysreg(Rrdi), NULL);
-		g(s, Irepstosb, NULL);
-
-		g(s, Imov, savsi, locphysreg(Rrsi), NULL);
-		g(s, Imov, savdi, locphysreg(Rrdi), NULL);
-		g(s, Imov, savcx, locphysreg(Rrcx), NULL);
 	}
 }