/src/ryu/src/pretty/mantissa.rs
Line | Count | Source |
1 | | use crate::digit_table::DIGIT_TABLE; |
2 | | use core::ptr; |
3 | | |
4 | | #[cfg_attr(feature = "no-panic", inline)] |
5 | 1.22k | pub unsafe fn write_mantissa_long(mut output: u64, mut result: *mut u8) { |
6 | 1.22k | if (output >> 32) != 0 { |
7 | 968 | // One expensive 64-bit division. |
8 | 968 | let mut output2 = (output - 100_000_000 * (output / 100_000_000)) as u32; |
9 | 968 | output /= 100_000_000; |
10 | 968 | |
11 | 968 | let c = output2 % 10_000; |
12 | 968 | output2 /= 10_000; |
13 | 968 | let d = output2 % 10_000; |
14 | 968 | let c0 = (c % 100) << 1; |
15 | 968 | let c1 = (c / 100) << 1; |
16 | 968 | let d0 = (d % 100) << 1; |
17 | 968 | let d1 = (d / 100) << 1; |
18 | 968 | ptr::copy_nonoverlapping(DIGIT_TABLE.as_ptr().offset(c0 as isize), result.sub(2), 2); |
19 | 968 | ptr::copy_nonoverlapping(DIGIT_TABLE.as_ptr().offset(c1 as isize), result.sub(4), 2); |
20 | 968 | ptr::copy_nonoverlapping(DIGIT_TABLE.as_ptr().offset(d0 as isize), result.sub(6), 2); |
21 | 968 | ptr::copy_nonoverlapping(DIGIT_TABLE.as_ptr().offset(d1 as isize), result.sub(8), 2); |
22 | 968 | result = result.sub(8); |
23 | 968 | } |
24 | 1.22k | write_mantissa(output as u32, result); |
25 | 1.22k | } |
26 | | |
27 | | #[cfg_attr(feature = "no-panic", inline)] |
28 | 1.22k | pub unsafe fn write_mantissa(mut output: u32, mut result: *mut u8) { |
29 | 2.48k | while output >= 10_000 { |
30 | 1.25k | let c = output - 10_000 * (output / 10_000); |
31 | 1.25k | output /= 10_000; |
32 | 1.25k | let c0 = (c % 100) << 1; |
33 | 1.25k | let c1 = (c / 100) << 1; |
34 | 1.25k | ptr::copy_nonoverlapping(DIGIT_TABLE.as_ptr().offset(c0 as isize), result.sub(2), 2); |
35 | 1.25k | ptr::copy_nonoverlapping(DIGIT_TABLE.as_ptr().offset(c1 as isize), result.sub(4), 2); |
36 | 1.25k | result = result.sub(4); |
37 | 1.25k | } |
38 | 1.22k | if output >= 100 { |
39 | 666 | let c = (output % 100) << 1; |
40 | 666 | output /= 100; |
41 | 666 | ptr::copy_nonoverlapping(DIGIT_TABLE.as_ptr().offset(c as isize), result.sub(2), 2); |
42 | 666 | result = result.sub(2); |
43 | 666 | } |
44 | 1.22k | if output >= 10 { |
45 | 621 | let c = output << 1; |
46 | 621 | ptr::copy_nonoverlapping(DIGIT_TABLE.as_ptr().offset(c as isize), result.sub(2), 2); |
47 | 621 | } else { |
48 | 608 | *result.sub(1) = b'0' + output as u8; |
49 | 608 | } |
50 | 1.22k | } |