upstream: https://github.com/mirage/mirage-crypto
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

entropy stubs: powerpc64 cycle_counter apply Val_long; specify origin of asm

+24 -14
+24 -14
src/native/entropy_cpu_stubs.c
··· 43 43 } 44 44 #endif /* aarch64 */ 45 45 46 + #if defined (__powerpc64__) 47 + /* from clang's builtin version and gperftools at 48 + https://chromium.googlesource.com/external/gperftools/+/master/src/base/cycleclock.h 49 + */ 50 + static inline uint64_t read_cycle_counter(void) 51 + { 52 + uint64_t rval; 53 + __asm__ volatile ("mfspr %0, 268":"=r" (rval)); 54 + return rval; 55 + } 56 + #endif 57 + 58 + CAMLprim value caml_cycle_counter (value __unused(unit)) { 59 + #if defined (__i386__) || defined (__x86_64__) 60 + return Val_long (__rdtsc ()); 61 + #elif defined (__arm__) || defined (__aarch64__) 62 + return Val_long (read_virtual_count ()); 63 + #elif defined(__powerpc64__) 64 + return Val_long (read_cycle_counter ()); 65 + #else 66 + #error ("No known cycle-counting instruction.") 67 + #endif 68 + } 69 + 46 70 enum cpu_rng_t { 47 71 RNG_NONE = 0, 48 72 RNG_RDRAND = 1, ··· 74 98 __cpu_rng |= RNG_RDSEED; 75 99 break; 76 100 } 77 - #endif 78 - } 79 - 80 - CAMLprim value caml_cycle_counter (value __unused(unit)) { 81 - #if defined (__i386__) || defined (__x86_64__) 82 - return Val_long (__rdtsc ()); 83 - #elif defined (__arm__) || defined (__aarch64__) 84 - return Val_long (read_virtual_count ()); 85 - #elif defined(__powerpc64__) 86 - uint64_t rval; 87 - __asm__ volatile ("mfspr %0, 268":"=r" (rval)); 88 - return rval; 89 - #else 90 - #error ("No known cycle-counting instruction.") 91 101 #endif 92 102 } 93 103