extract bit array negation to function
This commit is contained in:
parent
6aca324da7
commit
a9737c22ea
@ -11,11 +11,13 @@ static inline B arith_recm(BB2B f, B x) {
|
||||
return withFill(r, fx);
|
||||
}
|
||||
|
||||
void bit_negatePtr(u64* rp, u64* xp, usz count) {
|
||||
for (usz i = 0; i < count; i++) rp[i] = ~xp[i];
|
||||
}
|
||||
B bit_negate(B x) { // consumes
|
||||
u64* xp = bitarr_ptr(x);
|
||||
u64* rp; B r = m_bitarrc(&rp, x);
|
||||
usz ia = BIT_N(IA(x));
|
||||
for (usz i = 0; i < ia; i++) rp[i] = ~xp[i];
|
||||
bit_negatePtr(rp, xp, BIT_N(IA(x)));
|
||||
decG(x);
|
||||
return r;
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
|
||||
#include "../core.h"
|
||||
#include "../utils/hash.h"
|
||||
#include "../utils/calls.h"
|
||||
#include "../utils/file.h"
|
||||
#include "../utils/wyhash.h"
|
||||
#include "../utils/time.h"
|
||||
@ -1228,7 +1229,7 @@ B bitop1(B f, B x, enum BitOp1 op, char* name) {
|
||||
}
|
||||
switch (op) { default: UD;
|
||||
case op_not: {
|
||||
usz l = n/64; NOUNROLL for (usz i=0; i<l; i++) rp[i] = ~xp[i];
|
||||
usz l = n/64; bit_negatePtr(rp, xp, l);
|
||||
usz q = (-n)%64; if (q) rp[l] ^= (~(u64)0 >> q) & (rp[l]^~xp[l]);
|
||||
} break;
|
||||
case op_neg: switch (ow) {
|
||||
|
||||
@ -89,8 +89,8 @@ bitAA{bitop}(dst:*u64, wr:*void, xr:*void, len:Size) : void = {
|
||||
@forNZ (dst, w in *u64~~wr, x in *u64~~xr over _ to cdiv{len,64}) dst = bitop{w,x}
|
||||
}
|
||||
|
||||
not(dst:*u64, x:*u64, len:Size) : void = { am:=cdiv{len,64}; @forNZ (dst,x over _ to am) dst = ~x }
|
||||
cpy(dst:*u64, x:*u64, len:Size) : void = { am:=cdiv{len,64}; @forNZ (dst,x over _ to am) dst = x }
|
||||
not(dst:*u64, x:*u64, len:Size) : void = { am:=cdiv{len,64}; emit{void, 'bit_negatePtr', dst, x, am} }
|
||||
cpy(dst:*u64, x:*u64, len:Size) : void = { am:=cdiv{len,64}; emit{void, 'memcpy', dst, x, am*8} }
|
||||
|
||||
bitAS{op}(dst:*u64, wr:*void, x:u64, len:Size) : void = { # show{'bitAS'}
|
||||
xf:f64 = interp_f64{x}
|
||||
|
||||
@ -27,3 +27,5 @@ CMP_DEF(le, AS);
|
||||
|
||||
#define CMP_AA_IMM(FN, ELT, WHERE, WP, XP, LEN) CMP_AA_CALL(CMP_AA_FN(FN, ELT), WHERE, WP, XP, LEN)
|
||||
#define CMP_AS_IMM(FN, ELT, WHERE, WP, X, LEN) CMP_AS_CALL(CMP_AS_FN(FN, ELT), WHERE, WP, X, LEN)
|
||||
|
||||
void bit_negatePtr(u64* rp, u64* xp, usz count); // count is number of u64-s
|
||||
Loading…
Reference in New Issue
Block a user