Move xor-scan to scan.singeli; remove neq.singeli
This commit is contained in:
parent
e261e80168
commit
d16ba6c3b1
@ -651,7 +651,7 @@ cachedBin‿linkerCache ← {
|
|||||||
"xag"‿"src/builtins/sort.c"‿"bins"
|
"xag"‿"src/builtins/sort.c"‿"bins"
|
||||||
|
|
||||||
"2.."‿"src/builtins/select.c"‿"select", "xag"‿"src/builtins/scan.c"‿"scan",
|
"2.."‿"src/builtins/select.c"‿"select", "xag"‿"src/builtins/scan.c"‿"scan",
|
||||||
"2a."‿"src/builtins/slash.c"‿"constrep", "2.."‿"src/builtins/scan.c"‿"neq",
|
"2a."‿"src/builtins/slash.c"‿"constrep",
|
||||||
"xag"‿"src/builtins/slash.c"‿"slash", "2.."‿"src/builtins/slash.c"‿"count"
|
"xag"‿"src/builtins/slash.c"‿"slash", "2.."‿"src/builtins/slash.c"‿"count"
|
||||||
⟩
|
⟩
|
||||||
objs ← ⟨⟩
|
objs ← ⟨⟩
|
||||||
|
|||||||
@ -12,18 +12,14 @@ static u64 vg_rand(u64 x) { return x; }
|
|||||||
#if SINGELI
|
#if SINGELI
|
||||||
#define SINGELI_FILE scan
|
#define SINGELI_FILE scan
|
||||||
#include "../utils/includeSingeli.h"
|
#include "../utils/includeSingeli.h"
|
||||||
#if __PCLMUL__
|
|
||||||
#define SINGELI_FILE neq
|
|
||||||
#include "../utils/includeSingeli.h"
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
B scan_ne(B x, u64 p, u64 ia) { // consumes x
|
B scan_ne(B x, u64 p, u64 ia) { // consumes x
|
||||||
u64* xp = bitarr_ptr(x);
|
u64* xp = bitarr_ptr(x);
|
||||||
u64* rp; B r=m_bitarrv(&rp,ia);
|
u64* rp; B r=m_bitarrv(&rp,ia);
|
||||||
#if SINGELI_AVX2 && __PCLMUL__
|
#if SINGELI
|
||||||
clmul_scan_ne(p, xp, rp, BIT_N(ia));
|
si_scan_ne(p, xp, rp, BIT_N(ia));
|
||||||
#if USE_VALGRIND
|
#if USE_VALGRIND
|
||||||
if (ia&63) rp[ia>>6] = vg_def_u64(rp[ia>>6]);
|
if (ia&63) rp[ia>>6] = vg_def_u64(rp[ia>>6]);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -1,29 +0,0 @@
|
|||||||
include './base'
|
|
||||||
include './sse'
|
|
||||||
include './clmul'
|
|
||||||
|
|
||||||
fn clmul_scan_ne_any(x:*void, r:*void, init:u64, words:u64, mark:u64) : void = {
|
|
||||||
def V = [2]u64
|
|
||||||
m := V**mark
|
|
||||||
def xor64{a, i, carry} = { # carry is 64-bit broadcasted current total
|
|
||||||
p := clmul{a, m, i}
|
|
||||||
t := shr{[16]u8, p, 8}
|
|
||||||
s := p ^ carry
|
|
||||||
carry = s ^ t
|
|
||||||
s
|
|
||||||
}
|
|
||||||
xv := *V ~~ x
|
|
||||||
rv := *V ~~ r
|
|
||||||
e := words/2
|
|
||||||
c := V**init
|
|
||||||
@for (rv, xv over e) {
|
|
||||||
rv = apply{zipLo, (@collect (j to 2) xor64{xv, j, c})}
|
|
||||||
}
|
|
||||||
if (words & 1) {
|
|
||||||
storeLow{rv+e, 64, clmul{loadLow{xv+e, 64}, m, 0} ^ c}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn clmul_scan_ne_bit(init:u64, x:*u64, r:*u64, ia:u64) : void = {
|
|
||||||
clmul_scan_ne_any(*void~~x, *void~~r, init, ia, -(u64~~1))
|
|
||||||
}
|
|
||||||
export{'clmul_scan_ne', clmul_scan_ne_bit}
|
|
||||||
@ -1,5 +1,6 @@
|
|||||||
include './base'
|
include './base'
|
||||||
include './sse'
|
include './sse'
|
||||||
|
include './clmul'
|
||||||
include './avx'
|
include './avx'
|
||||||
include './avx2'
|
include './avx2'
|
||||||
include './mask'
|
include './mask'
|
||||||
@ -118,6 +119,40 @@ export{'si_scan_pluswrap_u8', scan_assoc_0{u8 , +}}
|
|||||||
export{'si_scan_pluswrap_u16', scan_assoc_0{u16, +}}
|
export{'si_scan_pluswrap_u16', scan_assoc_0{u16, +}}
|
||||||
export{'si_scan_pluswrap_u32', scan_assoc_0{u32, +}}
|
export{'si_scan_pluswrap_u32', scan_assoc_0{u32, +}}
|
||||||
|
|
||||||
|
# xor scan
|
||||||
|
fn scan_neq{}(p:u64, x:*u64, r:*u64, nw:u64) : void = {
|
||||||
|
@for (x, r over nw) {
|
||||||
|
def sc{v, k} = if (k==64) v else sc{v ^ (v<<k), 2*k}
|
||||||
|
r = p ^ sc{x, 1}
|
||||||
|
p = -(r>>63) # repeat sign bit
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn clmul_scan_ne_any{..._ & hasarch{'PCLMUL'}}(x:*void, r:*void, init:u64, words:u64, mark:u64) : void = {
|
||||||
|
def V = [2]u64
|
||||||
|
m := V**mark
|
||||||
|
def xor64{a, i, carry} = { # carry is 64-bit broadcasted current total
|
||||||
|
p := clmul{a, m, i}
|
||||||
|
t := shr{[16]u8, p, 8}
|
||||||
|
s := p ^ carry
|
||||||
|
carry = s ^ t
|
||||||
|
s
|
||||||
|
}
|
||||||
|
xv := *V ~~ x
|
||||||
|
rv := *V ~~ r
|
||||||
|
e := words/2
|
||||||
|
c := V**init
|
||||||
|
@for (rv, xv over e) {
|
||||||
|
rv = apply{zipLo, (@collect (j to 2) xor64{xv, j, c})}
|
||||||
|
}
|
||||||
|
if (words & 1) {
|
||||||
|
storeLow{rv+e, 64, clmul{loadLow{xv+e, 64}, m, 0} ^ c}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn scan_neq{..._ & hasarch{'PCLMUL'}}(init:u64, x:*u64, r:*u64, nw:u64) : void = {
|
||||||
|
clmul_scan_ne_any{}(*void~~x, *void~~r, init, nw, -(u64~~1))
|
||||||
|
}
|
||||||
|
export{'si_scan_ne', scan_neq{}}
|
||||||
|
|
||||||
# Boolean cumulative sum
|
# Boolean cumulative sum
|
||||||
fn bcs{T}(x:*u64, r:*T, l:u64) : void = {
|
fn bcs{T}(x:*u64, r:*T, l:u64) : void = {
|
||||||
def bitp_get{arr, n} = (load{arr, n>>6} >> (n&63)) & 1
|
def bitp_get{arr, n} = (load{arr, n>>6} >> (n&63)) & 1
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user