radeonsi: stop using v16i8
[mesa.git] / src / gallium / auxiliary / translate / translate_generic.c
index fdab0f34a1a944225cb36b1bb3c7fbeded2e54cf..3b460e11c3437428a94cd11c9940f81920ae2ad6 100644 (file)
@@ -1,6 +1,6 @@
 /**************************************************************************
  * 
- * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * Copyright 2007 VMware, Inc.
  * All Rights Reserved.
  * 
  * Permission is hereby granted, free of charge, to any person obtaining a
@@ -18,7 +18,7 @@
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -27,7 +27,7 @@
 
  /*
   * Authors:
-  *   Keith Whitwell <keith@tungstengraphics.com>
+  *   Keith Whitwell <keithw@vmware.com>
   */
 
 #include "util/u_memory.h"
@@ -73,7 +73,7 @@ struct translate_generic {
        */
       int copy_size;
 
-   } attrib[PIPE_MAX_ATTRIBS];
+   } attrib[TRANSLATE_MAX_ATTRIBS];
 
    unsigned nr_attrib;
 };
@@ -266,10 +266,7 @@ emit_B10G10R10A2_UNORM( const void *attrib, void *ptr )
    value |= (((uint32_t)(CLAMP(src[1], 0, 1) * 0x3ff)) & 0x3ff) << 10;
    value |= (((uint32_t)(CLAMP(src[0], 0, 1) * 0x3ff)) & 0x3ff) << 20;
    value |= ((uint32_t)(CLAMP(src[3], 0, 1) * 0x3)) << 30;
-#ifdef PIPE_ARCH_BIG_ENDIAN
-   value = util_bswap32(value);
-#endif
-   *(uint32_t *)attrib = value;
+   *(uint32_t *)attrib = util_le32_to_cpu(value);
 }
 
 static void
@@ -281,10 +278,7 @@ emit_B10G10R10A2_USCALED( const void *attrib, void *ptr )
    value |= (((uint32_t)CLAMP(src[1], 0, 1023)) & 0x3ff) << 10;
    value |= (((uint32_t)CLAMP(src[0], 0, 1023)) & 0x3ff) << 20;
    value |= ((uint32_t)CLAMP(src[3], 0, 3)) << 30;
-#ifdef PIPE_ARCH_BIG_ENDIAN
-   value = util_bswap32(value);
-#endif
-   *(uint32_t *)attrib = value;
+   *(uint32_t *)attrib = util_le32_to_cpu(value);
 }
 
 static void
@@ -296,10 +290,7 @@ emit_B10G10R10A2_SNORM( const void *attrib, void *ptr )
    value |= (uint32_t)((((uint32_t)(CLAMP(src[1], -1, 1) * 0x1ff)) & 0x3ff) << 10) ;
    value |= (uint32_t)((((uint32_t)(CLAMP(src[0], -1, 1) * 0x1ff)) & 0x3ff) << 20) ;
    value |= (uint32_t)(((uint32_t)(CLAMP(src[3], -1, 1) * 0x1)) << 30) ;
-#ifdef PIPE_ARCH_BIG_ENDIAN
-   value = util_bswap32(value);
-#endif
-   *(uint32_t *)attrib = value;
+   *(uint32_t *)attrib = util_le32_to_cpu(value);
 }
 
 static void
@@ -311,10 +302,7 @@ emit_B10G10R10A2_SSCALED( const void *attrib, void *ptr )
    value |= (uint32_t)((((uint32_t)CLAMP(src[1], -512, 511)) & 0x3ff) << 10) ;
    value |= (uint32_t)((((uint32_t)CLAMP(src[0], -512, 511)) & 0x3ff) << 20) ;
    value |= (uint32_t)(((uint32_t)CLAMP(src[3], -2, 1)) << 30) ;
-#ifdef PIPE_ARCH_BIG_ENDIAN
-   value = util_bswap32(value);
-#endif
-   *(uint32_t *)attrib = value;
+   *(uint32_t *)attrib = util_le32_to_cpu(value);
 }
 
 static void
