Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 14 additions & 18 deletions test/pico_float_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,13 @@ foreach (FLOAT_TYPE IN LISTS FLOAT_TYPES)
target_compile_options(custom_float_funcs_test_${FLOAT_TYPE} PRIVATE -fno-strict-float-cast-overflow)
endif()

if (NOT PICO_RISCV) # todo need risc-v support too
add_executable(float_benchmark_${FLOAT_TYPE} float_benchmark.c)
pico_set_float_implementation(float_benchmark_${FLOAT_TYPE} ${FLOAT_TYPE})
target_link_libraries(float_benchmark_${FLOAT_TYPE} PRIVATE pico_stdlib m)
pico_add_extra_outputs(float_benchmark_${FLOAT_TYPE})
target_compile_definitions(float_benchmark_${FLOAT_TYPE} PRIVATE PICO_FLOAT_IN_RAM=1)
pico_set_printf_implementation(float_benchmark_${FLOAT_TYPE} compiler)
pico_set_binary_type(float_benchmark_${FLOAT_TYPE} copy_to_ram)
endif()
add_executable(float_benchmark_${FLOAT_TYPE} float_benchmark.c)
pico_set_float_implementation(float_benchmark_${FLOAT_TYPE} ${FLOAT_TYPE})
target_link_libraries(float_benchmark_${FLOAT_TYPE} PRIVATE pico_stdlib m)
pico_add_extra_outputs(float_benchmark_${FLOAT_TYPE})
target_compile_definitions(float_benchmark_${FLOAT_TYPE} PRIVATE PICO_FLOAT_IN_RAM=1)
pico_set_printf_implementation(float_benchmark_${FLOAT_TYPE} compiler)
pico_set_binary_type(float_benchmark_${FLOAT_TYPE} copy_to_ram)
endforeach ()

foreach (DOUBLE_TYPE IN LISTS DOUBLE_TYPES)
Expand Down Expand Up @@ -127,15 +125,13 @@ foreach (DOUBLE_TYPE IN LISTS DOUBLE_TYPES)
endif()
endif()

if (NOT PICO_RISCV) # todo need risc-v support too
add_executable(double_benchmark_${DOUBLE_TYPE} double_benchmark.c)
pico_set_double_implementation(double_benchmark_${DOUBLE_TYPE} ${DOUBLE_TYPE})
target_link_libraries(double_benchmark_${DOUBLE_TYPE} PRIVATE pico_stdlib m)
pico_add_extra_outputs(double_benchmark_${DOUBLE_TYPE})
target_compile_definitions(double_benchmark_${DOUBLE_TYPE} PRIVATE PICO_DOUBLE_IN_RAM=1)
pico_set_printf_implementation(double_benchmark_${DOUBLE_TYPE} compiler)
pico_set_binary_type(double_benchmark_${DOUBLE_TYPE} copy_to_ram)
endif()
add_executable(double_benchmark_${DOUBLE_TYPE} double_benchmark.c)
pico_set_double_implementation(double_benchmark_${DOUBLE_TYPE} ${DOUBLE_TYPE})
target_link_libraries(double_benchmark_${DOUBLE_TYPE} PRIVATE pico_stdlib m)
pico_add_extra_outputs(double_benchmark_${DOUBLE_TYPE})
target_compile_definitions(double_benchmark_${DOUBLE_TYPE} PRIVATE PICO_DOUBLE_IN_RAM=1)
pico_set_printf_implementation(double_benchmark_${DOUBLE_TYPE} compiler)
pico_set_binary_type(double_benchmark_${DOUBLE_TYPE} copy_to_ram)
endforeach ()

if (PICO_RP2350 AND NOT PICO_RISCV)
Expand Down
41 changes: 29 additions & 12 deletions test/pico_float_test/double_benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,17 @@
#endif

static void init_systick() {
#ifdef __riscv
// Stop, clear then start 64-bit RISC-V platform timer for boot timing
sio_hw->mtime_ctrl = 0;
sio_hw->mtime = 0;
sio_hw->mtimeh = 0;
sio_hw->mtime_ctrl = SIO_MTIME_CTRL_FULLSPEED_BITS | SIO_MTIME_CTRL_EN_BITS;
#else
systick_hw->csr = 0;
systick_hw->rvr = ARM_CPU_PREFIXED(SYST_RVR_RELOAD_BITS);
systick_hw->csr = ARM_CPU_PREFIXED(SYST_CSR_CLKSOURCE_BITS) | ARM_CPU_PREFIXED(SYST_CSR_ENABLE_BITS);
#endif
}

