Mesa (master): u_math: add x86 optimized version of ifloor

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Apr 21 20:52:38 UTC 2020


Module: Mesa
Branch: master
Commit: 72acb66527df6f38c7b8b15fa5062a616d67074b
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=72acb66527df6f38c7b8b15fa5062a616d67074b

Author: Dylan Baker <dylan at pnwbakers.com>
Date:   Thu Sep  6 15:30:15 2018 -0700

u_math: add x86 optimized version of ifloor

This is copied from the one in src/mesa/main/imports.h, which is the
same otherwise.

Reviewed-by: Marek Olšák <marek.olsak at amd.com>
Reviewed-by: Kristian H. Kristensen <hoegsberg at google.com>
Reviewed-by: Matt Turner <mattst88 at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3024>

---

 src/util/u_math.h | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/src/util/u_math.h b/src/util/u_math.h
index 6c2cb5437c0..59266c16922 100644
--- a/src/util/u_math.h
+++ b/src/util/u_math.h
@@ -185,6 +185,23 @@ util_fast_pow(float x, float y)
 static inline int
 util_ifloor(float f)
 {
+#if defined(USE_X86_ASM) && defined(__GNUC__) && defined(__i386__)
+   /*
+    * IEEE floor for computers that round to nearest or even.
+    * 'f' must be between -4194304 and 4194303.
+    * This floor operation is done by "(iround(f + .5) + iround(f - .5)) >> 1",
+    * but uses some IEEE specific tricks for better speed.
+    * Contributed by Josh Vanderhoof
+    */
+   int ai, bi;
+   double af, bf;
+   af = (3 << 22) + 0.5 + (double)f;
+   bf = (3 << 22) + 0.5 - (double)f;
+   /* GCC generates an extra fstp/fld without this. */
+   __asm__ ("fstps %0" : "=m" (ai) : "t" (af) : "st");
+   __asm__ ("fstps %0" : "=m" (bi) : "t" (bf) : "st");
+   return (ai - bi) >> 1;
+#else
    int ai, bi;
    double af, bf;
    union fi u;
@@ -193,6 +210,7 @@ util_ifloor(float f)
    u.f = (float) af;  ai = u.i;
    u.f = (float) bf;  bi = u.i;
    return (ai - bi) >> 1;
+#endif
 }
 
 



More information about the mesa-commit mailing list