From patchwork Thu Oct 12 14:17:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2" X-Patchwork-Id: 152022 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp1264786vqb; Thu, 12 Oct 2023 07:17:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEP/tpLWNG6BQZo4RI/eocbBnaU3CJRxL1Z4CiCebBOugvpaQKhtv5KfSE1KIkIUw+0qX3P X-Received: by 2002:ac8:584b:0:b0:412:21f4:6f9e with SMTP id h11-20020ac8584b000000b0041221f46f9emr28458911qth.40.1697120268096; Thu, 12 Oct 2023 07:17:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697120268; cv=none; d=google.com; s=arc-20160816; b=iM4QMuiKDiLCyLPAYOQC0GYwl1T4c+F4HOcDwa+wPRN5SBdtYI0w5RlY9JszxVffIl 8ri7oIoyuRie+2thrLmSFu04/i+/5v4dqY2fqZq0yR9kvomPtjacRJ+o7Q+PDAs/klGR 4ZN9LlP9173hU99gC+wgpmh4Ks6Z2SNTL+BO6p4kN4daNQFKDwF31rgjM2oQYtkpqg5w 6kOf70O6nlFnbgHTTGLG1TWK0xwBkEyEuW5sq8XFFyzVmmkuZ6GgtEqK6aq+89yEapY7 9O1bg+4cXvITBtHCq/dFWeDgHWGtZ+pWZ12OaMILs+ikSHaILEYdA7oZpU3w7Wei0Xxx WKXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :dmarc-filter:delivered-to; bh=OQqZLHb1C/n9LgOWq7gk6G+Xz0/B0r1CrYfhnktWBQ0=; fh=yqBQmCEeFYB2Wjmf8l8QkV/dOy5iKwSEx/iU/FYQjxU=; b=gny/Ji+2SMS5xJ9A1hGYtv38MDqJf8wIheGLVdnW3Uyfq2MMj2+dpURfT+KJXAVvUd 6Qc93kM/JjASl4DCVXRUZG+hoXXvSAN04VrVOd8q2u/HLa4/9E3FygzQtG3ImUwgAszT FvKnCinQ48xPxT6qEeKnMe0cGTEUtBIJ/+ES7B0LbsVfH/j3OBWvyRBoap5lvdyB6pRz 7oWKdSUwPZ/dwm3Ty96fYEOITDqJ4U0ezUBwLAd7UUVtEyu4/r/k+dRo6T1V7opVKHlJ /BizUz0HrmnCZfJLFXKDrEIJ5V7o7hTU0dEYfiaaq7wSfR6fgo0ogau0YI3JpPTzA3sI SlKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ZBLkrmq0; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id p19-20020a05622a00d300b0041959f0417bsi11163532qtw.776.2023.10.12.07.17.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 07:17:48 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ZBLkrmq0; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D845F38582B7 for ; Thu, 12 Oct 2023 14:17:47 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.115]) by sourceware.org (Postfix) with ESMTPS id 8982A3858C5E for ; Thu, 12 Oct 2023 14:17:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8982A3858C5E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697120237; x=1728656237; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=NeUXM4X9YLyeZ5/svfHp4m+zdnqxx18291HHU8A7Tjw=; b=ZBLkrmq0LJEizePehifCn+nojV8ifNcSzYnnDzpmReQgJS4k/zWxUnS5 +1gkY1KQBeVrG5lAEYCH3smLxWfnu4f+RrbRQz2C9IpetBG/lXvNIN8My ZQeZhTSG7hVJoSZNATPOFxdpvu5fIsOoeTIt7b9F0G3ZdCxWqMH5YHMf7 hJ9yFNFTJsab5I4W/ZzYQXJSWswC5YzNMS0+PVF431us7+4F1UIhU8N7F e0Pj0UwZ3h4tf2e0cAT+Ns5g1+U5jOogn7c0lGTbkpDKCv2bBvhNcw9KA IBCKvBcbfsn3B3BC4CyuDQU5Ic0S33YKW29TkKNJryWBd3lmmlFM8/2P1 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10861"; a="384775689" X-IronPort-AV: E=Sophos;i="6.03,219,1694761200"; d="scan'208";a="384775689" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Oct 2023 07:17:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10861"; a="928015384" X-IronPort-AV: E=Sophos;i="6.03,219,1694761200"; d="scan'208";a="928015384" Received: from shvmail02.sh.intel.com ([10.239.244.9]) by orsmga005.jf.intel.com with ESMTP; 12 Oct 2023 07:17:14 -0700 Received: from pli-ubuntu.sh.intel.com (pli-ubuntu.sh.intel.com [10.239.159.47]) by shvmail02.sh.intel.com (Postfix) with ESMTP id 31A1C10057F6; Thu, 12 Oct 2023 22:17:13 +0800 (CST) From: pan2.li@intel.com To: gcc-patches@gcc.gnu.org Cc: juzhe.zhong@rivai.ai, pan2.li@intel.com, yanzhang.wang@intel.com, kito.cheng@gmail.com Subject: [PATCH v1] RISC-V: Support FP lceil/lceilf auto vectorization Date: Thu, 12 Oct 2023 22:17:11 +0800 Message-Id: <20231012141711.1303539-1-pan2.li@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779559582011949302 X-GMAIL-MSGID: 1779559582011949302 From: Pan Li This patch would like to support the FP lceil/lceilf auto vectorization. * long lceil (double) for rv64 * long lceilf (float) for rv32 Due to the limitation that only the same size of data type are allowed in the vectorier, the standard name lceilmn2 only act on DF => DI for rv64, and SF => SI for rv32. Given we have code like: void test_lceil (long *out, double *in, unsigned count) { for (unsigned i = 0; i < count; i++) out[i] = __builtin_lceil (in[i]); } Before this patch: .L3: ... fld fa5,0(a1) fcvt.l.d a5,fa5,rup sd a5,-8(a0) ... bne a1,a4,.L3 After this patch: frrm a6 ... fsrmi 3 // RUP .L3: ... vsetvli a3,zero,e64,m1,ta,ma vfcvt.x.f.v v1,v1 vsetvli zero,a2,e64,m1,ta,ma vse32.v v1,0(a0) ... bne a2,zero,.L3 ... fsrm a6 The rest part like SF => DI/HF => DI/DF => SI/HF => SI will be covered by TARGET_VECTORIZE_BUILTIN_VECTORIZED_FUNCTION. gcc/ChangeLog: * config/riscv/autovec.md (lceil2): New pattern] for lceil/lceilf. * config/riscv/riscv-protos.h (enum insn_type): New enum value. (expand_vec_lceil): New func decl for expanding lceil. * config/riscv/riscv-v.cc (expand_vec_lceil): New func impl for expanding lceil. gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/autovec/unop/math-lceil-0.c: New test. * gcc.target/riscv/rvv/autovec/unop/math-lceil-1.c: New test. * gcc.target/riscv/rvv/autovec/unop/math-lceil-run-0.c: New test. * gcc.target/riscv/rvv/autovec/unop/math-lceil-run-1.c: New test. * gcc.target/riscv/rvv/autovec/vls/math-lceil-0.c: New test. * gcc.target/riscv/rvv/autovec/vls/math-lceil-1.c: New test. Signed-off-by: Pan Li Signed-off-by: Pan Li Signed-off-by: Pan Li > --- gcc/config/riscv/autovec.md | 11 +++ gcc/config/riscv/riscv-protos.h | 2 + gcc/config/riscv/riscv-v.cc | 10 +++ .../riscv/rvv/autovec/unop/math-lceil-0.c | 19 +++++ .../riscv/rvv/autovec/unop/math-lceil-1.c | 19 +++++ .../riscv/rvv/autovec/unop/math-lceil-run-0.c | 69 +++++++++++++++++++ .../riscv/rvv/autovec/unop/math-lceil-run-1.c | 69 +++++++++++++++++++ .../riscv/rvv/autovec/vls/math-lceil-0.c | 30 ++++++++ .../riscv/rvv/autovec/vls/math-lceil-1.c | 30 ++++++++ 9 files changed, 259 insertions(+) create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/unop/math-lceil-0.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/unop/math-lceil-1.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/unop/math-lceil-run-0.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/unop/math-lceil-run-1.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/math-lceil-0.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/math-lceil-1.c diff --git a/gcc/config/riscv/autovec.md b/gcc/config/riscv/autovec.md index 33b11723c21..267691a0095 100644 --- a/gcc/config/riscv/autovec.md +++ b/gcc/config/riscv/autovec.md @@ -2241,6 +2241,7 @@ (define_expand "avg3_ceil" ;; - roundeven/roundevenf ;; - lrint/lrintf ;; - irintf +;; - lceil/lceilf ;; ------------------------------------------------------------------------- (define_expand "ceil2" [(match_operand:V_VLSF 0 "register_operand") @@ -2331,3 +2332,13 @@ (define_expand "lround2" DONE; } ) + +(define_expand "lceil2" + [(match_operand: 0 "register_operand") + (match_operand:V_VLS_FCONVERT_I_L_LL 1 "register_operand")] + "TARGET_VECTOR && !flag_trapping_math && !flag_rounding_math" + { + riscv_vector::expand_vec_lceil (operands[0], operands[1], mode, mode); + DONE; + } +) diff --git a/gcc/config/riscv/riscv-protos.h b/gcc/config/riscv/riscv-protos.h index b7eeeb8f55d..ab65ab19524 100644 --- a/gcc/config/riscv/riscv-protos.h +++ b/gcc/config/riscv/riscv-protos.h @@ -303,6 +303,7 @@ enum insn_type : unsigned int UNARY_OP_TAMU = __MASK_OP_TAMU | UNARY_OP_P, UNARY_OP_FRM_DYN = UNARY_OP | FRM_DYN_P, UNARY_OP_FRM_RMM = UNARY_OP | FRM_RMM_P, + UNARY_OP_FRM_RUP = UNARY_OP | FRM_RUP_P, UNARY_OP_TAMU_FRM_DYN = UNARY_OP_TAMU | FRM_DYN_P, UNARY_OP_TAMU_FRM_RUP = UNARY_OP_TAMU | FRM_RUP_P, UNARY_OP_TAMU_FRM_RDN = UNARY_OP_TAMU | FRM_RDN_P, @@ -477,6 +478,7 @@ void expand_vec_trunc (rtx, rtx, machine_mode, machine_mode); void expand_vec_roundeven (rtx, rtx, machine_mode, machine_mode); void expand_vec_lrint (rtx, rtx, machine_mode, machine_mode); void expand_vec_lround (rtx, rtx, machine_mode, machine_mode); +void expand_vec_lceil (rtx, rtx, machine_mode, machine_mode); #endif bool sew64_scalar_helper (rtx *, rtx *, rtx, machine_mode, bool, void (*)(rtx *, rtx)); diff --git a/gcc/config/riscv/riscv-v.cc b/gcc/config/riscv/riscv-v.cc index b61c745678b..b03213dd8ed 100644 --- a/gcc/config/riscv/riscv-v.cc +++ b/gcc/config/riscv/riscv-v.cc @@ -4132,4 +4132,14 @@ expand_vec_lround (rtx op_0, rtx op_1, machine_mode vec_fp_mode, emit_vec_cvt_x_f (op_0, op_1, UNARY_OP_FRM_RMM, vec_fp_mode); } +void +expand_vec_lceil (rtx op_0, rtx op_1, machine_mode vec_fp_mode, + machine_mode vec_long_mode) +{ + gcc_assert (known_eq (GET_MODE_SIZE (vec_fp_mode), + GET_MODE_SIZE (vec_long_mode))); + + emit_vec_cvt_x_f (op_0, op_1, UNARY_OP_FRM_RUP, vec_fp_mode); +} + } // namespace riscv_vector diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/unop/math-lceil-0.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/unop/math-lceil-0.c new file mode 100644 index 00000000000..3b13a52d555 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/unop/math-lceil-0.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gcv -mabi=lp64d -O3 -ftree-vectorize -fno-vect-cost-model -ffast-math -fno-schedule-insns -fno-schedule-insns2" } */ +/* { dg-final { check-function-bodies "**" "" } } */ + +#include "test-math.h" + +/* +** test_double_long___builtin_lceil: +** frrm\s+[atx][0-9]+ +** ... +** fsrmi\s+3 +** ... +** vsetvli\s+[atx][0-9]+,\s*zero,\s*e64,\s*m1,\s*ta,\s*ma +** vfcvt\.x\.f\.v\s+v[0-9]+,\s*v[0-9]+ +** ... +** fsrm\s+[atx][0-9]+ +** ret +*/ +TEST_UNARY_CALL_CVT (double, long, __builtin_lceil) diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/unop/math-lceil-1.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/unop/math-lceil-1.c new file mode 100644 index 00000000000..5ff5d1d2ab1 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/unop/math-lceil-1.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv32gcv -mabi=ilp32f -O3 -ftree-vectorize -fno-vect-cost-model -ffast-math -fno-schedule-insns -fno-schedule-insns2" } */ +/* { dg-final { check-function-bodies "**" "" } } */ + +#include "test-math.h" + +/* +** test_float_long___builtin_lceilf: +** frrm\s+[atx][0-9]+ +** ... +** fsrmi\s+3 +** ... +** vsetvli\s+[atx][0-9]+,\s*zero,\s*e32,\s*m1,\s*ta,\s*ma +** vfcvt\.x\.f\.v\s+v[0-9]+,\s*v[0-9]+ +** ... +** fsrm\s+[atx][0-9]+ +** ret +*/ +TEST_UNARY_CALL_CVT (float, long, __builtin_lceilf) diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/unop/math-lceil-run-0.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/unop/math-lceil-run-0.c new file mode 100644 index 00000000000..8a0f668e9ba --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/unop/math-lceil-run-0.c @@ -0,0 +1,69 @@ +/* { dg-do run { target { riscv_v && rv64 } } } */ +/* { dg-additional-options "-std=c99 -O3 -ftree-vectorize -fno-vect-cost-model -ffast-math" } */ + +#include "test-math.h" + +#define ARRAY_SIZE 128 + +double in[ARRAY_SIZE]; +long out[ARRAY_SIZE]; +long ref[ARRAY_SIZE]; + +TEST_UNARY_CALL_CVT (double, long, __builtin_lceil) +TEST_ASSERT (long) + +TEST_INIT_CVT (double, 1.2, long, __builtin_lceil (1.2), 1) +TEST_INIT_CVT (double, -1.2, long, __builtin_lceil (-1.2), 2) +TEST_INIT_CVT (double, 0.5, long, __builtin_lceil (0.5), 3) +TEST_INIT_CVT (double, -0.5, long, __builtin_lceil (-0.5), 4) +TEST_INIT_CVT (double, 0.1, long, __builtin_lceil (0.1), 5) +TEST_INIT_CVT (double, -0.1, long, __builtin_lceil (-0.1), 6) +TEST_INIT_CVT (double, 3.0, long, __builtin_lceil (3.0), 7) +TEST_INIT_CVT (double, -3.0, long, __builtin_lceil (-3.0), 8) +TEST_INIT_CVT (double, 4503599627370495.5, long, __builtin_lceil (4503599627370495.5), 9) +TEST_INIT_CVT (double, 4503599627370497.0, long, __builtin_lceil (4503599627370497.0), 10) +TEST_INIT_CVT (double, -4503599627370495.5, long, __builtin_lceil (-4503599627370495.5), 11) +TEST_INIT_CVT (double, -4503599627370496.0, long, __builtin_lceil (-4503599627370496.0), 12) +TEST_INIT_CVT (double, 0.0, long, __builtin_lceil (-0.0), 13) +TEST_INIT_CVT (double, -0.0, long, __builtin_lceil (-0.0), 14) +TEST_INIT_CVT (double, 9223372036854774784.0, long, __builtin_lceil (9223372036854774784.0), 15) +TEST_INIT_CVT (double, 9223372036854775808.0, long, 0x7fffffffffffffff, 16) +TEST_INIT_CVT (double, -9223372036854775808.0, long, __builtin_lceil (-9223372036854775808.0), 17) +TEST_INIT_CVT (double, -9223372036854777856.0, long, 0x8000000000000000, 18) +TEST_INIT_CVT (double, __builtin_inf (), long, __builtin_lceil (__builtin_inf ()), 19) +TEST_INIT_CVT (double, -__builtin_inf (), long, __builtin_lceil (-__builtin_inf ()), 20) +TEST_INIT_CVT (double, __builtin_nan (""), long, 0x7fffffffffffffff, 21) + +/* + Similar to lround, some reference are hard-code instead of leveraging + scalar __builtin_lceil because the return value of a NaN or an infinity, + or the rounded value is too large to be stored in a long is UNSPECIFIED. +*/ + +int +main () +{ + RUN_TEST_CVT (double, long, 1, __builtin_lceil, in, out, ref, ARRAY_SIZE); + RUN_TEST_CVT (double, long, 2, __builtin_lceil, in, out, ref, ARRAY_SIZE); + RUN_TEST_CVT (double, long, 3, __builtin_lceil, in, out, ref, ARRAY_SIZE); + RUN_TEST_CVT (double, long, 4, __builtin_lceil, in, out, ref, ARRAY_SIZE); + RUN_TEST_CVT (double, long, 5, __builtin_lceil, in, out, ref, ARRAY_SIZE); + RUN_TEST_CVT (double, long, 6, __builtin_lceil, in, out, ref, ARRAY_SIZE); + RUN_TEST_CVT (double, long, 7, __builtin_lceil, in, out, ref, ARRAY_SIZE); + RUN_TEST_CVT (double, long, 8, __builtin_lceil, in, out, ref, ARRAY_SIZE); + RUN_TEST_CVT (double, long, 9, __builtin_lceil, in, out, ref, ARRAY_SIZE); + RUN_TEST_CVT (double, long, 10, __builtin_lceil, in, out, ref, ARRAY_SIZE); + RUN_TEST_CVT (double, long, 11, __builtin_lceil, in, out, ref, ARRAY_SIZE); + RUN_TEST_CVT (double, long, 12, __builtin_lceil, in, out, ref, ARRAY_SIZE); + RUN_TEST_CVT (double, long, 13, __builtin_lceil, in, out, ref, ARRAY_SIZE); + RUN_TEST_CVT (double, long, 14, __builtin_lceil, in, out, ref, ARRAY_SIZE); + RUN_TEST_CVT (double, long, 15, __builtin_lceil, in, out, ref, ARRAY_SIZE); + RUN_TEST_CVT (double, long, 16, __builtin_lceil, in, out, ref, ARRAY_SIZE); + RUN_TEST_CVT (double, long, 17, __builtin_lceil, in, out, ref, ARRAY_SIZE); + RUN_TEST_CVT (double, long, 18, __builtin_lceil, in, out, ref, ARRAY_SIZE); + RUN_TEST_CVT (double, long, 19, __builtin_lceil, in, out, ref, ARRAY_SIZE); + RUN_TEST_CVT (double, long, 20, __builtin_lceil, in, out, ref, ARRAY_SIZE); + RUN_TEST_CVT (double, long, 21, __builtin_lceil, in, out, ref, ARRAY_SIZE); + + return 0; +} diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/unop/math-lceil-run-1.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/unop/math-lceil-run-1.c new file mode 100644 index 00000000000..e5e22ada1ed --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/unop/math-lceil-run-1.c @@ -0,0 +1,69 @@ +/* { dg-do run { target { riscv_v && rv32 } } } */ +/* { dg-additional-options "-std=c99 -O3 -ftree-vectorize -fno-vect-cost-model -ffast-math" } */ + +#include "test-math.h" + +#define ARRAY_SIZE 128 + +float in[ARRAY_SIZE]; +long out[ARRAY_SIZE]; +long ref[ARRAY_SIZE]; + +TEST_UNARY_CALL_CVT (float, long, __builtin_lceilf) +TEST_ASSERT (long) + +TEST_INIT_CVT (float, 1.2, long, __builtin_lceilf (1.2), 1) +TEST_INIT_CVT (float, -1.2, long, __builtin_lceilf (-1.2), 2) +TEST_INIT_CVT (float, 0.5, long, __builtin_lceilf (0.5), 3) +TEST_INIT_CVT (float, -0.5, long, __builtin_lceilf (-0.5), 4) +TEST_INIT_CVT (float, 0.1, long, __builtin_lceilf (0.1), 5) +TEST_INIT_CVT (float, -0.1, long, __builtin_lceilf (-0.1), 6) +TEST_INIT_CVT (float, 3.0, long, __builtin_lceilf (3.0), 7) +TEST_INIT_CVT (float, -3.0, long, __builtin_lceilf (-3.0), 8) +TEST_INIT_CVT (float, 8388607.5, long, __builtin_lceilf (8388607.5), 9) +TEST_INIT_CVT (float, 8388609.0, long, __builtin_lceilf (8388609.0), 10) +TEST_INIT_CVT (float, -8388607.5, long, __builtin_lceilf (-8388607.5), 11) +TEST_INIT_CVT (float, -8388609.0, long, __builtin_lceilf (-8388609.0), 12) +TEST_INIT_CVT (float, 0.0, long, __builtin_lceilf (-0.0), 13) +TEST_INIT_CVT (float, -0.0, long, __builtin_lceilf (-0.0), 14) +TEST_INIT_CVT (float, 2147483520.0, long, __builtin_lceilf (2147483520.0), 15) +TEST_INIT_CVT (float, 2147483648.0, long, 0x7fffffff, 16) +TEST_INIT_CVT (float, -2147483648.0, long, __builtin_lceilf (-2147483648.0), 17) +TEST_INIT_CVT (float, -2147483904.0, long, 0x80000000, 18) +TEST_INIT_CVT (float, __builtin_inf (), long, __builtin_lceilf (__builtin_inff ()), 19) +TEST_INIT_CVT (float, -__builtin_inf (), long, __builtin_lceilf (-__builtin_inff ()), 20) +TEST_INIT_CVT (float, __builtin_nanf (""), long, 0x7fffffff, 21) + +/* + Similar to lround, some reference are hard-code instead of leveraging + scalar __builtin_lceil because the return value of a NaN or an infinity, + or the rounded value is too large to be stored in a long is UNSPECIFIED. +*/ + +int +main () +{ + RUN_TEST_CVT (float, long, 1, __builtin_lceilf, in, out, ref, ARRAY_SIZE); + RUN_TEST_CVT (float, long, 2, __builtin_lceilf, in, out, ref, ARRAY_SIZE); + RUN_TEST_CVT (float, long, 3, __builtin_lceilf, in, out, ref, ARRAY_SIZE); + RUN_TEST_CVT (float, long, 4, __builtin_lceilf, in, out, ref, ARRAY_SIZE); + RUN_TEST_CVT (float, long, 5, __builtin_lceilf, in, out, ref, ARRAY_SIZE); + RUN_TEST_CVT (float, long, 6, __builtin_lceilf, in, out, ref, ARRAY_SIZE); + RUN_TEST_CVT (float, long, 7, __builtin_lceilf, in, out, ref, ARRAY_SIZE); + RUN_TEST_CVT (float, long, 8, __builtin_lceilf, in, out, ref, ARRAY_SIZE); + RUN_TEST_CVT (float, long, 9, __builtin_lceilf, in, out, ref, ARRAY_SIZE); + RUN_TEST_CVT (float, long, 10, __builtin_lceilf, in, out, ref, ARRAY_SIZE); + RUN_TEST_CVT (float, long, 11, __builtin_lceilf, in, out, ref, ARRAY_SIZE); + RUN_TEST_CVT (float, long, 12, __builtin_lceilf, in, out, ref, ARRAY_SIZE); + RUN_TEST_CVT (float, long, 13, __builtin_lceilf, in, out, ref, ARRAY_SIZE); + RUN_TEST_CVT (float, long, 14, __builtin_lceilf, in, out, ref, ARRAY_SIZE); + RUN_TEST_CVT (float, long, 15, __builtin_lceilf, in, out, ref, ARRAY_SIZE); + RUN_TEST_CVT (float, long, 16, __builtin_lceilf, in, out, ref, ARRAY_SIZE); + RUN_TEST_CVT (float, long, 17, __builtin_lceilf, in, out, ref, ARRAY_SIZE); + RUN_TEST_CVT (float, long, 18, __builtin_lceilf, in, out, ref, ARRAY_SIZE); + RUN_TEST_CVT (float, long, 19, __builtin_lceilf, in, out, ref, ARRAY_SIZE); + RUN_TEST_CVT (float, long, 20, __builtin_lceilf, in, out, ref, ARRAY_SIZE); + RUN_TEST_CVT (float, long, 21, __builtin_lceilf, in, out, ref, ARRAY_SIZE); + + return 0; +} diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/math-lceil-0.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/math-lceil-0.c new file mode 100644 index 00000000000..f84357460af --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/math-lceil-0.c @@ -0,0 +1,30 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gcv_zvfh_zvl4096b -mabi=lp64d -O3 --param=riscv-autovec-lmul=m8 -ffast-math -fdump-tree-optimized" } */ + +#include "def.h" + +DEF_OP_V_CVT (lceil, 1, double, long, __builtin_lceil) +DEF_OP_V_CVT (lceil, 2, double, long, __builtin_lceil) +DEF_OP_V_CVT (lceil, 4, double, long, __builtin_lceil) +DEF_OP_V_CVT (lceil, 8, double, long, __builtin_lceil) +DEF_OP_V_CVT (lceil, 16, double, long, __builtin_lceil) +DEF_OP_V_CVT (lceil, 32, double, long, __builtin_lceil) +DEF_OP_V_CVT (lceil, 64, double, long, __builtin_lceil) +DEF_OP_V_CVT (lceil, 128, double, long, __builtin_lceil) +DEF_OP_V_CVT (lceil, 256, double, long, __builtin_lceil) +DEF_OP_V_CVT (lceil, 512, double, long, __builtin_lceil) + +/* { dg-final { scan-assembler-not {csrr} } } */ +/* { dg-final { scan-tree-dump-not "1,1" "optimized" } } */ +/* { dg-final { scan-tree-dump-not "2,2" "optimized" } } */ +/* { dg-final { scan-tree-dump-not "4,4" "optimized" } } */ +/* { dg-final { scan-tree-dump-not "16,16" "optimized" } } */ +/* { dg-final { scan-tree-dump-not "32,32" "optimized" } } */ +/* { dg-final { scan-tree-dump-not "64,64" "optimized" } } */ +/* { dg-final { scan-tree-dump-not "128,128" "optimized" } } */ +/* { dg-final { scan-tree-dump-not "256,256" "optimized" } } */ +/* { dg-final { scan-tree-dump-not "512,512" "optimized" } } */ +/* { dg-final { scan-tree-dump-not "1024,1024" "optimized" } } */ +/* { dg-final { scan-tree-dump-not "2048,2048" "optimized" } } */ +/* { dg-final { scan-tree-dump-not "4096,4096" "optimized" } } */ +/* { dg-final { scan-assembler-times {vfcvt\.x\.f\.v\s+v[0-9]+,\s*v[0-9]+} 9 } } */ diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/math-lceil-1.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/math-lceil-1.c new file mode 100644 index 00000000000..2d4080868a9 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/math-lceil-1.c @@ -0,0 +1,30 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv32gcv_zvl4096b -mabi=ilp32f -O3 --param=riscv-autovec-lmul=m8 -ffast-math -fdump-tree-optimized" } */ + +#include "def.h" + +DEF_OP_V_CVT (lceilf, 1, float, long, __builtin_lceilf) +DEF_OP_V_CVT (lceilf, 2, float, long, __builtin_lceilf) +DEF_OP_V_CVT (lceilf, 4, float, long, __builtin_lceilf) +DEF_OP_V_CVT (lceilf, 8, float, long, __builtin_lceilf) +DEF_OP_V_CVT (lceilf, 16, float, long, __builtin_lceilf) +DEF_OP_V_CVT (lceilf, 32, float, long, __builtin_lceilf) +DEF_OP_V_CVT (lceilf, 64, float, long, __builtin_lceilf) +DEF_OP_V_CVT (lceilf, 128, float, long, __builtin_lceilf) +DEF_OP_V_CVT (lceilf, 256, float, long, __builtin_lceilf) +DEF_OP_V_CVT (lceilf, 512, float, long, __builtin_lceilf) + +/* { dg-final { scan-assembler-not {csrr} } } */ +/* { dg-final { scan-tree-dump-not "1,1" "optimized" } } */ +/* { dg-final { scan-tree-dump-not "2,2" "optimized" } } */ +/* { dg-final { scan-tree-dump-not "4,4" "optimized" } } */ +/* { dg-final { scan-tree-dump-not "16,16" "optimized" } } */ +/* { dg-final { scan-tree-dump-not "32,32" "optimized" } } */ +/* { dg-final { scan-tree-dump-not "64,64" "optimized" } } */ +/* { dg-final { scan-tree-dump-not "128,128" "optimized" } } */ +/* { dg-final { scan-tree-dump-not "256,256" "optimized" } } */ +/* { dg-final { scan-tree-dump-not "512,512" "optimized" } } */ +/* { dg-final { scan-tree-dump-not "1024,1024" "optimized" } } */ +/* { dg-final { scan-tree-dump-not "2048,2048" "optimized" } } */ +/* { dg-final { scan-tree-dump-not "4096,4096" "optimized" } } */ +/* { dg-final { scan-assembler-times {vfcvt\.x\.f\.v\s+v[0-9]+,\s*v[0-9]+} 9 } } */