鲲鹏社区首页
中文
注册
开发者
我要评分
文档获取效率
文档正确性
内容完整性
文档易理解
在线提单
论坛求助

pcmpestri在ARM上的替换方法

函数功能:按照MODEL规则(EQUAL_EACH、NEG_POLARITY)比较str1和str2中的元素,比较并返回首个不相同元素的索引值。

pcmpestri对应的Intrinsic函数详细说明,请参考Intrinsics Guide

  • 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;
    }
  • 在鲲鹏上替换后:
    #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;
        //本例替换的模式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;
    }