forked from cseagle/blc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
opbehavior.cc
736 lines (568 loc) · 20.8 KB
/
opbehavior.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "opbehavior.hh"
#include "translate.hh"
/// This routine generates a vector of OpBehavior objects indexed by opcode
/// \param inst is the vector of behaviors to be filled
/// \param trans is the translator object needed by the floating point behaviors
void OpBehavior::registerInstructions(vector<OpBehavior *> &inst,const Translate *trans)
{
inst.insert(inst.end(),CPUI_MAX,(OpBehavior *)0);
inst[CPUI_COPY] = new OpBehaviorCopy();
inst[CPUI_LOAD] = new OpBehavior(CPUI_LOAD,false,true);
inst[CPUI_STORE] = new OpBehavior(CPUI_STORE,false,true);
inst[CPUI_BRANCH] = new OpBehavior(CPUI_BRANCH,false,true);
inst[CPUI_CBRANCH] = new OpBehavior(CPUI_CBRANCH,false,true);
inst[CPUI_BRANCHIND] = new OpBehavior(CPUI_BRANCHIND,false,true);
inst[CPUI_CALL] = new OpBehavior(CPUI_CALL,false,true);
inst[CPUI_CALLIND] = new OpBehavior(CPUI_CALLIND,false,true);
inst[CPUI_CALLOTHER] = new OpBehavior(CPUI_CALLOTHER,false,true);
inst[CPUI_RETURN] = new OpBehavior(CPUI_RETURN,false,true);
inst[CPUI_MULTIEQUAL] = new OpBehavior(CPUI_MULTIEQUAL,false,true);
inst[CPUI_INDIRECT] = new OpBehavior(CPUI_INDIRECT,false,true);
inst[CPUI_PIECE] = new OpBehaviorPiece();
inst[CPUI_SUBPIECE] = new OpBehaviorSubpiece();
inst[CPUI_INT_EQUAL] = new OpBehaviorEqual();
inst[CPUI_INT_NOTEQUAL] = new OpBehaviorNotEqual();
inst[CPUI_INT_SLESS] = new OpBehaviorIntSless();
inst[CPUI_INT_SLESSEQUAL] = new OpBehaviorIntSlessEqual();
inst[CPUI_INT_LESS] = new OpBehaviorIntLess();
inst[CPUI_INT_LESSEQUAL] = new OpBehaviorIntLessEqual();
inst[CPUI_INT_ZEXT] = new OpBehaviorIntZext();
inst[CPUI_INT_SEXT] = new OpBehaviorIntSext();
inst[CPUI_INT_ADD] = new OpBehaviorIntAdd();
inst[CPUI_INT_SUB] = new OpBehaviorIntSub();
inst[CPUI_INT_CARRY] = new OpBehaviorIntCarry();
inst[CPUI_INT_SCARRY] = new OpBehaviorIntScarry();
inst[CPUI_INT_SBORROW] = new OpBehaviorIntSborrow();
inst[CPUI_INT_2COMP] = new OpBehaviorInt2Comp();
inst[CPUI_INT_NEGATE] = new OpBehaviorIntNegate();
inst[CPUI_INT_XOR] = new OpBehaviorIntXor();
inst[CPUI_INT_AND] = new OpBehaviorIntAnd();
inst[CPUI_INT_OR] = new OpBehaviorIntOr();
inst[CPUI_INT_LEFT] = new OpBehaviorIntLeft();
inst[CPUI_INT_RIGHT] = new OpBehaviorIntRight();
inst[CPUI_INT_SRIGHT] = new OpBehaviorIntSright();
inst[CPUI_INT_MULT] = new OpBehaviorIntMult();
inst[CPUI_INT_DIV] = new OpBehaviorIntDiv();
inst[CPUI_INT_SDIV] = new OpBehaviorIntSdiv();
inst[CPUI_INT_REM] = new OpBehaviorIntRem();
inst[CPUI_INT_SREM] = new OpBehaviorIntSrem();
inst[CPUI_BOOL_NEGATE] = new OpBehaviorBoolNegate();
inst[CPUI_BOOL_XOR] = new OpBehaviorBoolXor();
inst[CPUI_BOOL_AND] = new OpBehaviorBoolAnd();
inst[CPUI_BOOL_OR] = new OpBehaviorBoolOr();
inst[CPUI_CAST] = new OpBehavior(CPUI_CAST,false,true);
inst[CPUI_PTRADD] = new OpBehavior(CPUI_PTRADD,false,true);
inst[CPUI_PTRSUB] = new OpBehavior(CPUI_PTRSUB,false,true);
inst[CPUI_FLOAT_EQUAL] = new OpBehaviorFloatEqual(trans);
inst[CPUI_FLOAT_NOTEQUAL] = new OpBehaviorFloatNotEqual(trans);
inst[CPUI_FLOAT_LESS] = new OpBehaviorFloatLess(trans);
inst[CPUI_FLOAT_LESSEQUAL] = new OpBehaviorFloatLessEqual(trans);
inst[CPUI_FLOAT_NAN] = new OpBehaviorFloatNan(trans);
inst[CPUI_FLOAT_ADD] = new OpBehaviorFloatAdd(trans);
inst[CPUI_FLOAT_DIV] = new OpBehaviorFloatDiv(trans);
inst[CPUI_FLOAT_MULT] = new OpBehaviorFloatMult(trans);
inst[CPUI_FLOAT_SUB] = new OpBehaviorFloatSub(trans);
inst[CPUI_FLOAT_NEG] = new OpBehaviorFloatNeg(trans);
inst[CPUI_FLOAT_ABS] = new OpBehaviorFloatAbs(trans);
inst[CPUI_FLOAT_SQRT] = new OpBehaviorFloatSqrt(trans);
inst[CPUI_FLOAT_INT2FLOAT] = new OpBehaviorFloatInt2Float(trans);
inst[CPUI_FLOAT_FLOAT2FLOAT] = new OpBehaviorFloatFloat2Float(trans);
inst[CPUI_FLOAT_TRUNC] = new OpBehaviorFloatTrunc(trans);
inst[CPUI_FLOAT_CEIL] = new OpBehaviorFloatCeil(trans);
inst[CPUI_FLOAT_FLOOR] = new OpBehaviorFloatFloor(trans);
inst[CPUI_FLOAT_ROUND] = new OpBehaviorFloatRound(trans);
inst[CPUI_SEGMENTOP] = new OpBehavior(CPUI_SEGMENTOP,false,true);
inst[CPUI_CPOOLREF] = new OpBehavior(CPUI_CPOOLREF,false,true);
inst[CPUI_NEW] = new OpBehavior(CPUI_NEW,false,true);
inst[CPUI_INSERT] = new OpBehavior(CPUI_INSERT,false,true);
inst[CPUI_EXTRACT] = new OpBehavior(CPUI_EXTRACT,false,true);
inst[CPUI_POPCOUNT] = new OpBehaviorPopcount();
}
/// \param sizeout is the size of the output in bytes
/// \param sizein is the size of the input in bytes
/// \param in1 is the input value
/// \return the output value
uintb OpBehavior::evaluateUnary(int4 sizeout,int4 sizein,uintb in1) const
{
string name(get_opname(opcode));
throw LowlevelError("Unary emulation unimplemented for "+name);
}
/// \param sizeout is the size of the output in bytes
/// \param sizein is the size of the inputs in bytes
/// \param in1 is the first input value
/// \param in2 is the second input value
/// \return the output value
uintb OpBehavior::evaluateBinary(int4 sizeout,int4 sizein,uintb in1,uintb in2) const
{
string name(get_opname(opcode));
throw LowlevelError("Binary emulation unimplemented for "+name);
}
/// If the output value is known, recover the input value.
/// \param sizeout is the size of the output in bytes
/// \param out is the output value
/// \param sizein is the size of the input in bytes
/// \return the input value
uintb OpBehavior::recoverInputUnary(int4 sizeout,uintb out,int4 sizein) const
{
throw LowlevelError("Cannot recover input parameter without loss of information");
}
/// If the output value and one of the input values is known, recover the value
/// of the other input.
/// \param slot is the input slot to recover
/// \param sizeout is the size of the output in bytes
/// \param out is the output value
/// \param sizein is the size of the inputs in bytes
/// \param in is the known input value
/// \return the input value corresponding to the \b slot
uintb OpBehavior::recoverInputBinary(int4 slot,int4 sizeout,uintb out,int4 sizein,uintb in) const
{
throw LowlevelError("Cannot recover input parameter without loss of information");
}
uintb OpBehaviorCopy::evaluateUnary(int4 sizeout,int4 sizein,uintb in1) const
{
return in1;
}
uintb OpBehaviorCopy::recoverInputUnary(int4 sizeout,uintb out,int4 sizein) const
{
return out;
}
uintb OpBehaviorEqual::evaluateBinary(int4 sizeout,int4 sizein,uintb in1,uintb in2) const
{
uintb res = (in1 == in2) ? 1 : 0;
return res;
}
uintb OpBehaviorNotEqual::evaluateBinary(int4 sizeout,int4 sizein,uintb in1,uintb in2) const
{
uintb res = (in1 != in2) ? 1 : 0;
return res;
}
uintb OpBehaviorIntSless::evaluateBinary(int4 sizeout,int4 sizein,uintb in1,uintb in2) const
{
uintb res,mask,bit1,bit2;
if (sizein<=0)
res = 0;
else {
mask = 0x80;
mask <<= 8*(sizein-1);
bit1 = in1 & mask; // Get the sign bits
bit2 = in2 & mask;
if (bit1 != bit2)
res = (bit1 != 0) ? 1 : 0;
else
res = (in1 < in2) ? 1 : 0;
}
return res;
}
uintb OpBehaviorIntSlessEqual::evaluateBinary(int4 sizeout,int4 sizein,uintb in1,uintb in2) const
{
uintb res,mask,bit1,bit2;
if (sizein<=0)
res = 0;
else {
mask = 0x80;
mask <<= 8*(sizein-1);
bit1 = in1 & mask; // Get the sign bits
bit2 = in2 & mask;
if (bit1 != bit2)
res = (bit1 != 0) ? 1 : 0;
else
res = (in1 <= in2) ? 1 : 0;
}
return res;
}
uintb OpBehaviorIntLess::evaluateBinary(int4 sizeout,int4 sizein,uintb in1,uintb in2) const
{
uintb res = (in1 < in2) ? 1 : 0;
return res;
}
uintb OpBehaviorIntLessEqual::evaluateBinary(int4 sizeout,int4 sizein,uintb in1,uintb in2) const
{
uintb res = (in1 <= in2) ? 1 : 0;
return res;
}
uintb OpBehaviorIntZext::evaluateUnary(int4 sizeout,int4 sizein,uintb in1) const
{
return in1;
}
uintb OpBehaviorIntZext::recoverInputUnary(int4 sizeout,uintb out,int4 sizein) const
{
uintb mask = calc_mask(sizein);
if ((mask&out)!=out)
throw EvaluationError("Output is not in range of zext operation");
return out;
}
uintb OpBehaviorIntSext::evaluateUnary(int4 sizeout,int4 sizein,uintb in1) const
{
uintb res = sign_extend(in1,sizein,sizeout);
return res;
}
uintb OpBehaviorIntSext::recoverInputUnary(int4 sizeout,uintb out,int4 sizein) const
{
uintb masklong = calc_mask(sizeout);
uintb maskshort = calc_mask(sizein);
if ((out & (maskshort ^ (maskshort>>1))) == 0) { // Positive input
if ((out & maskshort) != out)
throw EvaluationError("Output is not in range of sext operation");
}
else { // Negative input
if ((out & (masklong^maskshort)) != (masklong^maskshort))
throw EvaluationError("Output is not in range of sext operation");
}
return (out&maskshort);
}
uintb OpBehaviorIntAdd::evaluateBinary(int4 sizeout,int4 sizein,uintb in1,uintb in2) const
{
uintb res = (in1 + in2) & calc_mask(sizeout);
return res;
}
uintb OpBehaviorIntAdd::recoverInputBinary(int4 slot,int4 sizeout,uintb out,int4 sizein,uintb in) const
{
uintb res = (out-in) & calc_mask(sizeout);
return res;
}
uintb OpBehaviorIntSub::evaluateBinary(int4 sizeout,int4 sizein,uintb in1,uintb in2) const
{
uintb res = (in1 - in2) & calc_mask(sizeout);
return res;
}
uintb OpBehaviorIntSub::recoverInputBinary(int4 slot,int4 sizeout,uintb out,int4 sizein,uintb in) const
{
uintb res;
if (slot==0)
res = in + out;
else
res = in - out;
res &= calc_mask(sizeout);
return res;
}
uintb OpBehaviorIntCarry::evaluateBinary(int4 sizeout,int4 sizein,uintb in1,uintb in2) const
{
uintb res = (in1 > ((in1 + in2)&calc_mask(sizein))) ? 1 : 0;
return res;
}
uintb OpBehaviorIntScarry::evaluateBinary(int4 sizeout,int4 sizein,uintb in1,uintb in2) const
{
uintb res = in1 + in2;
uint4 a = (in1>>(sizein*8-1))&1; // Grab sign bit
uint4 b = (in2>>(sizein*8-1))&1; // Grab sign bit
uint4 r = (res>>(sizein*8-1))&1; // Grab sign bit
r ^= a;
a ^= b;
a ^= 1;
r &= a;
return (uintb)r;
}
uintb OpBehaviorIntSborrow::evaluateBinary(int4 sizeout,int4 sizein,uintb in1,uintb in2) const
{
uintb res = in1 - in2;
uint4 a = (in1>>(sizein*8-1))&1; // Grab sign bit
uint4 b = (in2>>(sizein*8-1))&1; // Grab sign bit
uint4 r = (res>>(sizein*8-1))&1; // Grab sign bit
a ^= r;
r ^= b;
r ^= 1;
a &= r;
return (uintb)a;
}
uintb OpBehaviorInt2Comp::evaluateUnary(int4 sizeout,int4 sizein,uintb in1) const
{
uintb res = uintb_negate(in1-1,sizein);
return res;
}
uintb OpBehaviorIntNegate::evaluateUnary(int4 sizeout,int4 sizein,uintb in1) const
{
uintb res = uintb_negate(in1,sizein);
return res;
}
uintb OpBehaviorIntXor::evaluateBinary(int4 sizeout,int4 sizein,uintb in1,uintb in2) const
{
uintb res = in1 ^ in2;
return res;
}
uintb OpBehaviorIntAnd::evaluateBinary(int4 sizeout,int4 sizein,uintb in1,uintb in2) const
{
uintb res = in1 & in2;
return res;
}
uintb OpBehaviorIntOr::evaluateBinary(int4 sizeout,int4 sizein,uintb in1,uintb in2) const
{
uintb res = in1 | in2;
return res;
}
uintb OpBehaviorIntLeft::evaluateBinary(int4 sizeout,int4 sizein,uintb in1,uintb in2) const
{
uintb res = (in1 << in2) & calc_mask(sizeout);
return res;
}
uintb OpBehaviorIntLeft::recoverInputBinary(int4 slot,int4 sizeout,uintb out,int4 sizein,uintb in) const
{
if (slot!=0)
return OpBehavior::recoverInputBinary(slot,sizeout,out,sizein,in);
int4 sa = in;
if (((out<<(8*sizeout-sa))&calc_mask(sizeout))!=0)
throw EvaluationError("Output is not in range of left shift operation");
return out >> sa;
}
uintb OpBehaviorIntRight::evaluateBinary(int4 sizeout,int4 sizein,uintb in1,uintb in2) const
{
uintb res = (in1&calc_mask(sizeout)) >> in2;
return res;
}
uintb OpBehaviorIntRight::recoverInputBinary(int4 slot,int4 sizeout,uintb out,int4 sizein,uintb in) const
{
if (slot!=0)
return OpBehavior::recoverInputBinary(slot,sizeout,out,sizein,in);
int4 sa = in;
if ((out>>(8*sizein-sa))!=0)
throw EvaluationError("Output is not in range of right shift operation");
return out << sa;
}
uintb OpBehaviorIntSright::evaluateBinary(int4 sizeout,int4 sizein,uintb in1,uintb in2) const
{
uintb res;
if (signbit_negative(in1,sizein)) {
res = in1 >> in2;
uintb mask = calc_mask(sizein);
mask = (mask >> in2) ^ mask;
res |= mask;
}
else {
res = in1 >> in2;
}
return res;
}
uintb OpBehaviorIntSright::recoverInputBinary(int4 slot,int4 sizeout,uintb out,int4 sizein,uintb in) const
{
if (slot!=0)
return OpBehavior::recoverInputBinary(slot,sizeout,out,sizein,in);
int4 sa = in;
uintb testval = out>>(sizein*8-sa-1);
int4 count=0;
for(int4 i=0;i<=sa;++i) {
if ((testval&1)!=0) count += 1;
testval >>= 1;
}
if (count != sa+1)
throw EvaluationError("Output is not in range of right shift operation");
return out<<sa;
}
uintb OpBehaviorIntMult::evaluateBinary(int4 sizeout,int4 sizein,uintb in1,uintb in2) const
{
uintb res = (in1 * in2) & calc_mask(sizeout);
return res;
}
uintb OpBehaviorIntDiv::evaluateBinary(int4 sizeout,int4 sizein,uintb in1,uintb in2) const
{
if (in2 == 0)
throw EvaluationError("Divide by 0");
return in1 / in2;
}
uintb OpBehaviorIntSdiv::evaluateBinary(int4 sizeout,int4 sizein,uintb in1,uintb in2) const
{
if (in2 == 0)
throw EvaluationError("Divide by 0");
intb num = in1; // Convert to signed
intb denom = in2;
sign_extend(num,8*sizein-1);
sign_extend(denom,8*sizein-1);
intb sres = num/denom; // Do the signed division
zero_extend(sres,8*sizeout-1); // Cut to appropriate size
return (uintb)sres; // Recast as unsigned
}
uintb OpBehaviorIntRem::evaluateBinary(int4 sizeout,int4 sizein,uintb in1,uintb in2) const
{
if (in2 == 0)
throw EvaluationError("Remainder by 0");
uintb res = in1 % in2;
return res;
}
uintb OpBehaviorIntSrem::evaluateBinary(int4 sizeout,int4 sizein,uintb in1,uintb in2) const
{
if (in2 == 0)
throw EvaluationError("Remainder by 0");
intb val = in1;
intb mod = in2;
sign_extend(val,8*sizein-1); // Convert inputs to signed values
sign_extend(mod,8*sizein-1);
intb sres = in1 % in2; // Do the remainder
zero_extend(sres,8*sizeout-1); // Convert back to unsigned
return (uintb)sres;
}
uintb OpBehaviorBoolNegate::evaluateUnary(int4 sizeout,int4 sizein,uintb in1) const
{
uintb res = in1 ^ 1;
return res;
}
uintb OpBehaviorBoolXor::evaluateBinary(int4 sizeout,int4 sizein,uintb in1,uintb in2) const
{
uintb res = in1 ^ in2;
return res;
}
uintb OpBehaviorBoolAnd::evaluateBinary(int4 sizeout,int4 sizein,uintb in1,uintb in2) const
{
uintb res = in1 & in2;
return res;
}
uintb OpBehaviorBoolOr::evaluateBinary(int4 sizeout,int4 sizein,uintb in1,uintb in2) const
{
uintb res = in1 | in2;
return res;
}
uintb OpBehaviorFloatEqual::evaluateBinary(int4 sizeout,int4 sizein,uintb in1,uintb in2) const
{
const FloatFormat *format = translate->getFloatFormat(sizein);
if (format == (const FloatFormat *)0)
return OpBehavior::evaluateBinary(sizeout,sizein,in1,in2);
return format->opEqual(in1,in2);
}
uintb OpBehaviorFloatNotEqual::evaluateBinary(int4 sizeout,int4 sizein,uintb in1,uintb in2) const
{
const FloatFormat *format = translate->getFloatFormat(sizein);
if (format == (const FloatFormat *)0)
return OpBehavior::evaluateBinary(sizeout,sizein,in1,in2);
return format->opNotEqual(in1,in2);
}
uintb OpBehaviorFloatLess::evaluateBinary(int4 sizeout,int4 sizein,uintb in1,uintb in2) const
{
const FloatFormat *format = translate->getFloatFormat(sizein);
if (format == (const FloatFormat *)0)
return OpBehavior::evaluateBinary(sizeout,sizein,in1,in2);
return format->opLess(in1,in2);
}
uintb OpBehaviorFloatLessEqual::evaluateBinary(int4 sizeout,int4 sizein,uintb in1,uintb in2) const
{
const FloatFormat *format = translate->getFloatFormat(sizein);
if (format == (const FloatFormat *)0)
return OpBehavior::evaluateBinary(sizeout,sizein,in1,in2);
return format->opLessEqual(in1,in2);
}
uintb OpBehaviorFloatNan::evaluateUnary(int4 sizeout,int4 sizein,uintb in1) const
{
const FloatFormat *format = translate->getFloatFormat(sizein);
if (format == (const FloatFormat *)0)
return OpBehavior::evaluateUnary(sizeout,sizein,in1);
return format->opNan(in1);
}
uintb OpBehaviorFloatAdd::evaluateBinary(int4 sizeout,int4 sizein,uintb in1,uintb in2) const
{
const FloatFormat *format = translate->getFloatFormat(sizein);
if (format == (const FloatFormat *)0)
return OpBehavior::evaluateBinary(sizeout,sizein,in1,in2);
return format->opAdd(in1,in2);
}
uintb OpBehaviorFloatDiv::evaluateBinary(int4 sizeout,int4 sizein,uintb in1,uintb in2) const
{
const FloatFormat *format = translate->getFloatFormat(sizein);
if (format == (const FloatFormat *)0)
return OpBehavior::evaluateBinary(sizeout,sizein,in1,in2);
return format->opDiv(in1,in2);
}
uintb OpBehaviorFloatMult::evaluateBinary(int4 sizeout,int4 sizein,uintb in1,uintb in2) const
{
const FloatFormat *format = translate->getFloatFormat(sizein);
if (format == (const FloatFormat *)0)
return OpBehavior::evaluateBinary(sizeout,sizein,in1,in2);
return format->opMult(in1,in2);
}
uintb OpBehaviorFloatSub::evaluateBinary(int4 sizeout,int4 sizein,uintb in1,uintb in2) const
{
const FloatFormat *format = translate->getFloatFormat(sizein);
if (format == (const FloatFormat *)0)
return OpBehavior::evaluateBinary(sizeout,sizein,in1,in2);
return format->opSub(in1,in2);
}
uintb OpBehaviorFloatNeg::evaluateUnary(int4 sizeout,int4 sizein,uintb in1) const
{
const FloatFormat *format = translate->getFloatFormat(sizein);
if (format == (const FloatFormat *)0)
return OpBehavior::evaluateUnary(sizeout,sizein,in1);
return format->opNeg(in1);
}
uintb OpBehaviorFloatAbs::evaluateUnary(int4 sizeout,int4 sizein,uintb in1) const
{
const FloatFormat *format = translate->getFloatFormat(sizein);
if (format == (const FloatFormat *)0)
return OpBehavior::evaluateUnary(sizeout,sizein,in1);
return format->opAbs(in1);
}
uintb OpBehaviorFloatSqrt::evaluateUnary(int4 sizeout,int4 sizein,uintb in1) const
{
const FloatFormat *format = translate->getFloatFormat(sizein);
if (format == (const FloatFormat *)0)
return OpBehavior::evaluateUnary(sizeout,sizein,in1);
return format->opSqrt(in1);
}
uintb OpBehaviorFloatInt2Float::evaluateUnary(int4 sizeout,int4 sizein,uintb in1) const
{
const FloatFormat *format = translate->getFloatFormat(sizeout);
if (format == (const FloatFormat *)0)
return OpBehavior::evaluateUnary(sizeout,sizein,in1);
return format->opInt2Float(in1,sizein);
}
uintb OpBehaviorFloatFloat2Float::evaluateUnary(int4 sizeout,int4 sizein,uintb in1) const
{
const FloatFormat *formatout = translate->getFloatFormat(sizeout);
if (formatout == (const FloatFormat *)0)
return OpBehavior::evaluateUnary(sizeout,sizein,in1);
const FloatFormat *formatin = translate->getFloatFormat(sizein);
if (formatin == (const FloatFormat *)0)
return OpBehavior::evaluateUnary(sizeout,sizein,in1);
return formatin->opFloat2Float(in1,*formatout);
}
uintb OpBehaviorFloatTrunc::evaluateUnary(int4 sizeout,int4 sizein,uintb in1) const
{
const FloatFormat *format = translate->getFloatFormat(sizein);
if (format == (const FloatFormat *)0)
return OpBehavior::evaluateUnary(sizeout,sizein,in1);
return format->opTrunc(in1,sizeout);
}
uintb OpBehaviorFloatCeil::evaluateUnary(int4 sizeout,int4 sizein,uintb in1) const
{
const FloatFormat *format = translate->getFloatFormat(sizein);
if (format == (const FloatFormat *)0)
return OpBehavior::evaluateUnary(sizeout,sizein,in1);
return format->opCeil(in1);
}
uintb OpBehaviorFloatFloor::evaluateUnary(int4 sizeout,int4 sizein,uintb in1) const
{
const FloatFormat *format = translate->getFloatFormat(sizein);
if (format == (const FloatFormat *)0)
return OpBehavior::evaluateUnary(sizeout,sizein,in1);
return format->opFloor(in1);
}
uintb OpBehaviorFloatRound::evaluateUnary(int4 sizeout,int4 sizein,uintb in1) const
{
const FloatFormat *format = translate->getFloatFormat(sizein);
if (format == (const FloatFormat *)0)
return OpBehavior::evaluateUnary(sizeout,sizein,in1);
return format->opRound(in1);
}
uintb OpBehaviorPiece::evaluateBinary(int4 sizeout,int4 sizein,uintb in1,uintb in2) const
{
uintb res = ( in1<<((sizeout-sizein)*8)) | in2;
return res;
}
uintb OpBehaviorSubpiece::evaluateBinary(int4 sizeout,int4 sizein,uintb in1,uintb in2) const
{
uintb res = (in1>>(in2*8)) & calc_mask(sizeout);
return res;
}
uintb OpBehaviorPopcount::evaluateUnary(int4 sizeout,int4 sizein,uintb in1) const
{
return (uintb)popcount(in1);
}