Skip to content

Commit f63dcf4

Browse files
magvjodavies
authored andcommitted
Simplify 32-bit detection using stdint.h
1 parent 6210e9e commit f63dcf4

8 files changed

Lines changed: 121 additions & 216 deletions

File tree

configure.ac

Lines changed: 2 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -292,59 +292,6 @@ AS_IF([test "x$with_api" = xwindows],
292292
AM_CONDITIONAL([ONUNIX], [test "x$with_api" = xposix])
293293
AM_CONDITIONAL([ONWINDOWS], [test "x$with_api" = xwindows])
294294

295-
# Check for data model
296-
AC_CHECK_SIZEOF([char])
297-
AC_CHECK_SIZEOF([short])
298-
AC_CHECK_SIZEOF([int])
299-
AC_CHECK_SIZEOF([long])
300-
AC_CHECK_SIZEOF([long long])
301-
AC_CHECK_SIZEOF([void *])
302-
AC_CHECK_SIZEOF([off_t])
303-
304-
case $ac_cv_sizeof_char-$ac_cv_sizeof_short-$ac_cv_sizeof_int-$ac_cv_sizeof_long-$ac_cv_sizeof_long_long-$ac_cv_sizeof_void_p-$ac_cv_sizeof_off_t in
305-
1-2-4-4-*-4-*)
306-
# Most of today's 32 bit systems.
307-
print_data_model="ILP32"
308-
ac_cv_sizeof_WORD=$ac_cv_sizeof_short
309-
ac_cv_sizeof_LONG=$ac_cv_sizeof_long
310-
AC_DEFINE(ILP32, , [Compiling for ILP32 data model])
311-
# We need INT64.
312-
AS_IF([test $ac_cv_sizeof_long_long -ne 8],
313-
[AC_MSG_FAILURE([64-bit integers are not available])])
314-
;;
315-
1-2-4-4-8-8-*)
316-
# Microsoft Windows (X64/IA-64).
317-
print_data_model="LLP64"
318-
ac_cv_sizeof_WORD=$ac_cv_sizeof_int
319-
ac_cv_sizeof_LONG=$ac_cv_sizeof_long_long
320-
AC_DEFINE(LLP64, , [Compiling for LLP64 data model])
321-
;;
322-
1-2-4-8-*-8-*)
323-
# Most Unix and Unix-like systems, e.g., Solaris, Linux and Mac OS X.
324-
print_data_model="LP64"
325-
ac_cv_sizeof_WORD=$ac_cv_sizeof_int
326-
ac_cv_sizeof_LONG=$ac_cv_sizeof_long
327-
AC_DEFINE(LP64, , [Compiling for LP64 data model])
328-
;;
329-
*)
330-
AC_MSG_FAILURE([Cannot recognize the data model used in the compiler])
331-
;;
332-
esac
333-
# Our basic assumption:
334-
# sizeof(off_t) >= sizeof(LONG) >= sizeof(void *) >= sizeof(int)
335-
# >= sizeof(WORD) >= sizeof(char) == 1.
336-
flag=:
337-
$flag && test $ac_cv_sizeof_off_t -lt $ac_cv_sizeof_LONG && flag=false
338-
$flag && test $ac_cv_sizeof_LONG -lt $ac_cv_sizeof_void_p && flag=false
339-
$flag && test $ac_cv_sizeof_void_p -lt $ac_cv_sizeof_int && flag=false
340-
$flag && test $ac_cv_sizeof_int -lt $ac_cv_sizeof_WORD && flag=false
341-
$flag && test $ac_cv_sizeof_WORD -lt $ac_cv_sizeof_char && flag=false
342-
$flag && test $ac_cv_sizeof_char -ne 1 && flag=false
343-
AS_IF([$flag], [], [AC_MSG_FAILURE([Basic assumption sizeof(off_t) >= sizeof(LONG) >= sizeof(void *) >= sizeof(int) >= sizeof(WORD) >= sizeof(char) == 1 does not hold.])])
344-
# sizeof(off_t) <= 4 means files must <= 2 GB.
345-
AS_IF([test $ac_cv_sizeof_off_t -le 4], [AC_MSG_WARN([Large files more than 2 GB are not supported])])
346-
AC_MSG_NOTICE([The data model is $print_data_model])
347-
348295
# Check for gmp
349296
AC_ARG_WITH([gmp],
350297
[AS_HELP_STRING([--with-gmp@<:@=DIR@:>@],
@@ -975,15 +922,7 @@ if test "$my_test_COMPILEFLAGS" != set; then
975922
# Use -march=native if available.
976923
AX_CHECK_COMPILE_FLAG([-march=native],
977924
[COMPILEFLAGS="$COMPILEFLAGS -march=native"],
978-
[if test "x$print_data_model" = xILP32; then
979-
if test "x$print_cpu" = xPentium; then
980-
COMPILEFLAGS="$COMPILEFLAGS -march=i586"
981-
elif test "x$print_cpu" = 'xPentium Pro'; then
982-
COMPILEFLAGS="$COMPILEFLAGS -march=i686"
983-
elif test "x$print_cpu" = xOpteron; then
984-
COMPILEFLAGS="$COMPILEFLAGS -march=opteron"
985-
fi
986-
fi],
925+
[],
987926
[-Werror])
988927
fi
989928
# Profiling option.
@@ -1191,7 +1130,7 @@ manoutputdir=$(eval "echo $mandir")
11911130
manoutputdir=$(eval "echo $manoutputdir")
11921131
echo "FORM $VERSION"
11931132
echo
1194-
echo "Compiling for: $print_cpu $print_os ($print_data_model $print_api)"
1133+
echo "Compiling for: $print_cpu $print_os ($print_api)"
11951134
echo
11961135
echo "Optionally linked libraries:"
11971136
atleastone=no
@@ -1390,11 +1329,6 @@ fi
13901329
if test $atleastone = no; then
13911330
echo " <NONE>"
13921331
fi
1393-
if test $ac_cv_sizeof_off_t -le 4; then
1394-
echo
1395-
echo "***CAUTION*** Large files more than 2 GB will be"
1396-
echo "not supported."
1397-
fi
13981332
if test "x$thread_clock_ok" = xno; then
13991333
s="none"
14001334
if test "x$build_tform" = xyes && test "x$build_tvorm" = xyes; then

sources/compiler.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -268,32 +268,30 @@ LONG insubexpbuffers = 0;
268268
subexpbuffers = (SUBBUF *)Malloc1(256*sizeof(SUBBUF),"subexpbuffers");\
269269
topsubexpbuffers = subexpbuffers+256; } insubexpbuffers = 0; }
270270

271-
#if defined(ILP32)
272-
273-
#define PUTNUMBER128(t,n) { if ( n >= 16384 ) { \
271+
#if BITSINWORD == 32
272+
#define PUTNUMBER128(t,n) { if ( n >= 2097152 ) { \
273+
*t++ = ((n/128)/128)/128; *t++ = ((n/128)/128)%128; *t++ = (n/128)%128; *t++ = n%128; } \
274+
else if ( n >= 16384 ) { \
274275
*t++ = n/(128*128); *t++ = (n/128)%128; *t++ = n%128; } \
275276
else if ( n >= 128 ) { *t++ = n/128; *t++ = n%128; } \
276277
else *t++ = n; }
277-
#define PUTNUMBER100(t,n) { if ( n >= 10000 ) { \
278+
#define PUTNUMBER100(t,n) { if ( n >= 1000000 ) { \
279+
*t++ = ((n/100)/100)/100; *t++ = ((n/100)/100)%100; *t++ = (n/100)%100; *t++ = n%100; } \
280+
else if ( n >= 10000 ) { \
278281
*t++ = n/10000; *t++ = (n/100)%100; *t++ = n%100; } \
279282
else if ( n >= 100 ) { *t++ = n/100; *t++ = n%100; } \
280283
else *t++ = n; }
281-
282-
#elif ( defined(LLP64) || defined(LP64) )
283-
284-
#define PUTNUMBER128(t,n) { if ( n >= 2097152 ) { \
285-
*t++ = ((n/128)/128)/128; *t++ = ((n/128)/128)%128; *t++ = (n/128)%128; *t++ = n%128; } \
286-
else if ( n >= 16384 ) { \
284+
#elif BITSINWORD == 16
285+
#define PUTNUMBER128(t,n) { if ( n >= 16384 ) { \
287286
*t++ = n/(128*128); *t++ = (n/128)%128; *t++ = n%128; } \
288287
else if ( n >= 128 ) { *t++ = n/128; *t++ = n%128; } \
289288
else *t++ = n; }
290-
#define PUTNUMBER100(t,n) { if ( n >= 1000000 ) { \
291-
*t++ = ((n/100)/100)/100; *t++ = ((n/100)/100)%100; *t++ = (n/100)%100; *t++ = n%100; } \
292-
else if ( n >= 10000 ) { \
289+
#define PUTNUMBER100(t,n) { if ( n >= 10000 ) { \
293290
*t++ = n/10000; *t++ = (n/100)%100; *t++ = n%100; } \
294291
else if ( n >= 100 ) { *t++ = n/100; *t++ = n%100; } \
295292
else *t++ = n; }
296-
293+
#else
294+
#error Only 64-bit and 32-bit platforms are supported.
297295
#endif
298296

