From nobody Mon Feb 9 01:30:53 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651140524810973.3353224504009; Thu, 28 Apr 2022 03:08:44 -0700 (PDT) Received: from localhost ([::1]:39532 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nk14k-0006Ic-L6 for importer@patchew.org; Thu, 28 Apr 2022 06:08:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38518) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nk0kF-00037Z-Cp for qemu-devel@nongnu.org; Thu, 28 Apr 2022 05:47:32 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:31372) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nk0kC-0008Hp-UW for qemu-devel@nongnu.org; Thu, 28 Apr 2022 05:47:31 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-146-dD0PDARAMxm2ouydfXc5iA-1; Thu, 28 Apr 2022 05:47:27 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AD8F0811E81; Thu, 28 Apr 2022 09:47:26 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.194.113]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9F78540CFD16; Thu, 28 Apr 2022 09:47:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651139248; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+OU+lVbzYZDaortErPaSsIcCEyyHvbBLwrEPDjWpALw=; b=AoVzgQisgElRpkm2/oiuJbWBcEcDYtV/QhqUv15fVrcF9X+BLEQ6GoViGmkRmMLJI9IgIJ SKyhnWDjTeCm3SlYYqIa7u6zHCcYXaIXbg+AaBKPOrnzTKNYuscaSCIgVLFf2pnOfRgkPm G2H8rZVqAhWOs7ZRfSTckjvQCeJPFfQ= X-MC-Unique: dD0PDARAMxm2ouydfXc5iA-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v6 06/13] target/s390x: vxeh2: vector string search Date: Thu, 28 Apr 2022 11:47:01 +0200 Message-Id: <20220428094708.84835-7-david@redhat.com> In-Reply-To: <20220428094708.84835-1-david@redhat.com> References: <20220428094708.84835-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Huth , David Hildenbrand , Cornelia Huck , Richard Henderson , Eric Farman , David Miller , Halil Pasic , qemu-s390x@nongnu.org, Christian Borntraeger Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1651140527321100001 Content-Type: text/plain; charset="utf-8" From: David Miller Signed-off-by: David Miller Signed-off-by: Richard Henderson Reviewed-by: David Hildenbrand Tested-by: Thomas Huth Signed-off-by: David Hildenbrand --- target/s390x/helper.h | 6 ++ target/s390x/tcg/insn-data.def | 2 + target/s390x/tcg/translate.c | 3 +- target/s390x/tcg/translate_vx.c.inc | 25 +++++++ target/s390x/tcg/vec_string_helper.c | 99 ++++++++++++++++++++++++++++ 5 files changed, 134 insertions(+), 1 deletion(-) diff --git a/target/s390x/helper.h b/target/s390x/helper.h index 7cbcbd7f0b..7412130883 100644 --- a/target/s390x/helper.h +++ b/target/s390x/helper.h @@ -246,6 +246,12 @@ DEF_HELPER_6(gvec_vstrc_cc32, void, ptr, cptr, cptr, c= ptr, env, i32) DEF_HELPER_6(gvec_vstrc_cc_rt8, void, ptr, cptr, cptr, cptr, env, i32) DEF_HELPER_6(gvec_vstrc_cc_rt16, void, ptr, cptr, cptr, cptr, env, i32) DEF_HELPER_6(gvec_vstrc_cc_rt32, void, ptr, cptr, cptr, cptr, env, i32) +DEF_HELPER_6(gvec_vstrs_8, void, ptr, cptr, cptr, cptr, env, i32) +DEF_HELPER_6(gvec_vstrs_16, void, ptr, cptr, cptr, cptr, env, i32) +DEF_HELPER_6(gvec_vstrs_32, void, ptr, cptr, cptr, cptr, env, i32) +DEF_HELPER_6(gvec_vstrs_zs8, void, ptr, cptr, cptr, cptr, env, i32) +DEF_HELPER_6(gvec_vstrs_zs16, void, ptr, cptr, cptr, cptr, env, i32) +DEF_HELPER_6(gvec_vstrs_zs32, void, ptr, cptr, cptr, cptr, env, i32) =20 /* =3D=3D=3D Vector Floating-Point Instructions */ DEF_HELPER_FLAGS_5(gvec_vfa32, TCG_CALL_NO_WG, void, ptr, cptr, cptr, env,= i32) diff --git a/target/s390x/tcg/insn-data.def b/target/s390x/tcg/insn-data.def index 6c8a8b229f..46add91a0e 100644 --- a/target/s390x/tcg/insn-data.def +++ b/target/s390x/tcg/insn-data.def @@ -1246,6 +1246,8 @@ F(0xe75c, VISTR, VRR_a, V, 0, 0, 0, 0, vistr, 0, IF_VEC) /* VECTOR STRING RANGE COMPARE */ F(0xe78a, VSTRC, VRR_d, V, 0, 0, 0, 0, vstrc, 0, IF_VEC) +/* VECTOR STRING SEARCH */ + F(0xe78b, VSTRS, VRR_d, VE2, 0, 0, 0, 0, vstrs, 0, IF_VEC) =20 /* =3D=3D=3D Vector Floating-Point Instructions */ =20 diff --git a/target/s390x/tcg/translate.c b/target/s390x/tcg/translate.c index 8f092dab95..b40cb84bae 100644 --- a/target/s390x/tcg/translate.c +++ b/target/s390x/tcg/translate.c @@ -6222,7 +6222,8 @@ enum DisasInsnEnum { #define FAC_PCI S390_FEAT_ZPCI /* z/PCI facility */ #define FAC_AIS S390_FEAT_ADAPTER_INT_SUPPRESSION #define FAC_V S390_FEAT_VECTOR /* vector facility */ -#define FAC_VE S390_FEAT_VECTOR_ENH /* vector enhancements facili= ty 1 */ +#define FAC_VE S390_FEAT_VECTOR_ENH /* vector enhancements facil= ity 1 */ +#define FAC_VE2 S390_FEAT_VECTOR_ENH2 /* vector enhancements facil= ity 2 */ #define FAC_MIE2 S390_FEAT_MISC_INSTRUCTION_EXT2 /* miscellaneous-i= nstruction-extensions facility 2 */ #define FAC_MIE3 S390_FEAT_MISC_INSTRUCTION_EXT3 /* miscellaneous-i= nstruction-extensions facility 3 */ =20 diff --git a/target/s390x/tcg/translate_vx.c.inc b/target/s390x/tcg/transla= te_vx.c.inc index be9407d1ed..8ddbd440e2 100644 --- a/target/s390x/tcg/translate_vx.c.inc +++ b/target/s390x/tcg/translate_vx.c.inc @@ -2497,6 +2497,31 @@ static DisasJumpType op_vstrc(DisasContext *s, Disas= Ops *o) return DISAS_NEXT; } =20 +static DisasJumpType op_vstrs(DisasContext *s, DisasOps *o) +{ + typedef void (*helper_vstrs)(TCGv_ptr, TCGv_ptr, TCGv_ptr, + TCGv_ptr, TCGv_ptr, TCGv_i32); + static const helper_vstrs fns[3][2] =3D { + { gen_helper_gvec_vstrs_8, gen_helper_gvec_vstrs_zs8 }, + { gen_helper_gvec_vstrs_16, gen_helper_gvec_vstrs_zs16 }, + { gen_helper_gvec_vstrs_32, gen_helper_gvec_vstrs_zs32 }, + }; + const uint8_t es =3D get_field(s, m5); + const uint8_t m6 =3D get_field(s, m6); + const bool zs =3D extract32(m6, 1, 1); + + if (es > ES_32 || m6 & ~2) { + gen_program_exception(s, PGM_SPECIFICATION); + return DISAS_NORETURN; + } + + gen_gvec_4_ptr(get_field(s, v1), get_field(s, v2), + get_field(s, v3), get_field(s, v4), + cpu_env, 0, fns[es][zs]); + set_cc_static(s); + return DISAS_NEXT; +} + static DisasJumpType op_vfa(DisasContext *s, DisasOps *o) { const uint8_t fpf =3D get_field(s, m4); diff --git a/target/s390x/tcg/vec_string_helper.c b/target/s390x/tcg/vec_st= ring_helper.c index f8b54bba4a..9b85becdfb 100644 --- a/target/s390x/tcg/vec_string_helper.c +++ b/target/s390x/tcg/vec_string_helper.c @@ -470,3 +470,102 @@ void HELPER(gvec_vstrc_cc_rt##BITS)(void *v1, const v= oid *v2, const void *v3, \ DEF_VSTRC_CC_RT_HELPER(8) DEF_VSTRC_CC_RT_HELPER(16) DEF_VSTRC_CC_RT_HELPER(32) + +static int vstrs(S390Vector *v1, const S390Vector *v2, const S390Vector *v= 3, + const S390Vector *v4, uint8_t es, bool zs) +{ + int substr_elen, substr_0, str_elen, i, j, k, cc; + int nelem =3D 16 >> es; + bool eos =3D false; + + substr_elen =3D s390_vec_read_element8(v4, 7) >> es; + + /* If ZS, bound substr length by min(nelem, strlen(v3)). */ + if (zs) { + substr_elen =3D MIN(substr_elen, nelem); + for (i =3D 0; i < substr_elen; i++) { + if (s390_vec_read_element(v3, i, es) =3D=3D 0) { + substr_elen =3D i; + break; + } + } + } + + if (substr_elen =3D=3D 0) { + cc =3D 2; /* full match for degenerate case of empty substr */ + k =3D 0; + goto done; + } + + /* If ZS, look for eos in the searched string. */ + if (zs) { + for (k =3D 0; k < nelem; k++) { + if (s390_vec_read_element(v2, k, es) =3D=3D 0) { + eos =3D true; + break; + } + } + str_elen =3D k; + } else { + str_elen =3D nelem; + } + + substr_0 =3D s390_vec_read_element(v3, 0, es); + + for (k =3D 0; ; k++) { + for (; k < str_elen; k++) { + if (s390_vec_read_element(v2, k, es) =3D=3D substr_0) { + break; + } + } + + /* If we reached the end of the string, no match. */ + if (k =3D=3D str_elen) { + cc =3D eos; /* no match (with or without zero char) */ + goto done; + } + + /* If the substring is only one char, match. */ + if (substr_elen =3D=3D 1) { + cc =3D 2; /* full match */ + goto done; + } + + /* If the match begins at the last char, we have a partial match. = */ + if (k =3D=3D str_elen - 1) { + cc =3D 3; /* partial match */ + goto done; + } + + i =3D MIN(nelem, k + substr_elen); + for (j =3D k + 1; j < i; j++) { + uint32_t e2 =3D s390_vec_read_element(v2, j, es); + uint32_t e3 =3D s390_vec_read_element(v3, j - k, es); + if (e2 !=3D e3) { + break; + } + } + if (j =3D=3D i) { + /* Matched up until "end". */ + cc =3D i - k =3D=3D substr_elen ? 2 : 3; /* full or partial ma= tch */ + goto done; + } + } + + done: + s390_vec_write_element64(v1, 0, k << es); + s390_vec_write_element64(v1, 1, 0); + return cc; +} + +#define DEF_VSTRS_HELPER(BITS) = \ +void QEMU_FLATTEN HELPER(gvec_vstrs_##BITS)(void *v1, const void *v2, = \ + const void *v3, const void *v4, CPUS390XState *env, uint32_t desc) = \ + { env->cc_op =3D vstrs(v1, v2, v3, v4, MO_##BITS, false); } = \ +void QEMU_FLATTEN HELPER(gvec_vstrs_zs##BITS)(void *v1, const void *v2, = \ + const void *v3, const void *v4, CPUS390XState *env, uint32_t desc) = \ + { env->cc_op =3D vstrs(v1, v2, v3, v4, MO_##BITS, true); } + +DEF_VSTRS_HELPER(8) +DEF_VSTRS_HELPER(16) +DEF_VSTRS_HELPER(32) --=20 2.35.1