ppc_altivec_util.h
来自「最著名最快的分子模拟软件」· C头文件 代码 · 共 1,756 行 · 第 1/5 页
H
1,756 行
static inline void transpose_4_to_3(vector float xyz1, vector float xyz2, vector float xyz3, vector float xyz4, vector float *xvector, vector float *yvector, vector float *zvector){ *yvector = vec_mergeh(xyz1,xyz3); /* [x1 x3 y1 y3] */ *zvector = vec_mergeh(xyz2,xyz4); /* [x2 x4 y2 y4] */ xyz1 = vec_mergel(xyz1,xyz3); /* [z1 z3 ? ?] */ xyz2 = vec_mergel(xyz2,xyz4); /* [z2 z4 ? ?] */ *xvector = vec_mergeh(*yvector,*zvector); /* [x1 x2 x3 x4] */ *yvector = vec_mergel(*yvector,*zvector); /* [y1 y2 y3 y4] */ *zvector = vec_mergeh(xyz1,xyz2); /* [z1 z2 z3 z4] */}/** Transpose two coordinate triplets into common X/Y/Z variables.** This routine permutes two SIMD variables [x y z ?] into * [x1 x2 ? ?] [y1 y2 ? ?] [z1 z2 ? ?] *** @param xyz1 SIMD variable containing first coordinate triplet.* @param xyz2 SIMD variable containing second coordinate triplet.* @param xvector Output: SIMD variable [x1 x2 ? ?]* @param yvector Output: SIMD variable [y1 y2 ? ?]* @param zvector Output: SIMD variable [z1 z2 ? ?]*/static inline void transpose_2_to_3(vector float xyz1, vector float xyz2, vector float *xvector, vector float *yvector, vector float *zvector){ *xvector = vec_mergeh(xyz1,xyz2); /* x1 x2 y1 y2 */ *zvector = vec_mergel(xyz1,xyz2); /* z1 z2 ? ? */ *yvector = vec_sld(*xvector,*xvector,8); /* y1 y2 0 0 */}/** Transpose a single coordinate triplets into separate X/Y/Z variables.** This routine permutes a SIMD variablea [x y z ?] into * [x1 ? ? ?] [y1 ? ? ?] [z1 ? ? ?] *** @param xyz1 SIMD variable containing coordinate triplet.* @param xvector Output: SIMD variable [x1 ? ? ?]* @param yvector Output: SIMD variable [y1 ? ? ?]* @param zvector Output: SIMD variable [z1 ? ? ?]*/static inline void transpose_1_to_3(vector float xyz1, vector float *xvector, vector float *yvector, vector float *zvector){ /* simply use splat, since elem 2,3,4 dont matter. */ *xvector = vec_splat(xyz1,0); /* x1 x1 x1 x1 */ *yvector = vec_splat(xyz1,1); /* y1 y1 y1 y1 */ *zvector = vec_splat(xyz1,2); /* z1 z1 z1 z1 */}/** Transpose three separate X/Y/Z variables into 4 coordinate triplets.** This routine permutes three separate SIMD coordinate vectors * [x1 x2 x3 x4] [y1 y2 y3 y4] [z1 z2 z3 z4] into 4 triplets [x y z 0].** The fourth position of the output triplets will be set to zero.** @param xvector SIMD variable [x1 x2 x3 x4]* @param yvector SIMD variable [y1 y2 y3 y4]* @param zvector SIMD variable [z1 z2 z3 z4]* @param xyz1 Output: SIMD variable containing first coordinate triplet.* @param xyz2 Output: SIMD variable containing second coordinate triplet.* @param xyz3 Output: SIMD variable containing third coordinate triplet.* @param xyz4 Output: SIMD variable containing fourth coordinate triplet.*/static inline void transpose_3_to_4(vector float xvector, vector float yvector, vector float zvector, vector float *xyz1, vector float *xyz2, vector float *xyz3, vector float *xyz4){ vector float tmp1,tmp2; vector float nul=vec_zero(); *xyz2 = vec_mergeh(xvector,zvector); /* [x1 z1 x2 z2 ] */ tmp1 = vec_mergeh(yvector,nul); /* [y1 0 y2 0 ] */ *xyz4 = vec_mergel(xvector,zvector); /* [x3 z3 x4 z4 ] */ tmp2 = vec_mergel(yvector,nul); /* [y3 0 y4 0 ] */ *xyz1 = vec_mergeh(*xyz2,tmp1); /* [x1 y1 z1 0 ] */ *xyz2 = vec_mergel(*xyz2,tmp1); /* [x2 y2 z2 0 ] */ *xyz3 = vec_mergeh(*xyz4,tmp2); /* [x3 y3 z3 0 ] */ *xyz4 = vec_mergel(*xyz4,tmp2); /* [x4 y4 z4 0 ] */}/** Transpose three separate X/Y/Z variables into 2 coordinate triplets.** This routine permutes three separate SIMD coordinate vectors * [x1 x2 ? ?] [y1 y2 ? ?] [z1 z2 ? ?] into 2 triplets [x y z 0].** The fourth position of the output triplets will be set to zero.** @param xvector SIMD variable [x1 x2 ? ?]* @param yvector SIMD variable [y1 y2 ? ?]* @param zvector SIMD variable [z1 z2 ? ?]* @param xyz1 Output: SIMD variable containing first coordinate triplet.* @param xyz2 Output: SIMD variable containing second coordinate triplet.*/static inline void transpose_3_to_2(vector float xvector, vector float yvector, vector float zvector, vector float *xyz1, vector float *xyz2){ vector float tmp1; *xyz2 = vec_mergeh(xvector,zvector); /* [x1 z1 x2 z2 ] */ tmp1 = vec_mergeh(yvector,vec_zero()); /* [y1 0 y2 0 ] */ *xyz1 = vec_mergeh(*xyz2,tmp1); /* [x1 y1 z1 0 ] */ *xyz2 = vec_mergel(*xyz2,tmp1); /* [x2 y2 z2 0 ] */}/** Transpose three separate X/Y/Z variables into a single coordinate triplet.** This routine permutes three separate SIMD coordinate vectors * [x1 ? ? ?] [y1 ? ? ?] [z1 ? ? ?] into a single triplet [x y z 0].** The fourth position of the output triplet will be set to zero.** @param xvector SIMD variable [x1 ? ? ?]* @param yvector SIMD variable [y1 ? ? ?]* @param zvector SIMD variable [z1 ? ? ?]* @param xyz1 Output: SIMD variable containing coordinate triplet.*/static inline void transpose_3_to_1(vector float xvector, vector float yvector, vector float zvector, vector float *xyz1){ *xyz1 = vec_mergeh(xvector,zvector); /* [x1 z1 ? ? ] */ yvector = vec_mergeh(yvector,vec_zero()); /* [y1 0 ? 0] */ *xyz1 = vec_mergeh(*xyz1,yvector); /* [x1 y1 z1 0] */}/** Full 4-to-4 transpose of SIMD variables.** If the input SIMD vectors are pictured as rows in a 4x4 matrix, the output* result will be the column vectors of the same matrix.** @param in1 First row vector.* @param in2 Second row vector.* @param in3 Third row vector.* @param in4 Fourth row vector.* @param out1 Output: First column vector.* @param out2 Output: Second column vector.* @param out3 Output: Third column vector.* @param out4 Output: Fourth column vector.*/static inline void transpose_4_to_4(vector float in1, vector float in2, vector float in3, vector float in4, vector float *out1, vector float *out2, vector float *out3, vector float *out4){ *out2 = vec_mergeh(in1,in3); /* [x1 x3 y1 y3] */ *out3 = vec_mergeh(in2,in4); /* [x2 x4 y2 y4] */ in1 = vec_mergel(in1,in3); /* [z1 z3 w1 w3] */ in2 = vec_mergel(in2,in4); /* [z2 z4 w2 w4] */ *out1 = vec_mergeh(*out2,*out3); /* [x1 x2 x3 x4] */ *out2 = vec_mergel(*out2,*out3); /* [y1 y2 y3 y4] */ *out3 = vec_mergeh(in1,in2); /* [z1 z2 z3 z4] */ *out4 = vec_mergel(in1,in2); /* [w1 w2 w3 w4] */ }/** Transpose the first two elements of 4 SIMD variables to new variables.** If the input SIMD vectors are pictured as rows in a 4x4 matrix, the output* result will be the first two column vectors of the same matrix.** @param in1 First row vector.* @param in2 Second row vector.* @param in3 Third row vector.* @param in4 Fourth row vector.* @param out1 Output: First column vector.* @param out2 Output: Second column vector.*/static inline void transpose_4_to_2(vector float in1, vector float in2, vector float in3, vector float in4, vector float *out1, vector float *out2){ vector float tmp; tmp = vec_mergeh(in1,in3); /* [x1 x3 y1 y3] */ *out2 = vec_mergeh(in2,in4); /* [x2 x4 y2 y4] */ *out1 = vec_mergeh(tmp,*out2); /* [x1 x2 x3 x4] */ *out2 = vec_mergel(tmp,*out2); /* [y1 y2 y3 y4] */ }/** Transpose the first element of 4 SIMD variables to new variables.** If the input SIMD vectors are pictured as rows in a 4x4 matrix, the output* result will be the first column vector of the same matrix.** @param in1 First row vector.* @param in2 Second row vector.* @param in3 Third row vector.* @param in4 Fourth row vector.* @param out1 Output: First column vector.*/static inline void transpose_4_to_1(vector float in1, vector float in2, vector float in3, vector float in4, vector float *out1){ vector float tmp; tmp = vec_mergeh(in1,in3); /* [x1 x3 ? ?] */ *out1 = vec_mergeh(in2,in4); /* [x2 x4 ? ?] */ *out1 = vec_mergeh(tmp,*out1); /* [x1 x2 x3 x4] */ }/** Transpose two SIMD variables into the two first elements of 4 new ones.** If the input SIMD vectors are pictured as the two first rows in a 4x4 matrix, * the output result will be the column column vectors of the same matrix.** @param in1 First row vector.* @param in2 Second row vector.* @param out1 Output: First column vector.* @param out2 Output: Second column vector.* @param out3 Output: Third column vector.* @param out4 Output: Fourth column vector.*/static inline void transpose_2_to_4(vector float in1, vector float in2, vector float *out1, vector float *out2, vector float *out3, vector float *out4){ *out1 = vec_mergeh(in1,in2); /* [x1 x2 y1 y2] */ *out3 = vec_mergel(in1,in2); /* [z1 z2 w1 w2] */ *out2 = vec_sld(*out1,*out1,8);/* [y1 y2 0 0] */ *out4 = vec_sld(*out3,*out3,8);/* [w1 w2 0 0] */ }/** Transpose a SIMD variable into the first element of 4 new ones.** If the input SIMD vectors are pictured as the first row in a 4x4 matrix, * the output result will be the column column vectors of the same matrix.** @param in1 First row vector.* @param out1 Output: First column vector.* @param out2 Output: Second column vector.* @param out3 Output: Third column vector.* @param out4 Output: Fourth column vector.*/static inline voidtranspose_1_to_4(vector float in1, vector float *out1, vector float *out2, vector float *out3, vector float *out4){ *out1 = vec_splat(in1,0); /* [x1 x1 x1 x1] */ *out2 = vec_splat(in1,1); /* [y1 y1 y1 y1] */ *out3 = vec_splat(in1,2); /* [z1 z1 z1 z1] */ *out4 = vec_splat(in1,3); /* [w1 w1 w1 w1] */}/** Add first three elements of a SIMD variable to three memory values. * * This routine adds each of the three lowest elements in a FP SIMD variable * to a corresponding location in (unaligned). Note that we do not accumulate * the SIMD entries - three separate values in the SIMD variable are added to * three separate (but adjacent) memory locations. * * @param address Pointer to the float triplet in memory to add to. * @param vdata SIMD variable whose three lowest elements should be added * to corresponding positions in memory. */static inline void add_xyz_to_mem(float * address, vector float vdata){ vector float c1,c2,c3; c1 = vec_lde( 0, address); c2 = vec_lde( 4, address); c3 = vec_lde( 8, address); c1 = vec_add(c1,vec_splat(vdata,0)); c2 = vec_add(c2,vec_splat(vdata,1)); c3 = vec_add(c3,vec_splat(vdata,2)); vec_ste( c1, 0, address); vec_ste( c2, 4, address); vec_ste( c3, 8, address);}/** Add the elements of a SIMD variable to four memory values.** This routine adds each of the elements in a FP SIMD variable* to a corresponding location in (unaligned). Note that we do not accumulate* the SIMD entries - the separate values in the SIMD variable are added to * four separate (but adjacent) memory locations.** @param address Pointer to the 4 float values in memory to add to.* @param vdata SIMD variable whose elements should be added* to corresponding positions in memory.*/static inline void add_vector_to_float(float * address,
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?