mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-04 00:03:54 -06:00
tcg/loongarch64: Support 64- and 256-bit vectors
tcg/loongarch64: Fix tcg_out_movi vs some pcrel pointers util/bufferiszero: Split out host include files util/bufferiszero: Add loongarch64 vector acceleration accel/tcg: Fix typo causing tb->page_addr[1] to not be recorded target/sparc: use signed denominator in sdiv helper linux-user: Make TARGET_NR_setgroups affect only the current thread -----BEGIN PGP SIGNATURE----- iQFRBAABCgA7FiEEekgeeIaLTbaoWgXAZN846K9+IV8FAmZzRoMdHHJpY2hhcmQu aGVuZGVyc29uQGxpbmFyby5vcmcACgkQZN846K9+IV9Y7gf/ZUTGjCUdAO7W7J5e Z3JLUNOfUHO6PxoE05963XJc+APwKiuL6Yo2bnJo6km7WM50CoaX9/7L9CXD7STg s3eUJ2p7FfvOADZgO373nqRrB/2mhvoywhDbVJBl+NcRvRUDW8rMqrlSKIAwDIsC kwwTWlCfpBSlUgm/c6yCVmt815+sGUPD2k/p+pIzAVUG6fGYAosC2fwPzPajiDGX Q+obV1fryKq2SRR2dMnhmPRtr3pQBBkISLuTX6xNM2+CYhYqhBrAlQaOEGhp7Dx3 ucKjvQFpHgPOSdQxb/HaDv81A20ZUQaydiNNmuKQcTtMx3MsQFR8NyVjH7L+fbS8 JokjaQ== =yVKz -----END PGP SIGNATURE----- Merge tag 'pull-tcg-20240619' of https://gitlab.com/rth7680/qemu into staging tcg/loongarch64: Support 64- and 256-bit vectors tcg/loongarch64: Fix tcg_out_movi vs some pcrel pointers util/bufferiszero: Split out host include files util/bufferiszero: Add loongarch64 vector acceleration accel/tcg: Fix typo causing tb->page_addr[1] to not be recorded target/sparc: use signed denominator in sdiv helper linux-user: Make TARGET_NR_setgroups affect only the current thread # -----BEGIN PGP SIGNATURE----- # # iQFRBAABCgA7FiEEekgeeIaLTbaoWgXAZN846K9+IV8FAmZzRoMdHHJpY2hhcmQu # aGVuZGVyc29uQGxpbmFyby5vcmcACgkQZN846K9+IV9Y7gf/ZUTGjCUdAO7W7J5e # Z3JLUNOfUHO6PxoE05963XJc+APwKiuL6Yo2bnJo6km7WM50CoaX9/7L9CXD7STg # s3eUJ2p7FfvOADZgO373nqRrB/2mhvoywhDbVJBl+NcRvRUDW8rMqrlSKIAwDIsC # kwwTWlCfpBSlUgm/c6yCVmt815+sGUPD2k/p+pIzAVUG6fGYAosC2fwPzPajiDGX # Q+obV1fryKq2SRR2dMnhmPRtr3pQBBkISLuTX6xNM2+CYhYqhBrAlQaOEGhp7Dx3 # ucKjvQFpHgPOSdQxb/HaDv81A20ZUQaydiNNmuKQcTtMx3MsQFR8NyVjH7L+fbS8 # JokjaQ== # =yVKz # -----END PGP SIGNATURE----- # gpg: Signature made Wed 19 Jun 2024 01:58:43 PM PDT # gpg: using RSA key 7A481E78868B4DB6A85A05C064DF38E8AF7E215F # gpg: issuer "richard.henderson@linaro.org" # gpg: Good signature from "Richard Henderson <richard.henderson@linaro.org>" [ultimate] * tag 'pull-tcg-20240619' of https://gitlab.com/rth7680/qemu: (24 commits) tcg/loongarch64: Fix tcg_out_movi vs some pcrel pointers target/sparc: use signed denominator in sdiv helper linux-user: Make TARGET_NR_setgroups affect only the current thread accel/tcg: Fix typo causing tb->page_addr[1] to not be recorded util/bufferiszero: Add loongarch64 vector acceleration util/bufferiszero: Split out host include files tcg/loongarch64: Enable v256 with LASX tcg/loongarch64: Support LASX in tcg_out_vec_op tcg/loongarch64: Split out vdvjukN in tcg_out_vec_op tcg/loongarch64: Remove temp_vec from tcg_out_vec_op tcg/loongarch64: Support LASX in tcg_out_{mov,ld,st} tcg/loongarch64: Split out vdvjvk in tcg_out_vec_op tcg/loongarch64: Support LASX in tcg_out_addsub_vec tcg/loongarch64: Simplify tcg_out_addsub_vec tcg/loongarch64: Support LASX in tcg_out_dupi_vec tcg/loongarch64: Use tcg_out_dup_vec in tcg_out_dupi_vec tcg/loongarch64: Support LASX in tcg_out_dupm_vec tcg/loongarch64: Support LASX in tcg_out_dup_vec tcg/loongarch64: Simplify tcg_out_dup_vec util/loongarch64: Detect LASX vector support ... Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
commit
02d9c38236
14 changed files with 2838 additions and 4511 deletions
|
@ -81,196 +81,7 @@ static bool buffer_is_zero_int_ge256(const void *buf, size_t len)
|
|||
return t == 0;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_AVX2_OPT) || defined(__SSE2__)
|
||||
#include <immintrin.h>
|
||||
|
||||
/* Helper for preventing the compiler from reassociating
|
||||
chains of binary vector operations. */
|
||||
#define SSE_REASSOC_BARRIER(vec0, vec1) asm("" : "+x"(vec0), "+x"(vec1))
|
||||
|
||||
/* Note that these vectorized functions may assume len >= 256. */
|
||||
|
||||
static bool __attribute__((target("sse2")))
|
||||
buffer_zero_sse2(const void *buf, size_t len)
|
||||
{
|
||||
/* Unaligned loads at head/tail. */
|
||||
__m128i v = *(__m128i_u *)(buf);
|
||||
__m128i w = *(__m128i_u *)(buf + len - 16);
|
||||
/* Align head/tail to 16-byte boundaries. */
|
||||
const __m128i *p = QEMU_ALIGN_PTR_DOWN(buf + 16, 16);
|
||||
const __m128i *e = QEMU_ALIGN_PTR_DOWN(buf + len - 1, 16);
|
||||
__m128i zero = { 0 };
|
||||
|
||||
/* Collect a partial block at tail end. */
|
||||
v |= e[-1]; w |= e[-2];
|
||||
SSE_REASSOC_BARRIER(v, w);
|
||||
v |= e[-3]; w |= e[-4];
|
||||
SSE_REASSOC_BARRIER(v, w);
|
||||
v |= e[-5]; w |= e[-6];
|
||||
SSE_REASSOC_BARRIER(v, w);
|
||||
v |= e[-7]; v |= w;
|
||||
|
||||
/*
|
||||
* Loop over complete 128-byte blocks.
|
||||
* With the head and tail removed, e - p >= 14, so the loop
|
||||
* must iterate at least once.
|
||||
*/
|
||||
do {
|
||||
v = _mm_cmpeq_epi8(v, zero);
|
||||
if (unlikely(_mm_movemask_epi8(v) != 0xFFFF)) {
|
||||
return false;
|
||||
}
|
||||
v = p[0]; w = p[1];
|
||||
SSE_REASSOC_BARRIER(v, w);
|
||||
v |= p[2]; w |= p[3];
|
||||
SSE_REASSOC_BARRIER(v, w);
|
||||
v |= p[4]; w |= p[5];
|
||||
SSE_REASSOC_BARRIER(v, w);
|
||||
v |= p[6]; w |= p[7];
|
||||
SSE_REASSOC_BARRIER(v, w);
|
||||
v |= w;
|
||||
p += 8;
|
||||
} while (p < e - 7);
|
||||
|
||||
return _mm_movemask_epi8(_mm_cmpeq_epi8(v, zero)) == 0xFFFF;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_AVX2_OPT
|
||||
static bool __attribute__((target("avx2")))
|
||||
buffer_zero_avx2(const void *buf, size_t len)
|
||||
{
|
||||
/* Unaligned loads at head/tail. */
|
||||
__m256i v = *(__m256i_u *)(buf);
|
||||
__m256i w = *(__m256i_u *)(buf + len - 32);
|
||||
/* Align head/tail to 32-byte boundaries. */
|
||||
const __m256i *p = QEMU_ALIGN_PTR_DOWN(buf + 32, 32);
|
||||
const __m256i *e = QEMU_ALIGN_PTR_DOWN(buf + len - 1, 32);
|
||||
__m256i zero = { 0 };
|
||||
|
||||
/* Collect a partial block at tail end. */
|
||||
v |= e[-1]; w |= e[-2];
|
||||
SSE_REASSOC_BARRIER(v, w);
|
||||
v |= e[-3]; w |= e[-4];
|
||||
SSE_REASSOC_BARRIER(v, w);
|
||||
v |= e[-5]; w |= e[-6];
|
||||
SSE_REASSOC_BARRIER(v, w);
|
||||
v |= e[-7]; v |= w;
|
||||
|
||||
/* Loop over complete 256-byte blocks. */
|
||||
for (; p < e - 7; p += 8) {
|
||||
/* PTEST is not profitable here. */
|
||||
v = _mm256_cmpeq_epi8(v, zero);
|
||||
if (unlikely(_mm256_movemask_epi8(v) != 0xFFFFFFFF)) {
|
||||
return false;
|
||||
}
|
||||
v = p[0]; w = p[1];
|
||||
SSE_REASSOC_BARRIER(v, w);
|
||||
v |= p[2]; w |= p[3];
|
||||
SSE_REASSOC_BARRIER(v, w);
|
||||
v |= p[4]; w |= p[5];
|
||||
SSE_REASSOC_BARRIER(v, w);
|
||||
v |= p[6]; w |= p[7];
|
||||
SSE_REASSOC_BARRIER(v, w);
|
||||
v |= w;
|
||||
}
|
||||
|
||||
return _mm256_movemask_epi8(_mm256_cmpeq_epi8(v, zero)) == 0xFFFFFFFF;
|
||||
}
|
||||
#endif /* CONFIG_AVX2_OPT */
|
||||
|
||||
static biz_accel_fn const accel_table[] = {
|
||||
buffer_is_zero_int_ge256,
|
||||
buffer_zero_sse2,
|
||||
#ifdef CONFIG_AVX2_OPT
|
||||
buffer_zero_avx2,
|
||||
#endif
|
||||
};
|
||||
|
||||
static unsigned best_accel(void)
|
||||
{
|
||||
#ifdef CONFIG_AVX2_OPT
|
||||
unsigned info = cpuinfo_init();
|
||||
|
||||
if (info & CPUINFO_AVX2) {
|
||||
return 2;
|
||||
}
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
#elif defined(__aarch64__) && defined(__ARM_NEON)
|
||||
#include <arm_neon.h>
|
||||
|
||||
/*
|
||||
* Helper for preventing the compiler from reassociating
|
||||
* chains of binary vector operations.
|
||||
*/
|
||||
#define REASSOC_BARRIER(vec0, vec1) asm("" : "+w"(vec0), "+w"(vec1))
|
||||
|
||||
static bool buffer_is_zero_simd(const void *buf, size_t len)
|
||||
{
|
||||
uint32x4_t t0, t1, t2, t3;
|
||||
|
||||
/* Align head/tail to 16-byte boundaries. */
|
||||
const uint32x4_t *p = QEMU_ALIGN_PTR_DOWN(buf + 16, 16);
|
||||
const uint32x4_t *e = QEMU_ALIGN_PTR_DOWN(buf + len - 1, 16);
|
||||
|
||||
/* Unaligned loads at head/tail. */
|
||||
t0 = vld1q_u32(buf) | vld1q_u32(buf + len - 16);
|
||||
|
||||
/* Collect a partial block at tail end. */
|
||||
t1 = e[-7] | e[-6];
|
||||
t2 = e[-5] | e[-4];
|
||||
t3 = e[-3] | e[-2];
|
||||
t0 |= e[-1];
|
||||
REASSOC_BARRIER(t0, t1);
|
||||
REASSOC_BARRIER(t2, t3);
|
||||
t0 |= t1;
|
||||
t2 |= t3;
|
||||
REASSOC_BARRIER(t0, t2);
|
||||
t0 |= t2;
|
||||
|
||||
/*
|
||||
* Loop over complete 128-byte blocks.
|
||||
* With the head and tail removed, e - p >= 14, so the loop
|
||||
* must iterate at least once.
|
||||
*/
|
||||
do {
|
||||
/*
|
||||
* Reduce via UMAXV. Whatever the actual result,
|
||||
* it will only be zero if all input bytes are zero.
|
||||
*/
|
||||
if (unlikely(vmaxvq_u32(t0) != 0)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
t0 = p[0] | p[1];
|
||||
t1 = p[2] | p[3];
|
||||
t2 = p[4] | p[5];
|
||||
t3 = p[6] | p[7];
|
||||
REASSOC_BARRIER(t0, t1);
|
||||
REASSOC_BARRIER(t2, t3);
|
||||
t0 |= t1;
|
||||
t2 |= t3;
|
||||
REASSOC_BARRIER(t0, t2);
|
||||
t0 |= t2;
|
||||
p += 8;
|
||||
} while (p < e - 7);
|
||||
|
||||
return vmaxvq_u32(t0) == 0;
|
||||
}
|
||||
|
||||
#define best_accel() 1
|
||||
static biz_accel_fn const accel_table[] = {
|
||||
buffer_is_zero_int_ge256,
|
||||
buffer_is_zero_simd,
|
||||
};
|
||||
#else
|
||||
#define best_accel() 0
|
||||
static biz_accel_fn const accel_table[1] = {
|
||||
buffer_is_zero_int_ge256
|
||||
};
|
||||
#endif
|
||||
#include "host/bufferiszero.c.inc"
|
||||
|
||||
static biz_accel_fn buffer_is_zero_accel;
|
||||
static unsigned accel_index;
|
||||
|
|
|
@ -29,6 +29,7 @@ unsigned __attribute__((constructor)) cpuinfo_init(void)
|
|||
|
||||
info = CPUINFO_ALWAYS;
|
||||
info |= (hwcap & HWCAP_LOONGARCH_LSX ? CPUINFO_LSX : 0);
|
||||
info |= (hwcap & HWCAP_LOONGARCH_LASX ? CPUINFO_LASX : 0);
|
||||
|
||||
cpuinfo = info;
|
||||
return info;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue