Sparc support proposal. (#264)

* Sparc support proposal.

* Tweaks from feedback.
Shift to integer/pointers cast like other archs.
Assembly reworks.
Note apparently reading the register once is sufficient to provoke
a pause in the cpu adding a clobber tough.
This commit is contained in:
David CARLIER
2021-01-05 16:28:22 +00:00
committed by GitHub
parent 975a2bd6db
commit 2dd63606af
5 changed files with 72 additions and 3 deletions

View File

@@ -23,6 +23,10 @@
# define PLATFORM_IS_POWERPC
#endif
#if defined(__sparc__)
# define PLATFORM_IS_SPARC
#endif
namespace snmalloc
{
/**
@@ -54,6 +58,7 @@ namespace snmalloc
PowerPC,
X86,
X86_SGX,
Sparc,
};
/**
@@ -147,6 +152,8 @@ namespace snmalloc
# include "aal_arm.h"
#elif defined(PLATFORM_IS_POWERPC)
# include "aal_powerpc.h"
#elif defined(PLATFORM_IS_SPARC)
# include "aal_sparc.h"
#endif
namespace snmalloc

62
src/aal/aal_sparc.h Normal file
View File

@@ -0,0 +1,62 @@
#pragma once
#if defined(__arch64__) // More reliable than __sparc64__
# define SNMALLOC_VA_BITS_64
#else
# define SNMALLOC_VA_BITS_32
#endif
namespace snmalloc
{
/**
* Sparc architecture abstraction layer.
*/
class AAL_Sparc
{
public:
/**
* Bitmap of AalFeature flags
*/
static constexpr uint64_t aal_features = IntegerPointers;
static constexpr enum AalName aal_name = Sparc;
#ifdef SNMALLOC_VA_BITS_64
/**
* Even Ultra-Sparc I supports 8192 and onwards
*/
static constexpr size_t smallest_page_size = 0x2000;
#else
static constexpr size_t smallest_page_size = 0x1000;
#endif
/**
* On Sparc ideally pause instructions ought to be
* optimised per Sparc processor but here a version
* as least common denominator to avoid numerous ifdef,
* reading Conditions Code Register here
*/
static inline void pause()
{
__asm__ volatile("rd %%ccr, %%g0" ::: "memory");
}
static inline void prefetch(void* ptr)
{
#ifdef SNMALLOC_VA_BITS_64
__asm__ volatile("prefetch [%0], 0" ::"r"(ptr));
#else
UNUSED(ptr);
#endif
}
static inline uint64_t tick()
{
uint64_t tick;
__asm__ volatile("rd %%asr4, %0" : "=r"(tick));
return tick;
}
};
using AAL_Arch = AAL_Sparc;
} // namespace snmalloc

View File

@@ -26,7 +26,7 @@ namespace snmalloc
static constexpr uint64_t pal_features = PALPOSIX::pal_features;
static constexpr size_t page_size =
Aal::aal_name == PowerPC ? 0x10000 : 0x1000;
Aal::aal_name == PowerPC ? 0x10000 : PALPOSIX::page_size;
/**
* OS specific function for zeroing memory.

View File

@@ -39,7 +39,7 @@ namespace snmalloc
*/
static constexpr uint64_t pal_features = 0;
static constexpr size_t page_size = 0x1000;
static constexpr size_t page_size = Aal::smallest_page_size;
[[noreturn]] static void error(const char* const str)
{

View File

@@ -98,7 +98,7 @@ namespace snmalloc
*/
static constexpr uint64_t pal_features = LazyCommit;
static constexpr size_t page_size = 0x1000;
static constexpr size_t page_size = Aal::smallest_page_size;
static void print_stack_trace()
{