OpenCores
URL https://opencores.org/ocsvn/or2k/or2k/trunk

Subversion Repositories or2k

[/] [or2k/] [trunk/] [analysis-bin/] [insnanalysis/] [or1k-32-insn.h] - Blame information for rev 21

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 17 julius
/*
2
  Or1K instruction set-specific decoding and analysis functions.
3 16 julius
 
4 17 julius
  Julius Baxter, julius.baxter@orsoc.se
5 16 julius
 
6 17 julius
*/
7 16 julius
 
8
 
9 17 julius
 
10 16 julius
// Struct for information about the register to be confugred
11
// Set to 1 to enable
12
struct or1k_32_instruction_properties
13
{
14
  int has_jumptarg;
15
  int has_branchtarg;
16
 
17
  int has_imm;
18
  int has_split_imm;
19
 
20
  int has_rD;
21
  int has_rA;
22
  int has_rB;
23
 
24
  char *insn_string;
25 18 julius
  int insn_index;
26 16 julius
 
27
};
28
 
29 19 julius
 
30
// Structs for internal statistics keeping
31
 
32
struct or1k_value_list
33
{
34
 
35
#define OR1K_VALUE_MAX_ENTRIES 64
36
  int count;
37
  // [value][occurances_of_value]
38
  int32_t values[OR1K_VALUE_MAX_ENTRIES][2];
39
 
40
};
41
 
42
struct or1k_insn_info
43
{
44
  char* insn_string;
45
 
46
  int count;
47
 
48
  int has_branchtarg;
49
  struct or1k_value_list branch_info;
50
 
51
  int has_imm;
52
  struct or1k_value_list imm_info;
53
 
54
  int has_rD;
55
  int rD_use_freq[32];
56
  int has_rA;
57
  int rA_use_freq[32];
58
  int has_rB;
59
  int rB_use_freq[32];
60
 
61
  // Set maximum instructions in a row we'll keep track of, starting at pairs
62
#define OR1K_MAX_GROUPINGS_ANALYSIS 4
63 21 julius
#define OR1K_MAX_ENTRIES_PER_GROUP 300
64 19 julius
  // Format of grouping data:
65
  //
66
  // 1st dimension: A list for each n-tuple group we're keeping track of 
67
  // (starting at pairs of instructions)
68
  //
69
  // 2nd dimension: Stores the list entries for the 1st dimension-tuple 
70
  // grouping. The number in [x][0][0] is the number of entries in the list so 
71
  // far, beginning at 0. The actual entries with data for grouping x start at 
72
  // [x][1][], where that entry holds the 1st x+2-tuple grouping information 
73
  // (eg. at x=0, [0][1][] is the first entry for/ pair instruction 
74
  // information, x=1, is for triples, x=2 quadruples, etc)
75
  //
76
  // 3rd dimension: Store up to x+2 instruction indexes (where x is the first 
77
  // dimension index, meaning this particular data is for a (x+2)-tuple set) 
78
  // and then a frequency count for this set (in index (x+2) of the third 
79
  // dimension array). Note we will have the index for the instruction this 
80
  // struct corresponds to in [x][n][(x+2)-1], which seems redundant, but can 
81
  // help processing later on. The final entry after the instruction indexes
82
  // is the occurance count for this particular set (at [x][n][x+2])
83
  // 
84
  // Note that we will have empty entries in the third dimension arrays for all
85
  // but the last in the list of n-tuples. This is to save doing tricky naming
86
  // defines and, in the future, if we would like to analyse sets that are 
87
  // bigger or smaller, hopefully all we need to do is change a single define.
88
  //
89
  int groupings[OR1K_MAX_GROUPINGS_ANALYSIS][OR1K_MAX_ENTRIES_PER_GROUP+1][OR1K_MAX_GROUPINGS_ANALYSIS+1];
90
 
91
};
92
 
93
// This number should correspond to the maximum insn_index we assign in the 
94
// analyse function
95
#define OR1K_32_MAX_INSNS 117
96
extern struct or1k_insn_info * or1k_32_insns[OR1K_32_MAX_INSNS];
97
 
98
 
99 17 julius
// OpenRISC 1000 32-bit instruction defines, helping us
100
// extract fields of the instructions
101
 
102 16 julius
// Instruction decode/set its options
103
int or1k_32_analyse_insn(uint32_t insn,
104
                         struct or1k_32_instruction_properties *insn_props);
