aboutsummaryrefslogtreecommitdiffstats
path: root/OpenAL32
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2018-04-21 21:07:20 -0700
committerChris Robinson <[email protected]>2018-04-21 21:07:20 -0700
commitace8e648509a1afa587a4e6c778e37a2e854e496 (patch)
tree6517ff5a60126388d3d3759118f82ceff1e58913 /OpenAL32
parent4ee26f4ca3dc952dc9d7fdf58b735396b798df9c (diff)
Only use fast float-to-int workarounds for x87
At least SSE and ARM have opcodes that handle float-to-int conversions well enough. Also, Clang doesn't inline lrintf, incurring function call overhead for what should be a single opcode.
Diffstat (limited to 'OpenAL32')
-rw-r--r--OpenAL32/Include/alMain.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h
index 48d8fb4a..78dd01c5 100644
--- a/OpenAL32/Include/alMain.h
+++ b/OpenAL32/Include/alMain.h
@@ -230,6 +230,21 @@ inline size_t RoundUp(size_t value, size_t r)
* mode. */
inline ALint fastf2i(ALfloat f)
{
+#if (defined(__i386__) && !defined(__SSE_MATH__)) || (defined(_M_IX86_FP) && (_M_IX86_FP == 0))
+/* If using the x87 instruction set, try to use more efficient float-to-int
+ * operations. The fistp instruction converts to integer efficiently enough,
+ * but it isn't IEEE-754-compliant because it uses the current rounding mode
+ * instead of always truncating -- the compiler will generate costly control
+ * word changes with it to get correct behavior. If supported, lrintf converts
+ * to integer using the current rounding mode, i.e. using fistp without control
+ * word changes (if nothing even better is available). As long as the rounding
+ * mode is set to round-to-zero ahead of time, and the call gets inlined, this
+ * works fine.
+ *
+ * Other instruction sets, like SSE and ARM, have opcodes that inherently do
+ * the right thing, and don't suffer from the same excessive performance
+ * degredation from float-to-int conversions.
+ */
#ifdef HAVE_LRINTF
return lrintf(f);
#elif defined(_MSC_VER) && defined(_M_IX86)
@@ -240,6 +255,9 @@ inline ALint fastf2i(ALfloat f)
#else
return (ALint)f;
#endif
+#else
+ return (ALint)f;
+#endif
}