我知道我们可以使用二进制加法器的逻辑Sum = a XOR b和Carry = a AND b
我也有一个解决方案:
int add(int a, int b)
{
if(b == 0)
return sum;
sum = a ^ b;
carry = (a & b) << 1;
return add(sum,carry);
}
Run Code Online (Sandbox Code Playgroud)
我在这里不明白的是为什么在每次递归期间进位位移位或乘以2?
我打电话给GCC是这样的:
$ gcc -I/usr/include/SDL2 -D_REENTRANT -Ibuild -I. -S -fverbose-asm -O2 -m64 -mpc64 -mfpmath=both -fipa-pta -ftree-loop-linear -floop-interchange -floop-strip-mine -floop-block -ftree-loop-distribution -ftree-loop-distribute-patterns -funswitch-loops -ftree-vectorize -march=core-avx-i -c algo/collision.c -o build/collision.s
Run Code Online (Sandbox Code Playgroud)
重要的选择是:
-S : output assembly
-ftree-vectorize : vectorize loops
-march=core-avx-i : enable "MMX, SSE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2,
: AVX, AES, PCLMUL, FSGSBASE, RDRND and F16C
: instruction set support."
Run Code Online (Sandbox Code Playgroud)
这是汇编之前的来源:
#include "collision.h"
int8_t currentField[FIELD_W][FIELD_H];
// Clear and rebuild the field based on the objects with a gravity well
void buildField (const …Run Code Online (Sandbox Code Playgroud) 操作系统:Linux(Debian 10)
CC:GCC 8.3
CPU:i7-5775C
在GCC中有一个unsigned __int128/ __int128,但是有什么办法在GCC中有一个uint256_t/ int256_t?
我读过一篇__m256i似乎来自英特尔的文章。我可以包含任何标头来获取它吗?
它像假设一样有用unsigned __int256吗?我的意思是,如果您可以为其分配/比较,比较,按位运算等。
它的等效符号是什么(如果有)?
编辑1:
我做到了:
#include <immintrin.h>
typedef __m256i uint256_t;
Run Code Online (Sandbox Code Playgroud)
并编译。如果可以进行一些操作,请在此处进行更新。
编辑2:
发现问题:
uint256_t m;
ptrdiff_t l = 5;
m = ~((uint256_t)1 << l);
Run Code Online (Sandbox Code Playgroud)
输出:
error: can’t convert a value of type ‘int’ to vector type ‘__vector(4) long long int’ which has different size
m = ~((uint256_t)1 << l);
Run Code Online (Sandbox Code Playgroud) __m256i我正在寻找使用 AVX 将压缩的 32 位整数除以二(也称为右移一位)的最快方法。我无法访问 AVX2。据我所知,我的选择是:
如果我需要使用 SSE2,我会欣赏最好的 SSE2 实现。如果是 2),我想知道要使用的内在函数,以及是否有更优化的实现来专门除以 2。谢谢!