Remove shift of signed int in src_float_to_short_array #86
Remove shift of signed int in src_float_to_short_array #86erikd merged 2 commits intolibsndfile:masterfrom
Conversation
Scale by -SHORT_MIN Clip if float is outside range of short Otherwise round and truncate (guaranteed to fit to short) Uses float instead of double as float can fit all 16 bit values
|
After this was merged: Would it make sense to do the same for Sidenote: Unfortunately using
Docu: http://www.cplusplus.com/reference/cmath/lrint/ |
|
How do we get the "truncating rounding conversion of float/double->int in a single instruction"? |
|
Simply use a plain cast. See the godbolt link for resulting assembly in comparison |
|
Does a plain cast have the same rounding behavior as |
|
Yes and no. A cast is truncating so the same as "round to zero". So if the rounding mode is set to Note however that this "round to nearest" is not guaranteed when you use A good read with comparisons on different archs: https://stackoverflow.com/a/37624488/1930508 |
Uses float instead of double as float can fit all 16 bit values.
Better alternative to approaches like #85, also adds test that show where e.g. janstary@ec07760 would fail.
Omits the clipping optimization which is normally disabled on x64 due to
longbeing 64bits.