Skip to content

Commit

Permalink
Fix overflow detection (bootstrap)
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel-serrano committed Dec 15, 2024
1 parent a310f98 commit 947d2cc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
10 changes: 6 additions & 4 deletions runtime/Include/bigloo_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/* ------------------------------------------------------------- */
/* Author : Manuel Serrano */
/* Creation : Thu Mar 2 05:40:03 2017 */
/* Last change : Fri Nov 15 08:00:26 2024 (serrano) */
/* Last change : Sun Dec 15 07:21:47 2024 (serrano) */
/* Copyright : 2017-24 Manuel Serrano */
/* ------------------------------------------------------------- */
/* Bigloo INTEGERs */
Expand Down Expand Up @@ -290,9 +290,11 @@ extern bool_t __builtinmull_overflow(long x, long y, long *res);
#endif

#if !BGL_NAN_TAGGING && TAG_INT != 0
# define BGL_ADDFX_OV(x, y, res) (__builtin_saddl_overflow(CINT(x), CINT(y), (long*)&res) || (res = BINT((long)res), 0))
# define BGL_SUBFX_OV(x, y, res) (__builtin_ssubl_overflow(CINT(x), CINT(y), (long*)&res) || (res = BINT((long)res), 0))
# define BGL_MULFX_OV(x, y, res) (__builtin_smull_overflow(CINT(x), CINT(y), (long*)&res) || (res = BINT((long)res), 0))
# define BGL_BINT_SANS_TAG(x) ((long)(x) & ~TAG_MASK)
# define BGL_BINT_WITH_TAG(x) ((obj_t)((long)(x) | TAG_INT))
# define BGL_ADDFX_OV(x, y, res) (__builtin_saddl_overflow(BGL_BINT_SANS_TAG(x), BGL_BINT_SANS_TAG(y), (long*)&res) || (res = BGL_BINT_WITH_TAG((long)res), 0))
# define BGL_SUBFX_OV(x, y, res) (__builtin_ssubl_overflow(BGL_BINT_SANS_TAG(x), BGL_BINT_SANS_TAG(y), (long*)&res) || (res = BGL_BINT_WITH_TAG((long)res), 0))
# define BGL_MULFX_OV(x, y, res) (__builtin_smull_overflow(BGL_BINT_SANS_TAG(x), CINT(y), (long*)&res) || (res = BGL_BINT_WITH_TAG((long)res), 0))
#endif

#if BGL_NAN_TAGGING
Expand Down
6 changes: 3 additions & 3 deletions runtime/Unsafe/bignumber-generic.sch
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;* ------------------------------------------------------------- */
;* Author : Manuel Serrano */
;* Creation : Thu Aug 29 07:41:07 2024 */
;* Last change : Thu Dec 12 10:10:18 2024 (serrano) */
;* Last change : Fri Dec 13 15:32:13 2024 (serrano) */
;* Copyright : 2024 Manuel Serrano */
;* ------------------------------------------------------------- */
;* Portable implementation of bignums. This is used only when no */
Expand Down Expand Up @@ -1128,7 +1128,7 @@
(int64->uint64 ($bignum->int64 x)))

;*---------------------------------------------------------------------*/
;* $seed-rand ... */
;* $seed-rand ... */
;*---------------------------------------------------------------------*/
(define ($seed-rand seed)
($srand seed)
Expand All @@ -1148,7 +1148,7 @@
(random-fill-u8vector! (make-u8vector len)))

;*---------------------------------------------------------------------*/
;* $randbx ... */
;* $randbx ... */
;*---------------------------------------------------------------------*/
(define ($randbx range::bignum)
(let* ((range-bits (bignum-integer-length range))
Expand Down

0 comments on commit 947d2cc

Please sign in to comment.