From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mo4-p00-ob.smtp.rzone.de (mo4-p00-ob.smtp.rzone.de [81.169.146.161]) by sourceware.org (Postfix) with ESMTPS id DF7043858D20 for ; Mon, 6 Nov 2023 17:36:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DF7043858D20 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=clisp.org Authentication-Results: sourceware.org; spf=none smtp.mailfrom=clisp.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org DF7043858D20 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=81.169.146.161 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1699292174; cv=pass; b=g9HDpU+QJbRpWZtAHK2nZGv44Y0LcA9ao2BvfbG8ViIpssuKjeHcueLMyKIOz5OBCJMmSSfBITLAPHlxftag8iTnhGRHyW6UH24tRiID+JJ4czCZmas82/Mf7A9PV1oMQ4fEdjAopyp7lC4NxlKwfSbcBDu4Mu5mLyvBW1Rd4dQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1699292174; c=relaxed/simple; bh=u1Hn+uF9xWyuLx+ZnMTsiEFkMXwwdy32BNGKnEuYcHc=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=cvw7sS5/UWXlAtnxO7VdwdOb9II5sc7X7qbbZVK6nfZQJsnXqhVyIQTipEdW6qnYWJW0741H7ufWBOKedLgtGO+OdlAPuoxdCy+4T9IIdbWyLkkOw35EdUfO5mmJ6GNkRCMWYLSUL21I8mEQ3uTjygJh0Aoh2zpKFcWhd8oT/oU= ARC-Authentication-Results: i=2; server2.sourceware.org ARC-Seal: i=1; a=rsa-sha256; t=1699292170; cv=none; d=strato.com; s=strato-dkim-0002; b=ZTiG218RfaOJG65JMQUGgU7dmqXoWC5bhNWafSMem5XsnDdSz4cM29vfoO4wmr+Uy8 dN2p8TFBUYdD3v0NSEbvLCnuIQH6N2F0ug90ue0gPF8sZVPe11W8m9cgqI8igkyBmiSW +NWF/JgDWfQAZa4BzFFEqxBbPxym5d6+WlGoWDxx+yHSmnd+FHcJHfp75kVJ4+mAJItX 27gV9Icilmrej9BjGgdYkHcHnif4VKqnSKqEy7f7NTL3GCtY/a/SB2YO49FnGrgMFmxS iUrdmMoffJcyQIJiQPRQJezUtFcuK4e/Dzu8tQiKNJSuE1AXWjT0zvkFbSrrpkh5rrf/ qtFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1699292170; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=rs3BhS5lyEaoumVZVYekWTYuoZijuNvrXm/d8EM9Vzk=; b=bpGV4HJ5RIO0/TtgylezjoAuBz3VSlHZX48KUUMrMd1mqKgjJdwupfbHCksQzqMJsU SqszSofkw3O2xR7c6gHvvPVZ/T7FdC/pY1sJWNM4A4QTWncTYn/8j4yEKm+OG+2JLE7W Hvv9WKd79HdVyXfoeVXmP0ZWbbp7sNPa1IVgV4GwrndUnsviPMTAJEDUuY8+eRNicZxi nYf8amMtAfyhI/eNR+N6TFXhq6KiVj/qVRmF/qDtEYPAkuey03uJiClt6y2t/PUix9Rm emx8igzKxlRv3Q/Fs4LxY8x4VhrsJCfz2STXK4938u4oHN5pO9z9zQ2CVPGi8lRw/NNM hBGA== ARC-Authentication-Results: i=1; strato.com; arc=none; dkim=none X-RZG-CLASS-ID: mo00 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1699292170; s=strato-dkim-0002; d=clisp.org; h=References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=rs3BhS5lyEaoumVZVYekWTYuoZijuNvrXm/d8EM9Vzk=; b=YU0MPlAQwoynCjFsigFY8pEwyFlVW/AAI4+tJ5ndm6ZtkdoIA8os2pHy2C97JSLCGT IVae+avY6z17YE9eKP4Sjb44/iK2fxVcOdOga3osXK+lf5+n0HfIBZcFj9q1PRqy7Ksd c5OADNeRf6uIqGl2Ygi1aqlEoIt/p0A9vgydRkB0cNw9+SgFeX2gMrO3In4IZnkymR4e gBFXTka+xytUaKVmWh7i4/aVPqm+boYQTl9X02ii1iREpPycuxyzigizl05weO5GfOF+ 2PBKou/9cBMboIaWKkglWULrHNmr62M2QYkhuQnZ0/5xojUQmFBQL96NOy6jfaqRD2cX ammQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1699292170; s=strato-dkim-0003; d=clisp.org; h=References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=rs3BhS5lyEaoumVZVYekWTYuoZijuNvrXm/d8EM9Vzk=; b=qjQarfuXjiLopOPPK+Vy5Y3yHoDwJV5fwAXniO3DDSHjgUbjHmhVd/XN+lJ/gbhR+Y wPAx1va008v95aQWLyDg== X-RZG-AUTH: ":Ln4Re0+Ic/6oZXR1YgKryK8brlshOcZlIWs+iCP5vnk6shH0WWb0LN8XZoH94zq68+3cfpOfifxtHZ2nzVc5nNxjw6FTZMSe" Received: from nimes.localnet by smtp.strato.de (RZmta 49.9.1 AUTH) with ESMTPSA id ecf079zA6Ha9vpz (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Mon, 6 Nov 2023 18:36:09 +0100 (CET) From: Bruno Haible To: Carlos O'Donell Cc: Adhemerval Zanella , libc-alpha@sourceware.org Subject: Re: [PATCH v2 6/7] alpha: Fix fesetexceptflag (BZ 30998) Date: Mon, 06 Nov 2023 18:36:09 +0100 Message-ID: <6460552.QZNE9M9tJY@nimes> In-Reply-To: References: <20231106132713.953501-1-adhemerval.zanella@linaro.org> <20231106132713.953501-7-adhemerval.zanella@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Carlos O'Donell wrote: > I would expect (taken from hppa code I wrote for that port): > > /* Clear all status bits we care about. */ > tmp = tmp & ~(excepts & SWCR_STATUS_MASK); > /* Install the new ones. */ > tmp |= *flagp & excepts & SWCR_STATUS_MASK; This code is correct. And, as I wrote in https://sourceware.org/bugzilla/show_bug.cgi?id=30998#c2 the code with the double-xor is faster, because it uses one less instruction. Basically the code you proposed masks the bits to clear and the bits to set separately. Whereas the code with the double-xor masks the bits to *change* - a single AND instead of two. > > /* Set all the bits that were called for. */ > > - tmp = (tmp & ~SWCR_STATUS_MASK) | (*flagp & excepts & SWCR_STATUS_MASK); > > + tmp ^= (tmp ^ *flagp) & excepts & SWCR_STATUS_MASK; > > Does this actually work? Yes: It computes the bits to *change*, then applies the mask, then applies the changes. For bits in the mask, it does tmp.bit[i] ^= tmp.bit[i] ^ (*flagp).bit[i]; which simplifies to tmp.bit[i] = (*flagp).bit[i]; For bits outside the mask, it does tmp.bit[i] ^= 0; i.e. it leaves the bit unchanged. I'm using this same idiom also in gnulib https://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=blob;f=lib/fenv-except-state-set.c;h=2035f61e2714126e432c0c1f29450f18f58d81f1;hb=HEAD#l182 and I have verified that it works. > Assume excepts is FE_INVALID, and *flagp bit 17 is 0. > Assume currently bit 17 is 1. > > tmp ^ *flagp => bit 17 is still 1, even though bit 17 in flagp is 0. > & excepts => bit 17 is still 1. > & SWCR_STATUS_MASK => bit 17 is still 1. > ^= => bit 17 is still 1. In the last step: 1 xor 1 is 0. Bruno