DMARC-Filter: OpenDMARC Filter v1.4.2 delorie.com 65AEUOVq2103938 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 65AEUOVq2103938 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=npt4cg6P X-Recipient: archive-cygwin AT delorie DOT com DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 32B814BA79AC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com; s=default; t=1781101822; bh=uic/VFI3kfJKLdasp/w43eZ6WVgCE3hoCH3sgzpjDJw=; h=References:In-Reply-To:Date:Subject:To:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=npt4cg6PXkuYr6iLfMgR8Cc2w/Sh2zTRLd8c1evtWNbZj6fqaYKOkrEyKMnit/zjc AGnACn7MEH73UZzGii1wali0MYbHdBy0LM5208TZM9Q1XD277IXiTeIvVfnCPLI5fM FcOe+g/9j5FC4+UzaJxpmLPcNpdxHVfKhi5fIbJ8= X-Original-To: cygwin AT cygwin DOT com Delivered-To: cygwin AT cygwin DOT com DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5F8FD4BA5436 ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5F8FD4BA5436 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1781101772; cv=pass; b=j+Lw+6Lhu4pVRSMySz+ow80y/7wPfvbCY2EyGpRhy7L7oro2orNMFfq9pBxn7XuY+9H+bht5XxctxEhBiVxgBJeXXsp/LxKIonw5T8H5kJqzpw6KgOBqlx/C6IuE/8yltN7YH//gsF5iFixwRhKfpQUTzhqpPX8dlArMsimyaTw= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1781101772; c=relaxed/simple; bh=QJCcryCqS0q7Q9DhGm50ntVyhhsQ5uXpN8kG/e/hYA8=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=x4+kjRWiNKvHMu3U4xnmluytBjl63u/leG8ytHIbFe8l2ByHjWbOvvSVkyJ/qhkgjCOxyBg+oRV4bHiMN065RcuXfkBKKiZJkVYyGcOXjgl3IzB6XxDEaXqfcuU0bUkupDv2vdWcBTmKi+Ml3TBxIuW2B3QXA7fTX3GoopfDIt0= ARC-Authentication-Results: i=2; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=qJ/L7dK+ DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5F8FD4BA5436 ARC-Seal: i=1; a=rsa-sha256; t=1781101771; cv=none; d=google.com; s=arc-20240605; b=Vb30b39h8EkF+xQyXcdlUY6J5SWxu7WFjfE9GYhLblOK/+EiVLmelcA27TQ7pqVXPv 8x9X3e11BALI8Qs7lvW/yylkhw/wMarJGNnZSktcidRrho/ae/HxyaVgLK1oIhT4trZT MeJJ0Ye+SuyUfhhe73tXxCLWcfGrHFTzmb6mo0pgwTIGTYRSaemsTcM8+qim4hRjdCWl D4+jvYf9b65sDSWUq5Dy50YLf3TVCiBEQ+sBP+RjGvB0VUN1grdzuGjVSSVF4B5d2w3o e+mr1lSmsYull0F16ykyCkLbhYcgMX/A8HjzgImCAZyTpoX0c07yOotPYcTZjs/LKfA/ yfYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=s+MzHHqkX7Y3iE+pmi0Q8LlpAqijNyH6FIYIfxaLodc=; fh=PF2IJWk7412VLWd+aGOjQPMVr9nTv6qSVYBCO6aq+hU=; b=iGHp0k8nr24ysYM0sfydXpoqW+cjwQTBGcxC/AaNsrdAjkqY18neUjyL6nuORDZOqX O52RViUYn3rvMWVWt2UTj644bY4NET+UWLklyYgF2eGIGM4YS1hB3ZXMto6h3i8WktOE NPT8jjyMOVmh66f+ZNidasQelXLA7lGvyqmO1ecHuZYYEalVzjifloGXfNxBN1ETMgHR tTQ1nMz+bw3A7sXcjGb2XmZiyaicmRPNXN43EK60VFPPbTJb2sVZdpx85Yl62rw6d8Im txyJ5WvLiVwArZZ4aFn45gF616vyIJ4O70Be+z83wPF8rzHhKLL5xt6fS7pjiO38j3+V ouyA==; darn=cygwin.com ARC-Authentication-Results: i=1; mx.google.com; arc=none X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781101771; x=1781706571; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=s+MzHHqkX7Y3iE+pmi0Q8LlpAqijNyH6FIYIfxaLodc=; b=L/fytVVR9N/8cpltz2BVqjM1kf4ZG6T2bpNEZOF0JQFvjEYJfeqh9BXkj3u6dkH8G6 zGHomStGuZFjcn4I8YaU3NPZUyvxQ7O4UOMbm9yK/sS6eR8JvwqyARJv2Ge6zJDskd/Z zNVowwjRB7U5G9NIWzKHpg2pnodKE29v5V+XeR16D6MFNmSpilFUHSDPaIo5y04Q1AnL 414Mo7Iao4cTtRBT/XPBIMhQymZKWZ3l/AT8N50g1LZkOlldDw85NImbvtFqMTZA4oeu la+l4YMSyOACRNWO0HOtmEZ/OaDWBTieQbvhbBgBE5zfIjEfCB9nA+Kx/yJqwRJDKJze I0xw== X-Gm-Message-State: AOJu0YyNWi+x0A97+/067yvvIdfLaRmyXwM0jPDpYy1rlGTVkFC+6OQK r00c+pyTqPqWXqD1gsdSMsSqsGpEUeZWLBj3FoCXs3cUpZ1mjD8j17SAajQx4EvQVIzoRFuxsSR 2fqslwwo4b6NXnoO0byprq0DZ6eIsHEQ0GysG X-Gm-Gg: Acq92OEd1taf/eLO+9hg1LW9JWiVDZ2yrVyxxyo9ULfS0HExNtucrKqW+LQcCqmZ1Xd fLQkPe4BCY6Gfm16cl+CUVJAVex2Yl1VhtdkdvTNR74c0o4Krvx+/BXD3KVxWSQOS68yp65P9uS IA1v+aCfRfCPLldVGNAKGfi4e8rRl+Sg5ZV8c/dmn61nhbTMhmJGB/VjGVrDg+xkU5ffH1/0nyk 23o/ry8D61paEdcX3FV2Z8iVA+/OW2Fi/S9i77sa3HmB9AHzacEY5lPg982maSYO77QfqoiK65F UcI2TNEo8AJZfezHSewrZuQnFTBHoPB7607KxjxsUrcGWHB1GvPnru8DElZdeNpVOeynWVgjNaw ZGQw= X-Received: by 2002:adf:eccc:0:b0:43d:68ad:3b7f with SMTP id ffacd0b85a97d-46030502428mr30576369f8f.21.1781101770805; Wed, 10 Jun 2026 07:29:30 -0700 (PDT) MIME-Version: 1.0 References: <1640804308 DOT 295932 DOT 1780787212417 AT connect DOT xfinity DOT com> <2125010483 DOT 296244 DOT 1780788258493 AT connect DOT xfinity DOT com> In-Reply-To: Date: Wed, 10 Jun 2026 16:29:18 +0200 X-Gm-Features: AVVi8CejbIaBXHmDh2h-GPiLSikWBC9gd4A_cU1hoEJsTmCMb_8fCL6Ic349YH4 Message-ID: Subject: Re: log2() is not called for C code, a bug into math.h ? To: Jakob Bohm Cc: cygwin AT cygwin DOT com X-BeenThere: cygwin AT cygwin DOT com X-Mailman-Version: 2.1.30 List-Id: General Cygwin discussions and problem reports List-Archive: List-Post: List-Help: List-Subscribe: , From: "Carlo B. via Cygwin" Reply-To: "Carlo B." Content-Type: text/plain; charset="utf-8" Sender: "Cygwin" Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by delorie.com id 65AEUOVq2103938 Hello, I can understand that x86 family can get a more efficient implementation by using a dedicated instruction. However, this doesn't change the first problem: Calling log2() DOESN'T WORK. It returns wrong results and the Python testsuite fails because of it. The macro that "overloads" the log2() function must be removed for solving this. Sincerely, Carlo Bramini. Il giorno mar 9 giu 2026 alle ore 04:10 Jakob Bohm via Cygwin ha scritto: > > On 08/06/2026 10:48, Carlo B. via Cygwin wrote: > > Hello, > > actually, we have to say that the source code of log2() into newlib: > > > > https://sourceware.org/git/?p=newlib-cygwin.git;a=blob;f=newlib/libm/common/log2.c;h=e48c16cf8014b5ba4b3a89af261f54472d643f65;hb=HEAD > > > > and the source code of log2() into glibc: > > > > https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/ieee754/dbl-64/e_log2.c;h=872cebddd8b4283edd2e653167035c0fd527f3ea;hb=HEAD > > > > are identical, so we can assume that this code is correct and probably > > the best we can get in terms of speed. > > However, here the problem is different. > > Using log() and the property of the logarithms for changing the base > > is mathematically correct. > > But here, it is WRONG. > > Unfortunately, this method doesn't provide the right result because > > the intrinsic format of IEEE-754 numbers propagates a precision error. > > Calculating the log2 of 2^1023 is a perfect integer number and it's > > 1023, not 1023.00000000000011. > > So, in my opinion that macro MUST be removed and the genuine log2() > > function must be used instead. > > > > Thank you very much for your time. > > Sincerely, > > > > Carlo Bramini. > That implementation is not what the OP apparently found in the Cygwin > copy of newlib. > > And both implementations are suboptimal for the x86 family, which has > a dedicated singleinstruction log2(double) function named FY2LX in its > floating point hardware, as mentionedduring the January discussion, in > fact the basic floating point x87 instruction set offerslog10() and > ln() only via multiplying log2() by a constant from the FLDLxx > instruction family. > > Something like: > > #if defined(__x86_64__) || defined(__i386) > double logfuncnam(double v) { > __asm__( > "...lines below..." // Put ifndef __x86_64__ around "FWAIT" > : "=t" (v) : "=t" (v) : "st(7)"); > return v; > } > #endif > > ; x87 assembler implementations of floating point logarithms > ; Initially input is in ST(0) via register calling convention or inlining > ; Somehow make sure there is at least one free entry in the ST() stack, > perhaps by > ; telling gcc __asm__ that this is needed as shown above > > "FWAIT\n\t" // Only needed if 386-, waits for 80x87 ready for new > instruction > "FLDLxx\n\t" // Different Lxx for log2, ln and log10 > // This pushes a relevant constant onto the ST() stack > // Use FLD1 = 1.0 = log2(2) for log2(a) > // Use FLDLN2 = ln(2) for ln(a) > // Use FLDLG2 = log10(2) for log10(a) > "FWAIT\n\t" // Only needed if 386-, waits for 80x87 ready for new > instruction > "FXCH ST(1)\n\t" // Put constant in ST(1), input in ST(0) > "FWAIT\n\t" // Only needed if 386-, waits for 80x87 ready for new > instruction > "FYL2X\n\t" // replace ST(0) and ST(1) by ST(1)*log2(ST(0)) > "FWAIT\n\t" // Optional: Pass exception (such as zero #Z or negative > // #IA arg) from FPU to CPU on Pentium and later > // On 386 and older, it is enough to do nothing and > // let the exception interrupt the CPU later. An FWAIT > // here would just waste time by halting the CPU > while the > // x87 chip calculates the logarithm. > ; logarithm is now in ST(0) for return > > ; ln() Machine code for 486+ is thus D9 ED // D9 C9 > // D9 F1 > ; log10() Machine code for all x86 chips is thus 9B D9 EC // 9B D9 C9 // > 9B D9 F1 > > The SSE instruction set seems to require using the x87 instruction > for logarithm anyway. > > > 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 -- 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