Signed-off-by: Stefan Brankovic <stefan.branko...@rt-rk.com> --- accel/tcg/tcg-runtime-gvec.c | 42 ++++++++++++++++++++++++++++++++++++++++++ accel/tcg/tcg-runtime.h | 4 ++++ tcg/i386/tcg-target.h | 1 + tcg/tcg-op-gvec.c | 23 +++++++++++++++++++++++ tcg/tcg-op-gvec.h | 3 +++ tcg/tcg-op-vec.c | 5 +++++ tcg/tcg-op.h | 2 ++ tcg/tcg-opc.h | 2 ++ tcg/tcg.c | 2 ++ tcg/tcg.h | 1 + 10 files changed, 85 insertions(+)
diff --git a/accel/tcg/tcg-runtime-gvec.c b/accel/tcg/tcg-runtime-gvec.c index 51cb29c..28173ae 100644 --- a/accel/tcg/tcg-runtime-gvec.c +++ b/accel/tcg/tcg-runtime-gvec.c @@ -1458,3 +1458,45 @@ void HELPER(gvec_bitsel)(void *d, void *a, void *b, void *c, uint32_t desc) } clear_high(d, oprsz, desc); } + +void HELPER(gvec_vmrgh8)(void *d, void *a, void *b, uint32_t desc) +{ + intptr_t oprsz = simd_oprsz(desc); + intptr_t i; + + for (i = 0; i < (oprsz / 2); i += sizeof(uint8_t)) { + uint8_t aa = *(uint8_t *)(a + 8 * sizeof(uint8_t) + i); + uint8_t bb = *(uint8_t *)(b + 8 * sizeof(uint8_t) + i); + *(uint8_t *)(d + 2 * i) = bb; + *(uint8_t *)(d + 2 * i + sizeof(uint8_t)) = aa; + } + clear_high(d, oprsz, desc); +} + +void HELPER(gvec_vmrgh16)(void *d, void *a, void *b, uint32_t desc) +{ + intptr_t oprsz = simd_oprsz(desc); + intptr_t i; + + for (i = 0; i < (oprsz / 2); i += sizeof(uint16_t)) { + uint16_t aa = *(uint16_t *)(a + 4 * sizeof(uint16_t) + i); + uint16_t bb = *(uint16_t *)(b + 4 * sizeof(uint16_t) + i); + *(uint16_t *)(d + 2 * i) = bb; + *(uint16_t *)(d + 2 * i + sizeof(uint16_t)) = aa; + } + clear_high(d, oprsz, desc); +} + +void HELPER(gvec_vmrgh32)(void *d, void *a, void *b, uint32_t desc) +{ + intptr_t oprsz = simd_oprsz(desc); + intptr_t i; + + for (i = 0; i < oprsz; i += sizeof(uint32_t)) { + uint32_t aa = *(uint32_t *)(a + 2 * sizeof(uint32_t) + i); + uint32_t bb = *(uint32_t *)(b + 2 * sizeof(uint32_t) + i); + *(uint32_t *)(d + 2 * i) = bb; + *(uint32_t *)(d + 2 * i + sizeof(uint32_t)) = aa; + } + clear_high(d, oprsz, desc); +} diff --git a/accel/tcg/tcg-runtime.h b/accel/tcg/tcg-runtime.h index 4fa61b4..089956f 100644 --- a/accel/tcg/tcg-runtime.h +++ b/accel/tcg/tcg-runtime.h @@ -305,3 +305,7 @@ DEF_HELPER_FLAGS_4(gvec_leu32, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) DEF_HELPER_FLAGS_4(gvec_leu64, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) DEF_HELPER_FLAGS_5(gvec_bitsel, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) + +DEF_HELPER_FLAGS_4(gvec_vmrgh8, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) +DEF_HELPER_FLAGS_4(gvec_vmrgh16, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) +DEF_HELPER_FLAGS_4(gvec_vmrgh32, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) diff --git a/tcg/i386/tcg-target.h b/tcg/i386/tcg-target.h index 928e8b8..e11b22d 100644 --- a/tcg/i386/tcg-target.h +++ b/tcg/i386/tcg-target.h @@ -192,6 +192,7 @@ extern bool have_avx2; #define TCG_TARGET_HAS_minmax_vec 1 #define TCG_TARGET_HAS_bitsel_vec 0 #define TCG_TARGET_HAS_cmpsel_vec -1 +#define TCG_TARGET_HAS_vmrgh_vec 0 #define TCG_TARGET_deposit_i32_valid(ofs, len) \ (((ofs) == 0 && (len) == 8) || ((ofs) == 8 && (len) == 8) || \ diff --git a/tcg/tcg-op-gvec.c b/tcg/tcg-op-gvec.c index 17679b6..2560fb6 100644 --- a/tcg/tcg-op-gvec.c +++ b/tcg/tcg-op-gvec.c @@ -2102,6 +2102,29 @@ void tcg_gen_gvec_umax(unsigned vece, uint32_t dofs, uint32_t aofs, tcg_gen_gvec_3(dofs, aofs, bofs, oprsz, maxsz, &g[vece]); } +static const TCGOpcode vecop_list_vmrgh[] = { INDEX_op_vmrgh_vec, 0 }; + +void tcg_gen_gvec_vmrgh(unsigned vece, uint32_t dofs, uint32_t aofs, + uint32_t bofs, uint32_t oprsz, uint32_t maxsz) +{ + static const GVecGen3 g[3] = { + { .fniv = tcg_gen_vmrgh_vec, + .fno = gen_helper_gvec_vmrgh8, + .opt_opc = vecop_list_vmrgh, + .vece = MO_8 }, + { .fniv = tcg_gen_vmrgh_vec, + .fno = gen_helper_gvec_vmrgh16, + .opt_opc = vecop_list_vmrgh, + .vece = MO_16 }, + { .fniv = tcg_gen_vmrgh_vec, + .fno = gen_helper_gvec_vmrgh32, + .opt_opc = vecop_list_vmrgh, + .vece = MO_32 } + }; + tcg_debug_assert(vece <= MO_64); + tcg_gen_gvec_3(dofs, aofs, bofs, oprsz, maxsz, &g[vece]); +} + /* Perform a vector negation using normal negation and a mask. Compare gen_subv_mask above. */ static void gen_negv_mask(TCGv_i64 d, TCGv_i64 b, TCGv_i64 m) diff --git a/tcg/tcg-op-gvec.h b/tcg/tcg-op-gvec.h index 830d68f..8c04d71 100644 --- a/tcg/tcg-op-gvec.h +++ b/tcg/tcg-op-gvec.h @@ -272,6 +272,9 @@ void tcg_gen_gvec_smax(unsigned vece, uint32_t dofs, uint32_t aofs, uint32_t bofs, uint32_t oprsz, uint32_t maxsz); void tcg_gen_gvec_umax(unsigned vece, uint32_t dofs, uint32_t aofs, uint32_t bofs, uint32_t oprsz, uint32_t maxsz); +/* Vector merge. */ +void tcg_gen_gvec_vmrgh(unsigned vece, uint32_t dofs, uint32_t aofs, + uint32_t bofs, uint32_t oprsz, uint32_t maxsz); void tcg_gen_gvec_and(unsigned vece, uint32_t dofs, uint32_t aofs, uint32_t bofs, uint32_t oprsz, uint32_t maxsz); diff --git a/tcg/tcg-op-vec.c b/tcg/tcg-op-vec.c index c8fdc24..fb0b83e 100644 --- a/tcg/tcg-op-vec.c +++ b/tcg/tcg-op-vec.c @@ -663,6 +663,11 @@ void tcg_gen_umax_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b) do_minmax(vece, r, a, b, INDEX_op_umax_vec, TCG_COND_GTU); } +void tcg_gen_vmrgh_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b) +{ + do_op3(vece, r, a, b, INDEX_op_vmrgh_vec); +} + void tcg_gen_shlv_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b) { do_op3_nofail(vece, r, a, b, INDEX_op_shlv_vec); diff --git a/tcg/tcg-op.h b/tcg/tcg-op.h index 2d4dd5c..d8de022 100644 --- a/tcg/tcg-op.h +++ b/tcg/tcg-op.h @@ -985,6 +985,8 @@ void tcg_gen_umin_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b); void tcg_gen_smax_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b); void tcg_gen_umax_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b); +void tcg_gen_vmrgh_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b); + void tcg_gen_shli_vec(unsigned vece, TCGv_vec r, TCGv_vec a, int64_t i); void tcg_gen_shri_vec(unsigned vece, TCGv_vec r, TCGv_vec a, int64_t i); void tcg_gen_sari_vec(unsigned vece, TCGv_vec r, TCGv_vec a, int64_t i); diff --git a/tcg/tcg-opc.h b/tcg/tcg-opc.h index 242d608..2bc3bdf 100644 --- a/tcg/tcg-opc.h +++ b/tcg/tcg-opc.h @@ -235,6 +235,8 @@ DEF(umin_vec, 1, 2, 0, IMPLVEC | IMPL(TCG_TARGET_HAS_minmax_vec)) DEF(smax_vec, 1, 2, 0, IMPLVEC | IMPL(TCG_TARGET_HAS_minmax_vec)) DEF(umax_vec, 1, 2, 0, IMPLVEC | IMPL(TCG_TARGET_HAS_minmax_vec)) +DEF(vmrgh_vec, 1, 2, 0, IMPLVEC | IMPL(TCG_TARGET_HAS_vmrgh_vec)) + DEF(and_vec, 1, 2, 0, IMPLVEC) DEF(or_vec, 1, 2, 0, IMPLVEC) DEF(xor_vec, 1, 2, 0, IMPLVEC) diff --git a/tcg/tcg.c b/tcg/tcg.c index 02a2680..fed9a6f 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -1646,6 +1646,8 @@ bool tcg_op_supported(TCGOpcode op) case INDEX_op_smax_vec: case INDEX_op_umax_vec: return have_vec && TCG_TARGET_HAS_minmax_vec; + case INDEX_op_vmrgh_vec: + return have_vec && TCG_TARGET_HAS_vmrgh_vec; case INDEX_op_bitsel_vec: return have_vec && TCG_TARGET_HAS_bitsel_vec; case INDEX_op_cmpsel_vec: diff --git a/tcg/tcg.h b/tcg/tcg.h index b411e17..05b9b51 100644 --- a/tcg/tcg.h +++ b/tcg/tcg.h @@ -186,6 +186,7 @@ typedef uint64_t TCGRegSet; #define TCG_TARGET_HAS_mul_vec 0 #define TCG_TARGET_HAS_sat_vec 0 #define TCG_TARGET_HAS_minmax_vec 0 +#define TCG_TARGET_HAS_vmrgh_vec 0 #define TCG_TARGET_HAS_bitsel_vec 0 #define TCG_TARGET_HAS_cmpsel_vec 0 #else -- 2.7.4