1 // WebAssemblyInstrFloat.td-WebAssembly Float codegen support ---*- tablegen -*- 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 /// 10 /// \file 11 /// WebAssembly Floating-point operand code-gen constructs. 12 /// 13 //===----------------------------------------------------------------------===// 14 15 let Defs = [ARGUMENTS] in { 16 17 let isCommutable = 1 in 18 defm ADD : BinaryFP<fadd, "add ", 0x92, 0xa0>; 19 defm SUB : BinaryFP<fsub, "sub ", 0x93, 0xa1>; 20 let isCommutable = 1 in 21 defm MUL : BinaryFP<fmul, "mul ", 0x94, 0xa2>; 22 defm DIV : BinaryFP<fdiv, "div ", 0x95, 0xa3>; 23 defm SQRT : UnaryFP<fsqrt, "sqrt", 0x91, 0x9f>; 24 25 defm ABS : UnaryFP<fabs, "abs ", 0x8b, 0x99>; 26 defm NEG : UnaryFP<fneg, "neg ", 0x8c, 0x9a>; 27 defm COPYSIGN : BinaryFP<fcopysign, "copysign", 0x98, 0xa6>; 28 29 let isCommutable = 1 in { 30 defm MIN : BinaryFP<fminnan, "min ", 0x96, 0xa4>; 31 defm MAX : BinaryFP<fmaxnan, "max ", 0x97, 0xa5>; 32 } // isCommutable = 1 33 34 defm CEIL : UnaryFP<fceil, "ceil", 0x8d, 0x9b>; 35 defm FLOOR : UnaryFP<ffloor, "floor", 0x8e, 0x9c>; 36 defm TRUNC : UnaryFP<ftrunc, "trunc", 0x8f, 0x9d>; 37 defm NEAREST : UnaryFP<fnearbyint, "nearest", 0x90, 0x9e>; 38 39 } // Defs = [ARGUMENTS] 40 41 // DAGCombine oddly folds casts into the rhs of copysign. Unfold them. 42 def : Pat<(fcopysign F64:$lhs, F32:$rhs), 43 (COPYSIGN_F64 F64:$lhs, (F64_PROMOTE_F32 F32:$rhs))>; 44 def : Pat<(fcopysign F32:$lhs, F64:$rhs), 45 (COPYSIGN_F32 F32:$lhs, (F32_DEMOTE_F64 F64:$rhs))>; 46 47 // WebAssembly doesn't expose inexact exceptions, so map frint to fnearbyint. 48 def : Pat<(frint f32:$src), (NEAREST_F32 f32:$src)>; 49 def : Pat<(frint f64:$src), (NEAREST_F64 f64:$src)>; 50 51 let Defs = [ARGUMENTS] in { 52 53 let isCommutable = 1 in { 54 defm EQ : ComparisonFP<SETOEQ, "eq ", 0x5b, 0x61>; 55 defm NE : ComparisonFP<SETUNE, "ne ", 0x5c, 0x62>; 56 } // isCommutable = 1 57 defm LT : ComparisonFP<SETOLT, "lt ", 0x5d, 0x63>; 58 defm LE : ComparisonFP<SETOLE, "le ", 0x5f, 0x65>; 59 defm GT : ComparisonFP<SETOGT, "gt ", 0x5e, 0x64>; 60 defm GE : ComparisonFP<SETOGE, "ge ", 0x60, 0x66>; 61 62 } // Defs = [ARGUMENTS] 63 64 // Don't care floating-point comparisons, supported via other comparisons. 65 def : Pat<(seteq f32:$lhs, f32:$rhs), (EQ_F32 f32:$lhs, f32:$rhs)>; 66 def : Pat<(setne f32:$lhs, f32:$rhs), (NE_F32 f32:$lhs, f32:$rhs)>; 67 def : Pat<(setlt f32:$lhs, f32:$rhs), (LT_F32 f32:$lhs, f32:$rhs)>; 68 def : Pat<(setle f32:$lhs, f32:$rhs), (LE_F32 f32:$lhs, f32:$rhs)>; 69 def : Pat<(setgt f32:$lhs, f32:$rhs), (GT_F32 f32:$lhs, f32:$rhs)>; 70 def : Pat<(setge f32:$lhs, f32:$rhs), (GE_F32 f32:$lhs, f32:$rhs)>; 71 def : Pat<(seteq f64:$lhs, f64:$rhs), (EQ_F64 f64:$lhs, f64:$rhs)>; 72 def : Pat<(setne f64:$lhs, f64:$rhs), (NE_F64 f64:$lhs, f64:$rhs)>; 73 def : Pat<(setlt f64:$lhs, f64:$rhs), (LT_F64 f64:$lhs, f64:$rhs)>; 74 def : Pat<(setle f64:$lhs, f64:$rhs), (LE_F64 f64:$lhs, f64:$rhs)>; 75 def : Pat<(setgt f64:$lhs, f64:$rhs), (GT_F64 f64:$lhs, f64:$rhs)>; 76 def : Pat<(setge f64:$lhs, f64:$rhs), (GE_F64 f64:$lhs, f64:$rhs)>; 77 78 let Defs = [ARGUMENTS] in { 79 80 defm SELECT_F32 : I<(outs F32:$dst), (ins F32:$lhs, F32:$rhs, I32:$cond), 81 (outs), (ins), 82 [(set F32:$dst, (select I32:$cond, F32:$lhs, F32:$rhs))], 83 "f32.select\t$dst, $lhs, $rhs, $cond", "f32.select", 0x1b>; 84 defm SELECT_F64 : I<(outs F64:$dst), (ins F64:$lhs, F64:$rhs, I32:$cond), 85 (outs), (ins), 86 [(set F64:$dst, (select I32:$cond, F64:$lhs, F64:$rhs))], 87 "f64.select\t$dst, $lhs, $rhs, $cond", "f64.select", 0x1b>; 88 89 } // Defs = [ARGUMENTS] 90 91 // ISD::SELECT requires its operand to conform to getBooleanContents, but 92 // WebAssembly's select interprets any non-zero value as true, so we can fold 93 // a setne with 0 into a select. 94 def : Pat<(select (i32 (setne I32:$cond, 0)), F32:$lhs, F32:$rhs), 95 (SELECT_F32 F32:$lhs, F32:$rhs, I32:$cond)>; 96 def : Pat<(select (i32 (setne I32:$cond, 0)), F64:$lhs, F64:$rhs), 97 (SELECT_F64 F64:$lhs, F64:$rhs, I32:$cond)>; 98 99 // And again, this time with seteq instead of setne and the arms reversed. 100 def : Pat<(select (i32 (seteq I32:$cond, 0)), F32:$lhs, F32:$rhs), 101 (SELECT_F32 F32:$rhs, F32:$lhs, I32:$cond)>; 102 def : Pat<(select (i32 (seteq I32:$cond, 0)), F64:$lhs, F64:$rhs), 103 (SELECT_F64 F64:$rhs, F64:$lhs, I32:$cond)>; 104