snappy: optimize UnalignedCopy64 and IncrementalCopy for RISC-V#3360
Open
Felix-Gong wants to merge 1 commit into
Open
snappy: optimize UnalignedCopy64 and IncrementalCopy for RISC-V#3360Felix-Gong wants to merge 1 commit into
Felix-Gong wants to merge 1 commit into
Conversation
c9dbd91 to
25a5434
Compare
Use RISC-V inline assembly (ld/sd) for 8-byte copy operations instead of generic macro-based implementation. Changes: - UnalignedCopy64: direct ld/sd pair for 8-byte copy - IncrementalCopy: 8-byte bulk copies when source/dest don't overlap Performance improvement (direct function benchmark): - Decompress compressible-256K: 728 MB/s -> 2205 MB/s (+203%) - Decompress zeros-256K: 543 MB/s -> 1462 MB/s (+169%) Tests: brpc_snappy_compress_unittest passed (7/7) Signed-off-by: Felix-Gong <gongxiaofei24@iscas.ac.cn>
25a5434 to
83cd75a
Compare
Contributor
|
LGTM |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aims to improve Snappy decompression performance on RV64 by accelerating 8-byte copy paths in UnalignedCopy64() and IncrementalCopy() using inline RISC-V ld/sd.
Changes:
- Add an RV64-specific 8-byte bulk-copy loop to
IncrementalCopy()when overlap is considered safe. - Add an RV64-specific
ld/sdimplementation forUnalignedCopy64().
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/butil/third_party/snappy/snappy.cc | Adds RV64 inline-asm 8-byte copying to IncrementalCopy() for non-overlapping (or “safe overlap”) cases. |
| src/butil/third_party/snappy/snappy-stubs-internal.h | Adds RV64 inline-asm ld/sd fast path to UnalignedCopy64(). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+101
to
+116
| // RISC-V optimized: use 8-byte copies when possible | ||
| if (len >= 8 && (op - src >= 8 || src - op >= 8)) { | ||
| // Non-overlapping or safe overlap: copy 8 bytes at a time | ||
| do { | ||
| uint64_t tmp; | ||
| __asm__ volatile( | ||
| "ld %0, %1\n\t" | ||
| "sd %0, %2\n\t" | ||
| : "=&r"(tmp) | ||
| : "m"(*(const uint64_t*)src), "m"(*(uint64_t*)op) | ||
| : "memory"); | ||
| src += 8; | ||
| op += 8; | ||
| len -= 8; | ||
| } while (len >= 8); | ||
| } |
Comment on lines
+167
to
+176
| #if defined(__riscv) && __riscv_xlen == 64 | ||
| // RISC-V optimized: single ld/sd pair for 8-byte copy | ||
| uint64_t tmp; | ||
| __asm__ volatile( | ||
| "ld %0, %1\n\t" | ||
| "sd %0, %2\n\t" | ||
| : "=&r"(tmp) | ||
| : "m"(*(const uint64_t*)src), "m"(*(uint64_t*)dst) | ||
| : "memory"); | ||
| #else |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
UnalignedCopy64()with directld/sdinline assembly for 8-byte copyIncrementalCopy()with 8-byte bulk copies when source/dest don't overlapPerformance Improvement (direct function benchmark)
Changes
src/butil/third_party/snappy/snappy-stubs-internal.h: +11 linessrc/butil/third_party/snappy/snappy.cc: +24 linesTest Plan