1168404Spjd/* 2168404Spjd * CDDL HEADER START 3168404Spjd * 4168404Spjd * The contents of this file are subject to the terms of the 5185029Spjd * Common Development and Distribution License (the "License"). 6185029Spjd * You may not use this file except in compliance with the License. 7168404Spjd * 8168404Spjd * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9168404Spjd * or http://www.opensolaris.org/os/licensing. 10168404Spjd * See the License for the specific language governing permissions 11168404Spjd * and limitations under the License. 12168404Spjd * 13168404Spjd * When distributing Covered Code, include this CDDL HEADER in each 14168404Spjd * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15168404Spjd * If applicable, add the following below this CDDL HEADER, with the 16168404Spjd * fields enclosed by brackets "[]" replaced with your own identifying 17168404Spjd * information: Portions Copyright [yyyy] [name of copyright owner] 18168404Spjd * 19168404Spjd * CDDL HEADER END 20168404Spjd */ 21168404Spjd/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 22168404Spjd/* All Rights Reserved */ 23168404Spjd 24168404Spjd 25168404Spjd/* 26185029Spjd * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 27168404Spjd * Use is subject to license terms. 28168404Spjd */ 29168404Spjd 30168404Spjd#ifndef _SYS_SYSMACROS_H 31168404Spjd#define _SYS_SYSMACROS_H 32168404Spjd 33168404Spjd#include <sys/param.h> 34219089Spjd#include <sys/isa_defs.h> 35284591Savg#if defined(__FreeBSD__) && defined(_KERNEL) 36284591Savg#include <sys/libkern.h> 37284591Savg#endif 38168404Spjd 39168404Spjd#ifdef __cplusplus 40168404Spjdextern "C" { 41168404Spjd#endif 42168404Spjd 43168404Spjd/* 44168404Spjd * Some macros for units conversion 45168404Spjd */ 46168404Spjd/* 47168404Spjd * Disk blocks (sectors) and bytes. 48168404Spjd */ 49168404Spjd#define dtob(DD) ((DD) << DEV_BSHIFT) 50168404Spjd#define btod(BB) (((BB) + DEV_BSIZE - 1) >> DEV_BSHIFT) 51168404Spjd#define btodt(BB) ((BB) >> DEV_BSHIFT) 52168404Spjd#define lbtod(BB) (((offset_t)(BB) + DEV_BSIZE - 1) >> DEV_BSHIFT) 53168404Spjd 54168404Spjd/* common macros */ 55168404Spjd#ifndef MIN 56168404Spjd#define MIN(a, b) ((a) < (b) ? (a) : (b)) 57168404Spjd#endif 58168404Spjd#ifndef MAX 59168404Spjd#define MAX(a, b) ((a) < (b) ? (b) : (a)) 60168404Spjd#endif 61168404Spjd#ifndef ABS 62168404Spjd#define ABS(a) ((a) < 0 ? -(a) : (a)) 63168404Spjd#endif 64219089Spjd#ifndef SIGNOF 65219089Spjd#define SIGNOF(a) ((a) < 0 ? -1 : (a) > 0) 66219089Spjd#endif 67168404Spjd 68168404Spjd#ifdef _KERNEL 69168404Spjd 70168404Spjd/* 71168404Spjd * Convert a single byte to/from binary-coded decimal (BCD). 72168404Spjd */ 73168404Spjdextern unsigned char byte_to_bcd[256]; 74168404Spjdextern unsigned char bcd_to_byte[256]; 75168404Spjd 76168404Spjd#define BYTE_TO_BCD(x) byte_to_bcd[(x) & 0xff] 77168404Spjd#define BCD_TO_BYTE(x) bcd_to_byte[(x) & 0xff] 78168404Spjd 79168404Spjd#endif /* _KERNEL */ 80168404Spjd 81168404Spjd/* 82168404Spjd * WARNING: The device number macros defined here should not be used by device 83168404Spjd * drivers or user software. Device drivers should use the device functions 84168404Spjd * defined in the DDI/DKI interface (see also ddi.h). Application software 85168404Spjd * should make use of the library routines available in makedev(3). A set of 86168404Spjd * new device macros are provided to operate on the expanded device number 87168404Spjd * format supported in SVR4. Macro versions of the DDI device functions are 88168404Spjd * provided for use by kernel proper routines only. Macro routines bmajor(), 89168404Spjd * major(), minor(), emajor(), eminor(), and makedev() will be removed or 90168404Spjd * their definitions changed at the next major release following SVR4. 91168404Spjd */ 92168404Spjd 93168404Spjd#define O_BITSMAJOR 7 /* # of SVR3 major device bits */ 94168404Spjd#define O_BITSMINOR 8 /* # of SVR3 minor device bits */ 95168404Spjd#define O_MAXMAJ 0x7f /* SVR3 max major value */ 96168404Spjd#define O_MAXMIN 0xff /* SVR3 max minor value */ 97168404Spjd 98168404Spjd 99168404Spjd#define L_BITSMAJOR32 14 /* # of SVR4 major device bits */ 100168404Spjd#define L_BITSMINOR32 18 /* # of SVR4 minor device bits */ 101168404Spjd#define L_MAXMAJ32 0x3fff /* SVR4 max major value */ 102168404Spjd#define L_MAXMIN32 0x3ffff /* MAX minor for 3b2 software drivers. */ 103168404Spjd /* For 3b2 hardware devices the minor is */ 104168404Spjd /* restricted to 256 (0-255) */ 105168404Spjd 106168404Spjd#ifdef _LP64 107168404Spjd#define L_BITSMAJOR 32 /* # of major device bits in 64-bit Solaris */ 108168404Spjd#define L_BITSMINOR 32 /* # of minor device bits in 64-bit Solaris */ 109168404Spjd#define L_MAXMAJ 0xfffffffful /* max major value */ 110168404Spjd#define L_MAXMIN 0xfffffffful /* max minor value */ 111168404Spjd#else 112168404Spjd#define L_BITSMAJOR L_BITSMAJOR32 113168404Spjd#define L_BITSMINOR L_BITSMINOR32 114168404Spjd#define L_MAXMAJ L_MAXMAJ32 115168404Spjd#define L_MAXMIN L_MAXMIN32 116168404Spjd#endif 117168404Spjd 118277300Ssmh#ifdef illumos 119168404Spjd#ifdef _KERNEL 120168404Spjd 121168404Spjd/* major part of a device internal to the kernel */ 122168404Spjd 123168404Spjd#define major(x) (major_t)((((unsigned)(x)) >> O_BITSMINOR) & O_MAXMAJ) 124168404Spjd#define bmajor(x) (major_t)((((unsigned)(x)) >> O_BITSMINOR) & O_MAXMAJ) 125168404Spjd 126168404Spjd/* get internal major part of expanded device number */ 127168404Spjd 128168404Spjd#define getmajor(x) (major_t)((((dev_t)(x)) >> L_BITSMINOR) & L_MAXMAJ) 129168404Spjd 130168404Spjd/* minor part of a device internal to the kernel */ 131168404Spjd 132168404Spjd#define minor(x) (minor_t)((x) & O_MAXMIN) 133168404Spjd 134168404Spjd/* get internal minor part of expanded device number */ 135168404Spjd 136168404Spjd#define getminor(x) (minor_t)((x) & L_MAXMIN) 137168404Spjd 138168404Spjd#else 139168404Spjd 140168404Spjd/* major part of a device external from the kernel (same as emajor below) */ 141168404Spjd 142168404Spjd#define major(x) (major_t)((((unsigned)(x)) >> O_BITSMINOR) & O_MAXMAJ) 143168404Spjd 144168404Spjd/* minor part of a device external from the kernel (same as eminor below) */ 145168404Spjd 146168404Spjd#define minor(x) (minor_t)((x) & O_MAXMIN) 147168404Spjd 148168404Spjd#endif /* _KERNEL */ 149168404Spjd 150168404Spjd/* create old device number */ 151168404Spjd 152168404Spjd#define makedev(x, y) (unsigned short)(((x) << O_BITSMINOR) | ((y) & O_MAXMIN)) 153168404Spjd 154168404Spjd/* make an new device number */ 155168404Spjd 156168404Spjd#define makedevice(x, y) (dev_t)(((dev_t)(x) << L_BITSMINOR) | ((y) & L_MAXMIN)) 157168404Spjd 158168404Spjd 159168404Spjd/* 160168404Spjd * emajor() allows kernel/driver code to print external major numbers 161168404Spjd * eminor() allows kernel/driver code to print external minor numbers 162168404Spjd */ 163168404Spjd 164168404Spjd#define emajor(x) \ 165168404Spjd (major_t)(((unsigned int)(x) >> O_BITSMINOR) > O_MAXMAJ) ? \ 166168404Spjd NODEV : (((unsigned int)(x) >> O_BITSMINOR) & O_MAXMAJ) 167168404Spjd 168168404Spjd#define eminor(x) \ 169168404Spjd (minor_t)((x) & O_MAXMIN) 170168404Spjd 171168404Spjd/* 172168404Spjd * get external major and minor device 173168404Spjd * components from expanded device number 174168404Spjd */ 175168404Spjd#define getemajor(x) (major_t)((((dev_t)(x) >> L_BITSMINOR) > L_MAXMAJ) ? \ 176168404Spjd NODEV : (((dev_t)(x) >> L_BITSMINOR) & L_MAXMAJ)) 177168404Spjd#define geteminor(x) (minor_t)((x) & L_MAXMIN) 178277300Ssmh#endif /* illumos */ 179174049Sjb 180168404Spjd/* 181168404Spjd * These are versions of the kernel routines for compressing and 182168404Spjd * expanding long device numbers that don't return errors. 183168404Spjd */ 184168404Spjd#if (L_BITSMAJOR32 == L_BITSMAJOR) && (L_BITSMINOR32 == L_BITSMINOR) 185168404Spjd 186168404Spjd#define DEVCMPL(x) (x) 187168404Spjd#define DEVEXPL(x) (x) 188168404Spjd 189168404Spjd#else 190168404Spjd 191168404Spjd#define DEVCMPL(x) \ 192168404Spjd (dev32_t)((((x) >> L_BITSMINOR) > L_MAXMAJ32 || \ 193168404Spjd ((x) & L_MAXMIN) > L_MAXMIN32) ? NODEV32 : \ 194168404Spjd ((((x) >> L_BITSMINOR) << L_BITSMINOR32) | ((x) & L_MAXMIN32))) 195168404Spjd 196168404Spjd#define DEVEXPL(x) \ 197168404Spjd (((x) == NODEV32) ? NODEV : \ 198168404Spjd makedevice(((x) >> L_BITSMINOR32) & L_MAXMAJ32, (x) & L_MAXMIN32)) 199168404Spjd 200168404Spjd#endif /* L_BITSMAJOR32 ... */ 201168404Spjd 202168404Spjd/* convert to old (SVR3.2) dev format */ 203168404Spjd 204168404Spjd#define cmpdev(x) \ 205168404Spjd (o_dev_t)((((x) >> L_BITSMINOR) > O_MAXMAJ || \ 206168404Spjd ((x) & L_MAXMIN) > O_MAXMIN) ? NODEV : \ 207168404Spjd ((((x) >> L_BITSMINOR) << O_BITSMINOR) | ((x) & O_MAXMIN))) 208168404Spjd 209168404Spjd/* convert to new (SVR4) dev format */ 210168404Spjd 211168404Spjd#define expdev(x) \ 212168404Spjd (dev_t)(((dev_t)(((x) >> O_BITSMINOR) & O_MAXMAJ) << L_BITSMINOR) | \ 213168404Spjd ((x) & O_MAXMIN)) 214168404Spjd 215168404Spjd/* 216168404Spjd * Macro for checking power of 2 address alignment. 217168404Spjd */ 218168404Spjd#define IS_P2ALIGNED(v, a) ((((uintptr_t)(v)) & ((uintptr_t)(a) - 1)) == 0) 219168404Spjd 220168404Spjd/* 221168404Spjd * Macros for counting and rounding. 222168404Spjd */ 223168404Spjd#define howmany(x, y) (((x)+((y)-1))/(y)) 224168404Spjd#define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) 225168404Spjd 226168404Spjd/* 227168404Spjd * Macro to determine if value is a power of 2 228168404Spjd */ 229168404Spjd#define ISP2(x) (((x) & ((x) - 1)) == 0) 230168404Spjd 231168404Spjd/* 232185029Spjd * Macros for various sorts of alignment and rounding. The "align" must 233185029Spjd * be a power of 2. Often times it is a block, sector, or page. 234168404Spjd */ 235185029Spjd 236185029Spjd/* 237185029Spjd * return x rounded down to an align boundary 238185029Spjd * eg, P2ALIGN(1200, 1024) == 1024 (1*align) 239185029Spjd * eg, P2ALIGN(1024, 1024) == 1024 (1*align) 240185029Spjd * eg, P2ALIGN(0x1234, 0x100) == 0x1200 (0x12*align) 241185029Spjd * eg, P2ALIGN(0x5600, 0x100) == 0x5600 (0x56*align) 242185029Spjd */ 243168404Spjd#define P2ALIGN(x, align) ((x) & -(align)) 244185029Spjd 245185029Spjd/* 246185029Spjd * return x % (mod) align 247185029Spjd * eg, P2PHASE(0x1234, 0x100) == 0x34 (x-0x12*align) 248185029Spjd * eg, P2PHASE(0x5600, 0x100) == 0x00 (x-0x56*align) 249185029Spjd */ 250168404Spjd#define P2PHASE(x, align) ((x) & ((align) - 1)) 251185029Spjd 252185029Spjd/* 253185029Spjd * return how much space is left in this block (but if it's perfectly 254185029Spjd * aligned, return 0). 255185029Spjd * eg, P2NPHASE(0x1234, 0x100) == 0xcc (0x13*align-x) 256185029Spjd * eg, P2NPHASE(0x5600, 0x100) == 0x00 (0x56*align-x) 257185029Spjd */ 258168404Spjd#define P2NPHASE(x, align) (-(x) & ((align) - 1)) 259185029Spjd 260185029Spjd/* 261185029Spjd * return x rounded up to an align boundary 262185029Spjd * eg, P2ROUNDUP(0x1234, 0x100) == 0x1300 (0x13*align) 263185029Spjd * eg, P2ROUNDUP(0x5600, 0x100) == 0x5600 (0x56*align) 264185029Spjd */ 265168404Spjd#define P2ROUNDUP(x, align) (-(-(x) & -(align))) 266185029Spjd 267185029Spjd/* 268185029Spjd * return the ending address of the block that x is in 269185029Spjd * eg, P2END(0x1234, 0x100) == 0x12ff (0x13*align - 1) 270185029Spjd * eg, P2END(0x5600, 0x100) == 0x56ff (0x57*align - 1) 271185029Spjd */ 272168404Spjd#define P2END(x, align) (-(~(x) & -(align))) 273185029Spjd 274185029Spjd/* 275185029Spjd * return x rounded up to the next phase (offset) within align. 276185029Spjd * phase should be < align. 277185029Spjd * eg, P2PHASEUP(0x1234, 0x100, 0x10) == 0x1310 (0x13*align + phase) 278185029Spjd * eg, P2PHASEUP(0x5600, 0x100, 0x10) == 0x5610 (0x56*align + phase) 279185029Spjd */ 280168404Spjd#define P2PHASEUP(x, align, phase) ((phase) - (((phase) - (x)) & -(align))) 281185029Spjd 282168404Spjd/* 283185029Spjd * return TRUE if adding len to off would cause it to cross an align 284185029Spjd * boundary. 285185029Spjd * eg, P2BOUNDARY(0x1234, 0xe0, 0x100) == TRUE (0x1234 + 0xe0 == 0x1314) 286185029Spjd * eg, P2BOUNDARY(0x1234, 0x50, 0x100) == FALSE (0x1234 + 0x50 == 0x1284) 287168404Spjd */ 288185029Spjd#define P2BOUNDARY(off, len, align) \ 289185029Spjd (((off) ^ ((off) + (len) - 1)) > (align) - 1) 290185029Spjd 291185029Spjd/* 292185029Spjd * Return TRUE if they have the same highest bit set. 293185029Spjd * eg, P2SAMEHIGHBIT(0x1234, 0x1001) == TRUE (the high bit is 0x1000) 294185029Spjd * eg, P2SAMEHIGHBIT(0x1234, 0x3010) == FALSE (high bit of 0x3010 is 0x2000) 295185029Spjd */ 296168404Spjd#define P2SAMEHIGHBIT(x, y) (((x) ^ (y)) < ((x) & (y))) 297168404Spjd 298168404Spjd/* 299168404Spjd * Typed version of the P2* macros. These macros should be used to ensure 300168404Spjd * that the result is correctly calculated based on the data type of (x), 301168404Spjd * which is passed in as the last argument, regardless of the data 302168404Spjd * type of the alignment. For example, if (x) is of type uint64_t, 303168404Spjd * and we want to round it up to a page boundary using "PAGESIZE" as 304168404Spjd * the alignment, we can do either 305168404Spjd * P2ROUNDUP(x, (uint64_t)PAGESIZE) 306168404Spjd * or 307168404Spjd * P2ROUNDUP_TYPED(x, PAGESIZE, uint64_t) 308168404Spjd */ 309168404Spjd#define P2ALIGN_TYPED(x, align, type) \ 310168404Spjd ((type)(x) & -(type)(align)) 311168404Spjd#define P2PHASE_TYPED(x, align, type) \ 312168404Spjd ((type)(x) & ((type)(align) - 1)) 313168404Spjd#define P2NPHASE_TYPED(x, align, type) \ 314168404Spjd (-(type)(x) & ((type)(align) - 1)) 315168404Spjd#define P2ROUNDUP_TYPED(x, align, type) \ 316168404Spjd (-(-(type)(x) & -(type)(align))) 317168404Spjd#define P2END_TYPED(x, align, type) \ 318168404Spjd (-(~(type)(x) & -(type)(align))) 319168404Spjd#define P2PHASEUP_TYPED(x, align, phase, type) \ 320168404Spjd ((type)(phase) - (((type)(phase) - (type)(x)) & -(type)(align))) 321168404Spjd#define P2CROSS_TYPED(x, y, align, type) \ 322168404Spjd (((type)(x) ^ (type)(y)) > (type)(align) - 1) 323168404Spjd#define P2SAMEHIGHBIT_TYPED(x, y, type) \ 324168404Spjd (((type)(x) ^ (type)(y)) < ((type)(x) & (type)(y))) 325168404Spjd 326168404Spjd/* 327168404Spjd * Macros to atomically increment/decrement a variable. mutex and var 328168404Spjd * must be pointers. 329168404Spjd */ 330168404Spjd#define INCR_COUNT(var, mutex) mutex_enter(mutex), (*(var))++, mutex_exit(mutex) 331168404Spjd#define DECR_COUNT(var, mutex) mutex_enter(mutex), (*(var))--, mutex_exit(mutex) 332168404Spjd 333185029Spjd/* 334185029Spjd * Macros to declare bitfields - the order in the parameter list is 335185029Spjd * Low to High - that is, declare bit 0 first. We only support 8-bit bitfields 336185029Spjd * because if a field crosses a byte boundary it's not likely to be meaningful 337185029Spjd * without reassembly in its nonnative endianness. 338185029Spjd */ 339185029Spjd#if defined(_BIT_FIELDS_LTOH) 340185029Spjd#define DECL_BITFIELD2(_a, _b) \ 341185029Spjd uint8_t _a, _b 342185029Spjd#define DECL_BITFIELD3(_a, _b, _c) \ 343185029Spjd uint8_t _a, _b, _c 344185029Spjd#define DECL_BITFIELD4(_a, _b, _c, _d) \ 345185029Spjd uint8_t _a, _b, _c, _d 346185029Spjd#define DECL_BITFIELD5(_a, _b, _c, _d, _e) \ 347185029Spjd uint8_t _a, _b, _c, _d, _e 348185029Spjd#define DECL_BITFIELD6(_a, _b, _c, _d, _e, _f) \ 349185029Spjd uint8_t _a, _b, _c, _d, _e, _f 350185029Spjd#define DECL_BITFIELD7(_a, _b, _c, _d, _e, _f, _g) \ 351185029Spjd uint8_t _a, _b, _c, _d, _e, _f, _g 352185029Spjd#define DECL_BITFIELD8(_a, _b, _c, _d, _e, _f, _g, _h) \ 353185029Spjd uint8_t _a, _b, _c, _d, _e, _f, _g, _h 354185029Spjd#elif defined(_BIT_FIELDS_HTOL) 355185029Spjd#define DECL_BITFIELD2(_a, _b) \ 356185029Spjd uint8_t _b, _a 357185029Spjd#define DECL_BITFIELD3(_a, _b, _c) \ 358185029Spjd uint8_t _c, _b, _a 359185029Spjd#define DECL_BITFIELD4(_a, _b, _c, _d) \ 360185029Spjd uint8_t _d, _c, _b, _a 361185029Spjd#define DECL_BITFIELD5(_a, _b, _c, _d, _e) \ 362185029Spjd uint8_t _e, _d, _c, _b, _a 363185029Spjd#define DECL_BITFIELD6(_a, _b, _c, _d, _e, _f) \ 364185029Spjd uint8_t _f, _e, _d, _c, _b, _a 365185029Spjd#define DECL_BITFIELD7(_a, _b, _c, _d, _e, _f, _g) \ 366185029Spjd uint8_t _g, _f, _e, _d, _c, _b, _a 367185029Spjd#define DECL_BITFIELD8(_a, _b, _c, _d, _e, _f, _g, _h) \ 368185029Spjd uint8_t _h, _g, _f, _e, _d, _c, _b, _a 369185029Spjd#else 370185029Spjd#error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined 371185029Spjd#endif /* _BIT_FIELDS_LTOH */ 372185029Spjd 373168404Spjd#if defined(_KERNEL) && !defined(_KMEMUSER) && !defined(offsetof) 374168404Spjd 375168404Spjd/* avoid any possibility of clashing with <stddef.h> version */ 376168404Spjd 377168404Spjd#define offsetof(s, m) ((size_t)(&(((s *)0)->m))) 378168404Spjd#endif 379168404Spjd 380219089Spjd/* 381219089Spjd * Find highest one bit set. 382219089Spjd * Returns bit number + 1 of highest bit that is set, otherwise returns 0. 383219089Spjd * High order bit is 31 (or 63 in _LP64 kernel). 384219089Spjd */ 385219089Spjdstatic __inline int 386219089Spjdhighbit(ulong_t i) 387219089Spjd{ 388284591Savg#if defined(__FreeBSD__) && defined(_KERNEL) && defined(HAVE_INLINE_FLSL) 389284591Savg return (flsl(i)); 390284591Savg#else 391327470Sdim int h = 1; 392219089Spjd 393219089Spjd if (i == 0) 394219089Spjd return (0); 395219089Spjd#ifdef _LP64 396219089Spjd if (i & 0xffffffff00000000ul) { 397219089Spjd h += 32; i >>= 32; 398219089Spjd } 399219089Spjd#endif 400219089Spjd if (i & 0xffff0000) { 401219089Spjd h += 16; i >>= 16; 402219089Spjd } 403219089Spjd if (i & 0xff00) { 404219089Spjd h += 8; i >>= 8; 405219089Spjd } 406219089Spjd if (i & 0xf0) { 407219089Spjd h += 4; i >>= 4; 408219089Spjd } 409219089Spjd if (i & 0xc) { 410219089Spjd h += 2; i >>= 2; 411219089Spjd } 412219089Spjd if (i & 0x2) { 413219089Spjd h += 1; 414219089Spjd } 415219089Spjd return (h); 416284591Savg#endif 417219089Spjd} 418219089Spjd 419264669Sdelphij/* 420264669Sdelphij * Find highest one bit set. 421264669Sdelphij * Returns bit number + 1 of highest bit that is set, otherwise returns 0. 422264669Sdelphij */ 423264669Sdelphijstatic __inline int 424264669Sdelphijhighbit64(uint64_t i) 425264669Sdelphij{ 426284591Savg#if defined(__FreeBSD__) && defined(_KERNEL) && defined(HAVE_INLINE_FLSLL) 427284591Savg return (flsll(i)); 428284591Savg#else 429264669Sdelphij int h = 1; 430264669Sdelphij 431264669Sdelphij if (i == 0) 432264669Sdelphij return (0); 433264669Sdelphij if (i & 0xffffffff00000000ULL) { 434264669Sdelphij h += 32; i >>= 32; 435264669Sdelphij } 436264669Sdelphij if (i & 0xffff0000) { 437264669Sdelphij h += 16; i >>= 16; 438264669Sdelphij } 439264669Sdelphij if (i & 0xff00) { 440264669Sdelphij h += 8; i >>= 8; 441264669Sdelphij } 442264669Sdelphij if (i & 0xf0) { 443264669Sdelphij h += 4; i >>= 4; 444264669Sdelphij } 445264669Sdelphij if (i & 0xc) { 446264669Sdelphij h += 2; i >>= 2; 447264669Sdelphij } 448264669Sdelphij if (i & 0x2) { 449264669Sdelphij h += 1; 450264669Sdelphij } 451264669Sdelphij return (h); 452284591Savg#endif 453264669Sdelphij} 454264669Sdelphij 455168404Spjd#ifdef __cplusplus 456168404Spjd} 457168404Spjd#endif 458168404Spjd 459168404Spjd#endif /* _SYS_SYSMACROS_H */ 460