Speed up SSA generation and clang compilation

This commit is contained in:
Ginger Bill
2016-09-05 18:42:42 +01:00
parent ae72b3c5bd
commit 455820fc84
9 changed files with 977 additions and 786 deletions
+808 -695
View File
File diff suppressed because it is too large Load Diff
+8 -10
View File
@@ -6,9 +6,7 @@ TWO_HEARTS :: #rune "💕"
win32_perf_count_freq := GetQueryPerformanceFrequency()
time_now :: proc() -> f64 {
if win32_perf_count_freq == 0 {
debug_trap()
}
assert(win32_perf_count_freq != 0)
counter: i64
_ = QueryPerformanceCounter(^counter)
@@ -25,10 +23,10 @@ win32_print_last_error :: proc() {
}
// Yuk!
to_c_string :: proc(s: string) -> ^u8 {
c_str: ^u8 = alloc(len(s)+1)
memory_copy(c_str, ^s[0], len(s))
ptr_offset(c_str, len(s))^ = 0
to_c_string :: proc(s: string) -> []u8 {
c_str := new_slice(u8, len(s)+1)
_ = copy(c_str, s as []byte)
c_str[len(s)] = 0
return c_str
}
@@ -39,7 +37,7 @@ Window :: type struct {
dc: HDC
hwnd: HWND
opengl_context, rc: HGLRC
c_title: ^u8
c_title: []u8
}
make_window :: proc(title: string, msg, height: int, window_proc: WNDPROC) -> (Window, bool) {
@@ -65,7 +63,7 @@ make_window :: proc(title: string, msg, height: int, window_proc: WNDPROC) -> (W
}
w.hwnd = CreateWindowExA(0,
c_class_name, w.c_title,
c_class_name, ^w.c_title[0],
WS_VISIBLE | WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
CW_USEDEFAULT, CW_USEDEFAULT,
w.width as i32, w.height as i32,
@@ -114,7 +112,7 @@ make_window :: proc(title: string, msg, height: int, window_proc: WNDPROC) -> (W
}
destroy_window :: proc(w: ^Window) {
heap_free(w.c_title)
delete(w.c_title)
}
display_window :: proc(w: ^Window) {
+29 -15
View File
@@ -1,15 +1,25 @@
#load "win32.odin"
debug_trap :: proc() #foreign "llvm.debugtrap"
assume :: proc(cond: bool) #foreign "llvm.assume"
__debug_trap :: proc() #foreign "llvm.debugtrap"
__trap :: proc() #foreign "llvm.trap"
read_cycle_counter :: proc() -> u64 #foreign "llvm.readcyclecounter"
bit_reverse16 :: proc(b: u16) -> u16 #foreign "llvm.bitreverse.i16"
bit_reverse32 :: proc(b: u32) -> u32 #foreign "llvm.bitreverse.i32"
bit_reverse64 :: proc(b: u64) -> u64 #foreign "llvm.bitreverse.i64"
byte_swap16 :: proc(b: u16) -> u16 #foreign "llvm.bswap.i16"
byte_swap32 :: proc(b: u32) -> u32 #foreign "llvm.bswap.i32"
byte_swap64 :: proc(b: u64) -> u64 #foreign "llvm.bswap.i64"
fmuladd_f32 :: proc(a, b, c: f32) -> f32 #foreign "llvm.fmuladd.f32"
fmuladd_f64 :: proc(a, b, c: f64) -> f64 #foreign "llvm.fmuladd.f64"
// TODO(bill): make custom heap procedures
heap_alloc :: proc(len: int) -> rawptr {
return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len)
}
heap_free :: proc(ptr: rawptr) {
_ = HeapFree(GetProcessHeap(), 0, ptr)
}
heap_alloc :: proc(len: int) -> rawptr #foreign "malloc"
heap_dealloc :: proc(ptr: rawptr) #foreign "free"
memory_zero :: proc(data: rawptr, len: int) {
d := slice_ptr(data as ^byte, len)
@@ -288,10 +298,10 @@ Allocator :: type struct {
Context :: type struct {
thread_id: int
thread_ptr: rawptr
user_index: int
user_data: rawptr
user_index: int
allocator: Allocator
}
@@ -305,6 +315,10 @@ __check_context :: proc() {
if context.allocator.procedure == null {
context.allocator = __default_allocator()
}
if context.thread_ptr == null {
// TODO(bill):
// context.thread_ptr = current_thread_pointer()
}
}
@@ -368,13 +382,11 @@ __default_allocator_proc :: proc(allocator_data: rawptr, mode: Allocation_Mode,
using Allocation_Mode
match mode {
case ALLOC:
data := heap_alloc(size)
memory_zero(data, size)
return data
return heap_alloc(size)
case RESIZE:
return default_resize_align(old_memory, old_size, size, alignment)
case DEALLOC:
heap_free(old_memory)
heap_dealloc(old_memory)
case DEALLOC_ALL:
// NOTE(bill): Does nothing
}
@@ -394,5 +406,7 @@ __default_allocator :: proc() -> Allocator {
__assert :: proc(msg: string) {
file_write(file_get_standard(File_Standard.ERROR), msg as []byte)
debug_trap()
// TODO(bill): Which is better?
// __trap()
__debug_trap()
}