FuckBigTech347@lemmygrad.mltoProgrammer Humor@programming.dev•How should I increment an int?
0·
3 days agoYour CPU has big registers, so why not use them!
#include <x86intrin.h>
#include <stdio.h>
static int increment_one(int input)
{
int __attribute__((aligned(32))) result[8];
__m256i v = _mm256_set_epi32(0, 0, 0, 0, 0, 0, 1, input);
v = (__m256i)_mm256_hadd_ps((__m256)v, (__m256)v);
_mm256_store_si256((__m256i *)result, v);
return *result;
}
int main(void)
{
int input = 19;
printf("Input: %d, Incremented output: %d\n", input, increment_one(input));
return 0;
}
Unless your machine has error correcting memory. Then it will take literally forever.