diff --git a/basis/bootstrap/image/image.factor b/basis/bootstrap/image/image.factor index e086215e91..711f2f36f3 100644 --- a/basis/bootstrap/image/image.factor +++ b/basis/bootstrap/image/image.factor @@ -218,8 +218,12 @@ USERENV: undefined-quot 60 : here-as ( tag -- pointer ) here bitor ; +: (align-here) ( alignment -- ) + [ here neg ] dip rem + [ bootstrap-cell /i [ 0 emit ] times ] unless-zero ; + : align-here ( -- ) - here 8 mod 4 = [ 0 emit ] when ; + data-alignment get (align-here) ; : emit-fixnum ( n -- ) tag-fixnum emit ; @@ -293,7 +297,7 @@ M: fake-bignum ' n>> tag-fixnum ; M: float ' [ float [ - align-here double>bits emit-64 + 8 (align-here) double>bits emit-64 ] emit-object ] cache-eql-object ; @@ -411,6 +415,7 @@ M: byte-array ' [ byte-array [ dup length emit-fixnum + bootstrap-cell 4 = [ 0 emit 0 emit ] when pad-bytes emit-bytes ] emit-object ] cache-eq-object ; diff --git a/basis/compiler/constants/constants.factor b/basis/compiler/constants/constants.factor index a22d522809..ab607d2178 100644 --- a/basis/compiler/constants/constants.factor +++ b/basis/compiler/constants/constants.factor @@ -17,7 +17,7 @@ CONSTANT: deck-bits 18 : string-offset ( -- n ) 4 string tag-number slot-offset ; inline : string-aux-offset ( -- n ) 2 string tag-number slot-offset ; inline : profile-count-offset ( -- n ) 8 \ word tag-number slot-offset ; inline -: byte-array-offset ( -- n ) 2 byte-array tag-number slot-offset ; inline +: byte-array-offset ( -- n ) 16 byte-array tag-number - ; inline : alien-offset ( -- n ) 3 alien tag-number slot-offset ; inline : underlying-alien-offset ( -- n ) 1 alien tag-number slot-offset ; inline : tuple-class-offset ( -- n ) 1 tuple tag-number slot-offset ; inline diff --git a/basis/cpu/ppc/ppc.factor b/basis/cpu/ppc/ppc.factor index 517aa7587d..7226145c27 100644 --- a/basis/cpu/ppc/ppc.factor +++ b/basis/cpu/ppc/ppc.factor @@ -374,7 +374,7 @@ M: ppc %set-alien-double -rot STFD ; [ drop load-zone-ptr ] [ swap 0 LWZ ] 2bi ; :: inc-allot-ptr ( nursery-ptr allot-ptr n -- ) - scratch-reg allot-ptr n 8 align ADDI + scratch-reg allot-ptr n data-alignment get align ADDI scratch-reg nursery-ptr 0 STW ; :: store-header ( dst class -- ) diff --git a/basis/cpu/x86/x86.factor b/basis/cpu/x86/x86.factor index 4576956335..e061ea5d95 100644 --- a/basis/cpu/x86/x86.factor +++ b/basis/cpu/x86/x86.factor @@ -388,7 +388,7 @@ M: x86 %vm-field-ptr ( dst field -- ) [ drop "nursery" %vm-field-ptr ] [ swap [] MOV ] 2bi ; : inc-allot-ptr ( nursery-ptr n -- ) - [ [] ] dip 8 align ADD ; + [ [] ] dip data-alignment get align ADD ; : store-header ( temp class -- ) [ [] ] [ type-number tag-fixnum ] bi* MOV ; diff --git a/core/bootstrap/layouts/layouts.factor b/core/bootstrap/layouts/layouts.factor index 5ed92b7776..fef7ba2a83 100644 --- a/core/bootstrap/layouts/layouts.factor +++ b/core/bootstrap/layouts/layouts.factor @@ -5,6 +5,8 @@ hashtables vectors strings sbufs arrays quotations assocs layouts classes.tuple.private kernel.private ; +16 data-alignment set + BIN: 111 tag-mask set 8 num-tags set 3 tag-bits set diff --git a/core/layouts/layouts.factor b/core/layouts/layouts.factor index be6276a684..2f0fa12d44 100644 --- a/core/layouts/layouts.factor +++ b/core/layouts/layouts.factor @@ -4,6 +4,8 @@ USING: namespaces math words kernel assocs classes math.order kernel.private ; IN: layouts +SYMBOL: data-alignment + SYMBOL: tag-mask SYMBOL: num-tags diff --git a/vm/arrays.cpp b/vm/arrays.cpp index 09c6998e69..3af8b0600b 100644 --- a/vm/arrays.cpp +++ b/vm/arrays.cpp @@ -7,7 +7,7 @@ namespace factor array *factor_vm::allot_array(cell capacity, cell fill_) { gc_root fill(fill_,this); - gc_root new_array(allot_array_internal(capacity),this); + gc_root new_array(allot_uninitialized_array(capacity),this); if(fill.value() == tag_fixnum(0)) memset(new_array->data(),'\0',capacity * sizeof(cell)); @@ -33,7 +33,7 @@ void factor_vm::primitive_array() cell factor_vm::allot_array_1(cell obj_) { gc_root obj(obj_,this); - gc_root a(allot_array_internal(1),this); + gc_root a(allot_uninitialized_array(1),this); set_array_nth(a.untagged(),0,obj.value()); return a.value(); } @@ -42,7 +42,7 @@ cell factor_vm::allot_array_2(cell v1_, cell v2_) { gc_root v1(v1_,this); gc_root v2(v2_,this); - gc_root a(allot_array_internal(2),this); + gc_root a(allot_uninitialized_array(2),this); set_array_nth(a.untagged(),0,v1.value()); set_array_nth(a.untagged(),1,v2.value()); return a.value(); @@ -54,7 +54,7 @@ cell factor_vm::allot_array_4(cell v1_, cell v2_, cell v3_, cell v4_) gc_root v2(v2_,this); gc_root v3(v3_,this); gc_root v4(v4_,this); - gc_root a(allot_array_internal(4),this); + gc_root a(allot_uninitialized_array(4),this); set_array_nth(a.untagged(),0,v1.value()); set_array_nth(a.untagged(),1,v2.value()); set_array_nth(a.untagged(),2,v3.value()); diff --git a/vm/bignum.cpp b/vm/bignum.cpp index d8c5452b08..5a391e7625 100755 --- a/vm/bignum.cpp +++ b/vm/bignum.cpp @@ -1299,7 +1299,7 @@ bignum *factor_vm::bignum_digit_to_bignum(bignum_digit_type digit, int negative_ bignum *factor_vm::allot_bignum(bignum_length_type length, int negative_p) { BIGNUM_ASSERT ((length >= 0) || (length < BIGNUM_RADIX)); - bignum * result = allot_array_internal(length + 1); + bignum * result = allot_uninitialized_array(length + 1); BIGNUM_SET_NEGATIVE_P (result, negative_p); return (result); } diff --git a/vm/byte_arrays.cpp b/vm/byte_arrays.cpp index 56b5db7ad8..fa02ede6c3 100644 --- a/vm/byte_arrays.cpp +++ b/vm/byte_arrays.cpp @@ -5,7 +5,7 @@ namespace factor byte_array *factor_vm::allot_byte_array(cell size) { - byte_array *array = allot_array_internal(size); + byte_array *array = allot_uninitialized_array(size); memset(array + 1,0,size); return array; } @@ -19,7 +19,7 @@ void factor_vm::primitive_byte_array() void factor_vm::primitive_uninitialized_byte_array() { cell size = unbox_array_size(); - dpush(tag(allot_array_internal(size))); + dpush(tag(allot_uninitialized_array(size))); } void factor_vm::primitive_resize_byte_array() diff --git a/vm/callbacks.cpp b/vm/callbacks.cpp index dca0eb6c24..599271555b 100644 --- a/vm/callbacks.cpp +++ b/vm/callbacks.cpp @@ -39,14 +39,14 @@ callback *callback_heap::add(code_block *compiled) tagged insns(array_nth(code_template.untagged(),0)); cell size = array_capacity(insns.untagged()); - cell bump = align8(size) + sizeof(callback); + cell bump = align(size,sizeof(cell)) + sizeof(callback); if(here + bump > seg->end) fatal_error("Out of callback space",0); callback *stub = (callback *)here; stub->compiled = compiled; memcpy(stub + 1,insns->data(),size); - stub->size = align8(size); + stub->size = align(size,sizeof(cell)); here += bump; update(stub); diff --git a/vm/contexts.cpp b/vm/contexts.cpp index cc7029e7f1..ce52555a21 100644 --- a/vm/contexts.cpp +++ b/vm/contexts.cpp @@ -133,7 +133,7 @@ bool factor_vm::stack_to_array(cell bottom, cell top) return false; else { - array *a = allot_array_internal(depth / sizeof(cell)); + array *a = allot_uninitialized_array(depth / sizeof(cell)); memcpy(a + 1,(void*)bottom,depth); dpush(tag(a)); return true; diff --git a/vm/data_heap.cpp b/vm/data_heap.cpp index 335938acab..05ce026973 100755 --- a/vm/data_heap.cpp +++ b/vm/data_heap.cpp @@ -119,7 +119,7 @@ cell factor_vm::object_size(cell tagged) /* Size of the object pointed to by an untagged pointer */ cell factor_vm::untagged_object_size(object *pointer) { - return align8(unaligned_object_size(pointer)); + return align(unaligned_object_size(pointer),data_alignment); } /* Size of the data area of an object pointed to by an untagged pointer */ diff --git a/vm/generic_arrays.hpp b/vm/generic_arrays.hpp index 0ba6d11da2..e1d2c4dc0b 100755 --- a/vm/generic_arrays.hpp +++ b/vm/generic_arrays.hpp @@ -19,7 +19,7 @@ template cell array_size(Array *array) return array_size(array_capacity(array)); } -template Array *factor_vm::allot_array_internal(cell capacity) +template Array *factor_vm::allot_uninitialized_array(cell capacity) { Array *array = allot(array_size(capacity)); array->capacity = tag_fixnum(capacity); @@ -46,7 +46,7 @@ template Array *factor_vm::reallot_array(Array *array_, cell cap if(capacity < to_copy) to_copy = capacity; - Array *new_array = allot_array_internal(capacity); + Array *new_array = allot_uninitialized_array(capacity); memcpy(new_array + 1,array.untagged() + 1,to_copy * Array::element_size); memset((char *)(new_array + 1) + to_copy * Array::element_size, diff --git a/vm/io.cpp b/vm/io.cpp index d5cfc1745c..a75f41c5bf 100755 --- a/vm/io.cpp +++ b/vm/io.cpp @@ -88,7 +88,7 @@ void factor_vm::primitive_fread() return; } - gc_root buf(allot_array_internal(size),this); + gc_root buf(allot_uninitialized_array(size),this); for(;;) { diff --git a/vm/layouts.hpp b/vm/layouts.hpp index 6e8c89ceb3..c25c2c0fc1 100644 --- a/vm/layouts.hpp +++ b/vm/layouts.hpp @@ -23,10 +23,7 @@ inline static cell align(cell a, cell b) return (a + (b-1)) & ~(b-1); } -inline static cell align8(cell a) -{ - return align(a,8); -} +static const cell data_alignment = 16; #define WORD_SIZE (signed)(sizeof(cell)*8) @@ -186,6 +183,11 @@ struct byte_array : public object { /* tagged */ cell capacity; +#ifndef FACTOR_64 + cell padding0; + cell padding1; +#endif + template Scalar *data() { return (Scalar *)(this + 1); } }; @@ -249,9 +251,9 @@ struct code_block : public heap_block return (void *)(this + 1); } - cell type() + code_block_type type() { - return (header >> 1) & 0x3; + return (code_block_type)((header >> 1) & 0x3); } void set_type(code_block_type type) diff --git a/vm/strings.cpp b/vm/strings.cpp index d7434fe660..23fa75acca 100644 --- a/vm/strings.cpp +++ b/vm/strings.cpp @@ -45,7 +45,7 @@ void factor_vm::set_string_nth_slow(string *str_, cell index, cell ch) if the most significant bit of a character is set. Initially all of the bits are clear. */ - aux = allot_array_internal(untag_fixnum(str->length) * sizeof(u16)); + aux = allot_uninitialized_array(untag_fixnum(str->length) * sizeof(u16)); str->aux = tag(aux); write_barrier(&str->aux); diff --git a/vm/vm.hpp b/vm/vm.hpp index a2f979e400..87697d5a0f 100755 --- a/vm/vm.hpp +++ b/vm/vm.hpp @@ -298,7 +298,7 @@ struct factor_vm } // generic arrays - template Array *allot_array_internal(cell capacity); + template Array *allot_uninitialized_array(cell capacity); template bool reallot_array_in_place_p(Array *array, cell capacity); template Array *reallot_array(Array *array_, cell capacity); diff --git a/vm/zone.hpp b/vm/zone.hpp index 4fe4ae9b6b..2c28922fbc 100644 --- a/vm/zone.hpp +++ b/vm/zone.hpp @@ -18,7 +18,7 @@ struct zone { inline object *allot(cell size) { cell h = here; - here = h + align8(size); + here = h + align(size,data_alignment); return (object *)h; } };