<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Nov 20, 2014 at 12:48 AM, Iago Toral <span dir="ltr"><<a href="mailto:itoral@igalia.com" target="_blank">itoral@igalia.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Wed, 2014-11-19 at 14:15 -0600, Patrick Baggett wrote:<br>
><br>
><br>
> On Tue, Nov 18, 2014 at 3:23 AM, Iago Toral Quiroga<br>
> <<a href="mailto:itoral@igalia.com">itoral@igalia.com</a>> wrote:<br>
>         We have _mesa_swap{2,4} but these do in-place byte-swapping<br>
>         only. The new<br>
>         functions receive an extra parameter so we can swap bytes on a<br>
>         source<br>
>         input array and store the results in a (possibly different)<br>
>         destination<br>
>         array.<br>
><br>
><br>
><br>
> If this is being split into an "in-place" and "different pointers"<br>
> version, I think using the "restrict" keyword would be useful here to<br>
> improve the performance. Then, the in-place one cannot be implemented<br>
> as copy(p,p,n), but the code isn't overly complicated.<br>
<br>
</span>I did not know about 'restrict', thanks for the tip!.<br>
<br>
It kind of defeats the original idea of not duplicating the code but it<br>
is true that it is not particularly complex anyway, so maybe it is worth<br>
it if Jason agrees with having two versions of the functions instead of<br>
just one in the end. Jason, what do you think?<br></blockquote><div><br></div><div>The restrict keyword is a C99 thing and I don't think it's supported in MSVC so that would be a problem.  If it won't build with MSVC then it's a non-starter.  If MSVC can handle "restrict", then I don't know that I care much either way about 2 functions or 4<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<span class="HOEnZb"><font color="#888888"><br>
Iago<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
><br>
><br>
>         This is useful to implement byte-swapping in pixel uploads,<br>
>         since in this<br>
>         case we need to swap bytes on the src data which is owned by<br>
>         the<br>
>         application so we can't do an in-place byte swap.<br>
>         ---<br>
>          src/mesa/main/image.c | 25 +++++++++++++++++--------<br>
>          src/mesa/main/image.h | 10 ++++++++--<br>
>          2 files changed, 25 insertions(+), 10 deletions(-)<br>
><br>
>         diff --git a/src/mesa/main/image.c b/src/mesa/main/image.c<br>
>         index 4ea5f04..9ad97c5 100644<br>
>         --- a/src/mesa/main/image.c<br>
>         +++ b/src/mesa/main/image.c<br>
>         @@ -41,36 +41,45 @@<br>
><br>
><br>
>          /**<br>
>         - * Flip the order of the 2 bytes in each word in the given<br>
>         array.<br>
>         + * Flip the order of the 2 bytes in each word in the given<br>
>         array (src) and<br>
>         + * store the result in another array (dst). For in-place<br>
>         byte-swapping this<br>
>         + * function can be called with the same array for src and<br>
>         dst.<br>
>           *<br>
>         - * \param p array.<br>
>         + * \param dst the array where byte-swapped data will be<br>
>         stored.<br>
>         + * \param src the array with the source data we want to<br>
>         byte-swap.<br>
>           * \param n number of words.<br>
>           */<br>
>          void<br>
>         -_mesa_swap2( GLushort *p, GLuint n )<br>
>         +_mesa_swap2_copy( GLushort *dst, GLushort *src, GLuint n )<br>
>          {<br>
>             GLuint i;<br>
>             for (i = 0; i < n; i++) {<br>
>         -      p[i] = (p[i] >> 8) | ((p[i] << 8) & 0xff00);<br>
>         +      dst[i] = (src[i] >> 8) | ((src[i] << 8) & 0xff00);<br>
>             }<br>
>          }<br>
><br>
><br>
><br>
>          /*<br>
>         - * Flip the order of the 4 bytes in each word in the given<br>
>         array.<br>
>         + * Flip the order of the 4 bytes in each word in the given<br>
>         array (src) and<br>
>         + * store the result in another array (dst). For in-place<br>
>         byte-swapping this<br>
>         + * function can be called with the same array for src and<br>
>         dst.<br>
>         + *<br>
>         + * \param dst the array where byte-swapped data will be<br>
>         stored.<br>
>         + * \param src the array with the source data we want to<br>
>         byte-swap.<br>
>         + * \param n number of words.<br>
>           */<br>
>          void<br>
>         -_mesa_swap4( GLuint *p, GLuint n )<br>
>         +_mesa_swap4_copy( GLuint *dst, GLuint *src, GLuint n )<br>
>          {<br>
>             GLuint i, a, b;<br>
>             for (i = 0; i < n; i++) {<br>
>         -      b = p[i];<br>
>         +      b = src[i];<br>
>                a =  (b >> 24)<br>
>                 | ((b >> 8) & 0xff00)<br>
>                 | ((b << 8) & 0xff0000)<br>
>                 | ((b << 24) & 0xff000000);<br>
>         -      p[i] = a;<br>
>         +      dst[i] = a;<br>
>             }<br>
>          }<br>
><br>
>         diff --git a/src/mesa/main/image.h b/src/mesa/main/image.h<br>
>         index abd84bf..79c6e68 100644<br>
>         --- a/src/mesa/main/image.h<br>
>         +++ b/src/mesa/main/image.h<br>
>         @@ -33,10 +33,16 @@ struct gl_context;<br>
>          struct gl_pixelstore_attrib;<br>
><br>
>          extern void<br>
>         -_mesa_swap2( GLushort *p, GLuint n );<br>
>         +_mesa_swap2_copy( GLushort *dst, GLushort *src, GLuint n );<br>
><br>
>          extern void<br>
>         -_mesa_swap4( GLuint *p, GLuint n );<br>
>         +_mesa_swap4_copy( GLuint *dst, GLuint *src, GLuint n );<br>
>         +<br>
>         +static inline void<br>
>         +_mesa_swap2( GLushort *p, GLuint n ) { _mesa_swap2_copy(p, p,<br>
>         n); }<br>
>         +<br>
>         +static inline void<br>
>         +_mesa_swap4( GLuint *p, GLuint n ) { _mesa_swap4_copy(p, p,<br>
>         n); }<br>
><br>
>          extern GLintptr<br>
>          _mesa_image_offset( GLuint dimensions,<br>
>         --<br>
>         1.9.1<br>
><br>
>         _______________________________________________<br>
>         mesa-dev mailing list<br>
>         <a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
>         <a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
><br>
><br>
<br>
<br>
</div></div></blockquote></div><br></div></div>