Compare commits

..

2 Commits

Author SHA1 Message Date
Quentin Carbonneaux
bef981e9a1 no cmpneg() for float comparisons 2026-04-29 15:04:27 +02:00
Quentin Carbonneaux
0454fa259b arm64: fix unordered fp comparisons 2026-04-29 13:37:22 +02:00
3 changed files with 23 additions and 23 deletions

View File

@ -710,7 +710,7 @@ amd64_sysv_emitfn(Fn *fn, FILE *f)
default: default:
c = b->jmp.type - Jjf; c = b->jmp.type - Jjf;
if (0 <= c && c <= NCmp) { if (0 <= c && c <= NCmp) {
if (b->link == b->s2) { if (b->link == b->s2 || c >= NCmpI) {
s = b->s1; s = b->s1;
b->s1 = b->s2; b->s1 = b->s2;
b->s2 = s; b->s2 = s;
@ -827,7 +827,7 @@ amd64_winabi_emitfn(Fn *fn, FILE *f)
default: default:
c = b->jmp.type - Jjf; c = b->jmp.type - Jjf;
if (0 <= c && c <= NCmp) { if (0 <= c && c <= NCmp) {
if (b->link == b->s2) { if (b->link == b->s2 || c >= NCmpI) {
s = b->s1; s = b->s1;
b->s1 = b->s2; b->s1 = b->s2;
b->s2 = s; b->s2 = s;

View File

@ -660,7 +660,7 @@ arm64_emitfn(Fn *fn, FILE *out)
c = b->jmp.type - Jjf; c = b->jmp.type - Jjf;
if (c < 0 || c > NCmp) if (c < 0 || c > NCmp)
die("unhandled jump %d", b->jmp.type); die("unhandled jump %d", b->jmp.type);
if (b->link == b->s2) { if (b->link == b->s2 || c >= NCmpI) {
t = b->s1; t = b->s1;
b->s1 = b->s2; b->s1 = b->s2;
b->s2 = t; b->s2 = t;

40
util.c
View File

@ -343,31 +343,31 @@ icpy(Ins *d, Ins *s, ulong n)
} }
static int cmptab[][2] ={ static int cmptab[][2] ={
/* negation swap */ /* negation swap */
[Ciule] = {Ciugt, Ciuge}, [Ciule] = {Ciugt, Ciuge},
[Ciult] = {Ciuge, Ciugt}, [Ciult] = {Ciuge, Ciugt},
[Ciugt] = {Ciule, Ciult}, [Ciugt] = {Ciule, Ciult},
[Ciuge] = {Ciult, Ciule}, [Ciuge] = {Ciult, Ciule},
[Cisle] = {Cisgt, Cisge}, [Cisle] = {Cisgt, Cisge},
[Cislt] = {Cisge, Cisgt}, [Cislt] = {Cisge, Cisgt},
[Cisgt] = {Cisle, Cislt}, [Cisgt] = {Cisle, Cislt},
[Cisge] = {Cislt, Cisle}, [Cisge] = {Cislt, Cisle},
[Cieq] = {Cine, Cieq}, [Cieq] = {Cine, Cieq},
[Cine] = {Cieq, Cine}, [Cine] = {Cieq, Cine},
[NCmpI+Cfle] = {NCmpI+Cfgt, NCmpI+Cfge}, [NCmpI+Cfle] = {-1, NCmpI+Cfge},
[NCmpI+Cflt] = {NCmpI+Cfge, NCmpI+Cfgt}, [NCmpI+Cflt] = {-1, NCmpI+Cfgt},
[NCmpI+Cfgt] = {NCmpI+Cfle, NCmpI+Cflt}, [NCmpI+Cfgt] = {-1, NCmpI+Cflt},
[NCmpI+Cfge] = {NCmpI+Cflt, NCmpI+Cfle}, [NCmpI+Cfge] = {-1, NCmpI+Cfle},
[NCmpI+Cfeq] = {NCmpI+Cfne, NCmpI+Cfeq}, [NCmpI+Cfeq] = {-1, NCmpI+Cfeq},
[NCmpI+Cfne] = {NCmpI+Cfeq, NCmpI+Cfne}, [NCmpI+Cfne] = {-1, NCmpI+Cfne},
[NCmpI+Cfo] = {NCmpI+Cfuo, NCmpI+Cfo}, [NCmpI+Cfo] = {-1, NCmpI+Cfo},
[NCmpI+Cfuo] = {NCmpI+Cfo, NCmpI+Cfuo}, [NCmpI+Cfuo] = {-1, NCmpI+Cfuo},
}; };
int int
cmpneg(int c) cmpneg(int c)
{ {
assert(0 <= c && c < NCmp); assert(0 <= c && c < NCmpI);
return cmptab[c][0]; return cmptab[c][0];
} }