From: ·····@labs-n.bbn.com
Subject: RE: C is faster than lisp (lisp vs c++ / Rick Graham...)
Date: 
Message-ID: <33374o$cnn@info-server.bbn.com>
In article <·············@naggum.no> Erik Naggum <····@naggum.no> writes:
--> [·····@labs-n.bbn.com]
--> 
--> |   (dotimes (i 10000)
--> |     (* 123.4 i)
--> |     )
--> |   
--> |   each multiply seems to take 1.2 microseconds on my 25 MHz 32-bit
--> |   Explorer 2.
--> 
--> this is really _outstanding_.  on a SPARC 10, the following C program takes
--> 3 seconds to run when given an argument, and an imperctibly small number
--> with none, i.e., 3 microseconds per operation.

unfortunately, it's totally bogus.  Marty Hall, a person CLEARLY more
conversant on lisp compilers than I am, pointed out that the compiler
would have eliminated the multiply, since the result wasn't being used.
all I measured was 10000 loops of nothing.

the equivalent function, which didn't eliminate it:

(defun foo ()					; 0.197
  (let ((x 3.217))
    (declare (optimize (speed 3) (safety 0)))
    (dotimes (i 10000)
      (declare (integer i))
      (setq x (* x (float i)))
      )
    x)
  )

10k times, single-float, best optimization.  0.197 seconds for the whole
thing.  conses about 35 words, or some such--that's a dynamic
behavior,for reasons unknown to me.  that's 20 microseconds per.  still
good, but not great.  double-float time is 25 microseconds.  divide is
actually *faster*, but only about 1%.

disassembling this shows that it's only got 13 instructions, excluding
the FEF overhead. I don't know how many registers the LispChip has, but
it appears to be only one (!?) from looking at the assembly code. I
do'nt know the design, but the assembly code has several push and pop
instructions in it, which suggests that there's an on-chip
stack-register, and the there are two working registers for holding
numbers. the actual loop has three of these instructions in it, and my
(fading) knowledge of microprocessor design suggests that if they were
all registers they wouldn't be necessary here. or would you just have
different ones? been too long...

--> main (int argc, char ** argv)
--> {
-->     if (argc == 2) {
--> 	int i;
--> 	double d;
--> 	for (i = 0; i < 10000000; i++)
--> 	    d = 123.4 * i;
-->     }
-->     return 0;
--> }
--> 
--> of the three Common LISP implementations I have running here, interpreted
--> performance for your LISP expression is:
--> 
--> 	GCL	0.6 seconds
--> 	CLISP	2.2 seconds
--> 	CMUCL	4.1 seconds

those are decent numbmers. interpreted runtime on the E2-25 is ~9.8
seconds. for ten thousand cycles, single-float.

--> are you sure you meant _microseconds_, not milliseconds?

absolutely. the original number I gave was 0.012 seconds, but it was a
bogus number. the real one is 0.2 seconds.

Allegro 4.2 tells me it's 33 milliseconds for the compiled version,
i.e., about 3 microseconds per multiply.  and the dissassemble is
bigger, apparently.  looks like 104 words, and 28 instructions, 8 for
overhead.

 -- clint
From: Paul Fuqua
Subject: Re: C is faster than lisp (lisp vs c++ / Rick Graham...)
Date: 
Message-ID: <PF.94Aug21200446@elissa.hc.ti.com>
   Date: 19 Aug 1994 21:10:48 GMT
   From: ·····@labs-n.bbn.com

   disassembling this shows that it's only got 13 instructions, excluding
   the FEF overhead. I don't know how many registers the LispChip has, but
   it appears to be only one (!?) from looking at the assembly code. 

At the macroinstruction level, it's a stack machine, with some shortcuts
and warts in various places.  Most instructions leave their result(s) on
the stack, and args and locals are kept there (the top 1K is buffered
on-chip).  At the microcode level, it's mostly register-to-register with
32 pseudo-two-ported and 992 scratch registers (and at times in the past
we had experimental microcodes that implemented stack-accumulator and
register-window architectures).

As for the multiply speed, my memory and the 1987 chip spec suggest that
the only hardware assist was support for a two-bit-per-step Booth
algorithm for 32-bit integer multiply.  Plus, floats are consed;  header
word plus 32 or 64 bits of data (but consed in a special area that's
GC'd quickly and frequently).

Yeah, there are still some lispm people out here.  I'm typing this on a
Sun with the diamond keys mapped to Control and Control to Rubout (but I
read mail on the Explorer).

Paul Fuqua
Texas Instruments, Dallas, Texas                     ··@hc.ti.com