Re: Optimization flag for unchecked fixnums in SBCL?

Liste des GroupesRevenir à cl lisp 
Sujet : Re: Optimization flag for unchecked fixnums in SBCL?
De : david (at) *nospam* harpegolden.net (David De La Harpe Golden)
Groupes : comp.lang.lisp
Date : 11. Aug 2024, 03:32:26
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v994bb$148i2$1@dont-email.me>
References : 1 2 3
User-Agent : Mozilla Thunderbird
On 10/08/2024 04:00, Paul Rubin wrote:

The "trick" of this Euler problem is that a few (only a few) of
the intermediate values will overflow a 32 bit word.  But, everyone uses
64 bit machines these days, so that part works anyway.
Ah, good point. (erm, last (signed-byte 29) part my prev post probably only worked because - at (safety 0) - it was indeed generating code using unchecked >32-bit signed arithmetic ops on my 64-bit machine anyway)
Worth noting in context that if you use sbcl with (safety 3) ON and use (signed-byte 32) say, though, then the type-declarations-as-assertions nicely catches the problem (at runtime with dynamic check)
     $ head -n2 collatz-signed-byte-32-inline-safe.lisp
     (declaim (optimize (speed 0) (safety 3) (debug 3)))
     (declaim (ftype (function ((signed-byte 32)) (values (signed-byte 32) &optional)) collatz))
     $ sbcl --control-stack-size 1024 --dynamic-space-size 65536
     * (compile-file "collatz-signed-byte-32-inline-safe.lisp")
     [...]
     * (load "collatz-signed-byte-32-inline-safe.fasl")
     debugger invoked on a TYPE-ERROR @535D60FF in thread
     #<THREAD "main thread" RUNNING {1001348003}>:
       The value
         2482111348
       is not of type
         (SIGNED-BYTE 32)
      from the function type declaration.
     Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL.
     restarts (invokable by number or by possibly-abbreviated name):
       0: [ABORT] Exit debugger, returning to top level.
     (COLLATZ 827370449)
Playing about for n 1000000, apparently (signed-byte 37) enough...
     $ sbcl --control-stack-size 2048 --dynamic-space-size 65536 --script collatz-signed-byte-36-inline-safe.lisp
     Unhandled TYPE-ERROR in thread #<SB-THREAD:THREAD "main thread" RUNNING
                                       {1001348003}>:
       The value
         34988856874
       is not of type
         (SIGNED-BYTE 36)
       from the function type declaration.
     [...]
     $ sbcl --control-stack-size 2048 --dynamic-space-size 65536 --script collatz-signed-byte-37-inline-safe.lisp
     (837799 525)

Date Sujet#  Auteur
7 Aug 24 * Optimization flag for unchecked fixnums in SBCL?9Paul Rubin
8 Aug 24 +* Re: Optimization flag for unchecked fixnums in SBCL?5Jeff Barnett
8 Aug 24 i+* Re: Optimization flag for unchecked fixnums in SBCL?2Kaz Kylheku
8 Aug 24 ii`- Re: Optimization flag for unchecked fixnums in SBCL?1Jeff Barnett
10 Aug 24 i`* Re: Optimization flag for unchecked fixnums in SBCL?2Paul Rubin
11 Aug 24 i `- Re: Optimization flag for unchecked fixnums in SBCL?1David De La Harpe Golden
8 Aug 24 +- Re: Optimization flag for unchecked fixnums in SBCL?1David De La Harpe Golden
11 Aug 24 `* Re: Optimization flag for unchecked fixnums in SBCL?2steve g
13 Aug 24  `- Re: Optimization flag for unchecked fixnums in SBCL?1Paul Rubin

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal