-
Notifications
You must be signed in to change notification settings - Fork 2
[mlir][dxsa] Add dadd, ddiv, dmax, dmin, dmul and drcp instructions #190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tagolog
wants to merge
2
commits into
dxsa-mlir
Choose a base branch
from
vshiryaev/dxsa-mlir-double-arithmetic-instructions
base: dxsa-mlir
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+406
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
308 changes: 308 additions & 0 deletions
308
mlir/include/mlir/Dialect/DXSA/IR/DXSADoubleArithOps.td
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,308 @@ | ||
| //===- DXSADoubleArithOps.td - DXSA double arithmetic ops -*- tablegen -*-===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Double-precision arithmetic instructions of the DXSA dialect. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef MLIR_DIALECT_DXSA_IR_DXSADOUBLEARITHOPS | ||
| #define MLIR_DIALECT_DXSA_IR_DXSADOUBLEARITHOPS | ||
|
|
||
| include "mlir/Dialect/DXSA/IR/DXSAOpBase.td" | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // dxsa.dadd | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| def DXSA_Dadd : DXSA_BinaryOp<"dadd"> { | ||
| let summary = "component-wise double-precision add"; | ||
| let description = [{ | ||
| The `dxsa.dadd` operation computes the component-wise double-precision | ||
| sum `$dst = $lhs + $rhs`. Each operand holds a vector of doubles, one | ||
| double per `xy` and `zw` component pair. | ||
|
|
||
| Because each double spans a component pair, the destination write mask must | ||
| be `<x, y>`, `<z, w>`, or `<x, y, z, w>`, and each source swizzle must be | ||
| one of `<x, y, z, w>`, `<x, y, x, y>`, `<z, w, x, y>`, or `<z, w, z, w>`. | ||
|
|
||
| Example: | ||
|
|
||
| ```mlir | ||
| dxsa.dadd r<0>, r<1>, r<2> | ||
| dxsa.dadd r<0, <x, y>>, r<1, <z, w, x, y>>, -r<2> | ||
| ``` | ||
| }]; | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // dxsa.dadd_sat | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| def DXSA_DaddSat : DXSA_BinaryOp<"dadd_sat"> { | ||
| let summary = "component-wise double-precision add, saturated to [0, 1]"; | ||
| let description = [{ | ||
| The `dxsa.dadd_sat` operation computes the component-wise double-precision | ||
| sum of `$lhs` and `$rhs`, clamps each result component to `[0.0, 1.0]`, | ||
| and writes it to `$dst`. | ||
|
|
||
| Because each double spans a component pair, the destination write mask must | ||
| be `<x, y>`, `<z, w>`, or `<x, y, z, w>`, and each source swizzle must be | ||
| one of `<x, y, z, w>`, `<x, y, x, y>`, `<z, w, x, y>`, or `<z, w, z, w>`. | ||
|
|
||
| Example: | ||
|
|
||
| ```mlir | ||
| dxsa.dadd_sat r<0>, r<1>, r<2> | ||
| dxsa.dadd_sat r<0, <x, y>>, r<1, <z, w, x, y>>, -r<2> | ||
| ``` | ||
| }]; | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // dxsa.ddiv | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| def DXSA_Ddiv : DXSA_BinaryOp<"ddiv"> { | ||
| let summary = "component-wise double-precision divide"; | ||
| let description = [{ | ||
| The `dxsa.ddiv` operation computes the component-wise double-precision | ||
| quotient `$dst = $lhs / $rhs`. Each operand holds a vector of doubles, one | ||
| double per `xy` and `zw` component pair. | ||
|
|
||
| Because each double spans a component pair, the destination write mask must | ||
| be `<x, y>`, `<z, w>`, or `<x, y, z, w>`, and each source swizzle must be | ||
| one of `<x, y, z, w>`, `<x, y, x, y>`, `<z, w, x, y>`, or `<z, w, z, w>`. | ||
|
|
||
| Example: | ||
|
|
||
| ```mlir | ||
| dxsa.ddiv r<0>, r<1>, r<2> | ||
| dxsa.ddiv r<0, <x, y>>, r<1, <z, w, x, y>>, -r<2> | ||
| ``` | ||
| }]; | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // dxsa.ddiv_sat | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| def DXSA_DdivSat : DXSA_BinaryOp<"ddiv_sat"> { | ||
| let summary = "component-wise double-precision divide, saturated to [0, 1]"; | ||
| let description = [{ | ||
| The `dxsa.ddiv_sat` operation computes the component-wise double-precision | ||
| quotient of `$lhs` and `$rhs`, clamps each result component to | ||
| `[0.0, 1.0]`, and writes it to `$dst`. | ||
|
|
||
| Because each double spans a component pair, the destination write mask must | ||
| be `<x, y>`, `<z, w>`, or `<x, y, z, w>`, and each source swizzle must be | ||
| one of `<x, y, z, w>`, `<x, y, x, y>`, `<z, w, x, y>`, or `<z, w, z, w>`. | ||
|
|
||
| Example: | ||
|
|
||
| ```mlir | ||
| dxsa.ddiv_sat r<0>, r<1>, r<2> | ||
| dxsa.ddiv_sat r<0, <x, y>>, r<1, <z, w, x, y>>, -r<2> | ||
| ``` | ||
| }]; | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // dxsa.dmax | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| def DXSA_Dmax : DXSA_BinaryOp<"dmax"> { | ||
| let summary = "component-wise double-precision maximum"; | ||
| let description = [{ | ||
| The `dxsa.dmax` operation computes the component-wise double-precision | ||
| maximum `$dst = $lhs >= $rhs ? $lhs : $rhs`. If one source component is | ||
| NaN, the other source component is returned. | ||
|
|
||
| Because each double spans a component pair, the destination write mask must | ||
| be `<x, y>`, `<z, w>`, or `<x, y, z, w>`, and each source swizzle must be | ||
| one of `<x, y, z, w>`, `<x, y, x, y>`, `<z, w, x, y>`, or `<z, w, z, w>`. | ||
|
|
||
| Example: | ||
|
|
||
| ```mlir | ||
| dxsa.dmax r<0>, r<1>, r<2> | ||
| dxsa.dmax r<0, <x, y>>, r<1, <z, w, x, y>>, -r<2> | ||
| ``` | ||
| }]; | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // dxsa.dmax_sat | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| def DXSA_DmaxSat : DXSA_BinaryOp<"dmax_sat"> { | ||
| let summary = "component-wise double-precision maximum, saturated to [0, 1]"; | ||
| let description = [{ | ||
| The `dxsa.dmax_sat` operation computes the component-wise double-precision | ||
| maximum of `$lhs` and `$rhs`, clamps each result component to `[0.0, 1.0]`, | ||
| and writes it to `$dst`. If one source component is NaN, the other source | ||
| component is used. | ||
|
|
||
| Because each double spans a component pair, the destination write mask must | ||
| be `<x, y>`, `<z, w>`, or `<x, y, z, w>`, and each source swizzle must be | ||
| one of `<x, y, z, w>`, `<x, y, x, y>`, `<z, w, x, y>`, or `<z, w, z, w>`. | ||
|
|
||
| Example: | ||
|
|
||
| ```mlir | ||
| dxsa.dmax_sat r<0>, r<1>, r<2> | ||
| dxsa.dmax_sat r<0, <x, y>>, r<1, <z, w, x, y>>, -r<2> | ||
| ``` | ||
| }]; | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // dxsa.dmin | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| def DXSA_Dmin : DXSA_BinaryOp<"dmin"> { | ||
| let summary = "component-wise double-precision minimum"; | ||
| let description = [{ | ||
| The `dxsa.dmin` operation computes the component-wise double-precision | ||
| minimum `$dst = $lhs < $rhs ? $lhs : $rhs`. If one source component is | ||
| NaN, the other source component is returned. | ||
|
|
||
| Because each double spans a component pair, the destination write mask must | ||
| be `<x, y>`, `<z, w>`, or `<x, y, z, w>`, and each source swizzle must be | ||
| one of `<x, y, z, w>`, `<x, y, x, y>`, `<z, w, x, y>`, or `<z, w, z, w>`. | ||
|
|
||
| Example: | ||
|
|
||
| ```mlir | ||
| dxsa.dmin r<0>, r<1>, r<2> | ||
| dxsa.dmin r<0, <x, y>>, r<1, <z, w, x, y>>, -r<2> | ||
| ``` | ||
| }]; | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // dxsa.dmin_sat | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| def DXSA_DminSat : DXSA_BinaryOp<"dmin_sat"> { | ||
| let summary = "component-wise double-precision minimum, saturated to [0, 1]"; | ||
| let description = [{ | ||
| The `dxsa.dmin_sat` operation computes the component-wise double-precision | ||
| minimum of `$lhs` and `$rhs`, clamps each result component to `[0.0, 1.0]`, | ||
| and writes it to `$dst`. If one source component is NaN, the other source | ||
| component is used. | ||
|
|
||
| Because each double spans a component pair, the destination write mask must | ||
| be `<x, y>`, `<z, w>`, or `<x, y, z, w>`, and each source swizzle must be | ||
| one of `<x, y, z, w>`, `<x, y, x, y>`, `<z, w, x, y>`, or `<z, w, z, w>`. | ||
|
|
||
| Example: | ||
|
|
||
| ```mlir | ||
| dxsa.dmin_sat r<0>, r<1>, r<2> | ||
| dxsa.dmin_sat r<0, <x, y>>, r<1, <z, w, x, y>>, -r<2> | ||
| ``` | ||
| }]; | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // dxsa.dmul | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| def DXSA_Dmul : DXSA_BinaryOp<"dmul"> { | ||
| let summary = "component-wise double-precision multiply"; | ||
| let description = [{ | ||
| The `dxsa.dmul` operation computes the component-wise double-precision | ||
| product `$dst = $lhs * $rhs`. Each operand holds a vector of doubles, one | ||
| double per `xy` and `zw` component pair. | ||
|
|
||
| Because each double spans a component pair, the destination write mask must | ||
| be `<x, y>`, `<z, w>`, or `<x, y, z, w>`, and each source swizzle must be | ||
| one of `<x, y, z, w>`, `<x, y, x, y>`, `<z, w, x, y>`, or `<z, w, z, w>`. | ||
|
|
||
| Example: | ||
|
|
||
| ```mlir | ||
| dxsa.dmul r<0>, r<1>, r<2> | ||
| dxsa.dmul r<0, <x, y>>, r<1, <z, w, x, y>>, -r<2> | ||
| ``` | ||
| }]; | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // dxsa.dmul_sat | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| def DXSA_DmulSat : DXSA_BinaryOp<"dmul_sat"> { | ||
| let summary = "component-wise double-precision multiply, saturated to [0, 1]"; | ||
| let description = [{ | ||
| The `dxsa.dmul_sat` operation computes the component-wise double-precision | ||
| product of `$lhs` and `$rhs`, clamps each result component to `[0.0, 1.0]`, | ||
| and writes it to `$dst`. | ||
|
|
||
| Because each double spans a component pair, the destination write mask must | ||
| be `<x, y>`, `<z, w>`, or `<x, y, z, w>`, and each source swizzle must be | ||
| one of `<x, y, z, w>`, `<x, y, x, y>`, `<z, w, x, y>`, or `<z, w, z, w>`. | ||
|
|
||
| Example: | ||
|
|
||
| ```mlir | ||
| dxsa.dmul_sat r<0>, r<1>, r<2> | ||
| dxsa.dmul_sat r<0, <x, y>>, r<1, <z, w, x, y>>, -r<2> | ||
| ``` | ||
| }]; | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // dxsa.drcp | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| def DXSA_Drcp : DXSA_UnaryOp<"drcp"> { | ||
| let summary = "component-wise double-precision reciprocal"; | ||
| let description = [{ | ||
| The `dxsa.drcp` operation computes the component-wise double-precision | ||
| reciprocal `$dst = 1.0 / $src`. Each operand holds a vector of doubles, one | ||
| double per `xy` and `zw` component pair. | ||
|
|
||
| Because each double spans a component pair, the destination write mask must | ||
| be `<x, y>`, `<z, w>`, or `<x, y, z, w>`, and the source swizzle must be | ||
| one of `<x, y, z, w>`, `<x, y, x, y>`, `<z, w, x, y>`, or `<z, w, z, w>`. | ||
|
|
||
| Example: | ||
|
|
||
| ```mlir | ||
| dxsa.drcp r<0>, r<1> | ||
| dxsa.drcp r<0, <x, y>>, -r<1, <z, w, x, y>> | ||
| ``` | ||
| }]; | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // dxsa.drcp_sat | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| def DXSA_DrcpSat : DXSA_UnaryOp<"drcp_sat"> { | ||
| let summary = "component-wise double-precision reciprocal, saturated to [0, 1]"; | ||
| let description = [{ | ||
| The `dxsa.drcp_sat` operation computes the component-wise double-precision | ||
| reciprocal of `$src`, clamps each result component to `[0.0, 1.0]`, and | ||
| writes it to `$dst`. | ||
|
|
||
| Because each double spans a component pair, the destination write mask must | ||
| be `<x, y>`, `<z, w>`, or `<x, y, z, w>`, and the source swizzle must be | ||
| one of `<x, y, z, w>`, `<x, y, x, y>`, `<z, w, x, y>`, or `<z, w, z, w>`. | ||
|
|
||
| Example: | ||
|
|
||
| ```mlir | ||
| dxsa.drcp_sat r<0>, r<1> | ||
| dxsa.drcp_sat r<0, <x, y>>, -r<1, <z, w, x, y>> | ||
| ``` | ||
| }]; | ||
| } | ||
|
|
||
| #endif // MLIR_DIALECT_DXSA_IR_DXSADOUBLEARITHOPS | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm seeing in the documentation that
_satis an instruction modifier, these aren't actually separate instructions? In that case, would it make sense to find a way to avoid duplicating almost every instruction?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We decided to support
_satas a separate instruction (s) and a lot of instructions already implemented in this manner.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems inconsistent with the logic @asl gave in #194 against structured MLIR: "This is a bytecode dialect." In the bytecode, these aren't separate opcodes, so if we're modelling the MLIR after what the bytecode looks like, they shouldn't be separate instructions.
If it's decided that we're doing things this way then I'm of course not going to hold up this PR over it; I'm just leaving this comment to make it clear to anyone reading that it's intentional.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@asl what do you mean?