From 5f196c49d9d87f55c6fe86fe9cf10d9e5cb441f7 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Fri, 16 Sep 2022 20:08:23 -0400 Subject: [PATCH] Extend sparse and dense where to all cases fitting in i32s --- src/builtins/slash.c | 71 ++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/src/builtins/slash.c b/src/builtins/slash.c index b7bf7794..3840e786 100644 --- a/src/builtins/slash.c +++ b/src/builtins/slash.c @@ -361,54 +361,55 @@ B slash_c1(B t, B x) { usz xia = IA(x); B r; u8 xe = TI(x,elType); + if (xe!=el_bit && s<=xia) { x = num_squeeze(x); xe = TI(x,elType); } if (xe==el_bit) { r = where(x, xia, s); - } else if (RARE(xia>=I32_MAX)) { + } else if (RARE(xia > (usz)I32_MAX+1)) { SGetU(x) f64* rp; r = m_f64arrv(&rp, s); usz ri = 0; for (usz i = 0; i < xia; i++) { usz c = o2s(GetU(x, i)); for (usz j = 0; j < c; j++) rp[ri++] = i; } - } else { + } else if (RARE(xe > el_i32)) { i32* rp; r = m_i32arrv(&rp, s); - if (xe==el_i8) { - i8* xp = i8any_ptr(x); - if (s/16 <= xia) { - usz b = 1<<10; - for (usz k=0, j=0, js=0, ij=xp[0]; ; ) { - usz e = b0 && !xp[xia-1]) xia--; - for (u64 i = 0; i < xia; i++) { - i32 c = xp[i]; - for (i32 j = 0; j < c; j++) *rp++ = i; + i32* rp; r = m_i32arrv(&rp, s); + if (xe == el_i8 ) { SPARSE_IND(i8 ); } + else if (xe == el_i16) { SPARSE_IND(i16); } + else { SPARSE_IND(i32); } + #undef SPARSE_IND + } else { // Dense case: only result type matters + #define DENSE_IND(T) \ + T* rp; r = m_##T##arrv(&rp, s); \ + for (u64 i = 0; i < xia; i++) { \ + i32 c = xp[i]; \ + for (i32 j = 0; j < c; j++) *rp++ = i; \ } - } - } else if (xe==el_i32) { + if (xe < el_i32) x = taga(cpyI32Arr(x)); i32* xp = i32any_ptr(x); while (xia>0 && !xp[xia-1]) xia--; - for (u64 i = 0; i < xia; i++) { - i32 c = xp[i]; - if (LIKELY(c==0 || c==1)) { - *rp = i; - rp+= c; - } else { - for (i32 j = 0; j < c; j++) *rp++ = i; - } - } - } else { - SLOW1("/𝕩", x); - SGetU(x) - for (u64 i = 0; i < xia; i++) { - usz c = o2s(GetU(x, i)); - for (u64 j = 0; j < c; j++) *rp++ = i; - } + if (xia <= 128) { DENSE_IND(i8 ); } + else if (xia <= 32768) { DENSE_IND(i16); } + else { DENSE_IND(i32); } + #undef DENSE_IND } } decG(x);