mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
COMP: update endian macros. More universal syntax, less clutter.
This commit is contained in:
committed by
Andrew Heather
parent
487877377d
commit
a9096858f6
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
|
\\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -25,60 +25,33 @@ Description
|
|||||||
Help with architecture-specific aspects.
|
Help with architecture-specific aspects.
|
||||||
|
|
||||||
Defines WM_BIG_ENDIAN or WM_LITTLE_ENDIAN as well as providing a
|
Defines WM_BIG_ENDIAN or WM_LITTLE_ENDIAN as well as providing a
|
||||||
few runtime methods. Primarily used as a namespace, but provided
|
few runtime methods. Primarily used as a namespace, but defined as
|
||||||
as a class for possible future expansion.
|
a class to allow pTraits specialization.
|
||||||
|
|
||||||
SourceFiles
|
SourceFiles
|
||||||
endianI.H
|
endianI.H
|
||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#ifndef foamEndian_H // prefixed with 'foam' to avoid potential collisions
|
#ifndef foamEndian_H // Prefixed with 'foam' to avoid any name clashes
|
||||||
#define foamEndian_H
|
#define foamEndian_H
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
#ifdef darwin
|
#ifdef __BYTE_ORDER__
|
||||||
#include <machine/endian.h>
|
// Clang, Gcc, Icc, Pgi
|
||||||
#elif defined __GNUC__
|
#if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
|
||||||
#include <endian.h>
|
|
||||||
#elif defined __mips
|
|
||||||
#include <standards.h>
|
|
||||||
#include <sys/endian.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __BYTE_ORDER
|
|
||||||
#if (__BYTE_ORDER == __LITTLE_ENDIAN)
|
|
||||||
#define WM_LITTLE_ENDIAN
|
#define WM_LITTLE_ENDIAN
|
||||||
#elif (__BYTE_ORDER == __BIG_ENDIAN)
|
#elif (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
|
||||||
#define WM_BIG_ENDIAN
|
#define WM_BIG_ENDIAN
|
||||||
#else
|
#else
|
||||||
#error "__BYTE_ORDER defined, but not __LITTLE_ENDIAN or __BIG_ENDIAN."
|
#error "__BYTE_ORDER__ is not BIG or LITTLE endian"
|
||||||
#endif
|
|
||||||
#elif defined(__LITTLE_ENDIAN) \
|
|
||||||
|| defined(_LITTLE_ENDIAN) \
|
|
||||||
|| defined(LITTLE_ENDIAN)
|
|
||||||
#define WM_LITTLE_ENDIAN
|
|
||||||
#elif defined(__BIG_ENDIAN) \
|
|
||||||
|| defined(_BIG_ENDIAN) \
|
|
||||||
|| defined(BIG_ENDIAN)
|
|
||||||
#define WM_BIG_ENDIAN
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Special handling for OS-X
|
|
||||||
#ifdef __DARWIN_BYTE_ORDER
|
|
||||||
#if (__DARWIN_BYTE_ORDER == __DARWIN_BIG_ENDIAN)
|
|
||||||
#define WM_BIG_ENDIAN
|
|
||||||
#undef WM_LITTLE_ENDIAN
|
|
||||||
#elif (__DARWIN_BYTE_ORDER == __DARWIN_LITTLE_ENDIAN)
|
|
||||||
#define WM_LITTLE_ENDIAN
|
|
||||||
#undef WM_BIG_ENDIAN
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Could also downgrade to a warning, but then user always needs runtime check.
|
// Could downgrade to a warning, but then user always needs runtime check.
|
||||||
#if !defined(WM_BIG_ENDIAN) && !defined(WM_LITTLE_ENDIAN)
|
#if !defined(WM_BIG_ENDIAN) && !defined(WM_LITTLE_ENDIAN)
|
||||||
#error "Cannot determine BIG or LITTLE endian."
|
#error "Cannot determine BIG or LITTLE endian."
|
||||||
#error "Please add to compilation options"
|
#error "Please add to compilation options"
|
||||||
@ -95,17 +68,9 @@ namespace Foam
|
|||||||
|
|
||||||
class endian
|
class endian
|
||||||
{
|
{
|
||||||
// Private Member Functions
|
|
||||||
|
|
||||||
//- No copy construct
|
|
||||||
endian(const endian&) = delete;
|
|
||||||
|
|
||||||
//- No copy assignment
|
|
||||||
void operator=(const endian&) = delete;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Public data
|
// Public Methods
|
||||||
|
|
||||||
//- Runtime check for big endian.
|
//- Runtime check for big endian.
|
||||||
inline static bool isBig();
|
inline static bool isBig();
|
||||||
|
|||||||
@ -23,13 +23,12 @@ License
|
|||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "endian.H"
|
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
#define USE_BUILTIN_BYTESWAP
|
#define USE_BUILTIN_BYTESWAP
|
||||||
#else
|
#else
|
||||||
#undef USE_BUILTIN_BYTESWAP
|
#undef USE_BUILTIN_BYTESWAP
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// for Debugging:
|
// for Debugging:
|
||||||
// #undef USE_BUILTIN_BYTESWAP
|
// #undef USE_BUILTIN_BYTESWAP
|
||||||
|
|
||||||
@ -70,7 +69,7 @@ inline uint32_t Foam::endian::swap32(uint32_t u)
|
|||||||
| (((u) & 0x000000ff) << 24) // 3 <- 0
|
| (((u) & 0x000000ff) << 24) // 3 <- 0
|
||||||
);
|
);
|
||||||
|
|
||||||
// alternative formulation
|
// Alternative formulation
|
||||||
//
|
//
|
||||||
// u = ((u<<8) & 0xFF00FF00) | ((u>>8) & 0x00FF00FF);
|
// u = ((u<<8) & 0xFF00FF00) | ((u>>8) & 0x00FF00FF);
|
||||||
// u = (u>>16) | (u<<16);
|
// u = (u>>16) | (u<<16);
|
||||||
@ -96,7 +95,7 @@ inline uint64_t Foam::endian::swap64(uint64_t u)
|
|||||||
| (((u) & 0x00000000000000ffull) << 56) // 7 <- 0
|
| (((u) & 0x00000000000000ffull) << 56) // 7 <- 0
|
||||||
);
|
);
|
||||||
|
|
||||||
// alternative formulation
|
// Alternative formulation
|
||||||
/*
|
/*
|
||||||
u = ((u<< 8) & 0xFF00FF00FF00FF00ull) | ((u>> 8) & 0x00FF00FF00FF00FFull);
|
u = ((u<< 8) & 0xFF00FF00FF00FF00ull) | ((u>> 8) & 0x00FF00FF00FF00FFull);
|
||||||
u = ((u<<16) & 0xFFFF0000FFFF0000ull) | ((u>>16) & 0x0000FFFF0000FFFFull);
|
u = ((u<<16) & 0xFFFF0000FFFF0000ull) | ((u>>16) & 0x0000FFFF0000FFFFull);
|
||||||
|
|||||||
Reference in New Issue
Block a user