48 #include <px4_platform_common/px4_config.h>    49 #include <px4_platform_common/micro_hal.h>    55 #include <nuttx/irq.h>    56 static irqstate_t flags;
    62     flags = px4_enter_critical_section();
    69     px4_leave_critical_section(flags);
    73 #define PERF(name, op, count) do { \    76         perf_counter_t p = perf_alloc(PC_ELAPSED, name); \    77         for (int i = 0; i < count; i++) { \    85         perf_print_counter(p); \    92     virtual bool run_tests();
    95     bool time_single_precision_float();
    96     bool time_single_precision_float_trig();
    98     bool time_double_precision_float();
    99     bool time_double_precision_float_trig();
   101     bool time_8bit_integers();
   102     bool time_16bit_integers();
   103     bool time_32bit_integers();
   104     bool time_64bit_integers();
   130 bool MicroBenchMath::run_tests()
   141     return (_tests_failed == 0);
   147     const T scale = rand() / (T) RAND_MAX; 
   148     return min + scale * (max - 
min);      
   153     srand(time(
nullptr));
   157     f32_out = 
random(-2.0
f * M_PI, 2.0
f * M_PI);
   159     f64 = 
random(-2.0 * M_PI, 2.0 * M_PI);
   160     f64_out = 
random(-2.0 * M_PI, 2.0 * M_PI);
   180 bool MicroBenchMath::time_single_precision_float()
   182     PERF(
"float add", f32_out += f32, 1000);
   183     PERF(
"float sub", f32_out -= f32, 1000);
   184     PERF(
"float mul", f32_out *= f32, 1000);
   185     PERF(
"float div", f32_out /= f32, 1000);
   186     PERF(
"float sqrt", f32_out = sqrtf(f32), 1000);
   191 bool MicroBenchMath::time_single_precision_float_trig()
   193     PERF(
"sinf()", f32_out = sinf(f32), 1000);
   194     PERF(
"cosf()", f32_out = cosf(f32), 1000);
   195     PERF(
"tanf()", f32_out = tanf(f32), 1000);
   197     PERF(
"acosf()", f32_out = acosf(f32), 1000);
   198     PERF(
"asinf()", f32_out = asinf(f32), 1000);
   199     PERF(
"atan2f()", f32_out = atan2f(f32, 2.0
f * f32), 1000);
   204 bool MicroBenchMath::time_double_precision_float()
   206     PERF(
"double add", f64_out += f64, 1000);
   207     PERF(
"double sub", f64_out -= f64, 1000);
   208     PERF(
"double mul", f64_out *= f64, 1000);
   209     PERF(
"double div", f64_out /= f64, 1000);
   210     PERF(
"double sqrt", f64_out = 
sqrt(f64), 1000);
   215 bool MicroBenchMath::time_double_precision_float_trig()
   217     PERF(
"sin()", f64_out = 
sin(f64), 1000);
   218     PERF(
"cos()", f64_out = 
cos(f64), 1000);
   219     PERF(
"tan()", f64_out = 
tan(f64), 1000);
   221     PERF(
"acos()", f64_out = 
acos(f64 * 0.5), 1000);
   222     PERF(
"asin()", f64_out = 
asin(f64 * 0.6), 1000);
   223     PERF(
"atan2()", f64_out = 
atan2(f64 * 0.7, f64 * 0.8), 1000);
   225     PERF(
"sqrt()", f64_out = 
sqrt(f64), 1000);
   231 bool MicroBenchMath::time_8bit_integers()
   233     PERF(
"int8 add", i_8_out += i_8, 1000);
   234     PERF(
"int8 sub", i_8_out -= i_8, 1000);
   235     PERF(
"int8 mul", i_8_out *= i_8, 1000);
   236     PERF(
"int8 div", i_8_out /= i_8, 1000);
   241 bool MicroBenchMath::time_16bit_integers()
   243     PERF(
"int16 add", i_16_out += i_16, 1000);
   244     PERF(
"int16 sub", i_16_out -= i_16, 1000);
   245     PERF(
"int16 mul", i_16_out *= i_16, 1000);
   246     PERF(
"int16 div", i_16_out /= i_16, 1000);
   251 bool MicroBenchMath::time_32bit_integers()
   253     PERF(
"int32 add", i_32_out += i_32, 1000);
   254     PERF(
"int32 sub", i_32_out -= i_32, 1000);
   255     PERF(
"int32 mul", i_32_out *= i_32, 1000);
   256     PERF(
"int32 div", i_32_out /= i_32, 1000);
   261 bool MicroBenchMath::time_64bit_integers()
   263     PERF(
"int64 add", i_64_out += i_64, 1000);
   264     PERF(
"int64 sub", i_64_out -= i_64, 1000);
   265     PERF(
"int64 mul", i_64_out *= i_64, 1000);
   266     PERF(
"int64 div", i_64_out /= i_64, 1000);
 Dual< Scalar, N > acos(const Dual< Scalar, N > &a)
 
int test_microbench_math(int argc, char *argv[])
 
int reset(enum LPS22HB_BUS busid)
Reset the driver. 
 
Dual< Scalar, N > asin(const Dual< Scalar, N > &a)
 
Base class to be used for unit tests. 
 
High-resolution timer with callouts and timekeeping. 
 
ut_declare_test_c(test_microbench_math, MicroBenchMath) bool MicroBenchMath
 
Dual< Scalar, N > cos(const Dual< Scalar, N > &a)
 
Vector< float, 6 > f(float t, const Matrix< float, 6, 1 > &, const Matrix< float, 3, 1 > &)
 
#define PERF(name, op, count)
 
Dual< Scalar, N > tan(const Dual< Scalar, N > &a)
 
constexpr _Tp min(_Tp a, _Tp b)
 
constexpr _Tp max(_Tp a, _Tp b)
 
#define ut_run_test(test)
Runs a single unit test. 
 
Dual< Scalar, N > sin(const Dual< Scalar, N > &a)
 
Dual< Scalar, N > sqrt(const Dual< Scalar, N > &a)
 
Dual< Scalar, N > atan2(const Dual< Scalar, N > &a, const Dual< Scalar, N > &b)
 
Performance measuring tools.