平均运营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
最满意答案
您通过修改
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 (bothnom[j] =
lines). You should use itspush_back
member function instead, as well as concatenate your strings directly instead of using achar
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; }
相关问答
更多-
use List::Util 'maxstr'; my $maxChar = maxstr split //, 'abcb'; # 'c' use List::Util 'maxstr'; my $maxChar = maxstr split //, 'abcb'; # 'c'
-
字符串到数组的C char(C char of string to array)[2022-03-20]
最简单的,使用memcpy : #include#include #define FOO "AB" #define BAR 33 extern int rs232_write(const unsigned char *data, unsigned char count); unsigned char _foobar[] = { 0x22, 0, 0, 0x42, BAR, }; const unsigned char *foo ... -
预期的'const char **',但参数的类型是'char **'(expected expected ‘const char **’ but argument is of type ‘char **’)[2023-01-02]
因为从技术上讲,您可能会通过将非const指针传递给const指针参数来破坏承诺。 “拿走恒常是危险的” http://c-faq.com/ansi/constmismatch.html 以下是上述链接的内容: 你可以使用指向T的指针(对于任何类型T),其中指向const-T的指针是预期的。 但是,允许在限定指针类型中轻微不匹配的规则(明确的例外)不会递归应用,而只能在最高级别应用。 (const char **是指向const-char的指针,因此异常不适用。) 你不能将char **值赋给const c ... -
C ++错误 - 在'char'和'int'之前的预期主要表达式(C++ error - expected primary expression before 'char' and 'int')[2023-01-22]
在这条线上 Officer(char* a, int b, int c, char* d):Employee(char* a, int b, int c) 你应该只传递一个,b和c。 相反,您正在使用语法来声明a,b和c。 只要提到它们,你就不需要这些类型。 IE你应该这样做: Officer(char* a, int b, int c, char* d):Employee(a, b, c) 你可能会不小心将声明复制粘贴到子类的构造函数中。 On this line Officer(char ... -
错误FS0001:预期有类型字符串,但类型为char(Error FS0001: Expected to have type string, but has type char)[2023-06-10]
一种方法改变if到 if isInteger (someString.[-1] |> string) <> None then One way change the if to if isInteger (someString.[-1] |> string) <> None then -
期望'const char *',但参数的类型是C中的'char **'(expected ‘const char *’ but argument is of type ‘char **’ in C)[2024-03-23]
int low=strlen(array)-n; 是错的。 将数组大小作为不同的参数传递,如: int FindStringInSortedArray(char *key,char *array[],int n, int arraysize) 由于数组衰减成函数中的指针。 strlen宣言的形式 strlen (const char*) 并且你正在传递*array[]其类型衰减为char * * 。 在C99中,有三种基本情况,数组名称不会衰减为指向第一个元素的指针: 当它是& (address-of) ... -
您通过修改std::string的字符超过其末尾(均为nom[j] = lines)来调用未定义的行为。 您应该使用其push_back成员函数,以及直接连接字符串而不是使用char缓冲区。 另外,你只分配一个字符,然后strcpy方式通过它...并泄漏它的指针。 此外,您使用幻数而不是字符常量\r 。 这是一个更正(更简单)的版本: string getRuta(int i, char const* buffer, string directorio) { string nom; char ...
-
将"LINE TO BE SEPARATED"分配给char *line ,可以使line指向写入程序可执行文件的常量字符串。 你不能修改它。 你应该把这些变量声明为const char * 。 当声明为char[] ,你的字符串被声明在函数的堆栈中。 因此,您可以修改它。 When assigning "LINE TO BE SEPARATED" to char *line, you make line point to an constant string written in the program ...
-
char [1024] vs char *(char [1024] vs char *)[2022-09-29]
你提到你需要一个char **并且存在问题:对于数组, word和&word意味着相同的东西 - 数组内容的实际位置。 使用指针时它起作用的原因是因为“指针” 存储在不同的位置,而它指向同一个数组。 你不需要strdup ,你只需要创建一个指针: char* tmp = word; HashSetLookup(stopList, &tmp); You mention you need a char ** and there lies the problem: for an array, word and ... -
为什么C ++中的C字符串和Char数组和Char指针存在差异(Why the C string and Char Array and Char pointer differences in C++)[2022-05-16]
C字符串只不过是一个字符数组。 因此,除了您的工作示例,您还可以执行以下操作: const char cString[] = "Hello world"; 这基本上相当于: const char cString[] = { 'H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd' }; 请注意,这是一个char数组,而不是一个char 。 你遇到这个问题的原因: const char cString = "Hello world"; 是因为"Hello ...