compiler.h revision 03b705cf
103b705cfSriastradh/* 203b705cfSriastradh * Copyright (c) 2011 Intel Corporation 303b705cfSriastradh * 403b705cfSriastradh * Permission is hereby granted, free of charge, to any person obtaining a 503b705cfSriastradh * copy of this software and associated documentation files (the "Software"), 603b705cfSriastradh * to deal in the Software without restriction, including without limitation 703b705cfSriastradh * the rights to use, copy, modify, merge, publish, distribute, sublicense, 803b705cfSriastradh * and/or sell copies of the Software, and to permit persons to whom the 903b705cfSriastradh * Software is furnished to do so, subject to the following conditions: 1003b705cfSriastradh * 1103b705cfSriastradh * The above copyright notice and this permission notice (including the next 1203b705cfSriastradh * paragraph) shall be included in all copies or substantial portions of the 1303b705cfSriastradh * Software. 1403b705cfSriastradh * 1503b705cfSriastradh * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1603b705cfSriastradh * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1703b705cfSriastradh * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 1803b705cfSriastradh * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 1903b705cfSriastradh * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 2003b705cfSriastradh * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 2103b705cfSriastradh * SOFTWARE. 2203b705cfSriastradh * 2303b705cfSriastradh * Authors: 2403b705cfSriastradh * Chris Wilson <chris@chris-wilson.co.uk> 2503b705cfSriastradh * 2603b705cfSriastradh */ 2703b705cfSriastradh 2803b705cfSriastradh#ifndef _SNA_COMPILER_H_ 2903b705cfSriastradh#define _SNA_COMPILER_H_ 3003b705cfSriastradh 3103b705cfSriastradh#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__) 3203b705cfSriastradh#define likely(expr) (__builtin_expect (!!(expr), 1)) 3303b705cfSriastradh#define unlikely(expr) (__builtin_expect (!!(expr), 0)) 3403b705cfSriastradh#define noinline __attribute__((noinline)) 3503b705cfSriastradh#define force_inline inline __attribute__((always_inline)) 3603b705cfSriastradh#define fastcall __attribute__((regparm(3))) 3703b705cfSriastradh#define must_check __attribute__((warn_unused_result)) 3803b705cfSriastradh#define constant __attribute__((const)) 3903b705cfSriastradh#define pure __attribute__((pure)) 4003b705cfSriastradh#define tightly_packed __attribute__((__packed__)) 4103b705cfSriastradh#define flatten __attribute__((flatten)) 4203b705cfSriastradh#define page_aligned __attribute__((aligned(4096))) 4303b705cfSriastradh#else 4403b705cfSriastradh#define likely(expr) (expr) 4503b705cfSriastradh#define unlikely(expr) (expr) 4603b705cfSriastradh#define noinline 4703b705cfSriastradh#define force_inline inline 4803b705cfSriastradh#define fastcall 4903b705cfSriastradh#define must_check 5003b705cfSriastradh#define constant 5103b705cfSriastradh#define pure 5203b705cfSriastradh#define tighly_packed 5303b705cfSriastradh#define flatten 5403b705cfSriastradh#define page_aligned 5503b705cfSriastradh#endif 5603b705cfSriastradh 5703b705cfSriastradh#define HAS_GCC(major, minor) defined(__GNUC__) && (__GNUC__ > (major) || __GNUC__ == (major) && __GNUC_MINOR__ >= (minor)) 5803b705cfSriastradh 5903b705cfSriastradh#if HAS_GCC(4, 5) 6003b705cfSriastradh#define sse2 __attribute__((target("sse2,fpmath=sse"))) 6103b705cfSriastradh#define sse4_2 __attribute__((target("sse4.2,sse2,fpmath=sse"))) 6203b705cfSriastradh#endif 6303b705cfSriastradh 6403b705cfSriastradh#if HAS_GCC(4, 7) 6503b705cfSriastradh#define avx2 __attribute__((target("avx2,sse4.2,sse2,fpmath=sse"))) 6603b705cfSriastradh#endif 6703b705cfSriastradh 6803b705cfSriastradh#if HAS_GCC(4, 6) && defined(__OPTIMIZE__) 6903b705cfSriastradh#define fast __attribute__((optimize("Ofast"))) 7003b705cfSriastradh#else 7103b705cfSriastradh#define fast 7203b705cfSriastradh#endif 7303b705cfSriastradh 7403b705cfSriastradh#if HAS_GCC(4, 6) && defined(__OPTIMIZE__) 7503b705cfSriastradh#define fast_memcpy __attribute__((optimize("Ofast"))) __attribute__((target("inline-all-stringops"))) 7603b705cfSriastradh#elif HAS_GCC(4, 5) && defined(__OPTIMIZE__) 7703b705cfSriastradh#define fast_memcpy __attribute__((target("inline-all-stringops"))) 7803b705cfSriastradh#else 7903b705cfSriastradh#define fast_memcpy 8003b705cfSriastradh#endif 8103b705cfSriastradh 8203b705cfSriastradh#ifdef HAVE_VALGRIND 8303b705cfSriastradh#define VG(x) x 8403b705cfSriastradh#else 8503b705cfSriastradh#define VG(x) 8603b705cfSriastradh#endif 8703b705cfSriastradh 8803b705cfSriastradh#define VG_CLEAR(s) VG(memset(&s, 0, sizeof(s))) 8903b705cfSriastradh 9003b705cfSriastradh#define COMPILE_TIME_ASSERT(E) ((void)sizeof(char[1 - 2*!(E)])) 9103b705cfSriastradh 9203b705cfSriastradh#endif /* _SNA_COMPILER_H_ */ 93