1

C# cannot be coerced into deterministic floating point arithmetic, the designers seem to have considered the performance overhead too significant.

I'm trying to assess whether it would be possible to achieve deterministic floating point arithmetic by using just SIMD extensions. SSE appears to be deterministic, within reason.

Is there any reason that this would not work?

Community
  • 1
  • 1
Mr. Smith
  • 4,288
  • 7
  • 40
  • 82
  • Just for information, what are you planning to implement with such floating point precision requirement ? – rducom Feb 14 '15 at 23:13
  • I'm speculating here, but might this fail on systems that lack the necessary SIMD instructions? You could get "graceful" degradation to elementwise broken math or outright failure. – tmyklebu Feb 14 '15 at 23:59
  • @tmyklebu SSE was introduced in 1999, and [allegedly](http://en.wikipedia.org/wiki/Streaming_SIMD_Extensions) "*many scientific applications refuse to run unless the CPU supports SSE2 or SSE3.*". I think it would be rare to find PCs that don't support it these days. – Mr. Smith Feb 15 '15 at 00:20
  • 1
    @Mr.Smith: IIRC, SSE2 is the instruction set used to implement double-precision floating-point math by typical compilers on x86_64. It showed up with the P4. Yes, lots of code will blow up without SSE2; this is partially because SSE2 is so much faster and partially because floating-point as implemented by many compilers does not have any semantics whatsoever without SSE2. I'm raising a fairly theoretical issue here; what happens if you use the SIMD extensions on a P3? Best case is it bombs out, worst is it silently gives you broken arithmetic. – tmyklebu Feb 15 '15 at 00:53
  • 2
    Writing a program that gets identical results on different systems, even if those results are an approximation to the real number arithmetic result, is not an unreasonable requirement. Java has a combination of strictfp and a StrictMath library that ensures reproducible results even at a cost in performance. – Patricia Shanahan Feb 15 '15 at 03:29

1 Answers1

0

The answer to your question is a qualified yes -- you need SSE2, not just SSE, to do this; in fact, the x86-64 ABI on both Windows and Linux uses SSE2 for floating point arithmetic by default, which is why the .NET 64bit JIT uses SSE2 FP as well.

The problem with the original SSE (as seen on the Pentium III) is that it only supports single precision, which is not sufficient to get you a full-fledged floating point environment. Trying to run code that uses SSE2 on a processor that doesn't support it should trigger an illegal instruction trap.

LThode
  • 1,843
  • 1
  • 17
  • 28