Lisp HUG Maillist Archive

Optimizing aref

I have a function which looks something like this:

(defun xxx (x)
        (declare (optimize (debug 0) (float 0) (safety 0) (space 0) (speed 
3)))
        ...
        (let ((a (get-some-array x)))
                (declare (type (simple-array double-float 10) a))
                ...
                (let ((d (aref a 0)))
                        (declare (type double-float d))
                        ...)))

Looking through the disassembled code I can see that xxx is still calling 
"aref." I would have thought that aref would have been inlined as a simple 
offset calculation? Is that not possible in LispWorks--or am I doing 
something wrong?

(Btw, I also tried <gasp!> "(declare (inline aref))" and "(the 
double-float (aref a 0))".)


Unable to render article 2023 because of ":DEFAULT stream decoding error on #<SB-SYS:FD-STREAM for \"socket 192.168.43.216:64798, peer: 116.202.254.214:119\" {100749B423}>: the octet sequence #(246 115 99 104) cannot be decoded." error

Re: Optimizing aref


cartan@darkstar.cartan.de wrote on 03/13/2004 08:50:51 PM:

> MichaelL@frogware.com writes:
>
> > I have a function which looks something like this:
> >
> > (defun xxx (x)
> >         (declare (optimize (debug 0) (float 0) (safety 0)
> (space 0) (speed
> > 3)))
> >         ...
> >         (let ((a (get-some-array x)))
> >                 (declare (type (simple-array double-float 10) a))
>
> Try (simple-array double-float (10))...

No change. (Btw, the double-floats aren't being boxed/unboxed, so the type declaration is definitely working. I was just wondering if I could avoid a function call when de-referencing an array element.)

Unable to render article 2025 because of ":DEFAULT stream decoding error on #<SB-SYS:FD-STREAM for \"socket 192.168.43.216:64813, peer: 116.202.254.214:119\" {1005AF8AF3}>: the octet sequence #(246 115 99 104) cannot be decoded." error

Re: Optimizing aref

cartan@darkstar.cartan.de wrote on 03/13/2004 10:19:28 PM:

> MichaelL@frogware.com writes:
> 
> > cartan@darkstar.cartan.de wrote on 03/13/2004 08:50:51 PM:
> > 
> > > MichaelL@frogware.com writes:
> > > 
> > > > I have a function which looks something like this:
> > > > 
> > > > (defun xxx (x)
> > > >         (declare (optimize (debug 0) (float 0) (safety 0) 
> > > (space 0) (speed 
> > > > 3)))
> > > >         ...
> > > >         (let ((a (get-some-array x)))
> > > >                 (declare (type (simple-array double-float 10) a))
> > > 
> > > Try (simple-array double-float (10))...
> > 
> > No change. (Btw, the double-floats aren't being boxed/unboxed, so
> > the type declaration is definitely working. I was just wondering if
> > I could avoid a function call when de-referencing an array element.)
> 
> You're doing something wrong, then.  Try
> 
> CL-USER 15 > (compile (defun blark (a)
>                        (declare ((simple-array double-float (10)) a)
>                                 (optimize speed (safety 0) (float 0)))
>                        (incf (aref a 3) 1.0)
>                        a))
> BLARK
> NIL
> NIL
> 
> CL-USER 16 > (disassemble 'blark)
> 20714D82:
>        0:      55               push  ebp
>        1:      89E5             move  ebp, esp
>        3:      83EC14           sub   esp, 14
>        6:      C7042445140000   move  [esp], 1445
>       13:      DD402C           fldl  [eax+2C]
>       16:      DD05A8A47020     fldl  [2070A4A8]       ; 1.0
>       22:      DEC1             faddp st(1), st
>       24:      DD582C           fstpl [eax+2C]
>       27:      FD               std 
>       28:      C9               leave 
>       29:      C3               ret 
> NIL
> 
> for instance.

Yes, and (as you said originally) leaving the parens off the "10" makes a 
difference:

CL-USER 75 > (compile (defun blark (a)
                       (declare ((simple-array double-float 10) a)
                                (optimize speed (safety 0) (float 0)))
                       (incf (aref a 3) 1.0)
                       a))
BLARK
NIL
NIL

CL-USER 76 > (disassemble 'blark)
20669EF2:
       0:      55               push  ebp
       1:      89E5             move  ebp, esp
       3:      83EC14           sub   esp, 14
       6:      C7042445140000   move  [esp], 1445
      13:      50               push  eax
      14:      FF75E8           push  [ebp-18]
      17:      B502             moveb ch, 2
      19:      B800030000       move  eax, 300
      24:      FF15B8490020     call  [200049B8]       ; AREF
      30:      DD4004           fldl  [eax+4]
      33:      DD05201D6A20     fldl  [206A1D20]       ; 1.0
      39:      DEC1             faddp st(1), st
      41:      DD5DF8           fstpl [ebp-8]
      44:      83EC0C           sub   esp, C
      47:      C70424450C0000   move  [esp], C45
      54:      DD45F8           fldl  [ebp-8]
      57:      DD5C2404         fstpl [esp+4]
      61:      B501             moveb ch, 1
      63:      FF1530671120     call  [20116730]       ; 
SYSTEM::RAW-FAST-BOX-DOUBLE
      69:      50               push  eax
      70:      FF75E8           push  [ebp-18]
      73:      B503             moveb ch, 3
      75:      B800030000       move  eax, 300
      80:      FF15285B1120     call  [20115B28]       ; 
SETF::\"COMMON-LISP\"\ \"AREF\"
      86:      8B45E8           move  eax, [ebp-18]
      89:      FD               std 
      90:      C9               leave 
      91:      C3               ret 
      92:      90               nop 
      93:      90               nop 
NIL

I think I figured out went wrong when I tried it, though. My optimizations 
are declared in my defsystem through a semi-documented keyword. When I 
compile-system those optimizations are honored--but when I use the System 
Browser tool to compile they aren't...

Ah.

Thanks for the help!


Re: Optimizing aref

Unable to parse email body. Email id is 2036

Re: Optimizing aref

davef@xanalys.com wrote on 03/15/2004 01:56:17 PM:

> If you're saying that Systems > Compile did not honor your system's
> optimization setting, that sounds like a bug.
> 
> However, File > Compile in the System Browser simply does
> COMPILE-FILE, not COMPILE-SYSTEM.

I'm using the :optimize keyword in defsystem. If I compile-system, the 
keyword is honored; if I Systems > Compile or Execute Events it isn't. (Of 
course, it isn't really a *documented* keyword, but it is quite handy...)


Re: Optimizing aref

Unable to parse email body. Email id is 2087

Updated at: 2020-12-10 08:57 UTC