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

Subversion Repositories theia_gpu

[/] [theia_gpu/] [branches/] [beta_2.0/] [compiler/] [src/] [cp_compiler/] [Instruction.cpp] - Blame information for rev 216

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 216 diegovalve
 
2
/**********************************************************************************
3
Theia, Ray Cast Programable graphic Processing Unit.
4
Copyright (C) 2012  Diego Valverde (diego.valverde.g@gmail.com)
5
 
6
This program is free software; you can redistribute it and/or
7
modify it under the terms of the GNU General Public License
8
as published by the Free Software Foundation; either version 2
9
of the License, or (at your option) any later version.
10
 
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
GNU General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19
 
20
***********************************************************************************/
21
 
22
 
23
#include "Instruction.h"
24
#include <sstream>
25
#include <iostream>
26
#include <iomanip>
27
 
28
 
29
//--------------------------------------------------------------
30
template <std::size_t N >
31
inline void SetbitRange( std::bitset<N> & aBitset , unsigned int aEnd, unsigned int aStart, unsigned int aValue)
32
{
33
        unsigned long mask = 1;
34
        unsigned long result = 0;
35
        for (int i = aStart; i <= aEnd; ++i)
36
        {
37
                aBitset[i] =  ( mask & aValue );
38
                mask <<= 1;
39
        }
40
 
41
}
42
//--------------------------------------------------------------
43
template <std::size_t N >
44
inline unsigned int GetbitRange( std::bitset<N> & aBitset , unsigned int aEnd, unsigned int aStart)
45
{
46
 
47
        unsigned long Result = 0;
48
        int j = 0;
49
        for (int i = aStart; i <= aEnd; ++i)
50
        {
51
                Result |=  ( aBitset[i] << j++);
52
 
53
        }
54
 
55
        return Result;
56
 
57
}
58
//--------------------------------------------------------------
59
const char lookuparrbin2hex[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
60
 
61
char convert_bin2hex(std::string bits)
62
{
63
        unsigned int result = 0;
64
        unsigned int shifter0 = 0;
65
        unsigned int shifter1 = 1;
66
 
67
        for(int n=0; n < bits.length(); n++)
68
        {
69
                result <<= 1; //shift result to the left by 1
70
                if(bits[n] == '1') result = (result | shifter1);
71
                else result = (result | shifter0);
72
        }
73
        return lookuparrbin2hex[result];
74
}
75
//--------------------------------------------------------------
76
 
77
std::string BinStringToHexString(std::string aBinString )
78
{
79
        std::string endresult = "";
80
        for(int i = 0; i < aBinString.length(); i = i+4)
81
        {
82
                endresult += convert_bin2hex(aBinString.substr(i,4));
83
        }
84
        return endresult;
85
}
86
 
87
//--------------------------------------------------------------
88
CControlInstruction::CControlInstruction()
89
{
90
 
91
mSourceLine = -1;
92
}
93
//--------------------------------------------------------------
94
CControlInstruction::~CControlInstruction()
95
{
96
 
97
}
98
 
99
//--------------------------------------------------------------
100
void CControlInstruction::Clear()
101
{
102
        mOperation = 0;
103
        mDestination = 0;
104
        mSource1 = 0;
105
        mSource0 = 0;
106
        mComment.clear();
107
        mCopyDestinationAddress = 0;
108
        mCopySourceAddress = 0;
109
        mCopyDestinationId = 0;
110
        mCopySize = 0;
111
        mSourceLine = -1;
112
}
113
 
114
//--------------------------------------------------------------
115
void CControlInstruction::SetDestinationAddress( unsigned int aAddress )
116
{
117
 
118
        mDestination = aAddress;
119
 
120
}
121
//--------------------------------------------------------------
122
void CControlInstruction::SetSrc1Address(unsigned int aAddress )
123
{
124
        mSource1 = aAddress;
125
}
126
//--------------------------------------------------------------
127
void CControlInstruction::SetSrc0Address(unsigned int aAddress )
128
{
129
        mSource0 = aAddress;
130
}
131
//--------------------------------------------------------------
132
void CControlInstruction::SetOperation( EOPERATION aCode )
133
{
134
        mOperation = aCode;
135
}
136
//--------------------------------------------------------------
137
void CControlInstruction::SetCopyDestinationAddress( unsigned int aAddress )
138
{
139
        mCopyDestinationAddress = aAddress;
140
}
141
//--------------------------------------------------------------
142
void CControlInstruction::SetCopySourceAddress( unsigned int aAddress )
143
{
144
        mCopySourceAddress = aAddress;
145
}
146
//--------------------------------------------------------------
147
void CControlInstruction::SetCopyDestinationId( unsigned int aId )
148
{
149
        mCopyDestinationId = aId;
150
}
151
//--------------------------------------------------------------
152
 
153
void CControlInstruction::SetCopySize( unsigned int aSize )
154
{
155
        mCopyDestinationAddress = mCopyDestinationAddress;
156
}
157
 
158
//--------------------------------------------------------------
159
void CControlInstruction::SetLiteral(  unsigned int aLiteral )
160
{
161
        mLiteral = aLiteral;
162
}
163
//--------------------------------------------------------------
164
std::string OperationStrings[] =
165
{
166
        "NOP",
167
        "DELIVERCOMMAND",
168
        "ADD",
169
        "SUB",
170
        "AND",
171
        "OR",
172
        "BRANCH",
173
        "BEQ",
174
        "BNE",
175
        "BG",
176
        "BL",
177
        "BGE",
178
        "BLE",
179
        "ASSIGN",
180
        "COPYBLOCK",
181
        "EXIT",
182
        "NOT",
183
        "SHL",
184
        "SHR"
185
 
186
};
187
 
188
//--------------------------------------------------------------
189
std::string CControlInstruction::PrintAssembly( void )
190
{
191
        std::ostringstream oss;
192
        std::bitset<INSTRUCTION_SIZE> Bitset;
193
 
194
 
195
        SetbitRange<INSTRUCTION_SIZE>( Bitset ,OP_RNG , mOperation);
196
        switch (mOperation)
197
        {
198
                case EOPERATION_COPYBLOCK:
199
                {
200
                SetbitRange<INSTRUCTION_SIZE>( Bitset ,COPY_DST_RNG,  mCopyDestinationAddress);
201
                SetbitRange<INSTRUCTION_SIZE>( Bitset ,COPY_SRC_RNG,  mCopySourceAddress);
202
                SetbitRange<INSTRUCTION_SIZE>( Bitset ,COPY_DSTID_RNG,  mCopyDestinationId);
203
                //SetbitRange<INSTRUCTION_SIZE>( Bitset ,COPY_SIZE_RNG,  mCopyDestinationAddress);
204
 
205
                /*std::bitset<32> BitsetWord32_0( GetbitRange<INSTRUCTION_SIZE>(Bitset,31,0) );
206
                std::bitset<32> BitsetWord32_1( GetbitRange<INSTRUCTION_SIZE>(Bitset,63,32) );
207
                std::bitset<32> BitsetWord32_2( GetbitRange<INSTRUCTION_SIZE>(Bitset,84,64) );*/
208
 
209
                //oss << std::hex << BitsetWord32_2 << " " << BitsetWord32_1 << " "<< BitsetWord32_0;
210
                oss << std::hex << Bitset.to_ulong();
211
                oss << "\t\t//" << OperationStrings[mOperation];
212
                oss << std::dec  << " DstId: R"  << mCopyDestinationId << " SrcOffset: R" << mCopySourceAddress << " DstOffsetAndLen: R" << mCopyDestinationAddress;
213
                }
214
                break;
215
                case EOPERATION_ASSIGN:
216
                {
217
 
218
                SetbitRange<INSTRUCTION_SIZE>( Bitset ,DST_RNG , mDestination);
219
                SetbitRange<INSTRUCTION_SIZE>( Bitset ,LITERAL_RNG , mLiteral);
220
                //SetbitRange<INSTRUCTION_SIZE>( Bitset ,63,32 , 0);
221
 
222
                /*std::bitset<32> BitsetWord32_0( GetbitRange<INSTRUCTION_SIZE>(Bitset,31,0) );
223
                std::bitset<32> BitsetWord32_1( GetbitRange<INSTRUCTION_SIZE>(Bitset,63,32) );
224
                std::bitset<32> BitsetWord32_2( GetbitRange<INSTRUCTION_SIZE>(Bitset,84,64) );
225
 
226
                oss << std::hex << BitsetWord32_2 << " " << BitsetWord32_1 << " "<< BitsetWord32_0;*/
227
                oss << std::hex << Bitset.to_ulong();
228
                oss << "\t\t//" << OperationStrings[mOperation];
229
                oss << std::dec << " R"  << mDestination << " I(" << mLiteral << " )";
230
                }
231
                break;
232
                default:
233
                {
234
                SetbitRange<INSTRUCTION_SIZE>( Bitset ,SRC0_RNG, mSource0);
235
                SetbitRange<INSTRUCTION_SIZE>( Bitset ,SRC1_RNG, mSource1);
236
                SetbitRange<INSTRUCTION_SIZE>( Bitset ,DST_RNG , mDestination);
237
                /*
238
                std::bitset<32> BitsetWord32_0( GetbitRange<INSTRUCTION_SIZE>(Bitset,31,0) );
239
                std::bitset<32> BitsetWord32_1( GetbitRange<INSTRUCTION_SIZE>(Bitset,63,32) );
240
                std::bitset<32> BitsetWord32_2( GetbitRange<INSTRUCTION_SIZE>(Bitset,84,64) );
241
 
242
 
243
                oss << std::hex << BitsetWord32_2 << " " << BitsetWord32_1 << " "<< BitsetWord32_0;*/
244
                oss << std::hex << Bitset.to_ulong();
245
                oss << "\t\t//" << OperationStrings[mOperation];
246
                oss << std::dec << " R"  << mDestination << " R" << mSource1 << " R" << mSource0;
247
                }
248
        }
249
 
250
        return oss.str();
251
}
252
//--------------------------------------------------------------

powered by: WebSVN 2.1.0

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