~ubuntu-branches/ubuntu/precise/mysql-5.5/precise-201203300109

« back to all changes in this revision

Viewing changes to storage/ndb/include/kernel/Interpreter.hpp

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2011-11-08 11:31:13 UTC
  • Revision ID: package-import@ubuntu.com-20111108113113-3ulw01fvi4vn8m25
Tags: upstream-5.5.17
ImportĀ upstreamĀ versionĀ 5.5.17

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2003 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
#ifndef NDB_INTERPRETER_HPP
 
17
#define NDB_INTERPRETER_HPP
 
18
 
 
19
#include <ndb_types.h>
 
20
 
 
21
class Interpreter {
 
22
public:
 
23
 
 
24
  inline static Uint32 mod4(Uint32 len){
 
25
    return len + ((4 - (len & 3)) & 3);
 
26
  }
 
27
  
 
28
 
 
29
  /**
 
30
   * General Mnemonic format
 
31
   *
 
32
   * i = Instruction            -  5 Bits ( 0 - 5 ) max 63
 
33
   * x = Register 1             -  3 Bits ( 6 - 8 ) max 7
 
34
   * y = Register 2             -  3 Bits ( 9 -11 ) max 7
 
35
   * b = Branch offset (only branches)
 
36
   *
 
37
   *           1111111111222222222233
 
38
   * 01234567890123456789012345678901
 
39
   * iiiiiixxxyyy    bbbbbbbbbbbbbbbb
 
40
   *
 
41
   *
 
42
   */
 
43
 
 
44
  /**
 
45
   * Instructions
 
46
   */
 
47
  STATIC_CONST( READ_ATTR_INTO_REG    = 1 );
 
48
  STATIC_CONST( WRITE_ATTR_FROM_REG   = 2 );
 
49
  STATIC_CONST( LOAD_CONST_NULL       = 3 );
 
50
  STATIC_CONST( LOAD_CONST16          = 4 );
 
51
  STATIC_CONST( LOAD_CONST32          = 5 );
 
52
  STATIC_CONST( LOAD_CONST64          = 6 );
 
53
  STATIC_CONST( ADD_REG_REG           = 7 );
 
54
  STATIC_CONST( SUB_REG_REG           = 8 );
 
55
  STATIC_CONST( BRANCH                = 9 );
 
56
  STATIC_CONST( BRANCH_REG_EQ_NULL    = 10 );
 
57
  STATIC_CONST( BRANCH_REG_NE_NULL    = 11 );
 
58
  STATIC_CONST( BRANCH_EQ_REG_REG     = 12 );
 
59
  STATIC_CONST( BRANCH_NE_REG_REG     = 13 );
 
60
  STATIC_CONST( BRANCH_LT_REG_REG     = 14 );
 
61
  STATIC_CONST( BRANCH_LE_REG_REG     = 15 );
 
62
  STATIC_CONST( BRANCH_GT_REG_REG     = 16 );
 
63
  STATIC_CONST( BRANCH_GE_REG_REG     = 17 );
 
64
  STATIC_CONST( EXIT_OK               = 18 );
 
65
  STATIC_CONST( EXIT_REFUSE           = 19 );
 
66
  STATIC_CONST( CALL                  = 20 );
 
67
  STATIC_CONST( RETURN                = 21 );
 
68
  STATIC_CONST( EXIT_OK_LAST          = 22 );
 
69
  STATIC_CONST( BRANCH_ATTR_OP_ARG    = 23 );
 
70
  STATIC_CONST( BRANCH_ATTR_EQ_NULL   = 24 );
 
71
  STATIC_CONST( BRANCH_ATTR_NE_NULL   = 25 );
 
72
  
 
73
  /**
 
74
   * Macros for creating code
 
75
   */
 
76
  static Uint32 Read(Uint32 AttrId, Uint32 Register);
 
77
  static Uint32 Write(Uint32 AttrId, Uint32 Register);
 
78
  
 
79
  static Uint32 LoadNull(Uint32 Register);
 
80
  static Uint32 LoadConst16(Uint32 Register, Uint32 Value);
 
81
  static Uint32 LoadConst32(Uint32 Register); // Value in next word
 
82
  static Uint32 LoadConst64(Uint32 Register); // Value in next 2 words
 
83
  static Uint32 Add(Uint32 DstReg, Uint32 SrcReg1, Uint32 SrcReg2);
 
84
  static Uint32 Sub(Uint32 DstReg, Uint32 SrcReg1, Uint32 SrcReg2);
 
85
  static Uint32 Branch(Uint32 Inst, Uint32 Reg1, Uint32 Reg2);
 
86
  static Uint32 ExitOK();
 
87
 
 
88
  /**
 
89
   * Branch string
 
90
   *
 
91
   * i = Instruction            -  5 Bits ( 0 - 5 ) max 63
 
92
   * a = Attribute id
 
93
   * l = Length of string
 
94
   * b = Branch offset
 
95
   * t = branch type
 
96
   * d = Array length diff
 
97
   * v = Varchar flag
 
98
   * p = No-blank-padding flag for char compare
 
99
   *
 
100
   *           1111111111222222222233
 
101
   * 01234567890123456789012345678901
 
102
   * iiiiii   ddvtttpbbbbbbbbbbbbbbbb
 
103
   * aaaaaaaaaaaaaaaallllllllllllllll
 
104
   * -string....                    -
 
105
   */
 
106
  enum UnaryCondition {
 
107
    IS_NULL = 0,
 
108
    IS_NOT_NULL = 1
 
109
  };
 
110
 
 
111
  enum BinaryCondition {
 
112
    EQ = 0,
 
113
    NE = 1,
 
114
    LT = 2,
 
115
    LE = 3,
 
116
    GT = 4,
 
117
    GE = 5,
 
118
    LIKE = 6,
 
119
    NOT_LIKE = 7
 
120
  };
 
121
  static Uint32 BranchCol(BinaryCondition cond, 
 
122
                          Uint32 arrayLengthDiff, Uint32 varchar, bool nopad);
 
123
  static Uint32 BranchCol_2(Uint32 AttrId);
 
124
  static Uint32 BranchCol_2(Uint32 AttrId, Uint32 Len);
 
125
 
 
126
  static Uint32 getBinaryCondition(Uint32 op1);
 
127
  static Uint32 getArrayLengthDiff(Uint32 op1);
 
128
  static Uint32 isVarchar(Uint32 op1);
 
129
  static Uint32 isNopad(Uint32 op1);
 
130
  static Uint32 getBranchCol_AttrId(Uint32 op2);
 
131
  static Uint32 getBranchCol_Len(Uint32 op2);
 
132
  
 
133
  /**
 
134
   * Macros for decoding code
 
135
   */
 
136
  static Uint32 getOpCode(Uint32 op);
 
137
  static Uint32 getReg1(Uint32 op);
 
138
  static Uint32 getReg2(Uint32 op);
 
139
  static Uint32 getReg3(Uint32 op);
 
140
};
 
