From nobody Tue Feb 10 23:33:32 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1657962301423727.9089612931402; Sat, 16 Jul 2022 02:05:01 -0700 (PDT) Received: from localhost ([::1]:47080 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oCdjQ-000388-FM for importer@patchew.org; Sat, 16 Jul 2022 05:05:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56524) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oCdZO-0005cs-QL for qemu-devel@nongnu.org; Sat, 16 Jul 2022 04:54:42 -0400 Received: from mail.loongson.cn ([114.242.206.163]:50122 helo=loongson.cn) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oCdZL-0006eb-P0 for qemu-devel@nongnu.org; Sat, 16 Jul 2022 04:54:38 -0400 Received: from localhost.localdomain (unknown [10.2.5.185]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9Dxz9PCfNJijWQiAA--.28082S6; Sat, 16 Jul 2022 16:54:30 +0800 (CST) From: Song Gao To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org, alex.bennee@linaro.org, f4bug@amsat.org, gaosong@loongson.cn, peter.maydell@linaro.org, yangxiaojuan@loongson.cn Subject: [PATCH 4/8] tests/tcg/loongarch64: Add clo related instructions test Date: Sat, 16 Jul 2022 16:54:22 +0800 Message-Id: <20220716085426.3098060-5-gaosong@loongson.cn> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220716085426.3098060-1-gaosong@loongson.cn> References: <20220716085426.3098060-1-gaosong@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: AQAAf9Dxz9PCfNJijWQiAA--.28082S6 X-Coremail-Antispam: 1UD129KBjvJXoWxur1UKrWxCw4xWFWDZrW8Zwb_yoW5XFyDpF yfCr4rKrs7tFyaqrn3Kr15GF13tan5X3WUuF17Ww10vFZ5ur1kZry8K39rXFWIgF4v9r4f Zwnaga1a9FnrXaUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnUUvcSsGvfC2KfnxnUUI43ZEXa7xR_UUUUUUUUU== X-CM-SenderInfo: 5jdr20tqj6z05rqj20fqof0/ 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=114.242.206.163; envelope-from=gaosong@loongson.cn; helo=loongson.cn X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1657962303431100001 Content-Type: text/plain; charset="utf-8" This includes: - CL{O/Z}.{W/D} - CT{O/Z}.{W/D} Signed-off-by: Song Gao --- tests/tcg/loongarch64/Makefile.target | 15 +++++ tests/tcg/loongarch64/test_bit.c | 88 +++++++++++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 tests/tcg/loongarch64/Makefile.target create mode 100644 tests/tcg/loongarch64/test_bit.c diff --git a/tests/tcg/loongarch64/Makefile.target b/tests/tcg/loongarch64/= Makefile.target new file mode 100644 index 0000000000..c0bd8b9b86 --- /dev/null +++ b/tests/tcg/loongarch64/Makefile.target @@ -0,0 +1,15 @@ +# -*- Mode: makefile -*- +# +# LoongArch64 specific tweaks + +# Loongarch64 doesn't support gdb, so skip the EXTRA_RUNS +EXTRA_RUNS =3D + +LOONGARCH64_SRC=3D$(SRC_PATH)/tests/tcg/loongarch64 +VPATH +=3D $(LOONGARCH64_SRC) + +LDFLAGS+=3D-lm + +LOONGARCH64_TESTS =3D test_bit + +TESTS +=3D $(LOONGARCH64_TESTS) diff --git a/tests/tcg/loongarch64/test_bit.c b/tests/tcg/loongarch64/test_= bit.c new file mode 100644 index 0000000000..a6d9904909 --- /dev/null +++ b/tests/tcg/loongarch64/test_bit.c @@ -0,0 +1,88 @@ +#include +#include + +#define ARRAY_SIZE(X) (sizeof(X) / sizeof(*(X))) +#define TEST_CLO(N) \ +static uint64_t test_clo_##N(uint64_t rj) \ +{ \ + uint64_t rd =3D 0; \ + \ + asm volatile("clo."#N" %0, %1\n\t" \ + : "=3Dr"(rd) \ + : "r"(rj) \ + : ); \ + return rd; \ +} + +#define TEST_CLZ(N) \ +static uint64_t test_clz_##N(uint64_t rj) \ +{ \ + uint64_t rd =3D 0; \ + \ + asm volatile("clz."#N" %0, %1\n\t" \ + : "=3Dr"(rd) \ + : "r"(rj) \ + : ); \ + return rd; \ +} + +#define TEST_CTO(N) \ +static uint64_t test_cto_##N(uint64_t rj) \ +{ \ + uint64_t rd =3D 0; \ + \ + asm volatile("cto."#N" %0, %1\n\t" \ + : "=3Dr"(rd) \ + : "r"(rj) \ + : ); \ + return rd; \ +} + +#define TEST_CTZ(N) \ +static uint64_t test_ctz_##N(uint64_t rj) \ +{ \ + uint64_t rd =3D 0; \ + \ + asm volatile("ctz."#N" %0, %1\n\t" \ + : "=3Dr"(rd) \ + : "r"(rj) \ + : ); \ + return rd; \ +} + +TEST_CLO(w) +TEST_CLO(d) +TEST_CLZ(w) +TEST_CLZ(d) +TEST_CTO(w) +TEST_CTO(d) +TEST_CTZ(w) +TEST_CTZ(d) + +struct vector { + uint64_t (*func)(uint64_t); + uint64_t u; + uint64_t r; +}; + +static struct vector vectors[] =3D { + {test_clo_w, 0xfff11fff392476ab, 0}, + {test_clo_d, 0xabd28a64000000, 0}, + {test_clz_w, 0xfaffff42392476ab, 2}, + {test_clz_d, 0xabd28a64000000, 8}, + {test_cto_w, 0xfff11fff392476ab, 2}, + {test_cto_d, 0xabd28a64000000, 0}, + {test_ctz_w, 0xfaffff42392476ab, 0}, + {test_ctz_d, 0xabd28a64000000, 26}, +}; + +int main() +{ + int i; + + for (i =3D 0; i < ARRAY_SIZE(vectors); i++) { + assert((*vectors[i].func)(vectors[i].u) =3D=3D vectors[i].r); + } + + return 0; +} --=20 2.31.1