summaryrefslogtreecommitdiff
path: root/usr/src/uts/sun/sys/pr_impl_util.h
blob: 95609772dfbe6f819d735659b84a650d35fa16a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

/*
 * Pixrect implementation utilities
 */

#ifndef _SYS_PR_IMPL_UTIL_H
#define	_SYS_PR_IMPL_UTIL_H

#pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SunOS 1.10 */

#ifdef	__cplusplus
extern "C" {
#endif

/* Reiser cpp concatenation macros (which don't work in ANSI-C) */
#if	defined(__STDC__) && !defined(__LIBCPP__)

#ifndef _CAT
#define	_CAT(a, b)	a##b
#endif

#else	/* __STDC__ */

#ifndef _CAT
#undef	_IDENT
#define	_IDENT(x)	x
#define	_CAT(a, b)	_IDENT(a)b
#endif

#endif	/* __STDC__ */

/* code selection macros */
#define	IFTRUE(a, b) a
#define	IFFALSE(a, b) b

/* and together multiple options */
#define	IFAND IFAND2
#define	IFAND2(opt1, opt2, a, b) opt1(opt2(a, b), b)
#define	IFAND3(opt1, opt2, opt3, a, b) opt1(opt2(opt3(a, b), b), b)
#define	IFAND4(opt1, opt2, opt3, opt4, a, b) \
		opt1(opt2(opt3(opt4(a, b), b), b), b)
#define	IFAND5(opt1, opt2, opt3, opt4, opt5, a, b) \
		opt1(opt2(opt3(opt4(opt5(a, b), b), b), b), b)
#define	IFAND6(opt1, opt2, opt3, opt4, opt5, opt6, a, b) \
		opt1(opt2(opt3(opt4(opt5(opt6(a, b), b), b), b), b), b)

#ifdef _KERNEL
#define	IFKERNEL IFTRUE
#else
#define	IFKERNEL IFFALSE
#endif

/* lint */
#ifdef __lint

#define	IFLINT	IFTRUE

int _ZERO_;	/* "constant in conditional context" workaround */
#define	_ONE_	(!_ZERO_)
int _loop;	/* "_loop redefinition hides earlier one" */

#else	/* __lint */

#define	IFLINT	IFFALSE

#define	_ZERO_ 0
#define	_ONE_ 1

#endif	/* __lint */

/* portability aids */
#ifdef mc68000

#define	IF68000 IFTRUE

typedef caddr_t INT_T;		/* pseudo-integer type (address register) */
typedef ulong_t	PTR_T;		/* pseudo-pointer type (data register) */
typedef short	LOOP_T;		/* loop variable (for dbra loops) */

#define	LOOP_DECR(var)	(--(var) != -1)

#else	/* mc68000 */

#define	IF68000 IFFALSE

typedef int	INT_T;
typedef caddr_t PTR_T;
typedef int	LOOP_T;

#define	LOOP_DECR(var)	(--(var) >= 0)

#endif	/* mc68000 */

#if defined(__sparc)
#define	IFSPARC IFTRUE
#else
#define	IFSPARC IFFALSE
#endif

/* true if we can make 32 bit accesses on 16 bit boundaries */
#ifndef SHORT_ALIGN
#define	SHORT_ALIGN	(!defined(__sparc))
#endif

#if SHORT_ALIGN
#define	IFSHORT_ALIGN	IFTRUE
#else
#define	IFSHORT_ALIGN	IFFALSE
#endif


#ifndef LITTLE_ENDIAN
#define	LITTLE_ENDIAN	(defined(__i386) || defined(__amd64))
#endif

#if LITTLE_ENDIAN
#define	ENDIAN	IFTRUE
#else
#define	ENDIAN	IFFALSE
#endif

/*
 * SunOS release number
 * warning: these tests are fragile
 */
#if defined(__sun) && !defined(SUNOS)
#ifdef _sys_types_h
#define	SUNOS	41
#else	/* _sys_types_h */
#ifdef NFDBITS
#define	SUNOS	40
#else	/* NFDBITS */
#define	SUNOS	35
#endif	/* NFDBITS */
#endif	/* _sys_types_h */
#endif

#if SUNOS >= 40
#define	IFSUNOS4	IFTRUE
#else
#define	IFSUNOS4	IFFALSE
#endif

#if SUNOS >= 41
#define	IFSUNOS41	IFTRUE
#else
#define	IFSUNOS41	IFFALSE
#endif


/*
 * misc. macros
 */

/* statement macro */
#define	_STMT(op)	do { op } while (_ZERO_)

/* loop macros */
#define	PR_LOOPVP(var, op)	do { op; } while (LOOP_DECR(var))
#define	PR_LOOPV(var, op)	_STMT(while (LOOP_DECR(var)) { op; })
#define	PR_LOOPP(count, op)	_STMT(\
	IFLINT(, register LOOP_T) _loop = (count); PR_LOOPVP(_loop, op); \
)
#define	PR_LOOP(count, op)	_STMT(\
	IFLINT(, register LOOP_T) _loop = (count); PR_LOOPV(_loop, op); \
)

/* pointer manipulation */
#define	PTR_ADD(p, incr)	((caddr_t)(p) + (incr))
#define	PTR_INCR(type, p, incr) (p = (type) ((caddr_t)(p) + (incr)))

/* unshifted pixrect op codes */
#define	PIX_OPSRC	(12)
#define	PIX_OPDST	(10)
#define	PIX_OPNOT(op)	((op) ^ 15)
#define	PIX_OPCLR	(0)
#define	PIX_OPSET	(15)

/* extract color and op code fields */
#define	PIXOP_COLOR(op) ((op) >> 5)
#define	PIXOP_OP(op)	((op) >> 1 & 15)

/* reverse video src or dst */
#define	PIX_OP_REVERSESRC(op)	(((op) & 3) << 2 | (op) >> 2 & 3)
#define	PIX_OP_REVERSEDST(op)	((~(op) & 5) << 1 | ~(op) >> 1 & 0x5)

/* determine if op needs src or dst */
#define	PIX_OP_NEEDS_SRC(op)	(((op) >> 2 ^ (op)) & 3)
#define	PIX_OP_NEEDS_DST(op)	(((op) >> 1 ^ (op)) & 5)

/* misc. data types */
typedef short	MPR_T;		/* type used for memory pixrect data */
typedef ushort_t UMPR_T;	/* unsigned equivalent of MPR_T */

#ifdef	__cplusplus
}
#endif

#endif	/* _SYS_PR_IMPL_UTIL_H */