title: How to control whether C math uses SSE2?
body: <p>I stepped into the assembly of the transcendental math functions of the C library with MSVC in fp:strict mode. They all seem to follow the same pattern, here's what happens for <code>sin</code>.</p>
  
  <p>First there is a dispatch routine from a file called "disp_pentium4.inc". It checks if the variable <code>___use_sse2_mathfcns</code> has been set; if so, calls <code>__sin_pentium4</code>, otherwise calls <code>__sin_default</code>.</p>
  
  <p><code>__sin_pentium4</code> (in "sin_pentium4.asm") starts by transferring the argument from the x87 fpu to the xmm0 register, performs the calculation using SSE2 instructions, and loads the result back in the fpu.</p>
  
  <p><code>__sin_default</code> (in "sin.asm") keeps the variable on the x87 stack and simply calls <code>fsin</code>.</p>
  
  <p>So in both cases, the operand is pushed on the x87 stack and returned on it as well, making it transparent to the caller, but if <code>___use_sse2_mathfcns</code> is defined, the operation is actually performed in SSE2 rather than x87.</p>
  
  <p>This behavior is very interesting to me because the x87 transcendental functions are notorious for having slightly different behaviors depending on the implementation, whereas a given piece of SSE2 code should always give reproducible results.</p>
  
  <p>Is there a way to determine for certain, either at compile or run-time, that the SSE2 code path will be used? I am not proficient writing assembly, so if this involves writing any assembly, a code example would be appreciated.</p>