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