xref: /openbmc/qemu/target/mips/msa.c (revision 7d87775f)
1 /*
2  * MIPS SIMD Architecture Module Instruction emulation helpers for QEMU.
3  *
4  * Copyright (c) 2014 Imagination Technologies
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include "qemu/osdep.h"
21 #include "cpu.h"
22 #include "internal.h"
23 #include "fpu/softfloat.h"
24 #include "fpu_helper.h"
25 
26 void msa_reset(CPUMIPSState *env)
27 {
28     if (!ase_msa_available(env)) {
29         return;
30     }
31 
32 #ifdef CONFIG_USER_ONLY
33     /* MSA access enabled */
34     env->CP0_Config5 |= 1 << CP0C5_MSAEn;
35     env->CP0_Status |= (1 << CP0St_CU1) | (1 << CP0St_FR);
36 #endif
37 
38     /*
39      * MSA CSR:
40      * - non-signaling floating point exception mode off (NX bit is 0)
41      * - Cause, Enables, and Flags are all 0
42      * - round to nearest / ties to even (RM bits are 0)
43      */
44     env->active_tc.msacsr = 0;
45 
46     restore_msa_fp_status(env);
47 
48     /* tininess detected after rounding.*/
49     set_float_detect_tininess(float_tininess_after_rounding,
50                               &env->active_tc.msa_fp_status);
51 
52     /*
53      * According to MIPS specifications, if one of the two operands is
54      * a sNaN, a new qNaN has to be generated. This is done in
55      * floatXX_silence_nan(). For qNaN inputs the specifications
56      * says: "When possible, this QNaN result is one of the operand QNaN
57      * values." In practice it seems that most implementations choose
58      * the first operand if both operands are qNaN. In short this gives
59      * the following rules:
60      *  1. A if it is signaling
61      *  2. B if it is signaling
62      *  3. A (quiet)
63      *  4. B (quiet)
64      * A signaling NaN is always silenced before returning it.
65      */
66     set_float_2nan_prop_rule(float_2nan_prop_s_ab,
67                              &env->active_tc.msa_fp_status);
68 
69     /* clear float_status exception flags */
70     set_float_exception_flags(0, &env->active_tc.msa_fp_status);
71 
72     /* clear float_status nan mode */
73     set_default_nan_mode(0, &env->active_tc.msa_fp_status);
74 
75     /* set proper signanling bit meaning ("1" means "quiet") */
76     set_snan_bit_is_one(0, &env->active_tc.msa_fp_status);
77 }
78