説明を見る。00001
00002
00003 #ifndef EVAL_CONTAINER_QUAD_INT_H
00004 #define EVAL_CONTAINER_QUAD_INT_H
00005
00006 #include "osl/config.h"
00007 #include "osl/container.h"
00008 #include "osl/bits/align16New.h"
00009
00010 #if (defined __INTEL_COMPILER || defined __clang__)
00011 # include <emmintrin.h>
00012 # ifdef __INTEL_COMPILER
00013 # define __builtin_ia32_pxor128 _mm_xor_pd
00014 # endif
00015 # define __builtin_ia32_psubd128 _mm_sub_epi32
00016 # define __builtin_ia32_paddd128 _mm_add_epi32
00017 #endif
00018
00019 #ifndef OSL_NO_SSE
00020 #if (defined __x86_64__) || (defined __i386__)
00021 # ifndef OSL_USE_SSE
00022 # define OSL_USE_SSE 1
00023 # endif
00024 #else
00025 # warning "QuadInt without SSE"
00026 #endif
00027 #endif
00028
00029 namespace osl
00030 {
00031 namespace container
00032 {
00033 #ifdef OSL_USE_SSE
00034 # ifdef __INTEL_COMPILER
00035 typedef __v4si v4si;
00036 typedef __v2di v2di;
00037 # else
00038 typedef int v4si __attribute__ ((vector_size (16)));
00039 typedef long long v2di __attribute__ ((vector_size (16)));
00040 # endif
00041 #endif
00042 struct QuadInt : public misc::Align16New
00043 {
00044 union XMM{
00045 CArray<int,4> iv;
00046 CArray<long long,2> llv;
00047 #ifdef OSL_USE_SSE
00048 v4si v4;
00049 v2di v2;
00050 #endif
00051 } v
00052 #ifdef OSL_USE_SSE
00053 __attribute__((aligned(16)))
00054 #endif
00055 ;
00056 QuadInt(){
00057 clear();
00058 }
00059 QuadInt(QuadInt const& si){
00060 #if OSL_USE_SSE
00061 v.v4=si.v.v4;
00062 #else
00063 v.llv = si.v.llv;
00064 #endif
00065 }
00066 QuadInt& operator=(QuadInt const& si)
00067 {
00068 #if OSL_USE_SSE
00069 v.v4=si.v.v4;
00070 #else
00071 v.llv = si.v.llv;
00072 #endif
00073 return *this;
00074 }
00075 void clear()
00076 {
00077 #if OSL_USE_SSE
00078 v.v4=(v4si){ 0, 0, 0, 0 };
00079 #else
00080 v.llv[0] = v.llv[1] = 0;
00081 #endif
00082 }
00083 int& operator[](int i) {
00084 return v.iv[i];
00085 }
00086 const int& operator[](int i) const {
00087 return v.iv[i];
00088 }
00089 QuadInt operator-() const{
00090 QuadInt ret;
00091 ret -= *this;
00092 return ret;
00093 }
00094 QuadInt& operator+=(QuadInt const& si){
00095 #if OSL_USE_SSE
00096 v.v4=__builtin_ia32_paddd128(v.v4,si.v.v4);
00097 #else
00098 for(int i=0;i<4;i++) v.iv[i]+=si.v.iv[i];
00099 #endif
00100 return *this;
00101 }
00102 QuadInt& operator-=(QuadInt const& si){
00103 #if OSL_USE_SSE
00104 v.v4=__builtin_ia32_psubd128(v.v4,si.v.v4);
00105 #else
00106 for(int i=0;i<4;i++) v.iv[i]-=si.v.iv[i];
00107 #endif
00108 return *this;
00109 }
00110 QuadInt& operator*=(int scale){
00111 #if OSL_USE_SSE41
00112 XMM val;
00113 unsigned long long scalescale=(unsigned long long )((unsigned int)scale);
00114 scalescale|=scalescale<<32ull;
00115 val.v2=__builtin_ia32_vec_set_v2di(val.v2,(long long)scalescale,0);
00116 val.v2=__builtin_ia32_vec_set_v2di(val.v2,(long long)scalescale,1);
00117 v.v4=__builtin_ia32_pmulld128(v.v4,val.v4);
00118 #else
00119 for(int i=0;i<4;i++) v.iv[i]*=scale;
00120 #endif
00121 return *this;
00122 }
00123 static size_t size() { return 4; }
00124 };
00125 inline QuadInt operator+(QuadInt const& si0,QuadInt const& si1)
00126 {
00127 QuadInt ret(si0);
00128 ret+=si1;
00129 return ret;
00130 }
00131 inline QuadInt operator-(QuadInt const& si0,QuadInt const& si1)
00132 {
00133 QuadInt ret(si0);
00134 ret-=si1;
00135 return ret;
00136 }
00137 inline QuadInt operator*(QuadInt const& si0,int scale)
00138 {
00139 QuadInt ret(si0);
00140 ret*=scale;
00141 return ret;
00142 }
00143 inline bool operator==(QuadInt const& l,QuadInt const& r)
00144 {
00145 return l.v.llv[0] == r.v.llv[0] && l.v.llv[1] == r.v.llv[1];
00146 }
00147 inline bool operator<(QuadInt const& l,QuadInt const& r)
00148 {
00149 if (l.v.llv[0] != r.v.llv[0])
00150 return (l.v.llv[0] < r.v.llv[0]);
00151 return l.v.llv[1] < r.v.llv[1];
00152 }
00153
00154 class QuadIntPair
00155 {
00156 CArray<QuadInt,2> v;
00157 public:
00158 QuadIntPair() {}
00159 const QuadInt& operator[](int i) const{
00160 return v[i];
00161 }
00162 const QuadInt& operator[](Player pl) const{
00163 return v[pl];
00164 }
00165 QuadInt& operator[](int i){
00166 return v[i];
00167 }
00168 QuadInt& operator[](Player pl){
00169 return v[pl];
00170 }
00171 QuadIntPair& operator+=(QuadIntPair const& a){
00172 v[0]+=a.v[0];
00173 v[1]+=a.v[1];
00174 return *this;
00175 }
00176 QuadIntPair& operator-=(QuadIntPair const& a){
00177 v[0]-=a.v[0];
00178 v[1]-=a.v[1];
00179 return *this;
00180 }
00181 };
00182 inline QuadIntPair operator+(QuadIntPair const& si0,QuadIntPair const& si1)
00183 {
00184 QuadIntPair ret(si0);
00185 ret+=si1;
00186 return ret;
00187 }
00188 inline QuadIntPair operator-(QuadIntPair const& si0,QuadIntPair const& si1)
00189 {
00190 QuadIntPair ret(si0);
00191 ret-=si1;
00192 return ret;
00193 }
00194 inline bool operator==(QuadIntPair const& l,QuadIntPair const& r)
00195 {
00196 return l[0] == r[0] && l[1] == r[1];
00197 }
00198 }
00199
00200 using container::QuadInt;
00201 using container::QuadIntPair;
00202 }
00203 #endif // EVAL_CONTAINER_QUAD_INT_H
00204
00205
00206
00207