[Haskell-cafe] blas bindings, why are they so much slower the C?

Richard A. O'Keefe ok at cs.otago.ac.nz
Wed Jun 18 20:17:58 EDT 2008


On 19 Jun 2008, at 4:16 am, Anatoly Yakovenko wrote:
> C doesn't work like that :).  functions always get called.

Not true.  A C compiler must produce the same *effect* as if
the function had been called, but if by some means the compiler
knows that the function has no effect, it is entitled to skip
the call.  In particular, the C compiler I normally use offers
these pragmas, amongst others:

#pragma does_not_write_global_data (funcname [, funcname])
#pragma no_side_effect(funcname[, funcname])

So with a declaration like

	extern double cblas_ddot(
			int,
		        double const *, int,
                         double const *, int);
	#pragma no_side_effect (cblas_ddot)
>
the compiler would be completely within its rights to discard
any call to cblas_ddot() whose result was not used.  (As it
happens, it didn't, but it would have been allowed to.)
If using gcc,

	extern double cblas_ddot( ... as before ...)
		__attribute__ ((const));

seems to have the same effect, certainly the test case I tried
did in fact completely eliminate a call to cblas_ddot() when
so declared.

Since the malloc() results pointed to uninitialised memory,
the C compiler was entitled to do anything it pleased anyway.



More information about the Haskell-Cafe mailing list