From 5f85305f43068ee357a1cfa932033037ad575843 Mon Sep 17 00:00:00 2001 From: dzaima Date: Fri, 25 Nov 2022 02:20:58 +0200 Subject: [PATCH] GPR mask testing --- src/singeli/src/equal.singeli | 8 ++++---- src/singeli/src/mask.singeli | 12 ++++++++++++ src/singeli/src/sse3.singeli | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/singeli/src/equal.singeli b/src/singeli/src/equal.singeli index cea7f921..eb922b28 100644 --- a/src/singeli/src/equal.singeli +++ b/src/singeli/src/equal.singeli @@ -28,11 +28,11 @@ equal{W, X}(w:*void, x:*void, l:u64, d:u64) : u1 = { def bulk = 4 f0:= broadcast{T, 0.0} f1:= broadcast{T, 1.0} - maskedLoop{bulk, l, {i, M} => { + maskedLoopPositive{bulk, l, {i, M} => { cw:= load{*u8 ~~ w, i>>1} >> cast_i{u8, 4*(i&1)} cx:= load{*T ~~ x, i} wu:= blend{f0, f1, broadcast{[4]u64, cw} << make{[4]u64,63,62,61,60}} - if (anyne{wu, cx, M}) return{0} + if (anynePositive{wu, cx, M}) return{0} }} } else { # bitarr ≡ i8/i16/i32arr def T = [256/width{X}]X @@ -54,12 +54,12 @@ equal{W, X}(w:*void, x:*void, l:u64, d:u64) : u1 = { def ww{gw, E} = [gw/width{E}]E def fac = width{X}/width{W} - maskedLoop{bulk, l, {i, M} => { + maskedLoopPositive{bulk, l, {i, M} => { # TODO update this to modern mask stuff cw:= load{*ww{tern{fac==1, 256, 128}, W} ~~ (w + i*32/fac)} cx:= load{*ww{256, X} ~~ x, i} cwc:= cvt{W, ww{256, X}, cw} - if (anyne{cwc,cx,M}) return{0} + if (anynePositive{cwc,cx,M}) return{0} }} } 1 diff --git a/src/singeli/src/mask.singeli b/src/singeli/src/mask.singeli index 7bf60222..b8794bbf 100644 --- a/src/singeli/src/mask.singeli +++ b/src/singeli/src/mask.singeli @@ -19,6 +19,9 @@ def anyne{x:T, y:T, M & M{0}==0 & anyInt{x}} = x!=y def anyne{x:T, y:T, M & M{0}==1 & anyInt{x}} = M{x^y} != 0 def anyneBit{x:T, y:T, M} = ~M{x^y, 'all bits zeroes'} +def anynePositive{x:T, y:T, M & M{0}==0} = anyne{x, y, M} +def anynePositive{x:T, y:T, M & M{0}==1 & isvec{T}} = (promote{u32,~getmask{x==y}} << (32-M{'count'})) != 0 + def maskNone{x} = x def maskNone{x, mode=='all bits zeroes'} = andIsZero{x, x} def maskAfter{n} = { @@ -83,4 +86,13 @@ def maskedLoop{bulk, i0, l, step} = { left:= l & (bulk-1) if (left!=0) step{m, maskAfter{left}} +} + +def maskedLoopPositive{bulk, l:L, step} = { + i:L = 0 + while(i < (l-1)/bulk) { + step{i, maskNone} + i = i + 1 + } + step{i, maskAfter{l - i*bulk}} } \ No newline at end of file diff --git a/src/singeli/src/sse3.singeli b/src/singeli/src/sse3.singeli index 8d0298ab..8455071c 100644 --- a/src/singeli/src/sse3.singeli +++ b/src/singeli/src/sse3.singeli @@ -121,7 +121,7 @@ def __sub{a:T,b:T & w128i{T, 64}} = emit{T, '_mm_sub_epi64', a, b} # mask stuff -def getmask{x:T & w128{T, 8}} = emit{u32, '_mm_movemask_epi8', x} +def getmask{x:T & w128{T, 8}} = emit{u16, '_mm_movemask_epi8', x} def getmask{x:T & w128{T, 16}} = getmask{emit{[16]u8, '_mm_packs_epi16', x, broadcast{[8]u16, 0}}} def getmask{x:T & w128{T, 32}} = emit{u8, '_mm_movemask_ps', v2f{x}} def getmask{x:T & w128{T, 64}} = emit{u8, '_mm_movemask_pd', v2d{x}}