From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 127163 invoked by alias); 24 May 2017 09:34:06 -0000 Mailing-List: contact newlib-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: newlib-owner@sourceware.org Received: (qmail 126916 invoked by uid 89); 24 May 2017 09:34:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.4 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=rights, business, advised, reserved X-HELO: dedi548.your-server.de Received: from dedi548.your-server.de (HELO dedi548.your-server.de) (85.10.215.148) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 24 May 2017 09:34:00 +0000 Received: from [88.198.220.132] (helo=sslproxy03.your-server.de) by dedi548.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.85_2) (envelope-from ) id 1dDSg6-0005R4-08 for newlib@sourceware.org; Wed, 24 May 2017 11:34:02 +0200 Received: from [82.135.62.35] (helo=mail.embedded-brains.de) by sslproxy03.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dDSg5-00022j-A7 for newlib@sourceware.org; Wed, 24 May 2017 11:34:01 +0200 Received: from localhost (localhost.localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 3F7BE2A092A for ; Wed, 24 May 2017 11:34:43 +0200 (CEST) Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id zHv7mjIwlW-s for ; Wed, 24 May 2017 11:34:42 +0200 (CEST) Received: from localhost (localhost.localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 999412A167C for ; Wed, 24 May 2017 11:34:42 +0200 (CEST) Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id Z65d1TCBSg64 for ; Wed, 24 May 2017 11:34:42 +0200 (CEST) Received: from huber-linux.eb.localhost (unknown [192.168.96.129]) by mail.embedded-brains.de (Postfix) with ESMTP id 66E0B2A160A for ; Wed, 24 May 2017 11:34:42 +0200 (CEST) From: Sebastian Huber To: newlib@sourceware.org Subject: [PATCH v2 5/8] Add __bitcount*() to RTEMS Date: Wed, 24 May 2017 09:34:00 -0000 Message-Id: <20170524093359.18334-5-sebastian.huber@embedded-brains.de> In-Reply-To: <20170524093359.18334-1-sebastian.huber@embedded-brains.de> References: <20170524093359.18334-1-sebastian.huber@embedded-brains.de> X-IsSubscribed: yes X-SW-Source: 2017/txt/msg00361.txt.bz2 Use a dedicated header file to avoid cyclic header dependencies in future changes. Signed-off-by: Sebastian Huber --- newlib/libc/sys/rtems/include/machine/_bitcount.h | 90 +++++++++++++++++++++++ newlib/libc/sys/rtems/include/machine/types.h | 2 + 2 files changed, 92 insertions(+) create mode 100644 newlib/libc/sys/rtems/include/machine/_bitcount.h diff --git a/newlib/libc/sys/rtems/include/machine/_bitcount.h b/newlib/libc/sys/rtems/include/machine/_bitcount.h new file mode 100644 index 000000000..ec324d274 --- /dev/null +++ b/newlib/libc/sys/rtems/include/machine/_bitcount.h @@ -0,0 +1,90 @@ +/*- + * Copyright (c) 2015 John Baldwin . + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the author nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _MACHINE__BITCOUNT_H +#define _MACHINE__BITCOUNT_H + +#ifdef __POPCNT__ +#define __bitcount64(x) __builtin_popcountll((__uint64_t)(x)) +#define __bitcount32(x) __builtin_popcountl((__uint32_t)(x)) +#define __bitcount16(x) __builtin_popcount((__uint16_t)(x)) +#define __bitcountl(x) __builtin_popcountl((unsigned long)(x)) +#define __bitcount(x) __builtin_popcount((unsigned int)(x)) +#else /* !__POPCNT__ */ +static __inline __uint16_t +__bitcount16(__uint16_t _x) +{ + _x = (_x & 0x5555u) + ((_x & 0xaaaau) >> 1); + _x = (_x & 0x3333u) + ((_x & 0xccccu) >> 2); + _x = (_x + (_x >> 4)) & 0x0f0fu; + _x = (_x + (_x >> 8)) & 0x00ffu; + return (_x); +} + +static __inline __uint32_t +__bitcount32(__uint32_t _x) +{ + _x = (_x & 0x55555555u) + ((_x & 0xaaaaaaaau) >> 1); + _x = (_x & 0x33333333u) + ((_x & 0xccccccccu) >> 2); + _x = (_x + (_x >> 4)) & 0x0f0f0f0fu; + _x = (_x + (_x >> 8)); + _x = (_x + (_x >> 16)) & 0x000000ffu; + return (_x); +} + +static __inline __uint64_t +__bitcount64(__uint64_t _x) +{ +#if __SIZEOF_LONG__ == 8 + _x = (_x & 0x5555555555555555u) + ((_x & 0xaaaaaaaaaaaaaaaau) >> 1); + _x = (_x & 0x3333333333333333u) + ((_x & 0xccccccccccccccccu) >> 2); + _x = (_x + (_x >> 4)) & 0x0f0f0f0f0f0f0f0fu; + _x = (_x + (_x >> 8)); + _x = (_x + (_x >> 16)); + _x = (_x + (_x >> 32)) & 0x000000ffu; + return (_x); +#else + return (__bitcount32(_x >> 32) + __bitcount32(_x)); +#endif +} + +#if __SIZEOF_LONG__ == 8 +#define __bitcountl(x) __bitcount64((unsigned long)(x)) +#else +#define __bitcountl(x) __bitcount32((unsigned long)(x)) +#endif + +#if __SIZEOF_INT__ == 8 +#define __bitcount(x) __bitcount64((unsigned int)(x)) +#else +#define __bitcount(x) __bitcount32((unsigned int)(x)) +#endif +#endif /* __POPCNT__ */ + +#endif /* _MACHINE__BITCOUNT_H */ diff --git a/newlib/libc/sys/rtems/include/machine/types.h b/newlib/libc/sys/rtems/include/machine/types.h index b28f92310..11ca37f26 100644 --- a/newlib/libc/sys/rtems/include/machine/types.h +++ b/newlib/libc/sys/rtems/include/machine/types.h @@ -28,6 +28,8 @@ #error "must be included via " #endif /* !_SYS_TYPES_H */ +#include + #if __BSD_VISIBLE #ifndef _ACCMODE_T_DECLARED -- 2.12.0