[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-bugs-dist
Subject:    [Bug 302234] New: fesetround() function does not affect FPU calculations
From:       Alexander Kuznetsov <akuz48 () gmail ! com>
Date:       2012-06-20 12:33:00
Message-ID: bug-302234-17878 () http ! bugs ! kde ! org/
[Download RAW message or body]

https://bugs.kde.org/show_bug.cgi?id=302234

            Bug ID: 302234
          Severity: normal
           Version: 3.7.0
          Priority: NOR
          Assignee: jseward@acm.org
           Summary: fesetround() function does not affect FPU calculations
    Classification: Unclassified
                OS: Linux
          Reporter: akuz48@gmail.com
          Hardware: Ubuntu Packages
            Status: UNCONFIRMED
         Component: general
           Product: valgrind

Created attachment 71983
  --> https://bugs.kde.org/attachment.cgi?id=71983&action=edit
Code to reproduce

Under valgrind floating point calculations produce different results.
Code that reproduces issue 
compile with 
gcc -g -o roundtest roundtest.c -lm
Then run round test under valgrind and without it.

Running from command line  gives
$ ./roundtest
DEFAULT i = 41, res = 5.12499999999999911182,     res1 =
5.12000000000000010658,     res1*100. = 512.00000000000000000000
FE_TONEAREST i = 41, res = 5.12499999999999911182,     res1 =
5.12000000000000010658,     res1*100. = 512.00000000000000000000
FE_UPWARD i = 41, res = 5.12499999999999911182,     res1 =
5.13000000000000078160,     res1*100. = 513.00000000000011368684
FE_DOWNWARD i = 41, res = 5.12499999999999911182,     res1 =
5.11999999999999921840,     res1*100. = 511.99999999999994315658

Note that FE_UPWARD mode produces res1 = 5.13000000000000078160.
While under valgrind it gives 

==15269== Memcheck, a memory error detector
==15269== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==15269== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==15269== Command: ./roundtest
==15269== 
DEFAULT i = 41, res = 5.12499999999999911182,     res1 =
5.12000000000000010658,     res1*100. = 512.00000000000000000000
FE_TONEAREST i = 41, res = 5.12499999999999911182,     res1 =
5.12000000000000010658,     res1*100. = 512.00000000000000000000
FE_UPWARD i = 41, res = 5.12499999999999911182,     res1 =
5.12000000000000010658,     res1*100. = 512.00000000000000000000
FE_DOWNWARD i = 41, res = 5.12499999999999911182,     res1 =
5.12000000000000010658,     res1*100. = 512.00000000000000000000
==15269== 
==15269== HEAP SUMMARY:
==15269==     in use at exit: 0 bytes in 0 blocks
==15269==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==15269== 
==15269== All heap blocks were freed -- no leaks are possible
==15269== 
==15269== For counts of detected and suppressed errors, rerun with: -v
==15269== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 2)

and gives res1 = 5.12000000000000010658 which is wrong. Correct is 5.13

Comment
As far as I understand fesetround() function on Intel platform sets rounding
mode in FPU state registers EFLAGS (for x87 instruction set) and MXSCR (for SSE
mmx instructions). It looks like valgrind does not correctly handle contents of
this registers and program run always in default rounding mode.

-- 
You are receiving this mail because:
You are watching all bug changes.
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic