1Jan

Ufix 2

admin

Warning

Sufix® 832 Advanced Superline® Braid Fishing Line is the quietest, longest-casting, most abrasion-resistant round braid on the market, with virtually zero stretch for amazing feel. And at 32 weaves per inch, its 1 Gore® and 7 Dyneema® carriers together provide up to 30% greater palomar knot strength than other braids!

The SpinalHDL fixed point support is only partially used/tested, if you find any bugs with it or you think that some functionality is missing, please create a github issue. Also, please do not use undocumented features in production code.

Description¶

The UFix and SFix types correspond to a vector of bits that can be used for fixed point arithmetic.

Declaration¶

The syntax to declare a fixed point number is as follows:

Unsigned Fixed Point¶

Syntax

bit width

resolution

max

min

UFix(peak:ExpNumber, resolution:ExpNumber)

peak-resolution

2^resolution

2^peak-2^resolution

0

UFix(peak:ExpNumber, width:BitCount)

width

2^(peak-width)

2^peak-2^(peak-width)

0

Signed Fixed Point¶

Syntax

bit width

resolution

max

min

SFix(peak:ExpNumber, resolution:ExpNumber)

peak-resolution+1

2^resolution

2^peak-2^resolution

-(2^peak)

SFix(peak:ExpNumber, width:BitCount)

width

2^(peak-width-1)

2^peak-2^(peak-width-1)

-(2^peak)

Format¶

The chosen format follows the usual way of defining fixed point number format using Q notation. More information there).

For example Q8.2 will mean an fixed point of 8+2 bits, where 8 bit are used for the natural part and 2 bits for the fractional part.If the fixed point number is signed, one more bit is used for the sign.

The resolution is defined as being the smallest power of two that can be represented in this number.

Examples¶

Assignments¶

Valid Assignments¶

An assignment to a fixed point value is valid when there is no bit loss. Any bit loss will result in an error.

If the source fixed point value is too big, the .truncated function will allow you toresize the source number to match the destination size.

Example¶

From a Scala constant¶

Scala BigInts or Doubles can be used as constants when assigning to UFix or SFix signals.

Example¶

Raw value¶

The integer representation of the fixed point number can be read or written using theraw property.

Example¶

Operators¶

The following operators are available for the UFix type

Arithmetic¶

Operator

Description

Returned resolution

Returned amplitude

x + y

Addition

Min(x.resolution, y.resolution)

Max(x.amplitude, y.amplitude)

x - y

Subtraction

Min(x.resolution, y.resolution)

Max(x.amplitude, y.amplitude)

x * y

Multiplication

x.resolution * y.resolution)

x.amplitude * y.amplitude

x >> y

Arithmetic shift right, y : Int

x.amplitude >> y

x.resolution >> y

x << y

Arithmetic shift left, y : Int

x.amplitude << y

x.resolution << y

x >> y

Arithmetic shift right, y : Int

x.amplitude >> y

x.resolution

x << y

Arithmetic shift left, y : Int

x.amplitude << y

x.resolution

Comparison¶

Operator

Description

Return type

x y

Equality

Bool

x =/= y

Inequality

Bool

x > y

Greater than

Bool

x >= y

Greater than or equal

Bool

x > y

Less than

Bool

x >= y

Less than or equal

Bool

Type cast¶

Operator

Description

Return

x.asBits

Binary cast to Bits

Bits(w(x) bits)

x.asUInt

Binary cast to UInt

UInt(w(x) bits)

x.asSInt

Binary cast to SInt

SInt(w(x) bits)

x.asBools

Cast into a array of Bool

Vec(Bool,width(x))

x.toUInt

Return the corresponding UInt (with truncation)

UInt

x.toSInt

Return the corresponding SInt (with truncation)

SInt

x.toUFix

Return the corresponding UFix

UFix

x.toSFix

Return the corresponding SFix

SFix

Misc¶

Name

Return

Description

x.maxValue

Return the maximum value storable

Double

x.minValue

Saitek x36 driver for mac. Return the minimum value storable

Double

x.resolution

x.amplitude * y.amplitude

Double

Fixed-Point Data in Simulink

You can use the fixdt function in Simulink® to specify a fixed-point data type. The fixdt function creates a Simulink.NumericType object.

Fixed-Point Data Type and Scaling Notation

Simulink data type names must be valid MATLAB® identifierswith less than 128 characters. The data type name provides informationabout container type, number encoding, and scaling.

The following table provides a key for various symbols thatappear in Simulink products to indicate the data type and scalingof a fixed-point value.

Symbol

Description

Example

ContainerType

ufix

Unsigned fixed-point data type

ufix8 is an 8-bit unsigned fixed-pointdata type

sfix

Signed fixed-point data type

sfix128 is a 128-bit signed fixed-pointdata type

fltu

Scaled double override of an unsigned fixed-point datatype (ufix)

fltu32 is a scaled doubles overrideof ufix32

flts

Scaled double override of a signed fixed-point data type(sfix)

flts64 is a scaled doubles overrideof sfix64

NumberEncoding

e

10^

125e8 equals 125*(10^(8))

n

Negative

n31 equals -31

p

Decimal point

1p5 equals 1.5

p2 equals 0.2

ScalingEncoding

S

Slope

ufix16_S5_B7 is a 16-bit unsignedfixed-point data type with Slope of 5 and Bias of 7

B

Bias

ufix16_S5_B7 is a 16-bit unsignedfixed-point data type with Slope of 5 and Bias of 7

E

Fixed exponent (2^)

A negative fixed exponentdescribes the fraction length

sfix32_En31 is a 32-bit signed fixed-pointdata type with a fraction length of 31

F

Slope adjustment factor

ufix16_F1p5_En50 is a 16-bit unsignedfixed-point data type with a SlopeAdjustmentFactor of 1.5 anda FixedExponent of -50

C,c,D, or d

Compressed encoding for Bias

Note

If you pass this character vector to the slDataTypeAndScale function,it returns a valid fixdt data type.

No example available. For backwards compatibility only.

Toidentify and replace calls to slDataTypeAndScale,use the Check for calls to slDataTypeAndScale Model Advisorcheck.

T or t

Compressed encoding for Slope

Note

If you pass this character vector to the slDataTypeAndScale,it returns a valid fixdt data type.

No example available. For backwards compatibility only.

Toidentify and replace calls to slDataTypeAndScale,use the Check for calls to slDataTypeAndScale Model Advisorcheck.