sysmacros.h revision 277300
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>
35168404Spjd
36168404Spjd#ifdef	__cplusplus
37168404Spjdextern "C" {
38168404Spjd#endif
39168404Spjd
40168404Spjd/*
41168404Spjd * Some macros for units conversion
42168404Spjd */
43168404Spjd/*
44168404Spjd * Disk blocks (sectors) and bytes.
45168404Spjd */
46168404Spjd#define	dtob(DD)	((DD) << DEV_BSHIFT)
47168404Spjd#define	btod(BB)	(((BB) + DEV_BSIZE - 1) >> DEV_BSHIFT)
48168404Spjd#define	btodt(BB)	((BB) >> DEV_BSHIFT)
49168404Spjd#define	lbtod(BB)	(((offset_t)(BB) + DEV_BSIZE - 1) >> DEV_BSHIFT)
50168404Spjd
51168404Spjd/* common macros */
52168404Spjd#ifndef MIN
53168404Spjd#define	MIN(a, b)	((a) < (b) ? (a) : (b))
54168404Spjd#endif
55168404Spjd#ifndef MAX
56168404Spjd#define	MAX(a, b)	((a) < (b) ? (b) : (a))
57168404Spjd#endif
58168404Spjd#ifndef ABS
59168404Spjd#define	ABS(a)		((a) < 0 ? -(a) : (a))
60168404Spjd#endif
61219089Spjd#ifndef	SIGNOF
62219089Spjd#define	SIGNOF(a)	((a) < 0 ? -1 : (a) > 0)
63219089Spjd#endif
64168404Spjd
65168404Spjd#ifdef _KERNEL
66168404Spjd
67168404Spjd/*
68168404Spjd * Convert a single byte to/from binary-coded decimal (BCD).
69168404Spjd */
70168404Spjdextern unsigned char byte_to_bcd[256];
71168404Spjdextern unsigned char bcd_to_byte[256];
72168404Spjd
73168404Spjd#define	BYTE_TO_BCD(x)	byte_to_bcd[(x) & 0xff]
74168404Spjd#define	BCD_TO_BYTE(x)	bcd_to_byte[(x) & 0xff]
75168404Spjd
76168404Spjd#endif	/* _KERNEL */
77168404Spjd
78168404Spjd/*
79168404Spjd * WARNING: The device number macros defined here should not be used by device
80168404Spjd * drivers or user software. Device drivers should use the device functions
81168404Spjd * defined in the DDI/DKI interface (see also ddi.h). Application software
82168404Spjd * should make use of the library routines available in makedev(3). A set of
83168404Spjd * new device macros are provided to operate on the expanded device number
84168404Spjd * format supported in SVR4. Macro versions of the DDI device functions are
85168404Spjd * provided for use by kernel proper routines only. Macro routines bmajor(),
86168404Spjd * major(), minor(), emajor(), eminor(), and makedev() will be removed or
87168404Spjd * their definitions changed at the next major release following SVR4.
88168404Spjd */
89168404Spjd
90168404Spjd#define	O_BITSMAJOR	7	/* # of SVR3 major device bits */
91168404Spjd#define	O_BITSMINOR	8	/* # of SVR3 minor device bits */
92168404Spjd#define	O_MAXMAJ	0x7f	/* SVR3 max major value */
93168404Spjd#define	O_MAXMIN	0xff	/* SVR3 max minor value */
94168404Spjd
95168404Spjd
96168404Spjd#define	L_BITSMAJOR32	14	/* # of SVR4 major device bits */
97168404Spjd#define	L_BITSMINOR32	18	/* # of SVR4 minor device bits */
98168404Spjd#define	L_MAXMAJ32	0x3fff	/* SVR4 max major value */
99168404Spjd#define	L_MAXMIN32	0x3ffff	/* MAX minor for 3b2 software drivers. */
100168404Spjd				/* For 3b2 hardware devices the minor is */
101168404Spjd				/* restricted to 256 (0-255) */
102168404Spjd
103168404Spjd#ifdef _LP64
104168404Spjd#define	L_BITSMAJOR	32	/* # of major device bits in 64-bit Solaris */
105168404Spjd#define	L_BITSMINOR	32	/* # of minor device bits in 64-bit Solaris */
106168404Spjd#define	L_MAXMAJ	0xfffffffful	/* max major value */
107168404Spjd#define	L_MAXMIN	0xfffffffful	/* max minor value */
108168404Spjd#else
109168404Spjd#define	L_BITSMAJOR	L_BITSMAJOR32
110168404Spjd#define	L_BITSMINOR	L_BITSMINOR32
111168404Spjd#define	L_MAXMAJ	L_MAXMAJ32
112168404Spjd#define	L_MAXMIN	L_MAXMIN32
113168404Spjd#endif
114168404Spjd
115277300Ssmh#ifdef illumos
116168404Spjd#ifdef _KERNEL
117168404Spjd
118168404Spjd/* major part of a device internal to the kernel */
119168404Spjd
120168404Spjd#define	major(x)	(major_t)((((unsigned)(x)) >> O_BITSMINOR) & O_MAXMAJ)
121168404Spjd#define	bmajor(x)	(major_t)((((unsigned)(x)) >> O_BITSMINOR) & O_MAXMAJ)
122168404Spjd
123168404Spjd/* get internal major part of expanded device number */
124168404Spjd
125168404Spjd#define	getmajor(x)	(major_t)((((dev_t)(x)) >> L_BITSMINOR) & L_MAXMAJ)
126168404Spjd
127168404Spjd/* minor part of a device internal to the kernel */
128168404Spjd
129168404Spjd#define	minor(x)	(minor_t)((x) & O_MAXMIN)
130168404Spjd
131168404Spjd/* get internal minor part of expanded device number */
132168404Spjd
133168404Spjd#define	getminor(x)	(minor_t)((x) & L_MAXMIN)
134168404Spjd
135168404Spjd#else
136168404Spjd
137168404Spjd/* major part of a device external from the kernel (same as emajor below) */
138168404Spjd
139168404Spjd#define	major(x)	(major_t)((((unsigned)(x)) >> O_BITSMINOR) & O_MAXMAJ)
140168404Spjd
141168404Spjd/* minor part of a device external from the kernel  (same as eminor below) */
142168404Spjd
143168404Spjd#define	minor(x)	(minor_t)((x) & O_MAXMIN)
144168404Spjd
145168404Spjd#endif	/* _KERNEL */
146168404Spjd
147168404Spjd/* create old device number */
148168404Spjd
149168404Spjd#define	makedev(x, y) (unsigned short)(((x) << O_BITSMINOR) | ((y) & O_MAXMIN))
150168404Spjd
151168404Spjd/* make an new device number */
152168404Spjd
153168404Spjd#define	makedevice(x, y) (dev_t)(((dev_t)(x) << L_BITSMINOR) | ((y) & L_MAXMIN))
154168404Spjd
155168404Spjd
156168404Spjd/*
157168404Spjd * emajor() allows kernel/driver code to print external major numbers
158168404Spjd * eminor() allows kernel/driver code to print external minor numbers
159168404Spjd */
160168404Spjd
161168404Spjd#define	emajor(x) \
162168404Spjd	(major_t)(((unsigned int)(x) >> O_BITSMINOR) > O_MAXMAJ) ? \
163168404Spjd	    NODEV : (((unsigned int)(x) >> O_BITSMINOR) & O_MAXMAJ)
164168404Spjd
165168404Spjd#define	eminor(x) \
166168404Spjd	(minor_t)((x) & O_MAXMIN)
167168404Spjd
168168404Spjd/*
169168404Spjd * get external major and minor device
170168404Spjd * components from expanded device number
171168404Spjd */
172168404Spjd#define	getemajor(x)	(major_t)((((dev_t)(x) >> L_BITSMINOR) > L_MAXMAJ) ? \
173168404Spjd			    NODEV : (((dev_t)(x) >> L_BITSMINOR) & L_MAXMAJ))
174168404Spjd#define	geteminor(x)	(minor_t)((x) & L_MAXMIN)
175277300Ssmh#endif /* illumos */
176174049Sjb
177168404Spjd/*
178168404Spjd * These are versions of the kernel routines for compressing and
179168404Spjd * expanding long device numbers that don't return errors.
180168404Spjd */
181168404Spjd#if (L_BITSMAJOR32 == L_BITSMAJOR) && (L_BITSMINOR32 == L_BITSMINOR)
182168404Spjd
183168404Spjd#define	DEVCMPL(x)	(x)
184168404Spjd#define	DEVEXPL(x)	(x)
185168404Spjd
186168404Spjd#else
187168404Spjd
188168404Spjd#define	DEVCMPL(x)	\
189168404Spjd	(dev32_t)((((x) >> L_BITSMINOR) > L_MAXMAJ32 || \
190168404Spjd	    ((x) & L_MAXMIN) > L_MAXMIN32) ? NODEV32 : \
191168404Spjd	    ((((x) >> L_BITSMINOR) << L_BITSMINOR32) | ((x) & L_MAXMIN32)))
192168404Spjd
193168404Spjd#define	DEVEXPL(x)	\
194168404Spjd	(((x) == NODEV32) ? NODEV : \
195168404Spjd	makedevice(((x) >> L_BITSMINOR32) & L_MAXMAJ32, (x) & L_MAXMIN32))
196168404Spjd
197168404Spjd#endif /* L_BITSMAJOR32 ... */
198168404Spjd
199168404Spjd/* convert to old (SVR3.2) dev format */
200168404Spjd
201168404Spjd#define	cmpdev(x) \
202168404Spjd	(o_dev_t)((((x) >> L_BITSMINOR) > O_MAXMAJ || \
203168404Spjd	    ((x) & L_MAXMIN) > O_MAXMIN) ? NODEV : \
204168404Spjd	    ((((x) >> L_BITSMINOR) << O_BITSMINOR) | ((x) & O_MAXMIN)))
205168404Spjd
206168404Spjd/* convert to new (SVR4) dev format */
207168404Spjd
208168404Spjd#define	expdev(x) \
209168404Spjd	(dev_t)(((dev_t)(((x) >> O_BITSMINOR) & O_MAXMAJ) << L_BITSMINOR) | \
210168404Spjd	    ((x) & O_MAXMIN))
211168404Spjd
212168404Spjd/*
213168404Spjd * Macro for checking power of 2 address alignment.
214168404Spjd */
215168404Spjd#define	IS_P2ALIGNED(v, a) ((((uintptr_t)(v)) & ((uintptr_t)(a) - 1)) == 0)
216168404Spjd
217168404Spjd/*
218168404Spjd * Macros for counting and rounding.
219168404Spjd */
220168404Spjd#define	howmany(x, y)	(((x)+((y)-1))/(y))
221168404Spjd#define	roundup(x, y)	((((x)+((y)-1))/(y))*(y))
222168404Spjd
223168404Spjd/*
224168404Spjd * Macro to determine if value is a power of 2
225168404Spjd */
226168404Spjd#define	ISP2(x)		(((x) & ((x) - 1)) == 0)
227168404Spjd
228168404Spjd/*
229185029Spjd * Macros for various sorts of alignment and rounding.  The "align" must
230185029Spjd * be a power of 2.  Often times it is a block, sector, or page.
231168404Spjd */
232185029Spjd
233185029Spjd/*
234185029Spjd * return x rounded down to an align boundary
235185029Spjd * eg, P2ALIGN(1200, 1024) == 1024 (1*align)
236185029Spjd * eg, P2ALIGN(1024, 1024) == 1024 (1*align)
237185029Spjd * eg, P2ALIGN(0x1234, 0x100) == 0x1200 (0x12*align)
238185029Spjd * eg, P2ALIGN(0x5600, 0x100) == 0x5600 (0x56*align)
239185029Spjd */
240168404Spjd#define	P2ALIGN(x, align)		((x) & -(align))
241185029Spjd
242185029Spjd/*
243185029Spjd * return x % (mod) align
244185029Spjd * eg, P2PHASE(0x1234, 0x100) == 0x34 (x-0x12*align)
245185029Spjd * eg, P2PHASE(0x5600, 0x100) == 0x00 (x-0x56*align)
246185029Spjd */
247168404Spjd#define	P2PHASE(x, align)		((x) & ((align) - 1))
248185029Spjd
249185029Spjd/*
250185029Spjd * return how much space is left in this block (but if it's perfectly
251185029Spjd * aligned, return 0).
252185029Spjd * eg, P2NPHASE(0x1234, 0x100) == 0xcc (0x13*align-x)
253185029Spjd * eg, P2NPHASE(0x5600, 0x100) == 0x00 (0x56*align-x)
254185029Spjd */
255168404Spjd#define	P2NPHASE(x, align)		(-(x) & ((align) - 1))
256185029Spjd
257185029Spjd/*
258185029Spjd * return x rounded up to an align boundary
259185029Spjd * eg, P2ROUNDUP(0x1234, 0x100) == 0x1300 (0x13*align)
260185029Spjd * eg, P2ROUNDUP(0x5600, 0x100) == 0x5600 (0x56*align)
261185029Spjd */
262168404Spjd#define	P2ROUNDUP(x, align)		(-(-(x) & -(align)))
263185029Spjd
264185029Spjd/*
265185029Spjd * return the ending address of the block that x is in
266185029Spjd * eg, P2END(0x1234, 0x100) == 0x12ff (0x13*align - 1)
267185029Spjd * eg, P2END(0x5600, 0x100) == 0x56ff (0x57*align - 1)
268185029Spjd */
269168404Spjd#define	P2END(x, align)			(-(~(x) & -(align)))
270185029Spjd
271185029Spjd/*
272185029Spjd * return x rounded up to the next phase (offset) within align.
273185029Spjd * phase should be < align.
274185029Spjd * eg, P2PHASEUP(0x1234, 0x100, 0x10) == 0x1310 (0x13*align + phase)
275185029Spjd * eg, P2PHASEUP(0x5600, 0x100, 0x10) == 0x5610 (0x56*align + phase)
276185029Spjd */
277168404Spjd#define	P2PHASEUP(x, align, phase)	((phase) - (((phase) - (x)) & -(align)))
278185029Spjd
279168404Spjd/*
280185029Spjd * return TRUE if adding len to off would cause it to cross an align
281185029Spjd * boundary.
282185029Spjd * eg, P2BOUNDARY(0x1234, 0xe0, 0x100) == TRUE (0x1234 + 0xe0 == 0x1314)
283185029Spjd * eg, P2BOUNDARY(0x1234, 0x50, 0x100) == FALSE (0x1234 + 0x50 == 0x1284)
284168404Spjd */
285185029Spjd#define	P2BOUNDARY(off, len, align) \
286185029Spjd	(((off) ^ ((off) + (len) - 1)) > (align) - 1)
287185029Spjd
288185029Spjd/*
289185029Spjd * Return TRUE if they have the same highest bit set.
290185029Spjd * eg, P2SAMEHIGHBIT(0x1234, 0x1001) == TRUE (the high bit is 0x1000)
291185029Spjd * eg, P2SAMEHIGHBIT(0x1234, 0x3010) == FALSE (high bit of 0x3010 is 0x2000)
292185029Spjd */
293168404Spjd#define	P2SAMEHIGHBIT(x, y)		(((x) ^ (y)) < ((x) & (y)))
294168404Spjd
295168404Spjd/*
296168404Spjd * Typed version of the P2* macros.  These macros should be used to ensure
297168404Spjd * that the result is correctly calculated based on the data type of (x),
298168404Spjd * which is passed in as the last argument, regardless of the data
299168404Spjd * type of the alignment.  For example, if (x) is of type uint64_t,
300168404Spjd * and we want to round it up to a page boundary using "PAGESIZE" as
301168404Spjd * the alignment, we can do either
302168404Spjd *	P2ROUNDUP(x, (uint64_t)PAGESIZE)
303168404Spjd * or
304168404Spjd *	P2ROUNDUP_TYPED(x, PAGESIZE, uint64_t)
305168404Spjd */
306168404Spjd#define	P2ALIGN_TYPED(x, align, type)	\
307168404Spjd	((type)(x) & -(type)(align))
308168404Spjd#define	P2PHASE_TYPED(x, align, type)	\
309168404Spjd	((type)(x) & ((type)(align) - 1))
310168404Spjd#define	P2NPHASE_TYPED(x, align, type)	\
311168404Spjd	(-(type)(x) & ((type)(align) - 1))
312168404Spjd#define	P2ROUNDUP_TYPED(x, align, type)	\
313168404Spjd	(-(-(type)(x) & -(type)(align)))
314168404Spjd#define	P2END_TYPED(x, align, type)	\
315168404Spjd	(-(~(type)(x) & -(type)(align)))
316168404Spjd#define	P2PHASEUP_TYPED(x, align, phase, type)	\
317168404Spjd	((type)(phase) - (((type)(phase) - (type)(x)) & -(type)(align)))
318168404Spjd#define	P2CROSS_TYPED(x, y, align, type)	\
319168404Spjd	(((type)(x) ^ (type)(y)) > (type)(align) - 1)
320168404Spjd#define	P2SAMEHIGHBIT_TYPED(x, y, type) \
321168404Spjd	(((type)(x) ^ (type)(y)) < ((type)(x) & (type)(y)))
322168404Spjd
323168404Spjd/*
324168404Spjd * Macros to atomically increment/decrement a variable.  mutex and var
325168404Spjd * must be pointers.
326168404Spjd */
327168404Spjd#define	INCR_COUNT(var, mutex) mutex_enter(mutex), (*(var))++, mutex_exit(mutex)
328168404Spjd#define	DECR_COUNT(var, mutex) mutex_enter(mutex), (*(var))--, mutex_exit(mutex)
329168404Spjd
330185029Spjd/*
331185029Spjd * Macros to declare bitfields - the order in the parameter list is
332185029Spjd * Low to High - that is, declare bit 0 first.  We only support 8-bit bitfields
333185029Spjd * because if a field crosses a byte boundary it's not likely to be meaningful
334185029Spjd * without reassembly in its nonnative endianness.
335185029Spjd */
336185029Spjd#if defined(_BIT_FIELDS_LTOH)
337185029Spjd#define	DECL_BITFIELD2(_a, _b)				\
338185029Spjd	uint8_t _a, _b
339185029Spjd#define	DECL_BITFIELD3(_a, _b, _c)			\
340185029Spjd	uint8_t _a, _b, _c
341185029Spjd#define	DECL_BITFIELD4(_a, _b, _c, _d)			\
342185029Spjd	uint8_t _a, _b, _c, _d
343185029Spjd#define	DECL_BITFIELD5(_a, _b, _c, _d, _e)		\
344185029Spjd	uint8_t _a, _b, _c, _d, _e
345185029Spjd#define	DECL_BITFIELD6(_a, _b, _c, _d, _e, _f)		\
346185029Spjd	uint8_t _a, _b, _c, _d, _e, _f
347185029Spjd#define	DECL_BITFIELD7(_a, _b, _c, _d, _e, _f, _g)	\
348185029Spjd	uint8_t _a, _b, _c, _d, _e, _f, _g
349185029Spjd#define	DECL_BITFIELD8(_a, _b, _c, _d, _e, _f, _g, _h)	\
350185029Spjd	uint8_t _a, _b, _c, _d, _e, _f, _g, _h
351185029Spjd#elif defined(_BIT_FIELDS_HTOL)
352185029Spjd#define	DECL_BITFIELD2(_a, _b)				\
353185029Spjd	uint8_t _b, _a
354185029Spjd#define	DECL_BITFIELD3(_a, _b, _c)			\
355185029Spjd	uint8_t _c, _b, _a
356185029Spjd#define	DECL_BITFIELD4(_a, _b, _c, _d)			\
357185029Spjd	uint8_t _d, _c, _b, _a
358185029Spjd#define	DECL_BITFIELD5(_a, _b, _c, _d, _e)		\
359185029Spjd	uint8_t _e, _d, _c, _b, _a
360185029Spjd#define	DECL_BITFIELD6(_a, _b, _c, _d, _e, _f)		\
361185029Spjd	uint8_t _f, _e, _d, _c, _b, _a
362185029Spjd#define	DECL_BITFIELD7(_a, _b, _c, _d, _e, _f, _g)	\
363185029Spjd	uint8_t _g, _f, _e, _d, _c, _b, _a
364185029Spjd#define	DECL_BITFIELD8(_a, _b, _c, _d, _e, _f, _g, _h)	\
365185029Spjd	uint8_t _h, _g, _f, _e, _d, _c, _b, _a
366185029Spjd#else
367185029Spjd#error	One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
368185029Spjd#endif  /* _BIT_FIELDS_LTOH */
369185029Spjd
370168404Spjd#if defined(_KERNEL) && !defined(_KMEMUSER) && !defined(offsetof)
371168404Spjd
372168404Spjd/* avoid any possibility of clashing with <stddef.h> version */
373168404Spjd
374168404Spjd#define	offsetof(s, m)	((size_t)(&(((s *)0)->m)))
375168404Spjd#endif
376168404Spjd
377219089Spjd/*
378219089Spjd * Find highest one bit set.
379219089Spjd *      Returns bit number + 1 of highest bit that is set, otherwise returns 0.
380219089Spjd * High order bit is 31 (or 63 in _LP64 kernel).
381219089Spjd */
382219089Spjdstatic __inline int
383219089Spjdhighbit(ulong_t i)
384219089Spjd{
385219089Spjd	register int h = 1;
386219089Spjd
387219089Spjd	if (i == 0)
388219089Spjd		return (0);
389219089Spjd#ifdef _LP64
390219089Spjd	if (i & 0xffffffff00000000ul) {
391219089Spjd		h += 32; i >>= 32;
392219089Spjd	}
393219089Spjd#endif
394219089Spjd	if (i & 0xffff0000) {
395219089Spjd		h += 16; i >>= 16;
396219089Spjd	}
397219089Spjd	if (i & 0xff00) {
398219089Spjd		h += 8; i >>= 8;
399219089Spjd	}
400219089Spjd	if (i & 0xf0) {
401219089Spjd		h += 4; i >>= 4;
402219089Spjd	}
403219089Spjd	if (i & 0xc) {
404219089Spjd		h += 2; i >>= 2;
405219089Spjd	}
406219089Spjd	if (i & 0x2) {
407219089Spjd		h += 1;
408219089Spjd	}
409219089Spjd	return (h);
410219089Spjd}
411219089Spjd
412264669Sdelphij/*
413264669Sdelphij * Find highest one bit set.
414264669Sdelphij *	Returns bit number + 1 of highest bit that is set, otherwise returns 0.
415264669Sdelphij */
416264669Sdelphijstatic __inline int
417264669Sdelphijhighbit64(uint64_t i)
418264669Sdelphij{
419264669Sdelphij	int h = 1;
420264669Sdelphij
421264669Sdelphij	if (i == 0)
422264669Sdelphij		return (0);
423264669Sdelphij	if (i & 0xffffffff00000000ULL) {
424264669Sdelphij		h += 32; i >>= 32;
425264669Sdelphij	}
426264669Sdelphij	if (i & 0xffff0000) {
427264669Sdelphij		h += 16; i >>= 16;
428264669Sdelphij	}
429264669Sdelphij	if (i & 0xff00) {
430264669Sdelphij		h += 8; i >>= 8;
431264669Sdelphij	}
432264669Sdelphij	if (i & 0xf0) {
433264669Sdelphij		h += 4; i >>= 4;
434264669Sdelphij	}
435264669Sdelphij	if (i & 0xc) {
436264669Sdelphij		h += 2; i >>= 2;
437264669Sdelphij	}
438264669Sdelphij	if (i & 0x2) {
439264669Sdelphij		h += 1;
440264669Sdelphij	}
441264669Sdelphij	return (h);
442264669Sdelphij}
443264669Sdelphij
444168404Spjd#ifdef	__cplusplus
445168404Spjd}
446168404Spjd#endif
447168404Spjd
448168404Spjd#endif	/* _SYS_SYSMACROS_H */
449