Printf SSE __m128i variables in Visual Studio

I have code that uses SIMD optimization and various __m128i variables. Obviously printf cannot handle them. Is there an easy way for me to print their contents? I am using Visual Studio 2010 with C / C ++.

+4
source share
2 answers

Use this function to print:

void print128_num(__m128i var) { uint16_t *val = (uint16_t*) &var;//can also use uint32_t instead of 16_t printf("Numerical: %i %i %i %i %i %i %i %i \n", val[0], val[1], val[2], val[3], val[4], val[5], val[6], val[7]); } 

Before printing, you divided 128 bits into 16 bits (or 32 bits).

This is a 64-bit separation and printing method if you have 64-bit support:

 void print128_num(__m128i var) { int64_t *v64val = (int64_t*) &var; printf("%.16llx %.16llx\n", v64val[1], v64val[0]); } 

Replace llx with lld if you want to print int .

+3
source

I found the answer based on Vlad’s approach:

 __m128i var; printf("0x%I64x%I64x\n",var.m128i_i64[1], var.m128i_i64[0]); 

This outputs the entire 128-bit value as a hexadecimal string.

+1
source

All Articles