Bitarray copy algorithm was moved to C++ source file, thus C compiler is no longer required

This commit is contained in:
Pavel Kirienko 2014-03-10 19:33:06 +04:00
parent b86ea67563
commit 633fa9d8bd
3 changed files with 11 additions and 12 deletions

View File

@ -15,19 +15,13 @@ set(CMAKE_CXX_FLAGS_RELEASE "-O1 -DNDEBUG")
set(CMAKE_CXX_FLAGS_DEBUG "-g3 -DUAVCAN_DEBUG=1 -DDEBUG=1")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++03 -Wall -Wextra -Werror -pedantic -Wno-variadic-macros")
set(CMAKE_C_FLAGS_RELWITHDEBINFO ${CMAKE_CXX_FLAGS_RELWITHDEBINFO})
set(CMAKE_C_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
set(CMAKE_C_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -Wall -Wextra -Werror -pedantic")
include_directories(include)
#
# libuavcan
#
file(GLOB_RECURSE LIBUAVCAN_CXX_FILES RELATIVE ${CMAKE_SOURCE_DIR} "src/*.cpp")
file(GLOB_RECURSE LIBUAVCAN_C_FILES RELATIVE ${CMAKE_SOURCE_DIR} "src/*.c")
add_library(uavcan SHARED ${LIBUAVCAN_CXX_FILES} ${LIBUAVCAN_C_FILES})
add_library(uavcan SHARED ${LIBUAVCAN_CXX_FILES})
# TODO installation rules

View File

@ -13,8 +13,7 @@
namespace uavcan
{
extern "C" void bitarray_copy(const unsigned char *src_org, int src_offset, int src_len,
unsigned char *dst_org, int dst_offset);
void bitarray_copy(const unsigned char *src_org, int src_offset, int src_len, unsigned char *dst_org, int dst_offset);
class BitStream
{

View File

@ -3,9 +3,9 @@
* Source: http://stackoverflow.com/questions/3534535/whats-a-time-efficient-algorithm-to-copy-unaligned-bit-arrays
*/
#include <limits.h>
#include <string.h>
#include <stddef.h>
#include <climits>
#include <cstring>
#include <cstddef>
#define PREPARE_FIRST_COPY() \
do { \
@ -19,11 +19,15 @@
src_len = 0; \
} } while (0)
namespace uavcan
{
void
bitarray_copy(const unsigned char *src_org, int src_offset, int src_len,
unsigned char *dst_org, int dst_offset)
{
using namespace std;
static const unsigned char reverse_mask[] =
{ 0x55, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff };
static const unsigned char reverse_mask_xor[] =
@ -117,3 +121,5 @@ bitarray_copy(const unsigned char *src_org, int src_offset, int src_len,
}
}
}
}