Skip to content

Commit 8935c8c

Browse files
committed
✅ Many changes to benchmarks
- Support and test lpc4078 - Add benchmarks that uses empty strings (way worse than returning data)
1 parent dce801b commit 8935c8c

25 files changed

+14919
-513
lines changed

benchmark/CMakeLists.txt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,49 @@ foreach(test_path ${GENERATED_TEST})
110110
endif()
111111
endforeach()
112112

113+
114+
file(GLOB WRITTEN_TEST "${CMAKE_CURRENT_SOURCE_DIR}/written_tests/*.cpp")
115+
116+
foreach(test_path ${WRITTEN_TEST})
117+
get_filename_component(test_file_name ${test_path} NAME)
118+
set(elf ${test_file_name}.elf)
119+
120+
message(STATUS "Generating written Demo for \"${elf}\"")
121+
add_executable(${elf} ${test_path})
122+
target_include_directories(${elf} PRIVATE .)
123+
target_compile_options(${elf} PRIVATE ${BENCHMARK_COMPILE_OPTIONS})
124+
125+
# Check if the test file name starts with "result_"
126+
string(REGEX MATCH "^result_" is_result_file ${test_file_name})
127+
if(is_result_file)
128+
target_compile_options(${elf} PRIVATE
129+
$<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions>)
130+
else()
131+
target_compile_options(${elf} PRIVATE
132+
$<$<COMPILE_LANGUAGE:CXX>:-fexceptions>)
133+
endif()
134+
135+
target_link_libraries(${elf} PRIVATE
136+
startup_code
137+
libhal::$ENV{LIBHAL_PLATFORM_LIBRARY}
138+
)
139+
target_link_options(${elf} PRIVATE -fno-threadsafe-statics
140+
-L${CMAKE_SOURCE_DIR}/
141+
-Wl,-Map=${CMAKE_BINARY_DIR}/${elf}.map
142+
)
143+
if(prebuilt-picolibc_FOUND)
144+
target_link_libraries(${elf} PRIVATE picolibc)
145+
endif()
146+
147+
if(${CMAKE_CROSSCOMPILING})
148+
# Convert elf into .bin, .hex and other formats needed for programming
149+
# devices.
150+
libhal_post_build(${elf})
151+
libhal_disassemble(${elf})
152+
endif()
153+
endforeach()
154+
155+
113156
# Build nearpoint binary if if available
114157
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/nearpoint.cpp")
115158
message(STATUS "nearpoint.cpp exists!")

benchmark/README.md

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,33 @@ To execute the benchmark you can either supply the python script with a binary
7878
file to flash OR provide it a newline delimitated list of executable paths.
7979

8080
```bash
81-
python3 halbord_benchmark.py -o all_tests.csv -f all_tests.list
81+
python3 halbord_benchmark.py -n 10000000 -f test_order.list
8282
```
8383

8484
We currently provide the following test lists within the directory:
8585

86-
1. `all_tests.list`
87-
2. `except_tests.list`
88-
3. `result_tests.list`
86+
1. `test_order.csv`
87+
2. `test_order_lpc4078.csv`
88+
3. `test_nearpoint.csv`
89+
90+
## About `fast_gcc_except`
91+
92+
This test can only fully reach its maximum performance if you make the
93+
`search_EIT_Table()` function visible and weakened so the implementation in
94+
this project can take over.
95+
96+
To do this you must run the following command on ARM GCC:
97+
98+
```bash
99+
arm-none-eabi-objcopy \
100+
/path/to/arm-none-eabi-gcc/lib/gcc/arm-none-eabi/14.2.1/thumb/v7-m/nofp/libgcc.a \
101+
--globalize-symbol=search_EIT_table \
102+
--weaken-symbol=search_EIT_table \
103+
/path/to/arm-none-eabi-gcc/lib/gcc/arm-none-eabi/14.2.1/thumb/v7-m/nofp/libgcc.a
104+
```
105+
106+
You need to change the `/path/to/` to the actual path of your
107+
`arm-none-eabi-gcc` toolchain.
108+
109+
Once you've done this, delete the `build` directory if it exists and rebuilt
110+
the project.

benchmark/fast_gcc_unwind.cpp

Lines changed: 75 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <atomic>
12
#include <unwind.h>
23

34
#include <algorithm>
@@ -6,6 +7,8 @@
67
#include <cstdlib>
78
#include <span>
89

10+
#include <platform.hpp>
11+
912
/* Misc constants. */
1013
#define R_IP 12
1114
#define R_SP 13
@@ -76,48 +79,18 @@ typedef struct __EIT_entry
7679
std::uint32_t content;
7780
} __EIT_entry;
7881

