Skip to content
DenseChip
Learn
PracticeCode labInterview

DenseChip

Navigate

Menu

LearnPracticeCode labInterview

Tools

All toolsSV editorCode repoResume
DenseChip

Practice, courses, and chip-design tools in one focused workspace.

LearnPracticeCode labInterviewToolsLearning paths

© 2026 DenseChip

AboutContactPrivacyTerms
Skip to lesson

Course contents

  • Logic Synthesis Glossary
  • Logic Synthesis Cheatsheet
  • Synthesis Foundations14
  • Logic Optimisation and Mapping20
  • Constraints and Timing15
  • Sequential, FSM and Memory19
  • Datapath Synthesis14
    • Adders and Carry Structures
    • Multipliers and Compressors
    • Resource Sharing and Arithmetic Inference
      • ALU Inference and alumacc
      • Sharing Adders and the Mux Cost
      • wreduce and Operator Widths
      • Constant Multipliers and Carry Tricks
  • Area, Power and Test14
  • Verification, ECO and Handoff15
  • Flows and Debugging15
  • Interview and Judgment11
Loading lesson

‹Resource Sharing and Arithmetic Inference
  1. Topics
  2. Logic Synthesis
  3. Datapath Synthesis
  4. Resource Sharing and Arithmetic Inference
  5. wreduce and Operator Widths

Part 5 · Datapath Synthesis · Intermediate

wreduce and Operator Widths

Trimming operators to the bits the result actually keeps.

On this page

    Why operators come out too wide

    RTL sizes every operator from its context, often wider than needed. A sum assigned into a wide bus keeps a wide adder even when few result bits matter.

    Only kept bits need hardware. A kept low slice never depends on input bits above it, so the carry chain above can go.

    Kept result

    What the adder needs

    Low 4 bits of an 8-bit sum

    A 4-bit adder. Upper carries never reach kept bits.

    Full 8-bit sum

    A 9-bit result. 255 + 255 = 510 fits 9 bits.

    One unsigned compare

    A single decision bit from the shared subtract.

    What wreduce does

    The wreduce pass narrows operators toward the bits the design keeps. It trims result widths and drops logic that feeds only discarded bits.

    The block below keeps only the low 4 bits of an 8-bit sum. Its assertions pin one adder before and after the pass.

    yosys
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    read_verilog <<EOV
    module wtrim(input [7:0] a, b, output [3:0] y);
    wire [7:0] s = a + b;
    assign y = s[3:0];
    endmodule
    EOV
    hierarchy -top wtrim
    proc
    select -assert-count 1 t:$add
    wreduce
    select -assert-count 1 t:$add
    opt_clean
    select -assert-count 1 t:$add
    stat -liberty course.lib
    log PASS: wreduce keeps one trimmed adder

    The assertions pin the adder count at one before and after. The width it keeps follows the kept result bits: 4 here, from the hand arithmetic below.

    Signedness and extension

    Extension must match the declared signedness before any compare or slice. Zero extension keeps the bit pattern; sign extension keeps the value.

    Diagram
    8-bit unsigned addition: 255 + 255 = 510; 510 < 512 = 2^9, so the full sum needs 9 bits
    keeping only y[3:0] of a + b needs a 4-bit adder: each kept bit depends only on input bits at or below it
    extension changes value: 8'hff zero-extended to 16 bits = 255; sign-extended = 65535, which is -1 as signed 16-bit
    so (signed) -1 < 1 is true while (unsigned) 255 < 1 is false for the same byte

    Common mistakes

    Common pitfall

    Zero-extending a signed value before a compare turns -1 into 255. Sign-extend signed values and zero-extend unsigned ones, then recheck every compare on a value with the top bit set.

    Interview

    Likely probes: how much adder a kept slice needs, and which extension each compare wants.

    • Kept low bits need only that many adder bits; the carry above is discarded.

    • A full 8-bit unsigned sum needs 9 result bits, since 510 needs 2^9.

    • Signed compares need sign extension on both sides; unsigned compares need zero extension.

    Check yourself Only y[3:0] of an 8-bit a + b is kept. How wide is the adder wreduce keeps?

    4 bits. Each kept bit depends only on input bits at or below it, so the upper carry chain goes.

    Check yourself 8'hff is extended to 16 bits, then compared against 16'd255 for equality. True under zero extension, and under sign extension?

    True under zero extension, since both sides are 255. False under sign extension, since the extended value is 65535.

    Related topics

    • Constant multipliers and carry tricks

    • Synthesizable RTL and Inference

    • Comparators and Shifters

    Previous

    83 / 139

    Next: Constant Multipliers and Carry Tricks

    Up next

    Up nextConstant Multipliers and Carry Tricks

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • ALU Inference and alumacc