Verilog-A built-in functions¶
Verilog-A provides useful and frequently used built-in functions which include math, noise, Laplace, limiting and smoothing functions. Comprehensive list of Verilog-A functions with examples are listed below :
Basic Arithmetic & Utility Functions¶
| Function | Description |
|---|---|
| abs(x) | Absolute value |
| max(x, y) | Maximum of two values |
| min(x, y) | Minimum of two values |
| ceil(x) | Smallest integer ≥ x |
| floor(x) | Largest integer ≤ x |
| round(x) | Round to nearest integer |
| pow(x, y) | x raised to power y |
| sqrt(x) | Square root |
| sign(x) | Sign of x (−1, 0, +1) |
| hypot(x,y) | √(x2+y2) |
Example of abs():
y = max(abs(x), 1e-6);
Example of hypot(x,y):
real i_comp, q_comp, magnitude;
analog begin
i_comp = V(in_i);
q_comp = V(in_q);
// Calculate magnitude: sqrt(I^2 + Q^2)
magnitude = hypot(i_comp, q_comp);
V(out) <+ magnitude;
end
Crucial Convergence Issues at x = 0 for sqrt(x)
In analog simulators (like Spectre or HSPICE), every function must have a continuous derivative to help the simulator converge on a solution. The derivative of sqrt(x) is:
$$\cfrac{d}{dx}\sqrt{x}=\cfrac{1}{2\sqrt{x}}$$
As x approaches 0, the derivative approaches infinity. This often causes the simulator to fail or "hang" because it cannot find a stable slope to follow.
Exponential & Logarithmic Functions¶
| Function | Description |
|---|---|
| exp(x) | eˣ |
| ln(x) | Natural logarithm |
| log(x) | Base-10 logarithm |
| limexp(x) | Limited exponential (numerically safe) |
Note
Always prefer limexp() in device models to avoid convergence issues.
Example of limexp():
I(p,n) <+ Is * (limexp(V(p,n)/Vt) - 1);
Trigonometric Functions¶
| Function | Description |
|---|---|
| sin(x) | Sine |
| cos(x) | Cosine |
| tan(x) | Tangent |
| asin(x) | Inverse sine |
| acos(x) | Inverse cosine |
| atan(x) | Inverse tangent |
| atan2(y, x) | Four-quadrant inverse tangent |
Example:
V(out) <+ A * sin(2*`M_PI*f*time);
M_PI is a built-in physical constant representing π.
Hyperbolic Functions¶
| Function | Description |
|---|---|
| sinh(x) | Hyperbolic sine |
| cosh(x) | Hyperbolic cosine |
| tanh(x) | Hyperbolic tangent |
| atanh(x) | Inverse hyperbolic tangent |
| asinh(x) | Inverse hyperbolic sine |
| acosh(x) | Inverse hyperbolic cosine |
Common use: soft limiting, saturation models
Example:
V(out) <+ Vmax * tanh(V(in)/Vmax);
Random & Statistical Functions¶
| Function | Description |
|---|---|
| random() | Uniform random number (0–1) |
| rdist_normal(mean, sigma) | Gaussian distribution |
| rdist_uniform(min, max) | Uniform distribution |
| rdist_poisson(lambda) | Poisson distribution |
Example:
offset = rdist_normal(0, sigma_offset);
Used in:
- mismatch modeling
- Monte-Carlo simulations
Time & Simulation Functions¶
| Function | Description |
|---|---|
| time | Current simulation time |
| abstime | Absolute time |
| realtime | Real-time variable |
Example:
V(out) <+ sin(2*`M_PI*f*time);
Derivative & Integral Functions¶
| Function | Description |
|---|---|
| ddt(x) | Time derivative (dx/dt) |
| idt(x, ic) | Time integral with initial condition |
Example:
I(p,n) <+ C * ddt(V(p,n));
Transition & Smoothing Functions¶
| Function | Description |
|---|---|
| transition(x, td, tr) | Smooth transition |
| slew(x, rate) | Slew-rate limiting |
Example:
V(out) <+ transition(Vin > Vth, 0, 1n);
Used for:
- comparators
- DACs
- digital-to-analog boundaries
Laplace & Frequency-Domain Functions¶
| Function | Description |
|---|---|
| laplace_zp(input, z[], p[], k) | Zero-pole form |
| laplace_nd(input, num[], den[]) | numerator-denominator form |
| laplace_zd(input, z[], d[]) | zero-denominator form |
| laplace_np(input, z[], p[], k) | numerator-pole form |
More about Laplace functions : Verilog-A Laplace Functions in Detail
Limiting & Protection Functions¶
| Function | Description |
|---|---|
| limit(x, min, max) | Hard limit |
| clip(x, min, max) | Hard clip |
Example:
V(out) <+ limit(Vin, -1.2, 1.2);
Noise Functions¶
Used to model physical noise sources.
- white_noise(psd, name)
- flicker_noise(psd, exponent, name)
Example:
I(p,n) <+ white_noise(4*P_K*temperature/R, "thermal");
Event and Crossing Functions¶
Used for mixed-signal and event-driven behavior.
- cross(expr, direction) – detect zero crossings
- timer(t) – periodic event trigger
Example:
@(cross(V(in)-Vth, +1)) begin
state = 1;
end