cputil.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  1. /* cputil.h - part of valgrind cpu utilization tool
  2. Copyright (C) 2013,2016,2021 Matthew R. Wette
  3. mwette@alumni.caltech.edu
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License as
  6. published by the Free Software Foundation; either version 2 of
  7. the License, or (at your option) any later version.
  8. */
  9. #ifndef __cputil_h__
  10. #define __cputil_h__
  11. /* Use the macros CU_REGTHR, CU_CLRCTR, CU_GETCTR and CU_GETMUL like the
  12. * following function declarations:
  13. * void CPUTIL_REG_THR(); - register the calling thread
  14. * void CPUTIL_CLR_CTR(); - zero the counter
  15. * unsigned long CPUTIL_GET_CTR(); - return counter value
  16. * unsigned long CPUTIL_GET_DIV(); - return the divisor
  17. *
  18. * Example:
  19. * unsigned long foo_cnt;
  20. * unsigned long foo_div;
  21. *
  22. * CPUTIL_REG_THR(); - in task initialization
  23. *
  24. * CPUTIL_CLR_CTR(); - before each call
  25. * foo();
  26. * foo_cnt = CPUTIL_GET_CTR(); - after each call
  27. *
  28. * foo_div = CPUTIL_GET_DIV(); - to print results
  29. * printf("counts=%u/%d\n", foo_cnt, foo_div);
  30. *
  31. * If any counter grows above ULONG_MAX>>1 cputil stops counting and generates
  32. * an error message after the client program completes execution.
  33. */
  34. #define CPUTIL_REG_THR CU_REGTHR
  35. #define CPUTIL_CLR_CTR CU_CLRCTR
  36. #define CPUTIL_GET_CTR CU_GETCTR
  37. #define CPUTIL_GET_DIV CU_GETDIV
  38. /* backward compatiblity */
  39. #define CPUTIL_CLR_CTR1 CU_CLRCTR
  40. #define CPUTIL_GET_CTR1 CU_GETCTR
  41. /* autocoding: beg */
  42. #if defined(__APPLE__) && defined(__i386__)
  43. #define CU_REGTHR() \
  44. __extension__ ({volatile unsigned int _zzq_args[6]; \
  45. volatile unsigned int _zzq_result; _zzq_args[0] = (unsigned \
  46. int)(0x43550001); _zzq_args[1] = (unsigned int)(0); \
  47. _zzq_args[2] = (unsigned int)(0); _zzq_args[3] = (unsigned \
  48. int)(0); _zzq_args[4] = (unsigned int)(0); _zzq_args[5] = \
  49. (unsigned int)(0); __asm__ volatile( \
  50. "roll $3, %%edi ; roll $13, %%edi\n\t" \
  51. "roll $29, %%edi ; roll $19, %%edi\n\t" "xchgl %%ebx,%%ebx" \
  52. : "=d" (_zzq_result) : "a" (&_zzq_args[0]), "0" (0) : "cc", \
  53. "memory" ); _zzq_result; })
  54. #define CU_CLRCTR() \
  55. __extension__ ({volatile unsigned int _zzq_args[6]; \
  56. volatile unsigned int _zzq_result; _zzq_args[0] = (unsigned \
  57. int)(0x43550002); _zzq_args[1] = (unsigned int)(0); \
  58. _zzq_args[2] = (unsigned int)(0); _zzq_args[3] = (unsigned \
  59. int)(0); _zzq_args[4] = (unsigned int)(0); _zzq_args[5] = \
  60. (unsigned int)(0); __asm__ volatile( \
  61. "roll $3, %%edi ; roll $13, %%edi\n\t" \
  62. "roll $29, %%edi ; roll $19, %%edi\n\t" "xchgl %%ebx,%%ebx" \
  63. : "=d" (_zzq_result) : "a" (&_zzq_args[0]), "0" (0) : "cc", \
  64. "memory" ); _zzq_result; })
  65. #define CU_GETCTR() \
  66. __extension__ ({volatile unsigned int _zzq_args[6]; \
  67. volatile unsigned int _zzq_result; _zzq_args[0] = (unsigned \
  68. int)(0x43550003); _zzq_args[1] = (unsigned int)(0); \
  69. _zzq_args[2] = (unsigned int)(0); _zzq_args[3] = (unsigned \
  70. int)(0); _zzq_args[4] = (unsigned int)(0); _zzq_args[5] = \
  71. (unsigned int)(0); __asm__ volatile( \
  72. "roll $3, %%edi ; roll $13, %%edi\n\t" \
  73. "roll $29, %%edi ; roll $19, %%edi\n\t" "xchgl %%ebx,%%ebx" \
  74. : "=d" (_zzq_result) : "a" (&_zzq_args[0]), "0" (0) : "cc", \
  75. "memory" ); _zzq_result; })
  76. #define CU_GETDIV() \
  77. __extension__ ({volatile unsigned int _zzq_args[6]; \
  78. volatile unsigned int _zzq_result; _zzq_args[0] = (unsigned \
  79. int)(0x43550004); _zzq_args[1] = (unsigned int)(0); \
  80. _zzq_args[2] = (unsigned int)(0); _zzq_args[3] = (unsigned \
  81. int)(0); _zzq_args[4] = (unsigned int)(0); _zzq_args[5] = \
  82. (unsigned int)(0); __asm__ volatile( \
  83. "roll $3, %%edi ; roll $13, %%edi\n\t" \
  84. "roll $29, %%edi ; roll $19, %%edi\n\t" "xchgl %%ebx,%%ebx" \
  85. : "=d" (_zzq_result) : "a" (&_zzq_args[0]), "0" (0) : "cc", \
  86. "memory" ); _zzq_result; })
  87. #elif defined(__APPLE__) && defined(__x86_64__)
  88. #define CU_REGTHR() \
  89. __extension__ ({ volatile unsigned long int _zzq_args[6]; \
  90. volatile unsigned long int _zzq_result; _zzq_args[0] = \
  91. (unsigned long int)(0x43550001); _zzq_args[1] = (unsigned \
  92. long int)(0); _zzq_args[2] = (unsigned long int)(0); \
  93. _zzq_args[3] = (unsigned long int)(0); _zzq_args[4] = \
  94. (unsigned long int)(0); _zzq_args[5] = (unsigned long \
  95. int)(0); __asm__ volatile( \
  96. "rolq $3, %%rdi ; rolq $13, %%rdi\n\t" \
  97. "rolq $61, %%rdi ; rolq $51, %%rdi\n\t" "xchgq %%rbx,%%rbx" \
  98. : "=d" (_zzq_result) : "a" (&_zzq_args[0]), "0" (0) : "cc", \
  99. "memory" ); _zzq_result; })
  100. #define CU_CLRCTR() \
  101. __extension__ ({ volatile unsigned long int _zzq_args[6]; \
  102. volatile unsigned long int _zzq_result; _zzq_args[0] = \
  103. (unsigned long int)(0x43550002); _zzq_args[1] = (unsigned \
  104. long int)(0); _zzq_args[2] = (unsigned long int)(0); \
  105. _zzq_args[3] = (unsigned long int)(0); _zzq_args[4] = \
  106. (unsigned long int)(0); _zzq_args[5] = (unsigned long \
  107. int)(0); __asm__ volatile( \
  108. "rolq $3, %%rdi ; rolq $13, %%rdi\n\t" \
  109. "rolq $61, %%rdi ; rolq $51, %%rdi\n\t" "xchgq %%rbx,%%rbx" \
  110. : "=d" (_zzq_result) : "a" (&_zzq_args[0]), "0" (0) : "cc", \
  111. "memory" ); _zzq_result; })
  112. #define CU_GETCTR() \
  113. __extension__ ({ volatile unsigned long int _zzq_args[6]; \
  114. volatile unsigned long int _zzq_result; _zzq_args[0] = \
  115. (unsigned long int)(0x43550003); _zzq_args[1] = (unsigned \
  116. long int)(0); _zzq_args[2] = (unsigned long int)(0); \
  117. _zzq_args[3] = (unsigned long int)(0); _zzq_args[4] = \
  118. (unsigned long int)(0); _zzq_args[5] = (unsigned long \
  119. int)(0); __asm__ volatile( \
  120. "rolq $3, %%rdi ; rolq $13, %%rdi\n\t" \
  121. "rolq $61, %%rdi ; rolq $51, %%rdi\n\t" "xchgq %%rbx,%%rbx" \
  122. : "=d" (_zzq_result) : "a" (&_zzq_args[0]), "0" (0) : "cc", \
  123. "memory" ); _zzq_result; })
  124. #define CU_GETDIV() \
  125. __extension__ ({ volatile unsigned long int _zzq_args[6]; \
  126. volatile unsigned long int _zzq_result; _zzq_args[0] = \
  127. (unsigned long int)(0x43550004); _zzq_args[1] = (unsigned \
  128. long int)(0); _zzq_args[2] = (unsigned long int)(0); \
  129. _zzq_args[3] = (unsigned long int)(0); _zzq_args[4] = \
  130. (unsigned long int)(0); _zzq_args[5] = (unsigned long \
  131. int)(0); __asm__ volatile( \
  132. "rolq $3, %%rdi ; rolq $13, %%rdi\n\t" \
  133. "rolq $61, %%rdi ; rolq $51, %%rdi\n\t" "xchgq %%rbx,%%rbx" \
  134. : "=d" (_zzq_result) : "a" (&_zzq_args[0]), "0" (0) : "cc", \
  135. "memory" ); _zzq_result; })
  136. #elif defined(__MINGW32__) || defined(__CYGWIN32__) || (defined(_WIN32) && \
  137. defined(_M_IX86))
  138. #define CU_REGTHR() \
  139. __extension__ ({volatile unsigned int _zzq_args[6]; \
  140. volatile unsigned int _zzq_result; _zzq_args[0] = (unsigned \
  141. int)(0x43550001); _zzq_args[1] = (unsigned int)(0); \
  142. _zzq_args[2] = (unsigned int)(0); _zzq_args[3] = (unsigned \
  143. int)(0); _zzq_args[4] = (unsigned int)(0); _zzq_args[5] = \
  144. (unsigned int)(0); __asm__ volatile( \
  145. "roll $3, %%edi ; roll $13, %%edi\n\t" \
  146. "roll $29, %%edi ; roll $19, %%edi\n\t" "xchgl %%ebx,%%ebx" \
  147. : "=d" (_zzq_result) : "a" (&_zzq_args[0]), "0" (0) : "cc", \
  148. "memory" ); _zzq_result; })
  149. #define CU_CLRCTR() \
  150. __extension__ ({volatile unsigned int _zzq_args[6]; \
  151. volatile unsigned int _zzq_result; _zzq_args[0] = (unsigned \
  152. int)(0x43550002); _zzq_args[1] = (unsigned int)(0); \
  153. _zzq_args[2] = (unsigned int)(0); _zzq_args[3] = (unsigned \
  154. int)(0); _zzq_args[4] = (unsigned int)(0); _zzq_args[5] = \
  155. (unsigned int)(0); __asm__ volatile( \
  156. "roll $3, %%edi ; roll $13, %%edi\n\t" \
  157. "roll $29, %%edi ; roll $19, %%edi\n\t" "xchgl %%ebx,%%ebx" \
  158. : "=d" (_zzq_result) : "a" (&_zzq_args[0]), "0" (0) : "cc", \
  159. "memory" ); _zzq_result; })
  160. #define CU_GETCTR() \
  161. __extension__ ({volatile unsigned int _zzq_args[6]; \
  162. volatile unsigned int _zzq_result; _zzq_args[0] = (unsigned \
  163. int)(0x43550003); _zzq_args[1] = (unsigned int)(0); \
  164. _zzq_args[2] = (unsigned int)(0); _zzq_args[3] = (unsigned \
  165. int)(0); _zzq_args[4] = (unsigned int)(0); _zzq_args[5] = \
  166. (unsigned int)(0); __asm__ volatile( \
  167. "roll $3, %%edi ; roll $13, %%edi\n\t" \
  168. "roll $29, %%edi ; roll $19, %%edi\n\t" "xchgl %%ebx,%%ebx" \
  169. : "=d" (_zzq_result) : "a" (&_zzq_args[0]), "0" (0) : "cc", \
  170. "memory" ); _zzq_result; })
  171. #define CU_GETDIV() \
  172. __extension__ ({volatile unsigned int _zzq_args[6]; \
  173. volatile unsigned int _zzq_result; _zzq_args[0] = (unsigned \
  174. int)(0x43550004); _zzq_args[1] = (unsigned int)(0); \
  175. _zzq_args[2] = (unsigned int)(0); _zzq_args[3] = (unsigned \
  176. int)(0); _zzq_args[4] = (unsigned int)(0); _zzq_args[5] = \
  177. (unsigned int)(0); __asm__ volatile( \
  178. "roll $3, %%edi ; roll $13, %%edi\n\t" \
  179. "roll $29, %%edi ; roll $19, %%edi\n\t" "xchgl %%ebx,%%ebx" \
  180. : "=d" (_zzq_result) : "a" (&_zzq_args[0]), "0" (0) : "cc", \
  181. "memory" ); _zzq_result; })
  182. #elif defined(__linux__) && defined(__i386__)
  183. #define CU_REGTHR() \
  184. __extension__ ({volatile unsigned int _zzq_args[6]; \
  185. volatile unsigned int _zzq_result; _zzq_args[0] = (unsigned \
  186. int)(0x43550001); _zzq_args[1] = (unsigned int)(0); \
  187. _zzq_args[2] = (unsigned int)(0); _zzq_args[3] = (unsigned \
  188. int)(0); _zzq_args[4] = (unsigned int)(0); _zzq_args[5] = \
  189. (unsigned int)(0); __asm__ volatile( \
  190. "roll $3, %%edi ; roll $13, %%edi\n\t" \
  191. "roll $29, %%edi ; roll $19, %%edi\n\t" "xchgl %%ebx,%%ebx" \
  192. : "=d" (_zzq_result) : "a" (&_zzq_args[0]), "0" (0) : "cc", \
  193. "memory" ); _zzq_result; })
  194. #define CU_CLRCTR() \
  195. __extension__ ({volatile unsigned int _zzq_args[6]; \
  196. volatile unsigned int _zzq_result; _zzq_args[0] = (unsigned \
  197. int)(0x43550002); _zzq_args[1] = (unsigned int)(0); \
  198. _zzq_args[2] = (unsigned int)(0); _zzq_args[3] = (unsigned \
  199. int)(0); _zzq_args[4] = (unsigned int)(0); _zzq_args[5] = \
  200. (unsigned int)(0); __asm__ volatile( \
  201. "roll $3, %%edi ; roll $13, %%edi\n\t" \
  202. "roll $29, %%edi ; roll $19, %%edi\n\t" "xchgl %%ebx,%%ebx" \
  203. : "=d" (_zzq_result) : "a" (&_zzq_args[0]), "0" (0) : "cc", \
  204. "memory" ); _zzq_result; })
  205. #define CU_GETCTR() \
  206. __extension__ ({volatile unsigned int _zzq_args[6]; \
  207. volatile unsigned int _zzq_result; _zzq_args[0] = (unsigned \
  208. int)(0x43550003); _zzq_args[1] = (unsigned int)(0); \
  209. _zzq_args[2] = (unsigned int)(0); _zzq_args[3] = (unsigned \
  210. int)(0); _zzq_args[4] = (unsigned int)(0); _zzq_args[5] = \
  211. (unsigned int)(0); __asm__ volatile( \
  212. "roll $3, %%edi ; roll $13, %%edi\n\t" \
  213. "roll $29, %%edi ; roll $19, %%edi\n\t" "xchgl %%ebx,%%ebx" \
  214. : "=d" (_zzq_result) : "a" (&_zzq_args[0]), "0" (0) : "cc", \
  215. "memory" ); _zzq_result; })
  216. #define CU_GETDIV() \
  217. __extension__ ({volatile unsigned int _zzq_args[6]; \
  218. volatile unsigned int _zzq_result; _zzq_args[0] = (unsigned \
  219. int)(0x43550004); _zzq_args[1] = (unsigned int)(0); \
  220. _zzq_args[2] = (unsigned int)(0); _zzq_args[3] = (unsigned \
  221. int)(0); _zzq_args[4] = (unsigned int)(0); _zzq_args[5] = \
  222. (unsigned int)(0); __asm__ volatile( \
  223. "roll $3, %%edi ; roll $13, %%edi\n\t" \
  224. "roll $29, %%edi ; roll $19, %%edi\n\t" "xchgl %%ebx,%%ebx" \
  225. : "=d" (_zzq_result) : "a" (&_zzq_args[0]), "0" (0) : "cc", \
  226. "memory" ); _zzq_result; })
  227. #elif defined(__linux__) && defined(__x86_64__)
  228. #define CU_REGTHR() \
  229. __extension__ ({ volatile unsigned long int _zzq_args[6]; \
  230. volatile unsigned long int _zzq_result; _zzq_args[0] = \
  231. (unsigned long int)(0x43550001); _zzq_args[1] = (unsigned \
  232. long int)(0); _zzq_args[2] = (unsigned long int)(0); \
  233. _zzq_args[3] = (unsigned long int)(0); _zzq_args[4] = \
  234. (unsigned long int)(0); _zzq_args[5] = (unsigned long \
  235. int)(0); __asm__ volatile( \
  236. "rolq $3, %%rdi ; rolq $13, %%rdi\n\t" \
  237. "rolq $61, %%rdi ; rolq $51, %%rdi\n\t" "xchgq %%rbx,%%rbx" \
  238. : "=d" (_zzq_result) : "a" (&_zzq_args[0]), "0" (0) : "cc", \
  239. "memory" ); _zzq_result; })
  240. #define CU_CLRCTR() \
  241. __extension__ ({ volatile unsigned long int _zzq_args[6]; \
  242. volatile unsigned long int _zzq_result; _zzq_args[0] = \
  243. (unsigned long int)(0x43550002); _zzq_args[1] = (unsigned \
  244. long int)(0); _zzq_args[2] = (unsigned long int)(0); \
  245. _zzq_args[3] = (unsigned long int)(0); _zzq_args[4] = \
  246. (unsigned long int)(0); _zzq_args[5] = (unsigned long \
  247. int)(0); __asm__ volatile( \
  248. "rolq $3, %%rdi ; rolq $13, %%rdi\n\t" \
  249. "rolq $61, %%rdi ; rolq $51, %%rdi\n\t" "xchgq %%rbx,%%rbx" \
  250. : "=d" (_zzq_result) : "a" (&_zzq_args[0]), "0" (0) : "cc", \
  251. "memory" ); _zzq_result; })
  252. #define CU_GETCTR() \
  253. __extension__ ({ volatile unsigned long int _zzq_args[6]; \
  254. volatile unsigned long int _zzq_result; _zzq_args[0] = \
  255. (unsigned long int)(0x43550003); _zzq_args[1] = (unsigned \
  256. long int)(0); _zzq_args[2] = (unsigned long int)(0); \
  257. _zzq_args[3] = (unsigned long int)(0); _zzq_args[4] = \
  258. (unsigned long int)(0); _zzq_args[5] = (unsigned long \
  259. int)(0); __asm__ volatile( \
  260. "rolq $3, %%rdi ; rolq $13, %%rdi\n\t" \
  261. "rolq $61, %%rdi ; rolq $51, %%rdi\n\t" "xchgq %%rbx,%%rbx" \
  262. : "=d" (_zzq_result) : "a" (&_zzq_args[0]), "0" (0) : "cc", \
  263. "memory" ); _zzq_result; })
  264. #define CU_GETDIV() \
  265. __extension__ ({ volatile unsigned long int _zzq_args[6]; \
  266. volatile unsigned long int _zzq_result; _zzq_args[0] = \
  267. (unsigned long int)(0x43550004); _zzq_args[1] = (unsigned \
  268. long int)(0); _zzq_args[2] = (unsigned long int)(0); \
  269. _zzq_args[3] = (unsigned long int)(0); _zzq_args[4] = \
  270. (unsigned long int)(0); _zzq_args[5] = (unsigned long \
  271. int)(0); __asm__ volatile( \
  272. "rolq $3, %%rdi ; rolq $13, %%rdi\n\t" \
  273. "rolq $61, %%rdi ; rolq $51, %%rdi\n\t" "xchgq %%rbx,%%rbx" \
  274. : "=d" (_zzq_result) : "a" (&_zzq_args[0]), "0" (0) : "cc", \
  275. "memory" ); _zzq_result; })
  276. #elif defined(__linux__) && defined(__powerpc__) && !defined(__powerpc64__)
  277. #define CU_REGTHR() \
  278. __extension__ ({ unsigned int _zzq_args[6]; unsigned int \
  279. _zzq_result; unsigned int* _zzq_ptr; _zzq_args[0] = \
  280. (unsigned int)(0x43550001); _zzq_args[1] = (unsigned \
  281. int)(0); _zzq_args[2] = (unsigned int)(0); _zzq_args[3] = \
  282. (unsigned int)(0); _zzq_args[4] = (unsigned int)(0); \
  283. _zzq_args[5] = (unsigned int)(0); _zzq_ptr = _zzq_args; \
  284. __asm__ volatile("mr 3,%1\n\t" "mr 4,%2\n\t" \
  285. "rlwinm 0,0,3,0,31 ; rlwinm 0,0,13,0,31\n\t" \
  286. "rlwinm 0,0,29,0,31 ; rlwinm 0,0,19,0,31\n\t" \
  287. "or 1,1,1\n\t" "mr %0,3" : "=b" (_zzq_result) : "b" (0), \
  288. "b" (_zzq_ptr) : "cc", "memory", "r3", "r4"); _zzq_result; \
  289. })
  290. #define CU_CLRCTR() \
  291. __extension__ ({ unsigned int _zzq_args[6]; unsigned int \
  292. _zzq_result; unsigned int* _zzq_ptr; _zzq_args[0] = \
  293. (unsigned int)(0x43550002); _zzq_args[1] = (unsigned \
  294. int)(0); _zzq_args[2] = (unsigned int)(0); _zzq_args[3] = \
  295. (unsigned int)(0); _zzq_args[4] = (unsigned int)(0); \
  296. _zzq_args[5] = (unsigned int)(0); _zzq_ptr = _zzq_args; \
  297. __asm__ volatile("mr 3,%1\n\t" "mr 4,%2\n\t" \
  298. "rlwinm 0,0,3,0,31 ; rlwinm 0,0,13,0,31\n\t" \
  299. "rlwinm 0,0,29,0,31 ; rlwinm 0,0,19,0,31\n\t" \
  300. "or 1,1,1\n\t" "mr %0,3" : "=b" (_zzq_result) : "b" (0), \
  301. "b" (_zzq_ptr) : "cc", "memory", "r3", "r4"); _zzq_result; \
  302. })
  303. #define CU_GETCTR() \
  304. __extension__ ({ unsigned int _zzq_args[6]; unsigned int \
  305. _zzq_result; unsigned int* _zzq_ptr; _zzq_args[0] = \
  306. (unsigned int)(0x43550003); _zzq_args[1] = (unsigned \
  307. int)(0); _zzq_args[2] = (unsigned int)(0); _zzq_args[3] = \
  308. (unsigned int)(0); _zzq_args[4] = (unsigned int)(0); \
  309. _zzq_args[5] = (unsigned int)(0); _zzq_ptr = _zzq_args; \
  310. __asm__ volatile("mr 3,%1\n\t" "mr 4,%2\n\t" \
  311. "rlwinm 0,0,3,0,31 ; rlwinm 0,0,13,0,31\n\t" \
  312. "rlwinm 0,0,29,0,31 ; rlwinm 0,0,19,0,31\n\t" \
  313. "or 1,1,1\n\t" "mr %0,3" : "=b" (_zzq_result) : "b" (0), \
  314. "b" (_zzq_ptr) : "cc", "memory", "r3", "r4"); _zzq_result; \
  315. })
  316. #define CU_GETDIV() \
  317. __extension__ ({ unsigned int _zzq_args[6]; unsigned int \
  318. _zzq_result; unsigned int* _zzq_ptr; _zzq_args[0] = \
  319. (unsigned int)(0x43550004); _zzq_args[1] = (unsigned \
  320. int)(0); _zzq_args[2] = (unsigned int)(0); _zzq_args[3] = \
  321. (unsigned int)(0); _zzq_args[4] = (unsigned int)(0); \
  322. _zzq_args[5] = (unsigned int)(0); _zzq_ptr = _zzq_args; \
  323. __asm__ volatile("mr 3,%1\n\t" "mr 4,%2\n\t" \
  324. "rlwinm 0,0,3,0,31 ; rlwinm 0,0,13,0,31\n\t" \
  325. "rlwinm 0,0,29,0,31 ; rlwinm 0,0,19,0,31\n\t" \
  326. "or 1,1,1\n\t" "mr %0,3" : "=b" (_zzq_result) : "b" (0), \
  327. "b" (_zzq_ptr) : "cc", "memory", "r3", "r4"); _zzq_result; \
  328. })
  329. #elif defined(__linux__) && defined(__powerpc__) && defined(__powerpc64__)
  330. #define CU_REGTHR() \
  331. __extension__ ({ unsigned long int _zzq_args[6]; unsigned \
  332. long int _zzq_result; unsigned long int* _zzq_ptr; \
  333. _zzq_args[0] = (unsigned long int)(0x43550001); \
  334. _zzq_args[1] = (unsigned long int)(0); _zzq_args[2] = \
  335. (unsigned long int)(0); _zzq_args[3] = (unsigned long \
  336. int)(0); _zzq_args[4] = (unsigned long int)(0); \
  337. _zzq_args[5] = (unsigned long int)(0); _zzq_ptr = \
  338. _zzq_args; __asm__ volatile("mr 3,%1\n\t" "mr 4,%2\n\t" \
  339. "rotldi 0,0,3 ; rotldi 0,0,13\n\t" \
  340. "rotldi 0,0,61 ; rotldi 0,0,51\n\t" "or 1,1,1\n\t" \
  341. "mr %0,3" : "=b" (_zzq_result) : "b" (0), "b" (_zzq_ptr) : \
  342. "cc", "memory", "r3", "r4"); _zzq_result; })
  343. #define CU_CLRCTR() \
  344. __extension__ ({ unsigned long int _zzq_args[6]; unsigned \
  345. long int _zzq_result; unsigned long int* _zzq_ptr; \
  346. _zzq_args[0] = (unsigned long int)(0x43550002); \
  347. _zzq_args[1] = (unsigned long int)(0); _zzq_args[2] = \
  348. (unsigned long int)(0); _zzq_args[3] = (unsigned long \
  349. int)(0); _zzq_args[4] = (unsigned long int)(0); \
  350. _zzq_args[5] = (unsigned long int)(0); _zzq_ptr = \
  351. _zzq_args; __asm__ volatile("mr 3,%1\n\t" "mr 4,%2\n\t" \
  352. "rotldi 0,0,3 ; rotldi 0,0,13\n\t" \
  353. "rotldi 0,0,61 ; rotldi 0,0,51\n\t" "or 1,1,1\n\t" \
  354. "mr %0,3" : "=b" (_zzq_result) : "b" (0), "b" (_zzq_ptr) : \
  355. "cc", "memory", "r3", "r4"); _zzq_result; })
  356. #define CU_GETCTR() \
  357. __extension__ ({ unsigned long int _zzq_args[6]; unsigned \
  358. long int _zzq_result; unsigned long int* _zzq_ptr; \
  359. _zzq_args[0] = (unsigned long int)(0x43550003); \
  360. _zzq_args[1] = (unsigned long int)(0); _zzq_args[2] = \
  361. (unsigned long int)(0); _zzq_args[3] = (unsigned long \
  362. int)(0); _zzq_args[4] = (unsigned long int)(0); \
  363. _zzq_args[5] = (unsigned long int)(0); _zzq_ptr = \
  364. _zzq_args; __asm__ volatile("mr 3,%1\n\t" "mr 4,%2\n\t" \
  365. "rotldi 0,0,3 ; rotldi 0,0,13\n\t" \
  366. "rotldi 0,0,61 ; rotldi 0,0,51\n\t" "or 1,1,1\n\t" \
  367. "mr %0,3" : "=b" (_zzq_result) : "b" (0), "b" (_zzq_ptr) : \
  368. "cc", "memory", "r3", "r4"); _zzq_result; })
  369. #define CU_GETDIV() \
  370. __extension__ ({ unsigned long int _zzq_args[6]; unsigned \
  371. long int _zzq_result; unsigned long int* _zzq_ptr; \
  372. _zzq_args[0] = (unsigned long int)(0x43550004); \
  373. _zzq_args[1] = (unsigned long int)(0); _zzq_args[2] = \
  374. (unsigned long int)(0); _zzq_args[3] = (unsigned long \
  375. int)(0); _zzq_args[4] = (unsigned long int)(0); \
  376. _zzq_args[5] = (unsigned long int)(0); _zzq_ptr = \
  377. _zzq_args; __asm__ volatile("mr 3,%1\n\t" "mr 4,%2\n\t" \
  378. "rotldi 0,0,3 ; rotldi 0,0,13\n\t" \
  379. "rotldi 0,0,61 ; rotldi 0,0,51\n\t" "or 1,1,1\n\t" \
  380. "mr %0,3" : "=b" (_zzq_result) : "b" (0), "b" (_zzq_ptr) : \
  381. "cc", "memory", "r3", "r4"); _zzq_result; })
  382. #elif defined(__linux__) && defined(__arm__)
  383. #define CU_REGTHR() \
  384. __extension__ ({volatile unsigned int _zzq_args[6]; \
  385. volatile unsigned int _zzq_result; _zzq_args[0] = (unsigned \
  386. int)(0x43550001); _zzq_args[1] = (unsigned int)(0); \
  387. _zzq_args[2] = (unsigned int)(0); _zzq_args[3] = (unsigned \
  388. int)(0); _zzq_args[4] = (unsigned int)(0); _zzq_args[5] = \
  389. (unsigned int)(0); __asm__ volatile("mov r3, %1\n\t" \
  390. "mov r4, %2\n\t" \
  391. "mov r12, r12, ror #3 ; mov r12, r12, ror #13 \n\t" \
  392. "mov r12, r12, ror #29 ; mov r12, r12, ror #19 \n\t" \
  393. "orr r10, r10, r10\n\t" "mov %0, r3" : "=r" (_zzq_result) : \
  394. "r" (0), "r" (&_zzq_args[0]) : "cc","memory", "r3", "r4"); \
  395. _zzq_result; })
  396. #define CU_CLRCTR() \
  397. __extension__ ({volatile unsigned int _zzq_args[6]; \
  398. volatile unsigned int _zzq_result; _zzq_args[0] = (unsigned \
  399. int)(0x43550002); _zzq_args[1] = (unsigned int)(0); \
  400. _zzq_args[2] = (unsigned int)(0); _zzq_args[3] = (unsigned \
  401. int)(0); _zzq_args[4] = (unsigned int)(0); _zzq_args[5] = \
  402. (unsigned int)(0); __asm__ volatile("mov r3, %1\n\t" \
  403. "mov r4, %2\n\t" \
  404. "mov r12, r12, ror #3 ; mov r12, r12, ror #13 \n\t" \
  405. "mov r12, r12, ror #29 ; mov r12, r12, ror #19 \n\t" \
  406. "orr r10, r10, r10\n\t" "mov %0, r3" : "=r" (_zzq_result) : \
  407. "r" (0), "r" (&_zzq_args[0]) : "cc","memory", "r3", "r4"); \
  408. _zzq_result; })
  409. #define CU_GETCTR() \
  410. __extension__ ({volatile unsigned int _zzq_args[6]; \
  411. volatile unsigned int _zzq_result; _zzq_args[0] = (unsigned \
  412. int)(0x43550003); _zzq_args[1] = (unsigned int)(0); \
  413. _zzq_args[2] = (unsigned int)(0); _zzq_args[3] = (unsigned \
  414. int)(0); _zzq_args[4] = (unsigned int)(0); _zzq_args[5] = \
  415. (unsigned int)(0); __asm__ volatile("mov r3, %1\n\t" \
  416. "mov r4, %2\n\t" \
  417. "mov r12, r12, ror #3 ; mov r12, r12, ror #13 \n\t" \
  418. "mov r12, r12, ror #29 ; mov r12, r12, ror #19 \n\t" \
  419. "orr r10, r10, r10\n\t" "mov %0, r3" : "=r" (_zzq_result) : \
  420. "r" (0), "r" (&_zzq_args[0]) : "cc","memory", "r3", "r4"); \
  421. _zzq_result; })
  422. #define CU_GETDIV() \
  423. __extension__ ({volatile unsigned int _zzq_args[6]; \
  424. volatile unsigned int _zzq_result; _zzq_args[0] = (unsigned \
  425. int)(0x43550004); _zzq_args[1] = (unsigned int)(0); \
  426. _zzq_args[2] = (unsigned int)(0); _zzq_args[3] = (unsigned \
  427. int)(0); _zzq_args[4] = (unsigned int)(0); _zzq_args[5] = \
  428. (unsigned int)(0); __asm__ volatile("mov r3, %1\n\t" \
  429. "mov r4, %2\n\t" \
  430. "mov r12, r12, ror #3 ; mov r12, r12, ror #13 \n\t" \
  431. "mov r12, r12, ror #29 ; mov r12, r12, ror #19 \n\t" \
  432. "orr r10, r10, r10\n\t" "mov %0, r3" : "=r" (_zzq_result) : \
  433. "r" (0), "r" (&_zzq_args[0]) : "cc","memory", "r3", "r4"); \
  434. _zzq_result; })
  435. #elif defined(__linux__) && defined(__x390__) && defined(__s390x__)
  436. #define CU_REGTHR() \
  437. (0)
  438. #define CU_CLRCTR() \
  439. (0)
  440. #define CU_GETCTR() \
  441. (0)
  442. #define CU_GETDIV() \
  443. (0)
  444. #elif defined(__linux__) && defined(__mips__)
  445. #define CU_REGTHR() \
  446. (0)
  447. #define CU_CLRCTR() \
  448. (0)
  449. #define CU_GETCTR() \
  450. (0)
  451. #define CU_GETDIV() \
  452. (0)
  453. #else
  454. #define CU_REGTHR() 0
  455. #define CU_CLRCTR() 0
  456. #define CU_GETCTR() 0
  457. #define CU_GETDIV() 0
  458. #endif
  459. /* autocoding: end */
  460. #endif
  461. /* --- last line --- */