Skip to content

Commit 5fb27ac

Browse files
authored
v: add initial support for loongarch64 (#24343)
1 parent f4316bb commit 5fb27ac

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

‎vlib/v/gen/c/cheaders.v‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,17 @@ static char __CLOSURE_GET_DATA_BYTES[] = {
171171
0x66, 0x00, 0xc3, 0x7d, // mfvsrd %r3, %f14
172172
0x20, 0x00, 0x80, 0x4e, // blr
173173
};
174+
#elif defined (__V_loongarch64)
175+
static char __closure_thunk[] = {
176+
0x92, 0xFF, 0xFF, 0x1D, // pcaddu12i t6, -4
177+
0x48, 0x02, 0x80, 0x2B, // fld.d f8, t6, 0
178+
0x51, 0x22, 0xC0, 0x28, // ld.d t5, t6, 8
179+
0x20, 0x02, 0x00, 0x4C, // jr t5
180+
};
181+
static char __CLOSURE_GET_DATA_BYTES[] = {
182+
0x04, 0xB9, 0x14, 0x01, // movfr2gr.d a0, f8
183+
0x20, 0x00, 0x00, 0x4C, // ret
184+
};
174185
#endif
175186
176187
static void*(*__CLOSURE_GET_DATA)(void) = 0;
@@ -357,6 +368,12 @@ const c_common_macros = '
357368
#define __V_architecture 8
358369
#endif
359370
371+
#if defined(__loongarch64)
372+
#define __V_loongarch64 1
373+
#undef __V_architecture
374+
#define __V_architecture 9
375+
#endif
376+
360377
// Using just __GNUC__ for detecting gcc, is not reliable because other compilers define it too:
361378
#ifdef __GNUC__
362379
#define __V_GCC__
@@ -714,7 +731,7 @@ static void* g_live_info = NULL;
714731

715732
const c_builtin_types = '
716733
//================================== builtin types ================================*/
717-
#if defined(__x86_64__) || defined(_M_AMD64) || defined(__aarch64__) || defined(__arm64__) || defined(_M_ARM64) || (defined(__riscv_xlen) && __riscv_xlen == 64) || defined(__s390x__) || (defined(__powerpc64__) && defined(__LITTLE_ENDIAN__))
734+
#if defined(__x86_64__) || defined(_M_AMD64) || defined(__aarch64__) || defined(__arm64__) || defined(_M_ARM64) || (defined(__riscv_xlen) && __riscv_xlen == 64) || defined(__s390x__) || (defined(__powerpc64__) && defined(__LITTLE_ENDIAN__)) || defined(__loongarch64)
718735
typedef int64_t vint_t;
719736
#else
720737
typedef int32_t vint_t;

‎vlib/v/gen/c/comptime.v‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,6 +1302,9 @@ fn (mut g Gen) comptime_if_to_ifdef(name string, is_comptime_option bool) !strin
13021302
'ppc64le' {
13031303
return '__V_ppc64le'
13041304
}
1305+
'loongarch64' {
1306+
return '__V_loongarch64'
1307+
}
13051308
// bitness:
13061309
'x64' {
13071310
return 'TARGET_IS_64BIT'

0 commit comments

Comments
 (0)