diff --git a/asm/datetime_to_systemtime.asm b/asm/datetime_to_systemtime.asm index 344d807..8976555 100644 --- a/asm/datetime_to_systemtime.asm +++ b/asm/datetime_to_systemtime.asm @@ -39,10 +39,12 @@ datealgo::asm::datetime_to_systemtime: add rsi, rdi jns .LBB20_2 test edx, edx - je .LBB20_5 + je .LBB20_10 not rsi mov eax, 1000000000 sub eax, edx + cmp edx, 1000000001 + jb .LBB20_9 mov ecx, eax shr ecx, 9 imul rcx, rcx, 281475 @@ -50,12 +52,15 @@ datealgo::asm::datetime_to_systemtime: add rsi, rcx imul ecx, ecx, 1000000000 sub eax, ecx +.LBB20_9: lea rdi, [rip + .L__unnamed_1] mov edx, eax jmp qword ptr [rip + std::time::SystemTime::checked_sub@GOTPCREL] .LBB20_1: xor esi, esi .LBB20_2: + cmp edx, 1000000000 + jb .LBB20_4 mov eax, edx shr eax, 9 imul rax, rax, 281475 @@ -63,9 +68,10 @@ datealgo::asm::datetime_to_systemtime: add rsi, rax imul eax, eax, 1000000000 sub edx, eax +.LBB20_4: lea rdi, [rip + .L__unnamed_1] jmp qword ptr [rip + std::time::SystemTime::checked_add@GOTPCREL] -.LBB20_5: +.LBB20_10: neg rsi lea rdi, [rip + .L__unnamed_1] xor edx, edx diff --git a/asm/isoweekdate_to_date.asm b/asm/isoweekdate_to_date.asm index 4f2cec8..c6f6f50 100644 --- a/asm/isoweekdate_to_date.asm +++ b/asm/isoweekdate_to_date.asm @@ -27,35 +27,37 @@ datealgo::asm::isoweekdate_to_date: dec ecx movzx eax, cl sub esi, eax - lea ecx, [4*rsi + 1207] - imul rax, rcx, 963315389 - shr rax, 47 - imul edx, eax, 146097 - sub ecx, edx - or ecx, 3 - imul rcx, rcx, 2939745 - mov edx, ecx + lea eax, [4*rsi + 1207] + imul rcx, rax, 963315389 + shr rcx, 47 + imul edx, ecx, 146097 + sub eax, edx + or eax, 3 + imul rax, rax, 2939745 + mov edx, eax imul rdx, rdx, 1531969483 shr rdx, 54 imul edx, edx, 2141 add edx, 197913 - movzx esi, dx - shr edx, 16 - lea edi, [rdx + 244] - imul r8d, eax, 100 - mov rax, rcx - shr rax, 32 - add eax, r8d - cmp ecx, -696719416 - cmovb edi, edx - sbb eax, -1 - add eax, -1468000 - imul ecx, esi, 31345 - shr ecx, 26 - inc ecx - shl rcx, 40 + mov esi, edx + shr esi, 16 + lea edi, [rsi + 244] + imul r8d, ecx, 100 + mov rcx, rax + shr rcx, 32 + add ecx, r8d + cmp eax, -696719416 + cmovb edi, esi + sbb ecx, -1 + movzx eax, dx + add ecx, -1468000 + imul eax, eax, 31345 + shr eax, 26 + shl rax, 40 movzx edx, dil shl rdx, 32 - or rdx, rcx - or rax, rdx + or rdx, rax + or rcx, rdx + movabs rax, 1099511627776 + add rax, rcx ret diff --git a/asm/next_date.asm b/asm/next_date.asm index f12d83f..74e7b3d 100644 --- a/asm/next_date.asm +++ b/asm/next_date.asm @@ -7,7 +7,19 @@ datealgo::asm::next_date: mov rsi, rdi shr rsi, 40 cmp sil, 28 - jb .LBB4_3 + jae .LBB4_1 +.LBB4_3: + add rdi, rcx + movabs rcx, 280375465082880 + and rcx, rdi +.LBB4_8: + movzx edx, dl + shl rdx, 32 + mov eax, eax + or rax, rcx + or rax, rdx + ret +.LBB4_1: cmp dl, 2 jne .LBB4_2 imul r8d, edi, -1030792151 @@ -28,13 +40,7 @@ datealgo::asm::next_date: xor r8b, dl or r8b, 30 cmp r8b, sil - jbe .LBB4_4 -.LBB4_3: - add rdi, rcx - movabs rcx, 280375465082880 - and rcx, rdi - jmp .LBB4_8 -.LBB4_4: + ja .LBB4_3 cmp dl, 12 jae .LBB4_5 .LBB4_7: @@ -43,10 +49,4 @@ datealgo::asm::next_date: .LBB4_5: inc rax mov edx, 1 -.LBB4_8: - movzx edx, dl - shl rdx, 32 - mov eax, eax - or rax, rcx - or rax, rdx - ret + jmp .LBB4_8 diff --git a/asm/rd_to_date.asm b/asm/rd_to_date.asm index 106ce64..23424da 100644 --- a/asm/rd_to_date.asm +++ b/asm/rd_to_date.asm @@ -1,33 +1,35 @@ datealgo::asm::rd_to_date: - lea ecx, [4*rdi - 2147385461] - imul rax, rcx, 963315389 - shr rax, 47 - imul edx, eax, 146097 - sub ecx, edx - or ecx, 3 - imul rcx, rcx, 2939745 - mov edx, ecx + lea eax, [4*rdi - 2147385461] + imul rcx, rax, 963315389 + shr rcx, 47 + imul edx, ecx, 146097 + sub eax, edx + or eax, 3 + imul rax, rax, 2939745 + mov edx, eax imul rdx, rdx, 1531969483 shr rdx, 54 imul edx, edx, 2141 add edx, 197913 - movzx esi, dx - shr edx, 16 - lea edi, [rdx + 244] - imul r8d, eax, 100 - mov rax, rcx - shr rax, 32 - add eax, r8d - cmp ecx, -696719416 - cmovb edi, edx - sbb eax, -1 - add eax, -1468000 - imul ecx, esi, 31345 - shr ecx, 26 - inc ecx - shl rcx, 40 + mov esi, edx + shr esi, 16 + lea edi, [rsi + 244] + imul r8d, ecx, 100 + mov rcx, rax + shr rcx, 32 + add ecx, r8d + cmp eax, -696719416 + cmovb edi, esi + sbb ecx, -1 + movzx eax, dx + add ecx, -1468000 + imul eax, eax, 31345 + shr eax, 26 + shl rax, 40 movzx edx, dil shl rdx, 32 - or rdx, rcx - or rax, rdx + or rdx, rax + or rcx, rdx + movabs rax, 1099511627776 + add rax, rcx ret diff --git a/asm/secs_to_systemtime.asm b/asm/secs_to_systemtime.asm index a629c14..afc0bdf 100644 --- a/asm/secs_to_systemtime.asm +++ b/asm/secs_to_systemtime.asm @@ -3,6 +3,8 @@ datealgo::asm::secs_to_systemtime: mov rsi, rdi test rdi, rdi js .LBB18_1 + cmp eax, 1000000000 + jb .LBB18_5 mov ecx, eax shr ecx, 9 imul rcx, rcx, 281475 @@ -10,15 +12,18 @@ datealgo::asm::secs_to_systemtime: add rsi, rcx imul ecx, ecx, 1000000000 sub eax, ecx +.LBB18_5: lea rdi, [rip + .L__unnamed_1] mov edx, eax jmp qword ptr [rip + std::time::SystemTime::checked_add@GOTPCREL] .LBB18_1: test eax, eax - je .LBB18_4 + je .LBB18_2 not rsi mov edx, 1000000000 sub edx, eax + cmp eax, 1000000001 + jb .LBB18_8 mov eax, edx shr eax, 9 imul rax, rax, 281475 @@ -26,9 +31,10 @@ datealgo::asm::secs_to_systemtime: add rsi, rax imul eax, eax, 1000000000 sub edx, eax +.LBB18_8: lea rdi, [rip + .L__unnamed_1] jmp qword ptr [rip + std::time::SystemTime::checked_sub@GOTPCREL] -.LBB18_4: +.LBB18_2: neg rsi lea rdi, [rip + .L__unnamed_1] xor edx, edx diff --git a/asm/systemtime_to_datetime.asm b/asm/systemtime_to_datetime.asm index dcbac76..b40ca99 100644 --- a/asm/systemtime_to_datetime.asm +++ b/asm/systemtime_to_datetime.asm @@ -1,7 +1,7 @@ datealgo::asm::systemtime_to_datetime: push r14 push rbx - sub rsp, 56 + sub rsp, 40 mov rbx, rdi movabs r14, 46387741132800 mov qword ptr [rsp + 24], rsi @@ -12,34 +12,29 @@ datealgo::asm::systemtime_to_datetime: xor ecx, ecx call qword ptr [rip + std::time::SystemTime::duration_since@GOTPCREL] cmp qword ptr [rsp], 0 - je .LBB19_1 mov rax, qword ptr [rsp + 8] + je .LBB19_1 mov ecx, dword ptr [rsp + 16] - mov qword ptr [rsp + 40], rax - mov dword ptr [rsp + 48], ecx - lea rdi, [rsp + 40] - call qword ptr [rip + std::time::SystemTimeError::duration@GOTPCREL] - cmp edx, 1 + cmp ecx, 1 sbb rax, -1 cmp rax, r14 - ja .LBB19_6 + ja .LBB19_4 mov esi, 1000000000 - sub esi, edx - test edx, edx - cmove esi, edx + sub esi, ecx + test ecx, ecx + cmove esi, ecx neg rax - jmp .LBB19_5 + jmp .LBB19_6 .LBB19_1: - mov rax, qword ptr [rsp + 8] movabs rcx, 46381619174399 cmp rax, rcx jbe .LBB19_2 -.LBB19_6: +.LBB19_4: xor eax, eax jmp .LBB19_7 .LBB19_2: mov esi, dword ptr [rsp + 16] -.LBB19_5: +.LBB19_6: lea rcx, [r14 + rax] add rcx, 26438400 movabs rdx, -4454547087429121353 @@ -98,7 +93,7 @@ datealgo::asm::systemtime_to_datetime: .LBB19_7: mov dword ptr [rbx], eax mov rax, rbx - add rsp, 56 + add rsp, 40 pop rbx pop r14 ret diff --git a/asm/systemtime_to_secs.asm b/asm/systemtime_to_secs.asm index d6722e4..76f052e 100644 --- a/asm/systemtime_to_secs.asm +++ b/asm/systemtime_to_secs.asm @@ -1,6 +1,6 @@ datealgo::asm::systemtime_to_secs: push rbx - sub rsp, 64 + sub rsp, 48 mov rbx, rdi mov qword ptr [rsp + 32], rsi mov dword ptr [rsp + 40], edx @@ -10,18 +10,14 @@ datealgo::asm::systemtime_to_secs: xor ecx, ecx call qword ptr [rip + std::time::SystemTime::duration_since@GOTPCREL] cmp qword ptr [rsp + 8], 0 - je .LBB17_1 mov rax, qword ptr [rsp + 16] - mov ecx, dword ptr [rsp + 24] - mov qword ptr [rsp + 48], rax - mov dword ptr [rsp + 56], ecx - lea rdi, [rsp + 48] - call qword ptr [rip + std::time::SystemTimeError::duration@GOTPCREL] + je .LBB17_1 + mov edx, dword ptr [rsp + 24] cmp edx, 1 sbb rax, -1 movabs rcx, 46387741132800 cmp rax, rcx - ja .LBB17_6 + ja .LBB17_5 mov ecx, 1000000000 sub ecx, edx test edx, edx @@ -29,14 +25,13 @@ datealgo::asm::systemtime_to_secs: neg rax jmp .LBB17_3 .LBB17_1: - mov rax, qword ptr [rsp + 16] movabs rcx, 46381619174399 cmp rax, rcx jbe .LBB17_2 -.LBB17_6: +.LBB17_5: mov qword ptr [rbx], 0 mov rax, rbx - add rsp, 64 + add rsp, 48 pop rbx ret .LBB17_2: @@ -46,6 +41,6 @@ datealgo::asm::systemtime_to_secs: mov dword ptr [rbx + 16], ecx mov qword ptr [rbx], 1 mov rax, rbx - add rsp, 64 + add rsp, 48 pop rbx ret diff --git a/src/lib.rs b/src/lib.rs index e5e3439..9379dd7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -451,7 +451,7 @@ pub const fn date_to_rd((y, m, d): (i32, u8, u8)) -> i32 { /// > evaluate `m % 7 + 1` based on the binary representation of the reciprocal /// > of `7`, namely, `C := (0.001_001_001...)_2`. The following table presents /// > the binary values of `m % 7 + 1` and `p := (m + 1) * C` for `m = 0`, `2`, -/// `...`: +/// > `...`: /// > /// > | `m` | `m % 7 + 1` | `(m + 1) * C` | /// > | --- | ----------- | ---------------------- | @@ -1276,70 +1276,91 @@ pub mod asm { #[cfg(feature = "std")] use std::time::SystemTime; + #[inline(never)] pub const fn rd_to_date(n: i32) -> (i32, u8, u8) { super::rd_to_date(n) } + #[inline(never)] pub const fn date_to_rd((y, m, d): (i32, u8, u8)) -> i32 { super::date_to_rd((y, m, d)) } + #[inline(never)] pub const fn rd_to_weekday(n: i32) -> u8 { super::rd_to_weekday(n) } + #[inline(never)] pub const fn date_to_weekday((y, m, d): (i32, u8, u8)) -> u8 { super::date_to_weekday((y, m, d)) } + #[inline(never)] pub const fn next_date((y, m, d): (i32, u8, u8)) -> (i32, u8, u8) { super::next_date((y, m, d)) } + #[inline(never)] pub const fn prev_date((y, m, d): (i32, u8, u8)) -> (i32, u8, u8) { super::prev_date((y, m, d)) } + #[inline(never)] pub const fn secs_to_dhms(secs: i64) -> (i32, u8, u8, u8) { super::secs_to_dhms(secs) } + #[inline(never)] pub const fn dhms_to_secs((d, h, m, s): (i32, u8, u8, u8)) -> i64 { super::dhms_to_secs((d, h, m, s)) } + #[inline(never)] pub const fn secs_to_datetime(secs: i64) -> (i32, u8, u8, u8, u8, u8) { super::secs_to_datetime(secs) } + #[inline(never)] pub const fn datetime_to_secs((y, m, d, hh, mm, ss): (i32, u8, u8, u8, u8, u8)) -> i64 { super::datetime_to_secs((y, m, d, hh, mm, ss)) } + #[inline(never)] pub const fn is_leap_year(y: i32) -> bool { super::is_leap_year(y) } + #[inline(never)] pub const fn days_in_month(y: i32, m: u8) -> u8 { super::days_in_month(y, m) } + #[inline(never)] pub const fn rd_to_isoweekdate(rd: i32) -> (i32, u8, u8) { super::rd_to_isoweekdate(rd) } + #[inline(never)] pub const fn isoweekdate_to_rd((y, w, d): (i32, u8, u8)) -> i32 { super::isoweekdate_to_rd((y, w, d)) } + #[inline(never)] pub const fn date_to_isoweekdate((y, m, d): (i32, u8, u8)) -> (i32, u8, u8) { super::date_to_isoweekdate((y, m, d)) } + #[inline(never)] pub const fn isoweekdate_to_date((y, w, d): (i32, u8, u8)) -> (i32, u8, u8) { super::isoweekdate_to_date((y, w, d)) } + #[inline(never)] pub const fn isoweeks_in_year(y: i32) -> u8 { super::isoweeks_in_year(y) } #[cfg(feature = "std")] + #[inline(never)] pub fn systemtime_to_secs(st: SystemTime) -> Option<(i64, u32)> { super::systemtime_to_secs(st) } #[cfg(feature = "std")] + #[inline(never)] pub fn secs_to_systemtime((secs, nsecs): (i64, u32)) -> Option { super::secs_to_systemtime((secs, nsecs)) } #[cfg(feature = "std")] + #[inline(never)] pub fn systemtime_to_datetime(st: SystemTime) -> Option<(i32, u8, u8, u8, u8, u8, u32)> { super::systemtime_to_datetime(st) } #[cfg(feature = "std")] + #[inline(never)] pub fn datetime_to_systemtime((y, m, d, hh, mm, ss, nsec): (i32, u8, u8, u8, u8, u8, u32)) -> Option { super::datetime_to_systemtime((y, m, d, hh, mm, ss, nsec)) }