Skip to content

Commit

Permalink
[mlir][spirv] Add CL.mix op (llvm#72800)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hardcode84 authored Nov 21, 2023
1 parent b84fe8f commit 521277c
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
31 changes: 31 additions & 0 deletions mlir/include/mlir/Dialect/SPIRV/IR/SPIRVCLOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,37 @@ class SPIRV_CLTernaryArithmeticOp<string mnemonic, int opcode, Type type,



// -----

def SPIRV_CLMixOp : SPIRV_CLTernaryArithmeticOp<"mix", 99, SPIRV_Float> {
let summary = "Returns the linear blend of x & y implemented as: x + (y - x) * a";

let description = [{
Result Type, x, y and a must be floating-point or vector(2,3,4,8,16) of
floating-point values.

All of the operands, including the Result Type operand, must be of the
same type.

Note: This instruction can be implemented using contractions such as mad
or fma.

<!-- End of AutoGen section -->

```
mix-op ::= ssa-id `=` `spirv.CL.mix` ssa-use, ssa-use, ssa-use `:`
float-scalar-vector-type
```

#### Example:

```mlir
%0 = spirv.CL.mix %a, %b, %c : f32
%1 = spirv.CL.mix %a, %b, %c : vector<3xf16>
```
}];
}

// -----

def SPIRV_CLCeilOp : SPIRV_CLUnaryArithmeticOp<"ceil", 12, SPIRV_Float> {
Expand Down
20 changes: 20 additions & 0 deletions mlir/test/Dialect/SPIRV/IR/ocl-ops.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,26 @@ func.func @fma(%a : vector<3xf32>, %b : vector<3xf32>, %c : vector<3xf32>) -> ()

// -----

//===----------------------------------------------------------------------===//
// spirv.CL.mix
//===----------------------------------------------------------------------===//

func.func @mix(%a : f32, %b : f32, %c : f32) -> () {
// CHECK: spirv.CL.mix {{%[^,]*}}, {{%[^,]*}}, {{%[^,]*}} : f32
%2 = spirv.CL.mix %a, %b, %c : f32
return
}

// -----

func.func @mix(%a : vector<3xf32>, %b : vector<3xf32>, %c : vector<3xf32>) -> () {
// CHECK: spirv.CL.mix {{%[^,]*}}, {{%[^,]*}}, {{%[^,]*}} : vector<3xf32>
%2 = spirv.CL.mix %a, %b, %c : vector<3xf32>
return
}

// -----

//===----------------------------------------------------------------------===//
// spirv.CL.{F|S|U}{Max|Min}
//===----------------------------------------------------------------------===//
Expand Down

0 comments on commit 521277c

Please sign in to comment.