blob: c89c1b549816549b839aa7a9b117bda458b1ac39 [file] [log] [blame]
JF Bastien5ca0bac2015-07-10 18:23:10 +00001//===-- WebAssemblyInstrConv.td-WebAssembly Conversion 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
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000011/// WebAssembly datatype conversions, truncations, reinterpretations,
JF Bastien5ca0bac2015-07-10 18:23:10 +000012/// promotions, and demotions operand code-gen constructs.
13///
14//===----------------------------------------------------------------------===//
15
Dan Gohmanfb3e0592015-11-25 19:36:19 +000016let Defs = [ARGUMENTS] in {
17
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +000018defm I32_WRAP_I64 : I<(outs I32:$dst), (ins I64:$src), (outs), (ins),
Dan Gohmanbc58a7b2015-11-13 00:50:04 +000019 [(set I32:$dst, (trunc I64:$src))],
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +000020 "i32.wrap/i64\t$dst, $src", "i32.wrap/i64", 0xa7>;
Dan Gohmandc51b962015-10-03 02:10:28 +000021
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +000022defm I64_EXTEND_S_I32 : I<(outs I64:$dst), (ins I32:$src), (outs), (ins),
Dan Gohmanbc58a7b2015-11-13 00:50:04 +000023 [(set I64:$dst, (sext I32:$src))],
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +000024 "i64.extend_s/i32\t$dst, $src", "i64.extend_s/i32",
25 0xac>;
26defm I64_EXTEND_U_I32 : I<(outs I64:$dst), (ins I32:$src), (outs), (ins),
27 [(set I64:$dst, (zext I32:$src))],
28 "i64.extend_u/i32\t$dst, $src", "i64.extend_u/i32",
29 0xad>;
Dan Gohmandc51b962015-10-03 02:10:28 +000030
Dan Gohman5d2b9352018-01-19 17:16:24 +000031let Predicates = [HasSignExt] in {
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +000032defm I32_EXTEND8_S_I32 : I<(outs I32:$dst), (ins I32:$src), (outs), (ins),
33 [(set I32:$dst, (sext_inreg I32:$src, i8))],
34 "i32.extend8_s\t$dst, $src", "i32.extend8_s",
35 0xc0>;
36defm I32_EXTEND16_S_I32 : I<(outs I32:$dst), (ins I32:$src), (outs), (ins),
37 [(set I32:$dst, (sext_inreg I32:$src, i16))],
38 "i32.extend16_s\t$dst, $src", "i32.extend16_s",
39 0xc1>;
40defm I64_EXTEND8_S_I64 : I<(outs I64:$dst), (ins I64:$src), (outs), (ins),
41 [(set I64:$dst, (sext_inreg I64:$src, i8))],
42 "i64.extend8_s\t$dst, $src", "i64.extend8_s",
43 0xc2>;
44defm I64_EXTEND16_S_I64 : I<(outs I64:$dst), (ins I64:$src), (outs), (ins),
45 [(set I64:$dst, (sext_inreg I64:$src, i16))],
46 "i64.extend16_s\t$dst, $src", "i64.extend16_s",
47 0xc3>;
48defm I64_EXTEND32_S_I64 : I<(outs I64:$dst), (ins I64:$src), (outs), (ins),
49 [(set I64:$dst, (sext_inreg I64:$src, i32))],
50 "i64.extend32_s\t$dst, $src", "i64.extend32_s",
51 0xc4>;
Dan Gohman5d2b9352018-01-19 17:16:24 +000052} // Predicates = [HasSignExt]
Derek Schuffa519fe52017-09-13 00:29:06 +000053
Dan Gohmandf00a9e2015-12-10 00:17:35 +000054} // defs = [ARGUMENTS]
55
56// Expand a "don't care" extend into zero-extend (chosen over sign-extend
57// somewhat arbitrarily, although it favors popular hardware architectures
58// and is conceptually a simpler operation).
59def : Pat<(i64 (anyext I32:$src)), (I64_EXTEND_U_I32 I32:$src)>;
60
61let Defs = [ARGUMENTS] in {
62
Dan Gohmancdd48b82017-11-28 01:13:40 +000063// Conversion from floating point to integer instructions which don't trap on
64// overflow or invalid.
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +000065defm I32_TRUNC_S_SAT_F32 : I<(outs I32:$dst), (ins F32:$src), (outs), (ins),
66 [(set I32:$dst, (fp_to_sint F32:$src))],
67 "i32.trunc_s:sat/f32\t$dst, $src",
68 "i32.trunc_s:sat/f32", 0xfc00>,
69 Requires<[HasNontrappingFPToInt]>;
70defm I32_TRUNC_U_SAT_F32 : I<(outs I32:$dst), (ins F32:$src), (outs), (ins),
71 [(set I32:$dst, (fp_to_uint F32:$src))],
72 "i32.trunc_u:sat/f32\t$dst, $src",
73 "i32.trunc_u:sat/f32", 0xfc01>,
74 Requires<[HasNontrappingFPToInt]>;
75defm I64_TRUNC_S_SAT_F32 : I<(outs I64:$dst), (ins F32:$src), (outs), (ins),
76 [(set I64:$dst, (fp_to_sint F32:$src))],
77 "i64.trunc_s:sat/f32\t$dst, $src",
78 "i64.trunc_s:sat/f32", 0xfc04>,
79 Requires<[HasNontrappingFPToInt]>;
80defm I64_TRUNC_U_SAT_F32 : I<(outs I64:$dst), (ins F32:$src), (outs), (ins),
81 [(set I64:$dst, (fp_to_uint F32:$src))],
82 "i64.trunc_u:sat/f32\t$dst, $src",
83 "i64.trunc_u:sat/f32", 0xfc05>,
84 Requires<[HasNontrappingFPToInt]>;
85defm I32_TRUNC_S_SAT_F64 : I<(outs I32:$dst), (ins F64:$src), (outs), (ins),
86 [(set I32:$dst, (fp_to_sint F64:$src))],
87 "i32.trunc_s:sat/f64\t$dst, $src",
88 "i32.trunc_s:sat/f64", 0xfc02>,
89 Requires<[HasNontrappingFPToInt]>;
90defm I32_TRUNC_U_SAT_F64 : I<(outs I32:$dst), (ins F64:$src), (outs), (ins),
91 [(set I32:$dst, (fp_to_uint F64:$src))],
92 "i32.trunc_u:sat/f64\t$dst, $src",
93 "i32.trunc_u:sat/f64", 0xfc03>,
94 Requires<[HasNontrappingFPToInt]>;
95defm I64_TRUNC_S_SAT_F64 : I<(outs I64:$dst), (ins F64:$src), (outs), (ins),
96 [(set I64:$dst, (fp_to_sint F64:$src))],
97 "i64.trunc_s:sat/f64\t$dst, $src",
98 "i64.trunc_s:sat/f64", 0xfc06>,
99 Requires<[HasNontrappingFPToInt]>;
100defm I64_TRUNC_U_SAT_F64 : I<(outs I64:$dst), (ins F64:$src), (outs), (ins),
101 [(set I64:$dst, (fp_to_uint F64:$src))],
102 "i64.trunc_u:sat/f64\t$dst, $src",
103 "i64.trunc_u:sat/f64", 0xfc07>,
104 Requires<[HasNontrappingFPToInt]>;
Dan Gohmancdd48b82017-11-28 01:13:40 +0000105
106// Conversion from floating point to integer pseudo-instructions which don't
107// trap on overflow or invalid.
108let usesCustomInserter = 1, isCodeGenOnly = 1 in {
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000109defm FP_TO_SINT_I32_F32 : I<(outs I32:$dst), (ins F32:$src), (outs), (ins),
110 [(set I32:$dst, (fp_to_sint F32:$src))], "", "", 0>,
111 Requires<[NotHasNontrappingFPToInt]>;
112defm FP_TO_UINT_I32_F32 : I<(outs I32:$dst), (ins F32:$src), (outs), (ins),
113 [(set I32:$dst, (fp_to_uint F32:$src))], "", "", 0>,
114 Requires<[NotHasNontrappingFPToInt]>;
115defm FP_TO_SINT_I64_F32 : I<(outs I64:$dst), (ins F32:$src), (outs), (ins),
116 [(set I64:$dst, (fp_to_sint F32:$src))], "", "", 0>,
117 Requires<[NotHasNontrappingFPToInt]>;
118defm FP_TO_UINT_I64_F32 : I<(outs I64:$dst), (ins F32:$src), (outs), (ins),
119 [(set I64:$dst, (fp_to_uint F32:$src))], "", "", 0>,
120 Requires<[NotHasNontrappingFPToInt]>;
121defm FP_TO_SINT_I32_F64 : I<(outs I32:$dst), (ins F64:$src), (outs), (ins),
122 [(set I32:$dst, (fp_to_sint F64:$src))], "", "", 0>,
123 Requires<[NotHasNontrappingFPToInt]>;
124defm FP_TO_UINT_I32_F64 : I<(outs I32:$dst), (ins F64:$src), (outs), (ins),
125 [(set I32:$dst, (fp_to_uint F64:$src))], "", "", 0>,
126 Requires<[NotHasNontrappingFPToInt]>;
127defm FP_TO_SINT_I64_F64 : I<(outs I64:$dst), (ins F64:$src), (outs), (ins),
128 [(set I64:$dst, (fp_to_sint F64:$src))], "", "", 0>,
129 Requires<[NotHasNontrappingFPToInt]>;
130defm FP_TO_UINT_I64_F64 : I<(outs I64:$dst), (ins F64:$src), (outs), (ins),
131 [(set I64:$dst, (fp_to_uint F64:$src))], "", "", 0>,
132 Requires<[NotHasNontrappingFPToInt]>;
Dan Gohmancdd48b82017-11-28 01:13:40 +0000133} // usesCustomInserter, isCodeGenOnly = 1
134
Dan Gohman174b2d82015-11-29 22:59:19 +0000135// Conversion from floating point to integer traps on overflow and invalid.
136let hasSideEffects = 1 in {
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000137defm I32_TRUNC_S_F32 : I<(outs I32:$dst), (ins F32:$src), (outs), (ins),
138 [], "i32.trunc_s/f32\t$dst, $src", "i32.trunc_s/f32",
139 0xa8>;
140defm I32_TRUNC_U_F32 : I<(outs I32:$dst), (ins F32:$src), (outs), (ins),
141 [], "i32.trunc_u/f32\t$dst, $src", "i32.trunc_u/f32",
142 0xa9>;
143defm I64_TRUNC_S_F32 : I<(outs I64:$dst), (ins F32:$src), (outs), (ins),
144 [], "i64.trunc_s/f32\t$dst, $src", "i64.trunc_s/f32",
145 0xae>;
146defm I64_TRUNC_U_F32 : I<(outs I64:$dst), (ins F32:$src), (outs), (ins),
147 [], "i64.trunc_u/f32\t$dst, $src", "i64.trunc_u/f32",
148 0xaf>;
149defm I32_TRUNC_S_F64 : I<(outs I32:$dst), (ins F64:$src), (outs), (ins),
150 [], "i32.trunc_s/f64\t$dst, $src", "i32.trunc_s/f64",
151 0xaa>;
152defm I32_TRUNC_U_F64 : I<(outs I32:$dst), (ins F64:$src), (outs), (ins),
153 [], "i32.trunc_u/f64\t$dst, $src", "i32.trunc_u/f64",
154 0xab>;
155defm I64_TRUNC_S_F64 : I<(outs I64:$dst), (ins F64:$src), (outs), (ins),
156 [], "i64.trunc_s/f64\t$dst, $src", "i64.trunc_s/f64",
157 0xb0>;
158defm I64_TRUNC_U_F64 : I<(outs I64:$dst), (ins F64:$src), (outs), (ins),
159 [], "i64.trunc_u/f64\t$dst, $src", "i64.trunc_u/f64",
160 0xb1>;
Dan Gohman174b2d82015-11-29 22:59:19 +0000161} // hasSideEffects = 1
Dan Gohmandc51b962015-10-03 02:10:28 +0000162
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000163defm F32_CONVERT_S_I32 : I<(outs F32:$dst), (ins I32:$src), (outs), (ins),
164 [(set F32:$dst, (sint_to_fp I32:$src))],
165 "f32.convert_s/i32\t$dst, $src", "f32.convert_s/i32",
166 0xb2>;
167defm F32_CONVERT_U_I32 : I<(outs F32:$dst), (ins I32:$src), (outs), (ins),
168 [(set F32:$dst, (uint_to_fp I32:$src))],
169 "f32.convert_u/i32\t$dst, $src", "f32.convert_u/i32",
170 0xb3>;
171defm F64_CONVERT_S_I32 : I<(outs F64:$dst), (ins I32:$src), (outs), (ins),
172 [(set F64:$dst, (sint_to_fp I32:$src))],
173 "f64.convert_s/i32\t$dst, $src", "f64.convert_s/i32",
174 0xb7>;
175defm F64_CONVERT_U_I32 : I<(outs F64:$dst), (ins I32:$src), (outs), (ins),
176 [(set F64:$dst, (uint_to_fp I32:$src))],
177 "f64.convert_u/i32\t$dst, $src", "f64.convert_u/i32",
178 0xb8>;
179defm F32_CONVERT_S_I64 : I<(outs F32:$dst), (ins I64:$src), (outs), (ins),
180 [(set F32:$dst, (sint_to_fp I64:$src))],
181 "f32.convert_s/i64\t$dst, $src", "f32.convert_s/i64",
182 0xb4>;
183defm F32_CONVERT_U_I64 : I<(outs F32:$dst), (ins I64:$src), (outs), (ins),
184 [(set F32:$dst, (uint_to_fp I64:$src))],
185 "f32.convert_u/i64\t$dst, $src", "f32.convert_u/i64",
186 0xb5>;
187defm F64_CONVERT_S_I64 : I<(outs F64:$dst), (ins I64:$src), (outs), (ins),
188 [(set F64:$dst, (sint_to_fp I64:$src))],
189 "f64.convert_s/i64\t$dst, $src", "f64.convert_s/i64",
190 0xb9>;
191defm F64_CONVERT_U_I64 : I<(outs F64:$dst), (ins I64:$src), (outs), (ins),
192 [(set F64:$dst, (uint_to_fp I64:$src))],
193 "f64.convert_u/i64\t$dst, $src", "f64.convert_u/i64",
194 0xba>;
Dan Gohmandc51b962015-10-03 02:10:28 +0000195
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000196defm F64_PROMOTE_F32 : I<(outs F64:$dst), (ins F32:$src), (outs), (ins),
197 [(set F64:$dst, (fpextend F32:$src))],
198 "f64.promote/f32\t$dst, $src", "f64.promote/f32",
199 0xbb>;
200defm F32_DEMOTE_F64 : I<(outs F32:$dst), (ins F64:$src), (outs), (ins),
201 [(set F32:$dst, (fpround F64:$src))],
202 "f32.demote/f64\t$dst, $src", "f32.demote/f64",
203 0xb6>;
Dan Gohmandc51b962015-10-03 02:10:28 +0000204
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +0000205defm I32_REINTERPRET_F32 : I<(outs I32:$dst), (ins F32:$src), (outs), (ins),
206 [(set I32:$dst, (bitconvert F32:$src))],
207 "i32.reinterpret/f32\t$dst, $src",
208 "i32.reinterpret/f32", 0xbc>;
209defm F32_REINTERPRET_I32 : I<(outs F32:$dst), (ins I32:$src), (outs), (ins),
210 [(set F32:$dst, (bitconvert I32:$src))],
211 "f32.reinterpret/i32\t$dst, $src",
212 "f32.reinterpret/i32", 0xbe>;
213defm I64_REINTERPRET_F64 : I<(outs I64:$dst), (ins F64:$src), (outs), (ins),
214 [(set I64:$dst, (bitconvert F64:$src))],
215 "i64.reinterpret/f64\t$dst, $src",
216 "i64.reinterpret/f64", 0xbd>;
217defm F64_REINTERPRET_I64 : I<(outs F64:$dst), (ins I64:$src), (outs), (ins),
218 [(set F64:$dst, (bitconvert I64:$src))],
219 "f64.reinterpret/i64\t$dst, $src",
220 "f64.reinterpret/i64", 0xbf>;
Dan Gohmanfb3e0592015-11-25 19:36:19 +0000221
222} // Defs = [ARGUMENTS]