Browse Source

Merge pull request #281 from giact/develop

Fixed bug in EXP opcode; some gui improvements useful for testing
cl-refactor
Gav Wood 11 years ago
parent
commit
b58f506689
  1. 14
      alethzero/Main.ui
  2. 23
      alethzero/MainWin.cpp
  3. 2
      alethzero/MainWin.h
  4. 4
      libevm/VM.h
  5. 10
      liblll/Assembly.cpp

14
alethzero/Main.ui

@ -185,6 +185,7 @@
<addaction name="killBlockchain"/> <addaction name="killBlockchain"/>
<addaction name="inject"/> <addaction name="inject"/>
<addaction name="forceMining"/> <addaction name="forceMining"/>
<addaction name="enableOptimizer"/>
</widget> </widget>
<addaction name="menu_File"/> <addaction name="menu_File"/>
<addaction name="menu_Network"/> <addaction name="menu_Network"/>
@ -563,7 +564,7 @@
</widget> </widget>
<widget class="QTextEdit" name="code"> <widget class="QTextEdit" name="code">
<property name="focusPolicy"> <property name="focusPolicy">
<enum>Qt::NoFocus</enum> <enum>Qt::ClickFocus</enum>
</property> </property>
<property name="frameShape"> <property name="frameShape">
<enum>QFrame::NoFrame</enum> <enum>QFrame::NoFrame</enum>
@ -571,6 +572,9 @@
<property name="lineWidth"> <property name="lineWidth">
<number>0</number> <number>0</number>
</property> </property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget> </widget>
</widget> </widget>
</item> </item>
@ -1664,6 +1668,14 @@ font-size: 14pt</string>
<string>&amp;Refresh</string> <string>&amp;Refresh</string>
</property> </property>
</action> </action>
<action name="enableOptimizer">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>&amp;Enable LLL &amp;Optimizer</string>
</property>
</action>
</widget> </widget>
<layoutdefault spacing="6" margin="11"/> <layoutdefault spacing="6" margin="11"/>
<customwidgets> <customwidgets>

23
alethzero/MainWin.cpp

@ -332,6 +332,12 @@ void Main::on_forceMining_triggered()
m_client->setForceMining(ui->forceMining->isChecked()); m_client->setForceMining(ui->forceMining->isChecked());
} }
void Main::on_enableOptimizer_triggered()
{
m_enableOptimizer = ui->enableOptimizer->isChecked();
on_data_textChanged();
}
void Main::load(QString _s) void Main::load(QString _s)
{ {
QFile fin(_s); QFile fin(_s);
@ -523,6 +529,7 @@ void Main::writeSettings()
s.setValue("paranoia", ui->paranoia->isChecked()); s.setValue("paranoia", ui->paranoia->isChecked());
s.setValue("showAll", ui->showAll->isChecked()); s.setValue("showAll", ui->showAll->isChecked());
s.setValue("showAllAccounts", ui->showAllAccounts->isChecked()); s.setValue("showAllAccounts", ui->showAllAccounts->isChecked());
s.setValue("enableOptimizer", m_enableOptimizer);
s.setValue("clientName", ui->clientName->text()); s.setValue("clientName", ui->clientName->text());
s.setValue("idealPeers", ui->idealPeers->value()); s.setValue("idealPeers", ui->idealPeers->value());
s.setValue("port", ui->port->value()); s.setValue("port", ui->port->value());
@ -570,6 +577,8 @@ void Main::readSettings(bool _skipGeometry)
ui->paranoia->setChecked(s.value("paranoia", false).toBool()); ui->paranoia->setChecked(s.value("paranoia", false).toBool());
ui->showAll->setChecked(s.value("showAll", false).toBool()); ui->showAll->setChecked(s.value("showAll", false).toBool());
ui->showAllAccounts->setChecked(s.value("showAllAccounts", false).toBool()); ui->showAllAccounts->setChecked(s.value("showAllAccounts", false).toBool());
m_enableOptimizer = s.value("enableOptimizer", true).toBool();
ui->enableOptimizer->setChecked(m_enableOptimizer);
ui->clientName->setText(s.value("clientName", "").toString()); ui->clientName->setText(s.value("clientName", "").toString());
ui->idealPeers->setValue(s.value("idealPeers", ui->idealPeers->value()).toInt()); ui->idealPeers->setValue(s.value("idealPeers", ui->idealPeers->value()).toInt());
ui->port->setValue(s.value("port", ui->port->value()).toInt()); ui->port->setValue(s.value("port", ui->port->value()).toInt());
@ -1302,9 +1311,7 @@ void Main::on_data_textChanged()
} }
else else
{ {
auto asmcode = eth::compileLLLToAsm(src, false); m_data = eth::compileLLL(src, m_enableOptimizer, &errors);
auto asmcodeopt = eth::compileLLLToAsm(ui->data->toPlainText().toStdString(), true);
m_data = eth::compileLLL(ui->data->toPlainText().toStdString(), true, &errors);
if (errors.size()) if (errors.size())
{ {
try try
@ -1319,7 +1326,15 @@ void Main::on_data_textChanged()
} }
} }
else else
lll = "<h4>Opt</h4><pre>" + QString::fromStdString(asmcodeopt).toHtmlEscaped() + "</pre><h4>Pre</h4><pre>" + QString::fromStdString(asmcode).toHtmlEscaped() + "</pre>"; {
auto asmcode = eth::compileLLLToAsm(src, false);
lll = "<h4>Pre</h4><pre>" + QString::fromStdString(asmcode).toHtmlEscaped() + "</pre>";
if (m_enableOptimizer)
{
asmcode = eth::compileLLLToAsm(src, true);
lll = "<h4>Opt</h4><pre>" + QString::fromStdString(asmcode).toHtmlEscaped() + "</pre>" + lll;
}
}
} }
QString errs; QString errs;
if (errors.size()) if (errors.size())

