1/* 2 * Copyright 2007 Haiku Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5#ifndef _FBSD_COMPAT_SYS_TYPES_H_ 6#define _FBSD_COMPAT_SYS_TYPES_H_ 7 8 9#include <posix/stdint.h> 10#include <posix/sys/types.h> 11 12#include <sys/cdefs.h> 13 14#include <machine/endian.h> 15#include <sys/_types.h> 16 17 18typedef int boolean_t; 19typedef __const char* c_caddr_t; 20typedef uint64_t u_quad_t; 21 22 23#ifdef __POPCNT__ 24#define __bitcount64(x) __builtin_popcountll((u_int64_t)(x)) 25#define __bitcount32(x) __builtin_popcount((u_int32_t)(x)) 26#define __bitcount16(x) __builtin_popcount((u_int16_t)(x)) 27#define __bitcountl(x) __builtin_popcountl((unsigned long)(x)) 28#define __bitcount(x) __builtin_popcount((unsigned int)(x)) 29#else 30/* 31 * Population count algorithm using SWAR approach 32 * - "SIMD Within A Register". 33 */ 34static __inline u_int16_t 35__bitcount16(u_int16_t _x) 36{ 37 38 _x = (_x & 0x5555) + ((_x & 0xaaaa) >> 1); 39 _x = (_x & 0x3333) + ((_x & 0xcccc) >> 2); 40 _x = (_x + (_x >> 4)) & 0x0f0f; 41 _x = (_x + (_x >> 8)) & 0x00ff; 42 return (_x); 43} 44 45static __inline u_int32_t 46__bitcount32(u_int32_t _x) 47{ 48 49 _x = (_x & 0x55555555) + ((_x & 0xaaaaaaaa) >> 1); 50 _x = (_x & 0x33333333) + ((_x & 0xcccccccc) >> 2); 51 _x = (_x + (_x >> 4)) & 0x0f0f0f0f; 52 _x = (_x + (_x >> 8)); 53 _x = (_x + (_x >> 16)) & 0x000000ff; 54 return (_x); 55} 56 57#ifdef __LP64__ 58static __inline u_int64_t 59__bitcount64(u_int64_t _x) 60{ 61 62 _x = (_x & 0x5555555555555555) + ((_x & 0xaaaaaaaaaaaaaaaa) >> 1); 63 _x = (_x & 0x3333333333333333) + ((_x & 0xcccccccccccccccc) >> 2); 64 _x = (_x + (_x >> 4)) & 0x0f0f0f0f0f0f0f0f; 65 _x = (_x + (_x >> 8)); 66 _x = (_x + (_x >> 16)); 67 _x = (_x + (_x >> 32)) & 0x000000ff; 68 return (_x); 69} 70 71#define __bitcountl(x) __bitcount64((unsigned long)(x)) 72#else 73static __inline u_int64_t 74__bitcount64(u_int64_t _x) 75{ 76 77 return (__bitcount32(_x >> 32) + __bitcount32(_x)); 78} 79 80#define __bitcountl(x) __bitcount32((unsigned long)(x)) 81#endif 82#define __bitcount(x) __bitcount32((unsigned int)(x)) 83#endif 84 85 86#endif 87