move bit_sum to fold.c

This commit is contained in:
dzaima 2023-12-05 16:41:38 +02:00
parent a439c64e85
commit 9984d720c9
2 changed files with 8 additions and 6 deletions

View File

@ -293,6 +293,13 @@ B fold_c2(Md1D* d, B w, B x) { B f = d->f;
return c;
}
NOINLINE i64 bit_sum(u64* x, u64 am) {
i64 r = 0;
for (u64 i = 0; i < (am>>6); i++) r+= POPC(x[i]);
if (am&63) r+= POPC(x[am>>6]<<(64-am & 63));
return r;
}
u64 usum(B x) { // doesn't consume; will error on non-integers, or elements <0, or if sum overflows u64
assert(isArr(x));
u64 r = 0;

View File

@ -4,6 +4,7 @@
#include "../utils/talloc.h"
#include "../builtins.h"
#include <stdarg.h>
#include <math.h>
bool please_tail_call_err = true;
@ -360,12 +361,6 @@ NOINLINE void thrF(char* p, ...) {
}
i64 bit_sum(u64* x, u64 am) {
i64 r = 0;
for (u64 i = 0; i < (am>>6); i++) r+= POPC(x[i]);
if (am&63) r+= POPC(x[am>>6]<<(64-am & 63));
return r;
}
usz depthF(B x) { // doesn't consume
u64 r = 0;