8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-27 06:43:04 +01:00
firebird-mirror/src/misc/align.cpp

139 lines
2.9 KiB
C++
Raw Normal View History

2001-05-23 15:26:42 +02:00
/*
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
2001-05-23 15:26:42 +02:00
#include "firebird.h"
2001-05-23 15:26:42 +02:00
#include <signal.h>
2004-04-29 00:36:29 +02:00
#include <stdio.h>
2001-05-23 15:26:42 +02:00
2009-01-14 12:10:48 +01:00
struct xyz
{
2001-05-23 15:26:42 +02:00
char a;
double b;
2004-06-08 20:27:59 +02:00
};
typedef xyz* XYZ;
2001-05-23 15:26:42 +02:00
#define MAJOR_MINOR "((n + b - 1) & ~(b - 1))"
2004-11-24 10:22:07 +01:00
#define EVEN "((n + 1) & ~1)"
2001-05-23 15:26:42 +02:00
#define NO_OP "(n)"
2009-01-14 12:10:48 +01:00
struct alignment
{
2001-05-23 15:26:42 +02:00
short rule_offset;
short rule_length;
short rule_faults;
short rule_base_align;
short rule_double_align;
const char *rule_rule;
const char *rule_system;
2003-09-18 12:28:34 +02:00
};
2001-05-23 15:26:42 +02:00
2009-01-14 12:10:48 +01:00
static const alignment rules[] =
{
2001-05-23 15:26:42 +02:00
1, 9, 0, 4, 4, NO_OP, "VMS", /* VMS */
2, 10, 0, 4, 4, EVEN, "MC 68K", /* Generic Motorola */
4, 12, 0, 4, 4, MAJOR_MINOR, "VAX Ultrix, 386i, RT", /* VAX Ultrix */
8, 16, 1, 8, 8, MAJOR_MINOR, "HP Precision", /* HP Precision */
8, 16, 0, 4, 8, MAJOR_MINOR, "Sparc", /* MIPS, Sun Sparc */
0, 0, 0, 0, 0
};
2009-01-14 12:10:48 +01:00
static void check_byte_order();
static int check_double();
static void handler();
2001-05-23 15:26:42 +02:00
int main(int argc, char *argv[])
{
#if SIZEOF_LONG == 8
2001-05-23 15:26:42 +02:00
int vector[3];
#else
long vector[3];
#endif
2004-11-24 10:22:07 +01:00
const short offset = (int) &((XYZ) NULL)->b;
const short length = sizeof(xyz);
const short faults = check_double();
2001-05-23 15:26:42 +02:00
for (const alignment* rule = rules; rule->rule_offset; ++rule)
2001-05-23 15:26:42 +02:00
if (rule->rule_offset == offset &&
2004-11-24 10:22:07 +01:00
rule->rule_length == length && rule->rule_faults == faults)
{
2004-04-29 00:36:29 +02:00
printf("\n/* %s */\n\n", rule->rule_system);
printf("#define FB_ALIGNMENT\t%d\n", rule->rule_base_align);
printf("#define FB_DOUBLE_ALIGN\t%d\n", rule->rule_double_align);
2004-11-24 10:22:07 +01:00
printf("#define FB_ALIGN(n, b)\t%s\n", rule->rule_rule);
2001-05-23 15:26:42 +02:00
check_byte_order();
2004-04-29 00:36:29 +02:00
printf("\n");
2001-05-23 15:26:42 +02:00
return 1;
}
2004-04-29 00:36:29 +02:00
printf("Unknown system, double offset %d, structure length %d\n",
2001-05-23 15:26:42 +02:00
offset, length);
check_byte_order();
return 1;
}
2009-01-14 12:10:48 +01:00
static void check_byte_order()
2001-05-23 15:26:42 +02:00
{
union {
short s;
char c[2];
} order_test;
order_test.c[0] = 1;
order_test.c[1] = 2;
if (order_test.s == 0x0102)
2004-04-29 00:36:29 +02:00
printf("#define WORDS_BIGENDIAN\t\t1\n");
2001-05-23 15:26:42 +02:00
}
2009-01-14 12:10:48 +01:00
static int check_double()
2001-05-23 15:26:42 +02:00
{
2004-11-24 10:22:07 +01:00
double *p;
#if SIZEOF_LONG == 8
2001-05-23 15:26:42 +02:00
int vector[3];
#else
long vector[3];
#endif
2001-12-24 03:51:06 +01:00
try {
signal(SIGBUS, handler);
signal(SIGSEGV, handler);
p = (double *) &vector[0];
*p = 3;
*p *= 2.5;
p = (double *) &vector[1];
*p = 3;
*p *= 2.5;
}
2006-05-20 03:53:51 +02:00
catch (const Firebird::Exception&) {
2001-05-23 15:26:42 +02:00
return 1;
2001-12-24 03:51:06 +01:00
}
2001-05-23 15:26:42 +02:00
return 0;
}
static void handler()
{
Firebird::status_exception::raise();
2001-05-23 15:26:42 +02:00
}