33efbb350cba62e9d507b7a4c2bb43b6a4dbdaaf
[oota-llvm.git] / lib / Target / WebAssembly / WebAssemblyInstrFloat.td
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 /// \brief WebAssembly Floating-point operand code-gen constructs.
12 ///
13 //===----------------------------------------------------------------------===//
14
15 defm ADD : BinaryFP<fadd, "add ">;
16 defm SUB : BinaryFP<fsub, "sub ">;
17 defm MUL : BinaryFP<fmul, "mul ">;
18 defm DIV : BinaryFP<fdiv, "div ">;
19 defm SQRT : UnaryFP<fsqrt, "sqrt">;
20
21 defm ABS : UnaryFP<fabs, "abs ">;
22 defm NEG : UnaryFP<fneg, "neg ">;
23 defm COPYSIGN : BinaryFP<fcopysign, "copysign">;
24
25 defm MIN : BinaryFP<fminnan, "min ">;
26 defm MAX : BinaryFP<fmaxnan, "max ">;
27
28 defm CEIL : UnaryFP<fceil, "ceil">;
29 defm FLOOR : UnaryFP<ffloor, "floor">;
30 defm TRUNC : UnaryFP<ftrunc, "trunc">;
31 defm NEAREST : UnaryFP<fnearbyint, "nearest">;
32
33 // WebAssembly doesn't expose inexact exceptions, so map frint to fnearbyint.
34 def : Pat<(frint f32:$src), (NEAREST_F32 f32:$src)>;
35 def : Pat<(frint f64:$src), (NEAREST_F64 f64:$src)>;
36
37 defm EQ : ComparisonFP<SETOEQ, "eq  ">;
38 defm NE : ComparisonFP<SETUNE, "ne  ">;
39 defm LT : ComparisonFP<SETOLT, "lt  ">;
40 defm LE : ComparisonFP<SETOLE, "le  ">;
41 defm GT : ComparisonFP<SETOGT, "gt  ">;
42 defm GE : ComparisonFP<SETOGE, "ge  ">;
43
44 // Don't care floating-point comparisons, supported via other comparisons.
45 def : Pat<(seteq f32:$lhs, f32:$rhs), (EQ_F32 f32:$lhs, f32:$rhs)>;
46 def : Pat<(setne f32:$lhs, f32:$rhs), (NE_F32 f32:$lhs, f32:$rhs)>;
47 def : Pat<(setlt f32:$lhs, f32:$rhs), (LT_F32 f32:$lhs, f32:$rhs)>;
48 def : Pat<(setle f32:$lhs, f32:$rhs), (LE_F32 f32:$lhs, f32:$rhs)>;
49 def : Pat<(setgt f32:$lhs, f32:$rhs), (GT_F32 f32:$lhs, f32:$rhs)>;
50 def : Pat<(setge f32:$lhs, f32:$rhs), (GE_F32 f32:$lhs, f32:$rhs)>;
51 def : Pat<(seteq f64:$lhs, f64:$rhs), (EQ_F64 f64:$lhs, f64:$rhs)>;
52 def : Pat<(setne f64:$lhs, f64:$rhs), (NE_F64 f64:$lhs, f64:$rhs)>;
53 def : Pat<(setlt f64:$lhs, f64:$rhs), (LT_F64 f64:$lhs, f64:$rhs)>;
54 def : Pat<(setle f64:$lhs, f64:$rhs), (LE_F64 f64:$lhs, f64:$rhs)>;
55 def : Pat<(setgt f64:$lhs, f64:$rhs), (GT_F64 f64:$lhs, f64:$rhs)>;
56 def : Pat<(setge f64:$lhs, f64:$rhs), (GE_F64 f64:$lhs, f64:$rhs)>;
57
58 def SELECT_F32 : I<(outs F32:$dst), (ins I32:$cond, F32:$lhs, F32:$rhs),
59                    [(set F32:$dst, (select I32:$cond, F32:$lhs, F32:$rhs))],
60                    "f32.select\t$dst, $cond, $lhs, $rhs">;
61 def SELECT_F64 : I<(outs F64:$dst), (ins I32:$cond, F64:$lhs, F64:$rhs),
62                    [(set F64:$dst, (select I32:$cond, F64:$lhs, F64:$rhs))],
63                    "f64.select\t$dst, $cond, $lhs, $rhs">;