Skip to content
Permalink
Browse files

Moved to C++14; moved out Heap-Layers.

  • Loading branch information...
emeryberger committed Jul 26, 2017
1 parent 42602c1 commit d03608de72940ad67de181790d695836510b6067
@@ -1,3 +0,0 @@
[submodule "src/Heap-Layers"]
path = src/Heap-Layers
url = https://github.com/emeryberger/Heap-Layers.git
Submodule Heap-Layers deleted from c7ca8f
@@ -47,7 +47,10 @@ UNIX_SRC = Heap-Layers/wrappers/gnuwrapper.cpp source/libdieharder.cpp
# UNIX_SRC = Heap-Layers/wrappers/gnuwrapper-hooks.cpp source/libdieharder.cpp
MACOS_SRC = Heap-Layers/wrappers/macwrapper.cpp source/libdieharder.cpp

DEPS = $(UNIX_SRC) $(MACOS_SRC)
DEPS = Heap-Layers $(MACOS_SRC) $(UNIX_SRC)

Heap-Layers:
git clone https://github.com/emeryberger/Heap-Layers

REPLICATED_SRC = replicated/replicated.cpp

@@ -58,23 +61,23 @@ WIN_FLAGS = /Iinclude /Zi /Ox /Oy /DNDEBUG /MD /DDIEHARD_REPLICATED=0

WINDOWS_COMMAND_STANDALONE := cl /LD $(WIN_INCLUDES) $(WIN_FLAGS) winhard.cpp /link /base:0x63000000 kernel32.lib user32.lib msvcrt.lib advapi32.lib /subsystem:console /dll /incremental:no /entry:HardDllMain

MACOS_COMMAND_STANDALONE := $(MACOS_COMPILER) --std=c++11 -arch i386 -arch x86_64 -g -O3 -W -Wall -DDIEHARD_MULTITHREADED=1 -DNDEBUG $(INCLUDE) -D_REENTRANT=1 -compatibility_version 1 -current_version 1 -dynamiclib $(MACOS_SRC) -o $(TARGET).dylib
MACOS_COMMAND_STANDALONE := $(MACOS_COMPILER) --std=c++14 -arch i386 -arch x86_64 -g -O3 -W -Wall -DDIEHARD_MULTITHREADED=1 -DNDEBUG $(INCLUDE) -D_REENTRANT=1 -compatibility_version 1 -current_version 1 -dynamiclib $(MACOS_SRC) -o $(TARGET).dylib

MACOS_COMMAND_DEBUG_STANDALONE := $(MACOS_COMPILER) --std=c++11 -arch i386 -arch x86_64 -g -W -Wall -DDIEHARD_MULTITHREADED=1 $(INCLUDE) -D_REENTRANT=1 -compatibility_version 1 -current_version 1 -dynamiclib $(MACOS_SRC) -o $(TARGET).dylib
MACOS_COMMAND_DEBUG_STANDALONE := $(MACOS_COMPILER) --std=c++14 -arch i386 -arch x86_64 -g -W -Wall -DDIEHARD_MULTITHREADED=1 $(INCLUDE) -D_REENTRANT=1 -compatibility_version 1 -current_version 1 -dynamiclib $(MACOS_SRC) -o $(TARGET).dylib

MACOS_COMMAND_REPLICATED := $(MACOS_COMPILER) -pipe -O3 -finline-limit=65000 -fkeep-inline-functions -finline-functions -ffast-math -fomit-frame-pointer $(REPLICATED_SRC) -DDIEHARD_MULTITHREADED=1 -DNDEBUG $(INCLUDE) -D_REENTRANT=1 -compatibility_version 1 -current_version 1 -dynamiclib $(MACOS_SRC) -o libdieharder_r.dylib

LINUX_COMMAND_STANDALONE := $(CXX) -std=c++11 -m32 -finline-functions -malign-double -pipe -march=pentium4 -O3 -DNDEBUG $(INCLUDE) -D_REENTRANT=1 -DDIEHARD_MULTITHREADED=1 -shared $(UNIX_SRC) -Bsymbolic -o $(TARGET).so -ldl -lpthread
LINUX_COMMAND_STANDALONE := $(CXX) -std=c++14 -m32 -finline-functions -malign-double -pipe -march=pentium4 -O3 -DNDEBUG $(INCLUDE) -D_REENTRANT=1 -DDIEHARD_MULTITHREADED=1 -shared $(UNIX_SRC) -Bsymbolic -o $(TARGET).so -ldl -lpthread

