From 34eb8186fdb85d38a03e598cbff20941de84293e Mon Sep 17 00:00:00 2001 From: Lionel Debroux Date: Sun, 19 Nov 2023 17:14:08 +0100 Subject: [PATCH] Significantly optimize test_mov_inv_walk1() for size by moving the ternary operators related to inverse and pattern outside hot paths, which prevents generated code duplication and shortens one of the sides of duplicated loops. (#351) Before: text data bss dec hex filename 3019 0 0 3019 bcb build32/tests/mov_inv_walk1.o 2640 0 0 2640 a50 build64/tests/mov_inv_walk1.o After: text data bss dec hex filename 1705 0 0 1705 6a9 build32/tests/mov_inv_walk1.o 1464 0 0 1464 5b8 build64/tests/mov_inv_walk1.o --- tests/mov_inv_walk1.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/mov_inv_walk1.c b/tests/mov_inv_walk1.c index 78ba7e5..62edba4 100644 --- a/tests/mov_inv_walk1.c +++ b/tests/mov_inv_walk1.c @@ -32,9 +32,10 @@ int test_mov_inv_walk1(int my_cpu, int iterations, int offset, bool inverse) int ticks = 0; testword_t pattern = (testword_t)1 << offset; + pattern = inverse ? ~pattern : pattern; if (my_cpu == master_cpu) { - display_test_pattern_value(inverse ? ~pattern : pattern); + display_test_pattern_value(pattern); } // Initialize memory with the initial pattern. @@ -61,7 +62,7 @@ int test_mov_inv_walk1(int my_cpu, int iterations, int offset, bool inverse) } test_addr[my_cpu] = (uintptr_t)p; do { - write_word(p, inverse ? ~pattern : pattern); + write_word(p, pattern); pattern = pattern << 1 | pattern >> (TESTWORD_WIDTH - 1); // rotate left } while (p++ < pe); // test before increment in case pointer overflows do_tick(my_cpu); @@ -73,6 +74,7 @@ int test_mov_inv_walk1(int my_cpu, int iterations, int offset, bool inverse) // Test from bottom up and then from the top down. for (int i = 0; i < iterations; i++) { pattern = (testword_t)1 << offset; + pattern = inverse ? ~pattern : pattern; flush_caches(my_cpu); @@ -99,7 +101,7 @@ int test_mov_inv_walk1(int my_cpu, int iterations, int offset, bool inverse) } test_addr[my_cpu] = (uintptr_t)p; do { - testword_t expect = inverse ? ~pattern : pattern; + testword_t expect = pattern; testword_t actual = read_word(p); if (unlikely(actual != expect)) { data_error(p, expect, actual, true); @@ -112,6 +114,8 @@ int test_mov_inv_walk1(int my_cpu, int iterations, int offset, bool inverse) } while (!at_end && ++pe); // advance pe to next start point } + pattern = ~pattern; + flush_caches(my_cpu); for (int j = vm_map_size - 1; j >= 0; j--) { @@ -138,7 +142,7 @@ int test_mov_inv_walk1(int my_cpu, int iterations, int offset, bool inverse) test_addr[my_cpu] = (uintptr_t)ps; do { pattern = pattern >> 1 | pattern << (TESTWORD_WIDTH - 1); // rotate right - testword_t expect = inverse ? pattern : ~pattern; + testword_t expect = pattern; testword_t actual = read_word(p); if (unlikely(actual != expect)) { data_error(p, expect, actual, true);