[gambit-list] Are flonums passed around within Gambit by value or reference? What's their bit width on 32 & 64bir archs?

Marc Feeley feeley at iro.umontreal.ca
Tue Dec 18 16:43:53 EST 2012


On 2012-11-13, at 11:01 AM, Mikael <mikael.rcv at gmail.com> wrote:

> Dear Marc,
> 
> Something I was curious about for long:
> 
> So fixnums are passed around in Gambit by value and all objects like closures, pairs, vectors and bignums are passed around by reference.

I prefer to use a different terminology.  Values of type "Scheme objects" (the C type ___SCMOBJ) are encoded using a machine word (32 or 64 bits) which I call an "object reference".  The bottom 2 bits of an object reference give some primary information on the object's type.  For example, when the bottom 2 bits are zero, the object is a fixnum (the upper bits encode an integer).  When the bottom bit is 1, the object is memory allocated.  This means that the object reference is in fact a pointer to a block of memory where the object's content is stored.  The first word of this block is the "header", which gives some secondary type information (is it a pair, vector, bignum, flonum, string, etc and the length of the object).

Object references are always passed by value.

> What about flonums?

> 
> 
> Also, what's the flonum bit width (exponent & fraction respectively) on 32 and 64bit architectures?

On both architectures, a flonum is a memory allocated object with a header and a 64 bit IEEE-754 floating point number.  When doing floating point calculations, the code generator can avoid the allocation of flonums for temporary values if their life is bound by the basic block where they are calculated.  For example, in this function:

(define (f x y) (flsqrt (fl+ (fl* x x) (fl* y y))))

there is only one flonum that will be allocated on the heap (the result of flsqrt).  The intermediate results (i.e. x*x, y*y, and x*x+y*y) are stored in C local variables.

Marc





More information about the Gambit-list mailing list