3#ifndef PRINTLINES_ALLOWED
4#define PRINTLINES_ALLOWED 0
7static const char *FNAME =
"kest_fixed_point.c";
11 if (shift < 0 || shift > 17)
return 0;
13 int n = (18 - 1) - shift;
15 float scale = ldexpf(1.0f, n);
17 float max = (float)((1 << (18 - 1)) - 1) / scale;
18 float min = -(float)(1 << (18 - 1)) / scale;
23 return lrintf(x * scale);
32 float scale = (float)(1 << n);
46 if (x >= 0.999969482421875f)
return 32767;
47 if (x <= -1.0f)
return -32768;
49 return (int16_t)lrintf(x * 32768.0f);
72 p2 = ldexpf(1.0, format);
73 p2_r = ldexp(1.0, -(width - 1 - format));
74 if (min >= -p2 && max < p2 - p2_r)
79 kest_string_appendf(&
string,
"therefore, it requires format q%d.%d\n", 1 + format, width - 1 - format);
92 KEST_PRINTF(
"Compute format for filter %p\n", filter);
99 for (
int i = 0; i < filter->
coefs.count; i++)
102 format = (current_format > format) ? current_format : format;
105 KEST_PRINTF(
"Filter format: q%d.%d\n", 1 + format, 18 - format);
void kest_free(void *ptr)
kest_interval kest_expression_compute_range(kest_expression *expr, kest_expr_scope *scope)
const char * kest_expression_to_string(kest_expression *expr)
kest_fpga_sample_t float_to_q_nminus1(float x, int shift)
int16_t float_to_q15(float x)
int32_t float_to_q_nminus1_18bit(float x, int shift)
int kest_expression_compute_format(kest_expression *expr, kest_expr_scope *scope, int fmax, int width)
int kest_filter_compute_format(kest_filter *filter, kest_expr_scope *scope)
#define KEST_FPGA_DATA_WIDTH
#define KEST_FPGA_FILTER_WIDTH
int16_t kest_fpga_sample_t
char * kest_string_to_native(kest_string *string)
int kest_string_appendf(kest_string *string, const char *fmt,...)
int kest_string_init(kest_string *string)
int kest_string_destroy(kest_string *string)
struct kest_expression_ptr_list coefs