math
Modules
Abs #(int TO)
module Abs #(int TO) {
interface Abs : int #(FROM: -TO+1, TO) a -> int #(FROM: 0, TO) o
}Compute the Absolute Value of the given integer.
Examples:
Abs(3) == 3
Abs(-7) == 7
TreeAdd #(int WIDTH, int FROM, int TO)
module TreeAdd #(int WIDTH, int FROM, int TO) {
interface TreeAdd : int#(FROM, TO)[WIDTH] values'0 -> int#(FROM: FROM*WIDTH, TO: (TO - 1)*WIDTH + 1) total
}IntNarrow #(int FROM_I, int TO_I, int FROM, int TO)
module IntNarrow #(int FROM_I, int TO_I, int FROM, int TO) {
interface IntNarrow : int#(FROM: FROM_I, TO: TO_I) din'0 -> int#(FROM, TO) dout'0
}Unsafely shrinks the bounds of an integer.
The result is not defined if the value lies outside the FROM:TO range.
For folding behavior choose the mod operator instead.
Compile-Time Functions
clog2 #(int V)
const int clog2 #(int V)Computes the Base 2 logarithm of a value, rounded up.
Typically used to find the size in bits that the address would need to be to address into a memory of size V.
Requires V > 0
Examples:
clog2 #(V: 15) == 4
clog2 #(V: 16) == 4
clog2 #(V: 17) == 5
pow2 #(int E)
const int pow2 #(int E)Computes 2^E at compile-time
pow #(int B, int E)
const int pow #(int B, int E)Computes B^E at compile-time
nextPow2 #(int V)
const int nextPow2 #(int V)Returns the smallest power of two greater or equal to the input value. nextPow2#(V) >= V.
factorial #(int N)
const int factorial #(int N)Computes N!
falling_factorial #(int N, int K)
const int falling_factorial #(int N, int K)Computes N! / (N - K)!. for 0 <= K <= N
comb #(int N, int K)
const int comb #(int N, int K)Computes N! / (K! * (N - K)!). for 0 <= K <= N
min #(int A, int B)
const int min #(int A, int B)Compute the minimum of A and B
max #(int A, int B)
const int max #(int A, int B)Compute the maximum of A and B