2015-03-03 00:38:33 +08:00
|
|
|
/****************************************************************************
|
|
|
|
** GeomIO Library
|
|
|
|
** Copyright FougSys (2 Mar. 2015)
|
|
|
|
** contact@fougsys.fr
|
|
|
|
**
|
|
|
|
** This software is a reusable library whose purpose is to provide complete
|
|
|
|
** I/O support for various CAD file formats (eg. STL)
|
|
|
|
**
|
|
|
|
** This software is governed by the CeCILL-B license under French law and
|
|
|
|
** abiding by the rules of distribution of free software. You can use,
|
|
|
|
** modify and/ or redistribute the software under the terms of the CeCILL-B
|
|
|
|
** license as circulated by CEA, CNRS and INRIA at the following URL
|
2015-03-30 15:05:25 +08:00
|
|
|
** "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html".
|
2015-03-03 00:38:33 +08:00
|
|
|
****************************************************************************/
|
|
|
|
|
2015-03-03 18:35:15 +08:00
|
|
|
/* WARNING :
|
|
|
|
* this header has no multi-inclusion guard. It must be included only once
|
|
|
|
* in the translation unit of use. The reason is that all functions
|
|
|
|
* defined here are meant to be inlined for performance purpose
|
2014-01-29 02:06:24 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "../global.h"
|
|
|
|
|
2014-03-28 23:33:35 +08:00
|
|
|
#ifdef GMIO_HAVE_MSVC_BUILTIN_BSWAP_FUNC
|
2015-03-03 17:38:49 +08:00
|
|
|
# include <stdlib.h>
|
2014-01-29 02:06:24 +08:00
|
|
|
#endif
|
|
|
|
|
2015-03-03 18:35:15 +08:00
|
|
|
/*! Returns \p val with the order of bytes reversed, uses compiler builtin
|
|
|
|
* functions if available */
|
2014-03-28 23:33:35 +08:00
|
|
|
GMIO_INLINE static uint16_t gmio_uint16_bswap(uint16_t val)
|
2014-01-29 02:06:24 +08:00
|
|
|
{
|
2014-03-28 23:33:35 +08:00
|
|
|
#ifdef GMIO_HAVE_GCC_BUILTIN_BSWAP16_FUNC
|
2015-03-03 17:35:36 +08:00
|
|
|
return __builtin_bswap16(val);
|
2014-03-28 23:33:35 +08:00
|
|
|
#elif defined(GMIO_HAVE_MSVC_BUILTIN_BSWAP_FUNC)
|
2015-03-03 17:35:36 +08:00
|
|
|
return _byteswap_ushort(val);
|
2014-01-29 02:06:24 +08:00
|
|
|
#else
|
2015-03-03 17:35:36 +08:00
|
|
|
return ((val & 0x00FF) << 8) | ((val >> 8) & 0x00FF);
|
2014-01-29 02:06:24 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-03-03 18:35:15 +08:00
|
|
|
/*! Returns \p val with the order of bytes reversed, uses compiler builtin
|
|
|
|
* functions if available */
|
2014-03-28 23:33:35 +08:00
|
|
|
GMIO_INLINE static uint32_t gmio_uint32_bswap(uint32_t val)
|
2014-01-29 02:06:24 +08:00
|
|
|
{
|
2014-03-28 23:33:35 +08:00
|
|
|
#ifdef GMIO_HAVE_GCC_BUILTIN_BSWAP32_FUNC
|
2015-03-03 17:35:36 +08:00
|
|
|
return __builtin_bswap32(val);
|
2014-03-28 23:33:35 +08:00
|
|
|
#elif defined(GMIO_HAVE_MSVC_BUILTIN_BSWAP_FUNC)
|
2015-03-03 17:35:36 +08:00
|
|
|
return _byteswap_ulong(val);
|
2014-01-29 02:06:24 +08:00
|
|
|
#else
|
2015-03-03 17:35:36 +08:00
|
|
|
return
|
|
|
|
((val & 0x000000FF) << 24)
|
|
|
|
| ((val & 0x0000FF00) << 8)
|
|
|
|
| ((val >> 8) & 0x0000FF00)
|
|
|
|
| ((val >> 24) & 0x000000FF);
|
2014-01-29 02:06:24 +08:00
|
|
|
#endif
|
|
|
|
}
|