chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Optimizing inner loops


From: Will M Farr
Subject: Re: [Chicken-users] Optimizing inner loops
Date: Tue, 29 Aug 2006 14:46:11 -0400

Carlos,

On Aug 29, 2006, at 2:10 PM, Carlos Pita wrote:

Hi!
I would like to know if it's possible to implement very efficient inner loops that do flonum number crunching over srfi-4 arrays, avoiding type checking at all. I understand from the manual that fp +, fp-, etc assume that their args are flonums, and from the faq that f64vector-ref and f64vector-ref! will be handled specially by the compilator under usual-integrations. But what does it exactly mean?

In safe mode, it seems like the fp+ and fp-, etc, will check their arguments (in spite of what the manual says, I've had errors thrown from them---and I think it's great that they do throw errors in safe mode). In my (unscientific) measurements, this hits you for a factor of about 10 relative to the equivalent c code.

Will the accesors type check their arguments? Or will, say, fixnums be "promoted" to f64? I wonder if it's possible to get (almost) C- performance, resigning type safety, for compiled code using fp family of operators and fp64 vectors.

In unsafe mode, I've measured speed hits as small as a factor of 3 relative to c---perhaps others on this list could comment on their own benchmarks.

Thank you very much.
Regards, Carlos

Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
Probalo ya!
_______________________________________________
Chicken-users mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/chicken-users

The following seems to be the fastest way to implement a loop which, say, adds two vectors and stores the result into a third:

((foreign-lambda* void ((int n) (f64vector a) (f64vector b) (f64vector c))
"
int i;
for (i = 0; i < n; i++) {
     a[i] = b[i] + c[i];
}
")
 (f64vector-length a) a b c)

This has two disadvantages: 1. it's a lot of boring boiler-plate code to type for every fast floating-point operation and 2. it won't work in interpreted code. I've been wanting to improve on this for some time. At some point, I'll get some spare time and whip up a nice macro which uses (eval-when ...) to output the above at compile time, and uses the native scheme math operators when interpreted. Then you would have, for example,

(with-float-arithmetic
 (with-f64vectors (a b c)
   (a <- (+ b c))))

which works correctly when interpreted, and expands to the above when compiled (the (with-f64vectors ...) form comes from my blog post at http://wmfarr.blogspot.com/2005/06/making-scheme-behave-like- fortran-95.html ; though this post refers to Bigloo, it's pretty easy to make a syntax-rules analog for Chicken). If you want to go ahead and implement this, I'd think it was *really* neat!

Will





reply via email to

[Prev in Thread] Current Thread [Next in Thread]