Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 1 | /* |
Jeff Johnson | 32d95a3 | 2012-09-10 13:15:23 -0700 | [diff] [blame] | 2 | * Copyright (c) 2012, The Linux Foundation. All rights reserved. |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 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 | * |
| 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 */ |
| 129 | #define __ani_attr_packed |
| 130 | #define __ani_attr_pre_packed __packed |
| 131 | #define __ani_attr_aligned_2 __align(2) |
| 132 | #define __ani_attr_aligned_4 __align(4) |
| 133 | #define __ani_attr_aligned_8 __align(8) |
| 134 | #define __ani_attr_aligned_16 __align(16) |
| 135 | #define __ani_attr_aligned_32 __align(32) |
| 136 | #define PACKED __packed |
| 137 | #define PACKED_POST |
| 138 | #define ALIGN(__value) __align(__value) |
| 139 | #else |
| 140 | #error "Unknown compiler" |
| 141 | #endif |
| 142 | |
| 143 | #ifndef PACKED_PRE |
| 144 | #define PACKED_PRE __ani_attr_pre_packed |
| 145 | #endif |
| 146 | |
| 147 | #ifndef ALIGN_4 |
| 148 | #define ALIGN_4 __ani_attr_aligned_4 |
| 149 | #endif |
| 150 | |
| 151 | #endif //__ANI_COMPILER_ABSTRACT_H |
| 152 | |