@@ -993,16 +993,17 @@ def CmpOp : CIR_Op<"cmp", [Pure, SameTypeOperands]> {
993
993
// BitsOp
994
994
//===----------------------------------------------------------------------===//
995
995
996
- class CIR_BitOp<string mnemonic> : CIR_Op<mnemonic, [Pure]> {
997
- let arguments = (ins CIR_IntType:$input);
998
- let results = (outs CIR_IntType:$result);
996
+ class CIR_BitOp<string mnemonic, TypeConstraint inputTy>
997
+ : CIR_Op<mnemonic, [Pure]> {
998
+ let arguments = (ins inputTy:$input);
999
+ let results = (outs SInt32:$result);
999
1000
1000
1001
let assemblyFormat = [{
1001
1002
`(` $input `:` type($input) `)` `:` type($result) attr-dict
1002
1003
}];
1003
1004
}
1004
1005
1005
- def BitClrsbOp : CIR_BitOp<"bit.clrsb"> {
1006
+ def BitClrsbOp : CIR_BitOp<"bit.clrsb", SIntOfWidths<[32, 64]> > {
1006
1007
let summary = "Get the number of leading redundant sign bits in the input";
1007
1008
let description = [{
1008
1009
Compute the number of leading redundant sign bits in the input integer.
@@ -1012,6 +1013,8 @@ def BitClrsbOp : CIR_BitOp<"bit.clrsb"> {
1012
1013
number of redundant sign bits in the input, that is, the number of bits
1013
1014
following the most significant bit that are identical to it.
1014
1015
1016
+ The bit width of the input integer must be either 32 or 64.
1017
+
1015
1018
Examples:
1016
1019
1017
1020
```mlir
@@ -1029,17 +1032,15 @@ def BitClrsbOp : CIR_BitOp<"bit.clrsb"> {
1029
1032
%3 = cir.bit.clrsb(%2 : !s32i) : !s32i
1030
1033
```
1031
1034
}];
1032
-
1033
- let hasVerifier = 1;
1034
1035
}
1035
1036
1036
- def BitCtzOp : CIR_BitOp<"bit.ctz" > {
1037
- let summary = "Get the number of trailing 0-bits in the input";
1037
+ def BitClzOp : CIR_BitOp<"bit.clz", UIntOfWidths<[16, 32, 64]> > {
1038
+ let summary = "Get the number of leading 0-bits in the input";
1038
1039
let description = [{
1039
- Compute the number of trailing 0-bits in the input.
1040
+ Compute the number of leading 0-bits in the input.
1040
1041
1041
- The input integer must be an unsigned integer. The `cir.bit.ctz ` operation
1042
- returns the number of consecutive 0-bits at the least significant bit
1042
+ The input integer must be an unsigned integer. The `cir.bit.clz ` operation
1043
+ returns the number of consecutive 0-bits at the most significant bit
1043
1044
position in the input.
1044
1045
1045
1046
This operation invokes undefined behavior if the input value is 0.
@@ -1050,23 +1051,21 @@ def BitCtzOp : CIR_BitOp<"bit.ctz"> {
1050
1051
!s32i = !cir.int<s, 32>
1051
1052
!u32i = !cir.int<u, 32>
1052
1053
1053
- // %0 = 0b1000
1054
+ // %0 = 0b0000_0000_0000_0000_0000_0000_0000_1000
1054
1055
%0 = cir.const(#cir.int<8> : !u32i) : !u32i
1055
- // %1 will be 3
1056
- %1 = cir.bit.ctz (%0 : !u32i) : !s32i
1056
+ // %1 will be 28
1057
+ %1 = cir.bit.clz (%0 : !u32i) : !s32i
1057
1058
```
1058
1059
}];
1059
-
1060
- let hasVerifier = 1;
1061
1060
}
1062
1061
1063
- def BitClzOp : CIR_BitOp<"bit.clz" > {
1064
- let summary = "Get the number of leading 0-bits in the input";
1062
+ def BitCtzOp : CIR_BitOp<"bit.ctz", UIntOfWidths<[16, 32, 64]> > {
1063
+ let summary = "Get the number of trailing 0-bits in the input";
1065
1064
let description = [{
1066
- Compute the number of leading 0-bits in the input.
1065
+ Compute the number of trailing 0-bits in the input.
1067
1066
1068
- The input integer must be an unsigned integer. The `cir.bit.clz ` operation
1069
- returns the number of consecutive 0-bits at the most significant bit
1067
+ The input integer must be an unsigned integer. The `cir.bit.ctz ` operation
1068
+ returns the number of consecutive 0-bits at the least significant bit
1070
1069
position in the input.
1071
1070
1072
1071
This operation invokes undefined behavior if the input value is 0.
@@ -1077,17 +1076,15 @@ def BitClzOp : CIR_BitOp<"bit.clz"> {
1077
1076
!s32i = !cir.int<s, 32>
1078
1077
!u32i = !cir.int<u, 32>
1079
1078
1080
- // %0 = 0b0000_0000_0000_0000_0000_0000_0000_1000
1079
+ // %0 = 0b1000
1081
1080
%0 = cir.const(#cir.int<8> : !u32i) : !u32i
1082
- // %1 will be 28
1083
- %1 = cir.bit.clz (%0 : !u32i) : !s32i
1081
+ // %1 will be 3
1082
+ %1 = cir.bit.ctz (%0 : !u32i) : !s32i
1084
1083
```
1085
1084
}];
1086
-
1087
- let hasVerifier = 1;
1088
1085
}
1089
1086
1090
- def BitFfsOp : CIR_BitOp<"bit.ffs"> {
1087
+ def BitFfsOp : CIR_BitOp<"bit.ffs", SIntOfWidths<[32, 64]> > {
1091
1088
let summary = "Get the position of the least significant 1-bit of input";
1092
1089
let description = [{
1093
1090
Compute the position of the least significant 1-bit of the input.
@@ -1108,11 +1105,9 @@ def BitFfsOp : CIR_BitOp<"bit.ffs"> {
1108
1105
%1 = cir.bit.ffs(%0 : !s32i) : !s32i
1109
1106
```
1110
1107
}];
1111
-
1112
- let hasVerifier = 1;
1113
1108
}
1114
1109
1115
- def BitParityOp : CIR_BitOp<"bit.parity"> {
1110
+ def BitParityOp : CIR_BitOp<"bit.parity", UIntOfWidths<[32, 64]> > {
1116
1111
let summary = "Get the parity of input";
1117
1112
let description = [{
1118
1113
Compute the parity of the input. The parity of an integer is the number of
@@ -1132,11 +1127,9 @@ def BitParityOp : CIR_BitOp<"bit.parity"> {
1132
1127
%1 = cir.bit.parity(%0 : !u32i) : !s32i
1133
1128
```
1134
1129
}];
1135
-
1136
- let hasVerifier = 1;
1137
1130
}
1138
1131
1139
- def BitPopcountOp : CIR_BitOp<"bit.popcount"> {
1132
+ def BitPopcountOp : CIR_BitOp<"bit.popcount", UIntOfWidths<[16, 32, 64]> > {
1140
1133
let summary = "Get the number of 1-bits in input";
1141
1134
let description = [{
1142
1135
Compute the number of 1-bits in the input.
@@ -1155,8 +1148,6 @@ def BitPopcountOp : CIR_BitOp<"bit.popcount"> {
1155
1148
%1 = cir.bit.popcount(%0 : !u32i) : !s32i
1156
1149
```
1157
1150
}];
1158
-
1159
- let hasVerifier = 1;
1160
1151
}
1161
1152
1162
1153
//===----------------------------------------------------------------------===//
0 commit comments