From patchwork Fri Apr 21 16:49:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Simpson X-Patchwork-Id: 13220354 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A7EA8C77B76 for ; Fri, 21 Apr 2023 16:50:03 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pptx3-0005tF-1Y; Fri, 21 Apr 2023 12:49:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pptx1-0005ri-1Y for qemu-devel@nongnu.org; Fri, 21 Apr 2023 12:49:35 -0400 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pptwy-00044B-Nz for qemu-devel@nongnu.org; Fri, 21 Apr 2023 12:49:34 -0400 Received: from pps.filterd (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 33LCbTuC031457; Fri, 21 Apr 2023 16:49:28 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=qcppdkim1; bh=1b2O+qmlKf9WjWr8GTX3jBAtGg4oeFE29CaycHt1tLo=; b=K3VyU8rfAJza7r0MGk4QJrPQqTGgjVINxdPwofSwvGC3kS2+Ha3O3w/WTaBF5RwhngG/ PpW8p8oot7bjqc0S6eD9xySxCk+KRf1FIvi4F5mcsoqE7GmtKGoshrTPkggtMOVnGJfK FxInrNhevfmIVqLkrhHuxcfRxQSf8I728F1KDoUDY9X8Ljs3w7SWjmZ9PU8LNcLa4P+q YMIxBD4A7/S80+nVrH5U/bJ9opNx145W0fgtcQZ2w+4Y2Qct+U8Ew7lif6Waf/3KFk95 e2m8Ge+DcspaYIf1bZv0EhZwnVG5ILfGz39Cg1wqfY8kSH5ma/+AnVbd70PT7Ofg2JwP yA== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3q3qdm8y81-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Apr 2023 16:49:28 +0000 Received: from pps.filterd (NALASPPMTA04.qualcomm.com [127.0.0.1]) by NALASPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTP id 33LGlJmY003216; Fri, 21 Apr 2023 16:49:27 GMT Received: from pps.reinject (localhost [127.0.0.1]) by NALASPPMTA04.qualcomm.com (PPS) with ESMTPS id 3q3ncvu2sy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Apr 2023 16:49:27 +0000 Received: from NALASPPMTA04.qualcomm.com (NALASPPMTA04.qualcomm.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 33LGnR9n006522; Fri, 21 Apr 2023 16:49:27 GMT Received: from hu-devc-sd-u20-a-1.qualcomm.com (hu-tsimpson-lv.qualcomm.com [10.47.204.221]) by NALASPPMTA04.qualcomm.com (PPS) with ESMTPS id 33LGnQIh006509 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Apr 2023 16:49:27 +0000 Received: by hu-devc-sd-u20-a-1.qualcomm.com (Postfix, from userid 47164) id 25F53692; Fri, 21 Apr 2023 09:49:26 -0700 (PDT) From: Taylor Simpson To: qemu-devel@nongnu.org Cc: tsimpson@quicinc.com, richard.henderson@linaro.org, philmd@linaro.org, peter.maydell@linaro.org, bcain@quicinc.com, quic_mathbern@quicinc.com, stefanha@redhat.com, ale@rev.ng, anjo@rev.ng, quic_mliebel@quicinc.com Subject: [PULL v2 06/10] Hexagon (target/hexagon) Add overrides for count trailing zeros/ones Date: Fri, 21 Apr 2023 09:49:18 -0700 Message-Id: <20230421164922.3608183-7-tsimpson@quicinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230421164922.3608183-1-tsimpson@quicinc.com> References: <20230421164922.3608183-1-tsimpson@quicinc.com> MIME-Version: 1.0 X-QCInternal: smtphost X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: 30JpKq_uSYnHhqPgAFzhKu72G5eNdp8w X-Proofpoint-GUID: 30JpKq_uSYnHhqPgAFzhKu72G5eNdp8w X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-04-21_08,2023-04-21_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 mlxscore=0 malwarescore=0 mlxlogscore=609 priorityscore=1501 impostorscore=0 lowpriorityscore=0 phishscore=0 spamscore=0 bulkscore=0 adultscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2304210147 Received-SPF: pass client-ip=205.220.168.131; envelope-from=tsimpson@qualcomm.com; helo=mx0a-0031df01.pphosted.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.25, 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The following instructions are overriden S2_ct0 Count trailing zeros S2_ct1 Count trailing ones S2_ct0p Count trailing zeros (register pair) S2_ct1p Count trailing ones (register pair) These instructions are not handled by idef-parser because the imported semantics uses bit-reverse. However, they are straightforward to implement in TCG with tcg_gen_ctzi_* Test cases added to tests/tcg/hexagon/misc.c Signed-off-by: Taylor Simpson Reviewed-by: Richard Henderson Message-Id: <20230405164211.30015-1-tsimpson@quicinc.com> --- target/hexagon/gen_tcg.h | 24 +++++++++++++++++ tests/tcg/hexagon/misc.c | 56 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 79 insertions(+), 1 deletion(-) diff --git a/target/hexagon/gen_tcg.h b/target/hexagon/gen_tcg.h index bcf0cf466a..45f92adf6c 100644 --- a/target/hexagon/gen_tcg.h +++ b/target/hexagon/gen_tcg.h @@ -1058,6 +1058,30 @@ #define fGEN_TCG_SL2_jumpr31_fnew(SHORTCODE) \ gen_cond_jumpr31(ctx, TCG_COND_NE, hex_new_pred_value[0]) +/* Count trailing zeros/ones */ +#define fGEN_TCG_S2_ct0(SHORTCODE) \ + do { \ + tcg_gen_ctzi_tl(RdV, RsV, 32); \ + } while (0) +#define fGEN_TCG_S2_ct1(SHORTCODE) \ + do { \ + tcg_gen_not_tl(RdV, RsV); \ + tcg_gen_ctzi_tl(RdV, RdV, 32); \ + } while (0) +#define fGEN_TCG_S2_ct0p(SHORTCODE) \ + do { \ + TCGv_i64 tmp = tcg_temp_new_i64(); \ + tcg_gen_ctzi_i64(tmp, RssV, 64); \ + tcg_gen_extrl_i64_i32(RdV, tmp); \ + } while (0) +#define fGEN_TCG_S2_ct1p(SHORTCODE) \ + do { \ + TCGv_i64 tmp = tcg_temp_new_i64(); \ + tcg_gen_not_i64(tmp, RssV); \ + tcg_gen_ctzi_i64(tmp, tmp, 64); \ + tcg_gen_extrl_i64_i32(RdV, tmp); \ + } while (0) + /* Floating point */ #define fGEN_TCG_F2_conv_sf2df(SHORTCODE) \ gen_helper_conv_sf2df(RddV, cpu_env, RsV) diff --git a/tests/tcg/hexagon/misc.c b/tests/tcg/hexagon/misc.c index e73ab57334..e126751e3a 100644 --- a/tests/tcg/hexagon/misc.c +++ b/tests/tcg/hexagon/misc.c @@ -1,5 +1,5 @@ /* - * Copyright(c) 2019-2021 Qualcomm Innovation Center, Inc. All Rights Reserved. + * Copyright(c) 2019-2023 Qualcomm Innovation Center, Inc. All Rights Reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,6 +21,7 @@ typedef unsigned char uint8_t; typedef unsigned short uint16_t; typedef unsigned int uint32_t; +typedef unsigned long long uint64_t; static inline void S4_storerhnew_rr(void *p, int index, uint16_t v) @@ -333,6 +334,57 @@ void test_l2fetch(void) "l2fetch(r0, r3:2)\n\t"); } +static inline int ct0(uint32_t x) +{ + int res; + asm("%0 = ct0(%1)\n\t" : "=r"(res) : "r"(x)); + return res; +} + +static inline int ct1(uint32_t x) +{ + int res; + asm("%0 = ct1(%1)\n\t" : "=r"(res) : "r"(x)); + return res; +} + +static inline int ct0p(uint64_t x) +{ + int res; + asm("%0 = ct0(%1)\n\t" : "=r"(res) : "r"(x)); + return res; +} + +static inline int ct1p(uint64_t x) +{ + int res; + asm("%0 = ct1(%1)\n\t" : "=r"(res) : "r"(x)); + return res; +} + +void test_count_trailing_zeros_ones(void) +{ + check(ct0(0x0000000f), 0); + check(ct0(0x00000000), 32); + check(ct0(0x000000f0), 4); + + check(ct1(0x000000f0), 0); + check(ct1(0x0000000f), 4); + check(ct1(0x00000000), 0); + check(ct1(0xffffffff), 32); + + check(ct0p(0x000000000000000fULL), 0); + check(ct0p(0x0000000000000000ULL), 64); + check(ct0p(0x00000000000000f0ULL), 4); + + check(ct1p(0x00000000000000f0ULL), 0); + check(ct1p(0x000000000000000fULL), 4); + check(ct1p(0x0000000000000000ULL), 0); + check(ct1p(0xffffffffffffffffULL), 64); + check(ct1p(0xffffffffff0fffffULL), 20); + check(ct1p(0xffffff0fffffffffULL), 36); +} + int main() { int res; @@ -468,6 +520,8 @@ int main() test_l2fetch(); + test_count_trailing_zeros_ones(); + puts(err ? "FAIL" : "PASS"); return err; }