Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ jobs:
CMAKE_EXTRA_ARGS="$CMAKE_EXTRA_ARGS -DTARGET_ARCH=knm"
fi
if [[ '${{ matrix.sys.flags }}' == 'i386' ]]; then
CXX_FLAGS="$CXX_FLAGS -m32"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

that's so error prone, thanks for fixing this.

CXXFLAGS="$CXXFLAGS -m32"
fi
if [[ '${{ matrix.sys.flags }}' == 'force_no_instr_set' ]]; then
:
Expand All @@ -128,17 +128,19 @@ jobs:
fi

# Cheap way of spotting uninitialized read
CXX_FLAGS="$CXX_FLAGS -ftrivial-auto-var-init=pattern"
if echo 'int main(){}' | $CXX -x c++ -ftrivial-auto-var-init=pattern -fsyntax-only - 2>/dev/null; then
CXXFLAGS="$CXXFLAGS -ftrivial-auto-var-init=pattern"
fi

cmake -B _build \
-DBUILD_TESTS=ON \
-DBUILD_BENCHMARK=ON \
-DBUILD_EXAMPLES=ON \
-DBUILD_ARCHITECTURE_TESTS=OFF \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER=$CC \
-DCMAKE_CXX_COMPILER=$CXX \
$CMAKE_EXTRA_ARGS \
-DCMAKE_CXX_FLAGS='$CXX_FLAGS' \
-DCMAKE_CXX_FLAGS="$CXXFLAGS" \
-G Ninja
- name: Build
run: cmake --build _build
Expand All @@ -161,3 +163,33 @@ jobs:
export XSIMD_TEST_CPU_ASSUME_MANUFACTURER="intel,amd"
./test_xsimd
fi

build-extra:
Comment thread
serge-sans-paille marked this conversation as resolved.
runs-on: ubuntu-latest
name: 'clang 18 - architectures and benchmark'
steps:
- name: Setup compiler
run: |
sudo apt-get update || exit 1
sudo apt-get --no-install-suggests --no-install-recommends install clang-18 || exit 1
echo "CC=clang-18" >> $GITHUB_ENV
echo "CXX=clang++-18" >> $GITHUB_ENV
- name: Checkout xsimd
uses: actions/checkout@v6
- name: Install mamba
uses: mamba-org/setup-micromamba@v2
with:
environment-file: environment.yml
- name: Configure build
run: |
cmake -B _build \
-DBUILD_TESTS=ON \
-DBUILD_ARCHITECTURE_TESTS=ON \
-DBUILD_BENCHMARK=ON \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER=$CC \
-DCMAKE_CXX_COMPILER=$CXX \
-DXSIMD_ENABLE_WERROR=ON \
-G Ninja
- name: Build
run: cmake --build _build
6 changes: 3 additions & 3 deletions include/xsimd/arch/xsimd_avx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1726,12 +1726,12 @@ namespace xsimd
{ return ssub(batch<T, sse4_2>(s), batch<T, sse4_2>(o)); },
self, other);
}
else if (std::is_signed_v<T>)
else if constexpr (std::is_signed_v<T>)
{
auto mask = (other >> (8 * sizeof(T) - 1));
auto other_is_negative = other < batch<T, A>(T(0));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is much more idiomatic

auto self_overflow_branch = min(std::numeric_limits<T>::max() + other, self);
auto self_underflow_branch = max(std::numeric_limits<T>::min() + other, self);
return select(batch_bool<T, A>(mask.data), self_overflow_branch, self_underflow_branch) - other;
return select(other_is_negative, self_overflow_branch, self_underflow_branch) - other;
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions include/xsimd/arch/xsimd_avx512f.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1561,7 +1561,7 @@ namespace xsimd

const uint32_t magic = (0x80 + 0x4000 + 0x200000 + 0x10000000);

unsigned char res = ((data * magic) >> 24) & 0xFF;
unsigned char res = (data * magic) >> 28;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I feel ashamed. But also very proud of that trick ;-)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I tend to write all magic numbers as result of constexpr functions. Mostly because I cannot reverse engineer other people magic numbers 😅

return res;
}
else if constexpr (N == 2)
Expand All @@ -1571,7 +1571,7 @@ namespace xsimd

const uint16_t magic = (0x80 + 0x4000);

unsigned char res = ((data * magic) >> 8) & 0xFF;
unsigned char res = (data * magic) >> 14;
return res;
}
}
Expand Down
4 changes: 4 additions & 0 deletions include/xsimd/arch/xsimd_common_fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ namespace xsimd
XSIMD_INLINE batch<T, A> bitwise_rshift(batch<T, A> const& self, batch<T, A> const& other, requires_arch<common>) noexcept;
template <size_t shift, class A, class T, class = std::enable_if_t<std::is_integral_v<T>>>
XSIMD_INLINE batch<T, A> bitwise_rshift(batch<T, A> const& self, requires_arch<common>) noexcept;
template <class A, class T, class Mask>
XSIMD_INLINE batch<T, A> decr_if(batch<T, A> const& self, Mask const& mask, requires_arch<common>) noexcept;
template <class A, class T, class Mask>
XSIMD_INLINE batch<T, A> incr_if(batch<T, A> const& self, Mask const& mask, requires_arch<common>) noexcept;
template <class A, class T>
XSIMD_INLINE batch_bool<T, A> gt(batch<T, A> const& self, batch<T, A> const& other, requires_arch<common>) noexcept;
template <class A, class T, class = std::enable_if_t<std::is_integral_v<T>>>
Expand Down
5 changes: 4 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,10 @@ if (XSIMD_ENABLE_WERROR)
endif()

add_subdirectory(doc)
add_subdirectory(architectures)
OPTION(BUILD_ARCHITECTURE_TESTS "xsimd compilation tests for various -march targets" ON)
if(BUILD_ARCHITECTURE_TESTS)
add_subdirectory(architectures)
endif()

if(EMULATED_COMPILE_FLAGS)
message(STATUS ${EMULATED_COMPILE_FLAGS})
Expand Down
Loading