What is Compressed instruction?

An instruction that encodes a common operation in fewer bits than usual. The RISC-V C extension adds 16-bit instructions and cuts code size by roughly 25-30%.

Field: ISA & Assembly

Japanese name: 圧縮命令

Why code is made smaller

Smaller program code saves flash memory capacity in embedded devices. In high-performance processors too, more instructions fit in an instruction cache of the same size, which helps speed. An ISA in which every instruction is 32 bits tends to produce larger code than an ISA with variable-length instructions. Compressed instructions make up for this weakness.

How the RISC-V C extension works

Only frequently used forms of instructions are expressed in 16 bits. To make them short, restrictions are applied depending on the instruction: the usable registers are limited to eight commonly used ones, immediates are smaller, and the destination register is the same as one of the inputs. Every 16-bit instruction does the same job as exactly one 32-bit instruction, so the processor only has to expand it to the 32-bit form at the start of decoding. 16-bit and 32-bit instructions can be mixed freely with no switching operation. The lowest two bits of an instruction show which length it is.

Comparison with other ISAs

The 32-bit Arm instruction set has Thumb, which uses 16-bit instructions. The original Thumb required switching modes between it and the 32-bit instructions. It later became possible to mix 16-bit and 32-bit instructions, and processors for small microcontrollers use only this form. The 64-bit Arm instruction set chose a fixed length of 32 bits only, giving priority to simple decoding. When there are many possible lengths, decoding several instructions at once becomes difficult. RISC-V has only two, so the burden is light.

Try it: questions about Compressed instruction

What is the main purpose of the RISC-V C extension (compressed instructions)?

  1. ATo add instructions that compress data and reduce memory use
  2. BTo let the CPU run C programs directly
  3. CTo encode common instructions in 16 bits and make programs smaller
Show answer and explanation

Answer: C. To encode common instructions in 16 bits and make programs smaller

The C extension represents common instructions in 16-bit forms with restricted fields, for example "addi sp, sp, -16" or lw and sw with small offsets. They mix freely with 32-bit instructions and make code smaller. Smaller programs fit more easily in limited flash memory and more of them fit in the instruction cache, which helps both embedded devices and high-performance CPUs.

FAQ

Do compressed instructions slow things down?

Normally not, because the circuit that expands them to the 32-bit form is simple. Since more instructions fit in the instruction cache, they can even make things faster.

Does the programmer need to write with compressed instructions in mind?

No. The assembler or compiler automatically replaces instructions that can be compressed with their 16-bit forms.

Questions that mention Compressed instruction (1)

Compressed instruction appears in 2 practice questions across 1 topic, including ISA & Assembly.

  1. What instructions does the RISC-V M extension add to the base integer instruction set?

Books on ISA & Assembly Ad

As an Amazon Associate I earn from qualifying purchases.

This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.

Back to the glossary