Introduction
GDSII Stream is the long-standing exchange format for integrated circuit layouts: a library of
named structures, usually called cells, holding polygons, paths, text and references to other
structures, each shape on a numbered layer. It comes from the GDS II design system of Calma
Company, which described it in the GDSII Stream Format Manual (Release 6.0,
February 1987, is described here). Files use the extensions .gds and
.gdsii. Layout editors and chip manufacturing flows still read and write it.
Records
A file is a sequence of records with no gaps. Numbers are big-endian. Every record begins with four bytes, and its length is always even. The manual numbers the bits of a word from 0, the most significant, to 15; this page does the same.
| Bytes | Content |
|---|---|
| 0–1 | Length of the whole record in bytes, including these four; at least 4. |
| 2 | Record type. |
| 3 | Data type of the rest of the record. |
| 4 onwards | Data: any number of values of that type. |
On magnetic tape the stream was cut into blocks of 2,048 bytes, records running across block
boundaries. After the last record of the library the block is filled with zero words, so a file
copied from tape can end in zero bytes after ENDLIB.
| Data type | Meaning |
|---|---|
| 0 | No data. |
| 1 | Bit array: 16 flags in one word. |
| 2 | Two-byte signed integer, two’s complement. |
| 3 | Four-byte signed integer, two’s complement. |
| 4 | Four-byte real; no record uses it. |
| 5 | Eight-byte real. |
| 6 | ASCII string. A string of odd length is padded with one NUL byte, which the length counts and a reader removes. |
Reals
The reals are not IEEE floating point. Bit 0 is the sign, bits 1–7 hold a power of 16 with 64 added, and the remaining bits (24 or 56) are a positive fraction with the binary point at its left. The value is the fraction × 16exponent − 64, negated if the sign bit is set. A normalised number has a fraction of at least 1/16 and below 1, so its first hexadecimal digit is not zero, though its first one to three bits may be. Zero is all bits zero. A negative number differs from the positive one only in the sign bit. An eight-byte real is a four-byte real with 32 more bits of fraction.
| First four bytes (hex) | Value |
|---|---|
41 10 00 00 | 1 |
41 20 00 00 | 2 |
C1 10 00 00 | −1 |
40 80 00 00 | 0.5 |
41 18 00 00 | 1.5 |
42 64 00 00 | 100 |
Structure
The manual gives the order of records as follows. Square brackets mark an optional item,
braces a group, * zero or more and + one or more.
stream = HEADER BGNLIB [LIBDIRSIZE] [SRFNAME] [LIBSECUR] LIBNAME
[REFLIBS] [FONTS] [ATTRTABLE] [GENERATIONS] [format]
UNITS {structure}* ENDLIB
format = FORMAT | FORMAT {MASK}+ ENDMASKS
structure = BGNSTR STRNAME [STRCLASS] {element}* ENDSTR
element = {boundary | path | sref | aref | text | node | box}
{PROPATTR PROPVALUE}* ENDEL
boundary = BOUNDARY [ELFLAGS] [PLEX] LAYER DATATYPE XY
path = PATH [ELFLAGS] [PLEX] LAYER DATATYPE
[PATHTYPE] [WIDTH] [BGNEXTN] [ENDEXTN] XY
sref = SREF [ELFLAGS] [PLEX] SNAME [strans] XY
aref = AREF [ELFLAGS] [PLEX] SNAME [strans] COLROW XY
text = TEXT [ELFLAGS] [PLEX] LAYER TEXTTYPE [PRESENTATION]
[PATHTYPE] [WIDTH] [strans] XY STRING
node = NODE [ELFLAGS] [PLEX] LAYER NODETYPE XY
box = BOX [ELFLAGS] [PLEX] LAYER BOXTYPE XY
strans = STRANS [MAG] [ANGLE]
References name their structure in SNAME. The syntax does not require a structure
to come before the references to it, so a reader should resolve names after reading the whole
library.
Library records
The code is the record type and data type together, in hexadecimal.
| Code | Record | Content |
|---|---|---|
0002 | HEADER | Version: 0 before Release 3.0, then 3, 4 and 5 for Releases 3.0, 4.0 and 5.0, and 600 for Release 6.0. |
0102 | BGNLIB | Twelve integers: year, month, day, hour, minute and second of the last modification, then of the last access. |
3902 | LIBDIRSIZE | Number of pages in the library directory, used when importing into a new Calma library. |
3A06 | SRFNAME | Name of the sticks rules file bound to the library. |
3B02 | LIBSECUR | Access control list: 1 to 32 entries of group number, user number and access rights, three integers each. |
0206 | LIBNAME | Library name, following the file name rules of Calma’s system; it may include an extension, usually .DB. |
1F06 | REFLIBS | Names of the reference libraries, required if any are bound: fixed fields of 44 bytes, an unused one filled with NULs. : separates directory and file, . precedes the extension. |
2006 | FONTS | Four 44-byte NUL-padded names of the definition files of text fonts 0 to 3; present only if a font has one. |
2306 | ATTRTABLE | Name of the attribute definition file, if one is bound; at most 44 bytes. |
2202 | GENERATIONS | Number of copies of deleted or saved-over structures to keep, 2 to 99; 3 if absent. |
3602 | FORMAT | 0 archive: all layers and data types, and UNITS follows. 1 filtered: selected layers, listed in MASK records. Absent means archive. |
3706 | MASK | Layers and data types written, for example 1 5-7 10 ; 0-63: numbers and ranges, layers before the semicolon, data types after it. |
3800 | ENDMASKS | End of the masks; UNITS follows. |
0305 | UNITS | Two reals: the size of a database unit in user units, and in metres. Typical values are 0.001 and 10−9. A user unit in metres is the second divided by the first. |
0400 | ENDLIB | End of the library. |
0502 | BGNSTR | Start of a structure: creation time and last modification time, laid out as in BGNLIB. |
0606 | STRNAME | Structure name, at most 32 characters from A–Z a–z 0–9 _ ? $. |
3401 | STRCLASS | Flags for Calma’s own use; other writers leave it out or write zero. |
0700 | ENDSTR | End of a structure. |
Elements
| Code | Element | Meaning | Points in XY |
|---|---|---|---|
0800 | BOUNDARY | Filled polygon; the last point repeats the first. | 4–200 |
0900 | PATH | Line with a width along the points. | 2–200 |
0A00 | SREF | One copy of a structure, placed at the point. | 1 |
0B00 | AREF | Array of copies of a structure. | 3 |
0C00 | TEXT | Text anchored at the point. | 1 |
1500 | NODE | Node. | 1–50 |
2D00 | BOX | Box; the last point repeats the first. | 5 |
1100 | ENDEL | End of any element. |
XY (1003) holds pairs of four-byte integers, x then y, in database
units. For an AREF the three points are the reference point; the point displaced
from it by the number of columns times the column spacing; and the point displaced by the number
of rows times the row spacing. The manual calls the lattice orthogonal. COLROW (1302) gives the numbers of columns and rows, each
positive and at most 32,767.
Records inside elements
| Code | Record | Content |
|---|---|---|
0D02 | LAYER | Layer, 0–63. |
0E02 | DATATYPE | Data type, a second number beside the layer, 0–63. |
1602 | TEXTTYPE | Text type, 0–63. |
2A02 | NODETYPE | Node type, 0–63. |
2E02 | BOXTYPE | Box type, 0–63. |
1206 | SNAME | Name of the structure referred to. |
1906 | STRING | The text, at most 512 characters. |
1701 | PRESENTATION | Bits 10–11: font 0–3. Bits 12–13: vertical anchor, 00 top, 01 middle, 10 bottom. Bits 14–15: horizontal, 00 left, 01 centre, 10 right. Bits 0–9 are zero. Default: font 0, top left. |
2102 | PATHTYPE | Path ends: 0 square and flush with the end points (default), 1 round, a semicircle centred on each end point, 2 square, extended by half the width, 4 square with separate extensions (a CustomPlus feature). |
0F03 | WIDTH | Line width of a path or text in database units; 0 if absent. A negative value is an absolute width, not scaled by the magnification of references above it. |
3003 | BGNEXTN | For path type 4: distance the path extends beyond its first point; may be negative. |
3103 | ENDEXTN | The same beyond the last point. |
1A01 | STRANS | Transformation flags. Bit 0: reflect about the x axis before rotating (for an array, the whole lattice). Bit 13: the magnification is absolute. Bit 14: the angle is absolute. Others zero. |
1B05 | MAG | Magnification; 1 if absent. |
1C05 | ANGLE | Rotation in degrees, counter-clockwise; 0 if absent. An array rotates as a whole about its reference point. |
2601 | ELFLAGS | Bit 15: template data. Bit 14: exterior (external) data. Others zero. |
2F03 | PLEX | Positive number shared by the elements of a plex, a group within a structure. The head of the plex is marked by setting the seventh bit from the top, so the number uses the lower 24 bits. |
2B02 | PROPATTR | Property number, 1–127; 126 and 127 are reserved. |
2C06 | PROPVALUE | Property value, at most 126 characters. |
An element’s property numbers are distinct, and the string lengths plus two bytes for each property total at most 128 bytes, or 512 for references, arrays and nodes. A transformation in a reference applies to everything the referenced structure contains, and references nest.
Tape, retired and unreleased records
| Code | Record | Status in the 6.0 manual |
|---|---|---|
3202 | TAPENUM | Reel number of a multi-reel stream, from 1. |
3302 | TAPECODE | Twelve bytes (six integers) common to the reels of one set. |
1400 | TEXTNODE | Not in use. |
18 | SPACING | Discontinued. |
1D | UINTEGER | User integer of Release 2.0, no longer used; the importer turns it into property 126. |
1E | USTRING | User string of Releases 1.0 and 2.0, no longer used; turned into property 127. |
2406 | STYPTABLE | String, unreleased. |
2502 | STRTYPE | Two-byte integer, unreleased. |
2703 | ELKEY | Four-byte integer, unreleased. |
28 | LINKTYPE | Two-byte integer, unreleased. |
29 | LINKKEYS | Four-byte integer, unreleased. |
3503 | RESERVED | Reserved; formerly NUMTYPES. |
A stream split over several tape reels holds only whole records on each. The first reel ends
with TAPENUM, TAPECODE and LIBNAME; each later reel starts
with the same three, and a reel that is not the last ends with TAPENUM. Leaving
these groups out and joining the reels gives an ordinary stream.
Raith records
Records outside the Calma manual describe elements of Raith electron beam lithography software.
Raith MBMS path
Two records describe the MBMS (modulated beam moving stage) paths. What follows is how gdstk reads and writes them.
| Code | Name in gdstk | Content |
|---|---|---|
5A00 | RAITHMBMSPATH | Starts the element, in place of PATH. No data. |
6206 | RAITHPXXDATA | A binary block of 256 bytes, so a record of 260. The data type byte says string, but the content is not text. |
Such an element is written in this order: 5A00, LAYER,
DATATYPE, PATHTYPE, WIDTH, SNAME,
6206, BGNEXTN and ENDEXTN for path type 4,
XY, any properties, ENDEL. SNAME inside it names the
base cell, padded with a NUL to an even length.
The numbers in the block are little-endian, unlike the rest of the stream, and the reals are 8-byte IEEE doubles rather than GDSII reals.
| Offset | Size | Field | Content |
|---|---|---|---|
| 0 | 1 | calc_only | Not interpreted; gdstk writes 0. |
| 1 | 1 | dwelltime_selection | Dwell time selection. |
| 2 | 2 | unused | Written as 0. |
| 4 | 8 | pitch_parallel_to_path | Pitch along the path, a real. |
| 12 | 8 | pitch_perpendicular_to_path | Pitch across the path, a real. |
| 20 | 8 | pitch_scale | Pitch scale, a real. |
| 28 | 4 | periods | Number of periods. |
| 32 | 4 | grating_type | Grating type. |
| 36 | 4 | dots_per_cycle | Number of dots per cycle. |
| 40 | 4 | ret_base_pixel_count | Integer, not interpreted; written as 0. |
| 44 | 4 | ret_pixel_count | Integer, not interpreted; written as 0. |
| 48 | 8 | ret_stage_speed | Real, not interpreted; written as 0. |
| 56 | 8 | ret_dwell_time | Real, not interpreted; written as 0. |
| 64 | 190 | free | Zeros. |
| 254 | 2 | revision | gdstk writes 1. |
gdstk multiplies the three pitch values by its database scale when it writes them, and does not divide them again when it reads them.
Raith curved element
Two further records start whole elements. They are written by the Raith GDSII toolbox for
MATLAB, published by the National Research Council of Canada, and what follows is taken from
that program. Both end with ENDEL like any element.
Record 5600 is an arc, circle or ellipse. The records follow in this order:
5600, LAYER, DATATYPE, WIDTH (only when the
width is not zero), ANGLE, XY, ENDEL.
ANGLE is the angle in degrees from the +x axis to the first axis of the shape; the
toolbox always writes it for an ellipse, writes it for an arc only when it is not zero, and
never writes it for a circle. XY holds eight four-byte integers that are not four
points:
| Integer | Content |
|---|---|
| 1, 2 | Centre x and y, in database units. |
| 3, 4 | Radius along the first and the second axis; equal for a circle. |
| 5, 6 | Start and end of the parameter angle, in microradians (the toolbox converts degrees by 785,398/45 and rounds). Both are 0 for a full circle or ellipse. |
| 7 | Number of vertices used to draw the curve. |
| 8 | Shape flag, below. |
| Flag | Shape |
|---|---|
| 0 | Circle, unfilled. |
| 1 | Ellipse, unfilled. |
| 2 | Circle, filled. |
| 3 | Ellipse, filled. |
| 4 | Circular segment (arc), unfilled. |
| 5 | Elliptical segment, unfilled. |
| 6 | Circular segment, filled. |
| 7 | Elliptical segment, filled. |
A filled shape has no WIDTH, and an unfilled shape without WIDTH is
a line one pixel wide. When plotting, the toolbox takes a negative width to mean a filled shape
and calls this Raith’s behaviour, although in the GDSII record a negative width means an
absolute width. It fills a segment as the sector closed through the centre. With the
centre (xc, yc), radii rx and ry, rotation φ and
parameter t, a point of the curve is
x = xc + rx cos t cos φ − ry sin t sin φ,
y = yc + rx cos t sin φ + ry sin t cos φ.
Raith FBMS element
Record 5800 is a path or circle of Raith’s fixed beam moving stage mode, in the
order 5800, LAYER, DATATYPE, WIDTH (always
written; 0 is a line one pixel wide), XY, ENDEL. XY
begins with four zero integers. For a path, four integers per vertex follow: a flag (0 the
first vertex, 1 reached by a straight segment, 2 reached by an arc), x, y, and the curvature.
The curvature of an arc is its sagitta, the distance from the middle of the chord to the middle
of the arc, positive when the arc lies to the left of the chord in the direction of travel and
negative to the right; it is ignored for the first vertex. A circle has eight integers in all:
0, 0, 0, 0, 0, then the centre x and y and the radius. A path has at least two vertices, so at
least twelve integers. The toolbox draws an arc with 32 segments and an FBMS circle with 64
vertices, and says that these match Raith’s software.
The same toolbox writes a dot as a PATH of two identical points without
WIDTH, writes text as BOUNDARY elements, and puts 1,000 times the
relative exposure dose in DATATYPE.
Example
The start of the sample file printed in the manual: a Release 6.0 header, the date records, a directory size, one access control entry and the library name.
0006 0002 0258 HEADER, version 600
001C 0102 0055 0009 0003 ... BGNLIB, 1985-09-03 ...
0006 3902 0028 LIBDIRSIZE, 40
000A 3B02 0003 0005 0007 LIBSECUR: group 3, user 5, rights 7
000E 0206 4558414D504C452E4442 LIBNAME, "EXAMPLE.DB"
Its UNITS record, 0014 0305 3E41 8937 4BC6 A7EF 3944 B82F A09B 5A51,
holds 0.001 and 10−9: database units of a nanometre and user units of a micrometre.
Recognising a file
A stream begins with the bytes 00 06 00 02, a two-byte version, and then
00 1C 01 02, the start of BGNLIB. Walking the record lengths from the
start should reach ENDLIB (00 04 04 00), with nothing but zero bytes
after it.
In the explorer
A dropped .gds or .gdsii file opens as a record tree and as a
drawing of its top structures with every reference and array expanded. Any quarter of a
drawing opens larger, without limit, and any structure, or any pair of layer and type, can
be drawn alone. A drawing that needs more work than one pass allows is marked with a red and
white stripe and continues in further passes. The file is read in parts and never held
whole, so its size is not limited; what the viewer keeps grows with the number of structures
and of different reference transformations, and slowly with the number of elements.
Tables list the structures, elements with all their points, references, texts, properties, the access list, the tape, retired, unreleased and Raith records with their values as stored, and a count of records by code. A Raith curved element lists every vertex it asks for, however many; a drawing works them out as finely as it can show. Structures that are referred to but not in the file are named. Reference libraries and font, attribute definition and sticks rules files are separate files: when the file is opened with its folder, the window shows where in the folder each one lies. What goes beyond the limits of the 6.0 manual is counted.
Text is drawn in the viewer’s own stroke font, whatever font file the library names, placed
by PRESENTATION, with capitals MAG user units high, as KLayout takes
the size of a text. References above a text scale, turn and mirror it unless
STRANS says absolute, and WIDTH and PATHTYPE give the
width and ends of its strokes.
Five options at the top of the window choose between differing readings: layer and type
numbers as signed (the manual, the default) or unsigned (KLayout); only the first of several
XY records (the manual, the default) or all joined (KLayout); a negative width in
Raith curved and FBMS elements as filled (the Raith toolbox, the default) or as an absolute
width; text drawn or hidden; and text sized with the layout (the default) or at one size on
the screen.
Divergence from spec and in software
- The manual limits layers and types to 0–63. A later copy of the record descriptions published by Klaas Holwerda gives 0–255, and KLayout reads these two-byte fields as unsigned, so larger numbers are met. gdstk also accepts a layer written as a four-byte integer.
- The manual allows 200 points in a boundary or path. KLayout reads more, and for an
XYrecord of over 2,000 points it also looks for furtherXYrecords continuing the same shape, an extension that can be switched off. - The years in
BGNLIBare not consistent. The manual’s own example writes 1985 as 85, and gdstk writes years counted from 1900, so a reader should not assume a four-digit year. - KLayout’s reader ignores
NODEelements, and an option says whetherBOXelements are ignored, read as rectangles, read as polygons or treated as an error. - KLayout accepts property records in the library header, and splits very long property values
into several records whose text starts
#n,p:, naming the property and the part. Its reader has no case forLIBSECURin the header and reports an invalid record. - gdstk reads and writes two records that the manual does not have, the Raith MBMS path records. The Raith GDSII toolbox writes two more, the curved element and the FBMS element.
- Holwerda’s copy gives different file naming rules (UNIX rather than Calma’s), limits
REFLIBSto 15 libraries, lists furtherFORMATvalues for EDSM streams, and has a wrong byte pattern in one of its examples of reals (1000 is43 3E 80 00).
Not described
Described from Calma’s manual, Release 6.0, and compared with Holwerda’s copy and the sources of KLayout, gdstk and the Raith GDSII toolbox.
Unknown
- Reference: the meaning of the access rights values in
LIBSECUR, which the manual does not give. - Reference: the flags of
STRCLASS, which were for Calma’s own use. - Reference: the meaning of the unreleased records
STYPTABLE,STRTYPE,ELKEY,LINKTYPEandLINKKEYS, of which only the data types are published. - Reference: the values of the Raith fields
dwelltime_selectionandgrating_type, and the use ofcalc_onlyand the fourret_fields. - Viewer: how Raith’s software places the base structure along an MBMS path. The viewer draws it as an ordinary path of its width and lists the fields.
Links
Software
- KLayout – layout viewer and editor (Windows, macOS, Linux)
Developers
- gdstk – library for creating and reading GDSII and OASIS files (C++, Python)
- KLayout source – includes the GDSII reader and writer (C++)
- Raith_GDSII – MATLAB toolbox writing GDSII files with Raith’s elements (National Research Council of Canada)
Reference
- GDSII Stream Format Manual, Release 6.0 – Calma’s manual of February 1987 (PDF scan)
- The GDSII Stream Format – Klaas Holwerda’s web copy of the record descriptions and syntax