From patchwork Tue Mar 3 18:20:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matheus Castanho X-Patchwork-Id: 38393 X-Patchwork-Delegate: tuliom@linux.vnet.ibm.com Received: (qmail 49391 invoked by alias); 3 Mar 2020 18:20:44 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 49377 invoked by uid 89); 3 Mar 2020 18:20:44 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-15.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.1 spammy=HContent-Transfer-Encoding:8bit X-HELO: mx0a-001b2d01.pphosted.com From: Matheus Castanho To: libc-alpha@sourceware.org Subject: [PATCH] powerpc: Fix feraiseexcept and feclearexcept macros Date: Tue, 3 Mar 2020 15:20:38 -0300 Message-Id: <20200303182038.6873-1-msc@linux.ibm.com> MIME-Version: 1.0 A recent change to fenvinline.h modified the check if __e is a a power of 2 inside feraiseexcept and feclearexcept macros. It introduced the use of the powerof2 macro but also removed the if statement checking whether __e != 0 before issuing an mtfsb* instruction. This is problematic because powerof2 (0) evaluates to 1 and without the removed if __e is allowed to be 0 when __builtin_clz is called. In that case the value 32 is passed to __MTFSB*, which is invalid. This commit uses __builtin_popcount instead of powerof2 to fix this issue and avoid the extra check for __e != 0. This was the approach used by the initial versions of that previous patch. --- sysdeps/powerpc/bits/fenvinline.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sysdeps/powerpc/bits/fenvinline.h b/sysdeps/powerpc/bits/fenvinline.h index 89ea38a4f8..f2d095a72f 100644 --- a/sysdeps/powerpc/bits/fenvinline.h +++ b/sysdeps/powerpc/bits/fenvinline.h @@ -75,7 +75,7 @@ int __e = __excepts; \ int __ret = 0; \ if (__builtin_constant_p (__e) \ - && powerof2 (__e) \ + && __builtin_popcount (__e) == 1 \ && __e != FE_INVALID) \ { \ __MTFSB1 ((__builtin_clz (__e))); \ @@ -91,7 +91,7 @@ int __e = __excepts; \ int __ret = 0; \ if (__builtin_constant_p (__e) \ - && powerof2 (__e) \ + && __builtin_popcount (__e) == 1 \ && __e != FE_INVALID) \ { \ __MTFSB0 ((__builtin_clz (__e))); \