Home > Community > Forums > Custom IC SKILL > Cadence Skill - Totally Buggy?


* Required Fields

Recipients email * (separate multiple addresses with commas)

Your name *

Your email *

Message *

Contact Us

* Required Fields
First Name *

Last Name *

Email *

Company / Institution *

Comments: *

 Cadence Skill - Totally Buggy? 

Last post Mon, Nov 2 2009 1:25 AM by Andrew Beckett. 5 replies.
Started by cado 30 Oct 2009 04:16 AM. Topic has 5 replies and 3620 views
Page 1 of 1 (6 items)
Sort Posts:
  • Fri, Oct 30 2009 4:16 AM

    • cado
    • Not Ranked
    • Joined on Fri, Oct 30 2009
    • Posts 4
    • Points 95
    Cadence Skill - Totally Buggy? Reply

    skill evaluates 0.142-0.142 as follows 

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

    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 => 


    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?
    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)          
     wlist=cons(width wlist)
     printf("%s %f\n" "Rectangle width= " nwidth)
    ) ;if x~>width!=nil
    ) ;if M4
    ) ; foreach shape
    printf( "%s %s\n" "cell: " cell)

    if(w>=0.7 then
     foreach(mpl mapwlist
      if(w==mpl then match++)
      if(match>0 then return(w)
         foreach(mpl mapwlist
          dlist=cons(diff dlist)
           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
          ) ;foreach mpl
          ) ;if match>0
          ) ;if w>0.7
          ) ;prog

    Filed under:
    • Post Points: 35
  • Fri, Oct 30 2009 9:54 AM

    Re: Cadence Skill - Totally Buggy? Reply
    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


    • Post Points: 5
  • Fri, Oct 30 2009 11:08 AM

    • Riad KACED
    • Not Ranked
    • Joined on Thu, Jul 17 2008
    • Hillsboro, OR
    • Posts 14
    • Points 385
    Re: Cadence Skill - Totally Buggy? Reply


    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.





    • Post Points: 35
  • Fri, Oct 30 2009 11:41 AM

    Re: Cadence Skill - Totally Buggy? Reply
    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.


    • Post Points: 5
  • Sun, Nov 1 2009 10:19 PM

    • cado
    • Not Ranked
    • Joined on Fri, Oct 30 2009
    • Posts 4
    • Points 95
    Re: Cadence Skill - Totally Buggy? Reply

    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! :-) 

    Filed under:
    • Post Points: 20
  • Mon, Nov 2 2009 1:25 AM

    Re: Cadence Skill - Totally Buggy? Reply

    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":

      let((mapwlist mindiff closestw)
        ; Return value of the if is the closest w
        if(w>=0.7 then
          foreach(mpw mapwlist
    	when(!mindiff || delta<mindiff
    	) ; when
          ) ; foreach
        ) ; if
      ) ; let
    ) ; procedure




    • Post Points: 5
Page 1 of 1 (6 items)
Sort Posts:
Started by cado at 30 Oct 2009 04:16 AM. Topic has 5 replies.