[PATCH 1/5] wined3d: Use __builtin_clz() in wined3d_log2i() when available.
Henri Verbeet
hverbeet at codeweavers.com
Wed Dec 10 06:26:34 CST 2014
---
configure.ac | 9 +++++++++
dlls/wined3d/utils.c | 5 +++++
2 files changed, 14 insertions(+)
diff --git a/configure.ac b/configure.ac
index 400ee61..2773584 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2595,6 +2595,15 @@ AC_CHECK_FUNCS(\
)
LIBS="$ac_save_LIBS"
+dnl Check for __builtin_clz
+AC_CACHE_CHECK([for __builtin_clz], ac_cv_have___builtin_clz,
+ AC_LINK_IFELSE([AC_LANG_PROGRAM(,[[return __builtin_clz(1)]])],
+ [ac_cv_have___builtin_clz="yes"], [ac_cv_have___builtin_clz="no"]))
+if test "$ac_cv_have___builtin_clz" = "yes"
+then
+ AC_DEFINE(HAVE___BUILTIN_CLZ, 1, [Define to 1 if you have the `__builtin_clz' built-in function.])
+fi
+
dnl *** check for the need to define platform-specific symbols
case $host_cpu in
diff --git a/dlls/wined3d/utils.c b/dlls/wined3d/utils.c
index d3fb1d6..566d921 100644
--- a/dlls/wined3d/utils.c
+++ b/dlls/wined3d/utils.c
@@ -3929,8 +3929,12 @@ const struct wine_rb_functions wined3d_ffp_vertex_program_rb_functions =
wined3d_ffp_vertex_program_key_compare,
};
+/* Return the integer base-2 logarithm of x. Undefined for x == 0. */
UINT wined3d_log2i(UINT32 x)
{
+#ifdef HAVE___BUILTIN_CLZ
+ return __builtin_clz(x) ^ 0x1f;
+#else
static const UINT l[] =
{
~0U, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
@@ -3953,6 +3957,7 @@ UINT wined3d_log2i(UINT32 x)
UINT32 i;
return (i = x >> 16) ? (x = i >> 8) ? l[x] + 24 : l[i] + 16 : (i = x >> 8) ? l[i] + 8 : l[x];
+#endif
}
const struct blit_shader *wined3d_select_blitter(const struct wined3d_gl_info *gl_info, enum wined3d_blit_op blit_op,
--
1.7.10.4
More information about the wine-patches
mailing list