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

Subversion Repositories theia_gpu

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

Go to most recent revision | 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
#define OP_SIZE        16            
29
 
30
#define OP_RNG         63,48         
31
#define OP_BIT_IMM     15
32
#define OP_SCALE_RNG   14,11
33
#define OP_EOF         10
34
#define OP_BRANCH      9
35
#define OP_BTYPE_RNG   8,6
36
 
37
#define OP_CODE_RNG    2,0
38
 
39
#define DST_ADDR            7,0
40
#define DST_WE_RNG      10,8
41
#define DST_WE_Z        8
42
#define DST_WE_Y        9
43
#define DST_WE_X        10
44
 
45
#define DST_ZERO            13
46
#define SRC1_DISPLACED      12
47
#define SRC0_DISPLACED      11
48
#define ADDRMODE_RNG            13,11
49
 
50
#define DST_RNG             47,34
51
#define SCR1_RNG            33,17
52
#define SRC0_RNG            16,0
53
// Source0 structure
54
#define SRC0_SIZE           17
55
#define SRC0_RNG            16,0
56
#define SRC0_ADDR_SIZE      8
57
#define SRC0_SIGN_RNG       16,14
58
#define SRC0_SIGN_X         16
59
#define SRC0_SIGN_Y         15
60
#define SRC0_SIGN_Z         14
61
#define SRC0_SWZX_RNG       13,8  
62
#define SRC0_SWZ_X          13,12  
63
#define SRC0_SWZ_Y          11,10
64
#define SRC0_SWZ_Z          9,8
65
#define SRC0_ADDR_RNG       7,0
66
// Source1 structure 
67
#define SRC1_SIZE           17
68
#define SRC1_RNG            33,17
69
#define SRC1_ADDR_SIZE      8
70
#define SRC1_SIGN_RNG       16,14
71
#define SRC1_SIGN_X         16
72
#define SRC1_SIGN_Y         15
73
#define SRC1_SIGN_Z         14
74
#define SRC1_SWZX_RNG       13,8
75
#define SRC1_SWZ_X          13,12  
76
#define SRC1_SWZ_Y          11,10
77
#define SRC1_SWZ_Z          9,8
78
#define SRC1_ADDR_RNG       7,0
79
 
80
 
81
std::string gOperationStrings[] =
82
{
83
        "NOP",
84
        "ADD",
85
        "DIV",
86
        "MUL",
87
        "SQRT",
88
        "LOGIC",
89
        "OUT"
90
};
91
 
92
std::string gBranchTypeStrings[] =
93
{
94
"ALWAYS",
95
"ZERO",
96
"NOT_ZERO",
97
"SIGN",
98
"NOT_SIGN",
99
"ZERO_OR_SIGN",
100
"ZERO_OR_NOT_SIGN"
101
};
102
 
103
std::string gSwizzleXTypeStrings[] =
104
{
105
"x",
106
"z",
107
"y"
108
};
109
 
110
std::string gSwizzleYTypeStrings[] =
111
{
112
"y",
113
"z",
114
"x"
115
};
116
 
117
std::string gSwizzleZTypeStrings[] =
118
{
119
"z",
120
"y",
121
"x"
122
};
123
 
