native 0.0.1
Vectors, masks and wide register packs for C++26
Loading...
Searching...
No Matches
f16c_control.h
1// SPDX-License-Identifier: BSD-2-Clause OR Apache-2.0
2#pragma once
3#include "native/config.h"
4#include "native/detail/constexpr_float.h"
5#include <hint.h>
6#if NATIVE_HOST_X86
7#include <immintrin.h>
8namespace native::detail::x86_f16c {
9 struct control {
10 constexpr_float::rounding mode;
11 constexpr_float::policy environment;
12 };
13 [[nodiscard]] hint_inline control current_control() noexcept {
14 auto csr = _mm_getcsr();
15 constexpr_float::policy environment{};
16 environment.flush_inputs = (csr & 0x40u) != 0;
17 using r = constexpr_float::rounding;
18 constexpr r modes[]{r::nearest_even, r::downward, r::upward, r::toward_zero};
19 return {modes[(csr >> 13) & 3u], environment};
20 }
21}
22#endif