141
 
 
142
inline
 
143
Uint32
 
144
Interpreter::Read(Uint32 AttrId, Uint32 Register){
 
145
  return (AttrId << 16) + (Register << 6) + READ_ATTR_INTO_REG;
 
146
}
 
147
 
 
148
inline
 
149
Uint32
 
150
Interpreter::Write(Uint32 AttrId, Uint32 Register){
 
151
  return (AttrId << 16) + (Register << 6) + WRITE_ATTR_FROM_REG;
 
152
}
 
153
 
 
154
inline
 
155
Uint32
 
156
Interpreter::LoadConst16(Uint32 Register, Uint32 Value){
 
157
  return (Value << 16) + (Register << 6) + LOAD_CONST16;
 
158
}
 
159
 
 
160
inline
 
161
Uint32
 
162
Interpreter::LoadConst32(Uint32 Register){
 
163
  return (Register << 6) + LOAD_CONST32;
 
164
}
 
165
 
 
166
inline
 
167
Uint32
 
168
Interpreter::LoadConst64(Uint32 Register){
 
169
  return (Register << 6) + LOAD_CONST64;
 
170
}
 
171
 
 
172
inline
 
173
Uint32
 
174
Interpreter::Add(Uint32 Dcoleg, Uint32 SrcReg1, Uint32 SrcReg2){
 
175
  return (SrcReg1 << 6) + (SrcReg2 << 9) + (Dcoleg << 16) + ADD_REG_REG;
 
176
}
 
