std: more efficient inline assembly

This commit is contained in:
Andrew Kelley 2015-12-15 01:55:52 -07:00
parent a292eb8d64
commit 673d638070
2 changed files with 13 additions and 25 deletions

View File

@ -805,14 +805,12 @@ static LLVMValueRef gen_asm_expr(CodeGen *g, AstNode *node) {
LLVMValueRef *param_values = allocate<LLVMValueRef>(input_and_output_count);
for (int i = 0; i < asm_expr->output_list.length; i += 1, total_index += 1) {
AsmOutput *asm_output = asm_expr->output_list.at(i);
bool is_return = false;
if (buf_eql_str(&asm_output->constraint, "=m")) {
buf_append_str(&constraint_buf, "=*m");
} else if (buf_eql_str(&asm_output->constraint, "=r")) {
buf_append_str(&constraint_buf, "=r");
is_return = true;
bool is_return = (asm_output->return_type != nullptr);
assert(*buf_ptr(&asm_output->constraint) == '=');
if (is_return) {
buf_appendf(&constraint_buf, "=%s", buf_ptr(&asm_output->constraint) + 1);
} else {
zig_panic("TODO unable to handle anything other than '=m' and '=r' for outputs");
buf_appendf(&constraint_buf, "=*%s", buf_ptr(&asm_output->constraint) + 1);
}
if (total_index + 1 < total_constraint_count) {
buf_append_char(&constraint_buf, ',');

View File

@ -3,27 +3,17 @@ const SYS_exit : isize = 60;
const stdout_fileno : isize = 1;
fn syscall1(number: isize, arg1: isize) -> isize {
asm volatile ("
mov %[number], %%rax
mov %[arg1], %%rdi
syscall
mov %%rax, %[ret]"
: [ret] "=r" (return isize)
: [number] "r" (number), [arg1] "r" (arg1)
: "rcx", "r11", "rax", "rdi")
asm volatile ("syscall"
: [ret] "={rax}" (return isize)
: [number] "{rax}" (number), [arg1] "{rdi}" (arg1)
: "rcx", "r11")
}
fn syscall3(number: isize, arg1: isize, arg2: isize, arg3: isize) -> isize {
asm volatile ("
mov %[number], %%rax
mov %[arg1], %%rdi
mov %[arg2], %%rsi
mov %[arg3], %%rdx
syscall
mov %%rax, %[ret]"
: [ret] "=r" (return isize)
: [number] "r" (number), [arg1] "r" (arg1), [arg2] "r" (arg2), [arg3] "r" (arg3)
: "rcx", "r11", "rax", "rdi", "rsi", "rdx")
asm volatile ("syscall"
: [ret] "={rax}" (return isize)
: [number] "{rax}" (number), [arg1] "{rdi}" (arg1), [arg2] "{rsi}" (arg2), [arg3] "{rdx}" (arg3)
: "rcx", "r11")
}
pub fn write(fd: isize, buf: &const u8, count: usize) -> isize {