Compare commits

..

11 Commits

Author SHA1 Message Date
Quentin Carbonneaux
ac79f8fd02 mcf comments 2026-05-01 19:44:44 +02:00
Quentin Carbonneaux
84516c7484 relax assert in emitcon 2026-05-01 19:40:10 +02:00
Quentin Carbonneaux
f36c06c3ee rework docs 2026-04-29 11:22:19 +02:00
Quentin Carbonneaux
8c16de02ed rv64: got-free addresses for SGlo 2026-04-29 10:54:26 +02:00
Quentin Carbonneaux
63bb04f759 more fixes 2026-04-29 10:15:11 +02:00
Quentin Carbonneaux
6abea36b9b nits 2026-04-28 16:48:43 +02:00
Quentin Carbonneaux
b8b95a99df asserts in emitcon() 2026-04-28 16:23:47 +02:00
Quentin Carbonneaux
a9796317aa apple tls is global 2026-04-28 16:11:47 +02:00
Quentin Carbonneaux
5ac78c67c9 nits 2026-04-28 16:01:48 +02:00
Quentin Carbonneaux
fee64f4341 mcf review 2026-04-28 14:16:34 +02:00
Quentin Carbonneaux
7ab2fbe07c extern DYNCONST 2026-04-27 18:42:35 +02:00
4 changed files with 64 additions and 59 deletions

1
all.h
View File

@ -502,6 +502,7 @@ void emiti(Ins);
void idup(Blk *, Ins *, ulong);
Ins *icpy(Ins *, Ins *, ulong);
int cmpop(int);
int cmpneg(int);
int cmpwlneg(int);
int clsmerge(short *, short);
int phicls(int, Tmp *);

View File

