From b97c4d33965659b1ec9b20dec4ce359b78533d04 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Mon, 15 Dec 2014 01:59:53 +0100 Subject: [PATCH] Speed up binloader by ~10-15%. --- binloader.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/binloader.cpp b/binloader.cpp index 115cba6..3877ffc 100644 --- a/binloader.cpp +++ b/binloader.cpp @@ -19,21 +19,25 @@ using namespace std; -static int memcmp_different_len(const void *s1, size_t n1, const void *s2, size_t n2) +static inline int memcmp_different_len(const void *s1, size_t n1, const void *s2, size_t n2) { - int shared_len = min(n1, n2); + size_t shared_len = min(n1, n2); + if (shared_len >= 8) { + uint64_t a1 = *(const uint64_t *)s1; + uint64_t a2 = *(const uint64_t *)s2; + if (a1 != a2) { + a1 = __builtin_bswap64(a1); + a2 = __builtin_bswap64(a2); + return (a1 < a2) ? -1 : 1; + } + } + int s = memcmp(s1, s2, shared_len); if (s != 0) { return s; } - if (n1 < n2) { - return -1; - } else if (n1 > n2) { - return 1; - } else { - return 0; - } + return n2 - n1; } enum Result { WHITE = 0, DRAW, BLACK }; -- 2.39.2