Commit Graph

86 Commits

Author SHA1 Message Date
R. Timothy Edwards d3a0228958 Added a new device type "dsubcircuit" which basically behaves like
"csubcircuit" but swaps the first two pins (with the device
identifier layer becoming the 2nd pin and the other terminal the
first), which is needed for n-type diodes modeled as subcircuits
where the subcircuit pin order matches the order of pins for a
SPICE n-type diode component.  Previously "msubcircuit" was used
for this purpose, but will calculate the wrong L and W.  While
use of L and W for diodes is rare, this device type also works for
reversed capacitors (where the bottom or non-identifying layer
terminal is in the first pin position of the subcircuit).
2025-10-07 16:45:22 -04:00
R. Timothy Edwards 3631892cfa One more minor change to the behavior just implemented: A value
for a resistor or capacitor is optional but is valid SPICE and not
just limited to CDL format, so it is now allowed to add "r=" at
the end of a resistor or capacitor component (not subcircuit) to
generate the optional component value.
2025-10-06 20:37:30 -04:00
R. Timothy Edwards 8c323803b7 Additional modification to write out a resistor or capacitor value
as-is, without a parameter name and before any device model name or
substrate pin, according to CDL syntax, if the parameter has been
specified without a parameter name (e.g., "r=" instead of "r=r").
Corrected an error in the extract code which put the substrate node
name in front of parameters instead of after.  This was previously
unexercised because only in CDL format does a resistor or capacitor
model have parameters listed by name.
2025-10-06 17:42:34 -04:00
R. Timothy Edwards acdfb256a1 Made a change to CDL format output to place the substrate parameter
in front of the device name, which is a very inconsistent way to
make the syntax, but whatever.
2025-10-06 16:40:19 -04:00
R. Timothy Edwards 5e74ecf9fa Added code to avoid a segfault if a resistor or capacitor is
specified without a list of substrate connection types, but
the "s=" parameter is used, resulting in an attempt to access a
substrate node that does not exist.
2025-10-06 14:14:05 -04:00
R. Timothy Edwards 78f7d22796 A number of changes:
1) Corrected spurious error messages about cells already existing
   in GDS when using "flatten" or "flatglob".
2) Fixed handling of resistance as a subcircuit parameter
3) Added area and perimeter resistance for a device;  this is done
   through the "devresist" statement in the tech file, which is an
   extension of the original "fetresist" statement.  Where "fetresist"
   only supported type "linear", "devresist" supports types "area"
   and "perimeter".
4) Support for CDL syntax, including generating subcircuit-like
   parameters for components starting with SPICE-standard prefixes
   like M, R, C, etc., adding "/" between pins and subcircuit name,
   and saving the file as ".cdl" instead of ".spice".
5) Estimated L and W for devices whose geometry is complex and do not
   reduce to a simple rectangle.  L and W are estimated as the square
   root of the area.
6) Changed the method of extracting L and W for diodes to use the same
   method as capacitors.  Note that diodes are not usually specified
   by L and W, but if they are, this will produce the right result.
7) Corrected the reported filename and line number when printing error
   messages related to errors inside a technology file, when the
   technology file uses "include" to combine multiple files.
2025-10-01 15:17:49 -04:00
R. Timothy Edwards b4912fd550 Updated the version to go along with the merge of pull request
version 8.3.521 that, due to an argument size mismatch, causes
device parameters in netlist output to be printed as zero.
Also added a small extension to the list of extraction types
to include "device veriloga", which has the same syntax as
"device subcircuit" but generates a component type "N"
(Verilog-A component) in the netlist output.
2025-08-07 11:54:49 -04:00
Darryl L. Miles c6fe62f64a ext2spice.c: cleanup unused localvars -Wunused-variable -Wunused-but-set-variable 2025-08-06 22:58:30 +01:00
Darryl L. Miles ab24761d88 ext2hier.c: cleanup unused localvars -Wunused-variable -Wunused-but-set-variable 2025-08-06 22:58:30 +01:00
Darryl L. Miles 420a24ef33 extflat: integrate cb_extflat_hiervisitresists_t for EFHierVisitResists()
Additionally the HierName's hierName1 and hierName2 arguments have been
made 'const' to help convey the receiver can not modify the referenced
data passed.
2025-08-06 22:58:30 +01:00
Darryl L. Miles 6bbcd65c5f extflat: integrate cb_extflat_hiervisitdevs_t for EFHierVisitDevs() 2025-08-06 22:58:30 +01:00
Darryl L. Miles 301a5329db extflat: nodeSpiceHierName() constify API 2025-08-06 22:58:30 +01:00
Darryl L. Miles d78d7eddfd extflat: nodeSpiceName() consumer 2025-08-06 22:58:30 +01:00
Darryl L. Miles 7ab4911514 Revert "Added a type cast in ext2spice/ext2hier.c to avoid having the"
This reverts commit a3d02d92cc.
2025-08-06 10:42:55 -04:00
R. Timothy Edwards a3d02d92cc Added a type cast in ext2spice/ext2hier.c to avoid having the
compiler complain about a "const" variable passed to a routine
not declaring "const".
2025-08-04 16:38:41 -04:00
Darryl L. Miles 189c9f2452 ext2spice: forward declaration arguments or removal
Remove unnecessary forward declaration:
 extHierSDAttr() as ext2spice.h has prototype
