DMARC-Filter: OpenDMARC Filter v1.4.2 delorie.com 60IMiFxc3795026 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 60IMiFxc3795026 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=vlyrjATv X-Recipient: archive-cygwin AT delorie DOT com DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6C76B4BA23FF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com; s=default; t=1768776253; bh=5xJTmM4FDpeSAH4AP2tLiPLD5IKXxP2tMCq0VGnyKA0=; h=Date:Subject:To:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=vlyrjATvnWAX3zRBrgrFizmvWLYCNtFE2kEpm0eWueK3KodAejtW77SztvEZ4rVHE NKYCtMHNnU4Mn37zFKLTra2GFRsP2kxPhEPPLB2EMiXsvIuob9FqXxVb0LrwmiwDqk UqnIQOax1o4R+nwW8ZbgHhGuY7y2TnmoeDseH6/g= X-Original-To: cygwin AT cygwin DOT com Delivered-To: cygwin AT cygwin DOT com DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EE6D34BA2E1D ARC-Filter: OpenARC Filter v1.0.0 sourceware.org EE6D34BA2E1D ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1768776205; cv=none; b=wLuATi2/UEVeWeTMFMg27aHw4hvDx8Z5NeYnbhLFntYQmyvlG14Ki2qxCIpXvf4xPqpzandTW5iWOtGv0iuDaemtduJIx+ChVR7Lkum2RQ4uIXpN8V8BPvclwRiP39zqle2XUcug+oqaEy4jVmWWq+vlUautfMNxlUrONkaiDCw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1768776205; c=relaxed/simple; bh=Goz5oQzErO5pQVtNkdS2qHJEe6MhfCXdTRL63CT4QWY=; h=Message-ID:Date:MIME-Version:From:Subject:To:DKIM-Signature; b=qjlKpPBAyJ4tEXVVEIzSaE0o9PczLMq09xz8UOOWuJc+oNzD7ThUCyEGPs337YtCpvXovXrAx8k3UKt8vscZzTEHo2/QHx/6flwNydZuODHjfxTDTaOGX4L5fmLKaFZ26Eoy+wX57OlMasRaeQGzOcIeO0fKLRK0UFOE3fETQl0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EE6D34BA2E1D Message-ID: <3c56778a-870c-4bae-a855-6b96392870c8@SystematicSW.ab.ca> Date: Sun, 18 Jan 2026 15:43:21 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Log2 seems inefficient Content-Language: en-CA To: cygwin AT cygwin DOT com References: <226987210 DOT 591128 DOT 1768766440723 AT connect DOT xfinity DOT com> Organization: Systematic Software In-Reply-To: <226987210.591128.1768766440723@connect.xfinity.com> X-Stat-Signature: 4nzyfgjfowq74f6tw8n9n5f1wbdku4ze X-Rspamd-Server: rspamout01 X-Rspamd-Queue-Id: C307D20011 X-Session-Marker: 427269616E2E496E676C69734053797374656D6174696353572E61622E6361 X-Session-ID: U2FsdGVkX1+15EQ145VTHZpp+BwkyJujIu+357B8w6w= X-HE-Tag: 1768776202-619960 X-HE-Meta: U2FsdGVkX19bwq3CfcdXRmmSQ6cE9MFen9DX8yxADCRjUKeFNZcxnSuR2q90otIiSeHODweSoe/Q2JdOJQD1IPP49Z/t7RlCn2mIWmYxM/pgmCjIj1KoNeYkl4ZQcd8FnAXsbcUgw7r7N8D7bMHh+gpw/qrrS5fw1kUa0os7kuFWntzJx3FzYoI6WSFMn0xyCkxZD+5x9FH/GvXC1eIBGE09y/Jr0jK/b+yki0+X+qAWQsxwzXwUMV8OSR3+NC2Y3co1MIf1eZYaJBXjAIZS9b8R1Unq87ffxU/aVz/HHxgxsLrAArLUSp2S4yM6L4JPAzV+F3dgZBC3y6ef9eTSqvImcbQBX3ZCFQqimp7UIjtot+rPp1QV3vs7dd6RaBl6d0hHL1NOUocJ4JYUKEV8bBU7Aq5KEtTbmOcVlfJuzRporpf0m2PnytONdTwN2FIWZCQ1judKIb04HXa0YXiQBg== X-BeenThere: cygwin AT cygwin DOT com X-Mailman-Version: 2.1.30 Precedence: list List-Id: General Cygwin discussions and problem reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Brian Inglis via Cygwin Reply-To: cygwin AT cygwin DOT com Cc: Brian Inglis , Paul Zimmermann Content-Type: text/plain; charset="utf-8"; Format="flowed" Errors-To: cygwin-bounces~archive-cygwin=delorie DOT com AT cygwin DOT com Sender: "Cygwin" Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by delorie.com id 60IMiFxc3795026 On 2026-01-18 13:00, KENNON J CONRAD via Cygwin wrote: > 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. You are probably correct, as the FP exponent provides the first order estimate of the result, and only the mantissa bits need converted, with possibly minor iterative/unrolled tweaking for ultimate accuracy. When the code was updated by ARM in 2018, the commit message said: "... With default settings the worst case error in nearest rounding mode is 0.547 ULP with inlined fma and fma contraction. It uses a 1 KB lookup table, ... Note that the math.h header defines log2(x) to be log(x)/Ln2, this is not changed, so the new code is only used if that macro is suppressed." which may be to reduce the amount of space used by math tables in embedded libraries, the most numerous newlib targets, especially for minimal implementations like Nano libc, whereas hosted implementations like Cygwin, RTEMS, others may prefer to use the table. I think that perhaps Cygwin should interpose #ifdef log2/#undef log2 where these space saving measures have been employed, given the amount of space used by locales, charset support including Unicode, dates/times, ..., and you can do so yourself. You may want to check which implementation gives the quickest and most accurate results before making changes. Paul Zimmerman regularly posts library math function comparisons on the newlib and comparable library mailing lists, available at: https://members.loria.fr/PZimmermann/papers/accuracy.pdf that should give you an idea of the current state of the functions, if he is even aware of the issue. You can find his posts at: https://inbox.sourceware.org/newlib/?q=loria.fr -- Take care. Thanks, Brian Inglis Calgary, Alberta, Canada La perfection est atteinte Perfection is achieved non pas lorsqu'il n'y a plus rien à ajouter not when there is no more to add mais lorsqu'il n'y a plus rien à retrancher but when there is no more to cut -- Antoine de Saint-Exupéry -- 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