diff --git a/src/spicelib/devices/bsim3v32/b3v32ldseq.c b/src/spicelib/devices/bsim3v32/b3v32ldseq.c index b7669a3a2..fba6c72a3 100644 --- a/src/spicelib/devices/bsim3v32/b3v32ldseq.c +++ b/src/spicelib/devices/bsim3v32/b3v32ldseq.c @@ -78,25 +78,6 @@ typedef int BSIM3v32model; #define powMJSW(x,p) mypow(x,p) #define powMJSWG(x,p) mypow(x,p) -#if 0 -#ifdef NEWCONV -#pragma message "NEWCONV" -#else -#pragma message "no NEWCONV" -#endif - -#ifdef NOBYPASS -#pragma message "NOBYPASS" -#else -#pragma message "no NOBYPASS" -#endif -#ifdef PREDICTOR -#pragma message "PREDICTOR" -#else -#pragma message "no PREDICTOR" -#endif -#endif - int BSIM3v32_ACM_saturationCurrents ( BSIM3v32model *model, diff --git a/src/spicelib/devices/bsim3v32/b3v32ldsimd.c b/src/spicelib/devices/bsim3v32/b3v32ldsimd.c index 4ccd70c59..ef0aaf3ac 100644 --- a/src/spicelib/devices/bsim3v32/b3v32ldsimd.c +++ b/src/spicelib/devices/bsim3v32/b3v32ldsimd.c @@ -29,7 +29,9 @@ ******************************************************************************/ #include +#if USEX86INTRINSICS==1 #include +#endif #include #include "ngspice/ngspice.h" @@ -53,274 +55,18 @@ #define DELTA_3 0.02 #define DELTA_4 0.02 -typedef double Vec4d __attribute__ ((vector_size (sizeof(double)*4), aligned (sizeof(double)*4))); -typedef int64_t Vec4m __attribute__ ((vector_size (sizeof(double)*4), aligned (sizeof(double)*4))); - - #define SIMDANY(err) (err!=0) #define SIMDIFYCMD(cmd) /* empty */ #define SIMDifySaveScope(sc) /* empty */ -#if USEX86INTRINSICS==1 -static inline Vec4d vec4_blend(Vec4d fa, Vec4d tr, Vec4m mask) -{ - return _mm256_blendv_pd(fa,tr, (Vec4d) mask); -} -#else -static inline Vec4d vec4_blend(Vec4d fa, Vec4d tr, Vec4m mask) -{ - Vec4d r; - //#pragma omp simd - for(int i=0;i<4;i++) - r[i] = (mask[i]==0 ? fa[i] : tr[i]); - return r; -} +#if NSIMD==4 +#include "b3v32ldsimd4d.c" #endif -static inline Vec4d vec4_exp(Vec4d x) -{ - Vec4d r; - //#pragma omp simd - for(int i=0;i<4;i++) - r[i] = exp(x[i]); - return r; -} - -static inline Vec4d vec4_log(Vec4d x) -{ - Vec4d r; - //#pragma omp simd - for(int i=0;i<4;i++) - r[i] = log(x[i]); - return r; -} - -static inline Vec4d vec4_max(Vec4d x, Vec4d y) -{ - Vec4d r; - //#pragma omp simd - for(int i=0;i<4;i++) - r[i] = MAX(x[i],y[i]); - return r; -} - -static inline Vec4d vec4_sqrt(Vec4d x) -{ - Vec4d r; - //#pragma omp simd - for(int i=0;i<4;i++) - r[i] = sqrt(x[i]); - return r; -} - -static inline Vec4d vec4_fabs(Vec4d x) -{ - Vec4d r; - //#pragma omp simd - for(int i=0;i<4;i++) - r[i] = fabs(x[i]); - return r; -} - -#define vec4_pow0p7(x,p) vec4_pow(x,p) -#define vec4_powMJ(x,p) vec4_pow(x,p) -#define vec4_powMJSW(x,p) vec4_pow(x,p) -#define vec4_powMJSWG(x,p) vec4_pow(x,p) - -static inline Vec4d vec4_pow(Vec4d x, double p) -{ - return vec4_exp(vec4_log(x)*p); -} - -/* useful vectorized functions */ -static inline Vec4d vec4_SIMDTOVECTOR(double val) -{ - Vec4d r; - //#pragma omp simd - for(int i=0;i<4;i++) - r[i] = val; - return r; -} - -static inline Vec4m vec4_SIMDTOVECTORMASK(int val) -{ - Vec4m r; - //#pragma omp simd - for(int i=0;i<4;i++) - r[i] = val; - return r; -} -static inline Vec4d uuvec4_SIMDTOVECTOR(double val) -{ - return (Vec4d) {val,val,val,val}; -} - -static inline Vec4m uuvec4_SIMDTOVECTORMASK(int val) -{ - return (Vec4m) {val,val,val,val}; -} -/* TODO: prefix with vec4_ */ -static inline Vec4d SIMDLOADDATA(int idx, double data[7][4]) -{ - return (Vec4d) {data[idx][0],data[idx][1],data[idx][2],data[idx][3]}; -} - -static inline Vec4d vec4_BSIM3v32_StateAccess(double* cktstate, Vec4m stateindexes) -{ - Vec4d r; - //#pragma omp simd - for(int i=0;i<4;i++) - r[i] = cktstate[stateindexes[i]]; - return r; - - /*return (Vec4d) { - cktstate[stateindexes[0]], - cktstate[stateindexes[1]], - cktstate[stateindexes[2]], - cktstate[stateindexes[3]] - };"*/ -} - - -static inline void vec4_BSIM3v32_StateStore(double* cktstate, Vec4m stateindexes, Vec4d values) -{ - /*if(0) vec4_CheckCollisions(stateindexes,"SateStore");*/ - //#pragma omp simd - for(int idx=0;idx<4;idx++) - { - cktstate[stateindexes[idx]] = values[idx]; - } -} - -static inline void vec4_BSIM3v32_StateAdd(double* cktstate, Vec4m stateindexes, Vec4d values) -{ - /*if(0) vec4_CheckCollisions(stateindexes,"StateAdd");*/ - //#pragma omp simd - for(int idx=0;idx<4;idx++) - { - cktstate[stateindexes[idx]] += values[idx]; - } -} - -static inline void vec4_BSIM3v32_StateSub(double* cktstate, Vec4m stateindexes, Vec4d values) -{ - /*if(0) vec4_CheckCollisions(stateindexes,"StateSub");*/ - //#pragma omp simd - for(int idx=0;idx<4;idx++) - { - cktstate[stateindexes[idx]] -= values[idx]; - } -} - -static inline int vec4_BSIM3v32_ACM_saturationCurrents -( - BSIM3v32model *model, - BSIM3v32instance **heres, - Vec4d *DrainSatCurrent, - Vec4d *SourceSatCurrent -) -{ - int error; - double dsat,ssat; - for(int idx=0;idx<4;idx++) - { - error = BSIM3v32_ACM_saturationCurrents( - model, heres[idx], - &dsat, - &ssat - ); - (*DrainSatCurrent)[idx] = dsat; - (*SourceSatCurrent)[idx] = ssat; - if(error) return error; - } - return error; -} - -static inline int vec4_BSIM3v32_ACM_junctionCapacitances( - BSIM3v32model *model, - BSIM3v32instance **heres, - Vec4d *areaDrainBulkCapacitance, - Vec4d *periDrainBulkCapacitance, - Vec4d *gateDrainBulkCapacitance, - Vec4d *areaSourceBulkCapacitance, - Vec4d *periSourceBulkCapacitance, - Vec4d *gateSourceBulkCapacitance - -) -{ - int error; - double areaDB,periDB,gateDB,areaSB,periSB,gateSB; - - for(int idx=0;idx<4;idx++) - { - error = BSIM3v32_ACM_junctionCapacitances( - model, heres[idx], - &areaDB, - &periDB, - &gateDB, - &areaSB, - &periSB, - &gateSB - ); - (*areaDrainBulkCapacitance)[idx]=areaDB; - (*periDrainBulkCapacitance)[idx]=periDB; - (*gateDrainBulkCapacitance)[idx]=gateDB; - (*areaSourceBulkCapacitance)[idx]=areaSB; - (*periSourceBulkCapacitance)[idx]=periSB; - (*gateSourceBulkCapacitance)[idx]=gateSB; - if(error) return error; - } - return error; -} - -/* geq, ceq, and zero are not translated to vectors because there are unused */ -static inline int vec4_NIintegrate(CKTcircuit* ckt, double* geq, double *ceq, double zero, Vec4m chargestate) -{ - int error; - /*if (0) vec4_CheckCollisions(chargestate, "NIIntegrate");*/ - for(int idx=0;idx<4;idx++) - { - error = NIintegrate(ckt,geq,ceq,zero,chargestate[idx]); - if(error) return error; - } - return error; -} - -static inline int vec4_SIMDCOUNT(Vec4m mask) { - return (mask[0] ? 1 : 0) + (mask[1] ? 1 : 0) + (mask[2] ? 1 : 0) + (mask[3] ? 1 : 0); -} - - - -/* some debug utils functions */ -void vec4_printd(const char* msg, const char* name, Vec4d vecd) -{ - printf("%s %s %g %g %g %g\n",msg,name,vecd[0],vecd[1],vecd[2],vecd[3]); -} - -void vec4_printm(const char* msg, const char* name, Vec4m vecm) -{ - printf("%s %s %ld %ld %ld %ld\n",msg,name,vecm[0],vecm[1],vecm[2],vecm[3]); -} - -void vec4_CheckCollisions(Vec4m stateindexes, const char* msg) -{ - for(int i=0;i<4;i++) - for(int j=0;j<4;j++) - if(i!=j) - if(stateindexes[i]==stateindexes[j]) - { - printf("%s, collisions %ld %ld %ld %ld!\n",msg,stateindexes[0],stateindexes[1],stateindexes[2],stateindexes[3]); - raise(SIGINT); - } -} - #if NSIMD==8 #include "b3v32ldsimd8d.c" #endif -typedef float vecelem_t; - int BSIM3v32LoadSIMD(BSIM3v32instance **heres, CKTcircuit *ckt #ifndef USE_OMP , double data[7][NSIMD]