On 04/24/2013 01:33 PM, Mikael wrote:
Hi Brad!

2013/4/24 Bradley Lucier <lucier@math.purdue.edu>
On 04/24/2013 12:37 PM, Zhen Shen wrote:

[...]
 
> Now, doing (declare (flonum)) at the top level, does this stop gambit
> from boxing flonums across function calls?

No.  Gambit keeps flonums unboxed inside a basic block, whenever there's
a jump (or the possibility of a jump), Gambit boxes up all the
still-needed flonums.

What about fixnums, would they remain unboxed in a loop?

Yes.  Fixnums are always "immediate" (not boxed) values.


Also btw, are there any tricks that can be applied to make it keep flonums and fixnums unboxed in loops, like, (declare (not interrupts-enabled)) or (not safe)?

Use (declare (not safe)) and flonum-specific operations to keep flonums unboxed in a basic block.  There's no way to keep them unboxed across jumps.  (With generic operations, flonums are boxed even in a basic block.)

Or, you can use an f64vector as an explicit "box" for your flonum and write monstrous code like this.

(define (Array-sum a)
  (f64vector-ref (Array-reduce (lambda (result y)
                                 (f64vector-set! result 0 (fl+ (f64vector-ref result 0) y))
                                 result)
                               (f64vector 0.)
                               a)
                   0))

Brad