Skip to content

Commit

Permalink
Use move and use custom-float in src files
Browse files Browse the repository at this point in the history
  • Loading branch information
r-devulap committed Apr 5, 2024
1 parent 3a69a68 commit 97cb7ec
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 34 deletions.
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ cancompilefp16 = cpp.compiles(fp16code, args:'-march=sapphirerapids')
subdir('lib')
libsimdsort = shared_library('x86simdsortcpp',
'lib/x86simdsort.cpp',
include_directories : [utils, lib],
include_directories : [src, utils, lib],
link_with : [libtargets],
gnu_symbol_visibility : 'inlineshidden',
install : true,
Expand Down
31 changes: 17 additions & 14 deletions src/avx512-16bit-qsort.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,10 +560,11 @@ X86_SIMD_SORT_INLINE_ONLY bool is_a_nan<uint16_t>(uint16_t elem)
return ((elem & 0x7c00u) == 0x7c00u) && ((elem & 0x03ffu) != 0);
}

X86_SIMD_SORT_INLINE void avx512_qsort_fp16(uint16_t *arr,
arrsize_t arrsize,
bool hasnan = false,
bool descending = false)
[[maybe_unused]] X86_SIMD_SORT_INLINE void
avx512_qsort_fp16(uint16_t *arr,
arrsize_t arrsize,
bool hasnan = false,
bool descending = false)
{
using vtype = zmm_vector<float16>;

Expand All @@ -585,11 +586,12 @@ X86_SIMD_SORT_INLINE void avx512_qsort_fp16(uint16_t *arr,
}
}

X86_SIMD_SORT_INLINE void avx512_qselect_fp16(uint16_t *arr,
arrsize_t k,
arrsize_t arrsize,
bool hasnan = false,
bool descending = false)
[[maybe_unused]] X86_SIMD_SORT_INLINE void
avx512_qselect_fp16(uint16_t *arr,
arrsize_t k,
arrsize_t arrsize,
bool hasnan = false,
bool descending = false)
{
using vtype = zmm_vector<float16>;

Expand Down Expand Up @@ -617,11 +619,12 @@ X86_SIMD_SORT_INLINE void avx512_qselect_fp16(uint16_t *arr,
}
}

