| Message ID | 20250807130941.363722-1-ams@baylibre.com |
|---|---|
| State | New |
| Headers |
Return-Path: <newlib-bounces~patchwork=sourceware.org@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7A34A3858D21 for <patchwork@sourceware.org>; Thu, 7 Aug 2025 13:10:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7A34A3858D21 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=nsFhTwvf X-Original-To: newlib@sourceware.org Delivered-To: newlib@sourceware.org Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by sourceware.org (Postfix) with ESMTPS id 766653858408 for <newlib@sourceware.org>; Thu, 7 Aug 2025 13:09:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 766653858408 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=baylibre.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 766653858408 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::336 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1754572186; cv=none; b=tI2FWr3jlj9zPf/sBTXu9X4Dx1QkgXF0fKLTx7EaWCOp4Y61fryVmSmc7uFDkSBs1VIBp55rzvp+Y0z7Hgiv+x0mSr5Lb414o9lMZPMEtonwooyz5Cqhu9CNx/8Ek6nBGd2rxTVvMUwwJMRUcHXtZL/JMhJv7kfjgMnoebDTvz0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1754572186; c=relaxed/simple; bh=qSaQQOjshOSJLty0/MubomgsZDi+DNHrFnFXI/SxfkE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=QZGzUYx/2wkRhGx12j+4Ey7IB0nI2eTKoSs9iiSevoP97WqqTCXCPcpCBXMzNsya0nQS5EKrStMUpDbZPr2bAgzKuLoOUp1EUldkRhbELM8P5L1r/vst657o6Rclq4J70LHeCb3f7jx0ZxqyP48ZuSsWrEjFcdB8LWCG61UL0x8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 766653858408 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-459eb4ae596so8913495e9.1 for <newlib@sourceware.org>; Thu, 07 Aug 2025 06:09:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1754572185; x=1755176985; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=evIl15+sRpAdCv/UxZOgSBFVkk4fJEeo2VZpNthGBGQ=; b=nsFhTwvfUVwKRzEgn2EyBHoLNJx0mkLGoDPqnEGk/9m+C1L9JhxRHGmqaHnEAIhXKY 10D1LAMDVTdBsszXGhhbC8M1LfV0aTPzbrEKMWuGYIUzi4VpxPdFmspFQSv2nACA2a1x l9GQrd0JaL7nj9B3PbByWLYAdGBQ27JCP9aO8maSa+ZyS4eANNDq4x8g2UFccLQPKKjy PgJz/9MeFLPVEhJstQRcQJy9jYK+YP5TPfwceVlm5SaL5Apc5T2ehJLw5WY4k4mBZTtK t+ugUVuF062A/weKBMFhxyRnNQrkMatEwEKlaxOogiUGgF6KEO+4Gyrc5UR422iyt8Mc pUnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754572185; x=1755176985; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=evIl15+sRpAdCv/UxZOgSBFVkk4fJEeo2VZpNthGBGQ=; b=Ad1f1/FIASLT24iZk7GvAkr52xkETwVUy7z8mWsZikIvBYchjEVBar2YLRcg9VcptU yD1xd0NDAC2pDRgg3FCNBA+b+MyYrGvA8RBjvXZ4ScE5O74ViekvhXSy5v2YlxLLtJVZ i966fXy69MPN/ihy9p0i6Utv6pOdVkztIojysDcTUk22lnNiZScpnmqSzZjfCmjuanDe A1c6RreCVMFuQO48Bl/PUyQzNHnVT7OceqOq5S7I5UP32hWQdW70iFeNk3r8D1qN3EB+ XHuPFdLs7+gT+4jxP1cmaTWyzKNTQTh1r5CUvr28kV6kmkibMN9GpV6ITUpl3jTnvNzs qiOw== X-Gm-Message-State: AOJu0YxN17VdFozSSEgHEfSa1OUUmwjEQnjz6gisnzYd+9eoe4NdST0/ ha4AWsUMhGaVgpE4+PvGWL/pSQyksNRZ4TGDzMjCkyB7u+uVMme2MILfMFJXexvVKXLthKUHosl NbK8Y X-Gm-Gg: ASbGncs9eq7hl+tF4qxAvFdqQt54nZXi7BheO3jt/+rz6B7ic8I4bk56LzpIKt7tM8d Ybf08o9su1IJmHSzLQQkO+AYUdbntxuoBujhKbJlBAlX5BqamUKrHcA0fLoaQKy9TaudUSdtMUe AFwmtH5A7CMcxH8BbbnovdV3iXjwUvboCVvy3d0JBg3mvTauMEZldjwOoO2Cu9YexiyhT1K0qU2 Or7Wc1zbDPTadJNzdCp63H3Z0EKBGJw753HPIRjVct7db2ednTbT8xeOfRBaTSZ5ZfvDF1h1h57 QOuwSyQ1aFbfoL80D4bNCINbDzkHy1scal7FHSrD/Ry60DO1Q/3QVpMzwjv2Lku+6rLQy2ak0aQ L2Rx509AICepWy+LdgOQmjYeXeQ== X-Google-Smtp-Source: AGHT+IE/gI3XbaV6i2IRzDw5gon7/s+naDMa3PDMXOZVUOteQ4mmUjdfT6MEdUP9/ds/CRNUsxhTGg== X-Received: by 2002:a05:600c:1c18:b0:456:19be:5cc with SMTP id 5b1f17b1804b1-459e741fcebmr73402275e9.14.1754572184583; Thu, 07 Aug 2025 06:09:44 -0700 (PDT) Received: from vbuild-02.baylibre ([217.13.61.132]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-459e5843021sm104773455e9.3.2025.08.07.06.09.43 for <newlib@sourceware.org> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Aug 2025 06:09:44 -0700 (PDT) From: Andrew Stubbs <ams@baylibre.com> To: newlib@sourceware.org Subject: [PATCH] amdgcn, libm: fix infinite loop Date: Thu, 7 Aug 2025 13:09:41 +0000 Message-ID: <20250807130941.363722-1-ams@baylibre.com> X-Mailer: git-send-email 2.50.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, 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 X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Newlib mailing list <newlib.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/newlib>, <mailto:newlib-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/newlib/> List-Post: <mailto:newlib@sourceware.org> List-Help: <mailto:newlib-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/newlib>, <mailto:newlib-request@sourceware.org?subject=subscribe> Errors-To: newlib-bounces~patchwork=sourceware.org@sourceware.org |
| Series |
amdgcn, libm: fix infinite loop
|
|
Commit Message
Andrew Stubbs
Aug. 7, 2025, 1:09 p.m. UTC
The end condition on this loop, unlike all the other similar loops, is "i >= 0", which is a problem because "i <<= 1" can go negative and then zero if you continue shifting, and so back to true, again. This isn't a problem for the loop in the scalar implementation, but it means we need to mask the shift in the vector implementation. This fixes GCC PR#121392. --- newlib/libm/machine/amdgcn/v64sf_fmod.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
Comments
Hi Andrew! On 2025-08-07T13:09:41+0000, Andrew Stubbs <ams@baylibre.com> wrote: > The end condition on this loop, unlike all the other similar loops, is > "i >= 0", which is a problem because "i <<= 1" can go negative and then zero if > you continue shifting, and so back to true, again. This isn't a problem for > the loop in the scalar implementation, but it means we need to mask the shift > in the vector implementation. > > This fixes GCC PR#121392. Thanks, I confirm this fixes the issue. I suggest you 'git push', or I can do it for you if you don't have access to newlib Git -- or, I'll be happy to sponsor you to get access, as maintainer of the GCN parts in newlib. (<https://sourceware.org/cgi-bin/pdw/ps_form.cgi> has the instructions for the latter.) Grüße Thomas > newlib/libm/machine/amdgcn/v64sf_fmod.c | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > > diff --git a/newlib/libm/machine/amdgcn/v64sf_fmod.c b/newlib/libm/machine/amdgcn/v64sf_fmod.c > index 7302420ad..b62b81929 100644 > --- a/newlib/libm/machine/amdgcn/v64sf_fmod.c > +++ b/newlib/libm/machine/amdgcn/v64sf_fmod.c > @@ -70,8 +70,11 @@ DEF_VS_MATH_FUNC (v64sf, fmodf, v64sf x, v64sf y) > v64si iy; > VECTOR_IF (hy < 0x00800000, cond) // subnormal y > iy = VECTOR_INIT (-126); > - for (v64si i = (hy << 8); !ALL_ZEROES_P (cond & (i >= 0)); i <<= 1) > - VECTOR_COND_MOVE (iy, iy - 1, cond & (i >= 0)); > + for (v64si i = (hy << 8); !ALL_ZEROES_P (cond & (i >= 0)); /* i <<= 1 */) > + { > + VECTOR_COND_MOVE (iy, iy - 1, cond & (i >= 0)); > + VECTOR_COND_MOVE (i, i << 1, cond & (i >= 0)); > + } > VECTOR_ELSE (cond) > VECTOR_COND_MOVE (iy, (hy >> 23) - 127, cond); > VECTOR_ENDIF > -- > 2.50.0
On 08/08/2025 09:14, Thomas Schwinge wrote: > Hi Andrew! > > On 2025-08-07T13:09:41+0000, Andrew Stubbs <ams@baylibre.com> wrote: >> The end condition on this loop, unlike all the other similar loops, is >> "i >= 0", which is a problem because "i <<= 1" can go negative and then zero if >> you continue shifting, and so back to true, again. This isn't a problem for >> the loop in the scalar implementation, but it means we need to mask the shift >> in the vector implementation. >> >> This fixes GCC PR#121392. > > Thanks, I confirm this fixes the issue. > > I suggest you 'git push', or I can do it for you if you don't have access > to newlib Git -- or, I'll be happy to sponsor you to get access, as > maintainer of the GCN parts in newlib. > (<https://sourceware.org/cgi-bin/pdw/ps_form.cgi> has the instructions > for the latter.) I might be able to push (I can pull via ssh), but I'm not aware of having any authority to do so, in this project. I normally post my patches and one of the maintainers approves and applies it. I'm happy to take that task off their hands if they're happy for me to do so, but it's quite rare so I've never pushed for it. Andrew
Patch applied. Thanks. -- Jeff J. On Fri, Aug 8, 2025 at 4:15 AM Thomas Schwinge <tschwinge@baylibre.com> wrote: > Hi Andrew! > > On 2025-08-07T13:09:41+0000, Andrew Stubbs <ams@baylibre.com> wrote: > > The end condition on this loop, unlike all the other similar loops, is > > "i >= 0", which is a problem because "i <<= 1" can go negative and then > zero if > > you continue shifting, and so back to true, again. This isn't a problem > for > > the loop in the scalar implementation, but it means we need to mask the > shift > > in the vector implementation. > > > > This fixes GCC PR#121392. > > Thanks, I confirm this fixes the issue. > > I suggest you 'git push', or I can do it for you if you don't have access > to newlib Git -- or, I'll be happy to sponsor you to get access, as > maintainer of the GCN parts in newlib. > (<https://sourceware.org/cgi-bin/pdw/ps_form.cgi> has the instructions > for the latter.) > > > Grüße > Thomas > > > > newlib/libm/machine/amdgcn/v64sf_fmod.c | 7 +++++-- > > 1 file changed, 5 insertions(+), 2 deletions(-) > > > > diff --git a/newlib/libm/machine/amdgcn/v64sf_fmod.c > b/newlib/libm/machine/amdgcn/v64sf_fmod.c > > index 7302420ad..b62b81929 100644 > > --- a/newlib/libm/machine/amdgcn/v64sf_fmod.c > > +++ b/newlib/libm/machine/amdgcn/v64sf_fmod.c > > @@ -70,8 +70,11 @@ DEF_VS_MATH_FUNC (v64sf, fmodf, v64sf x, v64sf y) > > v64si iy; > > VECTOR_IF (hy < 0x00800000, cond) // subnormal y > > iy = VECTOR_INIT (-126); > > - for (v64si i = (hy << 8); !ALL_ZEROES_P (cond & (i >= 0)); i <<= 1) > > - VECTOR_COND_MOVE (iy, iy - 1, cond & (i >= 0)); > > + for (v64si i = (hy << 8); !ALL_ZEROES_P (cond & (i >= 0)); /* i <<= > 1 */) > > + { > > + VECTOR_COND_MOVE (iy, iy - 1, cond & (i >= 0)); > > + VECTOR_COND_MOVE (i, i << 1, cond & (i >= 0)); > > + } > > VECTOR_ELSE (cond) > > VECTOR_COND_MOVE (iy, (hy >> 23) - 127, cond); > > VECTOR_ENDIF > > -- > > 2.50.0 > >
diff --git a/newlib/libm/machine/amdgcn/v64sf_fmod.c b/newlib/libm/machine/amdgcn/v64sf_fmod.c index 7302420ad..b62b81929 100644 --- a/newlib/libm/machine/amdgcn/v64sf_fmod.c +++ b/newlib/libm/machine/amdgcn/v64sf_fmod.c @@ -70,8 +70,11 @@ DEF_VS_MATH_FUNC (v64sf, fmodf, v64sf x, v64sf y) v64si iy; VECTOR_IF (hy < 0x00800000, cond) // subnormal y iy = VECTOR_INIT (-126); - for (v64si i = (hy << 8); !ALL_ZEROES_P (cond & (i >= 0)); i <<= 1) - VECTOR_COND_MOVE (iy, iy - 1, cond & (i >= 0)); + for (v64si i = (hy << 8); !ALL_ZEROES_P (cond & (i >= 0)); /* i <<= 1 */) + { + VECTOR_COND_MOVE (iy, iy - 1, cond & (i >= 0)); + VECTOR_COND_MOVE (i, i << 1, cond & (i >= 0)); + } VECTOR_ELSE (cond) VECTOR_COND_MOVE (iy, (hy >> 23) - 127, cond); VECTOR_ENDIF