[Gridflow-cvs] [svn] commit: r6380 - in /trunk/src: numop1.cxx numop2.cxx

svn-gridflow at artengine.ca svn-gridflow at artengine.ca
Tue Sep 28 15:53:24 EDT 2010


Author: matju
Date: Tue Sep 28 15:53:21 2010
New Revision: 6380

Log:
some numop2 become numop1

Modified:
    trunk/src/numop1.cxx
    trunk/src/numop2.cxx

Modified: trunk/src/numop1.cxx
==============================================================================
--- trunk/src/numop1.cxx (original)
+++ trunk/src/numop1.cxx Tue Sep 28 15:53:21 2010
@@ -21,6 +21,85 @@
 
 #include "gridflow.hxx.fcs"
 #include <math.h>
+#include <complex>
+
+template <class T> class Op {
+public:
+	// I call abort() on those because I can't say they're purevirtual.
+	static T f(T a) {abort();}
+};
+
+template <class O, class T> class OpLoops: public Numop1::On<T> {
+public:
+  static inline T f(T a) {return O::f(a);}
+  #define FOO(I) as[I]=f(as[I]);
+  static void _map (long n, T *as) {if (!n) return; UNROLL_8(FOO,n,as)}
+  #undef FOO
+};
+
+#define Plex std::complex
+
+#define DEF_OP_COMMON(op,expr,T) inline static T f(T a) { return (T)(expr); }
+#define DEF_OP(op,expr) template <class T> class Y##op : Op<T> { public: DEF_OP_COMMON(op,expr,T);};
+#define DEF_OPFT(op,expr,T) template <> class Y##op<T> : Op<T> { public: DEF_OP_COMMON(op,expr,T);};
+// this macro is for operators that have different code for the float version
+#define DEF_OPF( op,expr,expr2) \
+	DEF_OP(  op,expr      ) \
+	DEF_OPFT(op,     expr2,float32) \
+	DEF_OPFT(op,     expr2,float64)
+
+#define  OL(O,T) OpLoops<Y##O<T>,T>
+#define VOL(O,T) OpLoops<Y##O<Plex<T> >,Plex<T> >
+#define DECL_OPON(L,O,T) Numop1::On<T>((Numop1::On<T>::Map) L(O,T)::_map)
+#define DECLOP(        L,M,O,sym,dim) Numop1(sym,M(L,O,uint8),M(L,O,int16),M(L,O,int32) \
+	NONLITE(,M(L,O,int64)),  M(L,O,float32)   NONLITE(,M(L,O,float64)),dim)
+#define DECLOP_NOFLOAT(L,M,O,sym,dim) Numop1(sym,M(L,O,uint8),M(L,O,int16),M(L,O,int32) \
+	NONLITE(,M(L,O,int64)),Numop1::On<float32>() NONLITE(,Numop1::On<float64>()),dim)
+//	NONLITE(,M(L,O,int64),Numop1::On<float32>(),Numop1::On<float64>()),dim)
+#define DECLOP_FLOAT(  L,M,O,sym,dim) Numop1(sym,Numop1::On<uint8>(),Numop1::On<int16>(),Numop1::On<int32>() \
+	NONLITE(,Numop1::On<int64>()),M(L,O,float32) NONLITE(,M(L,O,float64)),dim)
+
+#define DECL_OP(          O,sym)     DECLOP(         OL,DECL_OPON,O,sym,1)
+#define DECL_OP_NOFLOAT(  O,sym)     DECLOP_NOFLOAT( OL,DECL_OPON,O,sym,1)
+#define DECL_OP_FLOAT(    O,sym)     DECLOP_FLOAT(   OL,DECL_OPON,O,sym,1)
+#define DECL_VOP(         O,sym,dim) DECLOP(        VOL,DECL_OPON,O,sym,dim)
+#define DECL_VOP_NOFLOAT( O,sym,dim) DECLOP_NOFLOAT(VOL,DECL_OPON,O,sym,dim)
+#define DECL_VOP_FLOAT(   O,sym,dim) DECLOP_FLOAT(  VOL,DECL_OPON,O,sym,dim)
+
+DEF_OPF(sqrt,floor(sqrt(a)),sqrt(a))
+DEF_OP(rand, a==0 ? (T)0 : (T)(random()%(int32)a))
+
+DEF_OP(sin,  sin(a))
+DEF_OP(cos,  cos(a))
+DEF_OP(tanh, tanh(a))
+DEF_OP(exp,  exp(a))
+DEF_OP(log,  log(a))
+
+DEF_OP(cx_sin,  sin(a))
+DEF_OP(cx_cos,  cos(a))
+DEF_OP(cx_tanh, tanh(a))
+DEF_OP(cx_exp,  exp(a))
+DEF_OP(cx_log,  log(a))
+
+Numop1 op_table_unary[] = {
+	DECL_OP(sqrt, "sqrt"),
+	DECL_OP(rand, "rand"),
+	DECL_OP_FLOAT(sin,  "sin"),
+	DECL_OP_FLOAT(cos,  "cos"),
+	DECL_OP_FLOAT(tanh, "tanh"),
+	DECL_OP_FLOAT(exp,  "exp"),
+	DECL_OP_FLOAT(log,  "log"),
+	DECL_VOP_FLOAT(cx_sin,  "C.sin",  2),
+	DECL_VOP_FLOAT(cx_cos,  "C.cos",  2),
+	DECL_VOP_FLOAT(cx_tanh, "C.tanh", 2),
+	DECL_VOP_FLOAT(cx_exp,  "C.exp",  2),
+	DECL_VOP_FLOAT(cx_log,  "C.log",  2),
+};
+const long op_table_unary_n = COUNT(op_table_unary);
+
+// D=dictionary, A=table, A##_n=table count.
+#define INIT_TABLE(D,A) for(int i=0; i<A##_n; i++) D[string(A[i].name)]=&A[i];
 
 void startup_numop1 () {
+	INIT_TABLE(op_dict,op_table_unary)
 }

