Go to the documentation of this file.
74#define DGL_LITTLE_ENDIAN 1
75#define DGL_BIG_ENDIAN 2
86#define MACHINE_WORD_FORMAT DGL_LITTLE_ENDIAN
87#define MACHINE_FLOAT_FORMAT DGL_NON_IEEE
96#if defined(__linux__) && (__i386__ || __ia64__ || __x86_64__ || __arm__ || __arm64__ || __aarch64__)
98#define MACHINE_WORD_FORMAT DGL_LITTLE_ENDIAN
99#define MACHINE_FLOAT_FORMAT DGL_NON_IEEE
108#if defined(__APPLE__)
109#if defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__arm64__) || defined(__aarch64__)
111#define MACHINE_WORD_FORMAT DGL_LITTLE_ENDIAN
112#define MACHINE_FLOAT_FORMAT DGL_NON_IEEE
116#define MACHINE_WORD_FORMAT DGL_BIG_ENDIAN
117#define MACHINE_FLOAT_FORMAT DGL_BIG_IEEE
126#define M_SIZEOF(x) sizeof(x)
135#if MACHINE_WORD_FORMAT == DGL_BIG_ENDIAN
136#define DGL_HTON_SHORT(t,f) t = f
137#define DGL_NTOH_SHORT DGL_HTON_SHORT
138#define DGL_HTON_INT32(t,f) t = f
139#define DGL_NTOH_INT32 DGL_HTON_INT32
146#if MACHINE_FLOAT_FORMAT == DGL_BIG_IEEE
147#define DGL_HTON_FLOAT(t,f) t = f
148#define DGL_NTOH_FLOAT DGL_HTON_FLOAT
149#define DGL_HTON_DOUBLE(t,f) t = f
150#define DGL_NTOH_DOUBLE DGL_HTON_DOUBLE
159#if MACHINE_WORD_FORMAT == DGL_LITTLE_ENDIAN
162#define DGL_HTON_SHORT(t,f) \
164 short _from = f,_to; \
165 ((char *)&_to)[0] = ((char *)&_from)[1]; \
166 ((char *)&_to)[1] = ((char *)&_from)[0]; \
169#define DGL_NTOH_SHORT DGL_HTON_SHORT
170#define DGL_HTON_INT32(t,f) \
172 int32_t _from = f,_to; \
173 ((char *)&_to)[0] = ((char *)&_from)[3]; \
174 ((char *)&_to)[1] = ((char *)&_from)[2]; \
175 ((char *)&_to)[2] = ((char *)&_from)[1]; \
176 ((char *)&_to)[3] = ((char *)&_from)[0]; \
179#define DGL_NTOH_INT32 DGL_HTON_INT32
189#if MACHINE_FLOAT_FORMAT == DGL_NON_IEEE
190#if __i386__ || __x86_64__ || _M_X64 || __ia64__ || __arm__ || __arm64__ || __aarch64__
191void mem_hton_float(
float *t,
float *f);
192void mem_ntoh_float(
float *t,
float *f);
193void mem_hton_double(
double *t,
double *f);
194void mem_ntoh_double(
double *t,
double *f);
196#define DGL_HTON_FLOAT(t,f) mem_hton_float(&t,&f)
197#define DGL_NTOH_FLOAT(t,f) mem_ntoh_float(&t,&f)
198#define DGL_HTON_DOUBLE(t,f) mem_hton_double(&t,&f)
199#define DGL_NTOH_DOUBLE(t,f) mem_ntoh_double(&t,&f)
207#define INT32(p) (*(int32_t *)(p))
208#define FLOAT(p) (*(float *)(p))
209#define DOUBLE(p) (*(double *)(p))
210#define SHORT(p) (*(short *)(p))