-project (PF)
+project (GBE)
cmake_minimum_required (VERSION 2.6.0)
-set (PF_CMAKE_DIR "${PF_SOURCE_DIR}/cmake")
-set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PF_CMAKE_DIR}")
+set (GBE_CMAKE_DIR "${GBE_SOURCE_DIR}/cmake")
+set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${GBE_CMAKE_DIR}")
##############################################################
# Compilation directives
##############################################################
-set (PF_DEBUG_MEMORY false CACHE bool "Activate the memory debugger")
-set (PF_USE_BLOB false CACHE bool "Compile everything from one big file")
-set (PF_VERBOSE_VECTORIZER false CACHE bool "Output vectorizer diagnostic (GCC only)")
+set (GBE_DEBUG_MEMORY false CACHE bool "Activate the memory debugger")
+set (GBE_USE_BLOB false CACHE bool "Compile everything from one big file")
+set (GBE_VERBOSE_VECTORIZER false CACHE bool "Output vectorizer diagnostic (GCC only)")
##############################################################
# Compiler
set (DEF "-D")
endif (WIN32)
-if (PF_DEBUG_MEMORY)
- set (PF_DEBUG_MEMORY_FLAG "${DEF}PF_DEBUG_MEMORY=1")
-else (PF_DEBUG_MEMORY)
- set (PF_DEBUG_MEMORY_FLAG "${DEF}PF_DEBUG_MEMORY=0")
-endif (PF_DEBUG_MEMORY)
+if (GBE_DEBUG_MEMORY)
+ set (GBE_DEBUG_MEMORY_FLAG "${DEF}GBE_DEBUG_MEMORY=1")
+else (GBE_DEBUG_MEMORY)
+ set (GBE_DEBUG_MEMORY_FLAG "${DEF}GBE_DEBUG_MEMORY=0")
+endif (GBE_DEBUG_MEMORY)
## Linux compilation
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
set (VISIBILITY_FLAG "-fvisibility=hidden")
if (COMPILER STREQUAL "GCC")
- set (CMAKE_CXX_FLAGS "-Wstrict-aliasing=2 -Wno-invalid-offsetof -fstrict-aliasing -msse2 -ffast-math -fPIC -Wall -fno-rtti -std=c++0x")
- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PF_DEBUG_MEMORY_FLAG}")
+ set (CMAKE_CXX_FLAGS "-Wstrict-aliasing=2 -Wno-invalid-offsetof -fno-strict-aliasing -msse2 -ffast-math -fPIC -Wall -fno-rtti -std=c++0x")
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GBE_DEBUG_MEMORY_FLAG}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${VISIBILITY_FLAG} -Wl,-E")
set (CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG -ftree-vectorize")
- if (PF_VERBOSE_VECTORIZER)
+ if (GBE_VERBOSE_VECTORIZER)
set (CMAKE_CXX_FLAGS "-ftree-vectorizer-verbose=2")
- endif (PF_VERBOSE_VECTORIZER)
+ endif (GBE_VERBOSE_VECTORIZER)
elseif (COMPILER STREQUAL "CLANG")
set (CMAKE_C_COMPILER "clang")
set (CMAKE_C_FLAGS "-Wall -std=c99")
set (CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG")
set (CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g")
set (CMAKE_CXX_COMPILER "clang++")
- set (CMAKE_CXX_FLAGS "-fstrict-aliasing -msse2 -ffast-math -fPIC -Wall -Wno-format-security -Wno-invalid-offsetof -std=c++0x")
- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PF_DEBUG_MEMORY_FLAG}")
+ set (CMAKE_CXX_FLAGS "-fno-strict-aliasing -msse2 -ffast-math -fPIC -Wall -Wno-format-security -Wno-invalid-offsetof -std=c++0x")
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GBE_DEBUG_MEMORY_FLAG}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${VISIBILITY_FLAG}")
set (CMAKE_CXX_FLAGS_DEBUG "-g")
set (CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG")
elseif (COMPILER STREQUAL "ICC")
set (CMAKE_CXX_COMPILER "icpc")
set (CMAKE_C_COMPILER "icc")
- set (CMAKE_CXX_FLAGS "-std=c++0x -wd2928 -Wall -fPIC -fstrict-aliasing -fp-model fast -xSSE2")
- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PF_DEBUG_MEMORY_FLAG}")
+ set (CMAKE_CXX_FLAGS "-std=c++0x -wd2928 -Wall -fPIC -fno-strict-aliasing -fp-model fast -xSSE2")
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GBE_DEBUG_MEMORY_FLAG}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${VISIBILITY_FLAG} -Wl,-E")
set (CMAKE_CXX_FLAGS_DEBUG "-g -O0")
set (CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG -O2")
## Windows compilation
elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows")
if (MINGW)
- if (PF_VERBOSE_VECTORIZER)
+ if (GBE_VERBOSE_VECTORIZER)
set (CMAKE_CXX_FLAGS "-ftree-vectorizer-verbose=2")
- endif (PF_VERBOSE_VECTORIZER)
- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PF_DEBUG_MEMORY_FLAG} -Wno-invalid-offsetof -fstrict-aliasing -msse2 -ffast-math -Wall -fno-rtti -std=c++0x")
+ endif (GBE_VERBOSE_VECTORIZER)
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GBE_DEBUG_MEMORY_FLAG} -Wno-invalid-offsetof -fstrict-aliasing -msse2 -ffast-math -Wall -fno-rtti -std=c++0x")
set (CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
else (MINGW)
- set (COMMON_FLAGS "${PF_DEBUG_MEMORY_FLAG} /arch:SSE2 /D_CRT_SECURE_NO_WARNINGS /DNOMINMAX /GR- /GS- /W3 /wd4275")
+ set (COMMON_FLAGS "${GBE_DEBUG_MEMORY_FLAG} /arch:SSE2 /D_CRT_SECURE_NO_WARNINGS /DNOMINMAX /GR- /GS- /W3 /wd4275")
set (CMAKE_CXX_FLAGS ${COMMON_FLAGS})
set (CMAKE_C_FLAGS ${COMMON_FLAGS})
endif (MINGW)
sys/filename.hpp
sys/library.cpp
sys/library.hpp
- sys/thread.cpp
- sys/thread.hpp
sys/alloc.cpp
sys/alloc.hpp
sys/sysinfo.cpp
sys/condition.hpp
sys/platform.cpp
sys/platform.hpp
- sys/logging.cpp
- sys/logging.hpp
- sys/default_path.cpp
- sys/default_path.hpp
ir/ir_context.cpp
ir/ir_context.hpp
ir/ir_unit.cpp
void ConstantSet::append(const char *data,
const std::string &name,
- uint32 size,
- uint32 alignment)
+ uint32_t size,
+ uint32_t alignment)
{
- const uint32 offset = ALIGN(this->data.size(), alignment);
- const uint32 padding = offset - this->data.size();
+ const uint32_t offset = ALIGN(this->data.size(), alignment);
+ const uint32_t padding = offset - this->data.size();
const Constant constant(name, size, alignment, offset);
constants.push_back(constant);
- for (uint32 i = 0; i < padding; ++i) this->data.push_back(0);
- for (uint32 i = 0; i < size; ++i) this->data.push_back(data[i]);
+ for (uint32_t i = 0; i < padding; ++i) this->data.push_back(0);
+ for (uint32_t i = 0; i < size; ++i) this->data.push_back(data[i]);
}
} /* namespace gbe */
{
public:
/*! Build a constant description */
- INLINE Constant(const std::string &name, uint32 size, uint32 alignment, uint32 offset) :
+ INLINE Constant(const std::string &name, uint32_t size, uint32_t alignment, uint32_t offset) :
name(name), size(size), alignment(alignment), offset(offset) {}
/*! Copy constructor */
INLINE Constant(const Constant &other) :
INLINE ~Constant(void) {}
private:
std::string name; //!< Optional name of the constant
- uint32 size; //!< Size of the constant
- uint32 alignment; //!< Alignment required for each constant
- uint32 offset; //!< Offset of the constant in the data segment
+ uint32_t size; //!< Size of the constant
+ uint32_t alignment; //!< Alignment required for each constant
+ uint32_t offset; //!< Offset of the constant in the data segment
};
/*! A constant set is a set of immutable data associated to a compilation
{
public:
/*! Append a new constant in the constant set */
- void append(const char*, const std::string&, uint32 size, uint32 alignment);
+ void append(const char*, const std::string&, uint32_t size, uint32_t alignment);
private:
vector<char> data; //!< The constant data serialized in one array
vector<Constant> constants;//!< Each constant description
namespace gbe
{
Context::Context(Unit &unit) : unit(unit), fn(NULL), bb(NULL) {}
+
void Context::startFunction(const std::string &name) {
Function *fn = unit.newFunction(name);
- if (UNLIKELY(fn == NULL))
- throw std::exception("Function " + name " already defined");
+ GBE_ASSERT(fn != NULL);
fnStack.push_back(fn);
}
} /* namespace gbe */
/*! Empty basic block */
BasicBlock(void);
/*! Return the number of instruction in the block */
- INLINE uint32 getInsnNum(void) { return insn.size(); }
+ INLINE uint32_t getInsnNum(void) { return insn.size(); }
private:
vector<Instruction> insn; //!< Sequence of instructions in the block
};
/*! Extract the register from the register file */
- INLINE Register getRegister(uint32 ID) const { return file.get(ID); }
+ INLINE Register getRegister(uint32_t ID) const { return file.get(ID); }
/*! Get the register index from the tuple vector */
- INLINE RegisterIndex getRegisterIndex(TupleIndex ID, uint32 which) const {
+ INLINE RegisterIndex getRegisterIndex(TupleIndex ID, uint32_t which) const {
return file.get(ID, which);
}
/*! Get the given value ie immediate from the function */
- INLINE Value getValue(uint32 ID) const {
+ INLINE Value getValue(uint32_t ID) const {
assert(ID < value.size());
return value[ID];
}
/*! Use this when there is no source */
struct NoSrcPolicy {
- INLINE uint32 getSrcNum(void) const { return 0; }
- INLINE RegisterIndex getSrcIndex(const Function &fn, uint32 ID) const {
+ INLINE uint32_t getSrcNum(void) const { return 0; }
+ INLINE RegisterIndex getSrcIndex(const Function &fn, uint32_t ID) const {
NOT_IMPLEMENTED;
return 0;
}
/*! Use this when there is no destination */
struct NoDstPolicy {
- INLINE uint32 getDstNum(void) const { return 0; }
- INLINE RegisterIndex getDstIndex(const Function &fn, uint32 ID) const {
+ INLINE uint32_t getDstNum(void) const { return 0; }
+ INLINE RegisterIndex getDstIndex(const Function &fn, uint32_t ID) const {
NOT_IMPLEMENTED;
return 0;
}
};
/*! All unary and binary arithmetic instructions */
- template <uint32 srcNum> // 1 or 2
+ template <uint32_t srcNum> // 1 or 2
class ALIGNED_INSTRUCTION NaryInstruction {
public:
- INLINE uint32 getSrcNum(void) const { return srcNum; }
- INLINE uint32 getDstNum(void) const { return 1; }
- INLINE RegisterIndex getDstIndex(const Function &fn, uint32 ID) const {
+ INLINE uint32_t getSrcNum(void) const { return srcNum; }
+ INLINE uint32_t getDstNum(void) const { return 1; }
+ INLINE RegisterIndex getDstIndex(const Function &fn, uint32_t ID) const {
assert(ID == 0);
return dst;
}
- INLINE RegisterIndex getSrcIndex(const Function &fn, uint32 ID) const {
+ INLINE RegisterIndex getSrcIndex(const Function &fn, uint32_t ID) const {
assert(ID <= srcNum);
return src[ID];
}
INLINE Type getType(void) const { return this->type; }
- Opcode opcode; //!< Instruction opcode
- Type type; //!< Type of the instruction
+ Opcode opcode; //!< Instruction opcode
+ Type type; //!< Type of the instruction
RegisterIndex dst; //!< Index of the register in the register file
RegisterIndex src[srcNum];//!< Indices of the sources
};
this->dst = dst;
this->src = src;
}
- INLINE uint32 getSrcNum(void) const { return 3; }
- INLINE uint32 getDstNum(void) const { return 1; }
- INLINE RegisterIndex getDstIndex(const Function &fn, uint32 ID) const {
+ INLINE uint32_t getSrcNum(void) const { return 3; }
+ INLINE uint32_t getDstNum(void) const { return 1; }
+ INLINE RegisterIndex getDstIndex(const Function &fn, uint32_t ID) const {
assert(ID == 0);
return dst;
}
- INLINE RegisterIndex getSrcIndex(const Function &fn, uint32 ID) const {
+ INLINE RegisterIndex getSrcIndex(const Function &fn, uint32_t ID) const {
assert(ID <= 3);
return fn.getRegisterIndex(src, ID);
}
}
INLINE Type getSrcType(void) const { return this->srcType; }
INLINE Type getDstType(void) const { return this->dstType; }
- INLINE uint32 getSrcNum(void) const { return 1; }
- INLINE uint32 getDstNum(void) const { return 1; }
- INLINE RegisterIndex getDstIndex(const Function &fn, uint32 ID) const {
+ INLINE uint32_t getSrcNum(void) const { return 1; }
+ INLINE uint32_t getDstNum(void) const { return 1; }
+ INLINE RegisterIndex getDstIndex(const Function &fn, uint32_t ID) const {
assert(ID == 0);
return dst;
}
- INLINE RegisterIndex getSrcIndex(const Function &fn, uint32 ID) const {
+ INLINE RegisterIndex getSrcIndex(const Function &fn, uint32_t ID) const {
assert(ID == 0);
return src;
}
this->labelIndex = labelIndex;
this->hasPredicate = false;
}
- INLINE uint32 getSrcNum(void) const { return hasPredicate ? 1 : 0; }
- INLINE RegisterIndex getSrcIndex(const Function &fn, uint32 ID) const {
+ INLINE uint32_t getSrcNum(void) const { return hasPredicate ? 1 : 0; }
+ INLINE RegisterIndex getSrcIndex(const Function &fn, uint32_t ID) const {
assert(ID == 0 && hasPredicate);
return predicate;
}
TupleIndex dstValues,
RegisterIndex offset,
MemorySpace memSpace,
- uint16 valueNum)
+ uint16_t valueNum)
{
this->opcode = OP_STORE;
this->type = type;
this->memSpace = memSpace;
this->valueNum = valueNum;
}
- INLINE RegisterIndex getSrcIndex(const Function &fn, uint32 ID) const {
+ INLINE RegisterIndex getSrcIndex(const Function &fn, uint32_t ID) const {
assert(ID == 0u);
return offset;
}
- INLINE uint32 getSrcNum(void) const { return 1; }
- INLINE RegisterIndex getDstIndex(const Function &fn, uint32 ID) const {
+ INLINE uint32_t getSrcNum(void) const { return 1; }
+ INLINE RegisterIndex getDstIndex(const Function &fn, uint32_t ID) const {
assert(ID < valueNum);
return fn.getRegisterIndex(values, ID);
}
- INLINE uint32 getDstNum(void) const { return valueNum; }
+ INLINE uint32_t getDstNum(void) const { return valueNum; }
INLINE Type getValueType(void) const { return type; }
- INLINE uint32 getValueNum(void) const { return valueNum; }
+ INLINE uint32_t getValueNum(void) const { return valueNum; }
INLINE MemorySpace getAddressSpace(void) const { return memSpace; }
Opcode opcode; //!< Opcode of the instruction
Type type; //!< Type to store
RegisterIndex offset; //!< First source is the offset where to store
TupleIndex values; //!< Values to load
MemorySpace memSpace; //!< Where to store
- uint16 valueNum; //!< Number of values to store
+ uint16_t valueNum; //!< Number of values to store
};
class ALIGNED_INSTRUCTION StoreInstruction : public NoDstPolicy {
RegisterIndex offset,
TupleIndex values,
MemorySpace memSpace,
- uint16 valueNum)
+ uint16_t valueNum)
{
this->opcode = OP_STORE;
this->type = type;
this->memSpace = memSpace;
this->valueNum = valueNum;
}
- INLINE RegisterIndex getSrcIndex(const Function &fn, uint32 ID) const {
+ INLINE RegisterIndex getSrcIndex(const Function &fn, uint32_t ID) const {
assert(ID < valueNum + 1u); // offset + values to store
if (ID == 0u)
return offset;
else
return fn.getRegisterIndex(values, ID - 1);
}
- INLINE uint32 getSrcNum(void) const { return valueNum + 1u; }
+ INLINE uint32_t getSrcNum(void) const { return valueNum + 1u; }
INLINE Type getValueType(void) const { return type; }
- INLINE uint32 getValueNum(void) const { return valueNum; }
+ INLINE uint32_t getValueNum(void) const { return valueNum; }
INLINE MemorySpace getAddressSpace(void) const { return memSpace; }
Opcode opcode; //!< Opcode of the instruction
Type type; //!< Type to store
RegisterIndex offset; //!< First source is the offset where to store
TupleIndex values; //!< Values to store
MemorySpace memSpace; //!< Where to store
- uint16 valueNum; //!< Number of values to store
+ uint16_t valueNum; //!< Number of values to store
};
class ALIGNED_INSTRUCTION TextureInstruction :
INLINE Value getValue(const Function &fn) const {
return fn.getValue(valueIndex);
}
- INLINE uint32 getDstNum(void) const{ return 1; }
- INLINE RegisterIndex getDstIndex(const Function &fn, uint32 ID) const {
+ INLINE uint32_t getDstNum(void) const{ return 1; }
+ INLINE RegisterIndex getDstIndex(const Function &fn, uint32_t ID) const {
assert(ID == 0);
return dst;
}
enum { value = 1 };
};
- Register Instruction::getDst(const Function &fn, uint32 ID) const {
+ Register Instruction::getDst(const Function &fn, uint32_t ID) const {
return fn.getRegister(this->getDstIndex(fn, ID));
}
- Register Instruction::getSrc(const Function &fn, uint32 ID) const {
+ Register Instruction::getSrc(const Function &fn, uint32_t ID) const {
return fn.getRegister(this->getSrcIndex(fn, ID));
}
}
#define CALL getSrcNum()
-START_FUNCTION(Instruction, uint32, getSrcNum(void))
+START_FUNCTION(Instruction, uint32_t, getSrcNum(void))
#include "ir_instruction.hxx"
-END_FUNCTION(Instruction, uint32)
+END_FUNCTION(Instruction, uint32_t)
#undef CALL
#define CALL getDstNum()
-START_FUNCTION(Instruction, uint32, getDstNum(void))
+START_FUNCTION(Instruction, uint32_t, getDstNum(void))
#include "ir_instruction.hxx"
-END_FUNCTION(Instruction, uint32)
+END_FUNCTION(Instruction, uint32_t)
#undef CALL
#define CALL getDstIndex(fn, ID)
-START_FUNCTION(Instruction, RegisterIndex, getDstIndex(const Function &fn, uint32 ID))
+START_FUNCTION(Instruction, RegisterIndex, getDstIndex(const Function &fn, uint32_t ID))
#include "ir_instruction.hxx"
END_FUNCTION(Instruction, RegisterIndex)
#undef CALL
#define CALL getSrcIndex(fn, ID)
-START_FUNCTION(Instruction, RegisterIndex, getSrcIndex(const Function &fn, uint32 ID))
+START_FUNCTION(Instruction, RegisterIndex, getSrcIndex(const Function &fn, uint32_t ID))
#include "ir_instruction.hxx"
END_FUNCTION(Instruction, RegisterIndex)
#undef CALL
DECL_MEM_FN(ConvertInstruction, Type, getSrcType(void), getSrcType())
DECL_MEM_FN(ConvertInstruction, Type, getDstType(void), getDstType())
DECL_MEM_FN(StoreInstruction, Type, getValueType(void), getValueType())
-DECL_MEM_FN(StoreInstruction, uint32, getValueNum(void), getValueNum())
+DECL_MEM_FN(StoreInstruction, uint32_t, getValueNum(void), getValueNum())
DECL_MEM_FN(StoreInstruction, MemorySpace, getAddressSpace(void), getAddressSpace())
DECL_MEM_FN(LoadInstruction, Type, getValueType(void), getValueType())
-DECL_MEM_FN(LoadInstruction, uint32, getValueNum(void), getValueNum())
+DECL_MEM_FN(LoadInstruction, uint32_t, getValueNum(void), getValueNum())
DECL_MEM_FN(LoadInstruction, MemorySpace, getAddressSpace(void), getAddressSpace())
DECL_MEM_FN(LoadImmInstruction, Value, getValue(const Function &fn), getValue(fn))
DECL_MEM_FN(LoadImmInstruction, Type, getType(void), getType())
TupleIndex tuple, \
RegisterIndex offset, \
MemorySpace space, \
- uint16 valueNum) \
+ uint16_t valueNum) \
{ \
- internal::CLASS insn(type, tuple, offset, space, valueNum); \
- return *reinterpret_cast<Instruction*>(&insn); \
+ const internal::CLASS insn(type, tuple, offset, space, valueNum); \
+ return *reinterpret_cast<const Instruction*>(&insn); \
}
DECL_EMIT_FUNCTION(load, LoadInstruction)
namespace gbe
{
/*! All opcodes */
- enum Opcode : uint8 {
+ enum Opcode : uint8_t {
#define DECL_INSN(INSN, FAMILY) OP_##INSN,
#include "ir_instruction.hxx"
#undef DECL_INSN
};
/*! Different memory spaces */
- enum MemorySpace : uint8 {
+ enum MemorySpace : uint8_t {
MEM_GLOBAL = 0, //!< Global memory (a la OCL)
MEM_LOCAL, //!< Local memory (thread group memory)
MEM_CONSTANT, //!< Immutable global memory
};
/*! A label is identified with an unsigned short */
- typedef uint16 LabelIndex;
+ typedef uint16_t LabelIndex;
/*! A value is stored in a per-function vector. This is the index to it */
- typedef uint16 ValueIndex;
+ typedef uint16_t ValueIndex;
/*! Function class contains the register file and the register tuple. Any
* information related to the registers may therefore require a function
///////////////////////////////////////////////////////////////////////////
/*! Store the instruction description in 8 bytes */
- class ALIGNED(sizeof(uint64)) Instruction
+ class ALIGNED(sizeof(uint64_t)) Instruction
{
public:
/*! Get the instruction opcode */
INLINE Opcode getOpcode(void) const { return opcode; }
/*! Get the number of sources for this instruction */
- uint32 getSrcNum(void) const;
+ uint32_t getSrcNum(void) const;
/*! Get the number of destination for this instruction */
- uint32 getDstNum(void) const;
+ uint32_t getDstNum(void) const;
/*! Get the register index of the given source */
- RegisterIndex getSrcIndex(const Function &fn, uint32 ID = 0u) const;
+ RegisterIndex getSrcIndex(const Function &fn, uint32_t ID = 0u) const;
/*! Get the register index of the given destination */
- RegisterIndex getDstIndex(const Function &fn, uint32 ID = 0u) const;
+ RegisterIndex getDstIndex(const Function &fn, uint32_t ID = 0u) const;
/*! Get the register of the given source */
- Register getDst(const Function &fn, uint32 ID = 0u) const;
+ Register getDst(const Function &fn, uint32_t ID = 0u) const;
/*! Get the register of the given destination */
- Register getSrc(const Function &fn, uint32 ID = 0u) const;
+ Register getSrc(const Function &fn, uint32_t ID = 0u) const;
/*! Check that the instruction is well formed. Return true if well formed.
* j
* Otherwise, fill the string with a help message
}
protected:
Opcode opcode; //!< Idendifies the instruction
- uint8 opaque[sizeof(uint64)-sizeof(uint8)];//!< Remainder of it
+ uint8_t opaque[sizeof(uint64_t)-sizeof(uint8_t)];//!< Remainder of it
};
// Check that the instruction is properly formed by the compiler
- STATIC_ASSERT(sizeof(Instruction) == sizeof(uint64));
+ STATIC_ASSERT(sizeof(Instruction) == sizeof(uint64_t));
/*! Unary instructions are typed. dst and sources share the same type */
class UnaryInstruction : public Instruction {
/*! Return the types of the values to store */
Type getValueType(void) const;
/*! Give the number of values the instruction is storing (srcNum-1) */
- uint32 getValueNum(void) const;
+ uint32_t getValueNum(void) const;
/*! Address space that is manipulated here */
MemorySpace getAddressSpace(void) const;
/*! Return true if the given instruction is an instance of this class */
/*! Type of the loaded values (ie type of all the destinations) */
Type getValueType(void) const;
/*! Number of values loaded (ie number of destinations) */
- uint32 getValueNum(void) const;
+ uint32_t getValueNum(void) const;
/*! Address space that is manipulated here */
MemorySpace getAddressSpace(void) const;
/*! Return true if the given instruction is an instance of this class */
};
/*! Load immediate instruction loads an typed immediate value into the given
- * register. Since double and uint64 values will not fit into an instruction,
+ * register. Since double and uint64_t values will not fit into an instruction,
* the immediate themselves are stored in the function core. Contrary to
* regular load instructions, there is only one destination possible
*/
/*! loadi.type dst value */
Instruction loadi(Type type, RegisterIndex dst, ValueIndex value);
/*! load.type.space {dst1,...,dst_valueNum} offset value */
- Instruction load(Type type, TupleIndex dst, RegisterIndex offset, MemorySpace space, uint16 valueNum);
+ Instruction load(Type type, TupleIndex dst, RegisterIndex offset, MemorySpace space, uint16_t valueNum);
/*! store.type.space offset {src1,...,src_valueNum} value */
- Instruction store(Type type, TupleIndex src, RegisterIndex offset, MemorySpace space, uint16 valueNum);
+ Instruction store(Type type, TupleIndex src, RegisterIndex offset, MemorySpace space, uint16_t valueNum);
/*! fence.space */
Instruction fence(MemorySpace space);
/*! label labelIndex */
{
public:
/*! Register family */
- enum Family : uint8 {
+ enum Family : uint8_t {
BOOL = 0,
BYTE = 1,
WORD = 2,
};
/*! Register index is the position of the register in the register file */
- typedef uint16 RegisterIndex;
+ typedef uint16_t RegisterIndex;
/*! Tuple index is the position of the register index in the tuple vector */
- typedef uint32 TupleIndex;
+ typedef uint32_t TupleIndex;
/*! A register file allocates and destroys registers. Basically, we will have
* one register file per function
public:
/*! Return the index of a newly allocated register register */
INLINE RegisterIndex append(Register::Family family) {
- const uint32 index = regs.size();
+ const uint32_t index = regs.size();
const Register reg(family);
assert(index <= MAX_INDEX);
regs.push_back(reg);
return regs[index];
}
/*! Get the register index from the tuple */
- INLINE RegisterIndex get(TupleIndex index, uint32 which) const {
+ INLINE RegisterIndex get(TupleIndex index, uint32_t which) const {
assert(index + which < regTuples.size());
return regTuples[index + which];
}
/*! Number of registers in the register file */
- INLINE uint32 regNum(void) const { return regs.size(); }
+ INLINE uint32_t regNum(void) const { return regs.size(); }
private:
enum { MAX_INDEX = 0xffff }; //!< We encode indices in 2 bytes
vector<Register> regs; //!< All the registers together
namespace gbe
{
/*! All types possibly supported by the instruction */
- enum Type : uint8 {
+ enum Type : uint8_t {
TYPE_S8 = 0, //!< signed 8 bits integer
TYPE_U8, //!< unsigned 8 bits integer
TYPE_S16, //!< signed 16 bits integer
}
void Unit::newConstant(const char *data,
const std::string &name,
- uint32 size,
- uint32 alignment)
+ uint32_t size,
+ uint32_t alignment)
{
constantSet.append(data, name, size, alignment);
}
/*! Return NULL if the function already exists */
Function *newFunction(const std::string &name);
/*! Create a new constant in the constant set */
- void newConstant(const char*, const std::string&, uint32 size, uint32 alignment);
+ void newConstant(const char*, const std::string&, uint32_t size, uint32_t alignment);
private:
hash_map<std::string, Function*> functions; //!< All the defined functions
ConstantSet constantSet; //!< All the constants defined in the unit
public:
#define DECL_CONSTRUCTOR(TYPE, FIELD) \
Value(TYPE FIELD) { this->data.u64 = 0llu; this->data.FIELD = FIELD; }
- DECL_CONSTRUCTOR(int8, s8);
- DECL_CONSTRUCTOR(uint8, u8);
+ DECL_CONSTRUCTOR(int8_t, s8);
+ DECL_CONSTRUCTOR(uint8_t, u8);
union {
- int8 s8;
- uint8 u8;
- int16 i16;
- uint16 u16;
- int32 i32;
- uint32 u32;
- int64 i64;
- uint64 u64;
+ int8_t s8;
+ uint8_t u8;
+ int16_t i16;
+ uint16_t u16;
+ int32_t i32;
+ uint32_t u32;
+ int64_t i64;
+ uint64_t u64;
float f32;
double f64;
} data; //!< Value to store
#define __GBE_ALLOC_HPP__
#include "sys/platform.hpp"
+#include "sys/assert.hpp"
#include "math/math.hpp"
-#include <cstdlib>
-#include <new>
namespace gbe
{
{
INLINE operator double( ) const { return 0; }
INLINE operator float ( ) const { return 0; }
- INLINE operator int64 ( ) const { return 0; }
- INLINE operator uint64( ) const { return 0; }
- INLINE operator int32 ( ) const { return 0; }
- INLINE operator uint32( ) const { return 0; }
- INLINE operator int16 ( ) const { return 0; }
- INLINE operator uint16( ) const { return 0; }
- INLINE operator int8 ( ) const { return 0; }
- INLINE operator uint8 ( ) 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
{
INLINE operator double( ) const { return 1; }
INLINE operator float ( ) const { return 1; }
- INLINE operator int64 ( ) const { return 1; }
- INLINE operator uint64( ) const { return 1; }
- INLINE operator int32 ( ) const { return 1; }
- INLINE operator uint32( ) const { return 1; }
- INLINE operator int16 ( ) const { return 1; }
- INLINE operator uint16( ) const { return 1; }
- INLINE operator int8 ( ) const { return 1; }
- INLINE operator uint8 ( ) 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
{
INLINE operator double( ) const { return -std::numeric_limits<double>::infinity(); }
INLINE operator float ( ) const { return -std::numeric_limits<float>::infinity(); }
- INLINE operator int64 ( ) const { return std::numeric_limits<int64>::min(); }
- INLINE operator uint64( ) const { return std::numeric_limits<uint64>::min(); }
- INLINE operator int32 ( ) const { return std::numeric_limits<int32>::min(); }
- INLINE operator uint32( ) const { return std::numeric_limits<uint32>::min(); }
- INLINE operator int16 ( ) const { return std::numeric_limits<int16>::min(); }
- INLINE operator uint16( ) const { return std::numeric_limits<uint16>::min(); }
- INLINE operator int8 ( ) const { return std::numeric_limits<int8>::min(); }
- INLINE operator uint8 ( ) const { return std::numeric_limits<uint8>::min(); }
+ 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
{
INLINE operator double( ) const { return std::numeric_limits<double>::infinity(); }
INLINE operator float ( ) const { return std::numeric_limits<float>::infinity(); }
- INLINE operator int64 ( ) const { return std::numeric_limits<int64>::max(); }
- INLINE operator uint64( ) const { return std::numeric_limits<uint64>::max(); }
- INLINE operator int32 ( ) const { return std::numeric_limits<int32>::max(); }
- INLINE operator uint32( ) const { return std::numeric_limits<uint32>::max(); }
- INLINE operator int16 ( ) const { return std::numeric_limits<int16>::max(); }
- INLINE operator uint16( ) const { return std::numeric_limits<uint16>::max(); }
- INLINE operator int8 ( ) const { return std::numeric_limits<int8>::max(); }
- INLINE operator uint8 ( ) const { return std::numeric_limits<uint8>::max(); }
+ 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
+++ /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/default_path.hpp"
-#include "platform.hpp"
-
-namespace gbe
-{
- const char *defaultPath[] = {
- "./share/",
- "../share/",
- "../../share/",
- "./",
- "../",
- "../../",
- "./data/",
- "../data/",
- "../../data/"
- };
- const size_t defaultPathNum = ARRAY_ELEM_NUM(defaultPath);
-} /* namespace gbe */
-
+++ /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 __DEFAULT_PATH_HPP__
-#define __DEFAULT_PATH_HPP__
-
-#include <cstdlib>
-
-namespace gbe
-{
- /*! Where you may find data files and shaders */
- extern const char *defaultPath[];
- /*! Number of default paths */
- extern const size_t defaultPathNum;
-} /* namespace gbe */
-
-#endif /* __DEFAULT_PATH_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_FIXED_ARRAY_HPP__
-#define __GBE_FIXED_ARRAY_HPP__
-
-#include "platform.hpp"
-#include <cstring>
-
-namespace gbe
-{
- /*! Regular C array but with bound checks */
- template<typename T, size_t N>
- class fixed_array
- {
- public:
- /*! Do not initialize the data */
- fixed_array(void) {}
- /*! Copy the input array */
- fixed_array(const T array[N]) { std::memcpy(elem, array, N * sizeof(T)); }
- /*! First element (non const) */
- T* begin(void) { return &elem[0]; }
- /*! First non-valid element (non const) */
- T* end(void) { return begin() + N; }
- /*! First element (const) */
- const T* begin(void) const { return &elem[0]; }
- /*! First non-valid element (const) */
- const T* end(void) const { return begin() + N; }
- /*! Number of elements in the array */
- size_t size(void) const { return N; }
- /*! Get the pointer to the data (non-const) */
- T* data(void) { return &elem[0]; }
- /*! Get the pointer to the data (const) */
- const T* data(void) const { return &elem[0]; }
- /*! First element (const) */
- const T& front(void) const { return *begin(); }
- /*! Last element (const) */
- const T& back(void) const { return *(end() - 1); }
- /*! First element (non-const) */
- T& front(void) { return *begin(); }
- /*! Last element (non-const) */
- T& back(void) { return *(end() - 1); }
- /*! Get element at position index (with bound check) */
- INLINE T& operator[] (size_t index) {
- GBE_ASSERT(index < size());
- return elem[index];
- }
- /*! Get element at position index (with bound check) */
- INLINE const T& operator[] (size_t index) const {
- GBE_ASSERT(index < size());
- return elem[index];
- }
- private:
- T elem[N]; //!< Store the elements
- STATIC_ASSERT(N > 0); //!< zero element is not allowed
- GBE_CLASS(fixed_array);
- };
-
-} /* namespace gbe */
-
-#endif /* __GBE_FIXED_ARRAY_HPP__ */
-
-
}
INLINE size_t __btc(size_t v, size_t i) {
- __int64 r = v; _bittestandcomplement64(&r,i); return r;
+ __int64_t r = v; _bittestandcomplement64(&r,i); return r;
}
INLINE size_t __bts(size_t v, size_t i) {
- __int64 r = v; _bittestandset64(&r,i); return r;
+ __int64_t r = v; _bittestandset64(&r,i); return r;
}
INLINE size_t __btr(size_t v, size_t i) {
- __int64 r = v; _bittestandreset64(&r,i); return r;
+ __int64_t r = v; _bittestandreset64(&r,i); return r;
}
#endif /* defined(__X86_64__) && !defined(__INTEL_COMPILER) */
-typedef int32 atomic32_t;
+typedef int32_t atomic32_t;
-INLINE int32 atomic_add(volatile int32* m, const int32 v) {
+INLINE int32_t atomic_add(volatile int32_t* m, const int32_t v) {
return _InterlockedExchangeAdd((volatile long*)m,v);
}
-INLINE int32 atomic_cmpxchg(volatile int32* m, const int32 v, const int32 c) {
+INLINE int32_t atomic_cmpxchg(volatile int32_t* m, const int32_t v, const int32_t c) {
return _InterlockedCompareExchange((volatile long*)m,v,c);
}
#if defined(__X86_64__)
-typedef int64 atomic_t;
+typedef int64_t atomic_t;
-INLINE int64 atomic_add(volatile int64* m, const int64 v) {
+INLINE int64_t atomic_add(volatile int64_t* m, const int64_t v) {
return _InterlockedExchangeAdd64(m,v);
}
-INLINE int64 atomic_cmpxchg(volatile int64* m, const int64 v, const int64 c) {
+INLINE int64_t atomic_cmpxchg(volatile int64_t* m, const int64_t v, const int64_t c) {
return _InterlockedCompareExchange64(m,v,c);
}
#else
-typedef int32 atomic_t;
+typedef int32_t atomic_t;
#endif /* defined(__X86_64__) */
INLINE void memoryFence(void) { _mm_mfence(); }
-typedef int32 atomic32_t;
+typedef int32_t atomic32_t;
-INLINE int32 atomic_add(int32 volatile* value, int32 input)
+INLINE int32_t atomic_add(int32_t volatile* value, int32_t input)
{ asm volatile("lock xadd %0,%1" : "+r" (input), "+m" (*value) : "r" (input), "m" (*value)); return input; }
-INLINE int32 atomic_cmpxchg(int32 volatile* value, const int32 input, int32 comparand)
+INLINE int32_t atomic_cmpxchg(int32_t volatile* value, const int32_t input, int32_t comparand)
{ asm volatile("lock cmpxchg %2,%0" : "=m" (*value), "=a" (comparand) : "r" (input), "m" (*value), "a" (comparand) : "flags"); return comparand; }
#if defined(__X86_64__)
- typedef int64 atomic_t;
+ typedef int64_t atomic_t;
- INLINE int64 atomic_add(int64 volatile* value, int64 input)
+ INLINE int64_t atomic_add(int64_t volatile* value, int64_t input)
{ asm volatile("lock xaddq %0,%1" : "+r" (input), "+m" (*value) : "r" (input), "m" (*value)); return input; }
- INLINE int64 atomic_cmpxchg(int64 volatile* value, const int64 input, int64 comparand)
+ INLINE int64_t atomic_cmpxchg(int64_t volatile* value, const int64_t input, int64_t comparand)
{ asm volatile("lock cmpxchgq %2,%0" : "+m" (*value), "+a" (comparand) : "r" (input), "m" (*value), "r" (comparand) : "flags"); return comparand; }
#else
- typedef int32 atomic_t;
+ typedef int32_t atomic_t;
#endif /* defined(__X86_64__) */
+++ /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/logging.hpp"
-#include "sys/filename.hpp"
-
-namespace gbe
-{
- LoggerStream::LoggerStream(void) : next(NULL) {}
- LoggerStream::~LoggerStream(void) {}
-
- LoggerBuffer::LoggerBuffer(void) : logger(NULL) {}
-
- LoggerBuffer& LoggerBuffer::operator<< (LoggerFlushTy) {
- logger->output(ss.str());
- ss.str("");
- return *this;
- }
-
- LoggerBuffer& LoggerBuffer::operator<< (const LoggerInfo &info) {
- FileName fileName(info.file);
- return *this << fileName.base() << " at " << info.function << " line " << info.line;
- }
-
- Logger::Logger(void) : streams(NULL) {
- const uint32 threadNum = 1;
- 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");
- GBE_DELETE_ARRAY(buffers);
- }
-
- void Logger::output(const std::string &str) {
- Lock<MutexSys> lock(mutex);
- LoggerStream *stream = this->streams;
- while (stream) {
- *stream << str;
- stream = stream->next;
- }
- }
-
- void Logger::insert(LoggerStream &stream) {
- Lock<MutexSys> lock(mutex);
- stream.next = this->streams;
- this->streams = &stream;
- }
-
- void Logger::remove(LoggerStream &stream) {
- Lock<MutexSys> lock(mutex);
- LoggerStream *curr = this->streams;
- LoggerStream *pred = NULL;
- while (curr) {
- if (curr == &stream)
- break;
- pred = curr;
- curr = curr->next;
- }
- FATAL_IF (curr == NULL, "Unable to find the given stream");
- if (pred)
- pred->next = curr->next;
- else
- this->streams = curr->next;
- }
-
- Logger *logger = NULL;
-} /* namespace gbe */
-
+++ /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_LOGGING_HPP__
-#define __GBE_LOGGING_HPP__
-
-#include "sys/mutex.hpp"
-#include "sys/platform.hpp"
-#include <sstream>
-#include <iomanip>
-
-namespace gbe
-{
- class Logger;
- class LoggerBuffer;
- class LoggerStream;
-
- /*! A logger stream is one way to output a string. It can be a file,
- * stdout, the in-game console and so on...
- */
- class LoggerStream
- {
- public:
- LoggerStream(void);
- virtual ~LoggerStream(void);
- virtual LoggerStream& operator<< (const std::string &str) = 0;
- private:
- friend class Logger;
- LoggerStream *next; //!< We chain the logger elements together
- };
-
- /*! Helper and proxy structures to display various information */
- static struct LoggerFlushTy { } loggerFlush MAYBE_UNUSED;
- struct LoggerInfo {
- INLINE LoggerInfo(const char *file, const char *function, int line) :
- file(file), function(function), line(line) {}
- const char *file, *function;
- int line;
- GBE_CLASS(LoggerInfo);
- };
-
- /*! Used to lazily create strings from the user defined logs. When destroyed
- * or flushed, it displays everything in one piece
- */
- class LoggerBuffer
- {
- public:
- template <typename T> LoggerBuffer& operator<< (const T &x) {
- ss << x;
- return *this;
- }
- LoggerBuffer& operator<< (LoggerFlushTy);
- LoggerBuffer& operator<< (const LoggerInfo&);
- /*! Output the info a nice format */
- LoggerBuffer& info(const char *file, const char *function, int line);
- private:
- friend class Logger;
- LoggerBuffer(void);
- Logger *logger; //!< The logger that created this buffer
- std::stringstream ss; //!< Stores all the user strings
- GBE_CLASS(LoggerBuffer);
- };
-
- /*! Central class to log anything from the engine */
- class Logger
- {
- public:
- Logger(void);
- ~Logger(void);
- /*! Output the string into all the attached streams */
- void output(const std::string &str);
- template <typename T> LoggerBuffer& operator<< (const T &x) {
- const uint32 bufferID = 0;
- LoggerBuffer &buffer = buffers[bufferID];
- buffer << "[" << "thread " << std::setw(2) << bufferID << "] ";
- buffer << "[" << std::setw(12) << std::fixed << getSeconds() - startTime << "s] " << x;
- return buffer;
- }
- void insert(LoggerStream &stream);
- void remove(LoggerStream &stream);
- private:
- MutexSys mutex; //!< To insert / remove streams and output strings
- LoggerStream *streams; //!< All the output streams
- LoggerBuffer *buffers; //!< One buffer per thread
- double startTime; //!< When the logger has been created
- GBE_CLASS(Logger);
- };
-
- /*! We have one logger for the application */
- extern Logger *logger;
-
-} /* namespace gbe */
-
-/*! Macros to handle logging information in the code */
-#define GBE_LOG_HERE LoggerInfo(__FILE__, __FUNCTION__, __LINE__)
-#define GBE_INFO " ######## " << GBE_LOG_HERE
-
-/*! Verbose macros: they add logging position and thread ID */
-#define GBE_WARNING_V(MSG) do { \
- if (logger) *logger << "WARNING " << MSG << GBE_INFO << "\n" << loggerFlush; \
-} while (0)
-
-#define GBE_ERROR_V(MSG) do { \
- if (logger) *logger << "ERROR " << MSG << GBE_INFO << "\n" << loggerFlush; \
-} while (0)
-
-#define GBE_MSG_V(MSG) do { \
- if (logger) *logger << MSG << GBE_INFO << "\n" << loggerFlush; \
-} while (0)
-
-/*! Regular macros: just the user message */
-#define GBE_WARNING(MSG) do { \
- if (logger) *logger << "WARNING " << MSG << "\n" << loggerFlush; \
-} while (0)
-
-#define GBE_ERROR(MSG) do { \
- if (logger) *logger << "ERROR " << MSG << "\n" << loggerFlush; \
-} while (0)
-
-#define GBE_MSG(MSG) do { \
- if (logger) *logger << MSG << "\n" << loggerFlush; \
-} while (0)
-
-#endif /* __GBE_LOGGING_HPP__ */
-
#ifndef __GBE_PLATFORM_HPP__
#define __GBE_PLATFORM_HPP__
+
#include <cstddef>
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <cassert>
+#include <new>
////////////////////////////////////////////////////////////////////////////////
/// CPU architecture
/*! Run-time assertion */
#ifndef NDEBUG
-#define GBE_ASSERT(EXPR) do { \
- if (UNLIKELY(!(EXPR))) assert(EXPR); \
+#define GBE_ASSERT(EXPR) do { \
+ if (UNLIKELY(!(EXPR))) \
+ gbe::onFailedAssert(__FILE__, __FUNCTION__, __LINE__); \
} while (0)
#else
#define GBE_ASSERT(EXPR) do { } while (0)
////////////////////////////////////////////////////////////////////////////////
#if defined(__MSVC__)
-typedef __int64 int64;
-typedef unsigned __int64 uint64;
-typedef __int32 int32;
-typedef unsigned __int32 uint32;
-typedef __int16 int16;
-typedef unsigned __int16 uint16;
-typedef __int8 int8;
-typedef unsigned __int8 uint8;
+typedef __int64_t int64_t;
+typedef unsigned __int64_t uint64_t;
+typedef __int32_t int32_t;
+typedef unsigned __int32_t uint32_t;
+typedef __int16_t int16_t;
+typedef unsigned __int16_t uint16_t;
+typedef __int8_t int8_t;
+typedef unsigned __int8_t uint8_t;
#else
-typedef long long int64;
-typedef unsigned long long uint64;
-typedef int int32;
-typedef unsigned int uint32;
-typedef short int16;
-typedef unsigned short uint16;
-typedef char int8;
-typedef unsigned char uint8;
+#include <cstdint>
#endif
#if defined(__X86_64__)
-typedef int64 index_t;
+typedef int64_t index_t;
#else
-typedef int32 index_t;
+typedef int32_t index_t;
#endif
/*! To protect some classes from being copied */
void FATAL(const std::string&);
/*! Return the next power of 2 */
- INLINE uint32 nextHighestPowerOf2(uint32 x) {
+ INLINE uint32_t nextHighestPowerOf2(uint32_t x) {
x--;
x |= x >> 1;
x |= x >> 2;
return ++x;
}
- INLINE uint32 logi2(uint32 x) {
- uint32 r = 0;
+ INLINE uint32_t logi2(uint32_t x) {
+ uint32_t r = 0;
while(x >>= 1) r++;
return r;
}
- template<uint32 N>
- INLINE uint32 isPowerOf(uint32 i) {
+ template<uint32_t N>
+ INLINE uint32_t isPowerOf(uint32_t i) {
while (i > 1) {
if (i%N) return false;
i = i/N;
}
return true;
}
- template<> INLINE uint32 isPowerOf<2>(uint32 i) { return ((i-1)&i) == 0; }
+ template<> INLINE uint32_t isPowerOf<2>(uint32_t i) { return ((i-1)&i) == 0; }
/*! random functions */
template<typename T> T random() { return T(0); }
template<> INLINE int random() { return int(rand()); }
- template<> INLINE uint32 random() { return uint32(rand()); }
- template<> INLINE float random() { return random<uint32>()/float(RAND_MAX); }
- template<> INLINE double random() { return random<uint32>()/double(RAND_MAX); }
+ template<> INLINE uint32_t random() { return uint32_t(rand()); }
+ template<> INLINE float random() { return random<uint32_t>()/float(RAND_MAX); }
+ template<> INLINE double random() { return random<uint32_t>()/double(RAND_MAX); }
/** returns performance counter in seconds */
double getSeconds();
std::string loadFile(std::ifstream &stream)
{
- GBE_ASSERT(stream.is_open());
+ GBE_ASSERT(stream.is_open() == true);
std::string line;
std::stringstream text;
while (std::getline(stream, line))
std::string getExecutableFileName()
{
char buf[1024];
- uint32_t size = sizeof(buf);
+ uint32_t_t size = sizeof(buf);
if (_NSGetExecutablePath(buf, &size) != 0) return std::string();
return std::string(buf);
}
+++ /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 <iostream>
-
-#include "sys/thread.hpp"
-#include "sys/sysinfo.hpp"
-
-////////////////////////////////////////////////////////////////////////////////
-/// Windows Platform
-////////////////////////////////////////////////////////////////////////////////
-
-#ifdef __WIN32__
-
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
-
-namespace gbe
-{
- /*! creates a hardware thread running on specific core */
- thread_t createThread(thread_func f, void* arg, size_t stack_size, int affinity)
- {
- HANDLE handle = CreateThread(NULL,stack_size,(LPTHREAD_START_ROUTINE)f,arg,0,NULL);
- if (handle == NULL)
- FATAL("createThread error");
- if (affinity < 0) return thread_t(handle);
-
- // set thread affinity
- int thread = affinity % 64;
- SetThreadAffinityMask(handle, DWORD_PTR(1L << thread));
-
- return thread_t(handle);
- }
-
- void setAffinity(int affinity) {
- if (affinity >= 0) SetThreadAffinityMask(GetCurrentThread(), DWORD_PTR(1L << affinity));
- }
-
- void yield(int time) { Sleep(time); }
-
- void join(thread_t tid) {
- WaitForSingleObject(HANDLE(tid), INFINITE);
- CloseHandle(HANDLE(tid));
- }
-
- void destroyThread(thread_t tid) {
- TerminateThread(HANDLE(tid),0);
- CloseHandle(HANDLE(tid));
- }
-
- tls_t createTls() { return tls_t(TlsAlloc()); }
-
- void setTls(tls_t tls, void* const ptr) {
- TlsSetValue(DWORD(size_t(tls)), ptr);
- }
-
- void* getTls(tls_t tls) {
- return TlsGetValue(DWORD(size_t(tls)));
- }
-
- void destroyTls(tls_t tls) {
- TlsFree(DWORD(size_t(tls)));
- }
-}
-
-#endif
-
-////////////////////////////////////////////////////////////////////////////////
-/// Linux Platform
-////////////////////////////////////////////////////////////////////////////////
-
-#ifdef __LINUX__
-namespace gbe
-{
- /*! set affinity of the calling thread */
- void setAffinity(int affinity)
- {
- int wrap = getNumberOfLogicalThreads()/2;
- affinity = (affinity/2) + wrap*(affinity%2);
- if (affinity >= 0 && affinity < 64*64) {
- union { uint64 u; cpu_set_t set; } mask[64];
- for (size_t i=0; i<64; i++) mask[i].u = 0;
- mask[affinity/64].u= uint64(1) << (affinity % 64);
- if (pthread_setaffinity_np(pthread_self(), sizeof(mask), &mask[0].set) < 0)
- std::cerr << "Thread: cannot set affinity" << std::endl;
- }
- }
-}
-#endif
-
-////////////////////////////////////////////////////////////////////////////////
-/// MacOSX Platform
-////////////////////////////////////////////////////////////////////////////////
-
-#ifdef __MACOSX__
-
-#include <mach/thread_act.h>
-#include <mach/thread_policy.h>
-#include <mach/mach_init.h>
-
-namespace gbe
-{
- /*! set affinity of the calling thread */
- void setAffinity(int affinity)
- {
- if (affinity >= 0) {
- thread_affinity_policy ap;
- ap.affinity_tag = affinity;
- if (thread_policy_set(mach_thread_self(),THREAD_AFFINITY_POLICY,(integer_t*)&ap,THREAD_AFFINITY_POLICY_COUNT) != KERN_SUCCESS)
- std::cerr << "Thread: cannot set affinity" << std::endl;
- }
- }
-}
-#endif
-
-////////////////////////////////////////////////////////////////////////////////
-/// Unix Platform
-////////////////////////////////////////////////////////////////////////////////
-
-#ifdef __UNIX__
-
-#include <pthread.h>
-#include <sched.h>
-
-namespace gbe
-{
- struct ThreadStartupData {
- int affinity;
- thread_func f;
- void* arg;
- };
-
- static void* threadStartup(ThreadStartupData* parg)
- {
- ThreadStartupData arg = *parg; GBE_DELETE(parg); parg = NULL;
- setAffinity(arg.affinity);
- arg.f(arg.arg);
- return NULL;
- }
-
- thread_t createThread(thread_func f, void* arg, size_t stack_size, int affinity)
- {
- pthread_attr_t attr;
- pthread_attr_init(&attr);
- if (stack_size > 0) pthread_attr_setstacksize (&attr, stack_size);
-
- pthread_t* tid = GBE_NEW(pthread_t);
- ThreadStartupData* startup = GBE_NEW(ThreadStartupData);
- startup->f = f;
- startup->arg = arg;
- startup->affinity = affinity;
-
- if (pthread_create(tid,&attr,(void*(*)(void*))threadStartup,startup) != 0)
- FATAL("Thread creation error");
-
- return thread_t(tid);
- }
-
- void yield(int time) {
- if (time == 0) sched_yield();
- else usleep(time * 1000);
- }
-
- void join(thread_t tid) {
- if (pthread_join(*(pthread_t*)tid, NULL) != 0)
- FATAL("pthread_join error");
- GBE_DELETE((pthread_t*)tid);
- }
-
- void destroyThread(thread_t tid) {
- pthread_cancel(*(pthread_t*)tid);
- GBE_DELETE((pthread_t*)tid);
- }
-
- tls_t createTls() {
- 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* getTls(tls_t tls) {
- return pthread_getspecific(*(pthread_key_t*)tls);
- }
-
- void setTls(tls_t tls, void* const ptr) {
- if (pthread_setspecific(*(pthread_key_t*)tls, ptr) != 0)
- FATAL("pthread_setspecific error");
- }
-
- void destroyTls(tls_t tls) {
- if (pthread_key_delete(*(pthread_key_t*)tls) != 0)
- FATAL("pthread_key_delete error");
- GBE_DELETE((pthread_key_t*)tls);
- }
-}
-#endif
+++ /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_THREAD_HPP__
-#define __GBE_THREAD_HPP__
-
-#include "sys/platform.hpp"
-
-namespace gbe
-{
- /*! Type for thread */
- typedef struct opaque_thread_t* thread_t;
- /*! Signature of thread start function */
- typedef void (*thread_func)(void*);
- /*! Creates a hardware thread running on specific logical thread */
- thread_t createThread(thread_func f, void* arg, size_t stack_size = 0, int affinity = -1);
- /*! Set affinity of the calling thread */
- void setAffinity(int affinity);
- /*! The thread calling this function gets yielded for a number of seconds */
- void yield(int time = 0);
- /*! Waits until the given thread has terminated */
- void join(thread_t tid);
- /*! Destroy handle of a thread */
- void destroyThread(thread_t tid);
- /*! Type for handle to thread local storage */
- typedef struct opaque_tls_t* tls_t;
- /*! Creates thread local storage */
- tls_t createTls();
- /*! Set the thread local storage pointer */
- void setTls(tls_t tls, void* const ptr);
- /*! Return the thread local storage pointer */
- void* getTls(tls_t tls);
- /*! Destroys thread local storage identifier */
- void destroyTls(tls_t tls);
-}
-
-#endif /* __GBE_THREAD_HPP__ */
-