Re: Optimization flag for unchecked fixnums in SBCL?

Liste des GroupesRevenir à cl lisp 
Sujet : Re: Optimization flag for unchecked fixnums in SBCL?
De : jbb (at) *nospam* notatt.com (Jeff Barnett)
Groupes : comp.lang.lisp
Date : 08. Aug 2024, 03:17:22
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v916b5$3g9mg$1@dont-email.me>
References : 1
User-Agent : Mozilla Thunderbird
On 8/7/2024 1:42 PM, Paul Rubin wrote:
I looked in the manual and didn't see a way to do this.  The following
Haskell code (Euler problem 14) takes about 0.5 seconds on my old laptop:
      cl :: Int -> Int
     cl n = if odd n then 3*n+1 else n`quot`2
     dl n = (1+) . length . takeWhile (/= 1) . iterate cl $ n
     main = print . maximum $ [(dl n, n) | n <- [1..1000000]]
 Int is Haskell's built-in fixnum type.  Integer is bignums and that
version takes about 7 seconds.
 The below CL version takes 5 seconds (this is chopped down from a
memoized version that takes about 0.2 seconds).  I tried a few different
ways to tell the compiler that `collatz' should take and return fixnums,
but I didn't find the right way.  Any help?  Thanks.
      (defun collatz (n)
       (cond ((oddp n) (1+ (* 3 n)))
             (t (floor n 2))))
      (defun clen (n)
       (cond ((= n 1) 1)
             ((<= n 0) 'crash)
             (t (1+ (clen (collatz n))))))
      (defun run (&optional (n 1) (mi 0) (ma 0))
         (if (> n 1000000)
           (list mi ma)
           (let ((a (clen n))
                 (nn (1+ n)))
             (if (> a ma)
                 (run nn n a)
                 (run nn mi ma)))))
     (print (run))
     (terpri)
As a start, did you you try defining collatz and clen with defsubst? Did you try using declarations and their cousins? And did your CL system provide a decent, declaration-sensitive compiler?
In other words I'm not sure how and what you told the compiler or what compiler you were telling. What I recall about this muddle is that what a compiler (and system) did with declaration type things was highly implementation dependent so wouldn't be quite sure what to advise you.
Other than use defsubst. That should open code most anything in most any CL compiler-based system.
--
Jeff Barnett

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