@ -22,8 +22,8 @@ struct E {
X(Ciuge, "ae", "b") \
X(Cieq, "z", "nz") \
X(Cine, "nz", "z") \
X(NCmpI+Cfle, "?" , "?") \
X(NCmpI+Cflt, "?", "?") \
X(NCmpI+Cfle, "be", "a") \
X(NCmpI+Cflt, "b", "ae") \
X(NCmpI+Cfgt, "a", "be") \
X(NCmpI+Cfge, "ae", "b") \
X(NCmpI+Cfo, "np", "p") \
@ -660,8 +660,8 @@ sysv_framesz(E *e)
void
amd64_sysv_emitfn(Fn *fn, FILE *f)
{
static char *ctoa[][2] = {
#define X(c, s, n) [c] = {s, n},
static char *ctoa[] = {
#define X(c, s, _) [c] = s,
CMP(X)
#undef X
};
@ -747,10 +747,9 @@ amd64_sysv_emitfn(Fn *fn, FILE *f)
s = b->s1;
b->s1 = b->s2;
b->s2 = s;
n = 0;
} else
n = 1;
fprintf(f, "\tj%s %sbb%d\n", ctoa[c][n],
c = cmpneg(c);
fprintf(f, "\tj%s %sbb%d\n", ctoa[c],
T.asloc, id0+b->s2->id);
goto Jmp;
}
@ -786,15 +785,15 @@ winabi_framesz(E *e)
void
amd64_winabi_emitfn(Fn *fn, FILE *f)
{
static char *ctoa[][2] = {
#define X(c, s, n) [c] = {s, n},
static char *ctoa[] = {
#define X(c, s, _) [c] = s,
CMP(X)
#undef X
};
static int id0;
Blk *b, *s;
Ins *i, itmp;
int *r, c, n, lbl;
int *r, c, lbl;
E *e;
e = &(E){.f = f, .fn = fn};
@ -861,14 +860,13 @@ amd64_winabi_emitfn(Fn *fn, FILE *f)
default:
c = b->jmp.type - Jjf;
if (0 <= c && c <= NCmp) {
if (b->link == b->s2 || c >= NCmpI) {
if (b->link == b->s2) {
s = b->s1;
b->s1 = b->s2;
b->s2 = s;
n = 0;
} else
n = 1;
fprintf(f, "\tj%s %sbb%d\n", ctoa[c][n],
c = cmpneg(c);
fprintf(f, "\tj%s %sbb%d\n", ctoa[c],
T.asloc, id0+b->s2->id);
goto Jmp;
}

View File

@ -10,24 +10,24 @@ struct E {
};
#define CMP(X) \
X(Cieq, "eq", "ne") \
X(Cine, "ne", "eq") \
X(Cisge, "ge", "lt") \
X(Cisgt, "gt", "le") \
X(Cisle, "le", "gt") \
X(Cislt, "lt", "ge") \
X(Ciuge, "cs", "cc") \
X(Ciugt, "hi", "ls") \
X(Ciule, "ls", "hi") \
X(Ciult, "cc", "cs") \
X(NCmpI+Cfeq, "eq", "ne") \
X(NCmpI+Cfge, "ge", "lt") \
X(NCmpI+Cfgt, "gt", "le") \
X(NCmpI+Cfle, "ls", "hi") \
X(NCmpI+Cflt, "mi", "pl") \
X(NCmpI+Cfne, "ne", "eq") \
X(NCmpI+Cfo, "vc", "vs") \
X(NCmpI+Cfuo, "vs", "vc")
X(Cieq, "eq") \
X(Cine, "ne") \
X(Cisge, "ge") \
X(Cisgt, "gt") \
X(Cisle, "le") \
X(Cislt, "lt") \
X(Ciuge, "cs") \
X(Ciugt, "hi") \
X(Ciule, "ls") \
X(Ciult, "cc") \
X(NCmpI+Cfeq, "eq") \
X(NCmpI+Cfge, "ge") \
X(NCmpI+Cfgt, "gt") \
X(NCmpI+Cfle, "ls") \
X(NCmpI+Cflt, "mi") \
X(NCmpI+Cfne, "ne") \
X(NCmpI+Cfo, "vc") \
X(NCmpI+Cfuo, "vs")
enum {
Ki = -1, /* matches Kw and Kl */
@ -102,7 +102,7 @@ static struct {
{ Oacmn, Ki, "cmn %0, %1" },
{ Oafcmp, Ka, "fcmpe %0, %1" },
#define X(c, str, _) \
#define X(c, str) \
{ Oflag+c, Ki, "cset %=, " str },
CMP(X)
#undef X
@ -544,8 +544,8 @@ framelayout(E *e)
void
arm64_emitfn(Fn *fn, FILE *out)
{
static char *ctoa[][2] = {
#define X(c, s, n) [c] = {s, n},
static char *ctoa[] = {
#define X(c, s) [c] = s,
CMP(X)
#undef X
};
@ -676,12 +676,11 @@ arm64_emitfn(Fn *fn, FILE *out)
t = b->s1;
b->s1 = b->s2;
b->s2 = t;
n = 0;
} else
n = 1;
c = cmpneg(c);
fprintf(e->f,
"\tb%s\t%s%d\n",
ctoa[c][n], T.asloc, id0+b->s2->id
ctoa[c], T.asloc, id0+b->s2->id
);
goto Jmp;
}

49
util.c
View File

@ -343,27 +343,34 @@ icpy(Ins *d, Ins *s, ulong n)
}
static int cmptab[][2] ={
/* negation swap */
[Ciule] = {Ciugt, Ciuge},
[Ciult] = {Ciuge, Ciugt},
[Ciugt] = {Ciule, Ciult},
[Ciuge] = {Ciult, Ciule},
[Cisle] = {Cisgt, Cisge},
[Cislt] = {Cisge, Cisgt},
[Cisgt] = {Cisle, Cislt},
[Cisge] = {Cislt, Cisle},
[Cieq] = {Cine, Cieq},
[Cine] = {Cieq, Cine},
[NCmpI+Cfle] = {-1, NCmpI+Cfge},
[NCmpI+Cflt] = {-1, NCmpI+Cfgt},
[NCmpI+Cfgt] = {-1, NCmpI+Cflt},
[NCmpI+Cfge] = {-1, NCmpI+Cfle},
[NCmpI+Cfeq] = {-1, NCmpI+Cfeq},
[NCmpI+Cfne] = {-1, NCmpI+Cfne},
[NCmpI+Cfo] = {-1, NCmpI+Cfo},
[NCmpI+Cfuo] = {-1, NCmpI+Cfuo},
/* negation swap */
[Ciule] = {Ciugt, Ciuge},
[Ciult] = {Ciuge, Ciugt},
[Ciugt] = {Ciule, Ciult},
[Ciuge] = {Ciult, Ciule},
[Cisle] = {Cisgt, Cisge},
[Cislt] = {Cisge, Cisgt},
[Cisgt] = {Cisle, Cislt},
[Cisge] = {Cislt, Cisle},
[Cieq] = {Cine, Cieq},
[Cine] = {Cieq, Cine},
[NCmpI+Cfle] = {NCmpI+Cfgt, NCmpI+Cfge},
[NCmpI+Cflt] = {NCmpI+Cfge, NCmpI+Cfgt},
[NCmpI+Cfgt] = {NCmpI+Cfle, NCmpI+Cflt},
[NCmpI+Cfge] = {NCmpI+Cflt, NCmpI+Cfle},
[NCmpI+Cfeq] = {NCmpI+Cfne, NCmpI+Cfeq},
[NCmpI+Cfne] = {NCmpI+Cfeq, NCmpI+Cfne},
[NCmpI+Cfo] = {NCmpI+Cfuo, NCmpI+Cfo},
[NCmpI+Cfuo] = {NCmpI+Cfo, NCmpI+Cfuo},
};
int
cmpneg(int c)
{
assert(0 <= c && c < NCmp);
return cmptab[c][0];
}
int
cmpop(int c)
{
@ -375,9 +382,9 @@ int
cmpwlneg(int op)
{
if (INRANGE(op, Ocmpw, Ocmpw1))
return cmptab[op - Ocmpw][0] + Ocmpw;
return cmpneg(op - Ocmpw) + Ocmpw;
if (INRANGE(op, Ocmpl, Ocmpl1))
return cmptab[op - Ocmpl][0] + Ocmpl;
return cmpneg(op - Ocmpl) + Ocmpl;
die("not a wl comparison");
}