xref: /illumos-gate/usr/src/cmd/audio/include/archdep.h (revision 3b363e384673bd88fc57814d909651859c7c41a3)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Copyright (c) 1992-2001 by Sun Microsystems, Inc.
247c478bd9Sstevel@tonic-gate  * All rights reserved.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef _MULTIMEDIA_ARCHDEP_H
287c478bd9Sstevel@tonic-gate #define	_MULTIMEDIA_ARCHDEP_H
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #ifdef __cplusplus
317c478bd9Sstevel@tonic-gate extern "C" {
327c478bd9Sstevel@tonic-gate #endif
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate /*
357c478bd9Sstevel@tonic-gate  * Machine-dependent and implementation-dependent definitions
367c478bd9Sstevel@tonic-gate  * are placed here so that source code can be portable among a wide
377c478bd9Sstevel@tonic-gate  * variety of machines.
387c478bd9Sstevel@tonic-gate  */
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate /*
417c478bd9Sstevel@tonic-gate  * The following macros are used to generate architecture-specific
427c478bd9Sstevel@tonic-gate  * code for handling byte-ordering correctly.
437c478bd9Sstevel@tonic-gate  *
447c478bd9Sstevel@tonic-gate  * Note that these macros *do not* work for in-place transformations.
457c478bd9Sstevel@tonic-gate  */
467c478bd9Sstevel@tonic-gate 
47*3b363e38SRichard Lowe #if defined(_BIG_ENDIAN)
487c478bd9Sstevel@tonic-gate #define	DECODE_SHORT(from, to)	*((short *)(to)) = *((short *)(from))
497c478bd9Sstevel@tonic-gate #define	DECODE_LONG(from, to)	*((long *)(to)) = *((long *)(from))
507c478bd9Sstevel@tonic-gate #define	DECODE_FLOAT(from, to)	*((float *)(to)) = *((float *)(from))
517c478bd9Sstevel@tonic-gate #define	DECODE_DOUBLE(from, to)	*((double *)(to)) = *((double *)(from))
52*3b363e38SRichard Lowe #elif defined(_LITTLE_ENDIAN)
537c478bd9Sstevel@tonic-gate #define	DECODE_SHORT(from, to)						\
547c478bd9Sstevel@tonic-gate 			    ((char *)(to))[0] = ((char *)(from))[1];	\
557c478bd9Sstevel@tonic-gate 			    ((char *)(to))[1] = ((char *)(from))[0];
567c478bd9Sstevel@tonic-gate #define	DECODE_LONG(from, to)						\
577c478bd9Sstevel@tonic-gate 			    ((char *)(to))[0] = ((char *)(from))[3];	\
587c478bd9Sstevel@tonic-gate 			    ((char *)(to))[1] = ((char *)(from))[2];	\
597c478bd9Sstevel@tonic-gate 			    ((char *)(to))[2] = ((char *)(from))[1];	\
607c478bd9Sstevel@tonic-gate 			    ((char *)(to))[3] = ((char *)(from))[0];
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate #define	DECODE_FLOAT(from, to)		DECODE_LONG((to), (from))
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate #define	DECODE_DOUBLE(from, to)						\
657c478bd9Sstevel@tonic-gate 			    ((char *)(to))[0] = ((char *)(from))[7];	\
667c478bd9Sstevel@tonic-gate 			    ((char *)(to))[1] = ((char *)(from))[6];	\
677c478bd9Sstevel@tonic-gate 			    ((char *)(to))[2] = ((char *)(from))[5];	\
687c478bd9Sstevel@tonic-gate 			    ((char *)(to))[3] = ((char *)(from))[4];	\
697c478bd9Sstevel@tonic-gate 			    ((char *)(to))[4] = ((char *)(from))[3];	\
707c478bd9Sstevel@tonic-gate 			    ((char *)(to))[5] = ((char *)(from))[2];	\
717c478bd9Sstevel@tonic-gate 			    ((char *)(to))[6] = ((char *)(from))[1];	\
727c478bd9Sstevel@tonic-gate 			    ((char *)(to))[7] = ((char *)(from))[0];
73*3b363e38SRichard Lowe #else /* little-endian */
74*3b363e38SRichard Lowe #error Unknown machine endianness
75*3b363e38SRichard Lowe #endif
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate #define	ENCODE_SHORT(from, to)		DECODE_SHORT((from), (to))
787c478bd9Sstevel@tonic-gate #define	ENCODE_LONG(from, to)		DECODE_LONG((from), (to))
797c478bd9Sstevel@tonic-gate #define	ENCODE_FLOAT(from, to)		DECODE_FLOAT((from), (to))
807c478bd9Sstevel@tonic-gate #define	ENCODE_DOUBLE(from, to)		DECODE_DOUBLE((from), (to))
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate #ifdef __cplusplus
837c478bd9Sstevel@tonic-gate }
847c478bd9Sstevel@tonic-gate #endif
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate #endif /* !_MULTIMEDIA_ARCHDEP_H */
87