299297
/*

sources/form3.h

Lines changed: 30 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
#ifdef LINUX32
6060
#define UNIX
6161
#define LINUX
62-
#define ILP32
6362
#define _FILE_OFFSET_BITS 64
6463
#define WITHZLIB
6564
#define WITHGMP
@@ -69,7 +68,6 @@
6968
#ifdef LINUX64
7069
#define UNIX
7170
#define LINUX
72-
#define LP64
7371
#define WITHZLIB
7472
#define WITHGMP
7573
#define WITHPOSIXCLOCK
@@ -78,14 +76,12 @@
7876

7977
#ifdef APPLE32
8078
#define UNIX
81-
#define ILP32
8279
#define _FILE_OFFSET_BITS 64
8380
#define WITHZLIB
8481
#endif
8582

8683
#ifdef APPLE64
8784
#define UNIX
88-
#define LP64
8985
#define WITHZLIB
9086
#define WITHGMP
9187
#define WITHPOSIXCLOCK
@@ -96,17 +92,11 @@
9692

9793
#ifdef CYGWIN32
9894
#define UNIX
99-
#define ILP32
10095
#endif
10196

10297
#ifdef _MSC_VER
10398
#define WINDOWS
10499
#define _CRT_SECURE_NO_WARNINGS
105-
#if defined(_WIN64)
106-
#define LLP64
107-
#elif defined(_WIN32)
108-
#define ILP32
109-
#endif
110100
#endif
111101

112102
/*
@@ -202,67 +192,41 @@
202192

203193
#include <stdint.h>
204194

205-
/*
206-
* Data model. ILP32 or LLP64 or LP64 must be defined.
207-
*
208-
* Here we define basic types WORD, LONG and their unsigned versions
209-
* UWORD and ULONG. LONG must be double size of WORD. Their actual types
210-
* are system-dependent. BITSINWORD and BITSINLONG are also defined.
211-
*/
212-
#if defined(ILP32)
213-
214-
typedef short WORD;
215-
typedef long LONG;
216-
typedef unsigned short UWORD;
217-
typedef unsigned long ULONG;
218-
#define BITSINWORD 16
219-
#define BITSINLONG 32
220-
221-
#define WORD_MIN_VALUE SHRT_MIN
222-
#define WORD_MAX_VALUE SHRT_MAX
223-
#define LONG_MIN_VALUE LONG_MIN
224-
#define LONG_MAX_VALUE LONG_MAX
225-
226-
#elif defined(LLP64)
227-
228-
typedef int WORD;
229-
typedef long long LONG;
230-
typedef unsigned int UWORD;
231-
typedef unsigned long long ULONG;
232-
#define BITSINWORD 32
233-
#define BITSINLONG 64
234-
235-
#define WORD_MIN_VALUE INT_MIN
236-
#define WORD_MAX_VALUE INT_MAX
237-
#define LONG_MIN_VALUE LLONG_MIN
238-
#define LONG_MAX_VALUE LLONG_MAX
239-
240-
#elif defined(LP64)
241-
242-
typedef int WORD;
243-
typedef long LONG;
244-
typedef unsigned int UWORD;
245-
typedef unsigned long ULONG;
246-
#define BITSINWORD 32
247-
#define BITSINLONG 64
248-
249-
#define WORD_MIN_VALUE INT_MIN
250-
#define WORD_MAX_VALUE INT_MAX
251-
#define LONG_MIN_VALUE LONG_MIN
252-
#define LONG_MAX_VALUE LONG_MAX
253-
195+
#if UINTPTR_MAX == UINT64_MAX
196+
typedef int32_t WORD;
197+
typedef int64_t LONG;
198+
typedef uint32_t UWORD;
199+
typedef uint64_t ULONG;
200+
#define BITSINWORD 32
201+
#define BITSINLONG 64
202+
#define WORD_MIN_VALUE INT32_MIN
203+
#define WORD_MAX_VALUE INT32_MAX
204+
#define LONG_MIN_VALUE INT64_MIN
205+
#define LONG_MAX_VALUE INT64_MAX
206+
#elif UINTPTR_MAX == UINT32_MAX
207+
typedef int16_t WORD;
208+
typedef int32_t LONG;
209+
typedef uint16_t UWORD;
210+
typedef uint32_t ULONG;
211+
#define BITSINWORD 16
212+
#define BITSINLONG 32
213+
#define WORD_MIN_VALUE INT16_MIN
214+
#define WORD_MAX_VALUE INT16_MAX
215+
#define LONG_MIN_VALUE INT32_MIN
216+
#define LONG_MAX_VALUE INT32_MAX
254217
#else
255-
#error ILP32 or LLP64 or LP64 must be defined!
218+
#error Can not detect if this is a 32-bit or 64-bit platform.
256219
#endif
257220

