OpenASIP
2.0
|
#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"
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 |
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.
Definition in file OSAL.hh.
#define ADVANCE_CLOCK |
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.
#define BRANCH_DELAY_CYCLES (context.branchDelayCycles()) |
#define CONTEXT_ID (context.contextId()) |
#define CYCLE_COUNT (context.cycleCount()) |
#define DECLARE_VALID return true |
#define DEFINE_STATE | ( | 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.
#define END_ADVANCE_CLOCK } |
#define END_INPUT_VALIDATION |
#define END_OPERATION | ( | OPNAME | ) |
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.
#define END_OPERATION_WITH_STATE | ( | OPNAME | ) | END_OPERATION(OPNAME) |
#define END_TRIGGER return true; } |
#define EXEC_OPERATION | ( | OPNAME, | |
... | |||
) |
#define FINALIZE_STATE | ( | STATE_NAME | ) | public: ~STATE_NAME##_State() { |
#define FU_NAME (context.functionUnitName()) |
Returns the function unit name associated to the OperationContext.
#define INIT_STATE | ( | STATE_NAME | ) |
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.
#define INPUT_VALIDATION |
Opening macro for user defined input validation code.
#define MAU_SIZE (context.memory().MAUSize()) |
#define MEMORY context.memory() |
#define OP | ( | OPNAME, | |
... | |||
) |
#define OPERATION | ( | OPNAME | ) |
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.
#define OPERATION_COMMON | ( | OPNAME | ) |
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:
#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.
#define OSAL_WORD_WIDTH sizeof(ULongWord) * BYTE_BITWIDTH |
#define OUTPUT_STREAM OperationGlobals::outputStream() |
#define PROGRAM_COUNTER (context.programCounter()) |
#define RETURN_ADDRESS (context.returnAddress()) |
#define RETURN_READY |
#define RUNTIME_ERROR | ( | MESSAGE | ) |
Causes runtime error with given error explanation message.
Can be used to abort simulation in case of illegal operands etc.
#define SAVE_RETURN_ADDRESS context.setSaveReturnAddress(true) |
#define SET_PROGRAM_COUNTER | ( | PCVAL | ) |
#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.
#define STATE (*fetchState(context)) |
#define TRIGGER |
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.
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.