我使用的是 Ruby 2.3:
我有以下字符串:"\xFF\xFE"
我对File.binread()包含它的文件执行了 a 操作,因此该字符串的编码是ASCII-8BIT. "\xFF\xFE"然而,在我的代码中,我通过将其与文字字符串(其默认编码UTF-8与所有 Ruby 字符串相同)进行比较来检查该字符串是否确实被读取。
然而,即使两个字符串包含相同的字节,比较也会返回false- 恰好一个是编码的ASCII-8BIT,另一个是编码的UTF-8
我有两个问题:(1)为什么它会返回false?(2) 实现我想要的目标的最佳方法是什么?我只是想检查我读取的字符串是否匹配"\xFF\xFE"
我目前有以下代码:
float a[4] = { 10, 20, 30, 40 };
float b[4] = { 0.1, 0.1, 0.1, 0.1 };
asm volatile("movups (%0), %%xmm0\n\t"
"mulps (%1), %%xmm0\n\t"
"movups %%xmm0, (%1)"
:: "r" (a), "r" (b));
Run Code Online (Sandbox Code Playgroud)
我首先要问几个问题:
(1)如果我要在16字节边界上对齐数组,它甚至可以工作吗?由于数组是在堆栈上分配的,因此对齐它们几乎是不可能的吗?
看到这篇文章的选定答案:堆栈变量是否由GCC __attribute __((aligned(x)))对齐?
(2)代码是否可以重构以提高效率?如果我将两个浮点数组都放在寄存器而不只是一个?
谢谢
我正在对一些SSE代码(将4个浮点数乘以4个浮点数)与传统的C代码进行基准测试.我认为我的基准代码在某种程度上必须是错误的,因为它似乎说非SSE代码比SSE快2-3倍.
有人能告诉我下面的基准测试代码有什么问题吗?并且可能建议另一种方法准确地显示SSE和非SSE代码的速度.
#include <time.h>
#include <string.h>
#include <stdio.h>
#define ITERATIONS 100000
#define MULT_FLOAT4(X, Y) ({ \
asm volatile ( \
"movaps (%0), %%xmm0\n\t" \
"mulps (%1), %%xmm0\n\t" \
"movaps %%xmm0, (%1)" \
:: "r" (X), "r" (Y)); })
int main(void)
{
int i, j;
float a[4] __attribute__((aligned(16))) = { 10, 20, 30, 40 };
time_t timer, sse_time, std_time;
timer = time(NULL);
for(j = 0; j < 5000; ++j)
for(i = 0; i < ITERATIONS; ++i) {
float b[4] …Run Code Online (Sandbox Code Playgroud) 你可以看到我在下面尝试做的事情:
typedef struct image_bounds {
int xmin, ymin, xmax, ymax;
} image_bounds;
#define IMAGE_BOUNDS(X) ((image_bounds *)(X));
typedef struct {
image_bounds bounds;
float dummy;
} demo;
int
main(void) {
demo my_image;
/* this works fine */
((image_bounds *)(&my_image))->xmin = 10;
/* why doesn't this work? i get the following error:
/* In function main:
cast.c:20: error: expected expression before = token
*/
IMAGE_BOUNDS(&my_image)->xmin = 20;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
正如你从上面可以看到,C演员有效,但宏版本没有,我做错了什么?
对于我的生活,我找不到字段在xcode4中输入NSTableColumn的标识符,在xcode3中它看起来很简单,字段title在属性检查器的正下方,但是我无法inspectors在xcode4的任何一个中找到相应的字段.
提前致谢!