Skip to content

Use the optimized multiply path for decimal32_t - #1465

Merged
mborland merged 1 commit into
boostorg:developfrom
ibmibmibm:worktree-d32-mul
Sep 25, 2026
Merged

mborland merged 1 commit into
boostorg:developfrom
ibmibmibm:worktree-d32-mul

Conversation

@ibmibmibm

Copy link
Copy Markdown
Contributor
  • decimal32_t * decimal32_t gave the raw product to the constructor. The
    other types take the path through mul_finalize_u64, which is faster.
    A comment said that the hardware divide of the constructor was cheap
    enough, but on the machine below the constructor path is slower.
  • decimal32_t now takes the same path as the other types, except for one
    case. That path rounds the product to 7 digits before pack_in_range,
    and the constructor then rounds a subnormal result a second time.
  • Because of this, a product with an exponent below etiny still goes to
    the constructor unrounded. Above etiny, the rounded result has 7 digits
    or is at least 1e-94, so one rounding is correct.
  • decimal32_t * Integer keeps the constructor path. The optimized path
    gives a zero product a different quantum exponent there.

The results are bit-identical to develop. I compared 100 million random
products in each of the five rounding modes, with subnormal operands, short
significands and integer right operands.

test/benchmarks.cpp, multiplication, median of 6 runs (Ryzen 9 3900X,
GCC 16, -O3):

Type develop this PR
decimal32_t 3376647 us 2650213 us
decimal_fast32_t 2006705 us 2006168 us

The checksum s of the benchmark is the same before and after.

- decimal32_t * decimal32_t gave the raw product to the constructor, and did not use the
  faster path of the other types.
- That path rounds to 7 digits before pack_in_range, and the constructor then rounds a
  subnormal result again. Thus a product with an exponent below etiny still goes to the
  constructor unrounded. Above etiny, the rounded result has 7 digits or is at least 1e-94,
  so one rounding is correct.
- decimal32_t * Integer keeps the constructor path, because the optimized path gives a
  zero product a different exponent.
- The results are bit-identical to the old path in all five rounding modes.

@mborland mborland left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@mborland
mborland merged commit ea218b6 into boostorg:develop Sep 25, 2026
71 of 73 checks passed
@ibmibmibm
ibmibmibm deleted the worktree-d32-mul branch September 25, 2026 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants