safe arithmetic: disable on windows

This commit is contained in:
hellerve 2020-04-24 10:28:00 +02:00
parent 73816b8e5a
commit 38af3d344a
4 changed files with 17 additions and 9 deletions

View File

@ -27,9 +27,11 @@
to non-refs.")
(register copy (λ [&Long] Long))
(register safe-add (λ [Long Long (Ref Long)] Bool))
(register safe-sub (λ [Long Long (Ref Long)] Bool))
(register safe-mul (λ [Long Long (Ref Long)] Bool))
(not-on-windows ; this seems to generate invalid code on some windows machines
(register safe-add (λ [Long Long (Ref Long)] Bool))
(register safe-sub (λ [Long Long (Ref Long)] Bool))
(register safe-mul (λ [Long Long (Ref Long)] Bool))
)
(register abs (λ [Long] Long))

View File

@ -1,10 +1,12 @@
(system-include "carp_safe_int.h")
(defmodule Int
(doc safe-add "Performs an addition and checks whether it overflowed.")
(register safe-add (λ [Int Int (Ref Int)] Bool))
(doc safe-sub "Performs an substraction and checks whether it overflowed.")
(register safe-sub (λ [Int Int (Ref Int)] Bool))
(doc safe-mul "Performs an multiplication and checks whether it overflowed.")
(register safe-mul (λ [Int Int (Ref Int)] Bool))
(not-on-windows ; this seems to generate invalid code on some windows machines
(doc safe-add "Performs an addition and checks whether it overflowed.")
(register safe-add (λ [Int Int (Ref Int)] Bool))
(doc safe-sub "Performs an substraction and checks whether it overflowed.")
(register safe-sub (λ [Int Int (Ref Int)] Bool))
(doc safe-mul "Performs an multiplication and checks whether it overflowed.")
(register safe-mul (λ [Int Int (Ref Int)] Bool))
)
)

View File

@ -10,6 +10,7 @@ Long Long__MUL_(Long x, Long y) {
Long Long__DIV_(Long x, Long y) {
return x / y;
}
#ifndef _WIN32
bool Long_safe_MINUS_add(Long x, Long y, Long* res) {
return __builtin_add_overflow(x, y, res);
}
@ -19,6 +20,7 @@ bool Long_safe_MINUS_sub(Long x, Long y, Long* res) {
bool Long_safe_MINUS_mul(Long x, Long y, Long* res) {
return __builtin_mul_overflow(x, y, res);
}
#endif
bool Long__EQ_(Long x, Long y) {
return x == y;
}

View File

@ -1,3 +1,4 @@
#ifndef _WIN32
bool Int_safe_MINUS_add(int x, int y, int* res) {
return __builtin_add_overflow(x, y, res);
}
@ -7,3 +8,4 @@ bool Int_safe_MINUS_sub(int x, int y, int* res) {
bool Int_safe_MINUS_mul(int x, int y, int* res) {
return __builtin_mul_overflow(x, y, res);
}
#endif