X86_SIMD_SORT_INLINE void avx512_partial_qsort_fp16(uint16_t *arr,
arrsize_t k,
arrsize_t arrsize,
bool hasnan = false,
bool descending = false)
[[maybe_unused]] X86_SIMD_SORT_INLINE void
avx512_partial_qsort_fp16(uint16_t *arr,
arrsize_t k,
arrsize_t arrsize,
bool hasnan = false,
bool descending = false)
{
avx512_qselect_fp16(arr, k - 1, arrsize, hasnan, descending);
avx512_qsort_fp16(arr, k - 1, descending);
Expand Down
2 changes: 1 addition & 1 deletion src/avx512-64bit-keyvaluesort.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ avx512_qsort_kv(T1 *keys, T2 *indexes, arrsize_t arrsize, bool hasnan = false)
zmm_vector<T2>>::type;

if (arrsize > 1) {
if constexpr (std::is_floating_point_v<T1>) {
if constexpr (xss::fp::is_floating_point_v<T1>) {
arrsize_t nan_count = 0;
if (UNLIKELY(hasnan)) {
nan_count = replace_nan_with_inf<zmm_vector<T1>>(keys, arrsize);
Expand Down
8 changes: 4 additions & 4 deletions src/xss-common-argsort.h
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ avx512_argsort(T *arr, arrsize_t *arg, arrsize_t arrsize, bool hasnan = false)
zmm_vector<arrsize_t>>::type;

if (arrsize > 1) {
if constexpr (std::is_floating_point_v<T>) {
if constexpr (xss::fp::is_floating_point_v<T>) {
if ((hasnan) && (array_has_nan<vectype>(arr, arrsize))) {
std_argsort_withnan(arr, arg, 0, arrsize);
return;
Expand All @@ -580,7 +580,7 @@ avx2_argsort(T *arr, arrsize_t *arg, arrsize_t arrsize, bool hasnan = false)
avx2_half_vector<arrsize_t>,
avx2_vector<arrsize_t>>::type;
if (arrsize > 1) {
if constexpr (std::is_floating_point_v<T>) {
if constexpr (xss::fp::is_floating_point_v<T>) {
if ((hasnan) && (array_has_nan<vectype>(arr, arrsize))) {
std_argsort_withnan(arr, arg, 0, arrsize);
return;
Expand Down Expand Up @@ -611,7 +611,7 @@ X86_SIMD_SORT_INLINE void avx512_argselect(T *arr,
zmm_vector<arrsize_t>>::type;

if (arrsize > 1) {
if constexpr (std::is_floating_point_v<T>) {
if constexpr (xss::fp::is_floating_point_v<T>) {
if ((hasnan) && (array_has_nan<vectype>(arr, arrsize))) {
std_argselect_withnan(arr, arg, k, 0, arrsize);
return;
Expand Down Expand Up @@ -641,7 +641,7 @@ X86_SIMD_SORT_INLINE void avx2_argselect(T *arr,
avx2_vector<arrsize_t>>::type;

if (arrsize > 1) {
if constexpr (std::is_floating_point_v<T>) {
if constexpr (xss::fp::is_floating_point_v<T>) {
if ((hasnan) && (array_has_nan<vectype>(arr, arrsize))) {
std_argselect_withnan(arr, arg, k, 0, arrsize);
return;
Expand Down
1 change: 1 addition & 0 deletions src/xss-common-includes.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <immintrin.h>
#include <limits>
#include <vector>
#include "xss-custom-float.h"

#define X86_SIMD_SORT_INFINITY std::numeric_limits<double>::infinity()
#define X86_SIMD_SORT_INFINITYF std::numeric_limits<float>::infinity()
Expand Down
12 changes: 6 additions & 6 deletions src/xss-common-qsort.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ X86_SIMD_SORT_INLINE void replace_inf_with_nan(type_t *arr,
{
if (descending) {
for (arrsize_t ii = 0; nan_count > 0; ++ii) {
if constexpr (std::is_floating_point_v<type_t>) {
arr[ii] = std::numeric_limits<type_t>::quiet_NaN();
if constexpr (xss::fp::is_floating_point_v<type_t>) {
arr[ii] = xss::fp::quiet_NaN<type_t>();
}
else {
arr[ii] = 0xFFFF;
Expand All @@ -116,8 +116,8 @@ X86_SIMD_SORT_INLINE void replace_inf_with_nan(type_t *arr,
}
else {
for (arrsize_t ii = size - 1; nan_count > 0; --ii) {
if constexpr (std::is_floating_point_v<type_t>) {
arr[ii] = std::numeric_limits<type_t>::quiet_NaN();
if constexpr (xss::fp::is_floating_point_v<type_t>) {
arr[ii] = xss::fp::quiet_NaN<type_t>();
}
else {
arr[ii] = 0xFFFF;
Expand Down Expand Up @@ -619,7 +619,7 @@ X86_SIMD_SORT_INLINE void xss_qsort(T *arr, arrsize_t arrsize, bool hasnan)

if (arrsize > 1) {
arrsize_t nan_count = 0;
if constexpr (std::is_floating_point_v<T>) {
if constexpr (xss::fp::is_floating_point_v<T>) {
if (UNLIKELY(hasnan)) {
nan_count = replace_nan_with_inf<vtype>(arr, arrsize);
}
Expand All @@ -646,7 +646,7 @@ xss_qselect(T *arr, arrsize_t k, arrsize_t arrsize, bool hasnan)
arrsize_t index_first_elem = 0;
arrsize_t index_last_elem = arrsize - 1;

if constexpr (std::is_floating_point_v<T>) {
if constexpr (xss::fp::is_floating_point_v<T>) {
if (UNLIKELY(hasnan)) {
if constexpr (descending) {
index_first_elem = move_nans_to_start_of_array(arr, arrsize);
Expand Down
6 changes: 3 additions & 3 deletions utils/custom-float.h → src/xss-custom-float.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef UTILS_FLOAT
#define UTILS_FLOAT
#ifndef XSS_CUSTOM_FLOAT
#define XSS_CUSTOM_FLOAT
#include <cstdint>
namespace xss {
namespace fp {
Expand Down Expand Up @@ -87,4 +87,4 @@ namespace fp {

} // namespace fp
} // namespace xss
#endif
#endif // XSS_CUSTOM_FLOAT
6 changes: 3 additions & 3 deletions tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ libtests = []
libtests += static_library('tests_qsort',
files('test-qsort.cpp', ),
dependencies: gtest_dep,
include_directories : [lib, utils],
include_directories : [src, lib, utils],
)

libtests += static_library('tests_kvsort',
files('test-keyvalue.cpp', ),
dependencies: gtest_dep,
include_directories : [lib, utils],
include_directories : [src, lib, utils],
)

libtests += static_library('tests_objsort',
files('test-objqsort.cpp', ),
dependencies: gtest_dep,
include_directories : [lib, utils],
include_directories : [src, lib, utils],
)
2 changes: 1 addition & 1 deletion utils/custom-compare.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <limits>
#include <cmath>
#include "custom-float.h"
#include "xss-custom-float.h"

/*
* Custom comparator class to handle NAN's: treats NAN > INF
Expand Down
2 changes: 1 addition & 1 deletion utils/rand_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <type_traits>
#include <vector>
#include <algorithm>
#include "custom-float.h"
#include "xss-custom-float.h"

template <typename T>
static std::vector<T> get_uniform_rand_array(int64_t arrsize,
Expand Down

0 comments on commit 97cb7ec

Please sign in to comment.