From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 12836 invoked from network); 11 Aug 2021 17:04:38 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 11 Aug 2021 17:04:38 -0000 Received: (qmail 24243 invoked by uid 550); 11 Aug 2021 17:04:35 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 24222 invoked from network); 11 Aug 2021 17:04:35 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nexgo.de; s=vfde-smtpout-mb-15sep; t=1628700815; bh=AIGf5xtabrZA8l4zQKjQI2/rGWLN/afkdXvhl+dyVtQ=; h=From:To:Cc:References:In-Reply-To:Subject:Date; b=VTgoIk/UbVa2G6L6ZHL4T01vJIDVnqX1uy5bEoOHIx2GJBXnU1dTFT3SKu9udLoGk RbIG0o4Nt4tL7GvHCd2pd9e7IPs7XtYTcS3aHeZJI5wbG3EdmCeqVLOvEVSbpipGSp C6wg8AEAFpumUIQ3cj5XlzKWCRjYHtQXyzOxirTo= Message-ID: From: "Stefan Kanthak" To: "Rich Felker" Cc: "Szabolcs Nagy" , References: <0C6AAAD55DA44C6189B2FF4F5FB2C3E7@H270> <20210810213455.GB37904@port70.net> <5C60D05C95724A36B3DB9942D06CFE5F@H270> <20210811024010.GA13220@brightrain.aerifal.cx> <7143269BEC424DE6A3B0218C4268C4C8@H270> <20210811160938.GB13220@brightrain.aerifal.cx> In-Reply-To: <20210811160938.GB13220@brightrain.aerifal.cx> Date: Wed, 11 Aug 2021 18:50:28 +0200 Organization: Me, myself & IT MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Windows Mail 6.0.6002.18197 X-MimeOLE: Produced By Microsoft MimeOLE V6.1.7601.24158 X-purgate-type: clean X-purgate-Ad: Categorized by eleven eXpurgate (R) http://www.eleven.de X-purgate: This mail is considered clean (visit http://www.eleven.de for further information) X-purgate: clean X-purgate-size: 1931 X-purgate-ID: 155817::1628700815-00007455-B3C7B59F/0/0 Subject: Re: [musl] [PATCH] Properly simplified nextafter() Rich Felker wrote: [...] > static __inline unsigned __FLOAT_BITS(float __f) > { > union {float __f; unsigned __i;} __u; > __u.__f = __f; > return __u.__i; > } > > #define isnan(x) ( \ > sizeof(x) == sizeof(float) ? (__FLOAT_BITS(x) & 0x7fffffff) > 0x7f800000 : \ > sizeof(x) == sizeof(double) ? (__DOUBLE_BITS(x) & -1ULL>>1) > 0x7ffULL<<52 : \ > __fpclassifyl(x) == FP_NAN) > > So, nope. GCC typically uses its __builtin_isnan() for isnan(), which doesn't use integer instructions or reloads: $ cat isnan.c int foo(double x) { return isnan(x); } int bar(double x) { return __builtin_isnan(x); } $ gcc -S -O3 -o- isnan.c ... xorl %eax, %eax ucomisd %xmm0, %xmm0 setp %al ret ... > Unless it's doing some extremely high level rewriting of > this inspection of the representation. It performs the high-level substitution of isnan with __builtin_isnan [...] >> GCC generates here at least 12 instructions more, also longer ones, >> including 2 movabs to load 0x8000000000000000 and 0x7FFFFFFFFFFFFFFF, >> so the code is more than 50% fatter, mixes integer SSE and FP SSE >> instructions which incur 2 cycles penalty on many Intel CPUs, with >> WAY TOO MANY not so predictable (un)conditional branches. > > We don't use asm to optimize out 2 cycles. This is just ONE of the many deficiencies of the code GCC generates. > If the compiler is choosing a bad way to perform these loads the compiler > should be fixed. But I don't think it matters in any measurable way in real usage. On several families of Intel Core-i processors this 1 cycle penalty occurs EVERY time an SSE register is accessed by a FP instruction AFTER an integer instruction and vice versa! BAD: pxor xmm1, xmm1 cmpsd xmm0, xmm1 good: xorpd xmm1, xmm1 cmpsd xmm0, xmm1 Stefan