105
 
106
 
107
// Stat collection entry-oint
108
void or1k_32_collect_stats(uint32_t insn,
109
                           struct or1k_32_instruction_properties  * insn_props);
110
 
111
 
112
// List management/analysis functions
113
// Reset lists
114
void or1k_32_insn_lists_init(void);
115
 
116
// Add the stats for this one
117 18 julius
void or1k_32_insn_lists_add(uint32_t insn,
118 16 julius
                            struct or1k_32_instruction_properties *insn_props);
119
 
120 19 julius
// Record the occurance of a group of instructions
121
void or1k_32_ntuple_add(int n,
122
                        struct or1k_32_instruction_properties *insn_props);
123
 
124 17 julius
// Print out some useful information
125
void or1k_32_generate_stats(FILE * stream);
126
 
127 16 julius
// Free lists
128
void or1k_32_insn_lists_free(void);
129
 
130
#define JUMPTARG_MASK 0x3ffffff
131
 
132
#define insn_or1k_opcode(x) (x>>26 & 0x3f)
133
 
134
#define insn_or1k_32_rD(x) (((x>>21)&0x1f))
135
#define insn_or1k_32_rA(x) (((x>>16)&0x1f))
136
#define insn_or1k_32_rB(x) (((x>>11)&0x1f))
137
#define insn_or1k_32_imm(x) (x&0xffff)
138
#define insn_or1k_32_split_imm(x) ((((x>>21)&0x1f)<<11)|(x&0x7ff))
139
 
140
#define insn_or1k_opcode_0x00_get_jumptarg(x) (x&JUMPTARG_MASK)
141
 
142
#define insn_or1k_opcode_0x01_get_jumptarg(x) (x&JUMPTARG_MASK)
143
 
144
#define insn_or1k_opcode_0x03_get_branchoff(x) (x&JUMPTARG_MASK)
145
 
146
#define insn_or1k_opcode_0x04_get_branchoff(x) (x&JUMPTARG_MASK)
147
 
148
#define insn_or1k_opcode_0x05_get_noop_id(x) ((x>>24) & 0x3)
149
#define insn_or1k_opcode_0x05_get_imm(x) insn_or1k_32_imm(x)
150
 
151
#define insn_or1k_opcode_0x06_get_rD(x) insn_or1k_32_rD(x)
152
#define insn_or1k_opcode_0x06_get_id(x) ((x>>16) & 0x1)
153
#define insn_or1k_opcode_0x06_get_imm(x) insn_or1k_32_imm(x)
154
 
155
/* N/A: opcode 0x7 */
156
 
157
#define insn_or1k_opcode_0x08_get_id(x) ((x>>23)&0x7)
158
#define insn_or1k_opcode_0x08_get_imm(x) insn_or1k_32_imm(x)
159
 
160
#define insn_or1k_opcode_0x0a_get_rD(x) insn_or1k_32_rD(x)
161
#define insn_or1k_opcode_0x0a_get_rA(x) insn_or1k_32_rA(x)
162
#define insn_or1k_opcode_0x0a_get_rB(x) insn_or1k_32_rB(x)
163
#define insn_or1k_opcode_0x0a_get_op_hi(x) ((x>>4)&0xf)
164
#define insn_or1k_opcode_0x0a_get_op_lo(x) (x&0xf)
165
 
166
/* N/A: opcodes 0xb,c,d,e,f,10 */
167
 
168
#define insn_or1k_opcode_0x11_get_rB(x)  insn_or1k_32_rB(x)
169
 
170
#define insn_or1k_opcode_0x12_get_rB(x)  insn_or1k_32_rB(x)
171
 
172
#define insn_or1k_opcode_0x13_get_rA(x) insn_or1k_32_rA(x)
173
#define insn_or1k_opcode_0x13_get_imm(x) insn_or1k_32_split_imm(x)
174
 
175
/* N/A: opcodes 0x14,15, 16, 17, 18, 19, 1a, 1b */
176
 
177
#define insn_or1k_opcode_0x20_get_rD(x) insn_or1k_32_rD(x)
178
#define insn_or1k_opcode_0x20_get_rA(x) insn_or1k_32_rA(x)
179
#define insn_or1k_opcode_0x20_get_imm(x) insn_or1k_32_imm(x)
180
 
