bpaul-chess

UCI chess engine to replace Omelette Chess Engine
Log | Files | Refs | README | LICENSE

commit 25f5a5d8e5b1f22986782bfa72a779fc215dfefb
parent 6538c57c130b7b9406b9b8a87950132b6af2a645
Author: benjamin paul <bpaul@bpaul.xyz>
Date:   Sun,  8 Aug 2021 12:36:19 +1000

OMG this made an improvement in the perf -e instructions:u test!!

Diffstat:
Msrc/main.c | 39++++++++++++++++++++++++++++++++++++++-
1 file changed, 38 insertions(+), 1 deletion(-)

diff --git a/src/main.c b/src/main.c @@ -5,7 +5,44 @@ #define VERSION "v0.0.1" /* sizeof magically gets the length of the string! (plus \0) */ -#define CMD(s) strncmp(buf, s, sizeof(s)-1) == 0 +#define CMD(s) new_strncmp(buf, s, sizeof(s)-1) == 0 + +/* A modified version of the strncmp code which is somehow faster */ +bool +new_strncmp(const char *s1, const char *s2, unsigned long n) { + int i; + + char c[4]; + + if (n >= 4) { + unsigned long n4 = n >> 2; + do { + for (i = 0; i < 4; i++) { + c[i] = s1[i] - s2[i]; + if (s1[i] == '\0' || c[i] != 0) { + return c[i]; + } + } + + s1+=4; + s2+=4; + + n4--; + } while (n4 > 0); + n &= 3; + } + + while (n > 0) { + c[0] = *s1 - *s2; + if (*s1 == '\0' || c[0] != 0) { + return c[0]; + } + s1++; + s2++; + } + + return c[0]; +} int main() {