ref: 156c048f0239b99b870cf1694c6886e39b85ae09
parent: d68cb921e334d6fd802d6ae93398d6324cb784ff
author: Ori Bernstein <[email protected]>
date: Sat Jul 11 16:27:26 EDT 2020
Fix tests on BSDs and 9front, improve names.
--- a/6/asm.h
+++ b/6/asm.h
@@ -54,13 +54,15 @@
typedef enum {
ArgVoid,
- ArgReg, /* Either int or flt, depending on Loc* type */
- ArgSmallAggr_Int,
- ArgSmallAggr_Flt,
- ArgSmallAggr_Int_Int,
- ArgSmallAggr_Flt_Int,
- ArgSmallAggr_Int_Flt,
- ArgSmallAggr_Flt_Flt,
+ /* Either int or flt, depending on Loc* type */
+ ArgReg,
+ /* Small aggregates packed into registers */
+ ArgAggrI,
+ ArgAggrF,
+ ArgAggrII,
+ ArgAggrFI,
+ ArgAggrIF,
+ ArgAggrFF,
ArgBig,
} ArgType;
--- a/6/isel.c
+++ b/6/isel.c
@@ -611,34 +611,18 @@
static int
sufficientregs(ArgType a, size_t nfloats, size_t nints)
{
- size_t needed_ints = 0;
- size_t needed_flts = 0;
+ static const struct {
+ int ireg;
+ int freg;
+ } needed[] = {
+ [ArgAggrI] = {1, 0},
+ [ArgAggrFI] = {1, 1},
+ [ArgAggrIF] = {1, 1},
+ [ArgAggrII] = {2, 0},
+ [ArgAggrFF] = {0, 2},
+ };
- switch(a) {
- case ArgSmallAggr_Int:
- case ArgSmallAggr_Flt_Int:
- case ArgSmallAggr_Int_Flt:
- needed_ints = 1;
- break;
- case ArgSmallAggr_Int_Int:
- needed_ints = 2;
- break;
- default: break;
- }
-
- switch(a) {
- case ArgSmallAggr_Flt:
- case ArgSmallAggr_Flt_Int:
- case ArgSmallAggr_Int_Flt:
- needed_flts = 1;
- break;
- case ArgSmallAggr_Flt_Flt:
- needed_flts = 2;
- break;
- default: break;
- }
-
- return (needed_flts + nfloats <= Nfloatregargs) && (needed_ints + nints <= Nintregargs);
+ return (needed[a].freg + nfloats <= Nfloatregargs) && (needed[a].ireg + nints <= Nintregargs);
}
static Loc *
@@ -661,7 +645,7 @@
size_t nfloats, nints;
Loc *retloc1, *retloc2, *rsp; /* hard-coded registers */
Loc *ret;
- size_t nextintretreg = 0, nextfltretreg = 0;
+ size_t ri, rf;
Loc *stkbump; /* calculated stack offset */
Type *t, *fn;
Node **args;
@@ -673,6 +657,8 @@
rsp = locphysreg(Rrsp);
t = exprtype(n);
+ ri = 0;
+ rf = 0;
retloc1 = NULL;
retloc2 = NULL;
rettype = classify(t);
@@ -682,33 +668,29 @@
case ArgBig:
break;
case ArgReg:
- if (istyfloat(t)) {
- retloc1 = coreg(Rxmm0d, mode(n));
- } else {
- retloc1 = coreg(Rrax, mode(n));
- }
+ retloc1 = coreg((istyfloat(t)) ? Rxmm0d : Rrax, mode(n));
break;
- case ArgSmallAggr_Int:
- retloc1 = coreg(intretregs[nextintretreg++], tymodepart(t, 0, 0));
+ case ArgAggrI:
+ retloc1 = coreg(intretregs[ri++], tymodepart(t, 0, 0));
break;
- case ArgSmallAggr_Flt:
- retloc1 = coreg(fltretregs[nextfltretreg++], tymodepart(t, 1, 0));
+ case ArgAggrF:
+ retloc1 = coreg(fltretregs[rf++], tymodepart(t, 1, 0));
break;
- case ArgSmallAggr_Int_Int:
- retloc1 = coreg(intretregs[nextintretreg++], tymodepart(t, 0, 0));
- retloc2 = coreg(intretregs[nextintretreg++], tymodepart(t, 0, 8));
+ case ArgAggrII:
+ retloc1 = coreg(intretregs[ri++], tymodepart(t, 0, 0));
+ retloc2 = coreg(intretregs[ri++], tymodepart(t, 0, 8));
break;
- case ArgSmallAggr_Int_Flt:
- retloc1 = coreg(intretregs[nextintretreg++], tymodepart(t, 0, 0));
- retloc2 = coreg(fltretregs[nextfltretreg++], tymodepart(t, 1, 8));
+ case ArgAggrIF:
+ retloc1 = coreg(intretregs[ri++], tymodepart(t, 0, 0));
+ retloc2 = coreg(fltretregs[rf++], tymodepart(t, 1, 8));
break;
- case ArgSmallAggr_Flt_Int:
- retloc1 = coreg(fltretregs[nextfltretreg++], tymodepart(t, 1, 0));
- retloc2 = coreg(intretregs[nextintretreg++], tymodepart(t, 0, 8));
+ case ArgAggrFI:
+ retloc1 = coreg(fltretregs[rf++], tymodepart(t, 1, 0));
+ retloc2 = coreg(intretregs[ri++], tymodepart(t, 0, 8));
break;
- case ArgSmallAggr_Flt_Flt:
- retloc1 = coreg(fltretregs[nextfltretreg++], tymodepart(t, 1, 0));
- retloc2 = coreg(fltretregs[nextfltretreg++], tymodepart(t, 1, 8));
+ case ArgAggrFF:
+ retloc1 = coreg(fltretregs[rf++], tymodepart(t, 1, 0));
+ retloc2 = coreg(fltretregs[rf++], tymodepart(t, 1, 8));
break;
}
@@ -785,25 +767,25 @@
/* placearg can figure this out */
placearg(s, args[i], arg, PassInNoPref, rsp, vararg, &nfloats, &nints, &argoff);
break;
- case ArgSmallAggr_Int:
+ case ArgAggrI:
placearg(s, args[i], arg, PassInInt, rsp, vararg, &nfloats, &nints, &argoff);
break;
- case ArgSmallAggr_Flt:
+ case ArgAggrF:
placearg(s, args[i], arg, PassInSSE, rsp, vararg, &nfloats, &nints, &argoff);
break;
- case ArgSmallAggr_Int_Int:
+ case ArgAggrII:
placearg(s, args[i], arg , PassInInt, rsp, vararg, &nfloats, &nints, &argoff);
placearg(s, args[i], plus8(s, arg), PassInInt, rsp, vararg, &nfloats, &nints, &argoff);
break;
- case ArgSmallAggr_Int_Flt:
+ case ArgAggrIF:
placearg(s, args[i], arg , PassInInt, rsp, vararg, &nfloats, &nints, &argoff);
placearg(s, args[i], plus8(s, arg), PassInSSE, rsp, vararg, &nfloats, &nints, &argoff);
break;
- case ArgSmallAggr_Flt_Int:
+ case ArgAggrFI:
placearg(s, args[i], arg , PassInSSE, rsp, vararg, &nfloats, &nints, &argoff);
placearg(s, args[i], plus8(s, arg), PassInInt, rsp, vararg, &nfloats, &nints, &argoff);
break;
- case ArgSmallAggr_Flt_Flt:
+ case ArgAggrFF:
placearg(s, args[i], arg , PassInSSE, rsp, vararg, &nfloats, &nints, &argoff);
placearg(s, args[i], plus8(s, arg), PassInSSE, rsp, vararg, &nfloats, &nints, &argoff);
break;
@@ -830,25 +812,25 @@
else
g(s, Imov, retloc1, ret, NULL);
break;
- case ArgSmallAggr_Int:
+ case ArgAggrI:
g(s, Imov, retloc1, locmem(0, inri(s, selexpr(s, retnode)), NULL, ModeQ), NULL);
break;
- case ArgSmallAggr_Flt:
+ case ArgAggrF:
g(s, Imovs, retloc1, locmem(0, inri(s, selexpr(s, retnode)), NULL, ModeD), NULL);
break;
- case ArgSmallAggr_Int_Int:
+ case ArgAggrII:
g(s, Imov, retloc1, locmem(0, inri(s, selexpr(s, retnode)), NULL, ModeQ), NULL);
g(s, Imov, retloc2, locmem(8, inri(s, selexpr(s, retnode)), NULL, ModeQ), NULL);
break;
- case ArgSmallAggr_Int_Flt:
+ case ArgAggrIF:
g(s, Imov, retloc1, locmem(0, inri(s, selexpr(s, retnode)), NULL, ModeQ), NULL);
g(s, Imovs, retloc2, locmem(8, inri(s, selexpr(s, retnode)), NULL, ModeD), NULL);
break;
- case ArgSmallAggr_Flt_Int:
+ case ArgAggrFI:
g(s, Imovs, retloc1, locmem(0, inri(s, selexpr(s, retnode)), NULL, ModeD), NULL);
g(s, Imov, retloc2, locmem(8, inri(s, selexpr(s, retnode)), NULL, ModeQ), NULL);
break;
- case ArgSmallAggr_Flt_Flt:
+ case ArgAggrFF:
g(s, Imovs, retloc1, locmem(0, inri(s, selexpr(s, retnode)), NULL, ModeD), NULL);
g(s, Imovs, retloc2, locmem(8, inri(s, selexpr(s, retnode)), NULL, ModeD), NULL);
break;
@@ -1307,30 +1289,30 @@
/* retrievearg can figure this out */
retrievearg(s, arg, vararg, &nfloats, &nints, &argoff);
break;
- case ArgSmallAggr_Int:
+ case ArgAggrI:
l = loc(s, arg);
movearg(s, l, PassInInt, ModeQ, &nfloats, &nints, &argoff);
break;
- case ArgSmallAggr_Flt:
+ case ArgAggrF:
l = loc(s, arg);
movearg(s, l, PassInSSE, ModeD, &nfloats, &nints, &argoff);
break;
- case ArgSmallAggr_Int_Int:
+ case ArgAggrII:
l = loc(s, arg);
movearg(s, l , PassInInt, ModeQ, &nfloats, &nints, &argoff);
movearg(s, plus8(s, l), PassInInt, ModeQ, &nfloats, &nints, &argoff);
break;
- case ArgSmallAggr_Int_Flt:
+ case ArgAggrIF:
l = loc(s, arg);
movearg(s, l , PassInInt, ModeQ, &nfloats, &nints, &argoff);
movearg(s, plus8(s, l), PassInSSE, ModeD, &nfloats, &nints, &argoff);
break;
- case ArgSmallAggr_Flt_Int:
+ case ArgAggrFI:
l = loc(s, arg);
movearg(s, l , PassInSSE, ModeD, &nfloats, &nints, &argoff);
movearg(s, plus8(s, l), PassInInt, ModeQ, &nfloats, &nints, &argoff);
break;
- case ArgSmallAggr_Flt_Flt:
+ case ArgAggrFF:
l = loc(s, arg);
movearg(s, l , PassInSSE, ModeD, &nfloats, &nints, &argoff);
movearg(s, plus8(s, l), PassInSSE, ModeD, &nfloats, &nints, &argoff);
@@ -1378,12 +1360,13 @@
Loc *rsp, *rbp;
Loc *ret;
size_t i;
- size_t nextintretreg = 0, nextfltretreg = 0;
+ size_t ri = 0, rf = 0;
rsp = locphysreg(Rrsp);
rbp = locphysreg(Rrbp);
switch (s->rettype) {
- case ArgVoid: break;
+ case ArgVoid:
+ break;
case ArgReg:
/* s->ret is a value, and will be returned that way */
ret = loc(s, s->ret);
@@ -1397,45 +1380,43 @@
ret = loc(s, s->ret);
g(s, Imov, ret, coreg(Rax, ret->mode), NULL);
break;
- case ArgSmallAggr_Int:
+ case ArgAggrI:
/* s->ret is an address, and will be returned as values */
ret = loc(s, s->ret);
- load(s, locmem(0, ret, NULL, ModeQ), coreg(intretregs[nextintretreg++], ModeQ));
+ load(s, locmem(0, ret, NULL, ModeQ), coreg(intretregs[ri++], ModeQ));
break;
- case ArgSmallAggr_Flt:
+ case ArgAggrF:
ret = loc(s, s->ret);
- load(s, locmem(0, ret, NULL, ModeD), coreg(fltretregs[nextfltretreg++], ModeD));
+ load(s, locmem(0, ret, NULL, ModeD), coreg(fltretregs[rf++], ModeD));
break;
- case ArgSmallAggr_Int_Int:
+ case ArgAggrII:
ret = loc(s, s->ret);
- load(s, locmem(0, ret, NULL, ModeQ), coreg(intretregs[nextintretreg++], ModeQ));
- load(s, locmem(8, ret, NULL, ModeQ), coreg(intretregs[nextintretreg++], ModeQ));
+ load(s, locmem(0, ret, NULL, ModeQ), coreg(intretregs[ri++], ModeQ));
+ load(s, locmem(8, ret, NULL, ModeQ), coreg(intretregs[ri++], ModeQ));
break;
- case ArgSmallAggr_Int_Flt:
+ case ArgAggrIF:
ret = loc(s, s->ret);
- load(s, locmem(0, ret, NULL, ModeQ), coreg(intretregs[nextintretreg++], ModeQ));
- load(s, locmem(8, ret, NULL, ModeD), coreg(fltretregs[nextfltretreg++], ModeD));
+ load(s, locmem(0, ret, NULL, ModeQ), coreg(intretregs[ri++], ModeQ));
+ load(s, locmem(8, ret, NULL, ModeD), coreg(fltretregs[rf++], ModeD));
break;
- case ArgSmallAggr_Flt_Int:
+ case ArgAggrFI:
ret = loc(s, s->ret);
- load(s, locmem(0, ret, NULL, ModeD), coreg(fltretregs[nextfltretreg++], ModeD));
- load(s, locmem(8, ret, NULL, ModeQ), coreg(intretregs[nextintretreg++], ModeQ));
+ load(s, locmem(0, ret, NULL, ModeD), coreg(fltretregs[rf++], ModeD));
+ load(s, locmem(8, ret, NULL, ModeQ), coreg(intretregs[ri++], ModeQ));
break;
- case ArgSmallAggr_Flt_Flt:
+ case ArgAggrFF:
ret = loc(s, s->ret);
- load(s, locmem(0, ret, NULL, ModeD), coreg(fltretregs[nextfltretreg++], ModeD));
- load(s, locmem(8, ret, NULL, ModeD), coreg(fltretregs[nextfltretreg++], ModeD));
+ load(s, locmem(0, ret, NULL, ModeD), coreg(fltretregs[rf++], ModeD));
+ load(s, locmem(8, ret, NULL, ModeD), coreg(fltretregs[rf++], ModeD));
break;
}
/* restore registers */
- for (i = 0; savedregs[i] != Rnone; i++) {
- if (isfloatmode(s->calleesave[i]->mode)) {
+ for (i = 0; savedregs[i] != Rnone; i++)
+ if (isfloatmode(s->calleesave[i]->mode))
g(s, Imovs, s->calleesave[i], locphysreg(savedregs[i]), NULL);
- } else {
+ else
g(s, Imov, s->calleesave[i], locphysreg(savedregs[i]), NULL);
- }
- }
/* leave function */
g(s, Imov, rbp, rsp, NULL);
g(s, Ipop, rbp, NULL);
@@ -1490,16 +1471,16 @@
case ArgBig:
/* No need for any extra space for this arg */
break;
- case ArgSmallAggr_Int:
- case ArgSmallAggr_Flt:
+ case ArgAggrI:
+ case ArgAggrF:
fn->stksz += 8;
fn->stksz = align(fn->stksz, min(8, Ptrsz));
htput(fn->stkoff, fn->args[i], itop(fn->stksz));
break;
- case ArgSmallAggr_Int_Int:
- case ArgSmallAggr_Int_Flt:
- case ArgSmallAggr_Flt_Int:
- case ArgSmallAggr_Flt_Flt:
+ case ArgAggrII:
+ case ArgAggrIF:
+ case ArgAggrFI:
+ case ArgAggrFF:
fn->stksz += 16;
fn->stksz = align(fn->stksz, min(16, Ptrsz));
htput(fn->stkoff, fn->args[i], itop(fn->stksz));
--- a/6/simp.c
+++ b/6/simp.c
@@ -1095,12 +1095,12 @@
case ArgVoid:
break;
case ArgBig:
- case ArgSmallAggr_Int:
- case ArgSmallAggr_Flt:
- case ArgSmallAggr_Int_Int:
- case ArgSmallAggr_Int_Flt:
- case ArgSmallAggr_Flt_Int:
- case ArgSmallAggr_Flt_Flt:
+ case ArgAggrI:
+ case ArgAggrF:
+ case ArgAggrII:
+ case ArgAggrIF:
+ case ArgAggrFI:
+ case ArgAggrFF:
lappend(&args, &nargs, addr(s, r, exprtype(n)));
break;
case ArgReg:
@@ -1252,16 +1252,16 @@
/*
* Compute and put the correct value into s->ret. In the case of ArgBig
* and ArgReg, exfiltrate the value from the function. In the case of
- * ArgSmallAggr_XYZ, put a pointer to the value where the function
+ * ArgAggr_XYZ, put a pointer to the value where the function
* epilogue can access it.
*/
switch (s->rettype) {
- case ArgSmallAggr_Int:
- case ArgSmallAggr_Flt:
- case ArgSmallAggr_Int_Int:
- case ArgSmallAggr_Int_Flt:
- case ArgSmallAggr_Flt_Int:
- case ArgSmallAggr_Flt_Flt:
+ case ArgAggrI:
+ case ArgAggrF:
+ case ArgAggrII:
+ case ArgAggrIF:
+ case ArgAggrFI:
+ case ArgAggrFF:
t = s->ret;
u = rval(s, args[0], NULL);
u = addr(s, u, exprtype(args[0]));
@@ -1412,12 +1412,12 @@
switch(s->rettype) {
case ArgVoid:
break;
- case ArgSmallAggr_Int:
- case ArgSmallAggr_Flt:
- case ArgSmallAggr_Int_Int:
- case ArgSmallAggr_Int_Flt:
- case ArgSmallAggr_Flt_Int:
- case ArgSmallAggr_Flt_Flt:
+ case ArgAggrI:
+ case ArgAggrF:
+ case ArgAggrII:
+ case ArgAggrIF:
+ case ArgAggrFI:
+ case ArgAggrFF:
s->ret = gentemp(f->loc, mktyptr(f->loc, ty), &dcl);
break;
case ArgBig:
--- a/6/typeinfo.c
+++ b/6/typeinfo.c
@@ -560,11 +560,11 @@
switch(pi[0]) {
case PassInInt:
if (sz <= 8) {
- return ArgSmallAggr_Int;
+ return ArgAggrI;
}
switch(pi[1]) {
- case PassInInt: return ArgSmallAggr_Int_Int;
- case PassInSSE: return ArgSmallAggr_Int_Flt;
+ case PassInInt: return ArgAggrII;
+ case PassInSSE: return ArgAggrIF;
default:
die("Impossible return from classify_recursive");
break;
@@ -572,11 +572,11 @@
break;
case PassInSSE:
if (sz <= 8) {
- return ArgSmallAggr_Flt;
+ return ArgAggrF;
}
switch(pi[1]) {
- case PassInInt: return ArgSmallAggr_Flt_Int;
- case PassInSSE: return ArgSmallAggr_Flt_Flt;
+ case PassInInt: return ArgAggrFI;
+ case PassInSSE: return ArgAggrFF;
default:
die("Impossible return from classify_recursive");
break;
--- a/configure
+++ b/configure
@@ -71,7 +71,8 @@
echo export INST_MAN=$prefix/man/man >> config.mk
echo 'const Sys = "FreeBSD"' >> mbld/config.myr
echo 'const Linkcmd = ["ld", "--gc-sections"]' >> mbld/config.myr
- echo 'const Dlflags : byte[:][:] = [][:]' >> mbld/config.myr
+ echo 'const Dlflags : byte[:][:] = ["-L/usr/lib", '\
+ '"-dynamic-linker", "/libexec/ld-elf.so.1"][:]' >> mbld/config.myr
echo "const Manpath = \"man/man\"" >> mbld/config.myr
;;
*NetBSD*)
@@ -87,8 +88,8 @@
echo export INST_MAN=$prefix/man/man >> config.mk
echo 'const Sys = "OpenBSD"' >> mbld/config.myr
echo 'const Linkcmd = ["ld", "-nopie", "--gc-sections"]' >> mbld/config.myr
- echo 'const Dlflags = ["-dynamic-linker",' \
- '"/usr/libexec/ld.so"]' >> mbld/config.myr
+ echo 'const Dlflags = ["-L/usr/lib",'\
+ '"-dynamic-linker", "/usr/libexec/ld.so"]' >> mbld/config.myr
echo "const Manpath = \"man/man\"" >> mbld/config.myr
;;
*)
--- a/rt/start-freebsd.s
+++ b/rt/start-freebsd.s
@@ -1,9 +1,15 @@
.data
/* sys.__cenvp : byte## */
+.globl environ
.globl sys$__cenvp
+environ:
sys$__cenvp:
- .quad 0
+ .quad 0
+.globl __progname
+__progname:
+ .quad 0
+
.globl thread$__tls
thread$__tls:
.fill 88 /* sizeof(tlshdr) + (8 * sizeof(void#)) = 24 + 64 */
@@ -25,6 +31,8 @@
/* load argc, argv, envp from stack */
movq (%rdi),%rax /* argc */
leaq 8(%rdi),%rbx /* argv */
+ movq (%rbx),%rcx /* save progname */
+ movq %rcx,__progname
leaq 16(%rdi,%rax,8),%rcx /* envp = argv + 8*argc + 8 */
/* store envp for some syscalls to use without converting */
--- a/test/runtest.rc
+++ b/test/runtest.rc
@@ -4,13 +4,13 @@
MYR_MC=`{cd .. ; pwd}^/6/6.out
MYR_MUSE=`{cd .. ; pwd}^/muse/6.out
fn build {
- dir=`{echo $1 | grep '.*/'}
- if(~ $dir '') {
+ dir=`{basename -d $1}
+ if(~ $dir '.') {
rm -f $1 $1^.6 $1^.use
../obj/mbld/mbld -Bnone -o 'out' -b $1 -I../obj/lib/std -I../obj/lib/sys -I../obj/lib/regex -r../rt/_myrrt.6 $1^.myr
}
if not {
- target=`{echo $1 | grep -o '[^/]*$'}
+ target=`{basename $1}
top=`{pwd}
mkdir -p out/$dir
cd $dir
@@ -99,9 +99,10 @@
cd $here
}
+fn posixonly {
+ status=''
+}
+
echo 'MTEST ' `{grep '^[BF]' tests | wc -l}
. tests
-
-
-
--- a/test/runtest.sh
+++ b/test/runtest.sh
@@ -133,6 +133,10 @@
cd $here
}
+posixonly() {
+ $*
+}
+
echo "MTEST $(egrep '^[BF]' tests | wc -l)"
. tests
--- a/test/tests
+++ b/test/tests
@@ -181,10 +181,10 @@
B fmtalign E 0
B fmtnest P _.f2_2,_.f3__3,_4.4__
B implexpr P 12,z,hello
-B implexpr-concrete P zigzag
-B abi/001-return-tuple E 0
-B abi/002-arg-alignment E 0
-B abi/003-ret-alignment E 0
-B abi/004-torture-1 E 0
-B abi/005-torture-2 E 0
-B abi/006-torture-3 E 0
+implexpr-concrete P zigzag
+posixonly B abi/001-return-tuple E 0
+posixonly B abi/002-arg-alignment E 0
+posixonly B abi/003-ret-alignment E 0
+posixonly B abi/004-torture-1 E 0
+posixonly B abi/005-torture-2 E 0
+posixonly B abi/006-torture-3 E 0