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!