Skip to content

Commit 009a331

Browse files
update loongarch
Signed-off-by: Schrodinger ZHU Yifan <[email protected]>
1 parent 09bc0c6 commit 009a331

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed

src/snmalloc/aal/aal.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141
# define PLATFORM_IS_RISCV
4242
#endif
4343

44+
#if defined (__loongarch__)
45+
# define PLATFORM_IS_LOONGARCH
46+
#endif
47+
4448
namespace snmalloc
4549
{
4650
/**
@@ -230,6 +234,8 @@ namespace snmalloc
230234
# include "aal_sparc.h"
231235
#elif defined(PLATFORM_IS_RISCV)
232236
# include "aal_riscv.h"
237+
#elif defined(PLATFORM_IS_LOONGARCH)
238+
# include "aal_loongarch.h"
233239
#endif
234240

235241
#if defined(__CHERI_PURE_CAPABILITY__)

src/snmalloc/aal/aal_consts.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ namespace snmalloc
3333
X86,
3434
X86_SGX,
3535
Sparc,
36-
RISCV
36+
RISCV,
37+
LoongArch
3738
};
3839
} // namespace snmalloc

src/snmalloc/aal/aal_loongarch.h

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#pragma once
2+
3+
#if __SIZEOF_POINTER__ == 8
4+
# define SNMALLOC_VA_BITS_64
5+
#else
6+
# define SNMALLOC_VA_BITS_32
7+
#endif
8+
9+
#include <cstddef>
10+
namespace snmalloc
11+
{
12+
/**
13+
* Loongarch-specific architecture abstraction layer.
14+
*/
15+
class AAL_LoongArch
16+
{
17+
public:
18+
/**
19+
* Bitmap of AalFeature flags
20+
*/
21+
static constexpr uint64_t aal_features =
22+
IntegerPointers | NoCpuCycleCounters;
23+
24+
static constexpr enum AalName aal_name = LoongArch;
25+
26+
static constexpr size_t smallest_page_size = 0x1000;
27+
28+
/**
29+
* On pipelined processors, notify the core that we are in a spin loop and
30+
* that speculative execution past this point may not be a performance gain.
31+
*/
32+
static inline void pause()
33+
{
34+
__asm__ __volatile__("dbar 0" : : : "memory");
35+
}
36+
37+
/**
38+
* PRELD reads a cache-line of data from memory in advance into the Cache.
39+
* The access address is the 12bit immediate number of the value in the
40+
* general register rj plus the symbol extension.
41+
*
42+
* The processor learns from the hint in the PRELD instruction what type
43+
* will be acquired and which level of Cache the data to be taken back fill
44+
* in, hint has 32 optional values (0 to 31), 0 represents load to level 1
45+
* Cache If the Cache attribute of the access address of the PRELD
46+
* instruction is not cached, then the instruction cannot generate a memory
47+
* access action and is treated as a NOP instruction. The PRELD instruction
48+
* will not trigger any exceptions related to MMU or address.
49+
*/
50+
static inline void prefetch(void* ptr)
51+
{
52+
__asm__ volatile("preld 0, %0, 0" : "=r"(ptr));
53+
}
54+
};
55+
56+
using AAL_Arch = AAL_LoongArch;
57+
} // namespace snmalloc

0 commit comments

Comments
 (0)