From nobody Thu Aug 21 10:43:33 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4c70Kd5xx9z64gxx; Thu, 21 Aug 2025 10:43:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4c70Kd5Lt7z3Ss8; Thu, 21 Aug 2025 10:43:33 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1755773013; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=SIzdbBKUPr9BE7NqTkjl5a0dpR5FopasnxlLAavKkx8=; b=WzyYJZxjaI/1BTgbILjAQmWuaS7A6ZDV5XI3PuqX/awC6Xfla3If29HU3uSVvhgJ0nyumN PomFO0KQ97k8fWJqNY+ZnHZw714HzFrCR6EpruUZrQTNO6W85yMdanfPst8s3jgO2etHq/ RP7qoTGXhSfSe/MgX9ishUONwBr1Y6QSkdMORgnt6EYYhGJT1CNNpnRDuCjvkujutlfTgA FsmeHFYrlBSEnX8y6FMcBk59+3X9HzhyWU4Qs500q9Kf2bBROvabylYh5bfLwWGW+yGcOn Tk4k6bvLze/gbHvEYreX6Oy15zGGMgMjjIGo+ydq8bOS7D6edF6LjNIbdeol7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1755773013; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=SIzdbBKUPr9BE7NqTkjl5a0dpR5FopasnxlLAavKkx8=; b=cBkmfutCYrm5CeiDShdeHytFoZyykmdqVB0oEuOSUkMzTFu7/7S0Jto9Nd2eSCjVZcQzf8 ZDxbYxEAC9ZioWSF3vqhRO7F7uCWlDGpfkkbFvEAxdZFPh2wtFDMXEaC71/U7f4wRP3FZg P1uBdMD/tODbVF+dhlfyDZfPY68H5K59m5Z78sotqRJrH/ldFYr8POZioCn6Zx9YHMRoFw OCykkZReeMoQPpGyjwWASKsh2kDbjAMAYi9PCyMTeo1OrANxQXgiCT7WylIGgFmY9nhGu3 Wie9wKo1nAxRxT2ObI3Zoa6MAXWJyI08G0k0DKJ2aWgEuaJ9O2kQxcXdbX+yBA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1755773013; a=rsa-sha256; cv=none; b=YavF9ZXpoCN3UzphU+grMFKMZeOYb2laEVCkQ8rVpoXPZ+Db+9g93t8fiLMxOh3DPWunit AyEhkWWmfnhG+h1+w3FlPg6Q4wnfwntGPTgRtUhOLk1jAmbjQvutzNi5hPd9eH7y9zWlyY Fectd8ee0Uesv+nxqVOBw/6wuk5Wl6NZu5nN8C4Q9A/xt1yTjRPuQNLgLQ8acnDJPcRvor oKCz6FXcXMnDFqZas+dT1EyunImZgr3+ewbE5Gu3psFHgM81hAPmHypVeQeYmWn611FnSD Nr6IsMMDeRUaPp0bQpW8g4PlDlatclgyZBnmpESzlBzivPdQpTGugtm51kQ2sQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4c70Kd4jZ0zwcC; Thu, 21 Aug 2025 10:43:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 57LAhXlP075739; Thu, 21 Aug 2025 10:43:33 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 57LAhXjZ075736; Thu, 21 Aug 2025 10:43:33 GMT (envelope-from git) Date: Thu, 21 Aug 2025 10:43:33 GMT Message-Id: <202508211043.57LAhXjZ075736@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dimitry Andric Subject: git: 8d2c0354e138 - stable/13 - [libm] Avoid left shift of signed integer entities List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dim X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 8d2c0354e138c49e2d5f6e0160fd3c710052a0ef Auto-Submitted: auto-generated The branch stable/13 has been updated by dim: URL: https://cgit.FreeBSD.org/src/commit/?id=8d2c0354e138c49e2d5f6e0160fd3c710052a0ef commit 8d2c0354e138c49e2d5f6e0160fd3c710052a0ef Author: Steve Kargl AuthorDate: 2025-08-14 18:38:41 +0000 Commit: Dimitry Andric CommitDate: 2025-08-21 10:41:43 +0000 [libm] Avoid left shift of signed integer entities Follow-up commit d180086e6eae by fixing the left shift of signed integer entities through the use of a helper function. Specific per file changes are: * lib/msun/src/e_fmodf.c: * lib/msun/src/s_remquof.c: . Eliminate now unused variable 'i'. . Sort declaration statement. . Use subnormal_ilogbf() to avoid left shift of signed integer. * lib/msun/src/math_private.h b/lib/msun/src/math_private.h: . Implement subnormal_ilogbf() to extract an exponent of a subnormal float. This avoids left shifts of signed integers. . Update nearby comment. * lib/msun/src/s_ilogbf.c . Fix declaration of the function statement in accordance with style(9). . Use subnormal_ilogbf() to avoid left shift of signed integer. PR: 288850 MFC after: 1 week (cherry picked from commit c58c77246f88da87f309e8c449e98195d43e2c76) --- lib/msun/src/e_fmodf.c | 16 +++++++++------- lib/msun/src/math_private.h | 16 +++++++++++++++- lib/msun/src/s_ilogbf.c | 5 +++-- lib/msun/src/s_remquof.c | 16 +++++++++------- 4 files changed, 36 insertions(+), 17 deletions(-) diff --git a/lib/msun/src/e_fmodf.c b/lib/msun/src/e_fmodf.c index 0e6633fbe739..fc6fee879f52 100644 --- a/lib/msun/src/e_fmodf.c +++ b/lib/msun/src/e_fmodf.c @@ -28,7 +28,7 @@ static const float one = 1.0, Zero[] = {0.0, -0.0,}; float fmodf(float x, float y) { - int32_t n,hx,hy,hz,ix,iy,sx,i; + int32_t hx, hy, hz, ix, iy, n, sx; GET_FLOAT_WORD(hx,x); GET_FLOAT_WORD(hy,y); @@ -45,14 +45,16 @@ fmodf(float x, float y) return Zero[(u_int32_t)sx>>31]; /* |x|=|y| return x*0*/ /* determine ix = ilogb(x) */ - if(hx<0x00800000) { /* subnormal x */ - for (ix = -126,i=(hx<<8); i>0; i<<=1) ix -=1; - } else ix = (hx>>23)-127; + if(hx<0x00800000) + ix = subnormal_ilogbf(hx); + else + ix = (hx>>23)-127; /* determine iy = ilogb(y) */ - if(hy<0x00800000) { /* subnormal y */ - for (iy = -126,i=(hy<<8); i>=0; i<<=1) iy -=1; - } else iy = (hy>>23)-127; + if(hy<0x00800000) + iy = subnormal_ilogbf(hy); + else + iy = (hy>>23)-127; /* set up {hx,lx}, {hy,ly} and align y to x */ if(ix >= -126) diff --git a/lib/msun/src/math_private.h b/lib/msun/src/math_private.h index 8023cdf05857..6513c2ce14fc 100644 --- a/lib/msun/src/math_private.h +++ b/lib/msun/src/math_private.h @@ -741,7 +741,7 @@ irintl(long double x) } while (0) /* - * For a double entity split into high and low parts, compute ilogb. + * For a subnormal double entity split into high and low parts, compute ilogb. */ static inline int32_t subnormal_ilogb(int32_t hi, int32_t lo) @@ -761,6 +761,20 @@ subnormal_ilogb(int32_t hi, int32_t lo) return (j); } +/* + * For a subnormal float entity represented as an int32_t, compute ilogb. + */ +static inline int32_t +subnormal_ilogbf(int32_t hx) +{ + int32_t j; + uint32_t i; + i = (uint32_t) hx << 8; + for (j = -126; i < 0x7fffffff; i <<= 1) j -=1; + + return (j); +} + #ifdef DEBUG #if defined(__amd64__) || defined(__i386__) #define breakpoint() asm("int $3") diff --git a/lib/msun/src/s_ilogbf.c b/lib/msun/src/s_ilogbf.c index ff3df1fc5b90..75508ab77120 100644 --- a/lib/msun/src/s_ilogbf.c +++ b/lib/msun/src/s_ilogbf.c @@ -19,7 +19,8 @@ #include "math.h" #include "math_private.h" - int ilogbf(float x) +int +ilogbf(float x) { int32_t hx,ix; @@ -29,7 +30,7 @@ if(hx==0) return FP_ILOGB0; else /* subnormal x */ - for (ix = -126,hx<<=8; hx>0; hx<<=1) ix -=1; + ix = subnormal_ilogbf(hx); return ix; } else if (hx<0x7f800000) return (hx>>23)-127; diff --git a/lib/msun/src/s_remquof.c b/lib/msun/src/s_remquof.c index c42bd8c4320d..39b87a91845f 100644 --- a/lib/msun/src/s_remquof.c +++ b/lib/msun/src/s_remquof.c @@ -27,7 +27,7 @@ static const float Zero[] = {0.0, -0.0,}; float remquof(float x, float y, int *quo) { - int32_t n,hx,hy,hz,ix,iy,sx,i; + int32_t hx, hy, hz, ix, iy, n, sx; u_int32_t q,sxy; GET_FLOAT_WORD(hx,x); @@ -49,14 +49,16 @@ remquof(float x, float y, int *quo) } /* determine ix = ilogb(x) */ - if(hx<0x00800000) { /* subnormal x */ - for (ix = -126,i=(hx<<8); i>0; i<<=1) ix -=1; - } else ix = (hx>>23)-127; + if(hx<0x00800000) + ix = subnormal_ilogbf(hx); + else + ix = (hx>>23)-127; /* determine iy = ilogb(y) */ - if(hy<0x00800000) { /* subnormal y */ - for (iy = -126,i=(hy<<8); i>0; i<<=1) iy -=1; - } else iy = (hy>>23)-127; + if(hy<0x00800000) + iy = subnormal_ilogbf(hy); + else + iy = (hy>>23)-127; /* set up {hx,lx}, {hy,ly} and align y to x */ if(ix >= -126)