summaryrefslogtreecommitdiff
path: root/backend/src/sys
diff options
context:
space:
mode:
authorBenjamin Segovia <bsegovia@bsegovia-i70.sc.intel.com>2012-09-19 20:40:10 +0000
committerBenjamin Segovia <bsegovia@bsegovia-i70.sc.intel.com>2012-09-19 20:40:10 +0000
commitd8ffb5dcd384a9f68bb6d0900b6d63d6444342e3 (patch)
treed4ebe30ab3fdb3c46f265d6bf4c3199e9c47e39f /backend/src/sys
parent5c34e90c2b6e92c4406a8997b570ee2c7240c8ff (diff)
Removed unused files
Added extra functionalities to debug special allocator with valgrind
Diffstat (limited to 'backend/src/sys')
-rw-r--r--backend/src/sys/alloc.cpp62
-rw-r--r--backend/src/sys/alloc.hpp25
-rw-r--r--backend/src/sys/barrier.hpp67
-rw-r--r--backend/src/sys/condition.cpp144
-rw-r--r--backend/src/sys/condition.hpp45
-rw-r--r--backend/src/sys/constants.hpp150
-rw-r--r--backend/src/sys/platform.hpp5
-rw-r--r--backend/src/sys/string.cpp113
-rw-r--r--backend/src/sys/string.hpp58
-rw-r--r--backend/src/sys/sysinfo.cpp153
-rw-r--r--backend/src/sys/sysinfo.hpp42
11 files changed, 34 insertions, 830 deletions
diff --git a/backend/src/sys/alloc.cpp b/backend/src/sys/alloc.cpp
index 67368c74..cc2186f1 100644
--- a/backend/src/sys/alloc.cpp
+++ b/backend/src/sys/alloc.cpp
@@ -29,11 +29,7 @@
#include "sys/mutex.hpp"
#if GBE_DEBUG_MEMORY
-#ifdef __MSVC__
-#include <unordered_map>
-#else
#include <tr1/unordered_map>
-#endif /* __MSVC__ */
#include <cstring>
#endif /* GBE_DEBUG_MEMORY */
@@ -47,6 +43,7 @@
////////////////////////////////////////////////////////////////////////////////
/// Memory debugger
////////////////////////////////////////////////////////////////////////////////
+
#if GBE_DEBUG_MEMORY
namespace gbe
{
@@ -271,29 +268,6 @@ namespace gbe
#else /* GBE_DEBUG_MEMORY */
////////////////////////////////////////////////////////////////////////////////
-/// Windows Platform
-////////////////////////////////////////////////////////////////////////////////
-
-#if defined(__WIN32__)
-
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
-
-namespace gbe
-{
- void* alignedMalloc(size_t size, size_t align) {
- void* ptr = _mm_malloc(size,align);
- FATAL_IF (!ptr && size, "memory allocation failed");
- MemDebuggerInitializeMem(ptr, size);
- return ptr;
- }
-
- void alignedFree(void *ptr) { if (ptr) _mm_free(ptr); }
-} /* namespace gbe */
-
-#endif /* __WIN32__ */
-
-////////////////////////////////////////////////////////////////////////////////
/// Linux Platform
////////////////////////////////////////////////////////////////////////////////
@@ -317,34 +291,10 @@ namespace gbe
void alignedFree(void *ptr) { if (ptr) std::free(ptr); }
} /* namespace gbe */
+#else
+#error "Unsupported platform"
#endif /* __LINUX__ */
-
-////////////////////////////////////////////////////////////////////////////////
-/// MacOS Platform
-////////////////////////////////////////////////////////////////////////////////
-
-#if defined(__MACOSX__)
-
-#include <cstdlib>
-
-namespace gbe
-{
- void* alignedMalloc(size_t size, size_t align) {
- void* mem = malloc(size+align+sizeof(void*));
- FATAL_IF (!mem && size, "memory allocation failed");
- char* aligned = ((char*)mem) + sizeof(void*);
- aligned += align - ((uintptr_t)aligned & (align - 1));
- ((void**)aligned)[-1] = mem;
- MemDebuggerInitializeMem(aligned, size);
- return aligned;
- }
-
- void alignedFree(void* ptr) { if (ptr) free(((void**)ptr)[-1]); }
-} /* namespace gbe */
-
-#endif /* __MACOSX__ */
-
-#endif /* GBE_DEBUG_MEMORY */
+#endif
////////////////////////////////////////////////////////////////////////////////
// Linear allocator
@@ -372,6 +322,9 @@ namespace gbe
void *LinearAllocator::allocate(size_t size)
{
+#if GBE_DEBUG_SPECIAL_ALLOCATOR
+ if (ptr) GBE_ALIGNED_MALLOC(size, sizeof(void*));
+#else
// Try to use the current segment. This is the most likely condition here
this->curr->offset = ALIGN(this->curr->offset, sizeof(void*));
if (this->curr->offset + size <= this->curr->size) {
@@ -399,6 +352,7 @@ namespace gbe
char *ptr = (char*) curr->data;
this->curr->offset += size;
return ptr;
+#endif
}
} /* namespace gbe */
diff --git a/backend/src/sys/alloc.hpp b/backend/src/sys/alloc.hpp
index 4629708a..e8e35eb6 100644
--- a/backend/src/sys/alloc.hpp
+++ b/backend/src/sys/alloc.hpp
@@ -26,7 +26,7 @@
#include "sys/platform.hpp"
#include "sys/assert.hpp"
-#include "math/math.hpp"
+#include <algorithm>
namespace gbe
{
@@ -153,6 +153,11 @@ namespace gbe
INLINE bool operator!=(Allocator const& a) { return !operator==(a); }
};
+// Deactivate fast allocators
+#ifndef GBE_DEBUG_SPECIAL_ALLOCATOR
+#define GBE_DEBUG_SPECIAL_ALLOCATOR 0
+#endif
+
/*! A growing pool never gives memory to the system but chain free elements
* together such as deallocation can be quickly done
*/
@@ -165,6 +170,9 @@ namespace gbe
free(NULL), freeList(NULL) {}
~GrowingPool(void) { GBE_ASSERT(curr); GBE_DELETE(curr); }
void *allocate(void) {
+#if GBE_DEBUG_SPECIAL_ALLOCATOR
+ return GBE_ALIGNED_MALLOC(sizeof(T), AlignOf<T>::value);
+#else
// Pick up an element from the free list
if (this->freeList != NULL) {
void *data = (void*) freeList;
@@ -190,13 +198,19 @@ namespace gbe
}
void *data = (T*) curr->data + curr->allocated++;
return data;
+#endif /* GBE_DEBUG_SPECIAL_ALLOCATOR */
}
void deallocate(void *t) {
if (t == NULL) return;
+#if GBE_DEBUG_SPECIAL_ALLOCATOR
+ GBE_ALIGNED_FREE(t);
+#else
*(void**) t = this->freeList;
this->freeList = t;
+#endif
}
void rewind(void) {
+#if GBE_DEBUG_SPECIAL_ALLOCATOR == 0
// All free elements return to their blocks
this->freeList = NULL;
// Reverse the chain list and mark all blocks as empty
@@ -211,6 +225,7 @@ namespace gbe
GBE_ASSERT(this->free);
this->curr = this->free;
this->free = this->curr->next;
+#endif /* GBE_DEBUG_SPECIAL_ALLOCATOR */
}
private:
/*! Chunk of elements to allocate */
@@ -218,7 +233,7 @@ namespace gbe
{
friend class GrowingPool;
GrowingPoolElem(size_t elemNum) {
- const size_t sz = max(sizeof(T), sizeof(void*));
+ const size_t sz = std::max(sizeof(T), sizeof(void*));
this->data = (T*) GBE_ALIGNED_MALLOC(elemNum * sz, AlignOf<T>::value);
this->next = NULL;
this->maxElemNum = elemNum;
@@ -263,7 +278,11 @@ namespace gbe
/*! Allocate size bytes */
void *allocate(size_t size);
/*! Nothing here */
- INLINE void deallocate(void *ptr) {}
+ INLINE void deallocate(void *ptr) {
+#if GBE_DEBUG_SPECIAL_ALLOCATOR
+ if (ptr) GBE_ALIGNED_FREE(ptr);
+#endif /* GBE_DEBUG_SPECIAL_ALLOCATOR */
+ }
private:
/*! Helds an allocated segment of memory */
struct Segment {
diff --git a/backend/src/sys/barrier.hpp b/backend/src/sys/barrier.hpp
deleted file mode 100644
index 2721773a..00000000
--- a/backend/src/sys/barrier.hpp
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright © 2012 Intel Corporation
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- * Author: Benjamin Segovia <benjamin.segovia@intel.com>
- */
-
-//////////////////////////////////////////////////////////////////////////////////////////
-// Part of this file is taken from the Apache licensed Intel Embree project here: //
-// http://software.intel.com/en-us/articles/embree-photo-realistic-ray-tracing-kernels/ //
-//////////////////////////////////////////////////////////////////////////////////////////
-
-#ifndef __GBE_BARRIER_HPP__
-#define __GBE_BARRIER_HPP__
-
-#include "sys/condition.hpp"
-
-namespace gbe
-{
- /*! system barrier using operating system */
- class BarrierSys
- {
- public:
-
- void init(size_t count) {
- this->count = 0;
- this->full_size = count;
- }
-
- int wait() {
- count_mutex.lock();
- count++;
- if (count == full_size) {
- count = 0;
- cond.broadcast();
- count_mutex.unlock();
- return 1;
- }
- cond.wait(count_mutex);
- count_mutex.unlock();
- return 0;
- }
-
- protected:
- size_t count, full_size;
- MutexSys count_mutex;
- ConditionSys cond;
- GBE_CLASS(BarrierSys);
- };
-
- /* default barrier type */
- class Barrier : public BarrierSys {};
-}
-
-#endif
diff --git a/backend/src/sys/condition.cpp b/backend/src/sys/condition.cpp
deleted file mode 100644
index bed37d5b..00000000
--- a/backend/src/sys/condition.cpp
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * Copyright © 2012 Intel Corporation
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- * Author: Benjamin Segovia <benjamin.segovia@intel.com>
- */
-
-//////////////////////////////////////////////////////////////////////////////////////////
-// Part of this file is taken from the Apache licensed Intel Embree project here: //
-// http://software.intel.com/en-us/articles/embree-photo-realistic-ray-tracing-kernels/ //
-//////////////////////////////////////////////////////////////////////////////////////////
-
-#include "sys/condition.hpp"
-
-#if defined(__WIN32__)
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
-
-#if defined(__GNUC__)
-
-namespace gbe
-{
- // This is an implementation of POSIX "compatible" condition variables for
- // Win32, as described by Douglas C. Schmidt and Irfan Pyarali:
- // http://www.cs.wustl.edu/~schmidt/win32-cv-1.html. The code is directly
- // readapted from the glfw source code that may be found here:
- // http://www.glfw.org
- enum {
- MINGW32_COND_SIGNAL = 0,
- MINGW32_COND_BROADCAST = 1
- };
-
- /*! Implement the internal condition variable implementation Mingw lacks */
- struct Mingw32Cond
- {
- HANDLE events[2]; //<! Signal and broadcast event HANDLEs
- unsigned int waiters_count; //<! Count of the number of waiters
- CRITICAL_SECTION waiters_count_lock;//!< Serialize access to <waiters_count>
- };
-
- ConditionSys::ConditionSys ()
- {
- cond = (Mingw32Cond *) GBE_NEW(Mingw32Cond);
- ((Mingw32Cond *)cond)->waiters_count = 0;
- ((Mingw32Cond *)cond)->events[MINGW32_COND_SIGNAL] = CreateEvent(NULL, FALSE, FALSE, NULL);
- ((Mingw32Cond *)cond)->events[MINGW32_COND_BROADCAST] = CreateEvent(NULL, TRUE, FALSE, NULL);
- InitializeCriticalSection(&((Mingw32Cond *)cond)->waiters_count_lock);
- }
-
- ConditionSys::~ConditionSys ()
- {
- CloseHandle(((Mingw32Cond *)cond)->events[MINGW32_COND_SIGNAL]);
- CloseHandle(((Mingw32Cond *)cond)->events[MINGW32_COND_BROADCAST]);
- DeleteCriticalSection(&((Mingw32Cond *)cond)->waiters_count_lock);
- GBE_DELETE((Mingw32Cond *)cond);
- }
-
- void ConditionSys::wait(MutexSys& mutex)
- {
- Mingw32Cond *cv = (Mingw32Cond *) cond;
- int result, last_waiter;
- DWORD timeout_ms;
-
- // Avoid race conditions
- EnterCriticalSection(&cv->waiters_count_lock);
- cv->waiters_count ++;
- LeaveCriticalSection(&cv->waiters_count_lock);
-
- // It's ok to release the mutex here since Win32 manual-reset events
- // maintain state when used with SetEvent()
- LeaveCriticalSection((CRITICAL_SECTION *) mutex.mutex);
- timeout_ms = INFINITE;
-
- // Wait for either event to become signaled
- result = WaitForMultipleObjects(2, cv->events, FALSE, timeout_ms);
-
- // Check if we are the last waiter
- EnterCriticalSection(&cv->waiters_count_lock);
- cv->waiters_count --;
- last_waiter = (result == WAIT_OBJECT_0 + MINGW32_COND_BROADCAST) &&
- (cv->waiters_count == 0);
- LeaveCriticalSection(&cv->waiters_count_lock);
-
- // Some thread called broadcast
- if (last_waiter) {
- // We're the last waiter to be notified or to stop waiting, so
- // reset the manual event
- ResetEvent(cv->events[MINGW32_COND_BROADCAST]);
- }
-
- // Reacquire the mutex
- EnterCriticalSection((CRITICAL_SECTION *) mutex.mutex);
- }
-
- void ConditionSys::broadcast()
- {
- Mingw32Cond *cv = (Mingw32Cond *) cond;
- int have_waiters;
-
- // Avoid race conditions
- EnterCriticalSection(&cv->waiters_count_lock);
- have_waiters = cv->waiters_count > 0;
- LeaveCriticalSection(&cv->waiters_count_lock);
-
- if (have_waiters)
- SetEvent(cv->events[MINGW32_COND_BROADCAST]);
- }
-} /* namespace gbe */
-#else
-
-namespace gbe
-{
- /*! system condition using windows API */
- ConditionSys::ConditionSys () { cond = GBE_NEW(CONDITION_VARIABLE); InitializeConditionVariable((CONDITION_VARIABLE*)cond); }
- ConditionSys::~ConditionSys() { GBE_DELETE((CONDITION_VARIABLE*)cond); }
- void ConditionSys::wait(MutexSys& mutex) { SleepConditionVariableCS((CONDITION_VARIABLE*)cond, (CRITICAL_SECTION*)mutex.mutex, INFINITE); }
- void ConditionSys::broadcast() { WakeAllConditionVariable((CONDITION_VARIABLE*)cond); }
-} /* namespace gbe */
-#endif /* __GNUC__ */
-#endif /* __WIN32__ */
-
-#if defined(__UNIX__)
-#include <pthread.h>
-namespace gbe
-{
- ConditionSys::ConditionSys () { cond = GBE_NEW(pthread_cond_t); pthread_cond_init((pthread_cond_t*)cond,NULL); }
- ConditionSys::~ConditionSys() { GBE_DELETE((pthread_cond_t*)cond); }
- void ConditionSys::wait(MutexSys& mutex) { pthread_cond_wait((pthread_cond_t*)cond, (pthread_mutex_t*)mutex.mutex); }
- void ConditionSys::broadcast() { pthread_cond_broadcast((pthread_cond_t*)cond); }
-} /* namespace gbe */
-#endif /* __UNIX__ */
-
diff --git a/backend/src/sys/condition.hpp b/backend/src/sys/condition.hpp
deleted file mode 100644
index e61e12fe..00000000
--- a/backend/src/sys/condition.hpp
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright © 2012 Intel Corporation
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- * Author: Benjamin Segovia <benjamin.segovia@intel.com>
- */
-
-//////////////////////////////////////////////////////////////////////////////////////////
-// Part of this file is taken from the Apache licensed Intel Embree project here: //
-// http://software.intel.com/en-us/articles/embree-photo-realistic-ray-tracing-kernels/ //
-//////////////////////////////////////////////////////////////////////////////////////////
-
-#ifndef __GBE_CONDITION_HPP__
-#define __GBE_CONDITION_HPP__
-
-#include "sys/mutex.hpp"
-
-namespace gbe
-{
- class ConditionSys
- {
- public:
- ConditionSys(void);
- ~ConditionSys(void);
- void wait(class MutexSys& mutex);
- void broadcast(void);
- protected:
- void* cond;
- };
-}
-
-#endif /* __GBE_CONDITION_HPP__ */
-
diff --git a/backend/src/sys/constants.hpp b/backend/src/sys/constants.hpp
deleted file mode 100644
index ecefce19..00000000
--- a/backend/src/sys/constants.hpp
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
- * Copyright © 2012 Intel Corporation
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- * Author: Benjamin Segovia <benjamin.segovia@intel.com>
- */
-
-//////////////////////////////////////////////////////////////////////////////////////////
-// Part of this file is taken from the Apache licensed Intel Embree project here: //
-// http://software.intel.com/en-us/articles/embree-photo-realistic-ray-tracing-kernels/ //
-//////////////////////////////////////////////////////////////////////////////////////////
-
-#ifndef __GBE_CONSTANTS_HPP__
-#define __GBE_CONSTANTS_HPP__
-
-#ifndef NULL
-#define NULL 0
-#endif
-
-#include <limits>
-
-namespace gbe
-{
- static struct NullTy {
- } null MAYBE_UNUSED;
-
- static struct TrueTy {
- INLINE operator bool( ) const { return true; }
- } True MAYBE_UNUSED;
-
- static struct FalseTy {
- INLINE operator bool( ) const { return false; }
- } False MAYBE_UNUSED;
-
- static struct ZeroTy
- {
- INLINE operator double( ) const { return 0; }
- INLINE operator float ( ) const { return 0; }
- INLINE operator int64_t ( ) const { return 0; }
- INLINE operator uint64_t( ) const { return 0; }
- INLINE operator int32_t ( ) const { return 0; }
- INLINE operator uint32_t( ) const { return 0; }
- INLINE operator int16_t ( ) const { return 0; }
- INLINE operator uint16_t( ) const { return 0; }
- INLINE operator int8_t ( ) const { return 0; }
- INLINE operator uint8_t ( ) const { return 0; }
-#ifndef __MSVC__
- INLINE operator size_t( ) const { return 0; }
-#endif
-
- } zero MAYBE_UNUSED;
-
- static struct OneTy
- {
- INLINE operator double( ) const { return 1; }
- INLINE operator float ( ) const { return 1; }
- INLINE operator int64_t ( ) const { return 1; }
- INLINE operator uint64_t( ) const { return 1; }
- INLINE operator int32_t ( ) const { return 1; }
- INLINE operator uint32_t( ) const { return 1; }
- INLINE operator int16_t ( ) const { return 1; }
- INLINE operator uint16_t( ) const { return 1; }
- INLINE operator int8_t ( ) const { return 1; }
- INLINE operator uint8_t ( ) const { return 1; }
-#ifndef __MSVC__
- INLINE operator size_t( ) const { return 1; }
-#endif
- } one MAYBE_UNUSED;
-
- static struct NegInfTy
- {
- INLINE operator double( ) const { return -std::numeric_limits<double>::infinity(); }
- INLINE operator float ( ) const { return -std::numeric_limits<float>::infinity(); }
- INLINE operator int64_t ( ) const { return std::numeric_limits<int64_t>::min(); }
- INLINE operator uint64_t( ) const { return std::numeric_limits<uint64_t>::min(); }
- INLINE operator int32_t ( ) const { return std::numeric_limits<int32_t>::min(); }
- INLINE operator uint32_t( ) const { return std::numeric_limits<uint32_t>::min(); }
- INLINE operator int16_t ( ) const { return std::numeric_limits<int16_t>::min(); }
- INLINE operator uint16_t( ) const { return std::numeric_limits<uint16_t>::min(); }
- INLINE operator int8_t ( ) const { return std::numeric_limits<int8_t>::min(); }
- INLINE operator uint8_t ( ) const { return std::numeric_limits<uint8_t>::min(); }
-#ifndef __MSVC__
- INLINE operator size_t( ) const { return std::numeric_limits<size_t>::min(); }
-#endif
-
- } neg_inf MAYBE_UNUSED;
-
- static struct PosInfTy
- {
- INLINE operator double( ) const { return std::numeric_limits<double>::infinity(); }
- INLINE operator float ( ) const { return std::numeric_limits<float>::infinity(); }
- INLINE operator int64_t ( ) const { return std::numeric_limits<int64_t>::max(); }
- INLINE operator uint64_t( ) const { return std::numeric_limits<uint64_t>::max(); }
- INLINE operator int32_t ( ) const { return std::numeric_limits<int32_t>::max(); }
- INLINE operator uint32_t( ) const { return std::numeric_limits<uint32_t>::max(); }
- INLINE operator int16_t ( ) const { return std::numeric_limits<int16_t>::max(); }
- INLINE operator uint16_t( ) const { return std::numeric_limits<uint16_t>::max(); }
- INLINE operator int8_t ( ) const { return std::numeric_limits<int8_t>::max(); }
- INLINE operator uint8_t ( ) const { return std::numeric_limits<uint8_t>::max(); }
-#ifndef _WIN32
- INLINE operator size_t( ) const { return std::numeric_limits<size_t>::max(); }
-#endif
- } inf MAYBE_UNUSED, pos_inf MAYBE_UNUSED;
-
- static struct NaNTy
- {
- INLINE operator double( ) const { return std::numeric_limits<double>::quiet_NaN(); }
- INLINE operator float ( ) const { return std::numeric_limits<float>::quiet_NaN(); }
- } nan MAYBE_UNUSED;
-
- static struct UlpTy
- {
- INLINE operator double( ) const { return std::numeric_limits<double>::epsilon(); }
- INLINE operator float ( ) const { return std::numeric_limits<float>::epsilon(); }
- } ulp MAYBE_UNUSED;
-
- static struct PiTy
- {
- INLINE operator double( ) const { return 3.14159265358979323846; }
- INLINE operator float ( ) const { return 3.14159265358979323846f; }
- } pi MAYBE_UNUSED;
-
- static struct StepTy {
- } step MAYBE_UNUSED;
-
- static struct EmptyTy {
- } empty MAYBE_UNUSED;
-
- static struct FullTy {
- } full MAYBE_UNUSED;
-
- static const size_t KB = 1024u;
- static const size_t MB = KB*KB;
- static const size_t GB = KB*MB;
-}
-
-#endif /* __GBE_CONSTANTS_HPP__ */
-
diff --git a/backend/src/sys/platform.hpp b/backend/src/sys/platform.hpp
index 4f3b3001..735d38f1 100644
--- a/backend/src/sys/platform.hpp
+++ b/backend/src/sys/platform.hpp
@@ -260,6 +260,10 @@ private: \
/*! Default alignment for the platform */
#define GBE_DEFAULT_ALIGNMENT 16
+/*! Useful constants */
+#define KB 1024
+#define MB (KB*KB)
+
/*! Portable AlignOf */
template <typename T>
struct AlignOf {
@@ -336,7 +340,6 @@ private:
/// Default Includes and Functions
////////////////////////////////////////////////////////////////////////////////
-#include "sys/constants.hpp"
#include "sys/alloc.hpp"
namespace gbe
diff --git a/backend/src/sys/string.cpp b/backend/src/sys/string.cpp
deleted file mode 100644
index a63cfd3c..00000000
--- a/backend/src/sys/string.cpp
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Copyright © 2012 Intel Corporation
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- * Author: Benjamin Segovia <benjamin.segovia@intel.com>
- */
-
-/**
- * \file string.cpp
- *
- * \author Benjamin Segovia <benjamin.segovia@intel.com>
- */
-#include "sys/string.hpp"
-
-#include <cstdio>
-#include <cctype>
-#include <istream>
-#include <fstream>
-#include <algorithm>
-
-namespace std
-{
- char to_lower(char c) { return char(tolower(int(c))); }
- char to_upper(char c) { return char(toupper(int(c))); }
- string strlwr(const string& s) {
- string dst(s);
- std::transform(dst.begin(), dst.end(), dst.begin(), to_lower);
- return dst;
- }
- string strupr(const string& s) {
- string dst(s);
- std::transform(dst.begin(), dst.end(), dst.begin(), to_upper);
- return dst;
- }
-
-}
-namespace gbe
-{
- /* $Id: strtok_r.c,v 1.1 2003/12/03 15:22:23 chris_reid Exp $ */
- /*
- * Copyright (c) 1995, 1996, 1997 Kungliga Tekniska Hgskolan
- * (Royal Institute of Technology, Stockholm, Sweden).
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * 3. Neither the name of the Institute nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
- char* tokenize(char *s1, const char *s2, char **lasts)
- {
- char *ret;
-
- if (s1 == NULL)
- s1 = *lasts;
- while(*s1 && strchr(s2, *s1))
- ++s1;
- if(*s1 == '\0')
- return NULL;
- ret = s1;
- while(*s1 && !strchr(s2, *s1))
- ++s1;
- if(*s1)
- *s1++ = '\0';
- *lasts = s1;
- return ret;
- }
-
- bool strequal(const char *s1, const char *s2) {
- if (strcmp(s1, s2) == 0) return true;
- return false;
- }
-
- bool contains(const char *haystack, const char *needle) {
- if (strstr(haystack, needle) == NULL) return false;
- return true;
- }
-}
-
diff --git a/backend/src/sys/string.hpp b/backend/src/sys/string.hpp
deleted file mode 100644
index 2b2883a7..00000000
--- a/backend/src/sys/string.hpp
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright © 2012 Intel Corporation
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- * Author: Benjamin Segovia <benjamin.segovia@intel.com>
- */
-
-//////////////////////////////////////////////////////////////////////////////////////////
-// Part of this file is taken from the Apache licensed Intel Embree project here: //
-// http://software.intel.com/en-us/articles/embree-photo-realistic-ray-tracing-kernels/ //
-//////////////////////////////////////////////////////////////////////////////////////////
-
-#ifndef __GBE_STRING_HPP__
-#define __GBE_STRING_HPP__
-
-#include "sys/platform.hpp"
-
-#include <cstring>
-#include <string>
-#include <sstream>
-#include <fstream>
-#include <ostream>
-
-namespace std
-{
- string strlwr(const string& s);
- string strupr(const string& s);
- template<typename T> INLINE string stringOf(const T& v) {
- stringstream s; s << v; return s.str();
- }
-} /* namespace std */
-
-namespace gbe
-{
- /*! Compare two strings */
- bool strequal(const char *s1, const char *s2);
- /*! Say if needle is in haystack */
- bool contains(const char *haystack, const char *needle);
- /*! Tokenize a string (like strtok_r does) */
- char* tokenize(char *s1, const char *s2, char **lasts);
- /*! To append s or not */
- INLINE const char *plural(uint32_t value) { return value > 1 ? "s" : ""; }
-} /* namespace gbe */
-
-#endif /* __GBE_STRING_HPP__ */
-
diff --git a/backend/src/sys/sysinfo.cpp b/backend/src/sys/sysinfo.cpp
deleted file mode 100644
index cec306f3..00000000
--- a/backend/src/sys/sysinfo.cpp
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * Copyright © 2012 Intel Corporation
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- * Author: Benjamin Segovia <benjamin.segovia@intel.com>
- */
-
-//////////////////////////////////////////////////////////////////////////////////////////
-// Part of this file is taken from the Apache licensed Intel Embree project here: //
-// http://software.intel.com/en-us/articles/embree-photo-realistic-ray-tracing-kernels/ //
-//////////////////////////////////////////////////////////////////////////////////////////
-
-#include "sys/sysinfo.hpp"
-
-////////////////////////////////////////////////////////////////////////////////
-/// All Platforms
-////////////////////////////////////////////////////////////////////////////////
-
-namespace gbe
-{
- /* return platform name */
- std::string getPlatformName() {
-#if defined(__LINUX__) && !defined(__X86_64__)
- return "Linux (32bit)";
-#elif defined(__LINUX__) && defined(__X86_64__)
- return "Linux (64bit)";
-#elif defined(__FREEBSD__) && !defined(__X86_64__)
- return "FreeBSD (32bit)";
-#elif defined(__FREEBSD__) && defined(__X86_64__)
- return "FreeBSD (64bit)";
-#elif defined(__CYGWIN__) && !defined(__X86_64__)
- return "Cygwin (32bit)";
-#elif defined(__CYGWIN__) && defined(__X86_64__)
- return "Cygwin (64bit)";
-#elif defined(__WIN32__) && !defined(__X86_64__)
- return "Windows (32bit)";
-#elif defined(__WIN32__) && defined(__X86_64__)
- return "Windows (64bit)";
-#elif defined(__MACOSX__) && !defined(__X86_64__)
- return "MacOS (32bit)";
-#elif defined(__MACOSX__) && defined(__X86_64__)
- return "MacOS (64bit)";
-#elif defined(__UNIX__) && !defined(__X86_64__)
- return "Unix (32bit)";
-#elif defined(__UNIX__) && defined(__X86_64__)
- return "Unix (64bit)";
-#else
- return "Unknown";
-#endif
- }
-}
-
-////////////////////////////////////////////////////////////////////////////////
-/// Windows Platform
-////////////////////////////////////////////////////////////////////////////////
-
-#ifdef __WIN32__
-
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
-
-namespace gbe
-{
- /* get the full path to the running executable */
- std::string getExecutableFileName() {
- char filename[1024];
- if (!GetModuleFileName(NULL, filename, sizeof(filename))) return std::string();
- return std::string(filename);
- }
-
- /* return the number of logical threads of the system */
- int getNumberOfLogicalThreads() {
- SYSTEM_INFO sysinfo;
- GetSystemInfo(&sysinfo);
- return sysinfo.dwNumberOfProcessors;
- }
-}
-#endif
-
-////////////////////////////////////////////////////////////////////////////////
-/// Linux Platform
-////////////////////////////////////////////////////////////////////////////////
-
-#ifdef __LINUX__
-
-#include <stdio.h>
-#include <unistd.h>
-
-namespace gbe
-{
- /* get the full path to the running executable */
- std::string getExecutableFileName() {
- char pid[32]; sprintf(pid, "/proc/%d/exe", getpid());
- char buf[1024];
- int bytes = readlink(pid, buf, sizeof(buf)-1);
- if (bytes != -1) buf[bytes] = '\0';
- return std::string(buf);
- }
-}
-
-#endif
-
-////////////////////////////////////////////////////////////////////////////////
-/// MacOS Platform
-////////////////////////////////////////////////////////////////////////////////
-
-#ifdef __MACOSX__
-
-#include <mach-o/dyld.h>
-
-namespace gbe
-{
- /* get the full path to the running executable */
- std::string getExecutableFileName()
- {
- char buf[1024];
- uint32_t_t size = sizeof(buf);
- if (_NSGetExecutablePath(buf, &size) != 0) return std::string();
- return std::string(buf);
- }
-}
-
-#endif
-
-////////////////////////////////////////////////////////////////////////////////
-/// Unix Platform
-////////////////////////////////////////////////////////////////////////////////
-
-#if defined(__UNIX__)
-
-#include <unistd.h>
-
-namespace gbe
-{
- /* return the number of logical threads of the system */
- int getNumberOfLogicalThreads() {
- return sysconf(_SC_NPROCESSORS_CONF);
- }
-}
-#endif
-
diff --git a/backend/src/sys/sysinfo.hpp b/backend/src/sys/sysinfo.hpp
deleted file mode 100644
index a4e5b84f..00000000
--- a/backend/src/sys/sysinfo.hpp
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright © 2012 Intel Corporation
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- * Author: Benjamin Segovia <benjamin.segovia@intel.com>
- */
-
-//////////////////////////////////////////////////////////////////////////////////////////
-// Part of this file is taken from the Apache licensed Intel Embree project here: //
-// http://software.intel.com/en-us/articles/embree-photo-realistic-ray-tracing-kernels/ //
-//////////////////////////////////////////////////////////////////////////////////////////
-
-#ifndef __GBE_SYSINFO_HPP__
-#define __GBE_SYSINFO_HPP__
-
-#include "sys/platform.hpp"
-
-#include <string>
-
-namespace gbe
-{
- /*! get the full path to the running executable */
- std::string getExecutableFileName();
- /*! return platform name */
- std::string getPlatformName();
- /*! return the number of logical threads of the system */
- int getNumberOfLogicalThreads();
-}
-
-#endif