Modified: trunk/src/numop2.cxx
==============================================================================
--- trunk/src/numop2.cxx (original)
+++ trunk/src/numop2.cxx Tue Sep 28 15:53:21 2010
@@ -173,10 +173,8 @@
 #define DECL_VOP_NOFOLD_NOFLOAT(O,sym,flags,dim) DECLOP_NOFLOAT(VOL,DECL_OPON_NOFOLD,O,sym,flags,dim)
 #define DECL_VOP_NOFOLD_FLOAT(  O,sym,flags,dim) DECLOP_FLOAT(  VOL,DECL_OPON_NOFOLD,O,sym,flags,dim)
 
-template <class T> static inline T gf_floor (T a) {
-	return (T) floor((double)a); }
-template <class T> static inline T gf_trunc (T a) {
-	return (T) floor(abs((double)a)) * (a<0?-1:1); }
+template <class T> static inline T gf_floor (T a) {return (T) floor(    (double)a              );}
+template <class T> static inline T gf_trunc (T a) {return (T) floor(abs((double)a)) * (a<0?-1:1);}
 
 #ifdef PASS1
 DEF_OP(ignore, a, 0, side==at_right, side==at_left)
@@ -232,21 +230,13 @@
 DEF_OP(sqsub,   (a-b)*(a-b), 0, false, false)
 DEF_OP(avg,         (a+b)/2, 0, false, false)
 DEF_OPF(hypot, floor(sqrt(a*a+b*b)), sqrt(a*a+b*b), 0, false, false)
-DEF_OPF(sqrt,  floor(sqrt(a)),       sqrt(a),       0, false, false)
-DEF_OP(rand, a==0 ? (T)0 : (T)(random()%(int32)a), 0, false, false)
 //DEF_OP(erf,"erf*", 0)
 DEF_OP(weight,weight((uint64)(a^b) & (0xFFFFFFFFFFFFFFFFULL>>(64-sizeof(T)*8))),0,false,false)
 #define BITS(T) (sizeof(T)*8)
 DEF_OP(rol,((uint64)a<<b)|((uint64)a>>(T)((-b)&(BITS(T)-1))),0,false,false)
 DEF_OP(ror,((uint64)a>>b)|((uint64)a<<(T)((-b)&(BITS(T)-1))),0,false,false)
 
