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

Hard code endianness #649

Closed

Conversation

brycekahle
Copy link
Contributor

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.

internal/endian_le.go Show resolved Hide resolved
internal/endian.go Outdated Show resolved Hide resolved
@lmb
Copy link
Collaborator

lmb commented May 2, 2022

Interesting, thanks!

@brycekahle brycekahle force-pushed the bryce.kahle/endian-build-time branch from 0ca7fa5 to afd6cca Compare May 2, 2022 15:58
@brycekahle brycekahle changed the title Hard code endianness on amd64/arm64 Hard code endianness May 2, 2022
@lmb
Copy link
Collaborator

lmb commented May 3, 2022

I'm getting the following when trying to pull your branch:

$ git pull [email protected]:DataDog/ebpf.git bryce.kahle/endian-build-time
From github.com:DataDog/ebpf
 * branch            bryce.kahle/endian-build-time -> FETCH_HEAD
fatal: refusing to merge unrelated histories

Similar result when checking out via github CLI, it only shows me a single commit with all source code smushed into one blob. Did you do any unorthodox git mangling on your repo that could cause this?

@brycekahle
Copy link
Contributor Author

Did you do any unorthodox git mangling on your repo that could cause this?

I don't believe so. Did you try gh pr checkout 649?

@lmb
Copy link
Collaborator

lmb commented May 4, 2022

I tried pushing a fixup, but it seems like you have maintainer edits disabled? Anyways, I removed the generic fallback and added you good writeup to the commit message: 1a5ff41 Let me know if you want to force push that into your branch or if I should make a new PR.

@brycekahle
Copy link
Contributor Author

like you have maintainer edits disabled?

Apparently this isn't supported for org-owned forks at the moment.

Let me know if you want to force push that into your branch or if I should make a new PR.

Whatever is easier for you, is fine with me.

@lmb
Copy link
Collaborator

lmb commented May 4, 2022

See #662. Can you use a personal fork in the future?

@lmb lmb closed this May 4, 2022
@brycekahle
Copy link
Contributor Author

Can you use a personal fork in the future?

Yeah. That shouldn't be a problem.

@brycekahle brycekahle deleted the bryce.kahle/endian-build-time branch May 4, 2022 22:25
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