SPV_ALTERA_arbitrary_precision_fixed_point
SPV_ALTERA_arbitrary_precision_fixed_point
Table of Contents
Name Strings
Contact
Contributors
Notice
Status
Version
Dependencies
Overview
Extension Name
New Capabilities
New Instructions
Token Number Assignments
Modifications to the SPIR-V Specification Version 1.6
Issues
Revision History
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
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
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:
, and
is the total width of the datatype (including a sign bit, if required) and is encoded in the width of the
OpTypeInt
determines the position of the decimal point.
When
>= 0,
bits starting from the MSB of
are before the decimal point. If
is greater than
, then additional 0 bits are implied after the bits of
and before the decimal point.
When
< 0,
-I
0 bits are implied after the decimal point and before the MSB of
determines 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
and
Each operation will contain information about the input and result datatypes (including
, and
) where
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
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
TRN_ALTERA
Truncate towards -Inf
ArbitraryPrecisionFixedPointALTERA
TRN_ZERO_ALTERA
Truncate towards 0
ArbitraryPrecisionFixedPointALTERA
RND_ALTERA
Round towards +Inf
ArbitraryPrecisionFixedPointALTERA
RND_ZERO_ALTERA
Round towards 0
ArbitraryPrecisionFixedPointALTERA
RND_INF_ALTERA
Round positive values toward +Inf and negative values toward -Inf
ArbitraryPrecisionFixedPointALTERA
RND_MIN_INF_ALTERA
Round towards -Inf
ArbitraryPrecisionFixedPointALTERA
RND_CONV_ALTERA
Round towards even
ArbitraryPrecisionFixedPointALTERA
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
WRAP_ALTERA
Drop the bits to the left of the MSB
ArbitraryPrecisionFixedPointALTERA
SAT_ALTERA
Saturate to the closest of MIN or MAX
ArbitraryPrecisionFixedPointALTERA
SAT_ZERO_ALTERA
Set to 0 on overflow
ArbitraryPrecisionFixedPointALTERA
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
UNSIGNED_ALTERA
Input and result types are unsigned
ArbitraryPrecisionFixedPointALTERA
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 of the operation’s result, which is an arbitrary precision fixed point number.
is chosen from
Table 3.16d
that indicates the Signedness Mode of the input and output types.
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.
is a QuantizationMode enum chosen from
Table 3.16b
that indicates the Quantization Mode of this operation.
is an OverflowMode enum chosen from
Table 3.16c
that indicates the Overflow Mode of this operation.
Capability:
ArbitraryPrecisionFixedPointALTERA
5923
Result Type
Result
Input
Signedness
Literal
Literal
rI
QuatntizationMode
OverflowMode
OpFixedRecipALTERA
An
OpTypeInt
representing an arbitrary precision fixed point number (ac_fixed) is passed in as the
Input
and the reciprocal (
1/Input
) of the value is returned in
Result
Result Type
must be
OpTypeInt
Result
is the of the operation’s result, which is an arbitrary precision fixed point number.
is chosen from
Table 3.16d
that indicates the Signedness Mode of the input and output types.
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.
is a QuantizationMode enum chosen from
Table 3.16b
that indicates the Quantization Mode of this operation.
is an OverflowMode enum chosen from
Table 3.16c
that indicates the Overflow Mode of this operation.
Capability:
ArbitraryPrecisionFixedPointALTERA
5924
Result Type
Result
Input
Signedness
Literal
Literal
rI
QuatntizationMode
OverflowMode
OpFixedRsqrtALTERA
An
OpTypeInt
representing an arbitrary precision fixed point number (ac_fixed) is passed in as the
Input
and the reciprocal square root (
1/sqrt(Input)
) 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 of the operation’s result, which is an arbitrary precision fixed point number.
is chosen from
Table 3.16d
that indicates the Signedness Mode of the input and output types.
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.
is a QuantizationMode enum chosen from
Table 3.16b
that indicates the Quantization Mode of this operation.
is an OverflowMode enum chosen from
Table 3.16c
that indicates the Overflow Mode of this operation.
Capability:
ArbitraryPrecisionFixedPointALTERA
5925
Result Type
Result
Input
Signedness
Literal
Literal
rI
QuatntizationMode
OverflowMode
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 of the operation’s result, which is an arbitrary precision fixed point number.
is chosen from
Table 3.16d
that indicates the Signedness Mode of the input and output types.
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.
is a QuantizationMode enum chosen from
Table 3.16b
that indicates the Quantization Mode of this operation.
is an OverflowMode enum chosen from
Table 3.16c
that indicates the Overflow Mode of this operation.
Capability:
ArbitraryPrecisionFixedPointALTERA
5926
Result Type
Result
Input
Signedness
Literal
Literal
rI
QuatntizationMode
OverflowMode
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 of the operation’s result, which is an arbitrary precision fixed point number.
is chosen from
Table 3.16d
that indicates the Signedness Mode of the input and output types.
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.
is a QuantizationMode enum chosen from
Table 3.16b
that indicates the Quantization Mode of this operation.
is an OverflowMode enum chosen from
Table 3.16c
that indicates the Overflow Mode of this operation.
Capability:
ArbitraryPrecisionFixedPointALTERA
5927
Result Type
Result
Input
Signedness
Literal
Literal
rI
QuatntizationMode
OverflowMode
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.
is chosen from
Table 3.16d
that indicates the Signedness Mode of the input and output types.
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.
is a QuantizationMode enum chosen from
Table 3.16b
that indicates the Quantization Mode of this operation.
is an OverflowMode enum chosen from
Table 3.16c
that indicates the Overflow Mode of this operation.
Capability:
ArbitraryPrecisionFixedPointALTERA
5928
Result Type
Result
Input
Signedness
Literal
Literal
rI
QuatntizationMode
OverflowMode
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 of the operation’s result, which is an arbitrary precision fixed point number.
is chosen from
Table 3.16d
that indicates the Signedness Mode of the input and output types.
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.
is a QuantizationMode enum chosen from
Table 3.16b
that indicates the Quantization Mode of this operation.
is an OverflowMode enum chosen from
Table 3.16c
that indicates the Overflow Mode of this operation.
Capability:
ArbitraryPrecisionFixedPointALTERA
5929
Result Type
Result
Input
Signedness
Literal
Literal
rI
QuatntizationMode
OverflowMode
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 of the operation’s result, which is an arbitrary precision fixed point number.
is chosen from
Table 3.16d
that indicates the Signedness Mode of the input and output types.
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.
is a QuantizationMode enum chosen from
Table 3.16b
that indicates the Quantization Mode of this operation.
is an OverflowMode enum chosen from
Table 3.16c
that indicates the Overflow Mode of this operation.
Capability:
ArbitraryPrecisionFixedPointALTERA
5930
Result Type
Result
Input
Signedness
Literal
Literal
rI
QuatntizationMode
OverflowMode
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.
is chosen from
Table 3.16d
that indicates the Signedness Mode of the input and output types.
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.
is a QuantizationMode enum chosen from
Table 3.16b
that indicates the Quantization Mode of this operation.
is an OverflowMode enum chosen from
Table 3.16c
that indicates the Overflow Mode of this operation.
Capability:
ArbitraryPrecisionFixedPointALTERA
5931
Result Type
Result
Input
Signedness
Literal
Literal
rI
QuatntizationMode
OverflowMode
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 of the operation’s result, which is an arbitrary precision fixed point number.
is chosen from
Table 3.16d
that indicates the Signedness Mode of the input and output types.
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.
is a QuantizationMode enum chosen from
Table 3.16b
that indicates the Quantization Mode of this operation.
is an OverflowMode enum chosen from
Table 3.16c
that indicates the Overflow Mode of this operation.
Capability:
ArbitraryPrecisionFixedPointALTERA
5932
Result Type
Result
Input
Signedness
Literal
Literal
rI
QuatntizationMode
OverflowMode
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 of the operation’s result, which is an arbitrary precision fixed point number.
is chosen from
Table 3.16d
that indicates the Signedness Mode of the input and output types.
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.
is a QuantizationMode enum chosen from
Table 3.16b
that indicates the Quantization Mode of this operation.
is an OverflowMode enum chosen from
Table 3.16c
that indicates the Overflow Mode of this operation.
Capability:
ArbitraryPrecisionFixedPointALTERA
5933
Result Type
Result
Input
Signedness
Literal
Literal
rI
QuatntizationMode
OverflowMode
Validation Rules
None.
Issues
None.
Revision History
Rev
Date
Author
Changes
2023-03-21
Ajaykumar Kannan
Initial Public Release