blob: 9a0d6ca55b9a726cee301e0bd3fa816f1deea688 [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Jeff Johnson32d95a32012-09-10 13:15:23 -07002 * Copyright (c) 2012, The Linux Foundation. All rights reserved.
Jeff Johnson295189b2012-06-20 16:38:30 -07003 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/*==========================================================================
23 *
24 * @file: aniCompiler.h
25 *
26 * @brief: This file tries to abstract the differences among compilers.
27 * Supported compilers are:
28 * ARM RVCT compiler
29 *
30 * @author: Kumar Anand
31 *
32 * Copyright (C) 2010, Qualcomm, Inc.
33 * All rights reserved.
34 *
35 *=========================================================================*/
36#ifndef __ANI_COMPILER_ABSTRACT_H
37#define __ANI_COMPILER_ABSTRACT_H
38
39/*
40 * 1. GNU C/C++ Compiler
41 *
42 * How to detect gcc : __GNUC__
43 * How to detect gcc version :
44 * major version : __GNUC__ (2 = 2.x, 3 = 3.x, 4 = 4.x)
45 * minor version : __GNUC_MINOR__
46 *
47 * 2. Microsoft C/C++ Compiler
48 *
49 * How to detect msc : _MSC_VER
50 * How to detect msc version :
51 * _MSC_VER (1200 = MSVC 6.0, 1300 = MSVC 7.0, ...)
52 *
53 * 3. Intel C/C++ Compiler
54 *
55 * How to detect icc : __INTEL_COMPILER, __ICC (legacy), __ECC (legacy)
56 * How to detect icc version :
57 * __INTEL_COMPILER, __ICC, __ECC (700 = 7.0, 900 = 9.0, ...)
58 *
59 * 4. Other compilers (not supported)
60 *
61 * Borland : __BORLANDC__
62 * Greenhills : __ghs
63 * Metrowerks : __MWERKS__
64 * SGI MIPSpro : __sgi
65 */
66
67/*
68 * Packing directives : These are used to force compiler to pack bits and
69 * bytes in the data structure. C standard does not regulate this strictly,
70 * and many things are to compiler implementation. Many compilers support
71 * compiler specific directives or options that allow different packing
72 * and alignment.
73 *
74 * Alignment directives : Compiler may think packed data structures have
75 * no specific alignment requirement. Then compiler may generate multiple
76 * byte accesses to access two byte or four bytes data structures. This
77 * affects on performance especially for RISC systems. If some data
78 * structure is located on specific alignment always, alignment directives
79 * help compiler generate more efficient codes.
80 */
81
82#undef __ANI_COMPILER_PRAGMA_PACK_STACK
83#undef __ANI_COMPILER_PRAGMA_PACK
84
85#if defined(_MSC_VER)
86#define __ANI_COMPILER_PRAGMA_PACK_STACK 1
87#define __ANI_COMPILER_PRAGMA_PACK 1
88#define __ani_attr_pre_packed
89#define __ani_attr_packed
90#define __ani_attr_aligned_2
91#define __ani_attr_aligned_4
92#define __ani_attr_aligned_8
93#define __ani_attr_aligned_16
94#define __ani_attr_aligned_32
95#define PACKED
96#define PACKED_POST
97#define ALIGN(__value)
98#elif defined(__INTEL_COMPILER) || defined(__ICC) || defined(__ECC)
99#define __ANI_COMPILER_PRAGMA_PACK 1
100#define __ani_attr_pre_packed
101#define __ani_attr_packed
102#define __ani_attr_aligned_2
103#define __ani_attr_aligned_4
104#define __ani_attr_aligned_8
105#define __ani_attr_aligned_16
106#define __ani_attr_aligned_32
107#define PACKED
108#define PACKED_POST
109#define ALIGN(__value)
110#elif defined(__GNUC__)
111#define __ani_attr_pre_packed
112#define __ani_attr_packed __attribute__((packed))
113#define __ani_attr_aligned_2 __attribute__((aligned(2)))
114#define __ani_attr_aligned_4 __attribute__((aligned(4)))
115#define __ani_attr_aligned_8 __attribute__((aligned(8)))
116#define __ani_attr_aligned_16 __attribute__((aligned(16)))
117#define __ani_attr_aligned_32 __attribute__((aligned(32)))
118#ifndef PACKED
119#define PACKED
120#endif
121#ifndef PACKED_POST
122#define PACKED_POST __attribute__((packed))
123#endif
124#ifndef ALIGN
125#define ALIGN(__value) __attribute__((aligned(__value)))
126#endif
127#elif defined(ANI_COMPILER_TYPE_RVCT)
128/* Nothing defined so far */
Madan Mohan Koyyalamudi28335fe2012-12-12 15:04:08 -0800129
130/*
131 * RIVA 1.2 and Pronto uses ARMCT5.1 compiler and it throws lot of warning when __align() is used in structure definitions.
132 * __attribute__((aligned())) is GNU compiler attribute that is accepted by ARM compiler and resolves the warnings.
133 */
134#if (__ARMCC_VERSION > 400000)
135#define __ani_attr_packed
136#define __ani_attr_pre_packed __packed
137#define __ani_attr_aligned_2 __attribute__((aligned(2)))
138#define __ani_attr_aligned_4 __attribute__((aligned(4)))
139#define __ani_attr_aligned_8 __attribute__((aligned(8)))
140#define __ani_attr_aligned_16 __attribute__((aligned(16)))
141#define __ani_attr_aligned_32 __attribute__((aligned(32)))
142#define PACKED __packed
143#define PACKED_POST
144#define ALIGN(__value) __align(__value)
145#else
Jeff Johnson295189b2012-06-20 16:38:30 -0700146#define __ani_attr_packed
147#define __ani_attr_pre_packed __packed
148#define __ani_attr_aligned_2 __align(2)
149#define __ani_attr_aligned_4 __align(4)
150#define __ani_attr_aligned_8 __align(8)
151#define __ani_attr_aligned_16 __align(16)
152#define __ani_attr_aligned_32 __align(32)
153#define PACKED __packed
154#define PACKED_POST
155#define ALIGN(__value) __align(__value)
Madan Mohan Koyyalamudi28335fe2012-12-12 15:04:08 -0800156#endif
157
Jeff Johnson295189b2012-06-20 16:38:30 -0700158#else
159#error "Unknown compiler"
160#endif
161
162#ifndef PACKED_PRE
163#define PACKED_PRE __ani_attr_pre_packed
164#endif
165
166#ifndef ALIGN_4
167#define ALIGN_4 __ani_attr_aligned_4
168#endif
169
170#endif //__ANI_COMPILER_ABSTRACT_H
171