From 8f17560fa2aede38729419792e0e6f5f09dfd040 Mon Sep 17 00:00:00 2001 From: Douglas Katzman Date: Thu, 14 Sep 2017 12:58:06 -0400 Subject: [PATCH] Reserve 1 bit in bignum header for GC mark --- contrib/sb-gmp/gmp.lisp | 4 ++-- src/code/bignum.lisp | 5 +---- src/compiler/generic/vm-type.lisp | 12 ++++++------ 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/contrib/sb-gmp/gmp.lisp b/contrib/sb-gmp/gmp.lisp index c506c25b8..d054e29c6 100644 --- a/contrib/sb-gmp/gmp.lisp +++ b/contrib/sb-gmp/gmp.lisp @@ -330,7 +330,7 @@ pre-allocated bignum. The allocated bignum-length must be (1+ COUNT)." (defmacro with-mpz-results (pairs &body body) (loop for (gres size) in pairs for res = (gensym "RESULT") - collect `(when (> ,size sb-bignum::maximum-bignum-length) + collect `(when (> ,size sb-kernel::maximum-bignum-length) (error "Size of result exceeds maxim bignum length")) into checks collect `(,gres (struct gmpint)) into declares collect `(,res (%allocate-bignum ,size)) @@ -390,7 +390,7 @@ pre-allocated bignum. The allocated bignum-length must be (1+ COUNT)." collect `(__gmpz_init (addr ,gres)) into inits collect `(,size (abs (slot ,gres 'mp_size))) into resinits - collect `(when (> ,size (1- sb-bignum::maximum-bignum-length)) + collect `(when (> ,size (1- sb-kernel::maximum-bignum-length)) (error "Size of result exceeds maxim bignum length")) into checks collect `(,res (%allocate-bignum (1+ ,size))) into resallocs diff --git a/src/code/bignum.lisp b/src/code/bignum.lisp index f101ff8a6..722fea6d8 100644 --- a/src/code/bignum.lisp +++ b/src/code/bignum.lisp @@ -107,9 +107,6 @@ (defconstant digit-size sb!vm:n-word-bits) -(defconstant maximum-bignum-length (1- (ash 1 (- sb!vm:n-word-bits - sb!vm:n-widetag-bits)))) - (defconstant all-ones-digit (1- (ash 1 sb!vm:n-word-bits))) ;;;; internal inline routines @@ -1071,7 +1068,7 @@ (multiple-value-bind (digits n-bits) (truncate x digit-size) (let* ((bignum-len (or bignum-len (%bignum-length bignum))) (res-len (+ digits bignum-len 1))) - (when (> res-len maximum-bignum-length) + (when (> res-len sb!kernel::maximum-bignum-length) (error "can't represent result of left shift")) (if (zerop n-bits) (bignum-ashift-left-digits bignum bignum-len digits) diff --git a/src/compiler/generic/vm-type.lisp b/src/compiler/generic/vm-type.lisp index 10d85999c..8ce85d400 100644 --- a/src/compiler/generic/vm-type.lisp +++ b/src/compiler/generic/vm-type.lisp @@ -69,12 +69,12 @@ #.(- 62 (floor (log sb!xc:internal-time-units-per-second 2))))) (sb!xc:deftype bignum-element-type () 'sb!vm:word) -;;; FIXME: see also DEFCONSTANT MAXIMUM-BIGNUM-LENGTH in -;;; src/code/bignum.lisp. -- CSR, 2004-07-19 -(sb!xc:deftype bignum-index () - '(mod #.(1- (ash 1 (- sb!vm:n-word-bits sb!vm:n-widetag-bits))))) -(sb!xc:deftype bignum-length () - '(unsigned-byte #.(- sb!vm:n-word-bits sb!vm:n-widetag-bits))) +(defconstant maximum-bignum-length + ;; Compute number of bits in the maximum length's representation + ;; leaving one bit for a GC mark bit. + (ldb (byte (- sb!vm:n-word-bits sb!vm:n-widetag-bits 1) 0) -1)) +(sb!xc:deftype bignum-index () `(mod ,maximum-bignum-length)) +(sb!xc:deftype bignum-length () `(mod ,(1+ maximum-bignum-length))) ;;; an index into an integer (sb!xc:deftype bit-index () -- 2.11.4.GIT