1fed50ffdSPhilippe Mathieu-Daudé /* 2fed50ffdSPhilippe Mathieu-Daudé * MIPS SIMD Architecture Module Instruction emulation helpers for QEMU. 3fed50ffdSPhilippe Mathieu-Daudé * 4fed50ffdSPhilippe Mathieu-Daudé * Copyright (c) 2014 Imagination Technologies 5fed50ffdSPhilippe Mathieu-Daudé * 6fed50ffdSPhilippe Mathieu-Daudé * This library is free software; you can redistribute it and/or 7fed50ffdSPhilippe Mathieu-Daudé * modify it under the terms of the GNU Lesser General Public 8fed50ffdSPhilippe Mathieu-Daudé * License as published by the Free Software Foundation; either 9fed50ffdSPhilippe Mathieu-Daudé * version 2.1 of the License, or (at your option) any later version. 10fed50ffdSPhilippe Mathieu-Daudé * 11fed50ffdSPhilippe Mathieu-Daudé * This library is distributed in the hope that it will be useful, 12fed50ffdSPhilippe Mathieu-Daudé * but WITHOUT ANY WARRANTY; without even the implied warranty of 13fed50ffdSPhilippe Mathieu-Daudé * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14fed50ffdSPhilippe Mathieu-Daudé * Lesser General Public License for more details. 15fed50ffdSPhilippe Mathieu-Daudé * 16fed50ffdSPhilippe Mathieu-Daudé * You should have received a copy of the GNU Lesser General Public 17fed50ffdSPhilippe Mathieu-Daudé * License along with this library; if not, see <http://www.gnu.org/licenses/>. 18fed50ffdSPhilippe Mathieu-Daudé */ 19fed50ffdSPhilippe Mathieu-Daudé 20fed50ffdSPhilippe Mathieu-Daudé #include "qemu/osdep.h" 21fed50ffdSPhilippe Mathieu-Daudé #include "cpu.h" 22fed50ffdSPhilippe Mathieu-Daudé #include "internal.h" 23fed50ffdSPhilippe Mathieu-Daudé #include "fpu/softfloat.h" 24fed50ffdSPhilippe Mathieu-Daudé #include "fpu_helper.h" 25fed50ffdSPhilippe Mathieu-Daudé 26fed50ffdSPhilippe Mathieu-Daudé void msa_reset(CPUMIPSState *env) 27fed50ffdSPhilippe Mathieu-Daudé { 28fed50ffdSPhilippe Mathieu-Daudé if (!ase_msa_available(env)) { 29fed50ffdSPhilippe Mathieu-Daudé return; 30fed50ffdSPhilippe Mathieu-Daudé } 31fed50ffdSPhilippe Mathieu-Daudé 32fed50ffdSPhilippe Mathieu-Daudé #ifdef CONFIG_USER_ONLY 33fed50ffdSPhilippe Mathieu-Daudé /* MSA access enabled */ 34fed50ffdSPhilippe Mathieu-Daudé env->CP0_Config5 |= 1 << CP0C5_MSAEn; 35fed50ffdSPhilippe Mathieu-Daudé env->CP0_Status |= (1 << CP0St_CU1) | (1 << CP0St_FR); 36fed50ffdSPhilippe Mathieu-Daudé #endif 37fed50ffdSPhilippe Mathieu-Daudé 38fed50ffdSPhilippe Mathieu-Daudé /* 39fed50ffdSPhilippe Mathieu-Daudé * MSA CSR: 40fed50ffdSPhilippe Mathieu-Daudé * - non-signaling floating point exception mode off (NX bit is 0) 41fed50ffdSPhilippe Mathieu-Daudé * - Cause, Enables, and Flags are all 0 42fed50ffdSPhilippe Mathieu-Daudé * - round to nearest / ties to even (RM bits are 0) 43fed50ffdSPhilippe Mathieu-Daudé */ 44fed50ffdSPhilippe Mathieu-Daudé env->active_tc.msacsr = 0; 45fed50ffdSPhilippe Mathieu-Daudé 46fed50ffdSPhilippe Mathieu-Daudé restore_msa_fp_status(env); 47fed50ffdSPhilippe Mathieu-Daudé 48fed50ffdSPhilippe Mathieu-Daudé /* tininess detected after rounding.*/ 49fed50ffdSPhilippe Mathieu-Daudé set_float_detect_tininess(float_tininess_after_rounding, 50fed50ffdSPhilippe Mathieu-Daudé &env->active_tc.msa_fp_status); 51*28f13bccSPeter Maydell /* 52*28f13bccSPeter Maydell * MSACSR.FS detects tiny results to flush to zero before rounding 53*28f13bccSPeter Maydell * (per "MIPS Architecture for Programmers Volume IV-j: The MIPS64 SIMD 54*28f13bccSPeter Maydell * Architecture Module, Revision 1.1" section 3.5.4), even though it 55*28f13bccSPeter Maydell * detects tininess after rounding for underflow purposes (section 3.4.2 56*28f13bccSPeter Maydell * table 3.3). 57*28f13bccSPeter Maydell */ 58*28f13bccSPeter Maydell set_float_ftz_detection(float_ftz_before_rounding, 59*28f13bccSPeter Maydell &env->active_tc.msa_fp_status); 60fed50ffdSPhilippe Mathieu-Daudé 610c587f13SPeter Maydell /* 620c587f13SPeter Maydell * According to MIPS specifications, if one of the two operands is 630c587f13SPeter Maydell * a sNaN, a new qNaN has to be generated. This is done in 640c587f13SPeter Maydell * floatXX_silence_nan(). For qNaN inputs the specifications 650c587f13SPeter Maydell * says: "When possible, this QNaN result is one of the operand QNaN 660c587f13SPeter Maydell * values." In practice it seems that most implementations choose 670c587f13SPeter Maydell * the first operand if both operands are qNaN. In short this gives 680c587f13SPeter Maydell * the following rules: 690c587f13SPeter Maydell * 1. A if it is signaling 700c587f13SPeter Maydell * 2. B if it is signaling 710c587f13SPeter Maydell * 3. A (quiet) 720c587f13SPeter Maydell * 4. B (quiet) 730c587f13SPeter Maydell * A signaling NaN is always silenced before returning it. 740c587f13SPeter Maydell */ 750c587f13SPeter Maydell set_float_2nan_prop_rule(float_2nan_prop_s_ab, 760c587f13SPeter Maydell &env->active_tc.msa_fp_status); 770c587f13SPeter Maydell 783a453712SPeter Maydell set_float_3nan_prop_rule(float_3nan_prop_s_cab, 793a453712SPeter Maydell &env->active_tc.msa_fp_status); 803a453712SPeter Maydell 81fed50ffdSPhilippe Mathieu-Daudé /* clear float_status exception flags */ 82fed50ffdSPhilippe Mathieu-Daudé set_float_exception_flags(0, &env->active_tc.msa_fp_status); 83fed50ffdSPhilippe Mathieu-Daudé 84fed50ffdSPhilippe Mathieu-Daudé /* clear float_status nan mode */ 85fed50ffdSPhilippe Mathieu-Daudé set_default_nan_mode(0, &env->active_tc.msa_fp_status); 86fed50ffdSPhilippe Mathieu-Daudé 87fed50ffdSPhilippe Mathieu-Daudé /* set proper signanling bit meaning ("1" means "quiet") */ 88fed50ffdSPhilippe Mathieu-Daudé set_snan_bit_is_one(0, &env->active_tc.msa_fp_status); 89a71492f7SPeter Maydell 90a71492f7SPeter Maydell /* Inf * 0 + NaN returns the input NaN */ 91a71492f7SPeter Maydell set_float_infzeronan_rule(float_infzeronan_dnan_never, 92a71492f7SPeter Maydell &env->active_tc.msa_fp_status); 935c3ba810SPeter Maydell /* Default NaN: sign bit clear, frac msb set */ 945c3ba810SPeter Maydell set_float_default_nan_pattern(0b01000000, 955c3ba810SPeter Maydell &env->active_tc.msa_fp_status); 96fed50ffdSPhilippe Mathieu-Daudé } 97