Saurabh T wrote: > >>On Fri, Oct 24, 2008 at 7:21 PM, Saurabh T wrote: >> >>>I am seeing different results from running an executable on its own vs with >>>valgrind. The culprit is a simple C++ function that returns the square of >>>the double passed to it (the double value is exactly the same (upto >>>precision 20 at least); the square's 16th significant digit differs). The >>>function happens to be inline. Is it a bug that valgrind changes the output >>>of an executable? Is there an option etc to not make this happen? Because of >>>the different results, I'm unable to use valgrind to track the real problem >>>in the code. >>> >>>I tried adding the same numbers and function to a standalone program but >>>that works fine. All code was built with -m32 -O2 and no other flags. gcc is >>>4.1, rhel 5; valgrind is 3.3.1 built on both amd64-linux and x86-linux. >> >>Please read the section about floating point support in the Valgrind >>manual (http://valgrind.org/docs/manual/manual-core.html) -- Valgrind >>e.g. does not support 80 bit arithmetic. >> >>Bart. > > > Maybe I'm missing something but I didnt find anything relevant - the code I'm > talking about does not use long double at all. > saurabh
Indeed you are missing something. How x86 floating point works. By default, 32bit x86 uses the x87 floating point coprocessor. This uses 80bit arithmetic. For expressions in general, the input is converted from 64bit doubles to 80bit, then the expression is evaluated, and the result is then converted back to 64bit. For simple operations, there is no difference. For longer expressions, then the fact that more subexpressions are evaluated at 80bits means that differences due to the higher precision will creep in. You might consider trying the SSE instructions (look for sse options in the GCC man page, and maybe also -ffloat-store). When using this option, arithmetic is performed at 64bits, and you should get the same results as Valgrind. x64 defaults to using SSE, so I'd expect that x86 and Valgrind would also give the same results. A+ Paul ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Valgrind-users mailing list Valgrind-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/valgrind-users