181
 
182
#define insn_or1k_opcode_0x21_get_rD(x) insn_or1k_32_rD(x)
183
#define insn_or1k_opcode_0x21_get_rA(x) insn_or1k_32_rA(x)
184
#define insn_or1k_opcode_0x21_get_imm(x) insn_or1k_32_imm(x)
185
 
186
 
187
#define insn_or1k_opcode_0x22_get_rD(x) insn_or1k_32_rD(x)
188
#define insn_or1k_opcode_0x22_get_rA(x) insn_or1k_32_rA(x)
189
#define insn_or1k_opcode_0x22_get_imm(x) insn_or1k_32_imm(x)
190
 
191
 
192
#define insn_or1k_opcode_0x23_get_rD(x) insn_or1k_32_rD(x)
193
#define insn_or1k_opcode_0x23_get_rA(x) insn_or1k_32_rA(x)
194
#define insn_or1k_opcode_0x23_get_imm(x) insn_or1k_32_imm(x)
195
 
196
 
197
#define insn_or1k_opcode_0x24_get_rD(x) insn_or1k_32_rD(x)
198
#define insn_or1k_opcode_0x24_get_rA(x) insn_or1k_32_rA(x)
199
#define insn_or1k_opcode_0x24_get_imm(x) insn_or1k_32_imm(x)
200
 
201
 
202
#define insn_or1k_opcode_0x25_get_rD(x) insn_or1k_32_rD(x)
203
#define insn_or1k_opcode_0x25_get_rA(x) insn_or1k_32_rA(x)
204
#define insn_or1k_opcode_0x25_get_imm(x) insn_or1k_32_imm(x)
205
 
206
 
207
#define insn_or1k_opcode_0x26_get_rD(x) insn_or1k_32_rD(x)
208
#define insn_or1k_opcode_0x26_get_rA(x) insn_or1k_32_rA(x)
209
#define insn_or1k_opcode_0x26_get_imm(x) insn_or1k_32_imm(x)
210
 
211
 
212
#define insn_or1k_opcode_0x27_get_rD(x) insn_or1k_32_rD(x)
213
#define insn_or1k_opcode_0x27_get_rA(x) insn_or1k_32_rA(x)
214
#define insn_or1k_opcode_0x27_get_imm(x) insn_or1k_32_imm(x)
215
 
216
#define insn_or1k_opcode_0x28_get_rD(x) insn_or1k_32_rD(x)
217
#define insn_or1k_opcode_0x28_get_rA(x) insn_or1k_32_rA(x)
218
#define insn_or1k_opcode_0x28_get_imm(x) insn_or1k_32_imm(x)
219
 
220
 
221
#define insn_or1k_opcode_0x29_get_rD(x) insn_or1k_32_rD(x)
222
#define insn_or1k_opcode_0x29_get_rA(x) insn_or1k_32_rA(x)
223
#define insn_or1k_opcode_0x29_get_imm(x) insn_or1k_32_imm(x)
224
 
225
 
226
#define insn_or1k_opcode_0x2a_get_rD(x) insn_or1k_32_rD(x)
227
#define insn_or1k_opcode_0x2a_get_rA(x) insn_or1k_32_rA(x)
228
#define insn_or1k_opcode_0x2a_get_imm(x) insn_or1k_32_imm(x)
229
 
230
 
231
#define insn_or1k_opcode_0x2b_get_rD(x) insn_or1k_32_rD(x)
232
#define insn_or1k_opcode_0x2b_get_rA(x) insn_or1k_32_rA(x)
233
#define insn_or1k_opcode_0x2b_get_imm(x) insn_or1k_32_imm(x)
234
 
235
 
236
#define insn_or1k_opcode_0x2c_get_rD(x) insn_or1k_32_rD(x)
237
#define insn_or1k_opcode_0x2c_get_rA(x) insn_or1k_32_rA(x)
238
#define insn_or1k_opcode_0x2c_get_imm(x) insn_or1k_32_imm(x)
239
 
240
 
241
#define insn_or1k_opcode_0x2d_get_rD(x) insn_or1k_32_rD(x)
242
#define insn_or1k_opcode_0x2d_get_rA(x) insn_or1k_32_rA(x)
243
#define insn_or1k_opcode_0x2d_get_imm(x) insn_or1k_32_imm(x)
244
 
245
 
