Skip to content

Commit

Permalink
Merge pull request #190 from fangyaling/main
Browse files Browse the repository at this point in the history
Add support for Loongarch
  • Loading branch information
hannesm authored Feb 4, 2024
2 parents cf42ee7 + bce4646 commit a63f181
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/native/entropy_cpu_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ static inline unsigned long get_count(void) {
}
#endif

#if defined (__loongarch_lp64)
static inline unsigned long get_count(void) {
unsigned long count;
__asm__ __volatile__ ("rdtime.d %0, $zero\n" : "=r" (count));

return count;
}
#endif

CAMLprim value mc_cycle_counter (value __unused(unit)) {
#if defined (__i386__) || defined (__x86_64__)
Expand All @@ -157,6 +165,8 @@ CAMLprim value mc_cycle_counter (value __unused(unit)) {
return Val_long (getticks ());
#elif defined(__mips__)
return Val_long (get_count());
#elif defined(__loongarch_lp64)
return Val_long (get_count());
#else
#error ("No known cycle-counting instruction.")
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/native/mirage_crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ extern struct _mc_cpu_features mc_detected_cpu_features;

#endif /* __mc_ACCELERATE__ */

#if defined (__x86_64__) || defined (__aarch64__) || defined (__powerpc64__) || (64 == __riscv_xlen) || defined (__s390x__) || (defined (__mips__) && _MIPS_SIM==_ABI64)
#if defined (__x86_64__) || defined (__aarch64__) || defined (__powerpc64__) || (64 == __riscv_xlen) || defined (__s390x__) || (defined (__mips__) && _MIPS_SIM==_ABI64) || defined (__loongarch_lp64)
#define ARCH_64BIT
#elif defined (__i386__) || defined (__arm__) || (32 == __riscv_xlen) || (defined (__mips__) && _MIPS_SIM==_ABIO32)
#define ARCH_32BIT
Expand Down

0 comments on commit a63f181

Please sign in to comment.