1
0
mirror of https://github.com/paboyle/Grid.git synced 2024-09-20 01:05:38 +01:00

Fixing endian on linux I hope

This commit is contained in:
Peter Boyle 2015-04-23 07:51:15 +01:00
parent b32c14b433
commit 47292de769
2 changed files with 15 additions and 10 deletions

View File

@ -17,6 +17,7 @@ AC_PROG_RANLIB
AC_CHECK_HEADERS(stdint.h)
AC_CHECK_HEADERS(malloc/malloc.h)
AC_CHECK_HEADERS(malloc.h)
AC_CHECK_HEADERS(endian.h)
# Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_SIZE_T
@ -25,8 +26,6 @@ AC_TYPE_UINT64_T
# Checks for library functions.
AC_CHECK_FUNCS([gettimeofday])
AC_CHECK_FUNCS([ntohll])
AC_CHECK_FUNCS([be64toh])
AC_ARG_ENABLE([simd],[AC_HELP_STRING([--enable-simd=SSE|AVX|AVX2|AVX512],[Select instructions])],[ac_SIMD=${enable_simd}],[ac_SIMD=AVX2])

View File

@ -6,7 +6,13 @@
#include <iomanip>
#include <fstream>
#ifdef HAVE_ENDIAN_H
#include <endian.h>
#include <arpa/inet.h>
#define ntohll be64toh
#else
#include <arpa/inet.h>
#endif
namespace Grid {
@ -177,14 +183,14 @@ inline void reconstruct3(LorentzColourMatrix & cm)
}
void inline be32toh(void *file_object,uint32_t bytes)
void inline be32toh_v(void *file_object,uint32_t bytes)
{
uint32_t * f = (uint32_t *)file_object;
for(int i=0;i*sizeof(uint32_t)<bytes;i++){
f[i] = ntohl(f[i]);
}
}
void inline le32toh(void *file_object,uint32_t bytes)
void inline le32toh_v(void *file_object,uint32_t bytes)
{
uint32_t *fp = (uint32_t *)file_object;
@ -197,14 +203,14 @@ inline void reconstruct3(LorentzColourMatrix & cm)
fp[i] = ntohl(f);
}
}
void inline be64toh(void *file_object,uint32_t bytes)
void inline be64toh_v(void *file_object,uint32_t bytes)
{
uint64_t * f = (uint64_t *)file_object;
for(int i=0;i*sizeof(uint64_t)<bytes;i++){
f[i] = ntohll(f[i]);
}
}
void inline le64toh(void *file_object,uint32_t bytes)
void inline le64toh_v(void *file_object,uint32_t bytes)
{
uint64_t *fp = (uint64_t *)file_object;
uint64_t f,g;
@ -387,10 +393,10 @@ inline void readNerscObject(Lattice<vobj> &Umu,std::string file,munger munge,int
if ( grid->IsBoss() ) {
fin.read((char *)&file_object,sizeof(file_object));
if(ieee32big) be32toh((void *)&file_object,sizeof(file_object));
if(ieee32) le32toh((void *)&file_object,sizeof(file_object));
if(ieee64big) be64toh((void *)&file_object,sizeof(file_object));
if(ieee64) le64toh((void *)&file_object,sizeof(file_object));
if(ieee32big) be32toh_v((void *)&file_object,sizeof(file_object));
if(ieee32) le32toh_v((void *)&file_object,sizeof(file_object));
if(ieee64big) be64toh_v((void *)&file_object,sizeof(file_object));
if(ieee64) le64toh_v((void *)&file_object,sizeof(file_object));
munge(file_object,munged,csum);
}