commit 0d248a7dd9869e68fa1847920d775d3f453f6384
parent 26f69ca26b9d003e6ed7a5c095aeaa449c35bcaf
Author: Sebastian <sebastian@sebsite.pw>
Date: Tue, 5 Sep 2023 22:14:48 -0400
math: remove non-u64 popcount variants
These were all aliases of pop_count_u64 anyway.
Also renames pop_count to popcount, since this is the more common naming
afaict.
Signed-off-by: Sebastian <sebastian@sebsite.pw>
Diffstat:
2 files changed, 6 insertions(+), 25 deletions(-)
diff --git a/math/uints.ha b/math/uints.ha
@@ -279,19 +279,7 @@ export fn trailing_zeros_u64(x: u64) u8 = {
};
// Returns the number of bits set (the population count) of x.
-export fn pop_count_u(x: uint) u8 = pop_count_u64(x: u64);
-
-// Returns the number of bits set (the population count) of x.
-export fn pop_count_u8(x: u8) u8 = pop_count_u64(x: u8);
-
-// Returns the number of bits set (the population count) of x.
-export fn pop_count_u16(x: u16) u16 = pop_count_u64(x: u64);
-
-// Returns the number of bits set (the population count) of x.
-export fn pop_count_u32(x: u32) u32 = pop_count_u64(x: u64);
-
-// Returns the number of bits set (the population count) of x.
-export fn pop_count_u64(x: u64) u8 = {
+export fn popcount(x: u64) u8 = {
let i = 0u8;
for (x != 0; x >>= 1) {
if (x & 1 == 1) {
@@ -301,17 +289,10 @@ export fn pop_count_u64(x: u64) u8 = {
return i;
};
-@test fn pop_count_u() void = {
- assert(pop_count_u(0) == 0);
- assert(pop_count_u(0b11010110) == 5);
- assert(pop_count_u8(0) == 0);
- assert(pop_count_u8(0b11010110) == 5);
- assert(pop_count_u16(0) == 0);
- assert(pop_count_u16(0b11010110) == 5);
- assert(pop_count_u32(0) == 0);
- assert(pop_count_u32(0b11010110) == 5);
- assert(pop_count_u64(0) == 0);
- assert(pop_count_u64(0b11010110) == 5);
+@test fn popcount() void = {
+ assert(popcount(0) == 0);
+ assert(popcount(0b11010110) == 5);
+ assert(popcount(~0) == 64);
};
// Returns the sum with carry of x, y and carry: sum = x + y + carry.
diff --git a/os/+linux/platform_environ.ha b/os/+linux/platform_environ.ha
@@ -107,7 +107,7 @@ export fn cpucount() (int | errors::error) = {
let ret = 0;
for (let i = 0z; i < len(set.__bits); i += 1) {
- ret += math::pop_count_u64(set.__bits[i]): int;
+ ret += math::popcount(set.__bits[i]): int;
};
return ret;
};