Created
October 11, 2011 21:49
-
-
Save Themaister/1279562 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <emmintrin.h> | |
#include <stdio.h> | |
int main(void) | |
{ | |
static float buf[] __attribute__((aligned(16))) = {0x4000, 0x3000, 0x2000, 0x1000}; | |
printf("Before: %f, %f, %f, %f\n", buf[0], buf[1], buf[2], buf[3]); | |
__m128i reg = _mm_load_si128((__m128i*)buf); | |
__m128i exp = _mm_and_si128(reg, _mm_set1_epi32(0x7f800000)); | |
__m128i mantissa = _mm_and_si128(reg, _mm_set1_epi32(0x807fffff)); | |
exp = _mm_and_si128(_mm_sub_epi32(exp, _mm_set1_epi32(15 << 23)), _mm_set1_epi32(0x7f800000)); | |
_mm_store_ps(buf, (__m128)_mm_or_si128(exp, mantissa)); | |
printf("After: %f, %f, %f, %f\n", buf[0], buf[1], buf[2], buf[3]); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment