authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2015-12-15 01:55:52-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2015-12-15 01:55:52-07:00
log673d638070452d86543c6bb47879e83adcfa73a1
tree5a58cef1f45c198d93266ebbb072a102fbdfa5b2
parenta292eb8d64da4383f2d4637f231d338ed9c680e0

std: more efficient inline assembly


2 files changed, 13 insertions(+), 25 deletions(-)

src/codegen.cpp+5-7
...@@ -805,14 +805,12 @@ static LLVMValueRef gen_asm_expr(CodeGen *g, AstNode *node) {...@@ -805,14 +805,12 @@ static LLVMValueRef gen_asm_expr(CodeGen *g, AstNode *node) {
805 LLVMValueRef *param_values = allocate<LLVMValueRef>(input_and_output_count);805 LLVMValueRef *param_values = allocate<LLVMValueRef>(input_and_output_count);
806 for (int i = 0; i < asm_expr->output_list.length; i += 1, total_index += 1) {806 for (int i = 0; i < asm_expr->output_list.length; i += 1, total_index += 1) {
807 AsmOutput *asm_output = asm_expr->output_list.at(i);807 AsmOutput *asm_output = asm_expr->output_list.at(i);
808 bool is_return = false;808 bool is_return = (asm_output->return_type != nullptr);
809 if (buf_eql_str(&asm_output->constraint, "=m")) {809 assert(*buf_ptr(&asm_output->constraint) == '=');
810 buf_append_str(&constraint_buf, "=*m");810 if (is_return) {
811 } else if (buf_eql_str(&asm_output->constraint, "=r")) {811 buf_appendf(&constraint_buf, "=%s", buf_ptr(&asm_output->constraint) + 1);
812 buf_append_str(&constraint_buf, "=r");
813 is_return = true;
814 } else {812 } else {
815 zig_panic("TODO unable to handle anything other than '=m' and '=r' for outputs");813 buf_appendf(&constraint_buf, "=*%s", buf_ptr(&asm_output->constraint) + 1);
816 }814 }
817 if (total_index + 1 < total_constraint_count) {815 if (total_index + 1 < total_constraint_count) {
818 buf_append_char(&constraint_buf, ',');816 buf_append_char(&constraint_buf, ',');
std/std.zig+8-18
...@@ -3,27 +3,17 @@ const SYS_exit : isize = 60;...@@ -3,27 +3,17 @@ const SYS_exit : isize = 60;
3const stdout_fileno : isize = 1;3const stdout_fileno : isize = 1;
44
5fn syscall1(number: isize, arg1: isize) -> isize {5fn syscall1(number: isize, arg1: isize) -> isize {
6 asm volatile ("6 asm volatile ("syscall"
7 mov %[number], %%rax7 : [ret] "={rax}" (return isize)
8 mov %[arg1], %%rdi8 : [number] "{rax}" (number), [arg1] "{rdi}" (arg1)
9 syscall9 : "rcx", "r11")
10 mov %%rax, %[ret]"
11 : [ret] "=r" (return isize)
12 : [number] "r" (number), [arg1] "r" (arg1)
13 : "rcx", "r11", "rax", "rdi")
14}10}
1511
16fn syscall3(number: isize, arg1: isize, arg2: isize, arg3: isize) -> isize {12fn syscall3(number: isize, arg1: isize, arg2: isize, arg3: isize) -> isize {
17 asm volatile ("13 asm volatile ("syscall"
18 mov %[number], %%rax14 : [ret] "={rax}" (return isize)
19 mov %[arg1], %%rdi15 : [number] "{rax}" (number), [arg1] "{rdi}" (arg1), [arg2] "{rsi}" (arg2), [arg3] "{rdx}" (arg3)
20 mov %[arg2], %%rsi16 : "rcx", "r11")
21 mov %[arg3], %%rdx
22 syscall
23 mov %%rax, %[ret]"
24 : [ret] "=r" (return isize)
25 : [number] "r" (number), [arg1] "r" (arg1), [arg2] "r" (arg2), [arg3] "r" (arg3)
26 : "rcx", "r11", "rax", "rdi", "rsi", "rdx")
27}17}
2818
29pub fn write(fd: isize, buf: &const u8, count: usize) -> isize {19pub fn write(fd: isize, buf: &const u8, count: usize) -> isize {