Home
  • Products
  • Solutions
  • Support
  • Company

This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  • Products
  • Solutions
  • Support
  • Company
Community Custom IC SKILL How to filter out instances with a certain name from the...

Stats

  • Locked Locked
  • Replies 6
  • Subscribers 135
  • Views 3292
  • 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

How to filter out instances with a certain name from the data of dbGetTrueOverlaps return

dakuang01
dakuang01 10 months ago

Hello!

I would like to filter out some instances with a certain name from the data of dbGetTrueOverlaps return.

d_tmp = dbGetTrueOverlaps(cv l_bBox_4xMT "M1_4B" 20 t)

From the dbGetTrueOverlaps return data, d_tmp, I'm trying to get to the level that has "mesh2_20x20" and "mesh2_20x25" layout cells which are instances or mosaics and the cells have M1_4B in them.

I tried a few methods (by using the depth of the list and something else) to approach the cells but I ran into some issues.

The problem is that I don't know how deep the cells are of the data. It varies depending on the layout hierarchy. By using the approach, I ran into another issue. Instance and mosaic have a different depth for the data.

The only thing I know is what I'm targeting, in other words the db locations(inst or mosaic) of the leaf object are in the same level.



Using a different approach, do I need to check every single element whether each element is "inst" or "mosaic" with the cellname I'm searching?

Or I might need to use a recursive function? which I'm not very familiar with.

Please help me! Hope this will makes sense to you.

