| ... | @@ -12,6 +12,15 @@ static void assert_or_panic(bool ok) { | ... | @@ -12,6 +12,15 @@ static void assert_or_panic(bool ok) { |
| 12 | } | 12 | } |
| 13 | } | 13 | } |
| 14 | | 14 | |
| | 15 | #ifdef __i386__ |
| | 16 | # define ZIG_NO_I128 |
| | 17 | #endif |
| | 18 | |
| | 19 | #ifdef __i386__ |
| | 20 | # define ZIG_NO_COMPLEX |
| | 21 | #endif |
| | 22 | |
| | 23 | #ifndef ZIG_NO_I128 |
| 15 | struct i128 { | 24 | struct i128 { |
| 16 | __int128 value; | 25 | __int128 value; |
| 17 | }; | 26 | }; |
| ... | @@ -19,17 +28,22 @@ struct i128 { | ... | @@ -19,17 +28,22 @@ struct i128 { |
| 19 | struct u128 { | 28 | struct u128 { |
| 20 | unsigned __int128 value; | 29 | unsigned __int128 value; |
| 21 | }; | 30 | }; |
| | 31 | #endif |
| 22 | | 32 | |
| 23 | void zig_u8(uint8_t); | 33 | void zig_u8(uint8_t); |
| 24 | void zig_u16(uint16_t); | 34 | void zig_u16(uint16_t); |
| 25 | void zig_u32(uint32_t); | 35 | void zig_u32(uint32_t); |
| 26 | void zig_u64(uint64_t); | 36 | void zig_u64(uint64_t); |
| | 37 | #ifndef ZIG_NO_I128 |
| 27 | void zig_struct_u128(struct u128); | 38 | void zig_struct_u128(struct u128); |
| | 39 | #endif |
| 28 | void zig_i8(int8_t); | 40 | void zig_i8(int8_t); |
| 29 | void zig_i16(int16_t); | 41 | void zig_i16(int16_t); |
| 30 | void zig_i32(int32_t); | 42 | void zig_i32(int32_t); |
| 31 | void zig_i64(int64_t); | 43 | void zig_i64(int64_t); |
| | 44 | #ifndef ZIG_NO_I128 |
| 32 | void zig_struct_i128(struct i128); | 45 | void zig_struct_i128(struct i128); |
| | 46 | #endif |
| 33 | void zig_five_integers(int32_t, int32_t, int32_t, int32_t, int32_t); | 47 | void zig_five_integers(int32_t, int32_t, int32_t, int32_t, int32_t); |
| 34 | | 48 | |
| 35 | void zig_f32(float); | 49 | void zig_f32(float); |
| ... | @@ -95,7 +109,9 @@ void zig_med_struct_mixed(struct MedStructMixed); | ... | @@ -95,7 +109,9 @@ void zig_med_struct_mixed(struct MedStructMixed); |
| 95 | struct MedStructMixed zig_ret_med_struct_mixed(); | 109 | struct MedStructMixed zig_ret_med_struct_mixed(); |
| 96 | | 110 | |
| 97 | void zig_small_packed_struct(uint8_t); | 111 | void zig_small_packed_struct(uint8_t); |
| | 112 | #ifndef ZIG_NO_I128 |
| 98 | void zig_big_packed_struct(__int128); | 113 | void zig_big_packed_struct(__int128); |
| | 114 | #endif |
| 99 | | 115 | |
| 100 | struct SplitStructInts { | 116 | struct SplitStructInts { |
| 101 | uint64_t a; | 117 | uint64_t a; |
| ... | @@ -151,19 +167,26 @@ void run_c_tests(void) { | ... | @@ -151,19 +167,26 @@ void run_c_tests(void) { |
| 151 | zig_u16(0xfffe); | 167 | zig_u16(0xfffe); |
| 152 | zig_u32(0xfffffffd); | 168 | zig_u32(0xfffffffd); |
| 153 | zig_u64(0xfffffffffffffffc); | 169 | zig_u64(0xfffffffffffffffc); |
| | 170 | |
| | 171 | #ifndef ZIG_NO_I128 |
| 154 | { | 172 | { |
| 155 | struct u128 s = {0xfffffffffffffffc}; | 173 | struct u128 s = {0xfffffffffffffffc}; |
| 156 | zig_struct_u128(s); | 174 | zig_struct_u128(s); |
| 157 | } | 175 | } |
| | 176 | #endif |
| 158 | | 177 | |
| 159 | zig_i8(-1); | 178 | zig_i8(-1); |
| 160 | zig_i16(-2); | 179 | zig_i16(-2); |
| 161 | zig_i32(-3); | 180 | zig_i32(-3); |
| 162 | zig_i64(-4); | 181 | zig_i64(-4); |
| | 182 | |
| | 183 | #ifndef ZIG_NO_I128 |
| 163 | { | 184 | { |
| 164 | struct i128 s = {-6}; | 185 | struct i128 s = {-6}; |
| 165 | zig_struct_i128(s); | 186 | zig_struct_i128(s); |
| 166 | } | 187 | } |
| | 188 | #endif |
| | 189 | |
| 167 | zig_five_integers(12, 34, 56, 78, 90); | 190 | zig_five_integers(12, 34, 56, 78, 90); |
| 168 | | 191 | |
| 169 | zig_f32(12.34f); | 192 | zig_f32(12.34f); |
| ... | @@ -175,6 +198,7 @@ void run_c_tests(void) { | ... | @@ -175,6 +198,7 @@ void run_c_tests(void) { |
| 175 | | 198 | |
| 176 | zig_bool(true); | 199 | zig_bool(true); |
| 177 | | 200 | |
| | 201 | #ifndef ZIG_NO_COMPLEX |
| 178 | // TODO: Resolve https://github.com/ziglang/zig/issues/8465 | 202 | // TODO: Resolve https://github.com/ziglang/zig/issues/8465 |
| 179 | //{ | 203 | //{ |
| 180 | // float complex a = 1.25f + I * 2.6f; | 204 | // float complex a = 1.25f + I * 2.6f; |
| ... | @@ -211,23 +235,28 @@ void run_c_tests(void) { | ... | @@ -211,23 +235,28 @@ void run_c_tests(void) { |
| 211 | assert_or_panic(creal(z) == 1.5); | 235 | assert_or_panic(creal(z) == 1.5); |
| 212 | assert_or_panic(cimag(z) == 13.5); | 236 | assert_or_panic(cimag(z) == 13.5); |
| 213 | } | 237 | } |
| | 238 | #endif |
| 214 | | 239 | |
| 215 | { | 240 | { |
| 216 | struct BigStruct s = {1, 2, 3, 4, 5}; | 241 | struct BigStruct s = {1, 2, 3, 4, 5}; |
| 217 | zig_big_struct(s); | 242 | zig_big_struct(s); |
| 218 | } | 243 | } |
| 219 | | 244 | |
| | 245 | #ifndef __i386__ |
| 220 | { | 246 | { |
| 221 | struct SmallStructInts s = {1, 2, 3, 4}; | 247 | struct SmallStructInts s = {1, 2, 3, 4}; |
| 222 | zig_small_struct_ints(s); | 248 | zig_small_struct_ints(s); |
| 223 | } | 249 | } |
| | 250 | #endif |
| 224 | | 251 | |
| | 252 | #ifndef ZIG_NO_I128 |
| 225 | { | 253 | { |
| 226 | __int128 s = 0; | 254 | __int128 s = 0; |
| 227 | s |= 1 << 0; | 255 | s |= 1 << 0; |
| 228 | s |= (__int128)2 << 64; | 256 | s |= (__int128)2 << 64; |
| 229 | zig_big_packed_struct(s); | 257 | zig_big_packed_struct(s); |
| 230 | } | 258 | } |
| | 259 | #endif |
| 231 | | 260 | |
| 232 | { | 261 | { |
| 233 | uint8_t s = 0; | 262 | uint8_t s = 0; |
| ... | @@ -238,20 +267,24 @@ void run_c_tests(void) { | ... | @@ -238,20 +267,24 @@ void run_c_tests(void) { |
| 238 | zig_small_packed_struct(s); | 267 | zig_small_packed_struct(s); |
| 239 | } | 268 | } |
| 240 | | 269 | |
| | 270 | #ifndef __i386__ |
| 241 | { | 271 | { |
| 242 | struct SplitStructInts s = {1234, 100, 1337}; | 272 | struct SplitStructInts s = {1234, 100, 1337}; |
| 243 | zig_split_struct_ints(s); | 273 | zig_split_struct_ints(s); |
| 244 | } | 274 | } |
| | 275 | #endif |
| 245 | | 276 | |
| 246 | { | 277 | { |
| 247 | struct MedStructMixed s = {1234, 100.0f, 1337.0f}; | 278 | struct MedStructMixed s = {1234, 100.0f, 1337.0f}; |
| 248 | zig_med_struct_mixed(s); | 279 | zig_med_struct_mixed(s); |
| 249 | } | 280 | } |
| 250 | | 281 | |
| | 282 | #ifndef __i386__ |
| 251 | { | 283 | { |
| 252 | struct SplitStructMixed s = {1234, 100, 1337.0f}; | 284 | struct SplitStructMixed s = {1234, 100, 1337.0f}; |
| 253 | zig_split_struct_mixed(s); | 285 | zig_split_struct_mixed(s); |
| 254 | } | 286 | } |
| | 287 | #endif |
| 255 | | 288 | |
| 256 | { | 289 | { |
| 257 | struct BigStruct s = {30, 31, 32, 33, 34}; | 290 | struct BigStruct s = {30, 31, 32, 33, 34}; |
| ... | @@ -306,9 +339,11 @@ void c_u64(uint64_t x) { | ... | @@ -306,9 +339,11 @@ void c_u64(uint64_t x) { |
| 306 | assert_or_panic(x == 0xfffffffffffffffcULL); | 339 | assert_or_panic(x == 0xfffffffffffffffcULL); |
| 307 | } | 340 | } |
| 308 | | 341 | |
| | 342 | #ifndef ZIG_NO_I128 |
| 309 | void c_struct_u128(struct u128 x) { | 343 | void c_struct_u128(struct u128 x) { |
| 310 | assert_or_panic(x.value == 0xfffffffffffffffcULL); | 344 | assert_or_panic(x.value == 0xfffffffffffffffcULL); |
| 311 | } | 345 | } |
| | 346 | #endif |
| 312 | | 347 | |
| 313 | void c_i8(int8_t x) { | 348 | void c_i8(int8_t x) { |
| 314 | assert_or_panic(x == -1); | 349 | assert_or_panic(x == -1); |
| ... | @@ -326,9 +361,11 @@ void c_i64(int64_t x) { | ... | @@ -326,9 +361,11 @@ void c_i64(int64_t x) { |
| 326 | assert_or_panic(x == -4); | 361 | assert_or_panic(x == -4); |
| 327 | } | 362 | } |
| 328 | | 363 | |
| | 364 | #ifndef ZIG_NO_I128 |
| 329 | void c_struct_i128(struct i128 x) { | 365 | void c_struct_i128(struct i128 x) { |
| 330 | assert_or_panic(x.value == -6); | 366 | assert_or_panic(x.value == -6); |
| 331 | } | 367 | } |
| | 368 | #endif |
| 332 | | 369 | |
| 333 | void c_f32(float x) { | 370 | void c_f32(float x) { |
| 334 | assert_or_panic(x == 12.34f); | 371 | assert_or_panic(x == 12.34f); |
| ... | @@ -495,6 +532,7 @@ void c_small_packed_struct(uint8_t x) { | ... | @@ -495,6 +532,7 @@ void c_small_packed_struct(uint8_t x) { |
| 495 | assert_or_panic(((x >> 6) & 0x3) == 3); | 532 | assert_or_panic(((x >> 6) & 0x3) == 3); |
| 496 | } | 533 | } |
| 497 | | 534 | |
| | 535 | #ifndef ZIG_NO_I128 |
| 498 | __int128 c_ret_big_packed_struct() { | 536 | __int128 c_ret_big_packed_struct() { |
| 499 | __int128 s = 0; | 537 | __int128 s = 0; |
| 500 | s |= 1 << 0; | 538 | s |= 1 << 0; |
| ... | @@ -506,6 +544,7 @@ void c_big_packed_struct(__int128 x) { | ... | @@ -506,6 +544,7 @@ void c_big_packed_struct(__int128 x) { |
| 506 | assert_or_panic(((x >> 0) & 0xFFFFFFFFFFFFFFFF) == 1); | 544 | assert_or_panic(((x >> 0) & 0xFFFFFFFFFFFFFFFF) == 1); |
| 507 | assert_or_panic(((x >> 64) & 0xFFFFFFFFFFFFFFFF) == 2); | 545 | assert_or_panic(((x >> 64) & 0xFFFFFFFFFFFFFFFF) == 2); |
| 508 | } | 546 | } |
| | 547 | #endif |
| 509 | | 548 | |
| 510 | struct SplitStructMixed c_ret_split_struct_mixed() { | 549 | struct SplitStructMixed c_ret_split_struct_mixed() { |
| 511 | struct SplitStructMixed s = { | 550 | struct SplitStructMixed s = { |