mmxval.h
#pragma once
#include "miscdefs.h"
#include <stdlib.h>
#include <stdio.h>

union MmxVal
{
    Int8  i8[8];
    Int16 i16[4];
    Int32 i32[2];
    Int64 i64;
    Uint8  u8[8];
    Uint16 u16[4];
    Uint32 u32[2];
    Uint64 u64;

    char* ToString_i8(char* s, size_t len);
    char* ToString_i16(char* s, size_t len);
    char* ToString_i32(char* s, size_t len);
    char* ToString_i64(char* s, size_t len);

    char* ToString_u8(char* s, size_t len);
    char* ToString_u16(char* s, size_t len);
    char* ToString_u32(char* s, size_t len);
    char* ToString_u64(char* s, size_t len);

    char* ToString_x8(char* s, size_t len);
    char* ToString_x16(char* s, size_t len);
    char* ToString_x32(char* s, size_t len);
    char* ToString_x64(char* s, size_t len);
};
mmxval.cpp
/* build: g++ -c -m32 mmxval.cpp -o mmxval.o -std=c++11
 * The objectfile only is used in several other examples from the book
 */

#include "mmxval.h"

char* MmxVal::ToString_i8(char* s, size_t len){
    snprintf(s, len, "%4d %4d %4d %4d %4d %4d %4d %4d",
        i8[0], i8[1], i8[2], i8[3], i8[4], i8[5], i8[6], i8[7]);
    return s;
}
char* MmxVal::ToString_i16(char* s, size_t len){
	snprintf(s, len, "%8d %8d %8d %8d", i16[0], i16[1], i16[2], i16[3]);
    return s;
}
char* MmxVal::ToString_i32(char* s, size_t len){
	snprintf(s, len, "%12d %12d", i32[0], i32[1]);
    return s;
}
char* MmxVal::ToString_i64(char* s, size_t len){
	snprintf(s, len, "%16lld", i64);
    return s;
}
char* MmxVal::ToString_u8(char* s, size_t len){
	snprintf(s, len, "%4u %4u %4u %4u %4u %4u %4u %4u",
        u8[0], u8[1], u8[2], u8[3], u8[4], u8[5], u8[6], u8[7]);
    return s;
}
char* MmxVal::ToString_u16(char* s, size_t len){
	snprintf(s, len, "%8u %8u %8u %8u", u16[0], u16[1], u16[2], u16[3]);
    return s;
}
char* MmxVal::ToString_u32(char* s, size_t len){
	snprintf(s, len, "%12u %12u", u32[0], u32[1]);
    return s;
}
char* MmxVal::ToString_u64(char* s, size_t len){
	snprintf(s, len, "%16llu", u64);
    return s;
}
char* MmxVal::ToString_x8(char* s, size_t len){
	snprintf(s, len, "%02X %02X %02X %02X %02X %02X %02X %02X",
        u8[0], u8[1], u8[2], u8[3], u8[4], u8[5], u8[6], u8[7]);
    return s;
}
char* MmxVal::ToString_x16(char* s, size_t len){
	snprintf(s, len, "%04X %04X %04X %04X", u16[0], u16[1], u16[2], u16[3]);
    return s;
}
char* MmxVal::ToString_x32(char* s, size_t len){
	snprintf(s, len, "%08X %08X", u32[0], u32[1]);
    return s;
}
char* MmxVal::ToString_x64(char* s, size_t len){
	snprintf(s, len, "%016llX", u64);
    return s;
}