OpenASIP  2.0
Macros
OSAL.hh File Reference
#include <vector>
#include "tce_config.h"
#include "OperationContext.hh"
#include "SimValue.hh"
#include "OperationBehavior.hh"
#include "Operation.hh"
#include "Memory.hh"
#include "OperationPool.hh"
#include "OperationState.hh"
#include "OperationGlobals.hh"
#include "SimulateTriggerWrappers.icc"
Include dependency graph for OSAL.hh:

Go to the source code of this file.

Macros

#define OPERATION_COMMON(OPNAME)
 
#define OPERATION(OPNAME)
 
#define END_OPERATION(OPNAME)
 
#define OPERATION_WITH_STATE(OPNAME, STATE_NAME)
 
#define END_OPERATION_WITH_STATE(OPNAME)   END_OPERATION(OPNAME)
 
#define DEFINE_STATE(STATE_NAME)
 
#define END_DEFINE_STATE   };
 
#define INIT_STATE(STATE_NAME)
 
#define END_INIT_STATE   }
 
#define FINALIZE_STATE(STATE_NAME)   public: ~STATE_NAME##_State() {
 
#define END_FINALIZE_STATE   }
 
#define TRIGGER
 
#define STATE   (*fetchState(context))
 
#define END_TRIGGER   return true; }
 
#define ADVANCE_CLOCK
 
#define END_ADVANCE_CLOCK   }
 
#define RETURN_READY
 
#define INT(OPERAND)   (io[(OPERAND) - 1]->intValue())
 
#define UINT(OPERAND)   (io[(OPERAND) - 1]->unsignedValue())
 
#define LONG(OPERAND)   (io[(OPERAND) - 1]->sLongWordValue())
 
#define ULONG(OPERAND)   (io[(OPERAND) - 1]->uLongWordValue())
 
#define FLT(OPERAND)   (io[(OPERAND) - 1]->floatWordValue())
 
#define DBL(OPERAND)   (io[(OPERAND) - 1]->doubleWordValue())
 
#define HFLT(OPERAND)   (io[(OPERAND) -1]->halfFloatWordValue())
 
#define SUBWORD1(OPERAND, ELEMENT)   (io[(OPERAND) - 1]->bitElement(ELEMENT))
 
#define SUBWORD8(OPERAND, ELEMENT)   (io[(OPERAND) - 1]->byteElement(ELEMENT))
 
#define SUBWORD16(OPERAND, ELEMENT)   (io[(OPERAND) - 1]->halfWordElement(ELEMENT))
 
#define SUBWORD32(OPERAND, ELEMENT)   (io[(OPERAND) - 1]->wordElement(ELEMENT))
 
#define SET_SUBWORD1(OPERAND, ELEMENT, VALUE)   (io[(OPERAND) - 1]->setBitElement(ELEMENT, VALUE))
 
#define SET_SUBWORD8(OPERAND, ELEMENT, VALUE)   (io[(OPERAND) - 1]->setByteElement(ELEMENT, VALUE))
 
#define SET_SUBWORD16(OPERAND, ELEMENT, VALUE)   (io[(OPERAND) - 1]->setHalfWordElement(ELEMENT, VALUE))
 
#define SET_SUBWORD32(OPERAND, ELEMENT, VALUE)   (io[(OPERAND) - 1]->setWordElement(ELEMENT, VALUE))
 
#define SUBFLOAT16(OPERAND, ELEMENT)   (io[(OPERAND) - 1]->halfFloatElement(ELEMENT))
 
#define SUBFLOAT32(OPERAND, ELEMENT)   (io[(OPERAND) - 1]->floatElement(ELEMENT))
 
#define SUBFLOAT64(OPERAND, ELEMENT)   (io[(OPERAND) - 1]->doubleFloatElement(ELEMENT))
 
#define SET_SUBFLOAT16(OPERAND, ELEMENT, VALUE)   (io[(OPERAND) - 1]->setHalfFloatElement(ELEMENT, VALUE))
 
#define SET_SUBFLOAT32(OPERAND, ELEMENT, VALUE)   (io[(OPERAND) - 1]->setFloatElement(ELEMENT, VALUE))
 
#define SET_SUBFLOAT64(OPERAND, ELEMENT, VALUE)   (io[(OPERAND) - 1]->setDoubleWordElement(ELEMENT, VALUE))
 
