| ... | @@ -1,6 +1,8 @@ | ... | @@ -1,6 +1,8 @@ |
| 1 | #undef linux | 1 | #undef linux |
| 2 | | 2 | |
| | 3 | #ifndef __STDC_WANT_IEC_60559_TYPES_EXT__ |
| 3 | #define __STDC_WANT_IEC_60559_TYPES_EXT__ | 4 | #define __STDC_WANT_IEC_60559_TYPES_EXT__ |
| | 5 | #endif |
| 4 | #include <float.h> | 6 | #include <float.h> |
| 5 | #include <limits.h> | 7 | #include <limits.h> |
| 6 | #include <stddef.h> | 8 | #include <stddef.h> |
| ... | @@ -297,690 +299,791 @@ typedef char bool; | ... | @@ -297,690 +299,791 @@ typedef char bool; |
| 297 | | 299 | |
| 298 | #define zig_bitSizeOf(T) (CHAR_BIT * sizeof(T)) | 300 | #define zig_bitSizeOf(T) (CHAR_BIT * sizeof(T)) |
| 299 | | 301 | |
| 300 | typedef uintptr_t zig_usize; | 302 | #define zig_compiler_rt_abbrev_uint32_t si |
| 301 | typedef intptr_t zig_isize; | 303 | #define zig_compiler_rt_abbrev_int32_t si |
| 302 | typedef signed short int zig_c_short; | 304 | #define zig_compiler_rt_abbrev_uint64_t di |
| 303 | typedef unsigned short int zig_c_ushort; | 305 | #define zig_compiler_rt_abbrev_int64_t di |
| 304 | typedef signed int zig_c_int; | 306 | #define zig_compiler_rt_abbrev_zig_u128 ti |
| 305 | typedef unsigned int zig_c_uint; | 307 | #define zig_compiler_rt_abbrev_zig_i128 ti |
| 306 | typedef signed long int zig_c_long; | 308 | #define zig_compiler_rt_abbrev_zig_f16 hf |
| 307 | typedef unsigned long int zig_c_ulong; | 309 | #define zig_compiler_rt_abbrev_zig_f32 sf |
| 308 | typedef signed long long int zig_c_longlong; | 310 | #define zig_compiler_rt_abbrev_zig_f64 df |
| 309 | typedef unsigned long long int zig_c_ulonglong; | 311 | #define zig_compiler_rt_abbrev_zig_f80 xf |
| 310 | | 312 | #define zig_compiler_rt_abbrev_zig_f128 tf |
| 311 | typedef uint8_t zig_u8; | 313 | |
| 312 | typedef int8_t zig_i8; | 314 | zig_extern void *memcpy (void *zig_restrict, void const *zig_restrict, size_t); |
| 313 | typedef uint16_t zig_u16; | 315 | zig_extern void *memset (void *, int, size_t); |
| 314 | typedef int16_t zig_i16; | 316 | |
| 315 | typedef uint32_t zig_u32; | 317 | /* ===================== 8/16/32/64-bit Integer Support ===================== */ |
| 316 | typedef int32_t zig_i32; | 318 | |
| 317 | typedef uint64_t zig_u64; | 319 | #if __STDC_VERSION__ >= 199901L |
| 318 | typedef int64_t zig_i64; | 320 | #include <stdint.h> |
| 319 | | 321 | #else |
| 320 | #define zig_as_u8(val) UINT8_C(val) | 322 | |
| 321 | #define zig_as_i8(val) INT8_C(val) | 323 | #if SCHAR_MIN == ~0x7F && SCHAR_MAX == 0x7F && UCHAR_MAX == 0xFF |
| 322 | #define zig_as_u16(val) UINT16_C(val) | 324 | typedef unsigned char uint8_t; |
| 323 | #define zig_as_i16(val) INT16_C(val) | 325 | typedef signed char int8_t; |
| 324 | #define zig_as_u32(val) UINT32_C(val) | 326 | #define INT8_C(c) c |
| 325 | #define zig_as_i32(val) INT32_C(val) | 327 | #define UINT8_C(c) c##U |
| 326 | #define zig_as_u64(val) UINT64_C(val) | 328 | #elif SHRT_MIN == ~0x7F && SHRT_MAX == 0x7F && USHRT_MAX == 0xFF |
| 327 | #define zig_as_i64(val) INT64_C(val) | 329 | typedef unsigned short uint8_t; |
| 328 | | 330 | typedef signed short int8_t; |
| 329 | #define zig_minInt_u8 zig_as_u8(0) | 331 | #define INT8_C(c) c |
| 330 | #define zig_maxInt_u8 UINT8_MAX | 332 | #define UINT8_C(c) c##U |
| | 333 | #elif INT_MIN == ~0x7F && INT_MAX == 0x7F && UINT_MAX == 0xFF |
| | 334 | typedef unsigned int uint8_t; |
| | 335 | typedef signed int int8_t; |
| | 336 | #define INT8_C(c) c |
| | 337 | #define UINT8_C(c) c##U |
| | 338 | #elif LONG_MIN == ~0x7F && LONG_MAX == 0x7F && ULONG_MAX == 0xFF |
| | 339 | typedef unsigned long uint8_t; |
| | 340 | typedef signed long int8_t; |
| | 341 | #define INT8_C(c) c##L |
| | 342 | #define UINT8_C(c) c##LU |
| | 343 | #elif LLONG_MIN == ~0x7F && LLONG_MAX == 0x7F && ULLONG_MAX == 0xFF |
| | 344 | typedef unsigned long long uint8_t; |
| | 345 | typedef signed long long int8_t; |
| | 346 | #define INT8_C(c) c##LL |
| | 347 | #define UINT8_C(c) c##LLU |
| | 348 | #endif |
| | 349 | #define INT8_MIN (~INT8_C(0x7F)) |
| | 350 | #define INT8_MAX ( INT8_C(0x7F)) |
| | 351 | #define UINT8_MAX ( INT8_C(0xFF)) |
| | 352 | |
| | 353 | #if SCHAR_MIN == ~0x7FFF && SCHAR_MAX == 0x7FFF && UCHAR_MAX == 0xFFFF |
| | 354 | typedef unsigned char uint16_t; |
| | 355 | typedef signed char int16_t; |
| | 356 | #define INT16_C(c) c |
| | 357 | #define UINT16_C(c) c##U |
| | 358 | #elif SHRT_MIN == ~0x7FFF && SHRT_MAX == 0x7FFF && USHRT_MAX == 0xFFFF |
| | 359 | typedef unsigned short uint16_t; |
| | 360 | typedef signed short int16_t; |
| | 361 | #define INT16_C(c) c |
| | 362 | #define UINT16_C(c) c##U |
| | 363 | #elif INT_MIN == ~0x7FFF && INT_MAX == 0x7FFF && UINT_MAX == 0xFFFF |
| | 364 | typedef unsigned int uint16_t; |
| | 365 | typedef signed int int16_t; |
| | 366 | #define INT16_C(c) c |
| | 367 | #define UINT16_C(c) c##U |
| | 368 | #elif LONG_MIN == ~0x7FFF && LONG_MAX == 0x7FFF && ULONG_MAX == 0xFFFF |
| | 369 | typedef unsigned long uint16_t; |
| | 370 | typedef signed long int16_t; |
| | 371 | #define INT16_C(c) c##L |
| | 372 | #define UINT16_C(c) c##LU |
| | 373 | #elif LLONG_MIN == ~0x7FFF && LLONG_MAX == 0x7FFF && ULLONG_MAX == 0xFFFF |
| | 374 | typedef unsigned long long uint16_t; |
| | 375 | typedef signed long long int16_t; |
| | 376 | #define INT16_C(c) c##LL |
| | 377 | #define UINT16_C(c) c##LLU |
| | 378 | #endif |
| | 379 | #define INT16_MIN (~INT16_C(0x7FFF)) |
| | 380 | #define INT16_MAX ( INT16_C(0x7FFF)) |
| | 381 | #define UINT16_MAX ( INT16_C(0xFFFF)) |
| | 382 | |
| | 383 | #if SCHAR_MIN == ~0x7FFFFFFF && SCHAR_MAX == 0x7FFFFFFF && UCHAR_MAX == 0xFFFFFFFF |
| | 384 | typedef unsigned char uint32_t; |
| | 385 | typedef signed char int32_t; |
| | 386 | #define INT32_C(c) c |
| | 387 | #define UINT32_C(c) c##U |
| | 388 | #elif SHRT_MIN == ~0x7FFFFFFF && SHRT_MAX == 0x7FFFFFFF && USHRT_MAX == 0xFFFFFFFF |
| | 389 | typedef unsigned short uint32_t; |
| | 390 | typedef signed short int32_t; |
| | 391 | #define INT32_C(c) c |
| | 392 | #define UINT32_C(c) c##U |
| | 393 | #elif INT_MIN == ~0x7FFFFFFF && INT_MAX == 0x7FFFFFFF && UINT_MAX == 0xFFFFFFFF |
| | 394 | typedef unsigned int uint32_t; |
| | 395 | typedef signed int int32_t; |
| | 396 | #define INT32_C(c) c |
| | 397 | #define UINT32_C(c) c##U |
| | 398 | #elif LONG_MIN == ~0x7FFFFFFF && LONG_MAX == 0x7FFFFFFF && ULONG_MAX == 0xFFFFFFFF |
| | 399 | typedef unsigned long uint32_t; |
| | 400 | typedef signed long int32_t; |
| | 401 | #define INT32_C(c) c##L |
| | 402 | #define UINT32_C(c) c##LU |
| | 403 | #elif LLONG_MIN == ~0x7FFFFFFF && LLONG_MAX == 0x7FFFFFFF && ULLONG_MAX == 0xFFFFFFFF |
| | 404 | typedef unsigned long long uint32_t; |
| | 405 | typedef signed long long int32_t; |
| | 406 | #define INT32_C(c) c##LL |
| | 407 | #define UINT32_C(c) c##LLU |
| | 408 | #endif |
| | 409 | #define INT32_MIN (~INT32_C(0x7FFFFFFF)) |
| | 410 | #define INT32_MAX ( INT32_C(0x7FFFFFFF)) |
| | 411 | #define UINT32_MAX ( INT32_C(0xFFFFFFFF)) |
| | 412 | |
| | 413 | #if SCHAR_MIN == ~0x7FFFFFFFFFFFFFFF && SCHAR_MAX == 0x7FFFFFFFFFFFFFFF && UCHAR_MAX == 0xFFFFFFFFFFFFFFFF |
| | 414 | typedef unsigned char uint64_t; |
| | 415 | typedef signed char int64_t; |
| | 416 | #define INT64_C(c) c |
| | 417 | #define UINT64_C(c) c##U |
| | 418 | #elif SHRT_MIN == ~0x7FFFFFFFFFFFFFFF && SHRT_MAX == 0x7FFFFFFFFFFFFFFF && USHRT_MAX == 0xFFFFFFFFFFFFFFFF |
| | 419 | typedef unsigned short uint64_t; |
| | 420 | typedef signed short int64_t; |
| | 421 | #define INT64_C(c) c |
| | 422 | #define UINT64_C(c) c##U |
| | 423 | #elif INT_MIN == ~0x7FFFFFFFFFFFFFFF && INT_MAX == 0x7FFFFFFFFFFFFFFF && UINT_MAX == 0xFFFFFFFFFFFFFFFF |
| | 424 | typedef unsigned int uint64_t; |
| | 425 | typedef signed int int64_t; |
| | 426 | #define INT64_C(c) c |
| | 427 | #define UINT64_C(c) c##U |
| | 428 | #elif LONG_MIN == ~0x7FFFFFFFFFFFFFFF && LONG_MAX == 0x7FFFFFFFFFFFFFFF && ULONG_MAX == 0xFFFFFFFFFFFFFFFF |
| | 429 | typedef unsigned long uint64_t; |
| | 430 | typedef signed long int64_t; |
| | 431 | #define INT64_C(c) c##L |
| | 432 | #define UINT64_C(c) c##LU |
| | 433 | #elif LLONG_MIN == ~0x7FFFFFFFFFFFFFFF && LLONG_MAX == 0x7FFFFFFFFFFFFFFF && ULLONG_MAX == 0xFFFFFFFFFFFFFFFF |
| | 434 | typedef unsigned long long uint64_t; |
| | 435 | typedef signed long long int64_t; |
| | 436 | #define INT64_C(c) c##LL |
| | 437 | #define UINT64_C(c) c##LLU |
| | 438 | #endif |
| | 439 | #define INT64_MIN (~INT64_C(0x7FFFFFFFFFFFFFFF)) |
| | 440 | #define INT64_MAX ( INT64_C(0x7FFFFFFFFFFFFFFF)) |
| | 441 | #define UINT64_MAX ( INT64_C(0xFFFFFFFFFFFFFFFF)) |
| | 442 | |
| | 443 | typedef size_t uintptr_t; |
| | 444 | typedef ptrdiff_t intptr_t; |
| | 445 | |
| | 446 | #endif |
| | 447 | |
| 331 | #define zig_minInt_i8 INT8_MIN | 448 | #define zig_minInt_i8 INT8_MIN |
| 332 | #define zig_maxInt_i8 INT8_MAX | 449 | #define zig_maxInt_i8 INT8_MAX |
| 333 | #define zig_minInt_u16 zig_as_u16(0) | 450 | #define zig_minInt_u8 UINT8_C(0) |
| 334 | #define zig_maxInt_u16 UINT16_MAX | 451 | #define zig_maxInt_u8 UINT8_MAX |
| 335 | #define zig_minInt_i16 INT16_MIN | 452 | #define zig_minInt_i16 INT16_MIN |
| 336 | #define zig_maxInt_i16 INT16_MAX | 453 | #define zig_maxInt_i16 INT16_MAX |
| 337 | #define zig_minInt_u32 zig_as_u32(0) | 454 | #define zig_minInt_u16 UINT16_C(0) |
| 338 | #define zig_maxInt_u32 UINT32_MAX | 455 | #define zig_maxInt_u16 UINT16_MAX |
| 339 | #define zig_minInt_i32 INT32_MIN | 456 | #define zig_minInt_i32 INT32_MIN |
| 340 | #define zig_maxInt_i32 INT32_MAX | 457 | #define zig_maxInt_i32 INT32_MAX |
| 341 | #define zig_minInt_u64 zig_as_u64(0) | 458 | #define zig_minInt_u32 UINT32_C(0) |
| 342 | #define zig_maxInt_u64 UINT64_MAX | 459 | #define zig_maxInt_u32 UINT32_MAX |
| 343 | #define zig_minInt_i64 INT64_MIN | 460 | #define zig_minInt_i64 INT64_MIN |
| 344 | #define zig_maxInt_i64 INT64_MAX | 461 | #define zig_maxInt_i64 INT64_MAX |
| | 462 | #define zig_minInt_u64 UINT64_C(0) |
| | 463 | #define zig_maxInt_u64 UINT64_MAX |
| 345 | | 464 | |
| 346 | #define zig_compiler_rt_abbrev_u32 si | 465 | #define zig_intLimit(s, w, limit, bits) zig_shr_##s##w(zig_##limit##Int_##s##w, w - (bits)) |
| 347 | #define zig_compiler_rt_abbrev_i32 si | 466 | #define zig_minInt_i(w, bits) zig_intLimit(i, w, min, bits) |
| 348 | #define zig_compiler_rt_abbrev_u64 di | 467 | #define zig_maxInt_i(w, bits) zig_intLimit(i, w, max, bits) |
| 349 | #define zig_compiler_rt_abbrev_i64 di | 468 | #define zig_minInt_u(w, bits) zig_intLimit(u, w, min, bits) |
| 350 | #define zig_compiler_rt_abbrev_u128 ti | 469 | #define zig_maxInt_u(w, bits) zig_intLimit(u, w, max, bits) |
| 351 | #define zig_compiler_rt_abbrev_i128 ti | | |
| 352 | #define zig_compiler_rt_abbrev_f16 hf | | |
| 353 | #define zig_compiler_rt_abbrev_f32 sf | | |
| 354 | #define zig_compiler_rt_abbrev_f64 df | | |
| 355 | #define zig_compiler_rt_abbrev_f80 xf | | |
| 356 | #define zig_compiler_rt_abbrev_f128 tf | | |
| 357 | | | |
| 358 | zig_extern void *memcpy (void *zig_restrict, void const *zig_restrict, zig_usize); | | |
| 359 | zig_extern void *memset (void *, int, zig_usize); | | |
| 360 | | | |
| 361 | /* ==================== 8/16/32/64-bit Integer Routines ===================== */ | | |
| 362 | | | |
| 363 | #define zig_maxInt(Type, bits) zig_shr_##Type(zig_maxInt_##Type, (zig_bitSizeOf(zig_##Type) - bits)) | | |
| 364 | #define zig_expand_maxInt(Type, bits) zig_maxInt(Type, bits) | | |
| 365 | #define zig_minInt(Type, bits) zig_not_##Type(zig_maxInt(Type, bits), bits) | | |
| 366 | #define zig_expand_minInt(Type, bits) zig_minInt(Type, bits) | | |
| 367 | | 470 | |
| 368 | #define zig_int_operator(Type, RhsType, operation, operator) \ | 471 | #define zig_int_operator(Type, RhsType, operation, operator) \ |
| 369 | static inline zig_##Type zig_##operation##_##Type(zig_##Type lhs, zig_##RhsType rhs) { \ | 472 | static inline Type zig_##operation(Type lhs, RhsType rhs) { \ |
| 370 | return lhs operator rhs; \ | 473 | return lhs operator rhs; \ |
| 371 | } | 474 | } |
| 372 | #define zig_int_basic_operator(Type, operation, operator) \ | 475 | #define zig_int_basic_operator(Type, operation, operator) \ |
| 373 | zig_int_operator(Type, Type, operation, operator) | 476 | zig_int_operator(Type, Type, operation, operator) |
| 374 | #define zig_int_shift_operator(Type, operation, operator) \ | 477 | #define zig_int_shift_operator(Type, operation, operator) \ |
| 375 | zig_int_operator(Type, u8, operation, operator) | 478 | zig_int_operator(Type, uint8_t, operation, operator) |
| 376 | #define zig_int_helpers(w) \ | 479 | #define zig_int_helpers(w) \ |
| 377 | zig_int_basic_operator(u##w, and, &) \ | 480 | zig_int_basic_operator(uint##w##_t, and_u##w, &) \ |
| 378 | zig_int_basic_operator(i##w, and, &) \ | 481 | zig_int_basic_operator( int##w##_t, and_i##w, &) \ |
| 379 | zig_int_basic_operator(u##w, or, |) \ | 482 | zig_int_basic_operator(uint##w##_t, or_u##w, |) \ |
| 380 | zig_int_basic_operator(i##w, or, |) \ | 483 | zig_int_basic_operator( int##w##_t, or_i##w, |) \ |
| 381 | zig_int_basic_operator(u##w, xor, ^) \ | 484 | zig_int_basic_operator(uint##w##_t, xor_u##w, ^) \ |
| 382 | zig_int_basic_operator(i##w, xor, ^) \ | 485 | zig_int_basic_operator( int##w##_t, xor_i##w, ^) \ |
| 383 | zig_int_shift_operator(u##w, shl, <<) \ | 486 | zig_int_shift_operator(uint##w##_t, shl_u##w, <<) \ |
| 384 | zig_int_shift_operator(i##w, shl, <<) \ | 487 | zig_int_shift_operator( int##w##_t, shl_i##w, <<) \ |
| 385 | zig_int_shift_operator(u##w, shr, >>) \ | 488 | zig_int_shift_operator(uint##w##_t, shr_u##w, >>) \ |
| 386 | \ | 489 | \ |
| 387 | static inline zig_i##w zig_shr_i##w(zig_i##w lhs, zig_u8 rhs) { \ | 490 | static inline int##w##_t zig_shr_i##w(int##w##_t lhs, uint8_t rhs) { \ |
| 388 | zig_i##w sign_mask = lhs < zig_as_i##w(0) ? -zig_as_i##w(1) : zig_as_i##w(0); \ | 491 | int##w##_t sign_mask = lhs < INT##w##_C(0) ? -INT##w##_C(1) : INT##w##_C(0); \ |
| 389 | return ((lhs ^ sign_mask) >> rhs) ^ sign_mask; \ | 492 | return ((lhs ^ sign_mask) >> rhs) ^ sign_mask; \ |
| 390 | } \ | 493 | } \ |
| 391 | \ | 494 | \ |
| 392 | static inline zig_u##w zig_not_u##w(zig_u##w val, zig_u8 bits) { \ | 495 | static inline uint##w##_t zig_not_u##w(uint##w##_t val, uint8_t bits) { \ |
| 393 | return val ^ zig_maxInt(u##w, bits); \ | 496 | return val ^ zig_maxInt_u(w, bits); \ |
| 394 | } \ | 497 | } \ |
| 395 | \ | 498 | \ |
| 396 | static inline zig_i##w zig_not_i##w(zig_i##w val, zig_u8 bits) { \ | 499 | static inline int##w##_t zig_not_i##w(int##w##_t val, uint8_t bits) { \ |
| 397 | (void)bits; \ | 500 | (void)bits; \ |
| 398 | return ~val; \ | 501 | return ~val; \ |
| 399 | } \ | 502 | } \ |
| 400 | \ | 503 | \ |
| 401 | static inline zig_u##w zig_wrap_u##w(zig_u##w val, zig_u8 bits) { \ | 504 | static inline uint##w##_t zig_wrap_u##w(uint##w##_t val, uint8_t bits) { \ |
| 402 | return val & zig_maxInt(u##w, bits); \ | 505 | return val & zig_maxInt_u(w, bits); \ |
| 403 | } \ | 506 | } \ |
| 404 | \ | 507 | \ |
| 405 | static inline zig_i##w zig_wrap_i##w(zig_i##w val, zig_u8 bits) { \ | 508 | static inline int##w##_t zig_wrap_i##w(int##w##_t val, uint8_t bits) { \ |
| 406 | return (val & zig_as_u##w(1) << (bits - zig_as_u8(1))) != 0 \ | 509 | return (val & UINT##w##_C(1) << (bits - UINT8_C(1))) != 0 \ |
| 407 | ? val | zig_minInt(i##w, bits) : val & zig_maxInt(i##w, bits); \ | 510 | ? val | zig_minInt_i(w, bits) : val & zig_maxInt_i(w, bits); \ |
| 408 | } \ | 511 | } \ |
| 409 | \ | 512 | \ |
| 410 | zig_int_basic_operator(u##w, div_floor, /) \ | 513 | zig_int_basic_operator(uint##w##_t, div_floor_u##w, /) \ |
| 411 | \ | 514 | \ |
| 412 | static inline zig_i##w zig_div_floor_i##w(zig_i##w lhs, zig_i##w rhs) { \ | 515 | static inline int##w##_t zig_div_floor_i##w(int##w##_t lhs, int##w##_t rhs) { \ |
| 413 | return lhs / rhs - (((lhs ^ rhs) & (lhs % rhs)) < zig_as_i##w(0)); \ | 516 | return lhs / rhs - (((lhs ^ rhs) & (lhs % rhs)) < INT##w##_C(0)); \ |
| 414 | } \ | 517 | } \ |
| 415 | \ | 518 | \ |
| 416 | zig_int_basic_operator(u##w, mod, %) \ | 519 | zig_int_basic_operator(uint##w##_t, mod_u##w, %) \ |
| 417 | \ | 520 | \ |
| 418 | static inline zig_i##w zig_mod_i##w(zig_i##w lhs, zig_i##w rhs) { \ | 521 | static inline int##w##_t zig_mod_i##w(int##w##_t lhs, int##w##_t rhs) { \ |
| 419 | zig_i##w rem = lhs % rhs; \ | 522 | int##w##_t rem = lhs % rhs; \ |
| 420 | return rem + (((lhs ^ rhs) & rem) < zig_as_i##w(0) ? rhs : zig_as_i##w(0)); \ | 523 | return rem + (((lhs ^ rhs) & rem) < INT##w##_C(0) ? rhs : INT##w##_C(0)); \ |
| 421 | } \ | 524 | } \ |
| 422 | \ | 525 | \ |
| 423 | static inline zig_u##w zig_shlw_u##w(zig_u##w lhs, zig_u8 rhs, zig_u8 bits) { \ | 526 | static inline uint##w##_t zig_shlw_u##w(uint##w##_t lhs, uint8_t rhs, uint8_t bits) { \ |
| 424 | return zig_wrap_u##w(zig_shl_u##w(lhs, rhs), bits); \ | 527 | return zig_wrap_u##w(zig_shl_u##w(lhs, rhs), bits); \ |
| 425 | } \ | 528 | } \ |
| 426 | \ | 529 | \ |
| 427 | static inline zig_i##w zig_shlw_i##w(zig_i##w lhs, zig_u8 rhs, zig_u8 bits) { \ | 530 | static inline int##w##_t zig_shlw_i##w(int##w##_t lhs, uint8_t rhs, uint8_t bits) { \ |
| 428 | return zig_wrap_i##w((zig_i##w)zig_shl_u##w((zig_u##w)lhs, (zig_u##w)rhs), bits); \ | 531 | return zig_wrap_i##w((int##w##_t)zig_shl_u##w((uint##w##_t)lhs, (uint##w##_t)rhs), bits); \ |
| 429 | } \ | 532 | } \ |
| 430 | \ | 533 | \ |
| 431 | static inline zig_u##w zig_addw_u##w(zig_u##w lhs, zig_u##w rhs, zig_u8 bits) { \ | 534 | static inline uint##w##_t zig_addw_u##w(uint##w##_t lhs, uint##w##_t rhs, uint8_t bits) { \ |
| 432 | return zig_wrap_u##w(lhs + rhs, bits); \ | 535 | return zig_wrap_u##w(lhs + rhs, bits); \ |
| 433 | } \ | 536 | } \ |
| 434 | \ | 537 | \ |
| 435 | static inline zig_i##w zig_addw_i##w(zig_i##w lhs, zig_i##w rhs, zig_u8 bits) { \ | 538 | static inline int##w##_t zig_addw_i##w(int##w##_t lhs, int##w##_t rhs, uint8_t bits) { \ |
| 436 | return zig_wrap_i##w((zig_i##w)((zig_u##w)lhs + (zig_u##w)rhs), bits); \ | 539 | return zig_wrap_i##w((int##w##_t)((uint##w##_t)lhs + (uint##w##_t)rhs), bits); \ |
| 437 | } \ | 540 | } \ |
| 438 | \ | 541 | \ |
| 439 | static inline zig_u##w zig_subw_u##w(zig_u##w lhs, zig_u##w rhs, zig_u8 bits) { \ | 542 | static inline uint##w##_t zig_subw_u##w(uint##w##_t lhs, uint##w##_t rhs, uint8_t bits) { \ |
| 440 | return zig_wrap_u##w(lhs - rhs, bits); \ | 543 | return zig_wrap_u##w(lhs - rhs, bits); \ |
| 441 | } \ | 544 | } \ |
| 442 | \ | 545 | \ |
| 443 | static inline zig_i##w zig_subw_i##w(zig_i##w lhs, zig_i##w rhs, zig_u8 bits) { \ | 546 | static inline int##w##_t zig_subw_i##w(int##w##_t lhs, int##w##_t rhs, uint8_t bits) { \ |
| 444 | return zig_wrap_i##w((zig_i##w)((zig_u##w)lhs - (zig_u##w)rhs), bits); \ | 547 | return zig_wrap_i##w((int##w##_t)((uint##w##_t)lhs - (uint##w##_t)rhs), bits); \ |
| 445 | } \ | 548 | } \ |
| 446 | \ | 549 | \ |
| 447 | static inline zig_u##w zig_mulw_u##w(zig_u##w lhs, zig_u##w rhs, zig_u8 bits) { \ | 550 | static inline uint##w##_t zig_mulw_u##w(uint##w##_t lhs, uint##w##_t rhs, uint8_t bits) { \ |
| 448 | return zig_wrap_u##w(lhs * rhs, bits); \ | 551 | return zig_wrap_u##w(lhs * rhs, bits); \ |
| 449 | } \ | 552 | } \ |
| 450 | \ | 553 | \ |
| 451 | static inline zig_i##w zig_mulw_i##w(zig_i##w lhs, zig_i##w rhs, zig_u8 bits) { \ | 554 | static inline int##w##_t zig_mulw_i##w(int##w##_t lhs, int##w##_t rhs, uint8_t bits) { \ |
| 452 | return zig_wrap_i##w((zig_i##w)((zig_u##w)lhs * (zig_u##w)rhs), bits); \ | 555 | return zig_wrap_i##w((int##w##_t)((uint##w##_t)lhs * (uint##w##_t)rhs), bits); \ |
| 453 | } | 556 | } |
| 454 | zig_int_helpers(8) | 557 | zig_int_helpers(8) |
| 455 | zig_int_helpers(16) | 558 | zig_int_helpers(16) |
| 456 | zig_int_helpers(32) | 559 | zig_int_helpers(32) |
| 457 | zig_int_helpers(64) | 560 | zig_int_helpers(64) |
| 458 | | 561 | |
| 459 | static inline bool zig_addo_u32(zig_u32 *res, zig_u32 lhs, zig_u32 rhs, zig_u8 bits) { | 562 | static inline bool zig_addo_u32(uint32_t *res, uint32_t lhs, uint32_t rhs, uint8_t bits) { |
| 460 | #if zig_has_builtin(add_overflow) || defined(zig_gnuc) | 563 | #if zig_has_builtin(add_overflow) || defined(zig_gnuc) |
| 461 | zig_u32 full_res; | 564 | uint32_t full_res; |
| 462 | bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); | 565 | bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); |
| 463 | *res = zig_wrap_u32(full_res, bits); | 566 | *res = zig_wrap_u32(full_res, bits); |
| 464 | return overflow || full_res < zig_minInt(u32, bits) || full_res > zig_maxInt(u32, bits); | 567 | return overflow || full_res < zig_minInt_u(32, bits) || full_res > zig_maxInt_u(32, bits); |
| 465 | #else | 568 | #else |
| 466 | *res = zig_addw_u32(lhs, rhs, bits); | 569 | *res = zig_addw_u32(lhs, rhs, bits); |
| 467 | return *res < lhs; | 570 | return *res < lhs; |
| 468 | #endif | 571 | #endif |
| 469 | } | 572 | } |
| 470 | | 573 | |
| 471 | static inline void zig_vaddo_u32(zig_u8 *ov, zig_u32 *res, int n, | 574 | static inline void zig_vaddo_u32(uint8_t *ov, uint32_t *res, int n, |
| 472 | const zig_u32 *lhs, const zig_u32 *rhs, zig_u8 bits) | 575 | const uint32_t *lhs, const uint32_t *rhs, uint8_t bits) |
| 473 | { | 576 | { |
| 474 | for (int i = 0; i < n; ++i) ov[i] = zig_addo_u32(&res[i], lhs[i], rhs[i], bits); | 577 | for (int i = 0; i < n; ++i) ov[i] = zig_addo_u32(&res[i], lhs[i], rhs[i], bits); |
| 475 | } | 578 | } |
| 476 | | 579 | |
| 477 | zig_extern zig_i32 __addosi4(zig_i32 lhs, zig_i32 rhs, zig_c_int *overflow); | 580 | zig_extern int32_t __addosi4(int32_t lhs, int32_t rhs, int *overflow); |
| 478 | static inline bool zig_addo_i32(zig_i32 *res, zig_i32 lhs, zig_i32 rhs, zig_u8 bits) { | 581 | static inline bool zig_addo_i32(int32_t *res, int32_t lhs, int32_t rhs, uint8_t bits) { |
| 479 | #if zig_has_builtin(add_overflow) || defined(zig_gnuc) | 582 | #if zig_has_builtin(add_overflow) || defined(zig_gnuc) |
| 480 | zig_i32 full_res; | 583 | int32_t full_res; |
| 481 | bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); | 584 | bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); |
| 482 | #else | 585 | #else |
| 483 | zig_c_int overflow_int; | 586 | int overflow_int; |
| 484 | zig_i32 full_res = __addosi4(lhs, rhs, &overflow_int); | 587 | int32_t full_res = __addosi4(lhs, rhs, &overflow_int); |
| 485 | bool overflow = overflow_int != 0; | 588 | bool overflow = overflow_int != 0; |
| 486 | #endif | 589 | #endif |
| 487 | *res = zig_wrap_i32(full_res, bits); | 590 | *res = zig_wrap_i32(full_res, bits); |
| 488 | return overflow || full_res < zig_minInt(i32, bits) || full_res > zig_maxInt(i32, bits); | 591 | return overflow || full_res < zig_minInt_i(32, bits) || full_res > zig_maxInt_i(32, bits); |
| 489 | } | 592 | } |
| 490 | | 593 | |
| 491 | static inline void zig_vaddo_i32(zig_u8 *ov, zig_i32 *res, int n, | 594 | static inline void zig_vaddo_i32(uint8_t *ov, int32_t *res, int n, |
| 492 | const zig_i32 *lhs, const zig_i32 *rhs, zig_u8 bits) | 595 | const int32_t *lhs, const int32_t *rhs, uint8_t bits) |
| 493 | { | 596 | { |
| 494 | for (int i = 0; i < n; ++i) ov[i] = zig_addo_i32(&res[i], lhs[i], rhs[i], bits); | 597 | for (int i = 0; i < n; ++i) ov[i] = zig_addo_i32(&res[i], lhs[i], rhs[i], bits); |
| 495 | } | 598 | } |
| 496 | | 599 | |
| 497 | static inline bool zig_addo_u64(zig_u64 *res, zig_u64 lhs, zig_u64 rhs, zig_u8 bits) { | 600 | static inline bool zig_addo_u64(uint64_t *res, uint64_t lhs, uint64_t rhs, uint8_t bits) { |
| 498 | #if zig_has_builtin(add_overflow) || defined(zig_gnuc) | 601 | #if zig_has_builtin(add_overflow) || defined(zig_gnuc) |
| 499 | zig_u64 full_res; | 602 | uint64_t full_res; |
| 500 | bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); | 603 | bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); |
| 501 | *res = zig_wrap_u64(full_res, bits); | 604 | *res = zig_wrap_u64(full_res, bits); |
| 502 | return overflow || full_res < zig_minInt(u64, bits) || full_res > zig_maxInt(u64, bits); | 605 | return overflow || full_res < zig_minInt_u(64, bits) || full_res > zig_maxInt_u(64, bits); |
| 503 | #else | 606 | #else |
| 504 | *res = zig_addw_u64(lhs, rhs, bits); | 607 | *res = zig_addw_u64(lhs, rhs, bits); |
| 505 | return *res < lhs; | 608 | return *res < lhs; |
| 506 | #endif | 609 | #endif |
| 507 | } | 610 | } |
| 508 | | 611 | |
| 509 | static inline void zig_vaddo_u64(zig_u8 *ov, zig_u64 *res, int n, | 612 | static inline void zig_vaddo_u64(uint8_t *ov, uint64_t *res, int n, |
| 510 | const zig_u64 *lhs, const zig_u64 *rhs, zig_u8 bits) | 613 | const uint64_t *lhs, const uint64_t *rhs, uint8_t bits) |
| 511 | { | 614 | { |
| 512 | for (int i = 0; i < n; ++i) ov[i] = zig_addo_u64(&res[i], lhs[i], rhs[i], bits); | 615 | for (int i = 0; i < n; ++i) ov[i] = zig_addo_u64(&res[i], lhs[i], rhs[i], bits); |
| 513 | } | 616 | } |
| 514 | | 617 | |
| 515 | zig_extern zig_i64 __addodi4(zig_i64 lhs, zig_i64 rhs, zig_c_int *overflow); | 618 | zig_extern int64_t __addodi4(int64_t lhs, int64_t rhs, int *overflow); |
| 516 | static inline bool zig_addo_i64(zig_i64 *res, zig_i64 lhs, zig_i64 rhs, zig_u8 bits) { | 619 | static inline bool zig_addo_i64(int64_t *res, int64_t lhs, int64_t rhs, uint8_t bits) { |
| 517 | #if zig_has_builtin(add_overflow) || defined(zig_gnuc) | 620 | #if zig_has_builtin(add_overflow) || defined(zig_gnuc) |
| 518 | zig_i64 full_res; | 621 | int64_t full_res; |
| 519 | bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); | 622 | bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); |
| 520 | #else | 623 | #else |
| 521 | zig_c_int overflow_int; | 624 | int overflow_int; |
| 522 | zig_i64 full_res = __addodi4(lhs, rhs, &overflow_int); | 625 | int64_t full_res = __addodi4(lhs, rhs, &overflow_int); |
| 523 | bool overflow = overflow_int != 0; | 626 | bool overflow = overflow_int != 0; |
| 524 | #endif | 627 | #endif |
| 525 | *res = zig_wrap_i64(full_res, bits); | 628 | *res = zig_wrap_i64(full_res, bits); |
| 526 | return overflow || full_res < zig_minInt(i64, bits) || full_res > zig_maxInt(i64, bits); | 629 | return overflow || full_res < zig_minInt_i(64, bits) || full_res > zig_maxInt_i(64, bits); |
| 527 | } | 630 | } |
| 528 | | 631 | |
| 529 | static inline void zig_vaddo_i64(zig_u8 *ov, zig_i64 *res, int n, | 632 | static inline void zig_vaddo_i64(uint8_t *ov, int64_t *res, int n, |
| 530 | const zig_i64 *lhs, const zig_i64 *rhs, zig_u8 bits) | 633 | const int64_t *lhs, const int64_t *rhs, uint8_t bits) |
| 531 | { | 634 | { |
| 532 | for (int i = 0; i < n; ++i) ov[i] = zig_addo_i64(&res[i], lhs[i], rhs[i], bits); | 635 | for (int i = 0; i < n; ++i) ov[i] = zig_addo_i64(&res[i], lhs[i], rhs[i], bits); |
| 533 | } | 636 | } |
| 534 | | 637 | |
| 535 | static inline bool zig_addo_u8(zig_u8 *res, zig_u8 lhs, zig_u8 rhs, zig_u8 bits) { | 638 | static inline bool zig_addo_u8(uint8_t *res, uint8_t lhs, uint8_t rhs, uint8_t bits) { |
| 536 | #if zig_has_builtin(add_overflow) || defined(zig_gnuc) | 639 | #if zig_has_builtin(add_overflow) || defined(zig_gnuc) |
| 537 | zig_u8 full_res; | 640 | uint8_t full_res; |
| 538 | bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); | 641 | bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); |
| 539 | *res = zig_wrap_u8(full_res, bits); | 642 | *res = zig_wrap_u8(full_res, bits); |
| 540 | return overflow || full_res < zig_minInt(u8, bits) || full_res > zig_maxInt(u8, bits); | 643 | return overflow || full_res < zig_minInt_u(8, bits) || full_res > zig_maxInt_u(8, bits); |
| 541 | #else | 644 | #else |
| 542 | zig_u32 full_res; | 645 | uint32_t full_res; |
| 543 | bool overflow = zig_addo_u32(&full_res, lhs, rhs, bits); | 646 | bool overflow = zig_addo_u32(&full_res, lhs, rhs, bits); |
| 544 | *res = (zig_u8)full_res; | 647 | *res = (uint8_t)full_res; |
| 545 | return overflow; | 648 | return overflow; |
| 546 | #endif | 649 | #endif |
| 547 | } | 650 | } |
| 548 | | 651 | |
| 549 | static inline void zig_vaddo_u8(zig_u8 *ov, zig_u8 *res, int n, | 652 | static inline void zig_vaddo_u8(uint8_t *ov, uint8_t *res, int n, |
| 550 | const zig_u8 *lhs, const zig_u8 *rhs, zig_u8 bits) | 653 | const uint8_t *lhs, const uint8_t *rhs, uint8_t bits) |
| 551 | { | 654 | { |
| 552 | for (int i = 0; i < n; ++i) ov[i] = zig_addo_u8(&res[i], lhs[i], rhs[i], bits); | 655 | for (int i = 0; i < n; ++i) ov[i] = zig_addo_u8(&res[i], lhs[i], rhs[i], bits); |
| 553 | } | 656 | } |
| 554 | | 657 | |
| 555 | static inline bool zig_addo_i8(zig_i8 *res, zig_i8 lhs, zig_i8 rhs, zig_u8 bits) { | 658 | static inline bool zig_addo_i8(int8_t *res, int8_t lhs, int8_t rhs, uint8_t bits) { |
| 556 | #if zig_has_builtin(add_overflow) || defined(zig_gnuc) | 659 | #if zig_has_builtin(add_overflow) || defined(zig_gnuc) |
| 557 | zig_i8 full_res; | 660 | int8_t full_res; |
| 558 | bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); | 661 | bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); |
| 559 | *res = zig_wrap_i8(full_res, bits); | 662 | *res = zig_wrap_i8(full_res, bits); |
| 560 | return overflow || full_res < zig_minInt(i8, bits) || full_res > zig_maxInt(i8, bits); | 663 | return overflow || full_res < zig_minInt_i(8, bits) || full_res > zig_maxInt_i(8, bits); |
| 561 | #else | 664 | #else |
| 562 | zig_i32 full_res; | 665 | int32_t full_res; |
| 563 | bool overflow = zig_addo_i32(&full_res, lhs, rhs, bits); | 666 | bool overflow = zig_addo_i32(&full_res, lhs, rhs, bits); |
| 564 | *res = (zig_i8)full_res; | 667 | *res = (int8_t)full_res; |
| 565 | return overflow; | 668 | return overflow; |
| 566 | #endif | 669 | #endif |
| 567 | } | 670 | } |
| 568 | | 671 | |
| 569 | static inline void zig_vaddo_i8(zig_u8 *ov, zig_i8 *res, int n, | 672 | static inline void zig_vaddo_i8(uint8_t *ov, int8_t *res, int n, |
| 570 | const zig_i8 *lhs, const zig_i8 *rhs, zig_u8 bits) | 673 | const int8_t *lhs, const int8_t *rhs, uint8_t bits) |
| 571 | { | 674 | { |
| 572 | for (int i = 0; i < n; ++i) ov[i] = zig_addo_i8(&res[i], lhs[i], rhs[i], bits); | 675 | for (int i = 0; i < n; ++i) ov[i] = zig_addo_i8(&res[i], lhs[i], rhs[i], bits); |
| 573 | } | 676 | } |
| 574 | | 677 | |
| 575 | static inline bool zig_addo_u16(zig_u16 *res, zig_u16 lhs, zig_u16 rhs, zig_u8 bits) { | 678 | static inline bool zig_addo_u16(uint16_t *res, uint16_t lhs, uint16_t rhs, uint8_t bits) { |
| 576 | #if zig_has_builtin(add_overflow) || defined(zig_gnuc) | 679 | #if zig_has_builtin(add_overflow) || defined(zig_gnuc) |
| 577 | zig_u16 full_res; | 680 | uint16_t full_res; |
| 578 | bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); | 681 | bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); |
| 579 | *res = zig_wrap_u16(full_res, bits); | 682 | *res = zig_wrap_u16(full_res, bits); |
| 580 | return overflow || full_res < zig_minInt(u16, bits) || full_res > zig_maxInt(u16, bits); | 683 | return overflow || full_res < zig_minInt_u(16, bits) || full_res > zig_maxInt_u(16, bits); |
| 581 | #else | 684 | #else |
| 582 | zig_u32 full_res; | 685 | uint32_t full_res; |
| 583 | bool overflow = zig_addo_u32(&full_res, lhs, rhs, bits); | 686 | bool overflow = zig_addo_u32(&full_res, lhs, rhs, bits); |
| 584 | *res = (zig_u16)full_res; | 687 | *res = (uint16_t)full_res; |
| 585 | return overflow; | 688 | return overflow; |
| 586 | #endif | 689 | #endif |
| 587 | } | 690 | } |
| 588 | | 691 | |
| 589 | static inline void zig_vaddo_u16(zig_u8 *ov, zig_u16 *res, int n, | 692 | static inline void zig_vaddo_u16(uint8_t *ov, uint16_t *res, int n, |
| 590 | const zig_u16 *lhs, const zig_u16 *rhs, zig_u8 bits) | 693 | const uint16_t *lhs, const uint16_t *rhs, uint8_t bits) |
| 591 | { | 694 | { |
| 592 | for (int i = 0; i < n; ++i) ov[i] = zig_addo_u16(&res[i], lhs[i], rhs[i], bits); | 695 | for (int i = 0; i < n; ++i) ov[i] = zig_addo_u16(&res[i], lhs[i], rhs[i], bits); |
| 593 | } | 696 | } |
| 594 | | 697 | |
| 595 | static inline bool zig_addo_i16(zig_i16 *res, zig_i16 lhs, zig_i16 rhs, zig_u8 bits) { | 698 | static inline bool zig_addo_i16(int16_t *res, int16_t lhs, int16_t rhs, uint8_t bits) { |
| 596 | #if zig_has_builtin(add_overflow) || defined(zig_gnuc) | 699 | #if zig_has_builtin(add_overflow) || defined(zig_gnuc) |
| 597 | zig_i16 full_res; | 700 | int16_t full_res; |
| 598 | bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); | 701 | bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); |
| 599 | *res = zig_wrap_i16(full_res, bits); | 702 | *res = zig_wrap_i16(full_res, bits); |
| 600 | return overflow || full_res < zig_minInt(i16, bits) || full_res > zig_maxInt(i16, bits); | 703 | return overflow || full_res < zig_minInt_i(16, bits) || full_res > zig_maxInt_i(16, bits); |
| 601 | #else | 704 | #else |
| 602 | zig_i32 full_res; | 705 | int32_t full_res; |
| 603 | bool overflow = zig_addo_i32(&full_res, lhs, rhs, bits); | 706 | bool overflow = zig_addo_i32(&full_res, lhs, rhs, bits); |
| 604 | *res = (zig_i16)full_res; | 707 | *res = (int16_t)full_res; |
| 605 | return overflow; | 708 | return overflow; |
| 606 | #endif | 709 | #endif |
| 607 | } | 710 | } |
| 608 | | 711 | |
| 609 | static inline void zig_vaddo_i16(zig_u8 *ov, zig_i16 *res, int n, | 712 | static inline void zig_vaddo_i16(uint8_t *ov, int16_t *res, int n, |
| 610 | const zig_i16 *lhs, const zig_i16 *rhs, zig_u8 bits) | 713 | const int16_t *lhs, const int16_t *rhs, uint8_t bits) |
| 611 | { | 714 | { |
| 612 | for (int i = 0; i < n; ++i) ov[i] = zig_addo_i16(&res[i], lhs[i], rhs[i], bits); | 715 | for (int i = 0; i < n; ++i) ov[i] = zig_addo_i16(&res[i], lhs[i], rhs[i], bits); |
| 613 | } | 716 | } |
| 614 | | 717 | |
| 615 | static inline bool zig_subo_u32(zig_u32 *res, zig_u32 lhs, zig_u32 rhs, zig_u8 bits) { | 718 | static inline bool zig_subo_u32(uint32_t *res, uint32_t lhs, uint32_t rhs, uint8_t bits) { |
| 616 | #if zig_has_builtin(sub_overflow) || defined(zig_gnuc) | 719 | #if zig_has_builtin(sub_overflow) || defined(zig_gnuc) |
| 617 | zig_u32 full_res; | 720 | uint32_t full_res; |
| 618 | bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); | 721 | bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); |
| 619 | *res = zig_wrap_u32(full_res, bits); | 722 | *res = zig_wrap_u32(full_res, bits); |
| 620 | return overflow || full_res < zig_minInt(u32, bits) || full_res > zig_maxInt(u32, bits); | 723 | return overflow || full_res < zig_minInt_u(32, bits) || full_res > zig_maxInt_u(32, bits); |
| 621 | #else | 724 | #else |
| 622 | *res = zig_subw_u32(lhs, rhs, bits); | 725 | *res = zig_subw_u32(lhs, rhs, bits); |
| 623 | return *res > lhs; | 726 | return *res > lhs; |
| 624 | #endif | 727 | #endif |
| 625 | } | 728 | } |
| 626 | | 729 | |
| 627 | static inline void zig_vsubo_u32(zig_u8 *ov, zig_u32 *res, int n, | 730 | static inline void zig_vsubo_u32(uint8_t *ov, uint32_t *res, int n, |
| 628 | const zig_u32 *lhs, const zig_u32 *rhs, zig_u8 bits) | 731 | const uint32_t *lhs, const uint32_t *rhs, uint8_t bits) |
| 629 | { | 732 | { |
| 630 | for (int i = 0; i < n; ++i) ov[i] = zig_subo_u32(&res[i], lhs[i], rhs[i], bits); | 733 | for (int i = 0; i < n; ++i) ov[i] = zig_subo_u32(&res[i], lhs[i], rhs[i], bits); |
| 631 | } | 734 | } |
| 632 | | 735 | |
| 633 | zig_extern zig_i32 __subosi4(zig_i32 lhs, zig_i32 rhs, zig_c_int *overflow); | 736 | zig_extern int32_t __subosi4(int32_t lhs, int32_t rhs, int *overflow); |
| 634 | static inline bool zig_subo_i32(zig_i32 *res, zig_i32 lhs, zig_i32 rhs, zig_u8 bits) { | 737 | static inline bool zig_subo_i32(int32_t *res, int32_t lhs, int32_t rhs, uint8_t bits) { |
| 635 | #if zig_has_builtin(sub_overflow) || defined(zig_gnuc) | 738 | #if zig_has_builtin(sub_overflow) || defined(zig_gnuc) |
| 636 | zig_i32 full_res; | 739 | int32_t full_res; |
| 637 | bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); | 740 | bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); |
| 638 | #else | 741 | #else |
| 639 | zig_c_int overflow_int; | 742 | int overflow_int; |
| 640 | zig_i32 full_res = __subosi4(lhs, rhs, &overflow_int); | 743 | int32_t full_res = __subosi4(lhs, rhs, &overflow_int); |
| 641 | bool overflow = overflow_int != 0; | 744 | bool overflow = overflow_int != 0; |
| 642 | #endif | 745 | #endif |
| 643 | *res = zig_wrap_i32(full_res, bits); | 746 | *res = zig_wrap_i32(full_res, bits); |
| 644 | return overflow || full_res < zig_minInt(i32, bits) || full_res > zig_maxInt(i32, bits); | 747 | return overflow || full_res < zig_minInt_i(32, bits) || full_res > zig_maxInt_i(32, bits); |
| 645 | } | 748 | } |
| 646 | | 749 | |
| 647 | static inline void zig_vsubo_i32(zig_u8 *ov, zig_i32 *res, int n, | 750 | static inline void zig_vsubo_i32(uint8_t *ov, int32_t *res, int n, |
| 648 | const zig_i32 *lhs, const zig_i32 *rhs, zig_u8 bits) | 751 | const int32_t *lhs, const int32_t *rhs, uint8_t bits) |
| 649 | { | 752 | { |
| 650 | for (int i = 0; i < n; ++i) ov[i] = zig_subo_i32(&res[i], lhs[i], rhs[i], bits); | 753 | for (int i = 0; i < n; ++i) ov[i] = zig_subo_i32(&res[i], lhs[i], rhs[i], bits); |
| 651 | } | 754 | } |
| 652 | | 755 | |
| 653 | static inline bool zig_subo_u64(zig_u64 *res, zig_u64 lhs, zig_u64 rhs, zig_u8 bits) { | 756 | static inline bool zig_subo_u64(uint64_t *res, uint64_t lhs, uint64_t rhs, uint8_t bits) { |
| 654 | #if zig_has_builtin(sub_overflow) || defined(zig_gnuc) | 757 | #if zig_has_builtin(sub_overflow) || defined(zig_gnuc) |
| 655 | zig_u64 full_res; | 758 | uint64_t full_res; |
| 656 | bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); | 759 | bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); |
| 657 | *res = zig_wrap_u64(full_res, bits); | 760 | *res = zig_wrap_u64(full_res, bits); |
| 658 | return overflow || full_res < zig_minInt(u64, bits) || full_res > zig_maxInt(u64, bits); | 761 | return overflow || full_res < zig_minInt_u(64, bits) || full_res > zig_maxInt_u(64, bits); |
| 659 | #else | 762 | #else |
| 660 | *res = zig_subw_u64(lhs, rhs, bits); | 763 | *res = zig_subw_u64(lhs, rhs, bits); |
| 661 | return *res > lhs; | 764 | return *res > lhs; |
| 662 | #endif | 765 | #endif |
| 663 | } | 766 | } |
| 664 | | 767 | |
| 665 | static inline void zig_vsubo_u64(zig_u8 *ov, zig_u64 *res, int n, | 768 | static inline void zig_vsubo_u64(uint8_t *ov, uint64_t *res, int n, |
| 666 | const zig_u64 *lhs, const zig_u64 *rhs, zig_u8 bits) | 769 | const uint64_t *lhs, const uint64_t *rhs, uint8_t bits) |
| 667 | { | 770 | { |
| 668 | for (int i = 0; i < n; ++i) ov[i] = zig_subo_u64(&res[i], lhs[i], rhs[i], bits); | 771 | for (int i = 0; i < n; ++i) ov[i] = zig_subo_u64(&res[i], lhs[i], rhs[i], bits); |
| 669 | } | 772 | } |
| 670 | | 773 | |
| 671 | zig_extern zig_i64 __subodi4(zig_i64 lhs, zig_i64 rhs, zig_c_int *overflow); | 774 | zig_extern int64_t __subodi4(int64_t lhs, int64_t rhs, int *overflow); |
| 672 | static inline bool zig_subo_i64(zig_i64 *res, zig_i64 lhs, zig_i64 rhs, zig_u8 bits) { | 775 | static inline bool zig_subo_i64(int64_t *res, int64_t lhs, int64_t rhs, uint8_t bits) { |
| 673 | #if zig_has_builtin(sub_overflow) || defined(zig_gnuc) | 776 | #if zig_has_builtin(sub_overflow) || defined(zig_gnuc) |
| 674 | zig_i64 full_res; | 777 | int64_t full_res; |
| 675 | bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); | 778 | bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); |
| 676 | #else | 779 | #else |
| 677 | zig_c_int overflow_int; | 780 | int overflow_int; |
| 678 | zig_i64 full_res = __subodi4(lhs, rhs, &overflow_int); | 781 | int64_t full_res = __subodi4(lhs, rhs, &overflow_int); |
| 679 | bool overflow = overflow_int != 0; | 782 | bool overflow = overflow_int != 0; |
| 680 | #endif | 783 | #endif |
| 681 | *res = zig_wrap_i64(full_res, bits); | 784 | *res = zig_wrap_i64(full_res, bits); |
| 682 | return overflow || full_res < zig_minInt(i64, bits) || full_res > zig_maxInt(i64, bits); | 785 | return overflow || full_res < zig_minInt_i(64, bits) || full_res > zig_maxInt_i(64, bits); |
| 683 | } | 786 | } |
| 684 | | 787 | |
| 685 | static inline void zig_vsubo_i64(zig_u8 *ov, zig_i64 *res, int n, | 788 | static inline void zig_vsubo_i64(uint8_t *ov, int64_t *res, int n, |
| 686 | const zig_i64 *lhs, const zig_i64 *rhs, zig_u8 bits) | 789 | const int64_t *lhs, const int64_t *rhs, uint8_t bits) |
| 687 | { | 790 | { |
| 688 | for (int i = 0; i < n; ++i) ov[i] = zig_subo_i64(&res[i], lhs[i], rhs[i], bits); | 791 | for (int i = 0; i < n; ++i) ov[i] = zig_subo_i64(&res[i], lhs[i], rhs[i], bits); |
| 689 | } | 792 | } |
| 690 | | 793 | |
| 691 | static inline bool zig_subo_u8(zig_u8 *res, zig_u8 lhs, zig_u8 rhs, zig_u8 bits) { | 794 | static inline bool zig_subo_u8(uint8_t *res, uint8_t lhs, uint8_t rhs, uint8_t bits) { |
| 692 | #if zig_has_builtin(sub_overflow) || defined(zig_gnuc) | 795 | #if zig_has_builtin(sub_overflow) || defined(zig_gnuc) |
| 693 | zig_u8 full_res; | 796 | uint8_t full_res; |
| 694 | bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); | 797 | bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); |
| 695 | *res = zig_wrap_u8(full_res, bits); | 798 | *res = zig_wrap_u8(full_res, bits); |
| 696 | return overflow || full_res < zig_minInt(u8, bits) || full_res > zig_maxInt(u8, bits); | 799 | return overflow || full_res < zig_minInt_u(8, bits) || full_res > zig_maxInt_u(8, bits); |
| 697 | #else | 800 | #else |
| 698 | zig_u32 full_res; | 801 | uint32_t full_res; |
| 699 | bool overflow = zig_subo_u32(&full_res, lhs, rhs, bits); | 802 | bool overflow = zig_subo_u32(&full_res, lhs, rhs, bits); |
| 700 | *res = (zig_u8)full_res; | 803 | *res = (uint8_t)full_res; |
| 701 | return overflow; | 804 | return overflow; |
| 702 | #endif | 805 | #endif |
| 703 | } | 806 | } |
| 704 | | 807 | |
| 705 | static inline void zig_vsubo_u8(zig_u8 *ov, zig_u8 *res, int n, | 808 | static inline void zig_vsubo_u8(uint8_t *ov, uint8_t *res, int n, |
| 706 | const zig_u8 *lhs, const zig_u8 *rhs, zig_u8 bits) | 809 | const uint8_t *lhs, const uint8_t *rhs, uint8_t bits) |
| 707 | { | 810 | { |
| 708 | for (int i = 0; i < n; ++i) ov[i] = zig_subo_u8(&res[i], lhs[i], rhs[i], bits); | 811 | for (int i = 0; i < n; ++i) ov[i] = zig_subo_u8(&res[i], lhs[i], rhs[i], bits); |
| 709 | } | 812 | } |
| 710 | | 813 | |
| 711 | static inline bool zig_subo_i8(zig_i8 *res, zig_i8 lhs, zig_i8 rhs, zig_u8 bits) { | 814 | static inline bool zig_subo_i8(int8_t *res, int8_t lhs, int8_t rhs, uint8_t bits) { |
| 712 | #if zig_has_builtin(sub_overflow) || defined(zig_gnuc) | 815 | #if zig_has_builtin(sub_overflow) || defined(zig_gnuc) |
| 713 | zig_i8 full_res; | 816 | int8_t full_res; |
| 714 | bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); | 817 | bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); |
| 715 | *res = zig_wrap_i8(full_res, bits); | 818 | *res = zig_wrap_i8(full_res, bits); |
| 716 | return overflow || full_res < zig_minInt(i8, bits) || full_res > zig_maxInt(i8, bits); | 819 | return overflow || full_res < zig_minInt_i(8, bits) || full_res > zig_maxInt_i(8, bits); |
| 717 | #else | 820 | #else |
| 718 | zig_i32 full_res; | 821 | int32_t full_res; |
| 719 | bool overflow = zig_subo_i32(&full_res, lhs, rhs, bits); | 822 | bool overflow = zig_subo_i32(&full_res, lhs, rhs, bits); |
| 720 | *res = (zig_i8)full_res; | 823 | *res = (int8_t)full_res; |
| 721 | return overflow; | 824 | return overflow; |
| 722 | #endif | 825 | #endif |
| 723 | } | 826 | } |
| 724 | | 827 | |
| 725 | static inline void zig_vsubo_i8(zig_u8 *ov, zig_i8 *res, int n, | 828 | static inline void zig_vsubo_i8(uint8_t *ov, int8_t *res, int n, |
| 726 | const zig_i8 *lhs, const zig_i8 *rhs, zig_u8 bits) | 829 | const int8_t *lhs, const int8_t *rhs, uint8_t bits) |
| 727 | { | 830 | { |
| 728 | for (int i = 0; i < n; ++i) ov[i] = zig_subo_i8(&res[i], lhs[i], rhs[i], bits); | 831 | for (int i = 0; i < n; ++i) ov[i] = zig_subo_i8(&res[i], lhs[i], rhs[i], bits); |
| 729 | } | 832 | } |
| 730 | | 833 | |
| 731 | | 834 | |
| 732 | static inline bool zig_subo_u16(zig_u16 *res, zig_u16 lhs, zig_u16 rhs, zig_u8 bits) { | 835 | static inline bool zig_subo_u16(uint16_t *res, uint16_t lhs, uint16_t rhs, uint8_t bits) { |
| 733 | #if zig_has_builtin(sub_overflow) || defined(zig_gnuc) | 836 | #if zig_has_builtin(sub_overflow) || defined(zig_gnuc) |
| 734 | zig_u16 full_res; | 837 | uint16_t full_res; |
| 735 | bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); | 838 | bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); |
| 736 | *res = zig_wrap_u16(full_res, bits); | 839 | *res = zig_wrap_u16(full_res, bits); |
| 737 | return overflow || full_res < zig_minInt(u16, bits) || full_res > zig_maxInt(u16, bits); | 840 | return overflow || full_res < zig_minInt_u(16, bits) || full_res > zig_maxInt_u(16, bits); |
| 738 | #else | 841 | #else |
| 739 | zig_u32 full_res; | 842 | uint32_t full_res; |
| 740 | bool overflow = zig_subo_u32(&full_res, lhs, rhs, bits); | 843 | bool overflow = zig_subo_u32(&full_res, lhs, rhs, bits); |
| 741 | *res = (zig_u16)full_res; | 844 | *res = (uint16_t)full_res; |
| 742 | return overflow; | 845 | return overflow; |
| 743 | #endif | 846 | #endif |
| 744 | } | 847 | } |
| 745 | | 848 | |
| 746 | static inline void zig_vsubo_u16(zig_u8 *ov, zig_u16 *res, int n, | 849 | static inline void zig_vsubo_u16(uint8_t *ov, uint16_t *res, int n, |
| 747 | const zig_u16 *lhs, const zig_u16 *rhs, zig_u8 bits) | 850 | const uint16_t *lhs, const uint16_t *rhs, uint8_t bits) |
| 748 | { | 851 | { |
| 749 | for (int i = 0; i < n; ++i) ov[i] = zig_subo_u16(&res[i], lhs[i], rhs[i], bits); | 852 | for (int i = 0; i < n; ++i) ov[i] = zig_subo_u16(&res[i], lhs[i], rhs[i], bits); |
| 750 | } | 853 | } |
| 751 | | 854 | |
| 752 | | 855 | |
| 753 | static inline bool zig_subo_i16(zig_i16 *res, zig_i16 lhs, zig_i16 rhs, zig_u8 bits) { | 856 | static inline bool zig_subo_i16(int16_t *res, int16_t lhs, int16_t rhs, uint8_t bits) { |
| 754 | #if zig_has_builtin(sub_overflow) || defined(zig_gnuc) | 857 | #if zig_has_builtin(sub_overflow) || defined(zig_gnuc) |
| 755 | zig_i16 full_res; | 858 | int16_t full_res; |
| 756 | bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); | 859 | bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); |
| 757 | *res = zig_wrap_i16(full_res, bits); | 860 | *res = zig_wrap_i16(full_res, bits); |
| 758 | return overflow || full_res < zig_minInt(i16, bits) || full_res > zig_maxInt(i16, bits); | 861 | return overflow || full_res < zig_minInt_i(16, bits) || full_res > zig_maxInt_i(16, bits); |
| 759 | #else | 862 | #else |
| 760 | zig_i32 full_res; | 863 | int32_t full_res; |
| 761 | bool overflow = zig_subo_i32(&full_res, lhs, rhs, bits); | 864 | bool overflow = zig_subo_i32(&full_res, lhs, rhs, bits); |
| 762 | *res = (zig_i16)full_res; | 865 | *res = (int16_t)full_res; |
| 763 | return overflow; | 866 | return overflow; |
| 764 | #endif | 867 | #endif |
| 765 | } | 868 | } |
| 766 | | 869 | |
| 767 | static inline void zig_vsubo_i16(zig_u8 *ov, zig_i16 *res, int n, | 870 | static inline void zig_vsubo_i16(uint8_t *ov, int16_t *res, int n, |
| 768 | const zig_i16 *lhs, const zig_i16 *rhs, zig_u8 bits) | 871 | const int16_t *lhs, const int16_t *rhs, uint8_t bits) |
| 769 | { | 872 | { |
| 770 | for (int i = 0; i < n; ++i) ov[i] = zig_subo_i16(&res[i], lhs[i], rhs[i], bits); | 873 | for (int i = 0; i < n; ++i) ov[i] = zig_subo_i16(&res[i], lhs[i], rhs[i], bits); |
| 771 | } | 874 | } |
| 772 | | 875 | |
| 773 | static inline bool zig_mulo_u32(zig_u32 *res, zig_u32 lhs, zig_u32 rhs, zig_u8 bits) { | 876 | static inline bool zig_mulo_u32(uint32_t *res, uint32_t lhs, uint32_t rhs, uint8_t bits) { |
| 774 | #if zig_has_builtin(mul_overflow) || defined(zig_gnuc) | 877 | #if zig_has_builtin(mul_overflow) || defined(zig_gnuc) |
| 775 | zig_u32 full_res; | 878 | uint32_t full_res; |
| 776 | bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); | 879 | bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); |
| 777 | *res = zig_wrap_u32(full_res, bits); | 880 | *res = zig_wrap_u32(full_res, bits); |
| 778 | return overflow || full_res < zig_minInt(u32, bits) || full_res > zig_maxInt(u32, bits); | 881 | return overflow || full_res < zig_minInt_u(32, bits) || full_res > zig_maxInt_u(32, bits); |
| 779 | #else | 882 | #else |
| 780 | *res = zig_mulw_u32(lhs, rhs, bits); | 883 | *res = zig_mulw_u32(lhs, rhs, bits); |
| 781 | return rhs != zig_as_u32(0) && lhs > zig_maxInt(u32, bits) / rhs; | 884 | return rhs != UINT32_C(0) && lhs > zig_maxInt_u(32, bits) / rhs; |
| 782 | #endif | 885 | #endif |
| 783 | } | 886 | } |
| 784 | | 887 | |
| 785 | static inline void zig_vmulo_u32(zig_u8 *ov, zig_u32 *res, int n, | 888 | static inline void zig_vmulo_u32(uint8_t *ov, uint32_t *res, int n, |
| 786 | const zig_u32 *lhs, const zig_u32 *rhs, zig_u8 bits) | 889 | const uint32_t *lhs, const uint32_t *rhs, uint8_t bits) |
| 787 | { | 890 | { |
| 788 | for (int i = 0; i < n; ++i) ov[i] = zig_mulo_u32(&res[i], lhs[i], rhs[i], bits); | 891 | for (int i = 0; i < n; ++i) ov[i] = zig_mulo_u32(&res[i], lhs[i], rhs[i], bits); |
| 789 | } | 892 | } |
| 790 | | 893 | |
| 791 | zig_extern zig_i32 __mulosi4(zig_i32 lhs, zig_i32 rhs, zig_c_int *overflow); | 894 | zig_extern int32_t __mulosi4(int32_t lhs, int32_t rhs, int *overflow); |
| 792 | static inline bool zig_mulo_i32(zig_i32 *res, zig_i32 lhs, zig_i32 rhs, zig_u8 bits) { | 895 | static inline bool zig_mulo_i32(int32_t *res, int32_t lhs, int32_t rhs, uint8_t bits) { |
| 793 | #if zig_has_builtin(mul_overflow) || defined(zig_gnuc) | 896 | #if zig_has_builtin(mul_overflow) || defined(zig_gnuc) |
| 794 | zig_i32 full_res; | 897 | int32_t full_res; |
| 795 | bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); | 898 | bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); |
| 796 | #else | 899 | #else |
| 797 | zig_c_int overflow_int; | 900 | int overflow_int; |
| 798 | zig_i32 full_res = __mulosi4(lhs, rhs, &overflow_int); | 901 | int32_t full_res = __mulosi4(lhs, rhs, &overflow_int); |
| 799 | bool overflow = overflow_int != 0; | 902 | bool overflow = overflow_int != 0; |
| 800 | #endif | 903 | #endif |
| 801 | *res = zig_wrap_i32(full_res, bits); | 904 | *res = zig_wrap_i32(full_res, bits); |
| 802 | return overflow || full_res < zig_minInt(i32, bits) || full_res > zig_maxInt(i32, bits); | 905 | return overflow || full_res < zig_minInt_i(32, bits) || full_res > zig_maxInt_i(32, bits); |
| 803 | } | 906 | } |
| 804 | | 907 | |
| 805 | static inline void zig_vmulo_i32(zig_u8 *ov, zig_i32 *res, int n, | 908 | static inline void zig_vmulo_i32(uint8_t *ov, int32_t *res, int n, |
| 806 | const zig_i32 *lhs, const zig_i32 *rhs, zig_u8 bits) | 909 | const int32_t *lhs, const int32_t *rhs, uint8_t bits) |
| 807 | { | 910 | { |
| 808 | for (int i = 0; i < n; ++i) ov[i] = zig_mulo_i32(&res[i], lhs[i], rhs[i], bits); | 911 | for (int i = 0; i < n; ++i) ov[i] = zig_mulo_i32(&res[i], lhs[i], rhs[i], bits); |
| 809 | } | 912 | } |
| 810 | | 913 | |
| 811 | static inline bool zig_mulo_u64(zig_u64 *res, zig_u64 lhs, zig_u64 rhs, zig_u8 bits) { | 914 | static inline bool zig_mulo_u64(uint64_t *res, uint64_t lhs, uint64_t rhs, uint8_t bits) { |
| 812 | #if zig_has_builtin(mul_overflow) || defined(zig_gnuc) | 915 | #if zig_has_builtin(mul_overflow) || defined(zig_gnuc) |
| 813 | zig_u64 full_res; | 916 | uint64_t full_res; |
| 814 | bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); | 917 | bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); |
| 815 | *res = zig_wrap_u64(full_res, bits); | 918 | *res = zig_wrap_u64(full_res, bits); |
| 816 | return overflow || full_res < zig_minInt(u64, bits) || full_res > zig_maxInt(u64, bits); | 919 | return overflow || full_res < zig_minInt_u(64, bits) || full_res > zig_maxInt_u(64, bits); |
| 817 | #else | 920 | #else |
| 818 | *res = zig_mulw_u64(lhs, rhs, bits); | 921 | *res = zig_mulw_u64(lhs, rhs, bits); |
| 819 | return rhs != zig_as_u64(0) && lhs > zig_maxInt(u64, bits) / rhs; | 922 | return rhs != UINT64_C(0) && lhs > zig_maxInt_u(64, bits) / rhs; |
| 820 | #endif | 923 | #endif |
| 821 | } | 924 | } |
| 822 | | 925 | |
| 823 | static inline void zig_vmulo_u64(zig_u8 *ov, zig_u64 *res, int n, | 926 | static inline void zig_vmulo_u64(uint8_t *ov, uint64_t *res, int n, |
| 824 | const zig_u64 *lhs, const zig_u64 *rhs, zig_u8 bits) | 927 | const uint64_t *lhs, const uint64_t *rhs, uint8_t bits) |
| 825 | { | 928 | { |
| 826 | for (int i = 0; i < n; ++i) ov[i] = zig_mulo_u64(&res[i], lhs[i], rhs[i], bits); | 929 | for (int i = 0; i < n; ++i) ov[i] = zig_mulo_u64(&res[i], lhs[i], rhs[i], bits); |
| 827 | } | 930 | } |
| 828 | | 931 | |
| 829 | zig_extern zig_i64 __mulodi4(zig_i64 lhs, zig_i64 rhs, zig_c_int *overflow); | 932 | zig_extern int64_t __mulodi4(int64_t lhs, int64_t rhs, int *overflow); |
| 830 | static inline bool zig_mulo_i64(zig_i64 *res, zig_i64 lhs, zig_i64 rhs, zig_u8 bits) { | 933 | static inline bool zig_mulo_i64(int64_t *res, int64_t lhs, int64_t rhs, uint8_t bits) { |
| 831 | #if zig_has_builtin(mul_overflow) || defined(zig_gnuc) | 934 | #if zig_has_builtin(mul_overflow) || defined(zig_gnuc) |
| 832 | zig_i64 full_res; | 935 | int64_t full_res; |
| 833 | bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); | 936 | bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); |
| 834 | #else | 937 | #else |
| 835 | zig_c_int overflow_int; | 938 | int overflow_int; |
| 836 | zig_i64 full_res = __mulodi4(lhs, rhs, &overflow_int); | 939 | int64_t full_res = __mulodi4(lhs, rhs, &overflow_int); |
| 837 | bool overflow = overflow_int != 0; | 940 | bool overflow = overflow_int != 0; |
| 838 | #endif | 941 | #endif |
| 839 | *res = zig_wrap_i64(full_res, bits); | 942 | *res = zig_wrap_i64(full_res, bits); |
| 840 | return overflow || full_res < zig_minInt(i64, bits) || full_res > zig_maxInt(i64, bits); | 943 | return overflow || full_res < zig_minInt_i(64, bits) || full_res > zig_maxInt_i(64, bits); |
| 841 | } | 944 | } |
| 842 | | 945 | |
| 843 | static inline void zig_vmulo_i64(zig_u8 *ov, zig_i64 *res, int n, | 946 | static inline void zig_vmulo_i64(uint8_t *ov, int64_t *res, int n, |
| 844 | const zig_i64 *lhs, const zig_i64 *rhs, zig_u8 bits) | 947 | const int64_t *lhs, const int64_t *rhs, uint8_t bits) |
| 845 | { | 948 | { |
| 846 | for (int i = 0; i < n; ++i) ov[i] = zig_mulo_i64(&res[i], lhs[i], rhs[i], bits); | 949 | for (int i = 0; i < n; ++i) ov[i] = zig_mulo_i64(&res[i], lhs[i], rhs[i], bits); |
| 847 | } | 950 | } |
| 848 | | 951 | |
| 849 | static inline bool zig_mulo_u8(zig_u8 *res, zig_u8 lhs, zig_u8 rhs, zig_u8 bits) { | 952 | static inline bool zig_mulo_u8(uint8_t *res, uint8_t lhs, uint8_t rhs, uint8_t bits) { |
| 850 | #if zig_has_builtin(mul_overflow) || defined(zig_gnuc) | 953 | #if zig_has_builtin(mul_overflow) || defined(zig_gnuc) |
| 851 | zig_u8 full_res; | 954 | uint8_t full_res; |
| 852 | bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); | 955 | bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); |
| 853 | *res = zig_wrap_u8(full_res, bits); | 956 | *res = zig_wrap_u8(full_res, bits); |
| 854 | return overflow || full_res < zig_minInt(u8, bits) || full_res > zig_maxInt(u8, bits); | 957 | return overflow || full_res < zig_minInt_u(8, bits) || full_res > zig_maxInt_u(8, bits); |
| 855 | #else | 958 | #else |
| 856 | zig_u32 full_res; | 959 | uint32_t full_res; |
| 857 | bool overflow = zig_mulo_u32(&full_res, lhs, rhs, bits); | 960 | bool overflow = zig_mulo_u32(&full_res, lhs, rhs, bits); |
| 858 | *res = (zig_u8)full_res; | 961 | *res = (uint8_t)full_res; |
| 859 | return overflow; | 962 | return overflow; |
| 860 | #endif | 963 | #endif |
| 861 | } | 964 | } |
| 862 | | 965 | |
| 863 | static inline void zig_vmulo_u8(zig_u8 *ov, zig_u8 *res, int n, | 966 | static inline void zig_vmulo_u8(uint8_t *ov, uint8_t *res, int n, |
| 864 | const zig_u8 *lhs, const zig_u8 *rhs, zig_u8 bits) | 967 | const uint8_t *lhs, const uint8_t *rhs, uint8_t bits) |
| 865 | { | 968 | { |
| 866 | for (int i = 0; i < n; ++i) ov[i] = zig_mulo_u8(&res[i], lhs[i], rhs[i], bits); | 969 | for (int i = 0; i < n; ++i) ov[i] = zig_mulo_u8(&res[i], lhs[i], rhs[i], bits); |
| 867 | } | 970 | } |
| 868 | | 971 | |
| 869 | static inline bool zig_mulo_i8(zig_i8 *res, zig_i8 lhs, zig_i8 rhs, zig_u8 bits) { | 972 | static inline bool zig_mulo_i8(int8_t *res, int8_t lhs, int8_t rhs, uint8_t bits) { |
| 870 | #if zig_has_builtin(mul_overflow) || defined(zig_gnuc) | 973 | #if zig_has_builtin(mul_overflow) || defined(zig_gnuc) |
| 871 | zig_i8 full_res; | 974 | int8_t full_res; |
| 872 | bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); | 975 | bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); |
| 873 | *res = zig_wrap_i8(full_res, bits); | 976 | *res = zig_wrap_i8(full_res, bits); |
| 874 | return overflow || full_res < zig_minInt(i8, bits) || full_res > zig_maxInt(i8, bits); | 977 | return overflow || full_res < zig_minInt_i(8, bits) || full_res > zig_maxInt_i(8, bits); |
| 875 | #else | 978 | #else |
| 876 | zig_i32 full_res; | 979 | int32_t full_res; |
| 877 | bool overflow = zig_mulo_i32(&full_res, lhs, rhs, bits); | 980 | bool overflow = zig_mulo_i32(&full_res, lhs, rhs, bits); |
| 878 | *res = (zig_i8)full_res; | 981 | *res = (int8_t)full_res; |
| 879 | return overflow; | 982 | return overflow; |
| 880 | #endif | 983 | #endif |
| 881 | } | 984 | } |
| 882 | | 985 | |
| 883 | static inline void zig_vmulo_i8(zig_u8 *ov, zig_i8 *res, int n, | 986 | static inline void zig_vmulo_i8(uint8_t *ov, int8_t *res, int n, |
| 884 | const zig_i8 *lhs, const zig_i8 *rhs, zig_u8 bits) | 987 | const int8_t *lhs, const int8_t *rhs, uint8_t bits) |
| 885 | { | 988 | { |
| 886 | for (int i = 0; i < n; ++i) ov[i] = zig_mulo_i8(&res[i], lhs[i], rhs[i], bits); | 989 | for (int i = 0; i < n; ++i) ov[i] = zig_mulo_i8(&res[i], lhs[i], rhs[i], bits); |
| 887 | } | 990 | } |
| 888 | | 991 | |
| 889 | static inline bool zig_mulo_u16(zig_u16 *res, zig_u16 lhs, zig_u16 rhs, zig_u8 bits) { | 992 | static inline bool zig_mulo_u16(uint16_t *res, uint16_t lhs, uint16_t rhs, uint8_t bits) { |
| 890 | #if zig_has_builtin(mul_overflow) || defined(zig_gnuc) | 993 | #if zig_has_builtin(mul_overflow) || defined(zig_gnuc) |
| 891 | zig_u16 full_res; | 994 | uint16_t full_res; |
| 892 | bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); | 995 | bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); |
| 893 | *res = zig_wrap_u16(full_res, bits); | 996 | *res = zig_wrap_u16(full_res, bits); |
| 894 | return overflow || full_res < zig_minInt(u16, bits) || full_res > zig_maxInt(u16, bits); | 997 | return overflow || full_res < zig_minInt_u(16, bits) || full_res > zig_maxInt_u(16, bits); |
| 895 | #else | 998 | #else |
| 896 | zig_u32 full_res; | 999 | uint32_t full_res; |
| 897 | bool overflow = zig_mulo_u32(&full_res, lhs, rhs, bits); | 1000 | bool overflow = zig_mulo_u32(&full_res, lhs, rhs, bits); |
| 898 | *res = (zig_u16)full_res; | 1001 | *res = (uint16_t)full_res; |
| 899 | return overflow; | 1002 | return overflow; |
| 900 | #endif | 1003 | #endif |
| 901 | } | 1004 | } |
| 902 | | 1005 | |
| 903 | static inline void zig_vmulo_u16(zig_u8 *ov, zig_u16 *res, int n, | 1006 | static inline void zig_vmulo_u16(uint8_t *ov, uint16_t *res, int n, |
| 904 | const zig_u16 *lhs, const zig_u16 *rhs, zig_u8 bits) | 1007 | const uint16_t *lhs, const uint16_t *rhs, uint8_t bits) |
| 905 | { | 1008 | { |
| 906 | for (int i = 0; i < n; ++i) ov[i] = zig_mulo_u16(&res[i], lhs[i], rhs[i], bits); | 1009 | for (int i = 0; i < n; ++i) ov[i] = zig_mulo_u16(&res[i], lhs[i], rhs[i], bits); |
| 907 | } | 1010 | } |
| 908 | | 1011 | |
| 909 | static inline bool zig_mulo_i16(zig_i16 *res, zig_i16 lhs, zig_i16 rhs, zig_u8 bits) { | 1012 | static inline bool zig_mulo_i16(int16_t *res, int16_t lhs, int16_t rhs, uint8_t bits) { |
| 910 | #if zig_has_builtin(mul_overflow) || defined(zig_gnuc) | 1013 | #if zig_has_builtin(mul_overflow) || defined(zig_gnuc) |
| 911 | zig_i16 full_res; | 1014 | int16_t full_res; |
| 912 | bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); | 1015 | bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); |
| 913 | *res = zig_wrap_i16(full_res, bits); | 1016 | *res = zig_wrap_i16(full_res, bits); |
| 914 | return overflow || full_res < zig_minInt(i16, bits) || full_res > zig_maxInt(i16, bits); | 1017 | return overflow || full_res < zig_minInt_i(16, bits) || full_res > zig_maxInt_i(16, bits); |
| 915 | #else | 1018 | #else |
| 916 | zig_i32 full_res; | 1019 | int32_t full_res; |
| 917 | bool overflow = zig_mulo_i32(&full_res, lhs, rhs, bits); | 1020 | bool overflow = zig_mulo_i32(&full_res, lhs, rhs, bits); |
| 918 | *res = (zig_i16)full_res; | 1021 | *res = (int16_t)full_res; |
| 919 | return overflow; | 1022 | return overflow; |
| 920 | #endif | 1023 | #endif |
| 921 | } | 1024 | } |
| 922 | | 1025 | |
| 923 | static inline void zig_vmulo_i16(zig_u8 *ov, zig_i16 *res, int n, | 1026 | static inline void zig_vmulo_i16(uint8_t *ov, int16_t *res, int n, |
| 924 | const zig_i16 *lhs, const zig_i16 *rhs, zig_u8 bits) | 1027 | const int16_t *lhs, const int16_t *rhs, uint8_t bits) |
| 925 | { | 1028 | { |
| 926 | for (int i = 0; i < n; ++i) ov[i] = zig_mulo_i16(&res[i], lhs[i], rhs[i], bits); | 1029 | for (int i = 0; i < n; ++i) ov[i] = zig_mulo_i16(&res[i], lhs[i], rhs[i], bits); |
| 927 | } | 1030 | } |
| 928 | | 1031 | |
| 929 | #define zig_int_builtins(w) \ | 1032 | #define zig_int_builtins(w) \ |
| 930 | static inline bool zig_shlo_u##w(zig_u##w *res, zig_u##w lhs, zig_u8 rhs, zig_u8 bits) { \ | 1033 | static inline bool zig_shlo_u##w(uint##w##_t *res, uint##w##_t lhs, uint8_t rhs, uint8_t bits) { \ |
| 931 | *res = zig_shlw_u##w(lhs, rhs, bits); \ | 1034 | *res = zig_shlw_u##w(lhs, rhs, bits); \ |
| 932 | return lhs > zig_maxInt(u##w, bits) >> rhs; \ | 1035 | return lhs > zig_maxInt_u(w, bits) >> rhs; \ |
| 933 | } \ | 1036 | } \ |
| 934 | \ | 1037 | \ |
| 935 | static inline bool zig_shlo_i##w(zig_i##w *res, zig_i##w lhs, zig_u8 rhs, zig_u8 bits) { \ | 1038 | static inline bool zig_shlo_i##w(int##w##_t *res, int##w##_t lhs, uint8_t rhs, uint8_t bits) { \ |
| 936 | *res = zig_shlw_i##w(lhs, rhs, bits); \ | 1039 | *res = zig_shlw_i##w(lhs, rhs, bits); \ |
| 937 | zig_i##w mask = (zig_i##w)(zig_maxInt_u##w << (bits - rhs - 1)); \ | 1040 | int##w##_t mask = (int##w##_t)(UINT##w##_MAX << (bits - rhs - 1)); \ |
| 938 | return (lhs & mask) != zig_as_i##w(0) && (lhs & mask) != mask; \ | 1041 | return (lhs & mask) != INT##w##_C(0) && (lhs & mask) != mask; \ |
| 939 | } \ | 1042 | } \ |
| 940 | \ | 1043 | \ |
| 941 | static inline zig_u##w zig_shls_u##w(zig_u##w lhs, zig_u##w rhs, zig_u8 bits) { \ | 1044 | static inline uint##w##_t zig_shls_u##w(uint##w##_t lhs, uint##w##_t rhs, uint8_t bits) { \ |
| 942 | zig_u##w res; \ | 1045 | uint##w##_t res; \ |
| 943 | if (rhs >= bits) return lhs != zig_as_u##w(0) ? zig_maxInt(u##w, bits) : lhs; \ | 1046 | if (rhs >= bits) return lhs != UINT##w##_C(0) ? zig_maxInt_u(w, bits) : lhs; \ |
| 944 | return zig_shlo_u##w(&res, lhs, (zig_u8)rhs, bits) ? zig_maxInt(u##w, bits) : res; \ | 1047 | return zig_shlo_u##w(&res, lhs, (uint8_t)rhs, bits) ? zig_maxInt_u(w, bits) : res; \ |
| 945 | } \ | 1048 | } \ |
| 946 | \ | 1049 | \ |
| 947 | static inline zig_i##w zig_shls_i##w(zig_i##w lhs, zig_i##w rhs, zig_u8 bits) { \ | 1050 | static inline int##w##_t zig_shls_i##w(int##w##_t lhs, int##w##_t rhs, uint8_t bits) { \ |
| 948 | zig_i##w res; \ | 1051 | int##w##_t res; \ |
| 949 | if ((zig_u##w)rhs < (zig_u##w)bits && !zig_shlo_i##w(&res, lhs, rhs, bits)) return res; \ | 1052 | if ((uint##w##_t)rhs < (uint##w##_t)bits && !zig_shlo_i##w(&res, lhs, rhs, bits)) return res; \ |
| 950 | return lhs < zig_as_i##w(0) ? zig_minInt(i##w, bits) : zig_maxInt(i##w, bits); \ | 1053 | return lhs < INT##w##_C(0) ? zig_minInt_i(w, bits) : zig_maxInt_i(w, bits); \ |
| 951 | } \ | 1054 | } \ |
| 952 | \ | 1055 | \ |
| 953 | static inline zig_u##w zig_adds_u##w(zig_u##w lhs, zig_u##w rhs, zig_u8 bits) { \ | 1056 | static inline uint##w##_t zig_adds_u##w(uint##w##_t lhs, uint##w##_t rhs, uint8_t bits) { \ |
| 954 | zig_u##w res; \ | 1057 | uint##w##_t res; \ |
| 955 | return zig_addo_u##w(&res, lhs, rhs, bits) ? zig_maxInt(u##w, bits) : res; \ | 1058 | return zig_addo_u##w(&res, lhs, rhs, bits) ? zig_maxInt_u(w, bits) : res; \ |
| 956 | } \ | 1059 | } \ |
| 957 | \ | 1060 | \ |
| 958 | static inline zig_i##w zig_adds_i##w(zig_i##w lhs, zig_i##w rhs, zig_u8 bits) { \ | 1061 | static inline int##w##_t zig_adds_i##w(int##w##_t lhs, int##w##_t rhs, uint8_t bits) { \ |
| 959 | zig_i##w res; \ | 1062 | int##w##_t res; \ |
| 960 | if (!zig_addo_i##w(&res, lhs, rhs, bits)) return res; \ | 1063 | if (!zig_addo_i##w(&res, lhs, rhs, bits)) return res; \ |
| 961 | return res >= zig_as_i##w(0) ? zig_minInt(i##w, bits) : zig_maxInt(i##w, bits); \ | 1064 | return res >= INT##w##_C(0) ? zig_minInt_i(w, bits) : zig_maxInt_i(w, bits); \ |
| 962 | } \ | 1065 | } \ |
| 963 | \ | 1066 | \ |
| 964 | static inline zig_u##w zig_subs_u##w(zig_u##w lhs, zig_u##w rhs, zig_u8 bits) { \ | 1067 | static inline uint##w##_t zig_subs_u##w(uint##w##_t lhs, uint##w##_t rhs, uint8_t bits) { \ |
| 965 | zig_u##w res; \ | 1068 | uint##w##_t res; \ |
| 966 | return zig_subo_u##w(&res, lhs, rhs, bits) ? zig_minInt(u##w, bits) : res; \ | 1069 | return zig_subo_u##w(&res, lhs, rhs, bits) ? zig_minInt_u(w, bits) : res; \ |
| 967 | } \ | 1070 | } \ |
| 968 | \ | 1071 | \ |
| 969 | static inline zig_i##w zig_subs_i##w(zig_i##w lhs, zig_i##w rhs, zig_u8 bits) { \ | 1072 | static inline int##w##_t zig_subs_i##w(int##w##_t lhs, int##w##_t rhs, uint8_t bits) { \ |
| 970 | zig_i##w res; \ | 1073 | int##w##_t res; \ |
| 971 | if (!zig_subo_i##w(&res, lhs, rhs, bits)) return res; \ | 1074 | if (!zig_subo_i##w(&res, lhs, rhs, bits)) return res; \ |
| 972 | return res >= zig_as_i##w(0) ? zig_minInt(i##w, bits) : zig_maxInt(i##w, bits); \ | 1075 | return res >= INT##w##_C(0) ? zig_minInt_i(w, bits) : zig_maxInt_i(w, bits); \ |
| 973 | } \ | 1076 | } \ |
| 974 | \ | 1077 | \ |
| 975 | static inline zig_u##w zig_muls_u##w(zig_u##w lhs, zig_u##w rhs, zig_u8 bits) { \ | 1078 | static inline uint##w##_t zig_muls_u##w(uint##w##_t lhs, uint##w##_t rhs, uint8_t bits) { \ |
| 976 | zig_u##w res; \ | 1079 | uint##w##_t res; \ |
| 977 | return zig_mulo_u##w(&res, lhs, rhs, bits) ? zig_maxInt(u##w, bits) : res; \ | 1080 | return zig_mulo_u##w(&res, lhs, rhs, bits) ? zig_maxInt_u(w, bits) : res; \ |
| 978 | } \ | 1081 | } \ |
| 979 | \ | 1082 | \ |
| 980 | static inline zig_i##w zig_muls_i##w(zig_i##w lhs, zig_i##w rhs, zig_u8 bits) { \ | 1083 | static inline int##w##_t zig_muls_i##w(int##w##_t lhs, int##w##_t rhs, uint8_t bits) { \ |
| 981 | zig_i##w res; \ | 1084 | int##w##_t res; \ |
| 982 | if (!zig_mulo_i##w(&res, lhs, rhs, bits)) return res; \ | 1085 | if (!zig_mulo_i##w(&res, lhs, rhs, bits)) return res; \ |
| 983 | return (lhs ^ rhs) < zig_as_i##w(0) ? zig_minInt(i##w, bits) : zig_maxInt(i##w, bits); \ | 1086 | return (lhs ^ rhs) < INT##w##_C(0) ? zig_minInt_i(w, bits) : zig_maxInt_i(w, bits); \ |
| 984 | } | 1087 | } |
| 985 | zig_int_builtins(8) | 1088 | zig_int_builtins(8) |
| 986 | zig_int_builtins(16) | 1089 | zig_int_builtins(16) |
| ... | @@ -988,89 +1091,89 @@ zig_int_builtins(32) | ... | @@ -988,89 +1091,89 @@ zig_int_builtins(32) |
| 988 | zig_int_builtins(64) | 1091 | zig_int_builtins(64) |
| 989 | | 1092 | |
| 990 | #define zig_builtin8(name, val) __builtin_##name(val) | 1093 | #define zig_builtin8(name, val) __builtin_##name(val) |
| 991 | typedef zig_c_uint zig_Builtin8; | 1094 | typedef unsigned int zig_Builtin8; |
| 992 | | 1095 | |
| 993 | #define zig_builtin16(name, val) __builtin_##name(val) | 1096 | #define zig_builtin16(name, val) __builtin_##name(val) |
| 994 | typedef zig_c_uint zig_Builtin16; | 1097 | typedef unsigned int zig_Builtin16; |
| 995 | | 1098 | |
| 996 | #if INT_MIN <= INT32_MIN | 1099 | #if INT_MIN <= INT32_MIN |
| 997 | #define zig_builtin32(name, val) __builtin_##name(val) | 1100 | #define zig_builtin32(name, val) __builtin_##name(val) |
| 998 | typedef zig_c_uint zig_Builtin32; | 1101 | typedef unsigned int zig_Builtin32; |
| 999 | #elif LONG_MIN <= INT32_MIN | 1102 | #elif LONG_MIN <= INT32_MIN |
| 1000 | #define zig_builtin32(name, val) __builtin_##name##l(val) | 1103 | #define zig_builtin32(name, val) __builtin_##name##l(val) |
| 1001 | typedef zig_c_ulong zig_Builtin32; | 1104 | typedef unsigned long zig_Builtin32; |
| 1002 | #endif | 1105 | #endif |
| 1003 | | 1106 | |
| 1004 | #if INT_MIN <= INT64_MIN | 1107 | #if INT_MIN <= INT64_MIN |
| 1005 | #define zig_builtin64(name, val) __builtin_##name(val) | 1108 | #define zig_builtin64(name, val) __builtin_##name(val) |
| 1006 | typedef zig_c_uint zig_Builtin64; | 1109 | typedef unsigned int zig_Builtin64; |
| 1007 | #elif LONG_MIN <= INT64_MIN | 1110 | #elif LONG_MIN <= INT64_MIN |
| 1008 | #define zig_builtin64(name, val) __builtin_##name##l(val) | 1111 | #define zig_builtin64(name, val) __builtin_##name##l(val) |
| 1009 | typedef zig_c_ulong zig_Builtin64; | 1112 | typedef unsigned long zig_Builtin64; |
| 1010 | #elif LLONG_MIN <= INT64_MIN | 1113 | #elif LLONG_MIN <= INT64_MIN |
| 1011 | #define zig_builtin64(name, val) __builtin_##name##ll(val) | 1114 | #define zig_builtin64(name, val) __builtin_##name##ll(val) |
| 1012 | typedef zig_c_ulonglong zig_Builtin64; | 1115 | typedef unsigned long long zig_Builtin64; |
| 1013 | #endif | 1116 | #endif |
| 1014 | | 1117 | |
| 1015 | static inline zig_u8 zig_byte_swap_u8(zig_u8 val, zig_u8 bits) { | 1118 | static inline uint8_t zig_byte_swap_u8(uint8_t val, uint8_t bits) { |
| 1016 | return zig_wrap_u8(val >> (8 - bits), bits); | 1119 | return zig_wrap_u8(val >> (8 - bits), bits); |
| 1017 | } | 1120 | } |
| 1018 | | 1121 | |
| 1019 | static inline zig_i8 zig_byte_swap_i8(zig_i8 val, zig_u8 bits) { | 1122 | static inline int8_t zig_byte_swap_i8(int8_t val, uint8_t bits) { |
| 1020 | return zig_wrap_i8((zig_i8)zig_byte_swap_u8((zig_u8)val, bits), bits); | 1123 | return zig_wrap_i8((int8_t)zig_byte_swap_u8((uint8_t)val, bits), bits); |
| 1021 | } | 1124 | } |
| 1022 | | 1125 | |
| 1023 | static inline zig_u16 zig_byte_swap_u16(zig_u16 val, zig_u8 bits) { | 1126 | static inline uint16_t zig_byte_swap_u16(uint16_t val, uint8_t bits) { |
| 1024 | zig_u16 full_res; | 1127 | uint16_t full_res; |
| 1025 | #if zig_has_builtin(bswap16) || defined(zig_gnuc) | 1128 | #if zig_has_builtin(bswap16) || defined(zig_gnuc) |
| 1026 | full_res = __builtin_bswap16(val); | 1129 | full_res = __builtin_bswap16(val); |
| 1027 | #else | 1130 | #else |
| 1028 | full_res = (zig_u16)zig_byte_swap_u8((zig_u8)(val >> 0), 8) << 8 | | 1131 | full_res = (uint16_t)zig_byte_swap_u8((uint8_t)(val >> 0), 8) << 8 | |
| 1029 | (zig_u16)zig_byte_swap_u8((zig_u8)(val >> 8), 8) >> 0; | 1132 | (uint16_t)zig_byte_swap_u8((uint8_t)(val >> 8), 8) >> 0; |
| 1030 | #endif | 1133 | #endif |
| 1031 | return zig_wrap_u16(full_res >> (16 - bits), bits); | 1134 | return zig_wrap_u16(full_res >> (16 - bits), bits); |
| 1032 | } | 1135 | } |
| 1033 | | 1136 | |
| 1034 | static inline zig_i16 zig_byte_swap_i16(zig_i16 val, zig_u8 bits) { | 1137 | static inline int16_t zig_byte_swap_i16(int16_t val, uint8_t bits) { |
| 1035 | return zig_wrap_i16((zig_i16)zig_byte_swap_u16((zig_u16)val, bits), bits); | 1138 | return zig_wrap_i16((int16_t)zig_byte_swap_u16((uint16_t)val, bits), bits); |
| 1036 | } | 1139 | } |
| 1037 | | 1140 | |
| 1038 | static inline zig_u32 zig_byte_swap_u32(zig_u32 val, zig_u8 bits) { | 1141 | static inline uint32_t zig_byte_swap_u32(uint32_t val, uint8_t bits) { |
| 1039 | zig_u32 full_res; | 1142 | uint32_t full_res; |
| 1040 | #if zig_has_builtin(bswap32) || defined(zig_gnuc) | 1143 | #if zig_has_builtin(bswap32) || defined(zig_gnuc) |
| 1041 | full_res = __builtin_bswap32(val); | 1144 | full_res = __builtin_bswap32(val); |
| 1042 | #else | 1145 | #else |
| 1043 | full_res = (zig_u32)zig_byte_swap_u16((zig_u16)(val >> 0), 16) << 16 | | 1146 | full_res = (uint32_t)zig_byte_swap_u16((uint16_t)(val >> 0), 16) << 16 | |
| 1044 | (zig_u32)zig_byte_swap_u16((zig_u16)(val >> 16), 16) >> 0; | 1147 | (uint32_t)zig_byte_swap_u16((uint16_t)(val >> 16), 16) >> 0; |
| 1045 | #endif | 1148 | #endif |
| 1046 | return zig_wrap_u32(full_res >> (32 - bits), bits); | 1149 | return zig_wrap_u32(full_res >> (32 - bits), bits); |
| 1047 | } | 1150 | } |
| 1048 | | 1151 | |
| 1049 | static inline zig_i32 zig_byte_swap_i32(zig_i32 val, zig_u8 bits) { | 1152 | static inline int32_t zig_byte_swap_i32(int32_t val, uint8_t bits) { |
| 1050 | return zig_wrap_i32((zig_i32)zig_byte_swap_u32((zig_u32)val, bits), bits); | 1153 | return zig_wrap_i32((int32_t)zig_byte_swap_u32((uint32_t)val, bits), bits); |
| 1051 | } | 1154 | } |
| 1052 | | 1155 | |
| 1053 | static inline zig_u64 zig_byte_swap_u64(zig_u64 val, zig_u8 bits) { | 1156 | static inline uint64_t zig_byte_swap_u64(uint64_t val, uint8_t bits) { |
| 1054 | zig_u64 full_res; | 1157 | uint64_t full_res; |
| 1055 | #if zig_has_builtin(bswap64) || defined(zig_gnuc) | 1158 | #if zig_has_builtin(bswap64) || defined(zig_gnuc) |
| 1056 | full_res = __builtin_bswap64(val); | 1159 | full_res = __builtin_bswap64(val); |
| 1057 | #else | 1160 | #else |
| 1058 | full_res = (zig_u64)zig_byte_swap_u32((zig_u32)(val >> 0), 32) << 32 | | 1161 | full_res = (uint64_t)zig_byte_swap_u32((uint32_t)(val >> 0), 32) << 32 | |
| 1059 | (zig_u64)zig_byte_swap_u32((zig_u32)(val >> 32), 32) >> 0; | 1162 | (uint64_t)zig_byte_swap_u32((uint32_t)(val >> 32), 32) >> 0; |
| 1060 | #endif | 1163 | #endif |
| 1061 | return zig_wrap_u64(full_res >> (64 - bits), bits); | 1164 | return zig_wrap_u64(full_res >> (64 - bits), bits); |
| 1062 | } | 1165 | } |
| 1063 | | 1166 | |
| 1064 | static inline zig_i64 zig_byte_swap_i64(zig_i64 val, zig_u8 bits) { | 1167 | static inline int64_t zig_byte_swap_i64(int64_t val, uint8_t bits) { |
| 1065 | return zig_wrap_i64((zig_i64)zig_byte_swap_u64((zig_u64)val, bits), bits); | 1168 | return zig_wrap_i64((int64_t)zig_byte_swap_u64((uint64_t)val, bits), bits); |
| 1066 | } | 1169 | } |
| 1067 | | 1170 | |
| 1068 | static inline zig_u8 zig_bit_reverse_u8(zig_u8 val, zig_u8 bits) { | 1171 | static inline uint8_t zig_bit_reverse_u8(uint8_t val, uint8_t bits) { |
| 1069 | zig_u8 full_res; | 1172 | uint8_t full_res; |
| 1070 | #if zig_has_builtin(bitreverse8) | 1173 | #if zig_has_builtin(bitreverse8) |
| 1071 | full_res = __builtin_bitreverse8(val); | 1174 | full_res = __builtin_bitreverse8(val); |
| 1072 | #else | 1175 | #else |
| 1073 | static zig_u8 const lut[0x10] = { | 1176 | static uint8_t const lut[0x10] = { |
| 1074 | 0x0, 0x8, 0x4, 0xc, 0x2, 0xa, 0x6, 0xe, | 1177 | 0x0, 0x8, 0x4, 0xc, 0x2, 0xa, 0x6, 0xe, |
| 1075 | 0x1, 0x9, 0x5, 0xd, 0x3, 0xb, 0x7, 0xf | 1178 | 0x1, 0x9, 0x5, 0xd, 0x3, 0xb, 0x7, 0xf |
| 1076 | }; | 1179 | }; |
| ... | @@ -1079,62 +1182,62 @@ static inline zig_u8 zig_bit_reverse_u8(zig_u8 val, zig_u8 bits) { | ... | @@ -1079,62 +1182,62 @@ static inline zig_u8 zig_bit_reverse_u8(zig_u8 val, zig_u8 bits) { |
| 1079 | return zig_wrap_u8(full_res >> (8 - bits), bits); | 1182 | return zig_wrap_u8(full_res >> (8 - bits), bits); |
| 1080 | } | 1183 | } |
| 1081 | | 1184 | |
| 1082 | static inline zig_i8 zig_bit_reverse_i8(zig_i8 val, zig_u8 bits) { | 1185 | static inline int8_t zig_bit_reverse_i8(int8_t val, uint8_t bits) { |
| 1083 | return zig_wrap_i8((zig_i8)zig_bit_reverse_u8((zig_u8)val, bits), bits); | 1186 | return zig_wrap_i8((int8_t)zig_bit_reverse_u8((uint8_t)val, bits), bits); |
| 1084 | } | 1187 | } |
| 1085 | | 1188 | |
| 1086 | static inline zig_u16 zig_bit_reverse_u16(zig_u16 val, zig_u8 bits) { | 1189 | static inline uint16_t zig_bit_reverse_u16(uint16_t val, uint8_t bits) { |
| 1087 | zig_u16 full_res; | 1190 | uint16_t full_res; |
| 1088 | #if zig_has_builtin(bitreverse16) | 1191 | #if zig_has_builtin(bitreverse16) |
| 1089 | full_res = __builtin_bitreverse16(val); | 1192 | full_res = __builtin_bitreverse16(val); |
| 1090 | #else | 1193 | #else |
| 1091 | full_res = (zig_u16)zig_bit_reverse_u8((zig_u8)(val >> 0), 8) << 8 | | 1194 | full_res = (uint16_t)zig_bit_reverse_u8((uint8_t)(val >> 0), 8) << 8 | |
| 1092 | (zig_u16)zig_bit_reverse_u8((zig_u8)(val >> 8), 8) >> 0; | 1195 | (uint16_t)zig_bit_reverse_u8((uint8_t)(val >> 8), 8) >> 0; |
| 1093 | #endif | 1196 | #endif |
| 1094 | return zig_wrap_u16(full_res >> (16 - bits), bits); | 1197 | return zig_wrap_u16(full_res >> (16 - bits), bits); |
| 1095 | } | 1198 | } |
| 1096 | | 1199 | |
| 1097 | static inline zig_i16 zig_bit_reverse_i16(zig_i16 val, zig_u8 bits) { | 1200 | static inline int16_t zig_bit_reverse_i16(int16_t val, uint8_t bits) { |
| 1098 | return zig_wrap_i16((zig_i16)zig_bit_reverse_u16((zig_u16)val, bits), bits); | 1201 | return zig_wrap_i16((int16_t)zig_bit_reverse_u16((uint16_t)val, bits), bits); |
| 1099 | } | 1202 | } |
| 1100 | | 1203 | |
| 1101 | static inline zig_u32 zig_bit_reverse_u32(zig_u32 val, zig_u8 bits) { | 1204 | static inline uint32_t zig_bit_reverse_u32(uint32_t val, uint8_t bits) { |
| 1102 | zig_u32 full_res; | 1205 | uint32_t full_res; |
| 1103 | #if zig_has_builtin(bitreverse32) | 1206 | #if zig_has_builtin(bitreverse32) |
| 1104 | full_res = __builtin_bitreverse32(val); | 1207 | full_res = __builtin_bitreverse32(val); |
| 1105 | #else | 1208 | #else |
| 1106 | full_res = (zig_u32)zig_bit_reverse_u16((zig_u16)(val >> 0), 16) << 16 | | 1209 | full_res = (uint32_t)zig_bit_reverse_u16((uint16_t)(val >> 0), 16) << 16 | |
| 1107 | (zig_u32)zig_bit_reverse_u16((zig_u16)(val >> 16), 16) >> 0; | 1210 | (uint32_t)zig_bit_reverse_u16((uint16_t)(val >> 16), 16) >> 0; |
| 1108 | #endif | 1211 | #endif |
| 1109 | return zig_wrap_u32(full_res >> (32 - bits), bits); | 1212 | return zig_wrap_u32(full_res >> (32 - bits), bits); |
| 1110 | } | 1213 | } |
| 1111 | | 1214 | |
| 1112 | static inline zig_i32 zig_bit_reverse_i32(zig_i32 val, zig_u8 bits) { | 1215 | static inline int32_t zig_bit_reverse_i32(int32_t val, uint8_t bits) { |
| 1113 | return zig_wrap_i32((zig_i32)zig_bit_reverse_u32((zig_u32)val, bits), bits); | 1216 | return zig_wrap_i32((int32_t)zig_bit_reverse_u32((uint32_t)val, bits), bits); |
| 1114 | } | 1217 | } |
| 1115 | | 1218 | |
| 1116 | static inline zig_u64 zig_bit_reverse_u64(zig_u64 val, zig_u8 bits) { | 1219 | static inline uint64_t zig_bit_reverse_u64(uint64_t val, uint8_t bits) { |
| 1117 | zig_u64 full_res; | 1220 | uint64_t full_res; |
| 1118 | #if zig_has_builtin(bitreverse64) | 1221 | #if zig_has_builtin(bitreverse64) |
| 1119 | full_res = __builtin_bitreverse64(val); | 1222 | full_res = __builtin_bitreverse64(val); |
| 1120 | #else | 1223 | #else |
| 1121 | full_res = (zig_u64)zig_bit_reverse_u32((zig_u32)(val >> 0), 32) << 32 | | 1224 | full_res = (uint64_t)zig_bit_reverse_u32((uint32_t)(val >> 0), 32) << 32 | |
| 1122 | (zig_u64)zig_bit_reverse_u32((zig_u32)(val >> 32), 32) >> 0; | 1225 | (uint64_t)zig_bit_reverse_u32((uint32_t)(val >> 32), 32) >> 0; |
| 1123 | #endif | 1226 | #endif |
| 1124 | return zig_wrap_u64(full_res >> (64 - bits), bits); | 1227 | return zig_wrap_u64(full_res >> (64 - bits), bits); |
| 1125 | } | 1228 | } |
| 1126 | | 1229 | |
| 1127 | static inline zig_i64 zig_bit_reverse_i64(zig_i64 val, zig_u8 bits) { | 1230 | static inline int64_t zig_bit_reverse_i64(int64_t val, uint8_t bits) { |
| 1128 | return zig_wrap_i64((zig_i64)zig_bit_reverse_u64((zig_u64)val, bits), bits); | 1231 | return zig_wrap_i64((int64_t)zig_bit_reverse_u64((uint64_t)val, bits), bits); |
| 1129 | } | 1232 | } |
| 1130 | | 1233 | |
| 1131 | #define zig_builtin_popcount_common(w) \ | 1234 | #define zig_builtin_popcount_common(w) \ |
| 1132 | static inline zig_u8 zig_popcount_i##w(zig_i##w val, zig_u8 bits) { \ | 1235 | static inline uint8_t zig_popcount_i##w(int##w##_t val, uint8_t bits) { \ |
| 1133 | return zig_popcount_u##w((zig_u##w)val, bits); \ | 1236 | return zig_popcount_u##w((uint##w##_t)val, bits); \ |
| 1134 | } | 1237 | } |
| 1135 | #if zig_has_builtin(popcount) || defined(zig_gnuc) | 1238 | #if zig_has_builtin(popcount) || defined(zig_gnuc) |
| 1136 | #define zig_builtin_popcount(w) \ | 1239 | #define zig_builtin_popcount(w) \ |
| 1137 | static inline zig_u8 zig_popcount_u##w(zig_u##w val, zig_u8 bits) { \ | 1240 | static inline uint8_t zig_popcount_u##w(uint##w##_t val, uint8_t bits) { \ |
| 1138 | (void)bits; \ | 1241 | (void)bits; \ |
| 1139 | return zig_builtin##w(popcount, val); \ | 1242 | return zig_builtin##w(popcount, val); \ |
| 1140 | } \ | 1243 | } \ |
| ... | @@ -1142,12 +1245,12 @@ static inline zig_i64 zig_bit_reverse_i64(zig_i64 val, zig_u8 bits) { | ... | @@ -1142,12 +1245,12 @@ static inline zig_i64 zig_bit_reverse_i64(zig_i64 val, zig_u8 bits) { |
| 1142 | zig_builtin_popcount_common(w) | 1245 | zig_builtin_popcount_common(w) |
| 1143 | #else | 1246 | #else |
| 1144 | #define zig_builtin_popcount(w) \ | 1247 | #define zig_builtin_popcount(w) \ |
| 1145 | static inline zig_u8 zig_popcount_u##w(zig_u##w val, zig_u8 bits) { \ | 1248 | static inline uint8_t zig_popcount_u##w(uint##w##_t val, uint8_t bits) { \ |
| 1146 | (void)bits; \ | 1249 | (void)bits; \ |
| 1147 | zig_u##w temp = val - ((val >> 1) & (zig_maxInt_u##w / 3)); \ | 1250 | uint##w##_t temp = val - ((val >> 1) & (UINT##w##_MAX / 3)); \ |
| 1148 | temp = (temp & (zig_maxInt_u##w / 5)) + ((temp >> 2) & (zig_maxInt_u##w / 5)); \ | 1251 | temp = (temp & (UINT##w##_MAX / 5)) + ((temp >> 2) & (UINT##w##_MAX / 5)); \ |
| 1149 | temp = (temp + (temp >> 4)) & (zig_maxInt_u##w / 17); \ | 1252 | temp = (temp + (temp >> 4)) & (UINT##w##_MAX / 17); \ |
| 1150 | return temp * (zig_maxInt_u##w / 255) >> (w - 8); \ | 1253 | return temp * (UINT##w##_MAX / 255) >> (w - 8); \ |
| 1151 | } \ | 1254 | } \ |
| 1152 | \ | 1255 | \ |
| 1153 | zig_builtin_popcount_common(w) | 1256 | zig_builtin_popcount_common(w) |
| ... | @@ -1158,12 +1261,12 @@ zig_builtin_popcount(32) | ... | @@ -1158,12 +1261,12 @@ zig_builtin_popcount(32) |
| 1158 | zig_builtin_popcount(64) | 1261 | zig_builtin_popcount(64) |
| 1159 | | 1262 | |
| 1160 | #define zig_builtin_ctz_common(w) \ | 1263 | #define zig_builtin_ctz_common(w) \ |
| 1161 | static inline zig_u8 zig_ctz_i##w(zig_i##w val, zig_u8 bits) { \ | 1264 | static inline uint8_t zig_ctz_i##w(int##w##_t val, uint8_t bits) { \ |
| 1162 | return zig_ctz_u##w((zig_u##w)val, bits); \ | 1265 | return zig_ctz_u##w((uint##w##_t)val, bits); \ |
| 1163 | } | 1266 | } |
| 1164 | #if zig_has_builtin(ctz) || defined(zig_gnuc) | 1267 | #if zig_has_builtin(ctz) || defined(zig_gnuc) |
| 1165 | #define zig_builtin_ctz(w) \ | 1268 | #define zig_builtin_ctz(w) \ |
| 1166 | static inline zig_u8 zig_ctz_u##w(zig_u##w val, zig_u8 bits) { \ | 1269 | static inline uint8_t zig_ctz_u##w(uint##w##_t val, uint8_t bits) { \ |
| 1167 | if (val == 0) return bits; \ | 1270 | if (val == 0) return bits; \ |
| 1168 | return zig_builtin##w(ctz, val); \ | 1271 | return zig_builtin##w(ctz, val); \ |
| 1169 | } \ | 1272 | } \ |
| ... | @@ -1171,7 +1274,7 @@ zig_builtin_popcount(64) | ... | @@ -1171,7 +1274,7 @@ zig_builtin_popcount(64) |
| 1171 | zig_builtin_ctz_common(w) | 1274 | zig_builtin_ctz_common(w) |
| 1172 | #else | 1275 | #else |
| 1173 | #define zig_builtin_ctz(w) \ | 1276 | #define zig_builtin_ctz(w) \ |
| 1174 | static inline zig_u8 zig_ctz_u##w(zig_u##w val, zig_u8 bits) { \ | 1277 | static inline uint8_t zig_ctz_u##w(uint##w##_t val, uint8_t bits) { \ |
| 1175 | return zig_popcount_u##w(zig_not_u##w(val, bits) & zig_subw_u##w(val, 1, bits), bits); \ | 1278 | return zig_popcount_u##w(zig_not_u##w(val, bits) & zig_subw_u##w(val, 1, bits), bits); \ |
| 1176 | } \ | 1279 | } \ |
| 1177 | \ | 1280 | \ |
| ... | @@ -1183,12 +1286,12 @@ zig_builtin_ctz(32) | ... | @@ -1183,12 +1286,12 @@ zig_builtin_ctz(32) |
| 1183 | zig_builtin_ctz(64) | 1286 | zig_builtin_ctz(64) |
| 1184 | | 1287 | |
| 1185 | #define zig_builtin_clz_common(w) \ | 1288 | #define zig_builtin_clz_common(w) \ |
| 1186 | static inline zig_u8 zig_clz_i##w(zig_i##w val, zig_u8 bits) { \ | 1289 | static inline uint8_t zig_clz_i##w(int##w##_t val, uint8_t bits) { \ |
| 1187 | return zig_clz_u##w((zig_u##w)val, bits); \ | 1290 | return zig_clz_u##w((uint##w##_t)val, bits); \ |
| 1188 | } | 1291 | } |
| 1189 | #if zig_has_builtin(clz) || defined(zig_gnuc) | 1292 | #if zig_has_builtin(clz) || defined(zig_gnuc) |
| 1190 | #define zig_builtin_clz(w) \ | 1293 | #define zig_builtin_clz(w) \ |
| 1191 | static inline zig_u8 zig_clz_u##w(zig_u##w val, zig_u8 bits) { \ | 1294 | static inline uint8_t zig_clz_u##w(uint##w##_t val, uint8_t bits) { \ |
| 1192 | if (val == 0) return bits; \ | 1295 | if (val == 0) return bits; \ |
| 1193 | return zig_builtin##w(clz, val) - (zig_bitSizeOf(zig_Builtin##w) - bits); \ | 1296 | return zig_builtin##w(clz, val) - (zig_bitSizeOf(zig_Builtin##w) - bits); \ |
| 1194 | } \ | 1297 | } \ |
| ... | @@ -1196,7 +1299,7 @@ zig_builtin_ctz(64) | ... | @@ -1196,7 +1299,7 @@ zig_builtin_ctz(64) |
| 1196 | zig_builtin_clz_common(w) | 1299 | zig_builtin_clz_common(w) |
| 1197 | #else | 1300 | #else |
| 1198 | #define zig_builtin_clz(w) \ | 1301 | #define zig_builtin_clz(w) \ |
| 1199 | static inline zig_u8 zig_clz_u##w(zig_u##w val, zig_u8 bits) { \ | 1302 | static inline uint8_t zig_clz_u##w(uint##w##_t val, uint8_t bits) { \ |
| 1200 | return zig_ctz_u##w(zig_bit_reverse_u##w(val, bits), bits); \ | 1303 | return zig_ctz_u##w(zig_bit_reverse_u##w(val, bits), bits); \ |
| 1201 | } \ | 1304 | } \ |
| 1202 | \ | 1305 | \ |
| ... | @@ -1207,7 +1310,7 @@ zig_builtin_clz(16) | ... | @@ -1207,7 +1310,7 @@ zig_builtin_clz(16) |
| 1207 | zig_builtin_clz(32) | 1310 | zig_builtin_clz(32) |
| 1208 | zig_builtin_clz(64) | 1311 | zig_builtin_clz(64) |
| 1209 | | 1312 | |
| 1210 | /* ======================== 128-bit Integer Routines ======================== */ | 1313 | /* ======================== 128-bit Integer Support ========================= */ |
| 1211 | | 1314 | |
| 1212 | #if !defined(zig_has_int128) | 1315 | #if !defined(zig_has_int128) |
| 1213 | # if defined(__SIZEOF_INT128__) | 1316 | # if defined(__SIZEOF_INT128__) |
| ... | @@ -1222,18 +1325,18 @@ zig_builtin_clz(64) | ... | @@ -1222,18 +1325,18 @@ zig_builtin_clz(64) |
| 1222 | typedef unsigned __int128 zig_u128; | 1325 | typedef unsigned __int128 zig_u128; |
| 1223 | typedef signed __int128 zig_i128; | 1326 | typedef signed __int128 zig_i128; |
| 1224 | | 1327 | |
| 1225 | #define zig_as_u128(hi, lo) ((zig_u128)(hi)<<64|(lo)) | 1328 | #define zig_make_u128(hi, lo) ((zig_u128)(hi)<<64|(lo)) |
| 1226 | #define zig_as_i128(hi, lo) ((zig_i128)zig_as_u128(hi, lo)) | 1329 | #define zig_make_i128(hi, lo) ((zig_i128)zig_make_u128(hi, lo)) |
| 1227 | #define zig_as_constant_u128(hi, lo) zig_as_u128(hi, lo) | 1330 | #define zig_make_constant_u128(hi, lo) zig_make_u128(hi, lo) |
| 1228 | #define zig_as_constant_i128(hi, lo) zig_as_i128(hi, lo) | 1331 | #define zig_make_constant_i128(hi, lo) zig_make_i128(hi, lo) |
| 1229 | #define zig_hi_u128(val) ((zig_u64)((val) >> 64)) | 1332 | #define zig_hi_u128(val) ((uint64_t)((val) >> 64)) |
| 1230 | #define zig_lo_u128(val) ((zig_u64)((val) >> 0)) | 1333 | #define zig_lo_u128(val) ((uint64_t)((val) >> 0)) |
| 1231 | #define zig_hi_i128(val) ((zig_i64)((val) >> 64)) | 1334 | #define zig_hi_i128(val) (( int64_t)((val) >> 64)) |
| 1232 | #define zig_lo_i128(val) ((zig_u64)((val) >> 0)) | 1335 | #define zig_lo_i128(val) ((uint64_t)((val) >> 0)) |
| 1233 | #define zig_bitcast_u128(val) ((zig_u128)(val)) | 1336 | #define zig_bitcast_u128(val) ((zig_u128)(val)) |
| 1234 | #define zig_bitcast_i128(val) ((zig_i128)(val)) | 1337 | #define zig_bitcast_i128(val) ((zig_i128)(val)) |
| 1235 | #define zig_cmp_int128(Type) \ | 1338 | #define zig_cmp_int128(Type) \ |
| 1236 | static inline zig_i32 zig_cmp_##Type(zig_##Type lhs, zig_##Type rhs) { \ | 1339 | static inline int32_t zig_cmp_##Type(zig_##Type lhs, zig_##Type rhs) { \ |
| 1237 | return (lhs > rhs) - (lhs < rhs); \ | 1340 | return (lhs > rhs) - (lhs < rhs); \ |
| 1238 | } | 1341 | } |
| 1239 | #define zig_bit_int128(Type, operation, operator) \ | 1342 | #define zig_bit_int128(Type, operation, operator) \ |
| ... | @@ -1244,31 +1347,31 @@ typedef signed __int128 zig_i128; | ... | @@ -1244,31 +1347,31 @@ typedef signed __int128 zig_i128; |
| 1244 | #else /* zig_has_int128 */ | 1347 | #else /* zig_has_int128 */ |
| 1245 | | 1348 | |
| 1246 | #if __LITTLE_ENDIAN__ || _MSC_VER | 1349 | #if __LITTLE_ENDIAN__ || _MSC_VER |
| 1247 | typedef struct { zig_align(16) zig_u64 lo; zig_u64 hi; } zig_u128; | 1350 | typedef struct { zig_align(16) uint64_t lo; uint64_t hi; } zig_u128; |
| 1248 | typedef struct { zig_align(16) zig_u64 lo; zig_i64 hi; } zig_i128; | 1351 | typedef struct { zig_align(16) uint64_t lo; int64_t hi; } zig_i128; |
| 1249 | #else | 1352 | #else |
| 1250 | typedef struct { zig_align(16) zig_u64 hi; zig_u64 lo; } zig_u128; | 1353 | typedef struct { zig_align(16) uint64_t hi; uint64_t lo; } zig_u128; |
| 1251 | typedef struct { zig_align(16) zig_i64 hi; zig_u64 lo; } zig_i128; | 1354 | typedef struct { zig_align(16) int64_t hi; uint64_t lo; } zig_i128; |
| 1252 | #endif | 1355 | #endif |
| 1253 | | 1356 | |
| 1254 | #define zig_as_u128(hi, lo) ((zig_u128){ .h##i = (hi), .l##o = (lo) }) | 1357 | #define zig_make_u128(hi, lo) ((zig_u128){ .h##i = (hi), .l##o = (lo) }) |
| 1255 | #define zig_as_i128(hi, lo) ((zig_i128){ .h##i = (hi), .l##o = (lo) }) | 1358 | #define zig_make_i128(hi, lo) ((zig_i128){ .h##i = (hi), .l##o = (lo) }) |
| 1256 | | 1359 | |
| 1257 | #if _MSC_VER | 1360 | #if _MSC_VER |
| 1258 | #define zig_as_constant_u128(hi, lo) { .h##i = (hi), .l##o = (lo) } | 1361 | #define zig_make_constant_u128(hi, lo) { .h##i = (hi), .l##o = (lo) } |
| 1259 | #define zig_as_constant_i128(hi, lo) { .h##i = (hi), .l##o = (lo) } | 1362 | #define zig_make_constant_i128(hi, lo) { .h##i = (hi), .l##o = (lo) } |
| 1260 | #else | 1363 | #else |
| 1261 | #define zig_as_constant_u128(hi, lo) zig_as_u128(hi, lo) | 1364 | #define zig_make_constant_u128(hi, lo) zig_make_u128(hi, lo) |
| 1262 | #define zig_as_constant_i128(hi, lo) zig_as_i128(hi, lo) | 1365 | #define zig_make_constant_i128(hi, lo) zig_make_i128(hi, lo) |
| 1263 | #endif | 1366 | #endif |
| 1264 | #define zig_hi_u128(val) ((val).hi) | 1367 | #define zig_hi_u128(val) ((val).hi) |
| 1265 | #define zig_lo_u128(val) ((val).lo) | 1368 | #define zig_lo_u128(val) ((val).lo) |
| 1266 | #define zig_hi_i128(val) ((val).hi) | 1369 | #define zig_hi_i128(val) ((val).hi) |
| 1267 | #define zig_lo_i128(val) ((val).lo) | 1370 | #define zig_lo_i128(val) ((val).lo) |
| 1268 | #define zig_bitcast_u128(val) zig_as_u128((zig_u64)(val).hi, (val).lo) | 1371 | #define zig_bitcast_u128(val) zig_make_u128((uint64_t)(val).hi, (val).lo) |
| 1269 | #define zig_bitcast_i128(val) zig_as_i128((zig_i64)(val).hi, (val).lo) | 1372 | #define zig_bitcast_i128(val) zig_make_i128(( int64_t)(val).hi, (val).lo) |
| 1270 | #define zig_cmp_int128(Type) \ | 1373 | #define zig_cmp_int128(Type) \ |
| 1271 | static inline zig_i32 zig_cmp_##Type(zig_##Type lhs, zig_##Type rhs) { \ | 1374 | static inline int32_t zig_cmp_##Type(zig_##Type lhs, zig_##Type rhs) { \ |
| 1272 | return (lhs.hi == rhs.hi) \ | 1375 | return (lhs.hi == rhs.hi) \ |
| 1273 | ? (lhs.lo > rhs.lo) - (lhs.lo < rhs.lo) \ | 1376 | ? (lhs.lo > rhs.lo) - (lhs.lo < rhs.lo) \ |
| 1274 | : (lhs.hi > rhs.hi) - (lhs.hi < rhs.hi); \ | 1377 | : (lhs.hi > rhs.hi) - (lhs.hi < rhs.hi); \ |
| ... | @@ -1280,10 +1383,10 @@ typedef struct { zig_align(16) zig_i64 hi; zig_u64 lo; } zig_i128; | ... | @@ -1280,10 +1383,10 @@ typedef struct { zig_align(16) zig_i64 hi; zig_u64 lo; } zig_i128; |
| 1280 | | 1383 | |
| 1281 | #endif /* zig_has_int128 */ | 1384 | #endif /* zig_has_int128 */ |
| 1282 | | 1385 | |
| 1283 | #define zig_minInt_u128 zig_as_u128(zig_minInt_u64, zig_minInt_u64) | 1386 | #define zig_minInt_u128 zig_make_u128(zig_minInt_u64, zig_minInt_u64) |
| 1284 | #define zig_maxInt_u128 zig_as_u128(zig_maxInt_u64, zig_maxInt_u64) | 1387 | #define zig_maxInt_u128 zig_make_u128(zig_maxInt_u64, zig_maxInt_u64) |
| 1285 | #define zig_minInt_i128 zig_as_i128(zig_minInt_i64, zig_minInt_u64) | 1388 | #define zig_minInt_i128 zig_make_i128(zig_minInt_i64, zig_minInt_u64) |
| 1286 | #define zig_maxInt_i128 zig_as_i128(zig_maxInt_i64, zig_maxInt_u64) | 1389 | #define zig_maxInt_i128 zig_make_i128(zig_maxInt_i64, zig_maxInt_u64) |
| 1287 | | 1390 | |
| 1288 | zig_cmp_int128(u128) | 1391 | zig_cmp_int128(u128) |
| 1289 | zig_cmp_int128(i128) | 1392 | zig_cmp_int128(i128) |
| ... | @@ -1297,28 +1400,28 @@ zig_bit_int128(i128, or, |) | ... | @@ -1297,28 +1400,28 @@ zig_bit_int128(i128, or, |) |
| 1297 | zig_bit_int128(u128, xor, ^) | 1400 | zig_bit_int128(u128, xor, ^) |
| 1298 | zig_bit_int128(i128, xor, ^) | 1401 | zig_bit_int128(i128, xor, ^) |
| 1299 | | 1402 | |
| 1300 | static inline zig_u128 zig_shr_u128(zig_u128 lhs, zig_u8 rhs); | 1403 | static inline zig_u128 zig_shr_u128(zig_u128 lhs, uint8_t rhs); |
| 1301 | | 1404 | |
| 1302 | #if zig_has_int128 | 1405 | #if zig_has_int128 |
| 1303 | | 1406 | |
| 1304 | static inline zig_u128 zig_not_u128(zig_u128 val, zig_u8 bits) { | 1407 | static inline zig_u128 zig_not_u128(zig_u128 val, uint8_t bits) { |
| 1305 | return val ^ zig_maxInt(u128, bits); | 1408 | return val ^ zig_maxInt_u(128, bits); |
| 1306 | } | 1409 | } |
| 1307 | | 1410 | |
| 1308 | static inline zig_i128 zig_not_i128(zig_i128 val, zig_u8 bits) { | 1411 | static inline zig_i128 zig_not_i128(zig_i128 val, uint8_t bits) { |
| 1309 | (void)bits; | 1412 | (void)bits; |
| 1310 | return ~val; | 1413 | return ~val; |
| 1311 | } | 1414 | } |
| 1312 | | 1415 | |
| 1313 | static inline zig_u128 zig_shr_u128(zig_u128 lhs, zig_u8 rhs) { | 1416 | static inline zig_u128 zig_shr_u128(zig_u128 lhs, uint8_t rhs) { |
| 1314 | return lhs >> rhs; | 1417 | return lhs >> rhs; |
| 1315 | } | 1418 | } |
| 1316 | | 1419 | |
| 1317 | static inline zig_u128 zig_shl_u128(zig_u128 lhs, zig_u8 rhs) { | 1420 | static inline zig_u128 zig_shl_u128(zig_u128 lhs, uint8_t rhs) { |
| 1318 | return lhs << rhs; | 1421 | return lhs << rhs; |
| 1319 | } | 1422 | } |
| 1320 | | 1423 | |
| 1321 | static inline zig_i128 zig_shl_i128(zig_i128 lhs, zig_u8 rhs) { | 1424 | static inline zig_i128 zig_shl_i128(zig_i128 lhs, uint8_t rhs) { |
| 1322 | return lhs << rhs; | 1425 | return lhs << rhs; |
| 1323 | } | 1426 | } |
| 1324 | | 1427 | |
| ... | @@ -1363,40 +1466,40 @@ static inline zig_i128 zig_rem_i128(zig_i128 lhs, zig_i128 rhs) { | ... | @@ -1363,40 +1466,40 @@ static inline zig_i128 zig_rem_i128(zig_i128 lhs, zig_i128 rhs) { |
| 1363 | } | 1466 | } |
| 1364 | | 1467 | |
| 1365 | static inline zig_i128 zig_div_floor_i128(zig_i128 lhs, zig_i128 rhs) { | 1468 | static inline zig_i128 zig_div_floor_i128(zig_i128 lhs, zig_i128 rhs) { |
| 1366 | return zig_div_trunc_i128(lhs, rhs) - (((lhs ^ rhs) & zig_rem_i128(lhs, rhs)) < zig_as_i128(0, 0)); | 1469 | return zig_div_trunc_i128(lhs, rhs) - (((lhs ^ rhs) & zig_rem_i128(lhs, rhs)) < zig_make_i128(0, 0)); |
| 1367 | } | 1470 | } |
| 1368 | | 1471 | |
| 1369 | static inline zig_i128 zig_mod_i128(zig_i128 lhs, zig_i128 rhs) { | 1472 | static inline zig_i128 zig_mod_i128(zig_i128 lhs, zig_i128 rhs) { |
| 1370 | zig_i128 rem = zig_rem_i128(lhs, rhs); | 1473 | zig_i128 rem = zig_rem_i128(lhs, rhs); |
| 1371 | return rem + (((lhs ^ rhs) & rem) < zig_as_i128(0, 0) ? rhs : zig_as_i128(0, 0)); | 1474 | return rem + (((lhs ^ rhs) & rem) < zig_make_i128(0, 0) ? rhs : zig_make_i128(0, 0)); |
| 1372 | } | 1475 | } |
| 1373 | | 1476 | |
| 1374 | #else /* zig_has_int128 */ | 1477 | #else /* zig_has_int128 */ |
| 1375 | | 1478 | |
| 1376 | static inline zig_u128 zig_not_u128(zig_u128 val, zig_u8 bits) { | 1479 | static inline zig_u128 zig_not_u128(zig_u128 val, uint8_t bits) { |
| 1377 | return (zig_u128){ .hi = zig_not_u64(val.hi, bits - zig_as_u8(64)), .lo = zig_not_u64(val.lo, zig_as_u8(64)) }; | 1480 | return (zig_u128){ .hi = zig_not_u64(val.hi, bits - UINT8_C(64)), .lo = zig_not_u64(val.lo, UINT8_C(64)) }; |
| 1378 | } | 1481 | } |
| 1379 | | 1482 | |
| 1380 | static inline zig_i128 zig_not_i128(zig_i128 val, zig_u8 bits) { | 1483 | static inline zig_i128 zig_not_i128(zig_i128 val, uint8_t bits) { |
| 1381 | return (zig_i128){ .hi = zig_not_i64(val.hi, bits - zig_as_u8(64)), .lo = zig_not_u64(val.lo, zig_as_u8(64)) }; | 1484 | return (zig_i128){ .hi = zig_not_i64(val.hi, bits - UINT8_C(64)), .lo = zig_not_u64(val.lo, UINT8_C(64)) }; |
| 1382 | } | 1485 | } |
| 1383 | | 1486 | |
| 1384 | static inline zig_u128 zig_shr_u128(zig_u128 lhs, zig_u8 rhs) { | 1487 | static inline zig_u128 zig_shr_u128(zig_u128 lhs, uint8_t rhs) { |
| 1385 | if (rhs == zig_as_u8(0)) return lhs; | 1488 | if (rhs == UINT8_C(0)) return lhs; |
| 1386 | if (rhs >= zig_as_u8(64)) return (zig_u128){ .hi = zig_minInt_u64, .lo = lhs.hi >> (rhs - zig_as_u8(64)) }; | 1489 | if (rhs >= UINT8_C(64)) return (zig_u128){ .hi = zig_minInt_u64, .lo = lhs.hi >> (rhs - UINT8_C(64)) }; |
| 1387 | return (zig_u128){ .hi = lhs.hi >> rhs, .lo = lhs.hi << (zig_as_u8(64) - rhs) | lhs.lo >> rhs }; | 1490 | return (zig_u128){ .hi = lhs.hi >> rhs, .lo = lhs.hi << (UINT8_C(64) - rhs) | lhs.lo >> rhs }; |
| 1388 | } | 1491 | } |
| 1389 | | 1492 | |
| 1390 | static inline zig_u128 zig_shl_u128(zig_u128 lhs, zig_u8 rhs) { | 1493 | static inline zig_u128 zig_shl_u128(zig_u128 lhs, uint8_t rhs) { |
| 1391 | if (rhs == zig_as_u8(0)) return lhs; | 1494 | if (rhs == UINT8_C(0)) return lhs; |
| 1392 | if (rhs >= zig_as_u8(64)) return (zig_u128){ .hi = lhs.lo << (rhs - zig_as_u8(64)), .lo = zig_minInt_u64 }; | 1495 | if (rhs >= UINT8_C(64)) return (zig_u128){ .hi = lhs.lo << (rhs - UINT8_C(64)), .lo = zig_minInt_u64 }; |
| 1393 | return (zig_u128){ .hi = lhs.hi << rhs | lhs.lo >> (zig_as_u8(64) - rhs), .lo = lhs.lo << rhs }; | 1496 | return (zig_u128){ .hi = lhs.hi << rhs | lhs.lo >> (UINT8_C(64) - rhs), .lo = lhs.lo << rhs }; |
| 1394 | } | 1497 | } |
| 1395 | | 1498 | |
| 1396 | static inline zig_i128 zig_shl_i128(zig_i128 lhs, zig_u8 rhs) { | 1499 | static inline zig_i128 zig_shl_i128(zig_i128 lhs, uint8_t rhs) { |
| 1397 | if (rhs == zig_as_u8(0)) return lhs; | 1500 | if (rhs == UINT8_C(0)) return lhs; |
| 1398 | if (rhs >= zig_as_u8(64)) return (zig_i128){ .hi = lhs.lo << (rhs - zig_as_u8(64)), .lo = zig_minInt_u64 }; | 1501 | if (rhs >= UINT8_C(64)) return (zig_i128){ .hi = lhs.lo << (rhs - UINT8_C(64)), .lo = zig_minInt_u64 }; |
| 1399 | return (zig_i128){ .hi = lhs.hi << rhs | lhs.lo >> (zig_as_u8(64) - rhs), .lo = lhs.lo << rhs }; | 1502 | return (zig_i128){ .hi = lhs.hi << rhs | lhs.lo >> (UINT8_C(64) - rhs), .lo = lhs.lo << rhs }; |
| 1400 | } | 1503 | } |
| 1401 | | 1504 | |
| 1402 | static inline zig_u128 zig_add_u128(zig_u128 lhs, zig_u128 rhs) { | 1505 | static inline zig_u128 zig_add_u128(zig_u128 lhs, zig_u128 rhs) { |
| ... | @@ -1454,11 +1557,11 @@ static zig_i128 zig_rem_i128(zig_i128 lhs, zig_i128 rhs) { | ... | @@ -1454,11 +1557,11 @@ static zig_i128 zig_rem_i128(zig_i128 lhs, zig_i128 rhs) { |
| 1454 | | 1557 | |
| 1455 | static inline zig_i128 zig_mod_i128(zig_i128 lhs, zig_i128 rhs) { | 1558 | static inline zig_i128 zig_mod_i128(zig_i128 lhs, zig_i128 rhs) { |
| 1456 | zig_i128 rem = zig_rem_i128(lhs, rhs); | 1559 | zig_i128 rem = zig_rem_i128(lhs, rhs); |
| 1457 | return zig_add_i128(rem, (((lhs.hi ^ rhs.hi) & rem.hi) < zig_as_i64(0) ? rhs : zig_as_i128(0, 0))); | 1560 | return zig_add_i128(rem, (((lhs.hi ^ rhs.hi) & rem.hi) < INT64_C(0) ? rhs : zig_make_i128(0, 0))); |
| 1458 | } | 1561 | } |
| 1459 | | 1562 | |
| 1460 | static inline zig_i128 zig_div_floor_i128(zig_i128 lhs, zig_i128 rhs) { | 1563 | static inline zig_i128 zig_div_floor_i128(zig_i128 lhs, zig_i128 rhs) { |
| 1461 | return zig_sub_i128(zig_div_trunc_i128(lhs, rhs), zig_as_i128(0, zig_cmp_i128(zig_and_i128(zig_xor_i128(lhs, rhs), zig_rem_i128(lhs, rhs)), zig_as_i128(0, 0)) < zig_as_i32(0))); | 1564 | return zig_sub_i128(zig_div_trunc_i128(lhs, rhs), zig_make_i128(0, zig_cmp_i128(zig_and_i128(zig_xor_i128(lhs, rhs), zig_rem_i128(lhs, rhs)), zig_make_i128(0, 0)) < INT32_C(0))); |
| 1462 | } | 1565 | } |
| 1463 | | 1566 | |
| 1464 | #endif /* zig_has_int128 */ | 1567 | #endif /* zig_has_int128 */ |
| ... | @@ -1471,161 +1574,161 @@ static inline zig_u128 zig_nand_u128(zig_u128 lhs, zig_u128 rhs) { | ... | @@ -1471,161 +1574,161 @@ static inline zig_u128 zig_nand_u128(zig_u128 lhs, zig_u128 rhs) { |
| 1471 | } | 1574 | } |
| 1472 | | 1575 | |
| 1473 | static inline zig_u128 zig_min_u128(zig_u128 lhs, zig_u128 rhs) { | 1576 | static inline zig_u128 zig_min_u128(zig_u128 lhs, zig_u128 rhs) { |
| 1474 | return zig_cmp_u128(lhs, rhs) < zig_as_i32(0) ? lhs : rhs; | 1577 | return zig_cmp_u128(lhs, rhs) < INT32_C(0) ? lhs : rhs; |
| 1475 | } | 1578 | } |
| 1476 | | 1579 | |
| 1477 | static inline zig_i128 zig_min_i128(zig_i128 lhs, zig_i128 rhs) { | 1580 | static inline zig_i128 zig_min_i128(zig_i128 lhs, zig_i128 rhs) { |
| 1478 | return zig_cmp_i128(lhs, rhs) < zig_as_i32(0) ? lhs : rhs; | 1581 | return zig_cmp_i128(lhs, rhs) < INT32_C(0) ? lhs : rhs; |
| 1479 | } | 1582 | } |
| 1480 | | 1583 | |
| 1481 | static inline zig_u128 zig_max_u128(zig_u128 lhs, zig_u128 rhs) { | 1584 | static inline zig_u128 zig_max_u128(zig_u128 lhs, zig_u128 rhs) { |
| 1482 | return zig_cmp_u128(lhs, rhs) > zig_as_i32(0) ? lhs : rhs; | 1585 | return zig_cmp_u128(lhs, rhs) > INT32_C(0) ? lhs : rhs; |
| 1483 | } | 1586 | } |
| 1484 | | 1587 | |
| 1485 | static inline zig_i128 zig_max_i128(zig_i128 lhs, zig_i128 rhs) { | 1588 | static inline zig_i128 zig_max_i128(zig_i128 lhs, zig_i128 rhs) { |
| 1486 | return zig_cmp_i128(lhs, rhs) > zig_as_i32(0) ? lhs : rhs; | 1589 | return zig_cmp_i128(lhs, rhs) > INT32_C(0) ? lhs : rhs; |
| 1487 | } | 1590 | } |
| 1488 | | 1591 | |
| 1489 | static inline zig_i128 zig_shr_i128(zig_i128 lhs, zig_u8 rhs) { | 1592 | static inline zig_i128 zig_shr_i128(zig_i128 lhs, uint8_t rhs) { |
| 1490 | zig_i128 sign_mask = zig_cmp_i128(lhs, zig_as_i128(0, 0)) < zig_as_i32(0) ? zig_sub_i128(zig_as_i128(0, 0), zig_as_i128(0, 1)) : zig_as_i128(0, 0); | 1593 | zig_i128 sign_mask = zig_cmp_i128(lhs, zig_make_i128(0, 0)) < INT32_C(0) ? zig_sub_i128(zig_make_i128(0, 0), zig_make_i128(0, 1)) : zig_make_i128(0, 0); |
| 1491 | return zig_xor_i128(zig_bitcast_i128(zig_shr_u128(zig_bitcast_u128(zig_xor_i128(lhs, sign_mask)), rhs)), sign_mask); | 1594 | return zig_xor_i128(zig_bitcast_i128(zig_shr_u128(zig_bitcast_u128(zig_xor_i128(lhs, sign_mask)), rhs)), sign_mask); |
| 1492 | } | 1595 | } |
| 1493 | | 1596 | |
| 1494 | static inline zig_u128 zig_wrap_u128(zig_u128 val, zig_u8 bits) { | 1597 | static inline zig_u128 zig_wrap_u128(zig_u128 val, uint8_t bits) { |
| 1495 | return zig_and_u128(val, zig_maxInt(u128, bits)); | 1598 | return zig_and_u128(val, zig_maxInt_u(128, bits)); |
| 1496 | } | 1599 | } |
| 1497 | | 1600 | |
| 1498 | static inline zig_i128 zig_wrap_i128(zig_i128 val, zig_u8 bits) { | 1601 | static inline zig_i128 zig_wrap_i128(zig_i128 val, uint8_t bits) { |
| 1499 | return zig_as_i128(zig_wrap_i64(zig_hi_i128(val), bits - zig_as_u8(64)), zig_lo_i128(val)); | 1602 | return zig_make_i128(zig_wrap_i64(zig_hi_i128(val), bits - UINT8_C(64)), zig_lo_i128(val)); |
| 1500 | } | 1603 | } |
| 1501 | | 1604 | |
| 1502 | static inline zig_u128 zig_shlw_u128(zig_u128 lhs, zig_u8 rhs, zig_u8 bits) { | 1605 | static inline zig_u128 zig_shlw_u128(zig_u128 lhs, uint8_t rhs, uint8_t bits) { |
| 1503 | return zig_wrap_u128(zig_shl_u128(lhs, rhs), bits); | 1606 | return zig_wrap_u128(zig_shl_u128(lhs, rhs), bits); |
| 1504 | } | 1607 | } |
| 1505 | | 1608 | |
| 1506 | static inline zig_i128 zig_shlw_i128(zig_i128 lhs, zig_u8 rhs, zig_u8 bits) { | 1609 | static inline zig_i128 zig_shlw_i128(zig_i128 lhs, uint8_t rhs, uint8_t bits) { |
| 1507 | return zig_wrap_i128(zig_bitcast_i128(zig_shl_u128(zig_bitcast_u128(lhs), rhs)), bits); | 1610 | return zig_wrap_i128(zig_bitcast_i128(zig_shl_u128(zig_bitcast_u128(lhs), rhs)), bits); |
| 1508 | } | 1611 | } |
| 1509 | | 1612 | |
| 1510 | static inline zig_u128 zig_addw_u128(zig_u128 lhs, zig_u128 rhs, zig_u8 bits) { | 1613 | static inline zig_u128 zig_addw_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) { |
| 1511 | return zig_wrap_u128(zig_add_u128(lhs, rhs), bits); | 1614 | return zig_wrap_u128(zig_add_u128(lhs, rhs), bits); |
| 1512 | } | 1615 | } |
| 1513 | | 1616 | |
| 1514 | static inline zig_i128 zig_addw_i128(zig_i128 lhs, zig_i128 rhs, zig_u8 bits) { | 1617 | static inline zig_i128 zig_addw_i128(zig_i128 lhs, zig_i128 rhs, uint8_t bits) { |
| 1515 | return zig_wrap_i128(zig_bitcast_i128(zig_add_u128(zig_bitcast_u128(lhs), zig_bitcast_u128(rhs))), bits); | 1618 | return zig_wrap_i128(zig_bitcast_i128(zig_add_u128(zig_bitcast_u128(lhs), zig_bitcast_u128(rhs))), bits); |
| 1516 | } | 1619 | } |
| 1517 | | 1620 | |
| 1518 | static inline zig_u128 zig_subw_u128(zig_u128 lhs, zig_u128 rhs, zig_u8 bits) { | 1621 | static inline zig_u128 zig_subw_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) { |
| 1519 | return zig_wrap_u128(zig_sub_u128(lhs, rhs), bits); | 1622 | return zig_wrap_u128(zig_sub_u128(lhs, rhs), bits); |
| 1520 | } | 1623 | } |
| 1521 | | 1624 | |
| 1522 | static inline zig_i128 zig_subw_i128(zig_i128 lhs, zig_i128 rhs, zig_u8 bits) { | 1625 | static inline zig_i128 zig_subw_i128(zig_i128 lhs, zig_i128 rhs, uint8_t bits) { |
| 1523 | return zig_wrap_i128(zig_bitcast_i128(zig_sub_u128(zig_bitcast_u128(lhs), zig_bitcast_u128(rhs))), bits); | 1626 | return zig_wrap_i128(zig_bitcast_i128(zig_sub_u128(zig_bitcast_u128(lhs), zig_bitcast_u128(rhs))), bits); |
| 1524 | } | 1627 | } |
| 1525 | | 1628 | |
| 1526 | static inline zig_u128 zig_mulw_u128(zig_u128 lhs, zig_u128 rhs, zig_u8 bits) { | 1629 | static inline zig_u128 zig_mulw_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) { |
| 1527 | return zig_wrap_u128(zig_mul_u128(lhs, rhs), bits); | 1630 | return zig_wrap_u128(zig_mul_u128(lhs, rhs), bits); |
| 1528 | } | 1631 | } |
| 1529 | | 1632 | |
| 1530 | static inline zig_i128 zig_mulw_i128(zig_i128 lhs, zig_i128 rhs, zig_u8 bits) { | 1633 | static inline zig_i128 zig_mulw_i128(zig_i128 lhs, zig_i128 rhs, uint8_t bits) { |
| 1531 | return zig_wrap_i128(zig_bitcast_i128(zig_mul_u128(zig_bitcast_u128(lhs), zig_bitcast_u128(rhs))), bits); | 1634 | return zig_wrap_i128(zig_bitcast_i128(zig_mul_u128(zig_bitcast_u128(lhs), zig_bitcast_u128(rhs))), bits); |
| 1532 | } | 1635 | } |
| 1533 | | 1636 | |
| 1534 | #if zig_has_int128 | 1637 | #if zig_has_int128 |
| 1535 | | 1638 | |
| 1536 | static inline bool zig_addo_u128(zig_u128 *res, zig_u128 lhs, zig_u128 rhs, zig_u8 bits) { | 1639 | static inline bool zig_addo_u128(zig_u128 *res, zig_u128 lhs, zig_u128 rhs, uint8_t bits) { |
| 1537 | #if zig_has_builtin(add_overflow) | 1640 | #if zig_has_builtin(add_overflow) |
| 1538 | zig_u128 full_res; | 1641 | zig_u128 full_res; |
| 1539 | bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); | 1642 | bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); |
| 1540 | *res = zig_wrap_u128(full_res, bits); | 1643 | *res = zig_wrap_u128(full_res, bits); |
| 1541 | return overflow || full_res < zig_minInt(u128, bits) || full_res > zig_maxInt(u128, bits); | 1644 | return overflow || full_res < zig_minInt_u(128, bits) || full_res > zig_maxInt_u(128, bits); |
| 1542 | #else | 1645 | #else |
| 1543 | *res = zig_addw_u128(lhs, rhs, bits); | 1646 | *res = zig_addw_u128(lhs, rhs, bits); |
| 1544 | return *res < lhs; | 1647 | return *res < lhs; |
| 1545 | #endif | 1648 | #endif |
| 1546 | } | 1649 | } |
| 1547 | | 1650 | |
| 1548 | zig_extern zig_i128 __addoti4(zig_i128 lhs, zig_i128 rhs, zig_c_int *overflow); | 1651 | zig_extern zig_i128 __addoti4(zig_i128 lhs, zig_i128 rhs, int *overflow); |
| 1549 | static inline bool zig_addo_i128(zig_i128 *res, zig_i128 lhs, zig_i128 rhs, zig_u8 bits) { | 1652 | static inline bool zig_addo_i128(zig_i128 *res, zig_i128 lhs, zig_i128 rhs, uint8_t bits) { |
| 1550 | #if zig_has_builtin(add_overflow) | 1653 | #if zig_has_builtin(add_overflow) |
| 1551 | zig_i128 full_res; | 1654 | zig_i128 full_res; |
| 1552 | bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); | 1655 | bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); |
| 1553 | #else | 1656 | #else |
| 1554 | zig_c_int overflow_int; | 1657 | int overflow_int; |
| 1555 | zig_i128 full_res = __addoti4(lhs, rhs, &overflow_int); | 1658 | zig_i128 full_res = __addoti4(lhs, rhs, &overflow_int); |
| 1556 | bool overflow = overflow_int != 0; | 1659 | bool overflow = overflow_int != 0; |
| 1557 | #endif | 1660 | #endif |
| 1558 | *res = zig_wrap_i128(full_res, bits); | 1661 | *res = zig_wrap_i128(full_res, bits); |
| 1559 | return overflow || full_res < zig_minInt(i128, bits) || full_res > zig_maxInt(i128, bits); | 1662 | return overflow || full_res < zig_minInt_i(128, bits) || full_res > zig_maxInt_i(128, bits); |
| 1560 | } | 1663 | } |
| 1561 | | 1664 | |
| 1562 | static inline bool zig_subo_u128(zig_u128 *res, zig_u128 lhs, zig_u128 rhs, zig_u8 bits) { | 1665 | static inline bool zig_subo_u128(zig_u128 *res, zig_u128 lhs, zig_u128 rhs, uint8_t bits) { |
| 1563 | #if zig_has_builtin(sub_overflow) | 1666 | #if zig_has_builtin(sub_overflow) |
| 1564 | zig_u128 full_res; | 1667 | zig_u128 full_res; |
| 1565 | bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); | 1668 | bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); |
| 1566 | *res = zig_wrap_u128(full_res, bits); | 1669 | *res = zig_wrap_u128(full_res, bits); |
| 1567 | return overflow || full_res < zig_minInt(u128, bits) || full_res > zig_maxInt(u128, bits); | 1670 | return overflow || full_res < zig_minInt_u(128, bits) || full_res > zig_maxInt_u(128, bits); |
| 1568 | #else | 1671 | #else |
| 1569 | *res = zig_subw_u128(lhs, rhs, bits); | 1672 | *res = zig_subw_u128(lhs, rhs, bits); |
| 1570 | return *res > lhs; | 1673 | return *res > lhs; |
| 1571 | #endif | 1674 | #endif |
| 1572 | } | 1675 | } |
| 1573 | | 1676 | |
| 1574 | zig_extern zig_i128 __suboti4(zig_i128 lhs, zig_i128 rhs, zig_c_int *overflow); | 1677 | zig_extern zig_i128 __suboti4(zig_i128 lhs, zig_i128 rhs, int *overflow); |
| 1575 | static inline bool zig_subo_i128(zig_i128 *res, zig_i128 lhs, zig_i128 rhs, zig_u8 bits) { | 1678 | static inline bool zig_subo_i128(zig_i128 *res, zig_i128 lhs, zig_i128 rhs, uint8_t bits) { |
| 1576 | #if zig_has_builtin(sub_overflow) | 1679 | #if zig_has_builtin(sub_overflow) |
| 1577 | zig_i128 full_res; | 1680 | zig_i128 full_res; |
| 1578 | bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); | 1681 | bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); |
| 1579 | #else | 1682 | #else |
| 1580 | zig_c_int overflow_int; | 1683 | int overflow_int; |
| 1581 | zig_i128 full_res = __suboti4(lhs, rhs, &overflow_int); | 1684 | zig_i128 full_res = __suboti4(lhs, rhs, &overflow_int); |
| 1582 | bool overflow = overflow_int != 0; | 1685 | bool overflow = overflow_int != 0; |
| 1583 | #endif | 1686 | #endif |
| 1584 | *res = zig_wrap_i128(full_res, bits); | 1687 | *res = zig_wrap_i128(full_res, bits); |
| 1585 | return overflow || full_res < zig_minInt(i128, bits) || full_res > zig_maxInt(i128, bits); | 1688 | return overflow || full_res < zig_minInt_i(128, bits) || full_res > zig_maxInt_i(128, bits); |
| 1586 | } | 1689 | } |
| 1587 | | 1690 | |
| 1588 | static inline bool zig_mulo_u128(zig_u128 *res, zig_u128 lhs, zig_u128 rhs, zig_u8 bits) { | 1691 | static inline bool zig_mulo_u128(zig_u128 *res, zig_u128 lhs, zig_u128 rhs, uint8_t bits) { |
| 1589 | #if zig_has_builtin(mul_overflow) | 1692 | #if zig_has_builtin(mul_overflow) |
| 1590 | zig_u128 full_res; | 1693 | zig_u128 full_res; |
| 1591 | bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); | 1694 | bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); |
| 1592 | *res = zig_wrap_u128(full_res, bits); | 1695 | *res = zig_wrap_u128(full_res, bits); |
| 1593 | return overflow || full_res < zig_minInt(u128, bits) || full_res > zig_maxInt(u128, bits); | 1696 | return overflow || full_res < zig_minInt_u(128, bits) || full_res > zig_maxInt_u(128, bits); |
| 1594 | #else | 1697 | #else |
| 1595 | *res = zig_mulw_u128(lhs, rhs, bits); | 1698 | *res = zig_mulw_u128(lhs, rhs, bits); |
| 1596 | return rhs != zig_as_u128(0, 0) && lhs > zig_maxInt(u128, bits) / rhs; | 1699 | return rhs != zig_make_u128(0, 0) && lhs > zig_maxInt_u(128, bits) / rhs; |
| 1597 | #endif | 1700 | #endif |
| 1598 | } | 1701 | } |
| 1599 | | 1702 | |
| 1600 | zig_extern zig_i128 __muloti4(zig_i128 lhs, zig_i128 rhs, zig_c_int *overflow); | 1703 | zig_extern zig_i128 __muloti4(zig_i128 lhs, zig_i128 rhs, int *overflow); |
| 1601 | static inline bool zig_mulo_i128(zig_i128 *res, zig_i128 lhs, zig_i128 rhs, zig_u8 bits) { | 1704 | static inline bool zig_mulo_i128(zig_i128 *res, zig_i128 lhs, zig_i128 rhs, uint8_t bits) { |
| 1602 | #if zig_has_builtin(mul_overflow) | 1705 | #if zig_has_builtin(mul_overflow) |
| 1603 | zig_i128 full_res; | 1706 | zig_i128 full_res; |
| 1604 | bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); | 1707 | bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); |
| 1605 | #else | 1708 | #else |
| 1606 | zig_c_int overflow_int; | 1709 | int overflow_int; |
| 1607 | zig_i128 full_res = __muloti4(lhs, rhs, &overflow_int); | 1710 | zig_i128 full_res = __muloti4(lhs, rhs, &overflow_int); |
| 1608 | bool overflow = overflow_int != 0; | 1711 | bool overflow = overflow_int != 0; |
| 1609 | #endif | 1712 | #endif |
| 1610 | *res = zig_wrap_i128(full_res, bits); | 1713 | *res = zig_wrap_i128(full_res, bits); |
| 1611 | return overflow || full_res < zig_minInt(i128, bits) || full_res > zig_maxInt(i128, bits); | 1714 | return overflow || full_res < zig_minInt_i(128, bits) || full_res > zig_maxInt_i(128, bits); |
| 1612 | } | 1715 | } |
| 1613 | | 1716 | |
| 1614 | #else /* zig_has_int128 */ | 1717 | #else /* zig_has_int128 */ |
| 1615 | | 1718 | |
| 1616 | static inline bool zig_overflow_u128(bool overflow, zig_u128 full_res, zig_u8 bits) { | 1719 | static inline bool zig_overflow_u128(bool overflow, zig_u128 full_res, uint8_t bits) { |
| 1617 | return overflow || | 1720 | return overflow || |
| 1618 | zig_cmp_u128(full_res, zig_minInt(u128, bits)) < zig_as_i32(0) || | 1721 | zig_cmp_u128(full_res, zig_minInt_u(128, bits)) < INT32_C(0) || |
| 1619 | zig_cmp_u128(full_res, zig_maxInt(u128, bits)) > zig_as_i32(0); | 1722 | zig_cmp_u128(full_res, zig_maxInt_u(128, bits)) > INT32_C(0); |
| 1620 | } | 1723 | } |
| 1621 | | 1724 | |
| 1622 | static inline bool zig_overflow_i128(bool overflow, zig_i128 full_res, zig_u8 bits) { | 1725 | static inline bool zig_overflow_i128(bool overflow, zig_i128 full_res, uint8_t bits) { |
| 1623 | return overflow || | 1726 | return overflow || |
| 1624 | zig_cmp_i128(full_res, zig_minInt(i128, bits)) < zig_as_i32(0) || | 1727 | zig_cmp_i128(full_res, zig_minInt_i(128, bits)) < INT32_C(0) || |
| 1625 | zig_cmp_i128(full_res, zig_maxInt(i128, bits)) > zig_as_i32(0); | 1728 | zig_cmp_i128(full_res, zig_maxInt_i(128, bits)) > INT32_C(0); |
| 1626 | } | 1729 | } |
| 1627 | | 1730 | |
| 1628 | static inline bool zig_addo_u128(zig_u128 *res, zig_u128 lhs, zig_u128 rhs, zig_u8 bits) { | 1731 | static inline bool zig_addo_u128(zig_u128 *res, zig_u128 lhs, zig_u128 rhs, uint8_t bits) { |
| 1629 | zig_u128 full_res; | 1732 | zig_u128 full_res; |
| 1630 | bool overflow = | 1733 | bool overflow = |
| 1631 | zig_addo_u64(&full_res.hi, lhs.hi, rhs.hi, 64) | | 1734 | zig_addo_u64(&full_res.hi, lhs.hi, rhs.hi, 64) | |
| ... | @@ -1634,15 +1737,15 @@ static inline bool zig_addo_u128(zig_u128 *res, zig_u128 lhs, zig_u128 rhs, zig_ | ... | @@ -1634,15 +1737,15 @@ static inline bool zig_addo_u128(zig_u128 *res, zig_u128 lhs, zig_u128 rhs, zig_ |
| 1634 | return zig_overflow_u128(overflow, full_res, bits); | 1737 | return zig_overflow_u128(overflow, full_res, bits); |
| 1635 | } | 1738 | } |
| 1636 | | 1739 | |
| 1637 | zig_extern zig_i128 __addoti4(zig_i128 lhs, zig_i128 rhs, zig_c_int *overflow); | 1740 | zig_extern zig_i128 __addoti4(zig_i128 lhs, zig_i128 rhs, int *overflow); |
| 1638 | static inline bool zig_addo_i128(zig_i128 *res, zig_i128 lhs, zig_i128 rhs, zig_u8 bits) { | 1741 | static inline bool zig_addo_i128(zig_i128 *res, zig_i128 lhs, zig_i128 rhs, uint8_t bits) { |
| 1639 | zig_c_int overflow_int; | 1742 | int overflow_int; |
| 1640 | zig_i128 full_res = __addoti4(lhs, rhs, &overflow_int); | 1743 | zig_i128 full_res = __addoti4(lhs, rhs, &overflow_int); |
| 1641 | *res = zig_wrap_i128(full_res, bits); | 1744 | *res = zig_wrap_i128(full_res, bits); |
| 1642 | return zig_overflow_i128(overflow_int, full_res, bits); | 1745 | return zig_overflow_i128(overflow_int, full_res, bits); |
| 1643 | } | 1746 | } |
| 1644 | | 1747 | |
| 1645 | static inline bool zig_subo_u128(zig_u128 *res, zig_u128 lhs, zig_u128 rhs, zig_u8 bits) { | 1748 | static inline bool zig_subo_u128(zig_u128 *res, zig_u128 lhs, zig_u128 rhs, uint8_t bits) { |
| 1646 | zig_u128 full_res; | 1749 | zig_u128 full_res; |
| 1647 | bool overflow = | 1750 | bool overflow = |
| 1648 | zig_subo_u64(&full_res.hi, lhs.hi, rhs.hi, 64) | | 1751 | zig_subo_u64(&full_res.hi, lhs.hi, rhs.hi, 64) | |
| ... | @@ -1651,23 +1754,23 @@ static inline bool zig_subo_u128(zig_u128 *res, zig_u128 lhs, zig_u128 rhs, zig_ | ... | @@ -1651,23 +1754,23 @@ static inline bool zig_subo_u128(zig_u128 *res, zig_u128 lhs, zig_u128 rhs, zig_ |
| 1651 | return zig_overflow_u128(overflow, full_res, bits); | 1754 | return zig_overflow_u128(overflow, full_res, bits); |
| 1652 | } | 1755 | } |
| 1653 | | 1756 | |
| 1654 | zig_extern zig_i128 __suboti4(zig_i128 lhs, zig_i128 rhs, zig_c_int *overflow); | 1757 | zig_extern zig_i128 __suboti4(zig_i128 lhs, zig_i128 rhs, int *overflow); |
| 1655 | static inline bool zig_subo_i128(zig_i128 *res, zig_i128 lhs, zig_i128 rhs, zig_u8 bits) { | 1758 | static inline bool zig_subo_i128(zig_i128 *res, zig_i128 lhs, zig_i128 rhs, uint8_t bits) { |
| 1656 | zig_c_int overflow_int; | 1759 | int overflow_int; |
| 1657 | zig_i128 full_res = __suboti4(lhs, rhs, &overflow_int); | 1760 | zig_i128 full_res = __suboti4(lhs, rhs, &overflow_int); |
| 1658 | *res = zig_wrap_i128(full_res, bits); | 1761 | *res = zig_wrap_i128(full_res, bits); |
| 1659 | return zig_overflow_i128(overflow_int, full_res, bits); | 1762 | return zig_overflow_i128(overflow_int, full_res, bits); |
| 1660 | } | 1763 | } |
| 1661 | | 1764 | |
| 1662 | static inline bool zig_mulo_u128(zig_u128 *res, zig_u128 lhs, zig_u128 rhs, zig_u8 bits) { | 1765 | static inline bool zig_mulo_u128(zig_u128 *res, zig_u128 lhs, zig_u128 rhs, uint8_t bits) { |
| 1663 | *res = zig_mulw_u128(lhs, rhs, bits); | 1766 | *res = zig_mulw_u128(lhs, rhs, bits); |
| 1664 | return zig_cmp_u128(*res, zig_as_u128(0, 0)) != zig_as_i32(0) && | 1767 | return zig_cmp_u128(*res, zig_make_u128(0, 0)) != INT32_C(0) && |
| 1665 | zig_cmp_u128(lhs, zig_div_trunc_u128(zig_maxInt(u128, bits), rhs)) > zig_as_i32(0); | 1768 | zig_cmp_u128(lhs, zig_div_trunc_u128(zig_maxInt_u(128, bits), rhs)) > INT32_C(0); |
| 1666 | } | 1769 | } |
| 1667 | | 1770 | |
| 1668 | zig_extern zig_i128 __muloti4(zig_i128 lhs, zig_i128 rhs, zig_c_int *overflow); | 1771 | zig_extern zig_i128 __muloti4(zig_i128 lhs, zig_i128 rhs, int *overflow); |
| 1669 | static inline bool zig_mulo_i128(zig_i128 *res, zig_i128 lhs, zig_i128 rhs, zig_u8 bits) { | 1772 | static inline bool zig_mulo_i128(zig_i128 *res, zig_i128 lhs, zig_i128 rhs, uint8_t bits) { |
| 1670 | zig_c_int overflow_int; | 1773 | int overflow_int; |
| 1671 | zig_i128 full_res = __muloti4(lhs, rhs, &overflow_int); | 1774 | zig_i128 full_res = __muloti4(lhs, rhs, &overflow_int); |
| 1672 | *res = zig_wrap_i128(full_res, bits); | 1775 | *res = zig_wrap_i128(full_res, bits); |
| 1673 | return zig_overflow_i128(overflow_int, full_res, bits); | 1776 | return zig_overflow_i128(overflow_int, full_res, bits); |
| ... | @@ -1675,119 +1778,119 @@ static inline bool zig_mulo_i128(zig_i128 *res, zig_i128 lhs, zig_i128 rhs, zig_ | ... | @@ -1675,119 +1778,119 @@ static inline bool zig_mulo_i128(zig_i128 *res, zig_i128 lhs, zig_i128 rhs, zig_ |
| 1675 | | 1778 | |
| 1676 | #endif /* zig_has_int128 */ | 1779 | #endif /* zig_has_int128 */ |
| 1677 | | 1780 | |
| 1678 | static inline bool zig_shlo_u128(zig_u128 *res, zig_u128 lhs, zig_u8 rhs, zig_u8 bits) { | 1781 | static inline bool zig_shlo_u128(zig_u128 *res, zig_u128 lhs, uint8_t rhs, uint8_t bits) { |
| 1679 | *res = zig_shlw_u128(lhs, rhs, bits); | 1782 | *res = zig_shlw_u128(lhs, rhs, bits); |
| 1680 | return zig_cmp_u128(lhs, zig_shr_u128(zig_maxInt(u128, bits), rhs)) > zig_as_i32(0); | 1783 | return zig_cmp_u128(lhs, zig_shr_u128(zig_maxInt_u(128, bits), rhs)) > INT32_C(0); |
| 1681 | } | 1784 | } |
| 1682 | | 1785 | |
| 1683 | static inline bool zig_shlo_i128(zig_i128 *res, zig_i128 lhs, zig_u8 rhs, zig_u8 bits) { | 1786 | static inline bool zig_shlo_i128(zig_i128 *res, zig_i128 lhs, uint8_t rhs, uint8_t bits) { |
| 1684 | *res = zig_shlw_i128(lhs, rhs, bits); | 1787 | *res = zig_shlw_i128(lhs, rhs, bits); |
| 1685 | zig_i128 mask = zig_bitcast_i128(zig_shl_u128(zig_maxInt_u128, bits - rhs - zig_as_u8(1))); | 1788 | zig_i128 mask = zig_bitcast_i128(zig_shl_u128(zig_maxInt_u128, bits - rhs - UINT8_C(1))); |
| 1686 | return zig_cmp_i128(zig_and_i128(lhs, mask), zig_as_i128(0, 0)) != zig_as_i32(0) && | 1789 | return zig_cmp_i128(zig_and_i128(lhs, mask), zig_make_i128(0, 0)) != INT32_C(0) && |
| 1687 | zig_cmp_i128(zig_and_i128(lhs, mask), mask) != zig_as_i32(0); | 1790 | zig_cmp_i128(zig_and_i128(lhs, mask), mask) != INT32_C(0); |
| 1688 | } | 1791 | } |
| 1689 | | 1792 | |
| 1690 | static inline zig_u128 zig_shls_u128(zig_u128 lhs, zig_u128 rhs, zig_u8 bits) { | 1793 | static inline zig_u128 zig_shls_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) { |
| 1691 | zig_u128 res; | 1794 | zig_u128 res; |
| 1692 | if (zig_cmp_u128(rhs, zig_as_u128(0, bits)) >= zig_as_i32(0)) | 1795 | if (zig_cmp_u128(rhs, zig_make_u128(0, bits)) >= INT32_C(0)) |
| 1693 | return zig_cmp_u128(lhs, zig_as_u128(0, 0)) != zig_as_i32(0) ? zig_maxInt(u128, bits) : lhs; | 1796 | return zig_cmp_u128(lhs, zig_make_u128(0, 0)) != INT32_C(0) ? zig_maxInt_u(128, bits) : lhs; |
| 1694 | | 1797 | |
| 1695 | #if zig_has_int128 | 1798 | #if zig_has_int128 |
| 1696 | return zig_shlo_u128(&res, lhs, (zig_u8)rhs, bits) ? zig_maxInt(u128, bits) : res; | 1799 | return zig_shlo_u128(&res, lhs, (uint8_t)rhs, bits) ? zig_maxInt_u(128, bits) : res; |
| 1697 | #else | 1800 | #else |
| 1698 | return zig_shlo_u128(&res, lhs, (zig_u8)rhs.lo, bits) ? zig_maxInt(u128, bits) : res; | 1801 | return zig_shlo_u128(&res, lhs, (uint8_t)rhs.lo, bits) ? zig_maxInt_u(128, bits) : res; |
| 1699 | #endif | 1802 | #endif |
| 1700 | } | 1803 | } |
| 1701 | | 1804 | |
| 1702 | static inline zig_i128 zig_shls_i128(zig_i128 lhs, zig_i128 rhs, zig_u8 bits) { | 1805 | static inline zig_i128 zig_shls_i128(zig_i128 lhs, zig_i128 rhs, uint8_t bits) { |
| 1703 | zig_i128 res; | 1806 | zig_i128 res; |
| 1704 | if (zig_cmp_u128(zig_bitcast_u128(rhs), zig_as_u128(0, bits)) < zig_as_i32(0) && !zig_shlo_i128(&res, lhs, zig_lo_i128(rhs), bits)) return res; | 1807 | if (zig_cmp_u128(zig_bitcast_u128(rhs), zig_make_u128(0, bits)) < INT32_C(0) && !zig_shlo_i128(&res, lhs, zig_lo_i128(rhs), bits)) return res; |
| 1705 | return zig_cmp_i128(lhs, zig_as_i128(0, 0)) < zig_as_i32(0) ? zig_minInt(i128, bits) : zig_maxInt(i128, bits); | 1808 | return zig_cmp_i128(lhs, zig_make_i128(0, 0)) < INT32_C(0) ? zig_minInt_i(128, bits) : zig_maxInt_i(128, bits); |
| 1706 | } | 1809 | } |
| 1707 | | 1810 | |
| 1708 | static inline zig_u128 zig_adds_u128(zig_u128 lhs, zig_u128 rhs, zig_u8 bits) { | 1811 | static inline zig_u128 zig_adds_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) { |
| 1709 | zig_u128 res; | 1812 | zig_u128 res; |
| 1710 | return zig_addo_u128(&res, lhs, rhs, bits) ? zig_maxInt(u128, bits) : res; | 1813 | return zig_addo_u128(&res, lhs, rhs, bits) ? zig_maxInt_u(128, bits) : res; |
| 1711 | } | 1814 | } |
| 1712 | | 1815 | |
| 1713 | static inline zig_i128 zig_adds_i128(zig_i128 lhs, zig_i128 rhs, zig_u8 bits) { | 1816 | static inline zig_i128 zig_adds_i128(zig_i128 lhs, zig_i128 rhs, uint8_t bits) { |
| 1714 | zig_i128 res; | 1817 | zig_i128 res; |
| 1715 | if (!zig_addo_i128(&res, lhs, rhs, bits)) return res; | 1818 | if (!zig_addo_i128(&res, lhs, rhs, bits)) return res; |
| 1716 | return zig_cmp_i128(res, zig_as_i128(0, 0)) >= zig_as_i32(0) ? zig_minInt(i128, bits) : zig_maxInt(i128, bits); | 1819 | return zig_cmp_i128(res, zig_make_i128(0, 0)) >= INT32_C(0) ? zig_minInt_i(128, bits) : zig_maxInt_i(128, bits); |
| 1717 | } | 1820 | } |
| 1718 | | 1821 | |
| 1719 | static inline zig_u128 zig_subs_u128(zig_u128 lhs, zig_u128 rhs, zig_u8 bits) { | 1822 | static inline zig_u128 zig_subs_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) { |
| 1720 | zig_u128 res; | 1823 | zig_u128 res; |
| 1721 | return zig_subo_u128(&res, lhs, rhs, bits) ? zig_minInt(u128, bits) : res; | 1824 | return zig_subo_u128(&res, lhs, rhs, bits) ? zig_minInt_u(128, bits) : res; |
| 1722 | } | 1825 | } |
| 1723 | | 1826 | |
| 1724 | static inline zig_i128 zig_subs_i128(zig_i128 lhs, zig_i128 rhs, zig_u8 bits) { | 1827 | static inline zig_i128 zig_subs_i128(zig_i128 lhs, zig_i128 rhs, uint8_t bits) { |
| 1725 | zig_i128 res; | 1828 | zig_i128 res; |
| 1726 | if (!zig_subo_i128(&res, lhs, rhs, bits)) return res; | 1829 | if (!zig_subo_i128(&res, lhs, rhs, bits)) return res; |
| 1727 | return zig_cmp_i128(res, zig_as_i128(0, 0)) >= zig_as_i32(0) ? zig_minInt(i128, bits) : zig_maxInt(i128, bits); | 1830 | return zig_cmp_i128(res, zig_make_i128(0, 0)) >= INT32_C(0) ? zig_minInt_i(128, bits) : zig_maxInt_i(128, bits); |
| 1728 | } | 1831 | } |
| 1729 | | 1832 | |
| 1730 | static inline zig_u128 zig_muls_u128(zig_u128 lhs, zig_u128 rhs, zig_u8 bits) { | 1833 | static inline zig_u128 zig_muls_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) { |
| 1731 | zig_u128 res; | 1834 | zig_u128 res; |
| 1732 | return zig_mulo_u128(&res, lhs, rhs, bits) ? zig_maxInt(u128, bits) : res; | 1835 | return zig_mulo_u128(&res, lhs, rhs, bits) ? zig_maxInt_u(128, bits) : res; |
| 1733 | } | 1836 | } |
| 1734 | | 1837 | |
| 1735 | static inline zig_i128 zig_muls_i128(zig_i128 lhs, zig_i128 rhs, zig_u8 bits) { | 1838 | static inline zig_i128 zig_muls_i128(zig_i128 lhs, zig_i128 rhs, uint8_t bits) { |
| 1736 | zig_i128 res; | 1839 | zig_i128 res; |
| 1737 | if (!zig_mulo_i128(&res, lhs, rhs, bits)) return res; | 1840 | if (!zig_mulo_i128(&res, lhs, rhs, bits)) return res; |
| 1738 | return zig_cmp_i128(zig_xor_i128(lhs, rhs), zig_as_i128(0, 0)) < zig_as_i32(0) ? zig_minInt(i128, bits) : zig_maxInt(i128, bits); | 1841 | return zig_cmp_i128(zig_xor_i128(lhs, rhs), zig_make_i128(0, 0)) < INT32_C(0) ? zig_minInt_i(128, bits) : zig_maxInt_i(128, bits); |
| 1739 | } | 1842 | } |
| 1740 | | 1843 | |
| 1741 | static inline zig_u8 zig_clz_u128(zig_u128 val, zig_u8 bits) { | 1844 | static inline uint8_t zig_clz_u128(zig_u128 val, uint8_t bits) { |
| 1742 | if (bits <= zig_as_u8(64)) return zig_clz_u64(zig_lo_u128(val), bits); | 1845 | if (bits <= UINT8_C(64)) return zig_clz_u64(zig_lo_u128(val), bits); |
| 1743 | if (zig_hi_u128(val) != 0) return zig_clz_u64(zig_hi_u128(val), bits - zig_as_u8(64)); | 1846 | if (zig_hi_u128(val) != 0) return zig_clz_u64(zig_hi_u128(val), bits - UINT8_C(64)); |
| 1744 | return zig_clz_u64(zig_lo_u128(val), zig_as_u8(64)) + (bits - zig_as_u8(64)); | 1847 | return zig_clz_u64(zig_lo_u128(val), UINT8_C(64)) + (bits - UINT8_C(64)); |
| 1745 | } | 1848 | } |
| 1746 | | 1849 | |
| 1747 | static inline zig_u8 zig_clz_i128(zig_i128 val, zig_u8 bits) { | 1850 | static inline uint8_t zig_clz_i128(zig_i128 val, uint8_t bits) { |
| 1748 | return zig_clz_u128(zig_bitcast_u128(val), bits); | 1851 | return zig_clz_u128(zig_bitcast_u128(val), bits); |
| 1749 | } | 1852 | } |
| 1750 | | 1853 | |
| 1751 | static inline zig_u8 zig_ctz_u128(zig_u128 val, zig_u8 bits) { | 1854 | static inline uint8_t zig_ctz_u128(zig_u128 val, uint8_t bits) { |
| 1752 | if (zig_lo_u128(val) != 0) return zig_ctz_u64(zig_lo_u128(val), zig_as_u8(64)); | 1855 | if (zig_lo_u128(val) != 0) return zig_ctz_u64(zig_lo_u128(val), UINT8_C(64)); |
| 1753 | return zig_ctz_u64(zig_hi_u128(val), bits - zig_as_u8(64)) + zig_as_u8(64); | 1856 | return zig_ctz_u64(zig_hi_u128(val), bits - UINT8_C(64)) + UINT8_C(64); |
| 1754 | } | 1857 | } |
| 1755 | | 1858 | |
| 1756 | static inline zig_u8 zig_ctz_i128(zig_i128 val, zig_u8 bits) { | 1859 | static inline uint8_t zig_ctz_i128(zig_i128 val, uint8_t bits) { |
| 1757 | return zig_ctz_u128(zig_bitcast_u128(val), bits); | 1860 | return zig_ctz_u128(zig_bitcast_u128(val), bits); |
| 1758 | } | 1861 | } |
| 1759 | | 1862 | |
| 1760 | static inline zig_u8 zig_popcount_u128(zig_u128 val, zig_u8 bits) { | 1863 | static inline uint8_t zig_popcount_u128(zig_u128 val, uint8_t bits) { |
| 1761 | return zig_popcount_u64(zig_hi_u128(val), bits - zig_as_u8(64)) + | 1864 | return zig_popcount_u64(zig_hi_u128(val), bits - UINT8_C(64)) + |
| 1762 | zig_popcount_u64(zig_lo_u128(val), zig_as_u8(64)); | 1865 | zig_popcount_u64(zig_lo_u128(val), UINT8_C(64)); |
| 1763 | } | 1866 | } |
| 1764 | | 1867 | |
| 1765 | static inline zig_u8 zig_popcount_i128(zig_i128 val, zig_u8 bits) { | 1868 | static inline uint8_t zig_popcount_i128(zig_i128 val, uint8_t bits) { |
| 1766 | return zig_popcount_u128(zig_bitcast_u128(val), bits); | 1869 | return zig_popcount_u128(zig_bitcast_u128(val), bits); |
| 1767 | } | 1870 | } |
| 1768 | | 1871 | |
| 1769 | static inline zig_u128 zig_byte_swap_u128(zig_u128 val, zig_u8 bits) { | 1872 | static inline zig_u128 zig_byte_swap_u128(zig_u128 val, uint8_t bits) { |
| 1770 | zig_u128 full_res; | 1873 | zig_u128 full_res; |
| 1771 | #if zig_has_builtin(bswap128) | 1874 | #if zig_has_builtin(bswap128) |
| 1772 | full_res = __builtin_bswap128(val); | 1875 | full_res = __builtin_bswap128(val); |
| 1773 | #else | 1876 | #else |
| 1774 | full_res = zig_as_u128(zig_byte_swap_u64(zig_lo_u128(val), zig_as_u8(64)), | 1877 | full_res = zig_make_u128(zig_byte_swap_u64(zig_lo_u128(val), UINT8_C(64)), |
| 1775 | zig_byte_swap_u64(zig_hi_u128(val), zig_as_u8(64))); | 1878 | zig_byte_swap_u64(zig_hi_u128(val), UINT8_C(64))); |
| 1776 | #endif | 1879 | #endif |
| 1777 | return zig_shr_u128(full_res, zig_as_u8(128) - bits); | 1880 | return zig_shr_u128(full_res, UINT8_C(128) - bits); |
| 1778 | } | 1881 | } |
| 1779 | | 1882 | |
| 1780 | static inline zig_i128 zig_byte_swap_i128(zig_i128 val, zig_u8 bits) { | 1883 | static inline zig_i128 zig_byte_swap_i128(zig_i128 val, uint8_t bits) { |
| 1781 | return zig_bitcast_i128(zig_byte_swap_u128(zig_bitcast_u128(val), bits)); | 1884 | return zig_bitcast_i128(zig_byte_swap_u128(zig_bitcast_u128(val), bits)); |
| 1782 | } | 1885 | } |
| 1783 | | 1886 | |
| 1784 | static inline zig_u128 zig_bit_reverse_u128(zig_u128 val, zig_u8 bits) { | 1887 | static inline zig_u128 zig_bit_reverse_u128(zig_u128 val, uint8_t bits) { |
| 1785 | return zig_shr_u128(zig_as_u128(zig_bit_reverse_u64(zig_lo_u128(val), zig_as_u8(64)), | 1888 | return zig_shr_u128(zig_make_u128(zig_bit_reverse_u64(zig_lo_u128(val), UINT8_C(64)), |
| 1786 | zig_bit_reverse_u64(zig_hi_u128(val), zig_as_u8(64))), | 1889 | zig_bit_reverse_u64(zig_hi_u128(val), UINT8_C(64))), |
| 1787 | zig_as_u8(128) - bits); | 1890 | UINT8_C(128) - bits); |
| 1788 | } | 1891 | } |
| 1789 | | 1892 | |
| 1790 | static inline zig_i128 zig_bit_reverse_i128(zig_i128 val, zig_u8 bits) { | 1893 | static inline zig_i128 zig_bit_reverse_i128(zig_i128 val, uint8_t bits) { |
| 1791 | return zig_bitcast_i128(zig_bit_reverse_u128(zig_bitcast_u128(val), bits)); | 1894 | return zig_bitcast_i128(zig_bit_reverse_u128(zig_bitcast_u128(val), bits)); |
| 1792 | } | 1895 | } |
| 1793 | | 1896 | |
| ... | @@ -1810,85 +1913,85 @@ static inline zig_i128 zig_bit_reverse_i128(zig_i128 val, zig_u8 bits) { | ... | @@ -1810,85 +1913,85 @@ static inline zig_i128 zig_bit_reverse_i128(zig_i128 val, zig_u8 bits) { |
| 1810 | | 1913 | |
| 1811 | #if (zig_has_builtin(nan) && zig_has_builtin(nans) && zig_has_builtin(inf)) || defined(zig_gnuc) | 1914 | #if (zig_has_builtin(nan) && zig_has_builtin(nans) && zig_has_builtin(inf)) || defined(zig_gnuc) |
| 1812 | #define zig_has_float_builtins 1 | 1915 | #define zig_has_float_builtins 1 |
| 1813 | #define zig_as_special_f16(sign, name, arg, repr) sign zig_as_f16(__builtin_##name, )(arg) | 1916 | #define zig_make_special_f16(sign, name, arg, repr) sign zig_make_f16(__builtin_##name, )(arg) |
| 1814 | #define zig_as_special_f32(sign, name, arg, repr) sign zig_as_f32(__builtin_##name, )(arg) | 1917 | #define zig_make_special_f32(sign, name, arg, repr) sign zig_make_f32(__builtin_##name, )(arg) |
| 1815 | #define zig_as_special_f64(sign, name, arg, repr) sign zig_as_f64(__builtin_##name, )(arg) | 1918 | #define zig_make_special_f64(sign, name, arg, repr) sign zig_make_f64(__builtin_##name, )(arg) |
| 1816 | #define zig_as_special_f80(sign, name, arg, repr) sign zig_as_f80(__builtin_##name, )(arg) | 1919 | #define zig_make_special_f80(sign, name, arg, repr) sign zig_make_f80(__builtin_##name, )(arg) |
| 1817 | #define zig_as_special_f128(sign, name, arg, repr) sign zig_as_f128(__builtin_##name, )(arg) | 1920 | #define zig_make_special_f128(sign, name, arg, repr) sign zig_make_f128(__builtin_##name, )(arg) |
| 1818 | #define zig_as_special_c_longdouble(sign, name, arg, repr) sign zig_as_c_longdouble(__builtin_##name, )(arg) | 1921 | #define zig_make_special_c_longdouble(sign, name, arg, repr) sign zig_make_c_longdouble(__builtin_##name, )(arg) |
| 1819 | #else | 1922 | #else |
| 1820 | #define zig_has_float_builtins 0 | 1923 | #define zig_has_float_builtins 0 |
| 1821 | #define zig_as_special_f16(sign, name, arg, repr) zig_float_from_repr_f16(repr) | 1924 | #define zig_make_special_f16(sign, name, arg, repr) zig_float_from_repr_f16(repr) |
| 1822 | #define zig_as_special_f32(sign, name, arg, repr) zig_float_from_repr_f32(repr) | 1925 | #define zig_make_special_f32(sign, name, arg, repr) zig_float_from_repr_f32(repr) |
| 1823 | #define zig_as_special_f64(sign, name, arg, repr) zig_float_from_repr_f64(repr) | 1926 | #define zig_make_special_f64(sign, name, arg, repr) zig_float_from_repr_f64(repr) |
| 1824 | #define zig_as_special_f80(sign, name, arg, repr) zig_float_from_repr_f80(repr) | 1927 | #define zig_make_special_f80(sign, name, arg, repr) zig_float_from_repr_f80(repr) |
| 1825 | #define zig_as_special_f128(sign, name, arg, repr) zig_float_from_repr_f128(repr) | 1928 | #define zig_make_special_f128(sign, name, arg, repr) zig_float_from_repr_f128(repr) |
| 1826 | #define zig_as_special_c_longdouble(sign, name, arg, repr) zig_float_from_repr_c_longdouble(repr) | 1929 | #define zig_make_special_c_longdouble(sign, name, arg, repr) zig_float_from_repr_c_longdouble(repr) |
| 1827 | #endif | 1930 | #endif |
| 1828 | | 1931 | |
| 1829 | #define zig_has_f16 1 | 1932 | #define zig_has_f16 1 |
| 1830 | #define zig_bitSizeOf_f16 16 | 1933 | #define zig_bitSizeOf_f16 16 |
| 1831 | #define zig_libc_name_f16(name) __##name##h | 1934 | #define zig_libc_name_f16(name) __##name##h |
| 1832 | #define zig_as_special_constant_f16(sign, name, arg, repr) zig_as_special_f16(sign, name, arg, repr) | 1935 | #define zig_make_special_constant_f16(sign, name, arg, repr) zig_make_special_f16(sign, name, arg, repr) |
| 1833 | #if FLT_MANT_DIG == 11 | 1936 | #if FLT_MANT_DIG == 11 |
| 1834 | typedef float zig_f16; | 1937 | typedef float zig_f16; |
| 1835 | #define zig_as_f16(fp, repr) fp##f | 1938 | #define zig_make_f16(fp, repr) fp##f |
| 1836 | #elif DBL_MANT_DIG == 11 | 1939 | #elif DBL_MANT_DIG == 11 |
| 1837 | typedef double zig_f16; | 1940 | typedef double zig_f16; |
| 1838 | #define zig_as_f16(fp, repr) fp | 1941 | #define zig_make_f16(fp, repr) fp |
| 1839 | #elif LDBL_MANT_DIG == 11 | 1942 | #elif LDBL_MANT_DIG == 11 |
| 1840 | #define zig_bitSizeOf_c_longdouble 16 | 1943 | #define zig_bitSizeOf_c_longdouble 16 |
| 1841 | typedef long double zig_f16; | 1944 | typedef long double zig_f16; |
| 1842 | #define zig_as_f16(fp, repr) fp##l | 1945 | #define zig_make_f16(fp, repr) fp##l |
| 1843 | #elif FLT16_MANT_DIG == 11 && (zig_has_builtin(inff16) || defined(zig_gnuc)) | 1946 | #elif FLT16_MANT_DIG == 11 && (zig_has_builtin(inff16) || defined(zig_gnuc)) |
| 1844 | typedef _Float16 zig_f16; | 1947 | typedef _Float16 zig_f16; |
| 1845 | #define zig_as_f16(fp, repr) fp##f16 | 1948 | #define zig_make_f16(fp, repr) fp##f16 |
| 1846 | #elif defined(__SIZEOF_FP16__) | 1949 | #elif defined(__SIZEOF_FP16__) |
| 1847 | typedef __fp16 zig_f16; | 1950 | typedef __fp16 zig_f16; |
| 1848 | #define zig_as_f16(fp, repr) fp##f16 | 1951 | #define zig_make_f16(fp, repr) fp##f16 |
| 1849 | #else | 1952 | #else |
| 1850 | #undef zig_has_f16 | 1953 | #undef zig_has_f16 |
| 1851 | #define zig_has_f16 0 | 1954 | #define zig_has_f16 0 |
| 1852 | #define zig_repr_f16 i16 | 1955 | #define zig_bitSizeOf_repr_f16 16 |
| 1853 | typedef zig_i16 zig_f16; | 1956 | typedef int16_t zig_f16; |
| 1854 | #define zig_as_f16(fp, repr) repr | 1957 | #define zig_make_f16(fp, repr) repr |
| 1855 | #undef zig_as_special_f16 | 1958 | #undef zig_make_special_f16 |
| 1856 | #define zig_as_special_f16(sign, name, arg, repr) repr | 1959 | #define zig_make_special_f16(sign, name, arg, repr) repr |
| 1857 | #undef zig_as_special_constant_f16 | 1960 | #undef zig_make_special_constant_f16 |
| 1858 | #define zig_as_special_constant_f16(sign, name, arg, repr) repr | 1961 | #define zig_make_special_constant_f16(sign, name, arg, repr) repr |
| 1859 | #endif | 1962 | #endif |
| 1860 | | 1963 | |
| 1861 | #define zig_has_f32 1 | 1964 | #define zig_has_f32 1 |
| 1862 | #define zig_bitSizeOf_f32 32 | 1965 | #define zig_bitSizeOf_f32 32 |
| 1863 | #define zig_libc_name_f32(name) name##f | 1966 | #define zig_libc_name_f32(name) name##f |
| 1864 | #if _MSC_VER | 1967 | #if _MSC_VER |
| 1865 | #define zig_as_special_constant_f32(sign, name, arg, repr) sign zig_as_f32(zig_msvc_flt_##name, ) | 1968 | #define zig_make_special_constant_f32(sign, name, arg, repr) sign zig_make_f32(zig_msvc_flt_##name, ) |
| 1866 | #else | 1969 | #else |
| 1867 | #define zig_as_special_constant_f32(sign, name, arg, repr) zig_as_special_f32(sign, name, arg, repr) | 1970 | #define zig_make_special_constant_f32(sign, name, arg, repr) zig_make_special_f32(sign, name, arg, repr) |
| 1868 | #endif | 1971 | #endif |
| 1869 | #if FLT_MANT_DIG == 24 | 1972 | #if FLT_MANT_DIG == 24 |
| 1870 | typedef float zig_f32; | 1973 | typedef float zig_f32; |
| 1871 | #define zig_as_f32(fp, repr) fp##f | 1974 | #define zig_make_f32(fp, repr) fp##f |
| 1872 | #elif DBL_MANT_DIG == 24 | 1975 | #elif DBL_MANT_DIG == 24 |
| 1873 | typedef double zig_f32; | 1976 | typedef double zig_f32; |
| 1874 | #define zig_as_f32(fp, repr) fp | 1977 | #define zig_make_f32(fp, repr) fp |
| 1875 | #elif LDBL_MANT_DIG == 24 | 1978 | #elif LDBL_MANT_DIG == 24 |
| 1876 | #define zig_bitSizeOf_c_longdouble 32 | 1979 | #define zig_bitSizeOf_c_longdouble 32 |
| 1877 | typedef long double zig_f32; | 1980 | typedef long double zig_f32; |
| 1878 | #define zig_as_f32(fp, repr) fp##l | 1981 | #define zig_make_f32(fp, repr) fp##l |
| 1879 | #elif FLT32_MANT_DIG == 24 | 1982 | #elif FLT32_MANT_DIG == 24 |
| 1880 | typedef _Float32 zig_f32; | 1983 | typedef _Float32 zig_f32; |
| 1881 | #define zig_as_f32(fp, repr) fp##f32 | 1984 | #define zig_make_f32(fp, repr) fp##f32 |
| 1882 | #else | 1985 | #else |
| 1883 | #undef zig_has_f32 | 1986 | #undef zig_has_f32 |
| 1884 | #define zig_has_f32 0 | 1987 | #define zig_has_f32 0 |
| 1885 | #define zig_repr_f32 i32 | 1988 | #define zig_bitSizeOf_repr_f32 32 |
| 1886 | typedef zig_i32 zig_f32; | 1989 | typedef int32_t zig_f32; |
| 1887 | #define zig_as_f32(fp, repr) repr | 1990 | #define zig_make_f32(fp, repr) repr |
| 1888 | #undef zig_as_special_f32 | 1991 | #undef zig_make_special_f32 |
| 1889 | #define zig_as_special_f32(sign, name, arg, repr) repr | 1992 | #define zig_make_special_f32(sign, name, arg, repr) repr |
| 1890 | #undef zig_as_special_constant_f32 | 1993 | #undef zig_make_special_constant_f32 |
| 1891 | #define zig_as_special_constant_f32(sign, name, arg, repr) repr | 1994 | #define zig_make_special_constant_f32(sign, name, arg, repr) repr |
| 1892 | #endif | 1995 | #endif |
| 1893 | | 1996 | |
| 1894 | #define zig_has_f64 1 | 1997 | #define zig_has_f64 1 |
| ... | @@ -1898,108 +2001,108 @@ typedef zig_i32 zig_f32; | ... | @@ -1898,108 +2001,108 @@ typedef zig_i32 zig_f32; |
| 1898 | #ifdef ZIG_TARGET_ABI_MSVC | 2001 | #ifdef ZIG_TARGET_ABI_MSVC |
| 1899 | #define zig_bitSizeOf_c_longdouble 64 | 2002 | #define zig_bitSizeOf_c_longdouble 64 |
| 1900 | #endif | 2003 | #endif |
| 1901 | #define zig_as_special_constant_f64(sign, name, arg, repr) sign zig_as_f64(zig_msvc_flt_##name, ) | 2004 | #define zig_make_special_constant_f64(sign, name, arg, repr) sign zig_make_f64(zig_msvc_flt_##name, ) |
| 1902 | #else /* _MSC_VER */ | 2005 | #else /* _MSC_VER */ |
| 1903 | #define zig_as_special_constant_f64(sign, name, arg, repr) zig_as_special_f64(sign, name, arg, repr) | 2006 | #define zig_make_special_constant_f64(sign, name, arg, repr) zig_make_special_f64(sign, name, arg, repr) |
| 1904 | #endif /* _MSC_VER */ | 2007 | #endif /* _MSC_VER */ |
| 1905 | #if FLT_MANT_DIG == 53 | 2008 | #if FLT_MANT_DIG == 53 |
| 1906 | typedef float zig_f64; | 2009 | typedef float zig_f64; |
| 1907 | #define zig_as_f64(fp, repr) fp##f | 2010 | #define zig_make_f64(fp, repr) fp##f |
| 1908 | #elif DBL_MANT_DIG == 53 | 2011 | #elif DBL_MANT_DIG == 53 |
| 1909 | typedef double zig_f64; | 2012 | typedef double zig_f64; |
| 1910 | #define zig_as_f64(fp, repr) fp | 2013 | #define zig_make_f64(fp, repr) fp |
| 1911 | #elif LDBL_MANT_DIG == 53 | 2014 | #elif LDBL_MANT_DIG == 53 |
| 1912 | #define zig_bitSizeOf_c_longdouble 64 | 2015 | #define zig_bitSizeOf_c_longdouble 64 |
| 1913 | typedef long double zig_f64; | 2016 | typedef long double zig_f64; |
| 1914 | #define zig_as_f64(fp, repr) fp##l | 2017 | #define zig_make_f64(fp, repr) fp##l |
| 1915 | #elif FLT64_MANT_DIG == 53 | 2018 | #elif FLT64_MANT_DIG == 53 |
| 1916 | typedef _Float64 zig_f64; | 2019 | typedef _Float64 zig_f64; |
| 1917 | #define zig_as_f64(fp, repr) fp##f64 | 2020 | #define zig_make_f64(fp, repr) fp##f64 |
| 1918 | #elif FLT32X_MANT_DIG == 53 | 2021 | #elif FLT32X_MANT_DIG == 53 |
| 1919 | typedef _Float32x zig_f64; | 2022 | typedef _Float32x zig_f64; |
| 1920 | #define zig_as_f64(fp, repr) fp##f32x | 2023 | #define zig_make_f64(fp, repr) fp##f32x |
| 1921 | #else | 2024 | #else |
| 1922 | #undef zig_has_f64 | 2025 | #undef zig_has_f64 |
| 1923 | #define zig_has_f64 0 | 2026 | #define zig_has_f64 0 |
| 1924 | #define zig_repr_f64 i64 | 2027 | #define zig_bitSizeOf_repr_f64 64 |
| 1925 | typedef zig_i64 zig_f64; | 2028 | typedef int64_t zig_f64; |
| 1926 | #define zig_as_f64(fp, repr) repr | 2029 | #define zig_make_f64(fp, repr) repr |
| 1927 | #undef zig_as_special_f64 | 2030 | #undef zig_make_special_f64 |
| 1928 | #define zig_as_special_f64(sign, name, arg, repr) repr | 2031 | #define zig_make_special_f64(sign, name, arg, repr) repr |
| 1929 | #undef zig_as_special_constant_f64 | 2032 | #undef zig_make_special_constant_f64 |
| 1930 | #define zig_as_special_constant_f64(sign, name, arg, repr) repr | 2033 | #define zig_make_special_constant_f64(sign, name, arg, repr) repr |
| 1931 | #endif | 2034 | #endif |
| 1932 | | 2035 | |
| 1933 | #define zig_has_f80 1 | 2036 | #define zig_has_f80 1 |
| 1934 | #define zig_bitSizeOf_f80 80 | 2037 | #define zig_bitSizeOf_f80 80 |
| 1935 | #define zig_libc_name_f80(name) __##name##x | 2038 | #define zig_libc_name_f80(name) __##name##x |
| 1936 | #define zig_as_special_constant_f80(sign, name, arg, repr) zig_as_special_f80(sign, name, arg, repr) | 2039 | #define zig_make_special_constant_f80(sign, name, arg, repr) zig_make_special_f80(sign, name, arg, repr) |
| 1937 | #if FLT_MANT_DIG == 64 | 2040 | #if FLT_MANT_DIG == 64 |
| 1938 | typedef float zig_f80; | 2041 | typedef float zig_f80; |
| 1939 | #define zig_as_f80(fp, repr) fp##f | 2042 | #define zig_make_f80(fp, repr) fp##f |
| 1940 | #elif DBL_MANT_DIG == 64 | 2043 | #elif DBL_MANT_DIG == 64 |
| 1941 | typedef double zig_f80; | 2044 | typedef double zig_f80; |
| 1942 | #define zig_as_f80(fp, repr) fp | 2045 | #define zig_make_f80(fp, repr) fp |
| 1943 | #elif LDBL_MANT_DIG == 64 | 2046 | #elif LDBL_MANT_DIG == 64 |
| 1944 | #define zig_bitSizeOf_c_longdouble 80 | 2047 | #define zig_bitSizeOf_c_longdouble 80 |
| 1945 | typedef long double zig_f80; | 2048 | typedef long double zig_f80; |
| 1946 | #define zig_as_f80(fp, repr) fp##l | 2049 | #define zig_make_f80(fp, repr) fp##l |
| 1947 | #elif FLT80_MANT_DIG == 64 | 2050 | #elif FLT80_MANT_DIG == 64 |
| 1948 | typedef _Float80 zig_f80; | 2051 | typedef _Float80 zig_f80; |
| 1949 | #define zig_as_f80(fp, repr) fp##f80 | 2052 | #define zig_make_f80(fp, repr) fp##f80 |
| 1950 | #elif FLT64X_MANT_DIG == 64 | 2053 | #elif FLT64X_MANT_DIG == 64 |
| 1951 | typedef _Float64x zig_f80; | 2054 | typedef _Float64x zig_f80; |
| 1952 | #define zig_as_f80(fp, repr) fp##f64x | 2055 | #define zig_make_f80(fp, repr) fp##f64x |
| 1953 | #elif defined(__SIZEOF_FLOAT80__) | 2056 | #elif defined(__SIZEOF_FLOAT80__) |
| 1954 | typedef __float80 zig_f80; | 2057 | typedef __float80 zig_f80; |
| 1955 | #define zig_as_f80(fp, repr) fp##l | 2058 | #define zig_make_f80(fp, repr) fp##l |
| 1956 | #else | 2059 | #else |
| 1957 | #undef zig_has_f80 | 2060 | #undef zig_has_f80 |
| 1958 | #define zig_has_f80 0 | 2061 | #define zig_has_f80 0 |
| 1959 | #define zig_repr_f80 i128 | 2062 | #define zig_bitSizeOf_repr_f80 128 |
| 1960 | typedef zig_i128 zig_f80; | 2063 | typedef zig_i128 zig_f80; |
| 1961 | #define zig_as_f80(fp, repr) repr | 2064 | #define zig_make_f80(fp, repr) repr |
| 1962 | #undef zig_as_special_f80 | 2065 | #undef zig_make_special_f80 |
| 1963 | #define zig_as_special_f80(sign, name, arg, repr) repr | 2066 | #define zig_make_special_f80(sign, name, arg, repr) repr |
| 1964 | #undef zig_as_special_constant_f80 | 2067 | #undef zig_make_special_constant_f80 |
| 1965 | #define zig_as_special_constant_f80(sign, name, arg, repr) repr | 2068 | #define zig_make_special_constant_f80(sign, name, arg, repr) repr |
| 1966 | #endif | 2069 | #endif |
| 1967 | | 2070 | |
| 1968 | #define zig_has_f128 1 | 2071 | #define zig_has_f128 1 |
| 1969 | #define zig_bitSizeOf_f128 128 | 2072 | #define zig_bitSizeOf_f128 128 |
| 1970 | #define zig_libc_name_f128(name) name##q | 2073 | #define zig_libc_name_f128(name) name##q |
| 1971 | #define zig_as_special_constant_f128(sign, name, arg, repr) zig_as_special_f128(sign, name, arg, repr) | 2074 | #define zig_make_special_constant_f128(sign, name, arg, repr) zig_make_special_f128(sign, name, arg, repr) |
| 1972 | #if FLT_MANT_DIG == 113 | 2075 | #if FLT_MANT_DIG == 113 |
| 1973 | typedef float zig_f128; | 2076 | typedef float zig_f128; |
| 1974 | #define zig_as_f128(fp, repr) fp##f | 2077 | #define zig_make_f128(fp, repr) fp##f |
| 1975 | #elif DBL_MANT_DIG == 113 | 2078 | #elif DBL_MANT_DIG == 113 |
| 1976 | typedef double zig_f128; | 2079 | typedef double zig_f128; |
| 1977 | #define zig_as_f128(fp, repr) fp | 2080 | #define zig_make_f128(fp, repr) fp |
| 1978 | #elif LDBL_MANT_DIG == 113 | 2081 | #elif LDBL_MANT_DIG == 113 |
| 1979 | #define zig_bitSizeOf_c_longdouble 128 | 2082 | #define zig_bitSizeOf_c_longdouble 128 |
| 1980 | typedef long double zig_f128; | 2083 | typedef long double zig_f128; |
| 1981 | #define zig_as_f128(fp, repr) fp##l | 2084 | #define zig_make_f128(fp, repr) fp##l |
| 1982 | #elif FLT128_MANT_DIG == 113 | 2085 | #elif FLT128_MANT_DIG == 113 |
| 1983 | typedef _Float128 zig_f128; | 2086 | typedef _Float128 zig_f128; |
| 1984 | #define zig_as_f128(fp, repr) fp##f128 | 2087 | #define zig_make_f128(fp, repr) fp##f128 |
| 1985 | #elif FLT64X_MANT_DIG == 113 | 2088 | #elif FLT64X_MANT_DIG == 113 |
| 1986 | typedef _Float64x zig_f128; | 2089 | typedef _Float64x zig_f128; |
| 1987 | #define zig_as_f128(fp, repr) fp##f64x | 2090 | #define zig_make_f128(fp, repr) fp##f64x |
| 1988 | #elif defined(__SIZEOF_FLOAT128__) | 2091 | #elif defined(__SIZEOF_FLOAT128__) |
| 1989 | typedef __float128 zig_f128; | 2092 | typedef __float128 zig_f128; |
| 1990 | #define zig_as_f128(fp, repr) fp##q | 2093 | #define zig_make_f128(fp, repr) fp##q |
| 1991 | #undef zig_as_special_f128 | 2094 | #undef zig_make_special_f128 |
| 1992 | #define zig_as_special_f128(sign, name, arg, repr) sign __builtin_##name##f128(arg) | 2095 | #define zig_make_special_f128(sign, name, arg, repr) sign __builtin_##name##f128(arg) |
| 1993 | #else | 2096 | #else |
| 1994 | #undef zig_has_f128 | 2097 | #undef zig_has_f128 |
| 1995 | #define zig_has_f128 0 | 2098 | #define zig_has_f128 0 |
| 1996 | #define zig_repr_f128 i128 | 2099 | #define zig_bitSizeOf_repr_f128 128 |
| 1997 | typedef zig_i128 zig_f128; | 2100 | typedef zig_i128 zig_f128; |
| 1998 | #define zig_as_f128(fp, repr) repr | 2101 | #define zig_make_f128(fp, repr) repr |
| 1999 | #undef zig_as_special_f128 | 2102 | #undef zig_make_special_f128 |
| 2000 | #define zig_as_special_f128(sign, name, arg, repr) repr | 2103 | #define zig_make_special_f128(sign, name, arg, repr) repr |
| 2001 | #undef zig_as_special_constant_f128 | 2104 | #undef zig_make_special_constant_f128 |
| 2002 | #define zig_as_special_constant_f128(sign, name, arg, repr) repr | 2105 | #define zig_make_special_constant_f128(sign, name, arg, repr) repr |
| 2003 | #endif | 2106 | #endif |
| 2004 | | 2107 | |
| 2005 | #define zig_has_c_longdouble 1 | 2108 | #define zig_has_c_longdouble 1 |
| ... | @@ -2010,17 +2113,17 @@ typedef zig_i128 zig_f128; | ... | @@ -2010,17 +2113,17 @@ typedef zig_i128 zig_f128; |
| 2010 | #define zig_libc_name_c_longdouble(name) name##l | 2113 | #define zig_libc_name_c_longdouble(name) name##l |
| 2011 | #endif | 2114 | #endif |
| 2012 | | 2115 | |
| 2013 | #define zig_as_special_constant_c_longdouble(sign, name, arg, repr) zig_as_special_c_longdouble(sign, name, arg, repr) | 2116 | #define zig_make_special_constant_c_longdouble(sign, name, arg, repr) zig_make_special_c_longdouble(sign, name, arg, repr) |
| 2014 | #ifdef zig_bitSizeOf_c_longdouble | 2117 | #ifdef zig_bitSizeOf_c_longdouble |
| 2015 | | 2118 | |
| 2016 | #ifdef ZIG_TARGET_ABI_MSVC | 2119 | #ifdef ZIG_TARGET_ABI_MSVC |
| 2017 | typedef double zig_c_longdouble; | 2120 | typedef double zig_c_longdouble; |
| 2018 | #undef zig_bitSizeOf_c_longdouble | 2121 | #undef zig_bitSizeOf_c_longdouble |
| 2019 | #define zig_bitSizeOf_c_longdouble 64 | 2122 | #define zig_bitSizeOf_c_longdouble 64 |
| 2020 | #define zig_as_c_longdouble(fp, repr) fp | 2123 | #define zig_make_c_longdouble(fp, repr) fp |
| 2021 | #else | 2124 | #else |
| 2022 | typedef long double zig_c_longdouble; | 2125 | typedef long double zig_c_longdouble; |
| 2023 | #define zig_as_c_longdouble(fp, repr) fp##l | 2126 | #define zig_make_c_longdouble(fp, repr) fp##l |
| 2024 | #endif | 2127 | #endif |
| 2025 | | 2128 | |
| 2026 | #else /* zig_bitSizeOf_c_longdouble */ | 2129 | #else /* zig_bitSizeOf_c_longdouble */ |
| ... | @@ -2029,13 +2132,13 @@ typedef long double zig_c_longdouble; | ... | @@ -2029,13 +2132,13 @@ typedef long double zig_c_longdouble; |
| 2029 | #define zig_has_c_longdouble 0 | 2132 | #define zig_has_c_longdouble 0 |
| 2030 | #define zig_bitSizeOf_c_longdouble 80 | 2133 | #define zig_bitSizeOf_c_longdouble 80 |
| 2031 | #define zig_compiler_rt_abbrev_c_longdouble zig_compiler_rt_abbrev_f80 | 2134 | #define zig_compiler_rt_abbrev_c_longdouble zig_compiler_rt_abbrev_f80 |
| 2032 | #define zig_repr_c_longdouble i128 | 2135 | #define zig_bitSizeOf_repr_c_longdouble 128 |
| 2033 | typedef zig_i128 zig_c_longdouble; | 2136 | typedef zig_i128 zig_c_longdouble; |
| 2034 | #define zig_as_c_longdouble(fp, repr) repr | 2137 | #define zig_make_c_longdouble(fp, repr) repr |
| 2035 | #undef zig_as_special_c_longdouble | 2138 | #undef zig_make_special_c_longdouble |
| 2036 | #define zig_as_special_c_longdouble(sign, name, arg, repr) repr | 2139 | #define zig_make_special_c_longdouble(sign, name, arg, repr) repr |
| 2037 | #undef zig_as_special_constant_c_longdouble | 2140 | #undef zig_make_special_constant_c_longdouble |
| 2038 | #define zig_as_special_constant_c_longdouble(sign, name, arg, repr) repr | 2141 | #define zig_make_special_constant_c_longdouble(sign, name, arg, repr) repr |
| 2039 | | 2142 | |
| 2040 | #endif /* zig_bitSizeOf_c_longdouble */ | 2143 | #endif /* zig_bitSizeOf_c_longdouble */ |
| 2041 | | 2144 | |
| ... | @@ -2073,32 +2176,35 @@ zig_expand_float_from_repr(c_longdouble, zig_expand_concat(u, zig_bitSizeOf_c_lo | ... | @@ -2073,32 +2176,35 @@ zig_expand_float_from_repr(c_longdouble, zig_expand_concat(u, zig_bitSizeOf_c_lo |
| 2073 | #endif | 2176 | #endif |
| 2074 | | 2177 | |
| 2075 | #define zig_convert_builtin(ResType, operation, ArgType, version) \ | 2178 | #define zig_convert_builtin(ResType, operation, ArgType, version) \ |
| 2076 | zig_extern zig_##ResType zig_expand_concat(zig_expand_concat(zig_expand_concat(__##operation, \ | 2179 | zig_extern ResType zig_expand_concat(zig_expand_concat(zig_expand_concat(__##operation, \ |
| 2077 | zig_compiler_rt_abbrev_##ArgType), zig_compiler_rt_abbrev_##ResType), version)(zig_##ArgType); | 2180 | zig_compiler_rt_abbrev_##ArgType), zig_compiler_rt_abbrev_##ResType), version)(ArgType); |
| 2078 | zig_convert_builtin(f16, trunc, f32, 2) | 2181 | zig_convert_builtin(zig_f16, trunc, zig_f32, 2) |
| 2079 | zig_convert_builtin(f16, trunc, f64, 2) | 2182 | zig_convert_builtin(zig_f16, trunc, zig_f64, 2) |
| 2080 | zig_convert_builtin(f16, trunc, f80, 2) | 2183 | zig_convert_builtin(zig_f16, trunc, zig_f80, 2) |
| 2081 | zig_convert_builtin(f16, trunc, f128, 2) | 2184 | zig_convert_builtin(zig_f16, trunc, zig_f128, 2) |
| 2082 | zig_convert_builtin(f32, extend, f16, 2) | 2185 | zig_convert_builtin(zig_f32, extend, zig_f16, 2) |
| 2083 | zig_convert_builtin(f32, trunc, f64, 2) | 2186 | zig_convert_builtin(zig_f32, trunc, zig_f64, 2) |
| 2084 | zig_convert_builtin(f32, trunc, f80, 2) | 2187 | zig_convert_builtin(zig_f32, trunc, zig_f80, 2) |
| 2085 | zig_convert_builtin(f32, trunc, f128, 2) | 2188 | zig_convert_builtin(zig_f32, trunc, zig_f128, 2) |
| 2086 | zig_convert_builtin(f64, extend, f16, 2) | 2189 | zig_convert_builtin(zig_f64, extend, zig_f16, 2) |
| 2087 | zig_convert_builtin(f64, extend, f32, 2) | 2190 | zig_convert_builtin(zig_f64, extend, zig_f32, 2) |
| 2088 | zig_convert_builtin(f64, trunc, f80, 2) | 2191 | zig_convert_builtin(zig_f64, trunc, zig_f80, 2) |
| 2089 | zig_convert_builtin(f64, trunc, f128, 2) | 2192 | zig_convert_builtin(zig_f64, trunc, zig_f128, 2) |
| 2090 | zig_convert_builtin(f80, extend, f16, 2) | 2193 | zig_convert_builtin(zig_f80, extend, zig_f16, 2) |
| 2091 | zig_convert_builtin(f80, extend, f32, 2) | 2194 | zig_convert_builtin(zig_f80, extend, zig_f32, 2) |
| 2092 | zig_convert_builtin(f80, extend, f64, 2) | 2195 | zig_convert_builtin(zig_f80, extend, zig_f64, 2) |
| 2093 | zig_convert_builtin(f80, trunc, f128, 2) | 2196 | zig_convert_builtin(zig_f80, trunc, zig_f128, 2) |
| 2094 | zig_convert_builtin(f128, extend, f16, 2) | 2197 | zig_convert_builtin(zig_f128, extend, zig_f16, 2) |
| 2095 | zig_convert_builtin(f128, extend, f32, 2) | 2198 | zig_convert_builtin(zig_f128, extend, zig_f32, 2) |
| 2096 | zig_convert_builtin(f128, extend, f64, 2) | 2199 | zig_convert_builtin(zig_f128, extend, zig_f64, 2) |
| 2097 | zig_convert_builtin(f128, extend, f80, 2) | 2200 | zig_convert_builtin(zig_f128, extend, zig_f80, 2) |
| 2098 | | 2201 | |
| 2099 | #define zig_float_negate_builtin_0(Type) \ | 2202 | #define zig_float_negate_builtin_0(Type) \ |
| 2100 | static inline zig_##Type zig_neg_##Type(zig_##Type arg) { \ | 2203 | static inline zig_##Type zig_neg_##Type(zig_##Type arg) { \ |
| 2101 | return zig_expand_concat(zig_xor_, zig_repr_##Type)(arg, zig_expand_minInt(zig_repr_##Type, zig_bitSizeOf_##Type)); \ | 2204 | return zig_expand_concat(zig_xor_i, zig_bitSizeOf_repr_##Type)( \ |
| | 2205 | arg, \ |
| | 2206 | zig_minInt_i(zig_bitSizeOf_repr_##Type, zig_bitSizeOf_##Type) \ |
| | 2207 | ); \ |
| 2102 | } | 2208 | } |
| 2103 | #define zig_float_negate_builtin_1(Type) \ | 2209 | #define zig_float_negate_builtin_1(Type) \ |
| 2104 | static inline zig_##Type zig_neg_##Type(zig_##Type arg) { \ | 2210 | static inline zig_##Type zig_neg_##Type(zig_##Type arg) { \ |
| ... | @@ -2106,28 +2212,28 @@ zig_convert_builtin(f128, extend, f80, 2) | ... | @@ -2106,28 +2212,28 @@ zig_convert_builtin(f128, extend, f80, 2) |
| 2106 | } | 2212 | } |
| 2107 | | 2213 | |
| 2108 | #define zig_float_less_builtin_0(Type, operation) \ | 2214 | #define zig_float_less_builtin_0(Type, operation) \ |
| 2109 | zig_extern zig_i32 zig_expand_concat(zig_expand_concat(__##operation, \ | 2215 | zig_extern int32_t zig_expand_concat(zig_expand_concat(__##operation, \ |
| 2110 | zig_compiler_rt_abbrev_##Type), 2)(zig_##Type, zig_##Type); \ | 2216 | zig_compiler_rt_abbrev_zig_##Type), 2)(zig_##Type, zig_##Type); \ |
| 2111 | static inline zig_i32 zig_##operation##_##Type(zig_##Type lhs, zig_##Type rhs) { \ | 2217 | static inline int32_t zig_##operation##_##Type(zig_##Type lhs, zig_##Type rhs) { \ |
| 2112 | return zig_expand_concat(zig_expand_concat(__##operation, zig_compiler_rt_abbrev_##Type), 2)(lhs, rhs); \ | 2218 | return zig_expand_concat(zig_expand_concat(__##operation, zig_compiler_rt_abbrev_zig_##Type), 2)(lhs, rhs); \ |
| 2113 | } | 2219 | } |
| 2114 | #define zig_float_less_builtin_1(Type, operation) \ | 2220 | #define zig_float_less_builtin_1(Type, operation) \ |
| 2115 | static inline zig_i32 zig_##operation##_##Type(zig_##Type lhs, zig_##Type rhs) { \ | 2221 | static inline int32_t zig_##operation##_##Type(zig_##Type lhs, zig_##Type rhs) { \ |
| 2116 | return (!(lhs <= rhs) - (lhs < rhs)); \ | 2222 | return (!(lhs <= rhs) - (lhs < rhs)); \ |
| 2117 | } | 2223 | } |
| 2118 | | 2224 | |
| 2119 | #define zig_float_greater_builtin_0(Type, operation) \ | 2225 | #define zig_float_greater_builtin_0(Type, operation) \ |
| 2120 | zig_float_less_builtin_0(Type, operation) | 2226 | zig_float_less_builtin_0(Type, operation) |
| 2121 | #define zig_float_greater_builtin_1(Type, operation) \ | 2227 | #define zig_float_greater_builtin_1(Type, operation) \ |
| 2122 | static inline zig_i32 zig_##operation##_##Type(zig_##Type lhs, zig_##Type rhs) { \ | 2228 | static inline int32_t zig_##operation##_##Type(zig_##Type lhs, zig_##Type rhs) { \ |
| 2123 | return ((lhs > rhs) - !(lhs >= rhs)); \ | 2229 | return ((lhs > rhs) - !(lhs >= rhs)); \ |
| 2124 | } | 2230 | } |
| 2125 | | 2231 | |
| 2126 | #define zig_float_binary_builtin_0(Type, operation, operator) \ | 2232 | #define zig_float_binary_builtin_0(Type, operation, operator) \ |
| 2127 | zig_extern zig_##Type zig_expand_concat(zig_expand_concat(__##operation, \ | 2233 | zig_extern zig_##Type zig_expand_concat(zig_expand_concat(__##operation, \ |
| 2128 | zig_compiler_rt_abbrev_##Type), 3)(zig_##Type, zig_##Type); \ | 2234 | zig_compiler_rt_abbrev_zig_##Type), 3)(zig_##Type, zig_##Type); \ |
| 2129 | static inline zig_##Type zig_##operation##_##Type(zig_##Type lhs, zig_##Type rhs) { \ | 2235 | static inline zig_##Type zig_##operation##_##Type(zig_##Type lhs, zig_##Type rhs) { \ |
| 2130 | return zig_expand_concat(zig_expand_concat(__##operation, zig_compiler_rt_abbrev_##Type), 3)(lhs, rhs); \ | 2236 | return zig_expand_concat(zig_expand_concat(__##operation, zig_compiler_rt_abbrev_zig_##Type), 3)(lhs, rhs); \ |
| 2131 | } | 2237 | } |
| 2132 | #define zig_float_binary_builtin_1(Type, operation, operator) \ | 2238 | #define zig_float_binary_builtin_1(Type, operation, operator) \ |
| 2133 | static inline zig_##Type zig_##operation##_##Type(zig_##Type lhs, zig_##Type rhs) { \ | 2239 | static inline zig_##Type zig_##operation##_##Type(zig_##Type lhs, zig_##Type rhs) { \ |
| ... | @@ -2135,18 +2241,18 @@ zig_convert_builtin(f128, extend, f80, 2) | ... | @@ -2135,18 +2241,18 @@ zig_convert_builtin(f128, extend, f80, 2) |
| 2135 | } | 2241 | } |
| 2136 | | 2242 | |
| 2137 | #define zig_float_builtins(Type) \ | 2243 | #define zig_float_builtins(Type) \ |
| 2138 | zig_convert_builtin(i32, fix, Type, ) \ | 2244 | zig_convert_builtin( int32_t, fix, zig_##Type, ) \ |
| 2139 | zig_convert_builtin(u32, fixuns, Type, ) \ | 2245 | zig_convert_builtin(uint32_t, fixuns, zig_##Type, ) \ |
| 2140 | zig_convert_builtin(i64, fix, Type, ) \ | 2246 | zig_convert_builtin( int64_t, fix, zig_##Type, ) \ |
| 2141 | zig_convert_builtin(u64, fixuns, Type, ) \ | 2247 | zig_convert_builtin(uint64_t, fixuns, zig_##Type, ) \ |
| 2142 | zig_convert_builtin(i128, fix, Type, ) \ | 2248 | zig_convert_builtin(zig_i128, fix, zig_##Type, ) \ |
| 2143 | zig_convert_builtin(u128, fixuns, Type, ) \ | 2249 | zig_convert_builtin(zig_u128, fixuns, zig_##Type, ) \ |
| 2144 | zig_convert_builtin(Type, float, i32, ) \ | 2250 | zig_convert_builtin(zig_##Type, float, int32_t, ) \ |
| 2145 | zig_convert_builtin(Type, floatun, u32, ) \ | 2251 | zig_convert_builtin(zig_##Type, floatun, uint32_t, ) \ |
| 2146 | zig_convert_builtin(Type, float, i64, ) \ | 2252 | zig_convert_builtin(zig_##Type, float, int64_t, ) \ |
| 2147 | zig_convert_builtin(Type, floatun, u64, ) \ | 2253 | zig_convert_builtin(zig_##Type, floatun, uint64_t, ) \ |
| 2148 | zig_convert_builtin(Type, float, i128, ) \ | 2254 | zig_convert_builtin(zig_##Type, float, zig_i128, ) \ |
| 2149 | zig_convert_builtin(Type, floatun, u128, ) \ | 2255 | zig_convert_builtin(zig_##Type, floatun, zig_u128, ) \ |
| 2150 | zig_expand_concat(zig_float_negate_builtin_, zig_has_##Type)(Type) \ | 2256 | zig_expand_concat(zig_float_negate_builtin_, zig_has_##Type)(Type) \ |
| 2151 | zig_expand_concat(zig_float_less_builtin_, zig_has_##Type)(Type, cmp) \ | 2257 | zig_expand_concat(zig_float_less_builtin_, zig_has_##Type)(Type, cmp) \ |
| 2152 | zig_expand_concat(zig_float_less_builtin_, zig_has_##Type)(Type, ne) \ | 2258 | zig_expand_concat(zig_float_less_builtin_, zig_has_##Type)(Type, ne) \ |
| ... | @@ -2332,17 +2438,17 @@ zig_msvc_flt_atomics(f64, u64, 64) | ... | @@ -2332,17 +2438,17 @@ zig_msvc_flt_atomics(f64, u64, 64) |
| 2332 | | 2438 | |
| 2333 | #if _M_IX86 | 2439 | #if _M_IX86 |
| 2334 | static inline void zig_msvc_atomic_barrier() { | 2440 | static inline void zig_msvc_atomic_barrier() { |
| 2335 | zig_i32 barrier; | 2441 | int32_t barrier; |
| 2336 | __asm { | 2442 | __asm { |
| 2337 | xchg barrier, eax | 2443 | xchg barrier, eax |
| 2338 | } | 2444 | } |
| 2339 | } | 2445 | } |
| 2340 | | 2446 | |
| 2341 | static inline void* zig_msvc_atomicrmw_xchg_p32(void** obj, zig_u32* arg) { | 2447 | static inline void* zig_msvc_atomicrmw_xchg_p32(void** obj, uint32_t* arg) { |
| 2342 | return _InterlockedExchangePointer(obj, arg); | 2448 | return _InterlockedExchangePointer(obj, arg); |
| 2343 | } | 2449 | } |
| 2344 | | 2450 | |
| 2345 | static inline void zig_msvc_atomic_store_p32(void** obj, zig_u32* arg) { | 2451 | static inline void zig_msvc_atomic_store_p32(void** obj, uint32_t* arg) { |
| 2346 | _InterlockedExchangePointer(obj, arg); | 2452 | _InterlockedExchangePointer(obj, arg); |
| 2347 | } | 2453 | } |
| 2348 | | 2454 | |
| ... | @@ -2360,11 +2466,11 @@ static inline bool zig_msvc_cmpxchg_p32(void** obj, void** expected, void* desir | ... | @@ -2360,11 +2466,11 @@ static inline bool zig_msvc_cmpxchg_p32(void** obj, void** expected, void* desir |
| 2360 | return exchanged; | 2466 | return exchanged; |
| 2361 | } | 2467 | } |
| 2362 | #else /* _M_IX86 */ | 2468 | #else /* _M_IX86 */ |
| 2363 | static inline void* zig_msvc_atomicrmw_xchg_p64(void** obj, zig_u64* arg) { | 2469 | static inline void* zig_msvc_atomicrmw_xchg_p64(void** obj, uint64_t* arg) { |
| 2364 | return _InterlockedExchangePointer(obj, arg); | 2470 | return _InterlockedExchangePointer(obj, arg); |
| 2365 | } | 2471 | } |
| 2366 | | 2472 | |
| 2367 | static inline void zig_msvc_atomic_store_p64(void** obj, zig_u64* arg) { | 2473 | static inline void zig_msvc_atomic_store_p64(void** obj, uint64_t* arg) { |
| 2368 | _InterlockedExchangePointer(obj, arg); | 2474 | _InterlockedExchangePointer(obj, arg); |
| 2369 | } | 2475 | } |
| 2370 | | 2476 | |
| ... | @@ -2383,11 +2489,11 @@ static inline bool zig_msvc_cmpxchg_p64(void** obj, void** expected, void* desir | ... | @@ -2383,11 +2489,11 @@ static inline bool zig_msvc_cmpxchg_p64(void** obj, void** expected, void* desir |
| 2383 | } | 2489 | } |
| 2384 | | 2490 | |
| 2385 | static inline bool zig_msvc_cmpxchg_u128(zig_u128 volatile* obj, zig_u128* expected, zig_u128 desired) { | 2491 | static inline bool zig_msvc_cmpxchg_u128(zig_u128 volatile* obj, zig_u128* expected, zig_u128 desired) { |
| 2386 | return _InterlockedCompareExchange128((zig_i64 volatile*)obj, desired.hi, desired.lo, (zig_i64*)expected); | 2492 | return _InterlockedCompareExchange128((int64_t volatile*)obj, desired.hi, desired.lo, (int64_t*)expected); |
| 2387 | } | 2493 | } |
| 2388 | | 2494 | |
| 2389 | static inline bool zig_msvc_cmpxchg_i128(zig_i128 volatile* obj, zig_i128* expected, zig_i128 desired) { | 2495 | static inline bool zig_msvc_cmpxchg_i128(zig_i128 volatile* obj, zig_i128* expected, zig_i128 desired) { |
| 2390 | return _InterlockedCompareExchange128((zig_i64 volatile*)obj, desired.hi, desired.lo, (zig_u64*)expected); | 2496 | return _InterlockedCompareExchange128((int64_t volatile*)obj, desired.hi, desired.lo, (uint64_t*)expected); |
| 2391 | } | 2497 | } |
| 2392 | | 2498 | |
| 2393 | #define zig_msvc_atomics_128xchg(Type) \ | 2499 | #define zig_msvc_atomics_128xchg(Type) \ |
| ... | @@ -2429,7 +2535,7 @@ zig_msvc_atomics_128op(u128, max) | ... | @@ -2429,7 +2535,7 @@ zig_msvc_atomics_128op(u128, max) |
| 2429 | | 2535 | |
| 2430 | #endif /* _MSC_VER && (_M_IX86 || _M_X64) */ | 2536 | #endif /* _MSC_VER && (_M_IX86 || _M_X64) */ |
| 2431 | | 2537 | |
| 2432 | /* ========================= Special Case Intrinsics ========================= */ | 2538 | /* ======================== Special Case Intrinsics ========================= */ |
| 2433 | | 2539 | |
| 2434 | #if (_MSC_VER && _M_X64) || defined(__x86_64__) | 2540 | #if (_MSC_VER && _M_X64) || defined(__x86_64__) |
| 2435 | | 2541 | |
| ... | @@ -2459,8 +2565,8 @@ static inline void* zig_x86_windows_teb(void) { | ... | @@ -2459,8 +2565,8 @@ static inline void* zig_x86_windows_teb(void) { |
| 2459 | | 2565 | |
| 2460 | #if (_MSC_VER && (_M_IX86 || _M_X64)) || defined(__i386__) || defined(__x86_64__) | 2566 | #if (_MSC_VER && (_M_IX86 || _M_X64)) || defined(__i386__) || defined(__x86_64__) |
| 2461 | | 2567 | |
| 2462 | static inline void zig_x86_cpuid(zig_u32 leaf_id, zig_u32 subid, zig_u32* eax, zig_u32* ebx, zig_u32* ecx, zig_u32* edx) { | 2568 | static inline void zig_x86_cpuid(uint32_t leaf_id, uint32_t subid, uint32_t* eax, uint32_t* ebx, uint32_t* ecx, uint32_t* edx) { |
| 2463 | zig_u32 cpu_info[4]; | 2569 | uint32_t cpu_info[4]; |
| 2464 | #if _MSC_VER | 2570 | #if _MSC_VER |
| 2465 | __cpuidex(cpu_info, leaf_id, subid); | 2571 | __cpuidex(cpu_info, leaf_id, subid); |
| 2466 | #else | 2572 | #else |
| ... | @@ -2472,12 +2578,12 @@ static inline void zig_x86_cpuid(zig_u32 leaf_id, zig_u32 subid, zig_u32* eax, z | ... | @@ -2472,12 +2578,12 @@ static inline void zig_x86_cpuid(zig_u32 leaf_id, zig_u32 subid, zig_u32* eax, z |
| 2472 | *edx = cpu_info[3]; | 2578 | *edx = cpu_info[3]; |
| 2473 | } | 2579 | } |
| 2474 | | 2580 | |
| 2475 | static inline zig_u32 zig_x86_get_xcr0(void) { | 2581 | static inline uint32_t zig_x86_get_xcr0(void) { |
| 2476 | #if _MSC_VER | 2582 | #if _MSC_VER |
| 2477 | return (zig_u32)_xgetbv(0); | 2583 | return (uint32_t)_xgetbv(0); |
| 2478 | #else | 2584 | #else |
| 2479 | zig_u32 eax; | 2585 | uint32_t eax; |
| 2480 | zig_u32 edx; | 2586 | uint32_t edx; |
| 2481 | __asm__("xgetbv" : "=a"(eax), "=d"(edx) : "c"(0)); | 2587 | __asm__("xgetbv" : "=a"(eax), "=d"(edx) : "c"(0)); |
| 2482 | return eax; | 2588 | return eax; |
| 2483 | #endif | 2589 | #endif |