From f5939399f04ac96b71fae16413241d38d032ff10 Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Wed, 10 Dec 2014 13:26:34 +0100 Subject: [PATCH] wined3d: Use __builtin_clz() in wined3d_log2i() when available. --- configure | 33 +++++++++++++++++++++++++++++++++ configure.ac | 9 +++++++++ dlls/wined3d/utils.c | 5 +++++ include/config.h.in | 3 +++ 4 files changed, 50 insertions(+) diff --git a/configure b/configure index 2677e43cc04..e67969645f6 100755 --- a/configure +++ b/configure @@ -16448,6 +16448,39 @@ done LIBS="$ac_save_LIBS" +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __builtin_clz" >&5 +$as_echo_n "checking for __builtin_clz... " >&6; } +if ${ac_cv_have___builtin_clz+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ +return __builtin_clz(1) + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_have___builtin_clz="yes" +else + ac_cv_have___builtin_clz="no" +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_have___builtin_clz" >&5 +$as_echo "$ac_cv_have___builtin_clz" >&6; } +if test "$ac_cv_have___builtin_clz" = "yes" +then + +$as_echo "#define HAVE___BUILTIN_CLZ 1" >>confdefs.h + +fi + case $host_cpu in *i[3456789]86*) { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we need to define __i386__" >&5 diff --git a/configure.ac b/configure.ac index 8110995ccc9..6f4e7194fb2 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 d3fb1d69736..566d9211bc0 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, diff --git a/include/config.h.in b/include/config.h.in index 0370c6d34ad..a8ae6c576bf 100644 --- a/include/config.h.in +++ b/include/config.h.in @@ -1281,6 +1281,9 @@ /* Define to 1 if you have the `_vsnprintf' function. */ #undef HAVE__VSNPRINTF +/* Define to 1 if you have the `__builtin_clz' built-in function. */ +#undef HAVE___BUILTIN_CLZ + /* Define to 1 if you have the `__res_getservers' function. */ #undef HAVE___RES_GETSERVERS