@kv  0.0.4
Library for graph problems in C and Python
vec.h
1 
18 #if !defined(AT_CORE_H_INSIDE)
19 #error "Only <at/core.h> can be included directly."
20 #endif
21 #ifndef AT_VEC_H
22 #define AT_VEC_H
23 #include <stdint.h>
24 
25 typedef uint8_t __attribute__((vector_size(2))) v2u8;
26 typedef uint8_t __attribute__((vector_size(4))) v4u8;
27 
28 typedef uint16_t __attribute__((vector_size(4))) v2u16;
29 typedef uint16_t __attribute__((vector_size(8))) v4u16;
30 
31 typedef uint32_t __attribute__((vector_size(8))) v2u32;
32 typedef uint32_t __attribute__((vector_size(16))) v4u32;
33 
34 typedef uint64_t __attribute__((vector_size(16))) v2u64;
35 typedef uint64_t __attribute__((vector_size(32))) v4u64;
36 
37 typedef int8_t __attribute__((vector_size(2))) v2i8;
38 typedef int8_t __attribute__((vector_size(4))) v4i8;
39 
40 typedef int16_t __attribute__((vector_size(4))) v2i16;
41 typedef int16_t __attribute__((vector_size(8))) v4i16;
42 
43 typedef int32_t __attribute__((vector_size(8))) v2i32;
44 typedef int32_t __attribute__((vector_size(16))) v4i32;
45 
46 typedef int64_t __attribute__((vector_size(16))) v2i64;
47 typedef int64_t __attribute__((vector_size(32))) v4i64;
48 
49 typedef float __attribute__((vector_size(8))) v2f32;
50 typedef float __attribute__((vector_size(16))) v4f32;
51 
52 typedef double __attribute__((vector_size(16))) v2d64;
53 typedef double __attribute__((vector_size(32))) v4d64;
54 
55 #define AT_DECLARE_VEC2(vectype, uniontype, type) \
56 typedef union{ \
57  v2##vectype v; \
58  type d[2]; \
59  struct{ type x; type y;}; \
60  struct{ type width; type height;}; \
61 }AtVec2##uniontype;
62 
63 #define AT_DECLARE_VEC3(vectype, uniontype, type) \
64 typedef union{ \
65  v4##vectype v; \
66  type d[4]; \
67  struct{ type x; type y; type z;}; \
68  struct{ type r; type g; type b;}; \
69 }AtVec3##uniontype;
70 
71 #define AT_DECLARE_VEC4(vectype, uniontype, type) \
72 typedef union{ \
73  v4##vectype v; \
74  type d[4]; \
75  struct{ type x; type y; union{struct{type z; type w;};struct{type width; type height;};};}; \
76  struct{ type x0; type y0; type x1; type y1;}; \
77  struct{ type r; type g; type b; type a;}; \
78 }AtVec4##uniontype;
79 
80 AT_DECLARE_VEC2(u8, U8, uint8_t)
81 AT_DECLARE_VEC2(u16,U16,uint16_t)
82 AT_DECLARE_VEC2(u32,U32,uint32_t)
83 AT_DECLARE_VEC2(u64,U64,uint64_t)
84 AT_DECLARE_VEC2(i8, I8, int8_t)
85 AT_DECLARE_VEC2(i16,I16,int16_t)
86 AT_DECLARE_VEC2(i32,I32,int32_t)
87 AT_DECLARE_VEC2(i64,I64,int64_t)
88 AT_DECLARE_VEC2(f32,F32,float)
89 AT_DECLARE_VEC2(d64,D64,double)
90 
91 AT_DECLARE_VEC3(u8, U8, uint8_t)
92 AT_DECLARE_VEC3(u16,U16,uint16_t)
93 AT_DECLARE_VEC3(u32,U32,uint32_t)
94 AT_DECLARE_VEC3(u64,U64,uint64_t)
95 AT_DECLARE_VEC3(i8, I8, int8_t)
96 AT_DECLARE_VEC3(i16,I16,int16_t)
97 AT_DECLARE_VEC3(i32,I32,int32_t)
98 AT_DECLARE_VEC3(i64,I64,int64_t)
99 AT_DECLARE_VEC3(f32,F32,float)
100 AT_DECLARE_VEC3(d64,D64,double)
101 
102 AT_DECLARE_VEC4(u8, U8, uint8_t)
103 AT_DECLARE_VEC4(u16,U16,uint16_t)
104 AT_DECLARE_VEC4(u32,U32,uint32_t)
105 AT_DECLARE_VEC4(u64,U64,uint64_t)
106 AT_DECLARE_VEC4(i8, I8, int8_t)
107 AT_DECLARE_VEC4(i16,I16,int16_t)
108 AT_DECLARE_VEC4(i32,I32,int32_t)
109 AT_DECLARE_VEC4(i64,I64,int64_t)
110 AT_DECLARE_VEC4(f32,F32,float)
111 AT_DECLARE_VEC4(d64,D64,double)
112 
113 AtVec3D64
114 at_vec3d64_normalize(AtVec3D64 vec);
115 #endif