On Thu, 2017-06-22 at 15:22 +0300, Seppo Ingalsuo wrote:
Thanks, that works. At least with the compiler that I use (http://alsa-project.org/main/index.php/Firmware) the optimizing
does
the conversion to fixed without increase of the firmware image size.
I
also checked from disassembly that this part of the code remains identical. I did a minor fix and added rounding into the macro
since
compiler doesn't round the cast to int:
#define TONE_FREQ(f) (int)((f) * (1 << 16)) /* f = float */
#define TONE_FREQ(f) (((int)((f) * (1 << 17)) + 1) >> 1) /* f = float */
Sorry, the rounded version overflows and depending on the way 20000 vs. 20000.0 as the parameter the compiler may even pass it silently. However this way the rounded Q16.16 conversion seems to work:
#define TONE_FREQ(f) (int)(((int64_t)((f) * 131072.0 + 1.0)) >> 1) /* f = float */
Best to make 131072.0 a macro too so easy to understand what it's doing.
We should also have this as our non optimal "generic" version and we should look to create arch specific macros (with inline assembler) later on (that take take of overflow or larger types).
Liam
--------------------------------------------------------------------- Intel Corporation (UK) Limited Registered No. 1134945 (England) Registered Office: Pipers Way, Swindon SN3 1RJ VAT No: 860 2173 47
This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.