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 28

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