authorgravatar for myclevorname@gmail.comSam Connelly <myclevorname@gmail.com> 2026-03-12 09:04:39-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-04-16 19:21:16+02:00
log17e0afd0e5d8850171bdfeba9456ebfd38d11e3a
treeb07bd9d85134bc610c35621dea2d6a5d4a1ab36d
parentd092c752f3e2e0e162e9bab57d3f84de6ccde7c9

feat: init eZ80 arch via CBE


10 files changed, 465 insertions(+), 7 deletions(-)

lib/compiler/translate-c/Translator.zig+4
...@@ -475,8 +475,12 @@ pub const builtin_typedef_map = std.StaticStringMap([]const u8).initComptime(.{...@@ -475,8 +475,12 @@ pub const builtin_typedef_map = std.StaticStringMap([]const u8).initComptime(.{
475 .{ "int8_t", "i8" },475 .{ "int8_t", "i8" },
476 .{ "uint16_t", "u16" },476 .{ "uint16_t", "u16" },
477 .{ "int16_t", "i16" },477 .{ "int16_t", "i16" },
478 .{ "uint24_t", "u24" },
479 .{ "int24_t", "i24" },
478 .{ "uint32_t", "u32" },480 .{ "uint32_t", "u32" },
479 .{ "int32_t", "i32" },481 .{ "int32_t", "i32" },
482 .{ "uint48_t", "u48" },
483 .{ "int48_t", "i48" },
480 .{ "uint64_t", "u64" },484 .{ "uint64_t", "u64" },
481 .{ "int64_t", "i64" },485 .{ "int64_t", "i64" },
482 .{ "intptr_t", "isize" },486 .{ "intptr_t", "isize" },
lib/std/Target.zig+50-3
...@@ -68,6 +68,8 @@ pub const Os = struct {...@@ -68,6 +68,8 @@ pub const Os = struct {
68 opengl,68 opengl,
69 vulkan,69 vulkan,
7070
71 tios,
72
71 // LLVM tags deliberately omitted:73 // LLVM tags deliberately omitted:
72 // - bridgeos74 // - bridgeos
73 // - cheriotrtos75 // - cheriotrtos
...@@ -207,6 +209,8 @@ pub const Os = struct {...@@ -207,6 +209,8 @@ pub const Os = struct {
207 .opencl,209 .opencl,
208 .opengl,210 .opengl,
209 .vulkan,211 .vulkan,
212
213 .tios,
210 => .semver,214 => .semver,
211215
212 .hurd => .hurd,216 .hurd => .hurd,
...@@ -670,6 +674,12 @@ pub const Os = struct {...@@ -670,6 +674,12 @@ pub const Os = struct {
670 .max = .{ .major = 4, .minor = 6, .patch = 0 },674 .max = .{ .major = 4, .minor = 6, .patch = 0 },
671 },675 },
672 },676 },
677 .tios => .{
678 .semver = .{
679 .min = .{ .major = 5, .minor = 0, .patch = 0 },
680 .max = .{ .major = 5, .minor = 8, .patch = 4 },
681 },
682 },
673 .vulkan => .{683 .vulkan => .{
674 .semver = .{684 .semver = .{
675 .min = .{ .major = 1, .minor = 2, .patch = 0 },685 .min = .{ .major = 1, .minor = 2, .patch = 0 },
...@@ -758,6 +768,7 @@ pub const wasm = @import("Target/wasm.zig");...@@ -758,6 +768,7 @@ pub const wasm = @import("Target/wasm.zig");
758pub const x86 = @import("Target/x86.zig");768pub const x86 = @import("Target/x86.zig");
759pub const xcore = @import("Target/xcore.zig");769pub const xcore = @import("Target/xcore.zig");
760pub const xtensa = @import("Target/xtensa.zig");770pub const xtensa = @import("Target/xtensa.zig");
771pub const z80 = @import("Target/generic.zig");
761772
762pub const Abi = enum {773pub const Abi = enum {
763 none,774 none,
...@@ -942,6 +953,7 @@ pub const Abi = enum {...@@ -942,6 +953,7 @@ pub const Abi = enum {
942 .opencl,953 .opencl,
943 .opengl,954 .opengl,
944 .vulkan,955 .vulkan,
956 .tios,
945 => .none,957 => .none,
946 };958 };
947 }959 }
...@@ -1068,6 +1080,7 @@ pub fn toElfMachine(target: *const Target) std.elf.EM {...@@ -1068,6 +1080,7 @@ pub fn toElfMachine(target: *const Target) std.elf.EM {
1068 .avr => .AVR,1080 .avr => .AVR,
1069 .bpfeb, .bpfel => .BPF,1081 .bpfeb, .bpfel => .BPF,
1070 .csky => .CSKY,1082 .csky => .CSKY,
1083 .ez80 => .Z80,
1071 .hexagon => .QDSP6,1084 .hexagon => .QDSP6,
1072 .hppa, .hppa64 => .PARISC,1085 .hppa, .hppa64 => .PARISC,
1073 .kalimba => .CSR_KALIMBA,1086 .kalimba => .CSR_KALIMBA,
...@@ -1130,6 +1143,7 @@ pub fn toCoffMachine(target: *const Target) std.coff.IMAGE.FILE.MACHINE {...@@ -1130,6 +1143,7 @@ pub fn toCoffMachine(target: *const Target) std.coff.IMAGE.FILE.MACHINE {
1130 .bpfeb,1143 .bpfeb,
1131 .bpfel,1144 .bpfel,
1132 .csky,1145 .csky,
1146 .ez80,
1133 .hexagon,1147 .hexagon,
1134 .hppa,1148 .hppa,
1135 .hppa64,1149 .hppa64,
...@@ -1336,6 +1350,7 @@ pub const Cpu = struct {...@@ -1336,6 +1350,7 @@ pub const Cpu = struct {
1336 bpfeb,1350 bpfeb,
1337 bpfel,1351 bpfel,
1338 csky,1352 csky,
1353 ez80,
1339 hexagon,1354 hexagon,
1340 hppa,1355 hppa,
1341 hppa64,1356 hppa64,
...@@ -1437,6 +1452,7 @@ pub const Cpu = struct {...@@ -1437,6 +1452,7 @@ pub const Cpu = struct {
1437 x86,1452 x86,
1438 xcore,1453 xcore,
1439 xtensa,1454 xtensa,
1455 z80,
1440 };1456 };
14411457
1442 pub inline fn family(arch: Arch) Family {1458 pub inline fn family(arch: Arch) Family {
...@@ -1449,6 +1465,7 @@ pub const Cpu = struct {...@@ -1449,6 +1465,7 @@ pub const Cpu = struct {
1449 .avr => .avr,1465 .avr => .avr,
1450 .bpfeb, .bpfel => .bpf,1466 .bpfeb, .bpfel => .bpf,
1451 .csky => .csky,1467 .csky => .csky,
1468 .ez80 => .z80,
1452 .hexagon => .hexagon,1469 .hexagon => .hexagon,
1453 .hppa, .hppa64 => .hppa,1470 .hppa, .hppa64 => .hppa,
1454 .kalimba => .kalimba,1471 .kalimba => .kalimba,
...@@ -1678,6 +1695,7 @@ pub const Cpu = struct {...@@ -1678,6 +1695,7 @@ pub const Cpu = struct {
1678 .x86_64,1695 .x86_64,
1679 .xcore,1696 .xcore,
1680 .xtensa,1697 .xtensa,
1698 .ez80,
1681 => .little,1699 => .little,
16821700
1683 .aarch64_be,1701 .aarch64_be,
...@@ -1948,6 +1966,10 @@ pub const Cpu = struct {...@@ -1948,6 +1966,10 @@ pub const Cpu = struct {
1948 .spirv_fragment,1966 .spirv_fragment,
1949 .spirv_vertex,1967 .spirv_vertex,
1950 => &.{ .spirv32, .spirv64 },1968 => &.{ .spirv32, .spirv64 },
1969
1970 .ez80_cet,
1971 .ez80_tiflags,
1972 => &.{.ez80},
1951 };1973 };
1952 }1974 }
1953 };1975 };
...@@ -2236,6 +2258,7 @@ pub fn requiresLibC(target: *const Target) bool {...@@ -2236,6 +2258,7 @@ pub fn requiresLibC(target: *const Target) bool {
2236 .plan9,2258 .plan9,
2237 .other,2259 .other,
2238 .@"3ds",2260 .@"3ds",
2261 .tios,
2239 => false,2262 => false,
2240 };2263 };
2241}2264}
...@@ -2398,6 +2421,8 @@ pub const DynamicLinker = struct {...@@ -2398,6 +2421,8 @@ pub const DynamicLinker = struct {
2398 .ps5,2421 .ps5,
2399 .psp,2422 .psp,
2400 .vita,2423 .vita,
2424
2425 .tios,
2401 => .none,2426 => .none,
2402 };2427 };
2403 }2428 }
...@@ -2815,6 +2840,8 @@ pub const DynamicLinker = struct {...@@ -2815,6 +2840,8 @@ pub const DynamicLinker = struct {
2815 .opencl,2840 .opencl,
2816 .opengl,2841 .opengl,
2817 .vulkan,2842 .vulkan,
2843
2844 .tios,
2818 => none,2845 => none,
28192846
2820 // TODO go over each item in this list and either move it to the above list, or2847 // TODO go over each item in this list and either move it to the above list, or
...@@ -2849,6 +2876,9 @@ pub fn ptrBitWidth_arch_abi(cpu_arch: Cpu.Arch, abi: Abi) u16 {...@@ -2849,6 +2876,9 @@ pub fn ptrBitWidth_arch_abi(cpu_arch: Cpu.Arch, abi: Abi) u16 {
2849 .x86_16,2876 .x86_16,
2850 => 16,2877 => 16,
28512878
2879 .ez80,
2880 => 24,
2881
2852 .arc,2882 .arc,
2853 .arceb,2883 .arceb,
2854 .arm,2884 .arm,
...@@ -2917,6 +2947,8 @@ pub fn ptrBitWidth(target: *const Target) u16 {...@@ -2917,6 +2947,8 @@ pub fn ptrBitWidth(target: *const Target) u16 {
2917pub fn stackAlignment(target: *const Target) u16 {2947pub fn stackAlignment(target: *const Target) u16 {
2918 // Overrides for when the stack alignment is not equal to the pointer width.2948 // Overrides for when the stack alignment is not equal to the pointer width.
2919 switch (target.cpu.arch) {2949 switch (target.cpu.arch) {
2950 .ez80,
2951 => return 1,
2920 .m68k,2952 .m68k,
2921 => return 2,2953 => return 2,
2922 .amdgcn,2954 .amdgcn,
...@@ -2997,6 +3029,7 @@ pub fn cCharSignedness(target: *const Target) std.builtin.Signedness {...@@ -2997,6 +3029,7 @@ pub fn cCharSignedness(target: *const Target) std.builtin.Signedness {
2997 .arc,3029 .arc,
2998 .arceb,3030 .arceb,
2999 .csky,3031 .csky,
3032 .ez80,
3000 .hexagon,3033 .hexagon,
3001 .msp430,3034 .msp430,
3002 .powerpc,3035 .powerpc,
...@@ -3364,6 +3397,13 @@ pub fn cTypeBitSize(target: *const Target, c_type: CType) u16 {...@@ -3364,6 +3397,13 @@ pub fn cTypeBitSize(target: *const Target, c_type: CType) u16 {
3364 .long, .ulong => return 64,3397 .long, .ulong => return 64,
3365 .longlong, .ulonglong, .double, .longdouble => return 64,3398 .longlong, .ulonglong, .double, .longdouble => return 64,
3366 },3399 },
3400 .tios => switch (c_type) {
3401 .char => return 8,
3402 .short, .ushort => return 16,
3403 .int, .uint => return 24,
3404 .long, .ulong, .float, .double => return 32,
3405 .longlong, .ulonglong, .longdouble => return 64,
3406 },
33673407
3368 .ps3,3408 .ps3,
3369 .contiki,3409 .contiki,
...@@ -3376,7 +3416,7 @@ pub fn cTypeBitSize(target: *const Target, c_type: CType) u16 {...@@ -3376,7 +3416,7 @@ pub fn cTypeBitSize(target: *const Target, c_type: CType) u16 {
3376pub fn cTypeAlignment(target: *const Target, c_type: CType) u16 {3416pub fn cTypeAlignment(target: *const Target, c_type: CType) u16 {
3377 // Overrides for unusual alignments3417 // Overrides for unusual alignments
3378 switch (target.cpu.arch) {3418 switch (target.cpu.arch) {
3379 .avr => return 1,3419 .avr, .ez80 => return 1,
3380 .x86 => switch (target.os.tag) {3420 .x86 => switch (target.os.tag) {
3381 .windows, .uefi => switch (c_type) {3421 .windows, .uefi => switch (c_type) {
3382 .longlong, .ulonglong, .double => return 8,3422 .longlong, .ulonglong, .double => return 8,
...@@ -3406,6 +3446,8 @@ pub fn cTypeAlignment(target: *const Target, c_type: CType) u16 {...@@ -3406,6 +3446,8 @@ pub fn cTypeAlignment(target: *const Target, c_type: CType) u16 {
3406 return @min(3446 return @min(
3407 std.math.ceilPowerOfTwoAssert(u16, (cTypeBitSize(target, c_type) + 7) / 8),3447 std.math.ceilPowerOfTwoAssert(u16, (cTypeBitSize(target, c_type) + 7) / 8),
3408 @as(u16, switch (target.cpu.arch) {3448 @as(u16, switch (target.cpu.arch) {
3449 .ez80 => 1,
3450
3409 .msp430,3451 .msp430,
3410 .x86_16,3452 .x86_16,
3411 => 2,3453 => 2,
...@@ -3484,7 +3526,7 @@ pub fn cTypePreferredAlignment(target: *const Target, c_type: CType) u16 {...@@ -3484,7 +3526,7 @@ pub fn cTypePreferredAlignment(target: *const Target, c_type: CType) u16 {
3484 .longdouble => return 4,3526 .longdouble => return 4,
3485 else => {},3527 else => {},
3486 },3528 },
3487 .avr => return 1,3529 .avr, .ez80 => return 1,
3488 .x86 => switch (target.os.tag) {3530 .x86 => switch (target.os.tag) {
3489 .windows, .uefi => switch (c_type) {3531 .windows, .uefi => switch (c_type) {
3490 .longdouble => switch (target.abi) {3532 .longdouble => switch (target.abi) {
...@@ -3516,6 +3558,8 @@ pub fn cTypePreferredAlignment(target: *const Target, c_type: CType) u16 {...@@ -3516,6 +3558,8 @@ pub fn cTypePreferredAlignment(target: *const Target, c_type: CType) u16 {
3516 return @min(3558 return @min(
3517 std.math.ceilPowerOfTwoAssert(u16, (cTypeBitSize(target, c_type) + 7) / 8),3559 std.math.ceilPowerOfTwoAssert(u16, (cTypeBitSize(target, c_type) + 7) / 8),
3518 @as(u16, switch (target.cpu.arch) {3560 @as(u16, switch (target.cpu.arch) {
3561 .ez80 => 1,
3562
3519 .x86_16, .msp430 => 2,3563 .x86_16, .msp430 => 2,
35203564
3521 .arc,3565 .arc,
...@@ -3587,7 +3631,9 @@ pub fn cTypePreferredAlignment(target: *const Target, c_type: CType) u16 {...@@ -3587,7 +3631,9 @@ pub fn cTypePreferredAlignment(target: *const Target, c_type: CType) u16 {
35873631
3588pub fn cMaxIntAlignment(target: *const Target) u16 {3632pub fn cMaxIntAlignment(target: *const Target) u16 {
3589 return switch (target.cpu.arch) {3633 return switch (target.cpu.arch) {
3590 .avr => 1,3634 .avr,
3635 .ez80,
3636 => 1,
35913637
3592 .msp430, .x86_16 => 2,3638 .msp430, .x86_16 => 2,
35933639
...@@ -3726,6 +3772,7 @@ pub fn cCallingConvention(target: *const Target) ?std.builtin.CallingConvention...@@ -3726,6 +3772,7 @@ pub fn cCallingConvention(target: *const Target) ?std.builtin.CallingConvention
3726 .amdgcn => .{ .amdgcn_device = .{} },3772 .amdgcn => .{ .amdgcn_device = .{} },
3727 .nvptx, .nvptx64 => .nvptx_device,3773 .nvptx, .nvptx64 => .nvptx_device,
3728 .spirv32, .spirv64 => .spirv_device,3774 .spirv32, .spirv64 => .spirv_device,
3775 .ez80 => .ez80_cet,
3729 };3776 };
3730}3777}
37313778
lib/std/builtin.zig+4
...@@ -341,6 +341,10 @@ pub const CallingConvention = union(enum(u8)) {...@@ -341,6 +341,10 @@ pub const CallingConvention = union(enum(u8)) {
341 spirv_fragment,341 spirv_fragment,
342 spirv_vertex,342 spirv_vertex,
343343
344 // Calling conventions for the `ez80` architecture.
345 ez80_cet,
346 ez80_tiflags,
347
344 /// Options shared across most calling conventions.348 /// Options shared across most calling conventions.
345 pub const CommonOptions = struct {349 pub const CommonOptions = struct {
346 /// The boundary the stack is aligned to when the function is called.350 /// The boundary the stack is aligned to when the function is called.
lib/zig.h+340-1
...@@ -79,6 +79,9 @@...@@ -79,6 +79,9 @@
79#elif defined(__I86__)79#elif defined(__I86__)
80#define zig_x86_1680#define zig_x86_16
81#define zig_x8681#define zig_x86
82#elif defined (__ez80)
83#define zig_ez80
84#define zig_z80
82#endif85#endif
8386
84#if defined(zig_msvc) || __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__87#if defined(zig_msvc) || __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
...@@ -409,6 +412,8 @@...@@ -409,6 +412,8 @@
409#define zig_trap() __asm__ volatile("int $0x3")412#define zig_trap() __asm__ volatile("int $0x3")
410#elif defined(zig_x86)413#elif defined(zig_x86)
411#define zig_trap() __asm__ volatile("ud2")414#define zig_trap() __asm__ volatile("ud2")
415#elif defined(zig_z80)
416#define zig_trap() __asm__ volatile("rst 00h")
412#else417#else
413#define zig_trap() zig_trap_unavailable418#define zig_trap() zig_trap_unavailable
414#endif419#endif
...@@ -511,7 +516,7 @@ zig_extern void *memcpy (void *zig_restrict, void const *zig_restrict, size_t);...@@ -511,7 +516,7 @@ zig_extern void *memcpy (void *zig_restrict, void const *zig_restrict, size_t);
511zig_extern void *memset (void *, int, size_t);516zig_extern void *memset (void *, int, size_t);
512zig_extern void *memmove (void *, void const *, size_t);517zig_extern void *memmove (void *, void const *, size_t);
513518
514/* ================ Bool and 8/16/32/64-bit Integer Support ================= */519/* ================ Bool and 8/16/24/32/48/64-bit Integer Support ================= */
515520
516#include <limits.h>521#include <limits.h>
517522
...@@ -590,6 +595,16 @@ typedef signed long long int16_t;...@@ -590,6 +595,16 @@ typedef signed long long int16_t;
590#define INT16_MAX ( INT16_C(0x7FFF))595#define INT16_MAX ( INT16_C(0x7FFF))
591#define UINT16_MAX ( INT16_C(0xFFFF))596#define UINT16_MAX ( INT16_C(0xFFFF))
592597
598#if defined(zig_ez80)
599typedef unsigned int uint24_t;
600typedef signed int int24_t;
601#define INT24_C(c) c
602#define UINT24_C(c) c##U
603#endif
604#define INT24_MIN (~INT24_C(0x7FFF))
605#define INT24_MAX ( INT24_C(0x7FFF))
606#define UINT24_MAX ( INT24_C(0xFFFF))
607
593#if SCHAR_MIN == ~0x7FFFFFFF && SCHAR_MAX == 0x7FFFFFFF && UCHAR_MAX == 0xFFFFFFFF608#if SCHAR_MIN == ~0x7FFFFFFF && SCHAR_MAX == 0x7FFFFFFF && UCHAR_MAX == 0xFFFFFFFF
594typedef unsigned char uint32_t;609typedef unsigned char uint32_t;
595typedef signed char int32_t;610typedef signed char int32_t;
...@@ -620,6 +635,17 @@ typedef signed long long int32_t;...@@ -620,6 +635,17 @@ typedef signed long long int32_t;
620#define INT32_MAX ( INT32_C(0x7FFFFFFF))635#define INT32_MAX ( INT32_C(0x7FFFFFFF))
621#define UINT32_MAX ( INT32_C(0xFFFFFFFF))636#define UINT32_MAX ( INT32_C(0xFFFFFFFF))
622637
638#if defined(zig_ez80)
639typedef unsigned __int48 uint48_t;
640typedef signed __int48 int48_t;
641#define INT48_C(c) c
642/* no suffix */
643#define UINT48_C(c) ((uint48_t)(c))
644#endif
645#define INT48_MIN (~INT48_C(0x7FFFFFFFFFFF))
646#define INT48_MAX ( INT48_C(0x7FFFFFFFFFFF))
647#define UINT48_MAX ( INT48_C(0xFFFFFFFFFFFF))
648
623#if SCHAR_MIN == ~0x7FFFFFFFFFFFFFFF && SCHAR_MAX == 0x7FFFFFFFFFFFFFFF && UCHAR_MAX == 0xFFFFFFFFFFFFFFFF649#if SCHAR_MIN == ~0x7FFFFFFFFFFFFFFF && SCHAR_MAX == 0x7FFFFFFFFFFFFFFF && UCHAR_MAX == 0xFFFFFFFFFFFFFFFF
624typedef unsigned char uint64_t;650typedef unsigned char uint64_t;
625typedef signed char int64_t;651typedef signed char int64_t;
...@@ -663,10 +689,18 @@ typedef ptrdiff_t intptr_t;...@@ -663,10 +689,18 @@ typedef ptrdiff_t intptr_t;
663#define zig_maxInt_i16 INT16_MAX689#define zig_maxInt_i16 INT16_MAX
664#define zig_minInt_u16 UINT16_C(0)690#define zig_minInt_u16 UINT16_C(0)
665#define zig_maxInt_u16 UINT16_MAX691#define zig_maxInt_u16 UINT16_MAX
692#define zig_minInt_i24 INT24_MIN
693#define zig_maxInt_i24 INT24_MAX
694#define zig_minInt_u24 UINT24_C(0)
695#define zig_maxInt_u24 UINT24_MAX
666#define zig_minInt_i32 INT32_MIN696#define zig_minInt_i32 INT32_MIN
667#define zig_maxInt_i32 INT32_MAX697#define zig_maxInt_i32 INT32_MAX
668#define zig_minInt_u32 UINT32_C(0)698#define zig_minInt_u32 UINT32_C(0)
669#define zig_maxInt_u32 UINT32_MAX699#define zig_maxInt_u32 UINT32_MAX
700#define zig_minInt_i48 INT48_MIN
701#define zig_maxInt_i48 INT48_MAX
702#define zig_minInt_u48 UINT48_C(0)
703#define zig_maxInt_u48 UINT48_MAX
670#define zig_minInt_i64 INT64_MIN704#define zig_minInt_i64 INT64_MIN
671#define zig_maxInt_i64 INT64_MAX705#define zig_maxInt_i64 INT64_MAX
672#define zig_minInt_u64 UINT64_C(0)706#define zig_minInt_u64 UINT64_C(0)
...@@ -786,6 +820,17 @@ zig_int_helpers(16, unsigned long long)...@@ -786,6 +820,17 @@ zig_int_helpers(16, unsigned long long)
786#else820#else
787zig_int_helpers(16, uint16_t)821zig_int_helpers(16, uint16_t)
788#endif822#endif
823#if defined(zig_ez80)
824#if UINT24_MAX <= UINT_MAX
825zig_int_helpers(24, unsigned int)
826#elif UINT24_MAX <= ULONG_MAX
827zig_int_helpers(24, unsigned long)
828#elif UINT24_MAX <= ULLONG_MAX
829zig_int_helpers(24, unsigned long long)
830#else
831zig_int_helpers(24, uint24_t)
832#endif
833#endif
789#if UINT32_MAX <= UINT_MAX834#if UINT32_MAX <= UINT_MAX
790zig_int_helpers(32, unsigned int)835zig_int_helpers(32, unsigned int)
791#elif UINT32_MAX <= ULONG_MAX836#elif UINT32_MAX <= ULONG_MAX
...@@ -795,6 +840,17 @@ zig_int_helpers(32, unsigned long long)...@@ -795,6 +840,17 @@ zig_int_helpers(32, unsigned long long)
795#else840#else
796zig_int_helpers(32, uint32_t)841zig_int_helpers(32, uint32_t)
797#endif842#endif
843#if defined(zig_ez80)
844#if UINT24_MAX <= UINT_MAX
845zig_int_helpers(48, unsigned int)
846#elif UINT24_MAX <= ULONG_MAX
847zig_int_helpers(48, unsigned long)
848#elif UINT24_MAX <= ULLONG_MAX
849zig_int_helpers(48, unsigned long long)
850#else
851zig_int_helpers(48, uint48_t)
852#endif
853#endif
798#if UINT64_MAX <= UINT_MAX854#if UINT64_MAX <= UINT_MAX
799zig_int_helpers(64, unsigned int)855zig_int_helpers(64, unsigned int)
800#elif UINT64_MAX <= ULONG_MAX856#elif UINT64_MAX <= ULONG_MAX
...@@ -909,6 +965,66 @@ static inline bool zig_addo_i16(int16_t *res, int16_t lhs, int16_t rhs, uint8_t...@@ -909,6 +965,66 @@ static inline bool zig_addo_i16(int16_t *res, int16_t lhs, int16_t rhs, uint8_t
909#endif965#endif
910}966}
911967
968#if defined(zig_ez80)
969static inline bool zig_addo_u24(uint24_t *res, uint24_t lhs, uint24_t rhs, uint8_t bits) {
970#if zig_has_builtin(add_overflow) || defined(zig_gcc)
971 uint24_t full_res;
972 bool overflow = __builtin_add_overflow(lhs, rhs, &full_res);
973 *res = zig_wrap_u24(full_res, bits);
974 return overflow || full_res < zig_minInt_u(24, bits) || full_res > zig_maxInt_u(24, bits);
975#else
976 uint32_t full_res;
977 bool overflow = zig_addo_u32(&full_res, lhs, rhs, bits);
978 *res = (uint24_t)full_res;
979 return overflow;
980#endif
981}
982
983static inline bool zig_addo_i24(int24_t *res, int24_t lhs, int24_t rhs, uint8_t bits) {
984#if zig_has_builtin(add_overflow) || defined(zig_gcc)
985 int24_t full_res;
986 bool overflow = __builtin_add_overflow(lhs, rhs, &full_res);
987 *res = zig_wrap_i24(full_res, bits);
988 return overflow || full_res < zig_minInt_i(24, bits) || full_res > zig_maxInt_i(24, bits);
989#else
990 int32_t full_res;
991 bool overflow = zig_addo_i32(&full_res, lhs, rhs, bits);
992 *res = (int24_t)full_res;
993 return overflow;
994#endif
995}
996#endif
997
998#if defined(zig_ez80)
999static inline bool zig_addo_u48(uint48_t *res, uint48_t lhs, uint48_t rhs, uint8_t bits) {
1000#if zig_has_builtin(add_overflow) || defined(zig_gcc)
1001 uint48_t full_res;
1002 bool overflow = __builtin_add_overflow(lhs, rhs, &full_res);
1003 *res = zig_wrap_u48(full_res, bits);
1004 return overflow || full_res < zig_minInt_u(48, bits) || full_res > zig_maxInt_u(48, bits);
1005#else
1006 uint64_t full_res;
1007 bool overflow = zig_addo_u64(&full_res, lhs, rhs, bits);
1008 *res = (uint48_t)full_res;
1009 return overflow;
1010#endif
1011}
1012
1013static inline bool zig_addo_i48(int48_t *res, int48_t lhs, int48_t rhs, uint8_t bits) {
1014#if zig_has_builtin(add_overflow) || defined(zig_gcc)
1015 int48_t full_res;
1016 bool overflow = __builtin_add_overflow(lhs, rhs, &full_res);
1017 *res = zig_wrap_i48(full_res, bits);
1018 return overflow || full_res < zig_minInt_i(48, bits) || full_res > zig_maxInt_i(48, bits);
1019#else
1020 int64_t full_res;
1021 bool overflow = zig_addo_i64(&full_res, lhs, rhs, bits);
1022 *res = (int48_t)full_res;
1023 return overflow;
1024#endif
1025}
1026#endif
1027
912static inline bool zig_subo_u32(uint32_t *res, uint32_t lhs, uint32_t rhs, uint8_t bits) {1028static inline bool zig_subo_u32(uint32_t *res, uint32_t lhs, uint32_t rhs, uint8_t bits) {
913#if zig_has_builtin(sub_overflow) || defined(zig_gcc)1029#if zig_has_builtin(sub_overflow) || defined(zig_gcc)
914 uint32_t full_res;1030 uint32_t full_res;
...@@ -933,6 +1049,7 @@ static inline bool zig_subo_i32(int32_t *res, int32_t lhs, int32_t rhs, uint8_t...@@ -933,6 +1049,7 @@ static inline bool zig_subo_i32(int32_t *res, int32_t lhs, int32_t rhs, uint8_t
933 return overflow || full_res < zig_minInt_i(32, bits) || full_res > zig_maxInt_i(32, bits);1049 return overflow || full_res < zig_minInt_i(32, bits) || full_res > zig_maxInt_i(32, bits);
934}1050}
9351051
1052
936static inline bool zig_subo_u64(uint64_t *res, uint64_t lhs, uint64_t rhs, uint8_t bits) {1053static inline bool zig_subo_u64(uint64_t *res, uint64_t lhs, uint64_t rhs, uint8_t bits) {
937#if zig_has_builtin(sub_overflow) || defined(zig_gcc)1054#if zig_has_builtin(sub_overflow) || defined(zig_gcc)
938 uint64_t full_res;1055 uint64_t full_res;
...@@ -1013,6 +1130,66 @@ static inline bool zig_subo_i16(int16_t *res, int16_t lhs, int16_t rhs, uint8_t...@@ -1013,6 +1130,66 @@ static inline bool zig_subo_i16(int16_t *res, int16_t lhs, int16_t rhs, uint8_t
1013#endif1130#endif
1014}1131}
10151132
1133#if defined(zig_ez80)
1134static inline bool zig_subo_u24(uint24_t *res, uint24_t lhs, uint24_t rhs, uint8_t bits) {
1135#if zig_has_builtin(sub_overflow) || defined(zig_gcc)
1136 uint24_t full_res;
1137 bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res);
1138 *res = zig_wrap_u24(full_res, bits);
1139 return overflow || full_res < zig_minInt_u(24, bits) || full_res > zig_maxInt_u(24, bits);
1140#else
1141 uint32_t full_res;
1142 bool overflow = zig_subo_u32(&full_res, lhs, rhs, bits);
1143 *res = (uint24_t)full_res;
1144 return overflow;
1145#endif
1146}
1147
1148static inline bool zig_subo_i24(int24_t *res, int24_t lhs, int24_t rhs, uint8_t bits) {
1149#if zig_has_builtin(sub_overflow) || defined(zig_gcc)
1150 int24_t full_res;
1151 bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res);
1152 *res = zig_wrap_i24(full_res, bits);
1153 return overflow || full_res < zig_minInt_i(24, bits) || full_res > zig_maxInt_i(24, bits);
1154#else
1155 int32_t full_res;
1156 bool overflow = zig_subo_i32(&full_res, lhs, rhs, bits);
1157 *res = (int24_t)full_res;
1158 return overflow;
1159#endif
1160}
1161#endif
1162
1163#if defined(zig_ez80)
1164static inline bool zig_subo_u48(uint48_t *res, uint48_t lhs, uint48_t rhs, uint8_t bits) {
1165#if zig_has_builtin(sub_overflow) || defined(zig_gcc)
1166 uint48_t full_res;
1167 bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res);
1168 *res = zig_wrap_u48(full_res, bits);
1169 return overflow || full_res < zig_minInt_u(48, bits) || full_res > zig_maxInt_u(48, bits);
1170#else
1171 uint64_t full_res;
1172 bool overflow = zig_subo_u64(&full_res, lhs, rhs, bits);
1173 *res = (uint48_t)full_res;
1174 return overflow;
1175#endif
1176}
1177
1178static inline bool zig_subo_i48(int48_t *res, int48_t lhs, int48_t rhs, uint8_t bits) {
1179#if zig_has_builtin(sub_overflow) || defined(zig_gcc)
1180 int48_t full_res;
1181 bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res);
1182 *res = zig_wrap_i48(full_res, bits);
1183 return overflow || full_res < zig_minInt_i(48, bits) || full_res > zig_maxInt_i(48, bits);
1184#else
1185 int64_t full_res;
1186 bool overflow = zig_subo_i64(&full_res, lhs, rhs, bits);
1187 *res = (int48_t)full_res;
1188 return overflow;
1189#endif
1190}
1191#endif
1192
1016static inline bool zig_mulo_u32(uint32_t *res, uint32_t lhs, uint32_t rhs, uint8_t bits) {1193static inline bool zig_mulo_u32(uint32_t *res, uint32_t lhs, uint32_t rhs, uint8_t bits) {
1017#if zig_has_builtin(mul_overflow) || defined(zig_gcc)1194#if zig_has_builtin(mul_overflow) || defined(zig_gcc)
1018 uint32_t full_res;1195 uint32_t full_res;
...@@ -1121,6 +1298,66 @@ static inline bool zig_mulo_i16(int16_t *res, int16_t lhs, int16_t rhs, uint8_t...@@ -1121,6 +1298,66 @@ static inline bool zig_mulo_i16(int16_t *res, int16_t lhs, int16_t rhs, uint8_t
1121#endif1298#endif
1122}1299}
11231300
1301#if defined(zig_ez80)
1302static inline bool zig_mulo_u24(uint24_t *res, uint24_t lhs, uint24_t rhs, uint8_t bits) {
1303#if zig_has_builtin(mul_overflow) || defined(zig_gcc)
1304 uint24_t full_res;
1305 bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res);
1306 *res = zig_wrap_u24(full_res, bits);
1307 return overflow || full_res < zig_minInt_u(24, bits) || full_res > zig_maxInt_u(24, bits);
1308#else
1309 uint32_t full_res;
1310 bool overflow = zig_mulo_u32(&full_res, lhs, rhs, bits);
1311 *res = (uint24_t)full_res;
1312 return overflow;
1313#endif
1314}
1315
1316static inline bool zig_mulo_i24(int24_t *res, int24_t lhs, int24_t rhs, uint8_t bits) {
1317#if zig_has_builtin(mul_overflow) || defined(zig_gcc)
1318 int24_t full_res;
1319 bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res);
1320 *res = zig_wrap_i24(full_res, bits);
1321 return overflow || full_res < zig_minInt_i(24, bits) || full_res > zig_maxInt_i(24, bits);
1322#else
1323 int32_t full_res;
1324 bool overflow = zig_mulo_i32(&full_res, lhs, rhs, bits);
1325 *res = (int24_t)full_res;
1326 return overflow;
1327#endif
1328}
1329#endif
1330
1331#if defined(zig_ez80)
1332static inline bool zig_mulo_u48(uint48_t *res, uint48_t lhs, uint48_t rhs, uint8_t bits) {
1333#if zig_has_builtin(mul_overflow) || defined(zig_gcc)
1334 uint48_t full_res;
1335 bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res);
1336 *res = zig_wrap_u48(full_res, bits);
1337 return overflow || full_res < zig_minInt_u(48, bits) || full_res > zig_maxInt_u(48, bits);
1338#else
1339 uint64_t full_res;
1340 bool overflow = zig_mulo_u64(&full_res, lhs, rhs, bits);
1341 *res = (uint48_t)full_res;
1342 return overflow;
1343#endif
1344}
1345
1346static inline bool zig_mulo_i48(int48_t *res, int48_t lhs, int48_t rhs, uint8_t bits) {
1347#if zig_has_builtin(mul_overflow) || defined(zig_gcc)
1348 int48_t full_res;
1349 bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res);
1350 *res = zig_wrap_i48(full_res, bits);
1351 return overflow || full_res < zig_minInt_i(48, bits) || full_res > zig_maxInt_i(48, bits);
1352#else
1353 int64_t full_res;
1354 bool overflow = zig_mulo_i64(&full_res, lhs, rhs, bits);
1355 *res = (int48_t)full_res;
1356 return overflow;
1357#endif
1358}
1359#endif
1360
1124#define zig_int_builtins(w) \1361#define zig_int_builtins(w) \
1125 static inline bool zig_shlo_u##w(uint##w##_t *res, uint##w##_t lhs, uint8_t rhs, uint8_t bits) { \1362 static inline bool zig_shlo_u##w(uint##w##_t *res, uint##w##_t lhs, uint8_t rhs, uint8_t bits) { \
1126 *res = zig_shlw_u##w(lhs, rhs, bits); \1363 *res = zig_shlw_u##w(lhs, rhs, bits); \
...@@ -1180,7 +1417,13 @@ static inline bool zig_mulo_i16(int16_t *res, int16_t lhs, int16_t rhs, uint8_t...@@ -1180,7 +1417,13 @@ static inline bool zig_mulo_i16(int16_t *res, int16_t lhs, int16_t rhs, uint8_t
1180 }1417 }
1181zig_int_builtins(8)1418zig_int_builtins(8)
1182zig_int_builtins(16)1419zig_int_builtins(16)
1420#if defined(zig_ez80)
1421zig_int_builtins(24)
1422#endif
1183zig_int_builtins(32)1423zig_int_builtins(32)
1424#if defined(zig_ez80)
1425zig_int_builtins(48)
1426#endif
1184zig_int_builtins(64)1427zig_int_builtins(64)
11851428
1186#define zig_builtin8(name, val) __builtin_##name(val)1429#define zig_builtin8(name, val) __builtin_##name(val)
...@@ -1189,6 +1432,11 @@ typedef unsigned int zig_Builtin8;...@@ -1189,6 +1432,11 @@ typedef unsigned int zig_Builtin8;
1189#define zig_builtin16(name, val) __builtin_##name(val)1432#define zig_builtin16(name, val) __builtin_##name(val)
1190typedef unsigned int zig_Builtin16;1433typedef unsigned int zig_Builtin16;
11911434
1435#if defined(zig_ez80)
1436#define zig_builtin24(name, val) __builtin_##name(val)
1437typedef unsigned int zig_Builtin24;
1438#endif
1439
1192#if INT_MIN <= INT32_MIN1440#if INT_MIN <= INT32_MIN
1193#define zig_builtin32(name, val) __builtin_##name(val)1441#define zig_builtin32(name, val) __builtin_##name(val)
1194typedef unsigned int zig_Builtin32;1442typedef unsigned int zig_Builtin32;
...@@ -1197,6 +1445,11 @@ typedef unsigned int zig_Builtin32;...@@ -1197,6 +1445,11 @@ typedef unsigned int zig_Builtin32;
1197typedef unsigned long zig_Builtin32;1445typedef unsigned long zig_Builtin32;
1198#endif1446#endif
11991447
1448#if defined(zig_ez80)
1449#define zig_builtin48(name, val) __builtin_##name(val)
1450typedef unsigned long long zig_Builtin48;
1451#endif
1452
1200#if INT_MIN <= INT64_MIN1453#if INT_MIN <= INT64_MIN
1201#define zig_builtin64(name, val) __builtin_##name(val)1454#define zig_builtin64(name, val) __builtin_##name(val)
1202typedef unsigned int zig_Builtin64;1455typedef unsigned int zig_Builtin64;
...@@ -1231,6 +1484,23 @@ static inline int16_t zig_byte_swap_i16(int16_t val, uint8_t bits) {...@@ -1231,6 +1484,23 @@ static inline int16_t zig_byte_swap_i16(int16_t val, uint8_t bits) {
1231 return zig_wrap_i16((int16_t)zig_byte_swap_u16((uint16_t)val, bits), bits);1484 return zig_wrap_i16((int16_t)zig_byte_swap_u16((uint16_t)val, bits), bits);
1232}1485}
12331486
1487#if defined(zig_ez80)
1488static inline uint16_t zig_byte_swap_u24(uint24_t val, uint8_t bits) {
1489 uint24_t full_res;
1490#if zig_has_builtin(bswap24) || defined(zig_gcc)
1491 full_res = __builtin_bswap24(val);
1492#else
1493 full_res = (uint24_t)zig_byte_swap_u8((uint8_t)(val >> 0), 8) << 16 |
1494 (uint24_t)zig_byte_swap_u16((uint16_t)(val >> 8), 16) >> 0;
1495#endif
1496 return zig_wrap_u24(full_res >> (24 - bits), bits);
1497}
1498
1499static inline int16_t zig_byte_swap_i24(int24_t val, uint8_t bits) {
1500 return zig_wrap_i24((int24_t)zig_byte_swap_u24((uint24_t)val, bits), bits);
1501}
1502#endif
1503
1234static inline uint32_t zig_byte_swap_u32(uint32_t val, uint8_t bits) {1504static inline uint32_t zig_byte_swap_u32(uint32_t val, uint8_t bits) {
1235 uint32_t full_res;1505 uint32_t full_res;
1236#if zig_has_builtin(bswap32) || defined(zig_gcc)1506#if zig_has_builtin(bswap32) || defined(zig_gcc)
...@@ -1246,6 +1516,23 @@ static inline int32_t zig_byte_swap_i32(int32_t val, uint8_t bits) {...@@ -1246,6 +1516,23 @@ static inline int32_t zig_byte_swap_i32(int32_t val, uint8_t bits) {
1246 return zig_wrap_i32((int32_t)zig_byte_swap_u32((uint32_t)val, bits), bits);1516 return zig_wrap_i32((int32_t)zig_byte_swap_u32((uint32_t)val, bits), bits);
1247}1517}
12481518
1519#if defined(zig_ez80)
1520static inline uint32_t zig_byte_swap_u48(uint48_t val, uint8_t bits) {
1521 uint48_t full_res;
1522#if zig_has_builtin(bswap48) || defined(zig_gcc)
1523 full_res = __builtin_bswap48(val);
1524#else
1525 full_res = (uint48_t)zig_byte_swap_u24((uint24_t)(val >> 0), 24) << 24 |
1526 (uint48_t)zig_byte_swap_u24((uint24_t)(val >> 24), 24) >> 0;
1527#endif
1528 return zig_wrap_u48(full_res >> (48 - bits), bits);
1529}
1530
1531static inline int32_t zig_byte_swap_i48(int48_t val, uint8_t bits) {
1532 return zig_wrap_i48((int48_t)zig_byte_swap_u48((uint48_t)val, bits), bits);
1533}
1534#endif
1535
1249static inline uint64_t zig_byte_swap_u64(uint64_t val, uint8_t bits) {1536static inline uint64_t zig_byte_swap_u64(uint64_t val, uint8_t bits) {
1250 uint64_t full_res;1537 uint64_t full_res;
1251#if zig_has_builtin(bswap64) || defined(zig_gcc)1538#if zig_has_builtin(bswap64) || defined(zig_gcc)
...@@ -1294,6 +1581,23 @@ static inline int16_t zig_bit_reverse_i16(int16_t val, uint8_t bits) {...@@ -1294,6 +1581,23 @@ static inline int16_t zig_bit_reverse_i16(int16_t val, uint8_t bits) {
1294 return zig_wrap_i16((int16_t)zig_bit_reverse_u16((uint16_t)val, bits), bits);1581 return zig_wrap_i16((int16_t)zig_bit_reverse_u16((uint16_t)val, bits), bits);
1295}1582}
12961583
1584#if defined(zig_ez80)
1585static inline uint24_t zig_bit_reverse_u24(uint24_t val, uint8_t bits) {
1586 uint24_t full_res;
1587#if zig_has_builtin(bitreverse24)
1588 full_res = __builtin_bitreverse24(val);
1589#else
1590 full_res = (uint24_t)zig_bit_reverse_u8((uint8_t)(val >> 0), 8) << 16 |
1591 (uint24_t)zig_bit_reverse_u16((uint16_t)(val >> 8), 16) >> 0;
1592#endif
1593 return zig_wrap_u24(full_res >> (24 - bits), bits);
1594}
1595
1596static inline int24_t zig_bit_reverse_i24(int24_t val, uint8_t bits) {
1597 return zig_wrap_i24((int24_t)zig_bit_reverse_u24((uint24_t)val, bits), bits);
1598}
1599#endif
1600
1297static inline uint32_t zig_bit_reverse_u32(uint32_t val, uint8_t bits) {1601static inline uint32_t zig_bit_reverse_u32(uint32_t val, uint8_t bits) {
1298 uint32_t full_res;1602 uint32_t full_res;
1299#if zig_has_builtin(bitreverse32)1603#if zig_has_builtin(bitreverse32)
...@@ -1309,6 +1613,23 @@ static inline int32_t zig_bit_reverse_i32(int32_t val, uint8_t bits) {...@@ -1309,6 +1613,23 @@ static inline int32_t zig_bit_reverse_i32(int32_t val, uint8_t bits) {
1309 return zig_wrap_i32((int32_t)zig_bit_reverse_u32((uint32_t)val, bits), bits);1613 return zig_wrap_i32((int32_t)zig_bit_reverse_u32((uint32_t)val, bits), bits);
1310}1614}
13111615
1616#if defined(zig_ez80)
1617static inline uint32_t zig_bit_reverse_u48(uint48_t val, uint8_t bits) {
1618 uint48_t full_res;
1619#if zig_has_builtin(bitreverse48)
1620 full_res = __builtin_bitreverse48(val);
1621#else
1622 full_res = (uint48_t)zig_bit_reverse_u24((uint24_t)(val >> 0), 24) << 24 |
1623 (uint48_t)zig_bit_reverse_u24((uint24_t)(val >> 24), 24) >> 0;
1624#endif
1625 return zig_wrap_u32(full_res >> (48 - bits), bits);
1626}
1627
1628static inline int32_t zig_bit_reverse_i48(int48_t val, uint8_t bits) {
1629 return zig_wrap_i48((int48_t)zig_bit_reverse_u48((uint48_t)val, bits), bits);
1630}
1631#endif
1632
1312static inline uint64_t zig_bit_reverse_u64(uint64_t val, uint8_t bits) {1633static inline uint64_t zig_bit_reverse_u64(uint64_t val, uint8_t bits) {
1313 uint64_t full_res;1634 uint64_t full_res;
1314#if zig_has_builtin(bitreverse64)1635#if zig_has_builtin(bitreverse64)
...@@ -1350,7 +1671,13 @@ static inline int64_t zig_bit_reverse_i64(int64_t val, uint8_t bits) {...@@ -1350,7 +1671,13 @@ static inline int64_t zig_bit_reverse_i64(int64_t val, uint8_t bits) {
1350#endif1671#endif
1351zig_builtin_popcount(8)1672zig_builtin_popcount(8)
1352zig_builtin_popcount(16)1673zig_builtin_popcount(16)
1674#if defined(zig_ez80)
1675zig_builtin_popcount(24)
1676#endif
1353zig_builtin_popcount(32)1677zig_builtin_popcount(32)
1678#if defined(zig_ez80)
1679zig_builtin_popcount(48)
1680#endif
1354zig_builtin_popcount(64)1681zig_builtin_popcount(64)
13551682
1356#define zig_builtin_ctz_common(w) \1683#define zig_builtin_ctz_common(w) \
...@@ -1375,7 +1702,13 @@ zig_builtin_popcount(64)...@@ -1375,7 +1702,13 @@ zig_builtin_popcount(64)
1375#endif1702#endif
1376zig_builtin_ctz(8)1703zig_builtin_ctz(8)
1377zig_builtin_ctz(16)1704zig_builtin_ctz(16)
1705#if defined(zig_ez80)
1706zig_builtin_ctz(24)
1707#endif
1378zig_builtin_ctz(32)1708zig_builtin_ctz(32)
1709#if defined(zig_ez80)
1710zig_builtin_ctz(48)
1711#endif
1379zig_builtin_ctz(64)1712zig_builtin_ctz(64)
13801713
1381#define zig_builtin_clz_common(w) \1714#define zig_builtin_clz_common(w) \
...@@ -1400,7 +1733,13 @@ zig_builtin_ctz(64)...@@ -1400,7 +1733,13 @@ zig_builtin_ctz(64)
1400#endif1733#endif
1401zig_builtin_clz(8)1734zig_builtin_clz(8)
1402zig_builtin_clz(16)1735zig_builtin_clz(16)
1736#if defined(zig_ez80)
1737zig_builtin_clz(24)
1738#endif
1403zig_builtin_clz(32)1739zig_builtin_clz(32)
1740#if defined(zig_ez80)
1741zig_builtin_clz(48)
1742#endif
1404zig_builtin_clz(64)1743zig_builtin_clz(64)
14051744
1406/* ======================== 128-bit Integer Support ========================= */1745/* ======================== 128-bit Integer Support ========================= */
src/Type.zig+3
...@@ -1204,6 +1204,9 @@ pub fn abiSize(ty: Type, zcu: *const Zcu) u64 {...@@ -1204,6 +1204,9 @@ pub fn abiSize(ty: Type, zcu: *const Zcu) u64 {
1204}1204}
12051205
1206pub fn ptrAbiAlignment(target: *const Target) Alignment {1206pub fn ptrAbiAlignment(target: *const Target) Alignment {
1207 // The eZ80 has 24-bit pointers, which aren't exact powers of two, tripping
1208 // the assert. The alignment of eZ80 pointers is 1, so we bypass the check.
1209 if (target.cpu.arch == .ez80) return .@"1";
1207 return .fromNonzeroByteUnits(@divExact(target.ptrBitWidth(), 8));1210 return .fromNonzeroByteUnits(@divExact(target.ptrBitWidth(), 8));
1208}1211}
1209pub fn ptrAbiSize(target: *const Target) u64 {1212pub fn ptrAbiSize(target: *const Target) u64 {
src/Zcu.zig+5
...@@ -4022,6 +4022,9 @@ pub fn atomicPtrAlignment(...@@ -4022,6 +4022,9 @@ pub fn atomicPtrAlignment(
4022) AtomicPtrAlignmentError!Alignment {4022) AtomicPtrAlignmentError!Alignment {
4023 const target = zcu.getTarget();4023 const target = zcu.getTarget();
4024 const max_atomic_bits: u16 = switch (target.cpu.arch) {4024 const max_atomic_bits: u16 = switch (target.cpu.arch) {
4025 .ez80,
4026 => 8,
4027
4025 .aarch64,4028 .aarch64,
4026 .aarch64_be,4029 .aarch64_be,
4027 => 128,4030 => 128,
...@@ -4615,6 +4618,8 @@ pub fn callconvSupported(zcu: *Zcu, cc: std.builtin.CallingConvention) union(enu...@@ -4615,6 +4618,8 @@ pub fn callconvSupported(zcu: *Zcu, cc: std.builtin.CallingConvention) union(enu
4615 .avr_signal,4618 .avr_signal,
4616 => true,4619 => true,
46174620
4621 .ez80_tiflags => true,
4622
4618 .naked => true,4623 .naked => true,
46194624
4620 else => false,4625 else => false,
src/codegen/c.zig+23
...@@ -248,7 +248,9 @@ const reserved_idents = std.StaticStringMap(void).initComptime(.{...@@ -248,7 +248,9 @@ const reserved_idents = std.StaticStringMap(void).initComptime(.{
248 .{ "inline", {} },248 .{ "inline", {} },
249 .{ "int", {} },249 .{ "int", {} },
250 .{ "int16_t", {} },250 .{ "int16_t", {} },
251 .{ "int24_t", {} },
251 .{ "int32_t", {} },252 .{ "int32_t", {} },
253 .{ "int48_t", {} },
252 .{ "int64_t", {} },254 .{ "int64_t", {} },
253 .{ "int8_t", {} },255 .{ "int8_t", {} },
254 .{ "intptr_t", {} },256 .{ "intptr_t", {} },
...@@ -270,7 +272,9 @@ const reserved_idents = std.StaticStringMap(void).initComptime(.{...@@ -270,7 +272,9 @@ const reserved_idents = std.StaticStringMap(void).initComptime(.{
270 .{ "typedef", {} },272 .{ "typedef", {} },
271 .{ "typeof", {} },273 .{ "typeof", {} },
272 .{ "uint16_t", {} },274 .{ "uint16_t", {} },
275 .{ "uint24_t", {} },
273 .{ "uint32_t", {} },276 .{ "uint32_t", {} },
277 .{ "uint48_t", {} },
274 .{ "uint64_t", {} },278 .{ "uint64_t", {} },
275 .{ "uint8_t", {} },279 .{ "uint8_t", {} },
276 .{ "uintptr_t", {} },280 .{ "uintptr_t", {} },
...@@ -6992,6 +6996,9 @@ fn toCallingConvention(cc: std.builtin.CallingConvention, zcu: *Zcu) ?[]const u8...@@ -6992,6 +6996,9 @@ fn toCallingConvention(cc: std.builtin.CallingConvention, zcu: *Zcu) ?[]const u8
6992 .x86_64_interrupt,6996 .x86_64_interrupt,
6993 => "interrupt",6997 => "interrupt",
69946998
6999 .ez80_tiflags,
7000 => "__tiflags__",
7001
6995 else => unreachable, // `Zcu.callconvSupported`7002 else => unreachable, // `Zcu.callconvSupported`
6996 };7003 };
6997}7004}
...@@ -7285,7 +7292,9 @@ const FormatInt128 = struct {...@@ -7285,7 +7292,9 @@ const FormatInt128 = struct {
7285 switch (data.int_cty) {7292 switch (data.int_cty) {
7286 .uint8_t,7293 .uint8_t,
7287 .uint16_t,7294 .uint16_t,
7295 .uint24_t,
7288 .uint32_t,7296 .uint32_t,
7297 .uint48_t,
7289 .uint64_t,7298 .uint64_t,
7290 .@"unsigned short",7299 .@"unsigned short",
7291 .@"unsigned int",7300 .@"unsigned int",
...@@ -7298,6 +7307,8 @@ const FormatInt128 = struct {...@@ -7298,6 +7307,8 @@ const FormatInt128 = struct {
72987307
7299 .int8_t,7308 .int8_t,
7300 .int16_t,7309 .int16_t,
7310 .int24_t,
7311 .int48_t,
7301 .int32_t,7312 .int32_t,
7302 .int64_t,7313 .int64_t,
7303 .char,7314 .char,
...@@ -7443,13 +7454,17 @@ fn minMaxMacroPrefix(int_cty: CType.Int) []const u8 {...@@ -7443,13 +7454,17 @@ fn minMaxMacroPrefix(int_cty: CType.Int) []const u8 {
74437454
7444 .uint8_t => "UINT8",7455 .uint8_t => "UINT8",
7445 .uint16_t => "UINT16",7456 .uint16_t => "UINT16",
7457 .uint24_t => "UINT24",
7446 .uint32_t => "UINT32",7458 .uint32_t => "UINT32",
7459 .uint48_t => "UINT48",
7447 .uint64_t => "UINT64",7460 .uint64_t => "UINT64",
7448 .zig_u128 => unreachable,7461 .zig_u128 => unreachable,
74497462
7450 .int8_t => "INT8",7463 .int8_t => "INT8",
7451 .int16_t => "INT16",7464 .int16_t => "INT16",
7465 .int24_t => "INT24",
7452 .int32_t => "INT32",7466 .int32_t => "INT32",
7467 .int48_t => "INT48",
7453 .int64_t => "INT64",7468 .int64_t => "INT64",
7454 .zig_i128 => unreachable,7469 .zig_i128 => unreachable,
74557470
...@@ -7475,13 +7490,17 @@ fn intLiteralPrefix(cty: CType.Int, is_global: bool) []const u8 {...@@ -7475,13 +7490,17 @@ fn intLiteralPrefix(cty: CType.Int, is_global: bool) []const u8 {
74757490
7476 .uint8_t => "UINT8_C(",7491 .uint8_t => "UINT8_C(",
7477 .uint16_t => "UINT16_C(",7492 .uint16_t => "UINT16_C(",
7493 .uint24_t => "UINT24_C(",
7478 .uint32_t => "UINT32_C(",7494 .uint32_t => "UINT32_C(",
7495 .uint48_t => "UINT48_C(",
7479 .uint64_t => "UINT64_C(",7496 .uint64_t => "UINT64_C(",
7480 .zig_u128 => unreachable,7497 .zig_u128 => unreachable,
74817498
7482 .int8_t => "INT8_C(",7499 .int8_t => "INT8_C(",
7483 .int16_t => "INT16_C(",7500 .int16_t => "INT16_C(",
7501 .int24_t => "INT24_C(",
7484 .int32_t => "INT32_C(",7502 .int32_t => "INT32_C(",
7503 .int48_t => "INT48_C(",
7485 .int64_t => "INT64_C(",7504 .int64_t => "INT64_C(",
7486 .zig_i128 => unreachable,7505 .zig_i128 => unreachable,
74877506
...@@ -7507,13 +7526,17 @@ fn intLiteralSuffix(cty: CType.Int) []const u8 {...@@ -7507,13 +7526,17 @@ fn intLiteralSuffix(cty: CType.Int) []const u8 {
75077526
7508 .uint8_t => ")",7527 .uint8_t => ")",
7509 .uint16_t => ")",7528 .uint16_t => ")",
7529 .uint24_t => ")",
7510 .uint32_t => ")",7530 .uint32_t => ")",
7531 .uint48_t => ")",
7511 .uint64_t => ")",7532 .uint64_t => ")",
7512 .zig_u128 => unreachable,7533 .zig_u128 => unreachable,
75137534
7514 .int8_t => ")",7535 .int8_t => ")",
7515 .int16_t => ")",7536 .int16_t => ")",
7537 .int24_t => ")",
7516 .int32_t => ")",7538 .int32_t => ")",
7539 .int48_t => ")",
7517 .int64_t => ")",7540 .int64_t => ")",
7518 .zig_i128 => unreachable,7541 .zig_i128 => unreachable,
75197542
src/codegen/c/type.zig+25-2
...@@ -106,13 +106,21 @@ pub const CType = union(enum) {...@@ -106,13 +106,21 @@ pub const CType = union(enum) {
106106
107 uint8_t,107 uint8_t,
108 uint16_t,108 uint16_t,
109 /// eZ80-specific
110 uint24_t,
109 uint32_t,111 uint32_t,
112 /// eZ80-specific
113 uint48_t,
110 uint64_t,114 uint64_t,
111 zig_u128,115 zig_u128,
112116
113 int8_t,117 int8_t,
114 int16_t,118 int16_t,
119 /// eZ80-specific
120 int24_t,
115 int32_t,121 int32_t,
122 /// eZ80-specific
123 int48_t,
116 int64_t,124 int64_t,
117 zig_i128,125 zig_i128,
118126
...@@ -138,7 +146,9 @@ pub const CType = union(enum) {...@@ -138,7 +146,9 @@ pub const CType = union(enum) {
138146
139 .uint8_t, .int8_t => 8,147 .uint8_t, .int8_t => 8,
140 .uint16_t, .int16_t => 16,148 .uint16_t, .int16_t => 16,
149 .uint24_t, .int24_t => 24,
141 .uint32_t, .int32_t => 32,150 .uint32_t, .int32_t => 32,
151 .uint48_t, .int48_t => 48,
142 .uint64_t, .int64_t => 64,152 .uint64_t, .int64_t => 64,
143 .zig_u128, .zig_i128 => 128,153 .zig_u128, .zig_i128 => 128,
144 // zig fmt: on154 // zig fmt: on
...@@ -154,6 +164,7 @@ pub const CType = union(enum) {...@@ -154,6 +164,7 @@ pub const CType = union(enum) {
154 pub const LimbSize = enum {164 pub const LimbSize = enum {
155 @"8",165 @"8",
156 @"16",166 @"16",
167 @"24",
157 @"32",168 @"32",
158 @"64",169 @"64",
159 @"128",170 @"128",
...@@ -161,6 +172,7 @@ pub const CType = union(enum) {...@@ -161,6 +172,7 @@ pub const CType = union(enum) {
161 return switch (s) {172 return switch (s) {
162 .@"8" => 8,173 .@"8" => 8,
163 .@"16" => 16,174 .@"16" => 16,
175 .@"24" => 24,
164 .@"32" => 32,176 .@"32" => 32,
165 .@"64" => 64,177 .@"64" => 64,
166 .@"128" => 128,178 .@"128" => 128,
...@@ -170,6 +182,7 @@ pub const CType = union(enum) {...@@ -170,6 +182,7 @@ pub const CType = union(enum) {
170 return switch (s) {182 return switch (s) {
171 .@"8" => .uint8_t,183 .@"8" => .uint8_t,
172 .@"16" => .uint16_t,184 .@"16" => .uint16_t,
185 .@"24" => .uint24_t,
173 .@"32" => .uint32_t,186 .@"32" => .uint32_t,
174 .@"64" => .uint64_t,187 .@"64" => .uint64_t,
175 .@"128" => .zig_u128,188 .@"128" => .zig_u128,
...@@ -179,6 +192,7 @@ pub const CType = union(enum) {...@@ -179,6 +192,7 @@ pub const CType = union(enum) {
179 return switch (s) {192 return switch (s) {
180 .@"8" => .int8_t,193 .@"8" => .int8_t,
181 .@"16" => .int16_t,194 .@"16" => .int16_t,
195 .@"24" => .int24_t,
182 .@"32" => .int32_t,196 .@"32" => .int32_t,
183 .@"64" => .int64_t,197 .@"64" => .int64_t,
184 .@"128" => .zig_i128,198 .@"128" => .zig_i128,
...@@ -499,6 +513,7 @@ pub const CType = union(enum) {...@@ -499,6 +513,7 @@ pub const CType = union(enum) {
499 }513 }
500 }514 }
501 fn classifyBitInt(signedness: std.builtin.Signedness, bits: u16, zcu: *const Zcu) IntClass {515 fn classifyBitInt(signedness: std.builtin.Signedness, bits: u16, zcu: *const Zcu) IntClass {
516 const is_ez80 = zcu.getTarget().cpu.arch == .ez80;
502 return switch (bits) {517 return switch (bits) {
503 0 => .void,518 0 => .void,
504 1...8 => switch (signedness) {519 1...8 => switch (signedness) {
...@@ -509,11 +524,19 @@ pub const CType = union(enum) {...@@ -509,11 +524,19 @@ pub const CType = union(enum) {
509 .unsigned => .{ .small = .uint16_t },524 .unsigned => .{ .small = .uint16_t },
510 .signed => .{ .small = .int16_t },525 .signed => .{ .small = .int16_t },
511 },526 },
512 17...32 => switch (signedness) {527 17...24 => switch (signedness) {
528 .unsigned => .{ .small = if (is_ez80) .uint24_t else .uint32_t },
529 .signed => .{ .small = if (is_ez80) .int24_t else .int32_t },
530 },
531 25...32 => switch (signedness) {
513 .unsigned => .{ .small = .uint32_t },532 .unsigned => .{ .small = .uint32_t },
514 .signed => .{ .small = .int32_t },533 .signed => .{ .small = .int32_t },
515 },534 },
516 33...64 => switch (signedness) {535 33...48 => switch (signedness) {
536 .unsigned => .{ .small = if (is_ez80) .uint48_t else .uint64_t },
537 .signed => .{ .small = if (is_ez80) .int48_t else .int64_t },
538 },
539 49...64 => switch (signedness) {
517 .unsigned => .{ .small = .uint64_t },540 .unsigned => .{ .small = .uint64_t },
518 .signed => .{ .small = .int64_t },541 .signed => .{ .small = .int64_t },
519 },542 },
src/codegen/llvm.zig+7-1
...@@ -107,6 +107,7 @@ pub fn targetTriple(allocator: Allocator, target: *const std.Target) ![]const u8...@@ -107,6 +107,7 @@ pub fn targetTriple(allocator: Allocator, target: *const std.Target) ![]const u8
107107
108 .alpha,108 .alpha,
109 .arceb,109 .arceb,
110 .ez80,
110 .hppa,111 .hppa,
111 .hppa64,112 .hppa64,
112 .kalimba,113 .kalimba,
...@@ -244,6 +245,7 @@ pub fn targetTriple(allocator: Allocator, target: *const std.Target) ![]const u8...@@ -244,6 +245,7 @@ pub fn targetTriple(allocator: Allocator, target: *const std.Target) ![]const u8
244 .other,245 .other,
245 .plan9,246 .plan9,
246 .psp,247 .psp,
248 .tios,
247 .vita,249 .vita,
248 => "unknown",250 => "unknown",
249 };251 };
...@@ -473,6 +475,7 @@ pub fn dataLayout(target: *const std.Target) []const u8 {...@@ -473,6 +475,7 @@ pub fn dataLayout(target: *const std.Target) []const u8 {
473475
474 .alpha,476 .alpha,
475 .arceb,477 .arceb,
478 .ez80,
476 .hppa,479 .hppa,
477 .hppa64,480 .hppa64,
478 .kalimba,481 .kalimba,
...@@ -1365,7 +1368,7 @@ pub const Object = struct {...@@ -1365,7 +1368,7 @@ pub const Object = struct {
1365 for (0..field_types.len, llvm_args_start..) |field_i, llvm_arg_index| {1368 for (0..field_types.len, llvm_args_start..) |field_i, llvm_arg_index| {
1366 const param = wip.arg(@intCast(llvm_arg_index));1369 const param = wip.arg(@intCast(llvm_arg_index));
1367 const field_ptr = try wip.gepStruct(llvm_ty, arg_ptr, field_i, "");1370 const field_ptr = try wip.gepStruct(llvm_ty, arg_ptr, field_i, "");
1368 const alignment: Builder.Alignment = .fromByteUnits(@divExact(target.ptrBitWidth(), 8));1371 const alignment = Type.ptrAbiAlignment(target).toLlvm();
1369 _ = try wip.store(.normal, param, field_ptr, alignment);1372 _ = try wip.store(.normal, param, field_ptr, alignment);
1370 }1373 }
13711374
...@@ -4506,6 +4509,8 @@ pub fn toLlvmCallConvTag(cc_tag: std.builtin.CallingConvention.Tag, target: *con...@@ -4506,6 +4509,8 @@ pub fn toLlvmCallConvTag(cc_tag: std.builtin.CallingConvention.Tag, target: *con
4506 .avr_gnu,4509 .avr_gnu,
4507 .bpf_std,4510 .bpf_std,
4508 .csky_sysv,4511 .csky_sysv,
4512 .ez80_cet,
4513 .ez80_tiflags,
4509 .hexagon_sysv,4514 .hexagon_sysv,
4510 .hexagon_sysv_hvx,4515 .hexagon_sysv_hvx,
4511 .hppa_elf,4516 .hppa_elf,
...@@ -4903,6 +4908,7 @@ pub fn initializeLLVMTarget(arch: std.Target.Cpu.Arch) void {...@@ -4903,6 +4908,7 @@ pub fn initializeLLVMTarget(arch: std.Target.Cpu.Arch) void {
4903 // LLVM does does not have a backend for these.4908 // LLVM does does not have a backend for these.
4904 .alpha,4909 .alpha,
4905 .arceb,4910 .arceb,
4911 .ez80,
4906 .hppa,4912 .hppa,
4907 .hppa64,4913 .hppa64,
4908 .kalimba,4914 .kalimba,
src/target.zig+4
...@@ -234,6 +234,10 @@ pub fn hasLlvmSupport(target: *const std.Target, ofmt: std.Target.ObjectFormat)...@@ -234,6 +234,10 @@ pub fn hasLlvmSupport(target: *const std.Target, ofmt: std.Target.ObjectFormat)
234 .xtensa,234 .xtensa,
235 => false,235 => false,
236236
237 // Third-party LLVM backend exists.
238 .ez80,
239 => false,
240
237 // No LLVM backend exists.241 // No LLVM backend exists.
238 .alpha,242 .alpha,
239 .arceb,243 .arceb,