blob: ad1116e8c103b0b28a789fa2857e476b0cc8abf9 [file] [log] [blame]
Philippe Mathieu-Daudé81ddae72020-11-14 19:03:11 +01001/*
2 * Helpers for emulation of FPU-related MIPS instructions.
3 *
4 * Copyright (C) 2004-2005 Jocelyn Mayer
5 *
6 * SPDX-License-Identifier: LGPL-2.1-or-later
7 */
8#include "fpu/softfloat-helpers.h"
9#include "cpu.h"
10
11extern const FloatRoundMode ieee_rm[4];
12
13uint32_t float_class_s(uint32_t arg, float_status *fst);
14uint64_t float_class_d(uint64_t arg, float_status *fst);
15
16static inline void restore_rounding_mode(CPUMIPSState *env)
17{
18 set_float_rounding_mode(ieee_rm[env->active_fpu.fcr31 & 3],
19 &env->active_fpu.fp_status);
20}
21
22static inline void restore_flush_mode(CPUMIPSState *env)
23{
24 set_flush_to_zero((env->active_fpu.fcr31 & (1 << FCR31_FS)) != 0,
25 &env->active_fpu.fp_status);
26}
27
28static inline void restore_snan_bit_mode(CPUMIPSState *env)
29{
Richard Hendersone9e55342020-10-22 09:17:46 -070030 bool nan2008 = env->active_fpu.fcr31 & (1 << FCR31_NAN2008);
31
32 /*
33 * With nan2008, SNaNs are silenced in the usual way.
34 * Before that, SNaNs are not silenced; default nans are produced.
35 */
36 set_snan_bit_is_one(!nan2008, &env->active_fpu.fp_status);
37 set_default_nan_mode(!nan2008, &env->active_fpu.fp_status);
Philippe Mathieu-Daudé81ddae72020-11-14 19:03:11 +010038}
39
40static inline void restore_fp_status(CPUMIPSState *env)
41{
42 restore_rounding_mode(env);
43 restore_flush_mode(env);
44 restore_snan_bit_mode(env);
45}
46
47/* MSA */
48
49enum CPUMIPSMSADataFormat {
50 DF_BYTE = 0,
51 DF_HALF,
52 DF_WORD,
53 DF_DOUBLE
54};
55
56static inline void restore_msa_fp_status(CPUMIPSState *env)
57{
58 float_status *status = &env->active_tc.msa_fp_status;
59 int rounding_mode = (env->active_tc.msacsr & MSACSR_RM_MASK) >> MSACSR_RM;
60 bool flush_to_zero = (env->active_tc.msacsr & MSACSR_FS_MASK) != 0;
61
62 set_float_rounding_mode(ieee_rm[rounding_mode], status);
63 set_flush_to_zero(flush_to_zero, status);
64 set_flush_inputs_to_zero(flush_to_zero, status);
65}