/build/cargo-vendor-dir/ryu-1.0.20/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 | 0 | pub unsafe fn write_mantissa_long(mut output: u64, mut result: *mut u8) { |
6 | 0 | if (output >> 32) != 0 { |
7 | 0 | // One expensive 64-bit division. |
8 | 0 | let mut output2 = (output - 100_000_000 * (output / 100_000_000)) as u32; |
9 | 0 | output /= 100_000_000; |
10 | 0 |
|
11 | 0 | let c = output2 % 10_000; |
12 | 0 | output2 /= 10_000; |
13 | 0 | let d = output2 % 10_000; |
14 | 0 | let c0 = (c % 100) << 1; |
15 | 0 | let c1 = (c / 100) << 1; |
16 | 0 | let d0 = (d % 100) << 1; |
17 | 0 | let d1 = (d / 100) << 1; |
18 | 0 | ptr::copy_nonoverlapping( |
19 | 0 | DIGIT_TABLE.as_ptr().offset(c0 as isize), |
20 | 0 | result.offset(-2), |
21 | 0 | 2, |
22 | 0 | ); |
23 | 0 | ptr::copy_nonoverlapping( |
24 | 0 | DIGIT_TABLE.as_ptr().offset(c1 as isize), |
25 | 0 | result.offset(-4), |
26 | 0 | 2, |
27 | 0 | ); |
28 | 0 | ptr::copy_nonoverlapping( |
29 | 0 | DIGIT_TABLE.as_ptr().offset(d0 as isize), |
30 | 0 | result.offset(-6), |
31 | 0 | 2, |
32 | 0 | ); |
33 | 0 | ptr::copy_nonoverlapping( |
34 | 0 | DIGIT_TABLE.as_ptr().offset(d1 as isize), |
35 | 0 | result.offset(-8), |
36 | 0 | 2, |
37 | 0 | ); |
38 | 0 | result = result.offset(-8); |
39 | 0 | } |
40 | 0 | write_mantissa(output as u32, result); |
41 | 0 | } |
42 | | |
43 | | #[cfg_attr(feature = "no-panic", inline)] |
44 | 0 | pub unsafe fn write_mantissa(mut output: u32, mut result: *mut u8) { |
45 | 0 | while output >= 10_000 { |
46 | 0 | let c = output - 10_000 * (output / 10_000); |
47 | 0 | output /= 10_000; |
48 | 0 | let c0 = (c % 100) << 1; |
49 | 0 | let c1 = (c / 100) << 1; |
50 | 0 | ptr::copy_nonoverlapping( |
51 | 0 | DIGIT_TABLE.as_ptr().offset(c0 as isize), |
52 | 0 | result.offset(-2), |
53 | 0 | 2, |
54 | 0 | ); |
55 | 0 | ptr::copy_nonoverlapping( |
56 | 0 | DIGIT_TABLE.as_ptr().offset(c1 as isize), |
57 | 0 | result.offset(-4), |
58 | 0 | 2, |
59 | 0 | ); |
60 | 0 | result = result.offset(-4); |
61 | 0 | } |
62 | 0 | if output >= 100 { |
63 | 0 | let c = (output % 100) << 1; |
64 | 0 | output /= 100; |
65 | 0 | ptr::copy_nonoverlapping( |
66 | 0 | DIGIT_TABLE.as_ptr().offset(c as isize), |
67 | 0 | result.offset(-2), |
68 | 0 | 2, |
69 | 0 | ); |
70 | 0 | result = result.offset(-2); |
71 | 0 | } |
72 | 0 | if output >= 10 { |
73 | 0 | let c = output << 1; |
74 | 0 | ptr::copy_nonoverlapping( |
75 | 0 | DIGIT_TABLE.as_ptr().offset(c as isize), |
76 | 0 | result.offset(-2), |
77 | 0 | 2, |
78 | 0 | ); |
79 | 0 | } else { |
80 | 0 | *result.offset(-1) = b'0' + output as u8; |
81 | 0 | } |
82 | 0 | } |