Skip to content
Permalink
Browse files

[lldb] [lit] Use more readable consts and arrays in register read tests

Replace the constants used for r8/mm/xmm/ymm/zmm tests with something
more readable to ease debugging in case of failures (0x00 0x01 ...).
While at it, put the constants in array and copy them from memory
to simplify inline asm.

The original constants grew out of necessity.  The xmm constants were
'weird' because they were intended to be different from mm constants
(as that was necessary to catch NetBSD implementation bug).  The ymm
constants were made even weirded to not even partially collide with
other xmm registers (not saying it made sense, just how it was done).
Then, zmm constants were once again designed to avoid accidental
collisions with xmm and ymm constants, and at the same the 16 extra
registers required even more shuffling.

The new constants are meant to be more user-readable, so that a mistake
could be easily spotted.  All of xmm, ymm and zmm tests use a sequence
of {0x00 0x01 0x02 ...}, shifted by 1 for every register.  This should
provide enough uniquity, and space for future increase in number of
registers.  Since mm and r8..r15 are printed as uint64_t rather than
byte-by-byte, they use 0x000102...  As a result, on x86 endianness takes
care of making mm different than xmm.

The use of arrays is something I had to learn for zmm write tests.  It
avoids having to specify all the input values separately, and makes
GCC happy about zmm-read test (it was rejected previously because of
hitting a limit of 30 constraints).

llvm-svn: 360041
  • Loading branch information...
mgorny committed May 6, 2019
1 parent 8b92ec5 commit acbaa496ec8ea63f2315e0fdc7ed86c888a21a53
@@ -5,48 +5,50 @@ struct alignas(16) xmm_t {
};

