From 47477269bf3d3c3e3af2494c30d2139d8696794f Mon Sep 17 00:00:00 2001 From: Marty Kraimer Date: Tue, 20 Jan 1998 21:35:08 +0000 Subject: [PATCH] created for 64 bit architecture support --- src/libCom/adjustment.c | 66 ++++++++++++++++++++++++++++++++++++ src/libCom/adjustment.h | 19 +++++++++++ src/libCom/misc/adjustment.c | 66 ++++++++++++++++++++++++++++++++++++ src/libCom/misc/adjustment.h | 19 +++++++++++ 4 files changed, 170 insertions(+) create mode 100644 src/libCom/adjustment.c create mode 100644 src/libCom/adjustment.h create mode 100644 src/libCom/misc/adjustment.c create mode 100644 src/libCom/misc/adjustment.h diff --git a/src/libCom/adjustment.c b/src/libCom/adjustment.c new file mode 100644 index 000000000..559aefbed --- /dev/null +++ b/src/libCom/adjustment.c @@ -0,0 +1,66 @@ +/* src/libCom/adjustment.c */ + +/* Author: Peregrine McGehee Date: 21NOV1997 */ +/***************************************************************** + COPYRIGHT NOTIFICATION +***************************************************************** + +(C) COPYRIGHT 1993 UNIVERSITY OF CHICAGO + +This software was developed under a United States Government license +described on the COPYRIGHT_UniversityOfChicago file included as part +of this distribution. +**********************************************************************/ + +/* + * + * Modification Log: + * ----------------- + * .01 11-21-97 pmm Initial Implementation + */ + +#ifdef vxWorks +#include +#include +#include "fast_lock.h" +#endif + +#include +#include +#include + +#include "shareLib.h" +#include "adjustment.h" + +#define epicsExportSharedSymbols + +epicsShareFunc size_t epicsShareAPI adjustToWorstCaseAlignment(size_t size) +{ + int align_size, adjust; + struct test_long_word { char c; long lw; }; + struct test_double { char c; double d; }; + struct test_ptr { char c; void *p; }; + int test_long_size = sizeof(struct test_long_word) - sizeof(long); + int test_double_size = sizeof(struct test_double) - sizeof(double); + int test_ptr_size = sizeof(struct test_ptr) - sizeof(void *); + size_t adjusted_size = size; + + /* + * Use Jeff's alignment tests to determine worst case of long, + * double or pointer alignment requirements. + */ + align_size = test_long_size > test_ptr_size ? + test_long_size : test_ptr_size; + + align_size = align_size > test_double_size ? + align_size : test_double_size; + + /* + * Increase the size to fit worst case alignment if not already + * properly aligned. + */ + adjust = align_size - size%align_size; + if (adjust != align_size) adjusted_size += adjust; + + return (adjusted_size); +} diff --git a/src/libCom/adjustment.h b/src/libCom/adjustment.h new file mode 100644 index 000000000..ad7c13c14 --- /dev/null +++ b/src/libCom/adjustment.h @@ -0,0 +1,19 @@ +/* src/libCom/adjustment.h */ + +/***************************************************************** + COPYRIGHT NOTIFICATION +***************************************************************** + +(C) COPYRIGHT 1993 UNIVERSITY OF CHICAGO + +This software was developed under a United States Government license +described on the COPYRIGHT_UniversityOfChicago file included as part +of this distribution. +**********************************************************************/ +#ifndef INCadjustmenth +#define INCadjustmenth +#include "shareLib.h" +epicsShareFunc size_t epicsShareAPI adjustToWorstCaseAlignment(size_t size); + +#endif /*INCadjustmenth*/ + diff --git a/src/libCom/misc/adjustment.c b/src/libCom/misc/adjustment.c new file mode 100644 index 000000000..559aefbed --- /dev/null +++ b/src/libCom/misc/adjustment.c @@ -0,0 +1,66 @@ +/* src/libCom/adjustment.c */ + +/* Author: Peregrine McGehee Date: 21NOV1997 */ +/***************************************************************** + COPYRIGHT NOTIFICATION +***************************************************************** + +(C) COPYRIGHT 1993 UNIVERSITY OF CHICAGO + +This software was developed under a United States Government license +described on the COPYRIGHT_UniversityOfChicago file included as part +of this distribution. +**********************************************************************/ + +/* + * + * Modification Log: + * ----------------- + * .01 11-21-97 pmm Initial Implementation + */ + +#ifdef vxWorks +#include +#include +#include "fast_lock.h" +#endif + +#include +#include +#include + +#include "shareLib.h" +#include "adjustment.h" + +#define epicsExportSharedSymbols + +epicsShareFunc size_t epicsShareAPI adjustToWorstCaseAlignment(size_t size) +{ + int align_size, adjust; + struct test_long_word { char c; long lw; }; + struct test_double { char c; double d; }; + struct test_ptr { char c; void *p; }; + int test_long_size = sizeof(struct test_long_word) - sizeof(long); + int test_double_size = sizeof(struct test_double) - sizeof(double); + int test_ptr_size = sizeof(struct test_ptr) - sizeof(void *); + size_t adjusted_size = size; + + /* + * Use Jeff's alignment tests to determine worst case of long, + * double or pointer alignment requirements. + */ + align_size = test_long_size > test_ptr_size ? + test_long_size : test_ptr_size; + + align_size = align_size > test_double_size ? + align_size : test_double_size; + + /* + * Increase the size to fit worst case alignment if not already + * properly aligned. + */ + adjust = align_size - size%align_size; + if (adjust != align_size) adjusted_size += adjust; + + return (adjusted_size); +} diff --git a/src/libCom/misc/adjustment.h b/src/libCom/misc/adjustment.h new file mode 100644 index 000000000..ad7c13c14 --- /dev/null +++ b/src/libCom/misc/adjustment.h @@ -0,0 +1,19 @@ +/* src/libCom/adjustment.h */ + +/***************************************************************** + COPYRIGHT NOTIFICATION +***************************************************************** + +(C) COPYRIGHT 1993 UNIVERSITY OF CHICAGO + +This software was developed under a United States Government license +described on the COPYRIGHT_UniversityOfChicago file included as part +of this distribution. +**********************************************************************/ +#ifndef INCadjustmenth +#define INCadjustmenth +#include "shareLib.h" +epicsShareFunc size_t epicsShareAPI adjustToWorstCaseAlignment(size_t size); + +#endif /*INCadjustmenth*/ +