skip lookup table zero-initialization for x⊐x

This commit is contained in:
dzaima 2023-02-18 23:53:58 +02:00
parent 1c70a104cd
commit 428064a5c2

View File

@ -36,30 +36,32 @@ extern B mul_c2(B,B,B);
static u64 elRange(u8 eltype) { return 1ull<<(1<<elWidthLogBits(eltype)); } static u64 elRange(u8 eltype) { return 1ull<<(1<<elWidthLogBits(eltype)); }
#define TABLE(IN, FOR, TY, INIT, SET) \ #define TABLE(IN, FOR, TY, INIT, SET) \
usz it = elRange(IN##e); /* Range of writes */ \ usz it = elRange(IN##e); /* Range of writes */ \
usz ft = elRange(FOR##e); /* Range of lookups */ \ usz ft = elRange(FOR##e); /* Range of lookups */ \
usz t = it>ft? it : ft; /* Table allocation width */ \ usz t = it>ft? it : ft; /* Table allocation width */ \
TALLOC(TY, tab0, t); TY* tab = tab0 + t/2; \ TALLOC(TY, tab0, t); TY* tab = tab0 + t/2; \
usz m=IN##ia, n=FOR##ia; \ usz m=IN##ia, n=FOR##ia; \
void* ip = tyany_ptr(IN); \ void* ip = tyany_ptr(IN); \
void* fp = tyany_ptr(FOR); \ void* fp = tyany_ptr(FOR); \
/* Initialize */ \ /* Initialize */ \
if (FOR##e==el_i16 && n<ft/(64/sizeof(TY))) \ if (IN.u != FOR.u) { \
{ for (usz i=0; i<n; i++) tab[((i16*)fp)[i]]=INIT; } \ if (FOR##e==el_i16 && n<ft/(64/sizeof(TY))) \
else { TY* to=tab-(ft/2-(ft==2)); for (i64 i=0; i<ft; i++) to[i]=INIT; } \ { for (usz i=0; i<n; i++) tab[((i16*)fp)[i]]=INIT; } \
/* Set */ \ else { TY* to=tab-(ft/2-(ft==2)); for (i64 i=0; i<ft; i++) to[i]=INIT; } \
if (IN##e==el_i8) { for (usz i=m; i--; ) tab[((i8 *)ip)[i]]=SET; } \ } \
else { for (usz i=m; i--; ) tab[((i16*)ip)[i]]=SET; } \ /* Set */ \
decG(IN); \ if (IN##e==el_i8) { for (usz i=m; i--; ) tab[((i8 *)ip)[i]]=SET; } \
/* Lookup */ \ else { for (usz i=m; i--; ) tab[((i16*)ip)[i]]=SET; } \
if (FOR##e==el_bit) { \ decG(IN); \
r = bit_sel(FOR, m_i32(tab[0]), m_i32(tab[1])); \ /* Lookup */ \
} else { \ if (FOR##e==el_bit) { \
TY* rp; r = m_##TY##arrc(&rp, FOR); \ r = bit_sel(FOR, m_i32(tab[0]), m_i32(tab[1])); \
if (FOR##e==el_i8){ for (usz i=0; i<n; i++) rp[i]=tab[((i8 *)fp)[i]]; } \ } else { \
else { for (usz i=0; i<n; i++) rp[i]=tab[((i16*)fp)[i]]; } \ TY* rp; r = m_##TY##arrc(&rp, FOR); \
decG(FOR); \ if (FOR##e==el_i8){ for (usz i=0; i<n; i++) rp[i]=tab[((i8 *)fp)[i]]; } \
} \ else { for (usz i=0; i<n; i++) rp[i]=tab[((i16*)fp)[i]]; } \
decG(FOR); \
} \
TFREE(tab0); TFREE(tab0);
typedef struct { B n, p; } B2; typedef struct { B n, p; } B2;
@ -113,6 +115,7 @@ static NOINLINE B2 splitCells(B n, B p, u8 mode) { // 0:∊ 1:⊐ 2:⊒
u8 meb = neb>peb? neb : peb; u8 meb = neb>peb? neb : peb;
ux rb = csz<<meb; ux rb = csz<<meb;
if (rb!=0 && rb<=62) { if (rb!=0 && rb<=62) {
if (n.u == p.u) { decG(p); n=toIntCell(n,rb,1); return (B2){.n=n, .p=incG(n)}; }
if (neb!=meb) n = cpyToElLog(n, ne, meb); if (neb!=meb) n = cpyToElLog(n, ne, meb);
else if (peb!=meb) p = cpyToElLog(p, pe, meb); else if (peb!=meb) p = cpyToElLog(p, pe, meb);
return (B2){.n=toIntCell(n,rb,nco), .p=toIntCell(p,rb,1)}; return (B2){.n=toIntCell(n,rb,nco), .p=toIntCell(p,rb,1)};