• 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. Creating Pcells based on certain condition or passing variables...

Stats

  • Locked Locked
  • Replies 2
  • Subscribers 143
  • Views 11732
  • 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

Creating Pcells based on certain condition or passing variables to pcell code

harisps
harisps over 4 years ago

procedure(CreatePcell(libName cellName "tt")
      libId = ddGetObj( libName )
      pcDefinePCell( 
      .....................
      let ((......)
          foreach(i VarList
          ...................
          );end_foreach
      .).....................
);end_createPcell


procedure(MainCode(.........................)
    Let( (.............)
    VarList = setof(......)
    if( !(VarList== nil) then
         CreatePcell(libName cellName)
    );end_if
    );end_let
);end_procedure


1) Can pcell code be called based on conditional checks?
2) Whether pcell code can access "VarList" variable from MainCode. Esp. while instantiate them to other cellviews
3) Can I pass this variable to pcell code like "CreatePcell(libName cellName Variable)"
  • Cancel
  • mbracht
    mbracht over 4 years ago

    1) Can pcell code be called based on conditional checks?

       Yes of course!

    2) Whether pcell code can access "VarList" variable from MainCode. Esp. while instantiate them to other cellviews

       VarList is a global variable so yes you can access it from everywhere. Even if it was defined locally it'd be still visible in CreatePcell() because in SKILL you have dynamic scoping. In other words all variables a technically
       global only their value gets temporarily overwritten in for example a let block. If you want true local (lexical) variables you need to switch to SKILL++. That being said it'd be much cleaner to pass VarList as a parameter to CreatePcell

    3) Can I pass this variable to pcell code like "CreatePcell(libName cellName Variable)"

       see above...

     

    Max

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 4 years ago in reply to mbracht

    Max and I discussed this a bit further offline, and I think the issue is more that you want to be able to have the MainCode function determine the value of VarList and then have that used in the generated PCells.

    It's a bit more complicated in practice. In general it's not a good idea for the PCells to use global variable - after all, you'd need to ensure that global variable is always defined, and defined the same way in all sessions.

    You can't just set VarList in the MainCode and have it seen in the pcDefinePCell because of dynamic scoping, or even if you passed it as an argument to CreatePcell, it still won't work. 

    The issue here is that pcDefinePCell is an nlambda function. That means that it takes care of evaluating the pieces it wishes (using run-time evaluation), but importantly takes the literal body of the pcDefinePCell and stores it in the layout view (or schematic, or symbol) as a generated function. The code is then evaluated at PCell eval time, which means dynamic scoping from the MainCode isn't going to work. Nor is lexical scoping, because you can't call nlambda functions within lexically scoped code – it's simply not supported (it will tell you). So what are nlambda functions? They are a rarely used (and best avoided) capability in SKILL that mostly persists for legacy reasons - they allow a function to be written which gets its arguments unevaluated - and then can selectively choose which to evaluate (using run-time evaluation) and which not to (such as the body of the PCell). For most things, macros are a better solution (as these don't require run-time evaluation), which is why nlambda are not used much nowadays (my last reason to use one was in 1997, and even then I should have used a macro instead!) 

    Normally I'd suggest something like this:

    procedure(CreatePcell(libName cellName VarList "ttg")
        libId = ddGetObj( libName )
        eval(
          `pcDefinePCell( 
          .....................
          let ((......)
              foreach(i list(,VarList)
              ...................
              );end_foreach
          .).....................
        )
    );end_createPcell

    Yes, there's run-time evaluation, but creation of pcells is not something you typically do lots of times and so there's enough evaluation going on anyway when you are creating PCells that this is not a bad thing. So in other words, you're building the code for the pcDefinePCell using a backquoted list, but stuffing in the values into the right place using comma expansion (the `(blah blah whatever ,whatsit etc) is a way of describing an almost literal list, with the possibility of evaluating selective parts of it if preceded by comma; it's great for having code templates where you replace some part of the code).

    The code example should have a new more local variables, but that's probably just the illustration from the original poster rather than reality (I hope).

    Regards,

    Andrew

    • 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