From 6afcc370edbd77d494fc6378a20de0023be6981f Mon Sep 17 00:00:00 2001 From: IrgendwerA8 Date: Sat, 25 Feb 2017 20:19:34 +0100 Subject: [PATCH 1/7] Optimization of two string functions (size & speed). --- libsrc/common/strcat.s | 48 ++++++++------------ libsrc/common/strchr.s | 47 ++++++++++--------- testcode/lib/strcat-test.c | 93 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 136 insertions(+), 52 deletions(-) create mode 100644 testcode/lib/strcat-test.c diff --git a/libsrc/common/strcat.s b/libsrc/common/strcat.s index 7784d89f7..279bfe65b 100644 --- a/libsrc/common/strcat.s +++ b/libsrc/common/strcat.s @@ -1,5 +1,6 @@ ; ; Ullrich von Bassewitz, 31.05.1998 +; Christian Krueger: 2013-Jul-24, minor optimization ; ; char* strcat (char* dest, const char* src); ; @@ -12,44 +13,35 @@ _strcat: sta ptr1 ; Save src stx ptr1+1 jsr popax ; Get dest - sta ptr2 - stx ptr2+1 sta tmp3 ; Remember for function return - ldy #0 + tay + lda #0 + sta ptr2 ; access from page start, y contains low byte + stx ptr2+1 -; find end of dest - -sc1: lda (ptr2),y - beq sc2 +findEndOfDest: + lda (ptr2),y + beq endOfDestFound iny - bne sc1 + bne findEndOfDest inc ptr2+1 - bne sc1 + bne findEndOfDest -; end found, get offset in y into pointer +endOfDestFound: + sty ptr2 ; advance pointer to last y position + ldy #0 ; reset new y-offset -sc2: tya - clc - adc ptr2 - sta ptr2 - bcc sc3 - inc ptr2+1 - -; copy src - -sc3: ldy #0 -sc4: lda (ptr1),y +copyByte: + lda (ptr1),y sta (ptr2),y - beq sc5 + beq done iny - bne sc4 + bne copyByte inc ptr1+1 inc ptr2+1 - bne sc4 + bne copyByte ; like bra here -; done, return pointer to dest - -sc5: lda tmp3 ; X does still contain high byte +; return pointer to dest +done: lda tmp3 ; X does still contain high byte rts - diff --git a/libsrc/common/strchr.s b/libsrc/common/strchr.s index 308381b06..0bd55d0e1 100644 --- a/libsrc/common/strchr.s +++ b/libsrc/common/strchr.s @@ -1,5 +1,6 @@ ; ; Ullrich von Bassewitz, 31.05.1998 +; Christian Krueger, 2013-Aug-04, minor optimization ; ; const char* strchr (const char* s, int c); ; @@ -9,40 +10,38 @@ .importzp ptr1, tmp1 _strchr: - sta tmp1 ; Save c - jsr popax ; get s - sta ptr1 - stx ptr1+1 - ldy #0 + sta tmp1 ; Save c + jsr popax ; get s + tay ; low byte of pointer to y + stx ptr1+1 + lda #0 + sta ptr1 ; ptr access page wise -Loop: lda (ptr1),y ; Get next char - beq EOS ; Jump on end of string - cmp tmp1 ; Found? - beq Found ; Jump if yes +Loop: lda (ptr1),y ; Get next char + beq EOS ; Jump on end of string + cmp tmp1 ; Found? + beq Found ; Jump if yes iny - bne Loop - inc ptr1+1 - bne Loop ; Branch always + bne Loop + inc ptr1+1 + bne Loop ; Branch always ; End of string. Check if we're searching for the terminating zero -EOS: lda tmp1 ; Get the char we're searching for - bne NotFound ; Jump if not searching for terminator +EOS: + lda tmp1 ; Get the char we're searching for + bne NotFound ; Jump if not searching for terminator -; Found. Calculate pointer to c. +; Found. Set pointer to c. -Found: ldx ptr1+1 ; Load high byte of pointer - tya ; Low byte offset - clc - adc ptr1 - bcc Found1 - inx -Found1: rts +Found: + ldx ptr1+1 ; Load high byte of pointer + tya ; low byte is in y + rts ; Not found, return NULL NotFound: - lda #0 + lda #0 tax rts - diff --git a/testcode/lib/strcat-test.c b/testcode/lib/strcat-test.c new file mode 100644 index 000000000..edd614fc4 --- /dev/null +++ b/testcode/lib/strcat-test.c @@ -0,0 +1,93 @@ +#include +#include +#include + +#define SourceStringSize 257 // test correct page passing (>256) + +static char SourceString[SourceStringSize+1]; // +1 room for terminating null +static char DestinationString[2*SourceStringSize+1]; // will contain two times the source buffer + + +int main (void) +{ + unsigned i,j; + char* p; + + /* Print a header */ + printf ("strcat(): "); + + for (i=0; i < SourceStringSize; ++i) + SourceString[i] = (i%128)+1; + + SourceString[i] = 0; + + if (strlen(SourceString) != SourceStringSize) + { + printf ("Fail: Source string initialization or 'strlen()' problem!\n"); + printf ("Expected length: %u but is %u!\n", SourceStringSize, strlen(SourceString)); + exit (EXIT_FAILURE); + } + + /* Ensure empty destination string */ + DestinationString[0] = 0; + + if (strlen(DestinationString) != 0) + { + printf ("Fail: Destination string initialization or 'strlen()' problem!\n"); + printf ("Expected length: %u but is %u!\n", 0, strlen(DestinationString)); + exit (EXIT_FAILURE); + } + + /* Test concatenation to empty buffer */ + + p = strcat(DestinationString, SourceString); + + if (strlen(DestinationString) != SourceStringSize) + { + printf ("Fail: String concatenation to empty buffer!\n"); + printf ("Expected length: %u but is %u!\n", SourceStringSize, strlen(DestinationString)); + exit (EXIT_FAILURE); + } + + /* Test concatenation to non empty buffer */ + + p = strcat(DestinationString, SourceString); + + if (strlen(DestinationString) != 2*SourceStringSize) + { + printf ("Fail: String concatenation to non-empty buffer!\n"); + printf ("Expected length: %u but is %u!\n", 2*SourceStringSize, strlen(DestinationString)); + exit (EXIT_FAILURE); + } + + /* Test return value */ + + if (p != DestinationString) + { + printf ("Invalid return value!\n"); + exit (EXIT_FAILURE); + } + + /* Test contents */ + + for(j=0; j <2; ++j) + for(i=0; i < SourceStringSize; ++i) + { + unsigned position = j*SourceStringSize+i; + unsigned current = DestinationString[position]; + unsigned expected = (i%128)+1; + if (current != expected) + { + printf ("Fail: Unexpected destination buffer contents at position %u!\n", position); + printf ("Expected %u, but is %u!\n", expected, current); + exit (EXIT_FAILURE); + } + } + + /* Test passed */ + printf ("Passed\n"); + return EXIT_SUCCESS; +} + + + From c240d42a9e36f565f03d00eab80b9a2c5aa99ae3 Mon Sep 17 00:00:00 2001 From: IrgendwerA8 Date: Sun, 26 Feb 2017 20:03:05 +0100 Subject: [PATCH 2/7] Added "strrchr" optimizaion a matching unit test and tiny unit test framework. (Documentation for that will follow later) --- include/unittest.h | 89 +++++++++++++++++++++++++++++++++++++ libsrc/common/strrchr.s | 58 +++++++++++------------- testcode/lib/strcat-test.c | 65 ++++++--------------------- testcode/lib/strrchr-test.c | 38 ++++++++++++++++ 4 files changed, 167 insertions(+), 83 deletions(-) create mode 100644 include/unittest.h create mode 100644 testcode/lib/strrchr-test.c diff --git a/include/unittest.h b/include/unittest.h new file mode 100644 index 000000000..a58bbb937 --- /dev/null +++ b/include/unittest.h @@ -0,0 +1,89 @@ +/*****************************************************************************/ +/* */ +/* unittest.h */ +/* */ +/* Unit test helper macros */ +/* */ +/* */ +/* */ +/* (C) 2017 Christian Krueger */ +/* */ +/* This software is provided 'as-is', without any expressed or implied */ +/* warranty. In no event will the authors be held liable for any damages */ +/* arising from the use of this software. */ +/* */ +/* Permission is granted to anyone to use this software for any purpose, */ +/* including commercial applications, and to alter it and redistribute it */ +/* freely, subject to the following restrictions: */ +/* */ +/* 1. The origin of this software must not be misrepresented; you must not */ +/* claim that you wrote the original software. If you use this software */ +/* in a product, an acknowledgment in the product documentation would be */ +/* appreciated but is not required. */ +/* 2. Altered source versions must be plainly marked as such, and must not */ +/* be misrepresented as being the original software. */ +/* 3. This notice may not be removed or altered from any source */ +/* distribution. */ +/* */ +/*****************************************************************************/ + +#ifndef _UNITTEST_H +#define _UNITTEST_H + +#include +#include + +#ifndef COMMA +#define COMMA , +#endif + +#define TEST int main(void) \ + {\ + printf("%s: ",__FILE__); + +#define ENDTEST printf("Passed\n"); \ + return EXIT_SUCCESS; \ + } + +#define ASSERT_IsTrue(a,b) if (!(a)) \ + {\ + printf("Fail at line %d:\n",__LINE__);\ + printf(b);\ + printf("\n");\ + printf("Expected status should be true but wasn't!\n");\ + exit(EXIT_FAILURE);\ + } + +#define ASSERT_IsFalse(a,b) if ((a)) \ + {\ + printf("Fail at line %d:\n",__LINE__);\ + printf(b);\ + printf("\n");\ + printf("Expected status should be false but wasn't!\n");\ + exit(EXIT_FAILURE);\ + } + +#define ASSERT_AreEqual(a,b,c,d) if ((a) != (b)) \ + {\ + printf("Fail at line %d:\n",__LINE__);\ + printf(d);\ + printf("\n");\ + printf("Expected value: "c", but is "c"!\n", (a), (b));\ + exit(EXIT_FAILURE);\ + } + +#define ASSERT_AreNotEqual(a,b,c,d) if ((a) == (b)) \ + {\ + printf("Fail at line %d:\n",__LINE__);\ + printf(d);\ + printf("\n");\ + printf("Expected value not: "c", but is "c"!\n", (a), (b));\ + exit(EXIT_FAILURE);\ + } + +/* End of unittest.h */ +#endif + + + + diff --git a/libsrc/common/strrchr.s b/libsrc/common/strrchr.s index bd7389e76..3e4fb0810 100644 --- a/libsrc/common/strrchr.s +++ b/libsrc/common/strrchr.s @@ -1,47 +1,41 @@ ; ; Ullrich von Bassewitz, 31.05.1998 +; Christian Krueger: 2013-Aug-01, optimization ; ; char* strrchr (const char* s, int c); ; .export _strrchr .import popax - .importzp ptr1, ptr2, tmp1 + .importzp ptr1, tmp1, tmp2 _strrchr: - sta tmp1 ; Save c - jsr popax ; get s - sta ptr1 - stx ptr1+1 - lda #0 ; function result = NULL - sta ptr2 - sta ptr2+1 - tay + sta tmp1 ; Save c + jsr popax ; get s + tay ; low byte to y + stx ptr1+1 + ldx #0 ; default function result is NULL, X is high byte... + stx tmp2 ; tmp2 is low-byte + stx ptr1 ; low-byte of source string is in Y, so clear real one... + +testChar: + lda (ptr1),y ; get char + beq finished ; jump if end of string + cmp tmp1 ; found? + bne nextChar ; jump if no -L1: lda (ptr1),y ; get next char - beq L3 ; jump if end of string - cmp tmp1 ; found? - bne L2 ; jump if no +charFound: + sty tmp2 ; y has low byte of location, save it + ldx ptr1+1 ; x holds high-byte of result -; Remember a pointer to the character +nextChar: + iny + bne testChar + inc ptr1+1 + bne testChar ; here like bra... - tya - clc - adc ptr1 - sta ptr2 - lda ptr1+1 - adc #$00 - sta ptr2+1 +; return the pointer to the last occurrence -; Next char - -L2: iny - bne L1 - inc ptr1+1 - bne L1 ; jump always - -; Return the pointer to the last occurrence - -L3: lda ptr2 - ldx ptr2+1 +finished: + lda tmp2 ; high byte in X is already correct... rts diff --git a/testcode/lib/strcat-test.c b/testcode/lib/strcat-test.c index edd614fc4..fdc987288 100644 --- a/testcode/lib/strcat-test.c +++ b/testcode/lib/strcat-test.c @@ -1,5 +1,4 @@ -#include -#include +#include #include #define SourceStringSize 257 // test correct page passing (>256) @@ -8,65 +7,38 @@ static char SourceString[SourceStringSize+1]; // +1 room for terminating null static char DestinationString[2*SourceStringSize+1]; // will contain two times the source buffer -int main (void) +TEST { unsigned i,j; char* p; - - /* Print a header */ - printf ("strcat(): "); - + for (i=0; i < SourceStringSize; ++i) SourceString[i] = (i%128)+1; SourceString[i] = 0; - if (strlen(SourceString) != SourceStringSize) - { - printf ("Fail: Source string initialization or 'strlen()' problem!\n"); - printf ("Expected length: %u but is %u!\n", SourceStringSize, strlen(SourceString)); - exit (EXIT_FAILURE); - } + ASSERT_AreEqual(SourceStringSize, strlen(SourceString), "%u", "Source string initialization or 'strlen()' problem!"); /* Ensure empty destination string */ DestinationString[0] = 0; - if (strlen(DestinationString) != 0) - { - printf ("Fail: Destination string initialization or 'strlen()' problem!\n"); - printf ("Expected length: %u but is %u!\n", 0, strlen(DestinationString)); - exit (EXIT_FAILURE); - } - + ASSERT_AreEqual(0, strlen(DestinationString), "%u", "Destination string initialization or 'strlen()' problem!"); + /* Test concatenation to empty buffer */ - p = strcat(DestinationString, SourceString); - - if (strlen(DestinationString) != SourceStringSize) - { - printf ("Fail: String concatenation to empty buffer!\n"); - printf ("Expected length: %u but is %u!\n", SourceStringSize, strlen(DestinationString)); - exit (EXIT_FAILURE); - } - + strcat(DestinationString, SourceString); + + ASSERT_AreEqual(SourceStringSize, strlen(DestinationString), "%u", "Unexpected string length while string concatenation to empty buffer!"); + /* Test concatenation to non empty buffer */ p = strcat(DestinationString, SourceString); - if (strlen(DestinationString) != 2*SourceStringSize) - { - printf ("Fail: String concatenation to non-empty buffer!\n"); - printf ("Expected length: %u but is %u!\n", 2*SourceStringSize, strlen(DestinationString)); - exit (EXIT_FAILURE); - } + ASSERT_AreEqual(2*SourceStringSize, strlen(DestinationString), "%u", "Unexpected string length while string concatenation to non-empty buffer!"); /* Test return value */ - if (p != DestinationString) - { - printf ("Invalid return value!\n"); - exit (EXIT_FAILURE); - } + ASSERT_IsTrue(p == DestinationString,"Invalid return value!"); /* Test contents */ @@ -76,18 +48,9 @@ int main (void) unsigned position = j*SourceStringSize+i; unsigned current = DestinationString[position]; unsigned expected = (i%128)+1; - if (current != expected) - { - printf ("Fail: Unexpected destination buffer contents at position %u!\n", position); - printf ("Expected %u, but is %u!\n", expected, current); - exit (EXIT_FAILURE); - } + ASSERT_AreEqual(expected, current, "%u", "Unexpected destination buffer contents at position %u!\n" COMMA position); } - - /* Test passed */ - printf ("Passed\n"); - return EXIT_SUCCESS; } - +ENDTEST diff --git a/testcode/lib/strrchr-test.c b/testcode/lib/strrchr-test.c new file mode 100644 index 000000000..9c1c70032 --- /dev/null +++ b/testcode/lib/strrchr-test.c @@ -0,0 +1,38 @@ +#include +#include + +static char TestString[] = "01234567890123456789"; // two times the same string +static char Found[256]; + +TEST +{ + unsigned len; + unsigned i; + char* p; + + len = strlen(TestString)/2; // test only one half of the string, to find last appearance + + /* Search for all characters in the string, including the terminator */ + for (i = 0; i < len; ++i) + { + /* Search for this char */ + p = strrchr (TestString, TestString[i]); + ASSERT_AreEqual(i+len, p-TestString, "%u", "Unexpected location of character '%c' found!" COMMA TestString[i]); + + /* Mark the char as checked */ + Found[TestString[i]] = 1; + } + + /* Search for all other characters and make sure they aren't found */ + for (i = 0; i < 256; ++i) + { + if (!Found[i]) + { + p = strrchr (TestString, i); + ASSERT_IsFalse(p, "Unexpected location of character '%c' found!" COMMA TestString[i]); + } + } +} +ENDTEST + + From 3d28f5ca9089bd7f16ce77efeba0c66752932a07 Mon Sep 17 00:00:00 2001 From: IrgendwerA8 Date: Sun, 26 Feb 2017 22:36:19 +0100 Subject: [PATCH 3/7] Fixed indentation --- include/unittest.h | 78 ++++++++++++++++++------------------- libsrc/common/strcat.s | 47 +++++++++++----------- testcode/lib/strcat-test.c | 4 +- testcode/lib/strrchr-test.c | 4 +- 4 files changed, 66 insertions(+), 67 deletions(-) diff --git a/include/unittest.h b/include/unittest.h index a58bbb937..bd355bb0c 100644 --- a/include/unittest.h +++ b/include/unittest.h @@ -6,7 +6,7 @@ /* */ /* */ /* */ -/* (C) 2017 Christian Krueger */ +/* (C) 2017 Christian Krueger */ /* */ /* This software is provided 'as-is', without any expressed or implied */ /* warranty. In no event will the authors be held liable for any damages */ @@ -37,49 +37,49 @@ #define COMMA , #endif -#define TEST int main(void) \ - {\ - printf("%s: ",__FILE__); +#define TEST int main(void) \ + {\ + printf("%s: ",__FILE__); -#define ENDTEST printf("Passed\n"); \ - return EXIT_SUCCESS; \ - } +#define ENDTEST printf("Passed\n"); \ + return EXIT_SUCCESS; \ + } -#define ASSERT_IsTrue(a,b) if (!(a)) \ - {\ - printf("Fail at line %d:\n",__LINE__);\ - printf(b);\ - printf("\n");\ - printf("Expected status should be true but wasn't!\n");\ - exit(EXIT_FAILURE);\ - } +#define ASSERT_IsTrue(a,b) if (!(a)) \ + {\ + printf("Fail at line %d:\n",__LINE__);\ + printf(b);\ + printf("\n");\ + printf("Expected status should be true but wasn't!\n");\ + exit(EXIT_FAILURE);\ + } -#define ASSERT_IsFalse(a,b) if ((a)) \ - {\ - printf("Fail at line %d:\n",__LINE__);\ - printf(b);\ - printf("\n");\ - printf("Expected status should be false but wasn't!\n");\ - exit(EXIT_FAILURE);\ - } +#define ASSERT_IsFalse(a,b) if ((a)) \ + {\ + printf("Fail at line %d:\n",__LINE__);\ + printf(b);\ + printf("\n");\ + printf("Expected status should be false but wasn't!\n");\ + exit(EXIT_FAILURE);\ + } -#define ASSERT_AreEqual(a,b,c,d) if ((a) != (b)) \ - {\ - printf("Fail at line %d:\n",__LINE__);\ - printf(d);\ - printf("\n");\ - printf("Expected value: "c", but is "c"!\n", (a), (b));\ - exit(EXIT_FAILURE);\ - } +#define ASSERT_AreEqual(a,b,c,d) if ((a) != (b)) \ + {\ + printf("Fail at line %d:\n",__LINE__);\ + printf(d);\ + printf("\n");\ + printf("Expected value: "c", but is "c"!\n", (a), (b));\ + exit(EXIT_FAILURE);\ + } -#define ASSERT_AreNotEqual(a,b,c,d) if ((a) == (b)) \ - {\ - printf("Fail at line %d:\n",__LINE__);\ - printf(d);\ - printf("\n");\ - printf("Expected value not: "c", but is "c"!\n", (a), (b));\ - exit(EXIT_FAILURE);\ - } +#define ASSERT_AreNotEqual(a,b,c,d) if ((a) == (b)) \ + {\ + printf("Fail at line %d:\n",__LINE__);\ + printf(d);\ + printf("\n");\ + printf("Expected value not: "c", but is "c"!\n", (a), (b));\ + exit(EXIT_FAILURE);\ + } /* End of unittest.h */ #endif diff --git a/libsrc/common/strcat.s b/libsrc/common/strcat.s index 279bfe65b..9be65386f 100644 --- a/libsrc/common/strcat.s +++ b/libsrc/common/strcat.s @@ -10,38 +10,37 @@ .importzp ptr1, ptr2, tmp3 _strcat: - sta ptr1 ; Save src - stx ptr1+1 - jsr popax ; Get dest - sta tmp3 ; Remember for function return - tay - lda #0 - sta ptr2 ; access from page start, y contains low byte - stx ptr2+1 + sta ptr1 ; Save src + stx ptr1+1 + jsr popax ; Get dest + sta tmp3 ; Remember for function return + tay + lda #0 + sta ptr2 ; access from page start, y contains low byte + stx ptr2+1 findEndOfDest: - lda (ptr2),y - beq endOfDestFound + lda (ptr2),y + beq endOfDestFound iny - bne findEndOfDest - inc ptr2+1 - bne findEndOfDest + bne findEndOfDest + inc ptr2+1 + bne findEndOfDest endOfDestFound: - sty ptr2 ; advance pointer to last y position - ldy #0 ; reset new y-offset + sty ptr2 ; advance pointer to last y position + ldy #0 ; reset new y-offset copyByte: - lda (ptr1),y - sta (ptr2),y - beq done + lda (ptr1),y + sta (ptr2),y + beq done iny - bne copyByte - inc ptr1+1 - inc ptr2+1 - bne copyByte ; like bra here + bne copyByte + inc ptr1+1 + inc ptr2+1 + bne copyByte ; like bra here ; return pointer to dest -done: lda tmp3 ; X does still contain high byte +done: lda tmp3 ; X does still contain high byte rts - diff --git a/testcode/lib/strcat-test.c b/testcode/lib/strcat-test.c index fdc987288..2e00b80cb 100644 --- a/testcode/lib/strcat-test.c +++ b/testcode/lib/strcat-test.c @@ -3,7 +3,7 @@ #define SourceStringSize 257 // test correct page passing (>256) -static char SourceString[SourceStringSize+1]; // +1 room for terminating null +static char SourceString[SourceStringSize+1]; // +1 room for terminating null static char DestinationString[2*SourceStringSize+1]; // will contain two times the source buffer @@ -48,7 +48,7 @@ TEST unsigned position = j*SourceStringSize+i; unsigned current = DestinationString[position]; unsigned expected = (i%128)+1; - ASSERT_AreEqual(expected, current, "%u", "Unexpected destination buffer contents at position %u!\n" COMMA position); + ASSERT_AreEqual(expected, current, "%u", "Unexpected destination buffer contents at position %u!\n" COMMA position); } } ENDTEST diff --git a/testcode/lib/strrchr-test.c b/testcode/lib/strrchr-test.c index 9c1c70032..d2c2a20e4 100644 --- a/testcode/lib/strrchr-test.c +++ b/testcode/lib/strrchr-test.c @@ -1,7 +1,7 @@ #include #include -static char TestString[] = "01234567890123456789"; // two times the same string +static char TestString[] = "01234567890123456789"; // two times the same string static char Found[256]; TEST @@ -10,7 +10,7 @@ TEST unsigned i; char* p; - len = strlen(TestString)/2; // test only one half of the string, to find last appearance + len = strlen(TestString)/2; // test only one half of the string, to find last appearance /* Search for all characters in the string, including the terminator */ for (i = 0; i < len; ++i) From 09de875330a4ca5eeabf91a21e774758c1de4417 Mon Sep 17 00:00:00 2001 From: IrgendwerA8 Date: Tue, 28 Feb 2017 08:05:11 +0100 Subject: [PATCH 4/7] Changed the location of unittest.h --- testcode/lib/strcat-test.c | 2 +- testcode/lib/strrchr-test.c | 2 +- {include => testcode/lib}/unittest.h | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename {include => testcode/lib}/unittest.h (100%) diff --git a/testcode/lib/strcat-test.c b/testcode/lib/strcat-test.c index 2e00b80cb..58119e27a 100644 --- a/testcode/lib/strcat-test.c +++ b/testcode/lib/strcat-test.c @@ -1,5 +1,5 @@ -#include #include +#include "unittest.h" #define SourceStringSize 257 // test correct page passing (>256) diff --git a/testcode/lib/strrchr-test.c b/testcode/lib/strrchr-test.c index d2c2a20e4..a72c44db9 100644 --- a/testcode/lib/strrchr-test.c +++ b/testcode/lib/strrchr-test.c @@ -1,5 +1,5 @@ -#include #include +#include "unittest.h" static char TestString[] = "01234567890123456789"; // two times the same string static char Found[256]; diff --git a/include/unittest.h b/testcode/lib/unittest.h similarity index 100% rename from include/unittest.h rename to testcode/lib/unittest.h From 81115aa82625f2b7e773b29844a3a7af589cdb95 Mon Sep 17 00:00:00 2001 From: IrgendwerA8 Date: Sun, 5 Mar 2017 02:09:12 +0100 Subject: [PATCH 5/7] Added further optimizations and unit tests. --- libsrc/common/memmove.s | 11 +-- libsrc/common/strcat.s | 6 +- libsrc/common/strchr.s | 6 +- libsrc/common/strcspn.s | 78 +++++++-------- libsrc/common/strlen.s | 5 +- libsrc/common/strncat.s | 96 ++++++++++--------- libsrc/common/strspn.s | 80 ++++++++-------- libsrc/runtime/axlong.s | 16 ++-- test/val/{atoi-test.c => lib_common_atoi.c} | 0 test/val/lib_common_memmove.c | 61 ++++++++++++ .../val/lib_common_strcat.c | 2 - .../val/lib_common_strchr.c | 39 +++----- test/val/lib_common_strcspn.c | 26 +++++ test/val/lib_common_strncat.c | 54 +++++++++++ .../val/{strtol-test.c => lib_common_strol.c} | 0 .../val/lib_common_strrchr.c | 0 test/val/lib_common_strspn.c | 24 +++++ .../{strtoul-test.c => lib_common_strtoul.c} | 0 {testcode/lib => test/val}/unittest.h | 0 19 files changed, 327 insertions(+), 177 deletions(-) rename test/val/{atoi-test.c => lib_common_atoi.c} (100%) create mode 100644 test/val/lib_common_memmove.c rename testcode/lib/strcat-test.c => test/val/lib_common_strcat.c (99%) rename testcode/lib/strchr-test.c => test/val/lib_common_strchr.c (50%) create mode 100644 test/val/lib_common_strcspn.c create mode 100644 test/val/lib_common_strncat.c rename test/val/{strtol-test.c => lib_common_strol.c} (100%) rename testcode/lib/strrchr-test.c => test/val/lib_common_strrchr.c (100%) create mode 100644 test/val/lib_common_strspn.c rename test/val/{strtoul-test.c => lib_common_strtoul.c} (100%) rename {testcode/lib => test/val}/unittest.h (100%) diff --git a/libsrc/common/memmove.s b/libsrc/common/memmove.s index 9c33124f1..666447cd8 100644 --- a/libsrc/common/memmove.s +++ b/libsrc/common/memmove.s @@ -1,6 +1,6 @@ ; ; 2003-08-20, Ullrich von Bassewitz -; 2009-09-13, Christian Krueger -- performance increase (about 20%) +; 2009-09-13, Christian Krueger -- performance increase (about 20%), 2013-07-25 improved unrolling ; 2015-10-23, Greg King ; ; void* __fastcall__ memmove (void* dest, const void* src, size_t size); @@ -61,13 +61,10 @@ PageSizeCopy: ; assert Y = 0 dec ptr1+1 ; adjust base... dec ptr2+1 dey ; in entry case: 0 -> FF - lda (ptr1),y ; need to copy this 'intro byte' - sta (ptr2),y ; to 'land' later on Y=0! (as a result of the '.repeat'-block!) - dey ; FF ->FE @copyBytes: - .repeat 2 ; Unroll this a bit to make it faster... - lda (ptr1),y - sta (ptr2),y + .repeat 3 ; unroll this a bit to make it faster... + lda (ptr1),y ; important: unrolling three times gives a nice + sta (ptr2),y ; 255/3 = 85 loop which ends at 0 dey .endrepeat @copyEntry: ; in entry case: 0 -> FF diff --git a/libsrc/common/strcat.s b/libsrc/common/strcat.s index 9be65386f..74fef0759 100644 --- a/libsrc/common/strcat.s +++ b/libsrc/common/strcat.s @@ -1,6 +1,6 @@ ; ; Ullrich von Bassewitz, 31.05.1998 -; Christian Krueger: 2013-Jul-24, minor optimization +; Christian Krueger: 2013-Jul-24, minor optimizations ; ; char* strcat (char* dest, const char* src); ; @@ -15,8 +15,12 @@ _strcat: jsr popax ; Get dest sta tmp3 ; Remember for function return tay +.if (.cpu .bitand ::CPU_ISET_65SC02) + stz ptr2 +.else lda #0 sta ptr2 ; access from page start, y contains low byte +.endif stx ptr2+1 findEndOfDest: diff --git a/libsrc/common/strchr.s b/libsrc/common/strchr.s index 0bd55d0e1..48bb8822b 100644 --- a/libsrc/common/strchr.s +++ b/libsrc/common/strchr.s @@ -14,8 +14,12 @@ _strchr: jsr popax ; get s tay ; low byte of pointer to y stx ptr1+1 +.if (.cpu .bitand ::CPU_ISET_65SC02) + stz ptr1 +.else lda #0 - sta ptr1 ; ptr access page wise + sta ptr1 ; access from page start, y contains low byte +.endif Loop: lda (ptr1),y ; Get next char beq EOS ; Jump on end of string diff --git a/libsrc/common/strcspn.s b/libsrc/common/strcspn.s index 8fd567ae4..3f7b42ed1 100644 --- a/libsrc/common/strcspn.s +++ b/libsrc/common/strcspn.s @@ -1,54 +1,54 @@ ; ; Ullrich von Bassewitz, 11.06.1998 +; Christian Krueger: 05-Aug-2013, optimization ; ; size_t strcspn (const char* s1, const char* s2); ; .export _strcspn - .import popax - .importzp ptr1, ptr2, tmp1, tmp2, tmp3 + .import popax, _strlen + .importzp ptr1, ptr2, tmp1, tmp2 _strcspn: - sta ptr2 ; Save s2 - stx ptr2+1 - jsr popax ; Get s1 - sta ptr1 - stx ptr1+1 - ldx #0 ; low counter byte - stx tmp1 ; high counter byte - ldy #$00 + jsr _strlen ; get length in a/x and transfer s2 to ptr1 + ; Note: It does not make sense to + ; have more than 255 test chars, so + ; we don't support a high byte here! (ptr1+1 is + ; also unchanged in strlen then (important!)) + ; -> the original implementation also + ; ignored this case -L1: lda (ptr1),y ; get next char from s1 - beq L6 ; jump if done - sta tmp2 ; save char + sta tmp1 ; tmp1 = strlen of test chars + jsr popax ; get and save s1 + sta ptr2 ; to ptr2 + stx ptr2+1 + ldx #0 ; low counter byte + stx tmp2 ; high counter byte + +loadChar: + ldy #0 + lda (ptr2),y ; get next char from s1 + beq leave ; handly byte of s1 +advance: + inc ptr2 ; advance string position to test + bne check + inc ptr2+1 + dey ; correct next iny (faster/shorter than bne...) + +checkNext: iny - bne L2 - inc ptr1+1 -L2: sty tmp3 ; save index into s1 +check: cpy tmp1 ; compare with length of test character string + beq endOfTestChars + cmp (ptr1),y ; found matching char? + bne checkNext - ldy #0 ; get index into s2 -L3: lda (ptr2),y ; - beq L4 ; jump if done - cmp tmp2 - beq L6 - iny - bne L3 - -; The character was not found in s2. Increment the counter and start over - -L4: ldy tmp3 ; reload index - inx - bne L1 - inc tmp1 - bne L1 - -; The character was found, or we reached the end of s1. Return count of -; characters - -L6: txa ; get low counter byte - ldx tmp1 ; get high counter byte +leave: txa ; restore position of finding + ldx tmp2 ; and return rts - - +endOfTestChars: + inx + bne loadChar + inc tmp2 + bne loadChar ; like bra... diff --git a/libsrc/common/strlen.s b/libsrc/common/strlen.s index b583eea50..1a51edb11 100644 --- a/libsrc/common/strlen.s +++ b/libsrc/common/strlen.s @@ -1,6 +1,10 @@ ; ; Ullrich von Bassewitz, 31.05.1998 ; +; Note: strspn & strcspn call internally this function and rely on +; the usage of only ptr1 here! Keep in mind when appling changes +; and check the other implementations too! +; ; int strlen (const char* s); ; @@ -23,4 +27,3 @@ L1: lda (ptr1),y L9: tya ; get low byte of counter, hi's all set rts - diff --git a/libsrc/common/strncat.s b/libsrc/common/strncat.s index b7bb04b2a..42717853f 100644 --- a/libsrc/common/strncat.s +++ b/libsrc/common/strncat.s @@ -1,5 +1,6 @@ ; ; Ullrich von Bassewitz, 31.05.1998 +; Christian Krueger: 12-Aug-2013, minor optimizations ; ; char* strncat (char* dest, const char* src, size_t n); ; @@ -9,64 +10,65 @@ .importzp ptr1, ptr2, ptr3, tmp1, tmp2 _strncat: - eor #$FF ; one's complement to count upwards - sta tmp1 - txa - eor #$FF - sta tmp2 - jsr popax ; get src - sta ptr1 - stx ptr1+1 - jsr popax ; get dest - sta ptr2 - stx ptr2+1 - sta ptr3 ; remember for function return - stx ptr3+1 - ldy #0 + eor #$FF ; one's complement to count upwards + sta tmp1 + txa + eor #$FF + sta tmp2 + + jsr popax ; get src + sta ptr1 + stx ptr1+1 + + jsr popax ; get dest + sta ptr3 ; remember for function return + stx ptr3+1 + stx ptr2+1 + tay ; low byte as offset in Y +.if (.cpu .bitand ::CPU_ISET_65SC02) + stz ptr2 +.else + ldx #0 + stx ptr2 ; destination on page boundary +.endif ; find end of dest -L1: lda (ptr2),y - beq L2 - iny - bne L1 - inc ptr2+1 - bne L1 +L1: lda (ptr2),y + beq L2 + iny + bne L1 + inc ptr2+1 + bne L1 -; end found, get offset in y into pointer - -L2: tya - clc - adc ptr2 - sta ptr2 - bcc L3 - inc ptr2+1 +; end found, apply offset to dest ptr and reset y +L2: sty ptr2 ; copy src. We've put the ones complement of the count into the counter, so ; we'll increment the counter on top of the loop -L3: ldy #0 - ldx tmp1 ; low counter byte +L3: ldy #0 + ldx tmp1 ; low counter byte -L4: inx - bne L5 - inc tmp2 - beq L6 ; jump if done -L5: lda (ptr1),y - sta (ptr2),y - beq L7 - iny - bne L4 - inc ptr1+1 - inc ptr2+1 - bne L4 +L4: inx + bne L5 + inc tmp2 + beq L6 ; jump if done +L5: lda (ptr1),y + sta (ptr2),y + beq L7 + iny + bne L4 + inc ptr1+1 + inc ptr2+1 + bne L4 ; done, set the trailing zero and return pointer to dest -L6: lda #0 - sta (ptr2),y -L7: lda ptr3 - ldx ptr3+1 - rts +L6: lda #0 + sta (ptr2),y +L7: lda ptr3 + ldx ptr3+1 + rts diff --git a/libsrc/common/strspn.s b/libsrc/common/strspn.s index f8b8fff2a..3316f0dab 100644 --- a/libsrc/common/strspn.s +++ b/libsrc/common/strspn.s @@ -1,56 +1,54 @@ ; ; Ullrich von Bassewitz, 11.06.1998 +; Christian Krueger: 08-Aug-2013, optimization ; ; size_t strspn (const char* s1, const char* s2); ; .export _strspn - .import popax - .importzp ptr1, ptr2, tmp1, tmp2, tmp3 + .import popax, _strlen + .importzp ptr1, ptr2, tmp1, tmp2 _strspn: - sta ptr2 ; Save s2 - stx ptr2+1 - jsr popax ; get s1 - sta ptr1 - stx ptr1+1 - ldx #0 ; low counter byte - stx tmp1 ; high counter byte - ldy #$00 + jsr _strlen ; get length in a/x and transfer s2 to ptr1 + ; Note: It does not make sense to + ; have more than 255 test chars, so + ; we don't support a high byte here! (ptr1+1 is + ; also unchanged in strlen then (important!)) + ; -> the original implementation also + ; ignored this case -L1: lda (ptr1),y ; get next char from s1 - beq L6 ; jump if done - sta tmp2 ; save char + sta tmp1 ; tmp1 = strlen of test chars + jsr popax ; get and save s1 + sta ptr2 ; to ptr2 + stx ptr2+1 + ldx #0 ; low counter byte + stx tmp2 ; high counter byte + +loadChar: + ldy #0 + lda (ptr2),y ; get next char from s1 + beq leave ; handly byte of s1 +advance: + inc ptr2 ; advance string position to test + bne check + inc ptr2+1 + dey ; correct next iny (faster/shorter than bne...) + +checkNext: iny - bne L2 - inc ptr1+1 -L2: sty tmp3 ; save index into s1 +check: cpy tmp1 ; compare with length of test character string + beq leave + cmp (ptr1),y ; found matching char? + bne checkNext - ldy #0 ; get index into s2 -L3: lda (ptr2),y ; - beq L6 ; jump if done - cmp tmp2 - beq L4 - iny - bne L3 - -; The character was found in s2. Increment the counter and start over - -L4: ldy tmp3 ; reload index +foundTestChar: inx - bne L1 - inc tmp1 - bne L1 + bne loadChar + inc tmp2 + bne loadChar ; like bra... -; The character was not found, or we reached the end of s1. Return count of -; characters - -L6: txa ; get low counter byte - ldx tmp1 ; get high counter byte +leave: txa ; restore position of finding + ldx tmp2 ; and return rts - - - - - - + \ No newline at end of file diff --git a/libsrc/runtime/axlong.s b/libsrc/runtime/axlong.s index 6d97b5025..02d0a825c 100644 --- a/libsrc/runtime/axlong.s +++ b/libsrc/runtime/axlong.s @@ -1,5 +1,6 @@ ; ; Ullrich von Bassewitz, 25.10.2000 +; Christian Krueger, 02-Mar-2017, some bytes saved ; ; CC65 runtime: Convert int in ax into a long ; @@ -9,18 +10,13 @@ ; Convert AX from int to long in EAX +axlong: ldy #$ff + cpx #$80 ; Positive? + bcs store ; No, apply $FF + axulong: ldy #0 - sty sreg +store: sty sreg sty sreg+1 rts -axlong: cpx #$80 ; Positive? - bcc axulong ; Yes, handle like unsigned type - ldy #$ff - sty sreg - sty sreg+1 - rts - - - diff --git a/test/val/atoi-test.c b/test/val/lib_common_atoi.c similarity index 100% rename from test/val/atoi-test.c rename to test/val/lib_common_atoi.c diff --git a/test/val/lib_common_memmove.c b/test/val/lib_common_memmove.c new file mode 100644 index 000000000..dd5801569 --- /dev/null +++ b/test/val/lib_common_memmove.c @@ -0,0 +1,61 @@ +#include +#include "unittest.h" + +#define BufferSize 384 // test correct page passing (>256, multiple of 128 here) + +static char Buffer[BufferSize+3]; // +1 to move up (and down) + + + +TEST +{ + unsigned i, v; + char* p; + + for (i=0; i < BufferSize; ++i) + Buffer[i+1] = (i%128); + + Buffer[0] = 255; // to check if start position is untouched + Buffer[BufferSize+2] = 255; // to check if end position is untouched + + // copy upwards + p = memmove(Buffer+2, Buffer+1, BufferSize); + + // check buffer consistency before target + ASSERT_AreEqual(255, (unsigned)Buffer[0], "%u", "Unexpected value before range!"); + + // check buffer consistency at starting point + ASSERT_AreEqual(0, (unsigned)Buffer[1], "%u", "Unexpected value at range start!"); + + // check buffer consistency after range + ASSERT_AreEqual(255, (unsigned)Buffer[BufferSize+2], "%u", "Unexpected value after range!"); + + // check buffer values + for (i=0; i < BufferSize; ++i) + { + ASSERT_AreEqual(i%128, (unsigned)Buffer[i+2], "%u", "Unexpected value in buffer at position %u!" COMMA i+2); + } + + v = Buffer[BufferSize+1]; // rember value of first untouched end-byte + + // copy downwards + p = memmove(Buffer+1, Buffer+2, BufferSize); + + // check buffer consistency before target + ASSERT_AreEqual(255, (unsigned)Buffer[0], "%u", "Unexpected value before range!"); + + // check buffer consistency at end point + ASSERT_AreEqual(v, (unsigned)Buffer[BufferSize+1], "%u", "Unexpected value at range end!"); + + // check buffer consistency after range + ASSERT_AreEqual(255, (unsigned)Buffer[BufferSize+2], "%u", "Unexpected value after range!"); + + // check buffer values + for (i=0; i < BufferSize; ++i) + { + ASSERT_AreEqual(i%128, (unsigned)Buffer[i+1], "%u", "Unexpected value in buffer at position %u!" COMMA i+1); + } +} +ENDTEST + + diff --git a/testcode/lib/strcat-test.c b/test/val/lib_common_strcat.c similarity index 99% rename from testcode/lib/strcat-test.c rename to test/val/lib_common_strcat.c index 58119e27a..1872053a4 100644 --- a/testcode/lib/strcat-test.c +++ b/test/val/lib_common_strcat.c @@ -52,5 +52,3 @@ TEST } } ENDTEST - - diff --git a/testcode/lib/strchr-test.c b/test/val/lib_common_strchr.c similarity index 50% rename from testcode/lib/strchr-test.c rename to test/val/lib_common_strchr.c index 7aba1de1e..a48d287e5 100644 --- a/testcode/lib/strchr-test.c +++ b/test/val/lib_common_strchr.c @@ -1,7 +1,5 @@ -#include -#include #include - +#include "unittest.h" /* Test string. Must NOT have duplicate characters! */ @@ -11,49 +9,34 @@ static char Found[256]; -int main (void) +TEST { unsigned Len; unsigned I; char* P; - /* Print a header */ - printf ("strchr(): "); - /* Get the length of the string */ Len = strlen (S); /* Search for all characters in the string, including the terminator */ - for (I = 0; I < Len+1; ++I) { - + for (I = 0; I < Len+1; ++I) + { /* Search for this char */ P = strchr (S, S[I]); /* Check if we found it */ - if (P == 0 || (P - S) != I) { - printf ("Failed for code 0x%02X, offset %u!\n", S[I], I); - printf ("P = %04X offset = %04X\n", P, P-S); - exit (EXIT_FAILURE); - } - + ASSERT_IsFalse(P == 0 || (P - S) != I, "For code 0x%02X, offset %u!\nP = %04X offset = %04X\n" COMMA S[I] COMMA I COMMA P COMMA P-S); /* Mark the char as checked */ Found[S[I]] = 1; } /* Search for all other characters and make sure they aren't found */ - for (I = 0; I < 256; ++I) { - if (Found[I] == 0) { - if (strchr (S, (char)I) != 0) { - printf ("Failed for code 0x%02X\n", I); - exit (EXIT_FAILURE); - } + for (I = 0; I < 256; ++I) + { + if (Found[I] == 0) + { + ASSERT_IsFalse(strchr (S, (char)I), "Failed for code 0x%02X\n" COMMA I); } } - - /* Test passed */ - printf ("Passed\n"); - return EXIT_SUCCESS; } - - - +ENDTEST diff --git a/test/val/lib_common_strcspn.c b/test/val/lib_common_strcspn.c new file mode 100644 index 000000000..10935a78e --- /dev/null +++ b/test/val/lib_common_strcspn.c @@ -0,0 +1,26 @@ +#include +#include "unittest.h" + +#define EstimatedStringSize 384 // test correct page passing (>256) + +static char EstimatedString[EstimatedStringSize+1]; // +1 room for terminating null +static char* EmptyTestChars=""; // strlen equivalent... +static char* TestChars="1234567890"; // we like to find numbers + +TEST +{ + unsigned i; + + for (i=0; i < EstimatedStringSize; ++i) + EstimatedString[i] = (i%26)+'A'; // put ABCD... into the string to be estimated + + ASSERT_AreEqual(strlen(EstimatedString), strcspn(EstimatedString, TestChars), "%u", "Unxpected position returned for non-participant case!"); + + EstimatedString[EstimatedStringSize/2] = TestChars[strlen(TestChars-1)]; + ASSERT_AreEqual(EstimatedStringSize/2, strcspn(EstimatedString, TestChars), "%u", "Unxpected position returned for participant case!"); + + ASSERT_AreEqual(strlen(EstimatedString), strcspn(EstimatedString, EmptyTestChars), "%u", "Unxpected position returned for empty test case!"); +} +ENDTEST + + diff --git a/test/val/lib_common_strncat.c b/test/val/lib_common_strncat.c new file mode 100644 index 000000000..dd6df9147 --- /dev/null +++ b/test/val/lib_common_strncat.c @@ -0,0 +1,54 @@ +#include +#include "unittest.h" + +#define SourceStringSize 384 // test correct page passing (>256, multiple of 128 here) + +static char SourceString[SourceStringSize+1]; // +1 room for terminating null +static char DestinationString[2*SourceStringSize+1]; // will contain two times the source buffer + + +TEST +{ + unsigned i; + char* p; + + for (i=0; i < SourceStringSize; ++i) + SourceString[i] = (i%128)+1; + + SourceString[i] = 0; + + ASSERT_AreEqual(SourceStringSize, strlen(SourceString), "%u", "Source string initialization or 'strlen()' problem!"); + + /* Ensure empty destination string */ + DestinationString[0] = 0; + + ASSERT_AreEqual(0, strlen(DestinationString), "%u", "Destination string initialization or 'strlen()' problem!"); + + /* Test "unlimted" concatenation to empty buffer */ + + strncat(DestinationString, SourceString, 1024); + + ASSERT_AreEqual(SourceStringSize, strlen(DestinationString), "%u", "Unexpected string length while string concatenation to empty buffer!"); + + /* Test limited concatenation to non empty buffer */ + + p = strncat(DestinationString, SourceString, 128); + + ASSERT_AreEqual(SourceStringSize+128, strlen(DestinationString), "%u", "Unexpected string length while string concatenation to non-empty buffer!"); + + /* Test return value */ + + ASSERT_IsTrue(p == DestinationString, "Invalid return value!"); + + /* Test contents */ + + for(i=0; i < strlen(DestinationString); ++i) + { + unsigned current = DestinationString[i]; + unsigned expected = (i%128)+1; + ASSERT_AreEqual(expected, current, "%u", "Unexpected destination buffer contents at position %u!\n" COMMA i); + } +} +ENDTEST + + diff --git a/test/val/strtol-test.c b/test/val/lib_common_strol.c similarity index 100% rename from test/val/strtol-test.c rename to test/val/lib_common_strol.c diff --git a/testcode/lib/strrchr-test.c b/test/val/lib_common_strrchr.c similarity index 100% rename from testcode/lib/strrchr-test.c rename to test/val/lib_common_strrchr.c diff --git a/test/val/lib_common_strspn.c b/test/val/lib_common_strspn.c new file mode 100644 index 000000000..96a006469 --- /dev/null +++ b/test/val/lib_common_strspn.c @@ -0,0 +1,24 @@ +#include +#include "unittest.h" + +#define EstimatedStringSize 384 // test correct page passing (>256) + +static char EstimatedString[EstimatedStringSize+1]; // +1 room for terminating null +static char* EmptyTestChars=""; // empty test case... +static char* TestChars="1234567890"; // we like to find numbers + +TEST +{ + unsigned i; + + for (i=0; i < EstimatedStringSize; ++i) + EstimatedString[i] = (i%10)+'0'; // put 0123... into the string to be estimated + + ASSERT_AreEqual(strlen(EstimatedString), strspn(EstimatedString, TestChars), "%u", "Unxpected position returned for all participant case!"); + + EstimatedString[EstimatedStringSize/2] = 'X'; + ASSERT_AreEqual(EstimatedStringSize/2, strspn(EstimatedString, TestChars), "%u", "Unxpected position returned for breaking case!"); + + ASSERT_AreEqual(0, strspn(EstimatedString, EmptyTestChars), "%u", "Unxpected position returned for empty test case!"); +} +ENDTEST diff --git a/test/val/strtoul-test.c b/test/val/lib_common_strtoul.c similarity index 100% rename from test/val/strtoul-test.c rename to test/val/lib_common_strtoul.c diff --git a/testcode/lib/unittest.h b/test/val/unittest.h similarity index 100% rename from testcode/lib/unittest.h rename to test/val/unittest.h From 8d1b80e6fd7c4f3feef1fe7f56a321966bf59cd8 Mon Sep 17 00:00:00 2001 From: IrgendwerA8 Date: Sun, 5 Mar 2017 11:38:55 +0100 Subject: [PATCH 6/7] Fixed CPU-flag usage which fails on build server?! --- libsrc/common/strcat.s | 1 + libsrc/common/strchr.s | 1 + libsrc/common/strncat.s | 3 ++- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/libsrc/common/strcat.s b/libsrc/common/strcat.s index 74fef0759..7dce2f78a 100644 --- a/libsrc/common/strcat.s +++ b/libsrc/common/strcat.s @@ -8,6 +8,7 @@ .export _strcat .import popax .importzp ptr1, ptr2, tmp3 + .macpack cpu _strcat: sta ptr1 ; Save src diff --git a/libsrc/common/strchr.s b/libsrc/common/strchr.s index 48bb8822b..15c743776 100644 --- a/libsrc/common/strchr.s +++ b/libsrc/common/strchr.s @@ -8,6 +8,7 @@ .export _strchr .import popax .importzp ptr1, tmp1 + .macpack cpu _strchr: sta tmp1 ; Save c diff --git a/libsrc/common/strncat.s b/libsrc/common/strncat.s index 42717853f..e0fa39cc0 100644 --- a/libsrc/common/strncat.s +++ b/libsrc/common/strncat.s @@ -8,7 +8,8 @@ .export _strncat .import popax .importzp ptr1, ptr2, ptr3, tmp1, tmp2 - + .macpack cpu + _strncat: eor #$FF ; one's complement to count upwards sta tmp1 From 371e8efb7966268dbb86668f15813a36dd26d32e Mon Sep 17 00:00:00 2001 From: IrgendwerA8 Date: Tue, 7 Mar 2017 19:16:31 +0100 Subject: [PATCH 7/7] temporarily disable optimizations altogether until a fine grain control is implemented on Makefile level only disabling the compiler option -Os --- test/val/lib_common_memmove.c | 4 ++++ test/val/lib_common_strcat.c | 4 ++++ test/val/lib_common_strcspn.c | 4 ++++ test/val/lib_common_strncat.c | 4 ++++ test/val/lib_common_strspn.c | 4 ++++ 5 files changed, 20 insertions(+) diff --git a/test/val/lib_common_memmove.c b/test/val/lib_common_memmove.c index dd5801569..6c04e1951 100644 --- a/test/val/lib_common_memmove.c +++ b/test/val/lib_common_memmove.c @@ -1,3 +1,7 @@ +// temporarily disable optimizations altogether until a fine grain control +// is implemented on Makefile level only disabling the compiler option -Os +#pragma optimize (off) + #include #include "unittest.h" diff --git a/test/val/lib_common_strcat.c b/test/val/lib_common_strcat.c index 1872053a4..6389d5651 100644 --- a/test/val/lib_common_strcat.c +++ b/test/val/lib_common_strcat.c @@ -1,3 +1,7 @@ +// temporarily disable optimizations altogether until a fine grain control +// is implemented on Makefile level only disabling the compiler option -Os +#pragma optimize (off) + #include #include "unittest.h" diff --git a/test/val/lib_common_strcspn.c b/test/val/lib_common_strcspn.c index 10935a78e..06838c435 100644 --- a/test/val/lib_common_strcspn.c +++ b/test/val/lib_common_strcspn.c @@ -1,3 +1,7 @@ +// temporarily disable optimizations altogether until a fine grain control +// is implemented on Makefile level only disabling the compiler option -Os +#pragma optimize (off) + #include #include "unittest.h" diff --git a/test/val/lib_common_strncat.c b/test/val/lib_common_strncat.c index dd6df9147..84d904fa0 100644 --- a/test/val/lib_common_strncat.c +++ b/test/val/lib_common_strncat.c @@ -1,3 +1,7 @@ +// temporarily disable optimizations altogether until a fine grain control +// is implemented on Makefile level only disabling the compiler option -Os +#pragma optimize (off) + #include #include "unittest.h" diff --git a/test/val/lib_common_strspn.c b/test/val/lib_common_strspn.c index 96a006469..693a1136a 100644 --- a/test/val/lib_common_strspn.c +++ b/test/val/lib_common_strspn.c @@ -1,3 +1,7 @@ +// temporarily disable optimizations altogether until a fine grain control +// is implemented on Makefile level only disabling the compiler option -Os +#pragma optimize (off) + #include #include "unittest.h"