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
17 changes: 14 additions & 3 deletions benchmark/atoi-corpus.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "atoi.h"

#include "zoo/pp/platform.h"
#include <vector>
#include <string>
#include <cstring>
Expand Down Expand Up @@ -119,17 +119,28 @@ struct CorpusStringLength {
}
};


#if ZOO_CONFIGURED_TO_USE_AVX()
#define AVX2_STRLEN_CORPUS_X_LIST \
X(ZOO_AVX, zoo::avx2_strlen)
#else
#define AVX2_STRLEN_CORPUS_X_LIST /* nothing */
Copy link
Owner

Choose a reason for hiding this comment

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

I am going to immediately add cases to this X list, you'll see this was the proper way to encapsulate this.

Do you have "bandwidth" to help me do the equivalent for ARM? basically I can give you a diff patch that enables ARM, and hopefully it'll work, but if it doesn't you could fix it, of course that I will be online to help if you want

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yup, i can add a patch if that helps. also feel free to push to this branch and i can pull and check it and fix errors i face

#endif


#define STRLEN_CORPUS_X_LIST \
X(LIBC_STRLEN, strlen) \
X(ZOO_STRLEN, zoo::c_strLength) \
X(ZOO_NATURAL_STRLEN, zoo::c_strLength_natural) \
X(ZOO_MANUAL_STRLEN, zoo::c_strLength_manualComparison) \
X(ZOO_AVX, zoo::avx2_strlen) \
X(GENERIC_GLIBC_STRLEN, STRLEN_old)
X(GENERIC_GLIBC_STRLEN, STRLEN_old) \
AVX2_STRLEN_CORPUS_X_LIST


#define X(Typename, FunctionToCall) \
struct Invoke##Typename { int operator()(const char *p) { return FunctionToCall(p); } };

PARSE8BYTES_CORPUS_X_LIST
STRLEN_CORPUS_X_LIST

#undef X
4 changes: 4 additions & 0 deletions benchmark/atoi.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include "zoo/swar/SWAR.h"
#include "zoo/swar/associative_iteration.h"

#if ZOO_CONFIGURED_TO_USE_AVX
#include <immintrin.h>
#endif

#include <stdint.h>
#include <string.h>
Expand Down Expand Up @@ -117,6 +119,7 @@ std::size_t c_strLength_manualComparison(const char *s) {
}
}

#if ZOO_CONFIGURED_TO_USE_AVX
size_t avx2_strlen(const char* str) {
const __m256i zero = _mm256_setzero_si256(); // Vector of 32 zero bytes
size_t offset = 0;
Expand All @@ -140,6 +143,7 @@ size_t avx2_strlen(const char* str) {
// Unreachable, but included to avoid compiler warnings
return offset;
}
#endif

}

Expand Down
3 changes: 3 additions & 0 deletions benchmark/atoi.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ namespace zoo {
std::size_t c_strLength(const char *s);
std::size_t c_strLength_natural(const char *s);
std::size_t c_strLength_manualComparison(const char *s);

#if ZOO_CONFIGURED_TO_USE_AVX
std::size_t avx2_strlen(const char* str);
#endif

}

Expand Down
2 changes: 2 additions & 0 deletions benchmark/catch2swar-demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ TEST_CASE("Atoi benchmarks", "[atoi][swar]") {
REQUIRE(fromLIBC_STRLEN == fromZOO_NATURAL_STRLEN);
REQUIRE(fromZOO_NATURAL_STRLEN == fromZOO_MANUAL_STRLEN);
REQUIRE(fromGENERIC_GLIBC_STRLEN == fromZOO_NATURAL_STRLEN);
#if ZOO_CONFIGURED_TO_USE_AVX()
REQUIRE(fromZOO_AVX == fromZOO_STRLEN);
#endif

auto haveTheRoleOfMemoryBarrier = -1;
#define X(Type, Fun) \
Expand Down
10 changes: 6 additions & 4 deletions inc/zoo/pp/platform.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
#ifndef ZOO_PLATFORM_MACROS_H
#define ZOO_PLATFORM_MACROS_H

#ifdef _MSC_VER
#ifdef __AVX2__
#define ZOO_CONFIGURED_TO_USE_AVX() 1
#else
#define ZOO_CONFIGURED_TO_USE_AVX() 0
#endif

#ifdef _MSC_VER
#define MSVC_EMPTY_BASES __declspec(empty_bases)

#else

#define MSVC_EMPTY_BASES

#endif

#endif