# x86_64: fix unencodable \`rem\` lowerings · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/611c38e6daffc18bc044ebb1e20d161b4ef757f2)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 611c38e6daffc18bc044ebb1e20d161b4ef757f2

Requested commit: 611c38e6daffc18bc044ebb1e20d161b4ef757f2

Commit: 611c38e6daffc18bc044ebb1e20d161b4ef757f2

Tree: f825f464e0bfcfdaf3d4894a7006af8edfb62dfd

Author: mlugg

Committer: Jacob Young

## Message

```
x86_64: fix unencodable `rem` lowerings

The memory operand might use one of the extended GPRs R8 through R15 and
hence require a REX prefix, but having a REX prefix makes the high-byte
register AH unencodeable as the src operand. This latent bug was exposed
by this branch, presumably because `select` now happens to be putting
something in an extended GPR instead of a legacy GPR.

In theory this could be fixed with minimal cost by introducing a way to
communicate to `select` that neither the destination memory nor the
other temporary can be in an extended GPR. However, I just went for the
simple solution which comes at a cost of one trivial instruction: copy
the remainder from AH to AL, and *then* copy AL to the destination.

```

## Parents

- [77fca1652fce295fe0dd7c97432c23b0c4483724](https://git.cafe/gitcafe/zig/commit/77fca1652fce295fe0dd7c97432c23b0c4483724?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/611c38e6daffc18bc044ebb1e20d161b4ef757f2?format=markdown)
