From 70e2694f88837029212cb35a60c93e8a1c087953 Mon Sep 17 00:00:00 2001 From: dzaima Date: Wed, 29 Jan 2025 19:25:09 +0200 Subject: [PATCH] more Singeli NEON cleanup --- src/singeli/src/bitalign.singeli | 2 +- src/singeli/src/neon.singeli | 33 +++++++++++++++++--------------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/singeli/src/bitalign.singeli b/src/singeli/src/bitalign.singeli index dfc0677e..13a244ea 100644 --- a/src/singeli/src/bitalign.singeli +++ b/src/singeli/src/bitalign.singeli @@ -41,7 +41,7 @@ def new_shuf{...vs0 if isvec{try_same_type{vs0,'!'}}, {...is}} = { # : [length{i } def new_shuf{w if istype{w} or knum{w}, ...vs if isvec{try_same_type{vs,'!'}} and (not isvec{w} or width{w} == width{type0{vs}}), {...is}} = { def S = type0{vs} - def D = if (isvec{w}) w else re_el{if (isprim{w}) w else primtype{'u',w}, S} + def D = if (isvec{w}) w else re_el{if (isprim{w}) w else ty_u{w}, S} S~~new_shuf{...each{{c} => reinterpret{D, c}, vs}, is} } diff --git a/src/singeli/src/neon.singeli b/src/singeli/src/neon.singeli index 3c9a04df..5bd33555 100644 --- a/src/singeli/src/neon.singeli +++ b/src/singeli/src/neon.singeli @@ -106,8 +106,8 @@ def narrow {T, x:X=[_]E if w128{X} and eqqi{T,E} and width{T}*2==width{E}} def narrow {T, x:X=[_]E if w128{X} and isfloat{T}!=isfloat{E} and width{T}=16} = ~hom_any_lo64{subhn{[8]u16**16r def any_hom{x:V if w128{V} and elwidth{V}>=16} = hom_any_lo64{narrow{u8,[8]u16~~x}} # narrow probably better than maxp # TODO multi-vector any_hom for ew≥16 via addhn? - def any_top{x:V if nvec{V}} = fold_min{ty_s{x}}<0 def all_top{x:V if nvec{V}} = fold_max{ty_s{x}}<0 -def hom_to_int{x:T=[k]E if nvecu{T} and width{E}>=k} = { - truncBits{k, fold_add{x & make{T, 1<G{T}; {_}=>0 }, vs} +def hom_to_int{...vs if all_type{nvec,vs} and not all_type{nvecu,vs}} = hom_to_int{...each{ty_u, vs}} + +def hom_to_int{x:V=[k]E if nvecu{V} and width{E}>=k} = { + truncBits{k, fold_add{x & make{V, 1<>2) | ((range{16}&3)<<2)} - # fold_add{addpw{addpw{addp{ty_u{a}&m, ty_u{b}&m}}}< sel{tup{a,b}, make{[16]u8, ((range{16}&3)<<3) + (range{16}>>2) + i}}, tup{0, 4}} # t:= shrm{l, 4, h} & make{[16]u8, (1<<(range{16}>>2)) * 0x11} # fold_add{[4]u32~~t} } -def hom_to_int{a:T,b:T,c:T,d:T=[16]E if width{E}==8} = { +def hom_to_int{a:V,b:V,c:V,d:V=([16]u8)} = { m:= make{[16]u8, 1<<(iota{16}&7)} - t1:= addp{ty_u{a}&m, ty_u{b}&m} - t2:= addp{ty_u{c}&m, ty_u{d}&m} + t1:= addp{a & m, b & m} + t2:= addp{c & m, d & m} t3:= addp{t1, t2} extract{[2]u64~~addp{t3,t3},0} } -def hom_to_int{...as={a0:[_]E, _, ..._} if width{E}>=32} = hom_to_int{...each{{i}=>narrow_pair{select{as,i*2},select{as,i*2+1}}, iota{length{as}/2}}} -def hom_to_int{a:T,b:T=[k]E if k*2<=width{E}} = { - truncBits{k*2, fold_add{shrm{a,width{E}-k,b} & make{T, (1<=32} = hom_to_int{...each{{i}=>narrow_pair{select{as,i*2},select{as,i*2+1}}, iota{length{as}/2}}} +def hom_to_int{a:V,b:V=[k]E if nvecu{V} and k*2<=width{E}} = { + truncBits{k*2, fold_add{shrm{a,width{E}-k,b} & make{V, (1<