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. ALU Inference and alumacc

Part 5 · Datapath Synthesis · Intermediate

ALU Inference and alumacc

How add, subtract and compare become shared ALU cells.

On this page

    What the tool looks for

    Two branches that cannot execute together may share hardware. The tool checks mutual exclusion first, then whether the operators are compatible.

    Addition, subtraction and comparison on the same operands are compatible. They all reduce to addition around one carry chain.

    Operation

    Shared implementation

    +

    One adder.

    -

    The same adder with an inverted subtrahend and carry-in 1.

    <

    The same subtract, keeping only the carry or sign decision.

    ==

    A bitwise compare. It merges only when it shares the operands, and the tool decides.

    A compare with one signed side is evaluated as signed. Mark both sides explicitly so the tool builds the intended comparator.

    The alumacc step

    The alumacc pass rewrites compatible arithmetic cells into ALU cells. Each source operation gets an ALU cell, and the standalone add and subtract disappear.

    The block below builds a two-way ALU. Its assertions pin one add and one subtract before the pass, and two ALU cells with no standalone add or subtract after it.

    yosys
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    read_verilog <<EOV
    module alu2(input [7:0] a, b, input sel, output [7:0] y);
    assign y = sel ? (a + b) : (a - b);
    endmodule
    EOV
    hierarchy -top alu2
    proc
    opt_clean
    select -assert-count 1 t:$add
    select -assert-count 1 t:$sub
    alumacc
    select -assert-count 2 t:$alu
    select -assert-count 0 t:$add
    select -assert-count 0 t:$sub
    stat -liberty course.lib
    log PASS: add and subtract become ALU cells

    Equality and ordering share the subtract

    Ordering needs only the carry out of a shared subtract. Equality needs only a zero detect on the same difference.

    Diagram
    4-bit unsigned example: a = 11 (1011), b = 6 (0110)
    bitwise NOT of b within 4 bits: 15 - 6 = 9 (1001)
    a - b as addition: 11 + 9 + 1 = 21; 21 - 16 = 5; check 11 - 6 = 5
    carry out is 1 because 21 >= 16, so a >= b holds
    a < b is false and a == b is false from the same subtract

    Common mistakes

    Common pitfall

    An unsigned comparison against a sign-extended value compares the extended pattern, not the original byte. Extend with the right rule before comparing, or the ordering flips on values with the top bit set.

    Interview

    Likely probes: what alumacc produces, and what must match for the rewrite.

    • A matched add/subtract pair becomes ALU cells; the standalone operators disappear.

    • Ordering and equality fold in when they share the same operands and decision bits.

    • Widths and signedness must match, or the tool keeps the original cells.

    Check yourself Before alumacc, what cells does the two-way ALU hold, and what remains after?

    One $add, one $sub and steering. After the pass, two $alu cells with no standalone $add or $sub.

    Check yourself Compare 8'hff against 8'h01 as unsigned and as signed. Do the results agree?

    No. Unsigned 255 < 1 is false, while signed -1 < 1 is true. The same bits order differently.

    Related topics

    • Sharing adders and the mux cost

    • Adders and Carry Structures

    • Arithmetic Blocks

    Previous

    81 / 139

    Next: Sharing Adders and the Mux Cost

    Up next

    Up nextSharing Adders and the Mux Cost

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • wreduce and Operator Widths
    • Constant Multipliers and Carry Tricks