authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2015-12-15 02:47:39-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2015-12-15 02:47:39-07:00
log1f48b626a1cef1168d23654f5a9f21ed2196738e
tree697d703a204b26c2cb34b494a7ab53d75785f936
parent673d638070452d86543c6bb47879e83adcfa73a1

std: even more efficient inline assembly


4 files changed, 8 insertions(+), 15 deletions(-)

example/hello_world/hello.zig+1-1
...@@ -2,7 +2,7 @@ export executable "hello";...@@ -2,7 +2,7 @@ export executable "hello";
22
3use "std.zig";3use "std.zig";
44
5export fn main(argc: isize, argv: &&u8, env: &&u8) -> i32 {5pub fn main(argc: isize, argv: &&u8, env: &&u8) -> i32 {
6 // TODO implicit coercion from array to string6 // TODO implicit coercion from array to string
7 print_str("Hello, world!\n" as string);7 print_str("Hello, world!\n" as string);
8 return 0;8 return 0;
src/analyze.cpp+1-1
...@@ -315,7 +315,7 @@ static void preview_function_declarations(CodeGen *g, ImportTableEntry *import,...@@ -315,7 +315,7 @@ static void preview_function_declarations(CodeGen *g, ImportTableEntry *import,
315 auto entry = import->fn_table.maybe_get(proto_name);315 auto entry = import->fn_table.maybe_get(proto_name);
316 bool skip = false;316 bool skip = false;
317 bool is_internal = (proto_node->data.fn_proto.visib_mod != FnProtoVisibModExport);317 bool is_internal = (proto_node->data.fn_proto.visib_mod != FnProtoVisibModExport);
318 bool is_pub = (proto_node->data.fn_proto.visib_mod == FnProtoVisibModPub);318 bool is_pub = (proto_node->data.fn_proto.visib_mod != FnProtoVisibModPrivate);
319 if (entry) {319 if (entry) {
320 add_node_error(g, node,320 add_node_error(g, node,
321 buf_sprintf("redefinition of '%s'", buf_ptr(proto_name)));321 buf_sprintf("redefinition of '%s'", buf_ptr(proto_name)));
src/codegen.cpp+1-1
...@@ -1611,7 +1611,7 @@ static ImportTableEntry *codegen_add_code(CodeGen *g, Buf *src_dirname, Buf *src...@@ -1611,7 +1611,7 @@ static ImportTableEntry *codegen_add_code(CodeGen *g, Buf *src_dirname, Buf *src
1611 assert(proto_node->type == NodeTypeFnProto);1611 assert(proto_node->type == NodeTypeFnProto);
1612 Buf *proto_name = &proto_node->data.fn_proto.name;1612 Buf *proto_name = &proto_node->data.fn_proto.name;
16131613
1614 bool is_exported = (proto_node->data.fn_proto.visib_mod == FnProtoVisibModExport);1614 bool is_exported = (proto_node->data.fn_proto.visib_mod != FnProtoVisibModPrivate);
16151615
1616 if (buf_eql_str(proto_name, "main") && is_exported) {1616 if (buf_eql_str(proto_name, "main") && is_exported) {
1617 g->insert_bootstrap_code = true;1617 g->insert_bootstrap_code = true;
std/bootstrap.zig+5-12
...@@ -1,16 +1,9 @@...@@ -1,16 +1,9 @@
1use "std.zig";
12
2// TODO conditionally compile this differently for non-ELF
3#attribute("naked")3#attribute("naked")
4export fn _start() -> unreachable {4export fn _start() -> unreachable {
5 // TODO conditionally compile this differently for other architectures and other OSes5 const argc = asm("mov (%%rsp), %[argc]" : [argc] "=r" (return isize));
6 asm volatile ("6 const argv = asm("lea 0x8(%%rsp), %[argv]" : [argv] "=r" (return &&u8));
7 mov (%%rsp), %%rdi // first parameter is argc7 const env = asm("lea 0x10(%%rsp,%%rdi,8), %[env]" : [env] "=r" (return &&u8));
8 lea 0x8(%%rsp), %%rsi // second parameter is argv8 exit(main(argc, argv, env))
9 lea 0x10(%%rsp,%%rdi,8), %%rdx // third paremeter is env
10 callq main
11 mov %%rax, %%rdi // return value is the parameter to exit syscall
12 mov $60, %%rax // 60 is exit syscall number
13 syscall
14 ");
15 unreachable
16}9}