-
Notifications
You must be signed in to change notification settings - Fork 14.7k
[libc] Implement wide read strlen with LLVM vector type #152605
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jhuber6
wants to merge
1
commit into
llvm:main
Choose a base branch
from
jhuber6:libc_vector
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+147
−2
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
//===-- Helper functions for SIMD extensions --------------------*- 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_VECTOR_H | ||
#define LLVM_LIBC_SRC___SUPPORT_VECTOR_H | ||
|
||
#include "hdr/stdint_proxy.h" | ||
#include "src/__support/CPP/bit.h" | ||
#include "src/__support/CPP/type_traits.h" | ||
#include "src/__support/common.h" | ||
#include "src/__support/macros/properties/cpu_features.h" | ||
|
||
#include <stddef.h> | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
|
||
static_assert(LIBC_HAS_VECTOR_TYPE, "Compiler does not support vector types."); | ||
|
||
namespace vector { | ||
|
||
template <size_t N> struct BitmaskTy; | ||
template <> struct BitmaskTy<1> { | ||
using type = uint8_t; | ||
}; | ||
template <> struct BitmaskTy<8> { | ||
using type = uint8_t; | ||
}; | ||
template <> struct BitmaskTy<16> { | ||
using type = uint16_t; | ||
}; | ||
template <> struct BitmaskTy<32> { | ||
using type = uint32_t; | ||
}; | ||
template <> struct BitmaskTy<64> { | ||
using type = uint64_t; | ||
}; | ||
|
||
template <typename T> struct SSE2 { | ||
static constexpr size_t WIDTH = 16; | ||
static constexpr size_t NUM_ELEMENTS = WIDTH / sizeof(T); | ||
}; | ||
template <typename T> struct AVX2 { | ||
static constexpr size_t WIDTH = 32; | ||
static constexpr size_t NUM_ELEMENTS = WIDTH / sizeof(T); | ||
}; | ||
template <typename T> struct AVX512 { | ||
static constexpr size_t WIDTH = 64; | ||
static constexpr size_t NUM_ELEMENTS = WIDTH / sizeof(T); | ||
}; | ||
template <typename T> struct Neon { | ||
static constexpr size_t WIDTH = 16; | ||
static constexpr size_t NUM_ELEMENTS = WIDTH / sizeof(T); | ||
}; | ||
|
||
#if defined(LIBC_TARGET_CPU_HAS_AVX512F) | ||
template <typename T> using Platform = AVX512<T>; | ||
#elif defined(LIBC_TARGET_CPU_HAS_AVX2) | ||
template <typename T> using Platform = AVX2<T>; | ||
#elif defined(LIBC_TARGET_CPU_HAS_SSE2) | ||
template <typename T> using Platform = SSE2<T>; | ||
#elif defined(LIBC_TARGET_CPU_HAS_ARM_NEON) | ||
template <typename T> using Platform = Neon<T>; | ||
#endif | ||
|
||
template <typename T, size_t N = Platform<T>::NUM_ELEMENTS> | ||
using Vector = T LIBC_VECTOR_TYPE(N); | ||
|
||
template <typename To, typename From, size_t N> | ||
LIBC_INLINE Vector<To, N> convert(const Vector<From, N> &v) { | ||
return __builtin_convertvector(v, Vector<To, N>); | ||
} | ||
|
||
template <typename T, size_t N> | ||
LIBC_INLINE typename BitmaskTy<N>::type to_bitmask(const Vector<T, N> &v) { | ||
return cpp::bit_cast<typename BitmaskTy<N>::type>(convert<bool, T, N>(v)); | ||
} | ||
} // namespace vector | ||
|
||
} // namespace LIBC_NAMESPACE_DECL | ||
|
||
#endif // LLVM_LIBC_SRC___SUPPORT_VECTOR_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't exactly follow this condition. __has_attribute(ext_vector_type) should be all you need for a "has vector type". I would separate out the profitability concern
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's because clang 15 added support for bool vectors, which is what emits to something optimal here. Before clang 15 it was an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But you aren't using bool vectors? Also this would need to be much more specific and drop the target check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's inside the
get_bitmask
utility, we convert the-1
comparison mask to a bool vector and then bitcast it to a integer mask we usectz
on. Is there a more idiomatic check for bool vectors?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be broken up and commented, this is not a mere "has vector type"