commit d42bf83f3eb9a1bb6e233efc3080f6bd303eefa7
parent c5d94e5c3834651b8a0d2753dd775a4363b934e7
Author: Armin Preiml <apreiml@strohwolke.at>
Date: Fri, 3 Nov 2023 15:38:11 +0100
crypto::math: make eq0u32 param u32
The int parameter was inhereted from the BearSSL implementation. It does
not make any sense here though. It seems like some kind of a C
workaround (wild guess).
Signed-off-by: Armin Preiml <apreiml@strohwolke.at>
Diffstat:
7 files changed, 14 insertions(+), 12 deletions(-)
diff --git a/crypto/math/bits.ha b/crypto/math/bits.ha
@@ -1,6 +1,9 @@
// SPDX-License-Identifier: MPL-2.0
// (c) Hare authors <https://harelang.org>
+use types;
+
+
// Rotates a 32-bit unsigned integer left by k bits. k may be negative to rotate
// right instead, or see [[rotr32]].
export fn rotl32(x: u32, k: int) u32 = {
@@ -110,18 +113,17 @@ export fn equ32(x: u32, y: u32) u32 = {
};
// Returns 1 if 'x' is zero or 0 if not.
-export fn eq0u32(x: i32) u32 = {
- const q: u32 = x: u32;
- return ~(q | -q) >> 31;
+export fn eq0u32(x: u32) u32 = {
+ return ~(x | -x) >> 31;
};
@test fn eq0u32() void = {
assert(eq0u32(0) == 1);
assert(eq0u32(1) == 0);
assert(eq0u32(0x1234) == 0);
+ assert(eq0u32(types::U32_MAX) == 0);
};
-
// Returns 1 if x != y and 0 otherwise.
export fn nequ32(x: u32, y: u32) u32 = {
let q = x ^ y;
@@ -146,10 +148,10 @@ export fn gtu32(x: u32, y: u32) u32 = {
// Returns 1 if x >= y and 0 otherwise.
export fn geu32(x: u32, y: u32) u32 = notu32(gtu32(y, x));
-//
+
// Returns 1 if x < y and 0 otherwise.
export fn ltu32(x: u32, y: u32) u32 = gtu32(y, x);
-//
+
// Returns 1 if x <= y and 0 otherwise.
export fn leu32(x: u32, y: u32) u32 = notu32(gtu32(x, y));
diff --git a/makefiles/freebsd.aarch64.mk b/makefiles/freebsd.aarch64.mk
@@ -64,7 +64,7 @@ $(HARECACHE)/bufio.ssa: $(bufio_ha) $(HARECACHE)/bytes.td $(HARECACHE)/encoding_
@$(TDENV) $(HAREC) $(HARECFLAGS) -o $(HARECACHE)/bufio.ssa -t $(HARECACHE)/bufio.td.tmp -N bufio $(bufio_ha)
crypto_math_ha = crypto/math/arithm.ha crypto/math/bits.ha
-$(HARECACHE)/crypto_math.ssa: $(crypto_math_ha)
+$(HARECACHE)/crypto_math.ssa: $(crypto_math_ha) $(HARECACHE)/types.td
@mkdir -p -- "$(HARECACHE)"
@printf 'HAREC\t%s\n' "$@"
@$(TDENV) $(HAREC) $(HARECFLAGS) -o $(HARECACHE)/crypto_math.ssa -t $(HARECACHE)/crypto_math.td.tmp -N crypto::math $(crypto_math_ha)
diff --git a/makefiles/freebsd.riscv64.mk b/makefiles/freebsd.riscv64.mk
@@ -64,7 +64,7 @@ $(HARECACHE)/bufio.ssa: $(bufio_ha) $(HARECACHE)/bytes.td $(HARECACHE)/encoding_
@$(TDENV) $(HAREC) $(HARECFLAGS) -o $(HARECACHE)/bufio.ssa -t $(HARECACHE)/bufio.td.tmp -N bufio $(bufio_ha)
crypto_math_ha = crypto/math/arithm.ha crypto/math/bits.ha
-$(HARECACHE)/crypto_math.ssa: $(crypto_math_ha)
+$(HARECACHE)/crypto_math.ssa: $(crypto_math_ha) $(HARECACHE)/types.td
@mkdir -p -- "$(HARECACHE)"
@printf 'HAREC\t%s\n' "$@"
@$(TDENV) $(HAREC) $(HARECFLAGS) -o $(HARECACHE)/crypto_math.ssa -t $(HARECACHE)/crypto_math.td.tmp -N crypto::math $(crypto_math_ha)
diff --git a/makefiles/freebsd.x86_64.mk b/makefiles/freebsd.x86_64.mk
@@ -64,7 +64,7 @@ $(HARECACHE)/bufio.ssa: $(bufio_ha) $(HARECACHE)/bytes.td $(HARECACHE)/encoding_
@$(TDENV) $(HAREC) $(HARECFLAGS) -o $(HARECACHE)/bufio.ssa -t $(HARECACHE)/bufio.td.tmp -N bufio $(bufio_ha)
crypto_math_ha = crypto/math/arithm.ha crypto/math/bits.ha
-$(HARECACHE)/crypto_math.ssa: $(crypto_math_ha)
+$(HARECACHE)/crypto_math.ssa: $(crypto_math_ha) $(HARECACHE)/types.td
@mkdir -p -- "$(HARECACHE)"
@printf 'HAREC\t%s\n' "$@"
@$(TDENV) $(HAREC) $(HARECFLAGS) -o $(HARECACHE)/crypto_math.ssa -t $(HARECACHE)/crypto_math.td.tmp -N crypto::math $(crypto_math_ha)
diff --git a/makefiles/linux.aarch64.mk b/makefiles/linux.aarch64.mk
@@ -64,7 +64,7 @@ $(HARECACHE)/bufio.ssa: $(bufio_ha) $(HARECACHE)/bytes.td $(HARECACHE)/encoding_
@$(TDENV) $(HAREC) $(HARECFLAGS) -o $(HARECACHE)/bufio.ssa -t $(HARECACHE)/bufio.td.tmp -N bufio $(bufio_ha)
crypto_math_ha = crypto/math/arithm.ha crypto/math/bits.ha
-$(HARECACHE)/crypto_math.ssa: $(crypto_math_ha)
+$(HARECACHE)/crypto_math.ssa: $(crypto_math_ha) $(HARECACHE)/types.td
@mkdir -p -- "$(HARECACHE)"
@printf 'HAREC\t%s\n' "$@"
@$(TDENV) $(HAREC) $(HARECFLAGS) -o $(HARECACHE)/crypto_math.ssa -t $(HARECACHE)/crypto_math.td.tmp -N crypto::math $(crypto_math_ha)
diff --git a/makefiles/linux.riscv64.mk b/makefiles/linux.riscv64.mk
@@ -64,7 +64,7 @@ $(HARECACHE)/bufio.ssa: $(bufio_ha) $(HARECACHE)/bytes.td $(HARECACHE)/encoding_
@$(TDENV) $(HAREC) $(HARECFLAGS) -o $(HARECACHE)/bufio.ssa -t $(HARECACHE)/bufio.td.tmp -N bufio $(bufio_ha)
crypto_math_ha = crypto/math/arithm.ha crypto/math/bits.ha
-$(HARECACHE)/crypto_math.ssa: $(crypto_math_ha)
+$(HARECACHE)/crypto_math.ssa: $(crypto_math_ha) $(HARECACHE)/types.td
@mkdir -p -- "$(HARECACHE)"
@printf 'HAREC\t%s\n' "$@"
@$(TDENV) $(HAREC) $(HARECFLAGS) -o $(HARECACHE)/crypto_math.ssa -t $(HARECACHE)/crypto_math.td.tmp -N crypto::math $(crypto_math_ha)
diff --git a/makefiles/linux.x86_64.mk b/makefiles/linux.x86_64.mk
@@ -64,7 +64,7 @@ $(HARECACHE)/bufio.ssa: $(bufio_ha) $(HARECACHE)/bytes.td $(HARECACHE)/encoding_
@$(TDENV) $(HAREC) $(HARECFLAGS) -o $(HARECACHE)/bufio.ssa -t $(HARECACHE)/bufio.td.tmp -N bufio $(bufio_ha)
crypto_math_ha = crypto/math/arithm.ha crypto/math/bits.ha
-$(HARECACHE)/crypto_math.ssa: $(crypto_math_ha)
+$(HARECACHE)/crypto_math.ssa: $(crypto_math_ha) $(HARECACHE)/types.td
@mkdir -p -- "$(HARECACHE)"
@printf 'HAREC\t%s\n' "$@"
@$(TDENV) $(HAREC) $(HARECFLAGS) -o $(HARECACHE)/crypto_math.ssa -t $(HARECACHE)/crypto_math.td.tmp -N crypto::math $(crypto_math_ha)