Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix minor issue during porting(https://github.com/apache/incubator-nuttx) #99

Merged
merged 6 commits into from
Jun 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ CMakeCache.txt
CMakeFiles
CMakeScripts
Makefile
Make.dep
cmake_install.cmake
install_manifest.txt
CTestTestfile.cmake
.DS_Store
.built
.depend
.pio
.vscode/*
!.vscode/extensions.json
Expand Down
1 change: 1 addition & 0 deletions test/DivideTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ using set_t = std::set<IntT>;

using namespace libdivide;

#undef UNUSED
#define UNUSED(x) (void)(x)

#if defined(LIBDIVIDE_SSE2) || defined(LIBDIVIDE_AVX2) || defined(LIBDIVIDE_AVX512) || \
Expand Down
2 changes: 1 addition & 1 deletion test/benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include <string.h>

int main(int argc, char *argv[]) {
extern "C" int main(int argc, char *argv[]) {
// Disable printf buffering.
// This is mainly required for Windows.
setbuf(stdout, NULL);
Expand Down
1 change: 1 addition & 0 deletions test/benchmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <type_traits>
#endif

#undef UNUSED
#define UNUSED(x) (void)(x)

#if defined(_WIN32) || defined(WIN32)
Expand Down
2 changes: 1 addition & 1 deletion test/benchmark_branchfree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ void usage() {
<< std::endl;
}

int main(int argc, const char* argv[]) {
extern "C" int main(int argc, const char* argv[]) {
tasks_t tasks = 0;

for (int i = 1; i < argc; i++) {
Expand Down
2 changes: 1 addition & 1 deletion test/fast_div_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void print_disclaimer()
<< "// See " << __FILE__ << "\n";
}

int main(int argc, char *argv[]) {
extern "C" int main(int argc, char *argv[]) {
if (argc!=3) {
std::cout
<< "Usage: fast_div_generator [DATATYPE] [STYLE]\n"
Expand Down
22 changes: 11 additions & 11 deletions test/outputs.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// AVR doesn't support (s)printf() of 64-bit numbers.
// PRId64 is undefined & GCC will issue a warning
// So manually convert
char *to_str(char *buffer, uint64_t n) {
static inline char *to_str(char *buffer, uint64_t n) {
buffer += 20;
*buffer-- = 0;
while (n) {
Expand All @@ -21,7 +21,7 @@ char *to_str(char *buffer, uint64_t n) {
}
return buffer + 1;
}
char *to_str(char *buffer, int64_t n) {
static inline char *to_str(char *buffer, int64_t n) {
if (n<0){
buffer = to_str(buffer+1, (uint64_t)(n*-1))-1;
*buffer = '-';
Expand All @@ -31,15 +31,15 @@ char *to_str(char *buffer, int64_t n) {
}

template <typename _T>
void print_serial(const _T &item) { Serial.print(item); }
static inline void print_serial(const _T &item) { Serial.print(item); }
template <>
void print_serial(const uint64_t &item)
static inline void print_serial(const uint64_t &item)
{
char buffer[32];
Serial.print(to_str(buffer, item));
}
template <>
void print_serial(const int64_t &item)
static inline void print_serial(const int64_t &item)
{
char buffer[32];
Serial.print(to_str(buffer, item));
Expand All @@ -50,11 +50,11 @@ void print_serial(const int64_t &item)

#else

char *to_str(char *buffer, uint64_t n) {
static inline char *to_str(char *buffer, uint64_t n) {
sprintf(buffer, "%" PRIu64, n);
return buffer;
}
char *to_str(char *buffer, int64_t n) {
static inline char *to_str(char *buffer, int64_t n) {
sprintf(buffer, "%" PRId64, n);
return buffer;
}
Expand All @@ -73,20 +73,20 @@ char *to_str(char *buffer, int64_t n) {
#define PRINT_PROGRESS_MSG(item)
#endif

char *to_str(char *buffer, uint32_t n) {
static inline char *to_str(char *buffer, uint32_t n) {
sprintf(buffer, "%" PRIu32, n);
return buffer;
}
char *to_str(char *buffer, int32_t n) {
static inline char *to_str(char *buffer, int32_t n) {
sprintf(buffer, "%" PRId32, n);
return buffer;
}

char *to_str(char *buffer, uint16_t n) {
static inline char *to_str(char *buffer, uint16_t n) {
sprintf(buffer, "%" PRIu16, n);
return buffer;
}
char *to_str(char *buffer, int16_t n) {
static inline char *to_str(char *buffer, int16_t n) {
sprintf(buffer, "%" PRId16, n);
return buffer;
}
15 changes: 9 additions & 6 deletions test/test_c99.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#pragma warning(disable : 4146)
#endif

#undef UNUSED
#define UNUSED(x) (void)(x)
#define MIN_RANGE (UINT16_MAX/4U)
#define LOOP_STEP 3
Expand Down Expand Up @@ -48,7 +49,7 @@
} \
}

void test_u16() {
void test_u16(void) {
#define U16_DENOM 953 // Prime
struct libdivide_u16_t divider = libdivide_u16_gen(U16_DENOM);
#define OP_U16_DO(numer, divider) libdivide_u16_do(numer, &divider)
Expand All @@ -59,7 +60,7 @@ void test_u16() {
TEST_BODY(uint16_t, UINT16_MAX, U16_DENOM, U16_DENOM, PRIu16, CONSTANT_OP_U16)
}

void test_s16() {
void test_s16(void) {
int16_t denom = (int16_t)-4003; // Prime
struct libdivide_s16_t divider = libdivide_s16_gen(denom);
#define OP_S16(numer, divider) libdivide_s16_do(numer, &divider)
Expand All @@ -74,28 +75,28 @@ void test_s16() {
TEST_BODY(int16_t, INT16_MAX, -4003, 4003, PRId16, CONSTANT_OP_NEG_S16)
}

void test_u32() {
void test_u32(void) {
uint32_t denom = ((uint32_t)2 << 21) - 19; // Prime - see https://primes.utm.edu/lists/2small/0bit.html
struct libdivide_u32_t divider = libdivide_u32_gen(denom);
#define OP_U32(numer, divider) libdivide_u32_do(numer, &divider)
TEST_BODY(uint32_t, UINT32_MAX, denom, divider, PRIu32, OP_U32)
}

void test_s32() {
void test_s32(void) {
int32_t denom = -(((int32_t)2 << 21) - 55); // Prime - see https://primes.utm.edu/lists/2small/0bit.html
struct libdivide_s32_t divider = libdivide_s32_gen(denom);
#define OP_S32(numer, divider) libdivide_s32_do(numer, &divider)
TEST_BODY(int32_t, INT32_MAX, denom, divider, PRId32, OP_S32)
}

void test_u64() {
void test_u64(void) {
uint64_t denom = ((uint64_t)2 << 29) - 43; // Prime - see https://primes.utm.edu/lists/2small/0bit.html
struct libdivide_u64_t divider = libdivide_u64_gen(denom);
#define OP_U64(numer, divider) libdivide_u64_do(numer, &divider)
TEST_BODY(uint64_t, (UINT64_MAX/2) /* For speed */, denom, divider, PRIu64, OP_U64)
}

