Skip to content

Commit

Permalink
Add support for Loongarch
Browse files Browse the repository at this point in the history
  • Loading branch information
fangyaling committed Jan 29, 2024
1 parent 46e71a9 commit 2068045
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__)
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__)
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(__loongarch64)
#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 2068045

Please sign in to comment.