From 292f7ad60a26627d442e8bec980a57fcc6ea2b77 Mon Sep 17 00:00:00 2001 From: Brian Taylor Date: Thu, 28 Mar 2024 15:11:38 -0700 Subject: [PATCH] Fix bug in the LOGICEXP scan_gates optimizer. Some gates with an inverting output were generated with bad logic which gave incorrect simulation results. --- src/frontend/logicexp.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/frontend/logicexp.c b/src/frontend/logicexp.c index 3d3df6ea9..8d2ccad37 100644 --- a/src/frontend/logicexp.c +++ b/src/frontend/logicexp.c @@ -22,6 +22,7 @@ #include "ngspice/dstring.h" #include "ngspice/logicexp.h" #include "ngspice/udevices.h" +#include "ngspice/cpextern.h" static char *get_pindly_instance_name(void); static char *get_inst_name(void); @@ -573,6 +574,21 @@ static void scan_gates(DSTRING *lhs) { struct gate_data *current = NULL, *previous = NULL, *last_curr = NULL; struct gate_data *prev = NULL; + int ps_scan_gates_noopt = 0; + + if (!cp_getvar("ps_scan_gates_noopt", CP_NUM, &ps_scan_gates_noopt, 0)) { + ps_scan_gates_noopt = 0; + } + if (ps_scan_gates_noopt) { + current = last_gate; + if (ds_get_length(lhs) > 0) { + assert(current->finished == FALSE); + tfree(current->outp); + current->outp = TMALLOC(char, ds_get_length(lhs) + 1); + strcpy(current->outp, ds_get_buf(lhs)); + } + return; + } current = first_gate; while (current) {