1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: 2024 The Ebitengine Authors
3
4// Empty is empty
5struct Empty {};
6
7// NoStruct tests that an empty struct doesn't cause issues
8unsigned long NoStruct(struct Empty e) {
9 return 0xdeadbeef;
10}
11
12struct EmptyEmpty {
13 struct Empty x;
14};
15
16unsigned long EmptyEmpty(struct EmptyEmpty e) {
17 return 0xdeadbeef;
18}
19
20unsigned long EmptyEmptyWithReg(unsigned int x, struct EmptyEmpty e, unsigned int y) {
21 return (x << 16) | y;
22}
23
24// GreaterThan16Bytes is 24 bytes on 64 bit systems
25struct GreaterThan16Bytes {
26 long *x, *y, *z;
27};
28
29// GreaterThan16Bytes is a basic test for structs bigger than 16 bytes
30unsigned long GreaterThan16Bytes(struct GreaterThan16Bytes g) {
31 return *g.x + *g.y + *g.z;
32}
33
34// AfterRegisters tests to make sure that structs placed on the stack work properly
35unsigned long AfterRegisters(long a, long b, long c, long d, long e, long f, long g, long h, struct GreaterThan16Bytes bytes) {
36 long registers = a + b + c + d + e + f + g + h;
37 long stack = *bytes.x + *bytes.y + *bytes.z;
38 if (registers != stack) {
39 return 0xbadbad;
40 }
41 if (stack != 0xdeadbeef) {
42 return 0xcafebad;
43 }
44 return stack;
45}
46
47unsigned long BeforeRegisters(struct GreaterThan16Bytes bytes, long a, long b) {
48 return *bytes.x + *bytes.y + *bytes.z + a + b;
49}
50
51struct GreaterThan16BytesStruct {
52 struct {
53 long *x, *y, *z;
54 } a ;
55};
56
57unsigned long GreaterThan16BytesStruct(struct GreaterThan16BytesStruct g) {
58 return *(g.a.x) + *(g.a.y) + *(g.a.z);
59}
60
61struct IntLessThan16Bytes {
62 long x, y;
63};
64
65unsigned long IntLessThan16Bytes(struct IntLessThan16Bytes l) {
66 return l.x + l.y;
67}
68
69struct FloatLessThan16Bytes {
70 float x, y;
71};
72
73float FloatLessThan16Bytes(struct FloatLessThan16Bytes f) {
74 return f.x + f.y;
75}
76
77struct ThreeSmallFields {
78 float x, y, z;
79};
80
81float ThreeSmallFields(struct ThreeSmallFields f) {
82 return f.x + f.y + f.z;
83}
84
85struct FloatAndInt {
86 float x;
87 int y;
88};
89
90float FloatAndInt(struct FloatAndInt f) {
91 return f.x + f.y;
92}
93
94struct DoubleStruct {
95 double x;
96};
97
98double DoubleStruct(struct DoubleStruct d) {
99 return d.x;
100}
101
102struct TwoDoubleStruct {
103 double x, y;
104};
105
106double TwoDoubleStruct(struct TwoDoubleStruct d) {
107 return d.x + d.y;
108}
109
110struct TwoDoubleTwoStruct {
111 struct {
112 double x, y;
113 } s;
114};
115
116double TwoDoubleTwoStruct(struct TwoDoubleTwoStruct d) {
117 return d.s.x + d.s.y;
118}
119
120struct ThreeDoubleStruct {
121 double x, y, z;
122};
123
124double ThreeDoubleStruct(struct ThreeDoubleStruct d) {
125 return d.x + d.y + d.z;
126}
127
128struct LargeFloatStruct {
129 double a, b, c, d, e, f;
130};
131
132double LargeFloatStruct(struct LargeFloatStruct s) {
133 return s.a + s.b + s.c + s.d + s.e + s.f;
134}
135
136double LargeFloatStructWithRegs(double a, double b, double c, struct LargeFloatStruct s) {
137 return a + b + c + s.a + s.b + s.c + s.d + s.e + s.f;
138}
139
140struct Rect {
141 double x, y, w, h;
142};
143
144double Rectangle(struct Rect rect) {
145 return rect.x + rect.y + rect.w + rect.h;
146}
147
148double RectangleSubtract(struct Rect rect) {
149 return (rect.x + rect.y) - (rect.w + rect.h);
150}
151
152double RectangleWithRegs(double a, double b, double c, double d, double e, struct Rect rect) {
153 return a + b + c + d + e + rect.x + rect.y + rect.w + rect.h;
154}
155
156struct FloatArray {
157 double a[2];
158};
159
160double FloatArray(struct FloatArray f) {
161 return f.a[0] + f.a[1];
162}
163
164struct UnsignedChar4Bytes {
165 unsigned char a, b, c, d;
166};
167
168unsigned int UnsignedChar4Bytes(struct UnsignedChar4Bytes b) {
169 return (((int)b.a)<<24) | (((int)b.b)<<16) | (((int)b.c)<<8) | (((int)b.d)<<0);
170}
171
172struct UnsignedChar4BytesStruct {
173 struct {
174 unsigned char a;
175 } x;
176 struct {
177 unsigned char b;
178 } y;
179 struct {
180 unsigned char c;
181 } z;
182 struct {
183 unsigned char d;
184 } w;
185};
186
187unsigned int UnsignedChar4BytesStruct(struct UnsignedChar4BytesStruct b) {
188 return (((int)b.x.a)<<24) | (((int)b.y.b)<<16) | (((int)b.z.c)<<8) | (((int)b.w.d)<<0);
189}
190
191struct Short {
192 unsigned short a, b, c, d;
193};
194
195unsigned long Short(struct Short s) {
196 return (long)s.a << 48 | (long)s.b << 32 | (long)s.c << 16 | (long)s.d << 0;
197}
198
199struct Int {
200 unsigned int a, b;
201};
202
203unsigned long Int(struct Int i) {
204 return (long)i.a << 32 | (long)i.b << 0;
205}
206
207struct Long {
208 unsigned long a;
209};
210
211unsigned long Long(struct Long l) {
212 return l.a;
213}
214
215struct Char8Bytes {
216 signed char a, b, c, d, e, f, g, h;
217};
218
219int Char8Bytes(struct Char8Bytes b) {
220 return (int)b.a + (int)b.b + (int)b.c + (int)b.d + (int)b.e + (int)b.f + (int)b.g + (int)b.h;
221}
222
223struct Odd {
224 unsigned char a, b, c;
225};
226
227int Odd(struct Odd o) {
228 return (int)o.a + (int)o.b + (int)o.c;
229}
230
231struct Char2Short1 {
232 unsigned char a, b;
233 unsigned short c;
234};
235
236int Char2Short1s(struct Char2Short1 s) {
237 return (int)s.a + (int)s.b + (int)s.c;
238}
239
240struct SignedChar2Short1 {
241 signed char a, b;
242 signed short c;
243};
244
245int SignedChar2Short1(struct SignedChar2Short1 s) {
246 return s.a + s.b + s.c;
247}
248
249struct Array4UnsignedChars {
250 unsigned char a[4];
251};
252
253unsigned int Array4UnsignedChars(struct Array4UnsignedChars a) {
254 return (((int)a.a[0])<<24) | (((int)a.a[1])<<16) | (((int)a.a[2])<<8) | (((int)a.a[3])<<0);
255}
256
257struct Array3UnsignedChar {
258 unsigned char a[3];
259};
260
261unsigned int Array3UnsignedChars(struct Array3UnsignedChar a) {
262 return (((int)a.a[0])<<24) | (((int)a.a[1])<<16) | (((int)a.a[2])<<8) | 0xef;
263}
264
265struct Array2UnsignedShort {
266 unsigned short a[2];
267};
268
269unsigned int Array2UnsignedShorts(struct Array2UnsignedShort a) {
270 return (((int)a.a[0])<<16) | (((int)a.a[1])<<0);
271}
272
273struct Array4Chars {
274 char a[4];
275};
276
277int Array4Chars(struct Array4Chars a) {
278 return (int)a.a[0] + (int)a.a[1] + (int)a.a[2] + (int)a.a[3];
279}
280
281struct Array2Short {
282 short a[2];
283};
284
285int Array2Shorts(struct Array2Short a) {
286 return (int)a.a[0] + (int)a.a[1];
287}
288
289struct Array3Short {
290 short a[3];
291};
292
293int Array3Shorts(struct Array3Short a) {
294 return (int)a.a[0] + (int)a.a[1] + (int)a.a[2];
295}
296
297struct BoolStruct {
298 _Bool b;
299};
300
301_Bool BoolStruct(struct BoolStruct b) {
302 return b.b;
303}
304
305struct BoolFloat {
306 _Bool b;
307 float f;
308};
309
310float BoolFloat(struct BoolFloat s) {
311 if (s.b)
312 return s.f;
313 return -s.f;
314}
315
316struct Content {
317 struct { double x, y; } point;
318 struct { double width, height; } size;
319};
320
321unsigned long InitWithContentRect(int *win, struct Content c, int style, int backing, _Bool flag) {
322 if (win == 0)
323 return 0xBAD;
324 if (!flag)
325 return 0xF1A6; // FLAG
326 return (unsigned long)(c.point.x + c.point.y + c.size.width + c.size.height) / (style - backing);
327}