14 #define TRG_SHORT_NAMES
15 #define TRGCDC_SHORT_NAMES
18 #include "trg/cdc/JSignal.h"
19 #include "trg/cdc/FpgaUtility.h"
20 #include "trg/cdc/JSignalData.h"
23 #include "FpgaUtility.h"
24 #include "JSignalData.h"
41 using std::stringstream;
85 m_toReal = 1 / ((pow(2, bitwidth - 1) - 0.5) / max(maxValue, fabs(minValue)));
87 m_toReal = 1 / ((pow(2, bitwidth) - 0.5) / maxValue);
101 checkInt(
"TRGCDCJSignal(int, int, double, double)");
107 (*this) =
TRGCDCJSignal(bitwidth, value, minValue, maxValue, 0, commonData);
111 signed long long const& maxInt,
double const& actual,
double const& minActual,
double const& maxActual,
int const& finishClock,
130 checkInt(
"TRGCDCJSignal(int, double, signed long long, signed long long, double, double, double)");
150 checkInt(
"TRGCDCJSignal(double, double)");
180 if (!(t_calFinishClock == -2 || t_calFinishClock == -1)) {
182 if (targetClock == -3) t_rhs.
m_finishClock = t_calFinishClock + 1;
184 if (targetClock < t_calFinishClock) cout <<
"[Error] TRGCDCJSignal::assign() => targetClock is too small." << endl;
191 if ((*this).m_bitsize != -1 || (*this).m_name !=
"")
195 if ((*this).m_bitsize == 1) {
197 if ((*this).m_bitsize != t_rhs.
m_bitsize) {
198 cout <<
"[Warning] TRGCDCJSignal::operator<=() => rhs and lhs do not have same bitsize." << endl;
201 if ((*this).m_type != t_rhs.
m_type) {
202 cout <<
"[Warning] TRGCDCJSignal::operator<=() => rhs and lhs do not have same type." << endl;
206 cout <<
"[Warning] TRGCDCJSignal::operator<=() => rhs and lhs do not have same clock." << endl;
241 string t_finalCode(finalCode);
245 if (t_finalCode ==
"printAssignVhdlCode") {
269 string finalCode =
"printAssignVhdlCode";
270 return assignTo(rhs, targetClock, finalCode);
275 string finalCode =
"printAssignVhdlCode";
276 return assignTo(rhs, -3, finalCode);
291 t_signal.
m_int *= -1;
292 t_signal.
m_minInt = -(*this).m_maxInt;
293 t_signal.
m_maxInt = -(*this).m_minInt;
324 cout <<
"TRGCDCJSignal::operator+=()" << endl;
325 cout <<
"<<<Input lhs>>>" << endl;
327 cout <<
"<<<Input lhs>>>" << endl;
328 cout <<
"<<<Input rhs>>>" << endl;
330 cout <<
"<<<Input rhs>>>" << endl;
358 t_result.
checkInt(
"TRGCDCJSignal::operator+");
360 cout <<
"<<<Output>>>" << endl;
362 cout <<
"<<<Output>>>" << endl;
363 cout <<
"TRGCDCJSignal::operator+=()" << endl;
386 cout <<
"TRGCDCJSignal::operator-=()" << endl;
387 cout <<
"<<<Input lhs>>>" << endl;
389 cout <<
"<<<Input lhs>>>" << endl;
390 cout <<
"<<<Input rhs>>>" << endl;
392 cout <<
"<<<Input rhs>>>" << endl;
420 t_result.
checkInt(
"TRGCDCJSignal::operator-");
422 cout <<
"<<<Output>>>" << endl;
424 cout <<
"<<<Output>>>" << endl;
425 cout <<
"TRGCDCJSignal::operator-=()" << endl;
449 cout <<
"TRGCDCJSignal::operator*=()" << endl;
450 cout <<
"<<<Input lhs>>>" << endl;
452 cout <<
"<<<Input lhs>>>" << endl;
453 cout <<
"<<<Input rhs>>>" << endl;
455 cout <<
"<<<Input rhs>>>" << endl;
458 int nBitsLargeShift = 0;
459 int nBitsSmallShift = 0;
461 if (t_large.
m_type == 1) {
463 nBitsLargeShift = t_large.
m_bitsize - 24;
464 t_large = t_large.
shift(nBitsLargeShift, 0);
468 nBitsLargeShift = t_large.
m_bitsize - 25;
469 t_large = t_large.
shift(nBitsLargeShift, 0);
472 if (t_small.
m_type == 1) {
474 nBitsSmallShift = t_small.
m_bitsize - 17;
475 t_small = t_small.
shift(nBitsSmallShift, 0);
479 nBitsSmallShift = t_small.
m_bitsize - 18;
480 t_small = t_small.
shift(nBitsSmallShift, 0);
485 if (orderSwap) cout << nBitsSmallShift <<
" bit right shifted input lhs>>>" << endl;
486 else cout << nBitsLargeShift <<
" bit right shifted input lhs>>>" << endl;
487 if (orderSwap) t_small.
dump();
489 cout <<
"<<<Shifted input lhs>>>" << endl;
491 if (orderSwap) cout << nBitsLargeShift <<
" bit right shifted input rhs>>>" << endl;
492 else cout << nBitsSmallShift <<
" bit right shifted input rhs>>>" << endl;
493 if (orderSwap) t_large.
dump();
495 cout <<
"<<<Shifted input rhs>>>" << endl;
527 t_result.
checkInt(
"TRGCDCJSignal::operator*");
529 cout <<
"<<<Output>>>" << endl;
531 cout <<
"<<<Output>>>" << endl;
532 cout <<
"TRGCDCJSignal::operator*=()" << endl;
542 cout <<
"-----------------------------------" << endl;
543 cout <<
"name: " <<
m_name << endl;
544 cout <<
"type: " <<
m_type << endl;
545 cout <<
"bitsize: " <<
m_bitsize << endl;
546 int t_org = cout.precision();
548 cout <<
"actual: " <<
m_actual << endl;
549 cout.precision(t_org);
550 cout <<
"int: " <<
m_int << endl;
551 cout <<
"minInt: " <<
m_minInt << endl;
552 cout <<
"maxInt: " <<
m_maxInt << endl;
556 cout <<
"toReal: " <<
m_toReal << endl;
559 cout <<
"-----------------------------------" << endl;
569 t_signal.
m_int = floor(this->
m_int / pow(2, nBits));
580 t_signal.
checkInt(
"TRGCDCJSignal::shift()");
585 }
else if (nBits != 0) {
598 if (t_offset.
calType() != 1) cout <<
"[Error] TRGCDCJSignal::offset() => t_offset min value below 0. " << endl;
601 t_offset.
checkInt(
"TRGCDCJSignal::offset()");
615 t_result.
checkInt(
"TRGCDCJSignal::invOffset()");
623 TRGCDCJSignal const& reference, std::vector<std::vector<TRGCDCJSignal> > data,
int targetClock)
630 if (data.size() == 0 || data.size() == 1) {
631 cout <<
"[Error] TRGCDCJSignal::choose() => There is not enough data." << endl;
634 if ((*(data.end() - 1)).size() != 1) {
635 cout <<
"[Error] TRGCDCJSignal::choose() => Last data doesn't contain 1 TRGCDCJSignal." << endl;
641 for (
unsigned iCondition = 0; iCondition < data.size(); iCondition++) {
643 assign = &(data[iCondition][0]);
647 if (targetClock == -3) target.m_finishClock = t_maxClock + 1;
649 if (targetClock < t_maxClock) cout <<
"[Error] TRGCDCJSignal::choose() => targetClock is too small." << endl;
650 else target.m_finishClock = targetClock;
655 signed long long t_minInt = targetMin.
m_minInt;
656 signed long long t_maxInt = targetMax.
m_maxInt;
659 for (
unsigned iCondition = 0; iCondition < data.size(); iCondition++) {
663 assign = &(data[iCondition][0]);
687 if (data[iCondition].size() != 1) {
689 from = &(data[iCondition][1]);
690 to = &(data[iCondition][2]);
709 for (
unsigned iCondition = 0; iCondition < data.size(); iCondition++) {
711 assign = &(data[iCondition][0]);
713 if (data[iCondition].size() == 1) {
714 string t_string =
"";
715 target.assignTo(*assign, target.m_finishClock, t_string);
721 string t_string =
"";
722 target.assignTo(*assign, target.m_finishClock, t_string);
728 for (
unsigned iCondition = 0; iCondition < data.size(); iCondition++) {
730 assign = &(data[iCondition][0]);
732 if (data[iCondition].size() == 1) {
733 target.m_actual = (*assign).m_actual;
738 assign = &(data[iCondition][0]);
740 target.m_actual = (*assign).m_actual;
746 target.checkInt(
"TRGCDCJSignal::choose()");
751 target.m_commonData->m_vhdlInProcess += t_finalCode +
"\n";
758 TRGCDCJSignal const& reference, std::vector<std::vector<TRGCDCJSignal> >& data)
760 choose(target, targetMin, targetMax, reference, data, -3);
767 signed long long t_minInt;
768 signed long long t_maxInt;
773 for (
unsigned iCondition = 0; iCondition < data.size(); iCondition++) {
775 assign = &(data[iCondition][0]);
776 if (iCondition == 0) {
787 if (t_toReal != assign->
getToReal()) cout <<
"[Error] TRGCDCJSignal::choose() => toReal are not same between assignments in data."
792 TRGCDCJSignal t_targetMax(t_maxInt, t_toReal, t_maxInt, t_maxInt, t_maxActual, t_maxActual, t_maxActual, -1, target.m_commonData);
793 TRGCDCJSignal t_targetMin(t_minInt, t_toReal, t_minInt, t_minInt, t_minActual, t_minActual, t_minActual, -1, target.m_commonData);
795 choose(target, t_targetMin, t_targetMax, reference, data, targetClock);
800 choose(target, reference, data, -3);
808 if (data.size() == 0) {
809 cout <<
"[Error] TRGCDCJSignal::ifElse() => There is not enough data." << endl;
816 for (
unsigned iCase = 0; iCase < data.size(); iCase++) {
818 if (iCase != (data.size() - 1)) {
819 if (
comp.
m_argumentSignals.size() == 0) cout <<
"[Error] TRGCDCJSignal::ifElse() => comp signal has no m_vhdl." << endl;
821 ||
comp.
m_maxInt != 1) cout <<
"[Error] TRGCDCJSignal::ifElse() => comp signal m_minInt or m_maxInt is not correct." << endl;
824 for (
unsigned iAssignment = 0; iAssignment < data[iCase].second.size(); iAssignment++) {
833 int t_maxClock = data[0].first.calFinishClock();
834 for (
unsigned iCase = 0; iCase < data.size(); iCase++) {
835 int t_clock = data[iCase].first.calFinishClock();
836 if (t_maxClock < t_clock) t_maxClock = t_clock;
838 for (
unsigned iAssignment = 0; iAssignment < data[iCase].second.size(); iAssignment++) {
839 TRGCDCJSignal const& rhs = data[iCase].second[iAssignment].second;
841 if (t_maxClock < t_clock) t_maxClock = t_clock;
844 int t_finishClock = 0;
845 if (targetClock == -3) {
846 if (t_maxClock < 0) cout <<
"[Error] TRGCDCJSignal::ifElse() => t_maxClock is negative. Did not consider this case." << endl;
847 t_finishClock = t_maxClock + 1;
849 if (targetClock < t_maxClock) cout <<
"[Error] TRGCDCJSignal::ifElse() => targetClock is too small." << endl;
850 else t_finishClock = targetClock;
854 for (
unsigned iCase = 0; iCase < data.size(); iCase++) {
857 for (
unsigned iAssignment = 0; iAssignment < data[iCase].second.size(); iAssignment++) {
865 map<TRGCDCJSignal*, pair<vector<long long int>, vector<double> > > t_signalsRange;
866 for (
unsigned iCase = 0; iCase < data.size(); iCase++) {
867 for (
unsigned iAssignment = 0; iAssignment < data[iCase].second.size(); iAssignment++) {
869 TRGCDCJSignal& lhs = *(data[iCase].second[iAssignment].first);
870 if (t_signalsRange.find(&lhs) == t_signalsRange.end()) {
873 t_signalsRange[&lhs] = make_pair(t_intRange, t_actualRange);
875 long long int& t_minInt = t_signalsRange[&lhs].first[0];
876 long long int& t_maxInt = t_signalsRange[&lhs].first[1];
877 double& t_minActual = t_signalsRange[&lhs].second[0];
878 double& t_maxActual = t_signalsRange[&lhs].second[1];
887 for (
unsigned iCase = 0; iCase < data.size(); iCase++) {
888 for (
unsigned iAssignment = 0; iAssignment < data[iCase].second.size(); iAssignment++) {
890 TRGCDCJSignal& lhs = *(data[iCase].second[iAssignment].first);
892 long long int& t_minInt = t_signalsRange[&lhs].first[0];
893 long long int& t_maxInt = t_signalsRange[&lhs].first[1];
894 double& t_minActual = t_signalsRange[&lhs].second[0];
895 double& t_maxActual = t_signalsRange[&lhs].second[1];
907 for (
unsigned iCase = 0; iCase < data.size(); iCase++) {
911 for (
unsigned iAssignment = 0; iAssignment < data[iCase].second.size(); iAssignment++) {
912 TRGCDCJSignal& lhs = *(data[iCase].second[iAssignment].first);
914 string t_string =
"";
915 lhs.
assignTo(rhs, t_finishClock, t_string);
917 lhs.
checkInt(
"TRGCDCJSignal::ifElse()");
924 for (
unsigned iCase = 0; iCase < data.size(); iCase++) {
928 for (
unsigned iAssignment = 0; iAssignment < data[iCase].second.size(); iAssignment++) {
929 TRGCDCJSignal& lhs = *(data[iCase].second[iAssignment].first);
938 if (data[0].first.getPrintVhdl() == 1) {
940 for (
unsigned iCase = 0; iCase < data.size(); iCase++) {
941 for (
unsigned iAssignment = 0; iAssignment < data[iCase].second.size(); iAssignment++) {
942 TRGCDCJSignal& lhs = *(data[iCase].second[iAssignment].first);
949 data[0].first.m_commonData->m_vhdlInProcess += t_finalCode +
"\n";
962 double maxActual)
const
990 return limit(min.m_int, max.m_int, min.m_actual, max.m_actual);
995 if (this->
m_bitsize == bitwidth)
return (*
this);
1002 t_result.
checkInt(
"TRGCDCJSignal::resize()");
1045 signed long long const& maxInt,
double const& actual,
double const& minActual,
double const& maxActual,
int const& finishClock)
1048 vector<bool>
const& slv = in.
m_slv;
1051 if (in.
m_type != 2) cout <<
"[Error] TRGCDCJSignal::slvToSigned() => type is not slv." << endl;
1052 if (slv.size() > 63) cout <<
"[Error] TRGCDCJSignal::slvToSigned() => bitwidth is too large." << endl;
1058 for (
unsigned iBit = 0; iBit < slv.size() - 1; iBit++) {
1059 result.m_int += slv[iBit] * pow(2, iBit);
1061 result.m_int -= slv[slv.size() - 1] * pow(2, slv.size() - 1);
1063 result.m_minInt = minInt;
1064 result.m_maxInt = maxInt;
1065 result.m_actual = actual;
1066 result.m_minActual = minActual;
1067 result.m_maxActual = maxActual;
1068 result.m_toReal = toReal;
1070 result.m_type = result.calType();
1071 result.m_bitsize = result.calBitwidth();
1072 result.m_finishClock = finishClock;
1074 result.checkInt(
"slvToSigned");
1086 signed long long const& maxInt,
double const& actual,
double const& minActual,
double const& maxActual,
int const& finishClock)
1089 vector<bool>
const& slv = in.
m_slv;
1092 if (in.
m_type != 2) cout <<
"[Error] TRGCDCJSignal::slvToUnsigned() => type is not slv." << endl;
1093 if (slv.size() > 63) cout <<
"[Error] TRGCDCJSignal::slvToUnsigned() => bitwidth is too large." << endl;
1099 for (
unsigned iBit = 0; iBit < slv.size(); iBit++) {
1100 result.m_int += slv[iBit] * pow(2, iBit);
1103 result.m_minInt = minInt;
1104 result.m_maxInt = maxInt;
1105 result.m_actual = actual;
1106 result.m_minActual = minActual;
1107 result.m_maxActual = maxActual;
1108 result.m_toReal = toReal;
1110 result.m_type = result.calType();
1111 result.m_bitsize = result.calBitwidth();
1112 result.m_finishClock = finishClock;
1114 result.checkInt(
"slvToSigned");
1132 signed long long t_int = in.
m_int;
1137 result.m_slv.clear();
1139 for (
int iBit = 0; iBit < in.
m_bitsize; iBit++) {
1140 result.m_slv[iBit] = (bool)(t_int >> iBit) & 1;
1142 }
else if (in.
m_type == 1) {
1144 result.m_slv.clear();
1146 for (
int iBit = 0; iBit < in.
m_bitsize; iBit++) {
1147 result.m_slv[iBit] = (bool)(t_int >> iBit) & 1;
1150 cout <<
"[Error] TRGCDCJSignal::toSlv() => m_type is not 1 or -1." << endl;
1158 if (in.
m_type == 2)
return (in);
1161 cout <<
"[Error] TRGCDCJSignal::toSlv() => Slv is not same as unsigned anymore." << endl;
1184 bool t_bool =
false;
1185 if (operate ==
"=") {
1186 t_bool = (t_lhs.
m_int == t_rhs.
m_int ? 1 : 0);
1187 }
else if (operate ==
"/=") {
1188 t_bool = (t_lhs.
m_int != t_rhs.
m_int ? 1 : 0);
1189 }
else if (operate ==
"<") {
1190 t_bool = (t_lhs.
m_int < t_rhs.
m_int ? 1 : 0);
1191 }
else if (operate ==
"<=") {
1192 t_bool = (t_lhs.
m_int <= t_rhs.
m_int ? 1 : 0);
1193 }
else if (operate ==
">") {
1194 t_bool = (t_lhs.
m_int > t_rhs.
m_int ? 1 : 0);
1195 }
else if (operate ==
">=") {
1196 t_bool = (t_lhs.
m_int >= t_rhs.
m_int ? 1 : 0);
1197 }
else if (operate ==
"and") {
1198 t_bool = (t_lhs.
m_int && t_rhs.
m_int ? 1 : 0);
1199 }
else if (operate ==
"or") {
1200 t_bool = (t_lhs.
m_int || t_rhs.
m_int ? 1 : 0);
1202 cout <<
"[Error] TRGCDCJSignal::comp() => No operator named " << operate <<
"." << endl;
1205 if (operate ==
"=") {
1207 }
else if (operate ==
"/=") {
1209 }
else if (operate ==
"<") {
1211 }
else if (operate ==
"<=") {
1213 }
else if (operate ==
">") {
1215 }
else if (operate ==
">=") {
1217 }
else if (operate ==
"and") {
1219 }
else if (operate ==
"or") {
1222 cout <<
"[Error] TRGCDCJSignal::comp() => No operator named " << operate <<
"." << endl;
1247 std::swap(first.m_name, second.m_name);
1248 std::swap(first.m_type, second.m_type);
1249 std::swap(first.m_bitsize, second.m_bitsize);
1250 std::swap(first.m_int, second.m_int);
1251 std::swap(first.m_minInt, second.m_minInt);
1252 std::swap(first.m_maxInt, second.m_maxInt);
1253 std::swap(first.m_actual, second.m_actual);
1254 std::swap(first.m_minActual, second.m_minActual);
1255 std::swap(first.m_maxActual, second.m_maxActual);
1256 std::swap(first.m_toReal, second.m_toReal);
1257 std::swap(first.m_debug, second.m_debug);
1258 std::swap(first.m_vhdlCode, second.m_vhdlCode);
1259 std::swap(first.m_argumentSignals, second.m_argumentSignals);
1260 std::swap(first.m_finishClock, second.m_finishClock);
1261 std::swap(first.m_commonData, second.m_commonData);
1266 if (first.m_toReal != second.m_toReal) {
1268 double t_nBits = log(first.m_toReal / second.m_toReal) / log(2);
1271 t_nBits = int(t_nBits + 0.5);
1273 t_nBits = int(t_nBits - 0.5);
1277 first = first.shift(-t_nBits, 0);
1280 }
else if (t_nBits < 0) {
1281 second = second.shift(t_nBits, 0);
1286 if (fabs(first.m_toReal - second.m_toReal) > 0.00001 * first.m_toReal) {
1287 cout <<
"[Warning] TRGCDCJSignal::matchUnit() => in1 and in2 units are still different." << endl;
1288 cout << first.m_toReal <<
" " << second.m_toReal << endl;
1292 cout <<
"TRGCDCJSignal::matchUnit()" << endl;
1293 if (t_nBits > 0) cout <<
"lhs was shifted to left by " << t_nBits << endl;
1294 else if (t_nBits < 0) cout <<
"rhs was shifted to left by " << -t_nBits << endl;
1295 cout <<
"TRGCDCJSignal::matchUnit()" << endl;
1298 first.checkInt(
"TRGCDCJSignal::matchUnit()::first");
1299 second.checkInt(
"TRGCDCJSignal::matchUnit()::second");
1332 checkInt(
"TRGCDCJSignal::setBitsize()");
1349 cout <<
"[Error] TRGCDCJSignal::setPrintVhdl() => m_commonData does not exist." << endl;
1357 cout <<
"[Error] TRGCDCJSignal::setVhdlOutputFile() => m_commonData does not exist." << endl;
1445 cout <<
"[Error] TRGCDCJSignal::getCommonData() => m_commonData does not exist." << endl;
1461 if (minValue < 0)
return -1;
1469 if (
calType() != 1) t_bitwidth++;
1476 int t_bitwidth = ceil(log1p(max(maxInt, llabs(minInt))) / log(2));
1477 if (type != 1) t_bitwidth++;
1505 cout <<
"[Error] TRGCDCJSignal::getPrintVhdl() => m_commonData does not exist." << endl;
1514 cout <<
"[Error] TRGCDCJSignal::getVhdlOutputFile() => m_commonData does not exist." << endl;
1526 if (large.
m_type == 1) {;}
1541 signed long long t_maxValue;
1555 signed long long t_minValue;
1558 }
else if (
m_type == -1) {
1559 t_minValue = -pow(2,
m_bitsize - 1) + 1;
1561 t_minValue = -pow(2,
m_bitsize - 1) + 1;
1573 if (result.m_argumentSignals.size() == 0) result.initArgumentSignals();
1575 if (result.m_type != 1) {
1577 result.m_int = llabs(first.m_int);
1578 if (first.m_minInt < 0 && first.m_maxInt > 0) result.m_minInt = 0;
1579 else result.m_minInt = min(llabs(first.m_maxInt), llabs(first.m_minInt));
1580 result.m_maxInt = max(llabs(first.m_maxInt), llabs(first.m_minInt));
1581 result.m_actual = fabs(first.m_actual);
1582 if (first.m_minActual < 0 && first.m_maxActual > 0) result.m_minActual = 0;
1583 else result.m_minActual = min(fabs(first.m_maxActual), fabs(first.m_minActual));
1584 result.m_maxActual = max(fabs(first.m_maxActual), fabs(first.m_minActual));
1585 result.m_bitsize = first.m_bitsize - 1;
1588 result.checkInt(
"TRGCDCJSignal::absolute()");
1591 if (first.getPrintVhdl() == 1)
vhdlCode(
"abs", first, result, result.m_vhdlCode);
1674 if (first.m_type != second.m_type) {
1675 cout <<
"[Error] TRGCDCJSignal::calVhdlTypeBitwidth() => first and second type are different." << endl;
1676 cout << first.m_name <<
" " << second.m_name << endl;
1677 cout << first.m_type <<
" " << second.m_type << endl;
1680 int firstBitwidth = first.m_bitsize;
1681 int secondBitwidth = second.m_bitsize;
1683 if (operation ==
"+" || operation ==
"-") {
1684 if (first.m_type != 1 || second.m_type != 1) {
1686 bitwidth = max(firstBitwidth, secondBitwidth);
1689 bitwidth = max(first.m_bitsize, second.m_bitsize);
1691 }
else if (operation ==
"*") {
1692 if (first.m_type != 1 || second.m_type != 1) {
1694 bitwidth = firstBitwidth + secondBitwidth;
1697 bitwidth = first.m_bitsize + second.m_bitsize;
1699 }
else if (operation ==
"=" || operation ==
"/=" || operation ==
"<" || operation ==
"<=" ||
1700 operation ==
">" || operation ==
">=" || operation ==
"and" || operation ==
"or") {
1704 cout <<
"[Error] TRGCDCJSignal::calVhdlTypeBitwidth() => No operation named " << operation <<
"." << endl;
1715 t_name =
"decimal_string_to_unsigned(\"" + to_string(
m_int) +
"\"," + to_string(
m_bitsize) +
")";
1718 t_name =
"decimal_string_to_signed(\"" + to_string(
m_int) +
"\"," + to_string(
m_bitsize) +
")";
1721 }
else if (
m_name ==
"") {
1722 t_name =
"INPUT(" + to_string(
m_int) +
")";
1731 cout <<
"[Error] TRGCDCJSignal::initArgumentSignals() => m_argumentSignals.size() is not 0." << endl;
1737 result.m_argumentSignals.clear();
1738 result.m_argumentSignals.insert(result.m_argumentSignals.end(), first.m_argumentSignals.begin(), first.m_argumentSignals.end());
1739 result.m_argumentSignals.insert(result.m_argumentSignals.end(), second.m_argumentSignals.begin(), second.m_argumentSignals.end());
1745 cout <<
"[Error] TRGCDCJSignal::initVhdlCode() => m_vhdlCode is not \"\"." << endl;
1753 if (
m_type == -1)
return;
1756 if (
calType() == 1) t_bitwidth++;
1760 }
else if (t_bitwidth - 1 ==
m_bitsize) {
1764 cout <<
"[Error] TRGCDCJSignal::toSignedVhdlCode() => m_bitsize is too small." << endl;
1774 cout <<
"[Warning] TRGCDCJSignal::toUnsignedVhdlCode() => signal can be minus." << endl;
1798 if (t_first.
m_type * t_second.
m_type < 0 || (t_first.
m_type != -1 && result.m_type == -1)) {
1799 if (t_first.
m_type != -1) {
1802 if (t_second.
m_type != -1) {
1811 int logicType, logicBitwidth, vhdlType, vhdlBitwidth;
1812 logicType = result.m_type;
1813 logicBitwidth = result.m_bitsize;
1819 if (operation ==
"=" || operation ==
"/=" || operation ==
"<" || operation ==
"<=" ||
1820 operation ==
">" || operation ==
">=" || operation ==
"and" || operation ==
"or") {
1825 if (logicType > 0 && vhdlType == -1) {
1826 if (logicBitwidth + 1 > vhdlBitwidth) t_first.
m_vhdlCode =
"resize(" + t_first.
m_vhdlCode +
"," + to_string(
1827 logicBitwidth + 1) +
")";
1829 resultCode =
"resize(unsigned(" + resultCode +
")," + to_string(logicBitwidth) +
")";
1832 if (logicBitwidth > vhdlBitwidth) {
1837 if (logicBitwidth < vhdlBitwidth) {
1838 resultCode =
"resize(" + resultCode +
"," + to_string(logicBitwidth) +
")";
1842 resultVhdlCode = resultCode;
1855 if (t_first.
m_type != -1 && result.m_type == -1) {
1862 int logicType, logicBitwidth, vhdlType, vhdlBitwidth;
1863 logicType = result.m_type;
1864 logicBitwidth = result.m_bitsize;
1866 vhdlType = t_first.
m_type;
1872 if (logicType == 1 && vhdlType == -1) {
1873 if (logicBitwidth + 1 > vhdlBitwidth) t_first.
m_vhdlCode =
"resize(" + t_first.
m_vhdlCode +
"," + to_string(
1874 logicBitwidth + 1) +
")";
1875 if (operation ==
"shift_left"
1876 || operation ==
"shift_right") resultCode = operation +
"(" + t_first.
m_vhdlCode +
"," + to_string(abs(
1877 first.m_bitsize - result.m_bitsize)) +
")";
1878 else if (operation ==
"unsigned" || operation ==
"none") resultCode = t_first.
m_vhdlCode;
1879 else resultCode = operation +
"(" + t_first.
m_vhdlCode +
")";
1880 resultCode =
"resize(unsigned(" + resultCode +
")," + to_string(logicBitwidth) +
")";
1883 if (logicBitwidth > vhdlBitwidth) {
1886 if (operation ==
"shift_left"
1887 || operation ==
"shift_right") resultCode = operation +
"(" + t_first.
m_vhdlCode +
"," + to_string(abs(
1888 first.m_bitsize - result.m_bitsize)) +
")";
1889 else if (operation ==
"resize" || operation ==
"signed" || operation ==
"none") resultCode = t_first.
m_vhdlCode;
1890 else resultCode = operation +
"(" + t_first.
m_vhdlCode +
")";
1892 if (logicBitwidth < vhdlBitwidth) {
1893 resultCode =
"resize(" + resultCode +
"," + to_string(logicBitwidth) +
")";
1896 resultVhdlCode = resultCode;
1900 std::vector<pair<std::string, vector<int> > >
const& fromArgumentSignals,
int const& finishClock,
1901 std::map<std::string, vector<int> >& buffers)
1904 string t_vhdlCode =
"";
1906 size_t end = fromVhdlCode.find(
" ");
1907 int nIndex = (int)fromArgumentSignals.size();
1909 while (end != string::npos) {
1911 if (nIndex - 1 < index) {
1912 cout <<
"[Error] TRGCDCJSignal::replaceWithSignalNames() => Not enough signal names in m_argumentSignals." << endl;
1917 int t_buffer = (finishClock - 1) - fromArgumentSignals[index].second[2] - 1;
1919 if (t_buffer == -1 || t_buffer == -2
1920 || fromArgumentSignals[index].second[2] == -1) t_vhdlCode += fromVhdlCode.substr(start,
1921 end - start) + fromArgumentSignals[index].first;
1922 else if (t_buffer > -1) {
1923 t_vhdlCode += fromVhdlCode.substr(start, end - start) + fromArgumentSignals[index].first +
"_b(" + to_string(t_buffer) +
")";
1925 if (buffers.find(fromArgumentSignals[index].first) == buffers.end()) {
1926 buffers[fromArgumentSignals[index].first] = {fromArgumentSignals[index].second[0], fromArgumentSignals[index].second[1], t_buffer};
1928 if (buffers[fromArgumentSignals[index].first][2] < t_buffer) buffers[fromArgumentSignals[index].first][2] = t_buffer;
1931 cout <<
"[Error] TRGCDCJSignal::replaceWithSignalNames() => finishClock is too small." << endl;
1932 t_vhdlCode += fromVhdlCode.substr(start, end - start) + fromArgumentSignals[index].first;
1937 end = fromVhdlCode.find(
" ", start);
1939 t_vhdlCode += fromVhdlCode.substr(start, end - start);
1941 if (nIndex != index) {
1942 cout <<
"[Error] TRGCDCJSignal::replaceWithSignalNames() => Number of signal names and number of " " do not match." << endl;
1952 if (target.m_commonData == 0) {
1953 cout <<
"[Error] TRGCDCJSignal::assignVhdlCode() => target.m_commonData is not set." << endl;
1966 if (target.m_name ==
"") cout <<
"[Error] TRGCDCJSignal::assignVhdlCode() => target.m_name is \"\" " << endl;
1967 map<string, vector<int> >& t_signals = target.m_commonData->m_signals;
1968 if (t_signals.find(target.m_name) == t_signals.end()) {
1979 return target.m_name +
"<=" + t_vhdlCode +
";";
2004 std::vector<std::vector<TRGCDCJSignal> >
const& data)
2007 if (target.m_name ==
"") {
2008 cout <<
"[Error] TRGCDCJSignal::chooseVhdlCode() => target has no name." << endl;
2013 cout <<
"[Error] TRGCDCJSignal::cooseVhdlCode() => reference has no name or vhdlCode." << endl;
2026 map<signed long long, bool> t_used;
2028 stringstream t_vhdlCode;
2055 target.m_commonData->m_buffers);
2057 target.m_commonData->m_buffers);
2058 string t_fromPrefixSigned;
2059 string t_fromPostfixSigned;
2060 string t_toPrefixSigned;
2061 string t_toPostfixSigned;
2063 t_fromPrefixSigned =
"signed('0'&";
2064 t_fromPostfixSigned =
")";
2066 t_fromPrefixSigned =
"";
2067 t_fromPostfixSigned =
"";
2070 t_toPrefixSigned =
"signed('0'&";
2071 t_toPostfixSigned =
")";
2073 t_toPrefixSigned =
"";
2074 t_toPostfixSigned =
"";
2076 t_vhdlCode <<
"if (" << t_referenceVhdlCode <<
" >= " << t_fromPrefixSigned << t_fromVhdlCode << t_fromPostfixSigned <<
") and (" <<
2077 t_referenceVhdlCode <<
" <= " << t_toPrefixSigned << t_toVhdlCode << t_toPostfixSigned <<
") then" << endl;
2081 for (
unsigned iCondition = 1; iCondition < data.size() - 1; iCondition++) {
2088 t_fromPrefixSigned =
"signed('0'&";
2089 t_fromPostfixSigned =
")";
2091 t_fromPrefixSigned =
"";
2092 t_fromPostfixSigned =
"";
2095 t_toPrefixSigned =
"signed('0'&";
2096 t_toPostfixSigned =
")";
2098 t_toPrefixSigned =
"";
2099 t_toPostfixSigned =
"";
2102 target.m_commonData->m_buffers);
2104 t_vhdlCode <<
"elsif (" << t_referenceVhdlCode <<
" >= " << t_fromPrefixSigned << t_fromVhdlCode << t_fromPostfixSigned <<
") and ("
2105 << t_referenceVhdlCode <<
" <= " << t_toPrefixSigned << t_toVhdlCode << t_toPostfixSigned <<
") then" << endl;
2108 t_vhdlCode <<
"else" << endl;
2109 t_vhdlCode <<
" " <<
assignVhdlCode(target, (*(data.end() - 1))[0]) << endl;
2110 t_vhdlCode <<
"end if;";
2111 return t_vhdlCode.str();
2115 std::vector<std::pair<
TRGCDCJSignal, std::vector<std::pair<TRGCDCJSignal*, TRGCDCJSignal> > > >
const& data)
2118 for (
unsigned iCase = 0; iCase < data.size(); iCase++) {
2120 if (iCase != data.size() - 1) {
2122 cout <<
"[Error] TRGCDCJSignal::ifElseVhdlCode() => comp has no name." << endl;
2126 for (
unsigned iAssignment = 0; iAssignment < data[iCase].second.size(); iAssignment++) {
2127 TRGCDCJSignal const& lhs = *(data[iCase].second[iAssignment].first);
2129 cout <<
"[Error] TRGCDCJSignal::ifElseVhdlCode() => lhs has no name." << endl;
2137 stringstream t_vhdlCode;
2138 for (
unsigned iCase = 0; iCase < data.size(); iCase++) {
2143 if (iCase == 0) t_vhdlCode <<
"if " << t_compVhdlCode <<
" then" << endl;
2144 else if (
comp.
m_bitsize == -1) t_vhdlCode <<
"else" << endl;
2145 else t_vhdlCode <<
"elsif " << t_compVhdlCode <<
" then" << endl;
2146 for (
unsigned iAssignment = 0; iAssignment < data[iCase].second.size(); iAssignment++) {
2147 TRGCDCJSignal const& lhs = *(data[iCase].second[iAssignment].first);
2148 TRGCDCJSignal const& rhs = data[iCase].second[iAssignment].second;
2152 t_vhdlCode <<
"end if;";
2154 return t_vhdlCode.str();
2163 if (outFile.is_open()) {
2168 cout <<
"[Error] TRGCDCJSignal::printVhdl() => m_commonData doesn't exist." << endl;
2175 cout <<
"[Error] " << name <<
" => m_int overflow" << endl;
2176 cout <<
" Start dumping" << endl;
2178 cout <<
" End dumping" << endl;
2181 cout <<
"[Error] " << name <<
" => m_int underflow" << endl;
2182 cout <<
" Start dumping" << endl;
2184 cout <<
" End dumping" << endl;
2187 cout <<
"[Error] " << name <<
" => m_maxInt overflow" << endl;
2188 cout <<
" Start dumping" << endl;
2190 cout <<
" End dumping" << endl;
2193 cout <<
"[Error] " << name <<
" => m_minInt underflow" << endl;
2194 cout <<
" Start dumping" << endl;
2196 cout <<
" End dumping" << endl;
2210 for (
unsigned iSignals = 0; iSignals < inValues.size(); iSignals++) {
2211 string const& t_name = get<0>(inValues[iSignals]);
2212 double const& t_value = get<1>(inValues[iSignals]);
2213 int const& t_bitWidth = get<2>(inValues[iSignals]);
2214 double const& t_min = get<3>(inValues[iSignals]);
2215 double const& t_max = get<4>(inValues[iSignals]);
2216 int const& t_clock = get<5>(inValues[iSignals]);
2225 std::vector<std::pair<std::string, int> >
const& inChoose,
2226 std::vector<std::tuple<string, double, int, double, double, int> >& outValues)
2228 for (
unsigned iSignals = 0; iSignals < inChoose.size(); iSignals++) {
2229 int const& b_integerEffect = inChoose[iSignals].second;
2230 string const& t_name = inChoose[iSignals].first;
2232 double t_value = 0, t_min = 0, t_max = 0;
2234 if (b_integerEffect == 1) {
2244 tuple<string, double, int, double, double, int> outValue(t_name, t_value, t_bitwidth, t_min, t_max, t_clock);
2245 outValues.push_back(outValue);