Add loongarch64(LASX) optimization

List of optimized implementations using LASX:
-qt_convert_rgb888_to_rgb32
-qt_blend_rgb32_on_rgb32
-qt_blend_argb32_on_argb32
-comp_func_Source
-comp_func_SourceOver
-comp_func_solid_SourceOver
-comp_func_Source_rgb64
-comp_func_solid_SourceOver_rgb64
-fetchTransformedBilinearARGB32PM_simple_scale_helper
-fetchTransformedBilinearARGB32PM_downscale_helper
-fetchTransformedBilinearARGB32PM_fast_rotate_helper
-convertARGB32ToARGB32PM
-convertRGBA8888ToARGB32PM
-fetchARGB32ToARGB32PM
-fetchRGBA8888ToARGB32PM
-convertARGB32ToRGBA64PM
-convertRGBA8888ToRGBA64PM
-fetchARGB32ToRGBA64PM
-fetchRGBA8888ToRGBA64PM

Change-Id: I7a0859e4c780fd94f033440009645aa4c12c29f4
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Chen Zhanwang 2024-08-30 10:44:21 +08:00
parent f9185516eb
commit 0b155e9ea2
7 changed files with 1571 additions and 1 deletions

View File

@ -664,6 +664,12 @@ qt_internal_add_simd_part(Gui SIMD lsx
painting/qimagescale_lsx.cpp
)
qt_internal_add_simd_part(Gui SIMD lasx
SOURCES
image/qimage_lasx.cpp
painting/qdrawhelper_lasx.cpp
)
if(NOT ANDROID)
qt_internal_add_simd_part(Gui SIMD mips_dsp
SOURCES

View File

@ -2780,6 +2780,18 @@ static void qInitImageConversions()
}
#endif
#if defined(QT_COMPILER_SUPPORTS_LASX)
if (qCpuHasFeature(LASX)) {
extern void convert_RGB888_to_RGB32_lasx(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags);
qimage_converter_map[QImage::Format_RGB888][QImage::Format_RGB32] = convert_RGB888_to_RGB32_lasx;
qimage_converter_map[QImage::Format_RGB888][QImage::Format_ARGB32] = convert_RGB888_to_RGB32_lasx;
qimage_converter_map[QImage::Format_RGB888][QImage::Format_ARGB32_Premultiplied] = convert_RGB888_to_RGB32_lasx;
qimage_converter_map[QImage::Format_BGR888][QImage::Format_RGBX8888] = convert_RGB888_to_RGB32_lasx;
qimage_converter_map[QImage::Format_BGR888][QImage::Format_RGBA8888] = convert_RGB888_to_RGB32_lasx;
qimage_converter_map[QImage::Format_BGR888][QImage::Format_RGBA8888_Premultiplied] = convert_RGB888_to_RGB32_lasx;
}
#endif
#if defined(__ARM_NEON__)
extern void convert_RGB888_to_RGB32_neon(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags);
qimage_converter_map[QImage::Format_RGB888][QImage::Format_RGB32] = convert_RGB888_to_RGB32_neon;

View File

