[libc] [llvm] [libc][fenv] Refactor x86 fenv implementations to make it work for various fenv_t. (PR #165015)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 10 13:10:57 PST 2025
================
@@ -0,0 +1,261 @@
+//===-- x87 floating point env manipulation functions -----------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_FPUTIL_X86_64_FENV_X86_COMMON_H
+#define LLVM_LIBC_SRC___SUPPORT_FPUTIL_X86_64_FENV_X86_COMMON_H
+
+#include <stdbool.h>
+
+#include "hdr/stdint_proxy.h"
+#include "hdr/types/fenv_t.h"
+#include "src/__support/macros/attributes.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/architectures.h"
+#include "src/__support/macros/properties/compiler.h"
+#include "src/__support/macros/properties/cpu_features.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace fputil {
+
+namespace internal {
+
+// Default order of floating point exception flags in x87 and mxcsr registers:
+// - Bit 0: Invalid Operations
+// - Bit 1: Denormal
+// - Bit 2: Divide-by-zero
+// - Bit 3: Overflow
+// - Bit 4: Underflow
+// - Bit 5: Inexact
+struct ExceptionFlags {
+ static constexpr uint16_t INVALID_F = 0x1;
+ // Some libcs define __FE_DENORM corresponding to the denormal input
+ // exception and include it in FE_ALL_EXCEPTS. We define and use it to
+ // support compiling against headers provided by such libcs.
+ static constexpr uint16_t DENORMAL_F = 0x2;
+ static constexpr uint16_t DIV_BY_ZERO_F = 0x4;
+ static constexpr uint16_t OVERFLOW_F = 0x8;
+ static constexpr uint16_t UNDERFLOW_F = 0x10;
+ static constexpr uint16_t INEXACT_F = 0x20;
+ static constexpr uint16_t ALL_F =
+ static_cast<uint16_t>(INVALID_F | DENORMAL_F | DIV_BY_ZERO_F |
+ OVERFLOW_F | UNDERFLOW_F | INEXACT_F);
+ static constexpr unsigned MXCSR_EXCEPTION_MASK_BIT_POSITION = 7;
+};
+
+LIBC_INLINE static constexpr bool fenv_exceptions_match_x86() {
+ return (FE_INVALID == ExceptionFlags::INVALID_F) &&
+#ifdef __FE_DENORM
----------------
lntue wrote:
It is a `#define` in musl. Without the `#define`, how can we detect the availability of `__FE_DENORM` enum as in glibc?
https://github.com/llvm/llvm-project/pull/165015
More information about the llvm-commits
mailing list