From bd51dea6934d5c583fe9c8bc806e6287cac43f90 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 28 Feb 2021 23:51:30 -0800 Subject: Change twice used large const table to static This table is used twice in core::num::dec2flt::algorithm::power_of_ten. According to the semantics of const, a separate huge definition of the table is inlined at both places. fn power_of_ten(e: i16) -> Fp { assert!(e >= table::MIN_E); let i = e - table::MIN_E; let sig = table::POWERS.0[i as usize]; let exp = table::POWERS.1[i as usize]; Fp { f: sig, e: exp } } Theoretically this gets cleaned up by optimization passes, but in practice I am experiencing a miscompile from LTO on this code. Making the table a static, which would only be defined a single time and not require attention from LTO, eliminates the miscompile and seems semantically more appropriate anyway. A separate bug report on the LTO bug is forthcoming. --- src/etc/dec2flt_table.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/etc/dec2flt_table.py b/src/etc/dec2flt_table.py index 9bbcaf7c4cc..ad2292e8571 100755 --- a/src/etc/dec2flt_table.py +++ b/src/etc/dec2flt_table.py @@ -113,7 +113,7 @@ def print_proper_powers(): print() print("#[rustfmt::skip]") typ = "([u64; {0}], [i16; {0}])".format(len(powers)) - print("pub const POWERS: ", typ, " = (", sep='') + print("pub static POWERS: ", typ, " = (", sep='') print(" [") for z in powers: print(" 0x{:x},".format(z.sig)) -- cgit 1.4.1-3-g733a5