Skip to content

Commit

Permalink
Merge pull request #27 from ccrusius/solaris11
Browse files Browse the repository at this point in the history
Compile on Solaris 11 (Solaris 11 zone on SmartOS)
  • Loading branch information
staticfloat authored and ararslan committed Feb 3, 2017
1 parent 2040de7 commit bcc15f8
Showing 1 changed file with 55 additions and 37 deletions.
92 changes: 55 additions & 37 deletions src/specfun/fpmath.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,51 +38,69 @@
#endif
#endif

#ifdef __linux
#include <features.h>
#include <endian.h>
#define _LITTLE_ENDIAN __LITTLE_ENDIAN
#define _BIG_ENDIAN __BIG_ENDIAN
#define _PDP_ENDIAN __PDP_ENDIAN
#define _BYTE_ORDER __BYTE_ORDER
#endif

#ifdef __APPLE__
#include <machine/endian.h>
#define _LITTLE_ENDIAN LITTLE_ENDIAN
#define _BIG_ENDIAN BIG_ENDIAN
#define _PDP_ENDIAN PDP_ENDIAN
#define _BYTE_ORDER BYTE_ORDER
#endif

#ifdef __FreeBSD__
#include <machine/endian.h>
#endif
// We need to find out the byte ordering of the system.
//
// This will be stored in the following macros:
// _FPMATH_LITTLE_ENDIAN: An arbitrary constant
// _FPMATH_BIG_ENDIAN: An arbitrary constant
// _FPMATH_BYTE_ORDER: Either _FPMATH_LITTLE_ENDIAN or _FPMATH_BIG_ENDIAN

#ifdef _WIN32
#define _LITTLE_ENDIAN 1234
#define _BIG_ENDIAN 4321
#define _PDP_ENDIAN 3412
#define _BYTE_ORDER _LITTLE_ENDIAN
#define _FLOAT_WORD_ORDER _LITTLE_ENDIAN
#define LITTLE_ENDIAN _LITTLE_ENDIAN
#define BIG_ENDIAN _BIG_ENDIAN
#define PDP_ENDIAN _PDP_ENDIAN
#define BYTE_ORDER _BYTE_ORDER
// The GNU preprocessor defines a few things by itself
// See http://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html#Common-Predefined-Macros
#if defined(__ORDER_LITTLE_ENDIAN__) && defined(__ORDER_BIG_ENDIAN__) && defined(__BYTE_ORDER__)
# define _FPMATH_BIG_ENDIAN __ORDER_BIG_ENDIAN__
# define _FPMATH_LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
# define _FPMATH_BYTE_ORDER __BYTE_ORDER__
// If not defined by the preprocessor, let us try to do it ourselves.
// Linux
#elif defined(__linux)
# include <features.h>
# include <endian.h>
# define _FPMATH_LITTLE_ENDIAN __LITTLE_ENDIAN
# define _FPMATH_BIG_ENDIAN __BIG_ENDIAN
# define _FPMATH_BYTE_ORDER __BYTE_ORDER
// OSX
#elif defined(__APPLE__)
# include <machine/endian.h>
# define _FPMATH_LITTLE_ENDIAN LITTLE_ENDIAN
# define _FPMATH_BIG_ENDIAN BIG_ENDIAN
# define _FPMATH_BYTE_ORDER BYTE_ORDER
// FreeBSD
#elif defined(__FreeBSD__)
# include <machine/endian.h>
# define _FPMATH_LITTLE_ENDIAN _LITTLE_ENDIAN
# define _FPMATH_BIG_ENDIAN _BIG_ENDIAN
# define _FPMATH_BYTE_ORDER _BYTE_ORDER
// Windows
#elif defined(_WIN32)
# define _FPMATH_LITTLE_ENDIAN 1234
# define _FPMATH_BIG_ENDIAN 4321
# define _FPMATH_BYTE_ORDER _FPMATH_LITTLE_ENDIAN
// Solaris
#elif defined(__sun)
# define _FPMATH_LITTLE_ENDIAN 1234
# define _FPMATH_BIG_ENDIAN 4321
# include <sys/isa_defs.h>
# ifdef _LITTLE_ENDIAN
# define _FPMATH_BYTE_ORDER _FPMATH_LITTLE_ENDIAN
# endif
# ifdef _BIG_ENDIAN
# define _FPMATH_BYTE_ORDER _FPMATH_BIG_ENDIAN
# endif
#endif

#ifndef _IEEE_WORD_ORDER
#define _IEEE_WORD_ORDER _BYTE_ORDER
#define _IEEE_WORD_ORDER _FPMATH_BYTE_ORDER
#endif

union IEEEf2bits {
float f;
struct {
#if _BYTE_ORDER == _LITTLE_ENDIAN
#if _FPMATH_BYTE_ORDER == _FPMATH_LITTLE_ENDIAN
unsigned int man :23;
unsigned int exp :8;
unsigned int sign :1;
#else /* _BIG_ENDIAN */
#else /* _FPMATH_BIG_ENDIAN */
unsigned int sign :1;
unsigned int exp :8;
unsigned int man :23;
Expand All @@ -96,17 +114,17 @@ union IEEEf2bits {
union IEEEd2bits {
double d;
struct {
#if _BYTE_ORDER == _LITTLE_ENDIAN
#if _IEEE_WORD_ORDER == _LITTLE_ENDIAN
#if _FPMATH_BYTE_ORDER == _FPMATH_LITTLE_ENDIAN
#if _IEEE_WORD_ORDER == _FPMATH_LITTLE_ENDIAN
unsigned int manl :32;
#endif
unsigned int manh :20;
unsigned int exp :11;
unsigned int sign :1;
#if _IEEE_WORD_ORDER == _BIG_ENDIAN
#if _IEEE_WORD_ORDER == _FPMATH_BIG_ENDIAN
unsigned int manl :32;
#endif
#else /* _BIG_ENDIAN */
#else /* _FPMATH_BIG_ENDIAN */
unsigned int sign :1;
unsigned int exp :11;
unsigned int manh :20;
Expand Down

0 comments on commit bcc15f8

Please sign in to comment.