╭─────────────╮╭────────────╮ │scroll to top││next lines →│ ╰─────────────╯╰────────────╯ ╭ zig.h ────────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭ find file ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ ╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │ │ │http│ ssh │ │ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
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); 5095 #endif 5096 5097 return overflow; 5098 } 5099 5100 static inline void zig_shl_big(void *res, const void *lhs, uint16_t rhs, bool is_signed, uint16_t bits) { 5101 if (zig_shlo_big(res, lhs, rhs, is_signed, bits)) zig_trap(); // panic: left shift overflowed bits 5102 } 5103 5104 static inline void zig_shlw_big(void *res, const void *lhs, uint16_t rhs, bool is_signed, uint16_t bits) { 5105 (void)zig_shlo_big(res, lhs, rhs, is_signed, bits); 5106 } 5107 5108 #define zig_big_shls_builtin(w) \ 5109 static inline uint##w##_t zig_shls_u##w##_big(uint##w##_t lhs, const void *rhs, \ 5110 uint8_t lhs_bits, bool rhs_is_signed, uint16_t rhs_bits) { \ 5111 uint##w##_t res; \ 5112 const uint8_t *rhs_bytes = rhs; \ 5113 if (zig_cmp_big_u8(rhs, lhs_bits, rhs_is_signed, rhs_bits) < INT32_C(0) && \ 5114 !zig_shlo_u##w(&res, lhs, rhs_bytes[0], lhs_bits)) return res; \ 5115 return lhs == INT##w##_C(0) ? zig_minInt_u(w, lhs_bits) : zig_maxInt_u(w, lhs_bits); \ 5116 } \ 5117 \ 5118 static inline int##w##_t zig_shls_i##w##_big(int##w##_t lhs, const void *rhs, \ 5119 uint8_t lhs_bits, bool rhs_is_signed, uint16_t rhs_bits) { \ 5120 int##w##_t res; \ 5121 const uint8_t *rhs_bytes = rhs; \ 5122 if (zig_cmp_big_u8(rhs, lhs_bits, rhs_is_signed, rhs_bits) < INT32_C(0) && \ 5123 !zig_shlo_i##w(&res, lhs, rhs_bytes[0], lhs_bits)) return res; \ 5124 return lhs == INT##w##_C(0) ? INT##w##_C(0) : \ 5125 lhs < INT##w##_C(0) ? zig_minInt_i(w, lhs_bits) : zig_maxInt_i(w, lhs_bits); \ 5126 } \ 5127 \ 5128 static inline void zig_shls_big_u##w(void *res, const void *lhs, uint##w##_t rhs, bool is_signed, uint16_t bits) { \ 5129 const uint8_t *lhs_bytes = lhs; \ 5130 if (rhs < bits && !zig_shlo_big(res, lhs, zig_u16_intCast_u##w(rhs), is_signed, bits)) return; \ 5131 switch (zig_cmp_big_u8(lhs, UINT8_C(0), is_signed, bits)) { \ 5132 case -INT32_C(1): return zig_minInt_big(res, is_signed, bits); \ 5133 case INT32_C(0): return zig_minInt_big(res, false, bits); \ 5134 case INT32_C(1): return zig_maxInt_big(res, is_signed, bits); \ 5135 default: zig_unreachable(); \ 5136 } \ 5137 } 5138 zig_big_shls_builtin(8) 5139 zig_big_shls_builtin(16) 5140 zig_big_shls_builtin(32) 5141 zig_big_shls_builtin(64) 5142 5143 static inline void zig_byteSwap_big(void *res, const void *arg, bool is_signed, uint16_t bits) { 5144 uint8_t *res_bytes = res; 5145 const uint8_t *arg_bytes = arg; 5146 uint16_t res_byte_offset = UINT16_C(0); 5147 uint16_t arg_byte_offset = bits / CHAR_BIT; 5148 uint16_t end_byte_offset = UINT16_C(1); 5149 uint16_t size = zig_int_bytes(bits); 5150 5151 #if zig_big_endian 5152 res_byte_offset = size - res_byte_offset; 5153 arg_byte_offset = size - arg_byte_offset; 5154 end_byte_offset = size - end_byte_offset; 5155 #endif 5156 5157 while (arg_byte_offset != end_byte_offset) { 5158 #if zig_little_endian 5159 arg_byte_offset -= UINT16_C(1); 5160 #else 5161 res_byte_offset -= UINT16_C(1); 5162 #endif 5163 5164 res_bytes[res_byte_offset] = arg_bytes[arg_byte_offset]; 5165 5166 #if zig_little_endian 5167 res_byte_offset += UINT16_C(1); 5168 #else 5169 arg_byte_offset += UINT16_C(1); 5170 #endif 5171 } 5172 5173 { 5174 #if zig_little_endian 5175 arg_byte_offset -= UINT16_C(1); 5176 #else 5177 res_byte_offset -= UINT16_C(1); 5178 #endif 5179 5180 { 5181 uint8_t byte = arg_bytes[arg_byte_offset]; 5182 uint8_t fill = is_signed 5183 ? zig_u8_bitCast_i8(zig_shr_i8(zig_i8_bitCast_u8(byte, UINT8_C(8)), UINT8_C(7)), UINT8_C(8)) 5184 : UINT8_C(0); 5185 5186 res_bytes[res_byte_offset] = byte; 5187 5188 #if zig_little_endian 5189 res_byte_offset += UINT16_C(1); 5190 memset(&res_bytes[res_byte_offset], fill, size - res_byte_offset); 5191 #else 5192 memset(&res_bytes[0], fill, res_byte_offset); 5193 #endif 5194 } 5195 } 5196 } 5197 5198 static inline void zig_bitReverse_big(void *res, const void *arg, bool is_signed, uint16_t bits) { 5199 uint8_t *res_bytes = res; 5200 const uint8_t *arg_bytes = arg; 5201 uint16_t size = zig_int_bytes(bits); 5202 uint16_t res_byte_offset = UINT16_C(0); 5203 uint16_t arg_byte_offset = zig_shr_u16(bits - UINT16_C(1), UINT8_C(3)) + UINT16_C(1); 5204 uint16_t end_byte_offset = UINT16_C(0); 5205 uint8_t arg_prev_byte; 5206 uint8_t byte_shift = zig_u8_intCast_u16(zig_subw_u16(UINT16_C(0), bits, UINT8_C(3))); 5207 5208 #if zig_big_endian 5209 res_byte_offset = size - res_byte_offset; 5210 arg_byte_offset = size - arg_byte_offset; 5211 end_byte_offset = size - end_byte_offset; 5212 #endif 5213 5214 { 5215 #if zig_little_endian 5216 arg_byte_offset -= UINT16_C(1); 5217 #endif 5218 5219 arg_prev_byte = zig_bitReverse_u8(arg_bytes[arg_byte_offset], UINT8_C(8)); 5220 5221 #if zig_big_endian 5222 arg_byte_offset += UINT16_C(1); 5223 #endif 5224 } 5225 5226 while (arg_byte_offset != end_byte_offset) { 5227 #if zig_big_endian 5228 res_byte_offset -= UINT16_C(1); 5229 #else 5230 arg_byte_offset -= UINT16_C(1); 5231 #endif 5232 5233 { 5234 uint8_t arg_byte = zig_bitReverse_u8(arg_bytes[arg_byte_offset], UINT8_C(8)); 5235 5236 res_bytes[res_byte_offset] = zig_u8_intCast_u16(zig_shr_u16(zig_or_u16( 5237 zig_shl_u16(zig_u16_intCast_u8(arg_byte), UINT8_C(8)), 5238 zig_u16_intCast_u8(arg_prev_byte) 5239 ), byte_shift)); 5240 arg_prev_byte = arg_byte; 5241 } 5242 5243 #if zig_little_endian 5244 res_byte_offset += UINT16_C(1); 5245 #else 5246 arg_byte_offset += UINT16_C(1); 5247 #endif 5248 } 5249 5250 { 5251 uint8_t arg_sign_fill = UINT8_C(0); 5252 5253 #if zig_big_endian 5254 res_byte_offset -= UINT16_C(1); 5255 #endif 5256 5257 if (is_signed) { 5258 int8_t signed_byte = zig_i8_bitCast_u8(arg_prev_byte, UINT8_C(8)); 5259 5260 res_bytes[res_byte_offset] = zig_shr_i8(signed_byte, byte_shift); 5261 arg_sign_fill = zig_u8_bitCast_i8(zig_shr_i8(signed_byte, UINT8_C(7)), UINT8_C(8)); 5262 } else { 5263 res_bytes[res_byte_offset] = zig_shr_u8(arg_prev_byte, byte_shift); 5264 } 5265 5266 #if zig_little_endian 5267 res_byte_offset += UINT16_C(1); 5268 memset(&res_bytes[res_byte_offset], arg_sign_fill, size - res_byte_offset); 5269 #else 5270 memset(&res_bytes[0], arg_sign_fill, res_byte_offset); 5271 #endif 5272 } 5273 } 5274 5275 static inline uint16_t zig_popCount_big(const void *arg, bool is_signed, uint16_t bits) { 5276 const uint8_t *arg_bytes = arg; 5277 uint16_t byte_offset = 0; 5278 uint16_t remaining_bytes = zig_shr_u16(bits - UINT16_C(1), UINT8_C(3)) + UINT16_C(1); 5279 uint8_t top_bits = zig_u8_intCast_u16(remaining_bytes * CHAR_BIT - bits); 5280 uint16_t total_pc = 0; 5281 (void)is_signed; 5282 5283 #if zig_big_endian 5284 byte_offset = zig_int_bytes(bits); 5285 #endif 5286 5287 while (remaining_bytes >= 128 / CHAR_BIT) { 5288 uint8_t limb_bits = 128 - (remaining_bytes == 128 / CHAR_BIT ? top_bits : 0); 5289 5290 #if zig_big_endian 5291 byte_offset -= 128 / CHAR_BIT; 5292 #endif 5293 5294 { 5295 zig_u128 arg_limb; 5296 5297 memcpy(&arg_limb, &arg_bytes[byte_offset], sizeof(arg_limb)); 5298 total_pc += zig_popCount_u128(zig_u128_truncate_u128(arg_limb, limb_bits), limb_bits); 5299 } 5300 5301 remaining_bytes -= 128 / CHAR_BIT; 5302 5303 #if zig_little_endian 5304 byte_offset += 128 / CHAR_BIT; 5305 #endif 5306 } 5307 5308 while (remaining_bytes >= 64 / CHAR_BIT) { 5309 uint8_t limb_bits = 64 - (remaining_bytes == 64 / CHAR_BIT ? top_bits : 0); 5310 5311 #if zig_big_endian 5312 byte_offset -= 64 / CHAR_BIT; 5313 #endif 5314 5315 { 5316 uint64_t arg_limb; 5317 5318 memcpy(&arg_limb, &arg_bytes[byte_offset], sizeof(arg_limb)); 5319 total_pc += zig_popCount_u64(zig_u64_truncate_u64(arg_limb, limb_bits), limb_bits); 5320 } 5321 5322 remaining_bytes -= 64 / CHAR_BIT; 5323 5324 #if zig_little_endian 5325 byte_offset += 64 / CHAR_BIT; 5326 #endif 5327 } 5328 5329 while (remaining_bytes >= 32 / CHAR_BIT) { 5330 uint8_t limb_bits = 32 - (remaining_bytes == 32 / CHAR_BIT ? top_bits : 0); 5331 5332 #if zig_big_endian 5333 byte_offset -= 32 / CHAR_BIT; 5334 #endif 5335 5336 { 5337 uint32_t arg_limb; 5338 5339 memcpy(&arg_limb, &arg_bytes[byte_offset], sizeof(arg_limb)); 5340 total_pc += zig_popCount_u32(zig_u32_truncate_u32(arg_limb, limb_bits), limb_bits); 5341 } 5342 5343 remaining_bytes -= 32 / CHAR_BIT; 5344 5345 #if zig_little_endian 5346 byte_offset += 32 / CHAR_BIT; 5347 #endif 5348 } 5349 5350 while (remaining_bytes >= 16 / CHAR_BIT) { 5351 uint8_t limb_bits = 16 - (remaining_bytes == 16 / CHAR_BIT ? top_bits : 0); 5352 5353 #if zig_big_endian 5354 byte_offset -= 16 / CHAR_BIT; 5355 #endif 5356 5357 { 5358 uint16_t arg_limb; 5359 5360 memcpy(&arg_limb, &arg_bytes[byte_offset], sizeof(arg_limb)); 5361 total_pc += zig_popCount_u16(zig_u16_truncate_u16(arg_limb, limb_bits), limb_bits); 5362 } 5363 5364 remaining_bytes -= 16 / CHAR_BIT; 5365 5366 #if zig_little_endian 5367 byte_offset += 16 / CHAR_BIT; 5368 #endif 5369 } 5370 5371 while (remaining_bytes >= 8 / CHAR_BIT) { 5372 uint8_t limb_bits = 8 - (remaining_bytes == 8 / CHAR_BIT ? top_bits : 0); 5373 5374 #if zig_big_endian 5375 byte_offset -= 8 / CHAR_BIT; 5376 #endif 5377 5378 { 5379 uint8_t arg_limb; 5380 5381 memcpy(&arg_limb, &arg_bytes[byte_offset], sizeof(arg_limb)); 5382 total_pc += zig_popCount_u8(zig_u8_truncate_u8(arg_limb, limb_bits), limb_bits); 5383 } 5384 5385 remaining_bytes -= 8 / CHAR_BIT; 5386 5387 #if zig_little_endian 5388 byte_offset += 8 / CHAR_BIT; 5389 #endif 5390 } 5391 5392 return total_pc; 5393 } 5394 5395 static inline uint16_t zig_ctz_big(const void *arg, bool is_signed, uint16_t bits) { 5396 const uint8_t *arg_bytes = arg; 5397 uint16_t byte_offset = UINT16_C(0); 5398 uint16_t remaining_bytes = zig_shr_u16(bits - UINT16_C(1), UINT8_C(3)) + UINT16_C(1); 5399 uint8_t top_bits = zig_u8_intCast_u16(remaining_bytes * CHAR_BIT - bits); 5400 uint16_t total_tz = UINT16_C(0); 5401 uint16_t limb_tz; 5402 (void)is_signed; 5403 5404 #if zig_big_endian 5405 byte_offset = zig_int_bytes(bits); 5406 #endif 5407 5408 while (remaining_bytes >= 128 / CHAR_BIT) { 5409 uint8_t limb_bits = 128 - (remaining_bytes == 128 / CHAR_BIT ? top_bits : 0); 5410 5411 #if zig_big_endian 5412 byte_offset -= 128 / CHAR_BIT; 5413 #endif 5414 5415 { 5416 zig_u128 arg_limb; 5417 5418 memcpy(&arg_limb, &arg_bytes[byte_offset], sizeof(arg_limb)); 5419 limb_tz = zig_ctz_u128(zig_u128_truncate_u128(arg_limb, limb_bits), limb_bits); 5420 } 5421 5422 total_tz += limb_tz; 5423 if (limb_tz < limb_bits) return total_tz; 5424 remaining_bytes -= 128 / CHAR_BIT; 5425 5426 #if zig_little_endian 5427 byte_offset += 128 / CHAR_BIT; 5428 #endif 5429 } 5430 5431 while (remaining_bytes >= 64 / CHAR_BIT) { 5432 uint8_t limb_bits = 64 - (remaining_bytes == 64 / CHAR_BIT ? top_bits : 0); 5433 5434 #if zig_big_endian 5435 byte_offset -= 64 / CHAR_BIT; 5436 #endif 5437 5438 { 5439 uint64_t arg_limb; 5440 5441 memcpy(&arg_limb, &arg_bytes[byte_offset], sizeof(arg_limb)); 5442 limb_tz = zig_ctz_u64(zig_u64_truncate_u64(arg_limb, limb_bits), limb_bits); 5443 } 5444 5445 total_tz += limb_tz; 5446 if (limb_tz < limb_bits) return total_tz; 5447 remaining_bytes -= 64 / CHAR_BIT; 5448 5449 #if zig_little_endian 5450 byte_offset += 64 / CHAR_BIT; 5451 #endif 5452 } 5453 5454 while (remaining_bytes >= 32 / CHAR_BIT) { 5455 uint8_t limb_bits = 32 - (remaining_bytes == 32 / CHAR_BIT ? top_bits : 0); 5456 5457 #if zig_big_endian 5458 byte_offset -= 32 / CHAR_BIT; 5459 #endif 5460 5461 { 5462 uint32_t arg_limb; 5463 5464 memcpy(&arg_limb, &arg_bytes[byte_offset], sizeof(arg_limb)); 5465 limb_tz = zig_ctz_u32(zig_u32_truncate_u32(arg_limb, limb_bits), limb_bits); 5466 } 5467 5468 total_tz += limb_tz; 5469 if (limb_tz < limb_bits) return total_tz; 5470 remaining_bytes -= 32 / CHAR_BIT; 5471 5472 #if zig_little_endian 5473 byte_offset += 32 / CHAR_BIT; 5474 #endif 5475 } 5476 5477 while (remaining_bytes >= 16 / CHAR_BIT) { 5478 uint8_t limb_bits = 16 - (remaining_bytes == 16 / CHAR_BIT ? top_bits : 0); 5479 5480 #if zig_big_endian 5481 byte_offset -= 16 / CHAR_BIT; 5482 #endif 5483 5484 { 5485 uint16_t arg_limb; 5486 5487 memcpy(&arg_limb, &arg_bytes[byte_offset], sizeof(arg_limb)); 5488 limb_tz = zig_ctz_u16(zig_u16_truncate_u16(arg_limb, limb_bits), limb_bits); 5489 } 5490 5491 total_tz += limb_tz; 5492 if (limb_tz < limb_bits) return total_tz; 5493 remaining_bytes -= 16 / CHAR_BIT; 5494 5495 #if zig_little_endian 5496 byte_offset += 16 / CHAR_BIT; 5497 #endif 5498 } 5499 5500 while (remaining_bytes >= 8 / CHAR_BIT) { 5501 uint8_t limb_bits = 8 - (remaining_bytes == 8 / CHAR_BIT ? top_bits : 0); 5502 5503 #if zig_big_endian 5504 byte_offset -= 8 / CHAR_BIT; 5505 #endif 5506 5507 { 5508 uint8_t arg_limb; 5509 5510 memcpy(&arg_limb, &arg_bytes[byte_offset], sizeof(arg_limb)); 5511 limb_tz = zig_ctz_u8(zig_u8_truncate_u8(arg_limb, limb_bits), limb_bits); 5512 } 5513 5514 total_tz += limb_tz; 5515 if (limb_tz < limb_bits) return total_tz; 5516 remaining_bytes -= 8 / CHAR_BIT; 5517 5518 #if zig_little_endian 5519 byte_offset += 8 / CHAR_BIT; 5520 #endif 5521 } 5522 5523 return total_tz; 5524 } 5525 5526 static inline uint16_t zig_clz_big(const void *arg, bool is_signed, uint16_t bits) { 5527 const uint8_t *arg_bytes = arg; 5528 uint16_t byte_offset = zig_shr_u16(bits - UINT16_C(1), UINT8_C(3)) + UINT16_C(1); 5529 uint16_t remaining_bytes = byte_offset; 5530 uint8_t top_bits = zig_u8_intCast_u16(remaining_bytes * CHAR_BIT - bits); 5531 bool sign_limb = true; 5532 uint16_t total_lz = UINT16_C(0); 5533 uint16_t limb_lz; 5534 (void)is_signed; 5535 5536 #if zig_big_endian 5537 byte_offset = zig_int_bytes(bits) - remaining_bytes; 5538 #endif 5539 5540 while (remaining_bytes >= 128 / CHAR_BIT) { 5541 uint8_t limb_bits = UINT8_C(128) - (sign_limb ? top_bits : UINT8_C(0)); 5542 5543 #if zig_little_endian 5544 byte_offset -= 128 / CHAR_BIT; 5545 #endif 5546 5547 { 5548 zig_u128 arg_limb; 5549 5550 memcpy(&arg_limb, &arg_bytes[byte_offset], sizeof(arg_limb)); 5551 limb_lz = zig_clz_u128(zig_u128_truncate_u128(arg_limb, limb_bits), limb_bits); 5552 } 5553 5554 total_lz += limb_lz; 5555 if (limb_lz < limb_bits) return total_lz; 5556 sign_limb = false; 5557 remaining_bytes -= 128 / CHAR_BIT; 5558 5559 #if zig_big_endian 5560 byte_offset += 128 / CHAR_BIT; 5561 #endif 5562 } 5563 5564 while (remaining_bytes >= 64 / CHAR_BIT) { 5565 uint8_t limb_bits = UINT8_C(64) - (sign_limb ? top_bits : UINT8_C(0)); 5566 5567 #if zig_little_endian 5568 byte_offset -= 64 / CHAR_BIT; 5569 #endif 5570 5571 { 5572 uint64_t arg_limb; 5573 5574 memcpy(&arg_limb, &arg_bytes[byte_offset], sizeof(arg_limb)); 5575 limb_lz = zig_clz_u64(zig_u64_truncate_u64(arg_limb, limb_bits), limb_bits); 5576 } 5577 5578 total_lz += limb_lz; 5579 if (limb_lz < limb_bits) return total_lz; 5580 sign_limb = false; 5581 remaining_bytes -= 64 / CHAR_BIT; 5582 5583 #if zig_big_endian 5584 byte_offset += 64 / CHAR_BIT; 5585 #endif 5586 } 5587 5588 while (remaining_bytes >= 32 / CHAR_BIT) { 5589 uint8_t limb_bits = UINT8_C(32) - (sign_limb ? top_bits : UINT8_C(0)); 5590 5591 #if zig_little_endian 5592 byte_offset -= 32 / CHAR_BIT; 5593 #endif 5594 5595 { 5596 uint32_t arg_limb; 5597 5598 memcpy(&arg_limb, &arg_bytes[byte_offset], sizeof(arg_limb)); 5599 limb_lz = zig_clz_u32(zig_u32_truncate_u32(arg_limb, limb_bits), limb_bits); 5600 } 5601 5602 total_lz += limb_lz; 5603 if (limb_lz < limb_bits) return total_lz; 5604 sign_limb = false; 5605 remaining_bytes -= 32 / CHAR_BIT; 5606 5607 #if zig_big_endian 5608 byte_offset += 32 / CHAR_BIT; 5609 #endif 5610 } 5611 5612 while (remaining_bytes >= 16 / CHAR_BIT) { 5613 uint8_t limb_bits = UINT8_C(16) - (sign_limb ? top_bits : UINT8_C(0)); 5614 5615 #if zig_little_endian 5616 byte_offset -= 16 / CHAR_BIT; 5617 #endif 5618 5619 { 5620 uint16_t arg_limb; 5621 5622 memcpy(&arg_limb, &arg_bytes[byte_offset], sizeof(arg_limb)); 5623 limb_lz = zig_clz_u16(zig_u16_truncate_u16(arg_limb, limb_bits), limb_bits); 5624 } 5625 5626 total_lz += limb_lz; 5627 if (limb_lz < limb_bits) return total_lz; 5628 sign_limb = false; 5629 remaining_bytes -= 16 / CHAR_BIT; 5630 5631 #if zig_big_endian 5632 byte_offset += 16 / CHAR_BIT; 5633 #endif 5634 } 5635 5636 while (remaining_bytes >= 8 / CHAR_BIT) { 5637 uint8_t limb_bits = UINT8_C(8) - (sign_limb ? top_bits : UINT8_C(0)); 5638 5639 #if zig_little_endian 5640 byte_offset -= 8 / CHAR_BIT; 5641 #endif 5642 5643 { 5644 uint8_t arg_limb; 5645 5646 memcpy(&arg_limb, &arg_bytes[byte_offset], sizeof(arg_limb)); 5647 limb_lz = zig_clz_u8(zig_u8_truncate_u8(arg_limb, limb_bits), limb_bits); 5648 } 5649 5650 total_lz += limb_lz; 5651 if (limb_lz < limb_bits) return total_lz; 5652 sign_limb = false; 5653 remaining_bytes -= 8 / CHAR_BIT; 5654 5655 #if zig_big_endian 5656 byte_offset += 8 / CHAR_BIT; 5657 #endif 5658 } 5659 5660 return total_lz; 5661 } 5662 5663 /* ========================= Floating Point Support ========================= */ 5664 5665 #ifndef __STDC_WANT_IEC_60559_TYPES_EXT__ 5666 #define __STDC_WANT_IEC_60559_TYPES_EXT__ 5667 #endif 5668 5669 #include <float.h> 5670 5671 #if defined(zig_msvc) 5672 float __cdecl nanf(char const* input); 5673 double __cdecl nan(char const* input); 5674 long double __cdecl nanl(char const* input); 5675 5676 #define zig_msvc_flt_inf ((double)(1e+300 * 1e+300)) 5677 #define zig_msvc_flt_inff ((float)(1e+300 * 1e+300)) 5678 #define zig_msvc_flt_infl ((long double)(1e+300 * 1e+300)) 5679 #define zig_msvc_flt_nan ((double)(zig_msvc_flt_inf * 0.f)) 5680 #define zig_msvc_flt_nanf ((float)(zig_msvc_flt_inf * 0.f)) 5681 #define zig_msvc_flt_nanl ((long double)(zig_msvc_flt_inf * 0.f)) 5682 #define __builtin_nan(str) nan(str) 5683 #define __builtin_nanf(str) nanf(str) 5684 #define __builtin_nanl(str) nanl(str) 5685 #define __builtin_inf() zig_msvc_flt_inf 5686 #define __builtin_inff() zig_msvc_flt_inff 5687 #define __builtin_infl() zig_msvc_flt_infl 5688 #endif 5689 5690 #if (zig_has_builtin(nan) && zig_has_builtin(nans) && zig_has_builtin(inf)) || defined(zig_gcc) 5691 #define zig_make_special_f16(sign, name, arg, repr) sign zig_make_f16 (__builtin_##name, )(arg) 5692 #define zig_make_special_f32(sign, name, arg, repr) sign zig_make_f32 (__builtin_##name, )(arg) 5693 #define zig_make_special_f64(sign, name, arg, repr) sign zig_make_f64 (__builtin_##name, )(arg) 5694 #define zig_make_special_f80(sign, name, arg, repr) sign zig_make_f80 (__builtin_##name, )(arg) 5695 #define zig_make_special_f128(sign, name, arg, repr) sign zig_make_f128(__builtin_##name, )(arg) 5696 #else 5697 #define zig_make_special_f16(sign, name, arg, repr) zig_f16_bitCast_u16 (repr) 5698 #define zig_make_special_f32(sign, name, arg, repr) zig_f32_bitCast_u32 (repr) 5699 #define zig_make_special_f64(sign, name, arg, repr) zig_f64_bitCast_u64 (repr) 5700 #define zig_make_special_f80(sign, name, arg, repr) zig_f80_bitCast_u128(repr) 5701 #define zig_make_special_f128(sign, name, arg, repr) zig_f128_bitCast_u128(repr) 5702 #endif 5703 5704 #define zig_has_f16 1 5705 #define zig_libc_name_f16(name) __##name##h 5706 #define zig_init_special_f16(sign, name, arg, repr) zig_make_special_f16(sign, name, arg, repr) 5707 #if !defined(ZIG_TARGET_SOFT_COMPILER_RT_F16_ABI) && FLT_MANT_DIG == 11 5708 typedef float zig_f16; 5709 #define zig_make_f16(fp, repr) fp##f 5710 #elif !defined(ZIG_TARGET_SOFT_COMPILER_RT_F16_ABI) && DBL_MANT_DIG == 11 5711 typedef double zig_f16; 5712 #define zig_make_f16(fp, repr) fp 5713 #elif !defined(ZIG_TARGET_SOFT_COMPILER_RT_F16_ABI) && LDBL_MANT_DIG == 11 5714 typedef long double zig_f16; 5715 #define zig_make_f16(fp, repr) fp##l 5716 #elif !defined(ZIG_TARGET_SOFT_COMPILER_RT_F16_ABI) && FLT16_MANT_DIG == 11 && (zig_has_builtin(inff16) || defined(zig_gcc)) 5717 typedef _Float16 zig_f16; 5718 #define zig_make_f16(fp, repr) fp##f16 5719 #elif !defined(ZIG_TARGET_SOFT_COMPILER_RT_F16_ABI) && defined(__SIZEOF_FP16__) 5720 typedef __fp16 zig_f16; 5721 #define zig_make_f16(fp, repr) fp##f16 5722 #else 5723 #undef zig_has_f16 5724 #define zig_has_f16 0 5725 #define zig_repr_f16 u16 5726 typedef uint16_t zig_f16; 5727 #define zig_make_f16(fp, repr) repr 5728 #undef zig_make_special_f16 5729 #define zig_make_special_f16(sign, name, arg, repr) repr 5730 #undef zig_init_special_f16 5731 #define zig_init_special_f16(sign, name, arg, repr) repr 5732 #endif 5733 5734 #define zig_has_f32 1 5735 #define zig_libc_name_f32(name) name##f 5736 #if defined(zig_msvc) 5737 #define zig_init_special_f32(sign, name, arg, repr) sign zig_make_f32(zig_msvc_flt_##name, ) 5738 #else 5739 #define zig_init_special_f32(sign, name, arg, repr) zig_make_special_f32(sign, name, arg, repr) 5740 #endif 5741 #if !defined(ZIG_TARGET_SOFT_COMPILER_RT_F32_ABI) && FLT_MANT_DIG == 24 5742 typedef float zig_f32; 5743 #define zig_make_f32(fp, repr) fp##f 5744 #elif !defined(ZIG_TARGET_SOFT_COMPILER_RT_F32_ABI) && DBL_MANT_DIG == 24 5745 typedef double zig_f32; 5746 #define zig_make_f32(fp, repr) fp 5747 #elif !defined(ZIG_TARGET_SOFT_COMPILER_RT_F32_ABI) && LDBL_MANT_DIG == 24 5748 typedef long double zig_f32; 5749 #define zig_make_f32(fp, repr) fp##l 5750 #elif !defined(ZIG_TARGET_SOFT_COMPILER_RT_F32_ABI) && FLT32_MANT_DIG == 24 5751 typedef _Float32 zig_f32; 5752 #define zig_make_f32(fp, repr) fp##f32 5753 #else 5754 #undef zig_has_f32 5755 #define zig_has_f32 0 5756 #define zig_repr_f32 u32 5757 typedef uint32_t zig_f32; 5758 #define zig_make_f32(fp, repr) repr 5759 #undef zig_make_special_f32 5760 #define zig_make_special_f32(sign, name, arg, repr) repr 5761 #undef zig_init_special_f32 5762 #define zig_init_special_f32(sign, name, arg, repr) repr 5763 #endif 5764 5765 #define zig_has_f64 1 5766 #define zig_libc_name_f64(name) name 5767 5768 #if defined(zig_msvc) 5769 #define zig_init_special_f64(sign, name, arg, repr) sign zig_make_f64(zig_msvc_flt_##name, ) 5770 #else 5771 #define zig_init_special_f64(sign, name, arg, repr) zig_make_special_f64(sign, name, arg, repr) 5772 #endif 5773 #if !defined(ZIG_TARGET_SOFT_COMPILER_RT_F64_ABI) && FLT_MANT_DIG == 53 5774 typedef float zig_f64; 5775 #define zig_make_f64(fp, repr) fp##f 5776 #elif !defined(ZIG_TARGET_SOFT_COMPILER_RT_F64_ABI) && DBL_MANT_DIG == 53 5777 typedef double zig_f64; 5778 #define zig_make_f64(fp, repr) fp 5779 #elif !defined(ZIG_TARGET_SOFT_COMPILER_RT_F64_ABI) && LDBL_MANT_DIG == 53 5780 typedef long double zig_f64; 5781 #define zig_make_f64(fp, repr) fp##l 5782 #elif !defined(ZIG_TARGET_SOFT_COMPILER_RT_F64_ABI) && FLT64_MANT_DIG == 53 5783 typedef _Float64 zig_f64; 5784 #define zig_make_f64(fp, repr) fp##f64 5785 #elif !defined(ZIG_TARGET_SOFT_COMPILER_RT_F64_ABI) && FLT32X_MANT_DIG == 53 5786 typedef _Float32x zig_f64; 5787 #define zig_make_f64(fp, repr) fp##f32x 5788 #else 5789 #undef zig_has_f64 5790 #define zig_has_f64 0 5791 #define zig_repr_f64 u64 5792 typedef uint64_t zig_f64; 5793 #define zig_make_f64(fp, repr) repr 5794 #undef zig_make_special_f64 5795 #define zig_make_special_f64(sign, name, arg, repr) repr 5796 #undef zig_init_special_f64 5797 #define zig_init_special_f64(sign, name, arg, repr) repr 5798 #endif 5799 5800 #define zig_has_f80 1 5801 #define zig_libc_name_f80(name) __##name##x 5802 #define zig_init_special_f80(sign, name, arg, repr) zig_make_special_f80(sign, name, arg, repr) 5803 #ifdef ZIG_TARGET_SOFT_COMPILER_RT_F80_ABI 5804 #undef zig_has_f80 5805 typedef struct { uint64_t mantissa; uint16_t exponent; } zig_f80; 5806 #define zig_init_repr_f80(mantissa, exponent) { .mant##issa = mantissa, .expo##nent = exponent } 5807 #define zig_make_repr_f80(mantissa, exponent) (zig_f80)zig_init_repr_f80(mantissa, exponent) 5808 #define zig_mantissa_repr_f80(arg) (arg).mantissa 5809 #define zig_exponent_repr_f80(arg) (arg).exponent 5810 #elif FLT_MANT_DIG == 64 5811 typedef float zig_f80; 5812 #define zig_make_f80(fp, repr) fp##f 5813 #elif DBL_MANT_DIG == 64 5814 typedef double zig_f80; 5815 #define zig_make_f80(fp, repr) fp 5816 #elif LDBL_MANT_DIG == 64 5817 typedef long double zig_f80; 5818 #define zig_make_f80(fp, repr) fp##l 5819 #elif FLT80_MANT_DIG == 64 5820 typedef _Float80 zig_f80; 5821 #define zig_make_f80(fp, repr) fp##f80 5822 #elif FLT64X_MANT_DIG == 64 5823 typedef _Float64x zig_f80; 5824 #define zig_make_f80(fp, repr) fp##f64x 5825 #elif defined(__SIZEOF_FLOAT80__) 5826 typedef __float80 zig_f80; 5827 #define zig_make_f80(fp, repr) fp##l 5828 #else 5829 #undef zig_has_f80 5830 typedef zig_u128 zig_f80; 5831 #define zig_init_repr_f80(mantissa, exponent) zig_init_u128(exponent, mantissa) 5832 #define zig_make_repr_f80(mantissa, exponent) zig_make_u128(exponent, mantissa) 5833 #define zig_mantissa_repr_f80(arg) zig_lo_u128(arg) 5834 #define zig_exponent_repr_f80(arg) (uint16_t)zig_hi_u128(arg) 5835 #endif 5836 #ifndef zig_has_f80 5837 #define zig_has_f80 0 5838 #define zig_make_f80(fp, repr) repr 5839 #ifndef zig_make_repr_f80 5840 #define zig_make_repr_f80(mantissa, exponent) (zig_f80)zig_init_repr_f80(mantissa, exponent) 5841 #endif 5842 #undef zig_make_special_f80 5843 #define zig_make_special_f80(sign, name, arg, repr) repr 5844 #undef zig_init_special_f80 5845 #define zig_init_special_f80(sign, name, arg, repr) repr 5846 #endif 5847 5848 #define zig_has_f128 1 5849 #define zig_libc_name_f128(name) name##f128 5850 #define zig_init_special_f128(sign, name, arg, repr) zig_make_special_f128(sign, name, arg, repr) 5851 #ifdef ZIG_TARGET_SOFT_COMPILER_RT_F128_ABI 5852 #undef zig_has_f128 5853 #if zig_little_endian 5854 typedef struct { uint64_t lo, hi; } zig_f128; 5855 #else 5856 typedef struct { uint64_t hi, lo; } zig_f128; 5857 #endif 5858 #define zig_init_repr_f128(hi, lo) { .h##i = hi, .l##o = lo } 5859 #define zig_lo_repr_f128(arg) (arg).lo 5860 #define zig_hi_repr_f128(arg) (arg).hi 5861 #elif FLT_MANT_DIG == 113 5862 typedef float zig_f128; 5863 #define zig_make_f128(fp, repr) fp##f 5864 #elif DBL_MANT_DIG == 113 5865 typedef double zig_f128; 5866 #define zig_make_f128(fp, repr) fp 5867 #elif LDBL_MANT_DIG == 113 5868 typedef long double zig_f128; 5869 #define zig_make_f128(fp, repr) fp##l 5870 #elif FLT128_MANT_DIG == 113 5871 typedef _Float128 zig_f128; 5872 #define zig_make_f128(fp, repr) fp##f128 5873 #elif FLT64X_MANT_DIG == 113 5874 typedef _Float64x zig_f128; 5875 #define zig_make_f128(fp, repr) fp##f64x 5876 #elif defined(__SIZEOF_FLOAT128__) 5877 typedef __float128 zig_f128; 5878 #define zig_make_f128(fp, repr) fp##q 5879 #undef zig_make_special_f128 5880 #define zig_make_special_f128(sign, name, arg, repr) sign __builtin_##name##f128(arg) 5881 #else 5882 #undef zig_has_f128 5883 #if defined(zig_x86_64) && defined(ZIG_TARGET_ABI_MSVC) 5884 #if defined(zig_msvc) && !defined(__clang__) 5885 #include <emmintrin.h> 5886 typedef __m128i zig_f128; 5887 #define zig_init_repr_f128(hi, lo) { .m128i_u64 = { lo, hi } } 5888 #define zig_lo_repr_f128(arg) (arg).m128i_u64[0] 5889 #define zig_hi_repr_f128(arg) (arg).m128i_u64[1] 5890 #else 5891 typedef __attribute__((__vector_size__(2 * sizeof(uint64_t)))) uint64_t zig_f128; 5892 #define zig_init_repr_f128(hi, lo) { lo, hi } 5893 #define zig_lo_repr_f128(arg) (arg)[0] 5894 #define zig_hi_repr_f128(arg) (arg)[1] 5895 #endif 5896 #else 5897 typedef zig_u128 zig_f128; 5898 #define zig_init_repr_f128(hi, lo) zig_init_u128(hi, lo) 5899 #define zig_make_repr_f128(hi, lo) zig_make_u128(hi, lo) 5900 #define zig_lo_repr_f128(arg) zig_lo_u128(arg) 5901 #define zig_hi_repr_f128(arg) zig_hi_u128(arg) 5902 #endif 5903 #endif 5904 #ifndef zig_has_f128 5905 #define zig_has_f128 0 5906 #define zig_make_f128(fp, repr) repr 5907 #ifndef zig_make_repr_f128 5908 #define zig_make_repr_f128(hi, lo) (zig_f128)zig_init_repr_f128(hi, lo) 5909 #endif 5910 #undef zig_make_special_f128 5911 #define zig_make_special_f128(sign, name, arg, repr) repr 5912 #undef zig_init_special_f128 5913 #define zig_init_special_f128(sign, name, arg, repr) repr 5914 #endif 5915 5916 #if !defined(zig_msvc) && defined(ZIG_TARGET_ABI_MSVC) 5917 /* Emulate msvc abi on a gnu compiler */ 5918 typedef zig_f64 zig_c_longdouble; 5919 #elif defined(zig_msvc) && !defined(ZIG_TARGET_ABI_MSVC) 5920 /* Emulate gnu abi on an msvc compiler */ 5921 typedef zig_f128 zig_c_longdouble; 5922 #else 5923 /* Target and compiler abi match */ 5924 typedef long double zig_c_longdouble; 5925 #endif 5926 5927 #if __AVR__ 5928 typedef signed char zig_FloatCompareResult; 5929 #elif defined(zig_aarch64) 5930 typedef signed int zig_FloatCompareResult; 5931 #elif __SIZEOF_LONG__ >= __SIZEOF_POINTER__ 5932 typedef signed long zig_FloatCompareResult; 5933 #else 5934 typedef signed long long zig_FloatCompareResult; 5935 #endif 5936 5937 #define zig_bitCast_float(w, iw, UnsignedReprType, SignedReprType) \ 5938 static inline zig_f##w zig_f##w##_bitCast_u##iw(UnsignedReprType arg) { \ 5939 zig_f##w res; \ 5940 memcpy(&res, &arg, sizeof(zig_f##w)); \ 5941 return res; \ 5942 } \ 5943 static inline zig_f##w zig_f##w##_bitCast_i##iw(SignedReprType arg) { \ 5944 zig_f##w res; \ 5945 memcpy(&res, &arg, sizeof(zig_f##w)); \ 5946 return res; \ 5947 } \ 5948 static inline UnsignedReprType zig_u##iw##_bitCast_f##w(zig_f##w arg) { \ 5949 UnsignedReprType res; \ 5950 memcpy(&res, &arg, sizeof(zig_f##w)); \