Rate This Document
Findability
Accuracy
Completeness
Readability

Replacing pcmestri on Arm

This function is used to compare the elements in str1 and str2 based on the model rules (EQUAL_EACH and NEG_POLARITY), and return the index value of the first different element.

For details about the intrinsic function corresponding to pcmpestri, see Intrinsics Guide.

  • Code on x86:
    template<int MODE>
    static inline int SSE4_cmpestri(__m128i str1, int len1, __m128i str2, int len2) {
      int result;
      __asm__ __volatile__("pcmpestri %5, %2, %1": "=c"(result) : "x"(str1), "xm"(str2), "a"(len1), "d"(len2), "i"(MODE) : "cc");
      return result;
    }
  • Alternative for Kunpeng processors:
    #include <arm_neon.h>
    template<int MODE>
    static inline int SSE4_cmpestri(int32x4_t str1, int len1, int32x4_t str2, int len2) {
    __oword a, b;
    a.m128i = str1;
    b.m128i = str2;
        int len_s, len_l;
    if (len1 > len2) {
    len_s = len2;
    len_l = len1;
        } else {
    len_s = len1;
    len_l = len2;
      }
    int result;
    int i;
        // Replacement mode in this example: STRCMP_MODE =
    // PCMPSTR_EQUAL_EACH | PCMPSTR_UBYTE_OPS | PCMPSTR_NEG_POLARITY
        for(i = 0; i < len_s; i++) {
    if (a.m128i_u8[i] == b.m128i_u8[i]) {
    break;
    }
    }
    result = i;
    if (result == len_s) result = len_l;
    return result;
    }