@ -0,0 +1,112 @@
// Copyright (C) 2024 Loongson Technology Corporation Limited.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include <qimage.h>
#include <private/qimage_p.h>
#include <private/qsimd_p.h>
#ifdef QT_COMPILER_SUPPORTS_LASX
QT_BEGIN_NAMESPACE
// Convert a scanline of RGB888 (src) to RGB32 (dst)
// src must be at least len * 3 bytes
// dst must be at least len * 4 bytes
Q_GUI_EXPORT void QT_FASTCALL qt_convert_rgb888_to_rgb32_lasx(quint32 *dst, const uchar *src, int len)
{
int i = 0;
// Prologue, align dst to 32 bytes.
ALIGNMENT_PROLOGUE_32BYTES(dst, i, len) {
dst[i] = qRgb(src[0], src[1], src[2]);
src += 3;
}
// Mask 8 colors of the RGB888 vector
const __m256i shuffleMask1 = (__m256i)(v32i8){2, 1, 0, 16, 5, 4, 3, 16, 8, 7, 6, 16, 11, 10, 9, 16,
30, 29, 28, 16, 1, 0, 31, 16, 4, 3, 2, 16, 7, 6, 5, 16};
// Mask 8 colors of a RGB888 vector with an offset of shuffleMask1
const __m256i shuffleMask2 = (__m256i)(v32i8){10, 9, 8, 0, 13, 12, 11, 0, 16, 15, 14, 0, 19, 18, 17, 0,
6, 5, 4, 0, 9, 8, 7, 0, 12, 11, 10, 0, 15, 14, 13, 0};
const __m256i alphaMask = __lasx_xvreplgr2vr_w(0xff000000);
const __m256i *inVectorPtr = (const __m256i *)src;
__m256i *dstVectorPtr = (__m256i *)(dst + i);
for (; i < (len - 31); i += 32) { // one iteration in the loop converts 32 pixels
/*
RGB888 has 10 pixels per vector, + 2 byte from the next pixel. The idea here is
to load vectors of RGB888 and use palignr to select a vector out of two vectors.
After 3 loads of RGB888 and 3 stores of RGB32, we have 8 pixels left in the last
vector of RGB888, we can mask it directly to get a last store or RGB32. After that,
the first next byte is a R, and we can loop for the next 32 pixels.
The conversion itself is done with a byte permutation (xvshuf_b and xvpermi_q).
*/
__m256i firstSrcVector = __lasx_xvld(inVectorPtr, 0);
__m256i rFirstSrcVector = __lasx_xvpermi_q(firstSrcVector, firstSrcVector, 0b00000001);
__m256i outputVector = __lasx_xvshuf_b(rFirstSrcVector, firstSrcVector, shuffleMask1);
__lasx_xvst(__lasx_xvor_v(outputVector, alphaMask), dstVectorPtr, 0);
++inVectorPtr;
++dstVectorPtr;
// There are 8 unused bytes left in srcVector, we need to load the next 32 bytes
// and load the next input with palignr
__m256i secondSrcVector = __lasx_xvld(inVectorPtr, 0);
__m256i srcVector = __lasx_xvpermi_q(secondSrcVector, firstSrcVector, 0b00100001);
__m256i rSrcVector = __lasx_xvpermi_q(srcVector, srcVector, 0b00000001);
outputVector = __lasx_xvshuf_b(rSrcVector, srcVector, shuffleMask2);
__lasx_xvst(__lasx_xvor_v(outputVector, alphaMask), dstVectorPtr, 0);
++inVectorPtr;
++dstVectorPtr;
// We now have 16 unused bytes left in firstSrcVector
__m256i thirdSrcVector = __lasx_xvld(inVectorPtr, 0);
srcVector = __lasx_xvpermi_q(thirdSrcVector, secondSrcVector, 0b00100001);
rSrcVector = __lasx_xvpermi_q(srcVector, srcVector, 0b00000001);
outputVector = __lasx_xvshuf_b(rSrcVector, srcVector, shuffleMask1);
__lasx_xvst(__lasx_xvor_v(outputVector, alphaMask), dstVectorPtr, 0);
++inVectorPtr;
++dstVectorPtr;
// There are now 24 unused bytes in firstSrcVector.
// We can mask them directly, almost there.
srcVector = thirdSrcVector;
rSrcVector = __lasx_xvpermi_q(srcVector, srcVector, 0b00000001);
outputVector = __lasx_xvshuf_b(rSrcVector, srcVector, shuffleMask2);
__lasx_xvst(__lasx_xvor_v(outputVector, alphaMask), dstVectorPtr, 0);
++dstVectorPtr;
}
src = (const uchar *)inVectorPtr;
SIMD_EPILOGUE(i, len, 31) {
dst[i] = qRgb(src[0], src[1], src[2]);
src += 3;
}
}
void convert_RGB888_to_RGB32_lasx(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags)
{
Q_ASSERT(src->format == QImage::Format_RGB888 || src->format == QImage::Format_BGR888);
if (src->format == QImage::Format_BGR888)
Q_ASSERT(dest->format == QImage::Format_RGBX8888 || dest->format == QImage::Format_RGBA8888 || dest->format == QImage::Format_RGBA8888_Premultiplied);
else
Q_ASSERT(dest->format == QImage::Format_RGB32 || dest->format == QImage::Format_ARGB32 || dest->format == QImage::Format_ARGB32_Premultiplied);
Q_ASSERT(src->width == dest->width);
Q_ASSERT(src->height == dest->height);
const uchar *src_data = (uchar *) src->data;
quint32 *dest_data = (quint32 *) dest->data;
for (int i = 0; i < src->height; ++i) {
qt_convert_rgb888_to_rgb32_lasx(dest_data, src_data, src->width);
src_data += src->bytes_per_line;
dest_data = (quint32 *)((uchar*)dest_data + dest->bytes_per_line);
}
}
QT_END_NAMESPACE
#endif // QT_COMPILER_SUPPORTS_LASX

