• 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 2306
  • 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
  • Andrew Beckett
    Andrew Beckett over 15 years ago
    No, these are not bugs. I can't try the script because I'm on a train, but I can easily explain your first couple of issues.

    Given that your first point is showing trace output, you're observing the subtraction of two floating point numbers. As is common with most other programming languages (C included), floating point numbers are represented with IEEE double precision floating point format. This uses a 52 bit binary mantissa and 12 bit exponent. Because the fractional part is binary, you can very easily end up with a recurring fraction for a simple decimal number (so 0.1 decimal is actually a recurring fraction in binary). Consequently, in the same way that representing 1/3 in decimal ends up truncated, rounding errors can occur. Imagine you have 4 decimal digits of precision, doing the sum 1/3 * 10 - 3 should end up with 1/3 in fact it would be 0.3333 * 10 = 3.333 - 3 = 0.333. This is then NOT the same as 0.3333 - due to rounding errors.

    So you just have to be aware of rounding errors in any Computer floating point arithmetic.

    By default, SKILL shows numbers in output to something like 6 digits. You can use sstatus('fullPrecision t) to show them to 14 digits, but even then you may have rounding errors smaller than that.

    So SKILL is not mad; the two numbers you are observing are different right at the least significant end of the mantissa, and so are NOT equal (hence the difference you see). Displaying full precision in trace output would be very tedious and virtually not what you'd want most of the time.

    There are countless discussions of similar issues in every language you can find with a little light googling. Any rounding error you can get in SKILL, I can equally well reproduce in C, for example.

    For min(), it is not designed to be passed a list. Read the documentation. Instead you can use apply to pass the list as arguments to min. For example:

    Lst='(1 2 3)
    apply('min Lst) => 1

    Regards,

    Andrew
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Riad KACED
    Riad KACED over 15 years ago

    Hi,

    1. Generally speaking, you NEVER EVER match floating numbers as you did. Use booleans, integers but not floating numbers. This is true in all the languages. Andrew has explained the reasons why. BTW, there was a little tiny typo in Andrew's. The sstatus command is: 

     sstatus(fullPrecision t)

    i.e. with no tick '

    2. What's wrong with your Skill ? What is the problem you want us to check for you ? You could have put some comments in your code for people to get some clues. Well, I have tried your Skill and don't see any errors, it ran well. Have you had any errors at all ? If yes please post the message.

    Cheers,

    Riad.

     

     

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 15 years ago
    Er, whoops. Thanks Riad for catching my silly mistake with the tick. I'm sure I'd have not made that mistake if typing on a full-size screen rather than a hand-held device.

    Cheers,

    Andrew
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • cado
    cado over 15 years ago

    Thanks Berk....

    apply('min Lst)  works....

    but still there are issues....

    Actually I wanted to search for all"metal-4 drawing" layers, find their width, map it to the closest value in a specific list ("mapwlist") and print the newly mapped width. I made mapw function for mapping.It should have mapped a rectangle of 0.142 micron width to 0.142, instead it maps it to 0.066! I did a tracef() and found all these anomalies. I am sure it's not the issue with floating point round off.

    when I type mapw(0.142), it returns 0.142, but if I run the whole script, it maps 0.142 to 0.066.

     Please Help me if you know about this.

    Thanks in Advance! :-) 

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • 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

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