[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: inline array refs?

At 10:14 AM 5/13/94 +0000, Karsten Poeck wrote:
>I translated some code to test iterative repair alogirithms from c to LISP.
>The code mainly does fixnum operations and simple-array accesses. By adding
>appropriate (the fixnum ...) and (declare (type (simple-array fixnum (*))
>I managed to get about half the speed of the corresponding c program
>compiled with MPW on the same mac.
>The disassembly of the code shows calls to subroutines
>(jsr_subprim $SP-GETLONG) and
>(jsr_subprim $SP-MKLONG)
>I suspect that these calls slow down the programm. Does anybody know what
>these routines do and how I could avoid them? I always thought that adding
>enough declarations to a MCL program would give me the same speed as a
>corresponding c program.
>Anyhow I tried to run the same program under LIspWorks 3.2 on a Dec-Alpha
>and to my surprise a quadra 650 was more than two times faster than the
>alpha, even after declaring fixnum-safety = 0. From looking at the
>disassembly I suspect that the arefs are not inlined in LispWorks. Does
>anybody know how I could get LispWorks to inline the arefs too?

I don't know how to inline arefs in LispWorks, but I can help with
your MCL problem. In MCL, an array that is declared to have fixnum
elements is upgraded to have (signed-byte 32) elements. Since these
can be bignums, the code is calling $sp-getlong to convert the
untagged value from the array to an integer. To get rid of the
$sp-getlong call, use a simple-vector, i.e. a simple-array with an
element type of T:

? (make-array 5 :element-type 'fixnum)
#(1112098638 1431130323 2147419255 503316495 1465010516)
? (type-of *)
? (make-array 5)
? (type-of *)
? (defun fast-aref (a i)
    (declare (type simple-vector a)
             (fixnum i)
             (optimize (speed 3) (safety 0)))
    (aref a i))
? (disassemble *)
2 (VPUSH D1)
4 (VPUSH D0)
10 (MOVE.L @VSP D1)
12 (ASR.L 1 D1)
14 (MOVE.L (ATEMP0 D1.L 7) D0)
20 (RTS)