Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[interpreter] fp tests fail on Windows 32 due to bit pattern mismatches #124

Closed
kg opened this issue Oct 10, 2015 · 5 comments
Closed

[interpreter] fp tests fail on Windows 32 due to bit pattern mismatches #124

kg opened this issue Oct 10, 2015 · 5 comments
Labels
interpreter issues that only affect the interpreter wontfix
Milestone

Comments

@kg
Copy link
Contributor

kg commented Oct 10, 2015

test/f64.wast:2326.1-2326.103: assert_return f64 operands have different bit patterns
test/float_misc.wast:92.1-92.141: assert_return f64 operands have different bit patterns

======================================================================
FAIL: test/f64.wast (__main__.RunTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "./runtests.py", line 37, in <lambda>
    return lambda self : self._runTestFile(*rec)
  File "./runtests.py", line 20, in _runTestFile
    self.assertEqual(0, exitCode, "test runner failed with exit code %i" % exitCode)
AssertionError: test runner failed with exit code 1

======================================================================
FAIL: test/float_misc.wast (__main__.RunTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "./runtests.py", line 37, in <lambda>
    return lambda self : self._runTestFile(*rec)
  File "./runtests.py", line 20, in _runTestFile
    self.assertEqual(0, exitCode, "test runner failed with exit code %i" % exitCode)
AssertionError: test runner failed with exit code 1
@sunfishcode
Copy link
Member

The test at float_misc.wast:92 is the first of a series of tests with the comment "Computations that round differently on x87", so it's likely that the bug here is OCaml using x87 arithmetic on Windows.

The problem with x87 math in this case is double rounding, with results being first rounded to 80-bit precision and then rounded from there to 64-bit precision. This gives different results in some cases than if the value had been rounded to 64-bit precision directly.

Possible workarounds

Is this a debug or opt build? If an opt build, does anyone know if there's a way to force ocaml to use sse math instead of x87 math? Alternatively, is this a 32-bit or 64-bit build? If 32-bit, are you able to try 64-bit? 64-bit is more likely to default to sse math. If a debug build, if I read the OCaml source correctly, fp math is implemented in C code, so would it be possible to recompile your OCaml installation with sse enabled? I see mentions of mingw in the documentation; if so, the requisite command-line flags may be -msse2 -mfp-math=sse. Alternatively, a 64-bit may be more likely to default to sse math.

Possible fixes

It's also theoretically possible to write the spec interpreter to work around this problem. While there are techniques for achieving the desired rounding behavior in terms of x87 operations, I think someone at some point mentioned that there are software floating point implementations available for OCaml, and for the spec repo that might be best, keeping things simple. All floating point logic in the spec is factored out into spec/f32.ml, spec/f64.ml, and spec/*_convert.ml, so it should be fairly straightforward to port.

@kripken
Copy link
Member

kripken commented Nov 13, 2015

I see this issue on 32-bit Linux as well, but not on 64-bit. So it definitely looks like an issue with 32-bit ocaml.

Btw, I also saw the problem on 32-bit gcc as well, on the binaryen interpreter. @sunfishcode showed me that can be avoided by telling gcc to not use x87, with the flags -msse2 -mfpmath=sse. So this looks like a common issue on 32-bit compilers.

@sunfishcode sunfishcode modified the milestone: Meta Jul 8, 2016
@rossberg rossberg changed the title fp tests fail on Windows due to bit pattern mismatches [interpreter] fp tests fail on Windows due to bit pattern mismatches May 18, 2017
@ericprud
Copy link

ericprud commented Sep 5, 2018

Is this still an issue or can it be closed now?

@rossberg
Copy link
Member

rossberg commented Sep 5, 2018

Still an issue for those who care about compiling on x86-32.

@binji binji added the interpreter issues that only affect the interpreter label May 22, 2019
@rossberg rossberg changed the title [interpreter] fp tests fail on Windows due to bit pattern mismatches [interpreter] fp tests fail on Windows 32 due to bit pattern mismatches Aug 4, 2022
@rossberg
Copy link
Member

rossberg commented Aug 4, 2022

Closing as "won't fix".

@rossberg rossberg closed this as completed Aug 4, 2022
rossberg pushed a commit that referenced this issue Sep 4, 2024
nmadd(x, y, z) == nmadd(-x, y, z)

the tests were doing -z instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter issues that only affect the interpreter wontfix
Projects
None yet
Development

No branches or pull requests

6 participants