1// LoongArchFloat64InstrInfo.td - Double-Precision Float instr --*- tablegen -*- 2// 3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4// See https://llvm.org/LICENSE.txt for license information. 5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6// 7//===----------------------------------------------------------------------===// 8// 9// This file describes the basic double-precision floating-point instructions. 10// 11//===----------------------------------------------------------------------===// 12 13//===----------------------------------------------------------------------===// 14// Instructions 15//===----------------------------------------------------------------------===// 16 17let Predicates = [HasBasicD] in { 18 19// Arithmetic Operation Instructions 20def FADD_D : FP_ALU_3R<0x01010000, FPR64>; 21def FSUB_D : FP_ALU_3R<0x01030000, FPR64>; 22def FMUL_D : FP_ALU_3R<0x01050000, FPR64>; 23def FDIV_D : FP_ALU_3R<0x01070000, FPR64>; 24def FMADD_D : FP_ALU_4R<0x08200000, FPR64>; 25def FMSUB_D : FP_ALU_4R<0x08600000, FPR64>; 26def FNMADD_D : FP_ALU_4R<0x08a00000, FPR64>; 27def FNMSUB_D : FP_ALU_4R<0x08e00000, FPR64>; 28def FMAX_D : FP_ALU_3R<0x01090000, FPR64>; 29def FMIN_D : FP_ALU_3R<0x010b0000, FPR64>; 30def FMAXA_D : FP_ALU_3R<0x010d0000, FPR64>; 31def FMINA_D : FP_ALU_3R<0x010f0000, FPR64>; 32def FABS_D : FP_ALU_2R<0x01140800, FPR64>; 33def FNEG_D : FP_ALU_2R<0x01141800, FPR64>; 34def FSQRT_D : FP_ALU_2R<0x01144800, FPR64>; 35def FRECIP_D : FP_ALU_2R<0x01145800, FPR64>; 36def FRSQRT_D : FP_ALU_2R<0x01146800, FPR64>; 37def FSCALEB_D : FP_ALU_3R<0x01110000, FPR64>; 38def FLOGB_D : FP_ALU_2R<0x01142800, FPR64>; 39def FCOPYSIGN_D : FP_ALU_3R<0x01130000, FPR64>; 40def FCLASS_D : FP_ALU_2R<0x01143800, FPR64>; 41 42// Comparison Instructions 43def FCMP_CAF_D : FP_CMP<0x0c200000, FPR64>; 44def FCMP_CUN_D : FP_CMP<0x0c240000, FPR64>; 45def FCMP_CEQ_D : FP_CMP<0x0c220000, FPR64>; 46def FCMP_CUEQ_D : FP_CMP<0x0c260000, FPR64>; 47def FCMP_CLT_D : FP_CMP<0x0c210000, FPR64>; 48def FCMP_CULT_D : FP_CMP<0x0c250000, FPR64>; 49def FCMP_CLE_D : FP_CMP<0x0c230000, FPR64>; 50def FCMP_CULE_D : FP_CMP<0x0c270000, FPR64>; 51def FCMP_CNE_D : FP_CMP<0x0c280000, FPR64>; 52def FCMP_COR_D : FP_CMP<0x0c2a0000, FPR64>; 53def FCMP_CUNE_D : FP_CMP<0x0c2c0000, FPR64>; 54def FCMP_SAF_D : FP_CMP<0x0c208000, FPR64>; 55def FCMP_SUN_D : FP_CMP<0x0c248000, FPR64>; 56def FCMP_SEQ_D : FP_CMP<0x0c228000, FPR64>; 57def FCMP_SUEQ_D : FP_CMP<0x0c268000, FPR64>; 58def FCMP_SLT_D : FP_CMP<0x0c218000, FPR64>; 59def FCMP_SULT_D : FP_CMP<0x0c258000, FPR64>; 60def FCMP_SLE_D : FP_CMP<0x0c238000, FPR64>; 61def FCMP_SULE_D : FP_CMP<0x0c278000, FPR64>; 62def FCMP_SNE_D : FP_CMP<0x0c288000, FPR64>; 63def FCMP_SOR_D : FP_CMP<0x0c2a8000, FPR64>; 64def FCMP_SUNE_D : FP_CMP<0x0c2c8000, FPR64>; 65 66// Conversion Instructions 67def FFINT_S_L : FP_CONV<0x011d1800, FPR32, FPR64>; 68def FTINT_L_S : FP_CONV<0x011b2400, FPR64, FPR32>; 69def FTINTRM_L_S : FP_CONV<0x011a2400, FPR64, FPR32>; 70def FTINTRP_L_S : FP_CONV<0x011a6400, FPR64, FPR32>; 71def FTINTRZ_L_S : FP_CONV<0x011aa400, FPR64, FPR32>; 72def FTINTRNE_L_S : FP_CONV<0x011ae400, FPR64, FPR32>; 73def FCVT_S_D : FP_CONV<0x01191800, FPR32, FPR64>; 74def FCVT_D_S : FP_CONV<0x01192400, FPR64, FPR32>; 75def FFINT_D_W : FP_CONV<0x011d2000, FPR64, FPR32>; 76def FFINT_D_L : FP_CONV<0x011d2800, FPR64, FPR64>; 77def FTINT_W_D : FP_CONV<0x011b0800, FPR32, FPR64>; 78def FTINT_L_D : FP_CONV<0x011b2800, FPR64, FPR64>; 79def FTINTRM_W_D : FP_CONV<0x011a0800, FPR32, FPR64>; 80def FTINTRM_L_D : FP_CONV<0x011a2800, FPR64, FPR64>; 81def FTINTRP_W_D : FP_CONV<0x011a4800, FPR32, FPR64>; 82def FTINTRP_L_D : FP_CONV<0x011a6800, FPR64, FPR64>; 83def FTINTRZ_W_D : FP_CONV<0x011a8800, FPR32, FPR64>; 84def FTINTRZ_L_D : FP_CONV<0x011aa800, FPR64, FPR64>; 85def FTINTRNE_W_D : FP_CONV<0x011ac800, FPR32, FPR64>; 86def FTINTRNE_L_D : FP_CONV<0x011ae800, FPR64, FPR64>; 87def FRINT_D : FP_CONV<0x011e4800, FPR64, FPR64>; 88 89// Move Instructions 90def FMOV_D : FP_MOV<0x01149800, FPR64, FPR64>; 91def MOVFRH2GR_S : FP_MOV<0x0114bc00, GPR, FPR64>; 92let isCodeGenOnly = 1 in { 93def MOVFR2GR_S_64 : FP_MOV<0x0114b400, GPR, FPR64>; 94def FSEL_xD : FP_SEL<0x0d000000, FPR64>; 95} // isCodeGenOnly = 1 96let hasSideEffects = 0, mayLoad = 0, mayStore = 0, Constraints = "$dst = $out" in { 97def MOVGR2FRH_W : FPFmtMOV<0x0114ac00, (outs FPR64:$out), 98 (ins FPR64:$dst, GPR:$src), 99 "$dst, $src">; 100} // hasSideEffects = 0, mayLoad = 0, mayStore = 0, Constraints = "$dst = $out" 101 102// Common Memory Access Instructions 103def FLD_D : FP_LOAD_2RI12<0x2b800000, FPR64>; 104def FST_D : FP_STORE_2RI12<0x2bc00000, FPR64>; 105def FLDX_D : FP_LOAD_3R<0x38340000, FPR64>; 106def FSTX_D : FP_STORE_3R<0x383c0000, FPR64>; 107 108// Bound Check Memory Access Instructions 109def FLDGT_D : FP_LOAD_3R<0x38748000, FPR64>; 110def FLDLE_D : FP_LOAD_3R<0x38758000, FPR64>; 111def FSTGT_D : FP_STORE_3R<0x38768000, FPR64>; 112def FSTLE_D : FP_STORE_3R<0x38778000, FPR64>; 113 114} // Predicates = [HasBasicD] 115 116// Instructions only available on LA64 117let Predicates = [HasBasicD, IsLA64] in { 118def MOVGR2FR_D : FP_MOV<0x0114a800, FPR64, GPR>; 119def MOVFR2GR_D : FP_MOV<0x0114b800, GPR, FPR64>; 120} // Predicates = [HasBasicD, IsLA64] 121 122// Instructions only available on LA32 123let Predicates = [HasBasicD, IsLA32], isCodeGenOnly = 1 in { 124def MOVGR2FR_W_64 : FP_MOV<0x0114a400, FPR64, GPR>; 125} // Predicates = [HasBasicD, IsLA32], isCodeGenOnly = 1 126 127//===----------------------------------------------------------------------===// 128// Pseudo-instructions and codegen patterns 129//===----------------------------------------------------------------------===// 130 131let Predicates = [HasBasicD] in { 132 133/// Float arithmetic operations 134 135def : PatFprFpr<fadd, FADD_D, FPR64>; 136def : PatFprFpr<fsub, FSUB_D, FPR64>; 137def : PatFprFpr<fmul, FMUL_D, FPR64>; 138def : PatFprFpr<fdiv, FDIV_D, FPR64>; 139def : PatFprFpr<fcopysign, FCOPYSIGN_D, FPR64>; 140def : PatFprFpr<fmaxnum_ieee, FMAX_D, FPR64>; 141def : PatFprFpr<fminnum_ieee, FMIN_D, FPR64>; 142def : PatFpr<fneg, FNEG_D, FPR64>; 143def : PatFpr<fabs, FABS_D, FPR64>; 144def : PatFpr<fsqrt, FSQRT_D, FPR64>; 145 146def : Pat<(fdiv fpimm1, (fsqrt FPR64:$fj)), (FRSQRT_D FPR64:$fj)>; 147 148def : Pat<(fcopysign FPR64:$fj, FPR32:$fk), 149 (FCOPYSIGN_D FPR64:$fj, (FCVT_D_S FPR32:$fk))>; 150def : Pat<(fcopysign FPR32:$fj, FPR64:$fk), 151 (FCOPYSIGN_S FPR32:$fj, (FCVT_S_D FPR64:$fk))>; 152 153def : Pat<(fcanonicalize FPR64:$fj), (FMAX_D $fj, $fj)>; 154 155/// Setcc 156 157// Match non-signaling comparison 158 159// SETOGT/SETOGE/SETUGT/SETUGE/SETGE/SETNE/SETGT will expand into 160// SETOLT/SETOLE/SETULT/SETULE/SETLE/SETEQ/SETLT. 161def : PatFPSetcc<SETOEQ, FCMP_CEQ_D, FPR64>; 162def : PatFPSetcc<SETEQ, FCMP_CEQ_D, FPR64>; 163def : PatFPSetcc<SETOLT, FCMP_CLT_D, FPR64>; 164def : PatFPSetcc<SETOLE, FCMP_CLE_D, FPR64>; 165def : PatFPSetcc<SETLE, FCMP_CLE_D, FPR64>; 166def : PatFPSetcc<SETONE, FCMP_CNE_D, FPR64>; 167def : PatFPSetcc<SETO, FCMP_COR_D, FPR64>; 168def : PatFPSetcc<SETUEQ, FCMP_CUEQ_D, FPR64>; 169def : PatFPSetcc<SETULT, FCMP_CULT_D, FPR64>; 170def : PatFPSetcc<SETULE, FCMP_CULE_D, FPR64>; 171def : PatFPSetcc<SETUNE, FCMP_CUNE_D, FPR64>; 172def : PatFPSetcc<SETUO, FCMP_CUN_D, FPR64>; 173def : PatFPSetcc<SETLT, FCMP_CLT_D, FPR64>; 174 175defm : PatFPBrcond<SETOEQ, FCMP_CEQ_D, FPR64>; 176defm : PatFPBrcond<SETOLT, FCMP_CLT_D, FPR64>; 177defm : PatFPBrcond<SETOLE, FCMP_CLE_D, FPR64>; 178defm : PatFPBrcond<SETONE, FCMP_CNE_D, FPR64>; 179defm : PatFPBrcond<SETO, FCMP_COR_D, FPR64>; 180defm : PatFPBrcond<SETUEQ, FCMP_CUEQ_D, FPR64>; 181defm : PatFPBrcond<SETULT, FCMP_CULT_D, FPR64>; 182defm : PatFPBrcond<SETULE, FCMP_CULE_D, FPR64>; 183defm : PatFPBrcond<SETUNE, FCMP_CUNE_D, FPR64>; 184defm : PatFPBrcond<SETUO, FCMP_CUN_D, FPR64>; 185defm : PatFPBrcond<SETLT, FCMP_CLT_D, FPR64>; 186 187// Match signaling comparison 188 189def : PatStrictFsetccs<SETOEQ, FCMP_SEQ_D, FPR64>; 190def : PatStrictFsetccs<SETOLT, FCMP_SLT_D, FPR64>; 191def : PatStrictFsetccs<SETOLE, FCMP_SLE_D, FPR64>; 192def : PatStrictFsetccs<SETONE, FCMP_SNE_D, FPR64>; 193def : PatStrictFsetccs<SETO, FCMP_SOR_D, FPR64>; 194def : PatStrictFsetccs<SETUEQ, FCMP_SUEQ_D, FPR64>; 195def : PatStrictFsetccs<SETULT, FCMP_SULT_D, FPR64>; 196def : PatStrictFsetccs<SETULE, FCMP_SULE_D, FPR64>; 197def : PatStrictFsetccs<SETUNE, FCMP_SUNE_D, FPR64>; 198def : PatStrictFsetccs<SETUO, FCMP_SUN_D, FPR64>; 199def : PatStrictFsetccs<SETLT, FCMP_SLT_D, FPR64>; 200 201/// Select 202 203def : Pat<(select CFR:$cc, FPR64:$fk, FPR64:$fj), 204 (FSEL_xD FPR64:$fj, FPR64:$fk, CFR:$cc)>; 205 206/// Selectcc 207 208def : PatFPSelectcc<SETOEQ, FCMP_CEQ_D, FSEL_xD, FPR64>; 209def : PatFPSelectcc<SETOLT, FCMP_CLT_D, FSEL_xD, FPR64>; 210def : PatFPSelectcc<SETOLE, FCMP_CLE_D, FSEL_xD, FPR64>; 211def : PatFPSelectcc<SETONE, FCMP_CNE_D, FSEL_xD, FPR64>; 212def : PatFPSelectcc<SETO, FCMP_COR_D, FSEL_xD, FPR64>; 213def : PatFPSelectcc<SETUEQ, FCMP_CUEQ_D, FSEL_xD, FPR64>; 214def : PatFPSelectcc<SETULT, FCMP_CULT_D, FSEL_xD, FPR64>; 215def : PatFPSelectcc<SETULE, FCMP_CULE_D, FSEL_xD, FPR64>; 216def : PatFPSelectcc<SETUNE, FCMP_CUNE_D, FSEL_xD, FPR64>; 217def : PatFPSelectcc<SETUO, FCMP_CUN_D, FSEL_xD, FPR64>; 218 219/// Loads 220 221defm : LdPat<load, FLD_D, f64>; 222def : RegRegLdPat<load, FLDX_D, f64>; 223 224/// Stores 225 226defm : StPat<store, FST_D, FPR64, f64>; 227def : RegRegStPat<store, FSTX_D, FPR64, f64>; 228 229/// FP conversion operations 230 231def : Pat<(loongarch_ftint FPR64:$src), (FTINTRZ_W_D FPR64:$src)>; 232def : Pat<(f64 (loongarch_ftint FPR64:$src)), (FTINTRZ_L_D FPR64:$src)>; 233def : Pat<(loongarch_ftint FPR32:$src), (FTINTRZ_L_S FPR32:$src)>; 234 235// f64 -> f32 236def : Pat<(f32 (fpround FPR64:$src)), (FCVT_S_D FPR64:$src)>; 237// f32 -> f64 238def : Pat<(f64 (fpextend FPR32:$src)), (FCVT_D_S FPR32:$src)>; 239 240// FP reciprocal operation 241def : Pat<(fdiv fpimm1, FPR64:$src), (FRECIP_D $src)>; 242 243// fmadd.d: fj * fk + fa 244def : Pat<(fma FPR64:$fj, FPR64:$fk, FPR64:$fa), (FMADD_D $fj, $fk, $fa)>; 245 246// fmsub.d: fj * fk - fa 247def : Pat<(fma FPR64:$fj, FPR64:$fk, (fneg FPR64:$fa)), 248 (FMSUB_D FPR64:$fj, FPR64:$fk, FPR64:$fa)>; 249 250// fnmadd.d: -(fj * fk + fa) 251def : Pat<(fneg (fma FPR64:$fj, FPR64:$fk, FPR64:$fa)), 252 (FNMADD_D FPR64:$fj, FPR64:$fk, FPR64:$fa)>; 253 254// fnmadd.d: -fj * fk - fa (the nsz flag on the FMA) 255def : Pat<(fma_nsz (fneg FPR64:$fj), FPR64:$fk, (fneg FPR64:$fa)), 256 (FNMADD_D FPR64:$fj, FPR64:$fk, FPR64:$fa)>; 257 258// fnmsub.d: -(fj * fk - fa) 259def : Pat<(fma (fneg FPR64:$fj), FPR64:$fk, FPR64:$fa), 260 (FNMSUB_D FPR64:$fj, FPR64:$fk, FPR64:$fa)>; 261} // Predicates = [HasBasicD] 262 263/// Floating point constants 264 265let Predicates = [HasBasicD, IsLA64] in { 266def : Pat<(f64 fpimm0), (MOVGR2FR_D R0)>; 267def : Pat<(f64 fpimm0neg), (FNEG_D (MOVGR2FR_D R0))>; 268def : Pat<(f64 fpimm1), (FFINT_D_L (MOVGR2FR_D (ADDI_D R0, 1)))>; 269} // Predicates = [HasBasicD, IsLA64] 270let Predicates = [HasBasicD, IsLA32] in { 271def : Pat<(f64 fpimm0), (MOVGR2FRH_W (MOVGR2FR_W_64 R0), R0)>; 272def : Pat<(f64 fpimm0neg), (FNEG_D (MOVGR2FRH_W (MOVGR2FR_W_64 R0), R0))>; 273def : Pat<(f64 fpimm1), (FCVT_D_S (FFINT_S_W (MOVGR2FR_W (ADDI_W R0, 1))))>; 274} // Predicates = [HasBasicD, IsLA32] 275 276/// Convert int to FP 277 278let Predicates = [HasBasicD, IsLA64] in { 279def : Pat<(f32 (sint_to_fp GPR:$src)), (FFINT_S_L (MOVGR2FR_D GPR:$src))>; 280def : Pat<(f64 (sint_to_fp (i64 (sexti32 (i64 GPR:$src))))), 281 (FFINT_D_W (MOVGR2FR_W GPR:$src))>; 282def : Pat<(f64 (sint_to_fp GPR:$src)), (FFINT_D_L (MOVGR2FR_D GPR:$src))>; 283 284def : Pat<(bitconvert GPR:$src), (MOVGR2FR_D GPR:$src)>; 285} // Predicates = [HasBasicD, IsLA64] 286let Predicates = [HasBasicD, IsLA32] in { 287def : Pat<(f64 (sint_to_fp (i32 GPR:$src))), (FFINT_D_W (MOVGR2FR_W GPR:$src))>; 288} // Predicates = [HasBasicD, IsLA32] 289 290// Convert FP to int 291let Predicates = [HasBasicD, IsLA64] in { 292def : Pat<(bitconvert FPR64:$src), (MOVFR2GR_D FPR64:$src)>; 293} // Predicates = [HasBasicD, IsLA64] 294 295// FP Rounding 296let Predicates = [HasBasicD, IsLA64] in { 297def : PatFpr<frint, FRINT_D, FPR64>; 298} // Predicates = [HasBasicD, IsLA64] 299