-
Notifications
You must be signed in to change notification settings - Fork 280
Extend support of batch_cast<...> to upcasting to a type twice as big #1184
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /*************************************************************************** | ||
| * Copyright (c) Johan Mabille, Sylvain Corlay, Wolf Vollprecht and * | ||
| * Martin Renou * | ||
| * Copyright (c) QuantStack * | ||
| * Copyright (c) Serge Guelton * | ||
| * * | ||
| * Distributed under the terms of the BSD 3-Clause License. * | ||
| * * | ||
| * The full license is in the file LICENSE, distributed with this software. * | ||
| ****************************************************************************/ | ||
|
|
||
| #ifndef XSIMD_COMMON_CAST_HPP | ||
| #define XSIMD_COMMON_CAST_HPP | ||
|
|
||
| #include "../../types/xsimd_traits.hpp" | ||
|
|
||
| namespace xsimd | ||
| { | ||
| namespace kernel | ||
| { | ||
| template <class A, class T> | ||
| XSIMD_INLINE std::array<batch<widen_t<T>, A>, 2> widen(batch<T, A> const& x, requires_arch<common>) noexcept | ||
| { | ||
| alignas(A::alignment()) T buffer[batch<T, A>::size]; | ||
| x.store_aligned(&buffer[0]); | ||
|
|
||
| using T_out = widen_t<T>; | ||
| alignas(A::alignment()) T_out out_buffer[batch<T, A>::size]; | ||
| for (size_t i = 0; i < batch<T, A>::size; ++i) | ||
| out_buffer[i] = static_cast<T_out>(buffer[i]); | ||
|
|
||
| return { batch<T_out, A>::load_aligned(&out_buffer[0]), | ||
| batch<T_out, A>::load_aligned(&out_buffer[batch<T_out, A>::size]) }; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
| #endif | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1235,7 +1235,6 @@ namespace xsimd | |
| { | ||
| return cond ? true_br : false_br; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| #endif | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -332,6 +332,38 @@ namespace xsimd | |
|
|
||
| template <class T> | ||
| using mask_type_t = typename mask_type<T>::type; | ||
|
|
||
| namespace detail | ||
| { | ||
| template <typename T> | ||
| struct widen : widen<typename std::make_unsigned<T>::type> | ||
| { | ||
| }; | ||
|
|
||
| template <> | ||
| struct widen<uint32_t> | ||
| { | ||
| using type = uint64_t; | ||
| }; | ||
| template <> | ||
| struct widen<uint16_t> | ||
| { | ||
| using type = uint32_t; | ||
| }; | ||
| template <> | ||
| struct widen<uint8_t> | ||
| { | ||
| using type = uint16_t; | ||
| }; | ||
| template <> | ||
| struct widen<float> | ||
| { | ||
| using type = double; | ||
| }; | ||
|
Comment on lines
+338
to
+362
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think a trait that convert a byte size to a template <>
struct sized_uint<4>
{
using type = uint32_t;
};
...And then use with
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not in favor of this. Then we need |
||
| } | ||
| template <typename T> | ||
| using widen_t = typename detail::widen<T>::type; | ||
|
|
||
| } | ||
|
|
||
| #endif | ||
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.
out_bufferand
out_buffer + batch<T_out, A>::sizeseems clearer to meThere 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 mean doing pointer arithmetic directly instead of using the [] and & operators)