I have some code that uses SIMD optimization and various __m128i variables. Obviously, printf can't handle them. Is there an easy way for me to print their contents? I'm using Visual Studio 2010 with C/C++.
Asked
Active
Viewed 2,797 times
4
-
1Get bottom and upper parts as int64_t and print those? Roll your own to string conversion by dividing by ten until you reach 0, converting to ASCII, and then reversing the string? – Dec 10 '12 at 16:16
-
That's definitively an option I considered as well. I was hoping for an even easier solution (although this isn't hard at all). – Gustavo Litovsky Dec 10 '12 at 16:27
2 Answers
4
Use this function to print them:
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]);
}
You split 128bits into 16-bits(or 32-bits) before printing them.
This is a way of 64-bit splitting and printing if you have 64-bit support available:
void print128_num(__m128i var)
{
int64_t *v64val = (int64_t*) &var;
printf("%.16llx %.16llx\n", v64val[1], v64val[0]);
}
Replace llx
with lld
if u want int
output.

askmish
- 6,464
- 23
- 42
-
`printf("Numerical: %i %i %i %i %i %i %i %i \n", val[7], val[6], val[5], val[4], val[3], val[2], val[1], val[0]);` seems more logical printing order. – enthusiasticgeek May 28 '13 at 20:43
2
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 prints the whole 128 bit value as a hex string.

Gustavo Litovsky
- 2,457
- 1
- 29
- 41