[Mesa-dev] [PATCH] i965/tiled_memcpy: don't unconditionally use __builtin_bswap32
Patrick Baggett
baggett.patrick at gmail.com
Tue Apr 19 18:03:21 UTC 2016
On Mon, Apr 18, 2016 at 9:31 PM, Jonathan Gray <jsg at jsg.id.au> wrote:
> Use the defines Mesa configure sets to indicate presence of the bswap32
> builtins. This lets i965 work on OpenBSD again after the changes that
> were made in 0a5d8d9af42fd77fce1492d55f958da97816961a.
>
> Signed-off-by: Jonathan Gray <jsg at jsg.id.au>
> ---
> src/mesa/drivers/dri/i965/intel_tiled_memcpy.c | 15 ++++++++++++++-
> 1 file changed, 14 insertions(+), 1 deletion(-)
>
> diff --git a/src/mesa/drivers/dri/i965/intel_tiled_memcpy.c
> b/src/mesa/drivers/dri/i965/intel_tiled_memcpy.c
> index a549854..c888e46 100644
> --- a/src/mesa/drivers/dri/i965/intel_tiled_memcpy.c
> +++ b/src/mesa/drivers/dri/i965/intel_tiled_memcpy.c
> @@ -64,6 +64,19 @@ ror(uint32_t n, uint32_t d)
> return (n >> d) | (n << (32 - d));
> }
>
> +static inline uint32_t
> +bswap32(uint32_t n)
> +{
> +#if defined(HAVE___BUILTIN_BSWAP32)
> + return __builtin_bswap32(n);
> +#else
> + return (n >> 24) |
> + ((n >> 8) & 0x0000ff00) |
> + ((n << 8) & 0x00ff0000) |
> + (n << 24);
> +#endif
> +}
>
If I recall, GCC recognizes an open-coded byte swapping funciton and will
replace it with the BSWAP instruction. I'm about 99% sure it is not
necessary to use __built_bswap32() to have the benefits of using BSWAP.
While I understand that you're trying to fix the use of
__builtin_bswap32(), I don't think it is really necessary to continue to
use it in your wrapper function. I'm not sure about -O0 though... anyways,
maybe it isn't worth looking too hard into, but you might be able to drop
some of the ugly #if defined(....) stuff.
> +
> /**
> * Copy RGBA to BGRA - swap R and B.
> */
> @@ -76,7 +89,7 @@ rgba8_copy(void *dst, const void *src, size_t bytes)
> assert(bytes % 4 == 0);
>
> while (bytes >= 4) {
> - *d = ror(__builtin_bswap32(*s), 8);
> + *d = ror(bswap32(*s), 8);
> d += 1;
> s += 1;
> bytes -= 4;
> --
> 2.8.1
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20160419/3db11d9c/attachment-0001.html>
More information about the mesa-dev
mailing list