build fixes for Solaris 11.4 (gcc & Oracle Studio compilers)

This commit is contained in:
Brian Cox 2019-08-19 23:16:35 -07:00
parent 97ef149c40
commit a9443df76d
3 changed files with 72 additions and 61 deletions

View File

@ -351,7 +351,7 @@
# define USE_STD_CPP_LOCALE_WORKAROUND \ # define USE_STD_CPP_LOCALE_WORKAROUND \
(IS_SUNPRO || (IS_KAI && !IS_KAI_3_4)) // TODO:BAM -- name this something more general. (IS_SUNPRO || (IS_KAI && !IS_KAI_3_4)) // TODO:BAM -- name this something more general.
//# define USE_CLIB_LOCALE IS_KAI || HAVE_GCC //# define USE_CLIB_LOCALE IS_KAI || HAVE_GCC
# define USE_CLIB_LOCALE (!HAVE_LOCALE) # define USE_CLIB_LOCALE (!HAVE_LOCALE || (HAVE_GCC && IS_SOLARIS))
# define USES_CLIB_DATE_FUNCTION \ # define USES_CLIB_DATE_FUNCTION \
(USE_CLIB_LOCALE || IS_SUNPRO || \ (USE_CLIB_LOCALE || IS_SUNPRO || \
IS_MSVC) // if we use clib, can't use C++ time_put, and SUNPRO and MSVC add characters IS_MSVC) // if we use clib, can't use C++ time_put, and SUNPRO and MSVC add characters
@ -409,6 +409,13 @@
# define USE_DEV_URANDOM (HAVE_DEV_URANDOM && ENABLE_DEV_URANDOM) # define USE_DEV_URANDOM (HAVE_DEV_URANDOM && ENABLE_DEV_URANDOM)
#if IS_SOLARIS
# define UNAME_SUCCESS_POSIX 1
#else
# define UNAME_SUCCESS_ZERO
#endif
//============================================================================= //=============================================================================
// Miscellaneous // Miscellaneous
// //

View File

@ -20,7 +20,7 @@
union dword_union union dword_union
{ {
dword dw; dword dw;
struct { struct _w {
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
word high; word high;
word low; word low;
@ -28,7 +28,7 @@ union dword_union
word low; word low;
word high; word high;
#endif #endif
}; } w;
}; };
#if defined(_MSC_VER) && defined(_M_IX86) && (_M_IX86<=500) #if defined(_MSC_VER) && defined(_M_IX86) && (_M_IX86<=500)
@ -145,10 +145,10 @@ static word Add(word *C, const word *A, const word *B, unsigned int N)
{ {
dword_union u; dword_union u;
u.dw = (dword) carry + A[i] + B[i]; u.dw = (dword) carry + A[i] + B[i];
C[i] = u.low; C[i] = u.w.low;
u.dw = (dword) u.high + A[i+1] + B[i+1]; u.dw = (dword) u.w.high + A[i+1] + B[i+1];
C[i+1] = u.low; C[i+1] = u.w.low;
carry = u.high; carry = u.w.high;
} }
return carry; return carry;
} }
@ -162,10 +162,10 @@ static word Subtract(word *C, const word *A, const word *B, unsigned int N)
{ {
dword_union u; dword_union u;
u.dw = (dword) A[i] - B[i] - borrow; u.dw = (dword) A[i] - B[i] - borrow;
C[i] = u.low; C[i] = u.w.low;
u.dw = (dword) A[i+1] - B[i+1] - (word)(0-u.high); u.dw = (dword) A[i+1] - B[i+1] - (word)(0-u.w.high);
C[i+1] = u.low; C[i+1] = u.w.low;
borrow = 0-u.high; borrow = 0-u.w.high;
} }
return borrow; return borrow;
} }
@ -223,8 +223,8 @@ static word LinearMultiply(word *C, const word *A, word B, unsigned int N)
{ {
dword_union p; dword_union p;
p.dw = (dword)A[i] * B + carry; p.dw = (dword)A[i] * B + carry;
C[i] = p.low; C[i] = p.w.low;
carry = p.high; carry = p.w.high;
} }
return carry; return carry;
} }
@ -259,17 +259,17 @@ static void AtomicMultiply(word *C, word A0, word A1, word B0, word B1)
dword_union A0B0; dword_union A0B0;
A0B0.dw = (dword)A0*B0; A0B0.dw = (dword)A0*B0;
C[0] = A0B0.low; C[0] = A0B0.w.low;
dword_union A1B1; dword_union A1B1;
A1B1.dw = (dword)A1*B1; A1B1.dw = (dword)A1*B1;
dword_union t; dword_union t;
t.dw = (dword)A0B0.high + A0B0.low + d.low + A1B1.low; t.dw = (dword)A0B0.w.high + A0B0.w.low + d.w.low + A1B1.w.low;
C[1] = t.low; C[1] = t.w.low;
t.dw = A1B1.dw + t.high + A0B0.high + d.high + A1B1.high - s; t.dw = A1B1.dw + t.w.high + A0B0.w.high + d.w.high + A1B1.w.high - s;
C[2] = t.low; C[2] = t.w.low;
C[3] = t.high; C[3] = t.w.high;
} }
static word AtomicMultiplyAdd(word *C, word A0, word A1, word B0, word B1) static word AtomicMultiplyAdd(word *C, word A0, word A1, word B0, word B1)
@ -304,19 +304,19 @@ static word AtomicMultiplyAdd(word *C, word A0, word A1, word B0, word B1)
A0B0.dw = (dword)A0*B0; A0B0.dw = (dword)A0*B0;
dword_union t; dword_union t;
t.dw = A0B0.dw + C[0]; t.dw = A0B0.dw + C[0];
C[0] = t.low; C[0] = t.w.low;
dword_union A1B1; dword_union A1B1;
A1B1.dw = (dword)A1*B1; A1B1.dw = (dword)A1*B1;
t.dw = (dword) t.high + A0B0.low + d.low + A1B1.low + C[1]; t.dw = (dword) t.w.high + A0B0.w.low + d.w.low + A1B1.w.low + C[1];
C[1] = t.low; C[1] = t.w.low;
t.dw = (dword) t.high + A1B1.low + A0B0.high + d.high + A1B1.high - s + C[2]; t.dw = (dword) t.w.high + A1B1.w.low + A0B0.w.high + d.w.high + A1B1.w.high - s + C[2];
C[2] = t.low; C[2] = t.w.low;
t.dw = (dword) t.high + A1B1.high + C[3]; t.dw = (dword) t.w.high + A1B1.w.high + C[3];
C[3] = t.low; C[3] = t.w.low;
return t.high; return t.w.high;
} }
static inline void AtomicSquare(word *C, word A, word B) static inline void AtomicSquare(word *C, word A, word B)
@ -327,16 +327,16 @@ static inline void AtomicSquare(word *C, word A, word B)
#else #else
dword_union t1; dword_union t1;
t1.dw = (dword) A*A; t1.dw = (dword) A*A;
C[0] = t1.low; C[0] = t1.w.low;
dword_union t2; dword_union t2;
t2.dw = (dword) A*B; t2.dw = (dword) A*B;
t1.dw = (dword) t1.high + t2.low + t2.low; t1.dw = (dword) t1.w.high + t2.w.low + t2.w.low;
C[1] = t1.low; C[1] = t1.w.low;
t1.dw = (dword) B*B + t1.high + t2.high + t2.high; t1.dw = (dword) B*B + t1.w.high + t2.w.high + t2.w.high;
C[2] = t1.low; C[2] = t1.w.low;
C[3] = t1.high; C[3] = t1.w.high;
#endif #endif
} }
@ -344,16 +344,16 @@ static inline void AtomicMultiplyBottom(word *C, word A0, word A1, word B0, word
{ {
dword_union t; dword_union t;
t.dw = (dword)A0*B0; t.dw = (dword)A0*B0;
C[0] = t.low; C[0] = t.w.low;
C[1] = t.high + A0*B1 + A1*B0; C[1] = t.w.high + A0*B1 + A1*B0;
} }
static inline void AtomicMultiplyBottomAdd(word *C, word A0, word A1, word B0, word B1) static inline void AtomicMultiplyBottomAdd(word *C, word A0, word A1, word B0, word B1)
{ {
dword_union t; dword_union t;
t.dw = (dword)A0*B0 + C[0]; t.dw = (dword)A0*B0 + C[0];
C[0] = t.low; C[0] = t.w.low;
C[1] += t.high + A0*B1 + A1*B0; C[1] += t.w.high + A0*B1 + A1*B0;
} }
static void CombaMultiply(word *R, const word *A, const word *B) static void CombaMultiply(word *R, const word *A, const word *B)
@ -363,22 +363,22 @@ static void CombaMultiply(word *R, const word *A, const word *B)
#define MulAcc(x, y) \ #define MulAcc(x, y) \
p.dw = (dword)A[x] * B[y] + c; \ p.dw = (dword)A[x] * B[y] + c; \
c = p.low; \ c = p.w.low; \
p.dw = (dword)d + p.high; \ p.dw = (dword)d + p.w.high; \
d = p.low; \ d = p.w.low; \
e += p.high; e += p.w.high;
#define SaveMulAcc(s, x, y) \ #define SaveMulAcc(s, x, y) \
R[s] = c; \ R[s] = c; \
p.dw = (dword)A[x] * B[y] + d; \ p.dw = (dword)A[x] * B[y] + d; \
c = p.low; \ c = p.w.low; \
p.dw = (dword)e + p.high; \ p.dw = (dword)e + p.w.high; \
d = p.low; \ d = p.w.low; \
e = p.high; e = p.w.high;
p.dw = (dword)A[0] * B[0]; p.dw = (dword)A[0] * B[0];
R[0] = p.low; R[0] = p.w.low;
c = p.high; c = p.w.high;
d = e = 0; d = e = 0;
MulAcc(0, 1); MulAcc(0, 1);
@ -402,8 +402,8 @@ static void CombaMultiply(word *R, const word *A, const word *B)
R[5] = c; R[5] = c;
p.dw = (dword)A[3] * B[3] + d; p.dw = (dword)A[3] * B[3] + d;
R[6] = p.low; R[6] = p.w.low;
R[7] = e + p.high; R[7] = e + p.w.high;
#undef MulAcc #undef MulAcc
#undef SaveMulAcc #undef SaveMulAcc
@ -422,8 +422,8 @@ static void AtomicInverseModPower2(word *C, word A0, word A1)
assert(R.dw*A==1); assert(R.dw*A==1);
C[0] = R.low; C[0] = R.w.low;
C[1] = R.high; C[1] = R.w.high;
} }
// ******************************************************** // ********************************************************
@ -834,20 +834,20 @@ static word SubatomicDivide(word *A, word B0, word B1)
// now subtract Q*B from A // now subtract Q*B from A
p.dw = (dword) B0*Q; p.dw = (dword) B0*Q;
u.dw = (dword) A[0] - p.low; u.dw = (dword) A[0] - p.w.low;
A[0] = u.low; A[0] = u.w.low;
u.dw = (dword) A[1] - p.high - (word)(0-u.high) - (dword)B1*Q; u.dw = (dword) A[1] - p.w.high - (word)(0-u.w.high) - (dword)B1*Q;
A[1] = u.low; A[1] = u.w.low;
A[2] += u.high; A[2] += u.w.high;
// Q <= actual quotient, so fix it // Q <= actual quotient, so fix it
while (A[2] || A[1] > B1 || (A[1]==B1 && A[0]>=B0)) while (A[2] || A[1] > B1 || (A[1]==B1 && A[0]>=B0))
{ {
u.dw = (dword) A[0] - B0; u.dw = (dword) A[0] - B0;
A[0] = u.low; A[0] = u.w.low;
u.dw = (dword) A[1] - B1 - (word)(0-u.high); u.dw = (dword) A[1] - B1 - (word)(0-u.w.high);
A[1] = u.low; A[1] = u.w.low;
A[2] += u.high; A[2] += u.w.high;
Q++; Q++;
assert(Q); // shouldn't overflow assert(Q); // shouldn't overflow
} }
@ -1153,7 +1153,7 @@ long Integer::ConvertToLong() const
{ {
unsigned long value = reg[(unsigned int)0]; unsigned long value = reg[(unsigned int)0];
#ifndef __GNUC__ #ifndef __GNUC__
value += sizeof(value)>WORD_SIZE ? ((unsigned long)reg[1]<<WORD_BITS) : 0; value += (sizeof(value) > WORD_SIZE) ? (((unsigned long)(reg[(unsigned int)1])) << WORD_BITS) : 0;
#endif #endif
value = Crop(value, 8*sizeof(value)-1); value = Crop(value, 8*sizeof(value)-1);
return sign==POSITIVE ? value : -long(value); return sign==POSITIVE ? value : -long(value);

View File

@ -304,7 +304,11 @@ void TestPlatformDetection()
{ {
#if HAVE_SYS_UTSNAME_H #if HAVE_SYS_UTSNAME_H
struct utsname os_info; struct utsname os_info;
#if UNAME_SUCCESS_POSIX // Solaris documents uname() as succeding w/ any nonnegative value. This is actually the behavior specified by the POSIX standard, though in practice everyone else seems to return 0 on success.
TEST(uname(&os_info) >= 0);
#else
TEST(uname(&os_info) == 0); TEST(uname(&os_info) == 0);
#endif
TSTRING observed_os(os_info.sysname); TSTRING observed_os(os_info.sysname);