xref: /openbmc/qemu/target/mips/msa.c (revision f101c9fe)
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     /* clear float_status exception flags */
53     set_float_exception_flags(0, &env->active_tc.msa_fp_status);
54 
55     /* clear float_status nan mode */
56     set_default_nan_mode(0, &env->active_tc.msa_fp_status);
57 
58     /* set proper signanling bit meaning ("1" means "quiet") */
59     set_snan_bit_is_one(0, &env->active_tc.msa_fp_status);
60 }
61