[Mesa-dev] [PATCH 5/7] util: Use SSE intrinsics in _mesa_lroundeven{f, }.

Roland Scheidegger sroland at vmware.com
Mon Aug 3 16:17:57 PDT 2015


Am 03.08.2015 um 18:43 schrieb Matt Turner:
> gcc actually generates this for us now that we use -fno-math-errno
> (which is weird, since lrintf()/lrint() don't set errno) but clang still
> does not. Presumably helps MSVC as well.
> 
> Reduced .text size by 8.5k with gcc before -fno-math-errno.
> 
>    text     data      bss      dec      hex  filename
> 4935850   195136    26192  5157178   4eb13a  i965_dri.so before
> 4927225   195128    26192  5148545   4e8f81  i965_dri.so after
> ---
>  src/util/rounding.h | 22 ++++++++++++++++++++++
>  1 file changed, 22 insertions(+)
> 
> diff --git a/src/util/rounding.h b/src/util/rounding.h
> index 088cf86..b0c9918 100644
> --- a/src/util/rounding.h
> +++ b/src/util/rounding.h
> @@ -25,6 +25,12 @@
>  #define _ROUNDING_H
>  
>  #include <math.h>
> +#include <limits.h>
> +
> +#ifdef __x86_64__
> +#include <xmmintrin.h>
> +#include <emmintrin.h>
> +#endif
>  
>  #ifdef __SSE4_1__
>  #include <smmintrin.h>
> @@ -87,7 +93,15 @@ _mesa_roundeven(double x)
>  static inline long
>  _mesa_lroundevenf(float x)
>  {
> +#ifdef __x86_64__
> +#if LONG_BIT == 64
> +   return _mm_cvtss_si64(_mm_load_ss(&x));
> +#elif LONG_BIT == 32
> +   return _mm_cvtss_si32(_mm_load_ss(&x));
> +#endif
> +#else
>     return lrintf(x);
> +#endif
>  }
>  
>  /**
> @@ -97,7 +111,15 @@ _mesa_lroundevenf(float x)
>  static inline long
>  _mesa_lroundeven(double x)
>  {
> +#ifdef __x86_64__
> +#if LONG_BIT == 64
> +   return _mm_cvtsd_si64(_mm_load_sd(&x));
> +#elif LONG_BIT == 32
> +   return _mm_cvtsd_si32(_mm_load_sd(&x));
> +#endif
> +#else
>     return lrint(x);
> +#endif
>  }
>  
>  #endif
> 

Reviewed-by: Roland Scheidegger <sroland at vmware.com>

I'm wondering though if this is really exactly implementing lrintf why
we're using a different name and not just something like _mesa_lrintf().
Though arguably _mesa_roundeven is the same... A different name would be
more justifiable if this is not quite the same as lrintf (e.g. returning
int instead of long).
But anyway, that's not a deal breaker.

Roland



More information about the mesa-dev mailing list