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