From nobody Thu Aug 14 18:39:58 2025 X-Original-To: dev-commits-src-main@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 4c2vDZ4VPsz64rTf; Thu, 14 Aug 2025 18:39:58 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4c2vDZ3Qq7z3hKT; Thu, 14 Aug 2025 18:39:58 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1755196798; 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=DWK4d6PHaHTTQQPYQvta0dRd04HY917n/JHnJaBdIXw=; b=oDzjbWJQP9zHzIv4eBSXU746t56SD49H2CongJ3EiucCltPZCrfFzXZdg1MnHg2Sn7CBK3 B7dLetOOloIxQuvPM+hVCuj7DneizEkEoti7iXeCpz6aOvn56lNViCsIi0ORX+qUck0lXY idcg9YHTn+S/d4ZzIDNCbCKxRZwqQw9pDzPcw03ApvEj3M/neGMpoUT38MF7Qwhxp+k6+S qzedPNf96jL5JNN2L39gt3zj1BoMdtKRs8ADPxTt+Tswz2sd03akIiFDjf4my3zqvTVuoi +3Xp/5OSrLcYsqdZY0mTiFZPkSBRf1KYHTdJBa5hTQ91XGy68IKcIMmFyzFBpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1755196798; 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=DWK4d6PHaHTTQQPYQvta0dRd04HY917n/JHnJaBdIXw=; b=JBfCtdT1AIeKcPV334UGptTHR/DT7Iug9ijo8CxEzJ8HuXmdAbV4X79aykoRxxPbJaPSIM qwaDOomjtcfeOc9aP9rfW5eFiRQwO3LsnEX5oc4gfeLZsAjdLBXBwsAQGvRVJQGzuNJrIS ai6bPfZ1+9aqKkPiEbaHp6vjP86Xkm2W/3M018HcrT6N7uQdq1zkN2wg6SB9AmfRfr042r TNZULng837q08XUugVva2gjxWpaovBeVYIyIHBTL/EFmkPvn8xM/lAAFPwbuoYMCbaFidk neSXuDZMKjxh/w8zzkwgP4psysrAPkkxdS1DxK704KAxneEqEVab60LxiFti6g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1755196798; a=rsa-sha256; cv=none; b=EeoACZPwRF+ETizaJgMDVe7Kz6WpP/u9fBDl4ESZkRvglpDyDbtMZ6BIXVlNnH7veXBSVu HnnokPxnbpSPWxZJsx62kXJL+TJVfr3XOu9pvqKb6b3PM1B+14GwwjzM7RyNNFrliPD/HU jKHMCFLk4WKCcSRhr/gIbrKMr3lQPnd8ikvTfRnHdHDcMXrsjDBA+RDDB6/2xs9X1p89+G YofB/S9gBkyw80ILtFODM4RJi9TW8aOmIsh+DtejPZtJD7bjB568kYG71zJdn+pXZoqP7Q afjs/bazDeyY2fuJyoTnWlid/f3XA25kyP+bq5c8WteQRl778sHQ5io3ze7BGg== 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 4c2vDZ2rQ8z14SY; Thu, 14 Aug 2025 18:39:58 +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 57EIdwNl062169; Thu, 14 Aug 2025 18:39:58 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 57EIdwCF062166; Thu, 14 Aug 2025 18:39:58 GMT (envelope-from git) Date: Thu, 14 Aug 2025 18:39:58 GMT Message-Id: <202508141839.57EIdwCF062166@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dimitry Andric Subject: git: c58c77246f88 - main - [libm] Avoid left shift of signed integer entities List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: c58c77246f88da87f309e8c449e98195d43e2c76 Auto-Submitted: auto-generated The branch main has been updated by dim: URL: https://cgit.FreeBSD.org/src/commit/?id=c58c77246f88da87f309e8c449e98195d43e2c76 commit c58c77246f88da87f309e8c449e98195d43e2c76 Author: Steve Kargl AuthorDate: 2025-08-14 18:38:41 +0000 Commit: Dimitry Andric CommitDate: 2025-08-14 18:38:41 +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 --- 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 a7d1a0c22acd..ada969db44c7 100644 --- a/lib/msun/src/e_fmodf.c +++ b/lib/msun/src/e_fmodf.c @@ -27,7 +27,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); @@ -44,14 +44,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 0711f2f33c41..fbd84e246ca7 100644 --- a/lib/msun/src/math_private.h +++ b/lib/msun/src/math_private.h @@ -740,7 +740,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) @@ -760,6 +760,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 e0f8fee26ac8..5195e2331af3 100644 --- a/lib/msun/src/s_ilogbf.c +++ b/lib/msun/src/s_ilogbf.c @@ -18,7 +18,8 @@ #include "math.h" #include "math_private.h" - int ilogbf(float x) +int +ilogbf(float x) { int32_t hx,ix; @@ -28,7 +29,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 9cd148586796..e4adb8321559 100644 --- a/lib/msun/src/s_remquof.c +++ b/lib/msun/src/s_remquof.c @@ -25,7 +25,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); @@ -47,14 +47,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)