From 47170231676f65418941924fae82383a449150d0 Mon Sep 17 00:00:00 2001 From: dzaima Date: Mon, 25 Oct 2021 12:26:52 +0300 Subject: [PATCH] cmp C cleanup, assert length!=0 before while --- src/singeli/builtins/cmp.c | 26 ++++++++++---------------- src/singeli/src/base.singeli | 3 ++- src/singeli/src/cmp.singeli | 1 + 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/singeli/builtins/cmp.c b/src/singeli/builtins/cmp.c index 919605f8..065890e3 100644 --- a/src/singeli/builtins/cmp.c +++ b/src/singeli/builtins/cmp.c @@ -38,8 +38,6 @@ static void* tyany_ptr(B x) { #define CMP_IMPL(CHR, NAME, RNAME, PNAME, L, R, OP, FC, CF, BX) \ if (isF64(w)&isF64(x)) return m_i32(w.f OP x.f); \ if (isC32(w)&isC32(x)) return m_i32(w.u OP x.u); \ - if (isF64(w)&isC32(x)) return m_i32(FC); \ - if (isC32(w)&isF64(x)) return m_i32(CF); \ if (isArr(w)) { u8 we = TI(w,elType); \ if (we==el_B) goto end; \ if (isArr(x)) { u8 xe = TI(x,elType); \ @@ -52,18 +50,14 @@ static void* tyany_ptr(B x) { } \ AL(x) \ lut_avx2_##PNAME##AA[we](rp, tyany_ptr(L), tyany_ptr(R), ria); \ - dec(w);dec(x); return r; \ - } \ - } else { AL(w) \ - /*print(w);printf("@%d "CHR" ",we);print(x);printf(": ");*/ \ - lut_avx2_##NAME##AS[we](rp, tyany_ptr(w), x.u, ria); \ - /*print(r);putchar('\n');*/ \ - dec(w); return r; \ - } \ - } else if (isArr(x)) { u8 xe = TI(x,elType); if (xe==el_B) goto end; AL(x) \ - /*print(x);printf(" "CHR" ");print(w);printf("@%d: ", xe);*/ \ - lut_avx2_##RNAME##AS[xe](rp, tyany_ptr(x), w.u, ria); \ - /*print(r);putchar('\n');*/ \ - dec(x); return r; \ - } \ + dec(w);dec(x); return r; \ + } \ + } else { \ + AL(w) lut_avx2_##NAME##AS[we](rp, tyany_ptr(w), x.u, ria); dec(w); return r; \ + } \ + } else if (isArr(x)) { u8 xe = TI(x,elType); if (xe==el_B) goto end; \ + AL(x) lut_avx2_##RNAME##AS[xe](rp, tyany_ptr(x), w.u, ria); dec(x); return r; \ + } \ + if (isF64(w)&isC32(x)) return m_i32(FC); \ + if (isC32(w)&isF64(x)) return m_i32(CF); \ end:; diff --git a/src/singeli/src/base.singeli b/src/singeli/src/base.singeli index ba2ae14a..1e01870e 100644 --- a/src/singeli/src/base.singeli +++ b/src/singeli/src/base.singeli @@ -3,6 +3,7 @@ include 'arch/c' def cdiv{a,b} = (a+b-1)/b def rare{x:u1} = emit{u1, '__builtin_expect', x, 0} def isunsigned{T} = isint{T} & ~issigned{T} +def assert{x:u1} = emit{void, 'si_assert', x} def unroll{vars,begin,end,block & match{kind{begin},'number'} & match{kind{end},'number'}} = { def f{i,l & i==l} = 0 @@ -21,4 +22,4 @@ def for{vars,begin,end,block} = { } def maxvalue{T & T==u8 } = 0xff def maxvalue{T & T==u16} = 0xffff -def maxvalue{T & T==u32} = 0xffffffff \ No newline at end of file +def maxvalue{T & T==u32} = 0xffffffff diff --git a/src/singeli/src/cmp.singeli b/src/singeli/src/cmp.singeli index ecfa0706..bf0c7cba 100644 --- a/src/singeli/src/cmp.singeli +++ b/src/singeli/src/cmp.singeli @@ -78,6 +78,7 @@ def any2bit{VT, unr, op, wS, wV, xS, xV, dst:*u64, len:(Size)} = { ri:Size = 0 def bam = vcount{VT}*unr len:Size = cdiv{len,bam} + assert{len!=0} while (ri < len) { r:u64 = 0 @unroll (j from 0 to unr) r = r | (cast_i{u64, getmask{op{wV{xi+j}, xV{xi+j}}}} << (j*vcount{VT}))