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
This commit is contained in:
Lionel Debroux 2023-11-19 17:14:08 +01:00 committed by GitHub
parent bda3776df1
commit 34eb8186fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 4 deletions

View File

@ -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);