From 7a0e4643f883b634c76ae3577b41b8982ea6e1f2 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Sat, 25 Apr 2015 11:54:28 -0400 Subject: [PATCH] fix excess allocation in boxing functions. helps #10954 the alloc_*w functions were changed to refer to size not including tag, but these functions were not updated. --- src/alloc.c | 36 ++++++++++++++++++------------------ src/intrinsics.cpp | 5 ++--- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/alloc.c b/src/alloc.c index c381fb6bed204..c7b5500c31f72 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -672,13 +672,13 @@ jl_value_t *jl_box##nb(jl_datatype_t *t, int##nb##_t x) \ *(int##nb##_t*)jl_data_ptr(v) = x; \ return v; \ } -BOXN_FUNC(8, 2) -BOXN_FUNC(16, 2) -BOXN_FUNC(32, 2) +BOXN_FUNC(8, 1) +BOXN_FUNC(16, 1) +BOXN_FUNC(32, 1) #ifdef _P64 -BOXN_FUNC(64, 2) +BOXN_FUNC(64, 1) #else -BOXN_FUNC(64, 3) +BOXN_FUNC(64, 2) #endif #define UNBOX_FUNC(j_type,c_type) \ @@ -710,12 +710,12 @@ jl_value_t *pfx##_##typ(c_type x) \ *(c_type*)jl_data_ptr(v) = x; \ return v; \ } -BOX_FUNC(float32, float, jl_box, 2) -BOX_FUNC(voidpointer, void*, jl_box, 2) //2 pointers == two words on all platforms +BOX_FUNC(float32, float, jl_box, 1) +BOX_FUNC(voidpointer, void*, jl_box, 1) #ifdef _P64 -BOX_FUNC(float64, double, jl_box, 2) +BOX_FUNC(float64, double, jl_box, 1) #else -BOX_FUNC(float64, double, jl_box, 3) +BOX_FUNC(float64, double, jl_box, 2) #endif #define NBOX_C 1024 @@ -743,18 +743,18 @@ jl_value_t *jl_box_##typ(c_type x) \ *(c_type*)jl_data_ptr(v) = x; \ return v; \ } -SIBOX_FUNC(int16, int16_t, 2) -SIBOX_FUNC(int32, int32_t, 2) -UIBOX_FUNC(uint16, uint16_t, 2) -UIBOX_FUNC(uint32, uint32_t, 2) -UIBOX_FUNC(char, uint32_t, 2) -UIBOX_FUNC(gensym, size_t, 2) +SIBOX_FUNC(int16, int16_t, 1) +SIBOX_FUNC(int32, int32_t, 1) +UIBOX_FUNC(uint16, uint16_t, 1) +UIBOX_FUNC(uint32, uint32_t, 1) +UIBOX_FUNC(char, uint32_t, 1) +UIBOX_FUNC(gensym, size_t, 1) #ifdef _P64 +SIBOX_FUNC(int64, int64_t, 1) +UIBOX_FUNC(uint64, uint64_t, 1) +#else SIBOX_FUNC(int64, int64_t, 2) UIBOX_FUNC(uint64, uint64_t, 2) -#else -SIBOX_FUNC(int64, int64_t, 3) -UIBOX_FUNC(uint64, uint64_t, 3) #endif static jl_value_t *boxed_int8_cache[256]; diff --git a/src/intrinsics.cpp b/src/intrinsics.cpp index 1ad3bd85fcdfe..1c75907e3daba 100644 --- a/src/intrinsics.cpp +++ b/src/intrinsics.cpp @@ -636,15 +636,14 @@ static Value *emit_pointerref(jl_value_t *e, jl_value_t *i, jl_codectx_t *ctx) uint64_t size = jl_datatype_size(ety); Value *strct = builder.CreateCall(prepare_call(jlallocobj_func), - ConstantInt::get(T_size, - sizeof(void*)+size)); + ConstantInt::get(T_size, sizeof(void*)+size)); builder.CreateStore(literal_pointer_val((jl_value_t*)ety), emit_typeptr_addr(strct)); im1 = builder.CreateMul(im1, ConstantInt::get(T_size, LLT_ALIGN(size, ((jl_datatype_t*)ety)->alignment))); thePtr = builder.CreateGEP(builder.CreateBitCast(thePtr, T_pint8), im1); builder.CreateMemCpy(builder.CreateBitCast(strct, T_pint8), - thePtr, size, 1); + thePtr, size, 1); return mark_julia_type(strct, ety); } // TODO: alignment?