|
From: Greg C. <chi...@co...> - 2006-03-22 17:46:14
|
On 2006-3-22 16:36 UTC, Douglas Vechinski wrote: > [Danny wrote:] >> OK. Looking at assembler code, the difference is that >> (1)current version of mingw doesn't use -ffast-math (replacing library >> calls by inline asm) by default. This is a safe default since library >> calls have greater range/accuracy near extremes than naked asm. Also >> libray calls may have side effect of setting fp errs. >> > By this, are you saying that there shouldn't be much of a time > difference between using or not using the -ffast-math flag under Mingw. No, quite the opposite. Safety has a cost. It can cost a lot of machine cycles. Another compiler might choose a faster but less safe default, which might be about as fast and about as safe as gcc with '-ffast-math'. Making it the default doesn't make it safer; it just expresses an opinion that the extra safeguards are generally not worth the cost. OTOH, gcc strives for closer conformance to the standard by default, despite the cost. >> (2) Not inlining sin -> fsin, cos -> fcos prevents other optimizations/ >> > Others have made some comments concerning fsin, fcos, etc. How does one > call these functions. fsin isn't a C function. It's an assembly-language instruction. > If done by the compiler if you use > -finline-functions or some other optimization flag, or is it something > one has to do in the source code. '-ffast-math' was suggested above. > Are fsin, fcos etc. calls that > directly map to something the CPU does to internally calculate it? They're assembly-language instructions that translate directly to machine code. For instance, FABS is assembled to 1101 1001 1110 0001 > Looking at the assembly code for a source that just calculates a sin of > a value, all I ever see is a " call _sin", I haven't ever seen a fsin > function. Step into that call in a debugger, and you'll presumably reach an FSIN instruction eventually. Try compiling your code with '-O1 -ffast-math' and then look at the assembly: 'call _sin' should be replaced by FSIN. The difference is all the stuff that the '_sin' library function does. Probably it checks arguments and sets things like errno as needed. Maybe it does something to scale arguments of extreme magnitude, too. That means you get the behavior required by the C standard in edge cases, and maybe more accurate results for very large values. You should be able to find, online somewhere, the source code that implements sin() in glibc, if you want to learn how one standard library does this. >> (3) GCC-3.4.5 is not smart enough even with --ffast-math to replace >> fsin/fcos calls with fsincos calls when advantageous (it is in your >> testcase). GCC-4.1 is. >> > What is the difference then between fsin/fcos and fsincos? Often, when you want a number's sine, you want its cosine too. There's a special instruction that gives both together at less cost than getting them both separately. |