xref: /titanic_41/usr/src/cmd/audio/include/archdep.h (revision 35a5a3587fd94b666239c157d3722745250ccbd7)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 1992-2001 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #ifndef _MULTIMEDIA_ARCHDEP_H
28 #define	_MULTIMEDIA_ARCHDEP_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 /*
37  * Machine-dependent and implementation-dependent definitions
38  * are placed here so that source code can be portable among a wide
39  * variety of machines.
40  */
41 
42 /*
43  * The following macros are used to generate architecture-specific
44  * code for handling byte-ordering correctly.
45  *
46  * Note that these macros *do not* work for in-place transformations.
47  */
48 
49 #if defined(mc68000) || defined(sparc)
50 #define	DECODE_SHORT(from, to)	*((short *)(to)) = *((short *)(from))
51 #define	DECODE_LONG(from, to)	*((long *)(to)) = *((long *)(from))
52 #define	DECODE_FLOAT(from, to)	*((float *)(to)) = *((float *)(from))
53 #define	DECODE_DOUBLE(from, to)	*((double *)(to)) = *((double *)(from))
54 #endif /* big-endian */
55 
56 #if defined(i386) || defined(__ppc)
57 #define	DECODE_SHORT(from, to)						\
58 			    ((char *)(to))[0] = ((char *)(from))[1];	\
59 			    ((char *)(to))[1] = ((char *)(from))[0];
60 #define	DECODE_LONG(from, to)						\
61 			    ((char *)(to))[0] = ((char *)(from))[3];	\
62 			    ((char *)(to))[1] = ((char *)(from))[2];	\
63 			    ((char *)(to))[2] = ((char *)(from))[1];	\
64 			    ((char *)(to))[3] = ((char *)(from))[0];
65 
66 #define	DECODE_FLOAT(from, to)		DECODE_LONG((to), (from))
67 
68 #define	DECODE_DOUBLE(from, to)						\
69 			    ((char *)(to))[0] = ((char *)(from))[7];	\
70 			    ((char *)(to))[1] = ((char *)(from))[6];	\
71 			    ((char *)(to))[2] = ((char *)(from))[5];	\
72 			    ((char *)(to))[3] = ((char *)(from))[4];	\
73 			    ((char *)(to))[4] = ((char *)(from))[3];	\
74 			    ((char *)(to))[5] = ((char *)(from))[2];	\
75 			    ((char *)(to))[6] = ((char *)(from))[1];	\
76 			    ((char *)(to))[7] = ((char *)(from))[0];
77 #endif /* little-endian */
78 
79 
80 /* Most architectures are symmetrical with respect to conversions. */
81 #if defined(mc68000) || defined(sparc) || defined(i386) || defined(__ppc)
82 #define	ENCODE_SHORT(from, to)		DECODE_SHORT((from), (to))
83 #define	ENCODE_LONG(from, to)		DECODE_LONG((from), (to))
84 #define	ENCODE_FLOAT(from, to)		DECODE_FLOAT((from), (to))
85 #define	ENCODE_DOUBLE(from, to)		DECODE_DOUBLE((from), (to))
86 
87 /* Define types of specific length */
88 typedef char		i_8;
89 typedef short		i_16;
90 typedef int		i_32;
91 typedef unsigned char	u_8;
92 typedef unsigned short 	u_16;
93 typedef unsigned	u_32;
94 
95 #endif /* Sun machines */
96 
97 #ifdef __cplusplus
98 }
99 #endif
100 
101 #endif /* !_MULTIMEDIA_ARCHDEP_H */
102