* Author: Benjamin Segovia <benjamin.segovia@intel.com>
*/
+#include "ir_function.hpp"
+
--- /dev/null
+/*
+ * 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>
+ */
+
+#ifndef __GBE_IR_FUNCTION_HPP__
+#define __GBE_IR_FUNCTION_HPP__
+
+#endif /* __GBE_IR_FUNCTION_HPP__ */
+
--- /dev/null
+/*
+ * 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>
+ */
+
+#include "ir_instruction.hpp"
+
--- /dev/null
+/*
+ * 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>
+ */
+
+#ifndef __GBE_IR_INSTRUCTION_HPP__
+#define __GBE_IR_INSTRUCTION_HPP__
+
+#endif /* __GBE_IR_INSTRUCTION_HPP__ */
+
+
* Author: Benjamin Segovia <benjamin.segovia@intel.com>
*/
+#include "ir_register.hpp"
+
--- /dev/null
+/*
+ * 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>
+ */
+
+#ifndef __GBE_IR_REGISTER_HPP__
+#define __GBE_IR_REGISTER_HPP__
+
+#endif /* __GBE_IR_REGISTER_HPP__ */
+
+
* Author: Benjamin Segovia <benjamin.segovia@intel.com>
*/
+#include "ir_scope.hpp"
+
--- /dev/null
+/*
+ * 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>
+ */
+
+#ifndef __GBE_IR_SCOPE_HPP__
+#define __GBE_IR_SCOPE_HPP__
+
+#endif /* __GBE_IR_SCOPE_HPP__ */
+
+
* Author: Benjamin Segovia <benjamin.segovia@intel.com>
*/
+#include "ir_unit.hpp"
+
--- /dev/null
+/*
+ * 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>
+ */
+
+#ifndef __GBE_IR_UNIT_HPP__
+#define __GBE_IR_UNIT_HPP__
+
+#endif /* __GBE_IR_UNIT_HPP__ */
+
+
+++ /dev/null
-/*
- * 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>
- */
-
+++ /dev/null
-/*
- * 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>
- */
-
+++ /dev/null
-/*
- * 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>
- */
-
+++ /dev/null
-/*
- * 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>
- */
-
+++ /dev/null
-/*
- * 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>
- */
-
+++ /dev/null
-/*
- * 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>
- */
-
#include "sys/atomic.hpp"
#include "sys/mutex.hpp"
-#if PF_DEBUG_MEMORY
+#if GBE_DEBUG_MEMORY
#ifdef __MSVC__
#include <unordered_map>
#else
#include <tr1/unordered_map>
#endif /* __MSVC__ */
#include <cstring>
-#endif /* PF_DEBUG_MEMORY */
+#endif /* GBE_DEBUG_MEMORY */
#if defined(__ICC__)
#include <stdint.h>
////////////////////////////////////////////////////////////////////////////////
/// Memory debugger
////////////////////////////////////////////////////////////////////////////////
-namespace pf
+namespace gbe
{
-#if PF_DEBUG_MEMORY
+#if GBE_DEBUG_MEMORY
/*! Store each allocation data */
struct AllocData {
INLINE AllocData(void) {}
memDebugger = NULL;
delete _debug;
}
-#endif /* PF_DEBUG_MEMORY */
+#endif /* GBE_DEBUG_MEMORY */
}
-namespace pf
+namespace gbe
{
void* malloc(size_t size) {
void *ptr = std::malloc(size);
}
void* realloc(void *ptr, size_t size) {
-#if PF_DEBUG_MEMORY
+#if GBE_DEBUG_MEMORY
if (ptr) MemDebuggerRemoveAlloc(ptr);
-#endif /* PF_DEBUG_MEMORY */
- PF_ASSERT(size);
+#endif /* GBE_DEBUG_MEMORY */
+ GBE_ASSERT(size);
if (ptr == NULL) {
ptr = std::realloc(ptr, size);
MemDebuggerInitializeMem(ptr, size);
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
-namespace pf
+namespace gbe
{
void* alignedMalloc(size_t size, size_t align) {
void* ptr = _mm_malloc(size,align);
#include <malloc.h>
#include <iostream>
-namespace pf
+namespace gbe
{
void* alignedMalloc(size_t size, size_t align) {
void* ptr = memalign(align,size);
#include <cstdlib>
-namespace pf
+namespace gbe
{
void* alignedMalloc(size_t size, size_t align) {
void* mem = malloc(size+(align-1)+sizeof(void*));
}
void alignedFree(void* ptr) {
- PF_ASSERT(ptr);
+ GBE_ASSERT(ptr);
free(((void**)ptr)[-1]);
}
}
* Author: Benjamin Segovia <benjamin.segovia@intel.com>
*/
-#ifndef __PF_ALLOC_HPP__
-#define __PF_ALLOC_HPP__
+#ifndef __GBE_ALLOC_HPP__
+#define __GBE_ALLOC_HPP__
#include "sys/platform.hpp"
#include <cstdlib>
#include <new>
-namespace pf
+namespace gbe
{
/*! regular allocation */
void* malloc(size_t size);
void alignedFree(void* ptr);
/*! Monitor memory allocations */
-#if PF_DEBUG_MEMORY
+#if GBE_DEBUG_MEMORY
void* MemDebuggerInsertAlloc(void*, const char*, const char*, int);
void MemDebuggerRemoveAlloc(void *ptr);
void MemDebuggerDumpAlloc(void);
INLINE void MemDebuggerEnableMemoryInitialization(bool enabled) {}
INLINE void MemDebuggerStart(void) {}
INLINE void MemDebuggerEnd(void) {}
-#endif /* PF_DEBUG_MEMORY */
+#endif /* GBE_DEBUG_MEMORY */
/*! Properly handle the allocated type */
template <typename T>
MemDebuggerInsertAlloc(ptr, file, function, line);
return ptr;
}
-} /* namespace pf */
+} /* namespace gbe */
/*! Declare a structure with custom allocators */
-#define PF_STRUCT(TYPE) \
+#define GBE_STRUCT(TYPE) \
void* operator new(size_t size) { \
if (AlignOf<TYPE>::value > sizeof(uintptr_t)) \
- return pf::alignedMalloc(size, AlignOf<TYPE>::value); \
+ return gbe::alignedMalloc(size, AlignOf<TYPE>::value); \
else \
- return pf::malloc(size); \
+ return gbe::malloc(size); \
} \
void* operator new[](size_t size) { \
if (AlignOf<TYPE>::value > sizeof(uintptr_t)) \
- return pf::alignedMalloc(size, AlignOf<TYPE>::value); \
+ return gbe::alignedMalloc(size, AlignOf<TYPE>::value); \
else \
- return pf::malloc(size); \
+ return gbe::malloc(size); \
} \
void operator delete(void* ptr) { \
if (AlignOf<TYPE>::value > sizeof(uintptr_t)) \
- return pf::alignedFree(ptr); \
+ return gbe::alignedFree(ptr); \
else \
- return pf::free(ptr); \
+ return gbe::free(ptr); \
} \
void operator delete[](void* ptr) { \
if (AlignOf<TYPE>::value > sizeof(uintptr_t)) \
- return pf::alignedFree(ptr); \
+ return gbe::alignedFree(ptr); \
else \
- return pf::free(ptr); \
+ return gbe::free(ptr); \
} \
/*! Declare a class with custom allocators */
-#define PF_CLASS(TYPE) \
+#define GBE_CLASS(TYPE) \
public: \
- PF_STRUCT(TYPE) \
+ GBE_STRUCT(TYPE) \
private:
/*! Declare an aligned structure */
-#define PF_ALIGNED_STRUCT(ALIGN) \
- void* operator new(size_t size) { return pf::alignedMalloc(size, ALIGN); }\
- void* operator new[](size_t size) { return pf::alignedMalloc(size, ALIGN); }\
- void operator delete(void* ptr) { pf::alignedFree(ptr); } \
- void operator delete[](void* ptr) { pf::alignedFree(ptr); }
+#define GBE_ALIGNED_STRUCT(ALIGN) \
+ void* operator new(size_t size) { return gbe::alignedMalloc(size, ALIGN); }\
+ void* operator new[](size_t size) { return gbe::alignedMalloc(size, ALIGN); }\
+ void operator delete(void* ptr) { gbe::alignedFree(ptr); } \
+ void operator delete[](void* ptr) { gbe::alignedFree(ptr); }
/*! Declare an aligned class */
-#define PF_ALIGNED_CLASS(ALIGN) \
+#define GBE_ALIGNED_CLASS(ALIGN) \
public: \
- PF_ALIGNED_STRUCT(ALIGN) \
+ GBE_ALIGNED_STRUCT(ALIGN) \
private:
/*! Macros to handle allocation position */
-#define PF_NEW(T,...) \
- pf::_MemDebuggerInsertAlloc(new T(__VA_ARGS__), __FILE__, __FUNCTION__, __LINE__)
+#define GBE_NEW(T,...) \
+ gbe::_MemDebuggerInsertAlloc(new T(__VA_ARGS__), __FILE__, __FUNCTION__, __LINE__)
-#define PF_NEW_ARRAY(T,N,...) \
- pf::_MemDebuggerInsertAlloc(new T[N](__VA_ARGS__), __FILE__, __FUNCTION__, __LINE__)
+#define GBE_NEW_ARRAY(T,N,...) \
+ gbe::_MemDebuggerInsertAlloc(new T[N](__VA_ARGS__), __FILE__, __FUNCTION__, __LINE__)
-#define PF_NEW_P(T,X,...) \
- pf::_MemDebuggerInsertAlloc(new (X) T(__VA_ARGS__), __FILE__, __FUNCTION__, __LINE__)
+#define GBE_NEW_P(T,X,...) \
+ gbe::_MemDebuggerInsertAlloc(new (X) T(__VA_ARGS__), __FILE__, __FUNCTION__, __LINE__)
-#define PF_DELETE(X) \
- do { pf::MemDebuggerRemoveAlloc(X); delete X; } while (0)
+#define GBE_DELETE(X) \
+ do { gbe::MemDebuggerRemoveAlloc(X); delete X; } while (0)
-#define PF_DELETE_ARRAY(X) \
- do { pf::MemDebuggerRemoveAlloc(X); delete[] X; } while (0)
+#define GBE_DELETE_ARRAY(X) \
+ do { gbe::MemDebuggerRemoveAlloc(X); delete[] X; } while (0)
-#define PF_MALLOC(SZ) \
- pf::MemDebuggerInsertAlloc(pf::malloc(SZ),__FILE__, __FUNCTION__, __LINE__)
+#define GBE_MALLOC(SZ) \
+ gbe::MemDebuggerInsertAlloc(gbe::malloc(SZ),__FILE__, __FUNCTION__, __LINE__)
-#define PF_REALLOC(PTR, SZ) \
- pf::MemDebuggerInsertAlloc(pf::realloc(PTR, SZ),__FILE__, __FUNCTION__, __LINE__)
+#define GBE_REALLOC(PTR, SZ) \
+ gbe::MemDebuggerInsertAlloc(gbe::realloc(PTR, SZ),__FILE__, __FUNCTION__, __LINE__)
-#define PF_FREE(X) \
- do { pf::MemDebuggerRemoveAlloc(X); pf::free(X); } while (0)
+#define GBE_FREE(X) \
+ do { gbe::MemDebuggerRemoveAlloc(X); gbe::free(X); } while (0)
-#define PF_ALIGNED_FREE(X) \
- do { pf::MemDebuggerRemoveAlloc(X); pf::alignedFree(X); } while (0)
+#define GBE_ALIGNED_FREE(X) \
+ do { gbe::MemDebuggerRemoveAlloc(X); gbe::alignedFree(X); } while (0)
-#define PF_ALIGNED_MALLOC(SZ,ALIGN) \
- pf::MemDebuggerInsertAlloc(pf::alignedMalloc(SZ,ALIGN),__FILE__, __FUNCTION__, __LINE__)
+#define GBE_ALIGNED_MALLOC(SZ,ALIGN) \
+ gbe::MemDebuggerInsertAlloc(gbe::alignedMalloc(SZ,ALIGN),__FILE__, __FUNCTION__, __LINE__)
-namespace pf
+namespace gbe
{
/*! STL compliant allocator to intercept all memory allocations */
template<typename T>
INLINE const_pointer address(const_reference r) { return &r; }
INLINE pointer allocate(size_type n, void_allocator_ptr = 0) {
if (AlignOf<T>::value > sizeof(uintptr_t))
- return (pointer) PF_ALIGNED_MALLOC(n*sizeof(T), AlignOf<T>::value);
+ return (pointer) GBE_ALIGNED_MALLOC(n*sizeof(T), AlignOf<T>::value);
else
- return (pointer) PF_MALLOC(n * sizeof(T));
+ return (pointer) GBE_MALLOC(n * sizeof(T));
}
INLINE void deallocate(pointer p, size_type) {
if (AlignOf<T>::value > sizeof(uintptr_t))
- PF_ALIGNED_FREE(p);
+ GBE_ALIGNED_FREE(p);
else
- PF_FREE(p);
+ GBE_FREE(p);
}
INLINE size_type max_size(void) const {
return std::numeric_limits<size_type>::max() / sizeof(T);
class GrowingPool
{
public:
- GrowingPool(void) : current(PF_NEW(GrowingPoolElem, 1)) {}
- ~GrowingPool(void) { PF_ASSERT(current); PF_DELETE(current); }
+ GrowingPool(void) : current(GBE_NEW(GrowingPoolElem, 1)) {}
+ ~GrowingPool(void) { GBE_ASSERT(current); GBE_DELETE(current); }
T *allocate(void) {
if (UNLIKELY(current->allocated == current->maxElemNum)) {
- GrowingPoolElem *elem = PF_NEW(GrowingPoolElem, 2 * current->maxElemNum);
+ GrowingPoolElem *elem = GBE_NEW(GrowingPoolElem, 2 * current->maxElemNum);
elem->next = current;
current = elem;
}
{
friend class GrowingPool;
GrowingPoolElem(size_t elemNum) {
- this->data = PF_NEW_ARRAY(T, elemNum);
+ this->data = GBE_NEW_ARRAY(T, elemNum);
this->next = NULL;
this->maxElemNum = elemNum;
this->allocated = 0;
}
~GrowingPoolElem(void) {
- PF_ASSERT(this->data);
- PF_DELETE_ARRAY(this->data);
- if (this->next) PF_DELETE(this->next);
+ GBE_ASSERT(this->data);
+ GBE_DELETE_ARRAY(this->data);
+ if (this->next) GBE_DELETE(this->next);
}
T *data;
GrowingPoolElem *next;
size_t allocated, maxElemNum;
};
GrowingPoolElem *current;
- PF_CLASS(GrowingPool);
+ GBE_CLASS(GrowingPool);
};
-} /* namespace pf */
+} /* namespace gbe */
-#endif /* __PF_ALLOC_HPP__ */
+#endif /* __GBE_ALLOC_HPP__ */
* Author: Benjamin Segovia <benjamin.segovia@intel.com>
*/
-#ifndef __PF_ARRAY_HPP__
-#define __PF_ARRAY_HPP__
+#ifndef __GBE_ARRAY_HPP__
+#define __GBE_ARRAY_HPP__
#include "sys/platform.hpp"
#include <vector>
-namespace pf
+namespace gbe
{
/*! Non resizable array with no checking. We make it non-copiable right now
* since we do not want to implement an expensive deep copy
INLINE array(const array &other) {
this->elemNum = other.elemNum;
if (this->elemNum) {
- this->elem = PF_NEW_ARRAY(T, this->elemNum);
+ this->elem = GBE_NEW_ARRAY(T, this->elemNum);
for (size_t i = 0; i < this->elemNum; ++i) this->elem[i] = other.elem[i];
} else
this->elem = NULL;
/*! Assignment operator */
INLINE array& operator= (const array &other) {
if (this->elem != NULL && this->elemNum != other->elemNum) {
- PF_DELETE_ARRAY(this->elem);
+ GBE_DELETE_ARRAY(this->elem);
this->elem = NULL;
this->elemNum = 0;
}
this->elemNum = other.elemNum;
if (this->elemNum) {
if (this->elem == NULL)
- this->elem = PF_NEW_ARRAY(T, this->elemNum);
+ this->elem = GBE_NEW_ARRAY(T, this->elemNum);
for (size_t i = 0; i < this->elemNum; ++i) this->elem[i] = other.elem[i];
} else
this->elem = NULL;
return *this;
}
/*! Delete the allocated elements */
- INLINE ~array(void) { PF_SAFE_DELETE_ARRAY(elem); }
+ INLINE ~array(void) { GBE_SAFE_DELETE_ARRAY(elem); }
/*! Free the already allocated elements and allocate a new array */
INLINE void resize(size_t elemNum_) {
if (elemNum_ != this->elemNum) {
- PF_SAFE_DELETE_ARRAY(elem);
+ GBE_SAFE_DELETE_ARRAY(elem);
if (elemNum_)
- this->elem = PF_NEW_ARRAY(T, elemNum_);
+ this->elem = GBE_NEW_ARRAY(T, elemNum_);
else
this->elem = NULL;
this->elemNum = elemNum_;
INLINE T *end(void) { return this->elem + elemNum; }
/*! Get element at position index (with a bound check) */
INLINE T &operator[] (size_t index) {
- PF_ASSERT(elem && index < elemNum);
+ GBE_ASSERT(elem && index < elemNum);
return elem[index];
}
/*! Get element at position index (with bound check) */
INLINE const T &operator[] (size_t index) const {
- PF_ASSERT(elem && index < elemNum);
+ GBE_ASSERT(elem && index < elemNum);
return elem[index];
}
/*! Return the number of elements */
private:
T *elem; //!< Points to the elements
size_t elemNum; //!< Number of elements in the array
- PF_CLASS(array);
+ GBE_CLASS(array);
};
-} /* namespace pf */
+} /* namespace gbe */
-#endif /* __PF_ARRAY_HPP__ */
+#endif /* __GBE_ARRAY_HPP__ */
* Author: Benjamin Segovia <benjamin.segovia@intel.com>
*/
-#ifndef __PF_ATOMIC_HPP__
-#define __PF_ATOMIC_HPP__
+#ifndef __GBE_ATOMIC_HPP__
+#define __GBE_ATOMIC_HPP__
#include "sys/intrinsics.hpp"
-namespace pf
+namespace gbe
{
template <typename T>
struct AtomicInternal {
private:
volatile T data;
- PF_STRUCT(AtomicInternal);
+ GBE_STRUCT(AtomicInternal);
};
typedef AtomicInternal<atomic32_t> Atomic32;
typedef AtomicInternal<atomic_t> Atomic;
}
-#endif /* __PF_ATOMIC_HPP__ */
+#endif /* __GBE_ATOMIC_HPP__ */
* Author: Benjamin Segovia <benjamin.segovia@intel.com>
*/
-#ifndef __PF_BARRIER_H__
-#define __PF_BARRIER_H__
+#ifndef __GBE_BARRIER_H__
+#define __GBE_BARRIER_H__
#include "sys/condition.hpp"
-namespace pf
+namespace gbe
{
/*! system barrier using operating system */
class BarrierSys
size_t count, full_size;
MutexSys count_mutex;
ConditionSys cond;
- PF_CLASS(BarrierSys);
+ GBE_CLASS(BarrierSys);
};
/* default barrier type */
#if defined(__GNUC__)
-namespace pf
+namespace gbe
{
// This is an implementation of POSIX "compatible" condition variables for
// Win32, as described by Douglas C. Schmidt and Irfan Pyarali:
ConditionSys::ConditionSys ()
{
- cond = (Mingw32Cond *) PF_NEW(Mingw32Cond);
+ 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);
CloseHandle(((Mingw32Cond *)cond)->events[MINGW32_COND_SIGNAL]);
CloseHandle(((Mingw32Cond *)cond)->events[MINGW32_COND_BROADCAST]);
DeleteCriticalSection(&((Mingw32Cond *)cond)->waiters_count_lock);
- PF_DELETE((Mingw32Cond *)cond);
+ GBE_DELETE((Mingw32Cond *)cond);
}
void ConditionSys::wait(MutexSys& mutex)
if (have_waiters)
SetEvent(cv->events[MINGW32_COND_BROADCAST]);
}
-} /* namespace pf */
+} /* namespace gbe */
#else
-namespace pf
+namespace gbe
{
/*! system condition using windows API */
- ConditionSys::ConditionSys () { cond = PF_NEW(CONDITION_VARIABLE); InitializeConditionVariable((CONDITION_VARIABLE*)cond); }
- ConditionSys::~ConditionSys() { PF_DELETE((CONDITION_VARIABLE*)cond); }
+ 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 pf */
+} /* namespace gbe */
#endif /* __GNUC__ */
#endif /* __WIN32__ */
#if defined(__UNIX__)
#include <pthread.h>
-namespace pf
+namespace gbe
{
- ConditionSys::ConditionSys () { cond = PF_NEW(pthread_cond_t); pthread_cond_init((pthread_cond_t*)cond,NULL); }
- ConditionSys::~ConditionSys() { PF_DELETE((pthread_cond_t*)cond); }
+ 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 pf */
+} /* namespace gbe */
#endif /* __UNIX__ */
* Author: Benjamin Segovia <benjamin.segovia@intel.com>
*/
-#ifndef __PF_CONDITION_HPP__
-#define __PF_CONDITION_HPP__
+#ifndef __GBE_CONDITION_HPP__
+#define __GBE_CONDITION_HPP__
#include "sys/mutex.hpp"
-namespace pf
+namespace gbe
{
class ConditionSys
{
* Author: Benjamin Segovia <benjamin.segovia@intel.com>
*/
-#ifndef __PF_CONSTANTS_HPP__
-#define __PF_CONSTANTS_HPP__
+#ifndef __GBE_CONSTANTS_HPP__
+#define __GBE_CONSTANTS_HPP__
#ifndef NULL
#define NULL 0
#include <limits>
-namespace pf
+namespace gbe
{
static struct NullTy {
} null MAYBE_UNUSED;
#include "sys/default_path.hpp"
#include "platform.hpp"
-namespace pf
+namespace gbe
{
const char *defaultPath[] = {
"./share/",
"../../data/"
};
const size_t defaultPathNum = ARRAY_ELEM_NUM(defaultPath);
-} /* namespace pf */
+} /* namespace gbe */
#include <cstdlib>
-namespace pf
+namespace gbe
{
/*! Where you may find data files and shaders */
extern const char *defaultPath[];
/*! Number of default paths */
extern const size_t defaultPathNum;
-} /* namespace pf */
+} /* namespace gbe */
#endif /* __DEFAULT_PATH_HPP__ */
#include "sys/platform.hpp"
#include "sys/filename.hpp"
-namespace pf
+namespace gbe
{
#ifdef __WIN32__
const char path_sep = '\\';
* Author: Benjamin Segovia <benjamin.segovia@intel.com>
*/
-#ifndef __PF_FILENAME_HPP__
-#define __PF_FILENAME_HPP__
+#ifndef __GBE_FILENAME_HPP__
+#define __GBE_FILENAME_HPP__
#include "platform.hpp"
#include <string>
#include <cstdio>
-namespace pf
+namespace gbe
{
/*! Convenience class for handling file names and paths. */
class FileName
friend std::ostream& operator<<(std::ostream& cout, const FileName& filename);
private:
std::string filename;
- PF_CLASS(FileName);
+ GBE_CLASS(FileName);
};
}
-#endif /* __PF_FILENAME_HPP__ */
+#endif /* __GBE_FILENAME_HPP__ */
* Author: Benjamin Segovia <benjamin.segovia@intel.com>
*/
-#ifndef __PF_FIXED_ARRAY_HPP__
-#define __PF_FIXED_ARRAY_HPP__
+#ifndef __GBE_FIXED_ARRAY_HPP__
+#define __GBE_FIXED_ARRAY_HPP__
#include "platform.hpp"
#include <cstring>
-namespace pf
+namespace gbe
{
/*! Regular C array but with bound checks */
template<typename T, size_t N>
T& back(void) { return *(end() - 1); }
/*! Get element at position index (with bound check) */
INLINE T& operator[] (size_t index) {
- PF_ASSERT(index < size());
+ GBE_ASSERT(index < size());
return elem[index];
}
/*! Get element at position index (with bound check) */
INLINE const T& operator[] (size_t index) const {
- PF_ASSERT(index < size());
+ GBE_ASSERT(index < size());
return elem[index];
}
private:
T elem[N]; //!< Store the elements
STATIC_ASSERT(N > 0); //!< zero element is not allowed
- PF_CLASS(fixed_array);
+ GBE_CLASS(fixed_array);
};
-} /* namespace pf */
+} /* namespace gbe */
-#endif /* __PF_FIXED_ARRAY_HPP__ */
+#endif /* __GBE_FIXED_ARRAY_HPP__ */
* Author: Benjamin Segovia <benjamin.segovia@intel.com>
*/
-#ifndef __PF_HASH_MAP_HPP__
-#define __PF_HASH_MAP_HPP__
+#ifndef __GBE_HASH_MAP_HPP__
+#define __GBE_HASH_MAP_HPP__
#include "sys/platform.hpp"
#include <tr1/unordered_map>
#endif /* __MSVC__ */
-namespace pf
+namespace gbe
{
/*! Add specific allocator to the hash map */
template <class Key,
parent_type(first,last,n,hf,eql,a) {}
/*! Copy constructor */
INLINE hash_map(const hash_map &other) : parent_type(other) {}
- PF_CLASS(hash_map);
+ GBE_CLASS(hash_map);
};
-} /* namespace pf */
+} /* namespace gbe */
-#endif /* __PF_HASH_MAP_HPP__ */
+#endif /* __GBE_HASH_MAP_HPP__ */
* Author: Benjamin Segovia <benjamin.segovia@intel.com>
*/
-#ifndef __PF_INTRINSICS_H__
-#define __PF_INTRINSICS_H__
+#ifndef __GBE_INTRINSICS_H__
+#define __GBE_INTRINSICS_H__
#include "sys/platform.hpp"
#include <xmmintrin.h>
#include <intrin.h>
-#define PF_COMPILER_WRITE_BARRIER _WriteBarrier()
-#define PF_COMPILER_READ_WRITE_BARRIER _ReadWriteBarrier()
+#define GBE_COMPILER_WRITE_BARRIER _WriteBarrier()
+#define GBE_COMPILER_READ_WRITE_BARRIER _ReadWriteBarrier()
#if _MSC_VER >= 1400
#pragma intrinsic(_ReadBarrier)
-#define PF_COMPILER_READ_BARRIER _ReadBarrier()
+#define GBE_COMPILER_READ_BARRIER _ReadBarrier()
#else
-#define PF_COMPILER_READ_BARRIER _ReadWriteBarrier()
+#define GBE_COMPILER_READ_BARRIER _ReadWriteBarrier()
#endif /* _MSC_VER >= 1400 */
INLINE int __bsf(int v) {
#endif /* defined(__X86_64__) */
-#define PF_COMPILER_READ_WRITE_BARRIER asm volatile("" ::: "memory");
-#define PF_COMPILER_WRITE_BARRIER PF_COMPILER_READ_WRITE_BARRIER
-#define PF_COMPILER_READ_BARRIER PF_COMPILER_READ_WRITE_BARRIER
+#define GBE_COMPILER_READ_WRITE_BARRIER asm volatile("" ::: "memory");
+#define GBE_COMPILER_WRITE_BARRIER GBE_COMPILER_READ_WRITE_BARRIER
+#define GBE_COMPILER_READ_BARRIER GBE_COMPILER_READ_WRITE_BARRIER
#endif /* __MSVC__ */
template <typename T>
INLINE T __load_acquire(volatile T *ptr)
{
- PF_COMPILER_READ_WRITE_BARRIER;
+ GBE_COMPILER_READ_WRITE_BARRIER;
T x = *ptr; // for x86, load == load_acquire
- PF_COMPILER_READ_WRITE_BARRIER;
+ GBE_COMPILER_READ_WRITE_BARRIER;
return x;
}
template <typename T>
INLINE void __store_release(volatile T *ptr, T x)
{
- PF_COMPILER_READ_WRITE_BARRIER;
+ GBE_COMPILER_READ_WRITE_BARRIER;
*ptr = x; // for x86, store == store_release
- PF_COMPILER_READ_WRITE_BARRIER;
+ GBE_COMPILER_READ_WRITE_BARRIER;
}
-#endif /* __PF_INTRINSICS_H__ */
+#endif /* __GBE_INTRINSICS_H__ */
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
-namespace pf
+namespace gbe
{
/* opens a shared library */
lib_t openLibrary(const std::string& file)
#include <dlfcn.h>
-namespace pf
+namespace gbe
{
/* opens a shared library */
lib_t openLibrary(const std::string& file)
* Author: Benjamin Segovia <benjamin.segovia@intel.com>
*/
-#ifndef __PF_LIBRARY_HPP__
-#define __PF_LIBRARY_HPP__
+#ifndef __GBE_LIBRARY_HPP__
+#define __GBE_LIBRARY_HPP__
#include <string>
#include "sys/platform.hpp"
-namespace pf
+namespace gbe
{
/*! type for shared library */
typedef struct opaque_lib_t* lib_t;
void* getSymbol(lib_t lib, const std::string& sym);
/*! unloads a shared library */
void closeLibrary(lib_t lib);
-} /* namespace pf */
+} /* namespace gbe */
-#endif /* __PF_LIBRARY_HPP__ */
+#endif /* __GBE_LIBRARY_HPP__ */
* Author: Benjamin Segovia <benjamin.segovia@intel.com>
*/
-#ifndef __PF_LIST_HPP__
-#define __PF_LIST_HPP__
+#ifndef __GBE_LIST_HPP__
+#define __GBE_LIST_HPP__
#include "sys/platform.hpp"
#include <list>
-namespace pf
+namespace gbe
{
/*! Use custom allocator instead of std one */
template <typename T>
parent_type(first, last, a) {}
/*! Copy constructor */
INLINE list(const list &x) : parent_type(x) {}
- PF_CLASS(list);
+ GBE_CLASS(list);
};
-} /* namespace pf */
+} /* namespace gbe */
-#endif /* __PF_LIST_HPP__ */
+#endif /* __GBE_LIST_HPP__ */
#include "sys/logging.hpp"
#include "sys/filename.hpp"
-namespace pf
+namespace gbe
{
LoggerStream::LoggerStream(void) : next(NULL) {}
LoggerStream::~LoggerStream(void) {}
Logger::Logger(void) : streams(NULL) {
const uint32 threadNum = 1;
- this->buffers = PF_NEW_ARRAY(LoggerBuffer, threadNum);
+ this->buffers = GBE_NEW_ARRAY(LoggerBuffer, threadNum);
for (uint32 i = 0; i < threadNum; ++i) this->buffers[i].logger = this;
this->startTime = getSeconds();
}
Logger::~Logger(void) {
FATAL_IF(streams != NULL, "Remove all streams before deleting the logger");
- PF_DELETE_ARRAY(buffers);
+ GBE_DELETE_ARRAY(buffers);
}
void Logger::output(const std::string &str) {
}
Logger *logger = NULL;
-} /* namespace pf */
+} /* namespace gbe */
* Author: Benjamin Segovia <benjamin.segovia@intel.com>
*/
-#ifndef __PF_LOGGING_HPP__
-#define __PF_LOGGING_HPP__
+#ifndef __GBE_LOGGING_HPP__
+#define __GBE_LOGGING_HPP__
#include "sys/mutex.hpp"
#include "sys/platform.hpp"
#include <sstream>
#include <iomanip>
-namespace pf
+namespace gbe
{
class Logger;
class LoggerBuffer;
file(file), function(function), line(line) {}
const char *file, *function;
int line;
- PF_CLASS(LoggerInfo);
+ GBE_CLASS(LoggerInfo);
};
/*! Used to lazily create strings from the user defined logs. When destroyed
LoggerBuffer(void);
Logger *logger; //!< The logger that created this buffer
std::stringstream ss; //!< Stores all the user strings
- PF_CLASS(LoggerBuffer);
+ GBE_CLASS(LoggerBuffer);
};
/*! Central class to log anything from the engine */
LoggerStream *streams; //!< All the output streams
LoggerBuffer *buffers; //!< One buffer per thread
double startTime; //!< When the logger has been created
- PF_CLASS(Logger);
+ GBE_CLASS(Logger);
};
/*! We have one logger for the application */
extern Logger *logger;
-} /* namespace pf */
+} /* namespace gbe */
/*! Macros to handle logging information in the code */
-#define PF_LOG_HERE LoggerInfo(__FILE__, __FUNCTION__, __LINE__)
-#define PF_INFO " ######## " << PF_LOG_HERE
+#define GBE_LOG_HERE LoggerInfo(__FILE__, __FUNCTION__, __LINE__)
+#define GBE_INFO " ######## " << GBE_LOG_HERE
/*! Verbose macros: they add logging position and thread ID */
-#define PF_WARNING_V(MSG) do { \
- if (logger) *logger << "WARNING " << MSG << PF_INFO << "\n" << loggerFlush; \
+#define GBE_WARNING_V(MSG) do { \
+ if (logger) *logger << "WARNING " << MSG << GBE_INFO << "\n" << loggerFlush; \
} while (0)
-#define PF_ERROR_V(MSG) do { \
- if (logger) *logger << "ERROR " << MSG << PF_INFO << "\n" << loggerFlush; \
+#define GBE_ERROR_V(MSG) do { \
+ if (logger) *logger << "ERROR " << MSG << GBE_INFO << "\n" << loggerFlush; \
} while (0)
-#define PF_MSG_V(MSG) do { \
- if (logger) *logger << MSG << PF_INFO << "\n" << loggerFlush; \
+#define GBE_MSG_V(MSG) do { \
+ if (logger) *logger << MSG << GBE_INFO << "\n" << loggerFlush; \
} while (0)
/*! Regular macros: just the user message */
-#define PF_WARNING(MSG) do { \
+#define GBE_WARNING(MSG) do { \
if (logger) *logger << "WARNING " << MSG << "\n" << loggerFlush; \
} while (0)
-#define PF_ERROR(MSG) do { \
+#define GBE_ERROR(MSG) do { \
if (logger) *logger << "ERROR " << MSG << "\n" << loggerFlush; \
} while (0)
-#define PF_MSG(MSG) do { \
+#define GBE_MSG(MSG) do { \
if (logger) *logger << MSG << "\n" << loggerFlush; \
} while (0)
-#endif /* __PF_LOGGING_HPP__ */
+#endif /* __GBE_LOGGING_HPP__ */
* Author: Benjamin Segovia <benjamin.segovia@intel.com>
*/
-#ifndef __PF_MAP_HPP__
-#define __PF_MAP_HPP__
+#ifndef __GBE_MAP_HPP__
+#define __GBE_MAP_HPP__
#include "sys/platform.hpp"
#include <map>
parent_type(first, last, comp, a) {}
/*! Copy constructor */
INLINE map(const map& x) : parent_type(x) {}
- PF_CLASS(map);
+ GBE_CLASS(map);
};
} /* namespace pf */
-#endif /* __PF_MAP_HPP__ */
+#endif /* __GBE_MAP_HPP__ */
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
-namespace pf
+namespace gbe
{
/*! system mutex using windows API */
MutexSys::MutexSys( void ) { mutex = new CRITICAL_SECTION; InitializeCriticalSection((CRITICAL_SECTION*)mutex); }
#if defined(__UNIX__)
#include <pthread.h>
-namespace pf
+namespace gbe
{
/*! system mutex using pthreads */
MutexSys::MutexSys( void ) { mutex = new pthread_mutex_t; pthread_mutex_init((pthread_mutex_t*)mutex, NULL); }
* Author: Benjamin Segovia <benjamin.segovia@intel.com>
*/
-#ifndef __PF_MUTEX_H__
-#define __PF_MUTEX_H__
+#ifndef __GBE_MUTEX_H__
+#define __GBE_MUTEX_H__
#include "platform.hpp"
#include "atomic.hpp"
#include <xmmintrin.h>
-namespace pf
+namespace gbe
{
class MutexSys {
friend class ConditionSys;
void* mutex;
MutexSys(const MutexSys&); // don't implement
MutexSys& operator= (const MutexSys&); // don't implement
- PF_CLASS(MutexSys);
+ GBE_CLASS(MutexSys);
};
/*! active mutex */
public:
INLINE MutexActive(void) : $lock(LOCK_IS_FREE) {}
INLINE void lock(void) {
- PF_COMPILER_READ_BARRIER;
+ GBE_COMPILER_READ_BARRIER;
while (cmpxchg($lock, LOCK_IS_TAKEN, LOCK_IS_FREE) != LOCK_IS_FREE)
_mm_pause();
- PF_COMPILER_READ_BARRIER;
+ GBE_COMPILER_READ_BARRIER;
}
INLINE void unlock(void) { $lock.storeRelease(LOCK_IS_FREE); }
protected:
Atomic $lock;
MutexActive(const MutexActive&); // don't implement
MutexActive& operator=(const MutexActive&); // don't implement
- PF_CLASS(MutexActive);
+ GBE_CLASS(MutexActive);
};
/*! safe mutex lock and unlock helper */
Mutex& mutex;
Lock(const Lock&); // don't implement
Lock& operator= (const Lock&); // don't implement
- PF_CLASS(Lock);
+ GBE_CLASS(Lock);
};
}
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
-namespace pf
+namespace gbe
{
double getSeconds() {
LARGE_INTEGER freq, val;
void FATAL(const std::string &msg) {
std::cerr << msg << std::endl;
MessageBox(NULL, msg.c_str(), "Fatal Error", MB_OK | MB_ICONEXCLAMATION);
- PF_ASSERT(0);
+ GBE_ASSERT(0);
#ifdef __GNUC__
exit(-1);
#else
#endif /* __GNUC__ */
}
-} /* namespace pf */
+} /* namespace gbe */
#endif /* __WIN32__ */
////////////////////////////////////////////////////////////////////////////////
#include <sys/time.h>
-namespace pf
+namespace gbe
{
double getSeconds() {
struct timeval tp; gettimeofday(&tp,NULL);
void FATAL(const std::string &msg) {
std::cerr << msg << std::endl;
- PF_ASSERT(0);
+ GBE_ASSERT(0);
_exit(-1);
}
-} /* namespace pf */
+} /* namespace gbe */
#endif /* __UNIX__ */
* Author: Benjamin Segovia <benjamin.segovia@intel.com>
*/
-#ifndef __PF_PLATFORM_HPP__
-#define __PF_PLATFORM_HPP__
+#ifndef __GBE_PLATFORM_HPP__
+#define __GBE_PLATFORM_HPP__
#include <cstddef>
#include <cstdlib>
#include <cstdio>
/*! Run-time assertion */
#ifndef NDEBUG
-#define PF_ASSERT(EXPR) do { \
+#define GBE_ASSERT(EXPR) do { \
if (UNLIKELY(!(EXPR))) assert(EXPR); \
} while (0)
#else
-#define PF_ASSERT(EXPR) do { } while (0)
+#define GBE_ASSERT(EXPR) do { } while (0)
#endif
/*! Compile-time assertion */
} while (0)
/* Safe deletion macros */
-#define PF_SAFE_DELETE_ARRAY(x) do { if (x != NULL) PF_DELETE_ARRAY(x); } while (0)
-#define PF_SAFE_DELETE(x) do { if (x != NULL) PF_DELETE(x); } while (0)
+#define GBE_SAFE_DELETE_ARRAY(x) do { if (x != NULL) GBE_DELETE_ARRAY(x); } while (0)
+#define GBE_SAFE_DELETE(x) do { if (x != NULL) GBE_DELETE(x); } while (0)
/* Number of elements in an array */
#define ARRAY_ELEM_NUM(x) (sizeof(x) / sizeof(x[0]))
////////////////////////////////////////////////////////////////////////////////
#if defined __WIN32__
#if defined __GNUC__
- #define PF_EXPORT_SYMBOL __attribute__ ((dllexport))
- #define PF_IMPORT_SYMBOL __attribute__ ((dllimport))
+ #define GBE_EXPORT_SYMBOL __attribute__ ((dllexport))
+ #define GBE_IMPORT_SYMBOL __attribute__ ((dllimport))
#else
- #define PF_IMPORT_SYMBOL __declspec(dllimport)
- #define PF_EXPORT_SYMBOL __declspec(dllexport)
+ #define GBE_IMPORT_SYMBOL __declspec(dllimport)
+ #define GBE_EXPORT_SYMBOL __declspec(dllexport)
#endif /* __GNUC__ */
#else
- #define PF_EXPORT_SYMBOL __attribute__ ((visibility ("default")))
- #define PF_IMPORT_SYMBOL
+ #define GBE_EXPORT_SYMBOL __attribute__ ((visibility ("default")))
+ #define GBE_IMPORT_SYMBOL
#endif /* __WIN32__ */
////////////////////////////////////////////////////////////////////////////////
#include "sys/constants.hpp"
#include "sys/alloc.hpp"
-namespace pf
+namespace gbe
{
/*! selects */
INLINE bool select(bool s, bool t , bool f) { return s ? t : f; }
/** returns performance counter in seconds */
double getSeconds();
-} /* namespace pf */
+} /* namespace gbe */
-#endif /* __PF_PLATFORM_HPP__ */
+#endif /* __GBE_PLATFORM_HPP__ */
* Author: Benjamin Segovia <benjamin.segovia@intel.com>
*/
-#ifndef __PF_REF_HPP__
-#define __PF_REF_HPP__
+#ifndef __GBE_REF_HPP__
+#define __GBE_REF_HPP__
#include "sys/atomic.hpp"
#include "sys/alloc.hpp"
-namespace pf
+namespace gbe
{
class RefCount
{
INLINE Ref(NullTy) : ptr(NULL) {}
INLINE Ref(const Ref& input) : ptr(input.ptr) { if ( ptr ) ptr->refInc(); }
INLINE Ref(Type* const input) : ptr(input) { if (ptr) ptr->refInc(); }
- INLINE ~Ref(void) { if (ptr && ptr->refDec()) PF_DELETE(ptr); }
+ INLINE ~Ref(void) { if (ptr && ptr->refDec()) GBE_DELETE(ptr); }
INLINE Ref& operator= (const Ref &input) {
if (input.ptr) input.ptr->refInc();
- if (ptr && ptr->refDec()) PF_DELETE(ptr);
+ if (ptr && ptr->refDec()) GBE_DELETE(ptr);
*(Type**)&ptr = input.ptr;
return *this;
}
INLINE Ref<TypeOut> cast() { return Ref<TypeOut>(static_cast<TypeOut*>(ptr)); }
template<typename TypeOut>
INLINE const Ref<TypeOut> cast() const { return Ref<TypeOut>(static_cast<TypeOut*>(ptr)); }
- PF_CLASS(Ref);
+ GBE_CLASS(Ref);
};
template<typename Type> INLINE bool operator< ( const Ref<Type>& a, const Ref<Type>& b ) { return a.ptr < b.ptr ; }
template<typename Type> INLINE bool operator!= ( const Ref<Type>& a, const Ref<Type>& b ) { return a.ptr != b.ptr ; }
}
-#endif /* __PF_REF_HPP__ */
+#endif /* __GBE_REF_HPP__ */
* Author: Benjamin Segovia <benjamin.segovia@intel.com>
*/
-#ifndef __PF_SET_HPP__
-#define __PF_SET_HPP__
+#ifndef __GBE_SET_HPP__
+#define __GBE_SET_HPP__
#include "sys/platform.hpp"
#include <set>
-namespace pf
+namespace gbe
{
/*! Add our custom allocator to std::set */
template<class Key, class Pred = std::less<Key>>
parent_type(first, last, comp, a) {}
/*! Copy constructor */
INLINE set(const set& x) : parent_type(x) {}
- PF_CLASS(set);
+ GBE_CLASS(set);
};
-} /* namespace pf */
+} /* namespace gbe */
-#endif /* __PF_SET_HPP__ */
+#endif /* __GBE_SET_HPP__ */
}
}
-namespace pf
+namespace gbe
{
/* $Id: strtok_r.c,v 1.1 2003/12/03 15:22:23 chris_reid Exp $ */
/*
std::string loadFile(std::ifstream &stream)
{
- PF_ASSERT(stream.is_open());
+ GBE_ASSERT(stream.is_open());
std::string line;
std::stringstream text;
while (std::getline(stream, line))
* Author: Benjamin Segovia <benjamin.segovia@intel.com>
*/
-#ifndef __PF_STRING_H__
-#define __PF_STRING_H__
+#ifndef __GBE_STRING_HPP__
+#define __GBE_STRING_HPP__
#include "sys/platform.hpp"
#include "sys/filename.hpp"
{
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 pf
+} /* namespace std */
+
+namespace gbe
{
/*! Compare two strings */
bool strequal(const char *s1, const char *s2);
std::string loadFile(const FileName &path);
/*! Load a file from a stream and copies it into a string */
std::string loadFile(std::ifstream &stream);
-}
-#endif
+} /* namespace gbe */
+
+#endif /* __GBE_STRING_HPP__ */
+
/// All Platforms
////////////////////////////////////////////////////////////////////////////////
-namespace pf
+namespace gbe
{
/* return platform name */
std::string getPlatformName() {
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
-namespace pf
+namespace gbe
{
/* get the full path to the running executable */
std::string getExecutableFileName() {
#include <stdio.h>
#include <unistd.h>
-namespace pf
+namespace gbe
{
/* get the full path to the running executable */
std::string getExecutableFileName() {
#include <mach-o/dyld.h>
-namespace pf
+namespace gbe
{
/* get the full path to the running executable */
std::string getExecutableFileName()
#include <unistd.h>
-namespace pf
+namespace gbe
{
/* return the number of logical threads of the system */
int getNumberOfLogicalThreads() {
* Author: Benjamin Segovia <benjamin.segovia@intel.com>
*/
-#ifndef __PF_SYSINFO_H__
-#define __PF_SYSINFO_H__
+#ifndef __GBE_SYSINFO_HPP__
+#define __GBE_SYSINFO_HPP__
#include "sys/platform.hpp"
#include <string>
-namespace pf
+namespace gbe
{
/*! get the full path to the running executable */
std::string getExecutableFileName();
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
-namespace pf
+namespace gbe
{
/*! creates a hardware thread running on specific core */
thread_t createThread(thread_func f, void* arg, size_t stack_size, int affinity)
////////////////////////////////////////////////////////////////////////////////
#ifdef __LINUX__
-namespace pf
+namespace gbe
{
/*! set affinity of the calling thread */
void setAffinity(int affinity)
#include <mach/thread_policy.h>
#include <mach/mach_init.h>
-namespace pf
+namespace gbe
{
/*! set affinity of the calling thread */
void setAffinity(int affinity)
#include <pthread.h>
#include <sched.h>
-namespace pf
+namespace gbe
{
struct ThreadStartupData {
int affinity;
static void* threadStartup(ThreadStartupData* parg)
{
- ThreadStartupData arg = *parg; PF_DELETE(parg); parg = NULL;
+ ThreadStartupData arg = *parg; GBE_DELETE(parg); parg = NULL;
setAffinity(arg.affinity);
arg.f(arg.arg);
return NULL;
pthread_attr_init(&attr);
if (stack_size > 0) pthread_attr_setstacksize (&attr, stack_size);
- pthread_t* tid = PF_NEW(pthread_t);
- ThreadStartupData* startup = PF_NEW(ThreadStartupData);
+ pthread_t* tid = GBE_NEW(pthread_t);
+ ThreadStartupData* startup = GBE_NEW(ThreadStartupData);
startup->f = f;
startup->arg = arg;
startup->affinity = affinity;
void join(thread_t tid) {
if (pthread_join(*(pthread_t*)tid, NULL) != 0)
FATAL("pthread_join error");
- PF_DELETE((pthread_t*)tid);
+ GBE_DELETE((pthread_t*)tid);
}
void destroyThread(thread_t tid) {
pthread_cancel(*(pthread_t*)tid);
- PF_DELETE((pthread_t*)tid);
+ GBE_DELETE((pthread_t*)tid);
}
tls_t createTls() {
- pthread_key_t* key = PF_NEW(pthread_key_t);
+ pthread_key_t* key = GBE_NEW(pthread_key_t);
if (pthread_key_create(key,NULL) != 0)
FATAL("pthread_key_create error");
return tls_t(key);
void destroyTls(tls_t tls) {
if (pthread_key_delete(*(pthread_key_t*)tls) != 0)
FATAL("pthread_key_delete error");
- PF_DELETE((pthread_key_t*)tls);
+ GBE_DELETE((pthread_key_t*)tls);
}
}
#endif
* Author: Benjamin Segovia <benjamin.segovia@intel.com>
*/
-#ifndef __PF_THREAD_HPP__
-#define __PF_THREAD_HPP__
+#ifndef __GBE_THREAD_HPP__
+#define __GBE_THREAD_HPP__
#include "sys/platform.hpp"
-namespace pf
+namespace gbe
{
/*! Type for thread */
typedef struct opaque_thread_t* thread_t;
void destroyTls(tls_t tls);
}
-#endif /* __PF_THREAD_HPP__ */
+#endif /* __GBE_THREAD_HPP__ */
* Author: Benjamin Segovia <benjamin.segovia@intel.com>
*/
-#ifndef __PF_VECTOR_HPP__
-#define __PF_VECTOR_HPP__
+#ifndef __GBE_VECTOR_HPP__
+#define __GBE_VECTOR_HPP__
#include "sys/platform.hpp"
#include <vector>
-namespace pf
+namespace gbe
{
/*! Add bound checks to the standard vector class and use the internal
* allocator
parent_type(first, last, a) {}
/*! Get element at position index (with a bound check) */
T &operator[] (size_t index) {
- PF_ASSERT(index < this->size());
+ GBE_ASSERT(index < this->size());
return parent_type::operator[] (index);
}
/*! Get element at position index (with a bound check) */
const T &operator[] (size_t index) const {
- PF_ASSERT(index < this->size());
+ GBE_ASSERT(index < this->size());
return parent_type::operator[] (index);
}
- PF_CLASS(vector);
+ GBE_CLASS(vector);
};
-} /* namespace pf */
+} /* namespace gbe */
-#endif /* __PF_VECTOR_HPP__ */
+#endif /* __GBE_VECTOR_HPP__ */
* Author: Benjamin Segovia <benjamin.segovia@intel.com>
*/
-#ifndef __PF_UTEST_HPP__
-#define __PF_UTEST_HPP__
+#ifndef __GBE_UTEST_HPP__
+#define __GBE_UTEST_HPP__
#include <vector>
/*! Register a new unit test */
#define UTEST_REGISTER(FN) static const pf::UTest __##NAME##__(FN, #FN);
-#endif /* __PF_UTEST_HPP__ */
+#endif /* __GBE_UTEST_HPP__ */
WinOpen(640, 480);
ScriptSystem *scriptSystem = LuaScriptSystemCreate();
CommandSystemStart(*scriptSystem);
- UTestConsoleDisplay *display = PF_NEW(UTestConsoleDisplay);
+ UTestConsoleDisplay *display = GBE_NEW(UTestConsoleDisplay);
Console *console = ConsoleNew(*scriptSystem, *display);
console->addCompletion("while");
console->addCompletion("whilewhile");
for (;;) {
- Ref<InputControl> input = PF_NEW(InputControl);
+ Ref<InputControl> input = GBE_NEW(InputControl);
input->processEvents();
- if (input->getKey(PF_KEY_ASCII_ESC))
+ if (input->getKey(GBE_KEY_ASCII_ESC))
break;
console->update(*input);
WinSwapBuffers();
}
CommandSystemEnd();
- PF_DELETE(console);
- PF_DELETE(scriptSystem);
- PF_DELETE(display);
+ GBE_DELETE(console);
+ GBE_DELETE(scriptSystem);
+ GBE_DELETE(display);
WinClose();
}
const FileName path(std::string(defaultPath[i]) + fontName);
if (font.load(path)) break;
}
- PF_ASSERT(i < defaultPathNum);
+ GBE_ASSERT(i < defaultPathNum);
}
UTEST_REGISTER(utest_font);
#define _RUN_SCRIPT(STR, RUN_MODE) do {\
ScriptStatus status;\
scriptSystem->RUN_MODE(STR, status);\
- if (!status.success) PF_ERROR(status.msg);\
+ if (!status.success) GBE_ERROR(status.msg);\
} while (0)
#define RUN(STR) _RUN_SCRIPT(STR,run)
#define RUN_NON_PROTECTED(STR) _RUN_SCRIPT(STR,runNonProtected)
RUN_NON_PROTECTED("print(pf.cv.coucou)");
RUN("cv.player0 = \"hop\"");
RUN_NON_PROTECTED("print(pf.cv.player0)");
- if (coucou() == 1) PF_MSG("coucou is equal to 1");
+ if (coucou() == 1) GBE_MSG("coucou is equal to 1");
CommandSystemEnd();
- PF_DELETE(scriptSystem);
+ GBE_DELETE(scriptSystem);
}
UTEST_REGISTER(utest_lua)
//static const FileName objName("sponza.obj");
static RTTriangle *ObjComputeTriangle(const Obj &obj) {
- RTTriangle *tris = PF_NEW_ARRAY(RTTriangle, obj.triNum);
+ RTTriangle *tris = GBE_NEW_ARRAY(RTTriangle, obj.triNum);
for (size_t i = 0; i < obj.triNum; ++i) {
const vec3f &v0 = obj.vert[obj.tri[i].v[0]].p;
const vec3f &v1 = obj.vert[obj.tri[i].v[1]].p;
static void rayTrace(int w, int h, const uint32 *c) {
FPSCamera fpsCam;
const RTCamera cam(fpsCam.org, fpsCam.up, fpsCam.view, fpsCam.fov, fpsCam.ratio);
- uint32 *rgba = PF_NEW_ARRAY(uint32, w * h);
+ uint32 *rgba = GBE_NEW_ARRAY(uint32, w * h);
std::memset(rgba, 0, sizeof(uint32) * w * h);
- PF_COMPILER_READ_WRITE_BARRIER;
+ GBE_COMPILER_READ_WRITE_BARRIER;
const double t = getSeconds();
- Task *rayTask = PF_NEW(TaskRayTrace<singleRay>, *intersector,
+ Task *rayTask = GBE_NEW(TaskRayTrace<singleRay>, *intersector,
cam, c, rgba, w, h/RayPacket::height);
- Task *returnToMain = PF_NEW(TaskInterruptMain);
+ Task *returnToMain = GBE_NEW(TaskInterruptMain);
rayTask->starts(returnToMain);
rayTask->scheduled();
returnToMain->scheduled();
TaskingSystemEnter();
const double dt = getSeconds() - t;
- PF_MSG_V(dt * 1000. << " msec - " << CAMW * CAMH / dt << " rays/s");
+ GBE_MSG_V(dt * 1000. << " msec - " << CAMW * CAMH / dt << " rays/s");
if (singleRay)
stbi_write_bmp("single.bmp", w, h, 4, rgba);
else
stbi_write_bmp("packet.bmp", w, h, 4, rgba);
- PF_DELETE_ARRAY(rgba);
+ GBE_DELETE_ARRAY(rgba);
}
static void RTStart(void)
size_t path = 0;
for (path = 0; path < defaultPathNum; ++path)
if (obj.load(FileName(defaultPath[path]) + objName)) {
- PF_MSG_V("Obj: " << objName << " loaded from " << defaultPath[path]);
+ GBE_MSG_V("Obj: " << objName << " loaded from " << defaultPath[path]);
break;
}
if (path == defaultPathNum)
- PF_WARNING_V("Obj: " << objName << " not found");
+ GBE_WARNING_V("Obj: " << objName << " not found");
// Build the BVH
RTTriangle *tris = ObjComputeTriangle(obj);
- Ref<BVH2<RTTriangle>> bvh = PF_NEW(BVH2<RTTriangle>);
+ Ref<BVH2<RTTriangle>> bvh = GBE_NEW(BVH2<RTTriangle>);
buildBVH2(tris, obj.triNum, *bvh);
- PF_DELETE_ARRAY(tris);
+ GBE_DELETE_ARRAY(tris);
// Now we have an intersector on the triangle soup
- intersector = PF_NEW(BVH2Traverser<RTTriangle>, bvh);
+ intersector = GBE_NEW(BVH2Traverser<RTTriangle>, bvh);
// Compute some triangle color
- uint32 *c = PF_NEW_ARRAY(uint32, bvh->primNum);
+ uint32 *c = GBE_NEW_ARRAY(uint32, bvh->primNum);
for (uint32 i = 0; i < bvh->primNum; ++i) {
c[i] = rand();
c[i] |= 0xff000000;
}
// Ray trace now
- PF_MSG_V("Packet ray tracing");
+ GBE_MSG_V("Packet ray tracing");
for (int i = 0; i < 16; ++i) rayTrace<false>(CAMW, CAMH, c);
- PF_MSG_V("Single ray tracing");
+ GBE_MSG_V("Single ray tracing");
for (int i = 0; i < 16; ++i) rayTrace<true>(CAMW, CAMH, c);
- PF_DELETE_ARRAY(c);
+ GBE_DELETE_ARRAY(c);
}
static void RTEnd(void) { intersector = NULL; }
};
START_UTEST(TestDummy)
- Task *done = PF_NEW(TaskDone);
- Task *nothing = PF_NEW(TaskDummy);
+ Task *done = GBE_NEW(TaskDone);
+ Task *nothing = GBE_NEW(TaskDummy);
nothing->starts(done);
done->scheduled();
nothing->scheduled();
START_UTEST(TestTaskSet)
const size_t elemNum = 1 << 20;
- uint32 *array = PF_NEW_ARRAY(uint32, elemNum);
+ uint32 *array = GBE_NEW_ARRAY(uint32, elemNum);
for (size_t i = 0; i < elemNum; ++i) array[i] = 0;
double t = getSeconds();
- Task *done = PF_NEW(TaskDone);
- Task *taskSet = PF_NEW(TaskSetSimple, elemNum, array);
+ Task *done = GBE_NEW(TaskDone);
+ Task *taskSet = GBE_NEW(TaskSetSimple, elemNum, array);
taskSet->starts(done);
done->scheduled();
taskSet->scheduled();
std::cout << t * 1000. << " ms" << std::endl;
for (size_t i = 0; i < elemNum; ++i)
FATAL_IF(array[i] == 0, "TestTaskSet failed");
- PF_DELETE_ARRAY(array);
+ GBE_DELETE_ARRAY(array);
END_UTEST(TestTaskSet)
///////////////////////////////////////////////////////////////////////////////
if (this->lvl == maxLevel)
this->value++;
else {
- Task *left = PF_NEW(TaskNode, this->value, this->lvl+1, this->root);
- Task *right = PF_NEW(TaskNode, this->value, this->lvl+1, this->root);
+ Task *left = GBE_NEW(TaskNode, this->value, this->lvl+1, this->root);
+ Task *right = GBE_NEW(TaskNode, this->value, this->lvl+1, this->root);
left->ends(this->root);
right->ends(this->root);
left->scheduled();
this->value++;
return NULL;
} else {
- Task *left = PF_NEW(TaskNode, this->value, this->lvl+1, this->root);
- Task *right = PF_NEW(TaskNode, this->value, this->lvl+1, this->root);
+ Task *left = GBE_NEW(TaskNode, this->value, this->lvl+1, this->root);
+ Task *right = GBE_NEW(TaskNode, this->value, this->lvl+1, this->root);
left->ends(this->root);
right->ends(this->root);
left->scheduled();
if (this->lvl == maxLevel)
this->value++;
else {
- Task *left = PF_NEW(TaskCascadeNode, this->value, this->lvl+1);
- Task *right = PF_NEW(TaskCascadeNode, this->value, this->lvl+1);
+ Task *left = GBE_NEW(TaskCascadeNode, this->value, this->lvl+1);
+ Task *right = GBE_NEW(TaskCascadeNode, this->value, this->lvl+1);
left->ends(this);
right->ends(this);
left->scheduled();
this->value++;
return NULL;
} else {
- Task *left = PF_NEW(TaskCascadeNode, this->value, this->lvl+1);
- Task *right = PF_NEW(TaskCascadeNode, this->value, this->lvl+1);
+ Task *left = GBE_NEW(TaskCascadeNode, this->value, this->lvl+1);
+ Task *right = GBE_NEW(TaskCascadeNode, this->value, this->lvl+1);
left->ends(this);
right->ends(this);
left->scheduled();
Atomic value(0u);
std::cout << "nodeNum = " << (2 << maxLevel) - 1 << std::endl;
double t = getSeconds();
- Task *done = PF_NEW(TaskDone);
- Task *root = PF_NEW(NodeType, value, 0);
+ Task *done = GBE_NEW(TaskDone);
+ Task *root = GBE_NEW(NodeType, value, 0);
root->starts(done);
done->scheduled();
root->scheduled();
Task *tasks[allocNum];
for (int j = 0; j < iterNum; ++j) {
const int taskNum = rand() % allocNum;
- for (int i = 0; i < taskNum; ++i) tasks[i] = PF_NEW(TaskDummy);
- for (int i = 0; i < taskNum; ++i) PF_DELETE(tasks[i]);
+ for (int i = 0; i < taskNum; ++i) tasks[i] = GBE_NEW(TaskDummy);
+ for (int i = 0; i < taskNum; ++i) GBE_DELETE(tasks[i]);
}
}
START_UTEST(TestAllocator)
- Task *done = PF_NEW(TaskDone);
- Task *allocate = PF_NEW(TaskAllocate, 1 << 10);
+ Task *done = GBE_NEW(TaskDone);
+ Task *allocate = GBE_NEW(TaskAllocate, 1 << 10);
double t = getSeconds();
allocate->starts(done);
done->scheduled();
virtual Task* run(void) {
if (lvl == 0)
for (size_t i = 0; i < taskToSpawn; ++i) {
- Task *task = PF_NEW(TaskFull, "TaskFullLvl1", counter, 1);
+ Task *task = GBE_NEW(TaskFull, "TaskFullLvl1", counter, 1);
task->ends(this);
task->scheduled();
}
START_UTEST(TestFullQueue)
Atomic counter(0u);
double t = getSeconds();
- Task *done = PF_NEW(TaskDone);
+ Task *done = GBE_NEW(TaskDone);
for (size_t i = 0; i < 64; ++i) {
- Task *task = PF_NEW(TaskFull, "TaskFull", counter);
+ Task *task = GBE_NEW(TaskFull, "TaskFull", counter);
task->starts(done);
task->scheduled();
}
else {
const uint32 threadNum = TaskingSystemGetThreadNum();
for (uint32 i = 0; i < taskToSpawn; ++i) {
- Task *task = PF_NEW(TaskAffinity, done.ptr, counter, 1);
+ Task *task = GBE_NEW(TaskAffinity, done.ptr, counter, 1);
task->setAffinity(i % threadNum);
task->ends(this);
task->scheduled();
for (int i = 0; i < 8; ++i) {
Atomic counter(0u);
double t = getSeconds();
- Ref<Task> done = PF_NEW(TaskDone);
+ Ref<Task> done = GBE_NEW(TaskDone);
for (size_t i = 0; i < batchNum; ++i) {
- Task *task = PF_NEW(TaskAffinity, done.ptr, counter);
+ Task *task = GBE_NEW(TaskAffinity, done.ptr, counter);
task->starts(done.ptr);
task->scheduled();
}
Task *TaskFiboSpawn::run(void) {
if (rank > 1) {
- TaskFiboSpawn *left = PF_NEW(TaskFiboSpawn, rank-1, &this->sumLeft);
- TaskFiboSpawn *right = PF_NEW(TaskFiboSpawn, rank-2, &this->sumRight);
- FiboSumTask *sum = PF_NEW(FiboSumTask, this);
+ TaskFiboSpawn *left = GBE_NEW(TaskFiboSpawn, rank-1, &this->sumLeft);
+ TaskFiboSpawn *right = GBE_NEW(TaskFiboSpawn, rank-2, &this->sumRight);
+ FiboSumTask *sum = GBE_NEW(FiboSumTask, this);
left->starts(sum);
right->starts(sum);
sum->ends(this);
uint64 sum;
double t = getSeconds();
fiboNum = 0u;
- Ref<TaskFiboSpawn> fibo = PF_NEW(TaskFiboSpawn, rank, &sum);
- Task *done = PF_NEW(TaskDone);
+ Ref<TaskFiboSpawn> fibo = GBE_NEW(TaskFiboSpawn, rank, &sum);
+ Task *done = GBE_NEW(TaskDone);
fibo->starts(done);
fibo->scheduled();
done->scheduled();
static const uint32 triggeredTaskToSpawn = 512;
static const uint32 valueToSetNum = multiTaskToSpawn;
- int32 *toSet = PF_NEW_ARRAY(int32, valueToSetNum);
+ int32 *toSet = GBE_NEW_ARRAY(int32, valueToSetNum);
Atomic32 dst(0);
- Task *doneTask = PF_NEW(TaskDone);
+ Task *doneTask = GBE_NEW(TaskDone);
for (uint32 i = 0; i < valueToSetNum; ++i) toSet[i] = 0;
for (uint32 i = 0; i < multiTaskToSpawn; ++i) {
- Ref<TaskMultiTrigger> task = PF_NEW(TaskMultiTrigger, toSet + i);
+ Ref<TaskMultiTrigger> task = GBE_NEW(TaskMultiTrigger, toSet + i);
for (uint32 j = 0; j < triggeredTaskToSpawn; ++j) {
- Ref<Task> triggered = PF_NEW(TaskTriggered, toSet + i, dst);
- Ref<Task> dummy = PF_NEW(TaskDummy);
+ Ref<Task> triggered = GBE_NEW(TaskTriggered, toSet + i, dst);
+ Ref<Task> dummy = GBE_NEW(TaskDummy);
task->multiStarts(dummy);
dummy->starts(triggered);
triggered->starts(doneTask);
}
doneTask->scheduled();
TaskingSystemEnter();
- PF_DELETE_ARRAY(toSet);
+ GBE_DELETE_ARRAY(toSet);
const uint32 result = dst;
std::cout << "result: " << result << std::endl;
FATAL_IF(result != multiTaskToSpawn * triggeredTaskToSpawn,
static const uint32 triggeredTaskToSpawn = 512;
static const uint32 valueToSetNum = multiTaskToSpawn;
- int32 *toSet = PF_NEW_ARRAY(int32, valueToSetNum);
+ int32 *toSet = GBE_NEW_ARRAY(int32, valueToSetNum);
Atomic32 dst(0);
- Task *doneTask = PF_NEW(TaskDone);
+ Task *doneTask = GBE_NEW(TaskDone);
for (uint32 i = 0; i < valueToSetNum; ++i) toSet[i] = 0;
for (uint32 i = 0; i < multiTaskToSpawn; ++i) {
- Ref<TaskMultiTrigger> task = PF_NEW(TaskMultiTrigger, toSet + i);
+ Ref<TaskMultiTrigger> task = GBE_NEW(TaskMultiTrigger, toSet + i);
for (uint32 j = 0; j < triggeredTaskToSpawn; ++j) {
- Ref<Task> triggered = PF_NEW(TaskTriggered, toSet + i, dst);
+ Ref<Task> triggered = GBE_NEW(TaskTriggered, toSet + i, dst);
task->multiStarts(triggered);
triggered->starts(doneTask);
triggered->scheduled();
}
doneTask->scheduled();
TaskingSystemEnter();
- PF_DELETE_ARRAY(toSet);
+ GBE_DELETE_ARRAY(toSet);
const uint32 result = dst;
std::cout << "result: " << result << std::endl;
FATAL_IF(result != multiTaskToSpawn * triggeredTaskToSpawn,
static const uint32 repeatNum = 8;
Random rand;
for (uint32 i = 0; i < repeatNum; ++i) {
- int32 *toSet = PF_NEW_ARRAY(int32, valueToSetNum);
+ int32 *toSet = GBE_NEW_ARRAY(int32, valueToSetNum);
Atomic32 dst(0);
- Ref<Task> doneTask = PF_NEW(TaskDone);
+ Ref<Task> doneTask = GBE_NEW(TaskDone);
for (uint32 i = 0; i < valueToSetNum; ++i) toSet[i] = 0;
for (uint32 i = 0; i < multiTaskToSpawn; ++i) {
- Ref<TaskMultiTrigger> task = PF_NEW(TaskMultiTrigger, toSet + i);
+ Ref<TaskMultiTrigger> task = GBE_NEW(TaskMultiTrigger, toSet + i);
bool isScheduled = false;
for (uint32 j = 0; j < triggeredTaskToSpawn; ++j) {
- Ref<Task> triggered = PF_NEW(TaskTriggered, toSet + i, dst);
+ Ref<Task> triggered = GBE_NEW(TaskTriggered, toSet + i, dst);
task->multiStarts(triggered);
triggered->starts(doneTask);
triggered->scheduled();
}
doneTask->scheduled();
TaskingSystemEnter();
- PF_DELETE_ARRAY(toSet);
+ GBE_DELETE_ARRAY(toSet);
const uint32 result = dst;
std::cout << "result: " << result << std::endl;
FATAL_IF(result != multiTaskToSpawn * triggeredTaskToSpawn,
{
static const uint32 taskNum = 1024;
int32 shared = 0;
- Ref<Task> doneTask = PF_NEW(TaskDone);
+ Ref<Task> doneTask = GBE_NEW(TaskDone);
for (uint32 i = 0; i < taskNum; ++i) {
- Task *updateTask = PF_NEW(TaskLockUnlock, &shared);
+ Task *updateTask = GBE_NEW(TaskLockUnlock, &shared);
updateTask->starts(doneTask);
updateTask->scheduled();
}
///////////////////////////////////////////////////////////////////////////////
// Test tasking profiler
///////////////////////////////////////////////////////////////////////////////
-#if PF_TASK_PROFILER
+#if GBE_TASK_PROFILER
class UTestProfiler : public TaskProfiler
{
public:
START_UTEST(TestProfiler)
{
- UTestProfiler *profiler = PF_NEW(UTestProfiler);
+ UTestProfiler *profiler = GBE_NEW(UTestProfiler);
TaskingSystemSetProfiler(profiler);
TestFibo();
TestTaskSet();
OUTPUT_FIELD(endNum);
#undef OUTPUT_FIELD
TaskingSystemSetProfiler(NULL);
- PF_DELETE(profiler);
+ GBE_DELETE(profiler);
}
END_UTEST(TestProfiler)
-#endif /* PF_TASK_PROFILER */
+#endif /* GBE_TASK_PROFILER */
/*! Run all tasking tests */
void utest_tasking(void)