diff options
| author | Xavier ASUS <xavi92psx@gmail.com> | 2019-10-18 00:31:54 +0200 |
|---|---|---|
| committer | Xavier ASUS <xavi92psx@gmail.com> | 2019-10-18 00:31:54 +0200 |
| commit | 268a53de823a6750d6256ee1fb1e7707b4b45740 (patch) | |
| tree | 42c1799a9a82b2f7d9790ee9fe181d72a7274751 /support/regression/tests/loop.c | |
| download | sdcc-gas-268a53de823a6750d6256ee1fb1e7707b4b45740.tar.gz | |
sdcc-3.9.0 fork implementing GNU assembler syntax
This fork aims to provide better support for stm8-binutils
Diffstat (limited to 'support/regression/tests/loop.c')
| -rw-r--r-- | support/regression/tests/loop.c | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/support/regression/tests/loop.c b/support/regression/tests/loop.c new file mode 100644 index 0000000..4ca0526 --- /dev/null +++ b/support/regression/tests/loop.c @@ -0,0 +1,114 @@ +/** loopp counter narrowing optimizatrion test + type: unsigned long, signed long +*/ +#include <testfwk.h> + +#include <limits.h> +#include <setjmp.h> + +#if !defined(__SDCC_mcs51) && !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) +unsigned char array[300]; +#endif + +#if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) +/* A loop where the counter should be narrowed to an 8-bit unsigned type. */ +void loop8(unsigned char *a, {type} n) +{ + for({type} i = 0; i < n; i++) + a[i * n] = 8; +} + +/* A loop where the counter should be narrowed to a 16-bit unsigned type, but not further. */ +void loop16(unsigned char *a) +{ + for ({type} i = 0; i < 300; i++) + a[i] = 16; +} + +/* A loop where the subtraction should prevent optimization. */ +void loopm(unsigned char *a) +{ + for ({type} i = (1ul << 20); i < (1ul << 20) + 1; i++) + a[i - (1ul << 20)] = 1; +} + +void modify1({type} *p) +{ + *p = 17; +} + +void modify2({type} *p) +{ + *p = (1ul << 30); +} + +/* Loops where access to the counter via pointers should prevent optimization. */ +void address(unsigned char *a) +{ + for ({type} i = (1ul << 28); i < (1ul << 30); i++) + { + modify1(&i); + a[i] = 17; + modify2(&i); + } + + for ({type} i = (1ul << 28); i < (1ul << 30); i++) + { + {type} *p = &i; + *p = 18; + a[i] = 18; + *p = (1ul << 30); + } +} + +void jump_func(jmp_buf *jp, {type} i) +{ + ASSERT (i == (1ul << 29)); + longjmp (*jp, 0); +} + +/* A loop where the side-effects from jump_func() should prevent optimization. */ +void jump(unsigned char *a) +{ + jmp_buf j; + + if (setjmp (j)) + return; + + for ({type} i = (1ul << 29); i < (1ul << 30); i++) + { + jump_func(&j, i); + a[i] = 14; + } + + a[0] = 13; +} +#endif + +void testLoop(void) +{ +#if !defined(__SDCC_mcs51) && !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) + loop8 (array, 3); + ASSERT (array[0] == 8); + ASSERT (array[3] == 8); + ASSERT (array[6] == 8); + + loop16 (array); + ASSERT (array[0] == 16); + ASSERT (array[17] == 16); + ASSERT (array[255] == 16); + ASSERT (array[256] == 16); + ASSERT (array[299] == 16); + + loopm (array); + ASSERT (array[0] == 1); + + address (array); + ASSERT (array[17] == 17); + ASSERT (array[18] == 18); + + jump (array); + ASSERT (array[0] != 13); +#endif +} + |
