diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-12-13 11:17:58 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2018-02-06 01:28:16 +0000 |
commit | fd80b8aaeb836811113cb06f8965e4b2f0deaeff (patch) | |
tree | 392b641c480e381d9c45c869b2f42d43830dae13 /src/gui/painting/qdrawhelper_p.h | |
parent | 076087717e4b6ee0953902b24676e54a73ff5fff (diff) |
Unalias some core drawhelper loops
Some compilers will assume src and buffer are different and only
vectorize the unaliased case and take a slow path when they are equal.
In our case they are as often equal, so we need to manually unalias the
variables to make sure both cases are fully optimized.
Change-Id: I6ec86171dd179844facdf45376253c55980d9e36
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/gui/painting/qdrawhelper_p.h')
-rw-r--r-- | src/gui/painting/qdrawhelper_p.h | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/gui/painting/qdrawhelper_p.h b/src/gui/painting/qdrawhelper_p.h index 4c2fe87355..ebf215a3eb 100644 --- a/src/gui/painting/qdrawhelper_p.h +++ b/src/gui/painting/qdrawhelper_p.h @@ -1104,22 +1104,30 @@ inline int qBlue565(quint16 rgb) { return (b << 3) | (b >> 2); } +// We manually unalias the variables to make sure the compiler +// fully optimizes both aliased and unaliased cases. +#define UNALIASED_CONVERSION_LOOP(buffer, src, count, conversion) \ + if (src == buffer) { \ + for (int i = 0; i < count; ++i) \ + buffer[i] = conversion(buffer[i]); \ + } else { \ + for (int i = 0; i < count; ++i) \ + buffer[i] = conversion(src[i]); \ + } + static Q_ALWAYS_INLINE const uint *qt_convertARGB32ToARGB32PM(uint *buffer, const uint *src, int count) { - for (int i = 0; i < count; ++i) - buffer[i] = qPremultiply(src[i]); + UNALIASED_CONVERSION_LOOP(buffer, src, count, qPremultiply); return buffer; } static Q_ALWAYS_INLINE const uint *qt_convertRGBA8888ToARGB32PM(uint *buffer, const uint *src, int count) { - for (int i = 0; i < count; ++i) - buffer[i] = qPremultiply(RGBA2ARGB(src[i])); + UNALIASED_CONVERSION_LOOP(buffer, src, count, [](uint s) { return qPremultiply(RGBA2ARGB(s));}); return buffer; } - const uint qt_bayer_matrix[16][16] = { { 0x1, 0xc0, 0x30, 0xf0, 0xc, 0xcc, 0x3c, 0xfc, 0x3, 0xc3, 0x33, 0xf3, 0xf, 0xcf, 0x3f, 0xff}, |