void test_s64() {
void test_s64(void) {
int64_t denom = -(((int64_t)2 << 29) - 121); // Prime - see https://primes.utm.edu/lists/2small/0bit.html
struct libdivide_s64_t divider = libdivide_s64_gen(denom);
#define OP_S64(numer, divider) libdivide_s64_do(numer, &divider)
Expand All @@ -112,4 +113,6 @@ int main (int argc, char *argv[]) {
test_s32();
test_u64();
test_s64();

return 0;
}
2 changes: 1 addition & 1 deletion test/tester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void launch_test_thread(std::vector<std::thread> &test_threads) {
test_threads.emplace_back(run_test<_IntT>);
}

int main(int argc, char *argv[]) {
extern "C" int main(int argc, char *argv[]) {
bool default_do_test = (argc <= 1);
std::vector<bool> do_tests(6, default_do_test);

Expand Down
4 changes: 2 additions & 2 deletions test/type_mappings.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ template <typename _IntT> struct struct_selector {};
LIB_DIVIDE_GENERATOR(DECLARE_STRUCT_SELECTOR, NULL)

template <typename _IntT>
typename struct_selector<_IntT>::struct_t libdivide_gen(_IntT)
static inline typename struct_selector<_IntT>::struct_t libdivide_gen(_IntT)
{
}
#define LIBDIVDE_GEN(type, tag, ...) \
template <> \
typename struct_selector<type>::struct_t libdivide_gen(type d) \
inline typename struct_selector<type>::struct_t libdivide_gen(type d) \
{ \
return libdivide::libdivide_ ## tag ## _gen(d);\
}
Expand Down