18 #ifndef NDB_INTERPRETER_HPP 
   19 #define NDB_INTERPRETER_HPP 
   21 #include <ndb_types.h> 
   26   inline static Uint32 mod4(Uint32 len){
 
   27     return len + ((4 - (len & 3)) & 3);
 
   79   static Uint32 
Read(Uint32 AttrId, Uint32 Register);
 
   80   static Uint32 Write(Uint32 AttrId, Uint32 Register);
 
   82   static Uint32 LoadNull(Uint32 Register);
 
   83   static Uint32 LoadConst16(Uint32 Register, Uint32 Value);
 
   84   static Uint32 LoadConst32(Uint32 Register); 
 
   85   static Uint32 LoadConst64(Uint32 Register); 
 
   86   static Uint32 Add(Uint32 DstReg, Uint32 SrcReg1, Uint32 SrcReg2);
 
   87   static Uint32 Sub(Uint32 DstReg, Uint32 SrcReg1, Uint32 SrcReg2);
 
   88   static Uint32 Branch(Uint32 Inst, Uint32 Reg1, Uint32 Reg2);
 
   89   static Uint32 ExitOK();
 
  114   enum BinaryCondition {
 
  129   static Uint32 BranchCol(BinaryCondition cond, 
 
  130                           Uint32 arrayLengthDiff, Uint32 varchar);
 
  131   static Uint32 BranchCol_2(Uint32 AttrId);
 
  132   static Uint32 BranchCol_2(Uint32 AttrId, Uint32 Len);
 
  134   static Uint32 BranchColParameter(BinaryCondition cond);
 
  135   static Uint32 BranchColParameter_2(Uint32 AttrId, Uint32 ParamNo);
 
  137   static Uint32 getBinaryCondition(Uint32 op1);
 
  138   static Uint32 getArrayLengthDiff(Uint32 op1);
 
  139   static Uint32 isVarchar(Uint32 op1);
 
  140   static Uint32 getBranchCol_AttrId(Uint32 op2);
 
  141   static Uint32 getBranchCol_Len(Uint32 op2);
 
  142   static Uint32 getBranchCol_ParamNo(Uint32 op2);
 
  148   static Uint32 getReg1(Uint32 op);
 
  149   static Uint32 getReg2(Uint32 op);
 
  150   static Uint32 getReg3(Uint32 op);
 
  151   static Uint32 getLabel(Uint32 op);
 
  159     LABEL_ADDRESS_REPLACEMENT,
 
  160     SUB_ADDRESS_REPLACEMENT
 
  167   static Uint32 *getInstructionPreProcessingInfo(Uint32 *op,
 
  174   return (AttrId << 16) + (Register << 6) + READ_ATTR_INTO_REG;
 
  179 Interpreter::Write(Uint32 AttrId, Uint32 Register){
 
  180   return (AttrId << 16) + (Register << 6) + WRITE_ATTR_FROM_REG;
 
  185 Interpreter::LoadNull(Uint32 Register){
 
  186   return (Register << 6) + LOAD_CONST_NULL;
 
  191 Interpreter::LoadConst16(Uint32 Register, Uint32 Value){
 
  192   return (Value << 16) + (Register << 6) + LOAD_CONST16;
 
  197 Interpreter::LoadConst32(Uint32 Register){
 
  198   return (Register << 6) + LOAD_CONST32;
 
  203 Interpreter::LoadConst64(Uint32 Register){
 
  204   return (Register << 6) + LOAD_CONST64;
 
  209 Interpreter::Add(Uint32 Dcoleg, Uint32 SrcReg1, Uint32 SrcReg2){
 
  210   return (SrcReg1 << 6) + (SrcReg2 << 9) + (Dcoleg << 16) + ADD_REG_REG;
 
  215 Interpreter::Sub(Uint32 Dcoleg, Uint32 SrcReg1, Uint32 SrcReg2){
 
  216   return (SrcReg1 << 6) + (SrcReg2 << 9) + (Dcoleg << 16) + SUB_REG_REG;
 
  221 Interpreter::Branch(Uint32 Inst, Uint32 Reg1, Uint32 Reg2){
 
  222   return (Reg1 << 9) + (Reg2 << 6) + Inst;
 
  227 Interpreter::BranchCol(BinaryCondition cond, 
 
  228                        Uint32 arrayLengthDiff,
 
  234     (arrayLengthDiff << 9) + 
 
  241 Interpreter::BranchColParameter(BinaryCondition cond)
 
  243   return BRANCH_ATTR_OP_ARG_2 + (cond << 12);
 
  248 Interpreter::BranchColParameter_2(Uint32 AttrId, Uint32 ParamNo){
 
  249   return (AttrId << 16) + ParamNo;
 
  254 Interpreter::BranchCol_2(Uint32 AttrId, Uint32 Len){
 
  255   return (AttrId << 16) + Len;
 
  260 Interpreter::BranchCol_2(Uint32 AttrId){
 
  261   return (AttrId << 16);
 
  266 Interpreter::getBinaryCondition(Uint32 op){
 
  267   return (op >> 12) & 0xf;
 
  272 Interpreter::getArrayLengthDiff(Uint32 op){
 
  273   return (op >> 9) & 0x3;
 
  278 Interpreter::isVarchar(Uint32 op){
 
  279   return (op >> 11) & 1;
 
  284 Interpreter::getBranchCol_AttrId(Uint32 op){
 
  285   return (op >> 16) & 0xFFFF;
 
  290 Interpreter::getBranchCol_Len(Uint32 op){
 
  296 Interpreter::getBranchCol_ParamNo(Uint32 op){
 
  302 Interpreter::ExitOK(){
 
  314 Interpreter::getReg1(Uint32 op){
 
  315   return (op >> 6) & 0x7;
 
  320 Interpreter::getReg2(Uint32 op){
 
  321   return (op >> 9) & 0x7;
 
  326 Interpreter::getReg3(Uint32 op){
 
  327   return (op >> 16) & 0x7;
 
  332 Interpreter::getLabel(Uint32 op){
 
  333   return (op >> 16) & 0xffff;
 
  338 Interpreter::getInstructionPreProcessingInfo(Uint32 *op,
 
  339                                              InstructionPreProcessing& processing )
 
  350   case READ_ATTR_INTO_REG:
 
  351   case WRITE_ATTR_FROM_REG:
 
  352   case LOAD_CONST_NULL:
 
  363   case BRANCH_REG_EQ_NULL:
 
  364   case BRANCH_REG_NE_NULL:
 
  365   case BRANCH_EQ_REG_REG:
 
  366   case BRANCH_NE_REG_REG:
 
  367   case BRANCH_LT_REG_REG:
 
  368   case BRANCH_LE_REG_REG:
 
  369   case BRANCH_GT_REG_REG:
 
  370   case BRANCH_GE_REG_REG:
 
  371     processing= LABEL_ADDRESS_REPLACEMENT;
 
  373   case BRANCH_ATTR_OP_ARG:
 
  379     processing= LABEL_ADDRESS_REPLACEMENT;
 
  380     Uint32 byteLength= getBranchCol_Len(*(op+1));
 
  381     Uint32 wordLength= (byteLength + 3) >> 2;
 
  382     return op+2+wordLength;
 
  384   case BRANCH_ATTR_OP_ARG_2:
 
  390     processing= LABEL_ADDRESS_REPLACEMENT;
 
  393   case BRANCH_ATTR_EQ_NULL:
 
  394   case BRANCH_ATTR_NE_NULL:
 
  395     processing= LABEL_ADDRESS_REPLACEMENT;
 
  402     processing= SUB_ADDRESS_REPLACEMENT;