首页 \ 问答 \ 平均运营ARM NEON(average operation ARM NEON)

平均运营ARM NEON(average operation ARM NEON)

我需要计算与SSE相同的操作:

__m128i result1=_mm_avg_epu8 (upper, lower);

在NEON中,我执行以下操作:

uint8x16_t result1=vhaddq_u8(upper, lower);

结果应该是一样的,但是通过我获得的SSE指令:

91cb c895 aaa3 b0d4 cfc0 c1b0 aac7 b9b9

而根据我获得的NEON指令:

91ca c894 a9a2 b0d3 cec0 c1af aac7 b8b8 

我不明白为什么这两个结果是不同的。 你可以帮我吗?


I need to compute the same operation as the SSE one:

__m128i result1=_mm_avg_epu8 (upper, lower);

With NEON I do the following:

uint8x16_t result1=vhaddq_u8(upper, lower);

The results should be the same but with the SSE instruction I obtain:

91cb c895 aaa3 b0d4 cfc0 c1b0 aac7 b9b9

whereas with the NEON instruction I obtain:

91ca c894 a9a2 b0d3 cec0 c1af aac7 b8b8 

I don't understand why the two results are different. Can you help me?


原文:https://stackoverflow.com/questions/18657889
更新时间:2022-03-11 07:03

最满意答案

您通过修改std::string的字符超过其末尾(均为nom[j] = lines)来调用未定义的行为。 您应该使用其push_back成员函数,以及直接连接字符串而不是使用char缓冲区。

另外,你只分配一个字符,然后strcpy方式通过它...并泄漏它的指针。

此外,您使用幻数而不是字符常量\r

这是一个更正(更简单)的版本:

string getRuta(int i, char const* buffer, string directorio) {
    string nom;
    char c;
    do {
        c = buffer[i];
        nom.push_back(c);
        i++;
    } while (buffer[i] != '\r');

    string ruta = directorio + nom;
    printf("%s\n",ruta.c_str());
    return ruta;
}

You're invoking undefined behavior by modifying a std::string's characters past its end (both nom[j] = lines). You should use its push_back member function instead, as well as concatenate your strings directly instead of using a char buffer.

In addition, you only allocate one character, then strcpy way past it... and leak its pointer.

Also, you use a magic number instead of the character constant \r.

Here is a corrected (and much simpler) version:

string getRuta(int i, char const* buffer, string directorio) {
    string nom;
    char c;
    do {
        c = buffer[i];
        nom.push_back(c);
        i++;
    } while (buffer[i] != '\r');

    string ruta = directorio + nom;
    printf("%s\n",ruta.c_str());
    return ruta;
}

相关问答

更多

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)