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 + 9492a5b commit 0d952ae
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 13 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
8 changes: 4 additions & 4 deletions lib/lib_openmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ base64_encode_openmp
size_t t;
size_t sum = 0, len, last_len;
struct base64_state state, initial_state;
int num_threads;
int num_threads, i;

// Request a number of threads but not necessarily get them:
#pragma omp parallel
Expand All @@ -50,7 +50,7 @@ base64_encode_openmp
// Single has an implicit barrier for all threads to wait here
// for the above to complete:
#pragma omp for firstprivate(state) private(s) reduction(+:sum) schedule(static,1)
for (int i = 0; i < num_threads; i++)
for (i = 0; i < num_threads; i++)
{
// Feed each part of the string to the stream reader:
base64_stream_encode(&state, src + i * len, len, out + i * len * 4 / 3, &s);
Expand Down Expand Up @@ -82,7 +82,7 @@ base64_decode_openmp
, int flags
)
{
int num_threads, result = 0;
int num_threads, result = 0, i;
size_t sum = 0, len, last_len, s;
struct base64_state state, initial_state;

Expand Down Expand Up @@ -111,7 +111,7 @@ base64_decode_openmp
// Single has an implicit barrier to wait here for the above to
// complete:
#pragma omp for firstprivate(state) private(s) reduction(+:sum, result) schedule(static,1)
for (int i = 0; i < num_threads; i++)
for (i = 0; i < num_threads; i++)
{
int this_result;

Expand Down

0 comments on commit 0d952ae

Please sign in to comment.