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 \*\*(exp: scala.Int): FixPt[S,I,F]
Integer exponentiation, implemented in hardware as a reduction tree with exp inputs.
|
|
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]): 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 apply(i: scala.Int): Bit
Returns the given bit in this value.
0 corresponds to the least significant bit (LSB).
|
|
def reverse: FixPt[S,I,F]
Returns a fixed point value with this value’s bits in reverse order.
|
|
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]) | |
---|---|