authorgravatar for marc@tiehu.isMarc Tiehuis <marc@tiehu.is> 2019-03-02 00:44:52+13:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-03-01 08:23:11-05:00
logc4887d7f5430b38787ec01368ab7eba1537f0487
tree450a3637d355756236028e78759f023c2e761e1d
parent76b4e49178b72fb9b01e97aa6b46f9d5bdb83ab2

Use bitwise-and instead of modulo in __zig_return_error

Avoids emitting compiler-rt div calls on some targets.

2 files changed, 6 insertions(+), 4 deletions(-)

src/all_types.hpp+2-1
...@@ -3463,7 +3463,8 @@ static const size_t err_union_err_index = 0;...@@ -3463,7 +3463,8 @@ static const size_t err_union_err_index = 0;
3463static const size_t err_union_payload_index = 1;3463static const size_t err_union_payload_index = 1;
34643464
3465// TODO call graph analysis to find out what this number needs to be for every function3465// TODO call graph analysis to find out what this number needs to be for every function
3466static const size_t stack_trace_ptr_count = 30;3466// MUST BE A POWER OF TWO.
3467static const size_t stack_trace_ptr_count = 32;
34673468
3468// these belong to the async function3469// these belong to the async function
3469#define RETURN_ADDRESSES_FIELD_NAME "return_addresses"3470#define RETURN_ADDRESSES_FIELD_NAME "return_addresses"
src/codegen.cpp+4-3
...@@ -1236,7 +1236,7 @@ static LLVMValueRef get_add_error_return_trace_addr_fn(CodeGen *g) {...@@ -1236,7 +1236,7 @@ static LLVMValueRef get_add_error_return_trace_addr_fn(CodeGen *g) {
12361236
1237 LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->type_ref;1237 LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->type_ref;
12381238
1239 // stack_trace.instruction_addresses[stack_trace.index % stack_trace.instruction_addresses.len] = return_address;1239 // stack_trace.instruction_addresses[stack_trace.index & (stack_trace.instruction_addresses.len - 1)] = return_address;
12401240
1241 LLVMValueRef err_ret_trace_ptr = LLVMGetParam(fn_val, 0);1241 LLVMValueRef err_ret_trace_ptr = LLVMGetParam(fn_val, 0);
1242 LLVMValueRef address_value = LLVMGetParam(fn_val, 1);1242 LLVMValueRef address_value = LLVMGetParam(fn_val, 1);
...@@ -1254,9 +1254,10 @@ static LLVMValueRef get_add_error_return_trace_addr_fn(CodeGen *g) {...@@ -1254,9 +1254,10 @@ static LLVMValueRef get_add_error_return_trace_addr_fn(CodeGen *g) {
12541254
1255 LLVMValueRef len_value = gen_load_untyped(g, len_field_ptr, 0, false, "");1255 LLVMValueRef len_value = gen_load_untyped(g, len_field_ptr, 0, false, "");
1256 LLVMValueRef index_val = gen_load_untyped(g, index_field_ptr, 0, false, "");1256 LLVMValueRef index_val = gen_load_untyped(g, index_field_ptr, 0, false, "");
1257 LLVMValueRef modded_val = LLVMBuildURem(g->builder, index_val, len_value, "");1257 LLVMValueRef len_val_minus_one = LLVMBuildSub(g->builder, len_value, LLVMConstInt(usize_type_ref, 1, false), "");
1258 LLVMValueRef masked_val = LLVMBuildAnd(g->builder, index_val, len_val_minus_one, "");
1258 LLVMValueRef address_indices[] = {1259 LLVMValueRef address_indices[] = {
1259 modded_val,1260 masked_val,
1260 };1261 };
12611262
1262 LLVMValueRef ptr_value = gen_load_untyped(g, ptr_field_ptr, 0, false, "");1263 LLVMValueRef ptr_value = gen_load_untyped(g, ptr_field_ptr, 0, false, "");