79-
std::uint32_t selfrel_offset31(std::uint32_t const* p)
82+
std::uintptr_t selfrel_offset31(std::uint32_t const* p)
8083
{
81-
std::uint32_t offset;
84+
auto offset = static_cast<std::int32_t>(*p);
8285

83-
offset = *p;
8486
/* Sign extend to 32 bits. */
85-
if (offset & (1 << 30))
86-
offset |= 1u << 31;
87-
else
88-
offset &= ~(1u << 31);
87+
offset <<= 1;
88+
offset >>= 1;
8989

90-
return offset + (std::uint32_t)p;
90+
return std::bit_cast<std::uintptr_t>(offset +
91+
std::bit_cast<std::intptr_t>(p));
9192
}
9293

93-
struct eit_entry_less_than
94-
{
95-
[[gnu::always_inline]] static std::uint32_t to_absolute(
96-
__EIT_entry const& entry)
97-
{
98-
auto entry_addr = reinterpret_cast<std::uint32_t>(&entry.content);
99-
// Sign extend :D
100-
entry_addr <<= 1;
101-
entry_addr >>= 1;
102-
return entry_addr;
103-
}
104-
105-
bool operator()(__EIT_entry const& left, __EIT_entry const& right)
106-
{
107-
return left.fnoffset < right.fnoffset;
108-
}
109-
bool operator()(__EIT_entry const& left, std::uint32_t right)
110-
{
111-
std::uint32_t absolute_left = to_absolute(left);
112-
return absolute_left < right;
113-
}
114-
bool operator()(std::uint32_t left, __EIT_entry const& right)
115-
{
116-
std::uint32_t absolute_right = to_absolute(right);
117-
return left < absolute_right;
118-
}
119-
};
120-
12194
/* Return the next byte of unwinding information, or CODE_FINISH if there is
12295
no data remaining. */
12396
[[gnu::always_inline]] _uw8 next_unwind_byte(__gnu_unwind_state* uws)
@@ -411,18 +384,76 @@ extern "C"
411384
return __wrap___gnu_unwind_execute(context, &uws);
412385
}
413386

