make dyarith array-array dispatch its own function
This commit is contained in:
parent
bd04e38a5e
commit
1b8bd0707e
@ -255,7 +255,7 @@ static f64 pfmod(f64 a, f64 b) {
|
||||
case el_f64: { SI_AS_I(NAME,f64,x,asBad) } \
|
||||
case el_c8: case el_c16: case el_c32: case el_B:; /*fallthrough*/ \
|
||||
} asBad:;
|
||||
#define SI_AA(N) return do_dyArith(&N##DyTable, w, x);
|
||||
#define SI_AA(N) return dyArith_AA(&N##DyTableAA, w, x);
|
||||
#define IFN_SINGELI(X)
|
||||
#else
|
||||
#define SI_AA NO_SI_AA
|
||||
|
||||
@ -285,9 +285,8 @@ B internalTemp_c1(B t, B x) {
|
||||
#endif
|
||||
return x;
|
||||
}
|
||||
#if !SINGELI
|
||||
|
||||
B internalTemp_c2(B t, B w, B x) { dec(w); return x; }
|
||||
#endif
|
||||
|
||||
B heapDump_c1(B t, B x) {
|
||||
cbqn_heapDump();
|
||||
|
||||
@ -41,118 +41,100 @@ char* execAA_repr(u8 ex) {
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct FnInfo {
|
||||
typedef struct FnInfoAA {
|
||||
union { CheckedFn cFn; UncheckedFn uFn; };
|
||||
u8 ex1, ex2; // ExecAA
|
||||
u8 type; // t_*; unused for u_call_bit
|
||||
u8 width; // width in bytes; unused for u_call_bit
|
||||
} FnInfo;
|
||||
} FnInfoAA;
|
||||
typedef struct EntAA {
|
||||
FnInfo a, b;
|
||||
FnInfoAA a, b;
|
||||
} EntAA;
|
||||
|
||||
typedef struct DyTable {
|
||||
typedef struct DyTableAA {
|
||||
EntAA entsAA[8*8]; // one for each instruction
|
||||
BBB2B mainFn;
|
||||
char* repr;
|
||||
} DyTable;
|
||||
} DyTableAA;
|
||||
|
||||
NOINLINE B do_dyArith(DyTable* table, B w, B x) {
|
||||
B r;
|
||||
NOINLINE B dyArith_AA(DyTableAA* table, B w, B x) {
|
||||
u8 we = TI(w, elType); if (we==el_B) goto rec;
|
||||
u8 xe = TI(x, elType); if (xe==el_B) goto rec;
|
||||
ur wr = RNK(w);
|
||||
ur xr = RNK(x);
|
||||
if (wr!=xr || !eqShPart(SH(w), SH(x), wr)) goto rec;
|
||||
|
||||
if (1 || isArr(w)) {
|
||||
u8 we = TI(w, elType);
|
||||
if (we==el_B) goto rec;
|
||||
if (1 || isArr(x)) {
|
||||
u8 xe = TI(x, elType);
|
||||
if (xe==el_B) goto rec;
|
||||
ur wr = RNK(w);
|
||||
ur xr = RNK(x);
|
||||
if (wr!=xr || !eqShPart(SH(w), SH(x), wr)) goto rec;
|
||||
|
||||
usz ia = IA(w);
|
||||
EntAA* e = &table->entsAA[we*8 + xe];
|
||||
newEnt:
|
||||
|
||||
FnInfo* fn = &e->a;
|
||||
newFn:
|
||||
u8 ex = fn->ex1;
|
||||
newEx:
|
||||
B t;
|
||||
#if ARITH_DEBUG
|
||||
printf("opcode %d / %s\n", ex, execAA_repr(ex));
|
||||
#endif
|
||||
switch(ex) { default: UD;
|
||||
case wi8_reg: w=taga( cpyI8Arr(w)); goto do_ex2; case xi8_reg: x=taga( cpyI8Arr(x)); goto do_ex2;
|
||||
case wi16_reg: w=taga(cpyI16Arr(w)); goto do_ex2; case xi16_reg: x=taga(cpyI16Arr(x)); goto do_ex2;
|
||||
case wi32_reg: w=taga(cpyI32Arr(w)); goto do_ex2; case xi32_reg: x=taga(cpyI32Arr(x)); goto do_ex2;
|
||||
case wf64_reg: w=taga(cpyF64Arr(w)); goto do_ex2; case xf64_reg: x=taga(cpyF64Arr(x)); goto do_ex2;
|
||||
case wc16_reg: w=taga(cpyC16Arr(w)); goto do_ex2; case xc16_reg: x=taga(cpyC16Arr(x)); goto do_ex2;
|
||||
case wc32_reg: w=taga(cpyC32Arr(w)); goto do_ex2; case xc32_reg: x=taga(cpyC32Arr(x)); goto do_ex2;
|
||||
case wi8_swap: t=x; x=taga( cpyI8Arr(w)); w=t; goto do_ex2; case xi8_swap: t=w; w=taga( cpyI8Arr(x)); x=t; goto do_ex2;
|
||||
case wi16_swap: t=x; x=taga(cpyI16Arr(w)); w=t; goto do_ex2; case xi16_swap: t=w; w=taga(cpyI16Arr(x)); x=t; goto do_ex2;
|
||||
case wi32_swap: t=x; x=taga(cpyI32Arr(w)); w=t; goto do_ex2; case xi32_swap: t=w; w=taga(cpyI32Arr(x)); x=t; goto do_ex2;
|
||||
case wf64_swap: t=x; x=taga(cpyF64Arr(w)); w=t; goto do_ex2; case xf64_swap: t=w; w=taga(cpyF64Arr(x)); x=t; goto do_ex2;
|
||||
case wc16_swap: t=x; x=taga(cpyC16Arr(w)); w=t; goto do_ex2; case xc16_swap: t=w; w=taga(cpyC16Arr(x)); x=t; goto do_ex2;
|
||||
case wc32_swap: t=x; x=taga(cpyC32Arr(w)); w=t; goto do_ex2; case xc32_swap: t=w; w=taga(cpyC32Arr(x)); x=t; goto do_ex2;
|
||||
case swap: t=w; w=x; x=t; goto do_ex2;
|
||||
do_ex2: ex = fn->ex2; goto newEx;
|
||||
|
||||
case c_call_rbyte: { c_call_rbyte:
|
||||
u64 got = fn->cFn(m_tyarrlc(&r, fn->width, x, fn->type), tyany_ptr(w), tyany_ptr(x), ia);
|
||||
if (got==ia) goto decG_ret;
|
||||
decG(r);
|
||||
fn = &e->b;
|
||||
goto newFn;
|
||||
}
|
||||
case u_call_rbyte: {
|
||||
fn->uFn(m_tyarrlc(&r, fn->width, x, fn->type), tyany_ptr(w), tyany_ptr(x), ia);
|
||||
goto decG_ret;
|
||||
}
|
||||
case e_call_rbyte: {
|
||||
u64 got = fn->cFn(m_tyarrlc(&r, fn->width, x, fn->type), tyany_ptr(w), tyany_ptr(x), ia);
|
||||
if (got) goto rec;
|
||||
goto decG_ret;
|
||||
}
|
||||
case u_call_bit: {
|
||||
u64* rp; r = m_bitarrc(&rp, x);
|
||||
fn->uFn((u8*)rp, tyany_ptr(w), tyany_ptr(x), ia);
|
||||
goto decG_ret;
|
||||
}
|
||||
|
||||
case u_call_wxf64sq: {
|
||||
f64* rp; r = m_f64arrc(&rp, x);
|
||||
fn->uFn((u8*)rp, tyany_ptr(w = toF64Any(w)), tyany_ptr(x = toF64Any(x)), ia);
|
||||
r = num_squeeze(r);
|
||||
goto decG_ret;
|
||||
}
|
||||
case c_call_wxi8: {
|
||||
assert(TI(x,elType)==el_bit && TI(w,elType)==el_bit);
|
||||
w = taga(cpyI8Arr(w));
|
||||
x = taga(cpyI8Arr(x));
|
||||
goto c_call_rbyte;
|
||||
}
|
||||
case e_call_sqx: {
|
||||
assert(TI(x,elType)==el_f64);
|
||||
x = num_squeeze(x);
|
||||
u8 xe = TI(x,elType);
|
||||
if (xe==el_f64) goto rec;
|
||||
e = &table->entsAA[TI(w,elType)*8 + xe];
|
||||
goto newEnt;
|
||||
}
|
||||
case fail: goto rec;
|
||||
}
|
||||
} else {
|
||||
goto rec;
|
||||
usz ia = IA(w);
|
||||
EntAA* e = &table->entsAA[we*8 + xe];
|
||||
newEnt:
|
||||
|
||||
FnInfoAA* fn = &e->a;
|
||||
newFn:
|
||||
u8 ex = fn->ex1;
|
||||
newEx:
|
||||
B r, t;
|
||||
#if ARITH_DEBUG
|
||||
printf("opcode %d / %s\n", ex, execAA_repr(ex));
|
||||
#endif
|
||||
switch(ex) { default: UD;
|
||||
case wi8_reg: w=taga( cpyI8Arr(w)); goto do_ex2; case xi8_reg: x=taga( cpyI8Arr(x)); goto do_ex2;
|
||||
case wi16_reg: w=taga(cpyI16Arr(w)); goto do_ex2; case xi16_reg: x=taga(cpyI16Arr(x)); goto do_ex2;
|
||||
case wi32_reg: w=taga(cpyI32Arr(w)); goto do_ex2; case xi32_reg: x=taga(cpyI32Arr(x)); goto do_ex2;
|
||||
case wf64_reg: w=taga(cpyF64Arr(w)); goto do_ex2; case xf64_reg: x=taga(cpyF64Arr(x)); goto do_ex2;
|
||||
case wc16_reg: w=taga(cpyC16Arr(w)); goto do_ex2; case xc16_reg: x=taga(cpyC16Arr(x)); goto do_ex2;
|
||||
case wc32_reg: w=taga(cpyC32Arr(w)); goto do_ex2; case xc32_reg: x=taga(cpyC32Arr(x)); goto do_ex2;
|
||||
case wi8_swap: t=x; x=taga( cpyI8Arr(w)); w=t; goto do_ex2; case xi8_swap: t=w; w=taga( cpyI8Arr(x)); x=t; goto do_ex2;
|
||||
case wi16_swap: t=x; x=taga(cpyI16Arr(w)); w=t; goto do_ex2; case xi16_swap: t=w; w=taga(cpyI16Arr(x)); x=t; goto do_ex2;
|
||||
case wi32_swap: t=x; x=taga(cpyI32Arr(w)); w=t; goto do_ex2; case xi32_swap: t=w; w=taga(cpyI32Arr(x)); x=t; goto do_ex2;
|
||||
case wf64_swap: t=x; x=taga(cpyF64Arr(w)); w=t; goto do_ex2; case xf64_swap: t=w; w=taga(cpyF64Arr(x)); x=t; goto do_ex2;
|
||||
case wc16_swap: t=x; x=taga(cpyC16Arr(w)); w=t; goto do_ex2; case xc16_swap: t=w; w=taga(cpyC16Arr(x)); x=t; goto do_ex2;
|
||||
case wc32_swap: t=x; x=taga(cpyC32Arr(w)); w=t; goto do_ex2; case xc32_swap: t=w; w=taga(cpyC32Arr(x)); x=t; goto do_ex2;
|
||||
case swap: t=w; w=x; x=t; goto do_ex2;
|
||||
do_ex2: ex = fn->ex2; goto newEx;
|
||||
|
||||
case c_call_rbyte: { c_call_rbyte:
|
||||
u64 got = fn->cFn(m_tyarrlc(&r, fn->width, x, fn->type), tyany_ptr(w), tyany_ptr(x), ia);
|
||||
if (got==ia) goto decG_ret;
|
||||
decG(r);
|
||||
fn = &e->b;
|
||||
goto newFn;
|
||||
}
|
||||
} else {
|
||||
if (isArr(x)) {
|
||||
u8 xe = TI(x, elType);
|
||||
if (xe==el_B) goto rec;
|
||||
goto rec;
|
||||
} else { // TODO decide if this is even a case that needs to be handled here
|
||||
return table->mainFn(w, w, x);
|
||||
case u_call_rbyte: {
|
||||
fn->uFn(m_tyarrlc(&r, fn->width, x, fn->type), tyany_ptr(w), tyany_ptr(x), ia);
|
||||
goto decG_ret;
|
||||
}
|
||||
case e_call_rbyte: {
|
||||
u64 got = fn->cFn(m_tyarrlc(&r, fn->width, x, fn->type), tyany_ptr(w), tyany_ptr(x), ia);
|
||||
if (got) goto rec;
|
||||
goto decG_ret;
|
||||
}
|
||||
case u_call_bit: {
|
||||
u64* rp; r = m_bitarrc(&rp, x);
|
||||
fn->uFn((u8*)rp, tyany_ptr(w), tyany_ptr(x), ia);
|
||||
goto decG_ret;
|
||||
}
|
||||
|
||||
case u_call_wxf64sq: {
|
||||
f64* rp; r = m_f64arrc(&rp, x);
|
||||
fn->uFn((u8*)rp, tyany_ptr(w = toF64Any(w)), tyany_ptr(x = toF64Any(x)), ia);
|
||||
r = num_squeeze(r);
|
||||
goto decG_ret;
|
||||
}
|
||||
case c_call_wxi8: {
|
||||
assert(TI(x,elType)==el_bit && TI(w,elType)==el_bit);
|
||||
w = taga(cpyI8Arr(w));
|
||||
x = taga(cpyI8Arr(x));
|
||||
goto c_call_rbyte;
|
||||
}
|
||||
case e_call_sqx: {
|
||||
assert(TI(x,elType)==el_f64);
|
||||
x = num_squeeze(x);
|
||||
u8 xe = TI(x,elType);
|
||||
if (xe==el_f64) goto rec;
|
||||
e = &table->entsAA[TI(w,elType)*8 + xe];
|
||||
goto newEnt;
|
||||
}
|
||||
case fail: goto rec;
|
||||
}
|
||||
|
||||
rec:
|
||||
@ -174,8 +156,3 @@ static void stileAAu_f64_f64_f64(u8* r, u8* w, u8* x, u64 len) { for (u64 i = 0;
|
||||
static void logAAu_f64_f64_f64(u8* r, u8* w, u8* x, u64 len) { for (u64 i = 0; i < len; i++) ((f64*)r)[i] = log(((f64*)x)[i])/log(((f64*)w)[i]); }
|
||||
|
||||
#include "../gen/arTables.c"
|
||||
|
||||
|
||||
B internalTemp_c2(B t, B w, B x) {
|
||||
return do_dyArith(&addDyTable, w, x);
|
||||
}
|
||||
|
||||
@ -107,7 +107,7 @@ Make ← {𝕊ns:
|
||||
|
||||
cSrc∾↩ ∾⟨
|
||||
"B ", cbqn, "_c2(B,B,B);", nl
|
||||
"static DyTable ", cbqn,"DyTable = {", nl
|
||||
"static DyTableAA ", cbqn,"DyTableAA = {", nl
|
||||
" .entsAA = {", nl
|
||||
∾{ ⟨instrs, we‿xe⟩:
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user