Skip to content

Commit

Permalink
Move compiler-specific cruft into compiler.h.
Browse files Browse the repository at this point in the history
  • Loading branch information
foo86 committed May 6, 2015
1 parent 4c3191d commit e54330e
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 36 deletions.
48 changes: 16 additions & 32 deletions libdcadec/common.h
Expand Up @@ -28,20 +28,9 @@
#include <errno.h>
#include <assert.h>

#ifdef _MSC_VER
#define inline __inline
#define restrict __restrict

#define fseeko _fseeki64
#define ftello _ftelli64
#define STDIN_FILENO 0
#define STDOUT_FILENO 1

typedef __int64 off_t;
#endif

#define AT_LEAST_GCC(major, minor) \
(defined __GNUC__) && ((__GNUC__ > (major)) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)))
#include "compiler.h"
#include "dca_context.h"
#include "ta.h"

#if AT_LEAST_GCC(3, 4)
#define dca_clz32(x) __builtin_clz(x)
Expand Down Expand Up @@ -123,20 +112,7 @@ static inline uint64_t dca_bswap64(uint64_t x)
#define DCA_BSWAP32_C(x) ((DCA_BSWAP16_C(x) << 16) | (DCA_BSWAP16_C(x >> 16)))
#define DCA_BSWAP64_C(x) ((DCA_BSWAP32_C(x) << 32) | (DCA_BSWAP32_C(x >> 32)))

#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define DCA_16LE(x) ((uint16_t)(x))
#define DCA_32LE(x) ((uint32_t)(x))
#define DCA_64LE(x) ((uint64_t)(x))
#define DCA_16BE(x) dca_bswap16(x)
#define DCA_32BE(x) dca_bswap32(x)
#define DCA_64BE(x) dca_bswap64(x)
#define DCA_16LE_C(x) (x)
#define DCA_32LE_C(x) (x)
#define DCA_64LE_C(x) (x)
#define DCA_16BE_C(x) DCA_BSWAP16_C(x)
#define DCA_32BE_C(x) DCA_BSWAP32_C(x)
#define DCA_64BE_C(x) DCA_BSWAP64_C(x)
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
#if HAVE_BIGENDIAN
#define DCA_16LE(x) dca_bswap16(x)
#define DCA_32LE(x) dca_bswap32(x)
#define DCA_64LE(x) dca_bswap64(x)
Expand All @@ -150,7 +126,18 @@ static inline uint64_t dca_bswap64(uint64_t x)
#define DCA_32BE_C(x) (x)
#define DCA_64BE_C(x) (x)
#else
#error Unsupported byte order
#define DCA_16LE(x) ((uint16_t)(x))
#define DCA_32LE(x) ((uint32_t)(x))
#define DCA_64LE(x) ((uint64_t)(x))
#define DCA_16BE(x) dca_bswap16(x)
#define DCA_32BE(x) dca_bswap32(x)
#define DCA_64BE(x) dca_bswap64(x)
#define DCA_16LE_C(x) (x)
#define DCA_32LE_C(x) (x)
#define DCA_64LE_C(x) (x)
#define DCA_16BE_C(x) DCA_BSWAP16_C(x)
#define DCA_32BE_C(x) DCA_BSWAP32_C(x)
#define DCA_64BE_C(x) DCA_BSWAP64_C(x)
#endif

#define DCA_MIN(a, b) ((a) < (b) ? (a) : (b))
Expand Down Expand Up @@ -201,9 +188,6 @@ static inline uint32_t DCA_MEM32NE(const void *data)
} \
} while (false)

#include "dca_context.h"
#include "ta.h"

#define DCADEC_FLAG_KEEP_DMIX_MASK \
(DCADEC_FLAG_KEEP_DMIX_2CH | DCADEC_FLAG_KEEP_DMIX_6CH)

Expand Down
53 changes: 53 additions & 0 deletions libdcadec/compiler.h
@@ -0,0 +1,53 @@
/*
* This file is part of libdcadec.
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef COMPILER_H
#define COMPILER_H

#ifdef _MSC_VER
#define inline __inline
#define restrict __restrict

#define fseeko _fseeki64
#define ftello _ftelli64
#define STDIN_FILENO 0
#define STDOUT_FILENO 1

typedef __int64 off_t;
#endif

#define AT_LEAST_GCC(major, minor) \
(defined __GNUC__) && ((__GNUC__ > (major)) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)))

#ifndef HAVE_BIGENDIAN
# if (defined __GNUC__)
# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
# define HAVE_BIGENDIAN 0
# elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
# define HAVE_BIGENDIAN 1
# else
# error Unsupported byte order
# endif
# elif (defined _MSC_VER)
# define HAVE_BIGENDIAN 0
# else
# error Unsupported compiler. Define HAVE_BIGENDIAN macro to specify endianness.
# endif
#endif

#endif
5 changes: 1 addition & 4 deletions libdcadec/ta.c
Expand Up @@ -16,10 +16,7 @@
#include <stdio.h>
#include <assert.h>

#ifdef _MSC_VER
#define inline __inline
#endif

#include "compiler.h"
#include "ta.h"

// Note: the actual minimum alignment is dictated by malloc(). It doesn't
Expand Down

0 comments on commit e54330e

Please sign in to comment.