2
alethzero/MainWin.h

@ -138,6 +138,7 @@ private slots:
void on_debugDumpState_triggered(int _add = 1); void on_debugDumpState_triggered(int _add = 1);
void on_debugDumpStatePre_triggered(); void on_debugDumpStatePre_triggered();
void on_refresh_triggered(); void on_refresh_triggered();
void on_enableOptimizer_triggered();
signals: signals:
void poll(); void poll();
@ -221,6 +222,7 @@ private:
QMap<unsigned, unsigned> m_pcWarp; QMap<unsigned, unsigned> m_pcWarp;
QList<WorldState> m_history; QList<WorldState> m_history;
std::map<eth::u256, eth::bytes> m_codes; // and pcWarps std::map<eth::u256, eth::bytes> m_codes; // and pcWarps
bool m_enableOptimizer = true;
QNetworkAccessManager m_webCtrl; QNetworkAccessManager m_webCtrl;

4
libevm/VM.h

@ -241,9 +241,9 @@ template <class Ext> eth::bytesConstRef eth::VM::go(Ext& _ext, OnOpFunc const& _
{ {
require(2); require(2);
auto base = m_stack.back(); auto base = m_stack.back();
unsigned expon = (unsigned)m_stack[m_stack.size() - 2]; auto expon = m_stack[m_stack.size() - 2];
m_stack.pop_back(); m_stack.pop_back();
m_stack.back() = boost::multiprecision::pow(base, expon); m_stack.back() = (u256)boost::multiprecision::powm((bigint)base, (bigint)expon, bigint(2) << 256);
break; break;
} }
case Instruction::NEG: case Instruction::NEG:

10
liblll/Assembly.cpp

@ -227,14 +227,14 @@ Assembly& Assembly::optimise(bool _enable)
{ {
{ Instruction::SUB, [](u256 a, u256 b)->u256{return a - b;} }, { Instruction::SUB, [](u256 a, u256 b)->u256{return a - b;} },
{ Instruction::DIV, [](u256 a, u256 b)->u256{return a / b;} }, { Instruction::DIV, [](u256 a, u256 b)->u256{return a / b;} },
{ Instruction::SDIV, [](u256 a, u256 b)->u256{return s2u(u2s(a) / u2s(b));} }, { Instruction::SDIV, [](u256 a, u256 b)->u256{return s2u(u2s(a) / u2s(b));} },
{ Instruction::MOD, [](u256 a, u256 b)->u256{return a % b;} }, { Instruction::MOD, [](u256 a, u256 b)->u256{return a % b;} },
{ Instruction::SMOD, [](u256 a, u256 b)->u256{return s2u(u2s(a) % u2s(b));} }, { Instruction::SMOD, [](u256 a, u256 b)->u256{return s2u(u2s(a) % u2s(b));} },
{ Instruction::EXP, [](u256 a, u256 b)->u256{return boost::multiprecision::pow(a, (unsigned)b);} }, { Instruction::EXP, [](u256 a, u256 b)->u256{return (u256)boost::multiprecision::powm((bigint)a, (bigint)b, bigint(2) << 256);} },
{ Instruction::LT, [](u256 a, u256 b)->u256{return a < b ? 1 : 0;} }, { Instruction::LT, [](u256 a, u256 b)->u256{return a < b ? 1 : 0;} },
{ Instruction::GT, [](u256 a, u256 b)->u256{return a > b ? 1 : 0;} }, { Instruction::GT, [](u256 a, u256 b)->u256{return a > b ? 1 : 0;} },
{ Instruction::SLT, [](u256 a, u256 b)->u256{return u2s(a) < u2s(b) ? 1 : 0;} }, { Instruction::SLT, [](u256 a, u256 b)->u256{return u2s(a) < u2s(b) ? 1 : 0;} },
{ Instruction::SGT, [](u256 a, u256 b)->u256{return u2s(a) > u2s(b) ? 1 : 0;} }, { Instruction::SGT, [](u256 a, u256 b)->u256{return u2s(a) > u2s(b) ? 1 : 0;} },
{ Instruction::EQ, [](u256 a, u256 b)->u256{return a == b ? 1 : 0;} }, { Instruction::EQ, [](u256 a, u256 b)->u256{return a == b ? 1 : 0;} },
}; };
map<Instruction, function<u256(u256, u256)>> c_associative = map<Instruction, function<u256(u256, u256)>> c_associative =

Loading…
Cancel
Save