258221
STATIC_ASSERT(sizeof(WORD) * 8 == BITSINWORD);
259222
STATIC_ASSERT(sizeof(LONG) * 8 == BITSINLONG);
260223
STATIC_ASSERT(sizeof(WORD) * 2 == sizeof(LONG));
261224
STATIC_ASSERT(sizeof(LONG) >= sizeof(int *));
262-
263-
#if BITSINWORD == 32
264-
#define WORDSIZE32 1
265-
#endif
225+
STATIC_ASSERT(sizeof(LONG) >= sizeof(int *));
226+
STATIC_ASSERT(sizeof(int *) >= sizeof(int));
227+
STATIC_ASSERT(sizeof(int) >= sizeof(WORD));
228+
STATIC_ASSERT(sizeof(WORD) >= sizeof(char));
229+
STATIC_ASSERT(sizeof(char) == 1);
266230

267231
typedef signed char SBYTE;
268232
typedef unsigned char UBYTE;
@@ -441,6 +405,8 @@ template<typename T> struct calc {
441405
#include "declare.h"
442406
#include "variable.h"
443407

408+
STATIC_ASSERT(sizeof(off_t) >= sizeof(LONG));
409+
444410
/*
445411
* The interface to file routines for UNIX or non-UNIX (Windows).
446412
*/

0 commit comments

Comments
 (0)