[Mesa-dev] [RFC PATCH] mesa: Replace _mesa_round_to_even() with roundeven().
Ilia Mirkin
imirkin at alum.mit.edu
Wed Mar 11 15:04:28 PDT 2015
On Wed, Mar 11, 2015 at 5:52 PM, Matt Turner <mattst88 at gmail.com> wrote:
> +static inline float
> +roundevenf(float x)
> +{
> + float ret;
> +#ifdef __SSE4_1__
> + __m128 m = _mm_load_ss(&x);
> + m = _mm_round_ss(m, m, _MM_FROUND_TO_NEAREST_INT | _MM_FROUND_NO_EXC);
> + _mm_store_ss(&ret, m);
> +#else
> + /* Assume that the floating-point rounding mode has not been changed from
> + * the default (Round to nearest).
> + */
> + ret = rintf(x);
> +#endif
> + return ret;
> +}
> +
> +static inline double
> +roundeven(double x)
> +{
> + double ret;
> +#ifdef __SSE4_1__
> + __m128d m = _mm_load_sd(&x);
> + m = _mm_round_sd(m, m, _MM_FROUND_TO_NEAREST_INT | _MM_FROUND_NO_EXC);
> + _mm_store_sd(&ret, m);
> +#else
> + /* Assume that the floating-point rounding mode has not been changed from
> + * the default (Round to nearest).
> + */
> + ret = rint(x);
> +#endif
> + return ret;
> +}
While I'm not opposed to this style of implementation, do note that
99.9999738% of users will end up with distro-compiled packages
targeting generic x86_64 and thus won't use the SSE variant. If it's
really better, might make sense to do it "for real" (i.e. runtime
selection), otherwise just let it go and use rint/rintf everywhere so
that developers (who build their own libraries, probably with the
"right" -march) will get the same behaviour as users.
-ilia
More information about the mesa-dev
mailing list