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

crbytes: CommonPrefix #1

Merged
merged 1 commit into from
Aug 16, 2024
Merged

Conversation

RaduBerinde
Copy link
Member

@RaduBerinde RaduBerinde commented Aug 4, 2024

This commit adds a crbytes library with a CommonPrefix method. It has a generic implementation that compares 8 bytes at a time and a native amd64 implementation that is based on the bytes.Compare implementation.

This is a "long flight to Europe" special 😄 Maybe an arm64 implementation on the way back :)


This change is Reviewable


// This code is based on compare_amd64.s from Go 1.12.5.

TEXT ·CommonPrefix(SB),$0-56
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If anyone actually wants to look at this, here's the diff against bytes.Compare: https://editor.mergely.com/V6Bvcmbr

@RaduBerinde
Copy link
Member Author

Added arm64 assembly. Diff against bytes.Compare implementation: https://editor.mergely.com/lBD1P7YX

Copy link

@petermattis petermattis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 7 files reviewed, 1 unresolved discussion (waiting on @jbowens)

a discussion (no related file):

Previously, RaduBerinde wrote…

(Reviewable was unable to map this GitHub inline comment thread to the right spot — sorry!)

If anyone actually wants to look at this, here's the diff against bytes.Compare: https://editor.mergely.com/V6Bvcmbr

Neat! I didn't look at the assembly implementations in detail, but they looked good on a quick skim. I'll leave the thorough review to @jbowens.


Copy link
Contributor

@jbowens jbowens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started giving this a look, but it's slow going... gotta relearn everything I've paged out

Maybe an arm64 implementation on the way back :)

Added arm64 assembly.

Now your return flight is freed up for an assembly version of https://github.com/cockroachdb/pebble/blob/791b3749feb52978b973d79904fb79632b38046e/sstable/colblk/unsafe_slice.go#L115-L136 😄

Reviewed 5 of 7 files at r1, all commit messages.
Reviewable status: 5 of 7 files reviewed, 1 unresolved discussion (waiting on @petermattis)

@RaduBerinde
Copy link
Member Author

Maybe it's easier if we can go through it next week in a video chat?

Hehe, good idea about the UnsafeSlice thing, I will take a look. By the way, that code as written assumes little-endian arch correct?

@jbowens
Copy link
Contributor

jbowens commented Aug 9, 2024

Maybe it's easier if we can go through it next week in a video chat?

Yeah, that'd be great

By the way, that code as written assumes little-endian arch correct?

Yeah, it does. We might need to revisit that, as IIRC, there's some talk about officially adding support for one big-endian arch in particular. I'm not sure where else we assume little-endian arch within Pebble

@sumeerbhola
Copy link

By the way, that code as written assumes little-endian arch correct?

which part of that existing code is assuming little-endian?

@RaduBerinde
Copy link
Member Author

which part of that existing code is assuming little-endian?

In https://github.com/cockroachdb/pebble/blob/791b3749feb52978b973d79904fb79632b38046e/sstable/colblk/unsafe_slice.go#L115-L136 we cast directly to *uintX and the byte slice is in little-endian format (that is our disk format).

@RaduBerinde
Copy link
Member Author

Updated the AMD64 assembly with a lot more comments and simplified some sections.

@RaduBerinde RaduBerinde force-pushed the common-prefix branch 6 times, most recently from 7e34d6b to e24f2ac Compare August 14, 2024 20:16
@RaduBerinde
Copy link
Member Author

Updated ARM64 assembly with comments as well.

This commit adds a `crbytes` library with a `CommonPrefix` method. It
has a generic implementation that compares 8 bytes at a time and a
native `amd64` implementation that is based on the `bytes.Compare`
implementation.
@RaduBerinde
Copy link
Member Author

OK to merge?

Copy link
Contributor

@jbowens jbowens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 1 of 2 files at r3, 1 of 1 files at r4, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @RaduBerinde)

@RaduBerinde RaduBerinde merged commit 1c502cd into cockroachdb:main Aug 16, 2024
5 of 7 checks passed
@RaduBerinde RaduBerinde deleted the common-prefix branch August 16, 2024 11:58
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.

4 participants