DMARC-Filter: OpenDMARC Filter v1.4.2 delorie.com 60M2YE221867033
Authentication-Results: delorie.com; dmarc=pass (p=none dis=none) header.from=cygwin.com
Authentication-Results: delorie.com; spf=pass smtp.mailfrom=cygwin.com
DKIM-Filter: OpenDKIM Filter v2.11.0 delorie.com 60M2YE221867033
Authentication-Results: delorie.com;
	dkim=pass (1024-bit key, unprotected) header.d=cygwin.com header.i=@cygwin.com header.a=rsa-sha256 header.s=default header.b=paAZc3j3
X-Recipient: archive-cygwin@delorie.com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 636F54BC8974
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
	s=default; t=1769049253;
	bh=nP0APUQdMLL1a5SarIWmw02pyUXYk4JJhdCD3lXMUgA=;
	h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe:
	 List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:
	 From;
	b=paAZc3j3Owy4U7yH9ClrFAnZJUNrEavBIT3+1OR5dXopZggaJi3xTMFHlxNPQfVb5
	 VyFNmGlC/AL+EI4yCBPmnMeUkjyg895X/FBzgtjDJ9XGdXpMLx8a3qKjzTA/7HJDoT
	 zcMJao7R5/7n1+Qv/2FhVYY9vDOk+0Y89wuqVphs=
X-Original-To: cygwin@cygwin.com
Delivered-To: cygwin@cygwin.com
DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 267394BA900C
ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 267394BA900C
ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1769049204; cv=none;
 b=C2HFW1rL3fCtSAlLyd/LwkTqKYzZXJ2WPSWah3IPWxyglVLB0hhtCtDPVsU1GS0j1y47NHKsEZ+Sn4ZxQtjy1V6pWhIpYQoJ7VZoCpqXs9x+Jya2V3AULOfgyBu+dzmFjMC5Fid01uf4BMih6nE3W9BbgrrHeB9lS2OZcsmukf8=
ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key;
 t=1769049204; c=relaxed/simple;
 bh=VkCcbpqcljpsIbwlDdyFOLd94kuQyB89+ovcOcucbUo=;
 h=DKIM-Signature:Subject:To:From:Message-ID:Date:MIME-Version;
 b=USQQ1IpCUga+HrD0R23yeNgk7i0mHPigjUojdsi0w9wCurzrp+WlOHD3asNHEGCy4f8IM+3tIVAgeWp3N1By8sd6BWDsYu6b4ugqpiRj2kPOMxfKphuLCImDiXTN7q9Ar3oOsEcYQ6QdjlmsvqEUHQaSL00AcWPVMXupRZwblUM=
ARC-Authentication-Results: i=1; server2.sourceware.org
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 267394BA900C
Subject: Re: Log2 seems inefficient
To: cygwin@cygwin.com
References: <226987210.591128.1768766440723@connect.xfinity.com>
Organization: WiseMo A/S
Message-ID: <cc290097-2b7c-a067-981d-f0c3b6f5ee85@wisemo.com>
Date: Thu, 22 Jan 2026 03:33:22 +0100
X-Mailer: Epyrus/2.1.3
MIME-Version: 1.0
In-Reply-To: <226987210.591128.1768766440723@connect.xfinity.com>
Content-Language: en-US
X-BeenThere: cygwin@cygwin.com
X-Mailman-Version: 2.1.30
Precedence: list
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Unsubscribe: <https://cygwin.com/mailman/options/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=unsubscribe>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-request@cygwin.com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=subscribe>
From: Jakob Bohm via Cygwin <cygwin@cygwin.com>
Reply-To: Jakob Bohm <jb-cygwin@wisemo.com>
Content-Type: text/plain; charset="utf-8"; Format="flowed"
Errors-To: cygwin-bounces~archive-cygwin=delorie.com@cygwin.com
Sender: "Cygwin" <cygwin-bounces~archive-cygwin=delorie.com@cygwin.com>
Content-Transfer-Encoding: 8bit
X-MIME-Autoconverted: from base64 to 8bit by delorie.com id 60M2YE221867033

On 18/01/2026 21:00, KENNON J CONRAD via Cygwin wrote:
> Hello,
>   
>     I am not an experienced cygwin user but have been using it to compile code on Windows (gcc), so I may be leaving out some key details.  My issue is that for every log2 call in my code there is a divide that follows a log library call in the assembly code.  It appears to be related to these lines in math.h:
>   
> #if !defined(__cplusplus)
> #define log2(x) (log (x) / _M_LN2)
> #endif
>   
> My questions are:  If log(x) is used, wouldn't it be faster to multiply by constant (1/LN2) instead of divide by constant (LN2)?  And wouldn't it be even more efficient to compute log2 directly instead of computing the natural log and then converting it to log2?
>   
> I realize this is not a "bug", it just doesn't seem very optimal from an speed standpoint.
Please note, that on the x86 and x86_64 platforms, the natural log
function log() is often implemented in terms of the intrinsic log2()
function multiplied by log(2), which is done by the instruction FYL2X,
thus preferably the x86 family port of newlib should include an
intrinsic or inline implementation such as something doing the
assembler sequence FLD1, FXCH, FYL2X, which takes the arg in ST(0)
and returns the log2() result in ST(0).  For targets that tend to
run the floating point subsystem in a mode other than traditional
x87, perhaps finding similar inline code for SSE or MMX would be
needed.  Other libc implementations may include the needed code in
gcc-compatible format already.

Enjoy

Jakob
-- 
Jakob Bohm, CIO, Partner, WiseMo A/S.  https://www.wisemo.com
Transformervej 29, 2860 Søborg, Denmark.  Direct +45 31 13 16 10
This public discussion message is non-binding and may contain errors.
WiseMo - Remote Service Management for PCs, Phones and Embedded


-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

