Skip to content

Commit

Permalink
Merge pull request #61 from howjmay/malloc-free
Browse files Browse the repository at this point in the history
feat: Add _mm_free and _mm_malloc
  • Loading branch information
howjmay authored Jan 26, 2024
2 parents 52ea063 + 62609e9 commit d6dc3e5
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 21 deletions.
17 changes: 15 additions & 2 deletions sse2rvv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1468,7 +1468,7 @@ FORCE_INLINE int _mm_extract_ps(__m128 a, const int imm8) {

// FORCE_INLINE __m128 _mm_floor_ss (__m128 a, __m128 b) {}

// FORCE_INLINE void _mm_free (void * mem_addr) {}
FORCE_INLINE void _mm_free(void *mem_addr) { free(mem_addr); }

// FORCE_INLINE unsigned int _MM_GET_EXCEPTION_MASK () {}

Expand Down Expand Up @@ -1826,7 +1826,20 @@ FORCE_INLINE __m128i _mm_loadu_si64(void const *mem_addr) {

// FORCE_INLINE __m64 _mm_maddubs_pi16 (__m64 a, __m64 b) {}

// FORCE_INLINE void* _mm_malloc (size_t size, size_t align) {}
FORCE_INLINE void *_mm_malloc(size_t size, size_t align) {
void *ptr;
if (align == 1) {
return malloc(size);
}
if (align == 2 || (sizeof(void *) == 8 && align == 4)) {
align = sizeof(void *);
}
ptr = aligned_alloc(align, size);
if (ptr) {
return ptr;
}
return NULL;
}

// FORCE_INLINE void _mm_maskmove_si64 (__m64 a, __m64 mask, char* mem_addr) {}

Expand Down
48 changes: 29 additions & 19 deletions tests/impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2051,12 +2051,22 @@ result_t test_mm_malloc(const SSE2RVV_TEST_IMPL &impl, uint32_t iter);
// #ifdef ENABLE_TEST_ALL

result_t test_mm_free(const SSE2RVV_TEST_IMPL &impl, uint32_t iter) {
// #ifdef ENABLE_TEST_ALL
// /* We verify _mm_malloc first, and there is no need to check _mm_free .
// */ return test_mm_malloc(impl, iter);
// #else
#ifdef ENABLE_TEST_ALL
/* We verify _mm_malloc first, and there is no need to check _mm_free(). */
const size_t *a = (const size_t *)impl.test_cases_int_pointer1;
const size_t *b = (const size_t *)impl.test_cases_int_pointer2;
size_t size = *a % (1024 * 16) + 1;
size_t align = 2 << (*b % 5);

void *p = _mm_malloc(size, align);
if (!p)
return TEST_FAIL;
result_t res = (((uintptr_t)p % align) == 0) ? TEST_SUCCESS : TEST_FAIL;
_mm_free(p);
return res;
#else
return TEST_UNIMPL;
// #endif // ENABLE_TEST_ALL
#endif // ENABLE_TEST_ALL
}

result_t test_mm_get_flush_zero_mode(const SSE2RVV_TEST_IMPL &impl,
Expand Down Expand Up @@ -2282,21 +2292,21 @@ result_t test_mm_loadu_si64(const SSE2RVV_TEST_IMPL &impl, uint32_t iter) {
}

result_t test_mm_malloc(const SSE2RVV_TEST_IMPL &impl, uint32_t iter) {
// #ifdef ENABLE_TEST_ALL
// const size_t *a = (const size_t *)impl.test_cases_int_pointer1;
// const size_t *b = (const size_t *)impl.test_cases_int_pointer2;
// size_t size = *a % (1024 * 16) + 1;
// size_t align = 2 << (*b % 5);
//
// void *p = _mm_malloc(size, align);
// if (!p)
// return TEST_FAIL;
// result_t res = (((uintptr_t)p % align) == 0) ? TEST_SUCCESS : TEST_FAIL;
// _mm_free(p);
// return res;
// #else
#ifdef ENABLE_TEST_ALL
const size_t *a = (const size_t *)impl.test_cases_int_pointer1;
const size_t *b = (const size_t *)impl.test_cases_int_pointer2;
size_t size = *a % (1024 * 16) + 1;
size_t align = 2 << (*b % 5);

void *p = _mm_malloc(size, align);
if (!p)
return TEST_FAIL;
result_t res = (((uintptr_t)p % align) == 0) ? TEST_SUCCESS : TEST_FAIL;
_mm_free(p);
return res;
#else
return TEST_UNIMPL;
// #endif // ENABLE_TEST_ALL
#endif // ENABLE_TEST_ALL
}

result_t test_mm_maskmove_si64(const SSE2RVV_TEST_IMPL &impl, uint32_t iter) {
Expand Down

0 comments on commit d6dc3e5

Please sign in to comment.