-DEF_OP(sin,  sin(a-b),   0, false, false)
-DEF_OP(cos,  cos(a-b),   0, false, false)
 DEF_OP(atan2,atan2(a,b), 0, false, false)
-DEF_OP(tanh, tanh(a-b),  0, false, false)
-DEF_OP(exp,  exp(a-b),   0, false, false)
-DEF_OP(log,  log(a-b),   0, false, false)
-
 #endif
 #ifdef PASS4
 
@@ -283,12 +273,7 @@
 DEF_OP(cx_vidconj, a==Plex<T>(0,0) ? T(0) : conj(b)/a, 1, false, false)
 DEF_OP(cx_sqsub,   cx_sqsub(a,b), 0, false, false)
 DEF_OP(cx_abssub, cx_abssub(a,b), 0, false, false)
-DEF_OP(cx_sin,  sin(a-b),   0, false, false)
-DEF_OP(cx_cos,  cos(a-b),   0, false, false)
 //DEF_OP(cx_atan2,atan2(a,b), 0, false, false)
-DEF_OP(cx_tanh, tanh(a-b),  0, false, false)
-DEF_OP(cx_exp,  exp(a-b),   0, false, false)
-DEF_OP(cx_log,  log(a-b),   0, false, false)
 DEF_OP(c2p,     gf_c2p(a-b), 0, false, false)
 DEF_OP(p2c,     gf_p2c(a)+b, 0, false, false)
 #endif
@@ -369,19 +354,12 @@
 	DECL_OP_NOFOLD(sqsub, "sq-",  OP_COMM),
 	DECL_OP(avg,   "avg",  OP_COMM),
 	DECL_OP(hypot, "hypot",OP_COMM), // huh, almost OP_ASSOC
-	DECL_OP_NOFOLD(sqrt, "sqrt", 0),
-	DECL_OP_NOFOLD(rand, "rand", 0),
 	//DECL_OP_NOFOLD(erf,"erf*", 0),
 	DECL_OP_NOFOLD_NOFLOAT(weight,"weight",OP_COMM),
 	DECL_OP_NOFOLD_NOFLOAT(rol,"rol",0),
 	DECL_OP_NOFOLD_NOFLOAT(ror,"ror",0),
 
-	DECL_OP_NOFOLD_FLOAT(sin,  "sin",   0),
-	DECL_OP_NOFOLD_FLOAT(cos,  "cos",   0),
 	DECL_OP_NOFOLD_FLOAT(atan2,"atan2", 0),
-	DECL_OP_NOFOLD_FLOAT(tanh, "tanh",  0),
-	DECL_OP_NOFOLD_FLOAT(exp,  "exp",   0),
-	DECL_OP_NOFOLD_FLOAT(log,  "log",   0),
 
 };
 const long op_table3_n = COUNT(op_table3);
@@ -397,12 +375,7 @@
 //	DECL_VOP(cx_vidconj, "C.invconj*",  0,2),
 	DECL_VOP(cx_sqsub,   "C.sq-",   OP_COMM,2),
 	DECL_VOP(cx_abssub,  "C.abs-",  OP_COMM,2),
-	DECL_VOP_NOFOLD_FLOAT(cx_sin,  "C.sin",  0,2),
-	DECL_VOP_NOFOLD_FLOAT(cx_cos,  "C.cos",  0,2),
 //	DECL_VOP_NOFOLD_FLOAT(cx_atan2,"C.atan2",0,2),
-	DECL_VOP_NOFOLD_FLOAT(cx_tanh, "C.tanh", 0,2),
-	DECL_VOP_NOFOLD_FLOAT(cx_exp,  "C.exp",  0,2),
-	DECL_VOP_NOFOLD_FLOAT(cx_log,  "C.log",  0,2),
 	DECL_VOP_NOFOLD(      c2p,     "c2p", 0,2),
 	DECL_VOP_NOFOLD(      p2c,     "p2c", 0,2),
 };



More information about the Gridflow-cvs mailing list