From 2b7291dbfbfc316cae98a9616f97666dc2c27ca0 Mon Sep 17 00:00:00 2001 From: dzaima Date: Thu, 15 Dec 2022 20:26:41 +0200 Subject: [PATCH] =?UTF-8?q?cvt{E,T,v}=20=E2=86=92=20widen{T,to=5Fel{E,v}}?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/singeli/src/avx.singeli | 7 +++++-- src/singeli/src/avx2.singeli | 27 ++++++--------------------- src/singeli/src/base.singeli | 3 +++ src/singeli/src/equal.singeli | 2 +- src/singeli/src/mask.singeli | 2 +- src/singeli/src/select.singeli | 2 +- src/singeli/src/sse3.singeli | 13 +++++++++---- 7 files changed, 26 insertions(+), 30 deletions(-) diff --git a/src/singeli/src/avx.singeli b/src/singeli/src/avx.singeli index 40b017e1..00e8a9ec 100644 --- a/src/singeli/src/avx.singeli +++ b/src/singeli/src/avx.singeli @@ -101,8 +101,11 @@ def half{x:T, i==0 & w256{T}} = [vcount{T}/2](eltype{T}) ~~ emit{[8]i16, def pair{a:T,b:T & width{T}==128} = [vcount{T}*2](eltype{T}) ~~ emit{[8]i32, '_mm256_setr_m128i', a, b} def pair{x} = pair{tupsel{0,x},tupsel{1,x}} -def cvt{F==i32, T==[4]f64, a:A & w128i{A}} = emit{T, '_mm256_cvtepi32_pd', a} -def cvt{F, T, a:A & w256{A} & width{F}vcount{T}} = widen{T, half{x,0}} + # structural operations def extract{x:T, i & w256i{T,32} & knum{i}} = emit{eltype{T}, '_mm256_extract_epi32', x, i} diff --git a/src/singeli/src/avx2.singeli b/src/singeli/src/avx2.singeli index 6501d4aa..46107bd4 100644 --- a/src/singeli/src/avx2.singeli +++ b/src/singeli/src/avx2.singeli @@ -149,27 +149,12 @@ def topAll{x:T & w256i{T,16}} = homAll{[16]i16~~x < [16]i16**0} # conversion -# convert packed elements of type F to a result T -# TODO F param is unnecessary if correct element type of A is enforced -def cvt{F==u8, T==[16]u16, a:A & w128i{A}} = emit{T, '_mm256_cvtepu8_epi16', a} -def cvt{F==u8, T==[8]u32, a:A & w128i{A}} = emit{T, '_mm256_cvtepu8_epi32', a} -def cvt{F==u8, T==[4]u64, a:A & w128i{A}} = emit{T, '_mm256_cvtepu8_epi64', a} -def cvt{F==u16, T==[8]u32, a:A & w128i{A}} = emit{T, '_mm256_cvtepu16_epi32', a} -def cvt{F==u16, T==[4]u64, a:A & w128i{A}} = emit{T, '_mm256_cvtepu16_epi64', a} -def cvt{F==u32, T==[4]u64, a:A & w128i{A}} = emit{T, '_mm256_cvtepu32_epi64', a} - -def cvt{F==i8, T==[16]i16, a:A & w128i{A}} = emit{T, '_mm256_cvtepi8_epi16', a} -def cvt{F==i8, T==[8]i32, a:A & w128i{A}} = emit{T, '_mm256_cvtepi8_epi32', a} -def cvt{F==i8, T==[4]i64, a:A & w128i{A}} = emit{T, '_mm256_cvtepi8_epi64', a} -def cvt{F==i16, T==[8]i32, a:A & w128i{A}} = emit{T, '_mm256_cvtepi16_epi32', a} -def cvt{F==i16, T==[4]i64, a:A & w128i{A}} = emit{T, '_mm256_cvtepi16_epi64', a} -def cvt{F==i32, T==[4]i64, a:A & w128i{A}} = emit{T, '_mm256_cvtepi32_epi64', a} - -def cvt{F , T==[4]f64, a:A & w128i{A} & F!=i32} = cvt{i32, T, cvt{F, [4]i32, a}} - - -# def cvt0{F, T, a} = { show{'cvt invocation', F, T, a}; 0 } -# def cvt{F, T, a & cvt0{F, T, a}} = 123 +def widen{T==[16]u16, x:X & X==[16]u8} = emit{T, '_mm256_cvtepu8_epi16', x}; def widen{T==[16]i16, x:X & X==[16]i8} = emit{T, '_mm256_cvtepi8_epi16', x} +def widen{T==[ 8]u32, x:X & X==[16]u8} = emit{T, '_mm256_cvtepu8_epi32', x}; def widen{T==[ 8]i32, x:X & X==[16]i8} = emit{T, '_mm256_cvtepi8_epi32', x} +def widen{T==[ 8]u32, x:X & X==[8]u16} = emit{T, '_mm256_cvtepu16_epi32', x}; def widen{T==[ 8]i32, x:X & X==[8]i16} = emit{T, '_mm256_cvtepi16_epi32', x} +def widen{T==[ 4]u64, x:X & X==[16]u8} = emit{T, '_mm256_cvtepu8_epi64', x}; def widen{T==[ 4]i64, x:X & X==[16]i8} = emit{T, '_mm256_cvtepi8_epi64', x} +def widen{T==[ 4]u64, x:X & X==[8]u16} = emit{T, '_mm256_cvtepu16_epi64', x}; def widen{T==[ 4]i64, x:X & X==[8]i16} = emit{T, '_mm256_cvtepi16_epi64', x} +def widen{T==[ 4]u64, x:X & X==[4]u32} = emit{T, '_mm256_cvtepu32_epi64', x}; def widen{T==[ 4]i64, x:X & X==[4]i32} = emit{T, '_mm256_cvtepi32_epi64', x} # undo cvt; assumes elements of X fit in T, otherwise may be saturated or otherwise corrupted; but keeps the width of x, with trailing elements undefined def ucvt{T, x:X & w256i{X,32} & width{T}==8} = { diff --git a/src/singeli/src/base.singeli b/src/singeli/src/base.singeli index 4c6507e6..a1bbd756 100644 --- a/src/singeli/src/base.singeli +++ b/src/singeli/src/base.singeli @@ -84,6 +84,9 @@ def ty_half{T & isprim{T}} = to_w{T, width{T}/2} def ty_dbl {T & isvec{T}} = to_el{ty_dbl {eltype{T}}, T} def ty_half{T & isvec{T}} = to_el{ty_half{eltype{T}}, T} +# base vector utility definitions +def widen{T, x:X & T==X} = x + def unroll{vars,begin,end,block & knum{begin} & knum{end}} = { def f{i,l & i==l} = 0 def f{i,l & i!=l} = { diff --git a/src/singeli/src/equal.singeli b/src/singeli/src/equal.singeli index 2ce49cda..914b6605 100644 --- a/src/singeli/src/equal.singeli +++ b/src/singeli/src/equal.singeli @@ -58,7 +58,7 @@ equal{W, X}(w:*void, x:*void, l:u64, d:u64) : u1 = { # 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} + cwc:= widen{ww{256, X}, to_el{W, cw}} if (anynePositive{cwc,cx,M}) return{0} }} } diff --git a/src/singeli/src/mask.singeli b/src/singeli/src/mask.singeli index c9e2c4ea..650dc690 100644 --- a/src/singeli/src/mask.singeli +++ b/src/singeli/src/mask.singeli @@ -55,7 +55,7 @@ def loadBatch{ptr:P, n, T} = { def rpos = ptr + n*vcount{T} def E0 = eltype{P} - cvt{E0, T, loadLow{*to_el{E0, T} ~~ rpos, vcount{T}*width{E0}}} + widen{T, loadLow{*to_el{E0, T} ~~ rpos, vcount{T}*width{E0}}} } diff --git a/src/singeli/src/select.singeli b/src/singeli/src/select.singeli index 358dc135..587433aa 100644 --- a/src/singeli/src/select.singeli +++ b/src/singeli/src/select.singeli @@ -61,7 +61,7 @@ def perm_select{ri, rd, TI, w, r, wl, xl, selx} = { maskedLoop{ri, wl, {i, M} => { cw:= wrapChk{loadBatch{w, i, VI}, VI,xlf, M} is:= (if (ext>1) i<