Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | /* |
2 | * ========== Copyright Header Begin ========================================== | |
3 | * | |
4 | * OpenSPARC T2 Processor File: SS_Decode.h | |
5 | * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. | |
6 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES. | |
7 | * | |
8 | * The above named program is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU General Public | |
10 | * License version 2 as published by the Free Software Foundation. | |
11 | * | |
12 | * The above named program is distributed in the hope that it will be | |
13 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public | |
18 | * License along with this work; if not, write to the Free Software | |
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. | |
20 | * | |
21 | * ========== Copyright Header End ============================================ | |
22 | */ | |
23 | #ifndef __SS_Decode_h__ | |
24 | #define __SS_Decode_h__ | |
25 | ||
26 | #include "SS_Opcode.h" | |
27 | #include "SS_Instr.h" | |
28 | #include "SS_Strand.h" | |
29 | ||
30 | // SS_DecodeGroup<SIZE> holds a group of instructions that need further | |
31 | // decoding after the {op:op3} decoding. The sft and msk specify the | |
32 | // left shift and mask to apply to the opcode to get a byte index into | |
33 | // the table tbl of further decode functions. | |
34 | ||
35 | template<int SIZE> class SS_DecodeGroup | |
36 | { | |
37 | public: | |
38 | uint16_t sft; | |
39 | uint16_t msk; | |
40 | SS_Decode tbl[SIZE]; | |
41 | ||
42 | SS_Decode decode( SS_Opcode o ) | |
43 | { | |
44 | // The number of entries in a decode group must be a power of two. | |
45 | assert(SIZE & (SIZE - 1) == 0); | |
46 | return *(SS_Decode*)((char*)tbl + ((uint64_t(o.get()) >> sft) & msk)); | |
47 | } | |
48 | }; | |
49 | ||
50 | // SS_Decoder is the top level decoder. It takes {op:op3} as the first | |
51 | // selection into a table of decode functions or decode tables | |
52 | ||
53 | // The SS_DecodeTable class provides the structure to decode | |
54 | // instructions. It roots the decode tree. Each level of the decode | |
55 | // tree contains both SS_Decode entries, which point to methods to | |
56 | // decode instructions and SS_DecodeGroup template entries, which | |
57 | // reference the next level in the decode tree. | |
58 | // | |
59 | // To distinguish between the two kinds of entries, the LSB of a | |
60 | // SS_DecodeGroup template address is set to 1. See ss_dec_tbl() and | |
61 | // dec_grp() below. | |
62 | ||
63 | ||
64 | #define ss_dec_tbl(p) (SS_Decode)((long)&p + 1) | |
65 | ||
66 | class SS_DecodeTable | |
67 | { | |
68 | public: | |
69 | SS_Decode decode( SS_Opcode o ) | |
70 | { | |
71 | SS_Decode d = *(SS_Decode*)((char*)table + ((o.get() >> ptr_sft(30 - 6)) & ptr_msk(3 << 6)) | |
72 | + ((o.get() >> ptr_sft(19)) & ptr_msk(0x3f))); | |
73 | if (dec_grp(d)) | |
74 | { | |
75 | d = tbl_ptr(d)->decode(o); | |
76 | if (dec_grp(d)) | |
77 | { | |
78 | d = tbl_ptr(d)->decode(o); | |
79 | } | |
80 | } | |
81 | return d; | |
82 | } | |
83 | ||
84 | template<int SIZE> | |
85 | void set( uint_t i, SS_DecodeGroup<SIZE>* d ) { assert(i<256); table[i] = dec_tbl(d); } | |
86 | void set( uint_t i, SS_Decode d ) { assert(i<256); table[i] = d; } | |
87 | ||
88 | SS_Decode table[256]; // Top level decode table for {op:op3} | |
89 | ||
90 | // dec_grp() returns true when p is a pointer to a SS_DecodeGroup | |
91 | bool dec_grp( SS_Decode p ) | |
92 | { | |
93 | return (long)p & 1; | |
94 | } | |
95 | ||
96 | // dec_tlb() casts and tags a SS_DecodeGroup pointer into a SS_Decode pointer | |
97 | template<int SIZE> SS_Decode dec_tbl( SS_DecodeGroup<SIZE>* p ) | |
98 | { | |
99 | return (SS_Decode)((long)p + 1); | |
100 | } | |
101 | ||
102 | // tbl_ptr() casts and untags a SS_Decode pointer into a SS_DecodeGroup pointer | |
103 | SS_DecodeGroup<1>* tbl_ptr( SS_Decode p ) | |
104 | { | |
105 | return (SS_DecodeGroup<1>*)((long)p - 1); | |
106 | } | |
107 | }; | |
108 | ||
109 | #endif | |
110 | ||
111 | ||
112 | ||
113 | ||
114 |