• 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 Design
  3. Returning multiple variables in SKILL function

Stats

  • Locked Locked
  • Replies 11
  • Subscribers 127
  • Views 19381
  • 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

Returning multiple variables in SKILL function

RFStuff
RFStuff over 12 years ago

 Dear All,

I want to a skill function that can return multiple values.

Like: (a,b)=skillfunction(x,y,z....)

Could anybody please tell how it can be done.

Kind Regards,

 

         

 

  • Cancel
  • skillUser
    skillUser over 12 years ago

    Hi,

    Looks like you might be used to Perl, but one way to do this in SKILL is to return a list of values, but you would have to assign them to variables outside of the function call in a more manual way.  Here's a brief outline:

    
      procedure(skillfunction(x y z)
        let( (ret1 ret2)
        ;; do some function on these parameters
        ret1 = x + 2*y
        ret2 = y - z
        ;; this next line is the return value of the function
        list(ret1 ret2)
        ); let
      ); procedure
    
      retlist = skillfunction(10 20 5)
      a = car(retlist)
      b = cadr(retlist)
    

    Something like that. Function arguments are separated by whitespace.  If you have more than a couple of variables then you might consider a more general approach, for example using a table structure for storage in named slots.

    Hopefully this is helpful to you.

    Regards,

    Lawrence.

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

    Returning multiple values as a list is a clean way to do this, but you can also use the destructuringBind function (new in IC615) to destructure the list contents and assign to variables (local to the scope of the destructuringBind function). This example uses the function that Lawrence wrote above to illustrate this:

    destructuringBind((a b) skillfunction(10 20 5)
      printf("a=%L b=%L\n" a b)
    )

    You can use this with other interesting list structures - for example, imagine that you have an instance id from the database - you can do:

    area=destructuringBind(((llx lly) (urx ury)) instId~>bBox
      ; compute the area of the bBox
      (urx-llx)*(ury-lly)
    )

    Cool, eh? (OK, so I'm easily impressed)

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • kb how
    kb how over 12 years ago

    Interesting ...!

    Thanks for the sharing.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • RFStuff
    RFStuff over 12 years ago

     Dear  Lawrence & Andrew,

    Thanks a lot.

    Andrew: It is really nice. But is this feature available in IC5141.

    Kind Regards,

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

    In IC5141 you could use the following for the simple (non-nested list) case:

     (defmacro CCFsimpleMultiAssign (listOfVars listValue @rest body)
      `(apply (lambda ,listOfVars ,@body) ,listValue)
      )

    and then use CCFsimpleMultiAssign instead of destructuringBind in my first example. This won't work for the second bBox example - it would need a more complex macro (I threw the above together pretty quickly).

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • RFStuff
    RFStuff over 12 years ago

    Dear Andrew,

    Thanks a lot.

    Kind Regards,

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

     destructuringBind is wicked magic that should be studied in IC615. It is very useful, especially since you can return keyed values, optional values and @rest values.

    Before IC615, you could return the values as a disembodied property list (DPL). It is a list of key value pairs that begins with a nil:

    list( nil key1 "value1" key2 2.0 key3 list( "Value" "number" 3 ) )

    myDPL = callingMyFunction(....)

    myDPL->key1 => "value1"

    myDPL->key2 => 2.0

    myDPL->key3 => list("Value" "number" 3)

     Ted

     

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • RFStuff
    RFStuff over 12 years ago

    Dear Ted,

    Thanks a lot.

    Kind Regards,

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

     You know you are in trouble if you dream in SKILL.

     In my last post, I made an error and realized it last night. The key values in a DPL must be symbols. In the example, they are variables and the code may fail but will definately not work the way it was written. The DPL should be written as:

     list( nil 'key1 "value1" 'key2 2.0 'key3 list( "Value" "number" 3 ) )

     The keys must be quoted to be symbols.

    Ted

     

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • B Bruekers
    B Bruekers over 9 years ago
    Hi Andrew,

    I've been using the destructuringBind function and I've noticed that SKILL Lint does not understand the destructuringBind function correctly?
    code:
    bbox = list( '(0 0) '(1 2))
    area= destructuringBind(((llx lly) (urx ury)) bbox (urx-llx)*(ury-lly))

    First it complains that the llx, lly, urx and ury are defined globally. So after putting then in the let() I get the following errors:

    ERROR (CHK3): C:/Cadence/skill/test.il, line 455 (test) : Bad argument ( must be a symbol) : (llx lly)
    ERROR (CHK3): C:/Cadence/skill/test.il, line 455 (test) : Bad argument ( must be a symbol) : (urx ury)

    Do you have any idea if SKILL Lint is correct in these cases? Or should I just ignore this error?

    Thanks
    Bram
    • 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