00001 /* 00002 * $Id: compiler_opt.h 5720 2009-03-18 12:55:53Z henningw $ 00003 * 00004 * Copyright (C) 2007 iptelorg GmbH 00005 * 00006 * Permission to use, copy, modify, and distribute this software for any 00007 * purpose with or without fee is hereby granted, provided that the above 00008 * copyright notice and this permission notice appear in all copies. 00009 * 00010 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 00011 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 00012 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 00013 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 00014 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 00015 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 00016 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 00017 */ 00018 /* 00019 * compiler specific optimizations: 00020 * -------------------------------- 00021 * 00022 * likely(expr) - branch predicition optimization - is more likely 00023 * that expr value will be 1 so optimize for this 00024 * case. 00025 * Example: if (likely(p!=NULL)) {... } 00026 * unlikely(expr) - branch prediction optimization - is unlikely that 00027 * expr will be true, so optimize for this case 00028 * prefetch(addr) - will prefetch addr. for reading 00029 * prefetch_w(addr) - will prefetch addr. for writing 00030 * prefetch_loc_r(addr, loc) - prefetch for reading, data at addr has 00031 * no temporal locality (loc==0), a short 00032 * degree of temporal locality (loc==1), 00033 * moderate (loc==2) or high (loc==3). 00034 * prefetch(addr) is equiv. to 00035 * prefetch_loc_r(addr, 3). 00036 * prefetch_loc_w(addr, loc) - like above but for writing. 00037 */ 00038 /* 00039 * History: 00040 * -------- 00041 * 2007-05-14 created by andrei 00042 */ 00043 00044 #ifndef __compiler_opt_h 00045 #define __compiler_opt_h 00046 00047 #if __GNUC__ >= 3 00048 #define likely(expr) __builtin_expect(!!(expr), 1) 00049 #define unlikely(expr) __builtin_expect(!!(expr), 0) 00050 00051 #define prefetch(addr) __builtin_prefetch((addr)) 00052 #define prefetch_w(addr) __builtin_prefetch((addr), 1) 00053 #define prefetch_loc_r(addr, loc) __builtin_prefetch((addr), 0, (loc)) 00054 #define prefetch_loc_w(addr, loc) __builtin_prefetch((addr), 1, (loc)) 00055 00056 #else /* __GNUC__ */ 00057 00058 #warning "No compiler optimizations supported try gcc 4.x" 00059 #define likely(expr) (expr) 00060 #define unlikely(expr) (expr) 00061 00062 #define prefetch(addr) 00063 #define prefetch_w(addr) 00064 #define prefetch_loc_r(addr, loc) 00065 #define prefetch_loc_w(addr, loc) 00066 #endif /* __GNUC__ */ 00067 00068 #endif
1.5.6