• 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. Sorting Schematic Instance by location

Stats

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

Sorting Schematic Instance by location

nosaj
nosaj over 10 years ago

How do I sort schematic instances ( cv~>instHeaders ) based on the X location on the schematic?

  • Cancel
  • Andrew Beckett
    Andrew Beckett over 10 years ago

    I assume you meant cv~>instances rather than cv~>instHeaders (instHeaders are once per instantiated master, and can represent multiple instances of the same type - so an instHeader will have multiple xy locations, one for each instance). For that you'd do:

    instancesSortedByX=sort(cv~>instances lambda((a b) xCoord(a~>xy) < xCoord(b~>xy)))

    Regards,

    Andrew.

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

    My code uses instHeaders and still can't make it work with your suggestion.....could you correct it?                                                                                                                                                                                 

    foreach(ih cv~>instHeaders

        when( !member(ih~>libName skipLibList)

        instancesSortedbyX=sort(ih~>instances lambda((a b) xCoord(a~>xy) < xCoord(b~>xy)))

        foreach(inst instancesSortedbyX

          instNameList2 = cons(inst~>name instNameList2)

            printf("\tname=%s\txy=%L\n", inst~>name, inst~>xy)

        )

      )

    )

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

    So what doesn't work? I tried your code, and for each instHeader, the instances are output sorted by the X coordinate.

    Andrew.

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

     foreach(ih cv~>instHeaders
       when( !member(ih~>libName skipLibList)
         foreach(inst ih~>instances
           instNameList = cons(inst~>name instNameList)
             printf("\tname=%s\txy=%L\n", inst~>name, inst~>xy)    
         )
       )
     )
     printf("instNameList 1=%L\n", instNameList)
     printf("instNameList s=%L\n", sort(instNameList nil))


     foreach(ih cv~>instHeaders
       when( !member(ih~>libName skipLibList)
         instancesSortedbyX=sort(ih~>instances lambda((a b) xCoord(a~>xy) < xCoord(b~>xy)))
         foreach(inst instancesSortedbyX     
           instNameList2 = cons(inst~>name instNameList2)
             printf("\tname=%s\txy=%L\n", inst~>name, inst~>xy)    
         )
       )
     )

     printf("instNameList2=%L\n", instNameList2)


    OUTPUT :

        name=I0        xy=(-2.1875 1.125)
        name=I5        xy=(2.3125 0.3125)
        name=I2        xy=(-0.375 0.8125)
        name=Iz1    xy=(-1.375 0.0)
        name=I3        xy=(0.25 0.8125)
        name=I4        xy=(1.25 0.0625)
    instNameList 1=("I4" "I3" "Iz1" "I2" "I5" "I0")
    instNameList s=("I0" "I2" "I3" "I4" "I5" "Iz1")
        name=I0        xy=(-2.1875 1.125)
        name=I2        xy=(-0.375 0.8125)
        name=I5        xy=(2.3125 0.3125)
        name=Iz1      xy=(-1.375 0.0)
        name=I3        xy=(0.25 0.8125)
        name=I4        xy=(1.25 0.0625)
    instNameList2=("I4" "I3" "Iz1" "I5" "I2" "I0")

    See the output from the 2nd foreach, the instances were not sorted by x coordinate, correct order should be I0, Iz1, I2, I3, I4, I5.

    Pretty sure I'm not doing it correctly if you got it to work.

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

    I suspect the most likely explanation is that the instances are not all part of the same instHeader. It's only sorting within each instHeader.

    Please change the second loop to:

     foreach(ih cv~>instHeaders
       when( !member(ih~>libName skipLibList)
         printf("instHeader: %L %L %L master=%L\n" ih~>libName ih~>cellName ih~>viewName ih~>master)
         instancesSortedbyX=sort(ih~>instances lambda((a b) xCoord(a~>xy) < xCoord(b~>xy)))
         foreach(inst instancesSortedbyX     
           instNameList2 = cons(inst~>name instNameList2)
             printf("\tname=%s\txy=%L\n", inst~>name, inst~>xy)    
         )
       )
     )

    and then post what the output looks like.

    Regards,

    Andrew.

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

    I took out the cv~>instHeaders and replace it with

          foreach(inst sort(cv~>instances lambda((a b) xCoord(a~>xy) < xCoord(b~>xy)))
            when( !member(inst~>libName skipLibList)
              instNameList = cons(inst~>name instNameList)
              printf("\tname=%s\txy=%L\n", inst~>name, inst~>xy)   
            )
          )

    And that works now. 

    Output :

        name=I0    xy=(-2.1875 1.125)
        name=Iz1    xy=(-1.375 0.0)
        name=I2    xy=(-0.375 0.8125)
        name=I3    xy=(0.25 0.8125)
        name=I4    xy=(1.25 0.0625)
        name=I5    xy=(2.3125 0.3125)

    I don't know why the original code uses cv~>instHeaders and loop another foreach instHeader~>instances. 

    Is there any difference between [1] and [2]?

    [1]

    foreach (inst cv~>instances

    )

    [2]


    forearch(ih cv~>instHeaders

      foreach(ih~>instances

      )

    )

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

    If you're only interested in certain masters and have conditional code around the inner foreach over the instances for that instHeader, then the two loop approach will be more efficient. If you are visiting every instance, then there's not much in it.

    • 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