0001-fix-armv7-asm-inline-error-GH-115.patch 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. From 9c739800a8915d5f2a73c840190920e95ffa1c5c Mon Sep 17 00:00:00 2001
  2. From: Reini Urban <rurban@cpan.org>
  3. Date: Fri, 18 Feb 2022 09:46:45 +0100
  4. Subject: [PATCH] fix armv7 asm inline error GH #115
  5. some armv7 buildroot variants fail on asm.
  6. we already probe for that, so use it.
  7. Fixes GH #115
  8. [Retrieved from:
  9. https://github.com/rurban/safeclib/commit/9c739800a8915d5f2a73c840190920e95ffa1c5c]
  10. Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
  11. ---
  12. tests/perf_private.h | 49 +++++++++++++++++++++++++-------------------
  13. 1 file changed, 28 insertions(+), 21 deletions(-)
  14. diff --git a/tests/perf_private.h b/tests/perf_private.h
  15. index 3296cb3d..843674d3 100644
  16. --- a/tests/perf_private.h
  17. +++ b/tests/perf_private.h
  18. @@ -1,9 +1,9 @@
  19. /*------------------------------------------------------------------
  20. * perf_private.h - Internal benchmarking tools
  21. *
  22. - * 2020 Reini Urban
  23. + * 2020,2022 Reini Urban
  24. *
  25. - * Copyright (c) 2017, 2020 Reini Urban
  26. + * Copyright (c) 2017, 2020, 2022 Reini Urban
  27. * All rights reserved.
  28. *
  29. * Permission is hereby granted, free of charge, to any person
  30. @@ -55,13 +55,16 @@ static inline uint64_t timer_start();
  31. static inline uint64_t timer_end();
  32. static inline clock_t rdtsc() {
  33. -#ifdef __x86_64__
  34. +#ifndef ASM_INLINE
  35. +#define NO_CYCLE_COUNTER
  36. + return clock();
  37. +#elif defined __x86_64__
  38. uint64_t a, d;
  39. - __asm__ volatile("rdtsc" : "=a"(a), "=d"(d));
  40. + ASM_INLINE volatile("rdtsc" : "=a"(a), "=d"(d));
  41. return (clock_t)(a | (d << 32));
  42. #elif defined(__i386__)
  43. clock_t x;
  44. - __asm__ volatile("rdtsc" : "=A"(x));
  45. + ASM_INLINE volatile("rdtsc" : "=A"(x));
  46. return x;
  47. #elif defined(__ARM_ARCH) && (__ARM_ARCH >= 7) && (SIZEOF_SIZE_T == 4)
  48. // V7 is the earliest arch that has a standard cyclecount (some say 6)
  49. @@ -69,11 +72,11 @@ static inline clock_t rdtsc() {
  50. uint32_t pmuseren;
  51. uint32_t pmcntenset;
  52. // Read the user mode perf monitor counter access permissions.
  53. - asm volatile("mrc p15, 0, %0, c9, c14, 0" : "=r"(pmuseren));
  54. + ASM_INLINE volatile("mrc p15, 0, %0, c9, c14, 0" : "=r"(pmuseren));
  55. if (pmuseren & 1) { // Allows reading perfmon counters for user mode code.
  56. - asm volatile("mrc p15, 0, %0, c9, c12, 1" : "=r"(pmcntenset));
  57. + ASM_INLINE volatile("mrc p15, 0, %0, c9, c12, 1" : "=r"(pmcntenset));
  58. if (pmcntenset & 0x80000000ul) { // Is it counting?
  59. - asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r"(pmccntr));
  60. + ASM_INLINE volatile("mrc p15, 0, %0, c9, c13, 0" : "=r"(pmccntr));
  61. // The counter is set up to count every 64th cycle
  62. return (int64_t)(pmccntr) * 64; // Should optimize to << 6
  63. }
  64. @@ -83,22 +86,22 @@ static inline clock_t rdtsc() {
  65. uint64_t pmccntr;
  66. uint64_t pmuseren = 1UL;
  67. // Read the user mode perf monitor counter access permissions.
  68. - //asm volatile("mrs cntv_ctl_el0, %0" : "=r" (pmuseren));
  69. + //ASM_INLINE volatile("mrs cntv_ctl_el0, %0" : "=r" (pmuseren));
  70. if (pmuseren & 1) { // Allows reading perfmon counters for user mode code.
  71. - asm volatile("mrs %0, cntvct_el0" : "=r" (pmccntr));
  72. + ASM_INLINE volatile("mrs %0, cntvct_el0" : "=r" (pmccntr));
  73. return (uint64_t)(pmccntr) * 64; // Should optimize to << 6
  74. }
  75. return (uint64_t)rdtsc();
  76. #elif defined(__powerpc64__) || defined(__ppc64__)
  77. uint64_t tb;
  78. - __asm__ volatile (\
  79. + ASM_INLINE volatile (\
  80. "mfspr %0, 268"
  81. : "=r" (tb));
  82. return tb;
  83. #elif defined(__powerpc__) || defined(__ppc__)
  84. // This returns a time-base, which is not always precisely a cycle-count.
  85. uint32_t tbu, tbl, tmp;
  86. - __asm__ volatile (\
  87. + ASM_INLINE volatile (\
  88. "0:\n"
  89. "mftbu %0\n"
  90. "mftbl %1\n"
  91. @@ -109,12 +112,12 @@ static inline clock_t rdtsc() {
  92. return (((uint64_t) tbu << 32) | tbl);
  93. #elif defined(__sparc__)
  94. uint64_t tick;
  95. - asm(".byte 0x83, 0x41, 0x00, 0x00");
  96. - asm("mov %%g1, %0" : "=r" (tick));
  97. + ASM_INLINE(".byte 0x83, 0x41, 0x00, 0x00");
  98. + ASM_INLINE("mov %%g1, %0" : "=r" (tick));
  99. return tick;
  100. #elif defined(__ia64__)
  101. uint64_t itc;
  102. - asm("mov %0 = ar.itc" : "=r" (itc));
  103. + ASM_INLINE("mov %0 = ar.itc" : "=r" (itc));
  104. return itc;
  105. #else
  106. #define NO_CYCLE_COUNTER
  107. @@ -126,9 +129,11 @@ static inline clock_t rdtsc() {
  108. // 3.2.1 The Improved Benchmarking Method
  109. static inline uint64_t timer_start()
  110. {
  111. -#if defined (__i386__) || (defined(__x86_64__) && SIZEOF_SIZE_T == 4)
  112. +#ifndef ASM_INLINE
  113. + return (uint64_t)rdtsc();
  114. +#elif defined (__i386__) || (defined(__x86_64__) && SIZEOF_SIZE_T == 4)
  115. uint32_t cycles_high, cycles_low;
  116. - __asm__ volatile
  117. + ASM_INLINE volatile
  118. ("cpuid\n\t"
  119. "rdtsc\n\t"
  120. "mov %%edx, %0\n\t"
  121. @@ -137,7 +142,7 @@ static inline uint64_t timer_start()
  122. return ((uint64_t)cycles_high << 32) | cycles_low;
  123. #elif defined __x86_64__
  124. uint32_t cycles_high, cycles_low;
  125. - __asm__ volatile
  126. + ASM_INLINE volatile
  127. ("cpuid\n\t"
  128. "rdtsc\n\t"
  129. "mov %%edx, %0\n\t"
  130. @@ -151,9 +156,11 @@ static inline uint64_t timer_start()
  131. static inline uint64_t timer_end()
  132. {
  133. -#if defined (__i386__) || (defined(__x86_64__) && defined (HAVE_BIT32))
  134. +#ifndef ASM_INLINE
  135. + return (uint64_t)rdtsc();
  136. +#elif defined (__i386__) || (defined(__x86_64__) && defined (HAVE_BIT32))
  137. uint32_t cycles_high, cycles_low;
  138. - __asm__ volatile
  139. + ASM_INLINE volatile
  140. ("rdtscp\n\t"
  141. "mov %%edx, %0\n\t"
  142. "mov %%eax, %1\n\t"
  143. @@ -162,7 +169,7 @@ static inline uint64_t timer_end()
  144. return ((uint64_t)cycles_high << 32) | cycles_low;
  145. #elif defined __x86_64__
  146. uint32_t cycles_high, cycles_low;
  147. - __asm__ volatile
  148. + ASM_INLINE volatile
  149. ("rdtscp\n\t"
  150. "mov %%edx, %0\n\t"
  151. "mov %%eax, %1\n\t"