LINUX_COMMAND_REPLICATED := $(CXX) -std=c++11 -malign-double -pipe -march=pentium4 -O3 -fno-rtti -finline-functions -ffast-math -fomit-frame-pointer -DNDEBUG $(INCLUDE) -D_REENTRANT=1 $(REPLICATED_SRC) -DDIEHARD_MULTITHREADED=1 -shared $(UNIX_SRC) -Bsymbolic -o libdieharder_r.so -ldl -lpthread
LINUX_COMMAND_REPLICATED := $(CXX) -std=c++14 -malign-double -pipe -march=pentium4 -O3 -fno-rtti -finline-functions -ffast-math -fomit-frame-pointer -DNDEBUG $(INCLUDE) -D_REENTRANT=1 $(REPLICATED_SRC) -DDIEHARD_MULTITHREADED=1 -shared $(UNIX_SRC) -Bsymbolic -o libdieharder_r.so -ldl -lpthread

FLAGS = -pedantic -Wall -Wpointer-arith -Woverloaded-virtual -Werror=return-type -Wtype-limits -Wempty-body -Wno-ctor-dtor-privacy -Wno-overlength-strings -Wno-invalid-offsetof -Wno-variadic-macros -Wcast-align -Wno-long-long -pthread -pipe -DNDEBUG

LINUX_64_COMMAND_STANDALONE_DEBUG := $(CXX) -std=c++11 -W -Wall -O0 -pipe -fPIC -m64 -ffast-math -g $(INCLUDE) -D_REENTRANT=1 -DDIEHARD_MULTITHREADED=1 -shared $(UNIX_SRC) -Bsymbolic -o $(TARGET).so -ldl -lpthread
LINUX_64_COMMAND_STANDALONE_DEBUG := $(CXX) -std=c++14 -W -Wall -O0 -pipe -fPIC -m64 -ffast-math -g $(INCLUDE) -D_REENTRANT=1 -DDIEHARD_MULTITHREADED=1 -shared $(UNIX_SRC) -Bsymbolic -o $(TARGET).so -ldl -lpthread

LINUX_64_COMMAND_STANDALONE := $(CXX) $(FLAGS) -std=c++11 -W -Wall -O3 -DNDEBUG -pipe -fPIC -m64 -ffast-math -g $(INCLUDE) -D_REENTRANT=1 -DDIEHARD_MULTITHREADED=1 -shared $(UNIX_SRC) -Bsymbolic -o $(TARGET).so -ldl -lpthread
LINUX_64_COMMAND_STANDALONE := $(CXX) $(FLAGS) -std=c++14 -W -Wall -O3 -DNDEBUG -pipe -fPIC -m64 -ffast-math -g $(INCLUDE) -D_REENTRANT=1 -DDIEHARD_MULTITHREADED=1 -shared $(UNIX_SRC) -Bsymbolic -o $(TARGET).so -ldl -lpthread

LINUX_64_COMMAND_REPLICATED := $(CXX) -std=c++11 -O1 -DNDEBUG -pipe -fPIC -m64 -g $(INCLUDE) -D_REENTRANT=1 $(REPLICATED_SRC) -DDIEHARD_MULTITHREADED=1 -shared $(UNIX_SRC) -Bsymbolic -o libdieharder_r.so -ldl -lpthread
LINUX_64_COMMAND_REPLICATED := $(CXX) -std=c++14 -O1 -DNDEBUG -pipe -fPIC -m64 -g $(INCLUDE) -D_REENTRANT=1 $(REPLICATED_SRC) -DDIEHARD_MULTITHREADED=1 -shared $(UNIX_SRC) -Bsymbolic -o libdieharder_r.so -ldl -lpthread

SOLARIS_SPARC32_COMMAND_STANDALONE := CC -xtarget=ultra2 -xildoff -xO5 -xthreadvar=dynamic -L/usr/lib/lwp -R/usr/lib/lwp -DNDEBUG $(INCLUDE) -DDIEHARD_MULTITHREADED=1 -G -PIC $(UNIX_SRC) sparc-interchange.il -o $(TARGET).so -lthread -ldl -lCrun

@@ -85,46 +88,45 @@ SOLARIS_SPARC64_COMMAND_STANDALONE := CC -xcode=pic13 -xtarget=ultra2 -m64 -dali
SOLARIS_SPARC64_COMMAND_REPLICATED := CC -xcode=pic13 -xtarget=ultra2 -m64 -dalign -xbuiltin=%all -xO5 -xildoff -xthreadvar=dynamic -L/usr/lib/lwp -R/usr/lib/lwp -DNDEBUG $(INCLUDE) $(REPLICATED_SRC) -DDIEHARD_MULTITHREADED=1 -G -PIC $(UNIX_SRC) sparc-interchange.il -o libdieharder_r.so -lthread -ldl -lCrun


linux-gcc-x86:
linux-gcc-x86: $(DEPS)
$(LINUX_COMMAND_STANDALONE)

linux-gcc-x86-replicated:
linux-gcc-x86-replicated: $(DEPS)
$(LINUX_COMMAND_REPLICATED)

linux-gcc-x86-64:
linux-gcc-x86-64: $(DEPS)
$(LINUX_64_COMMAND_STANDALONE)

linux-gcc-x86-64-debug:
linux-gcc-x86-64-debug: $(DEPS)
$(LINUX_64_COMMAND_STANDALONE_DEBUG)

linux-gcc-x86-64-replicated:
linux-gcc-x86-64-replicated: $(DEPS)
$(LINUX_64_COMMAND_REPLICATED)

solaris-sparc:
solaris-sparc: $(DEPS)
$(SOLARIS_SPARC32_COMMAND_STANDALONE)

solaris-sparc-replicated:
solaris-sparc-replicated: $(DEPS)
$(SOLARIS_SPARC32_COMMAND_REPLICATED)

solaris-sparc-64:
solaris-sparc-64: $(DEPS)
$(SOLARIS_SPARC64_COMMAND_STANDALONE)

solaris-sparc-64-replicated:
solaris-sparc-64-replicated: $(DEPS)
$(SOLARIS_SPARC64_COMMAND_REPLICATED)

windows:
windows: $(DEPS)
$(WINDOWS_COMMAND_STANDALONE)

macos:
macos: $(DEPS)
$(MACOS_COMMAND_STANDALONE)

macos-debug:
macos-debug: $(DEPS)
$(MACOS_COMMAND_DEBUG_STANDALONE)

macos-replicated:
macos-replicated: $(DEPS)
$(MACOS_COMMAND_REPLICATED)


clean:
rm -f $(TARGET).so libdieharder_r.so $(TARGET).dylib

@@ -21,7 +21,6 @@
#include <new>

#include "heaplayers.h"
// #include "sassert.h"

