Browse code

*** empty log message ***

Andrei Pelinescu-Onciul authored on 14/05/2007 17:09:31
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,68 @@
0
+/*
1
+ * $Id$
2
+ * 
3
+ * Copyright (C) 2007 iptelorg GmbH
4
+ *
5
+ * Permission to use, copy, modify, and distribute this software for any
6
+ * purpose with or without fee is hereby granted, provided that the above
7
+ * copyright notice and this permission notice appear in all copies.
8
+ *
9
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
+ */
17
+/*
18
+ * compiler specific optimizations:
19
+ * --------------------------------
20
+ *
21
+ *   likely(expr)         - branch predicition optimization - is more likely
22
+ *                          that expr value will be 1 so optimize for this 
23
+ *                          case.
24
+ *                          Example: if (likely(p!=NULL)) {... }
25
+ *   unlikely(expr)       - branch prediction optimization - is unlikely that 
26
+ *                          expr will be true, so optimize for this case
27
+ *   prefetch(addr)        - will prefetch addr for reading
28
+ *   prefetch_w(addr)      - will prefetch add for writing
29
+ *   prefetch_loc_r(addr, loc) - prefetch for reading, data at addr has
30
+ *                                no temporal locality (loc==0), a short
31
+ *                                degree of temporal locality (loc==1), 
32
+ *                                moderate (loc==2) or high (loc==3).
33
+ *                                prefetch(addr) is equiv. to 
34
+ *                                prefetch_loc_r(addr, 3).
35
+ *  prefetch_loc_r(addr, loc) - like above but for writing.
36
+ */
37
+/* 
38
+ * History:
39
+ * --------
40
+ *  2007-05-14  created by andrei
41
+ */
42
+
43
+#ifndef __compiler_opt_h
44
+#define __compiler_opt_h
45
+
46
+#if __GNUC__ >= 3
47
+#define likely(expr)              __builtin_expect(!!(expr), 1)
48
+#define unlikely(expr)            __builtin_expect(!!(expr), 0)
49
+
50
+#define prefetch(addr)            __builtin_prefetch((addr))
51
+#define prefecth_w(addr)          __builtin_prefetch((addr), 1)
52
+#define prefetch_loc_r(addr, loc) __builtin_prefetch((addr), 0, (loc))
53
+#define prefetch_loc_w(addr, loc) __builtin_prefetch((addr), 1, (loc))
54
+
55
+#else /* __GNUC__ */
56
+
57
+#warning "No compiler optimizations supported try gcc 4.x"
58
+#define likely(expr) (expr)
59
+#define unlikely(expr) (expr)
60
+
61
+#define prefetch(addr)
62
+#define prefecth_w(addr)
63
+#define prefetch_loc_r(addr, loc)
64
+#define prefetch_loc_w(addr, loc)
65
+#endif /* __GNUC__ */
66
+
67
+#endif