some fixes for ubsan
This commit is contained in:
parent
9a00da6369
commit
0684fe5fcb
@ -326,6 +326,8 @@ B pick_c2(B t, B w, B x) {
|
|||||||
|
|
||||||
#ifdef __BMI2__
|
#ifdef __BMI2__
|
||||||
#include <immintrin.h>
|
#include <immintrin.h>
|
||||||
|
void storeu_u64(u64* p, u64 v) { memcpy(p, &v, 8); }
|
||||||
|
u64 loadu_u64(u64* p) { u64 v; memcpy(&v, p, 8); return v; }
|
||||||
#if SINGELI
|
#if SINGELI
|
||||||
#pragma GCC diagnostic push
|
#pragma GCC diagnostic push
|
||||||
#pragma GCC diagnostic ignored "-Wunused-variable"
|
#pragma GCC diagnostic ignored "-Wunused-variable"
|
||||||
|
|||||||
@ -1,11 +1,13 @@
|
|||||||
include './base'
|
include './base'
|
||||||
include './bmi2'
|
include './bmi2'
|
||||||
|
|
||||||
|
def storeu{p:T, i, v:eltype{T} & *u64==T} = emit{void, 'storeu_u64', p+i, v}
|
||||||
|
def loadu{p:T & *u64==T} = emit{eltype{T}, 'loadu_u64', p}
|
||||||
|
|
||||||
def comp8{w:*u64, X, r:*i8, l:u64} = {
|
def comp8{w:*u64, X, r:*i8, l:u64} = {
|
||||||
@for(w in reinterpret{*u8,w} over i to cdiv{l,8}) {
|
@for(w in *u8~~w over i to cdiv{l,8}) {
|
||||||
pc:= popc{w}
|
pc:= popc{w}
|
||||||
store{reinterpret{*u64,r}, 0, pext{promote{u64,X{}}, pdep{promote{u64, w}, cast{u64,0x0101010101010101}}*255}}
|
storeu{*u64~~r, 0, pext{promote{u64,X{}}, pdep{promote{u64, w}, cast{u64,0x0101010101010101}}*255}}
|
||||||
r+= pc
|
r+= pc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -19,10 +21,10 @@ def tab{n==0,l} = tup{0}
|
|||||||
c16lut:*u64 = tab{4,16}
|
c16lut:*u64 = tab{4,16}
|
||||||
|
|
||||||
def comp16{w:*u64, X, r:*i16, l:u64} = {
|
def comp16{w:*u64, X, r:*i16, l:u64} = {
|
||||||
@for(w in reinterpret{*u8,w} over i to cdiv{l,8}) {
|
@for(w in *u8~~w over i to cdiv{l,8}) {
|
||||||
def step{w} = {
|
def step{w} = {
|
||||||
pc:= popc{w}
|
pc:= popc{w}
|
||||||
store{reinterpret{*u64,r}, 0, pext{promote{u64,X{}}, load{c16lut, w}}} # TODO don't use unaligned store to make valgrind/ubsan happy
|
storeu{*u64~~r, 0, pext{promote{u64,X{}}, load{c16lut, w}}}
|
||||||
r+= pc
|
r+= pc
|
||||||
}
|
}
|
||||||
step{w&15}
|
step{w&15}
|
||||||
@ -31,8 +33,8 @@ def comp16{w:*u64, X, r:*i16, l:u64} = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
slash2{F, T}(w:*u64, x:*T, r:*T, l:u64) : void = {
|
slash2{F, T}(w:*u64, x:*T, r:*T, l:u64) : void = {
|
||||||
xv:= reinterpret{*u64, x}
|
xv:= *u64~~x
|
||||||
F{w, {} => {c:= *xv; xv+= 1; c}, r, l}
|
F{w, {} => {c:= loadu{xv}; xv+= 1; c}, r, l}
|
||||||
}
|
}
|
||||||
|
|
||||||
slash1{F, T, iota, add}(w:*u64, r:*T, l:u64) : void = {
|
slash1{F, T, iota, add}(w:*u64, r:*T, l:u64) : void = {
|
||||||
|
|||||||
@ -127,11 +127,11 @@ static void bit_cpy(u64* r, usz rs, u64* x, usz xs, usz l) {
|
|||||||
u64 ti = rs>>6;
|
u64 ti = rs>>6;
|
||||||
u64 ei = re>>6;
|
u64 ei = re>>6;
|
||||||
|
|
||||||
i64 dp = d>>6;
|
u64 dp = (u64)(d>>6);
|
||||||
u64 df = ((u64)d)&63u;
|
u64 df = ((u64)d)&63u;
|
||||||
#define RDF0 x[ti+dp]
|
#define RDFo(N) *(x + (i64)(ti+dp+N))
|
||||||
#define RDFp ((x[ti+dp] >> df) | (x[ti+dp+1] << (64-df)))
|
#define RDFp ((RDFo(0) >> df) | (RDFo(1) << (64-df)))
|
||||||
#define READ (df==0? RDF0 : RDFp)
|
#define READ (df==0? RDFo(0) : RDFp)
|
||||||
if (ti!=ei) {
|
if (ti!=ei) {
|
||||||
if (rs&63) {
|
if (rs&63) {
|
||||||
u64 m = (1ULL << (rs&63))-1;
|
u64 m = (1ULL << (rs&63))-1;
|
||||||
@ -139,7 +139,7 @@ static void bit_cpy(u64* r, usz rs, u64* x, usz xs, usz l) {
|
|||||||
ti++;
|
ti++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (df==0) for (; ti<ei; ti++) r[ti] = RDF0;
|
if (df==0) for (; ti<ei; ti++) r[ti] = RDFo(0);
|
||||||
else for (; ti<ei; ti++) r[ti] = RDFp;
|
else for (; ti<ei; ti++) r[ti] = RDFp;
|
||||||
|
|
||||||
if (re&63) {
|
if (re&63) {
|
||||||
@ -153,7 +153,7 @@ static void bit_cpy(u64* r, usz rs, u64* x, usz xs, usz l) {
|
|||||||
}
|
}
|
||||||
#undef READ
|
#undef READ
|
||||||
#undef RDFp
|
#undef RDFp
|
||||||
#undef RDF0
|
#undef RDFo
|
||||||
}
|
}
|
||||||
|
|
||||||
B vec_join(B w, B x); // consumes both
|
B vec_join(B w, B x); // consumes both
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user