• 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. About loop constructs

Stats

  • Locked Locked
  • Replies 8
  • Subscribers 125
  • Views 14502
  • 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

About loop constructs

bobbygang
bobbygang over 14 years ago

Hi, I have a strange problem. In skill code , can I set a function for loop constructs whose selection statement number is uncertain?
For example I set a  list Total=(A B C D E)  and their corresponding limit for loop just as ( 3 2 1 2 3 ).
And I set a new list Cycle =( A B). It includes part elements of Total as the statement 
Then I want a function LP(Total Cycle   (code)  )  to achieve like this( assume this function name is LP):

for(A 1 3
     for(B 1 2
          (code)
    )/*end for*/
)*end for*/

I f I modify change Cycle=(A B C)
LP(Total Cycle   (code)    )  will do something like this:

for(A 1 3
       for(B 1 2
            for(C 1 1
                     (code)
                )*end for*/
           )*end for*/
)*end for*/

Regards,


Bobby.

 

 

  • Cancel
  • Andrew Beckett
    Andrew Beckett over 14 years ago

    Seems a slightly odd requirement, but you could do it with this:

    defmacro(LP (Total Cycle @rest code)
      if(cdr(Cycle) then
        `for(,car(Cycle) 1 ,car(Total) LP(,cdr(Total) ,cdr(Cycle) ,@code))
      else
        `for(,car(Cycle) 1 ,(car Total) ,@code)
      )
    )

    ; example:
    procedure(foobar()
      LP((3 2 1) (A B C)
        println(list(A B C))
      )
    )

    Run foobar() once, and then you can do pp(foobar) to see the function - it will have then had the macro expanded. If you do the pp before running it, you'll see just the macro calls.

    Note the functions should really have sensible prefixes; calling them LP and foobar in the example above is not a good idea as they could clash with other poorly named functions. Also, if the requirement is that the arguments to LP are dynamic - i.e. they are variables which could change throughout the program, the above approach won't work because macros are done at compile time. If they're dynamic though, you might want to explain precisely what it is you're trying to do?

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • bobbygang
    bobbygang over 14 years ago

    Thank you! I will try this later. 

    Regards,

    Bobby

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 14 years ago
    Hi Bobby,

    In order to use , and ,@ you need to use a backquote (i.e. ` not '). If you use a conventional quote, the entire list is quoted. Backquote is a macro that expands into a corresponding list() call (it's not always list() - it depends) but gives you a convenient syntax - so is very useful for writing macros.

    Best Regards,

    Andrew
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • bobbygang
    bobbygang over 14 years ago

    ... I had found that before you answered me.  So I deleted it.
    Now I want to know outside defmacro is there anyway to use its local variable.
    For example, after input
    LP((3 2 ) (Process Bat) println(list(Process Bat) ) )
    I also want to variable Process for other use.

    Regards,

    Bobby.

     

     

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

    Bobby,

    Well, there's no reason why you can't use the variable Process outside the LP() function. The Process is local to the for() loop. If you're asking to access the for() loop's local variable outside the loop, then you can't (it wouldn't be local then, would it?), and even if you could, what would you expect it to contain?

    The main issue is that I don't understand what you're trying to achieve - so your question doesn't make sense to me.

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • bobbygang
    bobbygang over 14 years ago


    Andrew,

    I'm sorry, in fact I want to design some basis ocean for circuit design. So I want to achieve some function which makes other fresh man easier to understand and can be reused.But now I have never fully thought how to do it.
    The function discussed above is just one of them. It contains uncertain loops, each cycle corresponding to the different variables
    For example, there are variables A B C D E ... Every time I combine some of them  and see their impact on the circuit, the other variables remain typical value.
    Perhaps I may write analysis() in @rest code. But when analysis finishes I get some circuit result such as Id and I want to know its worst condition. Then combine these worst-case conditions to get the top worst condition.
    For example I want to get max value of Id.
    Loop is like this:
    A   B   Id       
    1   1   1u
          2   3u
    2   1    5u
          2   6u
    3   1    4u
          2   2u

    C   D  E   Id       
    1   1  1    1u
              2   1.5u
         2  1    3u
              2   3.5u
         3  1    5u
              2   4u
    2   1  1    2u
              2   6u
         2  1    2.5u
              2   3.5u
        3   1   1u
              2   0.5u

    To achieve above I may write
    LP((3 2) (A B) analysis()....) 
    LP((2 3 2) (C D E) analysis()....)    
    and get  worst condition from it:A=2 B=2 C=2 D=1 E=2
    And I will do simulation in this case.

    I know its easier if I use for(for (for .....))) to construct the ocean. But when combination need to change the code may be rewritten.
    May be my idea is too complicated. I hope you can help me.

    Regards,

    Bobby.

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

    You could do:

    resultTab=makeTable('results nil)
    LP((2 3 2) (C D E)
      analysis(...)
      resultTab[list(C D E)]=someCalculation
    )

    Then you have an association table with all the results in. You could then process this outside the loop once things have finished?

    In general, I would have expected foreach() to be more useful than for loops - because usually you will have a set of values or a set of corners, etc that need to be iterated over, rather than a for loop (which usually means you are using the wrong data structure in SKILL).

    I still don't quite get your overall aim - I'm not sure this disguising of the loops is really making life easier for the user.

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • bobbygang
    bobbygang over 14 years ago

    Hello Andrew,

        Wow, "makeTable" is something new to me. I think I need some time to learn it.

        Moreover, I will accept your advice that use "foreach" instead of "for"

    Regards,

    Bobby.

    • 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