ref: 56d1f1bccd4f943b43e5b8043dd63a17ceb2b2b1
parent: ef16012a85da92aa8e7fdb7890e2f7a88364c9bd
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Feb 13 10:31:03 EST 2016
Save regs correctly around rep movs
--- a/6/insns.def
+++ b/6/insns.def
@@ -55,22 +55,22 @@
"\trep movsb\n",
"\tREP; MOVSB\n",
Use(.r={Rrcx,Rrsi,Rrdi}),
- Def(None))
+ Def(.r={Rrcx,Rrsi,Rrdi}))
Insn(Irepmovsw,
"\trep movsw\n",
"\tREP; MOVSW\n",
Use(.r={Rrcx,Rrsi,Rrdi}),
- Def(None))
+ Def(.r={Rrcx,Rrsi,Rrdi}))
Insn(Irepmovsl,
"\trep movsl\n",
"\tREP; MOVSL\n",
Use(.r={Rrcx,Rrsi,Rrdi}),
- Def(None))
+ Def(.r={Rrcx,Rrsi,Rrdi}))
Insn(Irepmovsq,
"\trep movsq\n",
"\tREP; MOVSQ\n",
Use(.r={Rrcx,Rrsi,Rrdi}),
- Def(None))
+ 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,6 +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; /* pointers to src, dst */
Loc *sp, *dp, *len; /* pointers to src, dst */
Loc *tmp, *src, *dst; /* source memory, dst memory */
@@ -429,7 +430,13 @@
}
}
} else {
+ savsi = locreg(ModeQ);
+ savdi = locreg(ModeQ);
+ savcx = locreg(ModeQ);
len = loclit(sz, ModeQ);
+ g(s, Imov, locphysreg(Rrsi), savsi);
+ g(s, Imov, locphysreg(Rrdi), savdi);
+ g(s, Imov, locphysreg(Rrcx), savcx);
sp = newr(s, from);
dp = newr(s, to);
@@ -446,6 +453,9 @@
else
g(s, Imov, dp, locphysreg(Rrdi), NULL);
g(s, Irepmovsb, NULL);
+ g(s, Imov, savsi, locphysreg(Rrsi));
+ g(s, Imov, savdi, locphysreg(Rrdi));
+ g(s, Imov, savcx, locphysreg(Rrcx));
}
}