• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Custom IC SKILL
  3. defstruct in pcell (for layout), is it possible?

Stats

  • Locked Locked
  • Replies 8
  • Subscribers 144
  • Views 14841
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

defstruct in pcell (for layout), is it possible?

sjoerdh
sjoerdh over 10 years ago

Hello,

This is what I want to do:

  • Create a pcell that instantiates other pcells (layout)
  • Perform various "measurements" on this new instance (i.e.: retrieve the bounding box)
  • This information has to be used lateron in the pcell code

I'd like to store this information in a table, where each cell is a defstruct.The code looks like this:

procedure( genCurMir( ... )
    let( ()
        ...
        curMirInst = makeTable( "curMirInst" nil )
        defstruct( instance boundingBox gateCenter drainCenter sourceCentre )
        curMirInst["CELL1"] = make_instance()
        ...
        curMirInst["CELL1"]->boundingBox = instID~>bBox
        ...
    ) ;;; end of let
) ;;; end of procedure genCurMir

After generating the pcell (loading the code containing the command "pcDefinePCell") weird things happen: I am unable to open any view (layout/schematic/symbol/...).Entering commands in the CIW will result (9 out of 10 times) in an error, which is the same error when trying to open any cell-view:

*Error* setq/set: Variable is protected and cannot be assigned to - instance

I have tried creating the defstruct with an other name (blablablabla, definitely not used anywhere else), but the same error, only "instance" replaced by "blablablabla". I have to restart Cedence to regain control.

Furthermore, this created defstruct seems to be global, whereas I created it inside a let. I'd like to keep it local though.

So my question is:

Is it possible to use defstructs in pcells?
If so, what am I doing wrong?

I'd realy like to use this method (table of defstructs) since it is very conveniant.

Any help is highly appreciated.

Thanks in advance,

