blob: 689aeac62918ba8d6549705460f6c839713a029e [file] [log] [blame]
JF Bastien5ca0bac2015-07-10 18:23:10 +00001// 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
Dan Gohmanaf29bd42015-11-05 20:42:30 +000015defm ADD : BinaryFP<fadd, "add">;
16defm SUB : BinaryFP<fsub, "sub">;
17defm MUL : BinaryFP<fmul, "mul">;
18defm DIV : BinaryFP<fdiv, "div">;
19defm SQRT : UnaryFP<fsqrt, "sqrt">;
Dan Gohman896e53f2015-08-24 18:23:13 +000020
Dan Gohmanaf29bd42015-11-05 20:42:30 +000021defm ABS : UnaryFP<fabs, "abs">;
22defm NEG : UnaryFP<fneg, "neg">;
23defm COPYSIGN : BinaryFP<fcopysign, "copysign">;
JF Bastienef172fc2015-08-11 02:45:15 +000024
Dan Gohmanaf29bd42015-11-05 20:42:30 +000025defm CEIL : UnaryFP<fceil, "ceil">;
26defm FLOOR : UnaryFP<ffloor, "floor">;
27defm TRUNC : UnaryFP<ftrunc, "trunc">;
28defm NEAREST : UnaryFP<fnearbyint, "nearest">;
Dan Gohman896e53f2015-08-24 18:23:13 +000029
30// WebAssembly doesn't expose inexact exceptions, so map frint to fnearbyint.
Dan Gohmand0bf9812015-09-26 01:09:44 +000031def : Pat<(frint f32:$src), (NEAREST_F32 f32:$src)>;
32def : Pat<(frint f64:$src), (NEAREST_F64 f64:$src)>;
JF Bastiend9767a32015-07-14 21:13:29 +000033
Dan Gohmanaf29bd42015-11-05 20:42:30 +000034defm EQ : ComparisonFP<SETOEQ, "eq">;
35defm NE : ComparisonFP<SETUNE, "ne">;
36defm LT : ComparisonFP<SETOLT, "lt">;
37defm LE : ComparisonFP<SETOLE, "le">;
38defm GT : ComparisonFP<SETOGT, "gt">;
39defm GE : ComparisonFP<SETOGE, "ge">;
JF Bastiend9767a32015-07-14 21:13:29 +000040
JF Bastien71d29ac2015-08-12 17:53:29 +000041// Don't care floating-point comparisons, supported via other comparisons.
42def : Pat<(seteq f32:$lhs, f32:$rhs), (EQ_F32 f32:$lhs, f32:$rhs)>;
43def : Pat<(setne f32:$lhs, f32:$rhs), (NE_F32 f32:$lhs, f32:$rhs)>;
44def : Pat<(setlt f32:$lhs, f32:$rhs), (LT_F32 f32:$lhs, f32:$rhs)>;
45def : Pat<(setle f32:$lhs, f32:$rhs), (LE_F32 f32:$lhs, f32:$rhs)>;
46def : Pat<(setgt f32:$lhs, f32:$rhs), (GT_F32 f32:$lhs, f32:$rhs)>;
47def : Pat<(setge f32:$lhs, f32:$rhs), (GE_F32 f32:$lhs, f32:$rhs)>;
48def : Pat<(seteq f64:$lhs, f64:$rhs), (EQ_F64 f64:$lhs, f64:$rhs)>;
49def : Pat<(setne f64:$lhs, f64:$rhs), (NE_F64 f64:$lhs, f64:$rhs)>;
50def : Pat<(setlt f64:$lhs, f64:$rhs), (LT_F64 f64:$lhs, f64:$rhs)>;
51def : Pat<(setle f64:$lhs, f64:$rhs), (LE_F64 f64:$lhs, f64:$rhs)>;
52def : Pat<(setgt f64:$lhs, f64:$rhs), (GT_F64 f64:$lhs, f64:$rhs)>;
53def : Pat<(setge f64:$lhs, f64:$rhs), (GE_F64 f64:$lhs, f64:$rhs)>;
54
JF Bastiend9767a32015-07-14 21:13:29 +000055/*
56 * TODO(jfb): Add the following for 32-bit and 64-bit.
57 *
Dan Gohmand0bf9812015-09-26 01:09:44 +000058 * f32.min: minimum (binary operator); if either operand is NaN, returns NaN
59 * f32.max: maximum (binary operator); if either operand is NaN, returns NaN
JF Bastien5ca0bac2015-07-10 18:23:10 +000060 */
Derek Schuff6b5c6da2015-11-03 22:40:40 +000061
62def SELECT_F32 : I<(outs F32:$dst), (ins I32:$cond, F32:$lhs, F32:$rhs),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000063 [(set F32:$dst, (select I32:$cond, F32:$lhs, F32:$rhs))],
64 "f32.select $dst, $cond, $lhs, $rhs">;
Derek Schuff6b5c6da2015-11-03 22:40:40 +000065def SELECT_F64 : I<(outs F64:$dst), (ins I32:$cond, F64:$lhs, F64:$rhs),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000066 [(set F64:$dst, (select I32:$cond, F64:$lhs, F64:$rhs))],
67 "f64.select $dst, $cond, $lhs, $rhs">;