From 62dcda6bf2e501e5b269b225637e80e7f63389a9 Mon Sep 17 00:00:00 2001 From: Richard Thier Date: Mon, 13 Dec 2021 02:18:08 +0100 Subject: [PATCH] minor tweaks --- magyarsort.h | 8 ++++---- test.cpp | 36 ++++++++++++++++++------------------ 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/magyarsort.h b/magyarsort.h index 9227a94..c157093 100644 --- a/magyarsort.h +++ b/magyarsort.h @@ -62,7 +62,7 @@ namespace MagyarSort { /* HELPERS */ template - static inline uint32_t getDigit(uint32_t num) noexcept { + static inline __attribute__((always_inline)) uint32_t getDigit(uint32_t num) noexcept { static constexpr int SHIFT = DIGIT_CHOICE * BITS_PER_DIGIT; uint32_t shifted = num >> SHIFT; @@ -72,7 +72,7 @@ namespace MagyarSort { /** Recursive Functor: no class should be generated I think (compiler should be smart) */ template struct OccurenceMagic : public OccurenceMagic { - inline OccurenceMagic(uint32_t arr[], size_t i, size_t *radicsOut) noexcept + inline __attribute__((always_inline)) OccurenceMagic(uint32_t arr[], size_t i, size_t *radicsOut) noexcept : OccurenceMagic(arr, i, radicsOut) { // Parents run first so template recursion runs DIGIT=0 first... ++radicsOut[getDigit(arr[i]) + DIGIT_RANGE * DIGIT]; @@ -94,7 +94,7 @@ namespace MagyarSort { /** Recursive Functor: no class should be generated I think (compiler should be smart) */ template struct PrefixMagic : public PrefixMagic { - inline PrefixMagic(size_t *radics, size_t *prev, int i) noexcept + inline __attribute__((always_inline)) PrefixMagic(size_t *radics, size_t *prev, int i) noexcept : PrefixMagic(radics, prev, i) { static constexpr int DSTART = (DIGIT * DIGIT_RANGE); radics[DSTART + i] += prev[DIGIT]; @@ -109,7 +109,7 @@ namespace MagyarSort { /** Gets REFERENCE to the given digit from the radix-array that has more than one digits */ template - static inline size_t &rGet(size_t *radics, size_t i) noexcept { + static inline __attribute__((always_inline)) size_t &rGet(size_t *radics, size_t i) noexcept { static constexpr int DSTART = (DIGIT * DIGIT_RANGE); return radics[DSTART + i]; } diff --git a/test.cpp b/test.cpp index c1880a9..ca3b32b 100644 --- a/test.cpp +++ b/test.cpp @@ -14,7 +14,7 @@ // Uncomment if you want to see output before / after sorts (debugging for example) //#define PRINT_OUTPUT -//#define SKA_SORT +#define SKA_SORT /* Includes */ @@ -87,23 +87,6 @@ int main() { std::vector in1 = GenerateInput();; std::vector in2 = in1; // copy - uint32_t *arr1 = &(in1[0]); - -#ifdef PRINT_OUTPUT - printf("Inp: "); - MagyarSort::debugArr(arr1, in1.size()); -#endif // PRINT_OUTPUT - - /* Our sort */ - auto ourBegin = std::chrono::high_resolution_clock::now(); - MagyarSort::sort(arr1, in1.size()); - auto ourEnd = std::chrono::high_resolution_clock::now(); - -#ifdef PRINT_OUTPUT - printf("Our: "); - MagyarSort::debugArr(arr1, in1.size()); -#endif // PRINT_OUTPUT - auto stdBegin = std::chrono::high_resolution_clock::now(); #ifndef SKA_SORT /* std::sort */ @@ -121,6 +104,23 @@ int main() { MagyarSort::debugArr(&in2[0], in2.size()); #endif // PRINT_OUTPUT + uint32_t *arr1 = &(in1[0]); + +#ifdef PRINT_OUTPUT + printf("Inp: "); + MagyarSort::debugArr(arr1, in1.size()); +#endif // PRINT_OUTPUT + + /* Our sort */ + auto ourBegin = std::chrono::high_resolution_clock::now(); + MagyarSort::sort(arr1, in1.size()); + auto ourEnd = std::chrono::high_resolution_clock::now(); + +#ifdef PRINT_OUTPUT + printf("Our: "); + MagyarSort::debugArr(arr1, in1.size()); +#endif // PRINT_OUTPUT + /* Check against std - the real test */ bool good = true;