mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 16:32:11 +01:00
Optimize 128-bit muls in parse_number_f64_eisel
Processing citylots.json from github.com/zemirco/sf-city-lots-json $ cc -O3 script/process-json-numbers.c $ time ./a.out --parse-number-f64 < citylots.json gcc 9.3 Before/After real 0m0.638s real 0m0.609s clang 9.0 Before/After real 0m0.692s real 0m0.685s x86_64 Broadwell desktop CPU.
This commit is contained in:
1 parent
74d4af66e4
commit
18449ad75d
3 files changed
+37
-5
No files matched your search
@@ -844,10 +844,18 @@ wuffs_base__private_implementation__parse_number_f64_eisel(uint64_t man,
|
||||
// As a consequence, x_hi has either 0 or 1 leading zeroes. Shifting x_hi
|
||||
// right by either 9 or 10 bits (depending on x_hi's MSB) will therefore
|
||||
// leave the top 10 MSBs (bits 54 ..= 63) off and the 11th MSB (bit 53) on.
|
||||
#if defined(__GNUC__)
|
||||
// Clang also defines "__GNUC__".
|
||||
__uint128_t x =
|
||||
((__uint128_t)man) * (((uint64_t)po10[2]) | (((uint64_t)po10[3]) << 32));
|
||||
uint64_t x_hi = ((uint64_t)(x >> 64));
|
||||
uint64_t x_lo = ((uint64_t)(x));
|
||||
#else
|
||||
wuffs_base__multiply_u64__output x = wuffs_base__multiply_u64(
|
||||
man, ((uint64_t)po10[2]) | (((uint64_t)po10[3]) << 32));
|
||||
uint64_t x_hi = x.hi;
|
||||
uint64_t x_lo = x.lo;
|
||||
#endif
|
||||
|
||||
// Before we shift right by at least 9 bits, recall that the look-up table
|
||||
// entry was possibly truncated. We have so far only calculated a lower bound
|
||||
@@ -863,10 +871,18 @@ wuffs_base__private_implementation__parse_number_f64_eisel(uint64_t man,
|
||||
// a "low resolution" 64-bit mantissa. Now use a "high resolution" 128-bit
|
||||
// mantissa. We've already calculated x = (man * bits_0_to_63_incl_of_e).
|
||||
// Now calculate y = (man * bits_64_to_127_incl_of_e).
|
||||
#if defined(__GNUC__)
|
||||
// Clang also defines "__GNUC__".
|
||||
__uint128_t y = ((__uint128_t)man) *
|
||||
(((uint64_t)po10[0]) | (((uint64_t)po10[1]) << 32));
|
||||
uint64_t y_hi = ((uint64_t)(y >> 64));
|
||||
uint64_t y_lo = ((uint64_t)(y));
|
||||
#else
|
||||
wuffs_base__multiply_u64__output y = wuffs_base__multiply_u64(
|
||||
man, ((uint64_t)po10[0]) | (((uint64_t)po10[1]) << 32));
|
||||
uint64_t y_hi = y.hi;
|
||||
uint64_t y_lo = y.lo;
|
||||
#endif
|
||||
|
||||
// Merge the 128-bit x and 128-bit y, which overlap by 64 bits, to
|
||||
// calculate the 192-bit product of the 64-bit man by the 128-bit e.
|
||||
|
||||
Reference in new issue
Block a user