mirror of
https://github.com/ziglang/zig.git
synced 2025-12-08 15:23:14 +00:00
We already have a LICENSE file that covers the Zig Standard Library. We no longer need to remind everyone that the license is MIT in every single file. Previously this was introduced to clarify the situation for a fork of Zig that made Zig's LICENSE file harder to find, and replaced it with their own license that required annual payments to their company. However that fork now appears to be dead. So there is no need to reinforce the copyright notice in every single file.
77 lines
1.9 KiB
Zig
77 lines
1.9 KiB
Zig
const builtin = @import("builtin");
|
|
|
|
pub fn _alldiv(a: i64, b: i64) callconv(.Stdcall) i64 {
|
|
@setRuntimeSafety(builtin.is_test);
|
|
const s_a = a >> (64 - 1);
|
|
const s_b = b >> (64 - 1);
|
|
|
|
const an = (a ^ s_a) -% s_a;
|
|
const bn = (b ^ s_b) -% s_b;
|
|
|
|
const r = @bitCast(u64, an) / @bitCast(u64, bn);
|
|
const s = s_a ^ s_b;
|
|
return (@bitCast(i64, r) ^ s) -% s;
|
|
}
|
|
|
|
pub fn _aulldiv() callconv(.Naked) void {
|
|
@setRuntimeSafety(false);
|
|
|
|
// The stack layout is:
|
|
// ESP+16 divisor (hi)
|
|
// ESP+12 divisor (low)
|
|
// ESP+8 dividend (hi)
|
|
// ESP+4 dividend (low)
|
|
// ESP return address
|
|
|
|
asm volatile (
|
|
\\ push %%ebx
|
|
\\ push %%esi
|
|
\\ mov 0x18(%%esp),%%eax
|
|
\\ or %%eax,%%eax
|
|
\\ jne 1f
|
|
\\ mov 0x14(%%esp),%%ecx
|
|
\\ mov 0x10(%%esp),%%eax
|
|
\\ xor %%edx,%%edx
|
|
\\ div %%ecx
|
|
\\ mov %%eax,%%ebx
|
|
\\ mov 0xc(%%esp),%%eax
|
|
\\ div %%ecx
|
|
\\ mov %%ebx,%%edx
|
|
\\ jmp 5f
|
|
\\ 1:
|
|
\\ mov %%eax,%%ecx
|
|
\\ mov 0x14(%%esp),%%ebx
|
|
\\ mov 0x10(%%esp),%%edx
|
|
\\ mov 0xc(%%esp),%%eax
|
|
\\ 2:
|
|
\\ shr %%ecx
|
|
\\ rcr %%ebx
|
|
\\ shr %%edx
|
|
\\ rcr %%eax
|
|
\\ or %%ecx,%%ecx
|
|
\\ jne 2b
|
|
\\ div %%ebx
|
|
\\ mov %%eax,%%esi
|
|
\\ mull 0x18(%%esp)
|
|
\\ mov %%eax,%%ecx
|
|
\\ mov 0x14(%%esp),%%eax
|
|
\\ mul %%esi
|
|
\\ add %%ecx,%%edx
|
|
\\ jb 3f
|
|
\\ cmp 0x10(%%esp),%%edx
|
|
\\ ja 3f
|
|
\\ jb 4f
|
|
\\ cmp 0xc(%%esp),%%eax
|
|
\\ jbe 4f
|
|
\\ 3:
|
|
\\ dec %%esi
|
|
\\ 4:
|
|
\\ xor %%edx,%%edx
|
|
\\ mov %%esi,%%eax
|
|
\\ 5:
|
|
\\ pop %%esi
|
|
\\ pop %%ebx
|
|
\\ ret $0x10
|
|
);
|
|
}
|