@@ -118,3 +118,40 @@ func.func @apply_scale_test_i48(%arg0 : i48, %arg1 : i32, %arg2 : i8) -> (i32) {
118
118
%res = tosa.apply_scale %arg0 , %arg1 , %arg2 {double_round = true } : (i48 , i32 , i8 ) -> i32
119
119
return %res : i32
120
120
}
121
+
122
+ // -----
123
+
124
+ // CHECK-LABEL: @apply_scale_test_i64
125
+ // SCALE: tosa.apply_scale
126
+ func.func @apply_scale_test_i64 (%arg0 : i64 , %arg1 : i32 , %arg2 : i8 ) -> (i32 ) {
127
+ // CHECK-DAG: %[[C0:.+]] = arith.constant 0 : i64
128
+ // CHECK-DAG: %[[C1:.+]] = arith.constant 1 : i64
129
+ // CHECK-DAG: %[[C31:.+]] = arith.constant 31 : i32
130
+
131
+ // Multiply in 64 bits.
132
+ // CHECK-DAG: %[[M64:.+]] = arith.extsi %arg1 : i32 to i64
133
+ // CHECK-DAG: %[[MUL:.+]] = arith.muli %arg0, %[[M64]]
134
+
135
+ // Round normally.
136
+ // CHECK-DAG: %[[S32:.+]] = arith.extui %arg2 : i8 to i32
137
+ // CHECK-DAG: %[[S64:.+]] = arith.extui %[[S32]] : i32 to i64
138
+ // CHECK-DAG: %[[ONEL:.+]] = arith.shli %[[C1]], %[[S64]] : i64
139
+ // CHECK-DAG: %[[ONER:.+]] = arith.shrui %[[ONEL]], %[[C1]]
140
+ // CHECK-DAG: %[[ROUND:.+]] = arith.addi %[[MUL]], %[[ONER]]
141
+
142
+ // Apply double rounding.
143
+ // CHECK-DAG: %[[DUP:.+]] = arith.constant 1073741824 : i64
144
+ // CHECK-DAG: %[[DDOWN:.+]] = arith.constant -1073741824 : i64
145
+ // CHECK-DAG: %[[POS:.+]] = arith.cmpi sge, %arg0, %[[C0]]
146
+ // CHECK-DAG: %[[DBIT:.+]] = arith.select %[[POS]], %[[DUP]], %[[DDOWN]]
147
+ // CHECK-DAG: %[[DRND:.+]] = arith.addi %[[DBIT]], %[[ROUND]]
148
+ // CHECK-DAG: %[[USED:.+]] = arith.cmpi sgt, %[[S32]], %[[C31]] : i32
149
+ // CHECK-DAG: %[[RES64:.+]] = arith.select %[[USED]], %[[DRND]], %[[ROUND]] : i64
150
+
151
+ // Shift and truncate final answer.
152
+ // CHECK-DAG: %[[SHR:.+]] = arith.shrsi %[[RES64]], %[[S64]]
153
+ // CHECK-DAG: %[[TRUNC:.+]] = arith.trunci %[[SHR]] : i64 to i32
154
+ // CHECK: return %[[TRUNC]]
155
+ %res = tosa.apply_scale %arg0 , %arg1 , %arg2 {double_round = true } : (i64 , i32 , i8 ) -> i32
156
+ return %res : i32
157
+ }
0 commit comments