From 4a9af002a141b37701afeeb135439019b5346dc1 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Sun, 7 Mar 2021 12:15:40 +0100 Subject: [PATCH] DISlord speed improvements --- plot.c | 115 ++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 77 insertions(+), 38 deletions(-) diff --git a/plot.c b/plot.c index f369db3..d8ed6f1 100644 --- a/plot.c +++ b/plot.c @@ -284,14 +284,16 @@ draw_on_strut(int v0, int d, int color) } #endif -#define SQRT_50 ((float)7.0710678118654) -#define LOG_10_SQRT_50 ((float)0.84948500216800) -#define POW_30_20 ((float) 0.215443469) -#define POW_SQRT ((float)0.2236067950725555419921875) -#define LOG_10_SQRT_50_x20_plus30 ((float)46.98970004336) -#define LOG_10_SQRT_50_x20_plus90 ((float)106.98970004336) -#define LOG_DIV_10 ((float)0.2302585093) -#define LOG_DIV_20 ((float)0.11512925465) +#define SQRT_50 ((float)7.0710678118654) // sqrt(50.0) +#define LOG_10_SQRT_50 ((float)0.84948500216800) // log10(sqrt(50.0)) +#define POW_SQRT ((float)0.2236067950725555419921875) // pow(10, -30.0/20.0) * sqrt(50.0) +#define LOG_10_SQRT_50_x20_plus30 ((float)46.98970004336) // 30.0 - 20.0*log10(sqrt(50.0)) +#define LOG_10_SQRT_50_x20_plus90 ((float)106.98970004336) // 90.0 - 20.0*log10(sqrt(50.0)) +#define LOG_DIV_10 ((float)0.2302585093) // multiplier = log(10.0)/10.0 +#define LOG_DIV_20 ((float)0.11512925465) // multiplier = log(10.0)/20.0 +#define DIV_LOG10_x20 ((float)8.6858896380650) // multiplier = 20.0 / log(10) +#define DIV_LOG10_x10 ((float)4.3429448190325) // multiplier = 10.0 / log(10) + /* * calculate log10f(abs(gamma)) */ @@ -307,18 +309,18 @@ value(const float v) switch(setting.unit) { case U_DBMV: -// return v + 30.0 + 20.0*log10f(sqrtf(50)); +// return v + 30.0 + 20.0*log10f(sqrtf(50)); return v + LOG_10_SQRT_50_x20_plus30; // + 30.0 + 20.0*LOG_10_SQRT_50; case U_DBUV: -// return v + 90.0 + 20.0*log10f(sqrtf(50.0)); +// return v + 90.0 + 20.0*log10f(sqrtf(50.0)); return v + LOG_10_SQRT_50_x20_plus90; // 90.0 + 20.0*LOG_10_SQRT_50; case U_VOLT: // return powf(10.0, (v-30.0)/20.0) * sqrtf(50.0); // return powf(10.0, (v-30.0)/20.0) * SQRT_50; // powf(10.0,v/20.0) * powf(10, -30.0/20.0) * sqrtf(50) return expf(v*LOG_DIV_20) * POW_SQRT; // expf(v*logf(10.0)/20.0) * powf(10, -30.0/20.0) * sqrtf(50) case U_WATT: -// return powf(10.0, v/10.0)/1000.0; // powf(10, v/10.0)/1000.0 = expf(v*logf(10.0)/10.0)/1000.0 - return expf(v*LOG_DIV_10)/1000.0; // +// return powf(10.0, v/10.0)/1000.0; // powf(10, v/10.0)/1000.0 = expf(v*logf(10.0)/10.0)/1000.0 + return expf(v*LOG_DIV_10) / 1000.0; // } // case U_DBM: return v; // raw data is in logmag*10 format @@ -336,30 +338,66 @@ to_dBm(const float v) // return v - 90.0 - 20.0*log10f(sqrtf(50.0)); //TODO convert constants to single float number as GCC compiler does runtime calculation return v - LOG_10_SQRT_50_x20_plus90; // (90.0 + 20.0*LOG_10_SQRT_50); case U_VOLT: -// return log10f( v / (sqrtf(50.0))) * 20.0 + 30.0 ; - return log10f( v / SQRT_50) * 20.0 + 30.0 ; +// return log10f( v / (sqrtf(50.0))) * 20.0 + 30.0; +// return log10f( v / SQRT_50) * 20.0 + 30.0; + return logf(v / SQRT_50) * DIV_LOG10_x20 + 30.0; // logf(v / SQRT_50) * 20.0 / logf(10) + 30.0 case U_WATT: - return log10f(v*1000.0)*10.0; +// return log10f(v*1000.0)*10.0; + return logf(v*1000.0) * DIV_LOG10_x10; // logf(v*1000.0) * 10.0 / logf(10) } // case U_DBM: return v; // raw data is in logmag*10 format } -static inline index_x_t -trace_into_index_x(int i){ - return (i * (WIDTH) + (sweep_points-1)/2) / (sweep_points-1) + CELLOFFSETX; +static void +trace_into_index_x_array(index_x_t *x, uint16_t points){ + // Not need update if index calculated for this points count + static uint16_t old_points = 0; + if (old_points == points) return; + old_points = points; + points-=1; + for (int i=0; i<= points;i++) + x[i] = (i * WIDTH + (points>>1)) / points + CELLOFFSETX; } -static index_y_t -trace_into_index_y(float coeff) +// +// Optimized by speed/size array processing of value(const float v) function +// on screen need calculate as: +// y = (ref-v)/scale +// and align by top/bottom +static void +trace_into_index_y_array(index_y_t *y, float *array, int points) { - float refpos = get_trace_refpos(); - float scale = get_trace_scale(); - float v = (refpos - value(coeff)) / scale; - if (v < 0) v = 0; - if (v > NGRIDY) v = NGRIDY; - - return float2int(v * GRIDY); + float scale = GRIDY / get_trace_scale(); + float ref = get_trace_refpos(); + float mult = 0, vmult = 1.0; + float ref_shift = 0; + switch (setting.unit){ + case U_DBM: break; + case U_DBMV: ref_shift = LOG_10_SQRT_50_x20_plus30;break; + case U_DBUV: ref_shift = LOG_10_SQRT_50_x20_plus90;break; + case U_VOLT: vmult = POW_SQRT; mult = LOG_DIV_20;break; + case U_WATT: vmult = 0.001; mult = LOG_DIV_10;break; + default: + return; + } + // Universal formula look like this: + // v = (refpos - (mult ? expf(value*mult) : value) - ref_shift) * vmult) * scale; + // v = ((refpos - ref_shift) * scale) - (mult ? expf(value*mult) : value) * (vmult * scale) + // Made precalculated constants: + ref = (ref - ref_shift) * scale + 0.5; // add 0.5 for floor on int convert + scale = scale * vmult; + int max = NGRIDY * GRIDY, i; + for (i=0;i max) v = max; + y[i] = v; + } + return; } void trace_get_value_string( // Only used at one place @@ -431,8 +469,10 @@ void trace_get_value_string( // Only used at one place } #endif v = value(coeff[i]); - if (mtype & M_NOISE) - v = v - 10*log10f(actual_rbw_x10*100.0); + if (mtype & M_NOISE){ +// v-= log10f(actual_rbw_x10*100.0) * 10.0; + v-= logf(actual_rbw_x10*100.0) * DIV_LOG10_x10; + } if (v == -INFINITY) plot_printf(buf, len, "-INF"); else { @@ -516,7 +556,9 @@ markmap_upperarea(void) } static uint16_t get_trigger_level(void){ - return trace_into_index_y(setting.trigger_level); + index_y_t trigger; + trace_into_index_y_array(&trigger, &setting.trigger_level, 1); + return trigger; } static inline void @@ -816,22 +858,19 @@ search_nearest_index(int x, int y, int t) void plot_into_index(measurement_t measured) { - int t, i; + int t; // START_PROFILE - index_x_t *index_x = trace_index_x; - for (i = 0; i < sweep_points; i++) - index_x[i] = trace_into_index_x(i); - + trace_into_index_x_array(trace_index_x, sweep_points); for (t = 0; t < TRACES_MAX; t++) { if (!trace[t].enabled) continue; - index_y_t *index_y = trace_index_y[t]; - for (i = 0; i < sweep_points; i++) - index_y[i] = trace_into_index_y(measured[t][i]); + trace_into_index_y_array(trace_index_y[t], measured[t], sweep_points); } // STOP_PROFILE +// START_PROFILE mark_cells_from_index(); markmap_all_markers(); +// STOP_PROFILE } static void