Sjoerd

  • Cancel
  • theopaone
    theopaone over 10 years ago

    Hi Sjoerd

    You are re-creating the defstruct each time your pcell code evaluates. As you saw, the defstruct is a global object that can only be made once. You can then instantiate it inside of the pcells without any issues, keeping it in your table of defstructs. I would create the defstruct outside the pcDefinePCell statement and do it only once per PDK or check for its existance before creating it.

    Move this line outside the pcDefinePCell statement:

            defstruct( instance boundingBox gateCenter drainCenter sourceCentre )

    If you absolutely want the memory to be reclamed, use a DPL - disembodied property list or another table.

    Ted

     

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 10 years ago

    Hi Sjoerd,

    I would suggest moving the defstruct outside of a procedure. They are not local anyway, so there is no benefit. I also think that problems may occur because the definition of the structure is stored in a variable called (say) instance. If you have defined this, it may actually stamp on a dynamically scoped variable called instance at the same time.

    You can see this in the following code (completely separate from a pcell):

    defstruct( instance boundingBox gateCenter drainCenter sourceCentre )
    procedure(MyMakeThing()
      make_instance()
    )

    let((instance)
      MyMakeThing()
    )

    this will fail with an error:

    *Error* iliMakeDefstruct: Name given not a defstruct - instance

    the problem is the clash with the local variable instance and the global variable instance containing the structure definition. So I would suggest also ensuring that you call the defastruct MyInstance or something that is definition not going to clash.

    It's possible the instance in your case is clashing with something in the pcell system - I didn't check that.

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • theopaone
    theopaone over 10 years ago

     You can instantiate a defstruct in a pcell, but the defstruct definition is associated with a global symbol which, as Andrew demonstrated, can be masked with a local declaration. 

    It is the same thing with classes, defclass outside the pcDefinePCell statement but you can instantiate inside the pcell body code.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • sjoerdh
    sjoerdh over 10 years ago

    Hi theopaone,

    Thanks for your response.

    I wasn't aware that a defstruct is, by definition, something global. I don't like to create, or have to create, something global for a pcell. I always try to avoid using globals as much as possible (I only had to create a handfull of globals in the past 7 years...).

    I'll test the defstruct (defined outside the pcell-code) to just be able to see how it all works. Most likely, my final implementation will be a table-of tables.

    Kind regards,

    Sjoerd

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • sjoerdh
    sjoerdh over 10 years ago

    Hi Andrew,

    Thank you for your response.

    Please see my response to the post of theopaone. I'll test the defstruct option, but will most likely end up using a table-of-tables. Just have to see how easy it is to retrive/sort information from a t-o-t, which is very convenient if using a table-of-defstructs.

    With kind regards,

    Sjoerd

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • sjoerdh
    sjoerdh over 10 years ago

    Hi Andrew, theopaone and anyone else,

    I've been playing around with table-of-defstructs and table-of-tables, and sofar for most of my coding both work equally simple. However, there's one case which I can't get to work if I use  t-o-t, but is very easy in a t-o-ds. Please see an example below (the output is indented):

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ; Table of defstructs:
    tempInstDS = makeTable( 'tempInstDSTable nil )
    defstruct(sstCMMinstance instName instOrigin instOrient)
    tempInstDS[1] = make_sstCMMinstance()
    tempInstDS[2] = make_sstCMMinstance()
    tempInstDS[3] = make_sstCMMinstance()
    tempInstDS[1]->instName = "instC"
    tempInstDS[2]->instName = "instB"
    tempInstDS[3]->instName = "instA"
    tempInstDS[1]->instOrient = "R90"
    tempInstDS[2]->instOrient = "R180"
    tempInstDS[3]->instOrient = "MX"
    tempInstDS[1]
        sstCMMinstance@0x11a08878
    tempInstDS[1]->?
        (instOrient instOrigin instName)
    tempInstDS[1]->??
        (instOrient "R90" instOrigin nil instName
            "instC"
        )
    sort(tempInstDS->? 'lessp)
        (1 2 3)
    foreach(key sort(tempInstDS->? 'lessp) printf("%L\n" tempInstDS[key]->? )) =>
        (instOrient instOrigin instName)
        (instOrient instOrigin instName)
        (instOrient instOrigin instName)
        (1 2 3)
    foreach(key sort(tempInstDS->? 'lessp) printf("%L\n" tempInstDS[key]->?? ))
        (instOrient "R90" instOrigin nil instName "instC")
        (instOrient "R180" instOrigin nil instName "instB")
        (instOrient "MX" instOrigin nil instName "instA")
        (1 2 3)
    foreach(key sort(tempInstDS->? 'lessp) printf("%L\n" tempInstDS[key]->instName ))
        "instC"
        "instB"
        "instA"
        (1 2 3)
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    It is the last command I like to replicate using a t-o-t. This is the equivalent:

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ; Table of tables:
    tempInst=makeTable( 'tempInstTable nil )
    tempInst[list(1 "name")]="instC"
    tempInst[list(2 "name")]="instB"
    tempInst[list(3 "name")]="instA"
    tempInst[list(1 "orient")]="R90"
    tempInst[list(2 "orient")]="R180"
    tempInst[list(3 "orient")]="MY"
    tempInst->?
        ((1 "name")
            (3 "name")
            (2 "name")
            (1 "orient")
            (3 "orient")
            (2 "orient")
        )
    sortcar( tempInst->? 'lessp)
        ((1 "orient")
            (1 "name")
            (2 "orient")
            (2 "name")
            (3 "orient")
            (3 "name")
        )
    foreach( key sortcar( tempInst->? 'lessp) printf( "%L\n" tempInst[key] ))
        "R90"
        "instC"
        "R180"
        "instB"
        "MY"
        "instA"
        ((1 "orient")
            (1 "name")
            (2 "orient")
            (2 "name")
            (3 "orient")
            (3 "name")
        )
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    This is what I tried to get the same output as with the last command of the t-o-ds:

    Since the following works:
    tempInst['(1 "name")]
        "instC"

    I thought I had to do this:
    foreach( key sortcar( tempInst->? 'lessp) printf( "%L\n" tempInst['(car(key) "name")] ))
        output is all nil (6 times)

    I have tried many different constructions for the printf statement, oa:
    printf( "%L\n" tempInst['(key "name")] )
    printf( "%L\n" tempInst[list(car(key) "name")] )

    Even something simple as this doesn't work:
    for(i 1 3 printf( "%L\n" tempInst[list(i "name")] ))
    This truly surprises me since tempInst[list(1 "name")] does work...

    What I try to do:
    The output of the foreach should be all names (and only the names) of each instance.

    The t-o-ds solution is simple, and easy to understand (see the last command of the t-o-ds code). The t-o-t? No solution yet.

    I hope one of you can show me how to do it, or point me into the right direction by describing what I do wrong, so I can figur out myself what I am doing wrong.

    Thank you in advance.

    Kind regards,

    Sjoerd

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 10 years ago

    Hi Sjoerd,

    First of all, there is no problem with the defstruct using a global object to store its definition. After all, that's what your functions are too - these are globally named functions (unless you use lexical scoping in SKILL++ to have local functions, or potentially using the namespace mechanism in IC616 (I wouldn't recommend that currently since it needs some refinement in my opinion)). You're not really using a global object to communicate data - it's just a global definition - after creation you don't change it. So the trick is simply to give it a sensible prefix, which is what you should do with your functions too.

    Now, on to your question. Your table of tables is NOT a table of tables. It's a table, indexed by a list. Because of that, you have more keys in there than you really want. You could of course just filter them (using setof):

    foreach(key sortcar(setof(k tempInst cadr(k)=="name") 'lessp)  printf( "%L\n" tempInst[key]))

    Or have a conditional:

    foreach(key  sortcar( tempInst->? 'lessp) when(cadr(key)=="name" printf("%L\n" tempInst[key])))

    Or actually implement it as a table of tables! This is what I would do if I was implementing this without a defstruct - it means your keys in the top table are what you actually want them to be, rather than making the keys a compound of the real index and the slot name. So for example:

    tempInst=makeTable( 'tempInstTable nil )
    tempInstDS[1] = makeTable('instThing nil)
    tempInstDS[2] = makeTable('instThing nil)
    tempInstDS[3] = makeTable('instThing nil)
    tempInstDS[1]->instName = "instC"
    tempInstDS[2]->instName = "instB"
    tempInstDS[3]->instName = "instA"
    tempInstDS[1]->instOrient = "R90"
    tempInstDS[2]->instOrient = "R180"
    tempInstDS[3]->instOrient = "MX"

    Then you can use the rest of the code exactly as you did with the defstruct implementation. So for example:

    foreach(key sort(tempInstDS->? 'lessp) printf("%L\n" tempInstDS[key]->instName ))

    This works because rather conveniently if you have a table with symbols as the keys you can do:

      table->instName="instD"

    which is exactly the same as doing:

      table['instName]="instD"

    but has the readability of it being a defstruct or a DPL. It also makes it very easy to change a code implementation originally built using DPLs to tables, which can lead to a big efficiency improvement since DPLs are sequential, compared with tables which are hashed.

    Kind Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • sjoerdh
    sjoerdh over 10 years ago

    Thank you Andrew,

    This was very helpful. Not only do I understand what I did wrong (why it did not work the way I thought it would work), but I know now how to make it like I want it to be.

    I'll definitely go for the t-o-t solution. Although there is nothing wrong with using defstructs (as you clearly explained), I'd like the idea to keep everything as local as possible (except for my own functions...). Appart from the creation/filling of the cells of the first table (either with a defstruct or a table), all other code is identical, so I can change it whenever I like to, and feel the need to.

    With kind regards,

    Sjoerd

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information