@@ -326,10 +314,7 @@ emit_R10G10B10A2_UNORM( const void *attrib, void *ptr )
    value |= (((uint32_t)(CLAMP(src[1], 0, 1) * 0x3ff)) & 0x3ff) << 10;
    value |= (((uint32_t)(CLAMP(src[2], 0, 1) * 0x3ff)) & 0x3ff) << 20;
    value |= ((uint32_t)(CLAMP(src[3], 0, 1) * 0x3)) << 30;
-#ifdef PIPE_ARCH_BIG_ENDIAN
-   value = util_bswap32(value);
-#endif
-   *(uint32_t *)attrib = value;
+   *(uint32_t *)attrib = util_le32_to_cpu(value);
 }
 
 static void
@@ -341,10 +326,7 @@ emit_R10G10B10A2_USCALED( const void *attrib, void *ptr )
    value |= (((uint32_t)CLAMP(src[1], 0, 1023)) & 0x3ff) << 10;
    value |= (((uint32_t)CLAMP(src[2], 0, 1023)) & 0x3ff) << 20;
    value |= ((uint32_t)CLAMP(src[3], 0, 3)) << 30;
-#ifdef PIPE_ARCH_BIG_ENDIAN
-   value = util_bswap32(value);
-#endif
-   *(uint32_t *)attrib = value;
+   *(uint32_t *)attrib = util_le32_to_cpu(value);
 }
 
 static void
@@ -356,10 +338,7 @@ emit_R10G10B10A2_SNORM( const void *attrib, void *ptr )
    value |= (uint32_t)((((uint32_t)(CLAMP(src[1], -1, 1) * 0x1ff)) & 0x3ff) << 10) ;
    value |= (uint32_t)((((uint32_t)(CLAMP(src[2], -1, 1) * 0x1ff)) & 0x3ff) << 20) ;
    value |= (uint32_t)(((uint32_t)(CLAMP(src[3], -1, 1) * 0x1)) << 30) ;
-#ifdef PIPE_ARCH_BIG_ENDIAN
-   value = util_bswap32(value);
-#endif
-   *(uint32_t *)attrib = value;
+   *(uint32_t *)attrib = util_le32_to_cpu(value);
 }
 
 static void
@@ -371,10 +350,7 @@ emit_R10G10B10A2_SSCALED( const void *attrib, void *ptr)
    value |= (uint32_t)((((uint32_t)CLAMP(src[1], -512, 511)) & 0x3ff) << 10) ;
    value |= (uint32_t)((((uint32_t)CLAMP(src[2], -512, 511)) & 0x3ff) << 20) ;
    value |= (uint32_t)(((uint32_t)CLAMP(src[3], -2, 1)) << 30) ;
-#ifdef PIPE_ARCH_BIG_ENDIAN
-   value = util_bswap32(value);
-#endif
-   *(uint32_t *)attrib = value;
+   *(uint32_t *)attrib = util_le32_to_cpu(value);
 }
 
 static void 
@@ -638,7 +614,7 @@ static ALWAYS_INLINE void PIPE_CDECL generic_run_one( struct translate_generic *
          }
 
          src = tg->attrib[attr].input_ptr +
-               tg->attrib[attr].input_stride * index;
+               (ptrdiff_t)tg->attrib[attr].input_stride * index;
 
          copy_size = tg->attrib[attr].copy_size;
          if(likely(copy_size >= 0))
@@ -796,9 +772,11 @@ struct translate *translate_generic_create( const struct translate_key *key )
    struct translate_generic *tg = CALLOC_STRUCT(translate_generic);
    unsigned i;
 
-   if (tg == NULL)
+   if (!tg)
       return NULL;
 
+   assert(key->nr_elements <= TRANSLATE_MAX_ATTRIBS);
+
    tg->translate.key = *key;
    tg->translate.release = generic_release;
    tg->translate.set_buffer = generic_set_buffer;