GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
gcc/risc-v Performance Win

RISC-V: Use Zvbb extension for bswap instructions

Leverages RISC-V Zvbb extension for more efficient bswap operations.

GCC now utilizes the RISC-V Zvbb extension to implement byte swap (bswap) operations more efficiently. The shuffle_bswap_pattern has been extended to use the vrev8 instruction, allowing it to swap bytes within larger data types (SImode and DImode) that were previously inefficiently handled. This change improves performance for bswap operations when the Zvbb extension is available.

In Details

This patch enhances config/riscv/riscv-v.cc by extending shuffle_bswap_pattern to use the vrev8 instruction from the Zvbb extension. Previously, SImode and DImode bswaps were not profitable due to the cost of generic instructions. The vrev8 instruction allows for more efficient byte swapping across these larger modes. Additionally, vector.md is updated to include variants of vbrev in mode_idx, supporting this enhancement.

For Context
Zvbb extension
A RISC-V vector extension that provides bit manipulation instructions, including byte reversal operations.
bswap
Byte swap operation, which reverses the order of bytes within a multi-byte data type (e.g., swapping the bytes of a 32-bit integer).
vrev8
A RISC-V vector instruction that reverses the order of bytes within vector elements.
SImode, DImode
GCC internal modes representing signed integer types, typically 32-bit (SImode) and 64-bit (DImode).
Filed Under: risc-voptimizationvectorizationinstruction set