blob: d2decb23e2bc62cc8b17bdc13f4eaef3ff7521a3 [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
11/// \brief WebAssembly datatype conversions, truncations, reinterpretations,
12/// promotions, and demotions operand code-gen constructs.
13///
14//===----------------------------------------------------------------------===//
15
Dan Gohmanfb3e0592015-11-25 19:36:19 +000016let Defs = [ARGUMENTS] in {
17
Dan Gohmanbc58a7b2015-11-13 00:50:04 +000018def I32_WRAP_I64 : I<(outs I32:$dst), (ins I64:$src),
19 [(set I32:$dst, (trunc I64:$src))],
Dan Gohmanc9682972016-10-24 20:21:49 +000020 "i32.wrap/i64\t$dst, $src", 0xa7>;
Dan Gohmandc51b962015-10-03 02:10:28 +000021
Dan Gohmanbc58a7b2015-11-13 00:50:04 +000022def I64_EXTEND_S_I32 : I<(outs I64:$dst), (ins I32:$src),
23 [(set I64:$dst, (sext I32:$src))],
Dan Gohmanc9682972016-10-24 20:21:49 +000024 "i64.extend_s/i32\t$dst, $src", 0xac>;
Dan Gohmanbc58a7b2015-11-13 00:50:04 +000025def I64_EXTEND_U_I32 : I<(outs I64:$dst), (ins I32:$src),
26 [(set I64:$dst, (zext I32:$src))],
Dan Gohmanc9682972016-10-24 20:21:49 +000027 "i64.extend_u/i32\t$dst, $src", 0xad>;
Dan Gohmandc51b962015-10-03 02:10:28 +000028
Derek Schuffa519fe52017-09-13 00:29:06 +000029let Predicates = [HasAtomics] in {
30def I32_EXTEND8_S_I32 : I<(outs I32:$dst), (ins I32:$src),
31 [(set I32:$dst, (sext_inreg I32:$src, i8))],
32 "i32.extend8_s\t$dst, $src", 0xc0>;
33def I32_EXTEND16_S_I32 : I<(outs I32:$dst), (ins I32:$src),
34 [(set I32:$dst, (sext_inreg I32:$src, i16))],
35 "i32.extend16_s\t$dst, $src", 0xc1>;
36def I64_EXTEND8_S_I64 : I<(outs I64:$dst), (ins I64:$src),
37 [(set I64:$dst, (sext_inreg I64:$src, i8))],
38 "i64.extend8_s\t$dst, $src", 0xc2>;
39def I64_EXTEND16_S_I64 : I<(outs I64:$dst), (ins I64:$src),
40 [(set I64:$dst, (sext_inreg I64:$src, i16))],
41 "i64.extend16_s\t$dst, $src", 0xc3>;
42def I64_EXTEND32_S_I64 : I<(outs I64:$dst), (ins I64:$src),
43 [(set I64:$dst, (sext_inreg I64:$src, i32))],
44 "i64.extend32_s\t$dst, $src", 0xc4>;
45} // Predicates = [HasAtomics]
46
Dan Gohmandf00a9e2015-12-10 00:17:35 +000047} // defs = [ARGUMENTS]
48
49// Expand a "don't care" extend into zero-extend (chosen over sign-extend
50// somewhat arbitrarily, although it favors popular hardware architectures
51// and is conceptually a simpler operation).
52def : Pat<(i64 (anyext I32:$src)), (I64_EXTEND_U_I32 I32:$src)>;
53
54let Defs = [ARGUMENTS] in {
55
Dan Gohman174b2d82015-11-29 22:59:19 +000056// Conversion from floating point to integer traps on overflow and invalid.
57let hasSideEffects = 1 in {
Dan Gohmanbc58a7b2015-11-13 00:50:04 +000058def I32_TRUNC_S_F32 : I<(outs I32:$dst), (ins F32:$src),
59 [(set I32:$dst, (fp_to_sint F32:$src))],
Dan Gohmanc9682972016-10-24 20:21:49 +000060 "i32.trunc_s/f32\t$dst, $src", 0xa8>;
Dan Gohmanbc58a7b2015-11-13 00:50:04 +000061def I32_TRUNC_U_F32 : I<(outs I32:$dst), (ins F32:$src),
62 [(set I32:$dst, (fp_to_uint F32:$src))],
Dan Gohmanc9682972016-10-24 20:21:49 +000063 "i32.trunc_u/f32\t$dst, $src", 0xa9>;
Dan Gohmanbc58a7b2015-11-13 00:50:04 +000064def I64_TRUNC_S_F32 : I<(outs I64:$dst), (ins F32:$src),
65 [(set I64:$dst, (fp_to_sint F32:$src))],
Dan Gohmanc9682972016-10-24 20:21:49 +000066 "i64.trunc_s/f32\t$dst, $src", 0xae>;
Dan Gohmanbc58a7b2015-11-13 00:50:04 +000067def I64_TRUNC_U_F32 : I<(outs I64:$dst), (ins F32:$src),
68 [(set I64:$dst, (fp_to_uint F32:$src))],
Dan Gohmanc9682972016-10-24 20:21:49 +000069 "i64.trunc_u/f32\t$dst, $src", 0xaf>;
Dan Gohmanbc58a7b2015-11-13 00:50:04 +000070def I32_TRUNC_S_F64 : I<(outs I32:$dst), (ins F64:$src),
71 [(set I32:$dst, (fp_to_sint F64:$src))],
Dan Gohmanc9682972016-10-24 20:21:49 +000072 "i32.trunc_s/f64\t$dst, $src", 0xaa>;
Dan Gohmanbc58a7b2015-11-13 00:50:04 +000073def I32_TRUNC_U_F64 : I<(outs I32:$dst), (ins F64:$src),
74 [(set I32:$dst, (fp_to_uint F64:$src))],
Dan Gohmanc9682972016-10-24 20:21:49 +000075 "i32.trunc_u/f64\t$dst, $src", 0xab>;
Dan Gohmanbc58a7b2015-11-13 00:50:04 +000076def I64_TRUNC_S_F64 : I<(outs I64:$dst), (ins F64:$src),
77 [(set I64:$dst, (fp_to_sint F64:$src))],
Dan Gohmanc9682972016-10-24 20:21:49 +000078 "i64.trunc_s/f64\t$dst, $src", 0xb0>;
Dan Gohmanbc58a7b2015-11-13 00:50:04 +000079def I64_TRUNC_U_F64 : I<(outs I64:$dst), (ins F64:$src),
80 [(set I64:$dst, (fp_to_uint F64:$src))],
Dan Gohmanc9682972016-10-24 20:21:49 +000081 "i64.trunc_u/f64\t$dst, $src", 0xb1>;
Dan Gohman174b2d82015-11-29 22:59:19 +000082} // hasSideEffects = 1
Dan Gohmandc51b962015-10-03 02:10:28 +000083
Dan Gohmanbc58a7b2015-11-13 00:50:04 +000084def F32_CONVERT_S_I32 : I<(outs F32:$dst), (ins I32:$src),
85 [(set F32:$dst, (sint_to_fp I32:$src))],
Dan Gohmanc9682972016-10-24 20:21:49 +000086 "f32.convert_s/i32\t$dst, $src", 0xb2>;
Dan Gohmanbc58a7b2015-11-13 00:50:04 +000087def F32_CONVERT_U_I32 : I<(outs F32:$dst), (ins I32:$src),
88 [(set F32:$dst, (uint_to_fp I32:$src))],
Dan Gohmanc9682972016-10-24 20:21:49 +000089 "f32.convert_u/i32\t$dst, $src", 0xb3>;
Dan Gohmanbc58a7b2015-11-13 00:50:04 +000090def F64_CONVERT_S_I32 : I<(outs F64:$dst), (ins I32:$src),
91 [(set F64:$dst, (sint_to_fp I32:$src))],
Dan Gohmanc9682972016-10-24 20:21:49 +000092 "f64.convert_s/i32\t$dst, $src", 0xb7>;
Dan Gohmanbc58a7b2015-11-13 00:50:04 +000093def F64_CONVERT_U_I32 : I<(outs F64:$dst), (ins I32:$src),
94 [(set F64:$dst, (uint_to_fp I32:$src))],
Dan Gohmanc9682972016-10-24 20:21:49 +000095 "f64.convert_u/i32\t$dst, $src", 0xb8>;
Dan Gohmanbc58a7b2015-11-13 00:50:04 +000096def F32_CONVERT_S_I64 : I<(outs F32:$dst), (ins I64:$src),
97 [(set F32:$dst, (sint_to_fp I64:$src))],
Dan Gohmanc9682972016-10-24 20:21:49 +000098 "f32.convert_s/i64\t$dst, $src", 0xb4>;
Dan Gohmanbc58a7b2015-11-13 00:50:04 +000099def F32_CONVERT_U_I64 : I<(outs F32:$dst), (ins I64:$src),
100 [(set F32:$dst, (uint_to_fp I64:$src))],
Dan Gohmanc9682972016-10-24 20:21:49 +0000101 "f32.convert_u/i64\t$dst, $src", 0xb5>;
Dan Gohmanbc58a7b2015-11-13 00:50:04 +0000102def F64_CONVERT_S_I64 : I<(outs F64:$dst), (ins I64:$src),
103 [(set F64:$dst, (sint_to_fp I64:$src))],
Dan Gohmanc9682972016-10-24 20:21:49 +0000104 "f64.convert_s/i64\t$dst, $src", 0xb9>;
Dan Gohmanbc58a7b2015-11-13 00:50:04 +0000105def F64_CONVERT_U_I64 : I<(outs F64:$dst), (ins I64:$src),
106 [(set F64:$dst, (uint_to_fp I64:$src))],
Dan Gohmanc9682972016-10-24 20:21:49 +0000107 "f64.convert_u/i64\t$dst, $src", 0xba>;
Dan Gohmandc51b962015-10-03 02:10:28 +0000108
Dan Gohmanbc58a7b2015-11-13 00:50:04 +0000109def F64_PROMOTE_F32 : I<(outs F64:$dst), (ins F32:$src),
Michael Kuperstein2bc3d4d2016-08-18 20:08:15 +0000110 [(set F64:$dst, (fpextend F32:$src))],
Dan Gohmanc9682972016-10-24 20:21:49 +0000111 "f64.promote/f32\t$dst, $src", 0xbb>;
Dan Gohmanbc58a7b2015-11-13 00:50:04 +0000112def F32_DEMOTE_F64 : I<(outs F32:$dst), (ins F64:$src),
Michael Kuperstein2bc3d4d2016-08-18 20:08:15 +0000113 [(set F32:$dst, (fpround F64:$src))],
Dan Gohmanc9682972016-10-24 20:21:49 +0000114 "f32.demote/f64\t$dst, $src", 0xb6>;
Dan Gohmandc51b962015-10-03 02:10:28 +0000115
Dan Gohmanbc58a7b2015-11-13 00:50:04 +0000116def I32_REINTERPRET_F32 : I<(outs I32:$dst), (ins F32:$src),
117 [(set I32:$dst, (bitconvert F32:$src))],
Dan Gohmanc9682972016-10-24 20:21:49 +0000118 "i32.reinterpret/f32\t$dst, $src", 0xbc>;
Dan Gohmanbc58a7b2015-11-13 00:50:04 +0000119def F32_REINTERPRET_I32 : I<(outs F32:$dst), (ins I32:$src),
120 [(set F32:$dst, (bitconvert I32:$src))],
Dan Gohmanc9682972016-10-24 20:21:49 +0000121 "f32.reinterpret/i32\t$dst, $src", 0xbe>;
Dan Gohmanbc58a7b2015-11-13 00:50:04 +0000122def I64_REINTERPRET_F64 : I<(outs I64:$dst), (ins F64:$src),
123 [(set I64:$dst, (bitconvert F64:$src))],
Dan Gohmanc9682972016-10-24 20:21:49 +0000124 "i64.reinterpret/f64\t$dst, $src", 0xbd>;
Dan Gohmanbc58a7b2015-11-13 00:50:04 +0000125def F64_REINTERPRET_I64 : I<(outs F64:$dst), (ins I64:$src),
126 [(set F64:$dst, (bitconvert I64:$src))],
Dan Gohmanc9682972016-10-24 20:21:49 +0000127 "f64.reinterpret/i64\t$dst, $src", 0xbf>;
Dan Gohmanfb3e0592015-11-25 19:36:19 +0000128
129} // Defs = [ARGUMENTS]