ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SheepShaver/src/kpx_cpu/include/nvmemfun.hpp
Revision: 1.2
Committed: 2003-11-24T23:45:43Z (20 years, 11 months ago) by gbeauche
Branch: MAIN
Changes since 1.1: +16 -12 lines
Log Message:
Merge in-progress PowerPC "JIT1" engine for AMD64, IA-32, PPC.

The merge probably got wrong as there are some problems probably due to the
experiment begining with CR deferred evaluation. With nbench/ppc, performance
improvement was around 2x. With nbench on x86, performance improvement was
around 4x on average.

Incompatible change: instr_info_t has a new field in the middle. But since
insertion of PPC_I(XXX) identifiers is auto-generated, there is no problem.

File Contents

# User Rev Content
1 gbeauche 1.1 /*
2     * nvmemfun.hpp - Non-virtual member function wrappers
3     *
4     * Kheperix (C) 2003 Gwenole Beauchesne
5     *
6     * This program is free software; you can redistribute it and/or modify
7     * it under the terms of the GNU General Public License as published by
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10     *
11     * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with this program; if not, write to the Free Software
18     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19     */
20    
21     #ifndef NVMEMFUN_H
22     #define NVMEMFUN_H
23    
24     #include <functional>
25    
26     #if (defined(__GNUC__) || defined(__ICC))
27    
28     template< class PMF, class PF >
29     inline PF nv_mem_fun_of(PMF pmf) {
30     union { PMF pmf; uintptr p[2]; } x;
31     x.pmf = pmf;
32     #if defined(__GXX_ABI_VERSION) /* GCC >= 3.0 */
33     const int N = 0;
34     #else
35     const int N = 1;
36     #endif
37     return (PF)x.p[N];
38     }
39    
40     template< class R, class T >
41     class nv_mem_fun_t : public std::unary_function<T, R> {
42     typedef R (T::*pmf_t)();
43     typedef R (*pf_t)(T *);
44     pf_t pf;
45     public:
46     nv_mem_fun_t(pmf_t pmf) : pf(nv_mem_fun_of<pmf_t, pf_t>(pmf)) {}
47     R operator()(T *p) const { return (*pf)(p); }
48 gbeauche 1.2 pf_t ptr() const { return pf; }
49 gbeauche 1.1 };
50    
51     template< class R, class T >
52     class const_nv_mem_fun_t : public std::unary_function<T, R> {
53     typedef R (T::*pmf_t)();
54     typedef R (*pf_t)(T *);
55     pf_t const pf;
56     public:
57     const_nv_mem_fun_t(pmf_t const pmf) : pf(nv_mem_fun_of<pmf_t, pf_t>(pmf)) {}
58     R operator()(const T *p) const { return (*pf)(p); }
59 gbeauche 1.2 pf_t ptr() const { return pf; }
60 gbeauche 1.1 };
61    
62     template< class R, class T, class A >
63     class nv_mem_fun1_t : public std::binary_function<T, A, R> {
64     typedef R (T::*pmf_t)(A);
65     typedef R (*pf_t)(T *, A x);
66     pf_t pf;
67     public:
68     nv_mem_fun1_t(pmf_t pmf) : pf(nv_mem_fun_of<pmf_t, pf_t>(pmf)) {}
69     R operator()(T *p, A x) const { return (*pf)(p, x); }
70 gbeauche 1.2 pf_t ptr() const { return pf; }
71 gbeauche 1.1 };
72    
73     template< class R, class T, class A >
74     class const_nv_mem_fun1_t : public std::binary_function<T, A, R> {
75     typedef R (T::*pmf_t)(A);
76     typedef R (*pf_t)(T *, A x);
77     pf_t const pf;
78     public:
79     const_nv_mem_fun1_t(pmf_t const pmf) : pf(nv_mem_fun_of<pmf_t, pf_t>(pmf)) {}
80     R operator()(const T *p, A x) const { return (*pf)(p, x); }
81 gbeauche 1.2 pf_t ptr() const { return pf; }
82 gbeauche 1.1 };
83    
84     #else
85    
86     template< class R, class T >
87     class nv_mem_fun_t : public std::unary_function<T, R> {
88 gbeauche 1.2 typedef R (T::*pmf_t)();
89     pmf_t pf;
90 gbeauche 1.1 public:
91     nv_mem_fun_t(R (T::*pmf)()) : pf(pmf) {}
92     R operator()(T *p) const { return (p->*pf)(); }
93 gbeauche 1.2 pmf_t ptr() const { return pf; }
94 gbeauche 1.1 };
95    
96     template< class R, class T >
97     class const_nv_mem_fun_t : public std::unary_function<T, R> {
98 gbeauche 1.2 typedef R (T::*pmf_t)() const;
99     pmf_t pf;
100 gbeauche 1.1 public:
101     const_nv_mem_fun_t(R (T::*pmf)() const) : pf(pmf) {}
102     R operator()(const T *p) const { return (p->*pf)(); }
103 gbeauche 1.2 pmf_t ptr() const { return pf; }
104 gbeauche 1.1 };
105    
106     template< class R, class T, class A >
107     class nv_mem_fun1_t : public std::binary_function<T, A, R> {
108 gbeauche 1.2 typedef R (T::*pmf_t)(A);
109     pmf_t pf;
110 gbeauche 1.1 public:
111     nv_mem_fun1_t(R (T::*pmf)(A)) : pf(pmf) {}
112     R operator()(T *p, A x) const { return (p->*pf)(x); }
113 gbeauche 1.2 pmf_t ptr() const { return pf; }
114 gbeauche 1.1 };
115    
116     template< class R, class T, class A >
117     class const_nv_mem_fun1_t : public std::binary_function<T, A, R> {
118 gbeauche 1.2 typedef R (T::*pmf_t)(A) const;
119     pmf_t pf;
120 gbeauche 1.1 public:
121     const_nv_mem_fun1_t(R (T::*pmf)(A) const) : pf(pmf) {}
122     R operator()(const T *p, A x) const { return (p->*pf)(x); }
123 gbeauche 1.2 pmf_t ptr() const { return pf; }
124 gbeauche 1.1 };
125    
126     #endif
127    
128     template< class R, class T >
129     inline nv_mem_fun_t<R, T> nv_mem_fun(R (T::*pmf)()) {
130     return nv_mem_fun_t<R, T>(pmf);
131     }
132    
133     template< class R, class T >
134     inline const_nv_mem_fun_t<R, T> nv_mem_fun(R (T::*pmf)() const) {
135     return const_nv_mem_fun_t<R, T>(pmf);
136     }
137    
138     template< class R, class T, class A >
139     inline nv_mem_fun1_t<R, T, A> nv_mem_fun(R (T::*pmf)(A)) {
140     return nv_mem_fun1_t<R, T, A>(pmf);
141     }
142    
143     template< class R, class T, class A >
144     inline const_nv_mem_fun1_t<R, T, A> nv_mem_fun(R (T::*pmf)(A) const) {
145     return const_nv_mem_fun1_t<R, T, A>(pmf);
146     }
147    
148     #endif /* NVMEMFUN_H */