aboutsummaryrefslogtreecommitdiff
path: root/amd64/emit.c
diff options
context:
space:
mode:
authorRoland Paterson-Jones <[email protected]>2024-10-23 14:51:53 +0200
committerQuentin Carbonneaux <[email protected]>2026-01-13 18:11:30 +0100
commit5c1eb24e2c312021c7af4316e5adde53e270311a (patch)
treee661a5d0c58d58c0f7fb8fc84dba575a800cc646 /amd64/emit.c
parent72010791374d3be2ab21ee5ca1146fce2382d88b (diff)
If-conversion RFC 4 - x86 only (for now), use cmovXX
Replacement of tiny conditional jump graphlets with conditional move instructions. Currently enabled only for x86. Arm64 support using cselXX will be essentially identical. Adds (internal) frontend sel0/sel1 ops with flag-specific backend xselXX following jnz implementation pattern. Testing: standard QBE, cproc, harec, hare, roland
Diffstat (limited to 'amd64/emit.c')
-rw-r--r--amd64/emit.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/amd64/emit.c b/amd64/emit.c
index 6cf37ec..7290a80 100644
--- a/amd64/emit.c
+++ b/amd64/emit.c
@@ -576,6 +576,43 @@ emitins(Ins i, E *e)
case Odbgloc:
emitdbgloc(i.arg[0].val, i.arg[1].val, e->f);
break;
+ case Oxselieq:
+ case Oxseline:
+ case Oxselisge:
+ case Oxselisgt:
+ case Oxselisle:
+ case Oxselislt:
+ case Oxseliuge:
+ case Oxseliugt:
+ case Oxseliule:
+ case Oxseliult:
+ case Oxselfeq:
+ case Oxselfge:
+ case Oxselfgt:
+ case Oxselfle:
+ case Oxselflt:
+ case Oxselfne:
+ case Oxselfo:
+ case Oxselfuo:
+ {
+ // TODO - how to do this "properly"?
+ static char *F0[] = {
+ "z", "nz", "ge", "g", "le", "l", "ae", "a", "be", "b",
+ "nz", "ae", "a", "be", "b", "nz", "p", "np"
+ };
+ static char *F1[] = {
+ "nz", "z", "l", "le", "g", "ge", "b", "be", "a", "ae",
+ "z", "b", "be", "a", "ae", "z", "p", "np"
+ };
+ char ins[16];
+ sprintf(ins, "cmov%s %%1, %%=", F1[i.op-Oxselieq]);
+ if (req(i.to, i.arg[1]))
+ sprintf(ins, "cmov%s %%0, %%=", F0[i.op-Oxselieq]);
+ else if (!req(i.to, i.arg[0]))
+ emitf("mov %0, %=", &i, e);
+ emitf(ins, &i, e);
+ break;
+ }
}
}