177
 
 
178
inline
 
179
Uint32
 
180
Interpreter::Sub(Uint32 Dcoleg, Uint32 SrcReg1, Uint32 SrcReg2){
 
181
  return (SrcReg1 << 6) + (SrcReg2 << 9) + (Dcoleg << 16) + SUB_REG_REG;
 
182
}
 
183
 
 
184
inline
 
185
Uint32
 
186
Interpreter::Branch(Uint32 Inst, Uint32 Reg1, Uint32 Reg2){
 
187
  return (Reg1 << 9) + (Reg2 << 6) + Inst;
 
188
}
 
189
 
 
190
inline
 
191
Uint32
 
192
Interpreter::BranchCol(BinaryCondition cond, 
 
193
                       Uint32 arrayLengthDiff,
 
194
                       Uint32 varchar, bool nopad){
 
195
  //ndbout_c("BranchCol: cond=%d diff=%u varchar=%u nopad=%d",
 
196
      //cond, arrayLengthDiff, varchar, nopad);
 
197
  return 
 
198
    BRANCH_ATTR_OP_ARG + 
 
199
    (arrayLengthDiff << 9) + 
 
200
    (varchar << 11) +
 
201
    (cond << 12) +
 
202
    (nopad << 15);
 
203
}
 
204
 
 
205
inline
 
206
Uint32 
 
207
Interpreter::BranchCol_2(Uint32 AttrId, Uint32 Len){
 
208
  return (AttrId << 16) + Len;
 
209
}
 
210
 
 
211
inline
 
212
Uint32 
 
213
Interpreter::BranchCol_2(Uint32 AttrId){
 
214
  return (AttrId << 16);
 
215
}
 
216
 
 
217
inline
 
218
Uint32
 
219
Interpreter::getBinaryCondition(Uint32 op){
 
220
  return (op >> 12) & 0x7;
 
221
}
 
222
 
 
223
inline
 
224
Uint32
 
225
Interpreter::getArrayLengthDiff(Uint32 op){
 
226
  return (op >> 9) & 0x3;
 
227
}
 
228
 
 
229
inline
 
230
Uint32
 
231
Interpreter::isVarchar(Uint32 op){
 
232
  return (op >> 11) & 1;
 
233
}
 
234
 
 
235
inline
 
236
Uint32
 
237
Interpreter::isNopad(Uint32 op){
 
238
  return (op >> 15) & 1;
 
239
}
 
240
 
 
241
inline
 
242
Uint32
 
243
Interpreter::getBranchCol_AttrId(Uint32 op){
 
244
  return (op >> 16) & 0xFFFF;
 
245
}
 
246
 
 
247
inline
 
248
Uint32
 
249
Interpreter::getBranchCol_Len(Uint32 op){
 
250
  return op & 0xFFFF;
 
251
}
 
252
 
 
253
inline
 
254
Uint32
 
255
Interpreter::ExitOK(){
 
256
  return EXIT_OK;
 
257
}
 
258
 
 
259
inline
 
260
Uint32
 
261
Interpreter::getOpCode(Uint32 op){
 
262
  return op & 0x3f;
 
263
}
 
264
 
 
265
inline
 
266
Uint32
 
267
Interpreter::getReg1(Uint32 op){
 
268
  return (op >> 6) & 0x7;
 
269
}
 
270
 
 
271
inline
 
272
Uint32
 
273
Interpreter::getReg2(Uint32 op){
 
274
  return (op >> 9) & 0x7;
 
275
}
 
276
 
 
277
inline
 
278
Uint32
 
279
Interpreter::getReg3(Uint32 op){
 
280
  return (op >> 16) & 0x7;
 
281
}
 
282
 
 
283
#endif