2025-07-27 12:52:12 -04:00
Darryl L. Miles df6bc6bc51 ext2spice: use 'const' with 'rcsid' 2025-07-27 12:52:12 -04:00
Darryl L. Miles 828cec7bca K&R ext2spice/*.c: bulk function implementation conversion
int spcnAP() follows K&R param ordering
int spcnAPHier() follows K&R param ordering

TODO mergeAttr() sharing references (does this setup a future potential
use-after-free concern?)
2025-07-27 12:52:12 -04:00
Darryl L. Miles 0badf814c5 extraction: constify struct devMerge.next, devMergeList
Feel free to undo variables as necessary in the future as requirements change.
2025-07-27 12:49:54 -04:00
Darryl Miles 8c28342322 ext2hier.c: printf style constify fmt call-site 2025-01-03 09:08:14 +00:00
Tim Edwards 0a67151292 Extended the device parameters to allow a terminal width that is
different from the device (i.e., gate) width, for devices that do
not define a MOS-like gate spanning the width of the device.  This
is restricted to the assumption that the terminal is rectangular
and therefore a simple width and length can be derived from the
area and perimeter.  Also, length is defined as the smaller
dimension and width as the larger dimension.  For additional
restrictions, see the updated documentation.  This was added to
allow correct width and length extraction of a bipolar emitter
window, but may be more generally useful.
2024-12-06 16:42:43 -05:00
Darryl L. Miles be09edb8d8 12 x warning: suggest parentheses around '&&' within '||'
The '&' has higher precedence, so the expression of the '&' side receive
extra parentheses.

ResMakeRes.c:671:37: warning: suggest parentheses around '&&' within '||'
ResMakeRes.c:942:32: warning: suggest parentheses around '&&' within '||'
ResSimple.c:201:70: warning: suggest parentheses around '&&' within '||'
ResRex.c:1036:28: warning: suggest parentheses around '&&' within '||'
ResRex.c:1038:50: warning: suggest parentheses around '&&' within '||'
ext2sim.c:1341:47: warning: suggest parentheses around '&&' within '||'
ext2spice.c:172:44: warning: suggest parentheses around '&&' within '||'
ext2spice.c:173:49: warning: suggest parentheses around '&&' within '||'
ext2spice.c:3655:50: warning: suggest parentheses around '&&' within '||'
ext2hier.c:1412:50: warning: suggest parentheses around '&&' within '||'
gcrDebug.c:638:55: warning: suggest parentheses around '&&' within '||'
selEnum.c:323:28: warning: suggest parentheses around '&&' within '||'

GCC14 -Wall cleanup series [-Wparentheses]
2024-10-09 21:12:55 -04:00
Tim Edwards a3b61abe2b Corrected an error in which "extract unique noports" and
"extract unique notopports" both fail to work correctly because
an attempt some time ago to avoid issuing warnings about shorted
port names when using those options was changed in the wrong
line.
2024-10-07 11:48:27 -04:00
Tim Edwards 6162a9f459 Corrected the "bloat-all" function so that it behaves properly on
angled edges.  This is a rare case and so has never come up before,
but can happen especially on transistors with gate or diffusion
with 45 degree chamfers or flanges.  Thanks to Mark Martin for
providing the use case.
2024-10-03 20:37:43 -04:00
Darryl L. Miles 290887912f ext2spice/ext2hier.c: Wrong type of arguments to formatting function
Applied the same fixes as other commits already merged into file.

Copilot Autofix: Error contact support...

CodeQL: https://github.com/dlmiles/magic/security/code-scanning/38
        https://github.com/dlmiles/magic/security/code-scanning/39
        https://github.com/dlmiles/magic/security/code-scanning/41
2024-10-01 12:36:13 -04:00
Darryl Miles 9327388ae0 ext2spice/ext2hier.c: Multiplication result converted to larger type
Fix code scanning alert no. 42: Multiplication result converted to larger type (#65)

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
2024-10-01 12:36:13 -04:00
Darryl Miles 147ca7a61f ext2spice/ext2hier.c: Multiplication result converted to larger type
Fix code scanning alert no. 40: Multiplication result converted to larger type (#64)

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
2024-10-01 12:36:13 -04:00
Darryl Miles 86a6551f9b ext2spice/ext2hier.c: Multiplication result converted to larger type
Fix code scanning alert no. 37: Multiplication result converted to larger type (#58)

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
2024-10-01 12:36:13 -04:00
Darryl Miles 82bec60ccf ext2spice/ext2hier.c: Multiplication result converted to larger type
Fix code scanning alert no. 36: Multiplication result converted to larger type (#57)

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
2024-10-01 12:36:13 -04:00
Tim Edwards 07267dc126 Extended the device parameter notation to include offsets using
'+' and '-' in the same way that '*' is currently used for specifying
a parameter scaling.  The combination of a scale and offset for the
same parameter has not (yet) been implemented.
2023-06-21 20:44:38 -04:00
Tim Edwards 666c3c2c97 Corrected an issue in which the device merging routine can generate
NaN results for devices which are not FETs (specifically, devices
that are declared using "msubckt" but are not FETs, although there
may have been a related issue with non-FET devices not getting the
correct M count), due to the device having zero measured width or
length.  NOTE:  This may need more investigation.  If a subcircuit
device's method of merging cannot be understood, then such devices
should never extract with "merge aggressive", and should always
merge conservatively if and only if all parameters match.
2023-05-21 12:13:01 -04:00
Tim Edwards a2687d4385 Corrected an issue from the last commit, which is that the default
ground node name (which is static) gets put on the node list and
is improperly deallocated.  Corrected by simply allocating the
string for the default substrate node instead of using the static
string.
2023-03-14 12:53:22 -04:00
Tim Edwards a3f5f4db80 Changed the behavior of capacitance value output in ext2spice
and ext2sim to make use of the new esSIvalue() routine, so that
it no longer depends on a preformatted string.  Corrected an
issue where the esSIvalue() routine would output "a" for "atto"
which is not supported by ngspice.
2023-03-13 13:21:34 -04:00
Tim Edwards 0058000c22 Corrected "ext2spice" to mark nodes on resistors from "extresist"
so that they do not get marked as "FLOATING" nodes when writing out
the parasitic capacitances at the end.
2023-02-28 13:11:32 -05:00
Tim Edwards eb36edf35a Corrected the ext2spice device output for device length, which
somehow acquired a typo which made it write "w=".  Resolves
issue #223 from Mitch Bailey.
2023-02-28 09:34:25 -05:00
Tim Edwards c7f11d2169 Important update: Reworked the extraction method to properly
isolate the terminal areas of a device (e.g., source and drain)
and calculate their area and perimeter individually for the
device (in addition to the traditional method of calculating
area and perimeter of each resistance class for the entire node).

Also:  Reworked the SPICE syntax output to generate SI values
in the range 1-1000 with the appropriate suffix (e.g., "20u")
instead of defaulting to "u" for lengths and "p" for areas.
This prevents it from producing weird units like "150000u" when
a process definition already includes a scalefactor.

Reworked the "extresist" code to use the device terminal area
and perimeter.  This fixes an error in which "extresist" would
lose these values and "ext2spice" with option "extresist on"
would generate a new netlist output with zero terminal areas
and perimeters.
2023-02-16 11:59:13 -05:00
Tim Edwards 677cd8ab5e Implemented simple drain and source length calculations as device
parameters l1 and l2.  Provides a way to pass the source or drain
length as a parameter for, for example, an extended FET drain
implemented as a resistor abutting the FET gate.  Could potentially
be used as a way to determine source/drain area and perimeter
without resorting to measurements of a shared node.
2022-12-14 21:40:24 -05:00
Tim Edwards 65ef9a1ad3 Final (I hope!) corrections to the "def write" command. 2022-11-19 22:02:44 -05:00
Tim Edwards 16da74a2f9 Implemented a method in EFBuildNode() to capture nodes which are
redundant (same name, different net).  Previously, the method was
to keep the first such node and ignore all others except to add
their resistance and capacitance to the original node.  This
prevented routines like "def write" from enumerating all nets
unless they had unique names.  The new method keeps the additional
records including the node location where they can be found by
EFNodeVisit(), but flags them with EF_UNIQUE_NODE so that routines
like ext2spice or ext2sim can choose to ignore them.  This implies
that this method could be used to reimplement "extract unique"
within "ext2spice" or "ext2sim" without altering label text.  This
has not yet been implemented.
2022-11-18 21:44:06 -05:00
Alessandro De Laurenzis b306a39560 Compatibility with C99 standard
This commit makes the code (mostly) C99-compatible, enabling to compile
it without the -Wno-error=implicit-function-declaration flag. This
way, Magic becomes usable on arm64 architectures, specifically on Apple
computers with M1/M2 SoC.
2022-10-29 06:07:46 +02:00
Tim Edwards 2b7b12d34c Added a catch for a node named "(none)" in a merge line. This
prevents magic from crashing but does not do anything about the
fact that a non-existent node ended up in the .ext file, which
will have to be investigated.
2022-06-16 19:54:21 -04:00
Tim Edwards 468a8ae0be Added a 2nd use of the "device" property, which has long been needed,
which instead of defining a device or subcircuit that exists inside
the cell, instead redefines the cell itself as a device or subcircuit
model that exists in the PDK.  This is used where a specific layout
subcell has its own associated device definition in the PDK.  Instead
of the "device" property value being the line that gets generated for
a device in the subcells .ext file, the property value should be the
word "primitive" optionally followed by any parameters that need to
be passed to the subcircuit call.
2022-05-04 16:43:38 -04:00
Tim Edwards b1b986cbe4 Added a procedure to esMakePorts() in ext2hier.c which tracks the
EF_SUBS_PORT flags up the hierarchy.  This is a rather lot of code
needed to make substrate connections to circuits where the substrate
connects to devices but not make such connections where the substrate
doesn't.  There may be simpler ways to accomplish the same thing,
depending on whether the order of "merge" statements in a .ext file
is reliable;  this code does not depend on it.
2022-02-25 20:59:59 -05:00
Tim Edwards 6ecd077ab4 Restored compiling of the non-Tcl/Tk version of magic. This has
traditionally been kept for backwards compatibility.  However, the
operation of "ext2spice" and "ext2sim" as separate programs has
become extremely difficult to maintain, and so it has been dropped
in favor of folding both into the program as commands, as was done
a long time ago in the Tcl/Tk version.
2022-02-08 16:12:07 -05:00
Tim Edwards 91b00a633f (1) Modified the method used for the previous commit, as it was
found to make ext2spice runtimes very long for large layouts.
The new method is equivalent but doesn't incur the overhead.
Also:  Changed a flag check which was causing the substrate node
to be output as a port for certain layouts where the substrate
node connects to no devices, and so should be optimized out.
2022-01-13 17:00:07 -05:00
Tim Edwards 9a17539ca7 Corrected the use of EF_SUBS_NODE to distinguish between device
substrate (bulk terminal) and global substrate.  Otherwise, the
routine in ext2hier.c that finds the substrate node will find the
first device bulk connection, not the default substrate.
2021-12-30 13:27:42 -05:00
Tim Edwards 5e3c26c95a Tracked down two more memory leaks coming from ext2spice, due to
client data generated by ext2spice and attached to a node's
nodeClient record;  there is an initNodeClient() routine but no
corresponding freeNodeClient() routine.  Eventually had to add a
callback function passed to EFDone() and EFFlatDone() to clean up
these entries.  After doing that, valgrind reports clean for all
memory allocated within ext2spice (there are other things that are
not freed but not related to a specific command, so do not need to
be treated as leaks).
2021-12-13 18:05:53 -05:00
Tim Edwards 43bb499bcf Corrected an issue with the limited bitfield dedicated to port numbers;
this limited ports to 16384, which seemed reasonable at the time.
However, the sky130_sram_macro layouts connect power and ground in a
way that when coupled with "extract unique" can generate tens of
thousands of ports and overrun the bit field, showing that automation
can do the unexpected.  The solution was to split out the port number
from the label record as its own 32-bit value.
2021-12-12 22:09:31 -05:00
Tim Edwards 15f081b4da Made a change to ext2hier.c that should prevent the propagation of
substrate nodes in subcircuits that don't make connections to the
substrate (such as arrays of pFETs).  This is done under the
restriction that ext2spice is being called without generating
parasitics (otherwise the connection to substrate is valid), as it
would be when extracting for LVS.  The ground node must not appear
as a connection to any device.  This is then propagated up the
hierarchy such that if none of a subcell's descendents connect to
the substrate, then neither does the subcell.
2021-10-05 20:34:22 -04:00
Tim Edwards 6136d3ff0f Implemented a command option "ext2spice short voltage|resistor|none" that
implements a method for handling ports in a subcircuit that have different
port names and indexes but are shorted together.  "none" is the default
and backwards-compatible behavior that merges ports together, which will
often cause one of the ports to be optimized out of the netlist.  "resistor"
will separate the port names with a 0-ohm ideal resistor.  "voltage" will
separate the port names with a 0-volt voltage source.  This should work
well for simulation and potentially for LVS, although its impact on LVS
has not been fully investigated.
2021-07-10 21:13:24 -04:00