124
//--------------------------------------------------------------
125
template <std::size_t N >
126
inline void SetbitRange( std::bitset<N> & aBitset , unsigned int aEnd, unsigned int aStart, unsigned int aValue)
127
{
128
        unsigned long mask = 1;
129
        unsigned long result = 0;
130
        for (int i = aStart; i <= aEnd; ++i)
131
        {
132
                aBitset[i] =  ( mask & aValue );
133
                mask <<= 1;
134
        }
135
 
136
}
137
//--------------------------------------------------------------
138
template <std::size_t N >
139
inline unsigned int GetbitRange( std::bitset<N> & aBitset , unsigned int aEnd, unsigned int aStart)
140
{
141
 
142
        unsigned long Result = 0;
143
        int j = 0;
144
        for (int i = aStart; i <= aEnd; ++i)
145
        {
146
                Result |=  ( aBitset[i] << j++);
147
 
148
        }
149
 
150
        return Result;
151
 
152
}
153
//--------------------------------------------------------------
154
const char lookuparrbin2hex[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
155
 
156
char convert_bin2hex(std::string bits)
157
{
158
        unsigned int result = 0;
159
        unsigned int shifter0 = 0;
160
        unsigned int shifter1 = 1;
161
 
162
        for(int n=0; n < bits.length(); n++)
163
        {
164
                result <<= 1; //shift result to the left by 1
165
                if(bits[n] == '1') result = (result | shifter1);
166
                else result = (result | shifter0);
167
        }
168
        return lookuparrbin2hex[result];
169
}
170
//--------------------------------------------------------------
171
 
172
std::string BinStringToHexString(std::string aBinString )
173
{
174
        std::string endresult = "";
175
        for(int i = 0; i < aBinString.length(); i = i+4)
176
        {
177
                endresult += convert_bin2hex(aBinString.substr(i,4));
178
        }
179
        return endresult;
180
}
181
 
182
//--------------------------------------------------------------
183
Instruction::Instruction()
184
{
185
mDestinationIsSymbol = false;
186
mBisonFlagTrippleConstAssign = false;
187
mSourceLine = -1;
188
}
189
//--------------------------------------------------------------
190
Instruction::~Instruction()
191
{
192
 
193
}
194
//--------------------------------------------------------------
195
void Instruction::SetFields( unsigned int aOperation, unsigned int aDestination, unsigned int aSrc1, unsigned int aSrc0 )
196
{
197
        SetbitRange<16>(mOperation,16,0,aOperation);
198
        SetbitRange<14>(mDestination,14,0,aDestination);
199
        SetbitRange<17>(mSource1,17,0,aSrc1);
200
        SetbitRange<17>(mSource0,17,0,aSrc0);
201
}
202
//--------------------------------------------------------------
203
void Instruction::Clear()
204
{
205
        mOperation.reset();
206
        mDestination.reset();
207
        mSource1.reset();
208
        mSource0.reset();
209
        mComment.clear();
210
        mDestinationIsSymbol = false;
211
        mBisonFlagTrippleConstAssign = false;
212
        mSourceLine = -1;
213
}
214
//--------------------------------------------------------------
215
 
216
std::string Instruction::PrintHex32()
217
{
218
        std::string Bits = PrintBin();
219
 
220
 
221
        std::bitset<32> BitsetH(Bits.substr(0,32));
222
        std::bitset<32> BitsetL(Bits.substr(32,32));
223
 
224
        //std::cout << "!!! F" << Bits << " \n";
225
        //std::cout << "!!! H" << BitsetH.to_string() << BitsetL.to_string() << " \n";
226
 
227
 
228
        return BinStringToHexString( BitsetH.to_string() ) + " " + BinStringToHexString( BitsetL.to_string() ) ;
229
 
230
}
231
 
232
//--------------------------------------------------------------
233
std::string Instruction::PrintHex()
234
{
235
        std::string  I;
236
        if (mDestinationIsSymbol)
237
        {
238
                std::ostringstream oss;
239
                oss << std::hex << mOperation.to_ulong() << " ";
240
                oss << mDestinationSymbol;
241
                oss << " " << mSource1.to_ulong() << " " << mSource0.to_ulong();
242
                return oss.str();
243
        }
244
        I =  BinStringToHexString( PrintBin() );
245
 
246
        return I;
247
 
248
}
249
//--------------------------------------------------------------
250
unsigned int Instruction::GetOperation()
251
{
252
 
253
        return GetbitRange<16>(mOperation,OP_CODE_RNG);
254
}
255
//--------------------------------------------------------------
256
bool Instruction::GetImm( void)
257
{
258
return mOperation[OP_BIT_IMM];
259
}
260
//--------------------------------------------------------------
261
unsigned int Instruction::GetAddressingMode( void )
262
{
263
 
264
return GetbitRange<14>(mDestination,ADDRMODE_RNG);
265
}
266
//--------------------------------------------------------------
267
std::string Instruction::PrintAssembly()
268
{
269
 
270
        unsigned int Scale = GetbitRange<16>(mOperation,OP_SCALE_RNG);
271
        std::bitset<4> bScale( Scale );
272
 
273
        std::ostringstream oss,oss2;
274
        #if 1           
275
        oss << std::hex << mOperation.to_ulong() << " ";
276
        if (mDestinationIsSymbol)
277
                oss << mDestinationSymbol;
278
        else
279
                oss << mDestination.to_ulong();
280
 
281
        oss << " " << mSource1.to_ulong() << " " << mSource0.to_ulong();
282
 
283
        #else
284
        oss << PrintHex();
285
 
286
        #endif
287
 
288
        std::string tmpString = oss.str();
289
        while (tmpString.size() < 50) tmpString.push_back(' ');
290
        oss2 << tmpString << "//\t" << PrintHex() << "\t";
291
 
292
        oss2 << mOperationString << " ";
293
        if (mOperation[OP_BRANCH])
294
        {
295
 
296
                oss2 << "<BRANCH." << gBranchTypeStrings[ GetbitRange<16>(mOperation,OP_BTYPE_RNG) ] << "> ";
297
        }
298
 
299
        if (mDestinationIsSymbol)
300
                oss2 << mDestinationSymbol;
301
        else
302
        {
303
                if (bScale[2] && bScale[3])
304
                        oss2 << "(unscaled) ";
305
                else if (bScale[2])
306
                        oss2 << "(scaled) ";
307
 
308
                if (mOperation[OP_BIT_IMM])
309
                {
310
                        unsigned int AddressingMode = GetbitRange<14>(mDestination,ADDRMODE_RNG);
311
                        unsigned int DestinationIndex = GetbitRange<14>(mDestination,DST_ADDR);
312
                        std::string Reg =  ((mOperation[OP_BRANCH])?"@*R[":"R[");
313
                        switch ( AddressingMode )
314
                        {
315
                                case 0: oss2 << Reg << DestinationIndex << "]";break;
316
                                case 1: oss2 << Reg << DestinationIndex << " + offset ]"; break;
317
                                case 2: oss2 << Reg << DestinationIndex << " + offset ]"; break;
318
                                case 3: oss2 << Reg << DestinationIndex << "+ R[" << mSource1.to_ulong()  << " + offset] + offset ]";break;
319
                                case 4: oss2 << Reg << DestinationIndex << "]"; break;
320
                                case 5: oss2 << Reg << DestinationIndex << " + offset ]"; break;
321
                                case 6: oss2 << Reg << DestinationIndex << " + offset ]";break;
322
                                case 7: oss2 << Reg << DestinationIndex << " + offset ]";break;
323
                                default: oss2 << "??";
324
                        }
325
 
326
                /*
327
                        if (mDestination[SRC0_DISPLACED])
328
                        {
329
                                oss2 << ((mOperation[OP_BRANCH])?"@*R[":"R[") <<  GetbitRange<14>(mDestination,DST_ADDR) << "+ offset";
330
 
331
                                if (mDestination[SRC1_DISPLACED])
332
                                        oss2 << " + R[" << mSource1.to_ulong() << " + offset]";
333
                                oss2 << "]";
334
                        } else
335
                                oss2 << ((mOperation[OP_BRANCH])?"@*R":"R") <<  GetbitRange<14>(mDestination,DST_ADDR);
336
                                */
337
                }
338
                else
339
                {
340
                        if (mDestination[DST_ZERO])
341
                                oss2 << ((mOperation[OP_BRANCH])?"@[":"R[") <<  GetbitRange<14>(mDestination,DST_ADDR) << "+ offset]";
342
                        else
343
                                oss2 << ((mOperation[OP_BRANCH])?"@":"R") <<  GetbitRange<14>(mDestination,DST_ADDR);
344
                }
345
        }
346
        //Now print the write channels
347
        oss2 << ".";
348
        if (mDestination[DST_WE_X])
349
                oss2 << "x";
350
        else
351
                oss2 << "_";
352
 
353
        if (mDestination[DST_WE_Y])
354
                oss2 << "y";
355
        else
356
                oss2 << "_";
357
 
358
        if (mDestination[DST_WE_Z])
359
                oss2 << "z";
360
        else
361
                oss2 << "_";
362
 
363
        oss2 << " ";
364
 
365
        if (mOperation[OP_BIT_IMM])
366
        {
367
                unsigned int AddressingMode = GetbitRange<14>(mDestination,ADDRMODE_RNG);
368
                unsigned int ImmediateValue = (mSource0.to_ulong() + (mSource1.to_ulong() << 17));
369
                switch (AddressingMode)
370
                {
371
                        case 0: oss2 << std::hex << "I(" << ImmediateValue << ") R[DST]" ; break;
372
                        case 1: oss2 << std::hex << "I(" << ImmediateValue << ") R[DST+offset]" << " *** " << mSource1.to_ulong() << " , " << mSource1.to_ulong();break;
373
                        case 2: oss2 << "??????";break;
374
                        case 3: oss2 << std::dec << "0 R[" << mSource0.to_ulong() << " + offset]"; break;
375
                        case 4: oss2 << std::hex << "I(" << ImmediateValue << ") 0" ;break;
376
                        case 5: oss2 << std::hex << "I(" << ImmediateValue << ") 0" ;break;
377
                        case 6: oss2 << std::dec << " R[" << mSource1.to_ulong() << " + offset + index] 0";break;
378
                        case 7: oss2 << std::dec << " R[" << mSource1.to_ulong() << " + offset + index] R[" << mSource0.to_ulong() << " + offset]"; break;
379
                        default:
380
                                oss2 << "??";
381
                }
382
                /*if (mDestination[SRC1_DISPLACED] && mDestination[SRC0_DISPLACED] && !mDestination[DST_ZERO])
383
                {
384
                        oss2 << std::dec << " R[" << mSource0.to_ulong() << " + offset] 0";
385
                } else if (mDestination[SRC1_DISPLACED] && mDestination[SRC0_DISPLACED] && mDestination[DST_ZERO])
386
                {
387
                        oss2 << std::dec << " R[" << mSource0.to_ulong() << " + offset + index] R[" << mSource0.to_ulong() << " + offset]";
388
                }
389
                else
390
                {
391
                        oss2 << std::hex << "I(" << (mSource0.to_ulong() + (mSource1.to_ulong() << 17)) << ") ";
392
 
393
                        if (mDestination[DST_ZERO])
394
                                oss2 << "0";
395
                        else
396
                                oss2 << "R[DST]";
397
                }*/
398
        } else {
399
 
400
 
401
                if (bScale[0] && bScale[3])
402
                        oss2 << "(unscaled) ";
403
                else if (bScale[0])
404
                        oss2 << "(scaled) ";
405
 
406
 
407
                oss2 << "R";
408
                if (mDestination[SRC1_DISPLACED])
409
                        oss2 << "[" << GetbitRange<17>(mSource1,SRC1_ADDR_RNG) << " + offset]";
410
                else
411
                        oss2 << GetbitRange<17>(mSource1,SRC1_ADDR_RNG);
412
 
413
                oss2 << "."
414
 
415
                << ((mSource1[SRC1_SIGN_X]) ? "-":"") << gSwizzleXTypeStrings[ GetbitRange<17>(mSource1,SRC1_SWZ_X) ]
416
                << ((mSource1[SRC1_SIGN_Y]) ? "-":"") <<gSwizzleYTypeStrings[ GetbitRange<17>(mSource1,SRC1_SWZ_Y) ]
417
                << ((mSource1[SRC1_SIGN_Z]) ? "-":"") <<gSwizzleZTypeStrings[ GetbitRange<17>(mSource1,SRC1_SWZ_Z) ] << " ";
418
 
419
 
420
                if (bScale[1] && bScale[3])
421
                        oss2 << "(unscaled) ";
422
                else if (bScale[1])
423
                        oss2 << "(scaled) ";
424
 
425
                oss2 << "R";
426
                if (mDestination[SRC0_DISPLACED])
427
                        oss2 << "[" << GetbitRange<17>(mSource0,SRC0_ADDR_RNG) << " + offset]";
428
                else
429
                        oss2 << GetbitRange<17>(mSource0,SRC0_ADDR_RNG);
430
 
431
                oss2 << "."
432
 
433
                << ((mSource0[SRC0_SIGN_X]) ? "-":"") << gSwizzleXTypeStrings[ GetbitRange<17>(mSource0,SRC0_SWZ_X) ]
434
                << ((mSource0[SRC0_SIGN_Y]) ? "-":"") << gSwizzleYTypeStrings[ GetbitRange<17>(mSource0,SRC0_SWZ_Y) ]
435
                << ((mSource0[SRC0_SIGN_Z]) ? "-":"") << gSwizzleZTypeStrings[ GetbitRange<17>(mSource0,SRC0_SWZ_Z) ];
436
        }
437
 
438
 
439
        return oss2.str();
440
}
441
//--------------------------------------------------------------
442
unsigned int Instruction::GetDestinationAddress()
443
{
444
        return GetbitRange<14>(mDestination,DST_ADDR);
445
}
446
//--------------------------------------------------------------
447
void Instruction::SetImmBit( bool aImm )
448
{
449
        mOperation[OP_BIT_IMM] = aImm;
450
}
451
//--------------------------------------------------------------
452
void Instruction::PrintFields()
453
{
454
        if (mOperation[OP_BRANCH])
455
        {
456
                std::cout << "BRANCH to " << mDestination.to_ulong() << "\n";
457
        }
458
        std::cout << "Imm      :" << mOperation[OP_BIT_IMM] << "\n";
459
        std::cout << "Branch   :" << mOperation[OP_BRANCH] << "\n";
460
        std::cout << "WE.x     :" << mDestination[DST_WE_X] << "\n";
461
        std::cout << "WE.y     :" << mDestination[DST_WE_Y] << "\n";
462
        std::cout << "WE.z     :" << mDestination[DST_WE_Z] << "\n";
463
        std::cout << "EOF      :" << mOperation[OP_EOF] << "\n";
464
 
465
        std::cout << "OP       :" << mOperation.to_string() << "\n";
466
        if (mDestinationIsSymbol)
467
                std::cout << "DST      :" << mDestinationSymbol << "\n";
468
        else
469
                std::cout << "DST      :" << mDestination.to_string() << "\n";
470
        std::cout << "DSTZERO   :" <<   mDestination[DST_ZERO] << "\n";
471
        std::cout << "SRC1     :" << mSource1.to_string() << " (" << mSource1.to_ulong() << ")\n";
472
        std::cout << "SRC0     :" << mSource0.to_string() << " (" << mSource0.to_ulong() << ")\n";
473
}
474
//--------------------------------------------------------------
475
std::string Instruction::PrintBin()
476
{
477
 
478
        std::bitset<64> Bitset;
479
 
480
 
481
        SetbitRange<64>(Bitset,OP_RNG,mOperation.to_ulong());
482
        SetbitRange<64>(Bitset,DST_RNG,mDestination.to_ulong());
483
        SetbitRange<64>(Bitset,SRC1_RNG,mSource1.to_ulong());
484
        SetbitRange<64>(Bitset,SRC0_RNG,mSource0.to_ulong());
485
        return Bitset.to_string();
486
 
487
}
488
//--------------------------------------------------------------
489
void Instruction::SetEofFlag( bool aEof )
490
{
491
        mOperation[ OP_EOF ] = aEof;
492
}
493
//--------------------------------------------------------------
494
void Instruction::SetCode( EOPERATION aCode )
495
{
496
        SetbitRange<16>(mOperation,OP_CODE_RNG,aCode);
497
        mOperationString = gOperationStrings[aCode];
498
}
499
//--------------------------------------------------------------
500
void Instruction::SetImm( unsigned int aLiteral )
501
{
502
 
503
 
504
        mOperation[OP_BIT_IMM] = true;
505
        mSource0 = aLiteral;
506
        mSource1 = (aLiteral >> SOURCE0_SIZE);
507
}
508
//--------------------------------------------------------------
509
void Instruction::SetAddressingMode( bool aDstZero, bool aSrc1Dsp , bool  aSrc0Dsp)
510
{
511
                        SetDestZero( aDstZero );
512
                        SetSrc1Displace( aSrc1Dsp );
513
                        SetSrc0Displace( aSrc0Dsp );
514
}
515
//--------------------------------------------------------------
516
/*void SetAddressingMode( EADDRESSINGTYPE aAddressMode )
517
{
518
        std::bitset<4> AddressingMode( aAddressMode );
519
        AddressingMode[3] = mOperation[OP_BIT_IMM] ;
520
 
521
        switch ( AddressingMode )
522
        {
523
                case EDIRECT_ADDRESSING:
524
                        SetDestZero( false );
525
                        SetSrc1Displace( false );
526
                        SetSrc0Displace( false );
527
                        break;
528
                case EDIRECT_DISP_SRC0:
529
                        SetDestZero( false );
530
                        SetSrc1Displace( false );
531
                        SetSrc0Displace( true );
532
                        break;
533
                EDIRECT_DISP_SRC1:
534
                        SetDestZero( false );
535
                        SetSrc1Displace( true );
536
                        SetSrc0Displace( false );
537
                        break;
538
                EDIRECT_DISP_SRC1_SRC0:
539
                        SetDestZero( false );
540
                        SetSrc1Displace( true );
541
                        SetSrc0Displace( true );
542
                        break;
543
                EDIRECT_DISP_DST:
544
                        SetDestZero( true );
545
                        SetSrc1Displace( false );
546
                        SetSrc0Displace( false );
547
                        break;
548
                EDIRECT_DISP_DST_SRC0:
549
                        SetDestZero( true );
550
                        SetSrc1Displace( false );
551
                        SetSrc0Displace( true );
552
                        break;
553
                case EDIRECT_DISP_DST_SRC1:
554
                        SetDestZero( true );
555
                        SetSrc1Displace( true );
556
                        SetSrc0Displace( false );
557
                        break;
558
                case EDIRECT_DISP_DST_SRC1_SRC0:
559
                        SetDestZero( true );
560
                        SetSrc1Displace( true );
561
                        SetSrc0Displace( true );
562
                        break;
563
                EDIRECT_IMM:                            //R[DSTINDEX ] = IMMV op R[DSTINDEX]
564
                        SetDestZero( false );
565
                        SetSrc1Displace( false );
566
                        SetSrc0Displace( false );
567
                        break;
568
                EDIRECT_IMM_ZERO:                       //R[DSTINDEX ] = IMMV op 32'b0
569
                        SetDestZero( true );
570
                        SetSrc1Displace( false );
571
                        SetSrc0Displace( false );
572
                        break;
573
                EDIRECT_IMM_DISPALCE:           //R[DSTINDEX + offset] = IMMV op R[DSTINDEX]
574
                        SetDestZero( false );
575
                        SetSrc1Displace( false );
576
                        SetSrc0Displace( true );
577
                        break;
578
                EDIRECT_IMM_DISPALCE_ZERO: //R[DSTINDEX + offset] = IMMV op 32'b0
579
                        SetDestZero( true );
580
                        SetSrc1Displace( false );
581
                        SetSrc0Displace( true );
582
                        break;
583
                EINDIRECT_IMM_DISP:             // DST = R[ DSTINDEX ] + OFFSET
584
                        SetDestZero( false );
585
                        SetSrc1Displace( false );
586
                        SetSrc0Displace( false );
587
                        break;
588
                break;
589
                EINDIRECT_IMM_DISP_ZERO:
590
                break;
591
                EINDIRECT_NO_IMM:
592
                break;
593
                EINDIRECT_NO_IMM_DISP:
594
                break;
595
        }
596
}*/
597
//--------------------------------------------------------------
598
void Instruction::SetDestZero(  bool aZero )
599
{
600
        mDestination[DST_ZERO] = aZero;
601
}
602
//--------------------------------------------------------------
603
void Instruction::SetSrc0Displace( bool aDisplace )
604
{
605
        mDestination[SRC0_DISPLACED] = aDisplace;
606
}
607
//--------------------------------------------------------------
608
void Instruction::SetSrc1Displace( bool aDisplace )
609
{
610
        mDestination[SRC1_DISPLACED] = aDisplace;
611
}
612
//--------------------------------------------------------------
613
void Instruction::SetBranchFlag( bool aBranch )
614
{
615
        mOperation[OP_BRANCH] = aBranch;
616
}
617
//--------------------------------------------------------------
618
void Instruction::SetBranchType( EBRANCHTYPE aBranchType )
619
{
620
        SetbitRange<16>(mOperation,OP_BTYPE_RNG,aBranchType);
621
}
622
//--------------------------------------------------------------
623
void Instruction::ClearWriteChannel()
624
{
625
 
626
        mDestination[DST_WE_X] = false;
627
        mDestination[DST_WE_Y] = false;
628
        mDestination[DST_WE_Z] = false;
629
}
630
//--------------------------------------------------------------
631
void Instruction::SetWriteChannel( ECHANNEL aChannel )
632
{
633
 
634
        if (aChannel == ECHANNEL_XYZ)
635
        {
636
                mDestination[DST_WE_X] = true;
637
                mDestination[DST_WE_Y] = true;
638
                mDestination[DST_WE_Z] = true;
639
                return;
640
        }
641
 
642
        switch ( aChannel )
643
        {
644
                case ECHANNEL_X:
645
                mDestination[DST_WE_X] = true;
646
                break;
647
                case ECHANNEL_Y:
648
                mDestination[DST_WE_Y] = true;
649
                break;
650
                case ECHANNEL_Z:
651
                mDestination[DST_WE_Z] = true;
652
                break;
653
        }
654
 
655
}
656
//--------------------------------------------------------------
657
void Instruction::SetDestinationAddress( unsigned int aAddress )
658
{
659
 
660
        SetbitRange<14>(mDestination,DST_ADDR,aAddress);
661
 
662
}
663
//--------------------------------------------------------------
664
void Instruction::SetDestinationSymbol( std::string aSymbol )
665
{
666
        mDestinationIsSymbol = true;
667
        mDestinationSymbol = aSymbol;
668
}
669
//--------------------------------------------------------------
670
void Instruction::SetSrc1SignX( bool aSign )
671
{
672
        mSource1[SRC1_SIGN_X] = aSign;
673
}
674
//--------------------------------------------------------------
675
void Instruction::SetSrc1SignY( bool aSign )
676
{
677
        mSource1[SRC1_SIGN_Y] = aSign;
678
}
679
//--------------------------------------------------------------
680
void Instruction::SetSrc1SignZ( bool aSign )
681
{
682
        mSource1[SRC1_SIGN_Z] = aSign;
683
}
684
//--------------------------------------------------------------
685
void Instruction::SetSrc1SwizzleX(ESWIZZLE_X aChannel)
686
{
687
        SetbitRange<17>(mSource1,SRC1_SWZ_X,aChannel);
688
 
689
}
690
//--------------------------------------------------------------
691
void Instruction::SetSrc1SwizzleY(ESWIZZLE_Y aChannel)
692
{
693
        SetbitRange<17>(mSource1,SRC1_SWZ_Y,aChannel);
694
 
695
}
696
//--------------------------------------------------------------
697
void Instruction::SetSrc1SwizzleZ(ESWIZZLE_Z aChannel)
698
{
699
        SetbitRange<17>(mSource1,SRC1_SWZ_Z,aChannel);
700
 
701
}
702
//--------------------------------------------------------------
703
void Instruction::SetSrc1Address(unsigned int aAddress )
704
{
705
        SetbitRange<17>(mSource1,SRC1_ADDR_RNG,aAddress);
706
}
707
//--------------------------------------------------------------
708
void Instruction::SetLogicOperation(ELOGIC_OPERATION aOperation )
709
{
710
        SetbitRange<16>(mOperation,OP_SCALE_RNG,aOperation);
711
}
712
//--------------------------------------------------------------
713
void Instruction::SetSrc1Rotation( EROTATION aRotation )
714
{
715
        unsigned int OldVal = GetbitRange<16>(mOperation,OP_SCALE_RNG);
716
 
717
        SetbitRange<16>(mOperation,OP_SCALE_RNG,(OldVal | aRotation) );
718
}
719
//--------------------------------------------------------------
720
void Instruction::SetSrc0Rotation( EROTATION aRotation )
721
{
722
        unsigned int OldVal = GetbitRange<16>(mOperation,OP_SCALE_RNG);
723
 
724
        SetbitRange<16>(mOperation,OP_SCALE_RNG,(OldVal | aRotation ) );
725
}
726
//--------------------------------------------------------------
727
void Instruction::SetSrc0SignX( bool aSign )
728
{
729
        mSource0[SRC0_SIGN_X] = aSign;
730
}
731
//--------------------------------------------------------------
732
void Instruction::SetSrc0SignY( bool aSign )
733
{
734
        mSource0[SRC0_SIGN_Y] = aSign;
735
}
736
//--------------------------------------------------------------
737
void Instruction::SetSrc0SignZ( bool aSign )
738
{
739
        mSource0[SRC0_SIGN_Z] = aSign;
740
}
741
//--------------------------------------------------------------
742
void Instruction::SetSrc0SwizzleX(ESWIZZLE_X aChannel)
743
{
744
SetbitRange<17>(mSource0,SRC0_SWZ_X,aChannel);
745
 
746
}
747
//--------------------------------------------------------------
748
void Instruction::SetSrc0SwizzleY(ESWIZZLE_Y aChannel)
749
{
750
        SetbitRange<17>(mSource0,SRC0_SWZ_Y,aChannel);
751
 
752
 
753
}
754
//--------------------------------------------------------------
755
void Instruction::SetSrc0SwizzleZ(ESWIZZLE_Z aChannel)
756
{
757
SetbitRange<17>(mSource0,SRC0_SWZ_Z,aChannel);
758
 
759
}
760
//--------------------------------------------------------------
761
void Instruction::SetSrc0Address(unsigned int aAddress )
762
{
763
        SetbitRange<17>(mSource0,SRC0_ADDR_RNG,aAddress);
764
}
765
//--------------------------------------------------------------
766
 std::bitset<DESTINATION_SIZE> Instruction::GetDestination( )
767
{
768
        return mDestination;
769
}
770
//--------------------------------------------------------------
771
ECHANNEL Instruction::GetWriteChannel(  )
772
{
773
        //std::cout << "Ecahhhannel " << GetbitRange<DESTINATION_SIZE>(mDestination,DST_WE_RNG) << "\n";
774
 
775
        return ((ECHANNEL)GetbitRange<DESTINATION_SIZE>(mDestination,DST_WE_RNG));
776
}
777
//--------------------------------------------------------------
778
/*
779
void Instruction::SetDestination( std::bitset<DESTINATION_SIZE> aDestination )
780
{
781
        mDestination = aDestination;
782
}
783
*/
784
//--------------------------------------------------------------

powered by: WebSVN 2.1.0

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