Skip to content

odfs: share the byte-order helpers; one move per field on the 68020 - #63

Merged
reinauer merged 2 commits into
mainfrom
byteorder
Nov 29, 2026
Merged

reinauer merged 2 commits into
mainfrom
byteorder

Conversation

@reinauer

Copy link
Copy Markdown
Owner

Follow-up to #62.

Commits

  1. odfs: share the byte-order helpers. Each backend had its own copy of the endian loads (iso_read_le16/32, Rock Ridge's wrapper, udf_le16/32/64, hfs_be16/32/64), CDDA had its own store helpers, and session.c, charset.c and the host file media assembled bytes by hand. They're all in include/odfs/byteorder.h now: odfs_le16/32/64, odfs_be16/32/64, odfs_put_le16/32, odfs_put_be16/32.
    • The 68020 move.l load moves with odfs_le32, so UDF gets it too: the 020 build shrinks by 832 bytes, all of it in udf.o.
    • The 68000 and ROM builds differ only in charset.c, where the register allocation changed.
    • The endian tests move to a new tests/unit/test_byteorder.c, which also covers big-endian, 64-bit, stores and odd addresses.
  2. odfs: load 16-bit and big-endian fields with one move on the 68020. Under ODFS_M68K_UNALIGNED_OK, odfs_le16 becomes move.w plus a byte swap, and odfs_be16/odfs_be32 become a plain move. The 020 build shrinks by another 1848 bytes (2680 against main), mostly in HFS, HFS+ and UDF. The 68000 and ROM builds don't change.

handler_main.c still builds its SCSI fields by hand: any change in code generation in its packet loop moves CDBench.

CDBench (68040 rig, 68020 build, main → this)

Image Figure main this PR
UDF fixture seq read (KiB/s) 168676 172411
Discovery (entries/s) 5498 5617
same-offset random (µs) 85 80
HFS fixture Discovery (entries/s) 6119 6477
small open+read (µs) 390 384
ISO fixture every figure unchanged

The HFS fixture is the CDBench tree in an Apple partition map, made with hdiutil makehybrid -hfs.

Testing

  • Host: make check, golden-check and malformed-check pass. All OS3 targets build within their size limits.

  • Guest regression tool (5028 checks), ISO, UDF and HFS images, with main and this branch:

    • OS 3.2 / 68040 (020 build) in WinUAE
    • OS 4.1 on pegasos2 in QEMU
    • AROS i386 in QEMU

    The output is identical between main and this branch on every platform and image. ISO passes everywhere. The 896 failures on HFS (and UDF on OS3) are the tool's check for ISO's upper-case names, and they're the same on main.

  • AROS: List ALL output identical for all three images.

  • AmiFUSE integration test passes.

Each backend had its own copy of the little- and big-endian loads:
iso_read_le16/32 in the ISO 9660 backend, with Rock Ridge wrapping it,
udf_le16/32/64 for UDF, hfs_be16/32/64 for HFS and HFS+, store
helpers in the CDDA backend, and open-coded byte assembly in
session.c, charset.c and the host file media. Only the ISO copy loaded
its field with one move on the 68020.

Put them in one place, include/odfs/byteorder.h, as odfs_le16/32/64,
odfs_be16/32/64 and odfs_put_le16/32 and odfs_put_be16/32. The
68020 load is kept for odfs_le32, so the UDF backend now gets it too:
the 68020 build shrinks by 832 bytes, all of it in udf.o. The 68000
and ROM builds differ only in charset.c, where the UTF-16 decode now
takes the address of the code unit and GCC allocates registers a
little differently.

The endian tests move from test_iso9660.c to a new test_byteorder.c,
which also covers the big-endian, 64-bit and store helpers and loads
at odd addresses.

handler_main.c still builds its SCSI fields by hand: its packet loop
is sensitive to any change in code generation.
GCC keeps to aligned accesses on every m68k, so a field at an
arbitrary offset is assembled byte by byte, about seven instructions
for a long. The 68020 and later allow word and long accesses at any
address, and odfs_le32() already used one move.l there. Do the same
for odfs_le16() (move.w and a byte swap), odfs_be16() and odfs_be32()
(a plain move), and so for the 64-bit loads built from them.

That mostly helps HFS and HFS+, which are big-endian throughout, and
UDF. The 68020 build shrinks by another 1848 bytes, 2680 against
main. The 68000 and ROM builds do not change.

CDBench on the 68040 rig, 68020 build, main -> this:

  UDF fixture   seq read     168676 -> 172411 KiB/s
                Discovery      5498 -> 5617 entries/s
                same offset      85 -> 80 us
  HFS fixture   Discovery      6119 -> 6477 entries/s
                small o+r       390 -> 384 us
  ISO fixture   unchanged on every figure

The HFS fixture is the CDBench tree in an Apple partition map, made
with hdiutil makehybrid -hfs.
@reinauer
reinauer merged commit f84c874 into main Nov 29, 2026
3 checks passed
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.

1 participant