246
#define insn_or1k_opcode_0x2e_get_rD(x) insn_or1k_32_rD(x)
247
#define insn_or1k_opcode_0x2e_get_rA(x) insn_or1k_32_rA(x)
248
#define insn_or1k_opcode_0x2e_get_op(x) ((x>>6)&0x3)
249
#define insn_or1k_opcode_0x2e_get_imm(x) ((x&3f))
250
 
251
 
252
#define insn_or1k_opcode_0x2f_get_op(x) insn_or1k_32_rD(x)
253
#define insn_or1k_opcode_0x2f_get_rA(x) insn_or1k_32_rA(x)
254
#define insn_or1k_opcode_0x2f_get_imm(x) insn_or1k_32_imm(x)
255
 
256
 
257
#define insn_or1k_opcode_0x30_get_rA(x) insn_or1k_32_rA(x)
258
#define insn_or1k_opcode_0x30_get_rB(x) insn_or1k_32_rB(x)
259
#define insn_or1k_opcode_0x30_get_imm(x) insn_or1k_32_split_imm(x)
260
 
261
 
262
#define insn_or1k_opcode_0x31_get_rA(x) insn_or1k_32_rA(x)
263
#define insn_or1k_opcode_0x31_get_rB(x) insn_or1k_32_rB(x)
264
#define insn_or1k_opcode_0x31_get_op(x) (x&0xf)
265
 
266
 
267
#define insn_or1k_opcode_0x32_get_rD(x) insn_or1k_32_rD(x)
268
#define insn_or1k_opcode_0x32_get_rA(x) insn_or1k_32_rA(x)
269
#define insn_or1k_opcode_0x32_get_rB(x) insn_or1k_32_rB(x)
270
#define insn_or1k_opcode_0x32_get_op_hi(x) ((x>>4)&0xf)
271
#define insn_or1k_opcode_0x32_get_op_lo(x) ((x&0xf))
272
 
273
/* N/A: opcodes 0x33 */
274
 
275
#define insn_or1k_opcode_0x34_get_rD(x) insn_or1k_32_rA(x)
276
#define insn_or1k_opcode_0x34_get_rB(x) insn_or1k_32_rB(x)
277
#define insn_or1k_opcode_0x34_get_imm(x) insn_or1k_32_split_imm(x)
278
 
279
 
280
#define insn_or1k_opcode_0x35_get_rD(x) insn_or1k_32_rA(x)
281
#define insn_or1k_opcode_0x35_get_rB(x) insn_or1k_32_rB(x)
282
#define insn_or1k_opcode_0x35_get_imm(x) insn_or1k_32_split_imm(x)
283
 
284
 
285
#define insn_or1k_opcode_0x36_get_rD(x) insn_or1k_32_rA(x)
286
#define insn_or1k_opcode_0x36_get_rB(x) insn_or1k_32_rB(x)
287
#define insn_or1k_opcode_0x36_get_imm(x) insn_or1k_32_split_imm(x)
288
 
289
 
290
#define insn_or1k_opcode_0x37_get_rD(x) insn_or1k_32_rA(x)
291
#define insn_or1k_opcode_0x37_get_rB(x) insn_or1k_32_rB(x)
292
#define insn_or1k_opcode_0x37_get_imm(x) insn_or1k_32_split_imm(x)
293
 
294
 
295
#define insn_or1k_opcode_0x38_get_rD(x) insn_or1k_32_rD(x)
296
#define insn_or1k_opcode_0x38_get_rA(x) insn_or1k_32_rA(x)
297
#define insn_or1k_opcode_0x38_get_rB(x) insn_or1k_32_rB(x)
298
#define insn_or1k_opcode_0x38_get_op_hi_2bit(x) ((x>>8)&0x3)
299
#define insn_or1k_opcode_0x38_get_op_hi_4bit(x) ((x>>6)&0xf)
300
#define insn_or1k_opcode_0x38_get_op_lo(x) ((x&0xf))
301
 
302
#define insn_or1k_opcode_0x39_get_op(x) insn_or1k_32_rD(x)
303
#define insn_or1k_opcode_0x39_get_rA(x) insn_or1k_32_rA(x)
304
#define insn_or1k_opcode_0x39_get_rB(x) insn_or1k_32_rB(x)
305
 
306
/* N/A: opcodes 0x3a,3b */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.