#define IO(OPERAND)   (*io[(OPERAND) - 1])
 
#define BWIDTH(OPERAND)   (((io[(OPERAND) - 1])->width()))
 
#define PROGRAM_COUNTER   (context.programCounter())
 
#define SET_PROGRAM_COUNTER(PCVAL)
 
#define SAVE_RETURN_ADDRESS   context.setSaveReturnAddress(true)
 
#define RETURN_ADDRESS   (context.returnAddress())
 
#define CONTEXT_ID   (context.contextId())
 
#define MAU_SIZE   (context.memory().MAUSize())
 
#define MEMORY   context.memory()
 
#define SIGN_EXTEND(VALUE, WIDTH)   ((SLongWord)((SLongWord(VALUE) << (64-(WIDTH))) >> (64-(WIDTH))))
 
#define ZERO_EXTEND(VALUE, WIDTH)   ((ULongWord(VALUE) << (64-(WIDTH))) >> (64-(WIDTH)))
 
#define OUTPUT_STREAM   OperationGlobals::outputStream()
 
#define OSAL_WORD_WIDTH   sizeof(ULongWord) * BYTE_BITWIDTH
 
#define RUNTIME_ERROR(MESSAGE)
 
#define EXEC_OPERATION(OPNAME, ...)
 
#define OP(OPNAME, ...)
 
#define CYCLE_COUNT   (context.cycleCount())
 
#define FU_NAME   (context.functionUnitName())
 
#define BRANCH_DELAY_CYCLES   (context.branchDelayCycles())
 
#define INPUT_VALIDATION
 
#define END_INPUT_VALIDATION
 
#define DECLARE_VALID   return true
 

Detailed Description

Macro definitions for defining the behavior of operations in the Operation Set Abstraction Layer.

Macros expand to derived OperationBehavior class definitions and factory functions that instantiate these custom classes. The factory functions constitute the plugin interface.

Author
Pekka Jääskeläinen 2004-2015 (pekka.jaaskelainen-no.spam-tut.fi)
Note
This file is used in compiled simulation. Keep dependencies clean
rating: red

Definition in file OSAL.hh.

Macro Definition Documentation

◆ ADVANCE_CLOCK

#define ADVANCE_CLOCK
Value:
void advanceClock(OperationContext& context) { \
(void)context;

Starts the definition block for the state clock advancing simulation function.

"if (&context ..." is an ugly hack to avoid compiler warning when context is not used.

Definition at line 287 of file OSAL.hh.

◆ BRANCH_DELAY_CYCLES

#define BRANCH_DELAY_CYCLES   (context.branchDelayCycles())

Returns the delay cycle amount caused by pipeline length.

Definition at line 499 of file OSAL.hh.

◆ BWIDTH

#define BWIDTH (   OPERAND)    (((io[(OPERAND) - 1])->width()))

Macro for obtaining the bit width of the port the operand is bound to.

Definition at line 366 of file OSAL.hh.

◆ CONTEXT_ID

#define CONTEXT_ID   (context.contextId())

Access the unique id of the operation context.

Definition at line 394 of file OSAL.hh.

◆ CYCLE_COUNT

#define CYCLE_COUNT   (context.cycleCount())

Returns the cycle count since the beginning of simulation.

Definition at line 489 of file OSAL.hh.

◆ DBL

#define DBL (   OPERAND)    (io[(OPERAND) - 1]->doubleWordValue())

Definition at line 317 of file OSAL.hh.

◆ DECLARE_VALID

#define DECLARE_VALID   return true

Macro to accept given inputs in the user validation code.

Definition at line 527 of file OSAL.hh.

◆ DEFINE_STATE

#define DEFINE_STATE (   STATE_NAME)
Value:
class STATE_NAME##_State : public OperationState { \
public: \
const char* name() { return #STATE_NAME; };

Custom state definition.

The information of the custom state type used by the OPERATION_WITH_STATE definition is entered using DEFINE_STATE. The custom state must be defined with this macro before using it in an OPERATION_WITH_STATE definition.

Macro expands to a class structure which derives itself from OperationState and implements the pure virtual method name() trivially by returning the name of the state as a C string. Rest of the class, which are usually public member variables, are entered by the user.

Definition at line 214 of file OSAL.hh.

◆ END_ADVANCE_CLOCK

#define END_ADVANCE_CLOCK   }

Ends the definition block for the clock advancing simulation function.

Definition at line 294 of file OSAL.hh.

◆ END_DEFINE_STATE

#define END_DEFINE_STATE   };

Definition at line 219 of file OSAL.hh.

◆ END_FINALIZE_STATE

#define END_FINALIZE_STATE   }

Definition at line 245 of file OSAL.hh.

◆ END_INIT_STATE

#define END_INIT_STATE   }

Definition at line 233 of file OSAL.hh.

◆ END_INPUT_VALIDATION

#define END_INPUT_VALIDATION
Value:
return false; \
}

Closing macro for user defined input validation code.

Definition at line 520 of file OSAL.hh.

◆ END_OPERATION

#define END_OPERATION (   OPNAME)
Value:
}; \
extern "C" { \
OperationBehavior* createOpBehavior_##OPNAME(const Operation& parent) {\
return new OPNAME##_Behavior(parent);\
}\
void deleteOpBehavior_##OPNAME(OperationBehavior* target) {\
delete target;\
}\
}

