1f798f1e2SMichael Clark /* 2f798f1e2SMichael Clark * RISC-V FPU Emulation Helpers for QEMU. 3f798f1e2SMichael Clark * 4f798f1e2SMichael Clark * Copyright (c) 2016-2017 Sagar Karandikar, sagark@eecs.berkeley.edu 5f798f1e2SMichael Clark * 6f798f1e2SMichael Clark * This program is free software; you can redistribute it and/or modify it 7f798f1e2SMichael Clark * under the terms and conditions of the GNU General Public License, 8f798f1e2SMichael Clark * version 2 or later, as published by the Free Software Foundation. 9f798f1e2SMichael Clark * 10f798f1e2SMichael Clark * This program is distributed in the hope it will be useful, but WITHOUT 11f798f1e2SMichael Clark * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12f798f1e2SMichael Clark * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13f798f1e2SMichael Clark * more details. 14f798f1e2SMichael Clark * 15f798f1e2SMichael Clark * You should have received a copy of the GNU General Public License along with 16f798f1e2SMichael Clark * this program. If not, see <http://www.gnu.org/licenses/>. 17f798f1e2SMichael Clark */ 18f798f1e2SMichael Clark 19f798f1e2SMichael Clark #include "qemu/osdep.h" 20f798f1e2SMichael Clark #include "cpu.h" 21f798f1e2SMichael Clark #include "qemu/host-utils.h" 22f798f1e2SMichael Clark #include "exec/exec-all.h" 23f798f1e2SMichael Clark #include "exec/helper-proto.h" 24135b03cbSAlex Bennée #include "fpu/softfloat.h" 25121ddbb3SLIU Zhiwei #include "internals.h" 26f798f1e2SMichael Clark 27fb738839SMichael Clark target_ulong riscv_cpu_get_fflags(CPURISCVState *env) 28f798f1e2SMichael Clark { 29f798f1e2SMichael Clark int soft = get_float_exception_flags(&env->fp_status); 30f798f1e2SMichael Clark target_ulong hard = 0; 31f798f1e2SMichael Clark 32f798f1e2SMichael Clark hard |= (soft & float_flag_inexact) ? FPEXC_NX : 0; 33f798f1e2SMichael Clark hard |= (soft & float_flag_underflow) ? FPEXC_UF : 0; 34f798f1e2SMichael Clark hard |= (soft & float_flag_overflow) ? FPEXC_OF : 0; 35f798f1e2SMichael Clark hard |= (soft & float_flag_divbyzero) ? FPEXC_DZ : 0; 36f798f1e2SMichael Clark hard |= (soft & float_flag_invalid) ? FPEXC_NV : 0; 37f798f1e2SMichael Clark 38f798f1e2SMichael Clark return hard; 39f798f1e2SMichael Clark } 40f798f1e2SMichael Clark 41fb738839SMichael Clark void riscv_cpu_set_fflags(CPURISCVState *env, target_ulong hard) 42f798f1e2SMichael Clark { 43f798f1e2SMichael Clark int soft = 0; 44f798f1e2SMichael Clark 45f798f1e2SMichael Clark soft |= (hard & FPEXC_NX) ? float_flag_inexact : 0; 46f798f1e2SMichael Clark soft |= (hard & FPEXC_UF) ? float_flag_underflow : 0; 47f798f1e2SMichael Clark soft |= (hard & FPEXC_OF) ? float_flag_overflow : 0; 48f798f1e2SMichael Clark soft |= (hard & FPEXC_DZ) ? float_flag_divbyzero : 0; 49f798f1e2SMichael Clark soft |= (hard & FPEXC_NV) ? float_flag_invalid : 0; 50f798f1e2SMichael Clark 51f798f1e2SMichael Clark set_float_exception_flags(soft, &env->fp_status); 52f798f1e2SMichael Clark } 53f798f1e2SMichael Clark 54f798f1e2SMichael Clark void helper_set_rounding_mode(CPURISCVState *env, uint32_t rm) 55f798f1e2SMichael Clark { 56f798f1e2SMichael Clark int softrm; 57f798f1e2SMichael Clark 58986c895dSFrank Chang if (rm == RISCV_FRM_DYN) { 59f798f1e2SMichael Clark rm = env->frm; 60f798f1e2SMichael Clark } 61f798f1e2SMichael Clark switch (rm) { 62986c895dSFrank Chang case RISCV_FRM_RNE: 63f798f1e2SMichael Clark softrm = float_round_nearest_even; 64f798f1e2SMichael Clark break; 65986c895dSFrank Chang case RISCV_FRM_RTZ: 66f798f1e2SMichael Clark softrm = float_round_to_zero; 67f798f1e2SMichael Clark break; 68986c895dSFrank Chang case RISCV_FRM_RDN: 69f798f1e2SMichael Clark softrm = float_round_down; 70f798f1e2SMichael Clark break; 71986c895dSFrank Chang case RISCV_FRM_RUP: 72f798f1e2SMichael Clark softrm = float_round_up; 73f798f1e2SMichael Clark break; 74986c895dSFrank Chang case RISCV_FRM_RMM: 75f798f1e2SMichael Clark softrm = float_round_ties_away; 76f798f1e2SMichael Clark break; 77f798f1e2SMichael Clark default: 78fb738839SMichael Clark riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, GETPC()); 79f798f1e2SMichael Clark } 80f798f1e2SMichael Clark 81f798f1e2SMichael Clark set_float_rounding_mode(softrm, &env->fp_status); 82f798f1e2SMichael Clark } 83f798f1e2SMichael Clark 843ceeb19aSRichard Henderson void helper_set_rounding_mode_chkfrm(CPURISCVState *env, uint32_t rm) 853ceeb19aSRichard Henderson { 863ceeb19aSRichard Henderson int softrm; 873ceeb19aSRichard Henderson 883ceeb19aSRichard Henderson /* Always validate frm, even if rm != DYN. */ 893ceeb19aSRichard Henderson if (unlikely(env->frm >= 5)) { 903ceeb19aSRichard Henderson riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, GETPC()); 913ceeb19aSRichard Henderson } 923ceeb19aSRichard Henderson if (rm == RISCV_FRM_DYN) { 933ceeb19aSRichard Henderson rm = env->frm; 943ceeb19aSRichard Henderson } 953ceeb19aSRichard Henderson switch (rm) { 963ceeb19aSRichard Henderson case RISCV_FRM_RNE: 973ceeb19aSRichard Henderson softrm = float_round_nearest_even; 983ceeb19aSRichard Henderson break; 993ceeb19aSRichard Henderson case RISCV_FRM_RTZ: 1003ceeb19aSRichard Henderson softrm = float_round_to_zero; 1013ceeb19aSRichard Henderson break; 1023ceeb19aSRichard Henderson case RISCV_FRM_RDN: 1033ceeb19aSRichard Henderson softrm = float_round_down; 1043ceeb19aSRichard Henderson break; 1053ceeb19aSRichard Henderson case RISCV_FRM_RUP: 1063ceeb19aSRichard Henderson softrm = float_round_up; 1073ceeb19aSRichard Henderson break; 1083ceeb19aSRichard Henderson case RISCV_FRM_RMM: 1093ceeb19aSRichard Henderson softrm = float_round_ties_away; 1103ceeb19aSRichard Henderson break; 1113ceeb19aSRichard Henderson case RISCV_FRM_ROD: 1123ceeb19aSRichard Henderson softrm = float_round_to_odd; 1133ceeb19aSRichard Henderson break; 1143ceeb19aSRichard Henderson default: 1153ceeb19aSRichard Henderson g_assert_not_reached(); 1163ceeb19aSRichard Henderson } 1173ceeb19aSRichard Henderson 1183ceeb19aSRichard Henderson set_float_rounding_mode(softrm, &env->fp_status); 1193ceeb19aSRichard Henderson } 1203ceeb19aSRichard Henderson 12100c1899fSKito Cheng static uint64_t do_fmadd_h(CPURISCVState *env, uint64_t rs1, uint64_t rs2, 12200c1899fSKito Cheng uint64_t rs3, int flags) 12300c1899fSKito Cheng { 124a2464a4cSWeiwei Li float16 frs1 = check_nanbox_h(env, rs1); 125a2464a4cSWeiwei Li float16 frs2 = check_nanbox_h(env, rs2); 126a2464a4cSWeiwei Li float16 frs3 = check_nanbox_h(env, rs3); 127a2464a4cSWeiwei Li return nanbox_h(env, float16_muladd(frs1, frs2, frs3, flags, 128a2464a4cSWeiwei Li &env->fp_status)); 12900c1899fSKito Cheng } 13000c1899fSKito Cheng 13100e925c5SRichard Henderson static uint64_t do_fmadd_s(CPURISCVState *env, uint64_t rs1, uint64_t rs2, 13200e925c5SRichard Henderson uint64_t rs3, int flags) 1339921e3d3SRichard Henderson { 134e1a29bbdSWeiwei Li float32 frs1 = check_nanbox_s(env, rs1); 135e1a29bbdSWeiwei Li float32 frs2 = check_nanbox_s(env, rs2); 136e1a29bbdSWeiwei Li float32 frs3 = check_nanbox_s(env, rs3); 137e1a29bbdSWeiwei Li return nanbox_s(env, float32_muladd(frs1, frs2, frs3, flags, 138e1a29bbdSWeiwei Li &env->fp_status)); 1399921e3d3SRichard Henderson } 1409921e3d3SRichard Henderson 141f798f1e2SMichael Clark uint64_t helper_fmadd_s(CPURISCVState *env, uint64_t frs1, uint64_t frs2, 142f798f1e2SMichael Clark uint64_t frs3) 143f798f1e2SMichael Clark { 1449921e3d3SRichard Henderson return do_fmadd_s(env, frs1, frs2, frs3, 0); 145f798f1e2SMichael Clark } 146f798f1e2SMichael Clark 147f798f1e2SMichael Clark uint64_t helper_fmadd_d(CPURISCVState *env, uint64_t frs1, uint64_t frs2, 148f798f1e2SMichael Clark uint64_t frs3) 149f798f1e2SMichael Clark { 150f798f1e2SMichael Clark return float64_muladd(frs1, frs2, frs3, 0, &env->fp_status); 151f798f1e2SMichael Clark } 152f798f1e2SMichael Clark 15300c1899fSKito Cheng uint64_t helper_fmadd_h(CPURISCVState *env, uint64_t frs1, uint64_t frs2, 15400c1899fSKito Cheng uint64_t frs3) 15500c1899fSKito Cheng { 15600c1899fSKito Cheng return do_fmadd_h(env, frs1, frs2, frs3, 0); 15700c1899fSKito Cheng } 15800c1899fSKito Cheng 159f798f1e2SMichael Clark uint64_t helper_fmsub_s(CPURISCVState *env, uint64_t frs1, uint64_t frs2, 160f798f1e2SMichael Clark uint64_t frs3) 161f798f1e2SMichael Clark { 1629921e3d3SRichard Henderson return do_fmadd_s(env, frs1, frs2, frs3, float_muladd_negate_c); 163f798f1e2SMichael Clark } 164f798f1e2SMichael Clark 165f798f1e2SMichael Clark uint64_t helper_fmsub_d(CPURISCVState *env, uint64_t frs1, uint64_t frs2, 166f798f1e2SMichael Clark uint64_t frs3) 167f798f1e2SMichael Clark { 168f798f1e2SMichael Clark return float64_muladd(frs1, frs2, frs3, float_muladd_negate_c, 169f798f1e2SMichael Clark &env->fp_status); 170f798f1e2SMichael Clark } 171f798f1e2SMichael Clark 17200c1899fSKito Cheng uint64_t helper_fmsub_h(CPURISCVState *env, uint64_t frs1, uint64_t frs2, 17300c1899fSKito Cheng uint64_t frs3) 17400c1899fSKito Cheng { 17500c1899fSKito Cheng return do_fmadd_h(env, frs1, frs2, frs3, float_muladd_negate_c); 17600c1899fSKito Cheng } 17700c1899fSKito Cheng 178f798f1e2SMichael Clark uint64_t helper_fnmsub_s(CPURISCVState *env, uint64_t frs1, uint64_t frs2, 179f798f1e2SMichael Clark uint64_t frs3) 180f798f1e2SMichael Clark { 1819921e3d3SRichard Henderson return do_fmadd_s(env, frs1, frs2, frs3, float_muladd_negate_product); 182f798f1e2SMichael Clark } 183f798f1e2SMichael Clark 184f798f1e2SMichael Clark uint64_t helper_fnmsub_d(CPURISCVState *env, uint64_t frs1, uint64_t frs2, 185f798f1e2SMichael Clark uint64_t frs3) 186f798f1e2SMichael Clark { 187f798f1e2SMichael Clark return float64_muladd(frs1, frs2, frs3, float_muladd_negate_product, 188f798f1e2SMichael Clark &env->fp_status); 189f798f1e2SMichael Clark } 190f798f1e2SMichael Clark 19100c1899fSKito Cheng uint64_t helper_fnmsub_h(CPURISCVState *env, uint64_t frs1, uint64_t frs2, 19200c1899fSKito Cheng uint64_t frs3) 19300c1899fSKito Cheng { 19400c1899fSKito Cheng return do_fmadd_h(env, frs1, frs2, frs3, float_muladd_negate_product); 19500c1899fSKito Cheng } 19600c1899fSKito Cheng 197f798f1e2SMichael Clark uint64_t helper_fnmadd_s(CPURISCVState *env, uint64_t frs1, uint64_t frs2, 198f798f1e2SMichael Clark uint64_t frs3) 199f798f1e2SMichael Clark { 2009921e3d3SRichard Henderson return do_fmadd_s(env, frs1, frs2, frs3, 2019921e3d3SRichard Henderson float_muladd_negate_c | float_muladd_negate_product); 202f798f1e2SMichael Clark } 203f798f1e2SMichael Clark 204f798f1e2SMichael Clark uint64_t helper_fnmadd_d(CPURISCVState *env, uint64_t frs1, uint64_t frs2, 205f798f1e2SMichael Clark uint64_t frs3) 206f798f1e2SMichael Clark { 207f798f1e2SMichael Clark return float64_muladd(frs1, frs2, frs3, float_muladd_negate_c | 208f798f1e2SMichael Clark float_muladd_negate_product, &env->fp_status); 209f798f1e2SMichael Clark } 210f798f1e2SMichael Clark 21100c1899fSKito Cheng uint64_t helper_fnmadd_h(CPURISCVState *env, uint64_t frs1, uint64_t frs2, 21200c1899fSKito Cheng uint64_t frs3) 21300c1899fSKito Cheng { 21400c1899fSKito Cheng return do_fmadd_h(env, frs1, frs2, frs3, 21500c1899fSKito Cheng float_muladd_negate_c | float_muladd_negate_product); 21600c1899fSKito Cheng } 21700c1899fSKito Cheng 21800e925c5SRichard Henderson uint64_t helper_fadd_s(CPURISCVState *env, uint64_t rs1, uint64_t rs2) 219f798f1e2SMichael Clark { 220e1a29bbdSWeiwei Li float32 frs1 = check_nanbox_s(env, rs1); 221e1a29bbdSWeiwei Li float32 frs2 = check_nanbox_s(env, rs2); 222e1a29bbdSWeiwei Li return nanbox_s(env, float32_add(frs1, frs2, &env->fp_status)); 223f798f1e2SMichael Clark } 224f798f1e2SMichael Clark 22500e925c5SRichard Henderson uint64_t helper_fsub_s(CPURISCVState *env, uint64_t rs1, uint64_t rs2) 226f798f1e2SMichael Clark { 227e1a29bbdSWeiwei Li float32 frs1 = check_nanbox_s(env, rs1); 228e1a29bbdSWeiwei Li float32 frs2 = check_nanbox_s(env, rs2); 229e1a29bbdSWeiwei Li return nanbox_s(env, float32_sub(frs1, frs2, &env->fp_status)); 230f798f1e2SMichael Clark } 231f798f1e2SMichael Clark 23200e925c5SRichard Henderson uint64_t helper_fmul_s(CPURISCVState *env, uint64_t rs1, uint64_t rs2) 233f798f1e2SMichael Clark { 234e1a29bbdSWeiwei Li float32 frs1 = check_nanbox_s(env, rs1); 235e1a29bbdSWeiwei Li float32 frs2 = check_nanbox_s(env, rs2); 236e1a29bbdSWeiwei Li return nanbox_s(env, float32_mul(frs1, frs2, &env->fp_status)); 237f798f1e2SMichael Clark } 238f798f1e2SMichael Clark 23900e925c5SRichard Henderson uint64_t helper_fdiv_s(CPURISCVState *env, uint64_t rs1, uint64_t rs2) 240f798f1e2SMichael Clark { 241e1a29bbdSWeiwei Li float32 frs1 = check_nanbox_s(env, rs1); 242e1a29bbdSWeiwei Li float32 frs2 = check_nanbox_s(env, rs2); 243e1a29bbdSWeiwei Li return nanbox_s(env, float32_div(frs1, frs2, &env->fp_status)); 244f798f1e2SMichael Clark } 245f798f1e2SMichael Clark 24600e925c5SRichard Henderson uint64_t helper_fmin_s(CPURISCVState *env, uint64_t rs1, uint64_t rs2) 247f798f1e2SMichael Clark { 248e1a29bbdSWeiwei Li float32 frs1 = check_nanbox_s(env, rs1); 249e1a29bbdSWeiwei Li float32 frs2 = check_nanbox_s(env, rs2); 250e1a29bbdSWeiwei Li return nanbox_s(env, env->priv_ver < PRIV_VERSION_1_11_0 ? 25115161e42SChih-Min Chao float32_minnum(frs1, frs2, &env->fp_status) : 25215161e42SChih-Min Chao float32_minimum_number(frs1, frs2, &env->fp_status)); 253f798f1e2SMichael Clark } 254f798f1e2SMichael Clark 255*a47842d1SChristoph Müllner uint64_t helper_fminm_s(CPURISCVState *env, uint64_t rs1, uint64_t rs2) 256*a47842d1SChristoph Müllner { 257*a47842d1SChristoph Müllner float32 frs1 = check_nanbox_s(env, rs1); 258*a47842d1SChristoph Müllner float32 frs2 = check_nanbox_s(env, rs2); 259*a47842d1SChristoph Müllner float32 ret = float32_min(frs1, frs2, &env->fp_status); 260*a47842d1SChristoph Müllner return nanbox_s(env, ret); 261*a47842d1SChristoph Müllner } 262*a47842d1SChristoph Müllner 26300e925c5SRichard Henderson uint64_t helper_fmax_s(CPURISCVState *env, uint64_t rs1, uint64_t rs2) 264f798f1e2SMichael Clark { 265e1a29bbdSWeiwei Li float32 frs1 = check_nanbox_s(env, rs1); 266e1a29bbdSWeiwei Li float32 frs2 = check_nanbox_s(env, rs2); 267e1a29bbdSWeiwei Li return nanbox_s(env, env->priv_ver < PRIV_VERSION_1_11_0 ? 26815161e42SChih-Min Chao float32_maxnum(frs1, frs2, &env->fp_status) : 26915161e42SChih-Min Chao float32_maximum_number(frs1, frs2, &env->fp_status)); 270f798f1e2SMichael Clark } 271f798f1e2SMichael Clark 272*a47842d1SChristoph Müllner uint64_t helper_fmaxm_s(CPURISCVState *env, uint64_t rs1, uint64_t rs2) 273*a47842d1SChristoph Müllner { 274*a47842d1SChristoph Müllner float32 frs1 = check_nanbox_s(env, rs1); 275*a47842d1SChristoph Müllner float32 frs2 = check_nanbox_s(env, rs2); 276*a47842d1SChristoph Müllner float32 ret = float32_max(frs1, frs2, &env->fp_status); 277*a47842d1SChristoph Müllner return nanbox_s(env, ret); 278*a47842d1SChristoph Müllner } 279*a47842d1SChristoph Müllner 28000e925c5SRichard Henderson uint64_t helper_fsqrt_s(CPURISCVState *env, uint64_t rs1) 281f798f1e2SMichael Clark { 282e1a29bbdSWeiwei Li float32 frs1 = check_nanbox_s(env, rs1); 283e1a29bbdSWeiwei Li return nanbox_s(env, float32_sqrt(frs1, &env->fp_status)); 284f798f1e2SMichael Clark } 285f798f1e2SMichael Clark 28600e925c5SRichard Henderson target_ulong helper_fle_s(CPURISCVState *env, uint64_t rs1, uint64_t rs2) 287f798f1e2SMichael Clark { 288e1a29bbdSWeiwei Li float32 frs1 = check_nanbox_s(env, rs1); 289e1a29bbdSWeiwei Li float32 frs2 = check_nanbox_s(env, rs2); 290f798f1e2SMichael Clark return float32_le(frs1, frs2, &env->fp_status); 291f798f1e2SMichael Clark } 292f798f1e2SMichael Clark 293*a47842d1SChristoph Müllner target_ulong helper_fleq_s(CPURISCVState *env, uint64_t rs1, uint64_t rs2) 294*a47842d1SChristoph Müllner { 295*a47842d1SChristoph Müllner float32 frs1 = check_nanbox_s(env, rs1); 296*a47842d1SChristoph Müllner float32 frs2 = check_nanbox_s(env, rs2); 297*a47842d1SChristoph Müllner return float32_le_quiet(frs1, frs2, &env->fp_status); 298*a47842d1SChristoph Müllner } 299*a47842d1SChristoph Müllner 30000e925c5SRichard Henderson target_ulong helper_flt_s(CPURISCVState *env, uint64_t rs1, uint64_t rs2) 301f798f1e2SMichael Clark { 302e1a29bbdSWeiwei Li float32 frs1 = check_nanbox_s(env, rs1); 303e1a29bbdSWeiwei Li float32 frs2 = check_nanbox_s(env, rs2); 304f798f1e2SMichael Clark return float32_lt(frs1, frs2, &env->fp_status); 305f798f1e2SMichael Clark } 306f798f1e2SMichael Clark 307*a47842d1SChristoph Müllner target_ulong helper_fltq_s(CPURISCVState *env, uint64_t rs1, uint64_t rs2) 308*a47842d1SChristoph Müllner { 309*a47842d1SChristoph Müllner float32 frs1 = check_nanbox_s(env, rs1); 310*a47842d1SChristoph Müllner float32 frs2 = check_nanbox_s(env, rs2); 311*a47842d1SChristoph Müllner return float32_lt_quiet(frs1, frs2, &env->fp_status); 312*a47842d1SChristoph Müllner } 313*a47842d1SChristoph Müllner 31400e925c5SRichard Henderson target_ulong helper_feq_s(CPURISCVState *env, uint64_t rs1, uint64_t rs2) 315f798f1e2SMichael Clark { 316e1a29bbdSWeiwei Li float32 frs1 = check_nanbox_s(env, rs1); 317e1a29bbdSWeiwei Li float32 frs2 = check_nanbox_s(env, rs2); 318f798f1e2SMichael Clark return float32_eq_quiet(frs1, frs2, &env->fp_status); 319f798f1e2SMichael Clark } 320f798f1e2SMichael Clark 32100e925c5SRichard Henderson target_ulong helper_fcvt_w_s(CPURISCVState *env, uint64_t rs1) 322f798f1e2SMichael Clark { 323e1a29bbdSWeiwei Li float32 frs1 = check_nanbox_s(env, rs1); 324f798f1e2SMichael Clark return float32_to_int32(frs1, &env->fp_status); 325f798f1e2SMichael Clark } 326f798f1e2SMichael Clark 32700e925c5SRichard Henderson target_ulong helper_fcvt_wu_s(CPURISCVState *env, uint64_t rs1) 328f798f1e2SMichael Clark { 329e1a29bbdSWeiwei Li float32 frs1 = check_nanbox_s(env, rs1); 330f798f1e2SMichael Clark return (int32_t)float32_to_uint32(frs1, &env->fp_status); 331f798f1e2SMichael Clark } 332f798f1e2SMichael Clark 333daf866b6SAlistair Francis target_ulong helper_fcvt_l_s(CPURISCVState *env, uint64_t rs1) 334f798f1e2SMichael Clark { 335e1a29bbdSWeiwei Li float32 frs1 = check_nanbox_s(env, rs1); 336f798f1e2SMichael Clark return float32_to_int64(frs1, &env->fp_status); 337f798f1e2SMichael Clark } 338f798f1e2SMichael Clark 339daf866b6SAlistair Francis target_ulong helper_fcvt_lu_s(CPURISCVState *env, uint64_t rs1) 340f798f1e2SMichael Clark { 341e1a29bbdSWeiwei Li float32 frs1 = check_nanbox_s(env, rs1); 342f798f1e2SMichael Clark return float32_to_uint64(frs1, &env->fp_status); 343f798f1e2SMichael Clark } 344f798f1e2SMichael Clark 345f798f1e2SMichael Clark uint64_t helper_fcvt_s_w(CPURISCVState *env, target_ulong rs1) 346f798f1e2SMichael Clark { 347e1a29bbdSWeiwei Li return nanbox_s(env, int32_to_float32((int32_t)rs1, &env->fp_status)); 348f798f1e2SMichael Clark } 349f798f1e2SMichael Clark 350f798f1e2SMichael Clark uint64_t helper_fcvt_s_wu(CPURISCVState *env, target_ulong rs1) 351f798f1e2SMichael Clark { 352e1a29bbdSWeiwei Li return nanbox_s(env, uint32_to_float32((uint32_t)rs1, &env->fp_status)); 353f798f1e2SMichael Clark } 354f798f1e2SMichael Clark 355daf866b6SAlistair Francis uint64_t helper_fcvt_s_l(CPURISCVState *env, target_ulong rs1) 356f798f1e2SMichael Clark { 357e1a29bbdSWeiwei Li return nanbox_s(env, int64_to_float32(rs1, &env->fp_status)); 358f798f1e2SMichael Clark } 359f798f1e2SMichael Clark 360daf866b6SAlistair Francis uint64_t helper_fcvt_s_lu(CPURISCVState *env, target_ulong rs1) 361f798f1e2SMichael Clark { 362e1a29bbdSWeiwei Li return nanbox_s(env, uint64_to_float32(rs1, &env->fp_status)); 363f798f1e2SMichael Clark } 364f798f1e2SMichael Clark 365e1a29bbdSWeiwei Li target_ulong helper_fclass_s(CPURISCVState *env, uint64_t rs1) 366f798f1e2SMichael Clark { 367e1a29bbdSWeiwei Li float32 frs1 = check_nanbox_s(env, rs1); 368121ddbb3SLIU Zhiwei return fclass_s(frs1); 369f798f1e2SMichael Clark } 370f798f1e2SMichael Clark 371*a47842d1SChristoph Müllner uint64_t helper_fround_s(CPURISCVState *env, uint64_t rs1) 372*a47842d1SChristoph Müllner { 373*a47842d1SChristoph Müllner float_status *fs = &env->fp_status; 374*a47842d1SChristoph Müllner uint16_t nx_old = get_float_exception_flags(fs) & float_flag_inexact; 375*a47842d1SChristoph Müllner float32 frs1 = check_nanbox_s(env, rs1); 376*a47842d1SChristoph Müllner 377*a47842d1SChristoph Müllner frs1 = float32_round_to_int(frs1, fs); 378*a47842d1SChristoph Müllner 379*a47842d1SChristoph Müllner /* Restore the original NX flag. */ 380*a47842d1SChristoph Müllner uint16_t flags = get_float_exception_flags(fs); 381*a47842d1SChristoph Müllner flags &= ~float_flag_inexact; 382*a47842d1SChristoph Müllner flags |= nx_old; 383*a47842d1SChristoph Müllner set_float_exception_flags(flags, fs); 384*a47842d1SChristoph Müllner 385*a47842d1SChristoph Müllner return nanbox_s(env, frs1); 386*a47842d1SChristoph Müllner } 387*a47842d1SChristoph Müllner 388*a47842d1SChristoph Müllner uint64_t helper_froundnx_s(CPURISCVState *env, uint64_t rs1) 389*a47842d1SChristoph Müllner { 390*a47842d1SChristoph Müllner float32 frs1 = check_nanbox_s(env, rs1); 391*a47842d1SChristoph Müllner frs1 = float32_round_to_int(frs1, &env->fp_status); 392*a47842d1SChristoph Müllner return nanbox_s(env, frs1); 393*a47842d1SChristoph Müllner } 394*a47842d1SChristoph Müllner 395f798f1e2SMichael Clark uint64_t helper_fadd_d(CPURISCVState *env, uint64_t frs1, uint64_t frs2) 396f798f1e2SMichael Clark { 397f798f1e2SMichael Clark return float64_add(frs1, frs2, &env->fp_status); 398f798f1e2SMichael Clark } 399f798f1e2SMichael Clark 400f798f1e2SMichael Clark uint64_t helper_fsub_d(CPURISCVState *env, uint64_t frs1, uint64_t frs2) 401f798f1e2SMichael Clark { 402f798f1e2SMichael Clark return float64_sub(frs1, frs2, &env->fp_status); 403f798f1e2SMichael Clark } 404f798f1e2SMichael Clark 405f798f1e2SMichael Clark uint64_t helper_fmul_d(CPURISCVState *env, uint64_t frs1, uint64_t frs2) 406f798f1e2SMichael Clark { 407f798f1e2SMichael Clark return float64_mul(frs1, frs2, &env->fp_status); 408f798f1e2SMichael Clark } 409f798f1e2SMichael Clark 410f798f1e2SMichael Clark uint64_t helper_fdiv_d(CPURISCVState *env, uint64_t frs1, uint64_t frs2) 411f798f1e2SMichael Clark { 412f798f1e2SMichael Clark return float64_div(frs1, frs2, &env->fp_status); 413f798f1e2SMichael Clark } 414f798f1e2SMichael Clark 415f798f1e2SMichael Clark uint64_t helper_fmin_d(CPURISCVState *env, uint64_t frs1, uint64_t frs2) 416f798f1e2SMichael Clark { 41715161e42SChih-Min Chao return env->priv_ver < PRIV_VERSION_1_11_0 ? 41815161e42SChih-Min Chao float64_minnum(frs1, frs2, &env->fp_status) : 41915161e42SChih-Min Chao float64_minimum_number(frs1, frs2, &env->fp_status); 420f798f1e2SMichael Clark } 421f798f1e2SMichael Clark 422*a47842d1SChristoph Müllner uint64_t helper_fminm_d(CPURISCVState *env, uint64_t frs1, uint64_t frs2) 423*a47842d1SChristoph Müllner { 424*a47842d1SChristoph Müllner return float64_min(frs1, frs2, &env->fp_status); 425*a47842d1SChristoph Müllner } 426*a47842d1SChristoph Müllner 427f798f1e2SMichael Clark uint64_t helper_fmax_d(CPURISCVState *env, uint64_t frs1, uint64_t frs2) 428f798f1e2SMichael Clark { 42915161e42SChih-Min Chao return env->priv_ver < PRIV_VERSION_1_11_0 ? 43015161e42SChih-Min Chao float64_maxnum(frs1, frs2, &env->fp_status) : 43115161e42SChih-Min Chao float64_maximum_number(frs1, frs2, &env->fp_status); 432f798f1e2SMichael Clark } 433f798f1e2SMichael Clark 434*a47842d1SChristoph Müllner uint64_t helper_fmaxm_d(CPURISCVState *env, uint64_t frs1, uint64_t frs2) 435*a47842d1SChristoph Müllner { 436*a47842d1SChristoph Müllner return float64_max(frs1, frs2, &env->fp_status); 437*a47842d1SChristoph Müllner } 438*a47842d1SChristoph Müllner 439f798f1e2SMichael Clark uint64_t helper_fcvt_s_d(CPURISCVState *env, uint64_t rs1) 440f798f1e2SMichael Clark { 441e1a29bbdSWeiwei Li return nanbox_s(env, float64_to_float32(rs1, &env->fp_status)); 442f798f1e2SMichael Clark } 443f798f1e2SMichael Clark 444f798f1e2SMichael Clark uint64_t helper_fcvt_d_s(CPURISCVState *env, uint64_t rs1) 445f798f1e2SMichael Clark { 446e1a29bbdSWeiwei Li float32 frs1 = check_nanbox_s(env, rs1); 44700e925c5SRichard Henderson return float32_to_float64(frs1, &env->fp_status); 448f798f1e2SMichael Clark } 449f798f1e2SMichael Clark 450f798f1e2SMichael Clark uint64_t helper_fsqrt_d(CPURISCVState *env, uint64_t frs1) 451f798f1e2SMichael Clark { 452f798f1e2SMichael Clark return float64_sqrt(frs1, &env->fp_status); 453f798f1e2SMichael Clark } 454f798f1e2SMichael Clark 455f798f1e2SMichael Clark target_ulong helper_fle_d(CPURISCVState *env, uint64_t frs1, uint64_t frs2) 456f798f1e2SMichael Clark { 457f798f1e2SMichael Clark return float64_le(frs1, frs2, &env->fp_status); 458f798f1e2SMichael Clark } 459f798f1e2SMichael Clark 460*a47842d1SChristoph Müllner target_ulong helper_fleq_d(CPURISCVState *env, uint64_t frs1, uint64_t frs2) 461*a47842d1SChristoph Müllner { 462*a47842d1SChristoph Müllner return float64_le_quiet(frs1, frs2, &env->fp_status); 463*a47842d1SChristoph Müllner } 464*a47842d1SChristoph Müllner 465f798f1e2SMichael Clark target_ulong helper_flt_d(CPURISCVState *env, uint64_t frs1, uint64_t frs2) 466f798f1e2SMichael Clark { 467f798f1e2SMichael Clark return float64_lt(frs1, frs2, &env->fp_status); 468f798f1e2SMichael Clark } 469f798f1e2SMichael Clark 470*a47842d1SChristoph Müllner target_ulong helper_fltq_d(CPURISCVState *env, uint64_t frs1, uint64_t frs2) 471*a47842d1SChristoph Müllner { 472*a47842d1SChristoph Müllner return float64_lt_quiet(frs1, frs2, &env->fp_status); 473*a47842d1SChristoph Müllner } 474*a47842d1SChristoph Müllner 475f798f1e2SMichael Clark target_ulong helper_feq_d(CPURISCVState *env, uint64_t frs1, uint64_t frs2) 476f798f1e2SMichael Clark { 477f798f1e2SMichael Clark return float64_eq_quiet(frs1, frs2, &env->fp_status); 478f798f1e2SMichael Clark } 479f798f1e2SMichael Clark 480f798f1e2SMichael Clark target_ulong helper_fcvt_w_d(CPURISCVState *env, uint64_t frs1) 481f798f1e2SMichael Clark { 482f798f1e2SMichael Clark return float64_to_int32(frs1, &env->fp_status); 483f798f1e2SMichael Clark } 484f798f1e2SMichael Clark 485*a47842d1SChristoph Müllner uint64_t helper_fcvtmod_w_d(CPURISCVState *env, uint64_t value) 486*a47842d1SChristoph Müllner { 487*a47842d1SChristoph Müllner return float64_to_int32_modulo(value, float_round_to_zero, &env->fp_status); 488*a47842d1SChristoph Müllner } 489*a47842d1SChristoph Müllner 490f798f1e2SMichael Clark target_ulong helper_fcvt_wu_d(CPURISCVState *env, uint64_t frs1) 491f798f1e2SMichael Clark { 492f798f1e2SMichael Clark return (int32_t)float64_to_uint32(frs1, &env->fp_status); 493f798f1e2SMichael Clark } 494f798f1e2SMichael Clark 495daf866b6SAlistair Francis target_ulong helper_fcvt_l_d(CPURISCVState *env, uint64_t frs1) 496f798f1e2SMichael Clark { 497f798f1e2SMichael Clark return float64_to_int64(frs1, &env->fp_status); 498f798f1e2SMichael Clark } 499f798f1e2SMichael Clark 500daf866b6SAlistair Francis target_ulong helper_fcvt_lu_d(CPURISCVState *env, uint64_t frs1) 501f798f1e2SMichael Clark { 502f798f1e2SMichael Clark return float64_to_uint64(frs1, &env->fp_status); 503f798f1e2SMichael Clark } 504f798f1e2SMichael Clark 505f798f1e2SMichael Clark uint64_t helper_fcvt_d_w(CPURISCVState *env, target_ulong rs1) 506f798f1e2SMichael Clark { 507f798f1e2SMichael Clark return int32_to_float64((int32_t)rs1, &env->fp_status); 508f798f1e2SMichael Clark } 509f798f1e2SMichael Clark 510f798f1e2SMichael Clark uint64_t helper_fcvt_d_wu(CPURISCVState *env, target_ulong rs1) 511f798f1e2SMichael Clark { 512f798f1e2SMichael Clark return uint32_to_float64((uint32_t)rs1, &env->fp_status); 513f798f1e2SMichael Clark } 514f798f1e2SMichael Clark 515daf866b6SAlistair Francis uint64_t helper_fcvt_d_l(CPURISCVState *env, target_ulong rs1) 516f798f1e2SMichael Clark { 517f798f1e2SMichael Clark return int64_to_float64(rs1, &env->fp_status); 518f798f1e2SMichael Clark } 519f798f1e2SMichael Clark 520daf866b6SAlistair Francis uint64_t helper_fcvt_d_lu(CPURISCVState *env, target_ulong rs1) 521f798f1e2SMichael Clark { 522f798f1e2SMichael Clark return uint64_to_float64(rs1, &env->fp_status); 523f798f1e2SMichael Clark } 524f798f1e2SMichael Clark 525f798f1e2SMichael Clark target_ulong helper_fclass_d(uint64_t frs1) 526f798f1e2SMichael Clark { 527121ddbb3SLIU Zhiwei return fclass_d(frs1); 528f798f1e2SMichael Clark } 52900c1899fSKito Cheng 530*a47842d1SChristoph Müllner uint64_t helper_fround_d(CPURISCVState *env, uint64_t frs1) 531*a47842d1SChristoph Müllner { 532*a47842d1SChristoph Müllner float_status *fs = &env->fp_status; 533*a47842d1SChristoph Müllner uint16_t nx_old = get_float_exception_flags(fs) & float_flag_inexact; 534*a47842d1SChristoph Müllner 535*a47842d1SChristoph Müllner frs1 = float64_round_to_int(frs1, fs); 536*a47842d1SChristoph Müllner 537*a47842d1SChristoph Müllner /* Restore the original NX flag. */ 538*a47842d1SChristoph Müllner uint16_t flags = get_float_exception_flags(fs); 539*a47842d1SChristoph Müllner flags &= ~float_flag_inexact; 540*a47842d1SChristoph Müllner flags |= nx_old; 541*a47842d1SChristoph Müllner set_float_exception_flags(flags, fs); 542*a47842d1SChristoph Müllner 543*a47842d1SChristoph Müllner return frs1; 544*a47842d1SChristoph Müllner } 545*a47842d1SChristoph Müllner 546*a47842d1SChristoph Müllner uint64_t helper_froundnx_d(CPURISCVState *env, uint64_t frs1) 547*a47842d1SChristoph Müllner { 548*a47842d1SChristoph Müllner return float64_round_to_int(frs1, &env->fp_status); 549*a47842d1SChristoph Müllner } 550*a47842d1SChristoph Müllner 55100c1899fSKito Cheng uint64_t helper_fadd_h(CPURISCVState *env, uint64_t rs1, uint64_t rs2) 55200c1899fSKito Cheng { 553a2464a4cSWeiwei Li float16 frs1 = check_nanbox_h(env, rs1); 554a2464a4cSWeiwei Li float16 frs2 = check_nanbox_h(env, rs2); 555a2464a4cSWeiwei Li return nanbox_h(env, float16_add(frs1, frs2, &env->fp_status)); 55600c1899fSKito Cheng } 55700c1899fSKito Cheng 55800c1899fSKito Cheng uint64_t helper_fsub_h(CPURISCVState *env, uint64_t rs1, uint64_t rs2) 55900c1899fSKito Cheng { 560a2464a4cSWeiwei Li float16 frs1 = check_nanbox_h(env, rs1); 561a2464a4cSWeiwei Li float16 frs2 = check_nanbox_h(env, rs2); 562a2464a4cSWeiwei Li return nanbox_h(env, float16_sub(frs1, frs2, &env->fp_status)); 56300c1899fSKito Cheng } 56400c1899fSKito Cheng 56500c1899fSKito Cheng uint64_t helper_fmul_h(CPURISCVState *env, uint64_t rs1, uint64_t rs2) 56600c1899fSKito Cheng { 567a2464a4cSWeiwei Li float16 frs1 = check_nanbox_h(env, rs1); 568a2464a4cSWeiwei Li float16 frs2 = check_nanbox_h(env, rs2); 569a2464a4cSWeiwei Li return nanbox_h(env, float16_mul(frs1, frs2, &env->fp_status)); 57000c1899fSKito Cheng } 57100c1899fSKito Cheng 57200c1899fSKito Cheng uint64_t helper_fdiv_h(CPURISCVState *env, uint64_t rs1, uint64_t rs2) 57300c1899fSKito Cheng { 574a2464a4cSWeiwei Li float16 frs1 = check_nanbox_h(env, rs1); 575a2464a4cSWeiwei Li float16 frs2 = check_nanbox_h(env, rs2); 576a2464a4cSWeiwei Li return nanbox_h(env, float16_div(frs1, frs2, &env->fp_status)); 57700c1899fSKito Cheng } 57800c1899fSKito Cheng 57900c1899fSKito Cheng uint64_t helper_fmin_h(CPURISCVState *env, uint64_t rs1, uint64_t rs2) 58000c1899fSKito Cheng { 581a2464a4cSWeiwei Li float16 frs1 = check_nanbox_h(env, rs1); 582a2464a4cSWeiwei Li float16 frs2 = check_nanbox_h(env, rs2); 583a2464a4cSWeiwei Li return nanbox_h(env, env->priv_ver < PRIV_VERSION_1_11_0 ? 58400c1899fSKito Cheng float16_minnum(frs1, frs2, &env->fp_status) : 58500c1899fSKito Cheng float16_minimum_number(frs1, frs2, &env->fp_status)); 58600c1899fSKito Cheng } 58700c1899fSKito Cheng 588*a47842d1SChristoph Müllner uint64_t helper_fminm_h(CPURISCVState *env, uint64_t rs1, uint64_t rs2) 589*a47842d1SChristoph Müllner { 590*a47842d1SChristoph Müllner float16 frs1 = check_nanbox_h(env, rs1); 591*a47842d1SChristoph Müllner float16 frs2 = check_nanbox_h(env, rs2); 592*a47842d1SChristoph Müllner float16 ret = float16_min(frs1, frs2, &env->fp_status); 593*a47842d1SChristoph Müllner return nanbox_h(env, ret); 594*a47842d1SChristoph Müllner } 595*a47842d1SChristoph Müllner 59600c1899fSKito Cheng uint64_t helper_fmax_h(CPURISCVState *env, uint64_t rs1, uint64_t rs2) 59700c1899fSKito Cheng { 598a2464a4cSWeiwei Li float16 frs1 = check_nanbox_h(env, rs1); 599a2464a4cSWeiwei Li float16 frs2 = check_nanbox_h(env, rs2); 600a2464a4cSWeiwei Li return nanbox_h(env, env->priv_ver < PRIV_VERSION_1_11_0 ? 60100c1899fSKito Cheng float16_maxnum(frs1, frs2, &env->fp_status) : 60200c1899fSKito Cheng float16_maximum_number(frs1, frs2, &env->fp_status)); 60300c1899fSKito Cheng } 60400c1899fSKito Cheng 605*a47842d1SChristoph Müllner uint64_t helper_fmaxm_h(CPURISCVState *env, uint64_t rs1, uint64_t rs2) 606*a47842d1SChristoph Müllner { 607*a47842d1SChristoph Müllner float16 frs1 = check_nanbox_h(env, rs1); 608*a47842d1SChristoph Müllner float16 frs2 = check_nanbox_h(env, rs2); 609*a47842d1SChristoph Müllner float16 ret = float16_max(frs1, frs2, &env->fp_status); 610*a47842d1SChristoph Müllner return nanbox_h(env, ret); 611*a47842d1SChristoph Müllner } 612*a47842d1SChristoph Müllner 61300c1899fSKito Cheng uint64_t helper_fsqrt_h(CPURISCVState *env, uint64_t rs1) 61400c1899fSKito Cheng { 615a2464a4cSWeiwei Li float16 frs1 = check_nanbox_h(env, rs1); 616a2464a4cSWeiwei Li return nanbox_h(env, float16_sqrt(frs1, &env->fp_status)); 61700c1899fSKito Cheng } 6187b03c8e5SKito Cheng 61911f9c450SKito Cheng target_ulong helper_fle_h(CPURISCVState *env, uint64_t rs1, uint64_t rs2) 62011f9c450SKito Cheng { 621a2464a4cSWeiwei Li float16 frs1 = check_nanbox_h(env, rs1); 622a2464a4cSWeiwei Li float16 frs2 = check_nanbox_h(env, rs2); 62311f9c450SKito Cheng return float16_le(frs1, frs2, &env->fp_status); 62411f9c450SKito Cheng } 62511f9c450SKito Cheng 626*a47842d1SChristoph Müllner target_ulong helper_fleq_h(CPURISCVState *env, uint64_t rs1, uint64_t rs2) 627*a47842d1SChristoph Müllner { 628*a47842d1SChristoph Müllner float16 frs1 = check_nanbox_h(env, rs1); 629*a47842d1SChristoph Müllner float16 frs2 = check_nanbox_h(env, rs2); 630*a47842d1SChristoph Müllner return float16_le_quiet(frs1, frs2, &env->fp_status); 631*a47842d1SChristoph Müllner } 632*a47842d1SChristoph Müllner 63311f9c450SKito Cheng target_ulong helper_flt_h(CPURISCVState *env, uint64_t rs1, uint64_t rs2) 63411f9c450SKito Cheng { 635a2464a4cSWeiwei Li float16 frs1 = check_nanbox_h(env, rs1); 636a2464a4cSWeiwei Li float16 frs2 = check_nanbox_h(env, rs2); 63711f9c450SKito Cheng return float16_lt(frs1, frs2, &env->fp_status); 63811f9c450SKito Cheng } 63911f9c450SKito Cheng 640*a47842d1SChristoph Müllner target_ulong helper_fltq_h(CPURISCVState *env, uint64_t rs1, uint64_t rs2) 641*a47842d1SChristoph Müllner { 642*a47842d1SChristoph Müllner float16 frs1 = check_nanbox_h(env, rs1); 643*a47842d1SChristoph Müllner float16 frs2 = check_nanbox_h(env, rs2); 644*a47842d1SChristoph Müllner return float16_lt_quiet(frs1, frs2, &env->fp_status); 645*a47842d1SChristoph Müllner } 646*a47842d1SChristoph Müllner 64711f9c450SKito Cheng target_ulong helper_feq_h(CPURISCVState *env, uint64_t rs1, uint64_t rs2) 64811f9c450SKito Cheng { 649a2464a4cSWeiwei Li float16 frs1 = check_nanbox_h(env, rs1); 650a2464a4cSWeiwei Li float16 frs2 = check_nanbox_h(env, rs2); 65111f9c450SKito Cheng return float16_eq_quiet(frs1, frs2, &env->fp_status); 65211f9c450SKito Cheng } 65311f9c450SKito Cheng 654a2464a4cSWeiwei Li target_ulong helper_fclass_h(CPURISCVState *env, uint64_t rs1) 6556bc6fc96SKito Cheng { 656a2464a4cSWeiwei Li float16 frs1 = check_nanbox_h(env, rs1); 6576bc6fc96SKito Cheng return fclass_h(frs1); 6586bc6fc96SKito Cheng } 6596bc6fc96SKito Cheng 660*a47842d1SChristoph Müllner uint64_t helper_fround_h(CPURISCVState *env, uint64_t rs1) 661*a47842d1SChristoph Müllner { 662*a47842d1SChristoph Müllner float_status *fs = &env->fp_status; 663*a47842d1SChristoph Müllner uint16_t nx_old = get_float_exception_flags(fs) & float_flag_inexact; 664*a47842d1SChristoph Müllner float16 frs1 = check_nanbox_h(env, rs1); 665*a47842d1SChristoph Müllner 666*a47842d1SChristoph Müllner frs1 = float16_round_to_int(frs1, fs); 667*a47842d1SChristoph Müllner 668*a47842d1SChristoph Müllner /* Restore the original NX flag. */ 669*a47842d1SChristoph Müllner uint16_t flags = get_float_exception_flags(fs); 670*a47842d1SChristoph Müllner flags &= ~float_flag_inexact; 671*a47842d1SChristoph Müllner flags |= nx_old; 672*a47842d1SChristoph Müllner set_float_exception_flags(flags, fs); 673*a47842d1SChristoph Müllner 674*a47842d1SChristoph Müllner return nanbox_h(env, frs1); 675*a47842d1SChristoph Müllner } 676*a47842d1SChristoph Müllner 677*a47842d1SChristoph Müllner uint64_t helper_froundnx_h(CPURISCVState *env, uint64_t rs1) 678*a47842d1SChristoph Müllner { 679*a47842d1SChristoph Müllner float16 frs1 = check_nanbox_s(env, rs1); 680*a47842d1SChristoph Müllner frs1 = float16_round_to_int(frs1, &env->fp_status); 681*a47842d1SChristoph Müllner return nanbox_h(env, frs1); 682*a47842d1SChristoph Müllner } 683*a47842d1SChristoph Müllner 6847b03c8e5SKito Cheng target_ulong helper_fcvt_w_h(CPURISCVState *env, uint64_t rs1) 6857b03c8e5SKito Cheng { 686a2464a4cSWeiwei Li float16 frs1 = check_nanbox_h(env, rs1); 6877b03c8e5SKito Cheng return float16_to_int32(frs1, &env->fp_status); 6887b03c8e5SKito Cheng } 6897b03c8e5SKito Cheng 6907b03c8e5SKito Cheng target_ulong helper_fcvt_wu_h(CPURISCVState *env, uint64_t rs1) 6917b03c8e5SKito Cheng { 692a2464a4cSWeiwei Li float16 frs1 = check_nanbox_h(env, rs1); 6937b03c8e5SKito Cheng return (int32_t)float16_to_uint32(frs1, &env->fp_status); 6947b03c8e5SKito Cheng } 6957b03c8e5SKito Cheng 6967b03c8e5SKito Cheng target_ulong helper_fcvt_l_h(CPURISCVState *env, uint64_t rs1) 6977b03c8e5SKito Cheng { 698a2464a4cSWeiwei Li float16 frs1 = check_nanbox_h(env, rs1); 6997b03c8e5SKito Cheng return float16_to_int64(frs1, &env->fp_status); 7007b03c8e5SKito Cheng } 7017b03c8e5SKito Cheng 7027b03c8e5SKito Cheng target_ulong helper_fcvt_lu_h(CPURISCVState *env, uint64_t rs1) 7037b03c8e5SKito Cheng { 704a2464a4cSWeiwei Li float16 frs1 = check_nanbox_h(env, rs1); 7057b03c8e5SKito Cheng return float16_to_uint64(frs1, &env->fp_status); 7067b03c8e5SKito Cheng } 7077b03c8e5SKito Cheng 7087b03c8e5SKito Cheng uint64_t helper_fcvt_h_w(CPURISCVState *env, target_ulong rs1) 7097b03c8e5SKito Cheng { 710a2464a4cSWeiwei Li return nanbox_h(env, int32_to_float16((int32_t)rs1, &env->fp_status)); 7117b03c8e5SKito Cheng } 7127b03c8e5SKito Cheng 7137b03c8e5SKito Cheng uint64_t helper_fcvt_h_wu(CPURISCVState *env, target_ulong rs1) 7147b03c8e5SKito Cheng { 715a2464a4cSWeiwei Li return nanbox_h(env, uint32_to_float16((uint32_t)rs1, &env->fp_status)); 7167b03c8e5SKito Cheng } 7177b03c8e5SKito Cheng 7187b03c8e5SKito Cheng uint64_t helper_fcvt_h_l(CPURISCVState *env, target_ulong rs1) 7197b03c8e5SKito Cheng { 720a2464a4cSWeiwei Li return nanbox_h(env, int64_to_float16(rs1, &env->fp_status)); 7217b03c8e5SKito Cheng } 7227b03c8e5SKito Cheng 7237b03c8e5SKito Cheng uint64_t helper_fcvt_h_lu(CPURISCVState *env, target_ulong rs1) 7247b03c8e5SKito Cheng { 725a2464a4cSWeiwei Li return nanbox_h(env, uint64_to_float16(rs1, &env->fp_status)); 7267b03c8e5SKito Cheng } 7277b03c8e5SKito Cheng 7287b03c8e5SKito Cheng uint64_t helper_fcvt_h_s(CPURISCVState *env, uint64_t rs1) 7297b03c8e5SKito Cheng { 730e1a29bbdSWeiwei Li float32 frs1 = check_nanbox_s(env, rs1); 731a2464a4cSWeiwei Li return nanbox_h(env, float32_to_float16(frs1, true, &env->fp_status)); 7327b03c8e5SKito Cheng } 7337b03c8e5SKito Cheng 7347b03c8e5SKito Cheng uint64_t helper_fcvt_s_h(CPURISCVState *env, uint64_t rs1) 7357b03c8e5SKito Cheng { 736a2464a4cSWeiwei Li float16 frs1 = check_nanbox_h(env, rs1); 737e1a29bbdSWeiwei Li return nanbox_s(env, float16_to_float32(frs1, true, &env->fp_status)); 7387b03c8e5SKito Cheng } 7397b03c8e5SKito Cheng 7407b03c8e5SKito Cheng uint64_t helper_fcvt_h_d(CPURISCVState *env, uint64_t rs1) 7417b03c8e5SKito Cheng { 742a2464a4cSWeiwei Li return nanbox_h(env, float64_to_float16(rs1, true, &env->fp_status)); 7437b03c8e5SKito Cheng } 7447b03c8e5SKito Cheng 7457b03c8e5SKito Cheng uint64_t helper_fcvt_d_h(CPURISCVState *env, uint64_t rs1) 7467b03c8e5SKito Cheng { 747a2464a4cSWeiwei Li float16 frs1 = check_nanbox_h(env, rs1); 7487b03c8e5SKito Cheng return float16_to_float64(frs1, true, &env->fp_status); 7497b03c8e5SKito Cheng } 7505d1270caSWeiwei Li 7515d1270caSWeiwei Li uint64_t helper_fcvt_bf16_s(CPURISCVState *env, uint64_t rs1) 7525d1270caSWeiwei Li { 7535d1270caSWeiwei Li float32 frs1 = check_nanbox_s(env, rs1); 7545d1270caSWeiwei Li return nanbox_h(env, float32_to_bfloat16(frs1, &env->fp_status)); 7555d1270caSWeiwei Li } 7565d1270caSWeiwei Li 7575d1270caSWeiwei Li uint64_t helper_fcvt_s_bf16(CPURISCVState *env, uint64_t rs1) 7585d1270caSWeiwei Li { 7595d1270caSWeiwei Li float16 frs1 = check_nanbox_h(env, rs1); 7605d1270caSWeiwei Li return nanbox_s(env, bfloat16_to_float32(frs1, &env->fp_status)); 7615d1270caSWeiwei Li } 762