Thanks,
dakuang01

  • Cancel
  • AurelBuche
    AurelBuche 10 months ago

    Hi,

    To be honest, your description is not completely clear...

    Here is a snippet that might work

    Cheers,

    Aurélien

    (inScheme
    (defun ab_filter_instances_lists (obj fun)
      "OBJ can be an instance or a list containing sub-lists and/or atoms (including instances).
    FUN is a predicate to be applied on instances.
    
    Return an instance or a list of sub-lists and/or atoms.
    All instances that do not pass FUN predicate in list and sub-lists are filtered out.
    "
      (cond
        ;; An instance, check if it passes predicate
        ( (and (dbIsId obj)
               obj->isAnyInst
               )
          (when (fun obj) obj)
          )
        ;; A list, filter elements recursively
        ( (listp obj)
          (foreach mapcan elt obj
            (let ((res (ab_filter_instances_lists elt fun)))
              (when res (list res))
              )))
        ;; Any other object, return it as is
        (t obj)
        )))
    
    ;cv = (geGetEditCellView)
    ;l_bBox_4xMT = cv->bBox
    ;d_tmp = (dbGetTrueOverlaps cv l_bBox_4xMT t 20 t)
    
    d_tmp = dbGetTrueOverlaps(cv l_bBox_4xMT "M1_4B" 20 t)
    d_tmp = (ab_filter_instances_lists d_tmp
              ;; Keep only instances that do not contain expression in their name
              (lambda (inst) (not (pcreMatchp "mesh2_20x2[05]" inst->name))))
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • dakuang01
    dakuang01 10 months ago in reply to AurelBuche

    Hi Aurélien,

    Thank you very much for providing the code even though my question wasn't clear!

    Now I'm trying to understand the code and apply it, learning a lot from the code. : )

    Thanks,
    dakuang01

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • dakuang01
    dakuang01 10 months ago in reply to AurelBuche

    Hi Aurélien,

    I got an error on defun without inScheme so I updated it to procedure that's familiar to me : )
    And then I get an error here. (when (fun obj) obj)  - undefined function fun : Could you please explain what this line does for me?

    Also I don't understand well what these lines do. I see t(symbol) is added in the list when it sees an instance/mosaic having the name mesh2_20x2[05].

    (let ((res (ab_filter_instances_lists elt fun)))
       (when res (list res))
    ))

    Thanks,
    dakunag01

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett 10 months ago in reply to dakuang01

    Why did you remove the inScheme? This will only work in the Scheme (ILS/SKILL++) language mode, so removing that makes no sense. You could remove it provided that you put the content in a file with a .ils suffix, but presumably you haven't done that. Changing the defun to procedure wouldn't solve this either (there's no difference between the two other than a small syntax difference that defun has the name of the function separate from the argument list, whereas with procedure the first argument is a list of the function name and the argument list. Once defined though, they are indistinguishable.

    The code works by passing a function object to the ab_filter_instances_lists function, and then calling that as a function (that's what (fun obj) does).

    The part you have a question about is ensuring that if the ab_filter_instances returns something, it constructs a list from it, so that the surrounding foreach mapcan concatenates all the results.

    I agree with Aurélien though, your requirements are a bit unclear.

    Andrew

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • AurelBuche
    AurelBuche 10 months ago in reply to dakuang01

    `inScheme' was meant to use SKILL++ instead of SKILL
    I mostly code in SKILL++ (in my opinion, its behaviors are safer and more intuitive) and in Lisp-Style

    Some of them are detailled here:
    community.cadence.com/.../skill-for-the-skilled-what-is-skill

    In my function, the only behavior that differs from SKILL is about callable objects which can be used directly:

    ((lambda (a) a+3) 4) is valid SKILL++ code and will return 7, but will raise an error in SKILL
    (funcall (lambda (a) a+3) 4) is valid both in SKILL & SKILL++

    You will find below a 'simplified' example that might be more suitable for people used to C-Style SKILL
    I also added support for mosaics

    The most complicated part of the code is the foreach mapcan call
    When using `foreach mapcan', the last value of the loop hast to be a list
    The global result of `foreach mapcan' call the will then be a concatenated list of all the last value in each loop

    example:

    foreach( mapcan i '(1 2 3)
      list( i i )
      )
    ;; will return (1 1 2 2 3 3)

    It's very useful to filter some elements in complicated lists and process them at the same time
    (using setof could work but you would have to loop twice over your list to get the same result)

    foreach( mapcan i '(1 2 3 4 5)
      if( evenp(i)
        then
        list(i*2)
        ))
    ;; will return (4 8)
    ;; This works as `if' will return nil if i is not even

    This is how I filter out instances while trying to keep `dbGetTrueOverlaps' results structure

    Be very careful when using it: foreach mapcan is destructive!

    l='((1 2) (3 4) (5 6))
    (foreach mapcan i l
      i)
    ;; This will return l but flatten: (1 2 3 4 5 6)
    ;; But l is now modified :/
    l
    ;; This will return: ((1 2 3 4 5 6) (3 4 5 6) (5 6))
    
    ;; You have to make sure final loop value is a constructed list
    l='((1 2) (3 4) (5 6))
    (foreach mapcan i l
      copy(i))
    ;; This will return the same value (without modifying elements of l, they are parsed two times though...)

    Here's the updated code snippet

    procedure( ab_filter_instances_lists(obj fun)
      "OBJ can be an instance or a list containing sub-lists and/or atoms (including instances).
    FUN is a predicate to be applied on instances.
    
    Return an instance or a list of sub-lists and/or atoms.
    All instances that do not pass FUN predicate in list and sub-lists are filtered out.
    "
      cond(
        ;; An instance, check if it passes predicate
        ( dbIsId(obj) && obj->isAnyInst
          if( funcall(fun obj)
            then
            obj
            ))
        ;; A mosaic, check if its instance passes predicate
        ( listp(obj) && dbIsId(car(obj)) && integerp(cadr(obj)) && integerp(caddr(obj))
          if( funcall(fun car(obj))
            then
            obj
            ))
        ;; A list, filter elements recursively
        ( listp(obj)
          foreach(mapcan elt obj
            let( (res)
              res = ab_filter_instances_lists(elt fun)
              if( res
                then
                ;; `foreach mapcan' requires loop return value to be a list 
                list(res)
                ))
            ))
        ;; Any other object, return it as is
        ( t
          obj
          )
        ))
    • Cancel
    • Vote Up +1 Vote Down
    • Cancel
  • dakuang01
    dakuang01 10 months ago in reply to AurelBuche

    Wow, awesome!! The skill perfectly works in my code now.

    I'm a layout engineer. Whenever I need an automation, I try to come up with something so I'm not a super expert in SKILL.

    Thank you both for helping me. Special thanks to Aurélien!! You're so kind. Smiley

    • 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