5.1.1.2.2 : Le fichier source
Écrivons le fichier function_vectorize.cpp :
Nous commençons par inclure le header de la bibliothèque standard de math :
1 2 |
#include <cmath> #include "phoenix_intrinsics.h" |
Ensuite, nous incluons notre header :
1 |
#include "function_vectorize.h"
|
Ensuite nous implémentons l'appel d'une fonction std::COMPUTE_FUNCTION_DEF définie par une macro en prennant en compte le fait que nous devons indiquer au compilateur que les tableaux que nous utiliserons seront bien alignés en mémoire sur PLIB_VECTOR_SIZE_BYTE_FLOAT octets avec la fonction __builtin_assume_aligned :
1 2 3 4 5 6 7 8 9 10 11 12 13 |
///Do the function call /** @param[out] ptabResult : table of results of function(tabX) * @param ptabX : input table * @param nbElement : number of elements in the tables */ void function_vectorize(float* __restrict__ ptabResult, const float* __restrict__ ptabX, size_t nbElement){ float* tabResult = (float*)__builtin_assume_aligned(ptabResult, PLIB_VECTOR_SIZE_BYTE_FLOAT); const float* tabX = (const float*)__builtin_assume_aligned(ptabX, PLIB_VECTOR_SIZE_BYTE_FLOAT); for(size_t i(0lu); i < nbElement; ++i){ tabResult[i] = std::COMPUTE_FUNCTION_DEF(tabX[i]); } } |
Le fichier function_vectorize.cpp complet :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
/*************************************** Auteur : Pierre Aubert Mail : pierre.aubert@lapp.in2p3.fr Licence : CeCILL-C ****************************************/ #include <cmath> #include "phoenix_intrinsics.h" #include "function_vectorize.h" ///Do the function call /** @param[out] ptabResult : table of results of function(tabX) * @param ptabX : input table * @param nbElement : number of elements in the tables */ void function_vectorize(float* __restrict__ ptabResult, const float* __restrict__ ptabX, size_t nbElement){ float* tabResult = (float*)__builtin_assume_aligned(ptabResult, PLIB_VECTOR_SIZE_BYTE_FLOAT); const float* tabX = (const float*)__builtin_assume_aligned(ptabX, PLIB_VECTOR_SIZE_BYTE_FLOAT); for(size_t i(0lu); i < nbElement; ++i){ tabResult[i] = std::COMPUTE_FUNCTION_DEF(tabX[i]); } } |
Vous pouvez le télécharger ici.