From 6b4ac0bc6129306019fb12ab27b5efa9044a61a6 Mon Sep 17 00:00:00 2001 From: Hayden Kowalchuk Date: Sat, 17 Aug 2019 17:51:39 -0400 Subject: [PATCH] chore: keep strict-aliasing step 1 --- GL/private.h | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/GL/private.h b/GL/private.h index 1dabf2f..2065d5d 100644 --- a/GL/private.h +++ b/GL/private.h @@ -98,12 +98,17 @@ typedef struct { GLboolean is_directional; } LightSource; +union color_t { + uint8_t bgra[sizeof(uint32_t)]; + uint32_t packed; +}; + typedef struct { /* Same 32 byte layout as pvr_vertex_t */ uint32_t flags; float xyz[3]; float uv[2]; - uint8_t bgra[4]; + union color_t color; /* In the pvr_vertex_t structure, this next 4 bytes is oargb * but we're not using that for now, so having W here makes the code @@ -111,12 +116,14 @@ typedef struct { float w; } Vertex; + + /* FIXME: SH4 has a swap.w instruction, we should leverage it here! */ -#define _SWAP32(x, y) \ +#define _SWAP32(type, x, y) \ do { \ - uint32_t t = *((uint32_t*) &x); \ - *((uint32_t*) &x) = *((uint32_t*) &y); \ - *((uint32_t*) &y) = t; \ + type t = *((type*) &x); \ + *((type*) &x) = *((type*) &y); \ + *((type*) &y) = t; \ } while(0) /* @@ -127,14 +134,14 @@ do { \ #define swapVertex(a, b) \ do { \ - _SWAP32(a->flags, b->flags); \ - _SWAP32(a->xyz[0], b->xyz[0]); \ - _SWAP32(a->xyz[1], b->xyz[1]); \ - _SWAP32(a->xyz[2], b->xyz[2]); \ - _SWAP32(a->uv[0], b->uv[0]); \ - _SWAP32(a->uv[1], b->uv[1]); \ - _SWAP32(a->bgra, b->bgra); \ - _SWAP32(a->w, b->w); \ + _SWAP32(uint32_t, a->flags, b->flags); \ + _SWAP32(float, a->xyz[0], b->xyz[0]); \ + _SWAP32(float, a->xyz[1], b->xyz[1]); \ + _SWAP32(float, a->xyz[2], b->xyz[2]); \ + _SWAP32(float, a->uv[0], b->uv[0]); \ + _SWAP32(float, a->uv[1], b->uv[1]); \ + _SWAP32(uint32_t, a->color.packed, b->color.packed); \ + _SWAP32(float, a->w, b->w); \ } while(0) /* ClipVertex doesn't have room for these, so we need to parse them