Bug 497723 - forgot to restore callgrind output cleanup
[valgrind.git] / none / tests / ppc64 / test_mcrxrx.c
blob50aa40239ef4d8430d4f2f960faf8d33a021872a
1 /*
2 * Valgrind testcase for mcrxrx.
3 * This is a power9 (isa 3.0) instruction that copies
4 * OV,OV32,CA,CA32 fields from the XER and places them
5 * into a specified field of the CR. */
7 #include <stdio.h>
8 #include <string.h>
9 #include <unistd.h>
11 unsigned long long current_cr;
12 unsigned long long current_xer;
14 inline static void dissect_cr_field (unsigned long long full_cr, int offset) {
15 int mask;
16 int crfield;
17 mask = 0xf << (offset*4);
18 crfield = full_cr & mask;
19 crfield = crfield >> 4*offset;
21 if (crfield & 0x01) printf("(LT)"); else printf(" - ");
22 if (crfield & 0x02) printf("(GT)"); else printf(" - ");
23 if (crfield & 0x04) printf("(EQ)"); else printf(" - ");
24 if (crfield & 0x08) printf("(SO)"); else printf(" - ");
27 /* dissect_xer helpers */
28 static char * xer_strings[] = {
29 " 0-RSVD", " 1-RSVD", " 2-RSVD", " 3-RSVD", " 4-RSVD", " 5-RSVD", " 6-RSVD",
30 " 7-RSVD", " 8-RSVD", " 9-RSVD", "10-RSVD", "11-RSVD", "12-RSVD", "13-RSVD",
31 "14-RSVD", "15-RSVD", "16-RSVD", "17-RSVD", "18-RSVD", "19-RSVD",
32 "20-RSVD", "21-RSVD", "22-RSVD", "23-RSVD", "24-RSVD", "25-RSVD",
33 "26-RSVD", "27-RSVD", "28-RSVD", "29-RSVD", "30-RSVD", "31-RSVD",
34 /* 32 */ "SO", "OV", "CA",
35 /* 35 */ "35-RSVD", "36-RSVD", "37-RSVD", "38-RSVD", "39-RSVD",
36 /* 40 */ "40-RSVD", "41-RSVD", "42-RSVD", "43-RSVD",
37 /* 44 */ "OV32", "CA32",
38 /* 46 */ "46-RSVD", "47-RSVD", "48-RSVD", "49-RSVD", "50-RSVD", "51-RSVD",
39 "52-RSVD", "53-RSVD", "54-RSVD", "55-RSVD", "56-RSVD",
40 /* 57:63 # bytes transferred by a Load/Store String Indexed instruction. */
41 "LSI/SSI-0", "LSI/SSI-1", "LSI/SSI-2", "LSI/SSI-3",
42 "LSI/SSI-4", "LSI/SSI-5", "LSI/SSI-6",
45 /* Dissect the XER register contents.
47 static void dissect_xer_raw(unsigned long local_xer) {
48 int i;
49 long mybit;
50 char mystr[30];
51 strcpy(mystr,"");
52 for (i = 0; i <= 63; i++) {
53 mybit = 1ULL << (63 - i); /* compensate for reversed bit numbering. */
54 if (mybit & local_xer) {
55 strcat(mystr,xer_strings[i]);
56 strcat(mystr," ");
59 printf(" %16s",mystr);
62 int main (int argc, char **argv)
64 #if HAS_ISA_3_00
65 /* init xer to zero. */
66 unsigned long long Rx = 0;
67 __asm__ __volatile__ ("mtxer %0" : : "r" (Rx) :"xer");
69 /* iterate over each of the interesting fields in the xer
70 * OV,CA,OV32,CA32. Build a field with those bits set, and
71 * push that into the XER (mtxer). */
72 unsigned long long i18,i19,i29,i30;
73 for (i30=0; i30<2; i30++) { // iterate OV
74 for (i29=0; i29<2; i29++) { // iterate CA
75 for (i19=0; i19<2; i19++) { // iterate OV32
76 for (i18=0; i18<2; i18++) { // iterate CA32
77 Rx = i18 << 18;
78 Rx += i19 << 19;
79 Rx += i29 << 29;
80 Rx += i30 << 30;
82 printf("mcrxrx ");
84 /* move 'Rx' value into the xer. */
85 __asm__ __volatile__ ("mtxer %0" : : "r" (Rx) :"xer");
87 /* Retrieve the XER and print it. */
88 __asm__ __volatile__ ("mfxer %0" : "=b"(current_xer) );
90 /* Moving the xer contents to the CR field # 2
91 * using the mcrxr instruction. */
92 __asm__ __volatile__ (".machine push;" \
93 ".machine power9;" \
94 "mcrxrx 2;" \
95 ".machine pop;" );
97 /* Copy the cr into a reg so we can print it.. */
98 __asm__ __volatile__ ("mfcr %0" : "=b"(current_cr) );
100 dissect_xer_raw(current_xer);
101 printf(" => ");
102 dissect_cr_field(current_cr,5);
103 printf("\n");
108 #else
109 printf("HAS_ISA_3_00 not detected.\n");
110 #endif
111 return 0;