GCC Newspaper
JULY 29, 2026
Date
/
Architectures
Components
Topics
News & Policy
m68k

M68k bit operations on memory now use correct bit number

M68k bitset and bitclear instructions operating on memory now correctly use only the lower 3 bits of the bit number.

GCC’s m68k backend now correctly models the behavior of bset and bclr instructions when operating on memory. These instructions only use the lower 3 bits of the bit number to determine which bit to set or clear. A new test case is added to verify this fix.

In Details

The m68k bsetmemqi and bclrmemqi patterns in the machine description were missing a mask to ensure only the low 3 bits of the bit number are used, as per the hardware specification for memory operands. This commit adds the AND with 7 to the bit number operand in the relevant templates.

For Context
bset
M68k assembly instruction to set a specific bit in memory.
bclr
M68k assembly instruction to clear a specific bit in memory.
memory operands
Operands in assembly instructions that refer to data stored in RAM, as opposed to processor registers.
bit number
The index specifying which bit within a byte or word is targeted by an operation.
Filed Under: m68kcodegenbugfix