╭─────────────╮╭────────────╮ │scroll to top││next lines →│ ╰─────────────╯╰────────────╯ ╭ zig.h ────────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭ find file ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ ╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │ │ │http│ ssh │ │ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
95 #define zig_x86_64 96 #define zig_x86 97 #elif defined(__I86__) 98 #define zig_x86_16 99 #define zig_x86 100 #elif defined(__xtensa__) 101 #define zig_xtensa 102 #elif defined (__ez80) 103 #define zig_ez80 104 #define zig_z80 105 #endif 106 107 #if defined(zig_msvc) || __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 108 #define zig_little_endian 1 109 #define zig_big_endian 0 110 #else 111 #define zig_little_endian 0 112 #define zig_big_endian 1 113 #endif 114 115 #if defined(__APPLE__) 116 #define zig_darwin 117 #elif defined(__DragonFly__) 118 #define zig_dragonfly 119 #elif defined(__EMSCRIPTEN__) 120 #define zig_emscripten 121 #elif defined(__FreeBSD__) 122 #define zig_freebsd 123 #elif defined(__Fuchsia__) 124 #define zig_fuchsia 125 #elif defined(__HAIKU__) 126 #define zig_haiku 127 #elif defined(__gnu_hurd__) 128 #define zig_hurd 129 #elif defined(__illumos__) 130 #define zig_illumos 131 #elif defined(__linux__) 132 #define zig_linux 133 #elif defined(__NetBSD__) 134 #define zig_netbsd 135 #elif defined(__OpenBSD__) 136 #define zig_openbsd 137 #elif defined(__serenity__) 138 #define zig_serenity 139 #elif defined(__wasi__) 140 #define zig_wasi 141 #elif defined(_WIN32) 142 #define zig_windows 143 #endif 144 145 #if defined(zig_windows) 146 #define zig_coff 147 #elif defined(__ELF__) 148 #define zig_elf 149 #elif defined(zig_darwin) 150 #define zig_macho 151 #endif 152 153 #define zig_concat(lhs, rhs) lhs##rhs 154 #define zig_expand_concat(lhs, rhs) zig_concat(lhs, rhs) 155 156 #if defined(__has_include) 157 #define zig_has_include(include) __has_include(include) 158 #else 159 #define zig_has_include(include) 0 160 #endif 161 162 #if defined(__has_builtin) 163 #define zig_has_builtin(builtin) __has_builtin(__builtin_##builtin) 164 #else 165 #define zig_has_builtin(builtin) 0 166 #endif 167 #define zig_expand_has_builtin(b) zig_has_builtin(b) 168 169 #if defined(__has_feature) 170 #define zig_has_feature(feature) __has_feature(feature) 171 #else 172 #define zig_has_feature(feature) 0 173 #endif 174 175 #if defined(__has_attribute) 176 #define zig_has_attribute(attribute) __has_attribute(attribute) 177 #else 178 #define zig_has_attribute(attribute) 0 179 #endif 180 181 #if __STDC_VERSION__ >= 201112L 182 #define zig_static_assert(cond, msg) _Static_assert(cond, msg) 183 #elif zig_has_attribute(unused) 184 #define zig_static_assert(cond, msg) typedef char zig_expand_concat(zig_static_assert_fail_, __LINE__)[(cond) ? 1 : -1] __attribute__((unused)) 185 #else 186 #define zig_static_assert(cond, msg) typedef char zig_expand_concat(zig_static_assert_fail_, __LINE__)[(cond) ? 1 : -1] 187 #endif 188 189 #if __STDC_VERSION__ >= 202311L 190 #define zig_threadlocal thread_local 191 #elif __STDC_VERSION__ >= 201112L 192 #define zig_threadlocal _Thread_local 193 #elif defined(zig_gnuc) || defined(zig_slimcc) 194 #define zig_threadlocal __thread 195 #elif defined(zig_msvc) 196 #define zig_threadlocal __declspec(thread) 197 #else 198 #define zig_threadlocal zig_threadlocal_unavailable 199 #endif 200 201 #if defined(zig_msvc) 202 #define zig_callconv(c) __##c 203 #else 204 #define zig_callconv(c) __attribute__((c)) 205 #endif 206 207 #if zig_has_attribute(naked) || defined(zig_gcc) 208 #define zig_naked_decl __attribute__((naked)) 209 #define zig_naked __attribute__((naked)) 210 #elif defined(zig_msvc) 211 #define zig_naked_decl 212 #define zig_naked __declspec(naked) 213 #else 214 #define zig_naked_decl zig_naked_unavailable 215 #define zig_naked zig_naked_unavailable 216 #endif 217 218 #if zig_has_attribute(cold) 219 #define zig_cold __attribute__((cold)) 220 #else 221 #define zig_cold 222 #endif 223 224 #if zig_has_attribute(flatten) 225 #define zig_maybe_flatten __attribute__((flatten)) 226 #else 227 #define zig_maybe_flatten 228 #endif 229 230 #if zig_has_attribute(noinline) 231 #define zig_never_inline __attribute__((noinline)) zig_maybe_flatten 232 #elif defined(zig_msvc) 233 #define zig_never_inline __declspec(noinline) zig_maybe_flatten 234 #else 235 #define zig_never_inline zig_never_inline_unavailable 236 #endif 237 238 #if zig_has_attribute(not_tail_called) 239 #define zig_never_tail __attribute__((not_tail_called)) zig_never_inline 240 #else 241 #define zig_never_tail zig_never_tail_unavailable 242 #endif 243 244 #if zig_has_attribute(musttail) 245 #define zig_always_tail __attribute__((musttail)) 246 #else 247 #define zig_always_tail zig_always_tail_unavailable 248 #endif 249 250 #if __STDC_VERSION__ >= 199901L 251 #define zig_restrict restrict 252 #elif defined(zig_gnuc) || defined(zig_tinyc) 253 #define zig_restrict __restrict 254 #else 255 #define zig_restrict 256 #endif 257 258 #if zig_has_attribute(no_builtin) 259 #define zig_no_builtin __attribute__((no_builtin)) 260 #else 261 #define zig_no_builtin 262 #endif 263 264 #if zig_has_attribute(patchable_function_entry) 265 #define zig_patchable_function_entry(count) __attribute__((patchable_function_entry(count))) 266 #else 267 #define zig_patchable_function_entry(count) zig_patchable_function_entry_unavailable 268 #endif 269 270 #if zig_has_attribute(aligned) || defined(zig_tinyc) 271 #define zig_under_align(alignment) __attribute__((aligned(alignment))) 272 #elif defined(zig_msvc) 273 #define zig_under_align(alignment) __declspec(align(alignment)) 274 #else 275 #define zig_under_align zig_align_unavailable 276 #endif 277 278 #if __STDC_VERSION__ >= 202311L 279 #define zig_align(alignment) alignas(alignment) 280 #elif __STDC_VERSION__ >= 201112L || zig_has_feature(c_alignas) 281 #define zig_align(alignment) _Alignas(alignment) 282 #else 283 #define zig_align(alignment) zig_under_align(alignment) 284 #endif 285 286 #if __STDC_VERSION__ >= 202311L 287 #define zig_alignOf(Type) alignof(Type) 288 #elif __STDC_VERSION__ >= 201112L || zig_has_feature(c_alignof) 289 #define zig_alignOf(Type) _Alignof(Type) 290 #else 291 #define zig_alignOf(Type) (sizeof(struct { char c; Type t; }) - sizeof(Type)) 292 #endif 293 294 #if zig_has_attribute(aligned) || defined(zig_tinyc) 295 #define zig_align_fn(alignment) __attribute__((aligned(alignment))) 296 #elif defined(zig_msvc) 297 #define zig_align_fn(alignment) 298 #else 299 #define zig_align_fn zig_align_fn_unavailable 300 #endif 301 302 #if zig_has_attribute(nonstring) 303 #define zig_nonstring __attribute__((nonstring)) 304 #else 305 #define zig_nonstring 306 #endif 307 308 #if zig_has_attribute(packed) || defined(zig_tinyc) 309 #define zig_packed(definition) definition __attribute__((packed)) 310 #elif defined(zig_msvc) 311 #define zig_packed(definition) __pragma(pack(1)) definition __pragma(pack()) 312 #else 313 #define zig_packed(definition) zig_packed_unavailable 314 #endif 315 316 #if zig_has_attribute(section) || defined(zig_tinyc) 317 #define zig_linksection(name) __attribute__((section(name))) 318 #define zig_linksection_fn zig_linksection 319 #elif defined(zig_msvc) 320 #define zig_linksection(name) __pragma(section(name, read, write)) __declspec(allocate(name)) 321 #define zig_linksection_fn(name) __pragma(section(name, read, execute)) __declspec(code_seg(name)) 322 #else 323 #define zig_linksection(name) zig_linksection_unavailable 324 #define zig_linksection_fn zig_linksection 325 #endif 326 327 #if zig_has_attribute(visibility) 328 #define zig_visibility(name) __attribute__((visibility(#name))) 329 #else 330 #define zig_visibility(name) zig_visibility_##name 331 #define zig_visibility_default 332 #define zig_visibility_hidden zig_visibility_hidden_unavailable 333 #define zig_visibility_protected zig_visibility_protected_unavailable 334 #endif 335 336 #if zig_has_builtin(unreachable) || defined(zig_gcc) || defined(zig_tinyc) 337 #define zig_unreachable() __builtin_unreachable() 338 #elif defined(zig_msvc) 339 #define zig_unreachable() __assume(0) 340 #else 341 #define zig_unreachable() 342 #endif 343 344 #if defined(__cplusplus) 345 #define zig_extern extern "C" 346 #else 347 #define zig_extern extern 348 #endif 349 350 #if defined(zig_msvc) 351 #if defined(zig_x86_64) 352 #define zig_mangle_c(symbol) symbol 353 #else /* zig_x86_64 */ 354 #define zig_mangle_c(symbol) "_" symbol 355 #endif /* zig_x86_64 */ 356 #else /* zig_msvc */ 357 #if defined(zig_macho) 358 #define zig_mangle_c(symbol) "_" symbol 359 #else /* zig_macho */ 360 #define zig_mangle_c(symbol) symbol 361 #endif /* zig_macho */ 362 #endif /* zig_msvc */ 363 364 #if defined(zig_msvc) 365 #define zig_export(symbol, name) ; \ 366 __pragma(comment(linker, "/alternatename:" zig_mangle_c(name) "=" zig_mangle_c(symbol))) 367 #elif (zig_has_attribute(alias) || defined(zig_tinyc)) && !defined(zig_macho) 368 #define zig_export(symbol, name) __attribute__((alias(symbol))) 369 #else 370 #define zig_export(symbol, name) ; \ 371 __asm("\t.globl\t" zig_mangle_c(name) "\n" zig_mangle_c(name) " = " zig_mangle_c(symbol)) 372 #endif 373 374 #if defined(zig_msvc) 375 #define zig_mangled(mangled, unmangled) ; \ 376 zig_export(#mangled, unmangled) 377 #define zig_mangled_export(mangled, unmangled, symbol) \ 378 zig_export(unmangled, #mangled) \ 379 zig_export(symbol, unmangled) 380 #else /* zig_msvc */ 381 #define zig_mangled(mangled, unmangled) __asm(zig_mangle_c(unmangled)) 382 #define zig_mangled_export(mangled, unmangled, symbol) \ 383 zig_mangled(mangled, unmangled) \ 384 zig_export(symbol, unmangled) 385 #endif /* zig_msvc */ 386 387 #if defined(zig_msvc) 388 #define zig_import(Type, fn_name, libc_name, sig_args, call_args) zig_extern Type fn_name sig_args;\ 389 __pragma(comment(linker, "/alternatename:" zig_mangle_c(#fn_name) "=" zig_mangle_c(#libc_name))); 390 #define zig_import_builtin(Type, fn_name, libc_name, sig_args, call_args) zig_import(Type, fn_name, libc_name, sig_args, call_args) 391 #else /* zig_msvc */ 392 #define zig_import(Type, fn_name, libc_name, sig_args, call_args) zig_extern Type fn_name sig_args __asm(zig_mangle_c(#libc_name)); 393 #define zig_import_builtin(Type, fn_name, libc_name, sig_args, call_args) zig_extern Type libc_name sig_args; \ 394 static inline Type fn_name sig_args { return libc_name call_args; } 395 #endif 396 397 #define zig_expand_import_0(Type, fn_name, libc_name, sig_args, call_args) zig_import(Type, fn_name, libc_name, sig_args, call_args) 398 #define zig_expand_import_1(Type, fn_name, libc_name, sig_args, call_args) zig_import_builtin(Type, fn_name, libc_name, sig_args, call_args) 399 400 #if zig_has_attribute(weak) || defined(zig_gcc) || defined(zig_tinyc) 401 #define zig_weak_linkage __attribute__((weak)) 402 #define zig_weak_linkage_fn __attribute__((weak)) 403 #elif defined(zig_msvc) 404 #define zig_weak_linkage __declspec(selectany) 405 #define zig_weak_linkage_fn 406 #else 407 #define zig_weak_linkage zig_weak_linkage_unavailable 408 #define zig_weak_linkage_fn zig_weak_linkage_unavailable 409 #endif 410 411 #if defined(zig_gnuc) || defined(zig_tinyc) || defined(zig_slimcc) 412 #define zig_gnuc_asm 413 #endif 414 415 #if zig_has_builtin(trap) 416 #define zig_trap() __builtin_trap() 417 #elif defined(zig_msvc) 418 419 #if defined(zig_x86) 420 #define zig_trap() __ud2() 421 #else 422 #define zig_trap() __fastfail(7) 423 #endif 424 425 #elif defined(zig_gnuc_asm) 426 427 #if defined(zig_alpha) 428 #define zig_trap() __asm__ volatile("call_pal 0x000000") 429 #elif defined(zig_thumb) 430 #define zig_trap() __asm__ volatile("udf #0xfe") 431 #elif defined(zig_arm) || defined(zig_aarch64) 432 #define zig_trap() __asm__ volatile("udf #0xfdee") 433 #elif defined(zig_arc) 434 #define zig_trap() __asm__ volatile("unimp_s") 435 #elif defined(zig_csky) 436 #define zig_trap() __asm__ volatile(".word 0x3fff") 437 #elif defined(zig_hexagon) 438 #define zig_trap() __asm__ volatile("r27:26 = memd(#0xbadc0fee)") 439 #elif defined(zig_hppa) 440 #define zig_trap() __asm__ volatile("iitlbp %r0, (%sr0, %r0)") 441 #elif defined(zig_kvx) || defined(zig_loongarch) || defined(zig_powerpc) 442 #define zig_trap() __asm__ volatile(".word 0x0") 443 #elif defined(zig_m68k) 444 #define zig_trap() __asm__ volatile("illegal") 445 #elif defined(zig_m88k) 446 #define zig_trap() __asm__ volatile("tb0 0, %%r0, 511") 447 #elif defined(zig_microblaze) 448 #define zig_trap() __asm__ volatile("getd r0, r0") 449 #elif defined(zig_mips) 450 #define zig_trap() __asm__ volatile(".word 0x3d") 451 #elif defined(zig_or1k) 452 #define zig_trap() __asm__ volatile("l.cust8") 453 #elif defined(zig_riscv) 454 #define zig_trap() __asm__ volatile("unimp") 455 #elif defined(zig_s390x) 456 #define zig_trap() __asm__ volatile("j 0x2") 457 #elif defined(zig_sh) 458 #define zig_trap() __asm__ volatile(".word 0x0001") 459 #elif defined(zig_sparc) 460 #define zig_trap() __asm__ volatile("illtrap") 461 #elif defined(zig_x86_16) 462 #define zig_trap() __asm__ volatile("int $0x3") 463 #elif defined(zig_x86) 464 #define zig_trap() __asm__ volatile("ud2") 465 #elif defined(zig_xtensa) 466 #define zig_trap() __asm__ volatile("ill") 467 #elif defined(zig_z80) 468 #define zig_trap() __asm__ volatile("rst 00h") 469 #else 470 #define zig_trap() zig_trap_unavailable 471 #endif 472 473 #else 474 #define zig_trap() zig_trap_unavailable 475 #endif 476 477 #if zig_has_builtin(debugtrap) 478 #define zig_breakpoint() __builtin_debugtrap() 479 #elif defined(zig_msvc) 480 #define zig_breakpoint() __debugbreak() 481 #elif defined(zig_gnuc_asm) 482 483 #if defined(zig_alpha) 484 #define zig_breakpoint() __asm__ volatile("call_pal 0x000080") 485 #elif defined(zig_arm) || defined(zig_csky) 486 #define zig_breakpoint() __asm__ volatile("bkpt #0x0") 487 #elif defined(zig_aarch64) 488 #define zig_breakpoint() __asm__ volatile("brk #0xf000") 489 #elif defined(zig_arc) 490 #define zig_breakpoint() __asm__ volatile("brk_s") 491 #elif defined(zig_hexagon) 492 #define zig_breakpoint() __asm__ volatile("brkpt") 493 #elif defined(zig_hppa) 494 #define zig_breakpoint() __asm__ volatile("break 0x04, 0x0008") 495 #elif defined(zig_kvx) || defined(zig_loongarch) 496 #define zig_breakpoint() __asm__ volatile("break 0x0") 497 #elif defined(zig_m88k) 498 #define zig_breakpoint() __asm__ volatile("illop1") 499 #elif defined(zig_microblaze) 500 #define zig_breakpoint() __asm__ volatile("brki r16, 0x0018") 501 #elif defined(zig_mips) 502 #define zig_breakpoint() __asm__ volatile("break") 503 #elif defined(zig_or1k) 504 #define zig_breakpoint() __asm__ volatile("l.trap 0x0") 505 #elif defined(zig_powerpc) 506 #define zig_breakpoint() __asm__ volatile("trap") 507 #elif defined(zig_riscv) 508 #define zig_breakpoint() __asm__ volatile("ebreak") 509 #elif defined(zig_s390x) 510 #define zig_breakpoint() __asm__ volatile("j 0x6") 511 #elif defined(zig_sh) 512 #define zig_breakpoint() __asm__ volatile("trapa #0xc3") 513 #elif defined(zig_sparc) 514 #define zig_breakpoint() __asm__ volatile("ta 0x1") 515 #elif defined(zig_x86) 516 #define zig_breakpoint() __asm__ volatile("int $0x3") 517 #elif defined(zig_xtensa) 518 #define zig_breakpoint() __asm__ volatile("break 1, 1") 519 #else 520 #define zig_breakpoint() zig_breakpoint_unavailable 521 #endif 522 523 #else 524 #define zig_breakpoint() zig_breakpoint_unavailable 525 #endif 526 527 #if zig_has_builtin(return_address) || defined(zig_gcc) || defined(zig_tinyc) 528 #define zig_return_address() __builtin_extract_return_addr(__builtin_return_address(0)) 529 #elif defined(zig_msvc) 530 #define zig_return_address() _ReturnAddress() 531 #else 532 #define zig_return_address() 0 533 #endif 534 535 #if zig_has_builtin(frame_address) || defined(zig_gcc) || defined(zig_tinyc) 536 #define zig_frame_address() __builtin_frame_address(0) 537 #elif defined(zig_msvc) 538 #define zig_frame_address() _AddressOfReturnAddress() 539 #else 540 #define zig_frame_address() 0 541 #endif 542 543 #if zig_has_builtin(prefetch) || defined(zig_gcc) 544 #define zig_prefetch(addr, rw, locality) __builtin_prefetch(addr, rw, locality) 545 #else 546 #define zig_prefetch(addr, rw, locality) 547 #endif 548 549 #if zig_has_builtin(memory_size) && zig_has_builtin(memory_grow) 550 #define zig_wasm_memory_size(index) __builtin_wasm_memory_size(index) 551 #define zig_wasm_memory_grow(index, delta) __builtin_wasm_memory_grow(index, delta) 552 #else 553 #define zig_wasm_memory_size(index) zig_unimplemented() 554 #define zig_wasm_memory_grow(index, delta) zig_unimplemented() 555 #endif 556 557 #if __STDC_VERSION__ >= 202311L 558 #define zig_noreturn [[noreturn]] 559 #elif __STDC_VERSION__ >= 201112L 560 #define zig_noreturn _Noreturn 561 #elif zig_has_attribute(noreturn) || defined(zig_gcc) || defined(zig_tinyc) 562 #define zig_noreturn __attribute__((noreturn)) 563 #elif defined(zig_msvc) 564 #define zig_noreturn __declspec(noreturn) 565 #else 566 #define zig_noreturn 567 #endif 568 569 #define zig_has_always 1 570 #define zig_has_never 0 571 572 #define zig_compiler_rt_abbrev_uint32_t si 573 #define zig_compiler_rt_abbrev_int32_t si 574 #define zig_compiler_rt_abbrev_uint64_t di 575 #define zig_compiler_rt_abbrev_int64_t di 576 #define zig_compiler_rt_abbrev_zig_u128 ti 577 #define zig_compiler_rt_abbrev_zig_i128 ti 578 #define zig_compiler_rt_abbrev_zig_f16 hf 579 #define zig_compiler_rt_abbrev_zig_f32 sf 580 #define zig_compiler_rt_abbrev_zig_f64 df 581 #define zig_compiler_rt_abbrev_zig_f80 xf 582 #ifdef zig_powerpc 583 #define zig_compiler_rt_abbrev_zig_f128 kf 584 #else 585 #define zig_compiler_rt_abbrev_zig_f128 tf 586 #endif 587 588 zig_extern void *memcpy (void *zig_restrict, void const *zig_restrict, size_t); 589 zig_extern void *memset (void *, int, size_t); 590 zig_extern void *memmove (void *, void const *, size_t); 591 592 /* ================ Bool and 8/16/24/32/48/64-bit Integer Support ================= */ 593 594 #include <limits.h> 595 596 #define zig_bitSizeOf(T) (CHAR_BIT * sizeof(T)) 597 598 #if __STDC_VERSION__ >= 202311L 599 /* bool, true, and false are provided by the language. */ 600 #elif __STDC_VERSION__ >= 199901L || zig_has_include(<stdbool.h>) 601 #include <stdbool.h> 602 #else 603 typedef char bool; 604 #define false 0 605 #define true 1 606 #endif 607 608 #if __STDC_VERSION__ >= 199901L || defined(zig_msvc) || zig_has_include(<stdint.h>) 609 #include <stdint.h> 610 #else 611 #if SCHAR_MIN == ~0x7F && SCHAR_MAX == 0x7F && UCHAR_MAX == 0xFF 612 typedef unsigned char uint8_t; 613 typedef signed char int8_t; 614 #define INT8_C(c) c 615 #define UINT8_C(c) c##U 616 #elif SHRT_MIN == ~0x7F && SHRT_MAX == 0x7F && USHRT_MAX == 0xFF 617 typedef unsigned short uint8_t; 618 typedef signed short int8_t; 619 #define INT8_C(c) c 620 #define UINT8_C(c) c##U 621 #elif INT_MIN == ~0x7F && INT_MAX == 0x7F && UINT_MAX == 0xFF 622 typedef unsigned int uint8_t; 623 typedef signed int int8_t; 624 #define INT8_C(c) c 625 #define UINT8_C(c) c##U 626 #elif LONG_MIN == ~0x7F && LONG_MAX == 0x7F && ULONG_MAX == 0xFF 627 typedef unsigned long uint8_t; 628 typedef signed long int8_t; 629 #define INT8_C(c) c##L 630 #define UINT8_C(c) c##LU 631 #elif LLONG_MIN == ~0x7F && LLONG_MAX == 0x7F && ULLONG_MAX == 0xFF 632 typedef unsigned long long uint8_t; 633 typedef signed long long int8_t; 634 #define INT8_C(c) c##LL 635 #define UINT8_C(c) c##LLU 636 #endif 637 #define INT8_MIN (~INT8_C(0x7F)) 638 #define INT8_MAX ( INT8_C(0x7F)) 639 #define UINT8_MAX ( INT8_C(0xFF)) 640 641 #if SCHAR_MIN == ~0x7FFF && SCHAR_MAX == 0x7FFF && UCHAR_MAX == 0xFFFF 642 typedef unsigned char uint16_t; 643 typedef signed char int16_t; 644 #define INT16_C(c) c 645 #define UINT16_C(c) c##U 646 #elif SHRT_MIN == ~0x7FFF && SHRT_MAX == 0x7FFF && USHRT_MAX == 0xFFFF 647 typedef unsigned short uint16_t; 648 typedef signed short int16_t; 649 #define INT16_C(c) c 650 #define UINT16_C(c) c##U 651 #elif INT_MIN == ~0x7FFF && INT_MAX == 0x7FFF && UINT_MAX == 0xFFFF 652 typedef unsigned int uint16_t; 653 typedef signed int int16_t; 654 #define INT16_C(c) c 655 #define UINT16_C(c) c##U 656 #elif LONG_MIN == ~0x7FFF && LONG_MAX == 0x7FFF && ULONG_MAX == 0xFFFF 657 typedef unsigned long uint16_t; 658 typedef signed long int16_t; 659 #define INT16_C(c) c##L 660 #define UINT16_C(c) c##LU 661 #elif LLONG_MIN == ~0x7FFF && LLONG_MAX == 0x7FFF && ULLONG_MAX == 0xFFFF 662 typedef unsigned long long uint16_t; 663 typedef signed long long int16_t; 664 #define INT16_C(c) c##LL 665 #define UINT16_C(c) c##LLU 666 #endif 667 #define INT16_MIN (~INT16_C(0x7FFF)) 668 #define INT16_MAX ( INT16_C(0x7FFF)) 669 #define UINT16_MAX ( INT16_C(0xFFFF)) 670 671 #if SCHAR_MIN == ~0x7FFFFFFF && SCHAR_MAX == 0x7FFFFFFF && UCHAR_MAX == 0xFFFFFFFF 672 typedef unsigned char uint32_t; 673 typedef signed char int32_t; 674 #define INT32_C(c) c 675 #define UINT32_C(c) c##U 676 #elif SHRT_MIN == ~0x7FFFFFFF && SHRT_MAX == 0x7FFFFFFF && USHRT_MAX == 0xFFFFFFFF 677 typedef unsigned short uint32_t; 678 typedef signed short int32_t; 679 #define INT32_C(c) c 680 #define UINT32_C(c) c##U 681 #elif INT_MIN == ~0x7FFFFFFF && INT_MAX == 0x7FFFFFFF && UINT_MAX == 0xFFFFFFFF 682 typedef unsigned int uint32_t; 683 typedef signed int int32_t; 684 #define INT32_C(c) c 685 #define UINT32_C(c) c##U 686 #elif LONG_MIN == ~0x7FFFFFFF && LONG_MAX == 0x7FFFFFFF && ULONG_MAX == 0xFFFFFFFF 687 typedef unsigned long uint32_t; 688 typedef signed long int32_t; 689 #define INT32_C(c) c##L 690 #define UINT32_C(c) c##LU 691 #elif LLONG_MIN == ~0x7FFFFFFF && LLONG_MAX == 0x7FFFFFFF && ULLONG_MAX == 0xFFFFFFFF 692 typedef unsigned long long uint32_t; 693 typedef signed long long int32_t; 694 #define INT32_C(c) c##LL 695 #define UINT32_C(c) c##LLU 696 #endif 697 #define INT32_MIN (~INT32_C(0x7FFFFFFF)) 698 #define INT32_MAX ( INT32_C(0x7FFFFFFF)) 699 #define UINT32_MAX ( INT32_C(0xFFFFFFFF)) 700 701 #if SCHAR_MIN == ~0x7FFFFFFFFFFFFFFF && SCHAR_MAX == 0x7FFFFFFFFFFFFFFF && UCHAR_MAX == 0xFFFFFFFFFFFFFFFF 702 typedef unsigned char uint64_t; 703 typedef signed char int64_t; 704 #define INT64_C(c) c 705 #define UINT64_C(c) c##U 706 #elif SHRT_MIN == ~0x7FFFFFFFFFFFFFFF && SHRT_MAX == 0x7FFFFFFFFFFFFFFF && USHRT_MAX == 0xFFFFFFFFFFFFFFFF 707 typedef unsigned short uint64_t; 708 typedef signed short int64_t; 709 #define INT64_C(c) c 710 #define UINT64_C(c) c##U 711 #elif INT_MIN == ~0x7FFFFFFFFFFFFFFF && INT_MAX == 0x7FFFFFFFFFFFFFFF && UINT_MAX == 0xFFFFFFFFFFFFFFFF 712 typedef unsigned int uint64_t; 713 typedef signed int int64_t; 714 #define INT64_C(c) c 715 #define UINT64_C(c) c##U 716 #elif LONG_MIN == ~0x7FFFFFFFFFFFFFFF && LONG_MAX == 0x7FFFFFFFFFFFFFFF && ULONG_MAX == 0xFFFFFFFFFFFFFFFF 717 typedef unsigned long uint64_t; 718 typedef signed long int64_t; 719 #define INT64_C(c) c##L 720 #define UINT64_C(c) c##LU 721 #elif LLONG_MIN == ~0x7FFFFFFFFFFFFFFF && LLONG_MAX == 0x7FFFFFFFFFFFFFFF && ULLONG_MAX == 0xFFFFFFFFFFFFFFFF 722 typedef unsigned long long uint64_t; 723 typedef signed long long int64_t; 724 #define INT64_C(c) c##LL 725 #define UINT64_C(c) c##LLU 726 #endif 727 #define INT64_MIN (~INT64_C(0x7FFFFFFFFFFFFFFF)) 728 #define INT64_MAX ( INT64_C(0x7FFFFFFFFFFFFFFF)) 729 #define UINT64_MAX ( INT64_C(0xFFFFFFFFFFFFFFFF)) 730 731 #if defined(zig_ez80) 732 733 typedef unsigned int uint24_t; 734 typedef signed int int24_t; 735 #define INT24_C(c) c 736 #define UINT24_C(c) c##U 737 #define INT24_MIN (~INT24_C(0x7FFF)) 738 #define INT24_MAX ( INT24_C(0x7FFF)) 739 #define UINT24_MAX ( INT24_C(0xFFFF)) 740 741 typedef unsigned __int48 uint48_t; 742 typedef signed __int48 int48_t; 743 #define INT48_C(c) c 744 /* no suffix */ 745 #define UINT48_C(c) ((uint48_t)(c)) 746 #define INT48_MIN (~INT48_C(0x7FFFFFFFFFFF)) 747 #define INT48_MAX ( INT48_C(0x7FFFFFFFFFFF)) 748 #define UINT48_MAX ( INT48_C(0xFFFFFFFFFFFF)) 749 750 #endif 751 752 typedef size_t uintptr_t; 753 typedef ptrdiff_t intptr_t; 754 755 #endif 756 757 #define zig_minInt_i8 INT8_MIN 758 #define zig_maxInt_i8 INT8_MAX 759 #define zig_minInt_u8 UINT8_C(0) 760 #define zig_maxInt_u8 UINT8_MAX 761 #define zig_minInt_i16 INT16_MIN 762 #define zig_maxInt_i16 INT16_MAX 763 #define zig_minInt_u16 UINT16_C(0) 764 #define zig_maxInt_u16 UINT16_MAX 765 #define zig_minInt_i32 INT32_MIN 766 #define zig_maxInt_i32 INT32_MAX 767 #define zig_minInt_u32 UINT32_C(0) 768 #define zig_maxInt_u32 UINT32_MAX 769 #define zig_minInt_i64 INT64_MIN 770 #define zig_maxInt_i64 INT64_MAX 771 #define zig_minInt_u64 UINT64_C(0) 772 #define zig_maxInt_u64 UINT64_MAX 773 774 // zig_promoted_T implements C integral promotions except with signedness preserved, which 775 // allows wrapping operations to avoid the ub that would be caused by the normal promotion. 776 777 #if INT8_MAX <= INT_MAX 778 typedef unsigned int zig_promoted_i8; 779 #elif INT8_MAX <= LONG_MAX 780 typedef unsigned long zig_promoted_i8; 781 #elif INT8_MAX <= LLONG_MAX 782 typedef unsigned long long zig_promoted_i8; 783 #else 784 typedef int8_t zig_promoted_i8; 785 #endif 786 #if UINT8_MAX <= UINT_MAX 787 typedef unsigned int zig_promoted_u8; 788 #elif UINT8_MAX <= ULONG_MAX 789 typedef unsigned long zig_promoted_u8; 790 #elif UINT8_MAX <= ULLONG_MAX 791 typedef unsigned long long zig_promoted_u8; 792 #else 793 typedef uint8_t zig_promoted_u8; 794 #endif 795 796 #if INT16_MAX <= INT_MAX 797 typedef unsigned int zig_promoted_i16; 798 #elif INT16_MAX <= LONG_MAX 799 typedef unsigned long zig_promoted_i16; 800 #elif INT16_MAX <= LLONG_MAX 801 typedef unsigned long long zig_promoted_i16; 802 #else 803 typedef int16_t zig_promoted_i16; 804 #endif 805 #if UINT16_MAX <= UINT_MAX 806 typedef unsigned int zig_promoted_u16; 807 #elif UINT16_MAX <= ULONG_MAX 808 typedef unsigned long zig_promoted_u16; 809 #elif UINT16_MAX <= ULLONG_MAX 810 typedef unsigned long long zig_promoted_u16; 811 #else 812 typedef uint16_t zig_promoted_u16; 813 #endif 814 815 #if INT32_MAX <= INT_MAX 816 typedef unsigned int zig_promoted_i32; 817 #elif INT32_MAX <= LONG_MAX 818 typedef unsigned long zig_promoted_i32; 819 #elif INT32_MAX <= LLONG_MAX 820 typedef unsigned long long zig_promoted_i32; 821 #else 822 typedef int32_t zig_promoted_i32; 823 #endif 824 #if UINT32_MAX <= UINT_MAX 825 typedef unsigned int zig_promoted_u32; 826 #elif UINT32_MAX <= ULONG_MAX 827 typedef unsigned long zig_promoted_u32; 828 #elif UINT32_MAX <= ULLONG_MAX 829 typedef unsigned long long zig_promoted_u32; 830 #else 831 typedef uint32_t zig_promoted_u32; 832 #endif 833 834 #if INT64_MAX <= INT_MAX 835 typedef unsigned int zig_promoted_i64; 836 #elif INT64_MAX <= LONG_MAX 837 typedef unsigned long zig_promoted_i64; 838 #elif INT64_MAX <= LLONG_MAX 839 typedef unsigned long long zig_promoted_i64; 840 #else 841 typedef int64_t zig_promoted_i64; 842 #endif 843 #if UINT64_MAX <= UINT_MAX 844 typedef unsigned int zig_promoted_u64; 845 #elif UINT64_MAX <= ULONG_MAX 846 typedef unsigned long zig_promoted_u64; 847 #elif UINT64_MAX <= ULLONG_MAX 848 typedef unsigned long long zig_promoted_u64; 849 #else 850 typedef uint64_t zig_promoted_u64; 851 #endif 852 853 #ifdef zig_ez80 854 855 #define zig_minInt_i24 INT24_MIN 856 #define zig_maxInt_i24 INT24_MAX 857 #define zig_minInt_u24 UINT24_C(0) 858 #define zig_maxInt_u24 UINT24_MAX 859 #define zig_minInt_i48 INT48_MIN 860 #define zig_maxInt_i48 INT48_MAX 861 #define zig_minInt_u48 UINT48_C(0) 862 #define zig_maxInt_u48 UINT48_MAX 863 864 #if INT24_MAX <= INT_MAX 865 typedef unsigned int zig_promoted_i24; 866 #elif INT24_MAX <= LONG_MAX 867 typedef unsigned long zig_promoted_i24; 868 #elif INT24_MAX <= LLONG_MAX 869 typedef unsigned long long zig_promoted_i24; 870 #else 871 typedef int24_t zig_promoted_i24; 872 #endif 873 #if UINT24_MAX <= UINT_MAX 874 typedef unsigned int zig_promoted_u24; 875 #elif UINT24_MAX <= ULONG_MAX 876 typedef unsigned long zig_promoted_u24; 877 #elif UINT24_MAX <= ULLONG_MAX 878 typedef unsigned long long zig_promoted_u24; 879 #else 880 typedef uint24_t zig_promoted_u24; 881 #endif 882 883 #if INT48_MAX <= INT_MAX 884 typedef unsigned int zig_promoted_i48; 885 #elif INT48_MAX <= LONG_MAX 886 typedef unsigned long zig_promoted_i48; 887 #elif INT48_MAX <= LLONG_MAX 888 typedef unsigned long long zig_promoted_i48; 889 #else 890 typedef int48_t zig_promoted_i48; 891 #endif 892 #if UINT48_MAX <= UINT_MAX 893 typedef unsigned int zig_promoted_u48; 894 #elif UINT48_MAX <= ULONG_MAX 895 typedef unsigned long zig_promoted_u48; 896 #elif UINT48_MAX <= ULLONG_MAX 897 typedef unsigned long long zig_promoted_u48; 898 #else 899 typedef uint48_t zig_promoted_u48; 900 #endif 901 902 #endif 903 904 #define zig_intLimit(s, w, limit, bits) zig_shr_##s##w(zig_##limit##Int_##s##w, w - (bits)) 905 #define zig_minInt_i(w, bits) zig_intLimit(i, w, min, bits) 906 #define zig_maxInt_i(w, bits) zig_intLimit(i, w, max, bits) 907 #define zig_minInt_u(w, bits) zig_intLimit(u, w, min, bits) 908 #define zig_maxInt_u(w, bits) zig_intLimit(u, w, max, bits) 909 910 #define zig_operator(Type, RhsType, operation, operator) \ 911 static inline Type zig_##operation(Type lhs, RhsType rhs) { \ 912 return lhs operator rhs; \ 913 } 914 #define zig_basic_operator(Type, operation, operator) \ 915 zig_operator(Type, Type, operation, operator) 916 #define zig_shift_operator(Type, operation, operator) \ 917 zig_operator(Type, uint8_t, operation, operator) 918 919 #define zig_int_casts_common(bw, sw) \ 920 static inline uint##bw##_t zig_u##bw##_intCast_u##sw(uint##sw##_t arg) { \ 921 return arg; \ 922 } \ 923 \ 924 static inline uint##bw##_t zig_u##bw##_intCast_i##sw(int##sw##_t arg) { \ 925 return (uint##bw##_t)arg; \ 926 } \ 927 \ 928 static inline int##bw##_t zig_i##bw##_intCast_u##sw(uint##sw##_t arg) { \ 929 return arg; \ 930 } \ 931 \ 932 static inline int##bw##_t zig_i##bw##_intCast_i##sw(int##sw##_t arg) { \ 933 return arg; \ 934 } \ 935 \ 936 static inline uint##sw##_t zig_u##sw##_truncate_u##bw(uint##bw##_t arg, uint8_t bits) { \ 937 return (uint##sw##_t)arg & zig_maxInt_u(sw, bits); \ 938 } \ 939 \ 940 static inline int##sw##_t zig_i##sw##_truncate_i##bw(int##bw##_t arg, uint8_t bits) { \ 941 return ((uint##sw##_t)arg & UINT##sw##_C(1) << (bits - UINT8_C(1))) != UINT##sw##_C(0) \ 942 ? (int##sw##_t)arg | zig_minInt_i(sw, bits) : (int##sw##_t)arg & zig_maxInt_i(sw, bits); \ 943 } 944 #define zig_int_operators(w) \ 945 zig_basic_operator(uint##w##_t, and_u##w, &) \ 946 zig_basic_operator( int##w##_t, and_i##w, &) \ 947 zig_basic_operator(uint##w##_t, or_u##w, |) \ 948 zig_basic_operator( int##w##_t, or_i##w, |) \ 949 zig_basic_operator(uint##w##_t, xor_u##w, ^) \ 950 zig_basic_operator( int##w##_t, xor_i##w, ^) \ 951 zig_shift_operator(uint##w##_t, shl_u##w, <<) \ 952 zig_shift_operator( int##w##_t, shl_i##w, <<) \ 953 zig_shift_operator(uint##w##_t, shr_u##w, >>) \ 954 \ 955 static inline int##w##_t zig_shr_i##w(int##w##_t lhs, uint8_t rhs) { \ 956 int##w##_t sign_mask = lhs < INT##w##_C(0) ? -INT##w##_C(1) : INT##w##_C(0); \ 957 return ((lhs ^ sign_mask) >> rhs) ^ sign_mask; \ 958 } \ 959 \ 960 static inline uint##w##_t zig_not_u##w(uint##w##_t arg, uint8_t bits) { \ 961 return arg ^ zig_maxInt_u(w, bits); \ 962 } \ 963 \ 964 static inline int##w##_t zig_not_i##w(int##w##_t arg, uint8_t bits) { \ 965 (void)bits; \ 966 return ~arg; \ 967 } \ 968 \ 969 zig_basic_operator(uint##w##_t, divFloor_u##w, /) \ 970 \ 971 static inline int##w##_t zig_divFloor_i##w(int##w##_t lhs, int##w##_t rhs) { \ 972 return lhs / rhs + (lhs % rhs != INT##w##_C(0) ? zig_shr_i##w(lhs ^ rhs, UINT8_C(w) - UINT8_C(1)) : INT##w##_C(0)); \ 973 } \ 974 \ 975 static inline uint##w##_t zig_divCeil_u##w(uint##w##_t lhs, uint##w##_t rhs) { \ 976 return lhs / rhs + (lhs % rhs != UINT##w##_C(0) ? UINT##w##_C(1) : UINT##w##_C(0)); \ 977 } \ 978 \ 979 static inline int##w##_t zig_divCeil_i##w(int##w##_t lhs, int##w##_t rhs) { \ 980 return lhs / rhs + (lhs % rhs != INT##w##_C(0) \ 981 ? zig_shr_i##w(lhs ^ rhs, UINT8_C(w) - UINT8_C(1)) + INT##w##_C(1) : INT##w##_C(0)); \ 982 } \ 983 \ 984 zig_basic_operator(uint##w##_t, mod_u##w, %) \ 985 zig_int_casts_common(w, w) \ 986 \ 987 static inline uint##w##_t zig_u##w##_bitCast_u##w(uint##w##_t arg, uint8_t bits) { \ 988 return zig_u##w##_truncate_u##w(arg, bits); \ 989 } \ 990 \ 991 static inline uint##w##_t zig_u##w##_bitCast_i##w(int##w##_t arg, uint8_t bits) { \ 992 return zig_u##w##_bitCast_u##w((uint##w##_t)arg, bits); \ 993 } \ 994 \ 995 static inline int##w##_t zig_i##w##_bitCast_i##w(int##w##_t arg, uint8_t bits) { \ 996 return zig_i##w##_truncate_i##w(arg, bits); \ 997 } \ 998 \ 999 static inline int##w##_t zig_i##w##_bitCast_u##w(uint##w##_t arg, uint8_t bits) { \ 1000 return zig_i##w##_bitCast_i##w((int##w##_t)arg, bits); \ 1001 } \ 1002 \ 1003 static inline int##w##_t zig_mod_i##w(int##w##_t lhs, int##w##_t rhs) { \ 1004 int##w##_t rem = lhs % rhs; \ 1005 return rem + (rem != INT##w##_C(0) ? rhs & zig_shr_i##w(lhs ^ rhs, UINT8_C(w) - UINT8_C(1)) : INT##w##_C(0)); \ 1006 } \ 1007 \ 1008 static inline uint##w##_t zig_shlw_u##w(uint##w##_t lhs, uint8_t rhs, uint8_t bits) { \ 1009 return zig_u##w##_truncate_u##w(zig_shl_u##w(lhs, rhs), bits); \ 1010 } \ 1011 \ 1012 static inline int##w##_t zig_shlw_i##w(int##w##_t lhs, uint8_t rhs, uint8_t bits) { \ 1013 return zig_i##w##_bitCast_u##w(zig_shl_u##w(zig_u##w##_bitCast_i##w(lhs, bits), rhs), bits); \ 1014 } \ 1015 \ 1016 static inline uint##w##_t zig_addw_u##w(uint##w##_t lhs, uint##w##_t rhs, uint8_t bits) { \ 1017 return zig_u##w##_truncate_u##w((zig_promoted_u##w)lhs + rhs, bits); \ 1018 } \ 1019 \ 1020 static inline int##w##_t zig_addw_i##w(int##w##_t lhs, int##w##_t rhs, uint8_t bits) { \ 1021 return zig_i##w##_bitCast_u##w(zig_addw_u##w(zig_u##w##_bitCast_i##w(lhs, bits), zig_u##w##_bitCast_i##w(rhs, bits), bits), bits); \ 1022 } \ 1023 \ 1024 static inline uint##w##_t zig_subw_u##w(uint##w##_t lhs, uint##w##_t rhs, uint8_t bits) { \ 1025 return zig_u##w##_truncate_u##w((zig_promoted_u##w)lhs - rhs, bits); \ 1026 } \ 1027 \ 1028 static inline int##w##_t zig_subw_i##w(int##w##_t lhs, int##w##_t rhs, uint8_t bits) { \ 1029 return zig_i##w##_bitCast_u##w(zig_subw_u##w(zig_u##w##_bitCast_i##w(lhs, bits), zig_u##w##_bitCast_i##w(rhs, bits), bits), bits); \ 1030 } \ 1031 \ 1032 static inline uint##w##_t zig_mulw_u##w(uint##w##_t lhs, uint##w##_t rhs, uint8_t bits) { \ 1033 return zig_u##w##_truncate_u##w((zig_promoted_u##w)lhs * rhs, bits); \ 1034 } \ 1035 \ 1036 static inline int##w##_t zig_mulw_i##w(int##w##_t lhs, int##w##_t rhs, uint8_t bits) { \ 1037 return zig_i##w##_bitCast_u##w(zig_mulw_u##w(zig_u##w##_bitCast_i##w(lhs, bits), zig_u##w##_bitCast_i##w(rhs, bits), bits), bits); \ 1038 } \ 1039 \ 1040 static inline uint##w##_t zig_abs_i##w(int##w##_t arg) { \ 1041 int##w##_t tmp = zig_shr_i##w(arg, UINT8_C(w) - UINT8_C(1)); \ 1042 return zig_u##w##_bitCast_i##w(zig_subw_i##w(zig_xor_i##w(arg, tmp), tmp, UINT8_C(w)), UINT8_C(w)); \ 1043 } \ 1044 \ 1045 static inline uint##w##_t zig_min_u##w(uint##w##_t lhs, uint##w##_t rhs) { \ 1046 return lhs < rhs ? lhs : rhs; \ 1047 } \ 1048 \ 1049 static inline int##w##_t zig_min_i##w(int##w##_t lhs, int##w##_t rhs) { \ 1050 return lhs < rhs ? lhs : rhs; \ 1051 } \ 1052 \ 1053 static inline uint##w##_t zig_max_u##w(uint##w##_t lhs, uint##w##_t rhs) { \ 1054 return lhs >= rhs ? lhs : rhs; \ 1055 } \ 1056 \ 1057 static inline int##w##_t zig_max_i##w(int##w##_t lhs, int##w##_t rhs) { \ 1058 return lhs >= rhs ? lhs : rhs; \ 1059 } 1060 zig_int_operators(8) 1061 zig_int_operators(16) 1062 zig_int_operators(32) 1063 zig_int_operators(64) 1064 #ifdef zig_ez80 1065 zig_int_operators(24) 1066 zig_int_operators(48) 1067 #endif 1068 1069 #define zig_int_casts(bw, sw) \ 1070 static inline uint##sw##_t zig_u##sw##_intCast_u##bw(uint##bw##_t arg) { \ 1071 return (uint##sw##_t)arg; \ 1072 } \ 1073 \ 1074 static inline uint##sw##_t zig_u##sw##_intCast_i##bw(int##bw##_t arg) { \ 1075 return (uint##sw##_t)arg; \ 1076 } \ 1077 \ 1078 static inline int##sw##_t zig_i##sw##_intCast_u##bw(uint##bw##_t arg) { \ 1079 return (int##sw##_t)arg; \ 1080 } \ 1081 \ 1082 static inline int##sw##_t zig_i##sw##_intCast_i##bw(int##bw##_t arg) { \ 1083 return (int##sw##_t)arg; \ 1084 } \ 1085 \ 1086 zig_int_casts_common(bw, sw) 1087 zig_int_casts(16, 8) 1088 zig_int_casts(32, 8) 1089 zig_int_casts(64, 8) 1090 zig_int_casts(32, 16) 1091 zig_int_casts(64, 16) 1092 zig_int_casts(64, 32) 1093 #ifdef zig_ez80 1094 zig_int_casts(32, 24) 1095 zig_int_casts(48, 24) 1096 zig_int_casts(64, 24) 1097 zig_int_casts(64, 48) 1098 #endif 1099 1100 static inline bool zig_addo_u32(uint32_t *res, uint32_t lhs, uint32_t rhs, uint8_t bits) { 1101 #if zig_has_builtin(add_overflow) || defined(zig_gcc) 1102 uint32_t full_res; 1103 bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); 1104 *res = zig_u32_truncate_u32(full_res, bits); 1105 return overflow || full_res < zig_minInt_u(32, bits) || full_res > zig_maxInt_u(32, bits); 1106 #else 1107 *res = zig_addw_u32(lhs, rhs, bits); 1108 return *res < lhs; 1109 #endif 1110 } 1111 1112 static inline bool zig_addo_i32(int32_t *res, int32_t lhs, int32_t rhs, uint8_t bits) { 1113 #if zig_has_builtin(add_overflow) || defined(zig_gcc) 1114 int32_t full_res; 1115 bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); 1116 *res = zig_i32_truncate_i32(full_res, bits); 1117 return overflow || full_res < zig_minInt_i(32, bits) || full_res > zig_maxInt_i(32, bits); 1118 #else 1119 *res = zig_addw_i32(lhs, rhs, bits); 1120 return ((*res ^ lhs) & (*res ^ rhs)) < INT32_C(0); 1121 #endif 1122 } 1123 1124 static inline bool zig_addo_u64(uint64_t *res, uint64_t lhs, uint64_t rhs, uint8_t bits) { 1125 #if zig_has_builtin(add_overflow) || defined(zig_gcc) 1126 uint64_t full_res; 1127 bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); 1128 *res = zig_u64_truncate_u64(full_res, bits); 1129 return overflow || full_res < zig_minInt_u(64, bits) || full_res > zig_maxInt_u(64, bits); 1130 #else 1131 *res = zig_addw_u64(lhs, rhs, bits); 1132 return *res < lhs; 1133 #endif 1134 } 1135 1136 static inline bool zig_addo_i64(int64_t *res, int64_t lhs, int64_t rhs, uint8_t bits) { 1137 #if zig_has_builtin(add_overflow) || defined(zig_gcc) 1138 int64_t full_res; 1139 bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); 1140 *res = zig_i64_truncate_i64(full_res, bits); 1141 return overflow || full_res < zig_minInt_i(64, bits) || full_res > zig_maxInt_i(64, bits); 1142 #else 1143 *res = zig_addw_i64(lhs, rhs, bits); 1144 return ((*res ^ lhs) & (*res ^ rhs)) < INT64_C(0); 1145 #endif 1146 } 1147 1148 static inline bool zig_addo_u8(uint8_t *res, uint8_t lhs, uint8_t rhs, uint8_t bits) { 1149 #if zig_has_builtin(add_overflow) || defined(zig_gcc) 1150 uint8_t full_res; 1151 bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); 1152 *res = zig_u8_truncate_u8(full_res, bits); 1153 return overflow || full_res < zig_minInt_u(8, bits) || full_res > zig_maxInt_u(8, bits); 1154 #else 1155 uint32_t full_res; 1156 bool overflow = zig_addo_u32(&full_res, lhs, rhs, bits); 1157 *res = zig_u8_intCast_u32(full_res); 1158 return overflow; 1159 #endif 1160 } 1161 1162 static inline bool zig_addo_i8(int8_t *res, int8_t lhs, int8_t rhs, uint8_t bits) { 1163 #if zig_has_builtin(add_overflow) || defined(zig_gcc) 1164 int8_t full_res; 1165 bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); 1166 *res = zig_i8_truncate_i8(full_res, bits); 1167 return overflow || full_res < zig_minInt_i(8, bits) || full_res > zig_maxInt_i(8, bits); 1168 #else 1169 int32_t full_res; 1170 bool overflow = zig_addo_i32(&full_res, lhs, rhs, bits); 1171 *res = zig_i8_intCast_i32(full_res); 1172 return overflow; 1173 #endif 1174 } 1175 1176 static inline bool zig_addo_u16(uint16_t *res, uint16_t lhs, uint16_t rhs, uint8_t bits) { 1177 #if zig_has_builtin(add_overflow) || defined(zig_gcc) 1178 uint16_t full_res; 1179 bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); 1180 *res = zig_u16_truncate_u16(full_res, bits); 1181 return overflow || full_res < zig_minInt_u(16, bits) || full_res > zig_maxInt_u(16, bits); 1182 #else 1183 uint32_t full_res; 1184 bool overflow = zig_addo_u32(&full_res, lhs, rhs, bits); 1185 *res = zig_u16_intCast_u32(full_res); 1186 return overflow; 1187 #endif 1188 } 1189 1190 static inline bool zig_addo_i16(int16_t *res, int16_t lhs, int16_t rhs, uint8_t bits) { 1191 #if zig_has_builtin(add_overflow) || defined(zig_gcc) 1192 int16_t full_res; 1193 bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); 1194 *res = zig_i16_truncate_i16(full_res, bits); 1195 return overflow || full_res < zig_minInt_i(16, bits) || full_res > zig_maxInt_i(16, bits); 1196 #else 1197 int32_t full_res; 1198 bool overflow = zig_addo_i32(&full_res, lhs, rhs, bits); 1199 *res = zig_i16_intCast_i32(full_res); 1200 return overflow; 1201 #endif 1202 } 1203 1204 #if defined(zig_ez80) 1205 1206 static inline bool zig_addo_u24(uint24_t *res, uint24_t lhs, uint24_t rhs, uint8_t bits) { 1207 #if zig_has_builtin(add_overflow) || defined(zig_gcc) 1208 uint24_t full_res; 1209 bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); 1210 *res = zig_u24_truncate_u24(full_res, bits); 1211 return overflow || full_res < zig_minInt_u(24, bits) || full_res > zig_maxInt_u(24, bits); 1212 #else 1213 uint32_t full_res; 1214 bool overflow = zig_addo_u32(&full_res, lhs, rhs, bits); 1215 *res = zig_u24_intCast_u32(full_res); 1216 return overflow; 1217 #endif 1218 } 1219 1220 static inline bool zig_addo_i24(int24_t *res, int24_t lhs, int24_t rhs, uint8_t bits) { 1221 #if zig_has_builtin(add_overflow) || defined(zig_gcc) 1222 int24_t full_res; 1223 bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); 1224 *res = zig_i24_truncate_i24(full_res, bits); 1225 return overflow || full_res < zig_minInt_i(24, bits) || full_res > zig_maxInt_i(24, bits); 1226 #else 1227 int32_t full_res; 1228 bool overflow = zig_addo_i32(&full_res, lhs, rhs, bits); 1229 *res = zig_i24_intCast_i32(full_res); 1230 return overflow; 1231 #endif 1232 } 1233 1234 static inline bool zig_addo_u48(uint48_t *res, uint48_t lhs, uint48_t rhs, uint8_t bits) { 1235 #if zig_has_builtin(add_overflow) || defined(zig_gcc) 1236 uint48_t full_res; 1237 bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); 1238 *res = zig_u48_truncate_u48(full_res, bits); 1239 return overflow || full_res < zig_minInt_u(48, bits) || full_res > zig_maxInt_u(48, bits); 1240 #else 1241 uint64_t full_res; 1242 bool overflow = zig_addo_u64(&full_res, lhs, rhs, bits); 1243 *res = zig_u48_intCast_u64(full_res); 1244 return overflow; 1245 #endif 1246 } 1247 1248 static inline bool zig_addo_i48(int48_t *res, int48_t lhs, int48_t rhs, uint8_t bits) { 1249 #if zig_has_builtin(add_overflow) || defined(zig_gcc) 1250 int48_t full_res; 1251 bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); 1252 *res = zig_i48_truncate_i48(full_res, bits); 1253 return overflow || full_res < zig_minInt_i(48, bits) || full_res > zig_maxInt_i(48, bits); 1254 #else 1255 int64_t full_res; 1256 bool overflow = zig_addo_i64(&full_res, lhs, rhs, bits); 1257 *res = zig_i48_intCast_i64(full_res); 1258 return overflow; 1259 #endif 1260 } 1261 1262 #endif 1263 1264 static inline bool zig_subo_u32(uint32_t *res, uint32_t lhs, uint32_t rhs, uint8_t bits) { 1265 #if zig_has_builtin(sub_overflow) || defined(zig_gcc) 1266 uint32_t full_res; 1267 bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); 1268 *res = zig_u32_truncate_u32(full_res, bits); 1269 return overflow || full_res < zig_minInt_u(32, bits) || full_res > zig_maxInt_u(32, bits); 1270 #else 1271 *res = zig_subw_u32(lhs, rhs, bits); 1272 return *res > lhs; 1273 #endif 1274 } 1275 1276 static inline bool zig_subo_i32(int32_t *res, int32_t lhs, int32_t rhs, uint8_t bits) { 1277 #if zig_has_builtin(sub_overflow) || defined(zig_gcc) 1278 int32_t full_res; 1279 bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); 1280 *res = zig_i32_truncate_i32(full_res, bits); 1281 return overflow || full_res < zig_minInt_i(32, bits) || full_res > zig_maxInt_i(32, bits); 1282 #else 1283 *res = zig_subw_i32(lhs, rhs, bits); 1284 return ((lhs ^ rhs) & (*res ^ lhs)) < INT32_C(0); 1285 #endif 1286 } 1287 1288 static inline bool zig_subo_u64(uint64_t *res, uint64_t lhs, uint64_t rhs, uint8_t bits) { 1289 #if zig_has_builtin(sub_overflow) || defined(zig_gcc) 1290 uint64_t full_res; 1291 bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); 1292 *res = zig_u64_truncate_u64(full_res, bits); 1293 return overflow || full_res < zig_minInt_u(64, bits) || full_res > zig_maxInt_u(64, bits); 1294 #else 1295 *res = zig_subw_u64(lhs, rhs, bits); 1296 return *res > lhs; 1297 #endif 1298 } 1299 1300 static inline bool zig_subo_i64(int64_t *res, int64_t lhs, int64_t rhs, uint8_t bits) { 1301 #if zig_has_builtin(sub_overflow) || defined(zig_gcc) 1302 int64_t full_res; 1303 bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); 1304 *res = zig_i64_truncate_i64(full_res, bits); 1305 return overflow || full_res < zig_minInt_i(64, bits) || full_res > zig_maxInt_i(64, bits); 1306 #else 1307 *res = zig_subw_i64(lhs, rhs, bits); 1308 return ((lhs ^ rhs) & (*res ^ lhs)) < INT64_C(0); 1309 #endif 1310 } 1311 1312 static inline bool zig_subo_u8(uint8_t *res, uint8_t lhs, uint8_t rhs, uint8_t bits) { 1313 #if zig_has_builtin(sub_overflow) || defined(zig_gcc) 1314 uint8_t full_res; 1315 bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); 1316 *res = zig_u8_truncate_u8(full_res, bits); 1317 return overflow || full_res < zig_minInt_u(8, bits) || full_res > zig_maxInt_u(8, bits); 1318 #else 1319 uint32_t full_res; 1320 bool overflow = zig_subo_u32(&full_res, lhs, rhs, bits); 1321 *res = zig_u8_intCast_u32(full_res); 1322 return overflow; 1323 #endif 1324 } 1325 1326 static inline bool zig_subo_i8(int8_t *res, int8_t lhs, int8_t rhs, uint8_t bits) { 1327 #if zig_has_builtin(sub_overflow) || defined(zig_gcc) 1328 int8_t full_res; 1329 bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); 1330 *res = zig_i8_truncate_i8(full_res, bits); 1331 return overflow || full_res < zig_minInt_i(8, bits) || full_res > zig_maxInt_i(8, bits); 1332 #else 1333 int32_t full_res; 1334 bool overflow = zig_subo_i32(&full_res, lhs, rhs, bits); 1335 *res = zig_i8_intCast_i32(full_res); 1336 return overflow; 1337 #endif 1338 } 1339 1340 static inline bool zig_subo_u16(uint16_t *res, uint16_t lhs, uint16_t rhs, uint8_t bits) { 1341 #if zig_has_builtin(sub_overflow) || defined(zig_gcc) 1342 uint16_t full_res; 1343 bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); 1344 *res = zig_u16_truncate_u16(full_res, bits); 1345 return overflow || full_res < zig_minInt_u(16, bits) || full_res > zig_maxInt_u(16, bits); 1346 #else 1347 uint32_t full_res; 1348 bool overflow = zig_subo_u32(&full_res, lhs, rhs, bits); 1349 *res = zig_u16_intCast_u32(full_res); 1350 return overflow; 1351 #endif 1352 } 1353 1354 static inline bool zig_subo_i16(int16_t *res, int16_t lhs, int16_t rhs, uint8_t bits) { 1355 #if zig_has_builtin(sub_overflow) || defined(zig_gcc) 1356 int16_t full_res; 1357 bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); 1358 *res = zig_i16_truncate_i16(full_res, bits); 1359 return overflow || full_res < zig_minInt_i(16, bits) || full_res > zig_maxInt_i(16, bits); 1360 #else 1361 int32_t full_res; 1362 bool overflow = zig_subo_i32(&full_res, lhs, rhs, bits); 1363 *res = zig_i16_intCast_i32(full_res); 1364 return overflow; 1365 #endif 1366 } 1367 1368 #if defined(zig_ez80) 1369 1370 static inline bool zig_subo_u24(uint24_t *res, uint24_t lhs, uint24_t rhs, uint8_t bits) { 1371 #if zig_has_builtin(sub_overflow) || defined(zig_gcc) 1372 uint24_t full_res; 1373 bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); 1374 *res = zig_u24_truncate_u24(full_res, bits); 1375 return overflow || full_res < zig_minInt_u(24, bits) || full_res > zig_maxInt_u(24, bits); 1376 #else 1377 uint32_t full_res; 1378 bool overflow = zig_subo_u32(&full_res, lhs, rhs, bits); 1379 *res = zig_u24_intCast_u32(full_res); 1380 return overflow; 1381 #endif 1382 } 1383 1384 static inline bool zig_subo_i24(int24_t *res, int24_t lhs, int24_t rhs, uint8_t bits) { 1385 #if zig_has_builtin(sub_overflow) || defined(zig_gcc) 1386 int24_t full_res; 1387 bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); 1388 *res = zig_i24_truncate_i24(full_res, bits); 1389 return overflow || full_res < zig_minInt_i(24, bits) || full_res > zig_maxInt_i(24, bits); 1390 #else 1391 int32_t full_res; 1392 bool overflow = zig_subo_i32(&full_res, lhs, rhs, bits); 1393 *res = zig_i24_intCast_i32(full_res); 1394 return overflow; 1395 #endif 1396 } 1397 1398 static inline bool zig_subo_u48(uint48_t *res, uint48_t lhs, uint48_t rhs, uint8_t bits) { 1399 #if zig_has_builtin(sub_overflow) || defined(zig_gcc) 1400 uint48_t full_res; 1401 bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); 1402 *res = zig_u48_truncate_u48(full_res, bits); 1403 return overflow || full_res < zig_minInt_u(48, bits) || full_res > zig_maxInt_u(48, bits); 1404 #else 1405 uint64_t full_res; 1406 bool overflow = zig_subo_u64(&full_res, lhs, rhs, bits); 1407 *res = zig_u48_intCast_u64(full_res); 1408 return overflow; 1409 #endif 1410 } 1411 1412 static inline bool zig_subo_i48(int48_t *res, int48_t lhs, int48_t rhs, uint8_t bits) { 1413 #if zig_has_builtin(sub_overflow) || defined(zig_gcc) 1414 int48_t full_res; 1415 bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); 1416 *res = zig_i48_truncate_i48(full_res, bits); 1417 return overflow || full_res < zig_minInt_i(48, bits) || full_res > zig_maxInt_i(48, bits); 1418 #else 1419 int64_t full_res; 1420 bool overflow = zig_subo_i64(&full_res, lhs, rhs, bits); 1421 *res = zig_i48_intCast_i64(full_res); 1422 return overflow; 1423 #endif 1424 } 1425 1426 #endif 1427 1428 static inline bool zig_mulo_u32(uint32_t *res, uint32_t lhs, uint32_t rhs, uint8_t bits) { 1429 #if zig_has_builtin(mul_overflow) || defined(zig_gcc) 1430 uint32_t full_res; 1431 bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); 1432 *res = zig_u32_truncate_u32(full_res, bits); 1433 return overflow || full_res < zig_minInt_u(32, bits) || full_res > zig_maxInt_u(32, bits); 1434 #else 1435 *res = zig_mulw_u32(lhs, rhs, bits); 1436 return rhs != UINT32_C(0) && lhs > zig_maxInt_u(32, bits) / rhs; 1437 #endif 1438 } 1439 1440 static inline bool zig_mulo_i32(int32_t *res, int32_t lhs, int32_t rhs, uint8_t bits) { 1441 zig_extern int32_t __mulosi4(int32_t lhs, int32_t rhs, int *overflow); 1442 #if zig_has_builtin(mul_overflow) || defined(zig_gcc) 1443 int32_t full_res; 1444 bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); 1445 #else 1446 int overflow_int; 1447 int32_t full_res = __mulosi4(lhs, rhs, &overflow_int); 1448 bool overflow = overflow_int != 0; 1449 #endif 1450 *res = zig_i32_truncate_i32(full_res, bits); 1451 return overflow || full_res < zig_minInt_i(32, bits) || full_res > zig_maxInt_i(32, bits); 1452 } 1453 1454 static inline bool zig_mulo_u64(uint64_t *res, uint64_t lhs, uint64_t rhs, uint8_t bits) { 1455 #if zig_has_builtin(mul_overflow) || defined(zig_gcc) 1456 uint64_t full_res; 1457 bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); 1458 *res = zig_u64_truncate_u64(full_res, bits); 1459 return overflow || full_res < zig_minInt_u(64, bits) || full_res > zig_maxInt_u(64, bits); 1460 #else 1461 *res = zig_mulw_u64(lhs, rhs, bits); 1462 return rhs != UINT64_C(0) && lhs > zig_maxInt_u(64, bits) / rhs; 1463 #endif 1464 } 1465 1466 static inline bool zig_mulo_i64(int64_t *res, int64_t lhs, int64_t rhs, uint8_t bits) { 1467 zig_extern int64_t __mulodi4(int64_t lhs, int64_t rhs, int *overflow); 1468 #if zig_has_builtin(mul_overflow) || defined(zig_gcc) 1469 int64_t full_res; 1470 bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); 1471 #else 1472 int overflow_int; 1473 int64_t full_res = __mulodi4(lhs, rhs, &overflow_int); 1474 bool overflow = overflow_int != 0; 1475 #endif 1476 *res = zig_i64_truncate_i64(full_res, bits); 1477 return overflow || full_res < zig_minInt_i(64, bits) || full_res > zig_maxInt_i(64, bits); 1478 } 1479 1480 static inline bool zig_mulo_u8(uint8_t *res, uint8_t lhs, uint8_t rhs, uint8_t bits) { 1481 #if zig_has_builtin(mul_overflow) || defined(zig_gcc) 1482 uint8_t full_res; 1483 bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); 1484 *res = zig_u8_truncate_u8(full_res, bits); 1485 return overflow || full_res < zig_minInt_u(8, bits) || full_res > zig_maxInt_u(8, bits); 1486 #else 1487 uint32_t full_res; 1488 bool overflow = zig_mulo_u32(&full_res, lhs, rhs, bits); 1489 *res = zig_u8_intCast_u32(full_res); 1490 return overflow; 1491 #endif 1492 } 1493 1494 static inline bool zig_mulo_i8(int8_t *res, int8_t lhs, int8_t rhs, uint8_t bits) { 1495 #if zig_has_builtin(mul_overflow) || defined(zig_gcc) 1496 int8_t full_res; 1497 bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); 1498 *res = zig_i8_truncate_i8(full_res, bits); 1499 return overflow || full_res < zig_minInt_i(8, bits) || full_res > zig_maxInt_i(8, bits); 1500 #else 1501 int32_t full_res; 1502 bool overflow = zig_mulo_i32(&full_res, lhs, rhs, bits); 1503 *res = zig_i8_intCast_i32(full_res); 1504 return overflow; 1505 #endif 1506 } 1507 1508 static inline bool zig_mulo_u16(uint16_t *res, uint16_t lhs, uint16_t rhs, uint8_t bits) { 1509 #if zig_has_builtin(mul_overflow) || defined(zig_gcc) 1510 uint16_t full_res; 1511 bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); 1512 *res = zig_u16_truncate_u16(full_res, bits); 1513 return overflow || full_res < zig_minInt_u(16, bits) || full_res > zig_maxInt_u(16, bits); 1514 #else 1515 uint32_t full_res; 1516 bool overflow = zig_mulo_u32(&full_res, lhs, rhs, bits); 1517 *res = zig_u16_intCast_u32(full_res); 1518 return overflow; 1519 #endif 1520 } 1521 1522 static inline bool zig_mulo_i16(int16_t *res, int16_t lhs, int16_t rhs, uint8_t bits) { 1523 #if zig_has_builtin(mul_overflow) || defined(zig_gcc) 1524 int16_t full_res; 1525 bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); 1526 *res = zig_i16_truncate_i16(full_res, bits); 1527 return overflow || full_res < zig_minInt_i(16, bits) || full_res > zig_maxInt_i(16, bits); 1528 #else 1529 int32_t full_res; 1530 bool overflow = zig_mulo_i32(&full_res, lhs, rhs, bits); 1531 *res = zig_i16_intCast_i32(full_res); 1532 return overflow; 1533 #endif 1534 } 1535 1536 #if defined(zig_ez80) 1537 1538 static inline bool zig_mulo_u24(uint24_t *res, uint24_t lhs, uint24_t rhs, uint8_t bits) { 1539 #if zig_has_builtin(mul_overflow) || defined(zig_gcc) 1540 uint24_t full_res; 1541 bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); 1542 *res = zig_u24_truncate_u24(full_res, bits); 1543 return overflow || full_res < zig_minInt_u(24, bits) || full_res > zig_maxInt_u(24, bits); 1544 #else 1545 uint32_t full_res; 1546 bool overflow = zig_mulo_u32(&full_res, lhs, rhs, bits); 1547 *res = zig_u24_intCast_u32(full_res); 1548 return overflow; 1549 #endif 1550 } 1551 1552 static inline bool zig_mulo_i24(int24_t *res, int24_t lhs, int24_t rhs, uint8_t bits) { 1553 #if zig_has_builtin(mul_overflow) || defined(zig_gcc) 1554 int24_t full_res; 1555 bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); 1556 *res = zig_i24_truncate_i24(full_res, bits); 1557 return overflow || full_res < zig_minInt_i(24, bits) || full_res > zig_maxInt_i(24, bits); 1558 #else 1559 int32_t full_res; 1560 bool overflow = zig_mulo_i32(&full_res, lhs, rhs, bits); 1561 *res = zig_i24_intCast_i32(full_res); 1562 return overflow; 1563 #endif 1564 } 1565 1566 static inline bool zig_mulo_u48(uint48_t *res, uint48_t lhs, uint48_t rhs, uint8_t bits) { 1567 #if zig_has_builtin(mul_overflow) || defined(zig_gcc) 1568 uint48_t full_res; 1569 bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); 1570 *res = zig_u48_truncate_u48(full_res, bits); 1571 return overflow || full_res < zig_minInt_u(48, bits) || full_res > zig_maxInt_u(48, bits); 1572 #else 1573 uint64_t full_res; 1574 bool overflow = zig_mulo_u64(&full_res, lhs, rhs, bits); 1575 *res = zig_u48_intCast_u64(full_res); 1576 return overflow; 1577 #endif 1578 } 1579 1580 static inline bool zig_mulo_i48(int48_t *res, int48_t lhs, int48_t rhs, uint8_t bits) { 1581 #if zig_has_builtin(mul_overflow) || defined(zig_gcc) 1582 int48_t full_res; 1583 bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); 1584 *res = zig_i48_truncate_i48(full_res, bits); 1585 return overflow || full_res < zig_minInt_i(48, bits) || full_res > zig_maxInt_i(48, bits); 1586 #else 1587 int64_t full_res; 1588 bool overflow = zig_mulo_i64(&full_res, lhs, rhs, bits); 1589 *res = zig_i48_intCast_i64(full_res); 1590 return overflow; 1591 #endif 1592 } 1593 1594 #endif 1595 1596 #define zig_shls_builtins(lw, rw) \ 1597 static inline uint##lw##_t zig_shls_u##lw##_u##rw(uint##lw##_t lhs, uint##rw##_t rhs, uint8_t bits) { \ 1598 uint##lw##_t res; \ 1599 if (rhs < bits && !zig_shlo_u##lw(&res, lhs, zig_u8_intCast_u##rw(rhs), bits)) return res; \ 1600 return lhs == INT##lw##_C(0) ? zig_minInt_u(lw, bits) : zig_maxInt_u(lw, bits); \ 1601 } \ 1602 \ 1603 static inline int##lw##_t zig_shls_i##lw##_u##rw(int##lw##_t lhs, uint##rw##_t rhs, uint8_t bits) { \ 1604 int##lw##_t res; \ 1605 if (rhs < bits && !zig_shlo_i##lw(&res, lhs, zig_u8_intCast_u##rw(rhs), bits)) return res; \ 1606 return lhs == INT##lw##_C(0) ? INT##lw##_C(0) : \ 1607 lhs < INT##lw##_C(0) ? zig_minInt_i(lw, bits) : zig_maxInt_i(lw, bits); \ 1608 } 1609 #define zig_int_sat_builtins(w) \ 1610 static inline bool zig_shlo_u##w(uint##w##_t *res, uint##w##_t lhs, uint8_t rhs, uint8_t bits) { \ 1611 *res = zig_shlw_u##w(lhs, rhs, bits); \ 1612 return lhs > zig_maxInt_u(w, bits) >> rhs; \ 1613 } \ 1614 \ 1615 static inline bool zig_shlo_i##w(int##w##_t *res, int##w##_t lhs, uint8_t rhs, uint8_t bits) { \ 1616 *res = zig_shlw_i##w(lhs, rhs, bits); \ 1617 int##w##_t mask = (int##w##_t)(UINT##w##_MAX << (bits - rhs - 1)); \ 1618 return (lhs & mask) != INT##w##_C(0) && (lhs & mask) != mask; \ 1619 } \ 1620 \ 1621 zig_shls_builtins(w, 8) \ 1622 zig_shls_builtins(w, 16) \ 1623 zig_shls_builtins(w, 32) \ 1624 zig_shls_builtins(w, 64) \ 1625 \ 1626 static inline uint##w##_t zig_adds_u##w(uint##w##_t lhs, uint##w##_t rhs, uint8_t bits) { \ 1627 uint##w##_t res; \ 1628 return zig_addo_u##w(&res, lhs, rhs, bits) ? zig_maxInt_u(w, bits) : res; \ 1629 } \ 1630 \ 1631 static inline int##w##_t zig_adds_i##w(int##w##_t lhs, int##w##_t rhs, uint8_t bits) { \ 1632 int##w##_t res; \ 1633 if (!zig_addo_i##w(&res, lhs, rhs, bits)) return res; \ 1634 return res >= INT##w##_C(0) ? zig_minInt_i(w, bits) : zig_maxInt_i(w, bits); \ 1635 } \ 1636 \ 1637 static inline uint##w##_t zig_subs_u##w(uint##w##_t lhs, uint##w##_t rhs, uint8_t bits) { \ 1638 uint##w##_t res; \ 1639 return zig_subo_u##w(&res, lhs, rhs, bits) ? zig_minInt_u(w, bits) : res; \ 1640 } \ 1641 \ 1642 static inline int##w##_t zig_subs_i##w(int##w##_t lhs, int##w##_t rhs, uint8_t bits) { \ 1643 int##w##_t res; \ 1644 if (!zig_subo_i##w(&res, lhs, rhs, bits)) return res; \ 1645 return res >= INT##w##_C(0) ? zig_minInt_i(w, bits) : zig_maxInt_i(w, bits); \ 1646 } \ 1647 \ 1648 static inline uint##w##_t zig_muls_u##w(uint##w##_t lhs, uint##w##_t rhs, uint8_t bits) { \ 1649 uint##w##_t res; \ 1650 return zig_mulo_u##w(&res, lhs, rhs, bits) ? zig_maxInt_u(w, bits) : res; \ 1651 } \ 1652 \ 1653 static inline int##w##_t zig_muls_i##w(int##w##_t lhs, int##w##_t rhs, uint8_t bits) { \ 1654 int##w##_t res; \ 1655 if (!zig_mulo_i##w(&res, lhs, rhs, bits)) return res; \ 1656 return (lhs ^ rhs) < INT##w##_C(0) ? zig_minInt_i(w, bits) : zig_maxInt_i(w, bits); \ 1657 } 1658 zig_int_sat_builtins(8) 1659 zig_int_sat_builtins(16) 1660 zig_int_sat_builtins(32) 1661 zig_int_sat_builtins(64) 1662 #if defined(zig_ez80) 1663 zig_int_sat_builtins(24) 1664 zig_int_sat_builtins(48) 1665 #endif 1666 1667 #define zig_builtin8(name, arg) __builtin_##name(arg) 1668 typedef unsigned int zig_Builtin8; 1669 1670 #define zig_builtin16(name, arg) __builtin_##name(arg) 1671 typedef unsigned int zig_Builtin16; 1672 1673 #if INT_MIN <= INT32_MIN 1674 #define zig_builtin32(name, arg) __builtin_##name(arg) 1675 typedef unsigned int zig_Builtin32; 1676 #elif LONG_MIN <= INT32_MIN 1677 #define zig_builtin32(name, arg) __builtin_##name##l(arg) 1678 typedef unsigned long zig_Builtin32; 1679 #endif 1680 1681 #if INT_MIN <= INT64_MIN 1682 #define zig_builtin64(name, arg) __builtin_##name(arg) 1683 typedef unsigned int zig_Builtin64; 1684 #elif LONG_MIN <= INT64_MIN 1685 #define zig_builtin64(name, arg) __builtin_##name##l(arg) 1686 typedef unsigned long zig_Builtin64; 1687 #elif LLONG_MIN <= INT64_MIN 1688 #define zig_builtin64(name, arg) __builtin_##name##ll(arg) 1689 typedef unsigned long long zig_Builtin64; 1690 #endif 1691 1692 #if defined(zig_ez80) 1693 #define zig_builtin24(name, arg) __builtin_##name(arg) 1694 typedef unsigned int zig_Builtin24; 1695 #define zig_builtin48(name, arg) __builtin_##name(arg) 1696 typedef unsigned long long zig_Builtin48; 1697 #endif 1698 1699 static inline uint8_t zig_byteSwap_u8(uint8_t arg, uint8_t bits) { 1700 return zig_u8_truncate_u8(arg >> (8 - bits), bits); 1701 } 1702 1703 static inline int8_t zig_byteSwap_i8(int8_t arg, uint8_t bits) { 1704 return zig_i8_truncate_i8((int8_t)zig_byteSwap_u8((uint8_t)arg, bits), bits); 1705 } 1706 1707 static inline uint16_t zig_byteSwap_u16(uint16_t arg, uint8_t bits) { 1708 uint16_t full_res; 1709 #if zig_has_builtin(bswap16) || defined(zig_gcc) 1710 full_res = __builtin_bswap16(arg); 1711 #else 1712 full_res = (uint16_t)zig_byteSwap_u8((uint8_t)(arg >> 0), 8) << 8 | 1713 (uint16_t)zig_byteSwap_u8((uint8_t)(arg >> 8), 8) >> 0; 1714 #endif 1715 return zig_u16_truncate_u16(full_res >> (16 - bits), bits); 1716 } 1717 1718 static inline int16_t zig_byteSwap_i16(int16_t arg, uint8_t bits) { 1719 return zig_i16_truncate_i16((int16_t)zig_byteSwap_u16((uint16_t)arg, bits), bits); 1720 } 1721 1722 #if defined(zig_ez80) 1723 static inline uint16_t zig_byteSwap_u24(uint24_t arg, uint8_t bits) { 1724 uint24_t full_res; 1725 #if zig_has_builtin(bswap24) || defined(zig_gcc) 1726 full_res = __builtin_bswap24(arg); 1727 #else 1728 full_res = (uint24_t)zig_byteSwap_u8((uint8_t)(arg >> 0), 8) << 16 | 1729 (uint24_t)zig_byteSwap_u16((uint16_t)(arg >> 8), 16) >> 0; 1730 #endif 1731 return zig_u24_truncate_u24(full_res >> (24 - bits), bits); 1732 } 1733 1734 static inline int16_t zig_byteSwap_i24(int24_t arg, uint8_t bits) { 1735 return zig_i24_truncate_i24((int24_t)zig_byteSwap_u24((uint24_t)arg, bits), bits); 1736 } 1737 #endif 1738 1739 static inline uint32_t zig_byteSwap_u32(uint32_t arg, uint8_t bits) { 1740 uint32_t full_res; 1741 #if zig_has_builtin(bswap32) || defined(zig_gcc) 1742 full_res = __builtin_bswap32(arg); 1743 #else 1744 full_res = (uint32_t)zig_byteSwap_u16((uint16_t)(arg >> 0), 16) << 16 | 1745 (uint32_t)zig_byteSwap_u16((uint16_t)(arg >> 16), 16) >> 0; 1746 #endif 1747 return zig_u32_truncate_u32(full_res >> (32 - bits), bits); 1748 } 1749 1750 static inline int32_t zig_byteSwap_i32(int32_t arg, uint8_t bits) { 1751 return zig_i32_truncate_i32((int32_t)zig_byteSwap_u32((uint32_t)arg, bits), bits); 1752 } 1753 1754 #if defined(zig_ez80) 1755 static inline uint32_t zig_byteSwap_u48(uint48_t arg, uint8_t bits) { 1756 uint48_t full_res; 1757 #if zig_has_builtin(bswap48) || defined(zig_gcc) 1758 full_res = __builtin_bswap48(arg); 1759 #else 1760 full_res = (uint48_t)zig_byteSwap_u24((uint24_t)(arg >> 0), 24) << 24 | 1761 (uint48_t)zig_byteSwap_u24((uint24_t)(arg >> 24), 24) >> 0; 1762 #endif 1763 return zig_u48_truncate_u48(full_res >> (48 - bits), bits); 1764 } 1765 1766 static inline int32_t zig_byteSwap_i48(int48_t arg, uint8_t bits) { 1767 return zig_i48_truncate_i48((int48_t)zig_byteSwap_u48((uint48_t)arg, bits), bits); 1768 } 1769 #endif 1770 1771 static inline uint64_t zig_byteSwap_u64(uint64_t arg, uint8_t bits) { 1772 uint64_t full_res; 1773 #if zig_has_builtin(bswap64) || defined(zig_gcc) 1774 full_res = __builtin_bswap64(arg); 1775 #else 1776 full_res = (uint64_t)zig_byteSwap_u32((uint32_t)(arg >> 0), 32) << 32 | 1777 (uint64_t)zig_byteSwap_u32((uint32_t)(arg >> 32), 32) >> 0; 1778 #endif 1779 return zig_u64_truncate_u64(full_res >> (64 - bits), bits); 1780 } 1781 1782 static inline int64_t zig_byteSwap_i64(int64_t arg, uint8_t bits) { 1783 return zig_i64_truncate_i64((int64_t)zig_byteSwap_u64((uint64_t)arg, bits), bits); 1784 } 1785 1786 static inline uint8_t zig_bitReverse_u8(uint8_t arg, uint8_t bits) { 1787 uint8_t full_res; 1788 #if zig_has_builtin(bitreverse8) 1789 full_res = __builtin_bitreverse8(arg); 1790 #else 1791 static uint8_t const lut[0x10] = { 1792 0x0, 0x8, 0x4, 0xc, 0x2, 0xa, 0x6, 0xe, 1793 0x1, 0x9, 0x5, 0xd, 0x3, 0xb, 0x7, 0xf 1794 }; 1795 full_res = lut[arg >> 0 & 0xF] << 4 | lut[arg >> 4 & 0xF] << 0; 1796 #endif 1797 return zig_u8_truncate_u8(full_res >> (8 - bits), bits); 1798 } 1799 1800 static inline int8_t zig_bitReverse_i8(int8_t arg, uint8_t bits) { 1801 return zig_i8_truncate_i8((int8_t)zig_bitReverse_u8((uint8_t)arg, bits), bits); 1802 } 1803 1804 static inline uint16_t zig_bitReverse_u16(uint16_t arg, uint8_t bits) { 1805 uint16_t full_res; 1806 #if zig_has_builtin(bitreverse16) 1807 full_res = __builtin_bitreverse16(arg); 1808 #else 1809 full_res = (uint16_t)zig_bitReverse_u8((uint8_t)(arg >> 0), 8) << 8 | 1810 (uint16_t)zig_bitReverse_u8((uint8_t)(arg >> 8), 8) >> 0; 1811 #endif 1812 return zig_u16_truncate_u16(full_res >> (16 - bits), bits); 1813 } 1814 1815 static inline int16_t zig_bitReverse_i16(int16_t arg, uint8_t bits) { 1816 return zig_i16_truncate_i16((int16_t)zig_bitReverse_u16((uint16_t)arg, bits), bits); 1817 } 1818 1819 #if defined(zig_ez80) 1820 static inline uint24_t zig_bitReverse_u24(uint24_t arg, uint8_t bits) { 1821 uint24_t full_res; 1822 #if zig_has_builtin(bitreverse24) 1823 full_res = __builtin_bitreverse24(arg); 1824 #else 1825 full_res = (uint24_t)zig_bitReverse_u8((uint8_t)(arg >> 0), 8) << 16 | 1826 (uint24_t)zig_bitReverse_u16((uint16_t)(arg >> 8), 16) >> 0; 1827 #endif 1828 return zig_u24_truncate_u24(full_res >> (24 - bits), bits); 1829 } 1830 1831 static inline int24_t zig_bitReverse_i24(int24_t arg, uint8_t bits) { 1832 return zig_i24_truncate_i24((int24_t)zig_bitReverse_u24((uint24_t)arg, bits), bits); 1833 } 1834 #endif 1835 1836 static inline uint32_t zig_bitReverse_u32(uint32_t arg, uint8_t bits) { 1837 uint32_t full_res; 1838 #if zig_has_builtin(bitreverse32) 1839 full_res = __builtin_bitreverse32(arg); 1840 #else 1841 full_res = (uint32_t)zig_bitReverse_u16((uint16_t)(arg >> 0), 16) << 16 | 1842 (uint32_t)zig_bitReverse_u16((uint16_t)(arg >> 16), 16) >> 0; 1843 #endif 1844 return zig_u32_truncate_u32(full_res >> (32 - bits), bits); 1845 } 1846 1847 static inline int32_t zig_bitReverse_i32(int32_t arg, uint8_t bits) { 1848 return zig_i32_truncate_i32((int32_t)zig_bitReverse_u32((uint32_t)arg, bits), bits); 1849 } 1850 1851 #if defined(zig_ez80) 1852 static inline uint32_t zig_bitReverse_u48(uint48_t arg, uint8_t bits) { 1853 uint48_t full_res; 1854 #if zig_has_builtin(bitreverse48) 1855 full_res = __builtin_bitreverse48(arg); 1856 #else 1857 full_res = (uint48_t)zig_bitReverse_u24((uint24_t)(arg >> 0), 24) << 24 | 1858 (uint48_t)zig_bitReverse_u24((uint24_t)(arg >> 24), 24) >> 0; 1859 #endif 1860 return zig_u48_truncate_u48(full_res >> (48 - bits), bits); 1861 } 1862 1863 static inline int32_t zig_bitReverse_i48(int48_t arg, uint8_t bits) { 1864 return zig_i48_truncate_i48((int48_t)zig_bitReverse_u48((uint48_t)arg, bits), bits); 1865 } 1866 #endif 1867 1868 static inline uint64_t zig_bitReverse_u64(uint64_t arg, uint8_t bits) { 1869 uint64_t full_res; 1870 #if zig_has_builtin(bitreverse64) 1871 full_res = __builtin_bitreverse64(arg); 1872 #else 1873 full_res = (uint64_t)zig_bitReverse_u32((uint32_t)(arg >> 0), 32) << 32 | 1874 (uint64_t)zig_bitReverse_u32((uint32_t)(arg >> 32), 32) >> 0; 1875 #endif 1876 return zig_u64_truncate_u64(full_res >> (64 - bits), bits); 1877 } 1878 1879 static inline int64_t zig_bitReverse_i64(int64_t arg, uint8_t bits) { 1880 return zig_i64_truncate_i64((int64_t)zig_bitReverse_u64((uint64_t)arg, bits), bits); 1881 } 1882 1883 #define zig_builtin_popCount_common(w) \ 1884 static inline uint8_t zig_popCount_i##w(int##w##_t arg, uint8_t bits) { \ 1885 return zig_popCount_u##w((uint##w##_t)arg, bits); \ 1886 } 1887 #if zig_has_builtin(popCount) || defined(zig_gcc) || defined(zig_tinyc) 1888 #define zig_builtin_popCount(w) \ 1889 static inline uint8_t zig_popCount_u##w(uint##w##_t arg, uint8_t bits) { \ 1890 (void)bits; \ 1891 return zig_builtin##w(popcount, arg); \ 1892 } \ 1893 \ 1894 zig_builtin_popCount_common(w) 1895 #else 1896 #define zig_builtin_popCount(w) \ 1897 static inline uint8_t zig_popCount_u##w(uint##w##_t arg, uint8_t bits) { \ 1898 (void)bits; \ 1899 uint##w##_t temp = arg - ((arg >> 1) & (UINT##w##_MAX / 3)); \ 1900 temp = (temp & (UINT##w##_MAX / 5)) + ((temp >> 2) & (UINT##w##_MAX / 5)); \ 1901 temp = (temp + (temp >> 4)) & (UINT##w##_MAX / 17); \ 1902 return temp * (UINT##w##_MAX / 255) >> (UINT8_C(w) - UINT8_C(8)); \ 1903 } \ 1904 \ 1905 zig_builtin_popCount_common(w) 1906 #endif 1907 zig_builtin_popCount(8) 1908 zig_builtin_popCount(16) 1909 zig_builtin_popCount(32) 1910 zig_builtin_popCount(64) 1911 #if defined(zig_ez80) 1912 zig_builtin_popCount(24) 1913 zig_builtin_popCount(48) 1914 #endif 1915 1916 #define zig_builtin_ctz_common(w) \ 1917 static inline uint8_t zig_ctz_i##w(int##w##_t arg, uint8_t bits) { \ 1918 return zig_ctz_u##w((uint##w##_t)arg, bits); \ 1919 } 1920 #if zig_has_builtin(ctz) || defined(zig_gcc) || defined(zig_tinyc) 1921 #define zig_builtin_ctz(w) \ 1922 static inline uint8_t zig_ctz_u##w(uint##w##_t arg, uint8_t bits) { \ 1923 if (arg == 0) return bits; \ 1924 return zig_builtin##w(ctz, arg); \ 1925 } \ 1926 \ 1927 zig_builtin_ctz_common(w) 1928 #else 1929 #define zig_builtin_ctz(w) \ 1930 static inline uint8_t zig_ctz_u##w(uint##w##_t arg, uint8_t bits) { \ 1931 return zig_popCount_u##w(zig_not_u##w(arg, bits) & zig_subw_u##w(arg, 1, bits), bits); \ 1932 } \ 1933 \ 1934 zig_builtin_ctz_common(w) 1935 #endif 1936 zig_builtin_ctz(8) 1937 zig_builtin_ctz(16) 1938 zig_builtin_ctz(32) 1939 zig_builtin_ctz(64) 1940 #if defined(zig_ez80) 1941 zig_builtin_ctz(24) 1942 zig_builtin_ctz(48) 1943 #endif 1944 1945 #define zig_builtin_clz_common(w) \ 1946 static inline uint8_t zig_clz_i##w(int##w##_t arg, uint8_t bits) { \ 1947 return zig_clz_u##w((uint##w##_t)arg, bits); \ 1948 } 1949 #if zig_has_builtin(clz) || defined(zig_gcc) || defined(zig_tinyc) 1950 #define zig_builtin_clz(w) \ 1951 static inline uint8_t zig_clz_u##w(uint##w##_t arg, uint8_t bits) { \ 1952 if (arg == 0) return bits; \ 1953 return zig_builtin##w(clz, arg) - (zig_bitSizeOf(zig_Builtin##w) - bits); \ 1954 } \ 1955 \ 1956 zig_builtin_clz_common(w) 1957 #else 1958 #define zig_builtin_clz(w) \ 1959 static inline uint8_t zig_clz_u##w(uint##w##_t arg, uint8_t bits) { \ 1960 return zig_ctz_u##w(zig_bitReverse_u##w(arg, bits), bits); \ 1961 } \ 1962 \ 1963 zig_builtin_clz_common(w) 1964 #endif 1965 zig_builtin_clz(8) 1966 zig_builtin_clz(16) 1967 zig_builtin_clz(32) 1968 zig_builtin_clz(64) 1969 #if defined(zig_ez80) 1970 zig_builtin_clz(24) 1971 zig_builtin_clz(48) 1972 #endif 1973 1974 /* ======================== 128-bit Integer Support ========================= */ 1975 1976 #if !defined(zig_has_int128) 1977 # if defined(__SIZEOF_INT128__) 1978 # define zig_has_int128 1 1979 # else 1980 # define zig_has_int128 0 1981 # endif 1982 #endif 1983 1984 #if zig_has_int128 1985 1986 typedef unsigned __int128 zig_u128; 1987 typedef signed __int128 zig_i128; 1988 1989 #define zig_init_u128(hi, lo) ((zig_u128)(hi)<<64|(lo)) 1990 #define zig_init_i128(hi, lo) ((zig_i128)zig_make_u128(hi, lo)) 1991 #define zig_make_u128(hi, lo) zig_init_u128(hi, lo) 1992 #define zig_make_i128(hi, lo) zig_init_i128(hi, lo) 1993 #define zig_hi_u128(arg) ((uint64_t)((arg) >> 64)) 1994 #define zig_lo_u128(arg) ((uint64_t)((arg) >> 0)) 1995 #define zig_hi_i128(arg) (( int64_t)((arg) >> 64)) 1996 #define zig_lo_i128(arg) ((uint64_t)((arg) >> 0)) 1997 #define zig_cmp_int128(Type) \ 1998 static inline int32_t zig_cmp_##Type(zig_##Type lhs, zig_##Type rhs) { \ 1999 return (lhs > rhs) - (lhs < rhs); \ 2000 } 2001 #define zig_bit_int128(Type, operation, operator) \ 2002 static inline zig_##Type zig_##operation##_##Type(zig_##Type lhs, zig_##Type rhs) { \ 2003 return lhs operator rhs; \ 2004 } 2005 2006 static inline zig_u128 zig_shl_u128(zig_u128 lhs, uint8_t rhs) { 2007 return lhs << rhs; 2008 } 2009 2010 static inline zig_u128 zig_shr_u128(zig_u128 lhs, uint8_t rhs) { 2011 return lhs >> rhs; 2012 } 2013 2014 static inline zig_i128 zig_shl_i128(zig_i128 lhs, uint8_t rhs) { 2015 return lhs << rhs; 2016 } 2017 2018 static inline zig_i128 zig_shr_i128(zig_i128 lhs, uint8_t rhs) { 2019 // This works around a GCC miscompilation, but it has the side benefit of 2020 // emitting better code. It is behind the `#if` because it depends on 2021 // arithmetic right shift, which is implementation-defined in C, but should 2022 // be guaranteed on any GCC-compatible compiler. 2023 #if defined(zig_gnuc) 2024 return lhs >> rhs; 2025 #else 2026 zig_i128 sign_mask = lhs < zig_make_i128(0, 0) ? -zig_make_i128(0, 1) : zig_make_i128(0, 0); 2027 return ((lhs ^ sign_mask) >> rhs) ^ sign_mask; 2028 #endif 2029 } 2030 2031 #else /* zig_has_int128 */ 2032 2033 #if zig_little_endian 2034 typedef struct { zig_align(ZIG_TARGET_MAX_INT_ALIGNMENT) uint64_t lo; uint64_t hi; } zig_u128; 2035 typedef struct { zig_align(ZIG_TARGET_MAX_INT_ALIGNMENT) uint64_t lo; int64_t hi; } zig_i128; 2036 #else 2037 typedef struct { zig_align(ZIG_TARGET_MAX_INT_ALIGNMENT) uint64_t hi; uint64_t lo; } zig_u128; 2038 typedef struct { zig_align(ZIG_TARGET_MAX_INT_ALIGNMENT) int64_t hi; uint64_t lo; } zig_i128; 2039 #endif 2040 2041 #define zig_init_u128(hi, lo) { .h##i = hi, .l##o = lo } 2042 #define zig_init_i128(hi, lo) { .h##i = hi, .l##o = lo } 2043 #define zig_make_u128(hi, lo) (zig_u128)zig_init_u128(hi, lo) 2044 #define zig_make_i128(hi, lo) (zig_i128)zig_init_i128(hi, lo) 2045 #define zig_hi_u128(arg) (arg).hi 2046 #define zig_lo_u128(arg) (arg).lo 2047 #define zig_hi_i128(arg) (arg).hi 2048 #define zig_lo_i128(arg) (arg).lo 2049 #define zig_cmp_int128(Type) \ 2050 static inline int32_t zig_cmp_##Type(zig_##Type lhs, zig_##Type rhs) { \ 2051 return (lhs.hi == rhs.hi) \ 2052 ? (lhs.lo > rhs.lo) - (lhs.lo < rhs.lo) \ 2053 : (lhs.hi > rhs.hi) - (lhs.hi < rhs.hi); \ 2054 } 2055 #define zig_bit_int128(Type, operation, operator) \ 2056 static inline zig_##Type zig_##operation##_##Type(zig_##Type lhs, zig_##Type rhs) { \ 2057 return (zig_##Type){ .hi = lhs.hi operator rhs.hi, .lo = lhs.lo operator rhs.lo }; \ 2058 } 2059 2060 static inline zig_u128 zig_shl_u128(zig_u128 lhs, uint8_t rhs) { 2061 if (rhs == UINT8_C(0)) return lhs; 2062 if (rhs >= UINT8_C(64)) return (zig_u128){ .hi = lhs.lo << (rhs - UINT8_C(64)), .lo = zig_minInt_u64 }; 2063 return (zig_u128){ .hi = lhs.hi << rhs | lhs.lo >> (UINT8_C(64) - rhs), .lo = lhs.lo << rhs }; 2064 } 2065 2066 static inline zig_u128 zig_shr_u128(zig_u128 lhs, uint8_t rhs) { 2067 if (rhs == UINT8_C(0)) return lhs; 2068 if (rhs >= UINT8_C(64)) return (zig_u128){ .hi = zig_minInt_u64, .lo = lhs.hi >> (rhs - UINT8_C(64)) }; 2069 return (zig_u128){ .hi = lhs.hi >> rhs, .lo = lhs.hi << (UINT8_C(64) - rhs) | lhs.lo >> rhs }; 2070 } 2071 2072 static inline zig_i128 zig_shl_i128(zig_i128 lhs, uint8_t rhs) { 2073 if (rhs == UINT8_C(0)) return lhs; 2074 if (rhs >= UINT8_C(64)) return (zig_i128){ .hi = lhs.lo << (rhs - UINT8_C(64)), .lo = zig_minInt_u64 }; 2075 return (zig_i128){ .hi = lhs.hi << rhs | lhs.lo >> (UINT8_C(64) - rhs), .lo = lhs.lo << rhs }; 2076 } 2077 2078 static inline zig_i128 zig_shr_i128(zig_i128 lhs, uint8_t rhs) { 2079 if (rhs == UINT8_C(0)) return lhs; 2080 if (rhs >= UINT8_C(64)) return (zig_i128){ .hi = zig_shr_i64(lhs.hi, 63), .lo = zig_shr_i64(lhs.hi, (rhs - UINT8_C(64))) }; 2081 return (zig_i128){ .hi = zig_shr_i64(lhs.hi, rhs), .lo = lhs.lo >> rhs | (uint64_t)lhs.hi << (UINT8_C(64) - rhs) }; 2082 } 2083 2084 #endif /* zig_has_int128 */ 2085 2086 #define zig_minInt_u128 zig_make_u128(zig_minInt_u64, zig_minInt_u64) 2087 #define zig_maxInt_u128 zig_make_u128(zig_maxInt_u64, zig_maxInt_u64) 2088 #define zig_minInt_i128 zig_make_i128(zig_minInt_i64, zig_minInt_u64) 2089 #define zig_maxInt_i128 zig_make_i128(zig_maxInt_i64, zig_maxInt_u64) 2090 2091 zig_cmp_int128(u128) 2092 zig_cmp_int128(i128) 2093 2094 zig_bit_int128(u128, and, &) 2095 zig_bit_int128(i128, and, &) 2096 2097 zig_bit_int128(u128, or, |) 2098 zig_bit_int128(i128, or, |) 2099 2100 zig_bit_int128(u128, xor, ^) 2101 zig_bit_int128(i128, xor, ^) 2102 2103 static inline uint8_t zig_u8_intCast_u128(zig_u128 arg) { 2104 return (uint8_t)zig_lo_u128(arg); 2105 } 2106 static inline uint8_t zig_u8_intCast_i128(zig_i128 arg) { 2107 return (uint8_t)zig_lo_i128(arg); 2108 } 2109 static inline int8_t zig_i8_intCast_i128(zig_i128 arg) { 2110 return (int8_t)zig_lo_i128(arg); 2111 } 2112 static inline int8_t zig_i8_intCast_u128(zig_u128 arg) { 2113 return (int8_t)zig_lo_u128(arg); 2114 } 2115 2116 static inline uint16_t zig_u16_intCast_u128(zig_u128 arg) { 2117 return (uint16_t)zig_lo_u128(arg); 2118 } 2119 static inline uint16_t zig_u16_intCast_i128(zig_i128 arg) { 2120 return (uint16_t)zig_lo_i128(arg); 2121 } 2122 static inline int16_t zig_i16_intCast_i128(zig_i128 arg) { 2123 return (int16_t)zig_lo_i128(arg); 2124 } 2125 static inline int16_t zig_i16_intCast_u128(zig_u128 arg) { 2126 return (int16_t)zig_lo_u128(arg); 2127 } 2128 2129 static inline uint32_t zig_u32_intCast_u128(zig_u128 arg) { 2130 return (uint32_t)zig_lo_u128(arg); 2131 } 2132 static inline uint32_t zig_u32_intCast_i128(zig_i128 arg) { 2133 return (uint32_t)zig_lo_i128(arg); 2134 } 2135 static inline int32_t zig_i32_intCast_i128(zig_i128 arg) { 2136 return (int32_t)zig_lo_i128(arg); 2137 } 2138 static inline int32_t zig_i32_intCast_u128(zig_u128 arg) { 2139 return (int32_t)zig_lo_u128(arg); 2140 } 2141 2142 static inline uint64_t zig_u64_intCast_u128(zig_u128 arg) { 2143 return zig_lo_u128(arg); 2144 } 2145 static inline uint64_t zig_u64_intCast_i128(zig_i128 arg) { 2146 return zig_lo_i128(arg); 2147 } 2148 static inline int64_t zig_i64_intCast_i128(zig_i128 arg) { 2149 return (int64_t)zig_lo_i128(arg); 2150 } 2151 static inline int64_t zig_i64_intCast_u128(zig_u128 arg) { 2152 return (int64_t)zig_lo_u128(arg); 2153 } 2154 2155 static inline zig_u128 zig_u128_intCast_u8(uint8_t arg) { 2156 return zig_make_u128(UINT8_C(0), arg); 2157 } 2158 static inline zig_u128 zig_u128_intCast_i8(int8_t arg) { 2159 return zig_make_u128(UINT8_C(0), (uint8_t)arg); 2160 } 2161 static inline zig_i128 zig_i128_intCast_i8(int8_t arg) { 2162 return zig_make_i128(zig_shr_i64(arg, 63), (uint8_t)arg); 2163 } 2164 static inline zig_i128 zig_i128_intCast_u8(uint8_t arg) { 2165 return zig_make_i128(INT8_C(0), arg); 2166 } 2167 2168 static inline zig_u128 zig_u128_intCast_u16(uint16_t arg) { 2169 return zig_make_u128(UINT16_C(0), arg); 2170 } 2171 static inline zig_u128 zig_u128_intCast_i16(int16_t arg) { 2172 return zig_make_u128(UINT16_C(0), (uint16_t)arg); 2173 } 2174 static inline zig_i128 zig_i128_intCast_i16(int16_t arg) { 2175 return zig_make_i128(zig_shr_i64(arg, 63), (uint16_t)arg); 2176 } 2177 static inline zig_i128 zig_i128_intCast_u16(uint16_t arg) { 2178 return zig_make_i128(INT16_C(0), arg); 2179 } 2180 2181 static inline zig_u128 zig_u128_intCast_u32(uint32_t arg) { 2182 return zig_make_u128(UINT32_C(0), arg); 2183 } 2184 static inline zig_u128 zig_u128_intCast_i32(int32_t arg) { 2185 return zig_make_u128(UINT32_C(0), (uint32_t)arg); 2186 } 2187 static inline zig_i128 zig_i128_intCast_i32(int32_t arg) { 2188 return zig_make_i128(zig_shr_i64(arg, 63), (uint32_t)arg); 2189 } 2190 static inline zig_i128 zig_i128_intCast_u32(uint32_t arg) { 2191 return zig_make_i128(INT32_C(0), arg); 2192 } 2193 2194 static inline zig_u128 zig_u128_intCast_u64(uint64_t arg) { 2195 return zig_make_u128(UINT64_C(0), arg); 2196 } 2197 static inline zig_u128 zig_u128_intCast_i64(int64_t arg) { 2198 return zig_make_u128(UINT64_C(0), (uint64_t)arg); 2199 } 2200 static inline zig_i128 zig_i128_intCast_i64(int64_t arg) { 2201 return zig_make_i128(zig_shr_i64(arg, 63), (uint64_t)arg); 2202 } 2203 static inline zig_i128 zig_i128_intCast_u64(uint64_t arg) { 2204 return zig_make_i128(INT64_C(0), arg); 2205 } 2206 2207 static inline zig_u128 zig_u128_intCast_u128(zig_u128 arg) { 2208 return arg; 2209 } 2210 static inline zig_u128 zig_u128_intCast_i128(zig_i128 arg) { 2211 #if zig_has_int128 2212 return (zig_u128)arg; 2213 #else 2214 return zig_make_u128(zig_u64_bitCast_i64(zig_hi_i128(arg), UINT8_C(64)), zig_lo_u128(arg)); 2215 #endif 2216 } 2217 static inline zig_i128 zig_i128_intCast_i128(zig_i128 arg) { 2218 return arg; 2219 } 2220 static inline zig_i128 zig_i128_intCast_u128(zig_u128 arg) { 2221 #if zig_has_int128 2222 return (zig_i128)arg; 2223 #else 2224 return zig_make_i128(zig_i64_bitCast_u64(zig_hi_i128(arg), UINT8_C(64)), zig_lo_u128(arg)); 2225 #endif 2226 } 2227 2228 #define zig_int128_cast_builtins(w) \ 2229 static inline uint##w##_t zig_u##w##_truncate_u128(zig_u128 arg, uint8_t bits) { \ 2230 return zig_u##w##_truncate_u##w((uint##w##_t)zig_lo_u128(arg), bits); \ 2231 } \ 2232 \ 2233 static inline int##w##_t zig_i##w##_truncate_i128(zig_i128 arg, uint8_t bits) { \ 2234 return zig_i##w##_truncate_i##w((int##w##_t)zig_lo_i128(arg), bits); \ 2235 } 2236 zig_int128_cast_builtins(8) 2237 zig_int128_cast_builtins(16) 2238 zig_int128_cast_builtins(32) 2239 zig_int128_cast_builtins(64) 2240 2241 static inline zig_u128 zig_u128_truncate_u128(zig_u128 arg, uint8_t bits) { 2242 return zig_and_u128(arg, zig_maxInt_u(128, bits)); 2243 } 2244 static inline zig_i128 zig_i128_truncate_i128(zig_i128 arg, uint8_t bits) { 2245 if (bits > UINT8_C(64)) return zig_make_i128(zig_i64_truncate_i64(zig_hi_i128(arg), bits - UINT8_C(64)), zig_lo_i128(arg)); 2246 int64_t lo = zig_i64_truncate_i128(arg, bits); 2247 return zig_make_i128(zig_shr_i64(lo, 63), (uint64_t)lo); 2248 } 2249 2250 static inline zig_u128 zig_u128_bitCast_u128(zig_u128 arg, uint8_t bits) { 2251 (void)bits; 2252 return arg; 2253 } 2254 static inline zig_u128 zig_u128_bitCast_i128(zig_i128 arg, uint8_t bits) { 2255 return zig_u128_truncate_u128(zig_u128_intCast_i128(arg), bits); 2256 } 2257 static inline zig_i128 zig_i128_bitCast_i128(zig_i128 arg, uint8_t bits) { 2258 (void)bits; 2259 return arg; 2260 } 2261 static inline zig_i128 zig_i128_bitCast_u128(zig_u128 arg, uint8_t bits) { 2262 return zig_i128_truncate_i128(zig_i128_intCast_u128(arg), bits); 2263 } 2264 2265 #if zig_has_int128 2266 2267 static inline zig_u128 zig_not_u128(zig_u128 arg, uint8_t bits) { 2268 return arg ^ zig_maxInt_u(128, bits); 2269 } 2270 2271 static inline zig_i128 zig_not_i128(zig_i128 arg, uint8_t bits) { 2272 (void)bits; 2273 return ~arg; 2274 } 2275 2276 static inline zig_u128 zig_add_u128(zig_u128 lhs, zig_u128 rhs) { 2277 return lhs + rhs; 2278 } 2279 2280 static inline zig_i128 zig_add_i128(zig_i128 lhs, zig_i128 rhs) { 2281 return lhs + rhs; 2282 } 2283 2284 static inline zig_u128 zig_sub_u128(zig_u128 lhs, zig_u128 rhs) { 2285 return lhs - rhs; 2286 } 2287 2288 static inline zig_i128 zig_sub_i128(zig_i128 lhs, zig_i128 rhs) { 2289 return lhs - rhs; 2290 } 2291 2292 static inline zig_u128 zig_mul_u128(zig_u128 lhs, zig_u128 rhs) { 2293 return lhs * rhs; 2294 } 2295 2296 static inline zig_i128 zig_mul_i128(zig_i128 lhs, zig_i128 rhs) { 2297 return lhs * rhs; 2298 } 2299 2300 static inline zig_u128 zig_divTrunc_u128(zig_u128 lhs, zig_u128 rhs) { 2301 return lhs / rhs; 2302 } 2303 2304 static inline zig_i128 zig_divTrunc_i128(zig_i128 lhs, zig_i128 rhs) { 2305 return lhs / rhs; 2306 } 2307 2308 static inline zig_u128 zig_rem_u128(zig_u128 lhs, zig_u128 rhs) { 2309 return lhs % rhs; 2310 } 2311 2312 static inline zig_i128 zig_rem_i128(zig_i128 lhs, zig_i128 rhs) { 2313 return lhs % rhs; 2314 } 2315 2316 #else /* zig_has_int128 */ 2317 2318 static inline zig_u128 zig_not_u128(zig_u128 arg, uint8_t bits) { 2319 if (bits <= UINT8_C(64)) return (zig_u128){ .hi = UINT64_C(0), .lo = zig_not_u64(arg.lo, bits) }; 2320 return (zig_u128){ .hi = zig_not_u64(arg.hi, bits - UINT8_C(64)), .lo = zig_not_u64(arg.lo, UINT8_C(64)) }; 2321 } 2322 2323 static inline zig_i128 zig_not_i128(zig_i128 arg, uint8_t bits) { 2324 (void)bits; 2325 return (zig_i128){ .hi = ~arg.hi, .lo = ~arg.lo }; 2326 } 2327 2328 static inline zig_u128 zig_add_u128(zig_u128 lhs, zig_u128 rhs) { 2329 zig_u128 res; 2330 res.hi = lhs.hi + rhs.hi + zig_addo_u64(&res.lo, lhs.lo, rhs.lo, 64); 2331 return res; 2332 } 2333 2334 static inline zig_i128 zig_add_i128(zig_i128 lhs, zig_i128 rhs) { 2335 zig_i128 res; 2336 res.hi = lhs.hi + rhs.hi + zig_addo_u64(&res.lo, lhs.lo, rhs.lo, 64); 2337 return res; 2338 } 2339 2340 static inline zig_u128 zig_sub_u128(zig_u128 lhs, zig_u128 rhs) { 2341 zig_u128 res; 2342 res.hi = lhs.hi - rhs.hi - zig_subo_u64(&res.lo, lhs.lo, rhs.lo, 64); 2343 return res; 2344 } 2345 2346 static inline zig_i128 zig_sub_i128(zig_i128 lhs, zig_i128 rhs) { 2347 zig_i128 res; 2348 res.hi = lhs.hi - rhs.hi - zig_subo_u64(&res.lo, lhs.lo, rhs.lo, 64); 2349 return res; 2350 } 2351 2352 static zig_i128 zig_mul_i128(zig_i128 lhs, zig_i128 rhs) { 2353 zig_extern zig_i128 __multi3(zig_i128 lhs, zig_i128 rhs); 2354 return __multi3(lhs, rhs); 2355 } 2356 2357 static zig_u128 zig_mul_u128(zig_u128 lhs, zig_u128 rhs) { 2358 return zig_u128_bitCast_i128(zig_mul_i128(zig_i128_bitCast_u128(lhs, UINT8_C(128)), zig_i128_bitCast_u128(rhs, UINT8_C(128))), UINT8_C(128)); 2359 } 2360 2361 static zig_u128 zig_divTrunc_u128(zig_u128 lhs, zig_u128 rhs) { 2362 zig_extern zig_u128 __udivti3(zig_u128 lhs, zig_u128 rhs); 2363 return __udivti3(lhs, rhs); 2364 } 2365 2366 static zig_i128 zig_divTrunc_i128(zig_i128 lhs, zig_i128 rhs) { 2367 zig_extern zig_i128 __divti3(zig_i128 lhs, zig_i128 rhs); 2368 return __divti3(lhs, rhs); 2369 } 2370 2371 static zig_u128 zig_rem_u128(zig_u128 lhs, zig_u128 rhs) { 2372 zig_extern zig_u128 __umodti3(zig_u128 lhs, zig_u128 rhs); 2373 return __umodti3(lhs, rhs); 2374 } 2375 2376 static zig_i128 zig_rem_i128(zig_i128 lhs, zig_i128 rhs) { 2377 zig_extern zig_i128 __modti3(zig_i128 lhs, zig_i128 rhs); 2378 return __modti3(lhs, rhs); 2379 } 2380 2381 #endif /* zig_has_int128 */ 2382 2383 #define zig_divFloor_u128 zig_divTrunc_u128 2384 2385 static inline zig_i128 zig_divFloor_i128(zig_i128 lhs, zig_i128 rhs) { 2386 zig_i128 rem = zig_rem_i128(lhs, rhs); 2387 int64_t mask = zig_or_u64((uint64_t)zig_hi_i128(rem), zig_lo_i128(rem)) != UINT64_C(0) 2388 ? zig_shr_i64(zig_xor_i64(zig_hi_i128(lhs), zig_hi_i128(rhs)), UINT8_C(63)) : INT64_C(0); 2389 return zig_add_i128(zig_divTrunc_i128(lhs, rhs), zig_make_i128(mask, (uint64_t)mask)); 2390 } 2391 2392 static inline zig_u128 zig_divCeil_u128(zig_u128 lhs, zig_u128 rhs) { 2393 zig_u128 rem = zig_rem_u128(lhs, rhs); 2394 uint64_t mask = zig_or_u64(zig_hi_u128(rem), zig_lo_u128(rem)) != UINT64_C(0) 2395 ? UINT64_C(1) : UINT64_C(0); 2396 return zig_add_u128(zig_divTrunc_u128(lhs, rhs), zig_make_u128(UINT64_C(0), mask)); 2397 } 2398 2399 static inline zig_i128 zig_divCeil_i128(zig_i128 lhs, zig_i128 rhs) { 2400 zig_i128 rem = zig_rem_i128(lhs, rhs); 2401 int64_t mask = zig_or_u64((uint64_t)zig_hi_i128(rem), zig_lo_i128(rem)) != UINT64_C(0) 2402 ? zig_shr_i64(zig_xor_i64(zig_hi_i128(lhs), zig_hi_i128(rhs)), UINT8_C(63)) + INT64_C(1) 2403 : INT64_C(0); 2404 return zig_add_i128(zig_divTrunc_i128(lhs, rhs), zig_make_i128(INT64_C(0), (uint64_t)mask)); 2405 } 2406 2407 #define zig_mod_u128 zig_rem_u128 2408 2409 static inline zig_i128 zig_mod_i128(zig_i128 lhs, zig_i128 rhs) { 2410 zig_i128 rem = zig_rem_i128(lhs, rhs); 2411 int64_t mask = zig_or_u64((uint64_t)zig_hi_i128(rem), zig_lo_i128(rem)) != UINT64_C(0) 2412 ? zig_shr_i64(zig_xor_i64(zig_hi_i128(lhs), zig_hi_i128(rhs)), UINT8_C(63)) : INT64_C(0); 2413 return zig_add_i128(rem, zig_and_i128(rhs, zig_make_i128(mask, (uint64_t)mask))); 2414 } 2415 2416 static inline zig_u128 zig_min_u128(zig_u128 lhs, zig_u128 rhs) { 2417 return zig_cmp_u128(lhs, rhs) < INT32_C(0) ? lhs : rhs; 2418 } 2419 2420 static inline zig_i128 zig_min_i128(zig_i128 lhs, zig_i128 rhs) { 2421 return zig_cmp_i128(lhs, rhs) < INT32_C(0) ? lhs : rhs; 2422 } 2423 2424 static inline zig_u128 zig_max_u128(zig_u128 lhs, zig_u128 rhs) { 2425 return zig_cmp_u128(lhs, rhs) > INT32_C(0) ? lhs : rhs; 2426 } 2427 2428 static inline zig_i128 zig_max_i128(zig_i128 lhs, zig_i128 rhs) { 2429 return zig_cmp_i128(lhs, rhs) > INT32_C(0) ? lhs : rhs; 2430 } 2431 2432 static inline zig_u128 zig_shlw_u128(zig_u128 lhs, uint8_t rhs, uint8_t bits) { 2433 return zig_u128_truncate_u128(zig_shl_u128(lhs, rhs), bits); 2434 } 2435 2436 static inline zig_i128 zig_shlw_i128(zig_i128 lhs, uint8_t rhs, uint8_t bits) { 2437 return zig_i128_truncate_i128(zig_i128_bitCast_u128(zig_shl_u128(zig_u128_bitCast_i128(lhs, bits), rhs), bits), bits); 2438 } 2439 2440 static inline zig_u128 zig_addw_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) { 2441 return zig_u128_truncate_u128(zig_add_u128(lhs, rhs), bits); 2442 } 2443 2444 static inline zig_i128 zig_addw_i128(zig_i128 lhs, zig_i128 rhs, uint8_t bits) { 2445 return zig_i128_truncate_i128(zig_i128_bitCast_u128(zig_add_u128(zig_u128_bitCast_i128(lhs, bits), zig_u128_bitCast_i128(rhs, bits)), bits), bits); 2446 } 2447 2448 static inline zig_u128 zig_subw_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) { 2449 return zig_u128_truncate_u128(zig_sub_u128(lhs, rhs), bits); 2450 } 2451 2452 static inline zig_i128 zig_subw_i128(zig_i128 lhs, zig_i128 rhs, uint8_t bits) { 2453 return zig_i128_truncate_i128(zig_i128_bitCast_u128(zig_sub_u128(zig_u128_bitCast_i128(lhs, bits), zig_u128_bitCast_i128(rhs, bits)), bits), bits); 2454 } 2455 2456 static inline zig_u128 zig_mulw_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) { 2457 return zig_u128_truncate_u128(zig_mul_u128(lhs, rhs), bits); 2458 } 2459 2460 static inline zig_i128 zig_mulw_i128(zig_i128 lhs, zig_i128 rhs, uint8_t bits) { 2461 return zig_i128_truncate_i128(zig_i128_bitCast_u128(zig_mul_u128(zig_u128_bitCast_i128(lhs, bits), zig_u128_bitCast_i128(rhs, bits)), bits), bits); 2462 } 2463 2464 static inline zig_u128 zig_abs_i128(zig_i128 arg) { 2465 zig_u128 tmp = zig_u128_bitCast_i128(zig_shr_i128(arg, 127), UINT8_C(128)); 2466 return zig_sub_u128(zig_xor_u128(zig_u128_bitCast_i128(arg, UINT8_C(128)), tmp), tmp); 2467 } 2468 2469 #if zig_has_int128 2470 2471 static inline bool zig_addo_u128(zig_u128 *res, zig_u128 lhs, zig_u128 rhs, uint8_t bits) { 2472 #if zig_has_builtin(add_overflow) 2473 zig_u128 full_res; 2474 bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); 2475 *res = zig_u128_truncate_u128(full_res, bits); 2476 return overflow || full_res < zig_minInt_u(128, bits) || full_res > zig_maxInt_u(128, bits); 2477 #else 2478 *res = zig_addw_u128(lhs, rhs, bits); 2479 return *res < lhs; 2480 #endif 2481 } 2482 2483 static inline bool zig_addo_i128(zig_i128 *res, zig_i128 lhs, zig_i128 rhs, uint8_t bits) { 2484 #if zig_has_builtin(add_overflow) 2485 zig_i128 full_res; 2486 bool overflow = __builtin_add_overflow(lhs, rhs, &full_res); 2487 #else 2488 zig_i128 full_res = (zig_i128)((zig_u128)lhs + (zig_u128)rhs); 2489 bool overflow = ((full_res ^ lhs) & (full_res ^ rhs)) < 0; 2490 #endif 2491 *res = zig_i128_truncate_i128(full_res, bits); 2492 return overflow || full_res < zig_minInt_i(128, bits) || full_res > zig_maxInt_i(128, bits); 2493 } 2494 2495 static inline bool zig_subo_u128(zig_u128 *res, zig_u128 lhs, zig_u128 rhs, uint8_t bits) { 2496 #if zig_has_builtin(sub_overflow) 2497 zig_u128 full_res; 2498 bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); 2499 *res = zig_u128_truncate_u128(full_res, bits); 2500 return overflow || full_res < zig_minInt_u(128, bits) || full_res > zig_maxInt_u(128, bits); 2501 #else 2502 *res = zig_subw_u128(lhs, rhs, bits); 2503 return *res > lhs; 2504 #endif 2505 } 2506 2507 static inline bool zig_subo_i128(zig_i128 *res, zig_i128 lhs, zig_i128 rhs, uint8_t bits) { 2508 #if zig_has_builtin(sub_overflow) 2509 zig_i128 full_res; 2510 bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res); 2511 #else 2512 zig_i128 full_res = (zig_i128)((zig_u128)lhs - (zig_u128)rhs); 2513 bool overflow = ((lhs ^ rhs) & (full_res ^ lhs)) < 0; 2514 #endif 2515 *res = zig_i128_truncate_i128(full_res, bits); 2516 return overflow || full_res < zig_minInt_i(128, bits) || full_res > zig_maxInt_i(128, bits); 2517 } 2518 2519 static inline bool zig_mulo_u128(zig_u128 *res, zig_u128 lhs, zig_u128 rhs, uint8_t bits) { 2520 #if zig_has_builtin(mul_overflow) 2521 zig_u128 full_res; 2522 bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); 2523 *res = zig_u128_truncate_u128(full_res, bits); 2524 return overflow || full_res < zig_minInt_u(128, bits) || full_res > zig_maxInt_u(128, bits); 2525 #else 2526 *res = zig_mulw_u128(lhs, rhs, bits); 2527 return rhs != zig_make_u128(0, 0) && lhs > zig_maxInt_u(128, bits) / rhs; 2528 #endif 2529 } 2530 2531 static inline bool zig_mulo_i128(zig_i128 *res, zig_i128 lhs, zig_i128 rhs, uint8_t bits) { 2532 zig_extern zig_i128 __muloti4(zig_i128 lhs, zig_i128 rhs, int *overflow); 2533 #if zig_has_builtin(mul_overflow) 2534 zig_i128 full_res; 2535 bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res); 2536 #else 2537 int overflow_int; 2538 zig_i128 full_res = __muloti4(lhs, rhs, &overflow_int); 2539 bool overflow = overflow_int != 0; 2540 #endif 2541 *res = zig_i128_truncate_i128(full_res, bits); 2542 return overflow || full_res < zig_minInt_i(128, bits) || full_res > zig_maxInt_i(128, bits); 2543 } 2544 2545 #else /* zig_has_int128 */ 2546 2547 static inline bool zig_addo_u128(zig_u128 *res, zig_u128 lhs, zig_u128 rhs, uint8_t bits) { 2548 if (bits <= UINT8_C(64)) { 2549 uint64_t lo; 2550 bool overflow = zig_addo_u64(&lo, zig_u64_intCast_u128(lhs), zig_u64_intCast_u128(rhs), bits); 2551 *res = zig_u128_intCast_u64(lo); 2552 return overflow; 2553 } else { 2554 uint64_t hi; 2555 bool overflow = zig_addo_u64(&hi, lhs.hi, rhs.hi, bits - UINT8_C(64)); 2556 return overflow ^ zig_addo_u64(&res->hi, hi, zig_addo_u64(&res->lo, lhs.lo, rhs.lo, UINT8_C(64)), bits - UINT8_C(64)); 2557 } 2558 } 2559 2560 static inline bool zig_addo_i128(zig_i128 *res, zig_i128 lhs, zig_i128 rhs, uint8_t bits) { 2561 if (bits <= UINT8_C(64)) { 2562 int64_t lo; 2563 bool overflow = zig_addo_i64(&lo, zig_i64_intCast_i128(lhs), zig_i64_intCast_i128(rhs), bits); 2564 *res = zig_i128_intCast_i64(lo); 2565 return overflow; 2566 } else { 2567 int64_t hi; 2568 bool overflow = zig_addo_i64(&hi, lhs.hi, rhs.hi, bits - UINT8_C(64)); 2569 return overflow ^ zig_addo_i64(&res->hi, hi, zig_addo_u64(&res->lo, lhs.lo, rhs.lo, UINT8_C(64)), bits - UINT8_C(64)); 2570 } 2571 } 2572 2573 static inline bool zig_subo_u128(zig_u128 *res, zig_u128 lhs, zig_u128 rhs, uint8_t bits) { 2574 if (bits <= UINT8_C(64)) { 2575 uint64_t lo; 2576 bool overflow = zig_subo_u64(&lo, zig_u64_intCast_u128(lhs), zig_u64_intCast_u128(rhs), bits); 2577 *res = zig_u128_intCast_u64(lo); 2578 return overflow; 2579 } else { 2580 uint64_t hi; 2581 bool overflow = zig_subo_u64(&hi, lhs.hi, rhs.hi, bits - UINT8_C(64)); 2582 return overflow ^ zig_subo_u64(&res->hi, hi, zig_subo_u64(&res->lo, lhs.lo, rhs.lo, UINT8_C(64)), bits - UINT8_C(64)); 2583 } 2584 } 2585 2586 static inline bool zig_subo_i128(zig_i128 *res, zig_i128 lhs, zig_i128 rhs, uint8_t bits) { 2587 if (bits <= UINT8_C(64)) { 2588 int64_t lo; 2589 bool overflow = zig_subo_i64(&lo, zig_i64_intCast_i128(lhs), zig_i64_intCast_i128(rhs), bits); 2590 *res = zig_i128_intCast_i64(lo); 2591 return overflow; 2592 } else { 2593 int64_t hi; 2594 bool overflow = zig_subo_i64(&hi, lhs.hi, rhs.hi, bits - UINT8_C(64)); 2595 return overflow ^ zig_subo_i64(&res->hi, hi, zig_subo_u64(&res->lo, lhs.lo, rhs.lo, UINT8_C(64)), bits - UINT8_C(64)); 2596 } 2597 } 2598 2599 static inline bool zig_mulo_u128(zig_u128 *res, zig_u128 lhs, zig_u128 rhs, uint8_t bits) { 2600 *res = zig_mulw_u128(lhs, rhs, bits); 2601 return zig_cmp_u128(rhs, zig_make_u128(0, 0)) != INT32_C(0) && 2602 zig_cmp_u128(lhs, zig_divTrunc_u128(zig_maxInt_u(128, bits), rhs)) > INT32_C(0); 2603 } 2604 2605 static inline bool zig_mulo_i128(zig_i128 *res, zig_i128 lhs, zig_i128 rhs, uint8_t bits) { 2606 zig_extern zig_i128 __muloti4(zig_i128 lhs, zig_i128 rhs, int *overflow); 2607 int overflow_int; 2608 zig_i128 full_res = __muloti4(lhs, rhs, &overflow_int); 2609 bool overflow = overflow_int != 0 || 2610 zig_cmp_i128(full_res, zig_minInt_i(128, bits)) < INT32_C(0) || 2611 zig_cmp_i128(full_res, zig_maxInt_i(128, bits)) > INT32_C(0); 2612 *res = zig_i128_truncate_i128(full_res, bits); 2613 return overflow; 2614 } 2615 2616 #endif /* zig_has_int128 */ 2617 2618 static inline bool zig_shlo_u128(zig_u128 *res, zig_u128 lhs, uint8_t rhs, uint8_t bits) { 2619 *res = zig_shlw_u128(lhs, rhs, bits); 2620 return zig_cmp_u128(lhs, zig_shr_u128(zig_maxInt_u(128, bits), rhs)) > INT32_C(0); 2621 } 2622 2623 static inline bool zig_shlo_i128(zig_i128 *res, zig_i128 lhs, uint8_t rhs, uint8_t bits) { 2624 *res = zig_shlw_i128(lhs, rhs, bits); 2625 zig_i128 mask = zig_i128_bitCast_u128(zig_shl_u128(zig_maxInt_u128, bits - rhs - UINT8_C(1)), bits); 2626 return zig_cmp_i128(zig_and_i128(lhs, mask), zig_make_i128(0, 0)) != INT32_C(0) && 2627 zig_cmp_i128(zig_and_i128(lhs, mask), mask) != INT32_C(0); 2628 } 2629 2630 #define zig_int128_shls_builtins(rw) \ 2631 static inline zig_u128 zig_shls_u128_u##rw(zig_u128 lhs, uint##rw##_t rhs, uint8_t bits) { \ 2632 zig_u128 res; \ 2633 if (rhs < bits && !zig_shlo_u128(&res, lhs, zig_u8_intCast_u##rw(rhs), bits)) return res; \ 2634 switch (zig_cmp_u128(lhs, zig_make_u128(UINT64_C(0), UINT64_C(0)))) { \ 2635 case 0: return zig_minInt_u(128, bits); \ 2636 case 1: return zig_maxInt_u(128, bits); \ 2637 default: zig_unreachable(); \ 2638 } \ 2639 } \ 2640 \ 2641 static inline zig_i128 zig_shls_i128_u##rw(zig_i128 lhs, uint##rw##_t rhs, uint8_t bits) { \ 2642 zig_i128 res; \ 2643 if (rhs < bits && !zig_shlo_i128(&res, lhs, zig_u8_intCast_u##rw(rhs), bits)) return res; \ 2644 switch (zig_cmp_i128(lhs, zig_make_i128(INT64_C(0), UINT64_C(0)))) { \ 2645 case -1: return zig_minInt_i(128, bits); \ 2646 case 0: return zig_make_i128(INT64_C(0), UINT64_C(0)); \ 2647 case 1: return zig_maxInt_i(128, bits); \ 2648 default: zig_unreachable(); \ 2649 } \ 2650 } 2651 zig_int128_shls_builtins(8) 2652 zig_int128_shls_builtins(16) 2653 zig_int128_shls_builtins(32) 2654 zig_int128_shls_builtins(64) 2655 2656 static inline zig_u128 zig_shls_u128_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) { 2657 zig_u128 res; 2658 if (zig_cmp_u128(rhs, zig_make_u128(0, bits)) < INT32_C(0) && !zig_shlo_u128(&res, lhs, (uint8_t)zig_lo_u128(rhs), bits)) return res; 2659 switch (zig_cmp_u128(lhs, zig_make_u128(0, 0))) { 2660 case INT32_C(0): return zig_make_u128(0, 0); 2661 case INT32_C(1): return zig_maxInt_u(128, bits); 2662 default: zig_unreachable(); 2663 } 2664 } 2665 2666 static inline zig_i128 zig_shls_i128_u128(zig_i128 lhs, zig_u128 rhs, uint8_t bits) { 2667 zig_i128 res; 2668 if (zig_cmp_u128(rhs, zig_make_u128(0, bits)) < INT32_C(0) && !zig_shlo_i128(&res, lhs, (uint8_t)zig_lo_u128(rhs), bits)) return res; 2669 switch (zig_cmp_i128(lhs, zig_make_i128(0, 0))) { 2670 case -INT32_C(1): return zig_minInt_i(128, bits); 2671 case INT32_C(0): return zig_make_i128(0, 0); 2672 case INT32_C(1): return zig_maxInt_i(128, bits); 2673 default: zig_unreachable(); 2674 } 2675 } 2676 2677 static inline zig_u128 zig_adds_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) { 2678 zig_u128 res; 2679 return zig_addo_u128(&res, lhs, rhs, bits) ? zig_maxInt_u(128, bits) : res; 2680 } 2681 2682 static inline zig_i128 zig_adds_i128(zig_i128 lhs, zig_i128 rhs, uint8_t bits) { 2683 zig_i128 res; 2684 if (!zig_addo_i128(&res, lhs, rhs, bits)) return res; 2685 return zig_cmp_i128(res, zig_make_i128(0, 0)) >= INT32_C(0) ? zig_minInt_i(128, bits) : zig_maxInt_i(128, bits); 2686 } 2687 2688 static inline zig_u128 zig_subs_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) { 2689 zig_u128 res; 2690 return zig_subo_u128(&res, lhs, rhs, bits) ? zig_minInt_u(128, bits) : res; 2691 } 2692 2693 static inline zig_i128 zig_subs_i128(zig_i128 lhs, zig_i128 rhs, uint8_t bits) { 2694 zig_i128 res; 2695 if (!zig_subo_i128(&res, lhs, rhs, bits)) return res; 2696 return zig_cmp_i128(res, zig_make_i128(0, 0)) >= INT32_C(0) ? zig_minInt_i(128, bits) : zig_maxInt_i(128, bits); 2697 } 2698 2699 static inline zig_u128 zig_muls_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) { 2700 zig_u128 res; 2701 return zig_mulo_u128(&res, lhs, rhs, bits) ? zig_maxInt_u(128, bits) : res; 2702 } 2703 2704 static inline zig_i128 zig_muls_i128(zig_i128 lhs, zig_i128 rhs, uint8_t bits) { 2705 zig_i128 res; 2706 if (!zig_mulo_i128(&res, lhs, rhs, bits)) return res; 2707 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); 2708 } 2709 2710 static inline uint8_t zig_clz_u128(zig_u128 arg, uint8_t bits) { 2711 if (bits <= UINT8_C(64)) return zig_clz_u64(zig_lo_u128(arg), bits); 2712 if (zig_hi_u128(arg) != 0) return zig_clz_u64(zig_hi_u128(arg), bits - UINT8_C(64)); 2713 return zig_clz_u64(zig_lo_u128(arg), UINT8_C(64)) + (bits - UINT8_C(64)); 2714 } 2715 2716 static inline uint8_t zig_clz_i128(zig_i128 arg, uint8_t bits) { 2717 return zig_clz_u128(zig_u128_bitCast_i128(arg, bits), bits); 2718 } 2719 2720 static inline uint8_t zig_ctz_u128(zig_u128 arg, uint8_t bits) { 2721 if (zig_lo_u128(arg) != 0) return zig_ctz_u64(zig_lo_u128(arg), UINT8_C(64)); 2722 return zig_ctz_u64(zig_hi_u128(arg), bits - UINT8_C(64)) + UINT8_C(64); 2723 } 2724 2725 static inline uint8_t zig_ctz_i128(zig_i128 arg, uint8_t bits) { 2726 return zig_ctz_u128(zig_u128_bitCast_i128(arg, bits), bits); 2727 } 2728 2729 static inline uint8_t zig_popCount_u128(zig_u128 arg, uint8_t bits) { 2730 return (bits > UINT8_C(64) ? zig_popCount_u64(zig_hi_u128(arg), bits - UINT8_C(64)) : UINT8_C(0)) + 2731 zig_popCount_u64(zig_lo_u128(arg), UINT8_C(64)); 2732 } 2733 2734 static inline uint8_t zig_popCount_i128(zig_i128 arg, uint8_t bits) { 2735 return zig_popCount_u128(zig_u128_bitCast_i128(arg, bits), bits); 2736 } 2737 2738 static inline zig_u128 zig_byteSwap_u128(zig_u128 arg, uint8_t bits) { 2739 zig_u128 full_res; 2740 #if zig_has_builtin(bswap128) 2741 full_res = __builtin_bswap128(arg); 2742 #else 2743 full_res = zig_make_u128( 2744 zig_byteSwap_u64(zig_lo_u128(arg), UINT8_C(64)), 2745 zig_byteSwap_u64(zig_hi_u128(arg), UINT8_C(64)) 2746 ); 2747 #endif 2748 return zig_shr_u128(full_res, UINT8_C(128) - bits); 2749 } 2750 2751 static inline zig_i128 zig_byteSwap_i128(zig_i128 arg, uint8_t bits) { 2752 return zig_i128_bitCast_u128(zig_byteSwap_u128(zig_u128_bitCast_i128(arg, bits), bits), bits); 2753 } 2754 2755 static inline zig_u128 zig_bitReverse_u128(zig_u128 arg, uint8_t bits) { 2756 return zig_shr_u128(zig_make_u128( 2757 zig_bitReverse_u64(zig_lo_u128(arg), UINT8_C(64)), 2758 zig_bitReverse_u64(zig_hi_u128(arg), UINT8_C(64)) 2759 ), UINT8_C(128) - bits); 2760 } 2761 2762 static inline zig_i128 zig_bitReverse_i128(zig_i128 arg, uint8_t bits) { 2763 return zig_i128_bitCast_u128(zig_bitReverse_u128(zig_u128_bitCast_i128(arg, bits), bits), bits); 2764 } 2765 2766 #if zig_has_int128 2767 #define zig_switch_int128(operand) switch (operand) 2768 #define zig_switch_prong_begin_int128() 2769 #define zig_switch_case_int128(Type, operand, value) case value: 2770 #define zig_switch_prong_end_int128() 2771 #define zig_switch_default_int128() default: 2772 #else // zig_has_int128 2773 #define zig_switch_int128(operand) 2774 #define zig_switch_prong_begin_int128() if (0 2775 #define zig_switch_case_int128(Type, operand, value) || (zig_cmp_##Type(operand, value) == 0) 2776 #define zig_switch_prong_end_int128() ) 2777 #define zig_switch_default_int128() 2778 #endif // zig_has_int128 2779 2780 /* ========================== Big Integer Support =========================== */ 2781 2782 static inline uint16_t zig_int_bytes(uint16_t bits) { 2783 uint16_t bytes = (bits - UINT16_C(1)) / CHAR_BIT + UINT16_C(1); 2784 uint16_t alignment = ZIG_TARGET_MAX_INT_ALIGNMENT; 2785 2786 while (alignment / 2 >= bytes) alignment /= 2; 2787 return (bytes + alignment - 1) / alignment * alignment; 2788 } 2789 2790 static inline void zig_minInt_big(void *res, bool is_signed, uint16_t bits) { 2791 uint8_t *res_bytes = res; 2792 uint16_t size = zig_int_bytes(bits); 2793 uint16_t byte_offset = zig_shr_u16(bits - UINT16_C(1), UINT8_C(3)); 2794 uint16_t remainder_bits = zig_u8_truncate_u16(bits - UINT16_C(1), UINT8_C(3)) + UINT8_C(1); 2795 uint8_t sign_byte; 2796 uint8_t fill_byte; 2797 2798 if (is_signed) { 2799 int8_t signed_sign_byte = zig_minInt_i(8, remainder_bits); 2800 2801 sign_byte = zig_u8_bitCast_i8(signed_sign_byte, UINT8_C(8)); 2802 fill_byte = zig_u8_bitCast_i8(zig_shr_i8(signed_sign_byte, UINT8_C(7)), UINT8_C(8)); 2803 } else { 2804 sign_byte = zig_minInt_u(8, remainder_bits); 2805 fill_byte = UINT8_C(0); 2806 } 2807 2808 #if zig_little_endian 2809 memset(&res_bytes[0], zig_minInt_u8, byte_offset); 2810 res_bytes[byte_offset] = sign_byte; 2811 byte_offset += UINT16_C(1); 2812 memset(&res_bytes[byte_offset], fill_byte, size - byte_offset); 2813 #else 2814 byte_offset = size - UINT16_C(1) - byte_offset; 2815 memset(&res_bytes[0], fill_byte, byte_offset); 2816 res_bytes[byte_offset] = sign_byte; 2817 byte_offset += UINT16_C(1); 2818 memset(&res_bytes[byte_offset], zig_minInt_u8, size - byte_offset); 2819 #endif 2820 } 2821 2822 static inline void zig_maxInt_big(void *res, bool is_signed, uint16_t bits) { 2823 uint8_t *res_bytes = res; 2824 uint16_t size = zig_int_bytes(bits); 2825 uint16_t byte_offset = zig_shr_u16(bits - UINT16_C(1), UINT8_C(3)); 2826 uint16_t remainder_bits = zig_u8_truncate_u16(bits - UINT16_C(1), UINT8_C(3)) + UINT8_C(1); 2827 uint8_t sign_byte; 2828 uint8_t fill_byte; 2829 2830 if (is_signed) { 2831 int8_t signed_sign_byte = zig_maxInt_i(8, remainder_bits); 2832 2833 sign_byte = zig_u8_bitCast_i8(signed_sign_byte, UINT8_C(8)); 2834 fill_byte = zig_u8_bitCast_i8(zig_shr_i8(signed_sign_byte, UINT8_C(7)), UINT8_C(8)); 2835 } else { 2836 sign_byte = zig_maxInt_u(8, remainder_bits); 2837 fill_byte = UINT8_C(0); 2838 } 2839 2840 #if zig_little_endian 2841 memset(&res_bytes[0], zig_maxInt_u8, byte_offset); 2842 res_bytes[byte_offset] = sign_byte; 2843 byte_offset += UINT16_C(1); 2844 memset(&res_bytes[byte_offset], fill_byte, size - byte_offset); 2845 #else 2846 byte_offset = size - UINT16_C(1) - byte_offset; 2847 memset(&res_bytes[0], fill_byte, byte_offset); 2848 res_bytes[byte_offset] = sign_byte; 2849 byte_offset += UINT16_C(1); 2850 memset(&res_bytes[byte_offset], zig_maxInt_u8, size - byte_offset); 2851 #endif 2852 } 2853 2854 static inline int8_t zig_signFill_big(const void *arg, bool is_signed, uint16_t bits) { 2855 const uint8_t *arg_bytes = arg; 2856 uint16_t byte_offset = 0; 2857 2858 if (!is_signed) return INT8_C(0); 2859 #if zig_little_endian 2860 byte_offset = zig_int_bytes(bits) - 1; 2861 #endif 2862 return zig_shr_i8(zig_i8_bitCast_u8(arg_bytes[byte_offset], UINT8_C(8)), UINT8_C(7)); 2863 } 2864 2865 static inline void zig_big_intCast_big(void *res, const void *arg, bool res_is_signed, uint16_t res_bits, bool arg_is_signed, uint16_t arg_bits) { 2866 uint8_t *res_bytes = res; 2867 const uint8_t *arg_bytes = arg; 2868 uint16_t res_size = zig_int_bytes(res_bits); 2869 uint16_t arg_size = zig_int_bytes(arg_bits); 2870 uint16_t copy_size = zig_min_u16(res_size, arg_size); 2871 uint8_t sign_fill = zig_u8_bitCast_i8(zig_signFill_big(arg, arg_is_signed, arg_bits), UINT8_C(8)); 2872 2873 #if zig_little_endian 2874 memcpy(&res_bytes[0], &arg_bytes[0], copy_size); 2875 memset(&res_bytes[copy_size], sign_fill, res_size - copy_size); 2876 #else 2877 memset(&res_bytes[0], sign_fill, res_size - copy_size); 2878 memcpy(&res_bytes[res_size - copy_size], &arg_bytes[arg_size - copy_size], copy_size); 2879 #endif 2880 } 2881 2882 static inline void zig_big_truncate_big(void *res, const void *arg, bool res_is_signed, uint16_t res_bits, bool arg_is_signed, uint16_t arg_bits) { 2883 uint8_t *res_bytes = res; 2884 const uint8_t *arg_bytes = arg; 2885 uint16_t res_size = zig_int_bytes(res_bits); 2886 2887 if (res_is_signed != arg_is_signed) zig_unreachable(); 2888 if (res_bits > arg_bits) zig_unreachable(); 2889 2890 if (res_is_signed) { 2891 uint16_t arg_byte_offset = UINT16_C(0); 2892 2893 #if zig_big_endian 2894 arg_byte_offset = zig_int_bytes(arg_bits) - res_size; 2895 #endif 2896 2897 memcpy(&res_bytes[0], &arg_bytes[arg_byte_offset], res_size); 2898 } else { 2899 uint16_t res_byte_offset = zig_shr_u16(res_bits - UINT16_C(1), UINT8_C(3)); 2900 uint16_t arg_byte_offset = res_byte_offset; 2901 2902 #if zig_little_endian 2903 memcpy(&res_bytes[0], &arg_bytes[0], res_byte_offset); 2904 #else 2905 res_byte_offset = res_size - UINT16_C(1) - res_byte_offset; 2906 arg_byte_offset = zig_int_bytes(arg_bits) - UINT16_C(1) - arg_byte_offset; 2907 2908 memset(&res_bytes[0], zig_minInt_u8, res_byte_offset); 2909 #endif 2910 2911 res_bytes[res_byte_offset] = zig_u8_truncate_u8( 2912 arg_bytes[arg_byte_offset], 2913 zig_u8_truncate_u8(res_bits - UINT16_C(1), UINT8_C(3)) + UINT16_C(1) 2914 ); 2915 res_byte_offset += UINT16_C(1); 2916 arg_byte_offset += UINT16_C(1); 2917 2918 #if zig_little_endian 2919 memset(&res_bytes[res_byte_offset], zig_minInt_u8, res_size - res_byte_offset); 2920 #else 2921 memcpy(&res_bytes[res_byte_offset], &arg_bytes[arg_byte_offset], res_size - res_byte_offset); 2922 #endif 2923 } 2924 } 2925 2926 #define zig_big_casts(is, s, w, IntType) \ 2927 static inline IntType zig_##s##w##_intCast_big(const void *arg, bool arg_is_signed, uint16_t arg_bits) { \ 2928 IntType res; \ 2929 zig_big_intCast_big(&res, arg, is, w, arg_is_signed, arg_bits); \ 2930 return res; \ 2931 } \ 2932 \ 2933 static inline void zig_big_intCast_##s##w(void *res, IntType arg, bool res_is_signed, uint16_t res_bits) { \ 2934 zig_big_intCast_big(res, &arg, res_is_signed, res_bits, is, w); \ 2935 } \ 2936 \ 2937 static inline IntType zig_##s##w##_truncate_big(const void *arg, uint8_t res_bits, bool arg_is_signed, uint16_t arg_bits) { \ 2938 IntType res; \ 2939 zig_big_truncate_big(&res, arg, is, res_bits, arg_is_signed, arg_bits); \ 2940 return res; \ 2941 } \ 2942 \ 2943 static inline void zig_big_truncate_##s##w(void *res, IntType arg, bool res_is_signed, uint16_t res_bits) { \ 2944 zig_big_truncate_big(res, &arg, res_is_signed, res_bits, is, w); \ 2945 } 2946 zig_big_casts(false, u, 8, uint8_t) 2947 zig_big_casts(true , i, 8, int8_t) 2948 zig_big_casts(false, u, 16, uint16_t) 2949 zig_big_casts(true , i, 16, int16_t) 2950 zig_big_casts(false, u, 32, uint32_t) 2951 zig_big_casts(true , i, 32, int32_t) 2952 zig_big_casts(false, u, 64, uint64_t) 2953 zig_big_casts(true , i, 64, int64_t) 2954 zig_big_casts(false, u, 128, zig_u128) 2955 zig_big_casts(true , i, 128, zig_i128) 2956 2957 static inline void zig_big_bitCast_big(void *res, const void *arg, bool res_is_signed, uint16_t bits) { 2958 uint8_t *res_bytes = res; 2959 const uint8_t *arg_bytes = arg; 2960 uint16_t size = zig_int_bytes(bits); 2961 uint16_t byte_offset = zig_shr_u16(bits - UINT16_C(1), UINT8_C(3)); 2962 uint16_t remainder_bits = zig_u8_truncate_u16(bits - UINT16_C(1), UINT8_C(3)) + UINT8_C(1); 2963 uint8_t sign_byte; 2964 uint8_t fill_byte; 2965 2966 #if zig_big_endian 2967 byte_offset = size - UINT16_C(1) - byte_offset; 2968 #endif 2969 2970 if (res_is_signed) { 2971 int8_t signed_sign_byte = zig_i8_bitCast_u8(arg_bytes[byte_offset], remainder_bits); 2972 2973 sign_byte = zig_u8_bitCast_i8(signed_sign_byte, UINT8_C(8)); 2974 fill_byte = zig_u8_bitCast_i8(zig_shr_i8(signed_sign_byte, UINT8_C(7)), UINT8_C(8)); 2975 } else { 2976 sign_byte = zig_u8_bitCast_u8(arg_bytes[byte_offset], remainder_bits); 2977 fill_byte = UINT8_C(0); 2978 } 2979 2980 #if zig_little_endian 2981 memcpy(&res_bytes[0], &arg_bytes[0], byte_offset); 2982 res_bytes[byte_offset] = sign_byte; 2983 byte_offset += UINT16_C(1); 2984 memset(&res_bytes[byte_offset], fill_byte, size - byte_offset); 2985 #else 2986 memset(&res_bytes[0], fill_byte, byte_offset); 2987 res_bytes[byte_offset] = sign_byte; 2988 byte_offset += UINT16_C(1); 2989 memcpy(&res_bytes[byte_offset], &arg_bytes[byte_offset], size - byte_offset); 2990 #endif 2991 } 2992 2993 static inline int32_t zig_cmp_big_u8(const void *lhs, uint8_t rhs, bool is_signed, uint16_t bits) { 2994 const uint8_t *lhs_bytes = lhs; 2995 uint16_t byte_offset = 0; 2996 bool do_signed = is_signed; 2997 uint16_t remaining_bytes = zig_int_bytes(bits); 2998 2999 #if zig_little_endian 3000 byte_offset = remaining_bytes; 3001 #endif 3002 3003 while (remaining_bytes >= 128 / CHAR_BIT) { 3004 uint8_t rhs_byte = remaining_bytes == 128 / CHAR_BIT ? rhs : UINT8_C(0); 3005 int32_t limb_cmp; 3006 3007 #if zig_little_endian 3008 byte_offset -= 128 / CHAR_BIT; 3009 #endif 3010 3011 if (do_signed) { 3012 zig_i128 lhs_limb; 3013 zig_i128 rhs_limb = zig_i128_intCast_u8(rhs_byte); 3014 3015 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 3016 limb_cmp = zig_cmp_i128(lhs_limb, rhs_limb); 3017 do_signed = false; 3018 } else { 3019 zig_u128 lhs_limb; 3020 zig_u128 rhs_limb = zig_u128_intCast_u8(rhs_byte); 3021 3022 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 3023 limb_cmp = zig_cmp_u128(lhs_limb, rhs_limb); 3024 } 3025 3026 if (limb_cmp != 0) return limb_cmp; 3027 remaining_bytes -= 128 / CHAR_BIT; 3028 3029 #if zig_big_endian 3030 byte_offset += 128 / CHAR_BIT; 3031 #endif 3032 } 3033 3034 while (remaining_bytes >= 64 / CHAR_BIT) { 3035 uint8_t rhs_byte = remaining_bytes == 64 / CHAR_BIT ? rhs : UINT8_C(0); 3036 3037 #if zig_little_endian 3038 byte_offset -= 64 / CHAR_BIT; 3039 #endif 3040 3041 if (do_signed) { 3042 int64_t lhs_limb; 3043 int64_t rhs_limb = zig_i64_intCast_u8(rhs_byte); 3044 3045 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 3046 if (lhs_limb != rhs_limb) return (lhs_limb > rhs_limb) - (lhs_limb < rhs_limb); 3047 do_signed = false; 3048 } else { 3049 uint64_t lhs_limb; 3050 uint64_t rhs_limb = zig_u64_intCast_u8(rhs_byte); 3051 3052 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 3053 if (lhs_limb != rhs_limb) return (lhs_limb > rhs_limb) - (lhs_limb < rhs_limb); 3054 } 3055 3056 remaining_bytes -= 64 / CHAR_BIT; 3057 3058 #if zig_big_endian 3059 byte_offset += 64 / CHAR_BIT; 3060 #endif 3061 } 3062 3063 while (remaining_bytes >= 32 / CHAR_BIT) { 3064 uint8_t rhs_byte = remaining_bytes == 32 / CHAR_BIT ? rhs : UINT8_C(0); 3065 3066 #if zig_little_endian 3067 byte_offset -= 32 / CHAR_BIT; 3068 #endif 3069 3070 if (do_signed) { 3071 int32_t lhs_limb; 3072 int32_t rhs_limb = zig_i32_intCast_u8(rhs_byte); 3073 3074 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 3075 if (lhs_limb != rhs_limb) return (lhs_limb > rhs_limb) - (lhs_limb < rhs_limb); 3076 do_signed = false; 3077 } else { 3078 uint32_t lhs_limb; 3079 uint32_t rhs_limb = zig_u32_intCast_u8(rhs_byte); 3080 3081 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 3082 if (lhs_limb != rhs_limb) return (lhs_limb > rhs_limb) - (lhs_limb < rhs_limb); 3083 } 3084 3085 remaining_bytes -= 32 / CHAR_BIT; 3086 3087 #if zig_big_endian 3088 byte_offset += 32 / CHAR_BIT; 3089 #endif 3090 } 3091 3092 while (remaining_bytes >= 16 / CHAR_BIT) { 3093 uint8_t rhs_byte = remaining_bytes == 16 / CHAR_BIT ? rhs : UINT8_C(0); 3094 3095 #if zig_little_endian 3096 byte_offset -= 16 / CHAR_BIT; 3097 #endif 3098 3099 if (do_signed) { 3100 int16_t lhs_limb; 3101 int16_t rhs_limb = zig_i16_intCast_u8(rhs_byte); 3102 3103 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 3104 if (lhs_limb != rhs_limb) return (lhs_limb > rhs_limb) - (lhs_limb < rhs_limb); 3105 do_signed = false; 3106 } else { 3107 uint16_t lhs_limb; 3108 uint16_t rhs_limb = zig_u16_intCast_u8(rhs_byte); 3109 3110 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 3111 if (lhs_limb != rhs_limb) return (lhs_limb > rhs_limb) - (lhs_limb < rhs_limb); 3112 } 3113 3114 remaining_bytes -= 16 / CHAR_BIT; 3115 3116 #if zig_big_endian 3117 byte_offset += 16 / CHAR_BIT; 3118 #endif 3119 } 3120 3121 while (remaining_bytes >= 8 / CHAR_BIT) { 3122 uint8_t rhs_byte = remaining_bytes == 16 / CHAR_BIT ? rhs : UINT8_C(0); 3123 3124 #if zig_little_endian 3125 byte_offset -= 8 / CHAR_BIT; 3126 #endif 3127 3128 if (do_signed) { 3129 int8_t lhs_limb; 3130 int16_t lhs_cmp_limb; 3131 int16_t rhs_cmp_limb = zig_i16_intCast_u8(rhs_byte); 3132 3133 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 3134 lhs_cmp_limb = zig_i16_intCast_i8(lhs_limb); 3135 if (lhs_cmp_limb != rhs_cmp_limb) return (lhs_cmp_limb > rhs_cmp_limb) - (lhs_cmp_limb < rhs_cmp_limb); 3136 do_signed = false; 3137 } else { 3138 uint8_t lhs_limb; 3139 uint8_t rhs_limb = rhs_byte; 3140 3141 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 3142 if (lhs_limb != rhs_limb) return (lhs_limb > rhs_limb) - (lhs_limb < rhs_limb); 3143 } 3144 3145 remaining_bytes -= 8 / CHAR_BIT; 3146 3147 #if zig_big_endian 3148 byte_offset += 8 / CHAR_BIT; 3149 #endif 3150 } 3151 3152 return 0; 3153 } 3154 3155 static inline int32_t zig_cmp_big(const void *lhs, const void *rhs, bool is_signed, uint16_t bits) { 3156 const uint8_t *lhs_bytes = lhs; 3157 const uint8_t *rhs_bytes = rhs; 3158 uint16_t byte_offset = 0; 3159 bool do_signed = is_signed; 3160 uint16_t remaining_bytes = zig_int_bytes(bits); 3161 3162 #if zig_little_endian 3163 byte_offset = remaining_bytes; 3164 #endif 3165 3166 while (remaining_bytes >= 128 / CHAR_BIT) { 3167 int32_t limb_cmp; 3168 3169 #if zig_little_endian 3170 byte_offset -= 128 / CHAR_BIT; 3171 #endif 3172 3173 if (do_signed) { 3174 zig_i128 lhs_limb; 3175 zig_i128 rhs_limb; 3176 3177 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 3178 memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); 3179 limb_cmp = zig_cmp_i128(lhs_limb, rhs_limb); 3180 do_signed = false; 3181 } else { 3182 zig_u128 lhs_limb; 3183 zig_u128 rhs_limb; 3184 3185 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 3186 memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); 3187 limb_cmp = zig_cmp_u128(lhs_limb, rhs_limb); 3188 } 3189 3190 if (limb_cmp != 0) return limb_cmp; 3191 remaining_bytes -= 128 / CHAR_BIT; 3192 3193 #if zig_big_endian 3194 byte_offset += 128 / CHAR_BIT; 3195 #endif 3196 } 3197 3198 while (remaining_bytes >= 64 / CHAR_BIT) { 3199 #if zig_little_endian 3200 byte_offset -= 64 / CHAR_BIT; 3201 #endif 3202 3203 if (do_signed) { 3204 int64_t lhs_limb; 3205 int64_t rhs_limb; 3206 3207 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 3208 memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); 3209 if (lhs_limb != rhs_limb) return (lhs_limb > rhs_limb) - (lhs_limb < rhs_limb); 3210 do_signed = false; 3211 } else { 3212 uint64_t lhs_limb; 3213 uint64_t rhs_limb; 3214 3215 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 3216 memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); 3217 if (lhs_limb != rhs_limb) return (lhs_limb > rhs_limb) - (lhs_limb < rhs_limb); 3218 } 3219 3220 remaining_bytes -= 64 / CHAR_BIT; 3221 3222 #if zig_big_endian 3223 byte_offset += 64 / CHAR_BIT; 3224 #endif 3225 } 3226 3227 while (remaining_bytes >= 32 / CHAR_BIT) { 3228 #if zig_little_endian 3229 byte_offset -= 32 / CHAR_BIT; 3230 #endif 3231 3232 if (do_signed) { 3233 int32_t lhs_limb; 3234 int32_t rhs_limb; 3235 3236 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 3237 memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); 3238 if (lhs_limb != rhs_limb) return (lhs_limb > rhs_limb) - (lhs_limb < rhs_limb); 3239 do_signed = false; 3240 } else { 3241 uint32_t lhs_limb; 3242 uint32_t rhs_limb; 3243 3244 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 3245 memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); 3246 if (lhs_limb != rhs_limb) return (lhs_limb > rhs_limb) - (lhs_limb < rhs_limb); 3247 } 3248 3249 remaining_bytes -= 32 / CHAR_BIT; 3250 3251 #if zig_big_endian 3252 byte_offset += 32 / CHAR_BIT; 3253 #endif 3254 } 3255 3256 while (remaining_bytes >= 16 / CHAR_BIT) { 3257 #if zig_little_endian 3258 byte_offset -= 16 / CHAR_BIT; 3259 #endif 3260 3261 if (do_signed) { 3262 int16_t lhs_limb; 3263 int16_t rhs_limb; 3264 3265 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 3266 memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); 3267 if (lhs_limb != rhs_limb) return (lhs_limb > rhs_limb) - (lhs_limb < rhs_limb); 3268 do_signed = false; 3269 } else { 3270 uint16_t lhs_limb; 3271 uint16_t rhs_limb; 3272 3273 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 3274 memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); 3275 if (lhs_limb != rhs_limb) return (lhs_limb > rhs_limb) - (lhs_limb < rhs_limb); 3276 } 3277 3278 remaining_bytes -= 16 / CHAR_BIT; 3279 3280 #if zig_big_endian 3281 byte_offset += 16 / CHAR_BIT; 3282 #endif 3283 } 3284 3285 while (remaining_bytes >= 8 / CHAR_BIT) { 3286 #if zig_little_endian 3287 byte_offset -= 8 / CHAR_BIT; 3288 #endif 3289 3290 if (do_signed) { 3291 int8_t lhs_limb; 3292 int8_t rhs_limb; 3293 3294 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 3295 memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); 3296 if (lhs_limb != rhs_limb) return (lhs_limb > rhs_limb) - (lhs_limb < rhs_limb); 3297 do_signed = false; 3298 } else { 3299 uint8_t lhs_limb; 3300 uint8_t rhs_limb; 3301 3302 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 3303 memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); 3304 if (lhs_limb != rhs_limb) return (lhs_limb > rhs_limb) - (lhs_limb < rhs_limb); 3305 } 3306 3307 remaining_bytes -= 8 / CHAR_BIT; 3308 3309 #if zig_big_endian 3310 byte_offset += 8 / CHAR_BIT; 3311 #endif 3312 } 3313 3314 return 0; 3315 } 3316 3317 static inline void zig_not_big(void *res, const void *arg, bool is_signed, uint16_t bits) { 3318 uint8_t *res_bytes = res; 3319 const uint8_t *arg_bytes = arg; 3320 uint16_t byte_offset = 0; 3321 uint16_t remaining_bytes = zig_int_bytes(bits); 3322 uint8_t top_bits = zig_u8_intCast_u16(remaining_bytes * CHAR_BIT - bits); 3323 3324 #if zig_big_endian 3325 byte_offset = remaining_bytes; 3326 #endif 3327 3328 while (remaining_bytes >= 128 / CHAR_BIT) { 3329 uint8_t limb_bits = 128 - (remaining_bytes == 128 / CHAR_BIT ? top_bits : 0); 3330 3331 #if zig_big_endian 3332 byte_offset -= 128 / CHAR_BIT; 3333 #endif 3334 3335 if (remaining_bytes != 128 / CHAR_BIT || is_signed) { 3336 zig_i128 res_limb; 3337 zig_i128 arg_limb; 3338 3339 memcpy(&arg_limb, &arg_bytes[byte_offset], sizeof(arg_limb)); 3340 res_limb = zig_not_i128(arg_limb, limb_bits); 3341 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 3342 } else { 3343 zig_u128 res_limb; 3344 zig_u128 arg_limb; 3345 3346 memcpy(&arg_limb, &arg_bytes[byte_offset], sizeof(arg_limb)); 3347 res_limb = zig_not_u128(arg_limb, limb_bits); 3348 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 3349 } 3350 3351 remaining_bytes -= 128 / CHAR_BIT; 3352 3353 #if zig_little_endian 3354 byte_offset += 128 / CHAR_BIT; 3355 #endif 3356 } 3357 3358 while (remaining_bytes >= 64 / CHAR_BIT) { 3359 uint8_t limb_bits = 64 - (remaining_bytes == 64 / CHAR_BIT ? top_bits : 0); 3360 3361 #if zig_big_endian 3362 byte_offset -= 64 / CHAR_BIT; 3363 #endif 3364 3365 if (remaining_bytes != 64 / CHAR_BIT || is_signed) { 3366 int64_t res_limb; 3367 int64_t arg_limb; 3368 3369 memcpy(&arg_limb, &arg_bytes[byte_offset], sizeof(arg_limb)); 3370 res_limb = zig_not_i64(arg_limb, limb_bits); 3371 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 3372 } else { 3373 uint64_t res_limb; 3374 uint64_t arg_limb; 3375 3376 memcpy(&arg_limb, &arg_bytes[byte_offset], sizeof(arg_limb)); 3377 res_limb = zig_not_u64(arg_limb, limb_bits); 3378 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 3379 } 3380 3381 remaining_bytes -= 64 / CHAR_BIT; 3382 3383 #if zig_little_endian 3384 byte_offset += 64 / CHAR_BIT; 3385 #endif 3386 } 3387 3388 while (remaining_bytes >= 32 / CHAR_BIT) { 3389 uint8_t limb_bits = 32 - (remaining_bytes == 32 / CHAR_BIT ? top_bits : 0); 3390 3391 #if zig_big_endian 3392 byte_offset -= 32 / CHAR_BIT; 3393 #endif 3394 3395 if (remaining_bytes != 32 / CHAR_BIT || is_signed) { 3396 int32_t res_limb; 3397 int32_t arg_limb; 3398 3399 memcpy(&arg_limb, &arg_bytes[byte_offset], sizeof(arg_limb)); 3400 res_limb = zig_not_i32(arg_limb, limb_bits); 3401 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 3402 } else { 3403 uint32_t res_limb; 3404 uint32_t arg_limb; 3405 3406 memcpy(&arg_limb, &arg_bytes[byte_offset], sizeof(arg_limb)); 3407 res_limb = zig_not_u32(arg_limb, limb_bits); 3408 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 3409 } 3410 3411 remaining_bytes -= 32 / CHAR_BIT; 3412 3413 #if zig_little_endian 3414 byte_offset += 32 / CHAR_BIT; 3415 #endif 3416 } 3417 3418 while (remaining_bytes >= 16 / CHAR_BIT) { 3419 uint8_t limb_bits = 16 - (remaining_bytes == 16 / CHAR_BIT ? top_bits : 0); 3420 3421 #if zig_big_endian 3422 byte_offset -= 16 / CHAR_BIT; 3423 #endif 3424 3425 if (remaining_bytes != 16 / CHAR_BIT || is_signed) { 3426 int16_t res_limb; 3427 int16_t arg_limb; 3428 3429 memcpy(&arg_limb, &arg_bytes[byte_offset], sizeof(arg_limb)); 3430 res_limb = zig_not_i16(arg_limb, limb_bits); 3431 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 3432 } else { 3433 uint16_t res_limb; 3434 uint16_t arg_limb; 3435 3436 memcpy(&arg_limb, &arg_bytes[byte_offset], sizeof(arg_limb)); 3437 res_limb = zig_not_u16(arg_limb, limb_bits); 3438 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 3439 } 3440 3441 remaining_bytes -= 16 / CHAR_BIT; 3442 3443 #if zig_little_endian 3444 byte_offset += 16 / CHAR_BIT; 3445 #endif 3446 } 3447 3448 while (remaining_bytes >= 8 / CHAR_BIT) { 3449 uint8_t limb_bits = 8 - (remaining_bytes == 8 / CHAR_BIT ? top_bits : 0); 3450 3451 #if zig_big_endian 3452 byte_offset -= 8 / CHAR_BIT; 3453 #endif 3454 3455 if (remaining_bytes != 8 / CHAR_BIT || is_signed) { 3456 int8_t res_limb; 3457 int8_t arg_limb; 3458 3459 memcpy(&arg_limb, &arg_bytes[byte_offset], sizeof(arg_limb)); 3460 res_limb = zig_not_i8(arg_limb, limb_bits); 3461 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 3462 } else { 3463 uint8_t res_limb; 3464 uint8_t arg_limb; 3465 3466 memcpy(&arg_limb, &arg_bytes[byte_offset], sizeof(arg_limb)); 3467 res_limb = zig_not_u8(arg_limb, limb_bits); 3468 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 3469 } 3470 3471 remaining_bytes -= 8 / CHAR_BIT; 3472 3473 #if zig_little_endian 3474 byte_offset += 8 / CHAR_BIT; 3475 #endif 3476 } 3477 } 3478 3479 static inline void zig_and_big(void *res, const void *lhs, const void *rhs, bool is_signed, uint16_t bits) { 3480 uint8_t *res_bytes = res; 3481 const uint8_t *lhs_bytes = lhs; 3482 const uint8_t *rhs_bytes = rhs; 3483 uint16_t byte_offset = 0; 3484 uint16_t remaining_bytes = zig_int_bytes(bits); 3485 (void)is_signed; 3486 3487 while (remaining_bytes >= 128 / CHAR_BIT) { 3488 zig_u128 res_limb; 3489 zig_u128 lhs_limb; 3490 zig_u128 rhs_limb; 3491 3492 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 3493 memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); 3494 res_limb = zig_and_u128(lhs_limb, rhs_limb); 3495 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 3496 3497 remaining_bytes -= 128 / CHAR_BIT; 3498 byte_offset += 128 / CHAR_BIT; 3499 } 3500 3501 while (remaining_bytes >= 64 / CHAR_BIT) { 3502 uint64_t res_limb; 3503 uint64_t lhs_limb; 3504 uint64_t rhs_limb; 3505 3506 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 3507 memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); 3508 res_limb = zig_and_u64(lhs_limb, rhs_limb); 3509 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 3510 3511 remaining_bytes -= 64 / CHAR_BIT; 3512 byte_offset += 64 / CHAR_BIT; 3513 } 3514 3515 while (remaining_bytes >= 32 / CHAR_BIT) { 3516 uint32_t res_limb; 3517 uint32_t lhs_limb; 3518 uint32_t rhs_limb; 3519 3520 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 3521 memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); 3522 res_limb = zig_and_u32(lhs_limb, rhs_limb); 3523 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 3524 3525 remaining_bytes -= 32 / CHAR_BIT; 3526 byte_offset += 32 / CHAR_BIT; 3527 } 3528 3529 while (remaining_bytes >= 16 / CHAR_BIT) { 3530 uint16_t res_limb; 3531 uint16_t lhs_limb; 3532 uint16_t rhs_limb; 3533 3534 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 3535 memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); 3536 res_limb = zig_and_u16(lhs_limb, rhs_limb); 3537 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 3538 3539 remaining_bytes -= 16 / CHAR_BIT; 3540 byte_offset += 16 / CHAR_BIT; 3541 } 3542 3543 while (remaining_bytes >= 8 / CHAR_BIT) { 3544 uint8_t res_limb; 3545 uint8_t lhs_limb; 3546 uint8_t rhs_limb; 3547 3548 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 3549 memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); 3550 res_limb = zig_and_u8(lhs_limb, rhs_limb); 3551 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 3552 3553 remaining_bytes -= 8 / CHAR_BIT; 3554 byte_offset += 8 / CHAR_BIT; 3555 } 3556 } 3557 3558 static inline void zig_or_big(void *res, const void *lhs, const void *rhs, bool is_signed, uint16_t bits) { 3559 uint8_t *res_bytes = res; 3560 const uint8_t *lhs_bytes = lhs; 3561 const uint8_t *rhs_bytes = rhs; 3562 uint16_t byte_offset = 0; 3563 uint16_t remaining_bytes = zig_int_bytes(bits); 3564 (void)is_signed; 3565 3566 while (remaining_bytes >= 128 / CHAR_BIT) { 3567 zig_u128 res_limb; 3568 zig_u128 lhs_limb; 3569 zig_u128 rhs_limb; 3570 3571 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 3572 memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); 3573 res_limb = zig_or_u128(lhs_limb, rhs_limb); 3574 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 3575 3576 remaining_bytes -= 128 / CHAR_BIT; 3577 byte_offset += 128 / CHAR_BIT; 3578 } 3579 3580 while (remaining_bytes >= 64 / CHAR_BIT) { 3581 uint64_t res_limb; 3582 uint64_t lhs_limb; 3583 uint64_t rhs_limb; 3584 3585 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 3586 memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); 3587 res_limb = zig_or_u64(lhs_limb, rhs_limb); 3588 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 3589 3590 remaining_bytes -= 64 / CHAR_BIT; 3591 byte_offset += 64 / CHAR_BIT; 3592 } 3593 3594 while (remaining_bytes >= 32 / CHAR_BIT) { 3595 uint32_t res_limb; 3596 uint32_t lhs_limb; 3597 uint32_t rhs_limb; 3598 3599 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 3600 memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); 3601 res_limb = zig_or_u32(lhs_limb, rhs_limb); 3602 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 3603 3604 remaining_bytes -= 32 / CHAR_BIT; 3605 byte_offset += 32 / CHAR_BIT; 3606 } 3607 3608 while (remaining_bytes >= 16 / CHAR_BIT) { 3609 uint16_t res_limb; 3610 uint16_t lhs_limb; 3611 uint16_t rhs_limb; 3612 3613 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 3614 memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); 3615 res_limb = zig_or_u16(lhs_limb, rhs_limb); 3616 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 3617 3618 remaining_bytes -= 16 / CHAR_BIT; 3619 byte_offset += 16 / CHAR_BIT; 3620 } 3621 3622 while (remaining_bytes >= 8 / CHAR_BIT) { 3623 uint8_t res_limb; 3624 uint8_t lhs_limb; 3625 uint8_t rhs_limb; 3626 3627 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 3628 memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); 3629 res_limb = zig_or_u8(lhs_limb, rhs_limb); 3630 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 3631 3632 remaining_bytes -= 8 / CHAR_BIT; 3633 byte_offset += 8 / CHAR_BIT; 3634 } 3635 } 3636 3637 static inline void zig_xor_big(void *res, const void *lhs, const void *rhs, bool is_signed, uint16_t bits) { 3638 uint8_t *res_bytes = res; 3639 const uint8_t *lhs_bytes = lhs; 3640 const uint8_t *rhs_bytes = rhs; 3641 uint16_t byte_offset = 0; 3642 uint16_t remaining_bytes = zig_int_bytes(bits); 3643 (void)is_signed; 3644 3645 while (remaining_bytes >= 128 / CHAR_BIT) { 3646 zig_u128 res_limb; 3647 zig_u128 lhs_limb; 3648 zig_u128 rhs_limb; 3649 3650 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 3651 memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); 3652 res_limb = zig_xor_u128(lhs_limb, rhs_limb); 3653 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 3654 3655 remaining_bytes -= 128 / CHAR_BIT; 3656 byte_offset += 128 / CHAR_BIT; 3657 } 3658 3659 while (remaining_bytes >= 64 / CHAR_BIT) { 3660 uint64_t res_limb; 3661 uint64_t lhs_limb; 3662 uint64_t rhs_limb; 3663 3664 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 3665 memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); 3666 res_limb = zig_xor_u64(lhs_limb, rhs_limb); 3667 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 3668 3669 remaining_bytes -= 64 / CHAR_BIT; 3670 byte_offset += 64 / CHAR_BIT; 3671 } 3672 3673 while (remaining_bytes >= 32 / CHAR_BIT) { 3674 uint32_t res_limb; 3675 uint32_t lhs_limb; 3676 uint32_t rhs_limb; 3677 3678 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 3679 memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); 3680 res_limb = zig_xor_u32(lhs_limb, rhs_limb); 3681 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 3682 3683 remaining_bytes -= 32 / CHAR_BIT; 3684 byte_offset += 32 / CHAR_BIT; 3685 } 3686 3687 while (remaining_bytes >= 16 / CHAR_BIT) { 3688 uint16_t res_limb; 3689 uint16_t lhs_limb; 3690 uint16_t rhs_limb; 3691 3692 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 3693 memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); 3694 res_limb = zig_xor_u16(lhs_limb, rhs_limb); 3695 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 3696 3697 remaining_bytes -= 16 / CHAR_BIT; 3698 byte_offset += 16 / CHAR_BIT; 3699 } 3700 3701 while (remaining_bytes >= 8 / CHAR_BIT) { 3702 uint8_t res_limb; 3703 uint8_t lhs_limb; 3704 uint8_t rhs_limb; 3705 3706 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 3707 memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); 3708 res_limb = zig_xor_u8(lhs_limb, rhs_limb); 3709 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 3710 3711 remaining_bytes -= 8 / CHAR_BIT; 3712 byte_offset += 8 / CHAR_BIT; 3713 } 3714 } 3715 3716 static inline void zig_increment_big(void *res, bool is_signed, uint16_t bits) { 3717 uint8_t *res_bytes = res; 3718 uint16_t byte_offset = 0; 3719 uint16_t remaining_bytes = zig_int_bytes(bits); 3720 uint8_t top_bits = zig_u8_intCast_u16(remaining_bytes * CHAR_BIT - bits); 3721 3722 #if zig_big_endian 3723 byte_offset = remaining_bytes; 3724 #endif 3725 3726 while (remaining_bytes >= 128 / CHAR_BIT) { 3727 uint8_t limb_bits = 128 - (remaining_bytes == 128 / CHAR_BIT ? top_bits : 0); 3728 3729 #if zig_big_endian 3730 byte_offset -= 128 / CHAR_BIT; 3731 #endif 3732 3733 { 3734 zig_u128 res_limb; 3735 bool limb_overflow; 3736 3737 memcpy(&res_limb, &res_bytes[byte_offset], sizeof(res_limb)); 3738 limb_overflow = zig_addo_u128(&res_limb, res_limb, zig_make_u128(UINT64_C(0), UINT64_C(1)), limb_bits); 3739 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 3740 if (!limb_overflow) return; 3741 } 3742 3743 remaining_bytes -= 128 / CHAR_BIT; 3744 3745 #if zig_little_endian 3746 byte_offset += 128 / CHAR_BIT; 3747 #endif 3748 } 3749 3750 while (remaining_bytes >= 64 / CHAR_BIT) { 3751 uint8_t limb_bits = 64 - (remaining_bytes == 64 / CHAR_BIT ? top_bits : 0); 3752 3753 #if zig_big_endian 3754 byte_offset -= 64 / CHAR_BIT; 3755 #endif 3756 3757 { 3758 uint64_t res_limb; 3759 bool limb_overflow; 3760 3761 memcpy(&res_limb, &res_bytes[byte_offset], sizeof(res_limb)); 3762 limb_overflow = zig_addo_u64(&res_limb, res_limb, UINT64_C(1), limb_bits); 3763 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 3764 if (!limb_overflow) return; 3765 } 3766 3767 remaining_bytes -= 64 / CHAR_BIT; 3768 3769 #if zig_little_endian 3770 byte_offset += 64 / CHAR_BIT; 3771 #endif 3772 } 3773 3774 while (remaining_bytes >= 32 / CHAR_BIT) { 3775 uint8_t limb_bits = 32 - (remaining_bytes == 32 / CHAR_BIT ? top_bits : 0); 3776 3777 #if zig_big_endian 3778 byte_offset -= 32 / CHAR_BIT; 3779 #endif 3780 3781 { 3782 uint32_t res_limb; 3783 bool limb_overflow; 3784 3785 memcpy(&res_limb, &res_bytes[byte_offset], sizeof(res_limb)); 3786 limb_overflow = zig_addo_u32(&res_limb, res_limb, UINT32_C(1), limb_bits); 3787 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 3788 if (!limb_overflow) return; 3789 } 3790 3791 remaining_bytes -= 32 / CHAR_BIT; 3792 3793 #if zig_little_endian 3794 byte_offset += 32 / CHAR_BIT; 3795 #endif 3796 } 3797 3798 while (remaining_bytes >= 16 / CHAR_BIT) { 3799 uint8_t limb_bits = 16 - (remaining_bytes == 16 / CHAR_BIT ? top_bits : 0); 3800 3801 #if zig_big_endian 3802 byte_offset -= 16 / CHAR_BIT; 3803 #endif 3804 3805 { 3806 uint16_t res_limb; 3807 bool limb_overflow; 3808 3809 memcpy(&res_limb, &res_bytes[byte_offset], sizeof(res_limb)); 3810 limb_overflow = zig_addo_u16(&res_limb, res_limb, UINT16_C(1), limb_bits); 3811 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 3812 if (!limb_overflow) return; 3813 } 3814 3815 remaining_bytes -= 16 / CHAR_BIT; 3816 3817 #if zig_little_endian 3818 byte_offset += 16 / CHAR_BIT; 3819 #endif 3820 } 3821 3822 while (remaining_bytes >= 8 / CHAR_BIT) { 3823 uint8_t limb_bits = 8 - (remaining_bytes == 8 / CHAR_BIT ? top_bits : 0); 3824 3825 #if zig_big_endian 3826 byte_offset -= 8 / CHAR_BIT; 3827 #endif 3828 3829 { 3830 uint8_t res_limb; 3831 bool limb_overflow; 3832 3833 memcpy(&res_limb, &res_bytes[byte_offset], sizeof(res_limb)); 3834 limb_overflow = zig_addo_u8(&res_limb, res_limb, UINT8_C(1), limb_bits); 3835 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 3836 if (!limb_overflow) return; 3837 } 3838 3839 remaining_bytes -= 8 / CHAR_BIT; 3840 3841 #if zig_little_endian 3842 byte_offset += 8 / CHAR_BIT; 3843 #endif 3844 } 3845 } 3846 3847 static inline void zig_decrement_big(void *res, bool is_signed, uint16_t bits) { 3848 uint8_t *res_bytes = res; 3849 uint16_t byte_offset = 0; 3850 uint16_t remaining_bytes = zig_int_bytes(bits); 3851 uint8_t top_bits = zig_u8_intCast_u16(remaining_bytes * CHAR_BIT - bits); 3852 3853 #if zig_big_endian 3854 byte_offset = remaining_bytes; 3855 #endif 3856 3857 while (remaining_bytes >= 128 / CHAR_BIT) { 3858 uint8_t limb_bits = 128 - (remaining_bytes == 128 / CHAR_BIT ? top_bits : 0); 3859 3860 #if zig_big_endian 3861 byte_offset -= 128 / CHAR_BIT; 3862 #endif 3863 3864 { 3865 zig_u128 res_limb; 3866 bool limb_overflow; 3867 3868 memcpy(&res_limb, &res_bytes[byte_offset], sizeof(res_limb)); 3869 limb_overflow = zig_subo_u128(&res_limb, res_limb, zig_make_u128(UINT64_C(0), UINT64_C(1)), limb_bits); 3870 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 3871 if (!limb_overflow) return; 3872 } 3873 3874 remaining_bytes -= 128 / CHAR_BIT; 3875 3876 #if zig_little_endian 3877 byte_offset += 128 / CHAR_BIT; 3878 #endif 3879 } 3880 3881 while (remaining_bytes >= 64 / CHAR_BIT) { 3882 uint8_t limb_bits = 64 - (remaining_bytes == 64 / CHAR_BIT ? top_bits : 0); 3883 3884 #if zig_big_endian 3885 byte_offset -= 64 / CHAR_BIT; 3886 #endif 3887 3888 { 3889 uint64_t res_limb; 3890 bool limb_overflow; 3891 3892 memcpy(&res_limb, &res_bytes[byte_offset], sizeof(res_limb)); 3893 limb_overflow = zig_subo_u64(&res_limb, res_limb, UINT64_C(1), limb_bits); 3894 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 3895 if (!limb_overflow) return; 3896 } 3897 3898 remaining_bytes -= 64 / CHAR_BIT; 3899 3900 #if zig_little_endian 3901 byte_offset += 64 / CHAR_BIT; 3902 #endif 3903 } 3904 3905 while (remaining_bytes >= 32 / CHAR_BIT) { 3906 uint8_t limb_bits = 32 - (remaining_bytes == 32 / CHAR_BIT ? top_bits : 0); 3907 3908 #if zig_big_endian 3909 byte_offset -= 32 / CHAR_BIT; 3910 #endif 3911 3912 { 3913 uint32_t res_limb; 3914 bool limb_overflow; 3915 3916 memcpy(&res_limb, &res_bytes[byte_offset], sizeof(res_limb)); 3917 limb_overflow = zig_subo_u32(&res_limb, res_limb, UINT32_C(1), limb_bits); 3918 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 3919 if (!limb_overflow) return; 3920 } 3921 3922 remaining_bytes -= 32 / CHAR_BIT; 3923 3924 #if zig_little_endian 3925 byte_offset += 32 / CHAR_BIT; 3926 #endif 3927 } 3928 3929 while (remaining_bytes >= 16 / CHAR_BIT) { 3930 uint8_t limb_bits = 16 - (remaining_bytes == 16 / CHAR_BIT ? top_bits : 0); 3931 3932 #if zig_big_endian 3933 byte_offset -= 16 / CHAR_BIT; 3934 #endif 3935 3936 { 3937 uint16_t res_limb; 3938 bool limb_overflow; 3939 3940 memcpy(&res_limb, &res_bytes[byte_offset], sizeof(res_limb)); 3941 limb_overflow = zig_subo_u16(&res_limb, res_limb, UINT16_C(1), limb_bits); 3942 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 3943 if (!limb_overflow) return; 3944 } 3945 3946 remaining_bytes -= 16 / CHAR_BIT; 3947 3948 #if zig_little_endian 3949 byte_offset += 16 / CHAR_BIT; 3950 #endif 3951 } 3952 3953 while (remaining_bytes >= 8 / CHAR_BIT) { 3954 uint8_t limb_bits = 8 - (remaining_bytes == 8 / CHAR_BIT ? top_bits : 0); 3955 3956 #if zig_big_endian 3957 byte_offset -= 8 / CHAR_BIT; 3958 #endif 3959 3960 { 3961 uint8_t res_limb; 3962 bool limb_overflow; 3963 3964 memcpy(&res_limb, &res_bytes[byte_offset], sizeof(res_limb)); 3965 limb_overflow = zig_subo_u8(&res_limb, res_limb, UINT8_C(1), limb_bits); 3966 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 3967 if (!limb_overflow) return; 3968 } 3969 3970 remaining_bytes -= 8 / CHAR_BIT; 3971 3972 #if zig_little_endian 3973 byte_offset += 8 / CHAR_BIT; 3974 #endif 3975 } 3976 } 3977 3978 static inline void zig_abs_big(void *res, const void *arg, bool is_signed, uint16_t bits) { 3979 uint8_t *res_bytes = res; 3980 const uint8_t *arg_bytes = arg; 3981 uint16_t byte_offset = 0; 3982 uint16_t remaining_bytes = zig_int_bytes(bits); 3983 if (zig_signFill_big(arg, is_signed, bits) >= INT8_C(0)) { 3984 memcpy(res, arg, remaining_bytes); 3985 return; 3986 } 3987 uint8_t top_bits = zig_u8_intCast_u16(remaining_bytes * CHAR_BIT - bits); 3988 bool overflow = true; 3989 3990 #if zig_big_endian 3991 byte_offset = remaining_bytes; 3992 #endif 3993 3994 while (remaining_bytes >= 128 / CHAR_BIT) { 3995 uint8_t limb_bits = 128 - (remaining_bytes == 128 / CHAR_BIT ? top_bits : 0); 3996 3997 #if zig_big_endian 3998 byte_offset -= 128 / CHAR_BIT; 3999 #endif 4000 4001 { 4002 zig_u128 res_limb; 4003 zig_u128 arg_limb; 4004 4005 memcpy(&arg_limb, &arg_bytes[byte_offset], sizeof(arg_limb)); 4006 overflow = zig_addo_u128(&res_limb, zig_not_u128(arg_limb, UINT8_C(128)), zig_make_u128(UINT64_C(0), overflow ? UINT64_C(1) : UINT64_C(0)), limb_bits); 4007 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 4008 } 4009 4010 remaining_bytes -= 128 / CHAR_BIT; 4011 4012 #if zig_little_endian 4013 byte_offset += 128 / CHAR_BIT; 4014 #endif 4015 } 4016 4017 while (remaining_bytes >= 64 / CHAR_BIT) { 4018 uint8_t limb_bits = 64 - (remaining_bytes == 64 / CHAR_BIT ? top_bits : 0); 4019 4020 #if zig_big_endian 4021 byte_offset -= 64 / CHAR_BIT; 4022 #endif 4023 4024 { 4025 uint64_t res_limb; 4026 uint64_t arg_limb; 4027 4028 memcpy(&arg_limb, &arg_bytes[byte_offset], sizeof(arg_limb)); 4029 overflow = zig_addo_u64(&res_limb, zig_not_u64(arg_limb, UINT8_C(64)), overflow ? UINT64_C(1) : UINT64_C(0), limb_bits); 4030 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 4031 } 4032 4033 remaining_bytes -= 64 / CHAR_BIT; 4034 4035 #if zig_little_endian 4036 byte_offset += 64 / CHAR_BIT; 4037 #endif 4038 } 4039 4040 while (remaining_bytes >= 32 / CHAR_BIT) { 4041 uint8_t limb_bits = 32 - (remaining_bytes == 32 / CHAR_BIT ? top_bits : 0); 4042 4043 #if zig_big_endian 4044 byte_offset -= 32 / CHAR_BIT; 4045 #endif 4046 4047 { 4048 uint32_t res_limb; 4049 uint32_t arg_limb; 4050 4051 memcpy(&arg_limb, &arg_bytes[byte_offset], sizeof(arg_limb)); 4052 overflow = zig_addo_u32(&res_limb, zig_not_u32(arg_limb, UINT8_C(32)), overflow ? UINT32_C(1) : UINT32_C(0), limb_bits); 4053 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 4054 } 4055 4056 remaining_bytes -= 32 / CHAR_BIT; 4057 4058 #if zig_little_endian 4059 byte_offset += 32 / CHAR_BIT; 4060 #endif 4061 } 4062 4063 while (remaining_bytes >= 16 / CHAR_BIT) { 4064 uint8_t limb_bits = 16 - (remaining_bytes == 16 / CHAR_BIT ? top_bits : 0); 4065 4066 #if zig_big_endian 4067 byte_offset -= 16 / CHAR_BIT; 4068 #endif 4069 4070 { 4071 uint16_t res_limb; 4072 uint16_t arg_limb; 4073 4074 memcpy(&arg_limb, &arg_bytes[byte_offset], sizeof(arg_limb)); 4075 overflow = zig_addo_u16(&res_limb, zig_not_u16(arg_limb, UINT8_C(16)), overflow ? UINT16_C(1) : UINT16_C(0), limb_bits); 4076 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 4077 } 4078 4079 remaining_bytes -= 16 / CHAR_BIT; 4080 4081 #if zig_little_endian 4082 byte_offset += 16 / CHAR_BIT; 4083 #endif 4084 } 4085 4086 while (remaining_bytes >= 8 / CHAR_BIT) { 4087 uint8_t limb_bits = 8 - (remaining_bytes == 8 / CHAR_BIT ? top_bits : 0); 4088 4089 #if zig_big_endian 4090 byte_offset -= 8 / CHAR_BIT; 4091 #endif 4092 4093 { 4094 uint8_t res_limb; 4095 uint8_t arg_limb; 4096 4097 memcpy(&arg_limb, &arg_bytes[byte_offset], sizeof(arg_limb)); 4098 overflow = zig_addo_u8(&res_limb, zig_not_u8(arg_limb, UINT8_C(8)), overflow ? UINT8_C(1) : UINT8_C(0), limb_bits); 4099 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 4100 } 4101 4102 remaining_bytes -= 8 / CHAR_BIT; 4103 4104 #if zig_little_endian 4105 byte_offset += 8 / CHAR_BIT; 4106 #endif 4107 } 4108 } 4109 4110 static inline void zig_min_big(void *res, const void *lhs, const void *rhs, bool is_signed, uint16_t bits) { 4111 memcpy(res, zig_cmp_big(lhs, rhs, is_signed, bits) < INT32_C(0) ? lhs : rhs, zig_int_bytes(bits)); 4112 } 4113 4114 static inline void zig_max_big(void *res, const void *lhs, const void *rhs, bool is_signed, uint16_t bits) { 4115 memcpy(res, zig_cmp_big(lhs, rhs, is_signed, bits) >= INT32_C(0) ? lhs : rhs, zig_int_bytes(bits)); 4116 } 4117 4118 static inline bool zig_addo_big(void *res, const void *lhs, const void *rhs, bool is_signed, uint16_t bits) { 4119 uint8_t *res_bytes = res; 4120 const uint8_t *lhs_bytes = lhs; 4121 const uint8_t *rhs_bytes = rhs; 4122 uint16_t byte_offset = 0; 4123 uint16_t remaining_bytes = zig_int_bytes(bits); 4124 uint8_t top_bits = zig_u8_intCast_u16(remaining_bytes * CHAR_BIT - bits); 4125 bool overflow = false; 4126 4127 #if zig_big_endian 4128 byte_offset = remaining_bytes; 4129 #endif 4130 4131 while (remaining_bytes >= 128 / CHAR_BIT) { 4132 uint8_t limb_bits = 128 - (remaining_bytes == 128 / CHAR_BIT ? top_bits : 0); 4133 4134 #if zig_big_endian 4135 byte_offset -= 128 / CHAR_BIT; 4136 #endif 4137 4138 if (remaining_bytes == 128 / CHAR_BIT && is_signed) { 4139 zig_i128 res_limb; 4140 zig_i128 tmp_limb; 4141 zig_i128 lhs_limb; 4142 zig_i128 rhs_limb; 4143 bool limb_overflow; 4144 4145 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 4146 memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); 4147 limb_overflow = zig_addo_i128(&tmp_limb, lhs_limb, rhs_limb, limb_bits); 4148 overflow = limb_overflow ^ zig_addo_i128(&res_limb, tmp_limb, zig_make_i128(INT64_C(0), overflow ? UINT64_C(1) : UINT64_C(0)), limb_bits); 4149 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 4150 } else { 4151 zig_u128 res_limb; 4152 zig_u128 tmp_limb; 4153 zig_u128 lhs_limb; 4154 zig_u128 rhs_limb; 4155 bool limb_overflow; 4156 4157 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 4158 memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); 4159 limb_overflow = zig_addo_u128(&tmp_limb, lhs_limb, rhs_limb, limb_bits); 4160 overflow = limb_overflow ^ zig_addo_u128(&res_limb, tmp_limb, zig_make_u128(UINT64_C(0), overflow ? UINT64_C(1) : UINT64_C(0)), limb_bits); 4161 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 4162 } 4163 4164 remaining_bytes -= 128 / CHAR_BIT; 4165 4166 #if zig_little_endian 4167 byte_offset += 128 / CHAR_BIT; 4168 #endif 4169 } 4170 4171 while (remaining_bytes >= 64 / CHAR_BIT) { 4172 uint8_t limb_bits = 64 - (remaining_bytes == 64 / CHAR_BIT ? top_bits : 0); 4173 4174 #if zig_big_endian 4175 byte_offset -= 64 / CHAR_BIT; 4176 #endif 4177 4178 if (remaining_bytes == 64 / CHAR_BIT && is_signed) { 4179 int64_t res_limb; 4180 int64_t tmp_limb; 4181 int64_t lhs_limb; 4182 int64_t rhs_limb; 4183 bool limb_overflow; 4184 4185 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 4186 memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); 4187 limb_overflow = zig_addo_i64(&tmp_limb, lhs_limb, rhs_limb, limb_bits); 4188 overflow = limb_overflow ^ zig_addo_i64(&res_limb, tmp_limb, overflow ? INT64_C(1) : INT64_C(0), limb_bits); 4189 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 4190 } else { 4191 uint64_t res_limb; 4192 uint64_t tmp_limb; 4193 uint64_t lhs_limb; 4194 uint64_t rhs_limb; 4195 bool limb_overflow; 4196 4197 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 4198 memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); 4199 limb_overflow = zig_addo_u64(&tmp_limb, lhs_limb, rhs_limb, limb_bits); 4200 overflow = limb_overflow ^ zig_addo_u64(&res_limb, tmp_limb, overflow ? UINT64_C(1) : UINT64_C(0), limb_bits); 4201 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 4202 } 4203 4204 remaining_bytes -= 64 / CHAR_BIT; 4205 4206 #if zig_little_endian 4207 byte_offset += 64 / CHAR_BIT; 4208 #endif 4209 } 4210 4211 while (remaining_bytes >= 32 / CHAR_BIT) { 4212 uint8_t limb_bits = 32 - (remaining_bytes == 32 / CHAR_BIT ? top_bits : 0); 4213 4214 #if zig_big_endian 4215 byte_offset -= 32 / CHAR_BIT; 4216 #endif 4217 4218 if (remaining_bytes == 32 / CHAR_BIT && is_signed) { 4219 int32_t res_limb; 4220 int32_t tmp_limb; 4221 int32_t lhs_limb; 4222 int32_t rhs_limb; 4223 bool limb_overflow; 4224 4225 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 4226 memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); 4227 limb_overflow = zig_addo_i32(&tmp_limb, lhs_limb, rhs_limb, limb_bits); 4228 overflow = limb_overflow ^ zig_addo_i32(&res_limb, tmp_limb, overflow ? INT32_C(1) : INT32_C(0), limb_bits); 4229 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 4230 } else { 4231 uint32_t res_limb; 4232 uint32_t tmp_limb; 4233 uint32_t lhs_limb; 4234 uint32_t rhs_limb; 4235 bool limb_overflow; 4236 4237 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 4238 memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); 4239 limb_overflow = zig_addo_u32(&tmp_limb, lhs_limb, rhs_limb, limb_bits); 4240 overflow = limb_overflow ^ zig_addo_u32(&res_limb, tmp_limb, overflow ? UINT32_C(1) : UINT32_C(0), limb_bits); 4241 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 4242 } 4243 4244 remaining_bytes -= 32 / CHAR_BIT; 4245 4246 #if zig_little_endian 4247 byte_offset += 32 / CHAR_BIT; 4248 #endif 4249 } 4250 4251 while (remaining_bytes >= 16 / CHAR_BIT) { 4252 uint8_t limb_bits = 16 - (remaining_bytes == 16 / CHAR_BIT ? top_bits : 0); 4253 4254 #if zig_big_endian 4255 byte_offset -= 16 / CHAR_BIT; 4256 #endif 4257 4258 if (remaining_bytes == 16 / CHAR_BIT && is_signed) { 4259 int16_t res_limb; 4260 int16_t tmp_limb; 4261 int16_t lhs_limb; 4262 int16_t rhs_limb; 4263 bool limb_overflow; 4264 4265 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 4266 memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); 4267 limb_overflow = zig_addo_i16(&tmp_limb, lhs_limb, rhs_limb, limb_bits); 4268 overflow = limb_overflow ^ zig_addo_i16(&res_limb, tmp_limb, overflow ? INT16_C(1) : INT16_C(0), limb_bits); 4269 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 4270 } else { 4271 uint16_t res_limb; 4272 uint16_t tmp_limb; 4273 uint16_t lhs_limb; 4274 uint16_t rhs_limb; 4275 bool limb_overflow; 4276 4277 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 4278 memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); 4279 limb_overflow = zig_addo_u16(&tmp_limb, lhs_limb, rhs_limb, limb_bits); 4280 overflow = limb_overflow ^ zig_addo_u16(&res_limb, tmp_limb, overflow ? UINT16_C(1) : UINT16_C(0), limb_bits); 4281 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 4282 } 4283 4284 remaining_bytes -= 16 / CHAR_BIT; 4285 4286 #if zig_little_endian 4287 byte_offset += 16 / CHAR_BIT; 4288 #endif 4289 } 4290 4291 while (remaining_bytes >= 8 / CHAR_BIT) { 4292 uint8_t limb_bits = 8 - (remaining_bytes == 8 / CHAR_BIT ? top_bits : 0); 4293 4294 #if zig_big_endian 4295 byte_offset -= 8 / CHAR_BIT; 4296 #endif 4297 4298 if (remaining_bytes == 8 / CHAR_BIT && is_signed) { 4299 int8_t res_limb; 4300 int8_t tmp_limb; 4301 int8_t lhs_limb; 4302 int8_t rhs_limb; 4303 bool limb_overflow; 4304 4305 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 4306 memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); 4307 limb_overflow = zig_addo_i8(&tmp_limb, lhs_limb, rhs_limb, limb_bits); 4308 overflow = limb_overflow ^ zig_addo_i8(&res_limb, tmp_limb, overflow ? INT8_C(1) : INT8_C(0), limb_bits); 4309 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 4310 } else { 4311 uint8_t res_limb; 4312 uint8_t tmp_limb; 4313 uint8_t lhs_limb; 4314 uint8_t rhs_limb; 4315 bool limb_overflow; 4316 4317 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 4318 memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); 4319 limb_overflow = zig_addo_u8(&tmp_limb, lhs_limb, rhs_limb, limb_bits); 4320 overflow = limb_overflow ^ zig_addo_u8(&res_limb, tmp_limb, overflow ? UINT8_C(1) : UINT8_C(0), limb_bits); 4321 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 4322 } 4323 4324 remaining_bytes -= 8 / CHAR_BIT; 4325 4326 #if zig_little_endian 4327 byte_offset += 8 / CHAR_BIT; 4328 #endif 4329 } 4330 4331 return overflow; 4332 } 4333 4334 static inline bool zig_subo_big(void *res, const void *lhs, const void *rhs, bool is_signed, uint16_t bits) { 4335 uint8_t *res_bytes = res; 4336 const uint8_t *lhs_bytes = lhs; 4337 const uint8_t *rhs_bytes = rhs; 4338 uint16_t byte_offset = 0; 4339 uint16_t remaining_bytes = zig_int_bytes(bits); 4340 uint8_t top_bits = zig_u8_intCast_u16(remaining_bytes * CHAR_BIT - bits); 4341 bool overflow = false; 4342 4343 #if zig_big_endian 4344 byte_offset = remaining_bytes; 4345 #endif 4346 4347 while (remaining_bytes >= 128 / CHAR_BIT) { 4348 uint8_t limb_bits = 128 - (remaining_bytes == 128 / CHAR_BIT ? top_bits : 0); 4349 4350 #if zig_big_endian 4351 byte_offset -= 128 / CHAR_BIT; 4352 #endif 4353 4354 if (remaining_bytes == 128 / CHAR_BIT && is_signed) { 4355 zig_i128 res_limb; 4356 zig_i128 tmp_limb; 4357 zig_i128 lhs_limb; 4358 zig_i128 rhs_limb; 4359 bool limb_overflow; 4360 4361 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 4362 memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); 4363 limb_overflow = zig_subo_i128(&tmp_limb, lhs_limb, rhs_limb, limb_bits); 4364 overflow = limb_overflow ^ zig_subo_i128(&res_limb, tmp_limb, zig_make_i128(INT64_C(0), overflow ? UINT64_C(1) : UINT64_C(0)), limb_bits); 4365 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 4366 } else { 4367 zig_u128 res_limb; 4368 zig_u128 tmp_limb; 4369 zig_u128 lhs_limb; 4370 zig_u128 rhs_limb; 4371 bool limb_overflow; 4372 4373 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 4374 memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); 4375 limb_overflow = zig_subo_u128(&tmp_limb, lhs_limb, rhs_limb, limb_bits); 4376 overflow = limb_overflow ^ zig_subo_u128(&res_limb, tmp_limb, zig_make_u128(UINT64_C(0), overflow ? UINT64_C(1) : UINT64_C(0)), limb_bits); 4377 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 4378 } 4379 4380 remaining_bytes -= 128 / CHAR_BIT; 4381 4382 #if zig_little_endian 4383 byte_offset += 128 / CHAR_BIT; 4384 #endif 4385 } 4386 4387 while (remaining_bytes >= 64 / CHAR_BIT) { 4388 uint8_t limb_bits = 64 - (remaining_bytes == 64 / CHAR_BIT ? top_bits : 0); 4389 4390 #if zig_big_endian 4391 byte_offset -= 64 / CHAR_BIT; 4392 #endif 4393 4394 if (remaining_bytes == 64 / CHAR_BIT && is_signed) { 4395 int64_t res_limb; 4396 int64_t tmp_limb; 4397 int64_t lhs_limb; 4398 int64_t rhs_limb; 4399 bool limb_overflow; 4400 4401 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 4402 memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); 4403 limb_overflow = zig_subo_i64(&tmp_limb, lhs_limb, rhs_limb, limb_bits); 4404 overflow = limb_overflow ^ zig_subo_i64(&res_limb, tmp_limb, overflow ? INT64_C(1) : INT64_C(0), limb_bits); 4405 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 4406 } else { 4407 uint64_t res_limb; 4408 uint64_t tmp_limb; 4409 uint64_t lhs_limb; 4410 uint64_t rhs_limb; 4411 bool limb_overflow; 4412 4413 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 4414 memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); 4415 limb_overflow = zig_subo_u64(&tmp_limb, lhs_limb, rhs_limb, limb_bits); 4416 overflow = limb_overflow ^ zig_subo_u64(&res_limb, tmp_limb, overflow ? UINT64_C(1) : UINT64_C(0), limb_bits); 4417 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 4418 } 4419 4420 remaining_bytes -= 64 / CHAR_BIT; 4421 4422 #if zig_little_endian 4423 byte_offset += 64 / CHAR_BIT; 4424 #endif 4425 } 4426 4427 while (remaining_bytes >= 32 / CHAR_BIT) { 4428 uint8_t limb_bits = 32 - (remaining_bytes == 32 / CHAR_BIT ? top_bits : 0); 4429 4430 #if zig_big_endian 4431 byte_offset -= 32 / CHAR_BIT; 4432 #endif 4433 4434 if (remaining_bytes == 32 / CHAR_BIT && is_signed) { 4435 int32_t res_limb; 4436 int32_t tmp_limb; 4437 int32_t lhs_limb; 4438 int32_t rhs_limb; 4439 bool limb_overflow; 4440 4441 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 4442 memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); 4443 limb_overflow = zig_subo_i32(&tmp_limb, lhs_limb, rhs_limb, limb_bits); 4444 overflow = limb_overflow ^ zig_subo_i32(&res_limb, tmp_limb, overflow ? INT32_C(1) : INT32_C(0), limb_bits); 4445 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 4446 } else { 4447 uint32_t res_limb; 4448 uint32_t tmp_limb; 4449 uint32_t lhs_limb; 4450 uint32_t rhs_limb; 4451 bool limb_overflow; 4452 4453 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 4454 memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); 4455 limb_overflow = zig_subo_u32(&tmp_limb, lhs_limb, rhs_limb, limb_bits); 4456 overflow = limb_overflow ^ zig_subo_u32(&res_limb, tmp_limb, overflow ? UINT32_C(1) : UINT32_C(0), limb_bits); 4457 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 4458 } 4459 4460 remaining_bytes -= 32 / CHAR_BIT; 4461 4462 #if zig_little_endian 4463 byte_offset += 32 / CHAR_BIT; 4464 #endif 4465 } 4466 4467 while (remaining_bytes >= 16 / CHAR_BIT) { 4468 uint8_t limb_bits = 16 - (remaining_bytes == 16 / CHAR_BIT ? top_bits : 0); 4469 4470 #if zig_big_endian 4471 byte_offset -= 16 / CHAR_BIT; 4472 #endif 4473 4474 if (remaining_bytes == 16 / CHAR_BIT && is_signed) { 4475 int16_t res_limb; 4476 int16_t tmp_limb; 4477 int16_t lhs_limb; 4478 int16_t rhs_limb; 4479 bool limb_overflow; 4480 4481 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 4482 memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); 4483 limb_overflow = zig_subo_i16(&tmp_limb, lhs_limb, rhs_limb, limb_bits); 4484 overflow = limb_overflow ^ zig_subo_i16(&res_limb, tmp_limb, overflow ? INT16_C(1) : INT16_C(0), limb_bits); 4485 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 4486 } else { 4487 uint16_t res_limb; 4488 uint16_t tmp_limb; 4489 uint16_t lhs_limb; 4490 uint16_t rhs_limb; 4491 bool limb_overflow; 4492 4493 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 4494 memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); 4495 limb_overflow = zig_subo_u16(&tmp_limb, lhs_limb, rhs_limb, limb_bits); 4496 overflow = limb_overflow ^ zig_subo_u16(&res_limb, tmp_limb, overflow ? UINT16_C(1) : UINT16_C(0), limb_bits); 4497 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 4498 } 4499 4500 remaining_bytes -= 16 / CHAR_BIT; 4501 4502 #if zig_little_endian 4503 byte_offset += 16 / CHAR_BIT; 4504 #endif 4505 } 4506 4507 while (remaining_bytes >= 8 / CHAR_BIT) { 4508 uint8_t limb_bits = 8 - (remaining_bytes == 8 / CHAR_BIT ? top_bits : 0); 4509 4510 #if zig_big_endian 4511 byte_offset -= 8 / CHAR_BIT; 4512 #endif 4513 4514 if (remaining_bytes == 8 / CHAR_BIT && is_signed) { 4515 int8_t res_limb; 4516 int8_t tmp_limb; 4517 int8_t lhs_limb; 4518 int8_t rhs_limb; 4519 bool limb_overflow; 4520 4521 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 4522 memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); 4523 limb_overflow = zig_subo_i8(&tmp_limb, lhs_limb, rhs_limb, limb_bits); 4524 overflow = limb_overflow ^ zig_subo_i8(&res_limb, tmp_limb, overflow ? INT8_C(1) : INT8_C(0), limb_bits); 4525 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 4526 } else { 4527 uint8_t res_limb; 4528 uint8_t tmp_limb; 4529 uint8_t lhs_limb; 4530 uint8_t rhs_limb; 4531 bool limb_overflow; 4532 4533 memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); 4534 memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); 4535 limb_overflow = zig_subo_u8(&tmp_limb, lhs_limb, rhs_limb, limb_bits); 4536 overflow = limb_overflow ^ zig_subo_u8(&res_limb, tmp_limb, overflow ? UINT8_C(1) : UINT8_C(0), limb_bits); 4537 memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); 4538 } 4539 4540 remaining_bytes -= 8 / CHAR_BIT; 4541 4542 #if zig_little_endian 4543 byte_offset += 8 / CHAR_BIT; 4544 #endif 4545 } 4546 4547 return overflow; 4548 } 4549 4550 static inline void zig_add_big(void *res, const void *lhs, const void *rhs, bool is_signed, uint16_t bits) { 4551 if (zig_addo_big(res, lhs, rhs, is_signed, bits)) zig_trap(); // panic: integer overflow 4552 } 4553 4554 static inline void zig_addw_big(void *res, const void *lhs, const void *rhs, bool is_signed, uint16_t bits) { 4555 (void)zig_addo_big(res, lhs, rhs, is_signed, bits); 4556 } 4557 4558 static inline void zig_adds_big(void *res, const void *lhs, const void *rhs, bool is_signed, uint16_t bits) { 4559 int8_t sat_sign = zig_signFill_big(lhs, is_signed, bits); 4560 4561 if (!zig_addo_big(res, lhs, rhs, is_signed, bits)) return; 4562 switch (sat_sign) { 4563 case -INT8_C(1): return zig_minInt_big(res, is_signed, bits); 4564 case INT8_C(0): return zig_maxInt_big(res, is_signed, bits); 4565 } 4566 } 4567 4568 static inline void zig_sub_big(void *res, const void *lhs, const void *rhs, bool is_signed, uint16_t bits) { 4569 if (zig_subo_big(res, lhs, rhs, is_signed, bits)) zig_trap(); // panic: integer overflow 4570 } 4571 4572 static inline void zig_subw_big(void *res, const void *lhs, const void *rhs, bool is_signed, uint16_t bits) { 4573 (void)zig_subo_big(res, lhs, rhs, is_signed, bits); 4574 } 4575 4576 static inline void zig_subs_big(void *res, const void *lhs, const void *rhs, bool is_signed, uint16_t bits) { 4577 int8_t sat_sign = is_signed ? zig_signFill_big(lhs, is_signed, bits) : -INT8_C(1); 4578 4579 if (!zig_subo_big(res, lhs, rhs, is_signed, bits)) return; 4580 switch (sat_sign) { 4581 case -INT8_C(1): return zig_minInt_big(res, is_signed, bits); 4582 case INT8_C(0): return zig_maxInt_big(res, is_signed, bits); 4583 } 4584 } 4585 4586 static inline bool zig_mulo_big(void *res, const void *lhs, const void *rhs, bool is_signed, uint16_t bits) { 4587 uint8_t *res_bytes = res; 4588 const uint8_t *lhs_bytes = lhs; 4589 const uint8_t *rhs_bytes = rhs; 4590 uint16_t size = zig_int_bytes(bits); 4591 uint16_t sign_byte_offset = zig_shr_u16(bits - UINT16_C(1), UINT8_C(3)) + UINT16_C(1); 4592 uint8_t lhs_sign_fill = zig_u8_bitCast_i8(zig_signFill_big(lhs, is_signed, bits), UINT8_C(8)); 4593 uint8_t rhs_sign_fill = zig_u8_bitCast_i8(zig_signFill_big(rhs, is_signed, bits), UINT8_C(8)); 4594 uint16_t lhs_byte_offset = sign_byte_offset; 4595 uint16_t lhs_end_byte_offset = UINT16_C(0); 4596 bool overflow = false; 4597 4598 #if zig_big_endian 4599 lhs_byte_offset = size - lhs_byte_offset; 4600 lhs_end_byte_offset = size - lhs_end_byte_offset; 4601 #endif 4602 4603 while (lhs_byte_offset != lhs_end_byte_offset) { 4604 uint16_t rhs_byte_offset = UINT16_C(0); 4605 uint16_t end_byte_offset = sign_byte_offset; 4606 uint16_t res_byte_offset; 4607 uint16_t lhs_byte; 4608 uint8_t res_byte = UINT8_C(0); 4609 uint16_t mul_res = UINT16_C(0); 4610 uint8_t carry = UINT8_C(0); 4611 4612 #if zig_little_endian 4613 lhs_byte_offset -= UINT16_C(1); 4614 #else 4615 rhs_byte_offset = size - rhs_byte_offset; 4616 end_byte_offset = size - end_byte_offset; 4617 #endif 4618 4619 lhs_byte = zig_u16_intCast_u8(lhs_bytes[lhs_byte_offset]) ^ lhs_sign_fill; 4620 4621 #if zig_big_endian 4622 lhs_byte_offset += UINT16_C(1); 4623 #endif 4624 4625 res_byte_offset = lhs_byte_offset; 4626 4627 while (res_byte_offset != end_byte_offset) { 4628 bool res_byte_initialized = res_byte_offset != lhs_byte_offset; 4629 4630 #if zig_big_endian 4631 rhs_byte_offset -= UINT16_C(1); 4632 res_byte_offset -= UINT16_C(1); 4633 #endif 4634 4635 if (res_byte_initialized) res_byte = res_bytes[res_byte_offset]; 4636 carry = zig_addo_u8(&res_byte, res_byte, carry, UINT8_C(8)); 4637 carry += zig_addo_u8(&res_byte, res_byte, zig_u8_intCast_u16( 4638 zig_shr_u16(mul_res, UINT8_C(8)) 4639 ), UINT8_C(8)); 4640 mul_res = lhs_byte * zig_u16_intCast_u8(rhs_bytes[rhs_byte_offset] ^ rhs_sign_fill); 4641 carry += zig_addo_u8(&res_bytes[res_byte_offset], res_byte, zig_u8_truncate_u16( 4642 mul_res, 4643 UINT8_C(8) 4644 ), UINT8_C(8)); 4645 4646 #if zig_little_endian 4647 rhs_byte_offset += UINT16_C(1); 4648 res_byte_offset += UINT16_C(1); 4649 #endif 4650 } 4651 4652 while (rhs_byte_offset != end_byte_offset) { 4653 #if zig_big_endian 4654 rhs_byte_offset -= UINT16_C(1); 4655 #endif 4656 4657 carry = zig_addo_u8( 4658 &res_byte, 4659 zig_u8_intCast_u16(zig_shr_u16(mul_res, UINT8_C(8))), 4660 carry, 4661 UINT8_C(8) 4662 ); 4663 mul_res = lhs_byte * zig_u16_intCast_u8(rhs_bytes[rhs_byte_offset] ^ rhs_sign_fill); 4664 carry += zig_addo_u8(&res_byte, res_byte, zig_u8_truncate_u16( 4665 mul_res, 4666 UINT8_C(8) 4667 ), UINT8_C(8)); 4668 overflow |= res_byte != UINT8_C(0); 4669 4670 #if zig_little_endian 4671 rhs_byte_offset += UINT16_C(1); 4672 #endif 4673 } 4674 4675 overflow |= zig_shr_u16(mul_res, UINT8_C(8)) != UINT16_C(0); 4676 overflow |= carry != UINT8_C(0); 4677 } 4678 4679 #if zig_little_endian 4680 sign_byte_offset -= UINT64_C(1); 4681 #else 4682 sign_byte_offset = size - sign_byte_offset; 4683 #endif 4684 4685 if (lhs_sign_fill != rhs_sign_fill) { 4686 uint16_t byte_offset = UINT16_C(0); 4687 uint16_t end_byte_offset = sign_byte_offset; 4688 uint8_t res_byte; 4689 int8_t signed_res_byte; 4690 uint8_t carry = UINT8_C(0); 4691 4692 #if zig_big_endian 4693 byte_offset = size - byte_offset; 4694 end_byte_offset += UINT16_C(1); 4695 #endif 4696 4697 while (byte_offset != end_byte_offset) { 4698 #if zig_big_endian 4699 byte_offset -= UINT16_C(1); 4700 #endif 4701 4702 carry = zig_subo_u8(&res_byte, UINT8_C(0), carry, UINT8_C(8)); 4703 carry += zig_subo_u8(&res_byte, res_byte, res_bytes[byte_offset], UINT8_C(8)); 4704 carry += zig_subo_u8( 4705 &res_bytes[byte_offset], 4706 res_byte, 4707 (lhs_sign_fill == UINT8_C(0) ? lhs_bytes : rhs_bytes)[byte_offset], 4708 UINT8_C(8) 4709 ); 4710 4711 #if zig_little_endian 4712 byte_offset += UINT16_C(1); 4713 #endif 4714 } 4715 4716 #if zig_big_endian 4717 byte_offset -= UINT16_C(1); 4718 #endif 4719 4720 signed_res_byte = zig_i8_bitCast_u8(res_bytes[byte_offset], UINT8_C(8)); 4721 overflow |= signed_res_byte < INT8_C(0); 4722 overflow |= zig_subo_i8(&signed_res_byte, INT8_C(0), signed_res_byte, UINT8_C(8)); 4723 overflow |= zig_subo_i8(&signed_res_byte, signed_res_byte, zig_i8_intCast_u8(carry), UINT8_C(8)); 4724 overflow |= zig_subo_i8(&signed_res_byte, signed_res_byte, zig_i8_bitCast_u8( 4725 (lhs_sign_fill == UINT8_C(0) ? lhs_bytes : rhs_bytes)[byte_offset], 4726 UINT8_C(8) 4727 ), UINT8_C(8)); 4728 res_bytes[byte_offset] = zig_i8_bitCast_u8(signed_res_byte, UINT8_C(8)); 4729 } else if (lhs_sign_fill != UINT8_C(0)) { 4730 uint16_t byte_offset = UINT16_C(0); 4731 uint16_t end_byte_offset = sign_byte_offset; 4732 uint8_t res_byte; 4733 int8_t signed_res_byte; 4734 uint8_t carry = UINT8_C(1); 4735 4736 #if zig_big_endian 4737 byte_offset = size - byte_offset; 4738 end_byte_offset += UINT16_C(1); 4739 #endif 4740 4741 while (byte_offset != end_byte_offset) { 4742 #if zig_big_endian 4743 byte_offset -= UINT16_C(1); 4744 #endif 4745 4746 carry = zig_subo_u8(&res_byte, res_bytes[byte_offset], carry, UINT8_C(8)); 4747 carry += zig_subo_u8(&res_byte, res_byte, lhs_bytes[byte_offset], UINT8_C(8)); 4748 carry += zig_subo_u8(&res_bytes[byte_offset], res_byte, rhs_bytes[byte_offset], UINT8_C(8)); 4749 4750 #if zig_little_endian 4751 byte_offset += UINT16_C(1); 4752 #endif 4753 } 4754 4755 #if zig_big_endian 4756 byte_offset -= UINT16_C(1); 4757 #endif 4758 4759 signed_res_byte = zig_i8_bitCast_u8(res_bytes[byte_offset], UINT8_C(8)); 4760 overflow |= signed_res_byte < INT8_C(0); 4761 overflow |= zig_subo_i8(&signed_res_byte, signed_res_byte, zig_i8_intCast_u8(carry), UINT8_C(8)); 4762 overflow |= zig_subo_i8(&signed_res_byte, signed_res_byte, zig_i8_bitCast_u8( 4763 lhs_bytes[byte_offset], 4764 UINT8_C(8) 4765 ), UINT8_C(8)); 4766 overflow |= zig_subo_i8(&signed_res_byte, signed_res_byte, zig_i8_bitCast_u8( 4767 rhs_bytes[byte_offset], 4768 UINT8_C(8) 4769 ), UINT8_C(8)); 4770 res_bytes[byte_offset] = zig_i8_bitCast_u8(signed_res_byte, UINT8_C(8)); 4771 } else if (is_signed) { 4772 int8_t signed_res_byte = zig_i8_bitCast_u8(res_bytes[sign_byte_offset], UINT8_C(8)); 4773 4774 overflow |= signed_res_byte < INT8_C(0); 4775 } 4776 4777 { 4778 uint8_t truncate_bits = zig_u8_truncate_u16(bits - UINT16_C(1), UINT8_C(3)) + UINT16_C(1); 4779 uint8_t fill_byte = UINT8_C(0); 4780 4781 if (is_signed) { 4782 int8_t sign_byte = zig_i8_bitCast_u8(res_bytes[sign_byte_offset], UINT8_C(8)); 4783 int8_t truncated = zig_i8_truncate_i8(sign_byte, truncate_bits); 4784 4785 overflow |= sign_byte != truncated; 4786 res_bytes[sign_byte_offset] = zig_u8_bitCast_i8(truncated, UINT8_C(8)); 4787 fill_byte = zig_u8_bitCast_i8(zig_shr_i8(truncated, UINT8_C(7)), UINT8_C(8)); 4788 } else { 4789 uint8_t sign_byte = res_bytes[sign_byte_offset]; 4790 uint8_t truncated = zig_u8_truncate_u8(sign_byte, truncate_bits); 4791 4792 overflow |= sign_byte != truncated; 4793 res_bytes[sign_byte_offset] = truncated; 4794 } 4795 4796 #if zig_little_endian 4797 sign_byte_offset += UINT16_C(1); 4798 memset(&res_bytes[sign_byte_offset], fill_byte, size - sign_byte_offset); 4799 #else 4800 memset(&res_bytes[0], fill_byte, sign_byte_offset); 4801 #endif 4802 } 4803 4804 return overflow; 4805 } 4806 4807 static inline void zig_mul_big(void *res, const void *lhs, const void *rhs, bool is_signed, uint16_t bits) { 4808 if (zig_mulo_big(res, lhs, rhs, is_signed, bits)) zig_trap(); // panic: integer overflow 4809 } 4810 4811 static inline void zig_mulw_big(void *res, const void *lhs, const void *rhs, bool is_signed, uint16_t bits) { 4812 (void)zig_mulo_big(res, lhs, rhs, is_signed, bits); 4813 } 4814 4815 static inline void zig_muls_big(void *res, const void *lhs, const void *rhs, bool is_signed, uint16_t bits) { 4816 int8_t sat_sign = zig_signFill_big(lhs, is_signed, bits) ^ zig_signFill_big(rhs, is_signed, bits); 4817 4818 if (!zig_mulo_big(res, lhs, rhs, is_signed, bits)) return; 4819 switch (sat_sign) { 4820 case -INT8_C(1): return zig_minInt_big(res, is_signed, bits); 4821 case INT8_C(0): return zig_maxInt_big(res, is_signed, bits); 4822 } 4823 } 4824 4825 static inline void zig_divTrunc_big(void *res, const void *lhs, const void *rhs, void *temp, bool is_signed, uint16_t bits) { 4826 if (is_signed) { 4827 zig_extern void __divei5(uint32_t *res, const uint32_t *lhs, const uint32_t *rhs, uint32_t *temp, uintptr_t bits); 4828 __divei5(res, lhs, rhs, temp, bits); 4829 } else { 4830 zig_extern void __udivei5(uint32_t *res, const uint32_t *lhs, const uint32_t *rhs, uint32_t *temp, uintptr_t bits); 4831 __udivei5(res, lhs, rhs, temp, bits); 4832 } 4833 } 4834 4835 static inline void zig_rem_big(void *res, const void *lhs, const void *rhs, void *temp, bool is_signed, uint16_t bits) { 4836 if (is_signed) { 4837 zig_extern void __modei5(uint32_t *res, const uint32_t *lhs, const uint32_t *rhs, uint32_t *temp, uintptr_t bits); 4838 __modei5(res, lhs, rhs, temp, bits); 4839 } else { 4840 zig_extern void __umodei5(uint32_t *res, const uint32_t *lhs, const uint32_t *rhs, uint32_t *temp, uintptr_t bits); 4841 __umodei5(res, lhs, rhs, temp, bits); 4842 } 4843 } 4844 4845 static inline void zig_divFloor_big(void *res, const void *lhs, const void *rhs, void *temp, bool is_signed, uint16_t bits) { 4846 bool decrement = false; 4847 4848 if (is_signed) { 4849 zig_rem_big(res, lhs, rhs, temp, is_signed, bits); 4850 decrement = zig_u32_bitCast_i32(zig_xor_i32( 4851 zig_cmp_big_u8(res, UINT8_C(0), is_signed, bits), 4852 zig_and_i32(zig_i32_intCast_i8(zig_signFill_big(rhs, is_signed, bits)), zig_minInt_i32) 4853 ), UINT8_C(32)) > zig_u32_bitCast_i32(zig_minInt_i32, UINT8_C(32)); 4854 } 4855 zig_divTrunc_big(res, lhs, rhs, temp, is_signed, bits); 4856 if (decrement) zig_decrement_big(res, is_signed, bits); 4857 } 4858 4859 static inline void zig_divCeil_big(void *res, const void *lhs, const void *rhs, void *temp, bool is_signed, uint16_t bits) { 4860 bool increment = false; 4861 4862 zig_rem_big(res, lhs, rhs, temp, is_signed, bits); 4863 increment = zig_xor_i32( 4864 zig_cmp_big_u8(res, UINT8_C(0), is_signed, bits), 4865 zig_and_i32(zig_i32_intCast_i8(zig_signFill_big(rhs, is_signed, bits)), zig_minInt_i32) 4866 ) > INT32_C(0); 4867 zig_divTrunc_big(res, lhs, rhs, temp, is_signed, bits); 4868 if (increment) zig_increment_big(res, is_signed, bits); 4869 } 4870 4871 static inline void zig_mod_big(void *res, const void *lhs, const void *rhs, void *temp, bool is_signed, uint16_t bits) { 4872 bool fixup = false; 4873 4874 zig_rem_big(res, lhs, rhs, temp, is_signed, bits); 4875 if (is_signed && zig_u32_bitCast_i32(zig_xor_i32( 4876 zig_cmp_big_u8(res, UINT8_C(0), is_signed, bits), 4877 zig_and_i32(zig_i32_intCast_i8(zig_signFill_big(rhs, is_signed, bits)), zig_minInt_i32) 4878 ), UINT8_C(32)) > zig_u32_bitCast_i32(zig_minInt_i32, UINT8_C(32))) zig_add_big(res, res, rhs, is_signed, bits); 4879 } 4880 4881 static inline void zig_shr_big(void *res, const void *lhs, uint16_t rhs, bool is_signed, uint16_t bits) { 4882 uint8_t *res_bytes = res; 4883 const uint8_t *lhs_bytes = lhs; 4884 uint16_t size = zig_int_bytes(bits); 4885 uint16_t res_byte_offset = UINT16_C(0); 4886 uint16_t lhs_byte_offset = zig_shr_u16(rhs, UINT8_C(3)); 4887 uint16_t end_byte_offset = zig_shr_u16(bits - UINT16_C(1), UINT8_C(3)) + UINT16_C(1); 4888 uint8_t lhs_prev_byte; 4889 uint8_t byte_shift = zig_u8_truncate_u16(rhs, UINT8_C(3)); 4890 4891 #if zig_big_endian 4892 res_byte_offset = size - res_byte_offset; 4893 lhs_byte_offset = size - lhs_byte_offset; 4894 end_byte_offset = size - end_byte_offset; 4895 #endif 4896 4897 { 4898 #if zig_big_endian 4899 lhs_byte_offset -= UINT16_C(1); 4900 #endif 4901 4902 lhs_prev_byte = lhs_bytes[lhs_byte_offset]; 4903 4904 #if zig_little_endian 4905 lhs_byte_offset += UINT16_C(1); 4906 #endif 4907 } 4908 4909 while (lhs_byte_offset != end_byte_offset) { 4910 #if zig_big_endian 4911 res_byte_offset -= UINT16_C(1); 4912 lhs_byte_offset -= UINT16_C(1); 4913 #endif 4914 4915 { 4916 uint8_t lhs_byte = lhs_bytes[lhs_byte_offset]; 4917 4918 res_bytes[res_byte_offset] = zig_u8_intCast_u16(zig_shr_u16(zig_or_u16( 4919 zig_shl_u16(zig_u16_intCast_u8(lhs_byte), UINT8_C(8)), 4920 zig_u16_intCast_u8(lhs_prev_byte) 4921 ), byte_shift)); 4922 lhs_prev_byte = lhs_byte; 4923 } 4924 4925 #if zig_little_endian 4926 res_byte_offset += UINT16_C(1); 4927 lhs_byte_offset += UINT16_C(1); 4928 #endif 4929 } 4930 4931 { 4932 uint8_t lhs_sign_fill = UINT8_C(0); 4933 4934 #if zig_big_endian 4935 res_byte_offset -= UINT16_C(1); 4936 #endif 4937 4938 if (is_signed) { 4939 int8_t signed_byte = zig_i8_bitCast_u8(lhs_prev_byte, UINT8_C(8)); 4940 4941 res_bytes[res_byte_offset] = zig_shr_i8(signed_byte, byte_shift); 4942 lhs_sign_fill = zig_u8_bitCast_i8(zig_shr_i8(signed_byte, UINT8_C(7)), UINT8_C(8)); 4943 } else { 4944 res_bytes[res_byte_offset] = zig_shr_u8(lhs_prev_byte, byte_shift); 4945 } 4946 4947 #if zig_little_endian 4948 res_byte_offset += UINT16_C(1); 4949 memset(&res_bytes[res_byte_offset], lhs_sign_fill, size - res_byte_offset); 4950 #else 4951 memset(&res_bytes[0], lhs_sign_fill, res_byte_offset); 4952 #endif 4953 } 4954 } 4955 4956 static inline bool zig_shlo_big(void *res, const void *lhs, uint16_t rhs, bool is_signed, uint16_t bits) { 4957 uint8_t *res_bytes = res; 4958 const uint8_t *lhs_bytes = lhs; 4959 uint8_t lhs_sign_fill = zig_u8_bitCast_i8(zig_signFill_big(lhs, is_signed, bits), UINT8_C(8)); 4960 uint16_t size = zig_int_bytes(bits); 4961 uint16_t res_byte_offset = zig_shr_u16(bits - UINT16_C(1), UINT8_C(3)) + UINT16_C(1); 4962 uint16_t lhs_byte_offset = UINT16_C(0); 4963 uint16_t end_byte_offset = res_byte_offset - UINT16_C(1) - zig_shr_u16(rhs, UINT8_C(3)); 4964 uint8_t lhs_prev_byte = lhs_sign_fill; 4965 uint8_t byte_shift = UINT8_C(8) - zig_u8_truncate_u16(rhs, UINT8_C(3)); 4966 bool overflow = false; 4967 4968 #if zig_little_endian 4969 lhs_byte_offset = size - lhs_byte_offset; 4970 #else 4971 res_byte_offset = size - res_byte_offset; 4972 end_byte_offset = size - end_byte_offset; 4973 #endif 4974 4975 while (lhs_byte_offset != end_byte_offset) { 4976 #if zig_little_endian 4977 lhs_byte_offset -= UINT16_C(1); 4978 #endif 4979 4980 overflow |= lhs_prev_byte != lhs_sign_fill; 4981 lhs_prev_byte = lhs_bytes[lhs_byte_offset]; 4982 4983 #if zig_big_endian 4984 lhs_byte_offset += UINT16_C(1); 4985 #endif 4986 } 4987 4988 #if zig_little_endian 4989 end_byte_offset = UINT16_C(0); 4990 #else 4991 end_byte_offset = size; 4992 #endif 4993 4994 { 4995 bool lhs_more_bytes = lhs_byte_offset != end_byte_offset; 4996 4997 #if zig_little_endian 4998 if (lhs_more_bytes) lhs_byte_offset -= UINT16_C(1); 4999 #endif 5000 5001 { 5002 uint8_t lhs_byte = UINT8_C(0); 5003 5004 if (lhs_more_bytes) lhs_byte = lhs_bytes[lhs_byte_offset]; 5005 5006 if (is_signed) { 5007 int16_t shifted = zig_shr_i16(zig_or_i16( 5008 zig_shl_i16(zig_i16_intCast_u8(lhs_prev_byte), UINT8_C(8)), 5009 zig_i16_intCast_u8(lhs_byte) 5010 ), byte_shift); 5011 int8_t truncated = zig_i8_truncate_i16( 5012 shifted, 5013 zig_u8_truncate_u16(bits - UINT16_C(1), UINT8_C(3)) + UINT8_C(1) 5014 ); 5015 uint8_t fill = zig_u8_bitCast_i8(zig_shr_i8(truncated, UINT8_C(7)), UINT8_C(8)); 5016 5017 overflow |= zig_i16_intCast_i8(truncated) != shifted; 5018 #if zig_little_endian 5019 memset(&res_bytes[res_byte_offset], fill, size - res_byte_offset); 5020 res_byte_offset -= UINT16_C(1); 5021 #else 5022 memset(&res_bytes[0], fill, res_byte_offset); 5023 #endif 5024 res_bytes[res_byte_offset] = zig_u8_bitCast_i8(truncated, UINT8_C(8)); 5025 } else { 5026 uint16_t shifted = zig_shr_u16(zig_or_u16( 5027 zig_shl_u16(zig_u16_intCast_u8(lhs_prev_byte), UINT8_C(8)), 5028 zig_u16_intCast_u8(lhs_byte) 5029 ), byte_shift); 5030 uint8_t truncated = zig_u8_truncate_u16( 5031 shifted, 5032 zig_u8_truncate_u16(bits - UINT16_C(1), UINT8_C(3)) + UINT8_C(1) 5033 ); 5034 5035 overflow |= zig_u16_intCast_u8(truncated) != shifted; 5036 #if zig_little_endian 5037 memset(&res_bytes[res_byte_offset], zig_minInt_u8, size - res_byte_offset); 5038 res_byte_offset -= UINT16_C(1); 5039 #else 5040 memset(&res_bytes[0], zig_minInt_u8, res_byte_offset); 5041 #endif 5042 res_bytes[res_byte_offset] = truncated; 5043 } 5044 5045 lhs_prev_byte = lhs_byte; 5046 } 5047 5048 #if zig_big_endian 5049 res_byte_offset += UINT16_C(1); 5050 if (lhs_more_bytes) lhs_byte_offset += UINT16_C(1); 5051 #endif 5052 } 5053 5054 while (lhs_byte_offset != end_byte_offset) { 5055 #if zig_little_endian 5056 res_byte_offset -= UINT16_C(1); 5057 lhs_byte_offset -= UINT16_C(1); 5058 #endif 5059 5060 { 5061 uint8_t lhs_byte = lhs_bytes[lhs_byte_offset]; 5062 5063 res_bytes[res_byte_offset] = zig_u8_intCast_u16(zig_shr_u16(zig_or_u16( 5064 zig_shl_u16(zig_u16_intCast_u8(lhs_prev_byte), UINT8_C(8)), 5065 zig_u16_intCast_u8(lhs_byte) 5066 ), byte_shift)); 5067 lhs_prev_byte = lhs_byte; 5068 } 5069 5070 #if zig_big_endian 5071 res_byte_offset += UINT16_C(1); 5072 lhs_byte_offset += UINT16_C(1); 5073 #endif 5074 } 5075 5076 { 5077 #if zig_little_endian 5078 res_byte_offset -= UINT16_C(1); 5079 #endif 5080 5081 res_bytes[res_byte_offset] = zig_u8_intCast_u16(zig_shr_u16( 5082 zig_shl_u16(zig_u16_intCast_u8(lhs_prev_byte), UINT8_C(8)), 5083 byte_shift 5084 )); 5085 5086 #if zig_big_endian 5087 res_byte_offset += UINT16_C(1); 5088 #endif 5089 } 5090 5091 #if zig_little_endian 5092 memset(&res_bytes[0], zig_minInt_u8, res_byte_offset); 5093 #else 5094 memset(&res_bytes[res_byte_offset], zig_minInt_u8, size - res_byte_offset);