Re: float to pointer coercion (cost 13)
- From: Duane Rettig <duane@xxxxxxxxx>
- Date: 08 Apr 2005 15:07:35 -0700
rif <rif@xxxxxxx> writes:
> > Allegro CL does in fact provide for "non-descriptor" representations
> > of both single float and double float. It is called our "immediate-args"
> > facility, and it applies to return values as well as arguments. It
> > also not only applies to single-floats and double-floats, but machine
> > integers as well; if you have just overflowed a fixnum range, the
> > result need not be boxed up into a bignum; it can just be compiled as
> > immediate, as long as it stays within the 32 bit range (or 64-bit, for
> > 64-bit versions).
>
> May I ask how this works? Do you compile two versions of the
> function, one with immediate-args and one without, and decide which
> one to use at compile-time, depending on whether or not the calling
> function knows the return type?
Nope. The function is compiled once, but it is given two entry
points. The "normal" entry point is actually at the beginning of
the code vector, and it jumps to a hook function, whose job it is
to unbox the arguments according to the spec and then "call" the
original function again, but to the immediate-args entry point.
Once the function is done, it returns to the hook function, which
boxes up the result. When a function is compiled that knows about
the immediate-function, it places its arguments according to the calling
standard, and calls the function at its secondary (immediate-args)
entry point. It is also responsible for handling any unboxed value
coming back, since the function will return directly to the caller.
Note that there are lots of caveats to a system like this, and the
specification method is pretty bogus, which is why we haven't
exported the functionality (though we give unofficial documentation
to any customer who asks for it). Here is an example on the amd64
(I notice that I need to do some optimizing - there is no need for
all the register movement in the floating point instructions):
CL-USER(1): (setf (get 'foo 'sys::immed-args-call)
'((double-float double-float) double-float))
((DOUBLE-FLOAT DOUBLE-FLOAT) DOUBLE-FLOAT)
CL-USER(2): (compile (defun foo (x y)
(declare (optimize speed (safety 0)) (double-float x y))
(+ x y)))
FOO
NIL
NIL
CL-USER(3): (disassemble *)
;; disassembly of #<Function FOO>
;; formals: X EXCL::DF_PLACE-HOLDER Y EXCL::DF_PLACE-HOLDER
;; code start: #x10009348f8:
0: 41 ff a7 3f 06 jmp *[r15+1599] ; SYS::IMMED-ARG-HOOK
00 00
7: f2 44 0f 10 e8 movsd xmm13,xmm0
12: f2 44 0f 10 e1 movsd xmm12,xmm1
17: f2 45 0f 58 ec addsd xmm13,xmm12
22: f2 41 0f 10 c5 movsd xmm0,xmm13
27: 4c 8b 74 24 10 movq r14,[rsp+16]
32: c3 ret
33: 90 nop
CL-USER(4):
So the "normal" entry point is at offset 0, and the "immediate" entry
is at offset 7 on this architecture. Note that there should be only
one floating point instruction, a "addsd xmm0,xmm1", but that should be
easy to fix.
When the garbage collector enounters one of these functions on the stack,
it has a spec list of argument kinds (one of single-float, double-float,
machine-integer, or lisp) and it will skip over the slots that aren't
lisp slots (if it didn't do this, there would be problems for bit
patterns that happened to look like lisp objects).
--
Duane Rettig duane@xxxxxxxxx Franz Inc. http://www.franz.com/
555 12th St., Suite 1450 http://www.555citycenter.com/
Oakland, Ca. 94607 Phone: (510) 452-2000; Fax: (510) 452-0182
.
- Follow-Ups:
- Re: float to pointer coercion (cost 13)
- From: Kent M Pitman
- Re: float to pointer coercion (cost 13)
- From: rif
- Re: float to pointer coercion (cost 13)
- References:
- float to pointer coercion (cost 13)
- From: Jacek Generowicz
- Re: float to pointer coercion (cost 13)
- From: Christophe Rhodes
- Re: float to pointer coercion (cost 13)
- From: Jacek Generowicz
- Re: float to pointer coercion (cost 13)
- From: Duane Rettig
- Re: float to pointer coercion (cost 13)
- From: rif
- float to pointer coercion (cost 13)
- Prev by Date: Re: Practical Common Lisp now shipping from Amazon
- Next by Date: Re: Practical Common Lisp now shipping from Amazon
- Previous by thread: Re: float to pointer coercion (cost 13)
- Next by thread: Re: float to pointer coercion (cost 13)
- Index(es):
Relevant Pages
|