From: Ryan Kavanagh Date: Tue, 20 May 2025 12:15:59 -0400 Subject: Add RISCV64 support Forwarded: no Reviewed-by: Ryan Kavanagh Last-Update: 2025-05-20 --- basis-library/mlton/platform.sig | 2 +- basis-library/mlton/platform.sml | 3 + bin/platform | 3 + doc/guide/src/MLtonPlatform.adoc | 2 +- ...share.rep64.ok => mlton.share.riscv64-linux.ok} | 0 regression/size2.riscv64-linux.ok | 24 +++++ regression/size3.riscv64-linux.ok | 114 +++++++++++++++++++++ runtime/cenv.h | 2 + runtime/platform/riscv64.h | 1 + 9 files changed, 149 insertions(+), 2 deletions(-) copy regression/{mlton.share.rep64.ok => mlton.share.riscv64-linux.ok} (100%) create mode 100644 regression/size2.riscv64-linux.ok create mode 100644 regression/size3.riscv64-linux.ok create mode 100644 runtime/platform/riscv64.h diff --git a/basis-library/mlton/platform.sig b/basis-library/mlton/platform.sig index 44d0967..653b350 100644 --- a/basis-library/mlton/platform.sig +++ b/basis-library/mlton/platform.sig @@ -10,7 +10,7 @@ signature MLTON_PLATFORM = structure Arch: sig datatype t = Alpha | AMD64 | ARM | ARM64 | HPPA | IA64 | LoongArch64 | m68k | - MIPS | MIPS64 | PowerPC | PowerPC64 | RISCV | S390 | Sparc | Wasm32 | X86 + MIPS | MIPS64 | PowerPC | PowerPC64 | RISCV | RISCV64 | S390 | Sparc | Wasm32 | X86 val fromString: string -> t option val host: t diff --git a/basis-library/mlton/platform.sml b/basis-library/mlton/platform.sml index 650fb91..c14baa3 100644 --- a/basis-library/mlton/platform.sml +++ b/basis-library/mlton/platform.sml @@ -43,6 +43,7 @@ structure MLtonPlatform: MLTON_PLATFORM = | PowerPC | PowerPC64 | RISCV + | RISCV64 | S390 | Sparc | Wasm32 @@ -62,6 +63,7 @@ structure MLtonPlatform: MLTON_PLATFORM = (PowerPC, "PowerPC"):: (PowerPC64, "PowerPC64"):: (RISCV, "RISCV"):: + (RISCV64, "RISCV64"):: (S390, "S390"):: (Sparc, "Sparc"):: (Wasm32, "Wasm32"):: @@ -86,6 +88,7 @@ structure MLtonPlatform: MLTON_PLATFORM = | "powerpc" => PowerPC | "powerpc64" => PowerPC64 | "riscv" => RISCV + | "riscv64" => RISCV64 | "s390" => S390 | "sparc" => Sparc | "wasm32" => Wasm32 diff --git a/bin/platform b/bin/platform index eb8a9af..f3a2be1 100755 --- a/bin/platform +++ b/bin/platform @@ -137,6 +137,9 @@ ppc*) Power*) HOST_ARCH=powerpc ;; +riscv64) + HOST_ARCH=riscv64 +;; riscv*) HOST_ARCH=riscv ;; diff --git a/doc/guide/src/MLtonPlatform.adoc b/doc/guide/src/MLtonPlatform.adoc index 8220fd7..f16c312 100644 --- a/doc/guide/src/MLtonPlatform.adoc +++ b/doc/guide/src/MLtonPlatform.adoc @@ -7,7 +7,7 @@ signature MLTON_PLATFORM = structure Arch: sig datatype t = Alpha | AMD64 | ARM | ARM64 | HPPA | IA64 | m68k - | MIPS | MIPS64 | PowerPC | PowerPC64 | S390 | Sparc | X86 + | MIPS | MIPS64 | PowerPC | PowerPC64 | RISCV64 | S390 | Sparc | X86 val fromString: string -> t option val host: t diff --git a/regression/mlton.share.rep64.ok b/regression/mlton.share.riscv64-linux.ok similarity index 100% copy from regression/mlton.share.rep64.ok copy to regression/mlton.share.riscv64-linux.ok diff --git a/regression/size2.riscv64-linux.ok b/regression/size2.riscv64-linux.ok new file mode 100644 index 0000000..5d5f773 --- /dev/null +++ b/regression/size2.riscv64-linux.ok @@ -0,0 +1,24 @@ +The size of a char is = 0 bytes. +The size of an int list of length 4 is = 96 bytes. +The size of a string of length 10 is = 40 bytes. +The size of an int array of length 10 is = 64 bytes. +The size of a double array of length 10 is = 104 bytes. +The size of a (word32 * double) array of length 10 is = 184 bytes. +The size of a (word32 * word32 * double) array of length 10 is = 184 bytes. +The size of a (word64 * double) array of length 10 is = 184 bytes. +The size of a (word16 * double) array of length 10 is = 184 bytes. +The size of a word64 array of length 10 is = 104 bytes. +The size of a (word32 * word64) array of length 10 is = 184 bytes. +The size of a (word32 * word32 * word64) array of length 10 is = 184 bytes. +The size of a (word64 * word64) array of length 10 is = 184 bytes. +The size of a (word16 * word64) array of length 10 is = 184 bytes. +The size of an array of length 10 of 2-ples of ints is = 104 bytes. +The size of an array of length 10 of 2-ples of (shared) ints is = 104 bytes. +The size of an array of length 10 of arrays of length 20 of ints is = 1144 bytes. +The size of an array of length 10 of (shared) arrays of length 20 of ints is = 208 bytes. +The size of an array of length 10 of tuples of word16 * (arrays of length 20 of ints) is = 1224 bytes. +The size of an array of length 10 of tuples of word32 * (arrays of length 20 of ints) is = 1224 bytes. +The size of an array of length 10 of tuples of word64 * (arrays of length 20 of ints) is = 1224 bytes. +The size of an array of length 10 of tuples of real32 * (arrays of length 20 of ints) is = 1224 bytes. +The size of an array of length 10 of tuples of real64 * (arrays of length 20 of ints) is = 1224 bytes. +The size of a useless function is = 0 bytes. diff --git a/regression/size3.riscv64-linux.ok b/regression/size3.riscv64-linux.ok new file mode 100644 index 0000000..48720a9 --- /dev/null +++ b/regression/size3.riscv64-linux.ok @@ -0,0 +1,114 @@ +The size of unit is = 0 bytes. +The size of unit * unit is = 0 bytes. +The size of bool is = 0 bytes. +The size of bool * bool is = 16 bytes. +The size of day is = 0 bytes. +The size of day * day is = 0 bytes. +The size of a char is = 0 bytes. +The size of a char * char is = 0 bytes. +The size of a word8 is = 0 bytes. +The size of a word8 * word8 is = 0 bytes. +The size of a word16 is = 0 bytes. +The size of a word16 * word16 is = 0 bytes. +The size of a word32 is = 0 bytes. +The size of a word32 * word32 is = 16 bytes. +The size of a word64 is = 0 bytes. +The size of a word64 * word64 is = 24 bytes. +The size of a word64 * word64 * word64 is = 32 bytes. +The size of a word64 * word64 * word64 * word64 is = 40 bytes. +The size of a unit list of length 4 is = 64 bytes. +The size of a bool list of length 4 is = 96 bytes. +The size of a day list of length 4 is = 96 bytes. +The size of an int list of length 4 is = 96 bytes. +The size of a string of length 10 is = 40 bytes. +The size of a word64 array of length 0 is = 24 bytes. +The size of a word64 array of length 1 is = 32 bytes. +The size of a word64 array of length 2 is = 40 bytes. +The size of a word64 array of length 3 is = 48 bytes. +The size of a word64 array of length 4 is = 56 bytes. +The size of a word64 array of length 5 is = 64 bytes. +The size of a word64 array of length 6 is = 72 bytes. +The size of a word64 array of length 7 is = 80 bytes. +The size of a word64 array of length 8 is = 88 bytes. +The size of a word64 array of length 9 is = 96 bytes. +The size of a word64 array of length 10 is = 104 bytes. +The size of a word64 array of length 11 is = 112 bytes. +The size of a word64 array of length 12 is = 120 bytes. +The size of a word32 array of length 0 is = 24 bytes. +The size of a word32 array of length 1 is = 32 bytes. +The size of a word32 array of length 2 is = 32 bytes. +The size of a word32 array of length 3 is = 40 bytes. +The size of a word32 array of length 4 is = 40 bytes. +The size of a word32 array of length 5 is = 48 bytes. +The size of a word32 array of length 6 is = 48 bytes. +The size of a word32 array of length 7 is = 56 bytes. +The size of a word32 array of length 8 is = 56 bytes. +The size of a word32 array of length 9 is = 64 bytes. +The size of a word32 array of length 10 is = 64 bytes. +The size of a word32 array of length 11 is = 72 bytes. +The size of a word32 array of length 12 is = 72 bytes. +The size of a word16 array of length 0 is = 24 bytes. +The size of a word16 array of length 1 is = 32 bytes. +The size of a word16 array of length 2 is = 32 bytes. +The size of a word16 array of length 3 is = 32 bytes. +The size of a word16 array of length 4 is = 32 bytes. +The size of a word16 array of length 5 is = 40 bytes. +The size of a word16 array of length 6 is = 40 bytes. +The size of a word16 array of length 7 is = 40 bytes. +The size of a word16 array of length 8 is = 40 bytes. +The size of a word16 array of length 9 is = 48 bytes. +The size of a word16 array of length 10 is = 48 bytes. +The size of a word16 array of length 11 is = 48 bytes. +The size of a word16 array of length 12 is = 48 bytes. +The size of a word8 array of length 0 is = 24 bytes. +The size of a word8 array of length 1 is = 32 bytes. +The size of a word8 array of length 2 is = 32 bytes. +The size of a word8 array of length 3 is = 32 bytes. +The size of a word8 array of length 4 is = 32 bytes. +The size of a word8 array of length 5 is = 32 bytes. +The size of a word8 array of length 6 is = 32 bytes. +The size of a word8 array of length 7 is = 32 bytes. +The size of a word8 array of length 8 is = 32 bytes. +The size of a word8 array of length 9 is = 40 bytes. +The size of a word8 array of length 10 is = 40 bytes. +The size of a word8 array of length 11 is = 40 bytes. +The size of a word8 array of length 12 is = 40 bytes. +The size of a unit array of length 0 is = 24 bytes. +The size of a unit array of length 1 is = 24 bytes. +The size of a unit array of length 2 is = 24 bytes. +The size of a unit array of length 3 is = 24 bytes. +The size of a unit array of length 4 is = 24 bytes. +The size of a unit array of length 5 is = 24 bytes. +The size of a unit array of length 6 is = 24 bytes. +The size of a unit array of length 7 is = 24 bytes. +The size of a unit array of length 8 is = 24 bytes. +The size of a unit array of length 9 is = 24 bytes. +The size of a unit array of length 10 is = 24 bytes. +The size of a unit array of length 11 is = 24 bytes. +The size of a unit array of length 12 is = 24 bytes. +The size of a word64 ref is = 16 bytes. +The size of a word32 ref is = 16 bytes. +The size of a word16 ref is = 16 bytes. +The size of a word8 ref is = 16 bytes. +The size of a unit ref is = 8 bytes. +The size of a double array of length 10 is = 104 bytes. +The size of a (word32 * double) array of length 10 is = 184 bytes. +The size of a (word32 * word32 * double) array of length 10 is = 184 bytes. +The size of a (word64 * double) array of length 10 is = 184 bytes. +The size of a (word16 * double) array of length 10 is = 184 bytes. +The size of a word64 array of length 10 is = 104 bytes. +The size of a (word32 * word64) array of length 10 is = 184 bytes. +The size of a (word32 * word32 * word64) array of length 10 is = 184 bytes. +The size of a (word64 * word64) array of length 10 is = 184 bytes. +The size of a (word16 * word64) array of length 10 is = 184 bytes. +The size of an array of length 10 of 2-ples of ints is = 104 bytes. +The size of an array of length 10 of 2-ples of (shared) ints is = 104 bytes. +The size of an array of length 10 of arrays of length 20 of ints is = 1144 bytes. +The size of an array of length 10 of (shared) arrays of length 20 of ints is = 208 bytes. +The size of an array of length 10 of tuples of word16 * (arrays of length 20 of ints) is = 1224 bytes. +The size of an array of length 10 of tuples of word32 * (arrays of length 20 of ints) is = 1224 bytes. +The size of an array of length 10 of tuples of word64 * (arrays of length 20 of ints) is = 1224 bytes. +The size of an array of length 10 of tuples of real32 * (arrays of length 20 of ints) is = 1224 bytes. +The size of an array of length 10 of tuples of real64 * (arrays of length 20 of ints) is = 1224 bytes. +The size of a useless function is = 0 bytes. +The size of an empty string is = 24 bytes. diff --git a/runtime/cenv.h b/runtime/cenv.h index c805f00..327580b 100644 --- a/runtime/cenv.h +++ b/runtime/cenv.h @@ -111,6 +111,8 @@ COMPILE_TIME_ASSERT(sizeof_double__is_eight, sizeof(double) == 8); #include "platform/powerpc64.h" #elif (defined (__ppc__)) || (defined (__powerpc__)) #include "platform/powerpc.h" +#elif (defined(__riscv) && defined(__riscv_xlen) && __riscv_xlen == 64) +#include "platform/riscv64.h" #elif (defined (__riscv)) #include "platform/riscv.h" #elif (defined (__s390__)) diff --git a/runtime/platform/riscv64.h b/runtime/platform/riscv64.h new file mode 100644 index 0000000..7466a7e --- /dev/null +++ b/runtime/platform/riscv64.h @@ -0,0 +1 @@ +#define MLton_Platform_Arch_host "riscv64"