diff options
| author | Manuel Freiberger <manuel.freiberger@gmail.com> | 2019-12-22 10:01:35 -0800 |
|---|---|---|
| committer | A. Unique TensorFlower <gardener@tensorflow.org> | 2019-12-22 10:02:13 -0800 |
| commit | 22954a0e408afde1d8686dffb3a3dcab107a2cd3 (patch) | |
| tree | d206709d143fb15efd807a2c601035668fcae7b2 /mlir/include | |
| parent | dcc14f08656a82aadd326aeca54b95b5b866fc86 (diff) | |
| download | bcm5719-llvm-22954a0e408afde1d8686dffb3a3dcab107a2cd3.tar.gz bcm5719-llvm-22954a0e408afde1d8686dffb3a3dcab107a2cd3.zip | |
Add integer bit-shift operations to the standard dialect.
Rename the 'shlis' operation in the standard dialect to 'shift_left'. Add tests
for this operation (these have been missing so far) and add a lowering to the
'shl' operation in the LLVM dialect.
Add also 'shift_right_signed' (lowered to LLVM's 'ashr') and 'shift_right_unsigned'
(lowered to 'lshr').
The original plan was to name these operations 'shift.left', 'shift.right.signed'
and 'shift.right.unsigned'. This works if the operations are prefixed with 'std.'
in MLIR assembly. Unfortunately during import the short form is ambigous with
operations from a hypothetical 'shift' dialect. The best solution seems to omit
dots in standard operations for now.
Closes tensorflow/mlir#226
PiperOrigin-RevId: 286803388
Diffstat (limited to 'mlir/include')
| -rw-r--r-- | mlir/include/mlir/Dialect/StandardOps/Ops.td | 49 |
1 files changed, 43 insertions, 6 deletions
diff --git a/mlir/include/mlir/Dialect/StandardOps/Ops.td b/mlir/include/mlir/Dialect/StandardOps/Ops.td index 76c2ba57ea6..c26baf6a76e 100644 --- a/mlir/include/mlir/Dialect/StandardOps/Ops.td +++ b/mlir/include/mlir/Dialect/StandardOps/Ops.td @@ -698,12 +698,12 @@ def DivFOp : FloatArithmeticOp<"divf"> { let summary = "floating point division operation"; } -def DivISOp : IntArithmeticOp<"divis"> { +def SignedDivIOp : IntArithmeticOp<"divi_signed"> { let summary = "signed integer division operation"; let hasFolder = 1; } -def DivIUOp : IntArithmeticOp<"diviu"> { +def UnsignedDivIOp : IntArithmeticOp<"divi_unsigned"> { let summary = "unsigned integer division operation"; let hasFolder = 1; } @@ -1002,12 +1002,12 @@ def RemFOp : FloatArithmeticOp<"remf"> { let summary = "floating point division remainder operation"; } -def RemISOp : IntArithmeticOp<"remis"> { +def SignedRemIOp : IntArithmeticOp<"remi_signed"> { let summary = "signed integer division remainder operation"; let hasFolder = 1; } -def RemIUOp : IntArithmeticOp<"remiu"> { +def UnsignedRemIOp : IntArithmeticOp<"remi_unsigned"> { let summary = "unsigned integer division remainder operation"; let hasFolder = 1; } @@ -1102,8 +1102,45 @@ def SignExtendIOp : Std_Op<"sexti", }]; } -def ShlISOp : IntArithmeticOp<"shlis"> { - let summary = "signed integer shift left"; +def ShiftLeftOp : IntArithmeticOp<"shift_left"> { + let summary = "integer left-shift"; + let description = [{ + The shift_left operation shifts an integer value to the left by a variable + amount. The low order bits are filled with zeros. + + %1 = constant 5 : i8 // %1 is 0b00000101 + %2 = constant 3 : i8 + %3 = shift_left %1, %2 : (i8, i8) -> i8 // %3 is 0b00101000 + }]; +} + +def SignedShiftRightOp : IntArithmeticOp<"shift_right_signed"> { + let summary = "signed integer right-shift"; + let description = [{ + The shift_right_signed operation shifts an integer value to the right by + a variable amount. The integer is interpreted as signed. The high order + bits in the output are filled with copies of the most-significant bit + of the shifted value (which means that the sign of the value is preserved). + + %1 = constant 160 : i8 // %1 is 0b10100000 + %2 = constant 3 : i8 + %3 = shift_right_signed %1, %2 : (i8, i8) -> i8 // %3 is 0b11110100 + %4 = constant 96 : i8 // %4 is 0b01100000 + %5 = shift_right_signed %4, %2 : (i8, i8) -> i8 // %5 is 0b00001100 + }]; +} + +def UnsignedShiftRightOp : IntArithmeticOp<"shift_right_unsigned"> { + let summary = "unsigned integer right-shift"; + let description = [{ + The shift_right_unsigned operation shifts an integer value to the right by + a variable amount. The integer is interpreted as unsigned. The high order + bits are always filled with zeros. + + %1 = constant 160 : i8 // %1 is 0b10100000 + %2 = constant 3 : i8 + %3 = shift_right_unsigned %1, %2 : (i8, i8) -> i8 // %3 is 0b00010100 + }]; } def SIToFPOp : CastOp<"sitofp">, Arguments<(ins AnyType:$in)> { |

