GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
gcc/cris Performance Win

CRIS: Add support for SWAP instruction variants

New patterns enable efficient use of CRIS architecture's SWAP instruction for bit manipulation and rotation.

This commit enhances the CRIS backend by adding support for several variants of the SWAP instruction found in version 8 of the CRIS architecture. These new patterns allow GCC to efficiently implement operations like 32-bit rotates by 16 bits and bit reversal, significantly reducing code size and improving performance compared to previous manual implementations.

In Details

The CRIS architecture's backend (config/cris/cris.md) has been extended to support the SWAP instruction and its variants, specifically targeting architectures supporting version 8. This includes new define_insn patterns for operations like bitreversesi2 and rotatesi3_16. Previously, these operations required multiple instructions. The SWAP instruction, when available, can perform these bitwise manipulations in a single cycle, leading to substantial code size and performance improvements. The patch also renames an internal cris_swap_bits to a standard optab name, exposing it to the…

For Context
CRIS
A family of 16-bit microprocessors developed by Axis Communications. GCC has a backend for this architecture.
SWAP instruction
A processor instruction that exchanges the byte order of data within a register or memory location. In the CRIS V8 architecture, it is also used for bit reversal and rotation operations.
bit reversal
An operation that reverses the order of bits within a data word. For example, the bits in '1101' would become '1011'.
backend
The part of a compiler that generates machine code for a specific target architecture. For GCC, this includes files in config/<arch>/.
optab
Short for 'operator table'. It's a data structure within GCC that maps generic arithmetic and bitwise operations to specific machine instructions or sequences of instructions.
Filed Under: crisoptimizationarchitecture