Skip to content

Commit c8ed775

Browse files
add LoongArch aal
Signed-off-by: SchrodingerZhu <[email protected]>
1 parent 6e63874 commit c8ed775

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

src/aal/aal.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
# define PLATFORM_IS_SPARC
3333
#endif
3434

35+
#if defined (__loongarch__)
36+
# define PLATFORM_IS_LOONGARCH
37+
#endif
38+
3539
namespace snmalloc
3640
{
3741
/**
@@ -169,6 +173,8 @@ namespace snmalloc
169173
# include "aal_powerpc.h"
170174
#elif defined(PLATFORM_IS_SPARC)
171175
# include "aal_sparc.h"
176+
#elif defined(PLATFORM_IS_LOONGARCH)
177+
# include "aal_loongarch.h"
172178
#endif
173179

174180
namespace snmalloc

src/aal/aal_consts.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,6 @@ namespace snmalloc
3333
X86,
3434
X86_SGX,
3535
Sparc,
36+
LoongArch
3637
};
3738
} // namespace snmalloc

src/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+
#include <cstddef>
3+
#if _LOONGARCH_SZPTR == 64
4+
# define SNMALLOC_VA_BITS_64
5+
#elif _LOONGARCH_SZPTR == 32
6+
# define SNMALLOC_VA_BITS_32
7+
#else
8+
# error "Unsupported pointer size"
9+
#endif
10+
namespace snmalloc
11+
{
12+
/**
13+
* ARM-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 = 0x10000;
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 in,
44+
* hint has 32 optional values (0 to 31), 0 represents load to level 1 Cache
45+
* If the Cache attribute of the access address of the PRELD instruction is not
46+
* cached, then the instruction cannot generate a memory access action
47+
* and is treated as a NOP instruction. The PRELD instruction will not trigger
48+
* 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)