• 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 14504
  • 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
Parents
  • 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
Reply
  • 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
Children
No Data

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