From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by sourceware.org (Postfix) with ESMTPS id 0FA6B3858D32 for ; Sun, 2 Oct 2022 20:42:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0FA6B3858D32 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=dabbelt.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=dabbelt.com Received: by mail-pj1-x1032.google.com with SMTP id p3-20020a17090a284300b0020a85fa3ffcso1950889pjf.2 for ; Sun, 02 Oct 2022 13:42:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dabbelt-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:to:from:cc :in-reply-to:subject:date:from:to:cc:subject:date; bh=U0GbnUOQW0vi0C5VjZyummFvXVbt63buZLKPFiAxiiw=; b=pl5573N8PPqFdpDbgrlb7aCrcL/whIBEp/OxISP6M8zfvHHGOgvdp1Jr1EDME7gb3u OlpbeeU4Fvbjvx3F+TItTfU4aEmvfGZReUY33voUEiX7XmotHJ/9do2ItvAP5zh2BgYX luAvTxI20RE2oC9HMy0CzYmePxTV3mElpNXU3kjsTvrO5Z9e0DTTnvQTtUeiF7tlAQov boijQxrpxKipO2GKt6cWhErfrgrKsQDFziYUZnmJRJEESrEuaxSHZoALQhM9YfKYTbiY zCwVYvL2I7qvlV/tVYgUPngxRY2nQ1X9qTF8cyqoXkOTgToGVGDEcGhnogdFA1IIYh+o WB4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:to:from:cc :in-reply-to:subject:date:x-gm-message-state:from:to:cc:subject:date; bh=U0GbnUOQW0vi0C5VjZyummFvXVbt63buZLKPFiAxiiw=; b=sf6wbpV1gsZ7/WyTGojlJTxGI794hoOxFMJXO6tuinszMoSbOGEyI2nqmQElg58ji2 7YKIOSJ2RWgxmviUiCyzMtN8Yce/g+4v0/LPzyN1kmy5zEMrbQIJdNG4m+LBqGl03Rd+ WnneMGb9ranTwT9S2N54qe9apcXnIHCx3aiZYEb0sIYTlgsWQxkoEqxN4eI9qcxrulcp 6vhQF8RCb2j5NOrmFa5bNC/3BeY24Gz5CW9I6ra02UTnHifuaXv0GfrdakjJH7mXVnZq v+drw7AEski8Duyu9YD9BCts3+AK4lYqdbpoEFdNhZ6wKUCT9xTGZ6LxVOdJOnarAUZ1 dZFA== X-Gm-Message-State: ACrzQf1BsPO9uY6FG+0MxrbfupmpoPX9AObpIM1ZTLZpEBKJD6NXsVwu anARL9ahivxabvlmQ6VJEtaapA== X-Google-Smtp-Source: AMsMyM5ENz/Ky0ilD63T+b1mxEEmdoshlzTakVdwpIFBUORjUux6gSQZndrT/3evCBJEaWxYh6K3pg== X-Received: by 2002:a17:903:234c:b0:17a:a2e:40ce with SMTP id c12-20020a170903234c00b0017a0a2e40cemr19667120plh.106.1664743342790; Sun, 02 Oct 2022 13:42:22 -0700 (PDT) Received: from localhost (76-210-143-223.lightspeed.sntcca.sbcglobal.net. [76.210.143.223]) by smtp.gmail.com with ESMTPSA id c11-20020a056a00008b00b00561803acde2sm60175pfj.216.2022.10.02.13.42.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Oct 2022 13:42:21 -0700 (PDT) Date: Sun, 02 Oct 2022 13:42:21 -0700 (PDT) X-Google-Original-Date: Sun, 02 Oct 2022 13:42:19 PDT (-0700) Subject: Re: [PATCH] RISC-V missing __builtin_lceil and __builtin_lfloor In-Reply-To: CC: kevinl@rivosinc.com, gcc-patches@gcc.gnu.org From: Palmer Dabbelt To: Kito Cheng Message-ID: Mime-Version: 1.0 (MHng) Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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 List-Id: 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 於 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 >> Acked-by: Palmer Dabbelt >> >> Not sure if Kito had any comments for this one, but it looks good to me. >> >> > gcc/ChangeLog: >> > Michael Collison >> > * 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 >> > * 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" } } */ >>