// Stop the compiler from constant-folding a hardware base pointer into the
Expand All @@ -25,18 +33,22 @@ static void init_systick() {
__opaque_ptr; \
})

static __force_inline uint32_t systick_value() {
return systick_hw->cvr;
}

static __force_inline io_ro_32 *systick_value_ptr() {
#ifdef __riscv
return &sio_hw->mtime;
#else
return __get_opaque_ptr(&systick_hw->cvr);
#endif
}

static int cycle_diff(uint32_t systick1, uint32_t systick2) {
#ifdef __riscv
return systick2 - systick1 - 1;
#else
static_assert(ARM_CPU_PREFIXED(SYST_CVR_CURRENT_LSB) == 0, "");
uint32_t shift = 32 - ARM_CPU_PREFIXED(SYST_CVR_CURRENT_MSB);
return (((int32_t)((systick1 << shift) - (systick2 << shift))) >> shift) - 1; // -1 since the second systick read costs one
#endif
}

#define timer_func_def(name) static __noinline int __not_in_flash_func(time_##name)
Expand Down Expand Up @@ -156,8 +168,13 @@ static double time_unary_int64_n_func(int (*timer)(int64_t, int32_t), int64_t *i
// #pragma message("EMITS_VFP = " __XSTRING(EMITS_VFP))
// #pragma message("USING_HARD_FLOAT_ABI = " __XSTRING(USING_HARD_FLOAT_ABI))

#ifdef __riscv
#define LOAD_COST 1
#define STORE_COST 1
#else
#define LOAD_COST 2
#define STORE_COST 2
#endif

#define DOUBLE_INPUT_COST (LOAD_COST * 2)
#define DOUBLE_OUTPUT_COST (STORE_COST * 2)
Expand Down Expand Up @@ -913,7 +930,7 @@ timer_func_def(dcopysign)(volatile double a, volatile double b) {
uint32_t t0 = *systick_ptr;
volatile double x = copysign(a, b);
uint32_t t1 = *systick_ptr;
return cycle_diff(t0, t1) - DOUBLE_INPUT_COST - DOUBLE_OUTPUT_COST;
return cycle_diff(t0, t1) - DOUBLE_INPUT_COST * 2 - DOUBLE_OUTPUT_COST;
}

timer_func_def(dtrunc)(volatile double a) {
Expand Down Expand Up @@ -953,7 +970,7 @@ timer_func_def(dfmod)(volatile double a, volatile double b) {
uint32_t t0 = *systick_ptr;
volatile double x = fmod(a, b);
uint32_t t1 = *systick_ptr;
return cycle_diff(t0, t1) - DOUBLE_INPUT_COST - DOUBLE_OUTPUT_COST;
return cycle_diff(t0, t1) - DOUBLE_INPUT_COST * 2 - DOUBLE_OUTPUT_COST;
}

timer_func_def(ddrem)(volatile double a, volatile double b) {
Expand All @@ -965,7 +982,7 @@ timer_func_def(ddrem)(volatile double a, volatile double b) {
uint32_t t0 = *systick_ptr;
volatile double x = drem(a, b);
uint32_t t1 = *systick_ptr;
return cycle_diff(t0, t1) - DOUBLE_INPUT_COST - DOUBLE_OUTPUT_COST;
return cycle_diff(t0, t1) - DOUBLE_INPUT_COST * 2 - DOUBLE_OUTPUT_COST;
#endif
}

Expand All @@ -974,7 +991,7 @@ timer_func_def(dremainder)(volatile double a, volatile double b) {
uint32_t t0 = *systick_ptr;
volatile double x = remainder(a, b);
uint32_t t1 = *systick_ptr;
return cycle_diff(t0, t1) - DOUBLE_INPUT_COST - DOUBLE_OUTPUT_COST;
return cycle_diff(t0, t1) - DOUBLE_INPUT_COST * 2 - DOUBLE_OUTPUT_COST;
}

timer_func_def(dremquo)(volatile double a, volatile double b) {
Expand All @@ -983,7 +1000,7 @@ timer_func_def(dremquo)(volatile double a, volatile double b) {
uint32_t t0 = *systick_ptr;
volatile double x = remquo(a, b, &c);
uint32_t t1 = *systick_ptr;
return cycle_diff(t0, t1) - DOUBLE_INPUT_COST - DOUBLE_OUTPUT_COST;
return cycle_diff(t0, t1) - DOUBLE_INPUT_COST * 2 - DOUBLE_OUTPUT_COST;
}

timer_func_def(dexp2)(volatile double a) {
Expand Down Expand Up @@ -1047,7 +1064,7 @@ timer_func_def(dpow)(volatile double a, volatile double b) {
uint32_t t0 = *systick_ptr;
volatile double x = pow(a, b);
uint32_t t1 = *systick_ptr;
return cycle_diff(t0, t1) - DOUBLE_INPUT_COST - DOUBLE_OUTPUT_COST;
return cycle_diff(t0, t1) - DOUBLE_INPUT_COST * 2 - DOUBLE_OUTPUT_COST;
}

timer_func_def(dcbrt)(volatile double a) {
Expand Down Expand Up @@ -1089,7 +1106,7 @@ timer_func_def(dhypot)(volatile double a, volatile double b) {
uint32_t t0 = *systick_ptr;
volatile double x = hypot(a, b);
uint32_t t1 = *systick_ptr;
return cycle_diff(t0, t1) - DOUBLE_INPUT_COST - DOUBLE_OUTPUT_COST;
return cycle_diff(t0, t1) - DOUBLE_INPUT_COST * 2 - DOUBLE_OUTPUT_COST;
}

timer_func_def(dasin)(volatile double a) {
Expand Down Expand Up @@ -1184,8 +1201,8 @@ timer_func_def(dasinh)(volatile double a) {
}

int main() {
stdio_init_all();
init_systick();
stdio_init_all();
#if PICO_C_COMPILER_IS_CLANG
printf("================= Clang - ");
#else
Expand Down
41 changes: 29 additions & 12 deletions test/pico_float_test/float_benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,17 @@
#endif

static void init_systick() {
#ifdef __riscv
// Stop, clear then start 64-bit RISC-V platform timer for boot timing
sio_hw->mtime_ctrl = 0;
sio_hw->mtime = 0;
sio_hw->mtimeh = 0;
sio_hw->mtime_ctrl = SIO_MTIME_CTRL_FULLSPEED_BITS | SIO_MTIME_CTRL_EN_BITS;
#else
systick_hw->csr = 0;
systick_hw->rvr = ARM_CPU_PREFIXED(SYST_RVR_RELOAD_BITS);
systick_hw->csr = ARM_CPU_PREFIXED(SYST_CSR_CLKSOURCE_BITS) | ARM_CPU_PREFIXED(SYST_CSR_ENABLE_BITS);
#endif
}

// Stop the compiler from constant-folding a hardware base pointer into the
Expand All @@ -25,18 +33,22 @@ static void init_systick() {
__opaque_ptr; \
})

static __force_inline uint32_t systick_value() {
return systick_hw->cvr;
}

static __force_inline io_ro_32 *systick_value_ptr() {
#ifdef __riscv
return &sio_hw->mtime;
#else
return __get_opaque_ptr(&systick_hw->cvr);
#endif
}

static int cycle_diff(uint32_t systick1, uint32_t systick2) {
#ifdef __riscv
return systick2 - systick1 - 1;
#else
static_assert(ARM_CPU_PREFIXED(SYST_CVR_CURRENT_LSB) == 0, "");
uint32_t shift = 32 - ARM_CPU_PREFIXED(SYST_CVR_CURRENT_MSB);
return (((int32_t)((systick1 << shift) - (systick2 << shift))) >> shift) - 1; // -1 since the second systick read costs one
#endif
}

#define timer_func_def(name) static __noinline int __not_in_flash_func(time_##name)
Expand Down Expand Up @@ -156,8 +168,13 @@ static float time_unary_int64_n_func(int (*timer)(int64_t, int32_t), int64_t *i6
// #pragma message("EMITS_VFP = " __XSTRING(EMITS_VFP))
// #pragma message("USING_HARD_FLOAT_ABI = " __XSTRING(USING_HARD_FLOAT_ABI))

#ifdef __riscv
#define LOAD_COST 1
#define STORE_COST 1
#else
#define LOAD_COST 2
#define STORE_COST 2
#endif

#define FLOAT_INPUT_COST LOAD_COST
#define FLOAT_OUTPUT_COST STORE_COST
Expand Down Expand Up @@ -902,7 +919,7 @@ timer_func_def(fcopysign)(volatile float a, volatile float b) {
uint32_t t0 = *systick_ptr;
volatile float x = copysignf(a, b);
uint32_t t1 = *systick_ptr;
return cycle_diff(t0, t1) - FLOAT_INPUT_COST - FLOAT_OUTPUT_COST;
return cycle_diff(t0, t1) - FLOAT_INPUT_COST * 2 - FLOAT_OUTPUT_COST;
}

timer_func_def(ftrunc)(volatile float a) {
Expand Down Expand Up @@ -942,7 +959,7 @@ timer_func_def(ffmod)(volatile float a, volatile float b) {
uint32_t t0 = *systick_ptr;
volatile float x = fmodf(a, b);
uint32_t t1 = *systick_ptr;
return cycle_diff(t0, t1) - FLOAT_INPUT_COST - FLOAT_OUTPUT_COST;
return cycle_diff(t0, t1) - FLOAT_INPUT_COST * 2 - FLOAT_OUTPUT_COST;
}

timer_func_def(fdrem)(volatile float a, volatile float b) {
Expand All @@ -954,7 +971,7 @@ timer_func_def(fdrem)(volatile float a, volatile float b) {
uint32_t t0 = *systick_ptr;
volatile float x = dremf(a, b);
uint32_t t1 = *systick_ptr;
return cycle_diff(t0, t1) - FLOAT_INPUT_COST - FLOAT_OUTPUT_COST;
return cycle_diff(t0, t1) - FLOAT_INPUT_COST * 2 - FLOAT_OUTPUT_COST;
#endif
}

Expand All @@ -963,7 +980,7 @@ timer_func_def(fremainder)(volatile float a, volatile float b) {
uint32_t t0 = *systick_ptr;
volatile float x = remainderf(a, b);
uint32_t t1 = *systick_ptr;
return cycle_diff(t0, t1) - FLOAT_INPUT_COST - FLOAT_OUTPUT_COST;
return cycle_diff(t0, t1) - FLOAT_INPUT_COST * 2 - FLOAT_OUTPUT_COST;
}

timer_func_def(fremquo)(volatile float a, volatile float b) {
Expand All @@ -972,7 +989,7 @@ timer_func_def(fremquo)(volatile float a, volatile float b) {
uint32_t t0 = *systick_ptr;
volatile float x = remquof(a, b, &c);
uint32_t t1 = *systick_ptr;
return cycle_diff(t0, t1) - FLOAT_INPUT_COST - FLOAT_OUTPUT_COST;
return cycle_diff(t0, t1) - FLOAT_INPUT_COST * 2 - FLOAT_OUTPUT_COST;
}

timer_func_def(fexp2)(volatile float a) {
Expand Down Expand Up @@ -1036,7 +1053,7 @@ timer_func_def(fpow)(volatile float a, volatile float b) {
uint32_t t0 = *systick_ptr;
volatile float x = powf(a, b);
uint32_t t1 = *systick_ptr;
return cycle_diff(t0, t1) - FLOAT_INPUT_COST - FLOAT_OUTPUT_COST;
return cycle_diff(t0, t1) - FLOAT_INPUT_COST * 2 - FLOAT_OUTPUT_COST;
}

timer_func_def(fcbrt)(volatile float a) {
Expand Down Expand Up @@ -1068,7 +1085,7 @@ timer_func_def(fhypot)(volatile float a, volatile float b) {
uint32_t t0 = *systick_ptr;
volatile float x = hypotf(a, b);
uint32_t t1 = *systick_ptr;
return cycle_diff(t0, t1) - FLOAT_INPUT_COST - FLOAT_OUTPUT_COST;
return cycle_diff(t0, t1) - FLOAT_INPUT_COST * 2 - FLOAT_OUTPUT_COST;
}

timer_func_def(fasin)(volatile float a) {
Expand Down Expand Up @@ -1129,8 +1146,8 @@ timer_func_def(fasinh)(volatile float a) {


int main() {
stdio_init_all();
init_systick();
stdio_init_all();
#if PICO_C_COMPILER_IS_CLANG
printf("================= Clang - ");
#else
Expand Down
Loading