Browse Source

Add more group components to vector types

rexim 1 week ago
parent
commit
558e718eea
2 changed files with 39 additions and 3 deletions
  1. 20 0
      la.h
  2. 19 3
      src/lag.c

+ 20 - 0
la.h

@@ -81,6 +81,8 @@ typedef union {
 
 
 typedef union {
 typedef union {
     struct { float x, y, z; };
     struct { float x, y, z; };
+    struct { V2f xy; float __pad1; };
+    struct { float __pad2; V2f yz; };
     float c[3];
     float c[3];
 } V3f;
 } V3f;
 
 
@@ -97,6 +99,8 @@ typedef union {
 
 
 typedef union {
 typedef union {
     struct { double x, y, z; };
     struct { double x, y, z; };
+    struct { V2d xy; double __pad1; };
+    struct { double __pad2; V2d yz; };
     double c[3];
     double c[3];
 } V3d;
 } V3d;
 
 
@@ -113,6 +117,8 @@ typedef union {
 
 
 typedef union {
 typedef union {
     struct { int x, y, z; };
     struct { int x, y, z; };
+    struct { V2i xy; int __pad1; };
+    struct { int __pad2; V2i yz; };
     int c[3];
     int c[3];
 } V3i;
 } V3i;
 
 
@@ -129,6 +135,8 @@ typedef union {
 
 
 typedef union {
 typedef union {
     struct { unsigned int x, y, z; };
     struct { unsigned int x, y, z; };
+    struct { V2u xy; unsigned int __pad1; };
+    struct { unsigned int __pad2; V2u yz; };
     unsigned int c[3];
     unsigned int c[3];
 } V3u;
 } V3u;
 
 
@@ -146,6 +154,9 @@ typedef union {
 typedef union {
 typedef union {
     struct { float x, y, z, w; };
     struct { float x, y, z, w; };
     struct { V2f xy; V2f zw; };
     struct { V2f xy; V2f zw; };
+    struct { float __pad1; V2f yz; float __pad2; };
+    struct { V3f xyz; float __pad3; };
+    struct { float __pad4; V3f yzw; };
     float c[4];
     float c[4];
 } V4f;
 } V4f;
 
 
@@ -164,6 +175,9 @@ typedef union {
 typedef union {
 typedef union {
     struct { double x, y, z, w; };
     struct { double x, y, z, w; };
     struct { V2d xy; V2d zw; };
     struct { V2d xy; V2d zw; };
+    struct { double __pad1; V2d yz; double __pad2; };
+    struct { V3d xyz; double __pad3; };
+    struct { double __pad4; V3d yzw; };
     double c[4];
     double c[4];
 } V4d;
 } V4d;
 
 
@@ -182,6 +196,9 @@ typedef union {
 typedef union {
 typedef union {
     struct { int x, y, z, w; };
     struct { int x, y, z, w; };
     struct { V2i xy; V2i zw; };
     struct { V2i xy; V2i zw; };
+    struct { int __pad1; V2i yz; int __pad2; };
+    struct { V3i xyz; int __pad3; };
+    struct { int __pad4; V3i yzw; };
     int c[4];
     int c[4];
 } V4i;
 } V4i;
 
 
@@ -200,6 +217,9 @@ typedef union {
 typedef union {
 typedef union {
     struct { unsigned int x, y, z, w; };
     struct { unsigned int x, y, z, w; };
     struct { V2u xy; V2u zw; };
     struct { V2u xy; V2u zw; };
+    struct { unsigned int __pad1; V2u yz; unsigned int __pad2; };
+    struct { V3u xyz; unsigned int __pad3; };
+    struct { unsigned int __pad4; V3u yzw; };
     unsigned int c[4];
     unsigned int c[4];
 } V4u;
 } V4u;
 
 

+ 19 - 3
src/lag.c

@@ -109,10 +109,26 @@ void gen_vec_def(FILE *stream, size_t n, Type type)
     }
     }
     fgenf(stream, "; };");
     fgenf(stream, "; };");
     if (n == 4) {
     if (n == 4) {
-        // TODO: add more different group components like this
         fgenf(stream, "    struct { %s %s%s; %s %s%s; };",
         fgenf(stream, "    struct { %s %s%s; %s %s%s; };",
-              vec_type(n/2, type), vec_comps[0], vec_comps[1],
-              vec_type(n/2, type), vec_comps[2], vec_comps[3]);
+              vec_type(2, type), vec_comps[0], vec_comps[1],
+              vec_type(2, type), vec_comps[2], vec_comps[3]);
+        fgenf(stream, "    struct { %s __pad1; %s %s%s; %s __pad2; };",
+              type_defs[type].name,
+              vec_type(2, type), vec_comps[1], vec_comps[2],
+              type_defs[type].name);
+        fgenf(stream, "    struct { %s %s%s%s; %s __pad3; };",
+              vec_type(3, type), vec_comps[0], vec_comps[1], vec_comps[2],
+              type_defs[type].name);
+        fgenf(stream, "    struct { %s __pad4; %s %s%s%s; };",
+              type_defs[type].name,
+              vec_type(3, type), vec_comps[1], vec_comps[2], vec_comps[3]);
+    } else if (n == 3) {
+        fgenf(stream, "    struct { %s %s%s; %s __pad1; };",
+              vec_type(2, type), vec_comps[0], vec_comps[1],
+              type_defs[type].name);
+        fgenf(stream, "    struct { %s __pad2; %s %s%s; };",
+              type_defs[type].name,
+              vec_type(2, type), vec_comps[1], vec_comps[2]);
     }
     }
     fgenf(stream, "    %s c[%zu];", type_defs[type].name, n);
     fgenf(stream, "    %s c[%zu];", type_defs[type].name, n);
     fgenf(stream, "} %s;", vec_type(n, type));
     fgenf(stream, "} %s;", vec_type(n, type));