Skip to content

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

Mixed_ngspice: FP32 Mixed-Precision Ngspice for Analog Sizing

Test

Mixed-precision ngspice-46 that accelerates BSIM4v5 device evaluation by reducing floating-point precision from FP64 to FP32 in struct storage and hot-path math, while keeping critical computations in FP64.

  • < 0.003% DC accuracy loss on TSMC/SMIC 0.18µm circuits (TT corner)
  • 1.7-2.8× transient speedup on multi-transistor op-amps
  • -45% working set (struct members halved from 8 to 4 bytes)
  • v1.2: Double-precision BSIM4 math — 40/40 tests PASS, 0 NaN across 15 circuits × 6 PDKs

Quick Start

# Prerequisites: gcc, make, autotools, libx11-dev, bison, flex
sudo apt-get install -y build-essential autoconf automake libtool bison flex libx11-dev

# Clone and build
git clone https://github.com/gravity-wh/Mixed_ngspice.git
cd Mixed_ngspice
bash scripts/build.sh

# Run tests
bash test/run_all.sh

The build produces two binaries:

  • build_fp32/src/ngspice — mixed-precision (FP32 storage + selective FP32 math)
  • build_fp64/src/ngspice — reference double-precision

How It Works

Layer v1.1 v1.2 Effect
Storage double → SPICE_REAL (= float) in 1337 struct members Same Working set -45%, better cache
Math Selective exp() → expf() in hot paths Reverted to exp() (double) NaN-free across all PDKs
Safety Double-precision islands for Vbseff, Leff/Weff All 6 FP64 islands restored Eliminates catastrophic cancellation
NaN Guard 40+ NaN detection + zeroing points Removed (not needed) Cleaner code, zero overhead

v1.2 strategy: FP32 storage + double-precision BSIM4 math functions. Double ops account for <10% of hot-path operations (<2% total runtime impact). This mirrors mixed-precision training in deep learning (FP16 gradients + FP32 accumulation).

Validation Coverage (2026-07-21 — v1.2)

Dataset Circuits FP32 PASS Pass Rate
PTM 45nm (open) 5 circuits 16/16 tests 100%
PTM 130nm (open) 🆕 3 circuits 12/12 tests 100%
PTM 180nm (open) 🆕 2 circuits 6/6 tests 100%
TSMC bc018 (commercial) 1 circuit 2/2 tests 100%
TSMC 180nm MOSIS (commercial) 🆕 1 circuit 4/4 tests 100%
Behavioral 1 circuit 1/1 test 100%
Total 15 circuits 40/40 100%

DC Precision

Circuit Metric FP32 FP64 Error
NMOS 45nm id 1.48189e-05 1.48189e-05 0.00007%
PMOS 45nm id 2.15147e-05 2.15147e-05 0%
OpAmp DC v(out) 1.098757 1.093652 0.47%
bc018 22T OpAmp v(out) 1.79993 1.79978 0.0083%

v1.1 → v1.2: What Changed

Metric v1.1 v1.2
bc018 NaN 54,120 0
Total test coverage 11 tests 40 tests
PDKs verified 2 6
BSIM families 1 (v5) 3 (v3+v5, Lv14/49/54)
NaN firewall needed Yes (40+ guards) No
FP64 islands 3 6 (restored)

TRAN Milestones

  • ✅ BGR startup (SKY130A, BJT+MOSFET)
  • ✅ OTA closed-loop step (PTM45, unity-gain buffer)
  • ✅ OpAmp closed-loop step (PTM45, 2-stage Miller, 100mV step)
  • ✅ Comparator clocked (PTM45, 1GHz/50ps edge)
  • ✅ Buck converter (SKY130A, PWM switching)
  • ✅ LDO load step (SKY130A, feedback network)

Supported Process Corners

Corner PTM 45nm SKY130A SMIC 180nm BCD
TT (Typical) ✅ Verified ✅ Verified ⚠️ NMOS only
FF (Fast-Fast) In progress Model available ⚠️
SS (Slow-Slow) In progress Model available ⚠️

Documentation

Repository Structure

Mixed_ngspice/
├── patches/          # 15 patches against vanilla ngspice-46
├── scripts/          # Build, batch validation, waveform comparison
├── test/
│   ├── circuits/     # 8 PTM45 test circuits (DC/AC/TRAN)
│   ├── circuits_tran/# T1-T5 custom TRAN testbenches
│   ├── models/       # PTM 45nm LP/HP (TT/FF/SS/FS/SF)
│   └── expected/     # FP64 baseline JSON
├── docs/             # Technical documentation & validation reports
└── .github/          # CI workflows

License

BSD 3-Clause License — same as ngspice.

References

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages