xref: /openbmc/qemu/target/mips/msa.c (revision f15f7273ea55472d5904c53566c82369d81214c1)
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é 
msa_reset(CPUMIPSState * env)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);
51fed50ffdSPhilippe Mathieu-Daudé 
52*0c587f13SPeter Maydell     /*
53*0c587f13SPeter Maydell      * According to MIPS specifications, if one of the two operands is
54*0c587f13SPeter Maydell      * a sNaN, a new qNaN has to be generated. This is done in
55*0c587f13SPeter Maydell      * floatXX_silence_nan(). For qNaN inputs the specifications
56*0c587f13SPeter Maydell      * says: "When possible, this QNaN result is one of the operand QNaN
57*0c587f13SPeter Maydell      * values." In practice it seems that most implementations choose
58*0c587f13SPeter Maydell      * the first operand if both operands are qNaN. In short this gives
59*0c587f13SPeter Maydell      * the following rules:
60*0c587f13SPeter Maydell      *  1. A if it is signaling
61*0c587f13SPeter Maydell      *  2. B if it is signaling
62*0c587f13SPeter Maydell      *  3. A (quiet)
63*0c587f13SPeter Maydell      *  4. B (quiet)
64*0c587f13SPeter Maydell      * A signaling NaN is always silenced before returning it.
65*0c587f13SPeter Maydell      */
66*0c587f13SPeter Maydell     set_float_2nan_prop_rule(float_2nan_prop_s_ab,
67*0c587f13SPeter Maydell                              &env->active_tc.msa_fp_status);
68*0c587f13SPeter Maydell 
69fed50ffdSPhilippe Mathieu-Daudé     /* clear float_status exception flags */
70fed50ffdSPhilippe Mathieu-Daudé     set_float_exception_flags(0, &env->active_tc.msa_fp_status);
71fed50ffdSPhilippe Mathieu-Daudé 
72fed50ffdSPhilippe Mathieu-Daudé     /* clear float_status nan mode */
73fed50ffdSPhilippe Mathieu-Daudé     set_default_nan_mode(0, &env->active_tc.msa_fp_status);
74fed50ffdSPhilippe Mathieu-Daudé 
75fed50ffdSPhilippe Mathieu-Daudé     /* set proper signanling bit meaning ("1" means "quiet") */
76fed50ffdSPhilippe Mathieu-Daudé     set_snan_bit_is_one(0, &env->active_tc.msa_fp_status);
77fed50ffdSPhilippe Mathieu-Daudé }
78