Skip to content

Commit

Permalink
Merge branch 'feature/msvc-compat' into feature/cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
BurningEnlightenment committed Jul 2, 2016
2 parents 796a5a8 + d405e70 commit b361414
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 9 deletions.
1 change: 1 addition & 0 deletions lib/codec_avx2.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <stdint.h>
#include <stddef.h>
#include <stdlib.h>

#include "../include/libbase64.h"
#include "codecs.h"
Expand Down
1 change: 1 addition & 0 deletions lib/codec_neon32.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <stdint.h>
#include <stddef.h>
#include <stdlib.h>
#ifdef __ARM_NEON__
#include <arm_neon.h>
#endif
Expand Down
1 change: 1 addition & 0 deletions lib/codec_neon64.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <stdint.h>
#include <stddef.h>
#include <stdlib.h>
#ifdef __ARM_NEON__
#include <arm_neon.h>
#endif
Expand Down
9 changes: 5 additions & 4 deletions lib/codec_plain.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#include <stdint.h>
#include <stddef.h>
#include <stdlib.h>

#include "../include/libbase64.h"
#include "codecs.h"

BASE64_ENC_FUNCTION(plain)
{
#include "enc/head.c"
#if __WORDSIZE == 32
#if BASE64_WORDSIZE == 32
#include "enc/uint32.c"
#elif __WORDSIZE == 64
#elif BASE64_WORDSIZE == 64
#include "enc/uint64.c"
#endif
#include "enc/tail.c"
Expand All @@ -18,9 +19,9 @@ BASE64_ENC_FUNCTION(plain)
BASE64_DEC_FUNCTION(plain)
{
#include "dec/head.c"
#if __WORDSIZE == 32
#if BASE64_WORDSIZE == 32
#include "dec/uint32.c"
#elif __WORDSIZE == 64
#elif BASE64_WORDSIZE == 64
#include "dec/uint64.c"
#endif
#include "dec/tail.c"
Expand Down
1 change: 1 addition & 0 deletions lib/codec_ssse3.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <stdint.h>
#include <stddef.h>
#include <stdlib.h>

#include "../include/libbase64.h"
#include "codecs.h"
Expand Down
24 changes: 19 additions & 5 deletions lib/codecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,31 +58,45 @@ struct codec

// Define machine endianness. This is for GCC:
#if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
#define LITTLE_ENDIAN 1
#define BASE64_LITTLE_ENDIAN 1
#else
#define LITTLE_ENDIAN 0
#define BASE64_LITTLE_ENDIAN 0
#endif

// This is for Clang:
#ifdef __LITTLE_ENDIAN__
#define LITTLE_ENDIAN 1
#define BASE64_LITTLE_ENDIAN 1
#endif

#ifdef __BIG_ENDIAN__
#define LITTLE_ENDIAN 0
#define BASE64_LITTLE_ENDIAN 0
#endif

// Endian conversion functions
#if LITTLE_ENDIAN
#if BASE64_LITTLE_ENDIAN
#ifdef _MSC_VER
#define cpu_to_be32(x) _byteswap_ulong(x)
#define cpu_to_be64(x) _byteswap_uint64(x)
#define be32_to_cpu(x) _byteswap_ulong(x)
#define be64_to_cpu(x) _byteswap_uint64(x)
#else
#define cpu_to_be32(x) __builtin_bswap32(x)
#define cpu_to_be64(x) __builtin_bswap64(x)
#define be32_to_cpu(x) __builtin_bswap32(x)
#define be64_to_cpu(x) __builtin_bswap64(x)
#endif
#else
#define cpu_to_be32(x) (x)
#define cpu_to_be64(x) (x)
#define be32_to_cpu(x) (x)
#define be64_to_cpu(x) (x)
#endif

// detect word size
#ifdef _INTEGRAL_MAX_BITS
#define BASE64_WORDSIZE _INTEGRAL_MAX_BITS
#else
#define BASE64_WORDSIZE __WORDSIZE
#endif

void codec_choose (struct codec *, int flags);
Expand Down

0 comments on commit b361414

Please sign in to comment.