• 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. Less than operator (lessp, <) gives an error (containing...

Stats

  • Locked Locked
  • Replies 4
  • Subscribers 144
  • Views 3743
  • 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

Less than operator (lessp, <) gives an error (containing srrWave keyword) inside a procedure

baltacican
baltacican over 3 years ago

Hello,

I use  Virtuoso IC6.1.8.

I am quite new in SKILL. I wrote a procedure and got the following error:

ERROR (VIVA-3002):expression evaluation failed: val is not legal.
ERROR (VIVA-3002):expression evaluation failed: comparator(vsig_sampled 0.5)
("lessp" 0 t nil ("*Error* lessp: can't handle (srrWave:0x3e9c5540 < 0.5)"))

The procedure that gives the error above is the following:

procedure( comparator(wave threshold)

yVec = drGetWaveformYVec(wave)

i = 0

while(i < drVectorLength(yVec)

if( drGetElem(yVec i) < threshold then

drSetElem(yVec i 0)

else

drSetElem(yVec i 1)

);if

i=i+1

);while

drCreateWaveform(drGetWaveformXVec(wave) yVec)

);procedure

It is supposed to take a waveform and a threshold as the input arguments, then compare each elements of the y-vector of the waveform with the thresold argument and return to a new waveform that provides the comparison result. Below, you can find further details on how I use the procedure in the calculator/outputs and in which scenario it gives the error.

The schematic is very simple, just a square wave generator, connected to net vsig:

Before invoking comparator(), the following outputs are calculated in Assembler and can be observed on the screenshot below:

vsig = VT("/vsig")

vsig_sampled = value(vsig 0 ?period 5e-07 ?xName "cycle")

comparator() is used in the following output, which gives the error above.

vsig_sampled_saturated = comparator(vsig_sampled 0.5)

When I calculate comparator(vsig_sampled 0.5) in the calculator, I get the error. Could you please help me to find why it doesn't work?

Many thanks in advance.

Best regards,

Can

p.s. I made some other observations that are quite strange. First, the results window in Assembler doesn't give any calculation errors for vsig_sampled_saturated. I also don't get an error in CIW.

I get the error if I double click on the waveform to plot or when I calculate it in the calculator.

Second, I use the vsig_sampled_saturated output, which gives an error, in another output expression and the result is correctly calculated (forth output on the above screenshot):

vsig_count = countOccurrence(vsig_sampled_saturated 1)

The countOccurrence procedure is the following:

procedure( countOccurrence(wave yVal)

yVec = drGetWaveformYVec(wave)

i = 0

count = 0

while(i < drVectorLength(yVec)

if( drGetElem(yVec i) == yVal then

count = count + 1

);if

i=i+1

);while

count

);procedure

 

How can vsig_count be calculated if vsig_sampled_saturated has an error?

  • Cancel
Parents
  • Andrew Beckett
    Andrew Beckett over 3 years ago

    Your functions need to be able to handle families of waveforms as well as waveforms - at the moment, they don't. When plotting something in ADE, it will evaluate with the entire set of results for each signal, and so will see a family - your code needs to always cater for that. See this simple example to see the pattern. I've rewritten your two functions to do this, and used a for loop instead of while. It's also a good idea to create a new vector rather than overwriting the value in place as that can have unintended side effects.

    I think these should work:

    procedure( comparator(wave threshold)
      let((yVec newYVec)
        cond(
          (drIsWaveform(wave)
            yVec = drGetWaveformYVec(wave)
            newYVec = drCreateVec('double drVectorLength(yVec))
            for(i 0 drVectorLength(yVec)-1
              if( drGetElem(yVec i) < threshold then
                drSetElem(newYVec i 0)
              else
                drSetElem(newYVec i 1)
              );if
            );for
            drCreateWaveform(drGetWaveformXVec(wave) newYVec)
          )
          (famIsFamily(wave)
            famMap('comparator wave threshold)
          )
          (t
            error("comparator: cannot handle %L\n" wave)
          )
        )
      )
    )
    
    procedure( countOccurrence(wave yVal)
      let((yVec (count 0))
        cond(
          (drIsWaveform(wave)
            yVec = drGetWaveformYVec(wave)
            for(i 0 drVectorLength(yVec)-1
              when(nearlyEqual(drGetElem(yVec i) yVal)
                count++
              )
            )
            count
          )
          (famIsFamily(wave)
            famMap('countOccurrence wave yVal)
          )
          (t
            error("countOccurrence: cannot handle %L\n" wave)
          )
        )
      )
    )

    Andrew

    • Cancel
    • Vote Up +1 Vote Down
    • Cancel
  • baltaci
    baltaci over 3 years ago in reply to Andrew Beckett

    Hi Andrew,

    Thank you very much for your response. It worked and besides it was very educative.

    Finally, I would like to learn if the way I wrote the code was efficient in terms of execution speed. More generally, are there ways and tricks to make the code run faster? For example, in Matlab, we usually try to avoid for loops and solve the problems using matrix operation. Does this (or something similar to this) also apply to SKILL? If this is the case, could you recommend a source where I can find further information?

    Best regards,

    Can

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 3 years ago in reply to baltaci
    baltaci said:
    Finally, I would like to learn if the way I wrote the code was efficient in terms of execution speed

    There are a number of functions that already work on waveform objects and avoid the need to have to loop over each element to do something. However, in this case that can't be avoided. There isn't the same concept as having matrices and vectors which can be efficiently processed in SKILL (there are waveforms which many operators have been overloaded to handle, but not for every operation).

    In general there's a section in the SKILL Language User Guide on Optimizing SKILL. I also talk a bit about it in my Writing Good SKILL Code (Video)

    Andrew

    • Cancel
    • Vote Up +1 Vote Down
    • Cancel
Reply
  • Andrew Beckett
    Andrew Beckett over 3 years ago in reply to baltaci
    baltaci said:
    Finally, I would like to learn if the way I wrote the code was efficient in terms of execution speed

    There are a number of functions that already work on waveform objects and avoid the need to have to loop over each element to do something. However, in this case that can't be avoided. There isn't the same concept as having matrices and vectors which can be efficiently processed in SKILL (there are waveforms which many operators have been overloaded to handle, but not for every operation).

    In general there's a section in the SKILL Language User Guide on Optimizing SKILL. I also talk a bit about it in my Writing Good SKILL Code (Video)

    Andrew

    • Cancel
    • Vote Up +1 Vote Down
    • Cancel
Children
  • baltaci
    baltaci over 3 years ago in reply to Andrew Beckett

    Hi Andrew,

    Many thanks for the explanations and the link of the video.

    Best regards,

    Can

    • 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