Ends the definition of operation behavior without state.

This macro expands to a factory/destructor functions for the newly defined behavior class type. The functions are exported using C symbols so they are accesible without needing C++ name demangling. These two functions constitute the plugin interface which are used as an access point to the definitions in an operation behavior plugin module.

Factory function returns an instance of the newly defined behavior class. A reference to the operation the behavior belongs to is given as an argument. The function is named createOpBehavior_OPERATIONNAME(), e.g., createOpBehavior_Add4().

Destructor function needs to be defined because delete operator can be overridden in the plugin module and the deletion of the custom operation behavior instance has to be done using the correct delete operator. The instance cannot be simply deallocated using delete operator in the client's code. Function takes a pointer to the object that should be deleted as an argument. It's named deleteOpBehavior_OPERATIONNAME(), for example, deleteOpBehavior_Add4().

The dummy variable in the last line is to force addition of semicolon after the END_OPERATION() statement in user's code because semicolon is not allowed after an "extern" block (at least with all compilers).

The semicolon "policy" is wanted to be consistent with all statements: the statement that starts the block (e.g., OPERATION()) does not require semicolon after it, but the block ender (e.g., END_OPERATION()) does.

Definition at line 131 of file OSAL.hh.

◆ END_OPERATION_WITH_STATE

#define END_OPERATION_WITH_STATE (   OPNAME)    END_OPERATION(OPNAME)

Definition at line 199 of file OSAL.hh.

◆ END_TRIGGER

#define END_TRIGGER   return true; }

Ends the definition block for trigger simulation function.

Definition at line 277 of file OSAL.hh.

◆ EXEC_OPERATION

