From 88410c02e55987d1cb793983ee0c7ec3731a6394 Mon Sep 17 00:00:00 2001 From: dzaima Date: Tue, 24 Jan 2023 22:21:38 +0200 Subject: [PATCH] prep for NEON squeeze --- README.md | 2 +- src/builtins/squeeze.c | 4 ++++ src/singeli/src/base.singeli | 7 +++++++ src/singeli/src/mask.singeli | 1 + src/singeli/src/neon.singeli | 14 ++++++++------ src/singeli/src/squeeze.singeli | 10 +++++++--- 6 files changed, 28 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index cf17849f..f41d1281 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ Additionally, CBQN is known to compile as-is on macOS, but Windows requires [Win ## License -Most files here are copyright (c) 2021 dzaima & others, [GNU GPLv3 only](licenses/LICENSE-GPLv3). +Most files here are copyright (c) 2021-2023 dzaima & others, [GNU GPLv3 only](licenses/LICENSE-GPLv3). Exceptions are: - timsort implementation - `src/builtins/sortTemplate.h`: [MIT](licenses/LICENSE-MIT-sort); [original repo](https://github.com/swenson/sort/tree/f79f2a525d03f102034b5a197c395f046eb82708) - Ryu - `src/utils/ryu.c` & files in `src/utils/ryu/`: [Apache 2.0](licenses/LICENSE-Apache2) or [Boost 1.0](licenses/LICENSE-Boost); [original repo](https://github.com/ulfjack/ryu/tree/75d5a85440ed356ad7b23e9e6002d71f62a6255c) \ No newline at end of file diff --git a/src/builtins/squeeze.c b/src/builtins/squeeze.c index 15826bfc..38837a47 100644 --- a/src/builtins/squeeze.c +++ b/src/builtins/squeeze.c @@ -31,6 +31,10 @@ NOINLINE B num_squeezeF(B x, usz ia) { B num_squeeze(B x) { usz ia = IA(x); u8 xe = TI(x,elType); + if (ia==0) { + if (xe==el_bit) return x; + goto r_bit; + } #if !SINGELI_X86_64 usz i = 0; diff --git a/src/singeli/src/base.singeli b/src/singeli/src/base.singeli index d1108396..248fd138 100644 --- a/src/singeli/src/base.singeli +++ b/src/singeli/src/base.singeli @@ -120,6 +120,13 @@ def mul12{...x} = assert{'mul12 not supported', show{...x}} def unpackQ{...x} = assert{'unpackQ not supported', show{...x}} def packQ{...x} = assert{'packQ not supported', show{...x}} def __mulhi{...x} = assert{'__mulhi not supported', show{...x}} +def fold_max {...x} = assert{'fold_max not supported', show{...x}} +def fold_min {...x} = assert{'fold_min not supported', show{...x}} +def fold_add {...x} = assert{'fold_add not supported', show{...x}} +def fold_addw{...x} = assert{'fold_addw not supported', show{...x}} +def cvt{...x} = assert{'cvt not supported', show{...x}} +def cvt{T, x:X & T==eltype{X}} = x +def shuf{...x} = assert{'shuf not supported', show{...x}} def min{a, b & knum{a} & knum{b}} = tern{ab, a, b} diff --git a/src/singeli/src/mask.singeli b/src/singeli/src/mask.singeli index e36ff230..71cae6cb 100644 --- a/src/singeli/src/mask.singeli +++ b/src/singeli/src/mask.singeli @@ -12,6 +12,7 @@ local def maskOfImpl{T, n, w} = load{*ty_u{T} ~~ (*u8~~mask256 + 32 - n*(elwidth # get mask of first n items; 0 ≤ n ≤ vcount{T} def maskOf{T,n & width{T}==256} = maskOfImpl{T, n, 256} def maskOf{T,n & width{T}==128} = maskOfImpl{T, n, 128} +def maskOf{T,n & width{T}== 64} = maskOfImpl{T, n, 64} def anyne{x:T, y:T, M & M{0}==0 & isvec{T}} = ~homAll{x==y} def anyne{x:T, y:T, M & M{0}==1 & isvec{T}} = homAny{M{x!=y}} diff --git a/src/singeli/src/neon.singeli b/src/singeli/src/neon.singeli index 8ee8d0de..8f8b7b09 100644 --- a/src/singeli/src/neon.singeli +++ b/src/singeli/src/neon.singeli @@ -47,8 +47,8 @@ def min{a:T,b:T & nvec{T}} = emit{T, ntyp{'vmin', T}, a, b} def max{a:T,b:T & nvec{T}} = emit{T, ntyp{'vmax', T}, a, b} def __shl{a:T,b:S & nveci{T} & nveci{S} & elwidth{T}==elwidth{S}} = emit{T, ntyp{'vshl', T}, a, ty_s{b}} -def __shl{a:T,b & nveci{T} & knum{b}} = emit{T, ntyp{'vshl', '_n', T}, a, b}; def __shl{a:T,b==0 & nveci{T}} = a -def __shr{a:T,b & nveci{T} & knum{b}} = emit{T, ntyp{'vshr', '_n', T}, a, b}; def __shr{a:T,b==0 & nveci{T}} = a +def __shl{a:T,b & nveci{T} & knum{b} & b>0 & b0 & b elwidth{X}*2} = widen{T, widen{ty_half{T}, x}} -def widen{T, x:X & n64{X} & isfloat{eltype{T}}!=isfloat{eltype{X}} & elwidth{T}>elwidth{X}} = cvt{T, widen{[vcount{T}](to_w{eltype{X},elwidth{T}}), x}} +def widen{T, x:X & n64{X} & isfloat{eltype{T}}!=isfloat{eltype{X}} & elwidth{T}>elwidth{X}} = cvt{eltype{T}, widen{[vcount{T}](to_w{eltype{X},elwidth{T}}), x}} def widen{T, x:X & n128{X} & vcount{X}>vcount{T}} = widen{T, half{x,0}} def narrow{T, x:X & n128{X} & eqqi{T,eltype{X}} & width{T}*2< elwidth{X}} = narrow{T, undefPromote{ty_half{X}, narrow{ty_half{eltype{X}}, x}}} diff --git a/src/singeli/src/squeeze.singeli b/src/singeli/src/squeeze.singeli index 1795fac6..3f59ce41 100644 --- a/src/singeli/src/squeeze.singeli +++ b/src/singeli/src/squeeze.singeli @@ -1,7 +1,11 @@ include './base' -include './sse3' -include './avx' -include './avx2' +if (hasarch{'X86_64'}) { + include './sse3' + include './avx' + include './avx2' +} else if (hasarch{'AARCH64'}) { + include './neon' +} include './mask' include './cbqnDefs' include 'util/tup'