From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15472 invoked by alias); 19 May 2017 05:52:07 -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 127997 invoked by uid 89); 19 May 2017 05:50:56 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-18.9 required=5.0 tests=AWL,BAYES_00,FOREIGN_BODY,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS,T_FILL_THIS_FORM_SHORT autolearn=ham version=3.3.2 spammy=mitteilung, Mitteilung, H*r:192.168.96, Fax 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; Fri, 19 May 2017 05:50:46 +0000 Received: from [88.198.220.130] (helo=sslproxy01.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 1dBao6-0005X9-R8; Fri, 19 May 2017 07:50:34 +0200 Received: from [82.135.62.35] (helo=mail.embedded-brains.de) by sslproxy01.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dBao5-0004ky-MQ; Fri, 19 May 2017 07:50:34 +0200 Received: from localhost (localhost.localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 846402A003F; Fri, 19 May 2017 07:51:07 +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 rPlu2fq-ceh6; Fri, 19 May 2017 07:51:06 +0200 (CEST) Received: from localhost (localhost.localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id D260D2A0047; Fri, 19 May 2017 07:51:06 +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 6hBhKSIS9cKt; Fri, 19 May 2017 07:51:06 +0200 (CEST) Received: from [192.168.96.129] (unknown [192.168.96.129]) by mail.embedded-brains.de (Postfix) with ESMTPSA id B9B142A003F; Fri, 19 May 2017 07:51:06 +0200 (CEST) Subject: Re: [PATCH v2] For RTEMS-LIBBSD support, add bitcount routines To: Kevin Kirspel , newlib@sourceware.org References: <201705171306.v4HD3IpM000428@mx0a-00116901.pphosted.com> From: Sebastian Huber Message-ID: <591E87A5.3010608@embedded-brains.de> Date: Fri, 19 May 2017 05:52:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.0 MIME-Version: 1.0 In-Reply-To: <201705171306.v4HD3IpM000428@mx0a-00116901.pphosted.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2017/txt/msg00336.txt.bz2 On 17/05/17 15:06, Kevin Kirspel wrote: > --- > newlib/libc/sys/rtems/include/machine/types.h | 58 ++++++++++++++++++++= +++++++ > 1 file changed, 58 insertions(+) > > diff --git a/newlib/libc/sys/rtems/include/machine/types.h b/newlib/libc/= sys/rtems/include/machine/types.h > index b28f923..0b0a100 100644 > --- a/newlib/libc/sys/rtems/include/machine/types.h > +++ b/newlib/libc/sys/rtems/include/machine/types.h > @@ -83,3 +83,61 @@ typedef __uintmax_t rman_res_t; > #endif >=20=20=20 > #endif /* __BSD_VISIBLE */ > + > +#ifdef __POPCNT__ > +#define __bitcount64(x) __builtin_popcountll((__uint64_t)(x)) > +#define __bitcount32(x) __builtin_popcount((__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__ */ > +/* > + * Population count algorithm using SWAR approach > + * - "SIMD Within A Register". > + */ > +static __inline __uint16_t > +__bitcount16(__uint16_t _x) > +{ > + _x =3D (_x & 0x5555) + ((_x & 0xaaaa) >> 1); > + _x =3D (_x & 0x3333) + ((_x & 0xcccc) >> 2); > + _x =3D (_x + (_x >> 4)) & 0x0f0f; > + _x =3D (_x + (_x >> 8)) & 0x00ff; > + return (_x); > +} > + > +static __inline __uint32_t > +__bitcount32(__uint32_t _x) > +{ > + _x =3D (_x & 0x55555555) + ((_x & 0xaaaaaaaa) >> 1); > + _x =3D (_x & 0x33333333) + ((_x & 0xcccccccc) >> 2); > + _x =3D (_x + (_x >> 4)) & 0x0f0f0f0f; > + _x =3D (_x + (_x >> 8)); > + _x =3D (_x + (_x >> 16)) & 0x000000ff; > + return (_x); > +} > + > +#if __SIZEOF_INT__ =3D=3D 8 > +static __inline __uint64_t > +__bitcount64(__uint64_t _x) > +{ > + _x =3D (_x & 0x5555555555555555) + ((_x & 0xaaaaaaaaaaaaaaaa) >> 1); > + _x =3D (_x & 0x3333333333333333) + ((_x & 0xcccccccccccccccc) >> 2); > + _x =3D (_x + (_x >> 4)) & 0x0f0f0f0f0f0f0f0f; > + _x =3D (_x + (_x >> 8)); > + _x =3D (_x + (_x >> 16)); > + _x =3D (_x + (_x >> 32)) & 0x000000ff; > + return (_x); > +} > + > +#define __bitcountl(x) __bitcount64((unsigned long)(x)) > +#else /* __SIZEOF_INT__ =3D=3D 8 */ > +static __inline __uint64_t > +__bitcount64(__uint64_t _x) > +{ > + return (__bitcount32(_x >> 32) + __bitcount32(_x)); > +} The __bitcount64() implementation should be based on the word size of=20 the architecture. Usually this is indicated by sizeof long. > + > +#define __bitcountl(x) __bitcount32((unsigned long)(x)) > +#endif /* __SIZEOF_INT__ =3D=3D 8 */ > +#define __bitcount(x) __bitcount32((unsigned int)(x)) > +#endif /* __POPCNT__ */ Selection of __bitcountl() should be based on sizeof long. Selection of=20 __bitcount() should be based on sizeof int. Maybe it makes sense to add=20 a test for this to the RTEMS testsuite and do a check of the=20 pre-processor output on the arm-rtems4.12, sparc64-rtems4.12 and=20 m32c-rtems4.12 targets. --=20 Sebastian Huber, embedded brains GmbH Address : Dornierstr. 4, D-82178 Puchheim, Germany Phone : +49 89 189 47 41-16 Fax : +49 89 189 47 41-09 E-Mail : sebastian.huber@embedded-brains.de PGP : Public key available on request. Diese Nachricht ist keine gesch=E4ftliche Mitteilung im Sinne des EHUG.