Skip to content

Enable UNALIGNED_ACCESS_IS_FAST for all PowerPC variants#448

Merged
ebiggers merged 1 commit intoebiggers:masterfrom
Scottcjn:fix/powerpc-unaligned-access
Mar 16, 2026
Merged

Enable UNALIGNED_ACCESS_IS_FAST for all PowerPC variants#448
ebiggers merged 1 commit intoebiggers:masterfrom
Scottcjn:fix/powerpc-unaligned-access

Conversation

@Scottcjn
Copy link
Copy Markdown

Problem

The UNALIGNED_ACCESS_IS_FAST check in common_defs.h only tests
__powerpc64__, which misses:

  • 32-bit PowerPC (Linux/BSD) — uses __powerpc__ instead
  • Darwin/macOS PowerPC (both 32-bit and 64-bit) — uses __POWERPC__ instead

This causes all Mac PowerPC builds (G3/G4/G5) and 32-bit Linux PowerPC
to take the slow byte-by-byte code path unnecessarily.

Fixes #362

Fix

Add __powerpc__ and __POWERPC__ to the preprocessor conditional alongside the existing __powerpc64__ check.

Testing

Power Mac G5 (Darwin 9.8.0, GCC 10.5.0, big-endian PPC):

  • Only __POWERPC__ is defined (not __powerpc64__ or __powerpc__)
  • Before fix: UNALIGNED_ACCESS_IS_FAST = 0 (missed)
  • After fix: UNALIGNED_ACCESS_IS_FAST = 1 (detected)

IBM POWER8 S824 (Ubuntu 20.04, GCC 9.4.0, ppc64le):

  • Both __powerpc64__ and __powerpc__ defined
  • Was already detected via __powerpc64__, still works with the additional checks

Macro coverage

Platform __powerpc64__ __powerpc__ __POWERPC__
Linux ppc64/ppc64le
Linux ppc (32-bit)
Darwin PPC (G3/G4/G5)
Darwin PPC64

The existing check only tests __powerpc64__, which is defined on
64-bit Linux/BSD PowerPC. Add __powerpc__ (32-bit Linux/BSD) and
__POWERPC__ (Darwin/macOS, both 32-bit and 64-bit ABI) so that all
PowerPC platforms benefit from the fast unaligned access code paths.

All PowerPC processors support unaligned 32-bit integer access in
hardware with minimal penalty, so the byte-by-byte fallback path is
unnecessarily conservative on these platforms.

Tested on Power Mac G5 (Darwin 9.8.0, GCC 10.5.0) where only
__POWERPC__ is defined — the fix correctly enables the fast path.
Also verified on IBM POWER8 S824 (ppc64le, GCC 9.4.0).

Fixes ebiggers#362
@ebiggers ebiggers merged commit 4b6db59 into ebiggers:master Mar 16, 2026
47 checks passed
@ebiggers
Copy link
Copy Markdown
Owner

Merged, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unaligned access on PowerPC: forgotten macros in common_defs.h

2 participants