#define EXEC_OPERATION (   OPNAME,
  ... 
)
Value:
const Operation& __used_in_macro_temp__ = opPool_.operation(#OPNAME); \
executeOperation(__used_in_macro_temp__.behavior(), context, __VA_ARGS__);

Executes operation.

Definition at line 476 of file OSAL.hh.

◆ FINALIZE_STATE

#define FINALIZE_STATE (   STATE_NAME)    public: ~STATE_NAME##_State() {

Custom state deallocation.

If the state data needs to be deallocated when state instance is deleted, FINALIZE_STATE can be used to define a destructor to the state class.

Definition at line 242 of file OSAL.hh.

◆ FLT

#define FLT (   OPERAND)    (io[(OPERAND) - 1]->floatWordValue())

Definition at line 316 of file OSAL.hh.

◆ FU_NAME

#define FU_NAME   (context.functionUnitName())

Returns the function unit name associated to the OperationContext.

Definition at line 494 of file OSAL.hh.

◆ HFLT

#define HFLT (   OPERAND)    (io[(OPERAND) -1]->halfFloatWordValue())

Definition at line 318 of file OSAL.hh.

◆ INIT_STATE

#define INIT_STATE (   STATE_NAME)
Value:
public: STATE_NAME##_State(OperationContext& context) { \
context.isEmpty();

Custom state initialization.

If the state data needs to be initialized before use, INIT_STATE can be used to define a constructor to the state class. isEmpty call is to avoid warning about unused parameter.

Definition at line 229 of file OSAL.hh.

◆ INPUT_VALIDATION

#define INPUT_VALIDATION
Value:
virtual bool areValid( \
const OperationContext& context) const { \
(void)context; \
(void)inputs; \
std::vector<const SimValue*> io; \
for (size_t i = 0; i < inputs.size(); i++) { \
const SimValue* tmp = &inputs.at(i); \
io.push_back(tmp); \
}

Opening macro for user defined input validation code.

Definition at line 505 of file OSAL.hh.

◆ INT

#define INT (   OPERAND)    (io[(OPERAND) - 1]->intValue())

Operand value accessor macros for different types.

Each accessor macro accesses the corresponding type of value_ union of the operand SimValue. The value is a copy and thus can be only used as a rvalue of an assignment.

Definition at line 312 of file OSAL.hh.

◆ IO

#define IO (   OPERAND)    (*io[(OPERAND) - 1])

Operand accessor macro.

This macro must be used as lvalue when assigning values to output operands.

Definition at line 361 of file OSAL.hh.

◆ LONG

#define LONG (   OPERAND)    (io[(OPERAND) - 1]->sLongWordValue())

Definition at line 314 of file OSAL.hh.

◆ MAU_SIZE

#define MAU_SIZE   (context.memory().MAUSize())

Memory interface. Get the width of the minimum addressable unit of the memory.

Definition at line 403 of file OSAL.hh.

◆ MEMORY

#define MEMORY   context.memory()

Accesses the memory instance connected to the operation's FU.

Definition at line 408 of file OSAL.hh.

◆ OP

#define OP (   OPNAME,
  ... 
)
Value:
const Operation& __used_in_macro_temp__ = opPool_.operation(#OPNAME); \
executeOperation(__used_in_macro_temp__.behavior(), context, __VA_ARGS__);

Definition at line 479 of file OSAL.hh.

◆ OPERATION

#define OPERATION (   OPNAME)
Value:
class OPNAME##_Behavior : public OperationBehavior { \
public: \
typedef NullOperationState StateType; \
private: \
StateType* fetchState(const OperationContext&) const { \
}; \
OPERATION_COMMON(OPNAME) \
public:

Operation behavior without state.

fetchState() is called in the simulation functions to fetch instance of state (using STATE macro).

In an operation definition without state, the STATE is set point to an instance of NullOperationState.

Definition at line 90 of file OSAL.hh.

◆ OPERATION_COMMON

#define OPERATION_COMMON (   OPNAME)
Value:
public: \
OPNAME##_Behavior(const Operation& parent) : OperationBehavior(parent) {}; \
private: \
mutable OperationPool opPool_;

OPERATION and OPERATION_WITH_STATE start a definition block for operation behavior. They expand to a definition of a new OperationBehavior class with name OPERATION_Behavior (e.g., ADD4_Behavior).

Argument overloading is not supported by the preprocessor macros, thus we need two differently named OPERATION macros, OPERATION() and OPERATION_WITH_STATE(). OPERATION_COMMON provides definitions that are common to both OPERATION and OPERATION_WITH_STATE:

  • Constructor with Operation reference (points to the operation the behavior is defined for).

Definition at line 75 of file OSAL.hh.

◆ OPERATION_WITH_STATE

#define OPERATION_WITH_STATE (   OPNAME,
  STATE_NAME 
)

Operation behavior with state.

This definition connects user defined state type to an operation behavior definition. Connection is implemented with a typedef that sets StateType type to be the custom type.

createState() is called by the owner of the custom OperationBehavior instance, it is used to add a custom state instance to the operation context to be accessed later. deleteState() is used to remove the custom state from the context. See the design document for more information.

In an operation definition with state, the STATE is set to point to an instance of an OperationState object of a custom defined OperationState derived type. The instance is fetched from context and dynamic_casted to the correct type.

stateExists() helper method tells if an instance of the custom state already exists in the context.

Definition at line 162 of file OSAL.hh.

◆ OSAL_WORD_WIDTH

#define OSAL_WORD_WIDTH   sizeof(ULongWord) * BYTE_BITWIDTH

Maximum bit width of the inputs and outputs currently fully supported by behaviour models of base operations.

Definition at line 462 of file OSAL.hh.

◆ OUTPUT_STREAM

#define OUTPUT_STREAM   OperationGlobals::outputStream()

Provides access to the output stream which can be used to print out debug information to simulator console, or, for example, to simulate output from the TTA.

Default output stream is std::cout.

Definition at line 456 of file OSAL.hh.

◆ PROGRAM_COUNTER

#define PROGRAM_COUNTER   (context.programCounter())

Access the program counter register.

Definition at line 371 of file OSAL.hh.

◆ RETURN_ADDRESS

#define RETURN_ADDRESS   (context.returnAddress())

Access the return address register.

Definition at line 389 of file OSAL.hh.

◆ RETURN_READY

#define RETURN_READY

Explicit return statements for simulation function definitions. RETURN_READY is not needed anymore, macro is deprecated.

Definition at line 303 of file OSAL.hh.

◆ RUNTIME_ERROR

#define RUNTIME_ERROR (   MESSAGE)
Value:
MESSAGE, __FILE__, __LINE__, parent_);

