From f414ccc404b5a88f5274b7c443080ffd19e2e8e4 Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Sun, 6 Dec 2015 10:07:31 -0800 Subject: [PATCH] make Dumber and vector_simple even --- crap/mugi4.hpp | 2 +- include/Dumber.hpp | 94 ++++++++++++++++++++------------------ include/vectors_simple.hpp | 27 +---------- 3 files changed, 53 insertions(+), 70 deletions(-) diff --git a/crap/mugi4.hpp b/crap/mugi4.hpp index c384eba..44926c3 100644 --- a/crap/mugi4.hpp +++ b/crap/mugi4.hpp @@ -71,7 +71,7 @@ struct mugi4 { v2df sum = in + sumback1; v2df pre = -fd.p0*sum; - v2df temp = tanh2(pre/VT2); + v2df temp = tanh2(pre/v2df(VT2)); s1.process(fd, temp); s2.process(fd, s1.dout); s3.process(fd, s2.dout); diff --git a/include/Dumber.hpp b/include/Dumber.hpp index c70c996..4bcc481 100644 --- a/include/Dumber.hpp +++ b/include/Dumber.hpp @@ -18,59 +18,65 @@ struct DumberBase { DumberBase(const DumberBase &x) { v = x.v; } - inline DumberBase& - operator=(const DumberBase& v2) { - v = v2.v; - return *this; - } + friend inline DumberBase + operator-(const DumberBase &a) + { return -a.v; } - inline DumberBase - operator-() - { return -v; } + friend inline DumberBase + operator+(const DumberBase &a, const DumberBase &b) + { return a.v + b.v; } - inline DumberBase - operator+(const DumberBase &v2) - { return v + v2.v; } + friend inline DumberBase + operator-(const DumberBase &a, const DumberBase &b) + { return a.v - b.v; } - inline DumberBase - operator-(const DumberBase &v2) - { return v - v2.v; } + friend inline DumberBase + operator*(const DumberBase &a, const DumberBase &b) + { return a.v*b.v; } - inline DumberBase - operator*(const DumberBase &v2) - { return v*v2.v; } + friend inline DumberBase + operator/(const DumberBase &a, const DumberBase &b) + { return a.v/b.v; } - inline DumberBase - operator/(const DumberBase &v2) - { return v/v2.v; } + inline DumberBase & + operator+=(const DumberBase &a) + { v += a.v; return *this; } - inline DumberBase& - operator+=(const DumberBase &v2) - { - v = v + v2.v; - return *this; - } + inline DumberBase & + operator-=(const DumberBase &a) + { v -= a.v; return *this; } - inline DumberBase& - operator-=(const DumberBase &v2) - { - v = v - v2.v; - return *this; - } + inline DumberBase & + operator*=(const DumberBase &a) + { v *= a.v; return *this; } - inline DumberBase& - operator*=(const DumberBase &v2) - { - v = v*v2.v; - return *this; - } + inline DumberBase & + operator/=(const DumberBase &a) + { v /= a.v; return *this; } - inline DumberBase& - operator/=(const DumberBase &v2) - { - v = v/v2.v; - return *this; - } + friend inline DumberBase + operator&(const DumberBase &a, const DumberBase &b) + { return a.v & b.v; } + + friend inline DumberBase + operator|(const DumberBase &a, const DumberBase &b) + { return a.v | b.v; } + + friend inline DumberBase + operator^(const DumberBase &a, const DumberBase &b) + { return a.v ^ b.v; } + + friend inline DumberBase + operator<(const DumberBase &a, const DumberBase &b) + { return a.v < b.v; } + + friend inline DumberBase + operator>(const DumberBase &a, const DumberBase &b) + { return a.v > b.v; } + + friend inline DumberBase + operator==(const DumberBase &a, const DumberBase &b) + { return a.v == b.v; } }; TEMPLATE diff --git a/include/vectors_simple.hpp b/include/vectors_simple.hpp index c958bbc..ae8390a 100755 --- a/include/vectors_simple.hpp +++ b/include/vectors_simple.hpp @@ -1,3 +1,4 @@ +// mostly via http://charm.cs.uiuc.edu/doxygen/charm/SSE-Double_8h-source.shtml #include typedef __m128d _v2df; typedef __m64 _v2sf; @@ -39,22 +40,6 @@ struct v2df { sqrt(const v2df &a) { v2df c; c.v = _mm_sqrt_pd(a.v); return c; } - friend inline v2df - operator+(double a, const v2df &b) - { v2df c; c.v = _mm_add_pd(_mm_set1_pd(a),b.v); return c; } - - friend inline v2df - operator-(double a, const v2df &b) - { v2df c; c.v = _mm_sub_pd(_mm_set1_pd(a),b.v); return c; } - - friend inline v2df - operator*(double a, const v2df &b) - { v2df c; c.v = _mm_mul_pd(_mm_set1_pd(a),b.v); return c; } - - friend inline v2df - operator/(double a, const v2df &b) - { v2df c; c.v = _mm_div_pd(_mm_set1_pd(a),b.v); return c; } - inline v2df & operator+=(const v2df &a) { v = _mm_add_pd(v,a.v); return *this; } @@ -100,15 +85,7 @@ struct v2df { { v2df c; c.v = _mm_cmpeq_pd(a.v,b.v); return c; } friend inline v2df - operator<(const v2df &a, double b) - { v2df c; c.v = _mm_cmplt_pd(a.v,_mm_set1_pd(b)); return c; } - - friend inline v2df - operator>(const v2df &a, double b) - { v2df c; c.v = _mm_cmpgt_pd(a.v,_mm_set1_pd(b)); return c; } - - friend inline v2df - max(const v2df &a, v2df &b) + max(const v2df &a, const v2df &b) { v2df c; c.v = _mm_max_pd(a.v,b.v); return c; } inline double &