FixPt

FixPt[S,I,F] represents an arbitrary precision fixed point representation. FixPt values may be signed or unsigned. Negative values, if applicable, are represented in twos complement.

The type parameters for FixPt are:

S BOOL Signed representation TRUE | FALSE
I INT Number of integer bits (_1 - _64)
F INT | Number of fractional bits (_0 - _64)

Note that numbers of bits use the underscore prefix as integers cannot be used as type parameters in Scala.


Type Aliases

Specific types of FixPt values can be managed using type aliases. New type aliases can be created using syntax like the following:

type Q16_16 = FixPt[TRUE,_16,_16]

Spatial defines the following type aliases by default:

type IntN FixPt[TRUE,_N,_0] Signed, N bit integer (_2 - _128)
type UIntN FixPt[TRUE,_N,_0] Unsigned, N bit integer (_2 - _128)
type Char FixPt[TRUE,_8,_0] Signed, 8 bit integer
type Short FixPt[TRUE,_16,_0] Signed, 16 bit integer
type Int FixPt[TRUE,_32,_0] Signed, 32 bit integer
type Index FixPt[TRUE,_32,_0] Signed, 32 bit integer (indexing)
type Long FixPt[TRUE,_64,_0] Signed, 64 bit integer

Note that the Char, Short, Int, and Long types shadow their respective unstaged Scala types. In the case where an unstaged type is required, use the full scala.* name.


Infix methods

The following infix methods are defined on all FixPt classes. When the method takes a right hand argument, only values of the same FixPt class can be used for this argument.

class FixPt[S,I,F]
def unary_-(): FixPt[S,I,F]
Returns negation of this fixed point value.
def unary_~(): FixPt[S,I,F]
Returns bitwise inversion of this fixed point value.
def + (that: FixPt[S,I,F]): FixPt[S,I,F]
Fixed point addition.
def - (that: FixPt[S,I,F]): FixPt[S,I,F]
Fixed point subtraction.
def * (that: FixPt[S,I,F]): FixPt[S,I,F]
Fixed point multiplication.
def / (that: FixPt[S,I,F]): FixPt[S,I,F]
Fixed point division.
def % (that: FixPt[S,I,F]): FixPt[S,I,F]
Fixed point modulus.
def \*\*(exp: scala.Int): FixPt[S,I,F]
Integer exponentiation, implemented in hardware as a reduction tree with exp inputs.
def *& (that: FixPt[S,I,F]): FixPt[S,I,F]
Fixed point multiplication with unbiased rounding.

After multiplication, probabilistically rounds up or down to the closest representable number.
def /& (that: FixPt[S,I,F]): FixPt[S,I,F]
Fixed point division with unbiased rounding.

After division, probabilistically rounds up or down to the closest representable number.
def <+> (that: FixPt[S,I,F]): FixPt[S,I,F]
Saturating fixed point addition.

Addition which saturates at the largest or smallest representable number upon over/underflow.
def <-> (that: FixPt[S,I,F]): FixPt[S,I,F]
Saturating fixed point subtraction.

Subtraction which saturates at the largest or smallest representable number upon over/underflow.
def <*> (that: FixPt[S,I,F]): FixPt[S,I,F]
Saturating fixed point multiplication.

Multiplication which saturates at the largest or smallest representable number upon over/underflow.
def </> (that: FixPt[S,I,F]): FixPt[S,I,F]
Saturating fixed point division.

Division which saturates at the largest or smallest representable number upon over/underflow.
def <*&> (that: FixPt[S,I,F]): FixPt[S,I,F]
Saturating fixed point multiplication with unbiased rounding.

After multiplication, probabilistically rounds up or down to the closest representable number.
After rounding, also saturates at the largest or smallest representable number upon over/underflow.
def </&> (that: FixPt[S,I,F]): FixPt[S,I,F]
Saturating fixed point division with unbiased rounding.

After division, probabilistically rounds up or down to the closest representable number.
After rounding, also saturates at the largest or smallest representable number upon over/underflow.
def < (that: FixPt[S,I,F]): MBoolean
Less than comparison.

Returns true if this value is less than that value. Otherwise returns false.
def <=(that: FixPt[S,I,F]): MBoolean
Less than or equal comparison.

Returns true if this value is less than or equal to that value. Otherwise returns false.
def > (that: FixPt[S,I,F]): MBoolean
Greater than comparison

Returns true if this value is greater than that value. Otherwise returns false.
def >=(that: FixPt[S,I,F]): MBoolean
Greater than or equal comparison.

Returns true if this value is greater than or equal to that value. Otherwise returns false.
def !=(that: FixPt[S,I,F]): Boolean
Value inequality comparison.
Returns true if this value is not equal to the right hand side. Otherwise returns false.
def !=(that: FixPt[S,I,F]): Boolean
Value equality comparison.
Returns true if this value is equal to the right hand side. Otherwise returns false.
def & (that: FixPt[S,I,F]): FixPt[S,I,F]
Bit-wise AND.
def | (that: FixPt[S,I,F]): FixPt[S,I,F]
Bit-wise OR.
def ^ (that: FixPt[S,I,F]): FixPt[S,I,F]
Bit-wise XOR.
def <<(that: FixPt[S,I,_0]): FixPt[S,I,F]
Logical shift left.
def >>(that: FixPt[S,I,_0]): FixPt[S,I,F]
Arithmetic (sign-preserving) shift right.
def >>>(that: FixPt[S,I,_0]): FixPt[S,I,F]
Logical (zero-padded) shift right.
def as[T:Type:Bits]: T
Re-interprets this value’s bits as the given type, without conversion.
def apply(i: scala.Int): Bit
Returns the given bit in this value.
0 corresponds to the least significant bit (LSB).
def apply(range: Range): Vector[Bit]
Returns a vector of bits based on the given range.
The range must be statically determinable values.
def reverse: FixPt[S,I,F]
Returns a fixed point value with this value’s bits in reverse order.
def to[T:Type:Bits]: T
Converts this value to the given type.

Currently supported types are FixPt, FltPt, and String.
def toString: String
Creates a printable String representation of this value.

NOTE: This method is unsynthesizable, and can be used only on the CPU or in simulation.

Specialized infix methods

These methods are defined on only specific classes of FixPt values.

subclass Int (aliases: Index, FixPt[TRUE, _32, _0])
def ::(end: Int): Range
Creates a Range with this as the start (inclusive), the given end (noninclusive), and step of 1.
def by(step: Int): Range
Creates a Range with start of 0 (inclusive), this value as the end (noninclusive), and the given step.
def until(end: Int): Range
Creates a Range with this as the start (inclusive), the given end (noninclusive), and step of 1.