|
| 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