star-sp

Random number generators and distributions
git clone git://git.meso-star.fr/star-sp.git
Log | Files | Refs | README | LICENSE

commit ca2220ba658400f2795a5a9956ee3dfa38d0eb4e
parent b70c858c5d43211550f326dda87ec1eea56eedd9
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed, 11 Jul 2018 11:51:10 +0200

Align the allocated ssp_rng data structure on 16 bytes

The ssp_rng has a long double attribute, that on GNU/Linux 64-bits must
be aligned on 16 bytes.

This commit reverts the commit 8b7f4dd that did not fix anything but
only workarounds this "misaligned address" issue.

Diffstat:
Msrc/ssp_rng.c | 8++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/ssp_rng.c b/src/ssp_rng.c @@ -479,11 +479,15 @@ ssp_rng_create } allocator = mem_allocator ? mem_allocator : &mem_default_allocator; - rng = (struct ssp_rng*)MEM_CALLOC(allocator, 1, sizeof(struct ssp_rng)); + + /* Align the rng on 16 bytes since its 'r' attrib is a long double that on + * Linux 64-bits systems must be aligned on 16 bytes. */ + rng = (struct ssp_rng*)MEM_ALLOC_ALIGNED(allocator, sizeof(*rng), 16); if(!rng) { res = RES_MEM_ERR; goto error; } + memset(rng, 0, sizeof(struct ssp_rng)); rng->allocator = allocator; ref_init(&rng->ref); @@ -495,7 +499,7 @@ ssp_rng_create } res = type->init(allocator, rng->state); if(res != RES_OK) goto error; - memcpy(&rng->type, type, sizeof(*type)); + rng->type = *type; /* Precompute some values for the canonical distribution */ rng->r = (long double)rng->type.max - (long double)rng->type.min + 1.0L;