Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal: hard code endianness #662

Merged
merged 1 commit into from
May 4, 2022

Conversation

lmb
Copy link
Collaborator

@lmb lmb commented May 4, 2022

This results in a reduction of the instructions necessary for endian-related operations.
The wall clock time difference for a single call is miniscule (picoseconds).

An example, with the ByteOrder.Uint32 function:
Runtime instructions: https://godbolt.org/z/7vW1Pfnso
Buildtime instructions: https://godbolt.org/z/baxW1Wb7W

The function call on amd64 changes from:

MOVQ    "".NativeEndian(SB), CX
MOVQ    "".NativeEndian+8(SB), DX
MOVQ    64(CX), CX
MOVQ    AX, BX
MOVL    $4, DI
MOVQ    DX, AX
MOVQ    CX, DX
MOVQ    DI, CX
CALL    DX

to

XCHGL   AX, AX

The difference on arm64 is equivalent, but uses different specific instructions.

This results in a reduction of the instructions necessary for endian-related operations.
The wall clock time difference for a single call is miniscule (picoseconds).

An example, with the ByteOrder.Uint32 function:
Runtime instructions: https://godbolt.org/z/7vW1Pfnso
Buildtime instructions: https://godbolt.org/z/baxW1Wb7W

The function call on amd64 changes from:

    MOVQ    "".NativeEndian(SB), CX
    MOVQ    "".NativeEndian+8(SB), DX
    MOVQ    64(CX), CX
    MOVQ    AX, BX
    MOVL    $4, DI
    MOVQ    DX, AX
    MOVQ    CX, DX
    MOVQ    DI, CX
    CALL    DX
to

    XCHGL   AX, AX

The difference on arm64 is equivalent, but uses different specific instructions.
@lmb lmb mentioned this pull request May 4, 2022
@lmb lmb merged commit 422a008 into cilium:master May 4, 2022
@lmb lmb deleted the bryce.kahle/endian-build-time branch May 4, 2022 18:43
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.

2 participants