fix FASTCALL stack push, optimized size for multiple immediate value arguments
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
e76befaed7
commit
22b72ede9f
|
@ -62,29 +62,52 @@ namespace Instruction{
|
|||
}
|
||||
|
||||
void FastCall::initData(const std::vector<Token> &data) {
|
||||
uint32_t offset = 0;
|
||||
bool isAllData = true;
|
||||
for(auto& t : data){
|
||||
//TODO: optimize for immediate values
|
||||
if(offset >= 2){
|
||||
if(t.getType() == Token::Type::RegisterLocation){
|
||||
isAllData = false;
|
||||
break;
|
||||
}else{
|
||||
if(t.getType() == Token::Type::RegisterLocation){
|
||||
instructions.push_back(std::make_unique<Copy>(AddressWithOffset{(uint32_t)MgmtRegisters::MGMT_SCRATCH_0 + offset, 0}, AddressWithOffset{t.getNumericValue(), 0}, 1)); //TODO: allow offsets
|
||||
}else{
|
||||
instructions.push_back(std::make_unique<Write>(AddressWithOffset{(uint32_t)MgmtRegisters::MGMT_SCRATCH_0 + offset, 0}, std::vector<uint32_t>{t.getNumericValue()}));
|
||||
}
|
||||
}
|
||||
++offset;
|
||||
}
|
||||
|
||||
if(data.size() > 2){
|
||||
//Left to right
|
||||
for(uint32_t i = data.size() - 1; i > 2; --i){
|
||||
auto& t = data.at(i);
|
||||
if(t.getType() == Token::Type::RegisterLocation){
|
||||
instructions.push_back(std::make_unique<Stack::Push>(AddressWithOffset{t.getNumericValue(), 0})); //TODO: allow offsets
|
||||
if(isAllData){
|
||||
std::vector<uint32_t> scratchData;
|
||||
std::vector<uint32_t> stackData;
|
||||
for(uint32_t i = 0; i < data.size(); ++i){
|
||||
if(i < 2){
|
||||
scratchData.push_back(data.at(i).getNumericValue());
|
||||
}else{
|
||||
instructions.push_back(std::make_unique<Stack::PushImm>(t.getNumericValue()));
|
||||
stackData.push_back(data.at(i).getNumericValue());
|
||||
}
|
||||
}
|
||||
instructions.push_back(std::make_unique<Write>(AddressWithOffset{(uint32_t)MgmtRegisters::MGMT_SCRATCH_0, 0}, scratchData));
|
||||
if(!stackData.empty()){
|
||||
instructions.push_back(std::make_unique<Stack::PushImm>(stackData));
|
||||
}
|
||||
}else{
|
||||
uint32_t offset = 0;
|
||||
for(auto& t : data){
|
||||
if(offset >= 2){
|
||||
break;
|
||||
}else{
|
||||
if(t.getType() == Token::Type::RegisterLocation){
|
||||
instructions.push_back(std::make_unique<Copy>(AddressWithOffset{(uint32_t)MgmtRegisters::MGMT_SCRATCH_0 + offset, 0}, AddressWithOffset{t.getNumericValue(), 0}, 1)); //TODO: allow offsets
|
||||
}else{
|
||||
instructions.push_back(std::make_unique<Write>(AddressWithOffset{(uint32_t)MgmtRegisters::MGMT_SCRATCH_0 + offset, 0}, std::vector<uint32_t>{t.getNumericValue()}));
|
||||
}
|
||||
}
|
||||
++offset;
|
||||
}
|
||||
|
||||
if(data.size() > 2){
|
||||
//Left to right
|
||||
for(uint32_t i = data.size() - 1; i >= 2; --i){
|
||||
auto& t = data.at(i);
|
||||
if(t.getType() == Token::Type::RegisterLocation){
|
||||
instructions.push_back(std::make_unique<Stack::Push>(AddressWithOffset{t.getNumericValue(), 0})); //TODO: allow offsets
|
||||
}else{
|
||||
instructions.push_back(std::make_unique<Stack::PushImm>(t.getNumericValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue