Skip to content

A new emap core emapMap.c - #613

Open
hfthra wants to merge 4 commits into
berkeley-abc:masterfrom
hfthra:master
Open

hfthra wants to merge 4 commits into
berkeley-abc:masterfrom
hfthra:master

Conversation

@hfthra

@hfthra hfthra commented Nov 17, 2026

Copy link
Copy Markdown

Priority cuts with cached matches. Area flow and exact area under a delay target. Exact area decision is timed incrementally and undone if an output misses the target. When liberty data available, cells timed with NLDM tables with loads. Original implementation runs with emap -O

…w and exact area under a delay target. Exact area decision is timed incrementally and undone if an output miises the target. When liberty data available, cells timed with NLDM tables with loads. Original implementation runs with emap -O

@alanminko alanminko left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of 6cf7e5d based on code inspection only; no builds or tests were run. I found four issues, detailed in the inline comments.

The PR does not identify the benchmarks used to evaluate the new mapper. Please share the benchmarks (or public download links and the exact case list), the Liberty/GENLIB libraries, and the command lines or scripts, including preprocessing, used to compare the new emap with emap -O. Per-benchmark area, delay, and runtime results, together with the ABC revision and machine details, would let us reproduce the runs.

Comment thread src/map/emap/module.make
SRC += src/map/emap/emap.c \
src/map/emap/emapCore.c
src/map/emap/emapCore.c \
src/map/emap/emapMap.c

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Add the new source to the Windows project as well.

emap.c now references Emap_ManMapNew, but abclib.dsp still lists only emap.c and emapCore.c for this module. Applications linking that library will have an unresolved symbol. Please add emapMap.c to the Windows source list.

Comment thread src/map/emap/emapMap.c
if ( pB->Type == EMP_INV )
Emp_LoadInc( p, 2 * i + !f, Emp_InvCin(p, pB->iMem), Emp_InvCinD(p, pB->iMem) );
else if ( pB->Type == EMP_WIRE )
Emp_LoadInc( p, 2 * pB->Leaves[0] + pB->Phases[0], p->pLoad[2 * i + f], p->pLoadD[2 * i + f] );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Account for inverter loads before propagating wire loads.

When phase 0 is EMP_WIRE and phase 1 is EMP_INV, this loop forwards the wire load first, then adds the inverter input capacitance to the already-processed wire phase. That capacitance never reaches the actual driver. Consequently, even full retiming can underestimate delay and incorrectly report that the -D target is met. Please accumulate the inverter loads before forwarding loads through wires.

Comment thread src/map/emap/emapMap.c Outdated
Flow = pFam->Area[m] + LeafFlow;
if ( fArea && pB->Type != EMP_NONE && Flow > pB->Flow + 0.0001 )
break;
Emp_CellArrival( p, pCell, pCutLeaves, Load, fLeafLoad, nMem == 1 ? -1 : m, &Cand );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Do not use family size to disable NLDM timing.

A cell family with one member makes nMem == 1 even when NLDM is enabled and gain mode is off. Passing iMem = -1 here selects load-independent timing, and the nMem > 1 condition below also skips the leaf-load check. Area-flow matching therefore uses inconsistent timing for single-size families. Select the approximation using fGainMode/fNldm independently of family size. The MOG area-flow path repeats this issue.

Comment thread src/map/emap/emapMap.c Outdated
SC_Cell * pCell;
int i;
p->pScl = p->pPars->fNldm ? (SC_Lib *)Abc_FrameReadLibScl() : NULL;
if ( p->pScl == NULL || Abc_SclCellFind(p->pScl, Mio_GateReadName(Mio_LibraryReadInv(p->pMio))) < 0 )

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Validate the inverter before initializing NLDM.

With Liberty data loaded and no inverter in the current GENLIB, Mio_LibraryReadInv returns NULL and Mio_GateReadName dereferences it here. The missing-inverter check in Emp_LibPrepare runs only after Emp_ManStartNldm, so the command can crash before reporting the error. Please check the inverter before this lookup or perform the library validation first.

@hfthra

hfthra commented Nov 20, 2026

Copy link
Copy Markdown
Author

New modifications were tested using EPFL benchmarks using sky130_fd_sc_hd__tt_025C_1v80 library. Resyn2 used as the preprocessing step. Delay and area recorded with 'stime' command. Runtime was recorded using 'time' command.
ABC version 1.01. Machine: 30Gb RAM, 22core, X86-64, Ubuntu 24.04.5LTS.

emap -O vs emap (sky130)

design emap -O_area emap -O_delay_ps emap -O_runtime_s new_emap_area new_emap_delay_ps new_emap_runtime_s
adder 2554.95 64307.70 4.65 4444.26 12559.24 3.18
bar 10089.68 1737.22 5.57 10022.11 1250.70 4.74
div 149542.17 582512.19 908.27 168477.83 309102.12 70.91
hyp 792662.69 3088511.25 3390.57 743833.38 2319142.00 340.52
log2 99623.05 55801.75 569.19 83675.25 37431.11 52.97
max 9643.00 46403.24 24.66 9435.30 12544.70 8.48
multiplier 70038.42 55748.73 303.93 71033.12 20284.24 45.82
sin 18173.68 31690.11 70.10 15939.04 18033.41 8.19
sqrt 72528.31 811231.56 319.76 75894.04 495303.53 60.81
square 55511.99 39106.11 108.66 54795.05 14871.08 20.53
arbiter 32083.27 9369.34 341.37 39412.80 4948.44 107.14
cavlc 2040.71 1614.94 4.08 2307.21 823.11 1.95
ctrl 380.36 677.89 2.41 459.19 374.10 0.56
dec 1273.72 831.24 5.98 1328.77 552.68 0.42
i2c 3777.37 1594.96 8.33 4157.74 877.09 1.06
int2float 653.13 1051.71 3.13 710.68 712.46 0.85
mem_ctrl 138410.25 17820.35 322.27 130779.17 9978.83 53.31
priority 2412.31 14695.46 7.11 2964.09 12382.12 1.17
router 595.57 1836.67 4.48 643.12 998.77 0.67
voter 35007.32 8159.23 46.11 33937.55 5093.21 25.26

@hfthra

hfthra commented Nov 20, 2026

Copy link
Copy Markdown
Author

emap -O vs emap -D <delay from emap -O> (sky130)

design orig_area orig_delay_ps orig_time_s new_area new_delay_ps new_time_s
adder 2554.95 64307.70 4.84 2554.95 54053.40 0.71
bar 10089.68 1737.22 5.61 9939.53 1729.92 5.22
div 149542.17 582512.19 1011.52 131939.03 611793.81 81.64
hyp 792662.69 3088511.25 3449.14 746845.00 3068254.50 819.96
log2 99623.05 55801.75 522.46 80978.91 61831.32 56.12
max 9643.00 46403.24 25.29 8999.88 34324.21 6.59
multiplier 70038.42 55748.73 293.59 65402.73 56727.66 24.55
sin 18173.68 31690.11 70.55 15358.48 27589.85 8.70
sqrt 72528.31 811231.56 308.99 63887.52 811093.88 50.39
square 55511.99 39106.11 104.49 52266.38 44196.92 16.85
arbiter 32083.27 9369.34 345.74 32242.17 6892.31 15.52
cavlc 2040.71 1614.94 5.37 1891.81 1519.19 0.48
ctrl 380.36 677.89 2.24 357.84 663.52 0.24
dec 1273.72 831.24 6.99 1166.12 665.32 0.22
i2c 3777.37 1594.96 6.28 3542.15 1466.84 0.94
int2float 653.13 1051.71 2.69 643.12 937.45 0.33
mem_ctrl 138410.25 17820.35 312.44 130288.70 17617.45 54.26
priority 2412.31 14695.46 8.02 2443.59 14294.83 0.55
router 595.57 1836.67 5.16 529.26 1680.75 0.28
voter 35007.32 8159.23 42.69 26118.80 8759.99 9.00

Resyn2 used as the preprocessing step. Delay and area recorded with 'stime' command. Runtime was recorded using 'time' command.
ABC version 1.01. Machine: 30Gb RAM, 22core, X86-64, Ubuntu 24.04.5LTS.

@alanminko

Copy link
Copy Markdown
Contributor

Thank you very much for addressing the four points from the earlier review. I found three more correctness issues and three minor issues with timing, export, and area recovery.

  1. [P1] A two-output cell can produce incorrect Verilog. The matcher applies the same pin permutation to both outputs. GENLIB can list the physical inputs as (A, B) for one output and (B, A) for the other. The Verilog writer connects the instance using the first output’s pin names, so an asymmetric second output can compute the wrong function. I’d match the inputs by pin name or reject pairs whose pin orders differ. Matcher · Verilog writer

  2. [P1] emap accepts sequential AIGs and can discard their latches. The builder copies only primary inputs and outputs. A primary output driven by a latch fails to map. If the primary outputs depend only on primary inputs, mapping can succeed and replace the original network with one that has lost all its state. The smallest fix is to reject sequential networks at command entry. Command entry · Network builder

  3. [P1] A mappable circuit can abort ABC in an assertion-enabled build. Consider a two-input XOR and a library containing INV and XOR2. The root maps directly to XOR2, but the mapper first visits the ANDs in the XOR decomposition and asserts when the first AND has no match. An internal node should be allowed to remain unmatched if a larger cut covers it. Traversal · Assertion

  4. [P2] emap -D and stime can disagree on the same mapped network. I found two concrete differences. For a cell with both outputs used, emap correctly charges each physical input capacitance once. stime charges it once per output node. Also, emap initializes primary inputs with zero arrival and slew, while stime applies the load-dependent delay and slew from set_driving_cell. Either difference can affect whether a path meets its target. Mapper loads · stime loads · Mapper inputs · stime input driver

  5. [P2] Using only one output of a two-output cell breaks write_edgelist. The latest commit emits a single node for this case. The writer prints the inputs and output, then returns when it cannot find the twin, leaving the cell name and truth table out of the record. Builder change · Edge-list writer

  6. [P2] emap -F 0 -A 4 stops the first exact-area stage after one round. With zero area-flow rounds, the mapper passes zero as the starting area. The first positive area then satisfies the stopping condition even if that round substantially improved the cover. Initializing the comparison from the actual cover area would fix it. Initial area · Stopping condition

For the benchmark results, I’d ask to confirm equivalence against the exported netlist.

…in ioWriteEdgelist.c, reject sequential networks:Emap_Command in emap.c, adding Emp_ManReplaceLoneMogs to replace one output used two-output cells with single output cells if possible, and modifications in emapMap.c based on review comments
@hfthra

hfthra commented Nov 25, 2026 •

Copy link
Copy Markdown
Author

Thanks for the review comments.
As before, EPFL benchmark designs were used with sky130_fd_sc_hd__tt_025C_1v80 library. Resyn2 used as the preprocessing step. Delay and area recorded with 'stime' command as well as OpenSTA using the exported verilog.
Did not correct the issue mentioned in the point 4 related to stime in this PR.
Runtime was recorded using 'time' command.
Equivalence is done with exported verilogs against initial designs and all were CEC equivalent.

emap -O vs emap

design (emap -O)_area (emap -O)_delay_ps (emap -O)_runtime_s (emap)_area (emap)_delay_ps (emap)_runtime_s (emap -O)_sta_area (emap -O)_sta_delay_ps (emap)_sta_area (emap)_sta_delay_ps
adder 2554.95 64307.70 5.67 4444.26 12559.24 2.59 2554.950273 57803.425000 4444.262400 12559.249000
bar 10089.68 1737.22 7.16 10022.11 1250.70 7.00 10089.677184 1736.741000 10022.112061 1249.681000
div 149542.17 582512.19 975.81 168477.83 309102.12 70.13 149542.172473 568419.128000 168477.833493 309284.576000
hyp 792662.69 3088511.25 3492.11 743833.38 2319142.00 344.11 792662.724270 3185148.193000 743833.387859 2314206.543000
log2 99623.05 55801.75 635.05 83630.20 37431.11 52.70 99623.046637 54381.481000 83630.207535 35971.237000
max 9643.00 46403.24 43.59 9435.30 12544.70 9.25 9642.998400 44192.123000 9435.299201 12670.059000
multiplier 70038.42 55748.73 340.93 71033.12 20284.24 46.95 70038.420603 48905.373000 71033.126040 19201.359000
sin 18173.68 31690.11 112.57 15939.04 18033.41 8.36 18173.679983 29788.614000 15939.036759 17522.987000
sqrt 72528.31 811231.56 365.11 75894.04 495303.53 79.74 72528.310400 810298.157000 75894.038394 495226.288000
square 55511.99 39106.11 146.90 54795.05 14871.08 20.39 55515.743410 35600.437000 54798.805759 14749.257000
arbiter 32083.27 9369.34 371.65 39412.80 4948.44 125.67 32083.270400 9369.336000 39412.799864 4947.709000
cavlc 2040.71 1614.94 6.47 2307.21 823.11 2.05 2040.707200 1498.183000 2307.212799 823.109000
ctrl 380.36 677.89 2.51 459.19 374.10 0.75 380.364800 677.892000 459.190400 374.105000
dec 1273.72 831.24 10.17 1328.77 552.68 0.95 1273.721600 831.073000 1328.774400 552.676000
i2c 3777.37 1594.96 9.80 4157.74 877.09 2.50 3829.923208 1594.956000 4210.288003 876.484000
int2float 653.13 1051.71 3.40 710.68 712.46 1.17 653.126400 1051.712000 710.681600 712.462000
mem_ctrl 138410.25 17820.35 399.37 130779.17 9978.83 65.28 139288.588846 17820.343000 131657.520010 9978.827000
priority 2412.31 14695.46 13.03 2964.09 12382.12 2.27 2412.313600 14695.458000 2964.092800 12382.123000
router 595.57 1836.67 6.72 643.12 998.77 1.05 595.571200 1836.671000 643.116800 998.765000
voter 35007.32 8159.23 59.74 33900.01 5093.21 22.32 35007.324729 7713.898000 33900.012667 4845.577000

