0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include <stdio.h>
0015 #include <stdlib.h>
0016 #include <unistd.h>
0017 #include <string.h>
0018
0019 #include "tm.h"
0020 #include "utils.h"
0021
0022 int num_loops = 10000;
0023
0024 int test_tar(void)
0025 {
0026 int i;
0027
0028 SKIP_IF(!have_htm());
0029 SKIP_IF(htm_is_synthetic());
0030 SKIP_IF(!is_ppc64le());
0031
0032 for (i = 0; i < num_loops; i++)
0033 {
0034 uint64_t result = 0;
0035 asm __volatile__(
0036 "li 7, 1;"
0037 "mtspr %[tar], 7;"
0038 "tbegin.;"
0039 "beq 3f;"
0040 "li 4, 0x7000;"
0041 "2:;"
0042 "li 7, 2;"
0043 "mtspr %[tar], 7;"
0044 "tsuspend.;"
0045 "li 7, 3;"
0046 "mtspr %[tar], 7;"
0047 "tresume.;"
0048 "subi 4, 4, 1;"
0049 "cmpdi 4, 0;"
0050 "bne 2b;"
0051 "tend.;"
0052
0053
0054 "mfspr 7, %[tar];"
0055 "ori %[res], 7, 4;"
0056 "b 4f;"
0057
0058
0059 "3:;"
0060 "mfspr 7, %[tar];"
0061 "ori %[res], 7, 8;"
0062 "4:;"
0063
0064 : [res]"=r"(result)
0065 : [tar]"i"(SPRN_TAR)
0066 : "memory", "r0", "r4", "r7");
0067
0068
0069
0070 if ((result != 7) && (result != 9))
0071 return 1;
0072 }
0073 return 0;
0074 }
0075
0076 int main(int argc, char *argv[])
0077 {
0078
0079 if (argc > 1) {
0080 if (strcmp(argv[1], "-h") == 0) {
0081 printf("Syntax:\n\t%s [<num loops>]\n",
0082 argv[0]);
0083 return 1;
0084 } else {
0085 num_loops = atoi(argv[1]);
0086 }
0087 }
0088
0089 printf("Starting, %d loops\n", num_loops);
0090
0091 return test_harness(test_tar, "tm_tar");
0092 }