# cbe: fix big-endian unnatural integer bitcast · gitcafe/zig

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

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

Visibility: public

Requested revision: 891f1870320000205291940ba2e276c1fa043cd0

Requested commit: 891f1870320000205291940ba2e276c1fa043cd0

Commit: 891f1870320000205291940ba2e276c1fa043cd0

Tree: 336c97a163394c7795e76794fd2b3811342d7076

Author: Matthew Lugg

Committer: Alex Rønne Petersen

## Message

```
cbe: fix big-endian unnatural integer bitcast

Integers with padding bits on big-endian targets cannot quite be bitcast
with a trivial memcpy, because the padding bits (which are zext or sext)
are the most-significant, so are at the *lowest* addresses. So to
bitcast to something which doesn't have padding bits, we need to offset
past the padding.

The logic I've added here definitely doesn't handle all possibilities
correctly; I think that would actually be quite complicated. However, it
handles a common case, and so prevents the Zig compiler itself from
being miscompiled on big-endian targets (hence fixing a bootstrapping
problem on big-endian).

```

## Parents

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

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