Causes runtime error with given error explanation message.

Can be used to abort simulation in case of illegal operands etc.

Definition at line 470 of file OSAL.hh.

◆ SAVE_RETURN_ADDRESS

#define SAVE_RETURN_ADDRESS   context.setSaveReturnAddress(true)

Instruct the GCU to save the return address register.

Definition at line 384 of file OSAL.hh.

◆ SET_PROGRAM_COUNTER

#define SET_PROGRAM_COUNTER (   PCVAL)
Value:
context.programCounter() = (PCVAL); \
context.setUpdateProgramCounter(true)

Updates the program counter. This includes transport delay (the number of delay slots in the machine).

Definition at line 377 of file OSAL.hh.

◆ SET_SUBFLOAT16

#define SET_SUBFLOAT16 (   OPERAND,
  ELEMENT,
  VALUE 
)    (io[(OPERAND) - 1]->setHalfFloatElement(ELEMENT, VALUE))

Definition at line 349 of file OSAL.hh.

◆ SET_SUBFLOAT32

#define SET_SUBFLOAT32 (   OPERAND,
  ELEMENT,
  VALUE 
)    (io[(OPERAND) - 1]->setFloatElement(ELEMENT, VALUE))

Definition at line 351 of file OSAL.hh.

◆ SET_SUBFLOAT64

#define SET_SUBFLOAT64 (   OPERAND,
  ELEMENT,
  VALUE 
)    (io[(OPERAND) - 1]->setDoubleWordElement(ELEMENT, VALUE))

Definition at line 353 of file OSAL.hh.

◆ SET_SUBWORD1

#define SET_SUBWORD1 (   OPERAND,
  ELEMENT,
  VALUE 
)    (io[(OPERAND) - 1]->setBitElement(ELEMENT, VALUE))

Definition at line 333 of file OSAL.hh.

◆ SET_SUBWORD16

#define SET_SUBWORD16 (   OPERAND,
  ELEMENT,
  VALUE 
)    (io[(OPERAND) - 1]->setHalfWordElement(ELEMENT, VALUE))

Definition at line 337 of file OSAL.hh.

◆ SET_SUBWORD32

#define SET_SUBWORD32 (   OPERAND,
  ELEMENT,
  VALUE 
)    (io[(OPERAND) - 1]->setWordElement(ELEMENT, VALUE))

Definition at line 339 of file OSAL.hh.

◆ SET_SUBWORD8

#define SET_SUBWORD8 (   OPERAND,
  ELEMENT,
  VALUE 
)    (io[(OPERAND) - 1]->setByteElement(ELEMENT, VALUE))

Definition at line 335 of file OSAL.hh.

◆ SIGN_EXTEND

#define SIGN_EXTEND (   VALUE,
  WIDTH 
)    ((SLongWord)((SLongWord(VALUE) << (64-(WIDTH))) >> (64-(WIDTH))))

Sign extends the given integer.

Sign extension means that the sign bit of the source word is duplicated to the extra bits provided by the wider target destination word.

Example:

SRC: 1 0010b (5 bits) DST: 1111 0010b (8 bits)

The first argument is the integer that should be sign extended. The second argument is the bit width of the source argument. In the previous example, the bit width is 5. This is used to figure out which is the sign bit. Returns a sign extended (to 64 bits) IntWord.