#include "diefast.h"
#include "staticforloop.h"
@@ -55,29 +54,25 @@ class DieHardHeap {
enum { Alignment = 8 };
#endif

DieHardHeap (void)
DieHardHeap()
: _localRandomValue (RealRandomValue::value())
{
// Check that there are no size dependencies to worry about.
typedef RandomHeap<Numerator, Denominator, Alignment, MaxSize, RandomMiniHeap, DieFastOn, DieHarderOn> RH1;
typedef RandomHeap<Numerator, Denominator, 256 * Alignment, MaxSize, RandomMiniHeap, DieFastOn, DieHarderOn> RH2;

sassert<(sizeof(RH1) == (sizeof(RH2)))>
verifyNoSizeDependencies;
static_assert(sizeof(RH1) == sizeof(RH2),
"There can't be any dependencies on object sizes.");

// Check to make sure the size specified by MaxSize is correct.
#if USE_HALF_LOG
sassert<(StaticHalfPow2<MAX_INDEX-1>::VALUE) == MaxSize>
verifySizeFormulation;
static_assert(StaticHalfPow2<MAX_INDEX-1>::VALUE == MaxSize,
"Size specified by MaxSize is incorrect.");
#else
sassert<((1 << (MAX_INDEX-1)) * Alignment) == MaxSize>
verifySizeFormulation;
static_assert((1 << (MAX_INDEX-1)) * Alignment == MaxSize,
"Size specified by MaxSize is incorrect.");
#endif

// avoiding warnings here
verifyNoSizeDependencies = verifyNoSizeDependencies;
verifySizeFormulation = verifySizeFormulation;

// Warning: some crazy template meta-programming in the name of
// efficiency below.

@@ -11,8 +11,7 @@

template <int B>
inline size_t modulo (size_t v) {
sassert<(B > 0)> modulus_must_be_positive;
modulus_must_be_positive = modulus_must_be_positive;
static_assert(B > 0, "Modulus must be positive.");

enum { Pow2 = IsPowerOfTwo<B>::VALUE };
if (Pow2) {
@@ -98,18 +98,12 @@ class RandomHeap : public RandomHeapBase<Numerator, Denominator> {
Check<RandomHeap *> sanity (this);

// Some basic (static) sanity checks.
sassert<(ObjectSize > 0)> ensureReasonableObjects;
sassert<(Numerator >= Denominator)> ensureMultiplierAtLeastOne;
sassert<(MIN_SIZE >= ObjectSize)> ensureMinSizeAtLeastObjectSize;
sassert<(sizeof(MiniHeapType<MIN_OBJECTS>) ==
sizeof(MiniHeapType<MIN_OBJECTS*2>))>
ensureNoDependenciesOnNumberOfObjects;

// useless assignments to prevent warnings
ensureReasonableObjects = ensureReasonableObjects;
ensureMultiplierAtLeastOne = ensureMultiplierAtLeastOne;
ensureMinSizeAtLeastObjectSize = ensureMinSizeAtLeastObjectSize;
ensureNoDependenciesOnNumberOfObjects = ensureNoDependenciesOnNumberOfObjects;
static_assert(ObjectSize > 0, "Object is too small.");
static_assert(Numerator >= Denominator, "Multiplier must be at least one.");
static_assert(MIN_SIZE >= ObjectSize, "Minimum size must be at least as big as one object.");
static_assert(sizeof(MiniHeapType<MIN_OBJECTS>) ==
sizeof(MiniHeapType<MIN_OBJECTS*2>),
"There can't be any dependencies on the number of objects.");

// Fill the buffer with miniheaps. NB: the first two have the
// same number of objects -- this simplifies the math for
@@ -46,11 +46,8 @@ class RandomMiniHeapDieHarderBase :

// Object size must be a multiple of page size (if bigger than a
// page).
sassert<((ObjectSize <= CPUInfo::PageSize)
|| CPUInfo::PageSize * (ObjectSize / CPUInfo::PageSize) == ObjectSize)>
objectSizeMultipleOfPageSize;
objectSizeMultipleOfPageSize = objectSizeMultipleOfPageSize;

static_assert((ObjectSize <= CPUInfo::PageSize
|| CPUInfo::PageSize * (ObjectSize / CPUInfo::PageSize) == ObjectSize), "Object size must be a multiple of page size if it is bigger than a page.");
}

typedef RandomMiniHeapCore<Numerator, Denominator, ObjectSize, NObjects, Allocator, DieFastOn, true> SuperHeap;
@@ -255,8 +252,7 @@ class RandomMiniHeapDieHarderChoose<Numerator, Denominator, ObjectSize, NObjects

RandomMiniHeapDieHarderChoose()
{
sassert<(ObjectSize <= CPUInfo::PageSize)> verifySmall;
verifySmall = verifySmall;
static_assert(ObjectSize <= CPUInfo::PageSize, "Object must be no larger than a page.");
}

inline size_t getSize (void * ptr) {
@@ -287,8 +283,7 @@ class RandomMiniHeapDieHarderChoose<Numerator, Denominator, ObjectSize, NObjects
typedef RandomMiniHeapDieHarderBase<Numerator, Denominator, ObjectSize, NObjects, Allocator, DieFastOn> SuperHeap;

RandomMiniHeapDieHarderChoose() {
sassert<(ObjectSize >= CPUInfo::PageSize)> verifyLarge;
verifyLarge = verifyLarge;
static_assert(ObjectSize >= CPUInfo::PageSize, "Object must be at least a page in size.");
}

inline size_t getSize (void * ptr) {
@@ -36,7 +36,7 @@ class RandomMmap {
}

void * map (size_t sz) {
Guard<PosixLockType> m (_lock);
std::lock_guard<PosixLockType> m (_lock);

// Round up to the nearest number of pages required.
unsigned long npages = (sz + CPUInfo::PageSize - 1) / CPUInfo::PageSize;
@@ -78,7 +78,7 @@ class RandomMmap {

void unmap (void * ptr, size_t sz)
{
Guard<PosixLockType> m (_lock);
std::lock_guard<PosixLockType> m (_lock);

// Round up to the nearest number of pages required.
unsigned int npages = (sz + CPUInfo::PageSize - 1) / CPUInfo::PageSize;
@@ -78,15 +78,15 @@ class DynamicHashTable {
}

bool get (unsigned long k, VALUE_TYPE& value) {
Guard<HL::PosixLockType> l (_lock);
std::lock_guard<HL::PosixLockType> l (_lock);

return find (k, value);
}

/// @brief Insert the given object into the map.
void insert (const VALUE_TYPE& s)
{
Guard<HL::PosixLockType> l (_lock);
std::lock_guard<HL::PosixLockType> l (_lock);

#if 0
{

0 comments on commit d03608d

Please sign in to comment.
You can’t perform that action at this time.