Skip to content

Conversation

jhuber6
Copy link
Contributor

@jhuber6 jhuber6 commented Sep 2, 2025

Summary:
Fills out some of the missing fundamental floating point operations.
These just wrap the elementwise builtin of the same name.

Summary:
Fills out some of the missing fundamental floating point operations.
These just wrap the elementwise builtin of the same name.
Copy link
Contributor

@michaelrj-google michaelrj-google left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jhuber6 jhuber6 merged commit 4aeb290 into llvm:main Sep 3, 2025
19 of 20 checks passed
@llvmbot
Copy link
Member

llvmbot commented Sep 3, 2025

@llvm/pr-subscribers-libc

Author: Joseph Huber (jhuber6)

Changes

Summary:
Fills out some of the missing fundamental floating point operations.
These just wrap the elementwise builtin of the same name.


Full diff: https://github.com/llvm/llvm-project/pull/156515.diff

2 Files Affected:

  • (modified) libc/src/__support/CPP/simd.h (+51-2)
  • (modified) libc/src/string/memory_utils/generic/inline_strlen.h (+1)
diff --git a/libc/src/__support/CPP/simd.h b/libc/src/__support/CPP/simd.h
index 972f156419d4d..449455c5c0390 100644
--- a/libc/src/__support/CPP/simd.h
+++ b/libc/src/__support/CPP/simd.h
@@ -15,8 +15,8 @@
 
 #include "hdr/stdint_proxy.h"
 #include "src/__support/CPP/algorithm.h"
-#include "src/__support/CPP/bit.h"
-#include "src/__support/CPP/type_traits/integral_constant.h"
+#include "src/__support/CPP/limits.h"
+#include "src/__support/CPP/type_traits.h"
 #include "src/__support/macros/attributes.h"
 #include "src/__support/macros/config.h"
 
@@ -128,6 +128,55 @@ LIBC_INLINE constexpr simd<T, N> max(simd<T, N> x, simd<T, N> y) {
   return __builtin_elementwise_max(x, y);
 }
 
+template <typename T, size_t N>
+LIBC_INLINE constexpr simd<T, N> abs(simd<T, N> x) {
+  return __builtin_elementwise_abs(x);
+}
+template <typename T, size_t N>
+LIBC_INLINE constexpr simd<T, N> fma(simd<T, N> x, simd<T, N> y, simd<T, N> z) {
+  return __builtin_elementwise_fma(x, y, z);
+}
+template <typename T, size_t N>
+LIBC_INLINE constexpr simd<T, N> ceil(simd<T, N> x) {
+  return __builtin_elementwise_ceil(x);
+}
+template <typename T, size_t N>
+LIBC_INLINE constexpr simd<T, N> floor(simd<T, N> x) {
+  return __builtin_elementwise_floor(x);
+}
+template <typename T, size_t N>
+LIBC_INLINE constexpr simd<T, N> roundeven(simd<T, N> x) {
+  return __builtin_elementwise_roundeven(x);
+}
+template <typename T, size_t N>
+LIBC_INLINE constexpr simd<T, N> round(simd<T, N> x) {
+  return __builtin_elementwise_round(x);
+}
+template <typename T, size_t N>
+LIBC_INLINE constexpr simd<T, N> trunc(simd<T, N> x) {
+  return __builtin_elementwise_trunc(x);
+}
+template <typename T, size_t N>
+LIBC_INLINE constexpr simd<T, N> nearbyint(simd<T, N> x) {
+  return __builtin_elementwise_nearbyint(x);
+}
+template <typename T, size_t N>
+LIBC_INLINE constexpr simd<T, N> rint(simd<T, N> x) {
+  return __builtin_elementwise_rint(x);
+}
+template <typename T, size_t N>
+LIBC_INLINE constexpr simd<T, N> canonicalize(simd<T, N> x) {
+  return __builtin_elementwise_canonicalize(x);
+}
+template <typename T, size_t N>
+LIBC_INLINE constexpr simd<T, N> copysign(simd<T, N> x, simd<T, N> y) {
+  return __builtin_elementwise_copysign(x, y);
+}
+template <typename T, size_t N>
+LIBC_INLINE constexpr simd<T, N> fmod(simd<T, N> x, simd<T, N> y) {
+  return __builtin_elementwise_fmod(x, y);
+}
+
 // Reduction operations.
 template <typename T, size_t N, typename Op = cpp::plus<>>
 LIBC_INLINE constexpr T reduce(simd<T, N> v, Op op = {}) {
diff --git a/libc/src/string/memory_utils/generic/inline_strlen.h b/libc/src/string/memory_utils/generic/inline_strlen.h
index 111da35b85eeb..68fba2afb3a5c 100644
--- a/libc/src/string/memory_utils/generic/inline_strlen.h
+++ b/libc/src/string/memory_utils/generic/inline_strlen.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_LIBC_SRC_STRING_MEMORY_UTILS_GENERIC_INLINE_STRLEN_H
 #define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_GENERIC_INLINE_STRLEN_H
 
+#include "src/__support/CPP/bit.h"
 #include "src/__support/CPP/simd.h"
 #include "src/__support/common.h"
 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants