Ticket #5598 (closed task: fixed)
Function quotRem is inefficient
|Reported by:||boris||Owned by:||igloo|
|Keywords:||division, performance, primop||Cc:||kazu@…, pumpkingod@…, dterei|
|Type of failure:||Runtime performance bug||Difficulty:||Unknown|
|Test Case:||Blocked By:|
Function quotRem gets compiled into two div instructions although div computes both quotient and remainder. This inefficiency exists both with NCG and LLVM backends. Thus, quotRem is at least twice as slow as it could be.
As far as I understand, quotRem is decomposed into two primops quotInt# and remInt# (or quotWord# and remWord#) and each of them is compiled independently into code which has div instruction. I propose to add new primops quotRemInt# and quotRemWord# to address this flaw.
Please see the sample code and corresponding assembly.