Optimize swp and req with two-item queue

This commit is contained in:
0x4261756D 2023-07-28 07:04:39 +02:00
parent 92f7ec405d
commit b1cb4a0a0e
1 changed files with 29 additions and 1 deletions

View File

@ -357,7 +357,7 @@ fn merge_assemblies(data: &mut AssemblyData, data2: AssemblyData)
data.strings += data2.strings.as_str();
}
const ASSEMBLY_LINUX_X64_QUEUE_LENGTH: u32 = 1024;
const ASSEMBLY_LINUX_X64_QUEUE_LENGTH: u32 = 8192;
const ASSEMBLY_LINUX_X64_HEADER: &str = "format ELF64 executable 3\n";
const ASSEMBLY_LINUX_X64_TRY_RESET_QUEUE: &str = "\tcmp r12, r13\n\tcmove r12, r14\n\tcmove r13, r14\n";
const ASSEMBLY_LINUX_X64_EXIT: &str = "\tmov rax, 60\n\tmov rdi, 0\n\tsyscall\n";
@ -529,16 +529,34 @@ fn generate_assembly_linux_x64_block(operations: &Vec<Operation>, functions: &Ve
Operation::Requeue(line, col) =>
{
data.code += format!("\t;;req {}:{}\n", line, col).as_str();
data.code += "\tmov rax, r13\n";
data.code += "\tsub rax, r12\n";
data.code += "\tcmp rax, 2\n";
data.code += format!("\tje req_{line}_{col}_special\n").as_str();
data.code += "\tmov rax, [queue+8*r12]\n";
data.code += "\tinc r12\n";
data.code += ASSEMBLY_LINUX_X64_TRY_RESET_QUEUE;
data.code += "\tmov [queue+8*r13], rax\n";
data.code += "\tinc r13\n";
data.code += generate_assembly_linux_x64_queue_oob_check().as_str();
data.code += format!("\tjmp req_{line}_{col}_end\n").as_str();
data.code += format!("req_{line}_{col}_special:\n").as_str();
data.code += "\tmov qword rax, [queue+8*r12]\n";
data.code += "\tmov qword rdi, [queue+8*r12+8]\n";
data.code += "\tmov qword r12, r14\n";
data.code += "\tmov qword r13, r14\n";
data.code += "\tmov qword [queue+8*r12], rdi\n";
data.code += "\tmov qword [queue+8*r12+8], rax\n";
data.code += "\tadd r13, 2\n";
data.code += format!("req_{line}_{col}_end:\n").as_str();
}
Operation::Swap(line, col) =>
{
data.code += format!("\t;;swp {}:{}\n", line, col).as_str();
data.code += "\tmov rax, r13\n";
data.code += "\tsub rax, r12\n";
data.code += "\tcmp rax, 2\n";
data.code += format!("\tje swp_{line}_{col}_special\n").as_str();
data.code += "\tmov rax, [queue+8*r12]\n";
data.code += "\tmov rbx, [queue+8*r12+8]\n";
data.code += "\tadd r12, 2\n";
@ -547,6 +565,16 @@ fn generate_assembly_linux_x64_block(operations: &Vec<Operation>, functions: &Ve
data.code += "\tmov [queue+8*r13+8], rax\n";
data.code += "\tadd r13, 2\n";
data.code += generate_assembly_linux_x64_queue_oob_check().as_str();
data.code += format!("\tjmp swp_{line}_{col}_end\n").as_str();
data.code += format!("swp_{line}_{col}_special:\n").as_str();
data.code += "\tmov qword rax, [queue+8*r12]\n";
data.code += "\tmov qword rdi, [queue+8*r12+8]\n";
data.code += "\tmov qword r12, r14\n";
data.code += "\tmov qword r13, r14\n";
data.code += "\tmov qword [queue+8*r12], rdi\n";
data.code += "\tmov qword [queue+8*r12+8], rax\n";
data.code += "\tadd r13, 2\n";
data.code += format!("swp_{line}_{col}_end:\n").as_str();
}
Operation::While(while_operations, line, col) =>
{