Definition at line 426 of file OSAL.hh.

◆ STATE

#define STATE   (*fetchState(context))

Fetches the state instance.

Definition at line 271 of file OSAL.hh.

◆ SUBFLOAT16

#define SUBFLOAT16 (   OPERAND,
  ELEMENT 
)    (io[(OPERAND) - 1]->halfFloatElement(ELEMENT))

Definition at line 342 of file OSAL.hh.

◆ SUBFLOAT32

#define SUBFLOAT32 (   OPERAND,
  ELEMENT 
)    (io[(OPERAND) - 1]->floatElement(ELEMENT))

Definition at line 344 of file OSAL.hh.

◆ SUBFLOAT64

#define SUBFLOAT64 (   OPERAND,
  ELEMENT 
)    (io[(OPERAND) - 1]->doubleFloatElement(ELEMENT))

Definition at line 346 of file OSAL.hh.

◆ SUBWORD1

#define SUBWORD1 (   OPERAND,
  ELEMENT 
)    (io[(OPERAND) - 1]->bitElement(ELEMENT))

Operand value accessor macros for raw data field in value_ of SimValue.

Needed for vector operations to access subwords.

Definition at line 325 of file OSAL.hh.

◆ SUBWORD16

#define SUBWORD16 (   OPERAND,
  ELEMENT 
)    (io[(OPERAND) - 1]->halfWordElement(ELEMENT))

Definition at line 329 of file OSAL.hh.

◆ SUBWORD32

#define SUBWORD32 (   OPERAND,
  ELEMENT 
)    (io[(OPERAND) - 1]->wordElement(ELEMENT))

Definition at line 331 of file OSAL.hh.

◆ SUBWORD8

#define SUBWORD8 (   OPERAND,
  ELEMENT 
)    (io[(OPERAND) - 1]->byteElement(ELEMENT))

Definition at line 327 of file OSAL.hh.

◆ TRIGGER

#define TRIGGER
Value:
bool simulateTrigger( \
SimValue** io, \
OperationContext& context) const { \
(void)context; \
if (io == 0) { }

Simulation function definition macros.

Each simulation function fetches the state instance using fetchState() in the beginning of the function definition. Starts the definition block for a trigger simulation function.

"if (&context ..." is an ugly hack to avoid compiler warning when context is not used.

Definition at line 261 of file OSAL.hh.

◆ UINT

#define UINT (   OPERAND)    (io[(OPERAND) - 1]->unsignedValue())

Definition at line 313 of file OSAL.hh.

◆ ULONG

#define ULONG (   OPERAND)    (io[(OPERAND) - 1]->uLongWordValue())

Definition at line 315 of file OSAL.hh.

◆ ZERO_EXTEND

#define ZERO_EXTEND (   VALUE,
  WIDTH 
)    ((ULongWord(VALUE) << (64-(WIDTH))) >> (64-(WIDTH)))

Zero extends the given integer.

Zero extension means that the extra bits of the wider target destination word are set to zero.

Example:

SRC: 1 0010b (5 bits) DST: 0001 0010b (8 bits)

The first argument is the integer that should be zero extended. Second argument is the bit width of the source argument. In the previous example, the bit width is 5. This is used to figure out which bits to reset in the destination. Returns a zero extended (to 64 bits) IntWord.

Definition at line 446 of file OSAL.hh.

OperationState
Definition: OperationState.hh:46
OperationContext
Definition: OperationContext.hh:56
SimValue
Definition: SimValue.hh:96
NullOperationState::instance
static NullOperationState * instance()
NullOperationState
Definition: OperationState.hh:63
OperationState::name
virtual const char * name()=0
Operation
Definition: Operation.hh:59
OperationGlobals::runtimeError
static void runtimeError(const char *message, const char *file, int line, const Operation &parent)
Definition: OperationGlobals.cc:73
OperationBehavior::InputOperandVector
std::vector< SimValue > InputOperandVector
Input operand type for areValid()
Definition: OperationBehavior.hh:57
OperationBehavior
Definition: OperationBehavior.hh:53
Operation::behavior
virtual OperationBehavior & behavior() const
Definition: Operation.cc:388
OperationPool
Definition: OperationPool.hh:52