>>106739599
i just wrote this.
comments are for my own use so i dont waste time when ill come back to this code. i dont have much experience with intrinsics.
#include <immintrin.h>
#include <stdio.h>
#ifndef __NOUVO_DEFINES_VECTOR_ATOI_H__
#define __NOUVO_DEFINES_VECTOR_ATOI_H__
const __attribute__((aligned(32))) __m256i VECTOR_ATOI_BIAS_VEC = {
(long long)0x3030303030303030ULL,
(long long)0x3030303030303030ULL,
(long long)0x3030303030303030ULL,
(long long)0x3030303030303030ULL
};
const __attribute__((aligned(32))) __m256i VECTOR_ATOI_CHALLENGE_ZERO_VEC = {
(long long)0x0ULL,
(long long)0x0ULL,
(long long)0x0ULL,
(long long)0x0ULL
};
#endif
unsigned int vector_atoi_period(char *str)
{
//substract '0' from all bytes. if anything is less than \0, it means its a separator.
//assuming separators are . (period), space, newline or null termination
__m256i chunk = _mm256_loadu_si256((const __m256i *)str);
__m256i shifted = _mm256_sub_epi8(chunk, VECTOR_ATOI_BIAS_VEC);
//cmpgt is the only available so were checking if 0 is greater than the shifted chunk
__m256i is_digit = _mm256_cmpgt_epi8(VECTOR_ATOI_CHALLENGE_ZERO_VEC, shifted);
unsigned int mask = _mm256_movemask_epi8(is_digit);
printf("vector_atoi_period : period mask : %u\n", mask);
return (_tzcnt_u32(mask));
}
int main(void)
{
char buffer[1000] = "999.abcdefsg";
printf("main : period value : %u\n", vector_atoi_period(buffer));
}
i have no problems with indians btw, im just protecting my honor since im a /g/ poster