Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/compile/internal/amd64: improve fix up code for signed division
In order to avoid a CPU exception resulting from signed overflow, the signed division code tests if the divisor is -1 and if it is, runs fix up code to manually compute the quotient and remainder (thus avoiding IDIV and potential signed overflow). However, the way that this is currently structured means that the normal code path for the case where the divisor is not -1 results in five instructions and two branches (CMP, JEQ, followed by sign extension, IDIV and another JMP to skip over the fix up code). Rework the fix up code such that the final JMP is incurred by the less likely divisor is -1 code path, rather than more likely code path (which is already more expensive due to IDIV). This result in a four instruction sequence (CMP, JNE, sign extension, IDIV), with only a single branch. Updates #59089 Change-Id: Ie8d065750a178518d7397e194920b201afeb0530 Reviewed-on: https://go-review.googlesource.com/c/go/+/482658 Run-TryBot: Joel Sing <[email protected]> Reviewed-by: Keith Randall <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Michael Knyszek <[email protected]>
- Loading branch information