Skip to content

Commit 8e9c5b9

Browse files
committed
Change rust_vec to have a 16-byte header, to 16-byte-align vec-body data. Major perf win.
1 parent f6763ef commit 8e9c5b9

File tree

6 files changed

+14
-7
lines changed

6 files changed

+14
-7
lines changed

src/boot/be/abi.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ let tydesc_field_stateflag = 11;;
9393
let vec_elt_rc = 0;;
9494
let vec_elt_alloc = 1;;
9595
let vec_elt_fill = 2;;
96-
let vec_elt_data = 3;;
96+
let vec_elt_pad = 3;;
97+
let vec_elt_data = 4;;
9798

9899
let calltup_elt_out_ptr = 0;;
99100
let calltup_elt_task_ptr = 1;;

src/boot/me/semant.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2382,7 +2382,7 @@ and fn_rty (cx:ctxt) (opaque_box_body:bool) : Il.referent_ty =
23822382
and vec_sty (word_bits:Il.bits) : Il.scalar_ty =
23832383
let word = word_rty word_bits in
23842384
let ptr = Il.ScalarTy (Il.AddrTy Il.OpaqueTy) in
2385-
Il.AddrTy (Il.StructTy [| word; word; word; ptr |])
2385+
Il.AddrTy (Il.StructTy [| word; word; word; word; ptr |])
23862386

23872387
and referent_type
23882388
?parent_tags:parent_tags
@@ -2442,7 +2442,7 @@ and referent_type
24422442
| Ast.TY_mach (TY_i64)
24432443
| Ast.TY_mach (TY_f64) -> sv Il.Bits64
24442444

2445-
| Ast.TY_str -> sp (Il.StructTy [| word; word; word; ptr |])
2445+
| Ast.TY_str -> sp (Il.StructTy [| word; word; word; word; ptr |])
24462446
| Ast.TY_vec _ -> s (vec_sty word_bits)
24472447
| Ast.TY_tup tt -> tup tt
24482448
| Ast.TY_rec tr -> tup (Array.map snd tr)

src/boot/me/trans.ml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,6 +1549,7 @@ let trans_visitor
15491549
Asm.IMM Abi.const_refcount);
15501550
Asm.WORD (word_ty_mach, Asm.IMM init_sz);
15511551
Asm.WORD (word_ty_mach, Asm.IMM init_sz);
1552+
Asm.WORD (word_ty_mach, Asm.IMM 0L);
15521553
Asm.ZSTRING s
15531554
|]))
15541555
(referent_type cx Ast.TY_str)
@@ -2850,15 +2851,16 @@ let trans_visitor
28502851

28512852
(*
28522853
* A vec is implicitly boxed: every slot vec[T] is 1 word and
2853-
* points to a refcounted structure. That structure has 3 words with
2854+
* points to a refcounted structure. That structure has 4 words with
28542855
* defined meaning at the beginning; data follows the header.
28552856
*
28562857
* word 0: refcount or gc control word
28572858
* word 1: allocated size of data
28582859
* word 2: initialised size of data
2859-
* word 3...N: data
2860+
* word 3: padding word to hit even multiple of 16
2861+
* word 4...N: data
28602862
*
2861-
* This 3-word prefix is shared with strings, we factor the common
2863+
* This 4-word prefix is shared with strings, we factor the common
28622864
* part out for reuse in string code.
28632865
*)
28642866

src/comp/back/abi.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ const int general_code_alignment = 16;
2626
const int vec_elt_rc = 0;
2727
const int vec_elt_alloc = 1;
2828
const int vec_elt_fill = 2;
29-
const int vec_elt_data = 3;
29+
const int vec_elt_pad = 3;
30+
const int vec_elt_data = 4;
3031

3132
const int tydesc_field_first_param = 0;
3233
const int tydesc_field_size = 1;

src/comp/middle/trans.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ fn T_vec(TypeRef t) -> TypeRef {
372372
ret T_struct(vec(T_int(), // Refcount
373373
T_int(), // Alloc
374374
T_int(), // Fill
375+
T_int(), // Pad
375376
T_array(t, 0u) // Body elements
376377
));
377378
}
@@ -870,6 +871,7 @@ fn C_str(@crate_ctxt cx, str s) -> ValueRef {
870871
auto box = C_struct(vec(C_int(abi.const_refcount as int),
871872
C_int(len + 1u as int), // 'alloc'
872873
C_int(len + 1u as int), // 'fill'
874+
C_int(0), // 'pad'
873875
llvm.LLVMConstString(_str.buf(s),
874876
len, False)));
875877
auto g = llvm.LLVMAddGlobal(cx.llmod, val_ty(box),

src/rt/rust_util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ rust_vec : public rc_base<rust_vec>
172172
{
173173
size_t alloc;
174174
size_t fill;
175+
size_t pad; // Pad to align data[0] to 16 bytes.
175176
uint8_t data[];
176177
rust_vec(rust_dom *dom, size_t alloc, size_t fill, uint8_t const *d) :
177178
alloc(alloc),

0 commit comments

Comments
 (0)