mbutrovich opened a new issue, #11453:
URL: https://github.com/apache/arrow-rs/issues/11453

   ### Is your feature request related to a problem or challenge?
   
   `multiply_fixed_point` and `multiply_fixed_point_checked` widen each pair of 
`Decimal128` values to `i256`, multiply them, and rescale the product with 
[`divide_and_round`](https://github.com/apache/arrow-rs/blob/c7f60c612bd16ca5485cc9acddfd216c10ea9765/arrow-arith/src/arithmetic.rs#L172-L186).
 `divide_and_round` calls `div_wrapping` and `mod_wrapping` separately, so each 
row runs Knuth's Algorithm D 
([`div_rem_knuth`](https://github.com/apache/arrow-rs/blob/c7f60c612bd16ca5485cc9acddfd216c10ea9765/arrow-buffer/src/bigint/div.rs#L83))
 twice. It also computes `half = div / 2` for every row, though `div` is the 
same for the whole array.
   
   ### Describe the solution you'd like
   
   `divide_and_round` is private, and both callers 
([1](https://github.com/apache/arrow-rs/blob/c7f60c612bd16ca5485cc9acddfd216c10ea9765/arrow-arith/src/arithmetic.rs#L122),
 
[2](https://github.com/apache/arrow-rs/blob/c7f60c612bd16ca5485cc9acddfd216c10ea9765/arrow-arith/src/arithmetic.rs#L166))
 use `Decimal256Type`. It could take `i256` directly and call 
`i256::wrapping_div_rem` from #11425. `half` and `half_neg` could be computed 
once, before the `binary` and `try_binary` calls.
   
   While reviewing #11425, @andygrove measured this in a quick benchmark 
(arm64, 8192 rows, divisors from 10^10 to 10^54). The fused call was 1.6x to 
1.8x faster, and 2.0x to 2.2x faster with `half` computed outside the loop, 
with identical output. The `decimal128_multiply_fixed_point` benchmarks in 
#11427 can give before and after numbers in the repo.
   
   ### Describe alternatives you've considered
   
   The divisor is the same for every row, so the precomputed divisors in #11421 
would also apply here. This change doesn't depend on them and would come first.
   
   ### Additional context
   
   This depends on #11425.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to