> I am guessing based purely on my experience with being able to say in C/C++
>
> static const double <variable-name> = <compile-time-expression>;
>
> compared with
>
> const double <variable-name> = <compile-time-expression>;
>
> As things get more complex, the former comes out in front. For example
>
> #include <stdio.h>
> #include <math.h>
>
> #define SQRT_TWO sqrt(fabs(-2.0))
>
> main()
> {
> static const double sqrtTwo = SQRT_TWO;
> static const double sqrtHalf = SQRT_TWO * 0.5;
>
> printf("Look Ma - no sqrt() call! %16.8f %16.8f\n", sqrtTwo, sqrtHalf);
> return(0);
> }
>
> Compile this with 'gcc', even without the optimizer, and the sqrt() call is
> done by the compiler. Note that 'gcc' complains a bit but still does what it
> is asked. Look at the assembler and there is no trace of any call to 'sqrt()'
> or 'fabs()'.
I'm too close to bedtime to try this myself, but I'm not seeing why:
const sqrtTwo = sqrt(fabs(-2.0));
const sqrtHalf = sqrt(fabs(-2.0))*0.5;
writeln((sqrtTwo, sqrtHalf));
would necessarily break the back-end compiler's optimization of the
sqrt/fabs calls. The only guess I can come up with is that the pesky
Chapel compiler inserts temps that break the C expressions up across
multiple statements and break a pattern-matching based optimization in
gcc.
That said, I understand that by making it a full-fledged param function,
you could rest assured that it would happen at compile-time rather than
crossing your fingers and hoping for the best -- and that's a philosophy I
subscribe to.
> I think that the 'sqrt' case would be quite hard in Chapel because you would
> need either need an overloaded 'sqrt'
>
> proc sqrt(param x : real(w)) param
> {
> }
>
> or have some other smarts in the compiler. And that opens up a whole new ball
> game.
Right, you would definitely need functions like this (along with their
bodies) if you wanted 'chpl' to compute sqrt() or the like at compile
time.
-Brad
------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Chapel-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-users