Message ID | CALkvSf-K2bWSF_o4OOj89jkhEmTpGNrc_ZGKCRERPgK_HcdSHw@mail.gmail.com |
---|---|
State | New, archived |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6a10:38f:b0:2d5:3c95:9e21 with SMTP id 15csp1686283pxh; Mon, 15 Aug 2022 17:45:20 -0700 (PDT) X-Google-Smtp-Source: AA6agR7RocoY/Y5byp9v2vWak23X390UnNsdSxA967hk/RK2ybM4NoHZ8lUlkcED7gvLPHPiIBpe X-Received: by 2002:a05:6402:5289:b0:43b:69a9:38c8 with SMTP id en9-20020a056402528900b0043b69a938c8mr17094610edb.263.1660610720469; Mon, 15 Aug 2022 17:45:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660610720; cv=none; d=google.com; s=arc-20160816; b=QnUpS2Aqct5jiQNVkxtEDvyrKJu+cXJzw9xAz03TfvgZifttwajydhUuHJsxif51AA VckCTtQigs0Su2XPxgLFHwuBBzIkCgKtwaYHI3Ew4Xu/FuyTGTU0McPrJw4qokameqCZ i89KOKm+laYzO+SC+kJ1n5so0wEewUbIYZoCk/RPnm3ttxxeLDrp5VxT+XWmfiaKuaix D45FkK0dkY1Bj+TmV8nXU4NBYmvUd13piJF/lWVBNQTNEJ3mXFH9BK6WpkQT7HT0uMqW QQS8flMAPWHDCmIvpYELEyRR2jK+5HxIHON+ESNDlmdhGWY6of7HknYUg6iIrWAphaMJ +mOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:to:subject:message-id:date:from :mime-version:dkim-signature:dmarc-filter:delivered-to; bh=bSYheP2esTsDNb+TK/srMextIQRBtZH1nnGT18xKqCg=; b=Jd3qAIfxjzem0fwKH8dc3tXGbeWP0M6Z3yIIOY/k7eEmj6lxgBPbFAUwGOxlZSZu2a JQ5dsjPksscg+KUKc+B8363QY4/CcN8sqFVlB+LfxlveHxi3eP/cSYYhT+FRyPh+4Ok7 tNrW/DtDrOOBBfEsjbSCceRyfqfdsFLa/t2Sw/uwCbrlcUqbNffa9q+5DDTTg5QbwpYB Sn7MWtx43ydqD6DK1WZK1rQ4X+3CMnRhtBBdL6CGIdWkx121jEGRZ8df5nk6hAAVwgv4 xTbU4Tq1gZWB6FEuG5IQXta9aTpehtO0xAsj3MUyRvFdARa+z+mFwEG+FnaKLQhAc7TN 9+kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=Mrca3exP; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id w13-20020a05640234cd00b0043bd6cf51d1si10018545edc.530.2022.08.15.17.45.20 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Aug 2022 17:45:20 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=Mrca3exP; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7412538582A5 for <ouuuleilei@gmail.com>; Tue, 16 Aug 2022 00:45:16 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by sourceware.org (Postfix) with ESMTPS id 3F3793858C2D for <gcc-patches@gcc.gnu.org>; Tue, 16 Aug 2022 00:44:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3F3793858C2D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-pg1-x534.google.com with SMTP id 24so7920367pgr.7 for <gcc-patches@gcc.gnu.org>; Mon, 15 Aug 2022 17:44:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; h=to:subject:message-id:date:from:mime-version:from:to:cc; bh=poNRC37YtFvZqKQLJhwkSfqCg/hPTCIAojrY2iGo1D4=; b=Mrca3exPxIh7fwVbCFNJU5W+iWxRZjJDTBQofWlKWXfezXl9XeD+k30ZneX32SpduP 3jcR0Bmy9WdhDS3d9PmVp7JCo1GBlHFoeT3yUou3SBqdY5tBQwengzq0O1WHw9Gg6ux2 TvX2uWwcfKfkMbBHdF3l1HA+DUd9JRdX/HXYnNkOQqb+Ycq+5JoUjMM1C8ABS/Zf8/wt L+W3pD0ifhzpO+pQC+dhmDQ2zfONeJRyjzAAMx5xFC+AyoIFsYt0bW4FRrTcuOElvwt9 tUeCyO+loXGbLCGJVKrGmUe8BvFb+ZJt46RAaLks5C/FHUMdw9XwV9K8L/lvZ6MrS++q fiQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc; bh=poNRC37YtFvZqKQLJhwkSfqCg/hPTCIAojrY2iGo1D4=; b=wlK6XrSjudCHUMuuNwt5m0vA6pPC7Mppj59n2FSTt+V+QnDofOEeQRo36LjVITd96S Himd82WEw+qaJQZX0xYnWsVYEe07yo2spm5zY7ycaJ4g8cP9HXO9NMGC/ZLHo82Dcf4z 5LUCvnHy6vAU9v45WI4gynUUxLOEMpkhpTx2QoxiUJrlkqmb5/cKFQ73Q9cfZi/KTxyJ g4D9lAUtpflqTI6A7+mdxpo77t4OX+0LyXdDwBM0K3K7Ld9C5RIh04Iz+OwEHi8OiWlW NinxqreUdK7HoEK2r/JemKXimSB65ylKkCKEQ9NPdsckKRQtso9UVtIKqg/ZPlS05GeR T3dg== X-Gm-Message-State: ACgBeo3YOFCqW8Ip2cpWX/gTx2YUwhu8Dfib3aV/VUZ5so1ELjzEvt1t mxXOEYuOrbAXaunnZ8rxwH3i8AgCU41bwVHB1bgBVKylIXl67A== X-Received: by 2002:a05:6a00:2906:b0:52a:bc7f:f801 with SMTP id cg6-20020a056a00290600b0052abc7ff801mr19322874pfb.49.1660610685776; Mon, 15 Aug 2022 17:44:45 -0700 (PDT) MIME-Version: 1.0 From: Kevin Lee <kevinl@rivosinc.com> Date: Mon, 15 Aug 2022 17:44:35 -0700 Message-ID: <CALkvSf-K2bWSF_o4OOj89jkhEmTpGNrc_ZGKCRERPgK_HcdSHw@mail.gmail.com> Subject: [PATCH] RISC-V missing __builtin_lceil and __builtin_lfloor To: gcc-patches@gcc.gnu.org X-Spam-Status: No, score=-8.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, HTML_MESSAGE, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1741276546651164958?= X-GMAIL-MSGID: =?utf-8?q?1741276546651164958?= |
Series |
RISC-V missing __builtin_lceil and __builtin_lfloor
|
|
Commit Message
Kevin Lee
Aug. 16, 2022, 12:44 a.m. UTC
Hello, Currently, __builtin_lceil and __builtin_lfloor doesn't generate an existing instruction fcvt, but rather calls ceil and floor from the library. This patch adds the missing iterator and attributes for lceil and lfloor to produce the optimized code. The test cases check the correct generation of the fcvt instruction for float/double to int/long/long long. Passed the test in riscv-linux. Could this patch be committed? gcc/ChangeLog: Michael Collison <collison@rivosinc.com> * config/riscv/riscv.md (RINT): Add iterator for lceil and lround. (rint_pattern): Add ceil and floor. (rint_rm): Add rup and rdn. gcc/testsuite/ChangeLog: Kevin Lee <kevinl@rivosinc.com> * gcc.target/riscv/lfloor-lceil.c: New test. --- gcc/config/riscv/riscv.md | 13 ++- gcc/testsuite/gcc.target/riscv/lfloor-lceil.c | 79 +++++++++++++++++++ 2 files changed, 88 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gcc.target/riscv/lfloor-lceil.c
Comments
On Mon, 15 Aug 2022 17:44:35 PDT (-0700), kevinl@rivosinc.com wrote: > Hello, > Currently, __builtin_lceil and __builtin_lfloor doesn't generate an > existing instruction fcvt, but rather calls ceil and floor from the > library. This patch adds the missing iterator and attributes for lceil and > lfloor to produce the optimized code. > The test cases check the correct generation of the fcvt instruction for > float/double to int/long/long long. Passed the test in riscv-linux. > Could this patch be committed? Reviewed-by: Palmer Dabbelt <palmer@rivosinc.com> Acked-by: Palmer Dabbelt <palmer@rivosinc.com> Not sure if Kito had any comments for this one, but it looks good to me. > gcc/ChangeLog: > Michael Collison <collison@rivosinc.com> > * config/riscv/riscv.md (RINT): Add iterator for lceil and lround. > (rint_pattern): Add ceil and floor. > (rint_rm): Add rup and rdn. > > gcc/testsuite/ChangeLog: > Kevin Lee <kevinl@rivosinc.com> > * gcc.target/riscv/lfloor-lceil.c: New test. > --- > gcc/config/riscv/riscv.md | 13 ++- > gcc/testsuite/gcc.target/riscv/lfloor-lceil.c | 79 +++++++++++++++++++ > 2 files changed, 88 insertions(+), 4 deletions(-) > create mode 100644 gcc/testsuite/gcc.target/riscv/lfloor-lceil.c > > diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md > index c6399b1389e..070004fa7fe 100644 > --- a/gcc/config/riscv/riscv.md > +++ b/gcc/config/riscv/riscv.md > @@ -43,6 +43,9 @@ (define_c_enum "unspec" [ > UNSPEC_LRINT > UNSPEC_LROUND > > + UNSPEC_LCEIL > + UNSPEC_LFLOOR > + > ;; Stack tie > UNSPEC_TIE > ]) > @@ -345,10 +348,12 @@ (define_mode_attr UNITMODE [(SF "SF") (DF "DF")]) > ;; the controlling mode. > (define_mode_attr HALFMODE [(DF "SI") (DI "SI") (TF "DI")]) > > -;; Iterator and attributes for floating-point rounding instructions. > -(define_int_iterator RINT [UNSPEC_LRINT UNSPEC_LROUND]) > -(define_int_attr rint_pattern [(UNSPEC_LRINT "rint") (UNSPEC_LROUND > "round")]) > -(define_int_attr rint_rm [(UNSPEC_LRINT "dyn") (UNSPEC_LROUND "rmm")]) > +;; Iterator and attributes for floating-point rounding instructions.f > +(define_int_iterator RINT [UNSPEC_LRINT UNSPEC_LROUND UNSPEC_LCEIL > UNSPEC_LFLOOR]) > +(define_int_attr rint_pattern [(UNSPEC_LRINT "rint") (UNSPEC_LROUND > "round") > + (UNSPEC_LCEIL "ceil") (UNSPEC_LFLOOR > "floor")]) > +(define_int_attr rint_rm [(UNSPEC_LRINT "dyn") (UNSPEC_LROUND "rmm") > + (UNSPEC_LCEIL "rup") (UNSPEC_LFLOOR "rdn")]) > > ;; Iterator and attributes for quiet comparisons. > (define_int_iterator QUIET_COMPARISON [UNSPEC_FLT_QUIET UNSPEC_FLE_QUIET]) > diff --git a/gcc/testsuite/gcc.target/riscv/lfloor-lceil.c > b/gcc/testsuite/gcc.target/riscv/lfloor-lceil.c > new file mode 100644 > index 00000000000..4d81c12cefa > --- /dev/null > +++ b/gcc/testsuite/gcc.target/riscv/lfloor-lceil.c > @@ -0,0 +1,79 @@ > +/* { dg-do compile } */ > +/* { dg-options "-march=rv64gc -mabi=lp64d" } */ > +/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" } } */ > + > +int > +ceil1(float i) > +{ > + return __builtin_lceil(i); > +} > + > +long > +ceil2(float i) > +{ > + return __builtin_lceil(i); > +} > + > +long long > +ceil3(float i) > +{ > + return __builtin_lceil(i); > +} > + > +int > +ceil4(double i) > +{ > + return __builtin_lceil(i); > +} > + > +long > +ceil5(double i) > +{ > + return __builtin_lceil(i); > +} > + > +long long > +ceil6(double i) > +{ > + return __builtin_lceil(i); > +} > + > +int > +floor1(float i) > +{ > + return __builtin_lfloor(i); > +} > + > +long > +floor2(float i) > +{ > + return __builtin_lfloor(i); > +} > + > +long long > +floor3(float i) > +{ > + return __builtin_lfloor(i); > +} > + > +int > +floor4(double i) > +{ > + return __builtin_lfloor(i); > +} > + > +long > +floor5(double i) > +{ > + return __builtin_lfloor(i); > +} > + > +long long > +floor6(double i) > +{ > + return __builtin_lfloor(i); > +} > + > +/* { dg-final { scan-assembler-times "fcvt.l.s" 6 } } */ > +/* { dg-final { scan-assembler-times "fcvt.l.d" 6 } } */ > +/* { dg-final { scan-assembler-not "call" } } */
LGTM, thanks, I guess I just missed this before Palmer Dabbelt <palmer@dabbelt.com> 於 2022年9月17日 週六 23:07 寫道: > On Mon, 15 Aug 2022 17:44:35 PDT (-0700), kevinl@rivosinc.com wrote: > > Hello, > > Currently, __builtin_lceil and __builtin_lfloor doesn't generate an > > existing instruction fcvt, but rather calls ceil and floor from the > > library. This patch adds the missing iterator and attributes for lceil > and > > lfloor to produce the optimized code. > > The test cases check the correct generation of the fcvt instruction for > > float/double to int/long/long long. Passed the test in riscv-linux. > > Could this patch be committed? > > Reviewed-by: Palmer Dabbelt <palmer@rivosinc.com> > Acked-by: Palmer Dabbelt <palmer@rivosinc.com> > > Not sure if Kito had any comments for this one, but it looks good to me. > > > gcc/ChangeLog: > > Michael Collison <collison@rivosinc.com> > > * config/riscv/riscv.md (RINT): Add iterator for lceil and > lround. > > (rint_pattern): Add ceil and floor. > > (rint_rm): Add rup and rdn. > > > > gcc/testsuite/ChangeLog: > > Kevin Lee <kevinl@rivosinc.com> > > * gcc.target/riscv/lfloor-lceil.c: New test. > > --- > > gcc/config/riscv/riscv.md | 13 ++- > > gcc/testsuite/gcc.target/riscv/lfloor-lceil.c | 79 +++++++++++++++++++ > > 2 files changed, 88 insertions(+), 4 deletions(-) > > create mode 100644 gcc/testsuite/gcc.target/riscv/lfloor-lceil.c > > > > diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md > > index c6399b1389e..070004fa7fe 100644 > > --- a/gcc/config/riscv/riscv.md > > +++ b/gcc/config/riscv/riscv.md > > @@ -43,6 +43,9 @@ (define_c_enum "unspec" [ > > UNSPEC_LRINT > > UNSPEC_LROUND > > > > + UNSPEC_LCEIL > > + UNSPEC_LFLOOR > > + > > ;; Stack tie > > UNSPEC_TIE > > ]) > > @@ -345,10 +348,12 @@ (define_mode_attr UNITMODE [(SF "SF") (DF "DF")]) > > ;; the controlling mode. > > (define_mode_attr HALFMODE [(DF "SI") (DI "SI") (TF "DI")]) > > > > -;; Iterator and attributes for floating-point rounding instructions. > > -(define_int_iterator RINT [UNSPEC_LRINT UNSPEC_LROUND]) > > -(define_int_attr rint_pattern [(UNSPEC_LRINT "rint") (UNSPEC_LROUND > > "round")]) > > -(define_int_attr rint_rm [(UNSPEC_LRINT "dyn") (UNSPEC_LROUND "rmm")]) > > +;; Iterator and attributes for floating-point rounding instructions.f > > +(define_int_iterator RINT [UNSPEC_LRINT UNSPEC_LROUND UNSPEC_LCEIL > > UNSPEC_LFLOOR]) > > +(define_int_attr rint_pattern [(UNSPEC_LRINT "rint") (UNSPEC_LROUND > > "round") > > + (UNSPEC_LCEIL "ceil") (UNSPEC_LFLOOR > > "floor")]) > > +(define_int_attr rint_rm [(UNSPEC_LRINT "dyn") (UNSPEC_LROUND "rmm") > > + (UNSPEC_LCEIL "rup") (UNSPEC_LFLOOR "rdn")]) > > > > ;; Iterator and attributes for quiet comparisons. > > (define_int_iterator QUIET_COMPARISON [UNSPEC_FLT_QUIET > UNSPEC_FLE_QUIET]) > > diff --git a/gcc/testsuite/gcc.target/riscv/lfloor-lceil.c > > b/gcc/testsuite/gcc.target/riscv/lfloor-lceil.c > > new file mode 100644 > > index 00000000000..4d81c12cefa > > --- /dev/null > > +++ b/gcc/testsuite/gcc.target/riscv/lfloor-lceil.c > > @@ -0,0 +1,79 @@ > > +/* { dg-do compile } */ > > +/* { dg-options "-march=rv64gc -mabi=lp64d" } */ > > +/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" } } */ > > + > > +int > > +ceil1(float i) > > +{ > > + return __builtin_lceil(i); > > +} > > + > > +long > > +ceil2(float i) > > +{ > > + return __builtin_lceil(i); > > +} > > + > > +long long > > +ceil3(float i) > > +{ > > + return __builtin_lceil(i); > > +} > > + > > +int > > +ceil4(double i) > > +{ > > + return __builtin_lceil(i); > > +} > > + > > +long > > +ceil5(double i) > > +{ > > + return __builtin_lceil(i); > > +} > > + > > +long long > > +ceil6(double i) > > +{ > > + return __builtin_lceil(i); > > +} > > + > > +int > > +floor1(float i) > > +{ > > + return __builtin_lfloor(i); > > +} > > + > > +long > > +floor2(float i) > > +{ > > + return __builtin_lfloor(i); > > +} > > + > > +long long > > +floor3(float i) > > +{ > > + return __builtin_lfloor(i); > > +} > > + > > +int > > +floor4(double i) > > +{ > > + return __builtin_lfloor(i); > > +} > > + > > +long > > +floor5(double i) > > +{ > > + return __builtin_lfloor(i); > > +} > > + > > +long long > > +floor6(double i) > > +{ > > + return __builtin_lfloor(i); > > +} > > + > > +/* { dg-final { scan-assembler-times "fcvt.l.s" 6 } } */ > > +/* { dg-final { scan-assembler-times "fcvt.l.d" 6 } } */ > > +/* { dg-final { scan-assembler-not "call" } } */ >
On Sat, 17 Sep 2022 14:16:13 PDT (-0700), Kito Cheng wrote: > LGTM, thanks, I guess I just missed this before No worries, I'd just stubmled on it looking through old stuff. Kevin: Looks like this got corrupted, possibly from copy/paste into gmail. I resurrect it, but there's a floating-point test failure in gfortran. Looks like it predates this, but I'm trying to bisect it to at least have a root cause before just ignoring it. I've got this floating around on a branch and hopefully that'll remind me to commit it after I sort that out. > > Palmer Dabbelt <palmer@dabbelt.com> 於 2022年9月17日 週六 23:07 寫道: > >> On Mon, 15 Aug 2022 17:44:35 PDT (-0700), kevinl@rivosinc.com wrote: >> > Hello, >> > Currently, __builtin_lceil and __builtin_lfloor doesn't generate an >> > existing instruction fcvt, but rather calls ceil and floor from the >> > library. This patch adds the missing iterator and attributes for lceil >> and >> > lfloor to produce the optimized code. >> > The test cases check the correct generation of the fcvt instruction for >> > float/double to int/long/long long. Passed the test in riscv-linux. >> > Could this patch be committed? >> >> Reviewed-by: Palmer Dabbelt <palmer@rivosinc.com> >> Acked-by: Palmer Dabbelt <palmer@rivosinc.com> >> >> Not sure if Kito had any comments for this one, but it looks good to me. >> >> > gcc/ChangeLog: >> > Michael Collison <collison@rivosinc.com> >> > * config/riscv/riscv.md (RINT): Add iterator for lceil and >> lround. >> > (rint_pattern): Add ceil and floor. >> > (rint_rm): Add rup and rdn. >> > >> > gcc/testsuite/ChangeLog: >> > Kevin Lee <kevinl@rivosinc.com> >> > * gcc.target/riscv/lfloor-lceil.c: New test. >> > --- >> > gcc/config/riscv/riscv.md | 13 ++- >> > gcc/testsuite/gcc.target/riscv/lfloor-lceil.c | 79 +++++++++++++++++++ >> > 2 files changed, 88 insertions(+), 4 deletions(-) >> > create mode 100644 gcc/testsuite/gcc.target/riscv/lfloor-lceil.c >> > >> > diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md >> > index c6399b1389e..070004fa7fe 100644 >> > --- a/gcc/config/riscv/riscv.md >> > +++ b/gcc/config/riscv/riscv.md >> > @@ -43,6 +43,9 @@ (define_c_enum "unspec" [ >> > UNSPEC_LRINT >> > UNSPEC_LROUND >> > >> > + UNSPEC_LCEIL >> > + UNSPEC_LFLOOR >> > + >> > ;; Stack tie >> > UNSPEC_TIE >> > ]) >> > @@ -345,10 +348,12 @@ (define_mode_attr UNITMODE [(SF "SF") (DF "DF")]) >> > ;; the controlling mode. >> > (define_mode_attr HALFMODE [(DF "SI") (DI "SI") (TF "DI")]) >> > >> > -;; Iterator and attributes for floating-point rounding instructions. >> > -(define_int_iterator RINT [UNSPEC_LRINT UNSPEC_LROUND]) >> > -(define_int_attr rint_pattern [(UNSPEC_LRINT "rint") (UNSPEC_LROUND >> > "round")]) >> > -(define_int_attr rint_rm [(UNSPEC_LRINT "dyn") (UNSPEC_LROUND "rmm")]) >> > +;; Iterator and attributes for floating-point rounding instructions.f >> > +(define_int_iterator RINT [UNSPEC_LRINT UNSPEC_LROUND UNSPEC_LCEIL >> > UNSPEC_LFLOOR]) >> > +(define_int_attr rint_pattern [(UNSPEC_LRINT "rint") (UNSPEC_LROUND >> > "round") >> > + (UNSPEC_LCEIL "ceil") (UNSPEC_LFLOOR >> > "floor")]) >> > +(define_int_attr rint_rm [(UNSPEC_LRINT "dyn") (UNSPEC_LROUND "rmm") >> > + (UNSPEC_LCEIL "rup") (UNSPEC_LFLOOR "rdn")]) >> > >> > ;; Iterator and attributes for quiet comparisons. >> > (define_int_iterator QUIET_COMPARISON [UNSPEC_FLT_QUIET >> UNSPEC_FLE_QUIET]) >> > diff --git a/gcc/testsuite/gcc.target/riscv/lfloor-lceil.c >> > b/gcc/testsuite/gcc.target/riscv/lfloor-lceil.c >> > new file mode 100644 >> > index 00000000000..4d81c12cefa >> > --- /dev/null >> > +++ b/gcc/testsuite/gcc.target/riscv/lfloor-lceil.c >> > @@ -0,0 +1,79 @@ >> > +/* { dg-do compile } */ >> > +/* { dg-options "-march=rv64gc -mabi=lp64d" } */ >> > +/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" } } */ >> > + >> > +int >> > +ceil1(float i) >> > +{ >> > + return __builtin_lceil(i); >> > +} >> > + >> > +long >> > +ceil2(float i) >> > +{ >> > + return __builtin_lceil(i); >> > +} >> > + >> > +long long >> > +ceil3(float i) >> > +{ >> > + return __builtin_lceil(i); >> > +} >> > + >> > +int >> > +ceil4(double i) >> > +{ >> > + return __builtin_lceil(i); >> > +} >> > + >> > +long >> > +ceil5(double i) >> > +{ >> > + return __builtin_lceil(i); >> > +} >> > + >> > +long long >> > +ceil6(double i) >> > +{ >> > + return __builtin_lceil(i); >> > +} >> > + >> > +int >> > +floor1(float i) >> > +{ >> > + return __builtin_lfloor(i); >> > +} >> > + >> > +long >> > +floor2(float i) >> > +{ >> > + return __builtin_lfloor(i); >> > +} >> > + >> > +long long >> > +floor3(float i) >> > +{ >> > + return __builtin_lfloor(i); >> > +} >> > + >> > +int >> > +floor4(double i) >> > +{ >> > + return __builtin_lfloor(i); >> > +} >> > + >> > +long >> > +floor5(double i) >> > +{ >> > + return __builtin_lfloor(i); >> > +} >> > + >> > +long long >> > +floor6(double i) >> > +{ >> > + return __builtin_lfloor(i); >> > +} >> > + >> > +/* { dg-final { scan-assembler-times "fcvt.l.s" 6 } } */ >> > +/* { dg-final { scan-assembler-times "fcvt.l.d" 6 } } */ >> > +/* { dg-final { scan-assembler-not "call" } } */ >>
Thank you for the update Palmer. I'll certainly look into the corrupted patch issue and the floating-point test failure in gfortran. On Sun, Oct 2, 2022 at 1:42 PM Palmer Dabbelt <palmer@dabbelt.com> wrote: > On Sat, 17 Sep 2022 14:16:13 PDT (-0700), Kito Cheng wrote: > > LGTM, thanks, I guess I just missed this before > > No worries, I'd just stubmled on it looking through old stuff. > > Kevin: Looks like this got corrupted, possibly from copy/paste into > gmail. I resurrect it, but there's a floating-point test failure in > gfortran. Looks like it predates this, but I'm trying to bisect it to > at least have a root cause before just ignoring it. I've got this > floating around on a branch and hopefully that'll remind me to commit > it after I sort that out. > > > > > Palmer Dabbelt <palmer@dabbelt.com> 於 2022年9月17日 週六 23:07 寫道: > > > >> On Mon, 15 Aug 2022 17:44:35 PDT (-0700), kevinl@rivosinc.com wrote: > >> > Hello, > >> > Currently, __builtin_lceil and __builtin_lfloor doesn't generate an > >> > existing instruction fcvt, but rather calls ceil and floor from the > >> > library. This patch adds the missing iterator and attributes for lceil > >> and > >> > lfloor to produce the optimized code. > >> > The test cases check the correct generation of the fcvt instruction > for > >> > float/double to int/long/long long. Passed the test in riscv-linux. > >> > Could this patch be committed? > >> > >> Reviewed-by: Palmer Dabbelt <palmer@rivosinc.com> > >> Acked-by: Palmer Dabbelt <palmer@rivosinc.com> > >> > >> Not sure if Kito had any comments for this one, but it looks good to me. > >> > >> > gcc/ChangeLog: > >> > Michael Collison <collison@rivosinc.com> > >> > * config/riscv/riscv.md (RINT): Add iterator for lceil and > >> lround. > >> > (rint_pattern): Add ceil and floor. > >> > (rint_rm): Add rup and rdn. > >> > > >> > gcc/testsuite/ChangeLog: > >> > Kevin Lee <kevinl@rivosinc.com> > >> > * gcc.target/riscv/lfloor-lceil.c: New test. > >> > --- > >> > gcc/config/riscv/riscv.md | 13 ++- > >> > gcc/testsuite/gcc.target/riscv/lfloor-lceil.c | 79 > +++++++++++++++++++ > >> > 2 files changed, 88 insertions(+), 4 deletions(-) > >> > create mode 100644 gcc/testsuite/gcc.target/riscv/lfloor-lceil.c > >> > > >> > diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md > >> > index c6399b1389e..070004fa7fe 100644 > >> > --- a/gcc/config/riscv/riscv.md > >> > +++ b/gcc/config/riscv/riscv.md > >> > @@ -43,6 +43,9 @@ (define_c_enum "unspec" [ > >> > UNSPEC_LRINT > >> > UNSPEC_LROUND > >> > > >> > + UNSPEC_LCEIL > >> > + UNSPEC_LFLOOR > >> > + > >> > ;; Stack tie > >> > UNSPEC_TIE > >> > ]) > >> > @@ -345,10 +348,12 @@ (define_mode_attr UNITMODE [(SF "SF") (DF > "DF")]) > >> > ;; the controlling mode. > >> > (define_mode_attr HALFMODE [(DF "SI") (DI "SI") (TF "DI")]) > >> > > >> > -;; Iterator and attributes for floating-point rounding instructions. > >> > -(define_int_iterator RINT [UNSPEC_LRINT UNSPEC_LROUND]) > >> > -(define_int_attr rint_pattern [(UNSPEC_LRINT "rint") (UNSPEC_LROUND > >> > "round")]) > >> > -(define_int_attr rint_rm [(UNSPEC_LRINT "dyn") (UNSPEC_LROUND > "rmm")]) > >> > +;; Iterator and attributes for floating-point rounding instructions.f > >> > +(define_int_iterator RINT [UNSPEC_LRINT UNSPEC_LROUND UNSPEC_LCEIL > >> > UNSPEC_LFLOOR]) > >> > +(define_int_attr rint_pattern [(UNSPEC_LRINT "rint") (UNSPEC_LROUND > >> > "round") > >> > + (UNSPEC_LCEIL "ceil") (UNSPEC_LFLOOR > >> > "floor")]) > >> > +(define_int_attr rint_rm [(UNSPEC_LRINT "dyn") (UNSPEC_LROUND "rmm") > >> > + (UNSPEC_LCEIL "rup") (UNSPEC_LFLOOR "rdn")]) > >> > > >> > ;; Iterator and attributes for quiet comparisons. > >> > (define_int_iterator QUIET_COMPARISON [UNSPEC_FLT_QUIET > >> UNSPEC_FLE_QUIET]) > >> > diff --git a/gcc/testsuite/gcc.target/riscv/lfloor-lceil.c > >> > b/gcc/testsuite/gcc.target/riscv/lfloor-lceil.c > >> > new file mode 100644 > >> > index 00000000000..4d81c12cefa > >> > --- /dev/null > >> > +++ b/gcc/testsuite/gcc.target/riscv/lfloor-lceil.c > >> > @@ -0,0 +1,79 @@ > >> > +/* { dg-do compile } */ > >> > +/* { dg-options "-march=rv64gc -mabi=lp64d" } */ > >> > +/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" } } */ > >> > + > >> > +int > >> > +ceil1(float i) > >> > +{ > >> > + return __builtin_lceil(i); > >> > +} > >> > + > >> > +long > >> > +ceil2(float i) > >> > +{ > >> > + return __builtin_lceil(i); > >> > +} > >> > + > >> > +long long > >> > +ceil3(float i) > >> > +{ > >> > + return __builtin_lceil(i); > >> > +} > >> > + > >> > +int > >> > +ceil4(double i) > >> > +{ > >> > + return __builtin_lceil(i); > >> > +} > >> > + > >> > +long > >> > +ceil5(double i) > >> > +{ > >> > + return __builtin_lceil(i); > >> > +} > >> > + > >> > +long long > >> > +ceil6(double i) > >> > +{ > >> > + return __builtin_lceil(i); > >> > +} > >> > + > >> > +int > >> > +floor1(float i) > >> > +{ > >> > + return __builtin_lfloor(i); > >> > +} > >> > + > >> > +long > >> > +floor2(float i) > >> > +{ > >> > + return __builtin_lfloor(i); > >> > +} > >> > + > >> > +long long > >> > +floor3(float i) > >> > +{ > >> > + return __builtin_lfloor(i); > >> > +} > >> > + > >> > +int > >> > +floor4(double i) > >> > +{ > >> > + return __builtin_lfloor(i); > >> > +} > >> > + > >> > +long > >> > +floor5(double i) > >> > +{ > >> > + return __builtin_lfloor(i); > >> > +} > >> > + > >> > +long long > >> > +floor6(double i) > >> > +{ > >> > + return __builtin_lfloor(i); > >> > +} > >> > + > >> > +/* { dg-final { scan-assembler-times "fcvt.l.s" 6 } } */ > >> > +/* { dg-final { scan-assembler-times "fcvt.l.d" 6 } } */ > >> > +/* { dg-final { scan-assembler-not "call" } } */ > >> >
> Kevin: Looks like this got corrupted, possibly from copy/paste into > gmail. I resurrect it, but there's a floating-point test failure in > gfortran. Looks like it predates this, but I'm trying to bisect it to > at least have a root cause before just ignoring it. I've got this > floating around on a branch and hopefully that'll remind me to commit > it after I sort that out. Currently, the testsuite doesn't show additional failures. It seems like the corrupted patch caused the issue. I will post the clean patch as v2. Thank you for the review! On Sun, Oct 2, 2022 at 1:47 PM Kevin Lee <kevinl@rivosinc.com> wrote: > > Thank you for the update Palmer. I'll certainly look into the corrupted patch issue and the floating-point test failure in gfortran. > > On Sun, Oct 2, 2022 at 1:42 PM Palmer Dabbelt <palmer@dabbelt.com> wrote: >> >> On Sat, 17 Sep 2022 14:16:13 PDT (-0700), Kito Cheng wrote: >> > LGTM, thanks, I guess I just missed this before >> >> No worries, I'd just stubmled on it looking through old stuff. >> >> Kevin: Looks like this got corrupted, possibly from copy/paste into >> gmail. I resurrect it, but there's a floating-point test failure in >> gfortran. Looks like it predates this, but I'm trying to bisect it to >> at least have a root cause before just ignoring it. I've got this >> floating around on a branch and hopefully that'll remind me to commit >> it after I sort that out. >> >> > >> > Palmer Dabbelt <palmer@dabbelt.com> 於 2022年9月17日 週六 23:07 寫道: >> > >> >> On Mon, 15 Aug 2022 17:44:35 PDT (-0700), kevinl@rivosinc.com wrote: >> >> > Hello, >> >> > Currently, __builtin_lceil and __builtin_lfloor doesn't generate an >> >> > existing instruction fcvt, but rather calls ceil and floor from the >> >> > library. This patch adds the missing iterator and attributes for lceil >> >> and >> >> > lfloor to produce the optimized code. >> >> > The test cases check the correct generation of the fcvt instruction for >> >> > float/double to int/long/long long. Passed the test in riscv-linux. >> >> > Could this patch be committed? >> >> >> >> Reviewed-by: Palmer Dabbelt <palmer@rivosinc.com> >> >> Acked-by: Palmer Dabbelt <palmer@rivosinc.com> >> >> >> >> Not sure if Kito had any comments for this one, but it looks good to me. >> >> >> >> > gcc/ChangeLog: >> >> > Michael Collison <collison@rivosinc.com> >> >> > * config/riscv/riscv.md (RINT): Add iterator for lceil and >> >> lround. >> >> > (rint_pattern): Add ceil and floor. >> >> > (rint_rm): Add rup and rdn. >> >> > >> >> > gcc/testsuite/ChangeLog: >> >> > Kevin Lee <kevinl@rivosinc.com> >> >> > * gcc.target/riscv/lfloor-lceil.c: New test. >> >> > --- >> >> > gcc/config/riscv/riscv.md | 13 ++- >> >> > gcc/testsuite/gcc.target/riscv/lfloor-lceil.c | 79 +++++++++++++++++++ >> >> > 2 files changed, 88 insertions(+), 4 deletions(-) >> >> > create mode 100644 gcc/testsuite/gcc.target/riscv/lfloor-lceil.c >> >> > >> >> > diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md >> >> > index c6399b1389e..070004fa7fe 100644 >> >> > --- a/gcc/config/riscv/riscv.md >> >> > +++ b/gcc/config/riscv/riscv.md >> >> > @@ -43,6 +43,9 @@ (define_c_enum "unspec" [ >> >> > UNSPEC_LRINT >> >> > UNSPEC_LROUND >> >> > >> >> > + UNSPEC_LCEIL >> >> > + UNSPEC_LFLOOR >> >> > + >> >> > ;; Stack tie >> >> > UNSPEC_TIE >> >> > ]) >> >> > @@ -345,10 +348,12 @@ (define_mode_attr UNITMODE [(SF "SF") (DF "DF")]) >> >> > ;; the controlling mode. >> >> > (define_mode_attr HALFMODE [(DF "SI") (DI "SI") (TF "DI")]) >> >> > >> >> > -;; Iterator and attributes for floating-point rounding instructions. >> >> > -(define_int_iterator RINT [UNSPEC_LRINT UNSPEC_LROUND]) >> >> > -(define_int_attr rint_pattern [(UNSPEC_LRINT "rint") (UNSPEC_LROUND >> >> > "round")]) >> >> > -(define_int_attr rint_rm [(UNSPEC_LRINT "dyn") (UNSPEC_LROUND "rmm")]) >> >> > +;; Iterator and attributes for floating-point rounding instructions.f >> >> > +(define_int_iterator RINT [UNSPEC_LRINT UNSPEC_LROUND UNSPEC_LCEIL >> >> > UNSPEC_LFLOOR]) >> >> > +(define_int_attr rint_pattern [(UNSPEC_LRINT "rint") (UNSPEC_LROUND >> >> > "round") >> >> > + (UNSPEC_LCEIL "ceil") (UNSPEC_LFLOOR >> >> > "floor")]) >> >> > +(define_int_attr rint_rm [(UNSPEC_LRINT "dyn") (UNSPEC_LROUND "rmm") >> >> > + (UNSPEC_LCEIL "rup") (UNSPEC_LFLOOR "rdn")]) >> >> > >> >> > ;; Iterator and attributes for quiet comparisons. >> >> > (define_int_iterator QUIET_COMPARISON [UNSPEC_FLT_QUIET >> >> UNSPEC_FLE_QUIET]) >> >> > diff --git a/gcc/testsuite/gcc.target/riscv/lfloor-lceil.c >> >> > b/gcc/testsuite/gcc.target/riscv/lfloor-lceil.c >> >> > new file mode 100644 >> >> > index 00000000000..4d81c12cefa >> >> > --- /dev/null >> >> > +++ b/gcc/testsuite/gcc.target/riscv/lfloor-lceil.c >> >> > @@ -0,0 +1,79 @@ >> >> > +/* { dg-do compile } */ >> >> > +/* { dg-options "-march=rv64gc -mabi=lp64d" } */ >> >> > +/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" } } */ >> >> > + >> >> > +int >> >> > +ceil1(float i) >> >> > +{ >> >> > + return __builtin_lceil(i); >> >> > +} >> >> > + >> >> > +long >> >> > +ceil2(float i) >> >> > +{ >> >> > + return __builtin_lceil(i); >> >> > +} >> >> > + >> >> > +long long >> >> > +ceil3(float i) >> >> > +{ >> >> > + return __builtin_lceil(i); >> >> > +} >> >> > + >> >> > +int >> >> > +ceil4(double i) >> >> > +{ >> >> > + return __builtin_lceil(i); >> >> > +} >> >> > + >> >> > +long >> >> > +ceil5(double i) >> >> > +{ >> >> > + return __builtin_lceil(i); >> >> > +} >> >> > + >> >> > +long long >> >> > +ceil6(double i) >> >> > +{ >> >> > + return __builtin_lceil(i); >> >> > +} >> >> > + >> >> > +int >> >> > +floor1(float i) >> >> > +{ >> >> > + return __builtin_lfloor(i); >> >> > +} >> >> > + >> >> > +long >> >> > +floor2(float i) >> >> > +{ >> >> > + return __builtin_lfloor(i); >> >> > +} >> >> > + >> >> > +long long >> >> > +floor3(float i) >> >> > +{ >> >> > + return __builtin_lfloor(i); >> >> > +} >> >> > + >> >> > +int >> >> > +floor4(double i) >> >> > +{ >> >> > + return __builtin_lfloor(i); >> >> > +} >> >> > + >> >> > +long >> >> > +floor5(double i) >> >> > +{ >> >> > + return __builtin_lfloor(i); >> >> > +} >> >> > + >> >> > +long long >> >> > +floor6(double i) >> >> > +{ >> >> > + return __builtin_lfloor(i); >> >> > +} >> >> > + >> >> > +/* { dg-final { scan-assembler-times "fcvt.l.s" 6 } } */ >> >> > +/* { dg-final { scan-assembler-times "fcvt.l.d" 6 } } */ >> >> > +/* { dg-final { scan-assembler-not "call" } } */ >> >>
diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md index c6399b1389e..070004fa7fe 100644 --- a/gcc/config/riscv/riscv.md +++ b/gcc/config/riscv/riscv.md @@ -43,6 +43,9 @@ (define_c_enum "unspec" [ UNSPEC_LRINT UNSPEC_LROUND + UNSPEC_LCEIL + UNSPEC_LFLOOR + ;; Stack tie UNSPEC_TIE ]) @@ -345,10 +348,12 @@ (define_mode_attr UNITMODE [(SF "SF") (DF "DF")]) ;; the controlling mode. (define_mode_attr HALFMODE [(DF "SI") (DI "SI") (TF "DI")]) -;; Iterator and attributes for floating-point rounding instructions. -(define_int_iterator RINT [UNSPEC_LRINT UNSPEC_LROUND]) -(define_int_attr rint_pattern [(UNSPEC_LRINT "rint") (UNSPEC_LROUND "round")]) -(define_int_attr rint_rm [(UNSPEC_LRINT "dyn") (UNSPEC_LROUND "rmm")]) +;; Iterator and attributes for floating-point rounding instructions.f +(define_int_iterator RINT [UNSPEC_LRINT UNSPEC_LROUND UNSPEC_LCEIL UNSPEC_LFLOOR]) +(define_int_attr rint_pattern [(UNSPEC_LRINT "rint") (UNSPEC_LROUND "round") + (UNSPEC_LCEIL "ceil") (UNSPEC_LFLOOR "floor")]) +(define_int_attr rint_rm [(UNSPEC_LRINT "dyn") (UNSPEC_LROUND "rmm") + (UNSPEC_LCEIL "rup") (UNSPEC_LFLOOR "rdn")]) ;; Iterator and attributes for quiet comparisons. (define_int_iterator QUIET_COMPARISON [UNSPEC_FLT_QUIET UNSPEC_FLE_QUIET]) diff --git a/gcc/testsuite/gcc.target/riscv/lfloor-lceil.c b/gcc/testsuite/gcc.target/riscv/lfloor-lceil.c new file mode 100644 index 00000000000..4d81c12cefa --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/lfloor-lceil.c @@ -0,0 +1,79 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gc -mabi=lp64d" } */ +/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" } } */ + +int +ceil1(float i) +{ + return __builtin_lceil(i); +} + +long +ceil2(float i) +{ + return __builtin_lceil(i); +} + +long long +ceil3(float i) +{ + return __builtin_lceil(i); +} + +int +ceil4(double i) +{ + return __builtin_lceil(i); +} + +long +ceil5(double i) +{ + return __builtin_lceil(i); +} + +long long +ceil6(double i) +{ + return __builtin_lceil(i); +} + +int +floor1(float i) +{ + return __builtin_lfloor(i); +} + +long +floor2(float i) +{ + return __builtin_lfloor(i); +} + +long long +floor3(float i) +{ + return __builtin_lfloor(i); +} + +int +floor4(double i) +{ + return __builtin_lfloor(i); +} + +long +floor5(double i) +{ + return __builtin_lfloor(i); +} + +long long +floor6(double i) +{ + return __builtin_lfloor(i); +} + +/* { dg-final { scan-assembler-times "fcvt.l.s" 6 } } */ +/* { dg-final { scan-assembler-times "fcvt.l.d" 6 } } */ +/* { dg-final { scan-assembler-not "call" } } */