• 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. Cadence Skill - Totally Buggy?

Stats

  • Locked Locked
  • Replies 5
  • Subscribers 144
  • Views 2308
  • 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

Cadence Skill - Totally Buggy?

cado
cado over 15 years ago

skill evaluates 0.142-0.142 as follows 

||(0.142 - 0.142)
||difference --> -5.273559e-16
 
and 

if(0.142==0.142) as 

||(0.142 == 0.142)
||equal --> nil
 

Is SKILL mad? 
 
min(1,2,3) gives you 1 

but make a list list1='(1,2,3) 

then min(list1) gives you => 

(1,2,3)! 

in SKILL -5.273559e-16 & 0 are the SAME!!! 

and 0.142 is not equal to 0.142!!! 
 
Could anyone try the following script and tell me about the problem?
 
cv=geGetEditCellView()
cell=cv~>cellName
wlist=list()
foreach(x cv~>shapes if(x~>lpp==list("M4" "drawing") then if(x~>width!=nil then wlist=cons(x~>width wlist) nwidth=mapw(x~>width)  
        printf("%s %f\n" "path width= " nwidth)          
        else
 bbx=x~>bBox
 ll=lowerLeft(bbx)
 ur=upperRight(bbx)
 lly=yCoord(ll)
 ury=yCoord(ur)
 llx=xCoord(ll)
 urx=xCoord(ur)
 lx=urx-llx
 ly=ury-lly
 width=min(lx,ly)
 wlist=cons(width wlist)
 nwidth=mapw(width)
 printf("%s %f\n" "Rectangle width= " nwidth)
) ;if x~>width!=nil
) ;if M4
) ; foreach shape
printf( "%s %s\n" "cell: " cell)

procedure(mapw(w)
mapwlist='(0.052,0.066,0.072,0.09,0.1,0.142,0.23)
prog(()
if(w>=0.7 then
 return(w)
 else
 match=0
 foreach(mpl mapwlist
  if(w==mpl then match++)
  )
  if(match>0 then return(w)
     else
     dlist=list()
     foreach(mpl mapwlist
      diff=abs(w-mpl)
      dlist=cons(diff dlist)
      )
       mindiff=()
       dls=0.0
       for(i 0 length(dlist)-1  dls=nth(i dlist)
      if(i!=0 then dlspre=nth(i-1 dlist)
         if(dls>dlspre then  mindiff=dlspre else mindiff=dls) else mindiff=dls)
         )    
     
      foreach(mpl mapwlist
       if(abs(w-mpl)==mindiff then
           return(mpl)
          )
            
      ) ;foreach mpl
      ) ;if match>0
      ) ;if w>0.7
      ) ;prog

)
  • Cancel
Parents
  • Andrew Beckett
    Andrew Beckett over 15 years ago

    There are indeed rounding errors in the code (try putting:

      printf("Original Width= %.16f\n" width)

    before the call to mapw(). However, that's not the real problem - it's the fact that your algorithm for finding mindiff is totally wrong! For a start, it's horrendously inefficient:

    1. You traverse the list once to check for an exact match
    2. You traverse the list again finding all the differences from w
    3. You use a for loop to traverse the difference list, using nth() to access each index - which in turn traverses the list from scratch. You should never use nth() within a for loop - that's what foreach is for. Otherwise it's O(N^2) - which is inefficient.
    4. You compare against nth(i-1 dlist) - so again traverse the list within the list - and find if the current difference is bigger than the previous difference - if it is, you set mindiff to be the previous difference. Can't see what purpose this is - it's going to give you the second to last difference in the list in this case (and since the list is reversed, this corresponds to the second entry in mapwlist, i.e. 0.066). A few printf's in the code show that it's getting things wrong.
    5. Then you traverse the list again checking the differences against the found mindiff to find which matches.

    So that's many traversals of the list (including list traversals within list traversals), and an incorrect algorithm. In addition, you should name your functions with a sensible prefix - there's a global name space, and Cadence uses functions with rather similar names - e.g. mapc, map, maplist, mapcar, mapcan - so there's a high risk of clashing with a Cadence function.

    You also should define the function before it's used...

    Anyway, here's a better (simpler and more efficient) implementation of "CADOmapw":

    procedure(CADOmapw(w)
      let((mapwlist mindiff closestw)
        mapwlist='(0.052,0.066,0.072,0.09,0.1,0.142,0.23)
        ;--------------------------------------------------------------------
        ; Return value of the if is the closest w
        ;--------------------------------------------------------------------
        if(w>=0.7 then
          w
        else
          foreach(mpw mapwlist
    	delta=abs(w-mpw)
    	when(!mindiff || delta<mindiff
    	  closestw=mpw
    	  mindiff=delta
    	) ; when
          ) ; foreach
          closestw
        ) ; if
      ) ; let
    ) ; procedure
    

     

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • Andrew Beckett
    Andrew Beckett over 15 years ago

    There are indeed rounding errors in the code (try putting:

      printf("Original Width= %.16f\n" width)

    before the call to mapw(). However, that's not the real problem - it's the fact that your algorithm for finding mindiff is totally wrong! For a start, it's horrendously inefficient:

    1. You traverse the list once to check for an exact match
    2. You traverse the list again finding all the differences from w
    3. You use a for loop to traverse the difference list, using nth() to access each index - which in turn traverses the list from scratch. You should never use nth() within a for loop - that's what foreach is for. Otherwise it's O(N^2) - which is inefficient.
    4. You compare against nth(i-1 dlist) - so again traverse the list within the list - and find if the current difference is bigger than the previous difference - if it is, you set mindiff to be the previous difference. Can't see what purpose this is - it's going to give you the second to last difference in the list in this case (and since the list is reversed, this corresponds to the second entry in mapwlist, i.e. 0.066). A few printf's in the code show that it's getting things wrong.
    5. Then you traverse the list again checking the differences against the found mindiff to find which matches.

    So that's many traversals of the list (including list traversals within list traversals), and an incorrect algorithm. In addition, you should name your functions with a sensible prefix - there's a global name space, and Cadence uses functions with rather similar names - e.g. mapc, map, maplist, mapcar, mapcan - so there's a high risk of clashing with a Cadence function.

    You also should define the function before it's used...

    Anyway, here's a better (simpler and more efficient) implementation of "CADOmapw":

    procedure(CADOmapw(w)
      let((mapwlist mindiff closestw)
        mapwlist='(0.052,0.066,0.072,0.09,0.1,0.142,0.23)
        ;--------------------------------------------------------------------
        ; Return value of the if is the closest w
        ;--------------------------------------------------------------------
        if(w>=0.7 then
          w
        else
          foreach(mpw mapwlist
    	delta=abs(w-mpw)
    	when(!mindiff || delta<mindiff
    	  closestw=mpw
    	  mindiff=delta
    	) ; when
          ) ; foreach
          closestw
        ) ; if
      ) ; let
    ) ; procedure
    

     

    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