[Mesa-dev] [PATCH 1/3] util: Add util_memcpy_cpu_to_le32() v2

Patrick Baggett baggett.patrick at gmail.com
Fri Jul 18 13:26:00 PDT 2014


On Fri, Jul 18, 2014 at 2:10 PM, Tom Stellard <thomas.stellard at amd.com>
wrote:

> v2:
>   - Preserve word boundaries.
> ---
>  src/gallium/auxiliary/util/u_math.h | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
>
> diff --git a/src/gallium/auxiliary/util/u_math.h
> b/src/gallium/auxiliary/util/u_math.h
> index b9ed197..5de181a 100644
> --- a/src/gallium/auxiliary/util/u_math.h
> +++ b/src/gallium/auxiliary/util/u_math.h
> @@ -812,6 +812,23 @@ util_bswap16(uint16_t n)
>            (n << 8);
>  }
>
> +static INLINE void*
> +util_memcpy_cpu_to_le32(void *dest, void *src, size_t n)
>

I don't know where Mesa is with C99 standards, but if you are utilizing C99
keywords, I think "restrict" would help here to show that the two pointers
do not overlap. I'm not sure if have to mark 'd' and 's' as restrict to get
the benefit if they are initialized by a typecast, but it probably wouldn't
be a bad idea.

This may be a no-go with C++ however.


> +{
> +#ifdef PIPE_ARCH_BIG_ENDIAN
> +       size_t i, e;
> +       asset(n % 4 == 0);
> +
> +       for (i = 0, e = n / 4; i < e; i++) {
> +               uint32_t *d = (uint32_t*)dest;
> +               uint32_t *s = (uint32_t*)src;
> +               d[i] = util_bswap32(s[i]);
> +       }
> +       return dest;
> +#else
> +       return memcpy(dest, src, n);
> +#endif
> +}
>
>  /**
>   * Clamp X to [MIN, MAX].
> --
> 1.8.1.5
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20140718/6c9be01d/attachment.html>


More information about the mesa-dev mailing list