• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use crate::digit_table::*;
2 use core::ptr;
3 
4 #[cfg_attr(feature = "no-panic", inline)]
write_mantissa_long(mut output: u64, mut result: *mut u8)5 pub 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(DIGIT_TABLE.get_unchecked(c0 as usize), result.offset(-2), 2);
19         ptr::copy_nonoverlapping(DIGIT_TABLE.get_unchecked(c1 as usize), result.offset(-4), 2);
20         ptr::copy_nonoverlapping(DIGIT_TABLE.get_unchecked(d0 as usize), result.offset(-6), 2);
21         ptr::copy_nonoverlapping(DIGIT_TABLE.get_unchecked(d1 as usize), result.offset(-8), 2);
22         result = result.offset(-8);
23     }
24     write_mantissa(output as u32, result);
25 }
26 
27 #[cfg_attr(feature = "no-panic", inline)]
write_mantissa(mut output: u32, mut result: *mut u8)28 pub unsafe fn write_mantissa(mut output: u32, mut result: *mut u8) {
29     while output >= 10_000 {
30         let c = (output - 10_000 * (output / 10_000)) as u32;
31         output /= 10_000;
32         let c0 = (c % 100) << 1;
33         let c1 = (c / 100) << 1;
34         ptr::copy_nonoverlapping(DIGIT_TABLE.get_unchecked(c0 as usize), result.offset(-2), 2);
35         ptr::copy_nonoverlapping(DIGIT_TABLE.get_unchecked(c1 as usize), result.offset(-4), 2);
36         result = result.offset(-4);
37     }
38     if output >= 100 {
39         let c = ((output % 100) << 1) as u32;
40         output /= 100;
41         ptr::copy_nonoverlapping(DIGIT_TABLE.get_unchecked(c as usize), result.offset(-2), 2);
42         result = result.offset(-2);
43     }
44     if output >= 10 {
45         let c = (output << 1) as u32;
46         ptr::copy_nonoverlapping(DIGIT_TABLE.get_unchecked(c as usize), result.offset(-2), 2);
47     } else {
48         *result.offset(-1) = b'0' + output as u8;
49     }
50 }
51