From 006ac63208cdba554688083ecd1a5fc4031ba987 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Fri, 16 Oct 2015 12:50:56 +0100 Subject: [PATCH] Slightly optimize alignment --- config.h.in | 50 +++++++++++++---------------------- src/libutil/keypair_private.h | 6 ++--- 2 files changed, 22 insertions(+), 34 deletions(-) diff --git a/config.h.in b/config.h.in index 93721f82e..f53f51978 100644 --- a/config.h.in +++ b/config.h.in @@ -91,29 +91,6 @@ #if !defined(BYTE_ORDER) # error "Undefined or unknown BYTE_ORDER" #endif - -#ifdef _MSC_VER -# define RSPAMD_PACKED(name) \ - __pragma(pack(push, 1)) struct name __pragma(pack(pop)) -#elif defined(__GNUC__) -# define RSPAMD_PACKED(name) struct __attribute__((packed)) name -#else -# define RSPAMD_PACKED(name) struct name -#endif - - -#ifndef RSPAMD_ALIGNED -#if defined(_MSC_VER) -# define RSPAMD_ALIGNED(x) __declspec(align(x)) -#elif defined(__GNUC__) -# define RSPAMD_ALIGNED(x) __attribute__((aligned(x))) -#else -# define RSPAMD_ALIGNED(x) -#endif -#endif - - - #cmakedefine HAVE_SYS_QUEUE_H 1 #cmakedefine HAVE_SYS_MMAN_H 1 #cmakedefine HAVE_SYS_SOCKET_H 1 @@ -341,14 +318,6 @@ typedef off_t goffset; #endif -#ifndef ALIGN -#if defined(_MSC_VER) -# define ALIGN(x) __declspec(align(x)) -#else -# define ALIGN(x) __attribute__((aligned(x))) -#endif -#endif - #ifndef PARAM_H_HAS_BITSET /* Bit map related macros. */ #ifndef NBBY @@ -364,6 +333,25 @@ typedef off_t goffset; ((((const unsigned char *)(a))[(i) / NBBY] & (1 << ((i) % NBBY))) == 0) #endif +#ifdef _MSC_VER +# define RSPAMD_PACKED(name) \ + __pragma(pack(push, 1)) struct name __pragma(pack(pop)) +#elif defined(__GNUC__) +# define RSPAMD_PACKED(name) struct __attribute__((packed)) name +#else +# define RSPAMD_PACKED(name) struct name +#endif + +#ifndef RSPAMD_ALIGNED +#if defined(_MSC_VER) +# define RSPAMD_ALIGNED(x) __declspec(align(x)) +#elif defined(__GNUC__) +# define RSPAMD_ALIGNED(x) __attribute__((aligned(x))) +#else +# define RSPAMD_ALIGNED(x) +#endif +#endif + #ifndef BITSPERBYTE # define BITSPERBYTE (NBBY * sizeof (char)) #endif diff --git a/src/libutil/keypair_private.h b/src/libutil/keypair_private.h index ac70f25e6..757dabb6b 100644 --- a/src/libutil/keypair_private.h +++ b/src/libutil/keypair_private.h @@ -30,11 +30,11 @@ #include "blake2.h" #include "cryptobox.h" -struct rspamd_http_keypair { +struct RSPAMD_ALIGNED(32) rspamd_http_keypair { guchar pk[rspamd_cryptobox_PKBYTES]; - guchar sk[rspamd_cryptobox_SKBYTES]; + guchar RSPAMD_ALIGNED(32) sk[rspamd_cryptobox_SKBYTES]; guchar id[BLAKE2B_OUTBYTES]; - guchar nm[rspamd_cryptobox_NMBYTES]; + guchar RSPAMD_ALIGNED(32) nm[rspamd_cryptobox_NMBYTES]; gboolean has_nm; ref_entry_t ref; }; -- 2.39.5