View File

@ -1,4 +1,4 @@
// Copyright (C) 2016 The Qt Company Ltd.
// Copyright (C) 2024 Loongson Technology Corporation Limited.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include <qimage.h>

View File

@ -6987,6 +6987,73 @@ static void qInitDrawhelperFunctions()
qStoreFromRGBA32F[QImage::Format_RGBA32FPx4] = storeRGBA32FFromRGBA32F_lsx;
#endif // QT_CONFIG(raster_fp)
}
#if defined(QT_COMPILER_SUPPORTS_LASX)
if (qCpuHasFeature(LASX)) {
qt_memfill32 = qt_memfill32_lasx;
qt_memfill64 = qt_memfill64_lasx;
extern void qt_blend_rgb32_on_rgb32_lasx(uchar *destPixels, int dbpl,
const uchar *srcPixels, int sbpl,
int w, int h, int const_alpha);
extern void qt_blend_argb32_on_argb32_lasx(uchar *destPixels, int dbpl,
const uchar *srcPixels, int sbpl,
int w, int h, int const_alpha);
qBlendFunctions[QImage::Format_RGB32][QImage::Format_RGB32] = qt_blend_rgb32_on_rgb32_lasx;
qBlendFunctions[QImage::Format_ARGB32_Premultiplied][QImage::Format_RGB32] = qt_blend_rgb32_on_rgb32_lasx;
qBlendFunctions[QImage::Format_RGB32][QImage::Format_ARGB32_Premultiplied] = qt_blend_argb32_on_argb32_lasx;
qBlendFunctions[QImage::Format_ARGB32_Premultiplied][QImage::Format_ARGB32_Premultiplied] = qt_blend_argb32_on_argb32_lasx;
qBlendFunctions[QImage::Format_RGBX8888][QImage::Format_RGBX8888] = qt_blend_rgb32_on_rgb32_lasx;
qBlendFunctions[QImage::Format_RGBA8888_Premultiplied][QImage::Format_RGBX8888] = qt_blend_rgb32_on_rgb32_lasx;
qBlendFunctions[QImage::Format_RGBX8888][QImage::Format_RGBA8888_Premultiplied] = qt_blend_argb32_on_argb32_lasx;
qBlendFunctions[QImage::Format_RGBA8888_Premultiplied][QImage::Format_RGBA8888_Premultiplied] = qt_blend_argb32_on_argb32_lasx;
extern void QT_FASTCALL comp_func_Source_lasx(uint *destPixels, const uint *srcPixels, int length, uint const_alpha);
extern void QT_FASTCALL comp_func_SourceOver_lasx(uint *destPixels, const uint *srcPixels, int length, uint const_alpha);
extern void QT_FASTCALL comp_func_solid_SourceOver_lasx(uint *destPixels, int length, uint color, uint const_alpha);
qt_functionForMode_C[QPainter::CompositionMode_Source] = comp_func_Source_lasx;
qt_functionForMode_C[QPainter::CompositionMode_SourceOver] = comp_func_SourceOver_lasx;
qt_functionForModeSolid_C[QPainter::CompositionMode_SourceOver] = comp_func_solid_SourceOver_lasx;
#if QT_CONFIG(raster_64bit)
extern void QT_FASTCALL comp_func_Source_rgb64_lasx(QRgba64 *destPixels, const QRgba64 *srcPixels, int length, uint const_alpha);
extern void QT_FASTCALL comp_func_solid_SourceOver_rgb64_lasx(QRgba64 *destPixels, int length, QRgba64 color, uint const_alpha);
qt_functionForMode64_C[QPainter::CompositionMode_Source] = comp_func_Source_rgb64_lasx;
qt_functionForModeSolid64_C[QPainter::CompositionMode_SourceOver] = comp_func_solid_SourceOver_rgb64_lasx;
#endif
extern void QT_FASTCALL fetchTransformedBilinearARGB32PM_simple_scale_helper_lasx(uint *b, uint *end, const QTextureData &image,
int &fx, int &fy, int fdx, int /*fdy*/);
extern void QT_FASTCALL fetchTransformedBilinearARGB32PM_downscale_helper_lasx(uint *b, uint *end, const QTextureData &image,
int &fx, int &fy, int fdx, int /*fdy*/);
extern void QT_FASTCALL fetchTransformedBilinearARGB32PM_fast_rotate_helper_lasx(uint *b, uint *end, const QTextureData &image,
int &fx, int &fy, int fdx, int fdy);
bilinearFastTransformHelperARGB32PM[0][SimpleScaleTransform] = fetchTransformedBilinearARGB32PM_simple_scale_helper_lasx;
bilinearFastTransformHelperARGB32PM[0][DownscaleTransform] = fetchTransformedBilinearARGB32PM_downscale_helper_lasx;
bilinearFastTransformHelperARGB32PM[0][FastRotateTransform] = fetchTransformedBilinearARGB32PM_fast_rotate_helper_lasx;
extern void QT_FASTCALL convertARGB32ToARGB32PM_lasx(uint *buffer, int count, const QList<QRgb> *);
extern void QT_FASTCALL convertRGBA8888ToARGB32PM_lasx(uint *buffer, int count, const QList<QRgb> *);
extern const uint *QT_FASTCALL fetchARGB32ToARGB32PM_lasx(uint *buffer, const uchar *src, int index, int count,
const QList<QRgb> *, QDitherInfo *);
extern const uint *QT_FASTCALL fetchRGBA8888ToARGB32PM_lasx(uint *buffer, const uchar *src, int index, int count,
const QList<QRgb> *, QDitherInfo *);
qPixelLayouts[QImage::Format_ARGB32].fetchToARGB32PM = fetchARGB32ToARGB32PM_lasx;
qPixelLayouts[QImage::Format_ARGB32].convertToARGB32PM = convertARGB32ToARGB32PM_lasx;
qPixelLayouts[QImage::Format_RGBA8888].fetchToARGB32PM = fetchRGBA8888ToARGB32PM_lasx;
qPixelLayouts[QImage::Format_RGBA8888].convertToARGB32PM = convertRGBA8888ToARGB32PM_lasx;
extern const QRgba64 * QT_FASTCALL convertARGB32ToRGBA64PM_lasx(QRgba64 *, const uint *, int, const QList<QRgb> *, QDitherInfo *);
extern const QRgba64 * QT_FASTCALL convertRGBA8888ToRGBA64PM_lasx(QRgba64 *, const uint *, int count, const QList<QRgb> *, QDitherInfo *);
extern const QRgba64 *QT_FASTCALL fetchARGB32ToRGBA64PM_lasx(QRgba64 *, const uchar *, int, int, const QList<QRgb> *, QDitherInfo *);
extern const QRgba64 *QT_FASTCALL fetchRGBA8888ToRGBA64PM_lasx(QRgba64 *, const uchar *, int, int, const QList<QRgb> *, QDitherInfo *);
qPixelLayouts[QImage::Format_ARGB32].convertToRGBA64PM = convertARGB32ToRGBA64PM_lasx;
qPixelLayouts[QImage::Format_RGBX8888].convertToRGBA64PM = convertRGBA8888ToRGBA64PM_lasx;
qPixelLayouts[QImage::Format_ARGB32].fetchToRGBA64PM = fetchARGB32ToRGBA64PM_lasx;
qPixelLayouts[QImage::Format_RGBX8888].fetchToRGBA64PM = fetchRGBA8888ToRGBA64PM_lasx;
}
#endif //QT_COMPILER_SUPPORTS_LASX
#endif //QT_COMPILER_SUPPORTS_LSX
#if defined(__ARM_NEON__)

File diff suppressed because it is too large Load Diff

View File

@ -43,6 +43,11 @@ void qt_blend_rgb32_on_rgb32_lsx(uchar *destPixels, int dbpl,
#endif // QT_COMPILER_SUPPORTS_LSX
#ifdef QT_COMPILER_SUPPORTS_LASX
void qt_memfill64_lasx(quint64 *dest, quint64 value, qsizetype count);
void qt_memfill32_lasx(quint32 *dest, quint32 value, qsizetype count);
#endif // QT_COMPILER_SUPPORTS_LASX
QT_END_NAMESPACE
#endif // QDRAWHELPER_LOONGARCH64_P_H