2019-04-20 09:08:01 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2019 tevador
|
|
|
|
|
|
|
|
This file is part of RandomX.
|
|
|
|
|
|
|
|
RandomX is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
RandomX is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with RandomX. If not, see<http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2019-04-21 21:23:13 +00:00
|
|
|
#include <new>
|
2019-04-20 09:08:01 +00:00
|
|
|
#include "allocator.hpp"
|
2019-04-20 14:53:06 +00:00
|
|
|
#include "intrin_portable.h"
|
|
|
|
#include "virtual_memory.hpp"
|
2019-04-20 09:08:01 +00:00
|
|
|
#include "common.hpp"
|
|
|
|
|
|
|
|
namespace randomx {
|
|
|
|
|
|
|
|
template<size_t alignment>
|
|
|
|
void* AlignedAllocator<alignment>::allocMemory(size_t count) {
|
2019-04-21 21:23:13 +00:00
|
|
|
void *mem = _mm_malloc(count, alignment);
|
|
|
|
if (mem == nullptr)
|
|
|
|
throw std::bad_alloc();
|
|
|
|
return mem;
|
2019-04-20 09:08:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<size_t alignment>
|
|
|
|
void AlignedAllocator<alignment>::freeMemory(void* ptr, size_t count) {
|
|
|
|
_mm_free(ptr);
|
|
|
|
}
|
|
|
|
|
2019-04-21 12:07:32 +00:00
|
|
|
template class AlignedAllocator<CacheLineSize>;
|
|
|
|
template class AlignedAllocator<sizeof(__m128i)>;;
|
2019-04-20 09:08:01 +00:00
|
|
|
|
|
|
|
void* LargePageAllocator::allocMemory(size_t count) {
|
|
|
|
return allocLargePagesMemory(count);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LargePageAllocator::freeMemory(void* ptr, size_t count) {
|
|
|
|
freePagedMemory(ptr, count);
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|