Name Strings
SPV_ALTERA_arbitrary_precision_fixed_point
Contact
To report problems with this extension, please open a new issue at:
Contributors
-
Ajaykumar Kannan, Intel
-
Shuo Niu, Intel
-
Daniel Zhang, Intel
Notice
Copyright (c) 2023 Intel Corporation
Status
Final draft
Version
Last Modified Date |
2023-03-21 |
Revision |
1 |
Dependencies
This extension is written against the SPIR-V Specification Version 1.6, Revision 2.
While this extension does not require SPV_ALTERA_arbitrary_precision_integers, the new operators it adds are significantly more useful when that extension is supported as the combination of the two extensions allows for more freedom in the width of arbitrary precision data types that can be represented (see the definition of the W parameter below).
This extension is built on Mentor Graphics ac_datatypes spec v3.9.2.
Overview
This extension introduces operations for arbitrary precision fixed point numbers called ac_fixed. The ac_fixed datatype is an industry standard for fixed point numbers and is published by Mentor Graphics at hlslibs.org. This datatype and its corresponding operations can be useful on targets that can take advantage of narrower representation such as FPGAs.
Data Representation
The ac_fixed datatype will be represented in SPIR-V as a pseudo type using OpTypeInt.
It is characterized by three parameters: W, I, and S.
-
Wis the total width of the datatype (including a sign bit, if required) and is encoded in the width of the OpTypeInt. -
Idetermines the position of the decimal point.-
When
I>= 0,Ibits starting from the MSB ofWare before the decimal point. IfIis greater thanW, then additional 0 bits are implied after the bits ofWand before the decimal point. -
When
I< 0,-I0 bits are implied after the decimal point and before the MSB ofW.
-
-
Sdetermines if this is a signed or an unsigned number. Note that the support for signedness in OpTypeInt is not leveraged here. If the ac_fixed is signed, then the MSB (most significant bit) will contain the sign bit.
The datatype itself does not contain any information regarding I and S.
Each operation will contain information about the input and result datatypes (including W, S, and I) where W is implicit from the size of the OpTypeInt.
A variable of ac_fixed type can contain both an integer component and a fractional component depending on the value of I.
Based on its value, the number of bits allocated for the integer and fractional portions will change.
Note that it is also possible that one of the two portions may have no bits.
Extension Name
To use this extension within a SPIR-V module, the following OpExtension must be present in the module:
OpExtension "SPV_ALTERA_arbitrary_precision_fixed_point"
New Capabilities
This extension introduces a new capability:
ArbitraryPrecisionFixedPointALTERA
New Instructions
Instructions added under the ArbitraryPrecisionFixedPointALTERA capability:
OpFixedSqrtALTERA OpFixedRecipALTERA OpFixedRsqrtALTERA OpFixedSinALTERA OpFixedCosALTERA OpFixedSinCosALTERA OpFixedSinPiALTERA OpFixedCosPiALTERA OpFixedSinCosPiALTERA OpFixedLogALTERA OpFixedExpALTERA
Token Number Assignments
ArbitraryPrecisionFixedPointALTERA |
5922 |
OpFixedSqrtALTERA |
5923 |
OpFixedRecipALTERA |
5924 |
OpFixedRsqrtALTERA |
5925 |
OpFixedSinALTERA |
5926 |
OpFixedCosALTERA |
5927 |
OpFixedSinCosALTERA |
5928 |
OpFixedSinPiALTERA |
5929 |
OpFixedCosPiALTERA |
5930 |
OpFixedSinCosPiALTERA |
5931 |
OpFixedLogALTERA |
5932 |
OpFixedExpALTERA |
5933 |
Modifications to the SPIR-V Specification Version 1.6
After Section 3.16, add a new section "3.16b Quantization Modes" as follows:
Quantization Modes
| Value | Mode | Behavior | Enabling Capabilities |
|---|---|---|---|
0 |
TRN_ALTERA |
Truncate towards -Inf |
ArbitraryPrecisionFixedPointALTERA |
1 |
TRN_ZERO_ALTERA |
Truncate towards 0 |
ArbitraryPrecisionFixedPointALTERA |
2 |
RND_ALTERA |
Round towards +Inf |
ArbitraryPrecisionFixedPointALTERA |
3 |
RND_ZERO_ALTERA |
Round towards 0 |
ArbitraryPrecisionFixedPointALTERA |
4 |
RND_INF_ALTERA |
Round positive values toward +Inf and negative values toward -Inf |
ArbitraryPrecisionFixedPointALTERA |
5 |
RND_MIN_INF_ALTERA |
Round towards -Inf |
ArbitraryPrecisionFixedPointALTERA |
6 |
RND_CONV_ALTERA |
Round towards even |
ArbitraryPrecisionFixedPointALTERA |
7 |
RND_CONV_ODD_ALTERA |
Round towards odd |
ArbitraryPrecisionFixedPointALTERA |
After Section 3.16, add a new section "3.16c Overflow Modes" as follows:
Overflow Modes
| Value | Mode | Behavior | Enabling Capabilities |
|---|---|---|---|
0 |
WRAP_ALTERA |
Drop the bits to the left of the MSB |
ArbitraryPrecisionFixedPointALTERA |
1 |
SAT_ALTERA |
Saturate to the closest of MIN or MAX |
ArbitraryPrecisionFixedPointALTERA |
2 |
SAT_ZERO_ALTERA |
Set to 0 on overflow |
ArbitraryPrecisionFixedPointALTERA |
3 |
SAT_SYM_ALTERA |
For unsigned, treat as SAT_ALTERA. For signed: a positive overflow will saturate at the maximum positive value, whereas a negative overflow will saturate to the negation of the maximum positive value, as opposed to the most negative value. |
ArbitraryPrecisionFixedPointALTERA |
After Section 3.16, add a new section "3.16d Signedness Modes" as follows:
Signedness Modes
| Value | Mode | Behavior | Enabling Capabilities |
|---|---|---|---|
0 |
UNSIGNED_ALTERA |
Input and result types are unsigned |
ArbitraryPrecisionFixedPointALTERA |
1 |
SIGNED_ALTERA |
Input and result types are signed |
ArbitraryPrecisionFixedPointALTERA |
Capability
Modify Section 3.31, Capability, adding a row to the Capability table:
| Capability | Implicitly Declares | |
|---|---|---|
5922 |
ArbitraryPrecisionFixedPointALTERA Enables arbitrary precision fixed-point math instructions. |
|
Instructions
In Section 3.32.13, Arithmetic Instructions, add the following instructions:
OpFixedSqrtALTERA An OpTypeInt representing an arbitrary precision fixed point number (ac_fixed) is passed in as the Input and the square root of the value is returned in Result. The behavior of this function is undefined for input values < 0. Result Type must be OpTypeInt. Result is the <id> of the operation’s result, which is an arbitrary precision fixed point number. S is chosen from Table 3.16d that indicates the Signedness Mode of the input and output types. I is a signed 32-bit integer that refers to the location of the fixed-point relative to the MSB of the input type. rI is a signed 32-bit integer that refers to the location of the fixed-point relative to the MSB of the result type. Q is a QuantizationMode enum chosen from Table 3.16b that indicates the Quantization Mode of this operation. O is an OverflowMode enum chosen from Table 3.16c that indicates the Overflow Mode of this operation. |
Capability: ArbitraryPrecisionFixedPointALTERA |
||||||||
9 |
5923 |
<id> Result Type |
Result <id> |
Input <id> |
Signedness S |
Literal I |
Literal rI |
QuatntizationMode Q |
OverflowMode O |
OpFixedRecipALTERA An OpTypeInt representing an arbitrary precision fixed point number (ac_fixed) is passed in as the Input and the reciprocal ( Result Type must be OpTypeInt. Result is the <id> of the operation’s result, which is an arbitrary precision fixed point number. S is chosen from Table 3.16d that indicates the Signedness Mode of the input and output types. I is a signed 32-bit integer that refers to the location of the fixed-point relative to the MSB of the input type. rI is a signed 32-bit integer that refers to the location of the fixed-point relative to the MSB of the result type. Q is a QuantizationMode enum chosen from Table 3.16b that indicates the Quantization Mode of this operation. O is an OverflowMode enum chosen from Table 3.16c that indicates the Overflow Mode of this operation. |
Capability: ArbitraryPrecisionFixedPointALTERA |
||||||||
9 |
5924 |
<id> Result Type |
Result <id> |
Input <id> |
Signedness S |
Literal I |
Literal rI |
QuatntizationMode Q |
OverflowMode O |
OpFixedRsqrtALTERA An OpTypeInt representing an arbitrary precision fixed point number (ac_fixed) is passed in as the Input and the reciprocal square root ( Result Type must be OpTypeInt. Result is the <id> of the operation’s result, which is an arbitrary precision fixed point number. S is chosen from Table 3.16d that indicates the Signedness Mode of the input and output types. I is a signed 32-bit integer that refers to the location of the fixed-point relative to the MSB of the input type. rI is a signed 32-bit integer that refers to the location of the fixed-point relative to the MSB of the result type. Q is a QuantizationMode enum chosen from Table 3.16b that indicates the Quantization Mode of this operation. O is an OverflowMode enum chosen from Table 3.16c that indicates the Overflow Mode of this operation. |
Capability: ArbitraryPrecisionFixedPointALTERA |
||||||||
9 |
5925 |
<id> Result Type |
Result <id> |
Input <id> |
Signedness S |
Literal I |
Literal rI |
QuatntizationMode Q |
OverflowMode O |
OpFixedSinALTERA An OpTypeInt representing an arbitrary precision fixed point number (ac_fixed) is passed in as the Input and the sine of the value is returned in Result. Note that the angles are measured in radians. Result Type must be OpTypeInt. Result is the <id> of the operation’s result, which is an arbitrary precision fixed point number. S is chosen from Table 3.16d that indicates the Signedness Mode of the input and output types. I is a signed 32-bit integer that refers to the location of the fixed-point relative to the MSB of the input type. rI is a signed 32-bit integer that refers to the location of the fixed-point relative to the MSB of the result type. Q is a QuantizationMode enum chosen from Table 3.16b that indicates the Quantization Mode of this operation. O is an OverflowMode enum chosen from Table 3.16c that indicates the Overflow Mode of this operation. |
Capability: ArbitraryPrecisionFixedPointALTERA |
||||||||
9 |
5926 |
<id> Result Type |
Result <id> |
Input <id> |
Signedness S |
Literal I |
Literal rI |
QuatntizationMode Q |
OverflowMode O |
OpFixedCosALTERA An OpTypeInt representing an arbitrary precision fixed point number (ac_fixed) is passed in as the Input and the cosine of the value is returned in Result. Note that the angles are measured in radians. Result Type must be OpTypeInt. Result is the <id> of the operation’s result, which is an arbitrary precision fixed point number. S is chosen from Table 3.16d that indicates the Signedness Mode of the input and output types. I is a signed 32-bit integer that refers to the location of the fixed-point relative to the MSB of the input type. rI is a signed 32-bit integer that refers to the location of the fixed-point relative to the MSB of the result type. Q is a QuantizationMode enum chosen from Table 3.16b that indicates the Quantization Mode of this operation. O is an OverflowMode enum chosen from Table 3.16c that indicates the Overflow Mode of this operation. |
Capability: ArbitraryPrecisionFixedPointALTERA |
||||||||
9 |
5927 |
<id> Result Type |
Result <id> |
Input <id> |
Signedness S |
Literal I |
Literal rI |
QuatntizationMode Q |
OverflowMode O |
OpFixedSinCosALTERA An OpTypeInt representing an arbitrary precision fixed point number (ac_fixed) is passed in as the Input and both the sine and cosine of the value are returned in Result. Note that the angles are measured in radians. Result Type must be a two-component vector of OpTypeInt. The first component of the Result contains the sine of the Input and is an arbitrary fixed point number. The second component of the Result contains the cosine of the Input and is also an arbitrary fixed point number. S is chosen from Table 3.16d that indicates the Signedness Mode of the input and output types. I is a signed 32-bit integer that refers to the location of the fixed-point relative to the MSB of the input type. rI is a signed 32-bit integer that refers to the location of the fixed-point relative to the MSB of each component of the result type. Q is a QuantizationMode enum chosen from Table 3.16b that indicates the Quantization Mode of this operation. O is an OverflowMode enum chosen from Table 3.16c that indicates the Overflow Mode of this operation. |
Capability: ArbitraryPrecisionFixedPointALTERA |
||||||||
9 |
5928 |
<id> Result Type |
Result <id> |
Input <id> |
Signedness S |
Literal I |
Literal rI |
QuatntizationMode Q |
OverflowMode O |
OpFixedSinPiALTERA An OpTypeInt representing an arbitrary precision fixed point number (ac_fixed) is passed in as the Input and the sine of pi * Input is returned in Result. Note that the angles are measured in radians. Result Type must be OpTypeInt. Result is the <id> of the operation’s result, which is an arbitrary precision fixed point number. S is chosen from Table 3.16d that indicates the Signedness Mode of the input and output types. I is a signed 32-bit integer that refers to the location of the fixed-point relative to the MSB of the input type. rI is a signed 32-bit integer that refers to the location of the fixed-point relative to the MSB of the result type. Q is a QuantizationMode enum chosen from Table 3.16b that indicates the Quantization Mode of this operation. O is an OverflowMode enum chosen from Table 3.16c that indicates the Overflow Mode of this operation. |
Capability: ArbitraryPrecisionFixedPointALTERA |
||||||||
9 |
5929 |
<id> Result Type |
Result <id> |
Input <id> |
Signedness S |
Literal I |
Literal rI |
QuatntizationMode Q |
OverflowMode O |
OpFixedCosPiALTERA An OpTypeInt representing an arbitrary precision fixed point number (ac_fixed) is passed in as the Input and the cosine of pi * Input is returned in Result. Note that the angles are measured in radians. Result Type must be OpTypeInt. Result is the <id> of the operation’s result, which is an arbitrary precision fixed point number. S is chosen from Table 3.16d that indicates the Signedness Mode of the input and output types. I is a signed 32-bit integer that refers to the location of the fixed-point relative to the MSB of the input type. rI is a signed 32-bit integer that refers to the location of the fixed-point relative to the MSB of the result type. Q is a QuantizationMode enum chosen from Table 3.16b that indicates the Quantization Mode of this operation. O is an OverflowMode enum chosen from Table 3.16c that indicates the Overflow Mode of this operation. |
Capability: ArbitraryPrecisionFixedPointALTERA |
||||||||
9 |
5930 |
<id> Result Type |
Result <id> |
Input <id> |
Signedness S |
Literal I |
Literal rI |
QuatntizationMode Q |
OverflowMode O |
OpFixedSinCosPiALTERA An OpTypeInt representing an arbitrary precision fixed point number (ac_fixed) is passed in as the Input and both the sine and cosine of pi * Input are returned in Result. Note that the angles are measured in radians. Result Type must be a two-component vector of OpTypeInt. The first component of the Result contains the sine of the Input and is an arbitrary fixed point number. The second component of the Result contains the cosine of the Input and is also an arbitrary fixed point number. S is chosen from Table 3.16d that indicates the Signedness Mode of the input and output types. I is a signed 32-bit integer that refers to the location of the fixed-point relative to the MSB of the input type. rI is a signed 32-bit integer that refers to the location of the fixed-point relative to the MSB of each component of the result type. Q is a QuantizationMode enum chosen from Table 3.16b that indicates the Quantization Mode of this operation. O is an OverflowMode enum chosen from Table 3.16c that indicates the Overflow Mode of this operation. |
Capability: ArbitraryPrecisionFixedPointALTERA |
||||||||
9 |
5931 |
<id> Result Type |
Result <id> |
Input <id> |
Signedness S |
Literal I |
Literal rI |
QuatntizationMode Q |
OverflowMode O |
OpFixedLogALTERA An OpTypeInt representing an arbitrary precision fixed point number (ac_fixed) is passed in as the Input and the log of the value is returned in Result. Result Type must be OpTypeInt. Result is the <id> of the operation’s result, which is an arbitrary precision fixed point number. S is chosen from Table 3.16d that indicates the Signedness Mode of the input and output types. I is a signed 32-bit integer that refers to the location of the fixed-point relative to the MSB of the input type. rI is a signed 32-bit integer that refers to the location of the fixed-point relative to the MSB of the result type. Q is a QuantizationMode enum chosen from Table 3.16b that indicates the Quantization Mode of this operation. O is an OverflowMode enum chosen from Table 3.16c that indicates the Overflow Mode of this operation. |
Capability: ArbitraryPrecisionFixedPointALTERA |
||||||||
9 |
5932 |
<id> Result Type |
Result <id> |
Input <id> |
Signedness S |
Literal I |
Literal rI |
QuatntizationMode Q |
OverflowMode O |
OpFixedExpALTERA An OpTypeInt representing an arbitrary precision fixed point number (ac_fixed) is passed in as the Input and the exp of the value is returned in Result. Result Type must be OpTypeInt. Result is the <id> of the operation’s result, which is an arbitrary precision fixed point number. S is chosen from Table 3.16d that indicates the Signedness Mode of the input and output types. I is a signed 32-bit integer that refers to the location of the fixed-point relative to the MSB of the input type. rI is a signed 32-bit integer that refers to the location of the fixed-point relative to the MSB of the result type. Q is a QuantizationMode enum chosen from Table 3.16b that indicates the Quantization Mode of this operation. O is an OverflowMode enum chosen from Table 3.16c that indicates the Overflow Mode of this operation. |
Capability: ArbitraryPrecisionFixedPointALTERA |
||||||||
9 |
5933 |
<id> Result Type |
Result <id> |
Input <id> |
Signedness S |
Literal I |
Literal rI |
QuatntizationMode Q |
OverflowMode O |
Validation Rules
None.
Issues
None.
Revision History
| Rev | Date | Author | Changes |
|---|---|---|---|
1 |
2023-03-21 |
Ajaykumar Kannan |
Initial Public Release |