[gambit-list] Poor compilation of do-loops

Marc Feeley feeley at iro.umontreal.ca
Sun Oct 18 08:38:01 EDT 2009

On 2009-10-17, at 7:45 PM, Bradley Lucier wrote:

> If matrix-ref is inlined into the calculation
> 				  (fl+ a
> 				       (fl* (matrix-ref m1 i k)
> 					    (matrix-ref m2 k j))))))))))))))
> then there is even greater speedup, partly because no flonums need  
> to be
> boxed as return values of matrix-ref.  The compiler inlines some uses,
> but I tried to inline all uses with inlining-limit, but failed (bug  
> 117,
> I think), but after writing matrix-ref and matrix-set! as macros, I  
> get
> the following runtimes (on a different machine than before).
> Original code (but compiled using gsc -exe, so twice as fast as  
> original
> report, "with all possible optimizations turned on"):
>    1344 ms cpu time (1340 user, 4 system)
> Using declarations, fixnum- and flonum-specific operations, and
> f64vectors:
>    784 ms cpu time (776 user, 8 system)
> Using named let:
>    336 ms cpu time (328 user, 8 system)
> Inlining all (not just some) instances of matrix-ref and matrix-set!:
>    124 ms cpu time (120 user, 4 system)
> I'm planning to use Gambit again in my numerical PDE class next
> semester, so I'd like to win these benchmark games ;-).
> Brad

Adding the optimization you propose is certainly something interesting  
to explore.  However, it will not be done soon because the  
optimization depends on a nontrivial control flow analysis (to  
determine all the places in the code where the continuation of the do- 
loop may be invoked).  Jeremie Lasalle-Ratelle is currently  
implementing a 0-CFA and I believe his algorithm can be extended to  
perform the required analysis.

So to be safe you should plan teaching your students to avoid "do" by  
using named-let.


More information about the Gambit-list mailing list