This seems like a bad idea. Using integer comparisons over float data will actually result in a properly ordered array of floats, as @rlbond points out. (See http://www.h-schmidt.net/FloatConverter/IEEE754.html for playing with binary representations of floats.) Before using this, make sure sizeof(int32_t) == sizeof(float) .
Such a hack is not needed. Comparing a float not much more expensive than comparing int on modern hardware. (Intel Haswell: ucomiss - 1 microprocessor, with 1 bandwidth in each cycle. Comparison with the memory operand - 2 times, without micro-merging. And this can not be with a macro fuse, for example cmp/jcc ). However, FP add / sub and FP mul have higher delays than their integer equivalents and lower throughput. It seems silly to convert an entire array to a float , because you only write it because you want to do some FP math with the minimum and maximum values ββat the end.
The load-and-convert-int-to-float cvtsi2ss (x86 cvtsi2ss (single- cvtsi2ss single-digit integer with integer 2)) is about as fast and takes up the same code space as a regular load ( movss ).
If your data was originally integer, and you only use some of it, use int (avoiding conversion for values ββthat you will never need later). If you get access to everything, and only ever use your data as floats, save it as a float . If you use it as both, it is best to save it as an int , so it is faster if you use it as a whole, and at about the same speed when you use it as a float.
From your sample code, are you just using the values ββin the min and max positions? Finding the min and max values ββin an array is much faster than sorting the entire array. min / max is even vectorized with instructions with packed minimum values.
On many platforms, there is no such fast floating point as modern Intel processors, so do not go overboard with a floating point.
source share