PAPI 7.1.0.0
Loading...
Searching...
No Matches
branches_testcode.c
Go to the documentation of this file.
1#include <stdio.h>
2#include <stdlib.h>
3
4#include "testcode.h"
5
6#define BRNG() {\
7 b = ((z1 << 6) ^ z1) >> 13;\
8 z1 = ((z1 & 4294967294U) << 18) ^ b;\
9 b = ((z2 << 2) ^ z2) >> 27;\
10 z2 = ((z2 & 4294967288U) << 2) ^ b;\
11 b = ((z3 << 13) ^ z3) >> 21;\
12 z3 = ((z3 & 4294967280U) << 7) ^ b;\
13 b = ((z4 << 3) ^ z4) >> 12;\
14 z4 = ((z4 & 4294967168U) << 13) ^ b;\
15 z1++;\
16 result = z1 ^ z2 ^ z3 ^ z4;\
17}
18
19/* This code has 1,500,000 total branches */
20/* 500,000 not-taken conditional branches */
21/* 500,000 taken conditional branches */
22/* 500,000 unconditional branches */
24
25#if defined(__i386__) || (defined __x86_64__)
26 asm( "\txor %%ecx,%%ecx\n"
27 "\tmov $500000,%%ecx\n"
28 "test_loop:\n"
29 "\tjmp test_jmp\n"
30 "\tnop\n"
31 "test_jmp:\n"
32 "\txor %%eax,%%eax\n"
33 "\tjnz test_jmp2\n"
34 "\tinc %%eax\n"
35 "test_jmp2:\n"
36 "\tdec %%ecx\n"
37 "\tjnz test_loop\n"
38 : /* no output registers */
39 : /* no inputs */
40 : "cc", "%ecx", "%eax" /* clobbered */
41 );
42 return 0;
43
44#elif defined(__arm__)
45 /* Initial code contributed by sam wang linux.swang _at_ gmail.com */
46 asm( "\teor r3,r3,r3\n"
47 "\tldr r3,=500000\n"
48 "test_loop:\n"
49 "\tB test_jmp\n"
50 "\tnop\n"
51 "test_jmp:\n"
52 "\teor r2,r2,r2\n"
53 "\tcmp r2,#1\n"
54 "\tbge test_jmp2\n"
55 "\tnop\n"
56 "\tadd r2,r2,#1\n"
57 "test_jmp2:\n"
58 "\tsub r3,r3,#1\n"
59 "\tcmp r3,#1\n"
60 "\tbgt test_loop\n"
61 : /* no output registers */
62 : /* no inputs */
63 : "cc", "r2", "r3" /* clobbered */
64 );
65
66 return 0;
67#elif defined(__aarch64__)
68 asm( "\teor x3,x3,x3\n"
69 "\tldr x3,=500000\n"
70 "test_loop:\n"
71 "\tB test_jmp\n"
72 "\tnop\n"
73 "test_jmp:\n"
74 "\teor x2,x2,x2\n"
75 "\tcmp x2,#1\n"
76 "\tbge test_jmp2\n"
77 "\tnop\n"
78 "\tadd x2,x2,#1\n"
79 "test_jmp2:\n"
80 "\tsub x3,x3,#1\n"
81 "\tcmp x3,#1\n"
82 "\tbgt test_loop\n"
83 : /* no output registers */
84 : /* no inputs */
85 : "cc", "x2", "x3" /* clobbered */
86 );
87
88 return 0;
89#elif defined(__powerpc__)
90 /* Not really optimized */
91
92 asm( "\txor 3,3,3\n"
93 "\tlis 3,500000@ha\n"
94 "\taddi 3,3,500000@l\n"
95 "test_loop:\n"
96 "\tb test_jmp\n"
97 "\tnop\n"
98 "test_jmp:\n"
99 "\txor 4,4,4\n"
100 "\tcmpwi cr0,4,1\n"
101 "\tbge test_jmp2\n"
102 "\tnop\n"
103 "\taddi 4,4,1\n"
104 "test_jmp2:\n"
105 "\taddi 3,3,-1\n"
106 "\tcmpwi cr0,3,1\n"
107 "\tbgt test_loop\n"
108 : /* no output registers */
109 : /* no inputs */
110 : "cr0", "r3", "r4" /* clobbered */
111 );
112
113 return 0;
114#endif
115
116 return -1;
117
118}
119
120
121int random_branches_testcode(int number, int quiet) {
122
123 int j,junk=0;
124 double junk2=5.0;
125 long int b,z1,z2,z3,z4,result;
126 z1=236;
127 z2=347;
128 z3=458;
129 z4=9751;
130
131 for(j=0;j<number;j++) {
132
133 BRNG();
134 if( (result%2)==0 ){
135 junk = result + j;
136 junk = 1 + j/junk;
137 junk2 *= (double)junk;
138 }
139 BRNG();
140 junk = result + j;
141 junk = 1 + j/junk;
142 junk2 *= (double)junk;
143 }
144 if (!quiet) printf("%lf\n",junk2);
145
146 return junk;
147}
148
volatile int result
volatile unsigned int z1
volatile unsigned int z2
volatile unsigned int z3
volatile unsigned int z4
int branches_testcode(void)
#define BRNG()
int random_branches_testcode(int number, int quiet)
static double b[MATRIX_SIZE][MATRIX_SIZE]
Definition: libmsr_basic.c:39
int quiet
Definition: rapl_overflow.c:19