What is a compile-time operation

Is the cast of a param a run-time or a compile time operation. For example, given a const x of real(32), in the code sample

const t = x + 0.0:real(32);

Is that cast done at run time or compile time please?

As another example, is the bit-wise complement of a param uint(w) done at run-time or compile time?

Thanks.

Hi Damian --

Yes, 0.0:real(32) is a compile-time operation.

You can always find out if some operation on a param is a compile-time operation by trying to store it in a a new param.

use Math;

param x = 0.0:real(32); // no compilation error, so this cast is implemented as param

param y = ~1; // no compilation error, so ~ is implemented on param int 

param z = gcd(6, 12); // error: Initializing parameter 'z' to value not known at compile time

Let us know if you come across something that you expect to have a param result but gives the error like above.

2 Likes