• [^] # Re: Sans SSE

    Posté par (site web personnel) . En réponse au journal Recherche de valeur dans un tableau et l'écosystème des compilateurs C++. Évalué à 2.

    La version utilisant des long corrigée présente un gains de 10 % sur ARM, mais grand chose sur Intel, par rapport à la version entière... Il y a peut-être encore de marge en regardant le code généré, mais l'épilogue de la fonction est déjà compliqué à écrire (ou les cas non aligné, pour des tableaux de n'importe quelle taille).

    Donc sur cette tablette / Chromebook, le meilleur résultat est pour la boucle suivante (sans optimisation du prefetch) :

    size_t find_int_c4l(const int k, const int* v, const size_t n) {
     size_t i = 0;
     size_t n2 = n >> 1;
     const unsigned long* vl = (const unsigned long*)v;
     const unsigned long klow = (unsigned long)k;
     const unsigned long khi = (unsigned long)k << 32;
     const unsigned long maskLow = 0xffffffff;
     const unsigned long maskHi = maskLow << 32;
     unsigned int index = 0;
     for (; i <= n2; i += 8, vl += 8) {
     index = 0;
     __builtin_prefetch(vl + 256, 0, 1);
     index = ((vl[0] & maskLow) != klow && (vl[0] & maskHi) != khi) ? index : 1;
     index = ((vl[1] & maskLow) != klow && (vl[1] & maskHi) != khi) ? index : 1;
     index = ((vl[2] & maskLow) != klow && (vl[2] & maskHi) != khi) ? index : 1;
     index = ((vl[3] & maskLow) != klow && (vl[3] & maskHi) != khi) ? index : 1;
     index = ((vl[4] & maskLow) != klow && (vl[4] & maskHi) != khi) ? index : 1;
     index = ((vl[5] & maskLow) != klow && (vl[5] & maskHi) != khi) ? index : 1;
     index = ((vl[6] & maskLow) != klow && (vl[6] & maskHi) != khi) ? index : 1;
     index = ((vl[7] & maskLow) != klow && (vl[7] & maskHi) != khi) ? index : 1;
     if (index == 1) {
     break;
     }
     }
     return i; // i n/2 -8 si ok dans mon cas...
    }

    Résultat :
    bash
    C1 = 2850253 (499999984), C2 = 1233600 (499999984), C3 = 575797 (499999984), C4 = 547523 (499999984), C4l = 494092 (249999992), C5 = 556564 (499999984)

    Par rapport à la version originale, dans mon test sur ARM, la boucle C4l est 5,77 fois plus rapide.