tartan_arch/aarch64/
float.rs

1//! Floating-point control and status.
2
3use crate::system_register_access;
4use tartan_bitfield::bitfield;
5use tartan_c_enum::c_enum;
6
7
8bitfield! {
9    /// `FPCR`: Influences floating-point instruction execution.
10    pub struct ControlRegister(u64) {
11        /// `AHP`: Use an alternative format for half-precision floats when converting
12        /// to/from other formats. Otherwise, use the IEEE half-precision format.
13        [26] pub alternative_half_precision_format,
14        /// `DN`: Always use the default encoding for NaN results. Otherwise, use the
15        /// encoding from an input operand.
16        [25] pub default_nan,
17        /// `FZ`: When a result would be denormal, yield zero instead. Otherwise, use the
18        /// IEEE 754 behavior.
19        [24] pub flush_to_zero,
20        /// `RMode`: The IEEE 754 rounding mode in use.
21        [22..24] pub rounding_mode: u8 as RoundingMode,
22        /// `FZ16`: Counterpart to [`flush_to_zero`](Self::flush_to_zero) for
23        /// half-precision calculations.
24        ///
25        /// Requires `FEAT_FP16`.
26        [19] pub flush_to_zero_half_precision,
27        /// For each type of floating-point exception, defines whether the error will be
28        /// trapped. If false, the corresponding flag in [`StatusRegister::exceptions`]
29        /// will be set instead.
30        [ 8..16] pub trapped_exceptions: u8 as Exceptions,
31    }
32}
33
34system_register_access!(ControlRegister, "FPCR");
35
36
37bitfield! {
38    /// `FPSR`: Indicates non-trapped floating-point exceptions.
39    pub struct StatusRegister(u64) {
40        /// Indicates any non-trapped exceptions that have been detected since these flags
41        /// were last reset.
42        [ 0.. 8] pub exceptions: u8 as Exceptions,
43    }
44}
45
46system_register_access!(StatusRegister, "FPSR");
47
48
49c_enum! {
50    /// Floating-point rounding mode, as defined by IEEE 754.
51    pub enum RoundingMode(u8) {
52        /// Round to the nearest number, with ties toward even numbers.
53        Nearest,
54        /// Round toward positive infinity.
55        PlusInfinity,
56        /// Round toward negative infinity.
57        MinusInfinity,
58        /// Round toward zero (truncate).
59        Zero,
60    }
61}
62
63bitfield! {
64    /// Status/mask bits for each type of floating-point exception.
65    pub struct Exceptions(u8) {
66        /// `DN`: An operand was a denormal number.
67        [7] denormal_input,
68        /// `IX`: A result was rounded.
69        [4] inexact,
70        /// `UF`: A result was too small to be represented accurately.
71        [3] underflow,
72        /// `OF`: A result was too large to be represented accurately.
73        [2] overflow,
74        /// `DZ`: Attempted to divide a number by zero (other than zero or infinity, which
75        /// raises an [`invalid_operation`] instead).
76        [1] divide_by_zero,
77        /// `IO`: Attempted a mathematically undefined operation, such as infinity minus
78        /// infinity.
79        [0] invalid_operation,
80    }
81}