JF Bastien | 5ca0bac | 2015-07-10 18:23:10 +0000 | [diff] [blame] | 1 | //===-- 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 Gohman | fb3e059 | 2015-11-25 19:36:19 +0000 | [diff] [blame] | 16 | let Defs = [ARGUMENTS] in { |
| 17 | |
Dan Gohman | bc58a7b | 2015-11-13 00:50:04 +0000 | [diff] [blame] | 18 | def I32_WRAP_I64 : I<(outs I32:$dst), (ins I64:$src), |
| 19 | [(set I32:$dst, (trunc I64:$src))], |
Dan Gohman | c968297 | 2016-10-24 20:21:49 +0000 | [diff] [blame] | 20 | "i32.wrap/i64\t$dst, $src", 0xa7>; |
Dan Gohman | dc51b96 | 2015-10-03 02:10:28 +0000 | [diff] [blame] | 21 | |
Dan Gohman | bc58a7b | 2015-11-13 00:50:04 +0000 | [diff] [blame] | 22 | def I64_EXTEND_S_I32 : I<(outs I64:$dst), (ins I32:$src), |
| 23 | [(set I64:$dst, (sext I32:$src))], |
Dan Gohman | c968297 | 2016-10-24 20:21:49 +0000 | [diff] [blame] | 24 | "i64.extend_s/i32\t$dst, $src", 0xac>; |
Dan Gohman | bc58a7b | 2015-11-13 00:50:04 +0000 | [diff] [blame] | 25 | def I64_EXTEND_U_I32 : I<(outs I64:$dst), (ins I32:$src), |
| 26 | [(set I64:$dst, (zext I32:$src))], |
Dan Gohman | c968297 | 2016-10-24 20:21:49 +0000 | [diff] [blame] | 27 | "i64.extend_u/i32\t$dst, $src", 0xad>; |
Dan Gohman | dc51b96 | 2015-10-03 02:10:28 +0000 | [diff] [blame] | 28 | |
Dan Gohman | 5d2b935 | 2018-01-19 17:16:24 +0000 | [diff] [blame^] | 29 | let Predicates = [HasSignExt] in { |
Derek Schuff | a519fe5 | 2017-09-13 00:29:06 +0000 | [diff] [blame] | 30 | def 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>; |
| 33 | def 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>; |
| 36 | def 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>; |
| 39 | def 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>; |
| 42 | def 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>; |
Dan Gohman | 5d2b935 | 2018-01-19 17:16:24 +0000 | [diff] [blame^] | 45 | } // Predicates = [HasSignExt] |
Derek Schuff | a519fe5 | 2017-09-13 00:29:06 +0000 | [diff] [blame] | 46 | |
Dan Gohman | df00a9e | 2015-12-10 00:17:35 +0000 | [diff] [blame] | 47 | } // 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). |
| 52 | def : Pat<(i64 (anyext I32:$src)), (I64_EXTEND_U_I32 I32:$src)>; |
| 53 | |
| 54 | let Defs = [ARGUMENTS] in { |
| 55 | |
Dan Gohman | cdd48b8 | 2017-11-28 01:13:40 +0000 | [diff] [blame] | 56 | // Conversion from floating point to integer instructions which don't trap on |
| 57 | // overflow or invalid. |
| 58 | def I32_TRUNC_S_SAT_F32 : I<(outs I32:$dst), (ins F32:$src), |
| 59 | [(set I32:$dst, (fp_to_sint F32:$src))], |
| 60 | "i32.trunc_s:sat/f32\t$dst, $src", 0xfc00>, |
| 61 | Requires<[HasNontrappingFPToInt]>; |
| 62 | def I32_TRUNC_U_SAT_F32 : I<(outs I32:$dst), (ins F32:$src), |
| 63 | [(set I32:$dst, (fp_to_uint F32:$src))], |
| 64 | "i32.trunc_u:sat/f32\t$dst, $src", 0xfc01>, |
| 65 | Requires<[HasNontrappingFPToInt]>; |
| 66 | def I64_TRUNC_S_SAT_F32 : I<(outs I64:$dst), (ins F32:$src), |
| 67 | [(set I64:$dst, (fp_to_sint F32:$src))], |
| 68 | "i64.trunc_s:sat/f32\t$dst, $src", 0xfc04>, |
| 69 | Requires<[HasNontrappingFPToInt]>; |
| 70 | def I64_TRUNC_U_SAT_F32 : I<(outs I64:$dst), (ins F32:$src), |
| 71 | [(set I64:$dst, (fp_to_uint F32:$src))], |
| 72 | "i64.trunc_u:sat/f32\t$dst, $src", 0xfc05>, |
| 73 | Requires<[HasNontrappingFPToInt]>; |
| 74 | def I32_TRUNC_S_SAT_F64 : I<(outs I32:$dst), (ins F64:$src), |
| 75 | [(set I32:$dst, (fp_to_sint F64:$src))], |
| 76 | "i32.trunc_s:sat/f64\t$dst, $src", 0xfc02>, |
| 77 | Requires<[HasNontrappingFPToInt]>; |
| 78 | def I32_TRUNC_U_SAT_F64 : I<(outs I32:$dst), (ins F64:$src), |
| 79 | [(set I32:$dst, (fp_to_uint F64:$src))], |
| 80 | "i32.trunc_u:sat/f64\t$dst, $src", 0xfc03>, |
| 81 | Requires<[HasNontrappingFPToInt]>; |
| 82 | def I64_TRUNC_S_SAT_F64 : I<(outs I64:$dst), (ins F64:$src), |
| 83 | [(set I64:$dst, (fp_to_sint F64:$src))], |
| 84 | "i64.trunc_s:sat/f64\t$dst, $src", 0xfc06>, |
| 85 | Requires<[HasNontrappingFPToInt]>; |
| 86 | def I64_TRUNC_U_SAT_F64 : I<(outs I64:$dst), (ins F64:$src), |
| 87 | [(set I64:$dst, (fp_to_uint F64:$src))], |
| 88 | "i64.trunc_u:sat/f64\t$dst, $src", 0xfc07>, |
| 89 | Requires<[HasNontrappingFPToInt]>; |
| 90 | |
| 91 | // Conversion from floating point to integer pseudo-instructions which don't |
| 92 | // trap on overflow or invalid. |
| 93 | let usesCustomInserter = 1, isCodeGenOnly = 1 in { |
| 94 | def FP_TO_SINT_I32_F32 : I<(outs I32:$dst), (ins F32:$src), |
| 95 | [(set I32:$dst, (fp_to_sint F32:$src))], "", 0>, |
| 96 | Requires<[NotHasNontrappingFPToInt]>; |
| 97 | def FP_TO_UINT_I32_F32 : I<(outs I32:$dst), (ins F32:$src), |
| 98 | [(set I32:$dst, (fp_to_uint F32:$src))], "", 0>, |
| 99 | Requires<[NotHasNontrappingFPToInt]>; |
| 100 | def FP_TO_SINT_I64_F32 : I<(outs I64:$dst), (ins F32:$src), |
| 101 | [(set I64:$dst, (fp_to_sint F32:$src))], "", 0>, |
| 102 | Requires<[NotHasNontrappingFPToInt]>; |
| 103 | def FP_TO_UINT_I64_F32 : I<(outs I64:$dst), (ins F32:$src), |
| 104 | [(set I64:$dst, (fp_to_uint F32:$src))], "", 0>, |
| 105 | Requires<[NotHasNontrappingFPToInt]>; |
| 106 | def FP_TO_SINT_I32_F64 : I<(outs I32:$dst), (ins F64:$src), |
| 107 | [(set I32:$dst, (fp_to_sint F64:$src))], "", 0>, |
| 108 | Requires<[NotHasNontrappingFPToInt]>; |
| 109 | def FP_TO_UINT_I32_F64 : I<(outs I32:$dst), (ins F64:$src), |
| 110 | [(set I32:$dst, (fp_to_uint F64:$src))], "", 0>, |
| 111 | Requires<[NotHasNontrappingFPToInt]>; |
| 112 | def FP_TO_SINT_I64_F64 : I<(outs I64:$dst), (ins F64:$src), |
| 113 | [(set I64:$dst, (fp_to_sint F64:$src))], "", 0>, |
| 114 | Requires<[NotHasNontrappingFPToInt]>; |
| 115 | def FP_TO_UINT_I64_F64 : I<(outs I64:$dst), (ins F64:$src), |
| 116 | [(set I64:$dst, (fp_to_uint F64:$src))], "", 0>, |
| 117 | Requires<[NotHasNontrappingFPToInt]>; |
| 118 | } // usesCustomInserter, isCodeGenOnly = 1 |
| 119 | |
Dan Gohman | 174b2d8 | 2015-11-29 22:59:19 +0000 | [diff] [blame] | 120 | // Conversion from floating point to integer traps on overflow and invalid. |
| 121 | let hasSideEffects = 1 in { |
Dan Gohman | bc58a7b | 2015-11-13 00:50:04 +0000 | [diff] [blame] | 122 | def I32_TRUNC_S_F32 : I<(outs I32:$dst), (ins F32:$src), |
Dan Gohman | cdd48b8 | 2017-11-28 01:13:40 +0000 | [diff] [blame] | 123 | [], "i32.trunc_s/f32\t$dst, $src", 0xa8>; |
Dan Gohman | bc58a7b | 2015-11-13 00:50:04 +0000 | [diff] [blame] | 124 | def I32_TRUNC_U_F32 : I<(outs I32:$dst), (ins F32:$src), |
Dan Gohman | cdd48b8 | 2017-11-28 01:13:40 +0000 | [diff] [blame] | 125 | [], "i32.trunc_u/f32\t$dst, $src", 0xa9>; |
Dan Gohman | bc58a7b | 2015-11-13 00:50:04 +0000 | [diff] [blame] | 126 | def I64_TRUNC_S_F32 : I<(outs I64:$dst), (ins F32:$src), |
Dan Gohman | cdd48b8 | 2017-11-28 01:13:40 +0000 | [diff] [blame] | 127 | [], "i64.trunc_s/f32\t$dst, $src", 0xae>; |
Dan Gohman | bc58a7b | 2015-11-13 00:50:04 +0000 | [diff] [blame] | 128 | def I64_TRUNC_U_F32 : I<(outs I64:$dst), (ins F32:$src), |
Dan Gohman | cdd48b8 | 2017-11-28 01:13:40 +0000 | [diff] [blame] | 129 | [], "i64.trunc_u/f32\t$dst, $src", 0xaf>; |
Dan Gohman | bc58a7b | 2015-11-13 00:50:04 +0000 | [diff] [blame] | 130 | def I32_TRUNC_S_F64 : I<(outs I32:$dst), (ins F64:$src), |
Dan Gohman | cdd48b8 | 2017-11-28 01:13:40 +0000 | [diff] [blame] | 131 | [], "i32.trunc_s/f64\t$dst, $src", 0xaa>; |
Dan Gohman | bc58a7b | 2015-11-13 00:50:04 +0000 | [diff] [blame] | 132 | def I32_TRUNC_U_F64 : I<(outs I32:$dst), (ins F64:$src), |
Dan Gohman | cdd48b8 | 2017-11-28 01:13:40 +0000 | [diff] [blame] | 133 | [], "i32.trunc_u/f64\t$dst, $src", 0xab>; |
Dan Gohman | bc58a7b | 2015-11-13 00:50:04 +0000 | [diff] [blame] | 134 | def I64_TRUNC_S_F64 : I<(outs I64:$dst), (ins F64:$src), |
Dan Gohman | cdd48b8 | 2017-11-28 01:13:40 +0000 | [diff] [blame] | 135 | [], "i64.trunc_s/f64\t$dst, $src", 0xb0>; |
Dan Gohman | bc58a7b | 2015-11-13 00:50:04 +0000 | [diff] [blame] | 136 | def I64_TRUNC_U_F64 : I<(outs I64:$dst), (ins F64:$src), |
Dan Gohman | cdd48b8 | 2017-11-28 01:13:40 +0000 | [diff] [blame] | 137 | [], "i64.trunc_u/f64\t$dst, $src", 0xb1>; |
Dan Gohman | 174b2d8 | 2015-11-29 22:59:19 +0000 | [diff] [blame] | 138 | } // hasSideEffects = 1 |
Dan Gohman | dc51b96 | 2015-10-03 02:10:28 +0000 | [diff] [blame] | 139 | |
Dan Gohman | bc58a7b | 2015-11-13 00:50:04 +0000 | [diff] [blame] | 140 | def F32_CONVERT_S_I32 : I<(outs F32:$dst), (ins I32:$src), |
| 141 | [(set F32:$dst, (sint_to_fp I32:$src))], |
Dan Gohman | c968297 | 2016-10-24 20:21:49 +0000 | [diff] [blame] | 142 | "f32.convert_s/i32\t$dst, $src", 0xb2>; |
Dan Gohman | bc58a7b | 2015-11-13 00:50:04 +0000 | [diff] [blame] | 143 | def F32_CONVERT_U_I32 : I<(outs F32:$dst), (ins I32:$src), |
| 144 | [(set F32:$dst, (uint_to_fp I32:$src))], |
Dan Gohman | c968297 | 2016-10-24 20:21:49 +0000 | [diff] [blame] | 145 | "f32.convert_u/i32\t$dst, $src", 0xb3>; |
Dan Gohman | bc58a7b | 2015-11-13 00:50:04 +0000 | [diff] [blame] | 146 | def F64_CONVERT_S_I32 : I<(outs F64:$dst), (ins I32:$src), |
| 147 | [(set F64:$dst, (sint_to_fp I32:$src))], |
Dan Gohman | c968297 | 2016-10-24 20:21:49 +0000 | [diff] [blame] | 148 | "f64.convert_s/i32\t$dst, $src", 0xb7>; |
Dan Gohman | bc58a7b | 2015-11-13 00:50:04 +0000 | [diff] [blame] | 149 | def F64_CONVERT_U_I32 : I<(outs F64:$dst), (ins I32:$src), |
| 150 | [(set F64:$dst, (uint_to_fp I32:$src))], |
Dan Gohman | c968297 | 2016-10-24 20:21:49 +0000 | [diff] [blame] | 151 | "f64.convert_u/i32\t$dst, $src", 0xb8>; |
Dan Gohman | bc58a7b | 2015-11-13 00:50:04 +0000 | [diff] [blame] | 152 | def F32_CONVERT_S_I64 : I<(outs F32:$dst), (ins I64:$src), |
| 153 | [(set F32:$dst, (sint_to_fp I64:$src))], |
Dan Gohman | c968297 | 2016-10-24 20:21:49 +0000 | [diff] [blame] | 154 | "f32.convert_s/i64\t$dst, $src", 0xb4>; |
Dan Gohman | bc58a7b | 2015-11-13 00:50:04 +0000 | [diff] [blame] | 155 | def F32_CONVERT_U_I64 : I<(outs F32:$dst), (ins I64:$src), |
| 156 | [(set F32:$dst, (uint_to_fp I64:$src))], |
Dan Gohman | c968297 | 2016-10-24 20:21:49 +0000 | [diff] [blame] | 157 | "f32.convert_u/i64\t$dst, $src", 0xb5>; |
Dan Gohman | bc58a7b | 2015-11-13 00:50:04 +0000 | [diff] [blame] | 158 | def F64_CONVERT_S_I64 : I<(outs F64:$dst), (ins I64:$src), |
| 159 | [(set F64:$dst, (sint_to_fp I64:$src))], |
Dan Gohman | c968297 | 2016-10-24 20:21:49 +0000 | [diff] [blame] | 160 | "f64.convert_s/i64\t$dst, $src", 0xb9>; |
Dan Gohman | bc58a7b | 2015-11-13 00:50:04 +0000 | [diff] [blame] | 161 | def F64_CONVERT_U_I64 : I<(outs F64:$dst), (ins I64:$src), |
| 162 | [(set F64:$dst, (uint_to_fp I64:$src))], |
Dan Gohman | c968297 | 2016-10-24 20:21:49 +0000 | [diff] [blame] | 163 | "f64.convert_u/i64\t$dst, $src", 0xba>; |
Dan Gohman | dc51b96 | 2015-10-03 02:10:28 +0000 | [diff] [blame] | 164 | |
Dan Gohman | bc58a7b | 2015-11-13 00:50:04 +0000 | [diff] [blame] | 165 | def F64_PROMOTE_F32 : I<(outs F64:$dst), (ins F32:$src), |
Michael Kuperstein | 2bc3d4d | 2016-08-18 20:08:15 +0000 | [diff] [blame] | 166 | [(set F64:$dst, (fpextend F32:$src))], |
Dan Gohman | c968297 | 2016-10-24 20:21:49 +0000 | [diff] [blame] | 167 | "f64.promote/f32\t$dst, $src", 0xbb>; |
Dan Gohman | bc58a7b | 2015-11-13 00:50:04 +0000 | [diff] [blame] | 168 | def F32_DEMOTE_F64 : I<(outs F32:$dst), (ins F64:$src), |
Michael Kuperstein | 2bc3d4d | 2016-08-18 20:08:15 +0000 | [diff] [blame] | 169 | [(set F32:$dst, (fpround F64:$src))], |
Dan Gohman | c968297 | 2016-10-24 20:21:49 +0000 | [diff] [blame] | 170 | "f32.demote/f64\t$dst, $src", 0xb6>; |
Dan Gohman | dc51b96 | 2015-10-03 02:10:28 +0000 | [diff] [blame] | 171 | |
Dan Gohman | bc58a7b | 2015-11-13 00:50:04 +0000 | [diff] [blame] | 172 | def I32_REINTERPRET_F32 : I<(outs I32:$dst), (ins F32:$src), |
| 173 | [(set I32:$dst, (bitconvert F32:$src))], |
Dan Gohman | c968297 | 2016-10-24 20:21:49 +0000 | [diff] [blame] | 174 | "i32.reinterpret/f32\t$dst, $src", 0xbc>; |
Dan Gohman | bc58a7b | 2015-11-13 00:50:04 +0000 | [diff] [blame] | 175 | def F32_REINTERPRET_I32 : I<(outs F32:$dst), (ins I32:$src), |
| 176 | [(set F32:$dst, (bitconvert I32:$src))], |
Dan Gohman | c968297 | 2016-10-24 20:21:49 +0000 | [diff] [blame] | 177 | "f32.reinterpret/i32\t$dst, $src", 0xbe>; |
Dan Gohman | bc58a7b | 2015-11-13 00:50:04 +0000 | [diff] [blame] | 178 | def I64_REINTERPRET_F64 : I<(outs I64:$dst), (ins F64:$src), |
| 179 | [(set I64:$dst, (bitconvert F64:$src))], |
Dan Gohman | c968297 | 2016-10-24 20:21:49 +0000 | [diff] [blame] | 180 | "i64.reinterpret/f64\t$dst, $src", 0xbd>; |
Dan Gohman | bc58a7b | 2015-11-13 00:50:04 +0000 | [diff] [blame] | 181 | def F64_REINTERPRET_I64 : I<(outs F64:$dst), (ins I64:$src), |
| 182 | [(set F64:$dst, (bitconvert I64:$src))], |
Dan Gohman | c968297 | 2016-10-24 20:21:49 +0000 | [diff] [blame] | 183 | "f64.reinterpret/i64\t$dst, $src", 0xbf>; |
Dan Gohman | fb3e059 | 2015-11-25 19:36:19 +0000 | [diff] [blame] | 184 | |
| 185 | } // Defs = [ARGUMENTS] |