File tree Expand file tree Collapse file tree 2 files changed +67
-0
lines changed
include/mlir/Dialect/Math/IR Expand file tree Collapse file tree 2 files changed +67
-0
lines changed Original file line number Diff line number Diff line change @@ -437,6 +437,45 @@ def Math_CoshOp : Math_FloatUnaryOp<"cosh"> {
437
437
let hasFolder = 1;
438
438
}
439
439
440
+ //===----------------------------------------------------------------------===//
441
+ // SignIOp
442
+ //===----------------------------------------------------------------------===//
443
+
444
+ def Math_SignIOp : Math_IntegerUnaryOp<"signi"> {
445
+ let summary = "ternary-valued sign of an integer";
446
+ let description = [{
447
+ The `signi` operation computes -1 if the operand is negative, 0 if it is
448
+ zero, and 1 if it is positive.
449
+
450
+ Example:
451
+
452
+ ```mlir
453
+ %a = math.signi %b : i64
454
+ ```
455
+ }];
456
+ let hasFolder = 1;
457
+ }
458
+
459
+
460
+ //===----------------------------------------------------------------------===//
461
+ // SignFOp
462
+ //===----------------------------------------------------------------------===//
463
+
464
+ def Math_SignFOp : Math_FloatUnaryOp<"signf"> {
465
+ let summary = "ternary-valued sign of a floating point value";
466
+ let description = [{
467
+ The `signf` operation computes -1.0 if the operand is negative, 0.0 if it
468
+ is zero, 1.0 if it is positive, and `NaN` if the operand is `NaN`.
469
+
470
+ Example:
471
+
472
+ ```mlir
473
+ %a = math.signf %b : f32
474
+ ```
475
+ }];
476
+ let hasFolder = 1;
477
+ }
478
+
440
479
//===----------------------------------------------------------------------===//
441
480
// SinOp
442
481
//===----------------------------------------------------------------------===//
Original file line number Diff line number Diff line change @@ -266,6 +266,34 @@ OpFoldResult math::SinOp::fold(FoldAdaptor adaptor) {
266
266
});
267
267
}
268
268
269
+ // ===----------------------------------------------------------------------===//
270
+ // SignIOp folder
271
+ // ===----------------------------------------------------------------------===//
272
+
273
+ OpFoldResult math::SignIOp::fold (FoldAdaptor adaptor) {
274
+ return constFoldUnaryOp<IntegerAttr>(
275
+ adaptor.getOperands (), [](const APInt &a) {
276
+ return a.isNegative () ? APInt (a.getBitWidth (), -1 )
277
+ : (a.isZero () ? APInt (a.getBitWidth (), 0 )
278
+ : APInt (a.getBitWidth (), 1 ));
279
+ });
280
+ }
281
+
282
+ // ===----------------------------------------------------------------------===//
283
+ // SignFOp folder
284
+ // ===----------------------------------------------------------------------===//
285
+
286
+ OpFoldResult math::SignFOp::fold (FoldAdaptor adaptor) {
287
+ return constFoldUnaryOp<FloatAttr>(
288
+ adaptor.getOperands (), [](const APFloat &a) {
289
+ if (a.isNaN ())
290
+ return APFloat::getNaN (a.getSemantics ());
291
+ return a.isNegative () ? APFloat (a.getSemantics (), -1 )
292
+ : (a.isZero () ? APFloat (a.getSemantics (), 0 )
293
+ : APFloat (a.getSemantics (), 1 ));
294
+ });
295
+ }
296
+
269
297
// ===----------------------------------------------------------------------===//
270
298
// SinhOp folder
271
299
// ===----------------------------------------------------------------------===//
You can’t perform that action at this time.
0 commit comments