ppc_altivec_util.h
来自「最著名最快的分子模拟软件」· C头文件 代码 · 共 1,756 行 · 第 1/5 页
H
1,756 行
X = vec_perm( X, X, xshift); Y = vec_perm( Y, Y, yshift); return vec_mergel( X, Y ); }/** Load a single float into a single SIMD variable.** This routine loads a floating-point value from memory,* which do not have to be aligned, and returns a SIMD variable * with the value.** @param float1 Pointer to first value.** @return SIMD FP variable with value in lowest element. * Elements 2, 3 and 4 are zeroed.*/static inline vector float load_1_float(float *float1){ vector unsigned char xshift = vec_lvsl( 4, float1 ); vector float X = vec_lde( 0, float1 ); X = vec_perm( X, X, xshift); return vec_sld(X,vec_zero(),12);}/** Store 4 floats from a SIMD variable to 4 different memory locations.** This routine stores four floating-point values to different memory * locations, which do not have to be aligned.** @param v SIMD variable with the values.* @param float1 Pointer to memory where first element will be stored.* @param float2 Pointer to memory where second element will be stored.* @param float3 Pointer to memory where third element will be stored.* @param float4 Pointer to memory where fourth element will be stored.**/static inline void store_4_float(vector float v, float *float1, float *float2, float *float3, float *float4){ vector float e0 = vec_splat(v,0); vector float e1 = vec_splat(v,1); vector float e2 = vec_splat(v,2); vector float f0 = vec_lde( 0, float1 ); vector float f1 = vec_lde( 0, float2 ); vector float f2 = vec_lde( 0, float3 ); vector float f3 = vec_lde( 0, float4 ); v = vec_splat(v,3); e0 = vec_add(e0,f0); e1 = vec_add(e1,f1); e2 = vec_add(e2,f2); v = vec_add(v,f3); vec_ste(e0, 0, float1); vec_ste(e1, 0, float2); vec_ste(e2, 0, float3); vec_ste(v, 0, float4);}/** Store 3 floats from a SIMD variable to 3 different memory locations.** This routine stores three floating-point values to different memory * locations, which do not have to be aligned.** @param v SIMD variable with the values.* @param float1 Pointer to memory where first element will be stored.* @param float2 Pointer to memory where second element will be stored.* @param float3 Pointer to memory where third element will be stored.**/static inline void store_3_float(vector float v, float *float1, float *float2, float *float3){ vector float e0 = vec_splat(v,0); vector float e1 = vec_splat(v,1); vector float f0 = vec_lde( 0, float1 ); vector float f1 = vec_lde( 0, float2 ); vector float f2 = vec_lde( 0, float3 ); v = vec_splat(v,2); e0 = vec_add(e0,f0); e1 = vec_add(e1,f1); v = vec_add(v,f2); vec_ste(e0, 0, float1); vec_ste(e1, 0, float2); vec_ste(v, 0, float3);}/** Store 2 floats from a SIMD variable to 2 different memory locations.** This routine stores two floating-point values to different memory * locations, which do not have to be aligned.** @param v SIMD variable with the values.* @param float1 Pointer to memory where first element will be stored.* @param float2 Pointer to memory where second element will be stored.*/static inline void store_2_float(vector float v, float * float1, float * float2){ vector float e0 = vec_splat(v,0); vector float f0 = vec_lde( 0, float1 ); vector float f1 = vec_lde( 0, float2 ); v = vec_splat(v,1); e0 = vec_add(e0,f0); v = vec_add(v,f1); vec_ste(e0, 0, float1); vec_ste(v, 0, float2);}/** Store first element of SIMD variable to memory.** This routine stores the first floating-point entry of a SIMD variable* to memory, which do not have to be aligned.** @param v SIMD variable with the value.* @param float1 Pointer to memory where first element will be stored.*/static inline void store_1_float(vector float v, float * float1){ vector float f0 = vec_lde( 0, float1 ); v = vec_splat(v,0); v = vec_add(v,f0); vec_ste(v, 0, float1);}/** Load four pairs of floats and store into two SIMD variables. * * This routine is designed to load LJ parameters for four atoms and store in * two vectors, one for c6 and one for c12. * * The vdwparam memory is aligned on an 8-byte boundary and consists * of pairs, so the two parameters are either in the upper or * lower half of a 16-byte structure. The first value in the pair is the c6 * parameter, and the second c12. * * @param pair1 Pointer to LJ parameters for first atom. * @param pair2 Pointer to LJ parameters for second atom. * @param pair3 Pointer to LJ parameters for third atom. * @param pair4 Pointer to LJ parameters for fourth atom. * @param c6 Output: SIMD value with c6 for the four atoms. * @param c12 Output: SIMD value with c12 for the four atoms. */static inline void load_4_pair(float *pair1, float *pair2, float *pair3, float *pair4, vector float *c6, vector float *c12){ vector float X = vec_ld( 0,pair1); /* c6a c12a */ vector float Y = vec_ld( 0,pair2); /* c6b c12b */ vector float Z = vec_ld( 0,pair3); /* c6c c12c */ vector float W = vec_ld( 0,pair4); /* c6d c12d */ vector unsigned char perm1 = vec_lvsl(0,pair1); vector unsigned char perm2 = vec_lvsl(0,pair2); vector unsigned char perm3 = vec_lvsl(0,pair3); vector unsigned char perm4 = vec_lvsl(0,pair4); X = vec_perm(X,X,perm1); Y = vec_perm(Y,Y,perm2); Z = vec_perm(Z,Z,perm3); W = vec_perm(W,W,perm4); X = vec_mergeh(X,Z); /* c6a c6c c12a c12c */ Y = vec_mergeh(Y,W); /* c6b c6d c12b c12d */ *c6 = vec_mergeh(X,Y); *c12 = vec_mergel(X,Y); }/** Load three pairs of floats and store into two SIMD variables.** This routine is designed to load LJ parameters for three atoms and store in * two vectors, one for c6 and one for c12.** The vdwparam memory is aligned on an 8-byte boundary and consists* of pairs, so the two parameters are either in the upper or * lower half of a 16-byte structure. The first value in the pair is the c6* parameter, and the second c12.** @param pair1 Pointer to LJ parameters for first atom.* @param pair2 Pointer to LJ parameters for second atom.* @param pair3 Pointer to LJ parameters for third atom.* @param c6 Output: SIMD value with c6 for the atoms in elements 0-2.* @param c12 Output: SIMD value with c12 for the atoms in elements 0-2.*/static inline void load_3_pair(float *pair1, float *pair2, float *pair3, vector float *c6, vector float *c12){ vector float X = vec_ld( 0,pair1); /* c6a c12a */ vector float Y = vec_ld( 0,pair2); /* c6b c12b */ vector float Z = vec_ld( 0,pair3); /* c6c c12c */ vector unsigned char perm1 = vec_lvsl(0,pair1); vector unsigned char perm2 = vec_lvsl(0,pair2); vector unsigned char perm3 = vec_lvsl(0,pair3); X = vec_perm(X,X,perm1); Y = vec_perm(Y,Y,perm2); Z = vec_perm(Z,Z,perm3); X = vec_mergeh(X,Z); /* c6a c6c c12a c12c */ Y = vec_mergeh(Y,vec_zero()); /* c6b 0 c12b 0 */ *c6 = vec_mergeh(X,Y); *c12 = vec_mergel(X,Y); }/** Load two pairs of floats and store into two SIMD variables.** This routine is designed to load LJ parameters for two atoms and store in * two vectors, one for c6 and one for c12.** The vdwparam memory is aligned on an 8-byte boundary and consists* of pairs, so the two parameters are either in the upper or * lower half of a 16-byte structure. The first value in the pair is the c6* parameter, and the second c12.** @param pair1 Pointer to LJ parameters for first atom.* @param pair2 Pointer to LJ parameters for second atom.* @param c6 Output: SIMD value with c6 for the atoms in elements 0,1.* @param c12 Output: SIMD value with c12 for the atoms in elements 0,1.*/static inline void load_2_pair(float *pair1, float *pair2, vector float *c6, vector float *c12){ vector float X = vec_ld( 0,pair1); /* c6a c12a */ vector float Y = vec_ld( 0,pair2); /* c6b c12b */ vector unsigned char perm1 = vec_lvsl(0,pair1); vector unsigned char perm2 = vec_lvsl(0,pair2); X = vec_perm(X,X,perm1); Y = vec_perm(Y,Y,perm2); X = vec_mergeh(X,vec_zero()); /* c6a 0 c12a 0 */ Y = vec_mergeh(Y,vec_zero()); /* c6b 0 c12b 0 */ *c6 = vec_mergeh(X,Y); *c12 = vec_mergel(X,Y); }/** Load a pair of floats and store into two SIMD variables.** This routine is designed to load LJ parameters for a single atom and store in * two vectors, one for c6 and one for c12.** The vdwparam memory is aligned on an 8-byte boundary and consists* of pairs, so the two parameters are either in the upper or * lower half of a 16-byte structure. The first value in the pair is the c6* parameter, and the second c12.** @param pair1 Pointer to LJ parameters for atom.* @param c6 Output: SIMD value with c6 for the atom in lowest element.* @param c12 Output: SIMD value with c12 for the atom in lowest element.*/static inline void load_1_pair(float *pair1, vector float *c6, vector float *c12){ vector float X = vec_ld( 0,pair1); /* c6a c12a */ vector unsigned char perm1 = vec_lvsl(0,pair1); X = vec_perm(X,X,perm1); X = vec_mergeh(X,vec_zero()); /* c6a 0 c12a 0 */ *c6 = vec_mergeh(X,vec_zero()); *c12 = vec_mergel(X,vec_zero()); } /** Spread a coordinate triplet to three separate vectors. * * This routine permutes a SIMD variable [x y z ?] into three separate * variables: [x x x x] [y y y y] [z z z z] . * * * @param xyzreg SIMD variable containing [x y z ?] * @param xreg Output: SIMD variable [x x x x] * @param yreg Output: SIMD variable [y y y y] * @param zreg Output: SIMD variable [z z z z] */static inline void splat_xyz_to_vectors(vector float xyzreg, vector float *xreg, vector float *yreg, vector float *zreg){ *zreg = vec_splat(xyzreg,2); *yreg = vec_splat(xyzreg,1); *xreg = vec_splat(xyzreg,0);}/* The following transpose routines do not fill with zero padding: * * 1_to_3 * 2_to_3 * 1_to_4 * 2_to_4 * * ...but the rest do. *//** Transpose four coordinate triplets into common X/Y/Z variables.** This routine permutes four SIMD variables [x y z ?] into * [x1 x2 x3 x4] [y1 y2 y3 y4] [z1 z2 z3 z4] ** @param xyz1 SIMD variable containing first coordinate triplet.* @param xyz2 SIMD variable containing second coordinate triplet.* @param xyz3 SIMD variable containing third coordinate triplet.* @param xyz4 SIMD variable containing fourth coordinate triplet.* @param xvector Output: SIMD variable [x1 x2 x3 x4]* @param yvector Output: SIMD variable [y1 y2 y3 y4]* @param zvector Output: SIMD variable [z1 z2 z3 z4]*/
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?