414-
__EIT_entry const* search_EIT_table(__EIT_entry const* table,
415-
int nrec, // NOLINT
387+
struct eit_entry_less_than
388+
{
389+
bool operator()(__EIT_entry const& left, __EIT_entry const& right)
390+
{
391+
return selfrel_offset31(&left.fnoffset) <
392+
selfrel_offset31(&right.fnoffset);
393+
}
394+
395+
bool operator()(__EIT_entry const& left, std::uint32_t right)
396+
{
397+
return selfrel_offset31(&left.fnoffset) < right;
398+
}
399+
bool operator()(std::uint32_t left, __EIT_entry const& right)
400+
{
401+
return left < selfrel_offset31(&right.fnoffset);
402+
}
403+
bool operator()(std::uint32_t left, std::uint32_t right)
404+
{
405+
return left < right;
406+
}
407+
};
408+
409+
#if 1
410+
__EIT_entry const* search_EIT_table(__EIT_entry const* table, // NOLINT
411+
int nrec, // NOLINT
416412
std::uint32_t return_address)
417413
{
418414
if (nrec == 0) {
419415
return nullptr;
420416
}
421-
std::span<__EIT_entry const> table_span(table, nrec);
422-
auto const& entry = std::upper_bound(table_span.begin(),
423-
table_span.end(),
424-
return_address,
425-
eit_entry_less_than{});
426-
return entry.base();
417+
418+
auto const& next_entry = std::ranges::upper_bound(
419+
std::span(table, nrec), return_address, eit_entry_less_than{});
420+
auto const& actual_entry = *(next_entry - 1);
421+
422+
return &actual_entry;
423+
}
424+
#else
425+
__EIT_entry const* search_EIT_table(__EIT_entry const* table, // NOLINT
426+
int nrec, // NOLINT
427+
_uw return_address)
428+
{
429+
_uw next_fn;
430+
_uw this_fn;
431+
int n, left, right;
432+
if (nrec == 0)
433+
return (__EIT_entry*)0;
434+
435+
left = 0;
436+
right = nrec - 1;
437+
438+
while (1) {
439+
n = (left + right) / 2;
440+
this_fn = selfrel_offset31(&table[n].fnoffset);
441+
if (n != nrec - 1) {
442+
next_fn = selfrel_offset31(&table[n + 1].fnoffset) - 1;
443+
} else {
444+
next_fn = (_uw)0 - 1;
445+
}
446+
if (return_address < this_fn) {
447+
if (n == left) {
448+
return (__EIT_entry*)0;
449+
}
450+
right = n - 1;
451+
} else if (return_address <= next_fn) {
452+
return &table[n];
453+
} else {
454+
left = n + 1;
455+
}
456+
}
427457
}
458+
#endif
428459
}
Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,61 @@
11
depth,error_size,destructor_percentage,pulse_us
2-
50,4,0,341.33
3-
35,4,0,244.79
4-
15,4,0,117.21
5-
5,4,0,52.12
6-
1,4,0,26.54
7-
50,4,25,429.54
8-
35,4,25,306.83
9-
15,4,25,144.96
10-
5,4,25,66.79
11-
1,4,25,34.25
12-
50,4,50,510.33
13-
35,4,50,366.88
14-
15,4,50,171.33
15-
5,4,50,73.96
16-
1,4,50,34.25
17-
50,4,100,677.79
18-
35,4,100,480.96
19-
15,4,100,217.92
20-
5,4,100,86.96
21-
1,4,100,34.25
22-
50,16,0,341.33
23-
35,16,0,244.83
24-
15,16,0,117.12
25-
5,16,0,52.17
26-
1,16,0,26.58
27-
50,16,25,429.5
28-
35,16,25,307.21
29-
15,16,25,144.96
30-
5,16,25,66.42
31-
1,16,25,34.29
32-
50,16,50,510.33
33-
35,16,50,366.88
34-
15,16,50,171.38
35-
5,16,50,74.0
36-
1,16,50,34.25
37-
50,16,100,677.75
38-
35,16,100,481.0
39-
15,16,100,217.92
40-
5,16,100,87.04
41-
1,16,100,34.25
42-
50,65,0,357.0
43-
35,65,0,260.42
44-
15,65,0,132.75
45-
5,65,0,67.75
46-
1,65,0,42.17
47-
50,65,25,445.5
48-
35,65,25,322.75
49-
15,65,25,160.12
50-
5,65,25,81.96
51-
1,65,25,49.75
52-
50,65,50,525.88
53-
35,65,50,382.38
54-
15,65,50,186.88
55-
5,65,50,89.5
56-
1,65,50,49.75
57-
50,65,100,693.33
58-
35,65,100,496.54
59-
15,65,100,233.46
60-
5,65,100,102.5
61-
1,65,100,49.79
2+
50,4,0,335.04
3+
35,4,0,240.29
4+
15,4,0,115.17
5+
5,4,0,51.33
6+
1,4,0,26.29
7+
50,4,25,423.21
8+
35,4,25,302.25
9+
15,4,25,142.96
10+
5,4,25,65.96
11+
1,4,25,33.96
12+
50,4,50,504.0
13+
35,4,50,362.29
14+
15,4,50,169.29
15+
5,4,50,73.12
16+
1,4,50,33.92
17+
50,4,100,671.38
18+
35,4,100,476.38
19+
15,4,100,215.92
20+
5,4,100,86.17
21+
1,4,100,33.96
22+
50,16,0,335.0
23+
35,16,0,240.25
24+
15,16,0,115.12
25+
5,16,0,51.33
26+
1,16,0,26.25
27+
50,16,25,423.21
28+
35,16,25,302.67
29+
15,16,25,142.96
30+
5,16,25,65.62
31+
1,16,25,34.0
32+
50,16,50,504.04
33+
35,16,50,362.38
34+
15,16,50,169.38
35+
5,16,50,73.12
36+
1,16,50,33.96
37+
50,16,100,671.42
38+
35,16,100,476.42
39+
15,16,100,215.92
40+
5,16,100,86.17
41+
1,16,100,33.96
42+
50,65,0,345.54
43+
35,65,0,250.75
44+
15,65,0,125.62
45+
5,65,0,61.83
46+
1,65,0,36.75
47+
50,65,25,434.0
48+
35,65,25,313.04
49+
15,65,25,152.96
50+
5,65,25,76.04
51+
1,65,25,44.38
52+
50,65,50,514.42
53+
35,65,50,372.71
54+
15,65,50,179.75
55+
5,65,50,83.58
56+
1,65,50,44.38
57+
50,65,100,681.83
58+
35,65,100,486.83
59+
15,65,100,226.33
60+
5,65,100,96.58
61+
1,65,100,44.38

benchmark/generated_tests/except.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <cstdint>
22

33
#include <array>
4+
#include <string>
45

56
#include <platform.hpp>
67

0 commit comments

Comments
 (0)