emap -O vs emap -D <delay from emap -O as the target>

design (emap -O)_area (emap -O)_delay_ps (emap -O)_runtime_s (emap -D)_area (emap -D)_delay_ps (emap -D)_runtime_s (emap -O)_sta_area (emap -O)_sta_delay_ps (emap -D)_sta_area (emap -D)_sta_delay_ps
adder 2554.95 64307.70 4.74 2554.95 54053.40 0.75 2554.950273 57803.425000 2554.950273 48475.281000
bar 10089.68 1737.22 5.78 9939.53 1729.92 5.00 10089.677184 1736.741000 9939.532862 1729.316000
div 149542.17 582512.19 872.19 131688.80 600329.44 75.02 149542.172473 568419.128000 131688.798836 560983.093000
hyp 792662.69 3088511.25 3315.36 757132.38 3176172.00 631.93 792662.724270 3185148.193000 757132.397054 3180505.371000
log2 99623.05 55801.75 509.66 81087.77 59911.44 69.32 99623.046637 54381.481000 81087.768459 54148.476000
max 9643.00 46403.24 33.92 9306.43 42255.80 7.59 9642.998400 44192.123000 9306.425600 41158.699000
multiplier 70038.42 55748.73 276.07 65596.66 53887.75 28.02 70038.420603 48905.373000 65596.661200 48768.322000
sin 18173.68 31690.11 65.83 15506.12 27857.77 6.06 18173.679983 29788.614000 15506.121444 25405.569000
sqrt 72528.31 811231.56 309.13 63967.60 809697.25 58.65 72528.310400 810298.157000 63967.600000 810472.717000
square 55511.99 39106.11 107.68 52331.44 40659.12 28.21 55515.743410 35600.437000 52335.192540 35495.724000
arbiter 32083.27 9369.34 303.25 32242.17 6892.31 21.69 32083.270400 9369.336000 32242.172800 6892.095000
cavlc 2040.71 1614.94 4.19 2099.51 1036.06 0.65 2040.707200 1498.183000 2099.513592 1036.061000
ctrl 380.36 677.89 2.47 357.84 663.52 0.19 380.364800 677.892000 357.843200 663.519000
dec 1273.72 831.24 7.04 1166.12 665.32 0.33 1273.721600 831.073000 1166.118400 665.322000
i2c 3777.37 1594.96 7.56 3542.15 1466.84 1.22 3829.923208 1594.956000 3594.697600 1466.843000
int2float 653.13 1051.71 3.30 643.12 937.45 0.39 653.126400 1051.712000 643.116800 937.451000
mem_ctrl 138410.25 17820.35 315.20 130288.70 17617.45 59.15 139288.588846 17820.343000 131167.049613 17617.445000
priority 2412.31 14695.46 7.47 2443.59 14294.83 0.79 2412.313600 14695.458000 2443.593600 14294.832000
router 595.57 1836.67 4.77 529.26 1680.75 0.61 595.571200 1836.671000 529.257600 1680.750000
voter 35007.32 8159.23 44.53 26150.08 8427.76 15.03 35007.324729 7713.898000 26150.079189 7806.835000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants