Zvikomborero VIncent Zvikaramba | b726168 | 2016-08-03 01:27:15 -0400 | [diff] [blame] | 1 | /* |
| 2 | * 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 | |
| 22 | /* |
| 23 | * This file was originally distributed by Qualcomm Atheros, Inc. |
| 24 | * under proprietary terms before Copyright ownership was assigned |
| 25 | * to the Linux Foundation. |
| 26 | */ |
| 27 | |
| 28 | /*========================================================================== |
| 29 | * |
| 30 | * @file: aniCompiler.h |
| 31 | * |
| 32 | * @brief: This file tries to abstract the differences among compilers. |
| 33 | * Supported compilers are: |
| 34 | * ARM RVCT compiler |
| 35 | * |
| 36 | * @author: Kumar Anand |
| 37 | * |
| 38 | * |
| 39 | *=========================================================================*/ |
| 40 | #ifndef __ANI_COMPILER_ABSTRACT_H |
| 41 | #define __ANI_COMPILER_ABSTRACT_H |
| 42 | |
| 43 | /* |
| 44 | * 1. GNU C/C++ Compiler |
| 45 | * |
| 46 | * How to detect gcc : __GNUC__ |
| 47 | * How to detect gcc version : |
| 48 | * major version : __GNUC__ (2 = 2.x, 3 = 3.x, 4 = 4.x) |
| 49 | * minor version : __GNUC_MINOR__ |
| 50 | * |
| 51 | * 2. Microsoft C/C++ Compiler |
| 52 | * |
| 53 | * How to detect msc : _MSC_VER |
| 54 | * How to detect msc version : |
| 55 | * _MSC_VER (1200 = MSVC 6.0, 1300 = MSVC 7.0, ...) |
| 56 | * |
| 57 | * 3. Intel C/C++ Compiler |
| 58 | * |
| 59 | * How to detect icc : __INTEL_COMPILER, __ICC (legacy), __ECC (legacy) |
| 60 | * How to detect icc version : |
| 61 | * __INTEL_COMPILER, __ICC, __ECC (700 = 7.0, 900 = 9.0, ...) |
| 62 | * |
| 63 | * 4. Other compilers (not supported) |
| 64 | * |
| 65 | * Borland : __BORLANDC__ |
| 66 | * Greenhills : __ghs |
| 67 | * Metrowerks : __MWERKS__ |
| 68 | * SGI MIPSpro : __sgi |
| 69 | */ |
| 70 | |
| 71 | /* |
| 72 | * Packing directives : These are used to force compiler to pack bits and |
| 73 | * bytes in the data structure. C standard does not regulate this strictly, |
| 74 | * and many things are to compiler implementation. Many compilers support |
| 75 | * compiler specific directives or options that allow different packing |
| 76 | * and alignment. |
| 77 | * |
| 78 | * Alignment directives : Compiler may think packed data structures have |
| 79 | * no specific alignment requirement. Then compiler may generate multiple |
| 80 | * byte accesses to access two byte or four bytes data structures. This |
| 81 | * affects on performance especially for RISC systems. If some data |
| 82 | * structure is located on specific alignment always, alignment directives |
| 83 | * help compiler generate more efficient codes. |
| 84 | */ |
| 85 | |
| 86 | #undef __ANI_COMPILER_PRAGMA_PACK_STACK |
| 87 | #undef __ANI_COMPILER_PRAGMA_PACK |
| 88 | |
| 89 | #if defined(_MSC_VER) |
| 90 | #define __ANI_COMPILER_PRAGMA_PACK_STACK 1 |
| 91 | #define __ANI_COMPILER_PRAGMA_PACK 1 |
| 92 | #define __ani_attr_pre_packed |
| 93 | #define __ani_attr_packed |
| 94 | #define __ani_attr_aligned_2 |
| 95 | #define __ani_attr_aligned_4 |
| 96 | #define __ani_attr_aligned_8 |
| 97 | #define __ani_attr_aligned_16 |
| 98 | #define __ani_attr_aligned_32 |
| 99 | #define PACKED |
| 100 | #define PACKED_POST |
| 101 | #define ALIGN(__value) |
| 102 | #elif defined(__INTEL_COMPILER) || defined(__ICC) || defined(__ECC) |
| 103 | #define __ANI_COMPILER_PRAGMA_PACK 1 |
| 104 | #define __ani_attr_pre_packed |
| 105 | #define __ani_attr_packed |
| 106 | #define __ani_attr_aligned_2 |
| 107 | #define __ani_attr_aligned_4 |
| 108 | #define __ani_attr_aligned_8 |
| 109 | #define __ani_attr_aligned_16 |
| 110 | #define __ani_attr_aligned_32 |
| 111 | #define PACKED |
| 112 | #define PACKED_POST |
| 113 | #define ALIGN(__value) |
| 114 | #elif defined(__GNUC__) |
| 115 | #define __ani_attr_pre_packed |
| 116 | #define __ani_attr_packed __attribute__((packed)) |
| 117 | #define __ani_attr_aligned_2 __attribute__((aligned(2))) |
| 118 | #define __ani_attr_aligned_4 __attribute__((aligned(4))) |
| 119 | #define __ani_attr_aligned_8 __attribute__((aligned(8))) |
| 120 | #define __ani_attr_aligned_16 __attribute__((aligned(16))) |
| 121 | #define __ani_attr_aligned_32 __attribute__((aligned(32))) |
| 122 | #ifndef PACKED |
| 123 | #define PACKED |
| 124 | #endif |
| 125 | #ifndef PACKED_POST |
| 126 | #define PACKED_POST __attribute__((packed)) |
| 127 | #endif |
| 128 | #ifndef ALIGN |
| 129 | #define ALIGN(__value) __attribute__((aligned(__value))) |
| 130 | #endif |
| 131 | #elif defined(ANI_COMPILER_TYPE_RVCT) |
| 132 | /* Nothing defined so far */ |
| 133 | |
| 134 | /* |
| 135 | * RIVA 1.2 and Pronto uses ARMCT5.1 compiler and it throws lot of warning when __align() is used in structure definitions. |
| 136 | * __attribute__((aligned())) is GNU compiler attribute that is accepted by ARM compiler and resolves the warnings. |
| 137 | */ |
| 138 | #if (__ARMCC_VERSION > 400000) |
| 139 | #define __ani_attr_packed |
| 140 | #define __ani_attr_pre_packed __packed |
| 141 | #define __ani_attr_aligned_2 __attribute__((aligned(2))) |
| 142 | #define __ani_attr_aligned_4 __attribute__((aligned(4))) |
| 143 | #define __ani_attr_aligned_8 __attribute__((aligned(8))) |
| 144 | #define __ani_attr_aligned_16 __attribute__((aligned(16))) |
| 145 | #define __ani_attr_aligned_32 __attribute__((aligned(32))) |
| 146 | #define PACKED __packed |
| 147 | #define PACKED_POST |
| 148 | #define ALIGN(__value) __align(__value) |
| 149 | #define PREPACK __packed |
| 150 | #define POSTPACK |
| 151 | #else |
| 152 | #define __ani_attr_packed |
| 153 | #define __ani_attr_pre_packed __packed |
| 154 | #define __ani_attr_aligned_2 __align(2) |
| 155 | #define __ani_attr_aligned_4 __align(4) |
| 156 | #define __ani_attr_aligned_8 __align(8) |
| 157 | #define __ani_attr_aligned_16 __align(16) |
| 158 | #define __ani_attr_aligned_32 __align(32) |
| 159 | #define PACKED __packed |
| 160 | #define PACKED_POST |
| 161 | #define ALIGN(__value) __align(__value) |
| 162 | #endif |
| 163 | |
| 164 | #else |
| 165 | #error "Unknown compiler" |
| 166 | #endif |
| 167 | |
| 168 | #ifndef PACKED_PRE |
| 169 | #define PACKED_PRE __ani_attr_pre_packed |
| 170 | #endif |
| 171 | |
| 172 | #ifndef ALIGN_4 |
| 173 | #define ALIGN_4 __ani_attr_aligned_4 |
| 174 | #endif |
| 175 | |
| 176 | #endif //__ANI_COMPILER_ABSTRACT_H |
| 177 | |