From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by sourceware.org (Postfix) with ESMTPS id 177D63858C2D for ; Thu, 7 Sep 2023 10:16:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 177D63858C2D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-x52f.google.com with SMTP id 4fb4d7f45d1cf-51e28cac164so4073511a12.1 for ; Thu, 07 Sep 2023 03:16:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694081760; x=1694686560; darn=gcc.gnu.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=SqooA1J7ZdJlnCdK1CqJ2Lh46CbD4Dx/JrxrAuWHuMc=; b=P8GuxqGwXgJakj1A1GbJSbgScFMY+1vwReI+C+RvqcToSpOS+ytAU6szQKT1Qk/mVd cLjy+xxI27NzxIuwcq8tboH/tDA6Wp1HNH962iCcU6n78u0kvzdVKVnwhKP/rSyxcNIP Zg7T1dn1Eu2g5ZzWp2yijTNLvI6b6FGP0P5lk5MNVvlEJW+/KSsaeFg39peKZRsvyueV iRSI19S3AY1RcM9pssjrD+xS+7ZY8CBmHZSSto6vxB98WuZscDRGCC40+PfWoiEgg+e7 Tc4LS1Q+u5er2cZ8J4w6vOa7LD/WTrFRuzc/uFrRJGjEzxK9Iy3+VTx2BA0rtkGAk1oA Jtrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1694081760; x=1694686560; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SqooA1J7ZdJlnCdK1CqJ2Lh46CbD4Dx/JrxrAuWHuMc=; b=dkrTEqe6S8OxqG7Wx/3Ap+IyjtWGbruymKpY54Uhe5II5Pg2dnaif6vy3kxIAYeZzY 2c+m19C44uE9Pz3JJJNku0j4UaSrB0g9VlQ+/+Ps3TMG8B7oXrMHtXElUDu5QGnEEs3t QCJgPRVg6WbVgaLZmvAHEWciTHfpz3BwIAzI/7dSPRTu/kpdeP0tgLY8YRKs6uSsxG5n c4FB6pPO8Ml2hssQqsvtPIXqWxGPIvsPXDE7QSOkHtNT1hnmDCCivQExAzKttv+FILhJ b5M0pUmgkBJMcmKxIdiS/kub2/uXMwZdW2u+v6jzIPxU/E6IAItykxYeBzhHqFdl2ahZ +FJQ== X-Gm-Message-State: AOJu0Yy0RLX2uOUswIHvWw2cXQk1faAG/yaOgL8YiSy5d4D0d984Unud UktpWYkU8LxX55QFwlBdzff97EdwT1ZYb8n+OB5O1TLG X-Google-Smtp-Source: AGHT+IFX3JFlMM51oBdW1W+lCvj9gWT9PYKiop8IYkrZsJs/YUWkwtpbBoImYMdeMywoUSHwIf9mTwNc3eh5qSuT8Qo= X-Received: by 2002:a05:6402:42cb:b0:525:4d74:be8c with SMTP id i11-20020a05640242cb00b005254d74be8cmr3040947edc.14.1694081759764; Thu, 07 Sep 2023 03:15:59 -0700 (PDT) MIME-Version: 1.0 References: <20230906125026.16091-1-shahab@synopsys.com> <20230906125026.16091-2-shahab@synopsys.com> In-Reply-To: <20230906125026.16091-2-shahab@synopsys.com> From: Claudiu Zissulescu Ianculescu Date: Thu, 7 Sep 2023 13:15:48 +0300 Message-ID: Subject: Re: [PATCH 2/2] ARC: Use intrinsics for __builtin_sub_overflow*() To: Shahab Vahedi Cc: gcc-patches@gcc.gnu.org, Francois Bedard Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,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: OK, Thank you for your contribution, Claudiu On Wed, Sep 6, 2023 at 3:50=E2=80=AFPM Shahab Vahedi wrote: > > This patch covers signed and unsigned subtractions. The generated code > would be something along these lines: > > signed: > sub.f r0, r1, r2 > b.v @label > > unsigned: > sub.f r0, r1, r2 > b.c @label > > gcc/ChangeLog: > > * config/arc/arc.md (subsi3_v): New insn. > (subvsi4): New expand. > (subsi3_c): New insn. > (usubvsi4): New expand. > > gcc/testsuite/ChangeLog: > > * gcc.target/arc/overflow-2.c: New. > > Signed-off-by: Shahab Vahedi > --- > gcc/config/arc/arc.md | 48 +++++++++++ > gcc/testsuite/gcc.target/arc/overflow-2.c | 97 +++++++++++++++++++++++ > 2 files changed, 145 insertions(+) > create mode 100644 gcc/testsuite/gcc.target/arc/overflow-2.c > > diff --git a/gcc/config/arc/arc.md b/gcc/config/arc/arc.md > index 9d011f6b4a9..34e9e1a7f1d 100644 > --- a/gcc/config/arc/arc.md > +++ b/gcc/config/arc/arc.md > @@ -2973,6 +2973,54 @@ archs4x, archs4xd" > (set_attr "cpu_facility" "*,cd,*,*,*,*,*,*,*,*") > ]) > > +(define_insn "subsi3_v" > + [(set (match_operand:SI 0 "register_operand" "=3Dr,r,r, r") > + (minus:SI (match_operand:SI 1 "register_operand" "r,r,0, r") > + (match_operand:SI 2 "nonmemory_operand" "r,L,I,C32"))) > + (set (reg:CC_V CC_REG) > + (compare:CC_V (sign_extend:DI (minus:SI (match_dup 1) > + (match_dup 2))) > + (minus:DI (sign_extend:DI (match_dup 1)) > + (sign_extend:DI (match_dup 2)))))] > + "" > + "sub.f\\t%0,%1,%2" > + [(set_attr "cond" "set") > + (set_attr "type" "compare") > + (set_attr "length" "4,4,4,8")]) > + > +(define_expand "subvsi4" > + [(match_operand:SI 0 "register_operand") > + (match_operand:SI 1 "register_operand") > + (match_operand:SI 2 "nonmemory_operand") > + (label_ref (match_operand 3 "" ""))] > + "" > + "emit_insn (gen_subsi3_v (operands[0], operands[1], operands[2])); > + arc_gen_unlikely_cbranch (NE, CC_Vmode, operands[3]); > + DONE;") > + > +(define_insn "subsi3_c" > + [(set (match_operand:SI 0 "register_operand" "=3Dr,r,r, r") > + (minus:SI (match_operand:SI 1 "register_operand" "r,r,0, r") > + (match_operand:SI 2 "nonmemory_operand" "r,L,I,C32"))) > + (set (reg:CC_C CC_REG) > + (compare:CC_C (match_dup 1) > + (match_dup 2)))] > + "" > + "sub.f\\t%0,%1,%2" > + [(set_attr "cond" "set") > + (set_attr "type" "compare") > + (set_attr "length" "4,4,4,8")]) > + > +(define_expand "usubvsi4" > + [(match_operand:SI 0 "register_operand") > + (match_operand:SI 1 "register_operand") > + (match_operand:SI 2 "nonmemory_operand") > + (label_ref (match_operand 3 "" ""))] > + "" > + "emit_insn (gen_subsi3_c (operands[0], operands[1], operands[2])); > + arc_gen_unlikely_cbranch (LTU, CC_Cmode, operands[3]); > + DONE;") > + > (define_expand "subdi3" > [(set (match_operand:DI 0 "register_operand" "") > (minus:DI (match_operand:DI 1 "register_operand" "") > diff --git a/gcc/testsuite/gcc.target/arc/overflow-2.c b/gcc/testsuite/gc= c.target/arc/overflow-2.c > new file mode 100644 > index 00000000000..b4de8c03b22 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/arc/overflow-2.c > @@ -0,0 +1,97 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O1" } */ > + > +#include > +#include > + > +/* > + * sub.f r0,r0,r1 > + * st_s r0,[r2] > + * mov_s r0,1 > + * j_s.d [blink] > + * mov.nv r0,0 > + */ > +bool sub_overflow (int32_t a, int32_t b, int32_t *res) > +{ > + return __builtin_sub_overflow (a, b, res); > +} > + > +/* > + * sub.f r0,r0,-1234 > + * st_s r0,[r1] > + * mov_s r0,1 > + * j_s.d [blink] > + * mov.nv r0,0 > + */ > +bool subi_overflow (int32_t a, int32_t *res) > +{ > + return __builtin_sub_overflow (a, -1234, res); > +} > + > +/* > + * sub.f r3,r0,r1 > + * st_s r3,[r2] > + * j_s.d [blink] > + * setlo r0,r0,r1 > + */ > +bool usub_overflow (uint32_t a, uint32_t b, uint32_t *res) > +{ > + return __builtin_sub_overflow (a, b, res); > +} > + > +/* > + * sub.f r2,r0,4321 > + * seths r0,4320,r0 > + * j_s.d [blink] > + * st_s r2,[r1] > + */ > +bool usubi_overflow (uint32_t a, uint32_t *res) > +{ > + return __builtin_sub_overflow (a, 4321, res); > +} > + > +/* > + * sub.f r0,r0,r1 > + * mov_s r0,1 > + * j_s.d [blink] > + * mov.nv r0,0 > + */ > +bool sub_overflow_p (int32_t a, int32_t b, int32_t res) > +{ > + return __builtin_sub_overflow_p (a, b, res); > +} > + > +/* > + * sub.f r0,r0,-1000 > + * mov_s r0,1 > + * j_s.d [blink] > + * mov.nv r0,0 > + */ > +bool subi_overflow_p (int32_t a, int32_t res) > +{ > + return __builtin_sub_overflow_p (a, -1000, res); > +} > + > +/* > + * j_s.d [blink] > + * setlo r0,r0,r1 > + */ > +bool usub_overflow_p (uint32_t a, uint32_t b, uint32_t res) > +{ > + return __builtin_sub_overflow_p (a, b, res); > +} > + > +/* > + * seths r0,1999,r0 > + * j_s.d [blink] > + */ > +bool usubi_overflow_p (uint32_t a, uint32_t res) > +{ > + return __builtin_sub_overflow_p (a, 2000, res); > +} > + > +/* { dg-final { scan-assembler-times "sub.f\\s\+" 6 } } */ > +/* { dg-final { scan-assembler-times "mov\.nv\\s\+" 4 } } */ > +/* { dg-final { scan-assembler-times "setlo\\s\+" 2 } } */ > +/* { dg-final { scan-assembler-times "seths\\s\+" 2 } } */ > +/* { dg-final { scan-assembler-not "cmp" } } */ > -- > 2.42.0 >