int main() {
constexpr uint64_t r8 = 0x0102030405060708;
constexpr uint64_t r9 = 0x1112131415161718;
constexpr uint64_t r10 = 0x2122232425262728;
constexpr uint64_t r11 = 0x3132333435363738;
constexpr uint64_t r12 = 0x4142434445464748;
constexpr uint64_t r13 = 0x5152535455565758;
constexpr uint64_t r14 = 0x6162636465666768;
constexpr uint64_t r15 = 0x7172737475767778;
constexpr uint64_t r8[] = {
0x0001020304050607,
0x1011121314151617,
0x2021222324252627,
0x3031323334353637,
0x4041424344454647,
0x5051525354555657,
0x6061626364656667,
0x7071727374757677,
};

constexpr xmm_t xmm8 = { 0x020406080A0C0E01, 0x030507090B0D0F00 };
constexpr xmm_t xmm9 = { 0x121416181A1C1E11, 0x131517191B1D1F10 };
constexpr xmm_t xmm10 = { 0x222426282A2C2E21, 0x232527292B2D2F20 };
constexpr xmm_t xmm11 = { 0x323436383A3C3E31, 0x333537393B3D3F30 };
constexpr xmm_t xmm12 = { 0x424446484A4C4E41, 0x434547494B4D4F40 };
constexpr xmm_t xmm13 = { 0x525456585A5C5E51, 0x535557595B5D5F50 };
constexpr xmm_t xmm14 = { 0x626466686A6C6E61, 0x636567696B6D6F60 };
constexpr xmm_t xmm15 = { 0x727476787A7C7E71, 0x737577797B7D7F70 };
constexpr xmm_t xmm8[] = {
{ 0x0F0E0D0C0B0A0908, 0x1716151413121110, },
{ 0x100F0E0D0C0B0A09, 0x1817161514131211, },
{ 0x11100F0E0D0C0B0A, 0x1918171615141312, },
{ 0x1211100F0E0D0C0B, 0x1A19181716151413, },
{ 0x131211100F0E0D0C, 0x1B1A191817161514, },
{ 0x14131211100F0E0D, 0x1C1B1A1918171615, },
{ 0x1514131211100F0E, 0x1D1C1B1A19181716, },
{ 0x161514131211100F, 0x1E1D1C1B1A191817, },
};

asm volatile(
"movq %0, %%r8\n\t"
"movq %1, %%r9\n\t"
"movq %2, %%r10\n\t"
"movq %3, %%r11\n\t"
"movq %4, %%r12\n\t"
"movq %5, %%r13\n\t"
"movq %6, %%r14\n\t"
"movq %7, %%r15\n\t"
"movq 0x00(%%rax), %%r8\n\t"
"movq 0x08(%%rax), %%r9\n\t"
"movq 0x10(%%rax), %%r10\n\t"
"movq 0x18(%%rax), %%r11\n\t"
"movq 0x20(%%rax), %%r12\n\t"
"movq 0x28(%%rax), %%r13\n\t"
"movq 0x30(%%rax), %%r14\n\t"
"movq 0x38(%%rax), %%r15\n\t"
"\n\t"
"movaps %8, %%xmm8\n\t"
"movaps %9, %%xmm9\n\t"
"movaps %10, %%xmm10\n\t"
"movaps %11, %%xmm11\n\t"
"movaps %12, %%xmm12\n\t"
"movaps %13, %%xmm13\n\t"
"movaps %14, %%xmm14\n\t"
"movaps %15, %%xmm15\n\t"
"movaps 0x00(%%rbx), %%xmm8\n\t"
"movaps 0x10(%%rbx), %%xmm9\n\t"
"movaps 0x20(%%rbx), %%xmm10\n\t"
"movaps 0x30(%%rbx), %%xmm11\n\t"
"movaps 0x40(%%rbx), %%xmm12\n\t"
"movaps 0x50(%%rbx), %%xmm13\n\t"
"movaps 0x60(%%rbx), %%xmm14\n\t"
"movaps 0x70(%%rbx), %%xmm15\n\t"
"\n\t"
"int3"
"int3\n\t"
:
: "i"(r8), "i"(r9), "i"(r10), "i"(r11), "i"(r12), "i"(r13), "i"(r14),
"i"(r15), "m"(xmm8), "m"(xmm9), "m"(xmm10), "m"(xmm11), "m"(xmm12),
"m"(xmm13), "m"(xmm14), "m"(xmm15)
: "a"(r8), "b"(xmm8)
: "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15", "%xmm8",
"%xmm9", "%xmm10", "%xmm11", "%xmm12", "%xmm13", "%xmm14", "%xmm15"
);
@@ -5,48 +5,50 @@ struct alignas(16) xmm_t {
};

int main() {
constexpr uint64_t mm0 = 0x0102030405060708;
constexpr uint64_t mm1 = 0x1112131415161718;
constexpr uint64_t mm2 = 0x2122232425262728;
constexpr uint64_t mm3 = 0x3132333435363738;
constexpr uint64_t mm4 = 0x4142434445464748;
constexpr uint64_t mm5 = 0x5152535455565758;
constexpr uint64_t mm6 = 0x6162636465666768;
constexpr uint64_t mm7 = 0x7172737475767778;
constexpr uint64_t mm[] = {
0x0001020304050607,
0x1011121314151617,
0x2021222324252627,
0x3031323334353637,
0x4041424344454647,
0x5051525354555657,
0x6061626364656667,
0x7071727374757677,
};

constexpr xmm_t xmm0 = { 0x020406080A0C0E01, 0x030507090B0D0F00 };
constexpr xmm_t xmm1 = { 0x121416181A1C1E11, 0x131517191B1D1F10 };
constexpr xmm_t xmm2 = { 0x222426282A2C2E21, 0x232527292B2D2F20 };
constexpr xmm_t xmm3 = { 0x323436383A3C3E31, 0x333537393B3D3F30 };
constexpr xmm_t xmm4 = { 0x424446484A4C4E41, 0x434547494B4D4F40 };
constexpr xmm_t xmm5 = { 0x525456585A5C5E51, 0x535557595B5D5F50 };
constexpr xmm_t xmm6 = { 0x626466686A6C6E61, 0x636567696B6D6F60 };
constexpr xmm_t xmm7 = { 0x727476787A7C7E71, 0x737577797B7D7F70 };
constexpr xmm_t xmm[] = {
{ 0x0706050403020100, 0x0F0E0D0C0B0A0908, },
{ 0x0807060504030201, 0x100F0E0D0C0B0A09, },
{ 0x0908070605040302, 0x11100F0E0D0C0B0A, },
{ 0x0A09080706050403, 0x1211100F0E0D0C0B, },
{ 0x0B0A090807060504, 0x131211100F0E0D0C, },
{ 0x0C0B0A0908070605, 0x14131211100F0E0D, },
{ 0x0D0C0B0A09080706, 0x1514131211100F0E, },
{ 0x0E0D0C0B0A090807, 0x161514131211100F, },
};

asm volatile(
"movq %0, %%mm0\n\t"
"movq %1, %%mm1\n\t"
"movq %2, %%mm2\n\t"
"movq %3, %%mm3\n\t"
"movq %4, %%mm4\n\t"
"movq %5, %%mm5\n\t"
"movq %6, %%mm6\n\t"
"movq %7, %%mm7\n\t"
"movq 0x00(%%rax), %%mm0\n\t"
"movq 0x08(%%rax), %%mm1\n\t"
"movq 0x10(%%rax), %%mm2\n\t"
"movq 0x18(%%rax), %%mm3\n\t"
"movq 0x20(%%rax), %%mm4\n\t"
"movq 0x28(%%rax), %%mm5\n\t"
"movq 0x30(%%rax), %%mm6\n\t"
"movq 0x38(%%rax), %%mm7\n\t"
"\n\t"
"movaps %8, %%xmm0\n\t"
"movaps %9, %%xmm1\n\t"
"movaps %10, %%xmm2\n\t"
"movaps %11, %%xmm3\n\t"
"movaps %12, %%xmm4\n\t"
"movaps %13, %%xmm5\n\t"
"movaps %14, %%xmm6\n\t"
"movaps %15, %%xmm7\n\t"
"movaps 0x00(%%rbx), %%xmm0\n\t"
"movaps 0x10(%%rbx), %%xmm1\n\t"
"movaps 0x20(%%rbx), %%xmm2\n\t"
"movaps 0x30(%%rbx), %%xmm3\n\t"
"movaps 0x40(%%rbx), %%xmm4\n\t"
"movaps 0x50(%%rbx), %%xmm5\n\t"
"movaps 0x60(%%rbx), %%xmm6\n\t"
"movaps 0x70(%%rbx), %%xmm7\n\t"
"\n\t"
"int3"
"int3\n\t"
:
: "rm"(mm0), "rm"(mm1), "rm"(mm2), "rm"(mm3), "rm"(mm4), "rm"(mm5),
"rm"(mm6), "rm"(mm7), "m"(xmm0), "m"(xmm1), "m"(xmm2), "m"(xmm3),
"m"(xmm4), "m"(xmm5), "m"(xmm6), "m"(xmm7)
: "a"(mm), "b"(xmm)
: "%mm0", "%mm1", "%mm2", "%mm3", "%mm4", "%mm5", "%mm6", "%mm7",
"%xmm0", "%xmm1", "%xmm2", "%xmm3", "%xmm4", "%xmm5", "%xmm6", "%xmm7"
);
@@ -5,70 +5,66 @@ struct alignas(32) ymm_t {
};

int main() {
constexpr ymm_t ymm0 = { 0x020406080A0C0E01, 0x030507090B0D0F00,
0x838587898B8D8F80, 0x828486888A8C8E81 };
constexpr ymm_t ymm1 = { 0x121416181A1C1E11, 0x131517191B1D1F10,
0x939597999B9D9F90, 0x929496989A9C9E91 };
constexpr ymm_t ymm2 = { 0x222426282A2C2E21, 0x232527292B2D2F20,
0xA3A5A7A9ABADAFA0, 0xA2A4A6A8AAACAEA1 };
constexpr ymm_t ymm3 = { 0x323436383A3C3E31, 0x333537393B3D3F30,
0xB3B5B7B9BBBDBFB0, 0xB2B4B6B8BABCBEB1 };
constexpr ymm_t ymm4 = { 0x424446484A4C4E41, 0x434547494B4D4F40,
0xC3C5C7C9CBCDCFC0, 0xC2C4C6C8CACCCEC1 };
constexpr ymm_t ymm5 = { 0x525456585A5C5E51, 0x535557595B5D5F50,
0xD3D5D7D9DBDDDFD0, 0xD2D4D6D8DADCDED1 };
constexpr ymm_t ymm6 = { 0x626466686A6C6E61, 0x636567696B6D6F60,
0xE3E5E7E9EBEDEFE0, 0xE2E4E6E8EAECEEE1 };
constexpr ymm_t ymm7 = { 0x727476787A7C7E71, 0x737577797B7D7F70,
0xF3F5F7F9FBFDFFF0, 0xF2F4F6F8FAFCFEF1 };
constexpr ymm_t ymm[] = {
{ 0x0706050403020100, 0x0F0E0D0C0B0A0908,
0x1716151413121110, 0x1F1E1D1C1B1A1918, },
{ 0x0807060504030201, 0x100F0E0D0C0B0A09,
0x1817161514131211, 0x201F1E1D1C1B1A19, },
{ 0x0908070605040302, 0x11100F0E0D0C0B0A,
0x1918171615141312, 0x21201F1E1D1C1B1A, },
{ 0x0A09080706050403, 0x1211100F0E0D0C0B,
0x1A19181716151413, 0x2221201F1E1D1C1B, },
{ 0x0B0A090807060504, 0x131211100F0E0D0C,
0x1B1A191817161514, 0x232221201F1E1D1C, },
{ 0x0C0B0A0908070605, 0x14131211100F0E0D,
0x1C1B1A1918171615, 0x24232221201F1E1D, },
{ 0x0D0C0B0A09080706, 0x1514131211100F0E,
0x1D1C1B1A19181716, 0x2524232221201F1E, },
{ 0x0E0D0C0B0A090807, 0x161514131211100F,
0x1E1D1C1B1A191817, 0x262524232221201F, },
#if defined(__x86_64__) || defined(_M_X64)
constexpr ymm_t ymm8 = { 0x838587898B8D8F80, 0x828486888A8C8E81,
0x020406080A0C0E01, 0x030507090B0D0F00 };
constexpr ymm_t ymm9 = { 0x939597999B9D9F90, 0x929496989A9C9E91,
0x121416181A1C1E11, 0x131517191B1D1F10 };
constexpr ymm_t ymm10 = { 0xA3A5A7A9ABADAFA0, 0xA2A4A6A8AAACAEA1,
0x222426282A2C2E21, 0x232527292B2D2F20 };
constexpr ymm_t ymm11 = { 0xB3B5B7B9BBBDBFB0, 0xB2B4B6B8BABCBEB1,
0x323436383A3C3E31, 0x333537393B3D3F30 };
constexpr ymm_t ymm12 = { 0xC3C5C7C9CBCDCFC0, 0xC2C4C6C8CACCCEC1,
0x424446484A4C4E41, 0x434547494B4D4F40 };
constexpr ymm_t ymm13 = { 0xD3D5D7D9DBDDDFD0, 0xD2D4D6D8DADCDED1,
0x525456585A5C5E51, 0x535557595B5D5F50 };
constexpr ymm_t ymm14 = { 0xE3E5E7E9EBEDEFE0, 0xE2E4E6E8EAECEEE1,
0x626466686A6C6E61, 0x636567696B6D6F60 };
constexpr ymm_t ymm15 = { 0xF3F5F7F9FBFDFFF0, 0xF2F4F6F8FAFCFEF1,
0x727476787A7C7E71, 0x737577797B7D7F70 };
{ 0x0F0E0D0C0B0A0908, 0x1716151413121110,
0x1F1E1D1C1B1A1918, 0x2726252423222120, },
{ 0x100F0E0D0C0B0A09, 0x1817161514131211,
0x201F1E1D1C1B1A19, 0x2827262524232221, },
{ 0x11100F0E0D0C0B0A, 0x1918171615141312,
0x21201F1E1D1C1B1A, 0x2928272625242322, },
{ 0x1211100F0E0D0C0B, 0x1A19181716151413,
0x2221201F1E1D1C1B, 0x2A29282726252423, },
{ 0x131211100F0E0D0C, 0x1B1A191817161514,
0x232221201F1E1D1C, 0x2B2A292827262524, },
{ 0x14131211100F0E0D, 0x1C1B1A1918171615,
0x24232221201F1E1D, 0x2C2B2A2928272625, },
{ 0x1514131211100F0E, 0x1D1C1B1A19181716,
0x2524232221201F1E, 0x2D2C2B2A29282726, },
{ 0x161514131211100F, 0x1E1D1C1B1A191817,
0x262524232221201F, 0x2E2D2C2B2A292827, },
#endif
};

asm volatile(
"vmovaps %0, %%ymm0\n\t"
"vmovaps %1, %%ymm1\n\t"
"vmovaps %2, %%ymm2\n\t"
"vmovaps %3, %%ymm3\n\t"
"vmovaps %4, %%ymm4\n\t"
"vmovaps %5, %%ymm5\n\t"
"vmovaps %6, %%ymm6\n\t"
"vmovaps %7, %%ymm7\n\t"
"vmovaps 0x000(%%rbx), %%ymm0\n\t"
"vmovaps 0x020(%%rbx), %%ymm1\n\t"
"vmovaps 0x040(%%rbx), %%ymm2\n\t"
"vmovaps 0x060(%%rbx), %%ymm3\n\t"
"vmovaps 0x080(%%rbx), %%ymm4\n\t"
"vmovaps 0x0A0(%%rbx), %%ymm5\n\t"
"vmovaps 0x0C0(%%rbx), %%ymm6\n\t"
"vmovaps 0x0E0(%%rbx), %%ymm7\n\t"
#if defined(__x86_64__) || defined(_M_X64)
"vmovaps %8, %%ymm8\n\t"
"vmovaps %9, %%ymm9\n\t"
"vmovaps %10, %%ymm10\n\t"
"vmovaps %11, %%ymm11\n\t"
"vmovaps %12, %%ymm12\n\t"
"vmovaps %13, %%ymm13\n\t"
"vmovaps %14, %%ymm14\n\t"
"vmovaps %15, %%ymm15\n\t"
"vmovaps 0x100(%%rbx), %%ymm8\n\t"
"vmovaps 0x120(%%rbx), %%ymm9\n\t"
"vmovaps 0x140(%%rbx), %%ymm10\n\t"
"vmovaps 0x160(%%rbx), %%ymm11\n\t"
"vmovaps 0x180(%%rbx), %%ymm12\n\t"
"vmovaps 0x1A0(%%rbx), %%ymm13\n\t"
"vmovaps 0x1C0(%%rbx), %%ymm14\n\t"
"vmovaps 0x1E0(%%rbx), %%ymm15\n\t"
#endif
"\n\t"
"int3"
"int3\n\t"
:
: "m"(ymm0), "m"(ymm1), "m"(ymm2), "m"(ymm3), "m"(ymm4), "m"(ymm5),
"m"(ymm6), "m"(ymm7)
#if defined(__x86_64__) || defined(_M_X64)
,
"m"(ymm8), "m"(ymm9), "m"(ymm10), "m"(ymm11),
"m"(ymm12), "m"(ymm13), "m"(ymm14), "m"(ymm15)
#endif
: "b"(ymm)
: "%ymm0", "%ymm1", "%ymm2", "%ymm3", "%ymm4", "%ymm5", "%ymm6", "%ymm7"
#if defined(__x86_64__) || defined(_M_X64)
,

0 comments on commit acbaa49

Please sign in to comment.
You can’t perform that action at this time.