Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Generate simpler code for Int and Long division and remainder. #114

Merged
merged 1 commit into from
Apr 23, 2024

Conversation

sjrd
Copy link
Collaborator

@sjrd sjrd commented Apr 20, 2024

Notably, when the rhs is a constant, we can emit straightforward code without any branches. This is worth it because the divisor of integer divisions and remainders is often constant in practice.

To handle the overflow case of MinValue / -1, we also remove one branch by turning lhs / -1 into 0 - lhs. The previous codegen used if (lhs == MinValue) MinValue else lhs / -1 in the same situation.

Copy link
Owner

@tanishiking tanishiking left a comment

Choose a reason for hiding this comment

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

👍

Notably, when the rhs is a constant, we can emit straightforward
code without any branches. This is worth it because the divisor of
integer divisions and remainders is often constant in practice.

To handle the overflow case of `MinValue / -1`, we also remove one
branch by turning `lhs / -1` into `0 - lhs`. The previous codegen
used `if (lhs == MinValue) MinValue else lhs / -1` in the same
situation.
@sjrd sjrd merged commit 1be5a2b into tanishiking:main Apr 23, 2024
1 check passed
@sjrd sjrd deleted the simpler-int-div-mod branch April 23, 2024 08:04
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants