Re: Re: Finding the correct alignment for all architectures

2016-10-30 Thread Thomas Weber
Thanks guys, I went with _Alignof(double), which interestingly aligns to
8 bytes on amd64.

Thomas



Re: Finding the correct alignment for all architectures

2016-10-12 Thread Jakub Wilk

* Christian Seiler , 2016-10-13, 00:20:

On 10/12/2016 11:51 PM, Thomas Weber wrote:
I am maintaining lcms2. In #749975, I received a patch to ensure correct 
alignment for doubles von MIPS. I have forwarded the patch upstream[1], but 
in the latest release, upstream has chosen a different way. It is now 
possible to configure the alignment via a preprocessor variable 
CMS_PTR_ALIGNMENT[2]:

[...]
I would like to drop the Debian-specific patch. But what value for 
CMS_PTR_ALIGNMENT would be good/sufficient on all arches?


Use _Alignof(type), that will always be correct. :-)

For example:

#define POINTER_ALIGNMENT_Alignof(void *)
#define DOUBLE_ALIGNMENT _Alignof(double)


If you are not delighted with leading underscores, you can #include 
 and then do s/_Alignof/alignof/.


Technically, this was introduced in C11/C++11, so if you need to support 
really old compilers, this may be problematic, but gcc/clang have supported 
that for a while. (A quick test tells me that gcc and clang from Jessie 
already support it.)


gcc in wheezy supports it too.

Alternatively, you may want to use the (gcc-specific) __BIGGEST_ALIGNMENT__ 
macro, but that kinda wasteful. For example, on i386 it's 16, even though 
alignof(t) is <= 4 for most t you can think of.


--
Jakub Wilk



Re: Finding the correct alignment for all architectures

2016-10-12 Thread Christian Seiler
Hi,

On 10/12/2016 11:51 PM, Thomas Weber wrote:
> I am maintaining lcms2. In #749975, I received a patch to ensure correct
> alignment for doubles von MIPS. I have forwarded the patch upstream[1], but
> in the latest release, upstream has chosen a different way. It is now
> possible to configure the alignment via a preprocessor variable
> CMS_PTR_ALIGNMENT[2]:
> // Alignment to memory pointer
> 
> // (Ultra)SPARC with gcc requires ptr alignment of 8 bytes
> // even though sizeof(void *) is only four: for greatest flexibility
> // allow the build to specify ptr alignment.
> #ifndef CMS_PTR_ALIGNMENT
> # define CMS_PTR_ALIGNMENT sizeof(void *)
> #endif
> 
> #define _cmsALIGNMEM(x)  (((x)+(CMS_PTR_ALIGNMENT - 1)) & ~(CMS_PTR_ALIGNMENT 
> - 1))
> 
> I would like to drop the Debian-specific patch. But what value for
> CMS_PTR_ALIGNMENT would be good/sufficient on all arches?

Use _Alignof(type), that will always be correct. :-)

For example:

#define POINTER_ALIGNMENT_Alignof(void *)
#define DOUBLE_ALIGNMENT _Alignof(double)

Technically, this was introduced in C11/C++11, so if you
need to support really old compilers, this may be problematic,
but gcc/clang have supported that for a while. (A quick test
tells me that gcc and clang from Jessie already support it.)

Regards,
Christian



Finding the correct alignment for all architectures

2016-10-12 Thread Thomas Weber
Hi, 
I am maintaining lcms2. In #749975, I received a patch to ensure correct
alignment for doubles von MIPS. I have forwarded the patch upstream[1], but
in the latest release, upstream has chosen a different way. It is now
possible to configure the alignment via a preprocessor variable
CMS_PTR_ALIGNMENT[2]:
// Alignment to memory pointer

// (Ultra)SPARC with gcc requires ptr alignment of 8 bytes
// even though sizeof(void *) is only four: for greatest flexibility
// allow the build to specify ptr alignment.
#ifndef CMS_PTR_ALIGNMENT
# define CMS_PTR_ALIGNMENT sizeof(void *)
#endif

#define _cmsALIGNMEM(x)  (((x)+(CMS_PTR_ALIGNMENT - 1)) & ~(CMS_PTR_ALIGNMENT - 
1))

I would like to drop the Debian-specific patch. But what value for
CMS_PTR_ALIGNMENT would be good/sufficient on all arches?

[1] https://github.com/mm2/Little-CMS/issues/32
[2] https://github.com/mm2/Little-CMS/blob/master/src/lcms2_internal.h

Thanks
Thomas