mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 23:28:48 +00:00
Add minor optimization for lb_map_cell_index_static
This commit is contained in:
@@ -552,9 +552,6 @@ lbValue lb_map_get_proc_for_type(lbModule *m, Type *type) {
|
|||||||
vs = lb_emit_conv(p, vs, alloc_type_pointer(type->Map.value));
|
vs = lb_emit_conv(p, vs, alloc_type_pointer(type->Map.value));
|
||||||
hs = lb_emit_conv(p, hs, alloc_type_pointer(t_uintptr));
|
hs = lb_emit_conv(p, hs, alloc_type_pointer(t_uintptr));
|
||||||
|
|
||||||
// lbValue res =
|
|
||||||
// LLVMBuildRet(p->builder, res.value);
|
|
||||||
|
|
||||||
lb_emit_jump(p, loop_block);
|
lb_emit_jump(p, loop_block);
|
||||||
lb_start_block(p, loop_block);
|
lb_start_block(p, loop_block);
|
||||||
|
|
||||||
|
|||||||
@@ -382,12 +382,20 @@ lbValue lb_map_cell_index_static(lbProcedure *p, Type *type, lbValue cells_ptr,
|
|||||||
return lb_emit_ptr_offset(p, elems_ptr, index);
|
return lb_emit_ptr_offset(p, elems_ptr, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TOOD(bill): N power of two optimization to use >> and &
|
lbValue cell_index = {};
|
||||||
|
lbValue data_index = {};
|
||||||
|
|
||||||
lbValue size_const = lb_const_int(p->module, t_uintptr, size);
|
lbValue size_const = lb_const_int(p->module, t_uintptr, size);
|
||||||
lbValue len_const = lb_const_int(p->module, t_uintptr, len);
|
lbValue len_const = lb_const_int(p->module, t_uintptr, len);
|
||||||
lbValue cell_index = lb_emit_arith(p, Token_Quo, index, len_const, t_uintptr);
|
|
||||||
lbValue data_index = lb_emit_arith(p, Token_Mod, index, len_const, t_uintptr);
|
if (is_power_of_two(len)) {
|
||||||
|
u64 log2_len = floor_log2(cast(u64)len);
|
||||||
|
cell_index = log2_len == 0 ? index : lb_emit_arith(p, Token_Shr, index, lb_const_int(p->module, t_uintptr, log2_len), t_uintptr);
|
||||||
|
data_index = lb_emit_arith(p, Token_And, index, lb_const_int(p->module, t_uintptr, len-1), t_uintptr);
|
||||||
|
} else {
|
||||||
|
cell_index = lb_emit_arith(p, Token_Quo, index, len_const, t_uintptr);
|
||||||
|
data_index = lb_emit_arith(p, Token_Mod, index, len_const, t_uintptr);
|
||||||
|
}
|
||||||
|
|
||||||
lbValue elems_ptr = lb_emit_conv(p, cells_ptr, t_uintptr);
|
lbValue elems_ptr = lb_emit_conv(p, cells_ptr, t_uintptr);
|
||||||
lbValue cell_offset = lb_emit_arith(p, Token_Mul, size_const, cell_index, t_uintptr);
|
lbValue cell_offset = lb_emit_arith(p, Token_Mul, size_const, cell_index, t_uintptr);
|
||||||
|
|||||||
Reference in New Issue
Block a user