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