Skip to content

Commit 7c81174

Browse files
committed
Filter: use direct float cast instead of i2f helper
_i2f is a compatibility shim for `(float)` for pre-2015 versions of GCC (added in 2017 in ef1df61). Compilers can presumably optimize `(float)` better than an inline function call. The helper is then unused and removed.
1 parent 0975cdd commit 7c81174

2 files changed

Lines changed: 9 additions & 25 deletions

File tree

src/libImaging/Filter.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,20 +113,18 @@ kernel_i16(int size, UINT8 *in0, int x, const float *kernel, int bigendian) {
113113
int half_size = (size - 1) / 2;
114114
for (i = 0; i < size; i++) {
115115
int x1 = x + i - half_size;
116-
result += _i2f(
117-
in0[x1 * 2 + (bigendian ? 1 : 0)] +
118-
(in0[x1 * 2 + (bigendian ? 0 : 1)] >> 8)
119-
) *
116+
result += (float)(in0[x1 * 2 + (bigendian ? 1 : 0)] +
117+
(in0[x1 * 2 + (bigendian ? 0 : 1)] >> 8)) *
120118
kernel[i];
121119
}
122120
return result;
123121
}
124122

125123
static void
126124
ImagingFilter3x3(Imaging imOut, Imaging im, const float *kernel, float offset) {
127-
#define KERNEL1x3(in0, x, kernel, d) \
128-
(_i2f(in0[x - d]) * (kernel)[0] + _i2f(in0[x]) * (kernel)[1] + \
129-
_i2f(in0[x + d]) * (kernel)[2])
125+
#define KERNEL1x3(in0, x, kernel, d) \
126+
((float)(in0[x - d]) * (kernel)[0] + (float)(in0[x]) * (kernel)[1] + \
127+
(float)(in0[x + d]) * (kernel)[2])
130128

131129
int x = 0, y = 0;
132130
// restrict safety: assert im and imOut to be separate,
@@ -275,10 +273,10 @@ ImagingFilter3x3(Imaging imOut, Imaging im, const float *kernel, float offset) {
275273

276274
static void
277275
ImagingFilter5x5(Imaging imOut, Imaging im, const float *kernel, float offset) {
278-
#define KERNEL1x5(in0, x, kernel, d) \
279-
(_i2f(in0[x - d - d]) * (kernel)[0] + _i2f(in0[x - d]) * (kernel)[1] + \
280-
_i2f(in0[x]) * (kernel)[2] + _i2f(in0[x + d]) * (kernel)[3] + \
281-
_i2f(in0[x + d + d]) * (kernel)[4])
276+
#define KERNEL1x5(in0, x, kernel, d) \
277+
((float)(in0[x - d - d]) * (kernel)[0] + (float)(in0[x - d]) * (kernel)[1] + \
278+
(float)(in0[x]) * (kernel)[2] + (float)(in0[x + d]) * (kernel)[3] + \
279+
(float)(in0[x + d + d]) * (kernel)[4])
282280

283281
int x = 0, y = 0;
284282

src/libImaging/ImagingUtils.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,3 @@
2828
#define CLIP8(v) ((v) <= 0 ? 0 : (v) < 256 ? (v) : 255)
2929

3030
#define CLIP16(v) ((v) <= 0 ? 0 : (v) < 65536 ? (v) : 65535)
31-
32-
/* This is to work around a bug in GCC prior 4.9 in 64 bit mode.
33-
GCC generates code with partial dependency which is 3 times slower.
34-
See: https://stackoverflow.com/a/26588074/253146 */
35-
#if defined(__x86_64__) && defined(__SSE__) && !defined(__NO_INLINE__) && \
36-
!defined(__clang__) && defined(GCC_VERSION) && (GCC_VERSION < 40900)
37-
static float __attribute__((always_inline)) inline _i2f(int v) {
38-
float x;
39-
__asm__("xorps %0, %0; cvtsi2ss %1, %0" : "=x"(x) : "r"(v));
40-
return x;
41-
}
42-
#else
43-
static float inline _i2f(int v) { return (float)v; }
44-
#endif

0 commit comments

Comments
 (0)