From b57b3251e21b44a656cbd9b525c3a639094e1ceb Mon Sep 17 00:00:00 2001 From: Pan7 Date: Wed, 26 May 2021 14:42:39 +0200 Subject: [PATCH 1/2] Check for missing header files --- configure.ac | 2 +- cpu-miner.c | 4 ++++ miner.h | 2 ++ util.c | 2 ++ 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 74b4c1039..8f4128e50 100644 --- a/configure.ac +++ b/configure.ac @@ -18,7 +18,7 @@ AC_PROG_RANLIB dnl Checks for header files AC_HEADER_STDC -AC_CHECK_HEADERS([sys/endian.h sys/param.h syslog.h]) +AC_CHECK_HEADERS([sys/endian.h sys/param.h syslog.h unistd.h sys/time.h]) # sys/sysctl.h requires sys/types.h on FreeBSD # sys/sysctl.h requires sys/param.h on OpenBSD AC_CHECK_HEADERS([sys/sysctl.h], [], [], diff --git a/cpu-miner.c b/cpu-miner.c index ef2fc7672..c5f9af4da 100644 --- a/cpu-miner.c +++ b/cpu-miner.c @@ -16,8 +16,12 @@ #include #include #include +#ifdef HAVE_UNISTD_H #include +#endif +#ifdef HAVE_SYS_TIME_H #include +#endif #include #ifdef WIN32 #include diff --git a/miner.h b/miner.h index ba9163ae2..0acf930bf 100644 --- a/miner.h +++ b/miner.h @@ -5,7 +5,9 @@ #include #include +#ifdef HAVE_SYS_TIME_H #include +#endif #include #include #include diff --git a/util.c b/util.c index 171031041..0dca27884 100644 --- a/util.c +++ b/util.c @@ -22,7 +22,9 @@ #include #include #include +#ifdef HAVE_UNISTD_H #include +#endif #include #include #include From 471b7f398fd7e533a5de0d7dafaffd1ea5608da6 Mon Sep 17 00:00:00 2001 From: Pan7 Date: Fri, 4 Jun 2021 02:10:22 +0200 Subject: [PATCH 2/2] Support for msvc 2019 with cmake --- CMakeLists.txt | 392 +++++++++++++++++++++++++++++++++++++++++++++++++ compat.h | 50 +++++++ scrypt.c | 62 ++++---- sha2.c | 26 ++-- util.c | 8 +- 5 files changed, 490 insertions(+), 48 deletions(-) create mode 100644 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 000000000..2657ee249 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,392 @@ +# The MIT License (MIT) +# +# Copyright (c) 2021 github.com/Pan7 +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# +cmake_minimum_required(VERSION 2.8.12) +if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) + message(FATAL_ERROR "Not building in source directory. Please create an extra build directory and run cmake there. I.e. commands: mkdir build;cd build;cmake ..") +endif() +get_property(IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) +if(NOT IS_MULTI_CONFIG AND NOT CMAKE_BUILD_TYPE) + message(WARNING "Single-configuration generators require CMAKE_BUILD_TYPE to be set. I.e. -DCMAKE_BUILD_TYPE=Release") +endif() + +set(PACKAGE_NAME "cpuminer") +set(PACKAGE_TARGET "minerd") +set(PACKAGE_STATIC_TARGET "${PACKAGE_TARGET}-static") +project(${PACKAGE_NAME}) + +#read PACKAGE_VERSION from configure.ac +if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/configure.ac") + file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/configure.ac" AC_INIT LIMIT_COUNT 1) + string(REGEX MATCH "\\[[0-9]+\\.[0-9]+\\.[0-9]+(-[A-Za-z0-9]+)?\\]" PACKAGE_VERSION_STR "${AC_INIT}") + string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+(-[A-Za-z0-9]+)?" PACKAGE_VERSION "${PACKAGE_VERSION_STR}") +endif() +set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") +message(STATUS "Package ${PACKAGE_STRING}") + +include(CheckCSourceCompiles) +include(CheckFunctionExists) +include(CheckIncludeFiles) +include(CheckLibraryExists) +include(CheckSymbolExists) + +option(USE_ASM "Use assembly routines" ON) +option(USE_AVX "Use AVX assembly" ON) +option(USE_AVX2 "Use AVX2 assembly" ON) +option(USE_XOP "Use XOP assembly" ON) + +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/cpuminer-config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/include/cpuminer-config.h) + +include_directories(${CMAKE_CURRENT_BINARY_DIR}/include) + +list(APPEND SRC_FILES +cpu-miner.c +scrypt.c +sha2.c +util.c +) +list(APPEND HEADER_FILES +compat.h +elist.h +miner.h +) +list(APPEND ARM_FILES +scrypt-arm.S +sha2-arm.S +) +list(APPEND PPC_FILES +scrypt-ppc.S +sha2-ppc.S +) +list(APPEND X86_FILES +scrypt-x86.S +sha2-x86.S +) +list(APPEND X64_FILES +scrypt-x64.S +sha2-x64.S +) + +CHECK_INCLUDE_FILES(alloca.h HAVE_ALLOCA_H) +CHECK_INCLUDE_FILES(getopt.h HAVE_GETOPT_H) +CHECK_INCLUDE_FILES(stdlib.h HAVE_STDLIB_H) +CHECK_INCLUDE_FILES(string.h HAVE_STRING_H) +CHECK_INCLUDE_FILES(strings.h HAVE_STRINGS_H) +CHECK_INCLUDE_FILES(syslog.h HAVE_SYSLOG_H) +CHECK_INCLUDE_FILES(sys/endian.h HAVE_SYS_ENDIAN_H) +CHECK_INCLUDE_FILES(sys/param.h HAVE_SYS_PARAM_H) +CHECK_INCLUDE_FILES(sys/time.h HAVE_SYS_TIME_H) +CHECK_INCLUDE_FILES(unistd.h HAVE_UNISTD_H) + +if(HAVE_ALLOCA_H) + list(APPEND EXTRA_DEFS "-DHAVE_ALLOCA_H") + CHECK_SYMBOL_EXISTS(alloca alloca.h HAVE_ALLOCA) +else() + CHECK_FUNCTION_EXISTS(alloca HAVE_ALLOCA) +endif() +if(HAVE_GETOPT_H) + list(APPEND EXTRA_DEFS "-DHAVE_GETOPT_H") + CHECK_SYMBOL_EXISTS(getopt_long getopt.h HAVE_GETOPT_LONG) +else() + CHECK_FUNCTION_EXISTS(getopt_long HAVE_GETOPT_LONG) +endif() +if(HAVE_GETOPT_LONG) + list(APPEND EXTRA_DEFS "-DHAVE_GETOPT_LONG") +endif() +if(HAVE_STRINGS_H) + list(APPEND EXTRA_DEFS "-DHAVE_STRINGS_H") + CHECK_SYMBOL_EXISTS(strncasecmp strings.h HAVE_STRNCASECMP) + CHECK_SYMBOL_EXISTS(strcasecmp strings.h HAVE_STRCASECMP) +else() + CHECK_FUNCTION_EXISTS(strncasecmp HAVE_STRNCASECMP) + CHECK_FUNCTION_EXISTS(strcasecmp HAVE_STRCASECMP) +endif() +if(HAVE_SYS_ENDIAN_H) + list(APPEND EXTRA_DEFS "-DHAVE_SYS_ENDIAN_H") + CHECK_SYMBOL_EXISTS(be32dec sys/endian.h HAVE_DECL_BE32DEC) + CHECK_SYMBOL_EXISTS(le32dec sys/endian.h HAVE_DECL_LE32DEC) + CHECK_SYMBOL_EXISTS(be32enc sys/endian.h HAVE_DECL_BE32ENC) + CHECK_SYMBOL_EXISTS(le32enc sys/endian.h HAVE_DECL_LE32ENC) +else() + CHECK_FUNCTION_EXISTS(be32dec HAVE_DECL_BE32DEC) + CHECK_FUNCTION_EXISTS(le32dec HAVE_DECL_LE32DEC) + CHECK_FUNCTION_EXISTS(be32enc HAVE_DECL_BE32ENC) + CHECK_FUNCTION_EXISTS(le32enc HAVE_DECL_LE32ENC) +endif(HAVE_SYS_ENDIAN_H) +if(HAVE_DECL_BE32DEC) + list(APPEND EXTRA_DEFS "-DHAVE_DECL_BE32DEC") +endif() +if(HAVE_DECL_LE32DEC) + list(APPEND EXTRA_DEFS "-DHAVE_DECL_LE32DEC") +endif() +if(HAVE_DECL_BE32ENC) + list(APPEND EXTRA_DEFS "-DHAVE_DECL_BE32ENC") +endif() +if(HAVE_DECL_LE32ENC) + list(APPEND EXTRA_DEFS "-DHAVE_DECL_LE32ENC") +endif() +if(HAVE_SYS_PARAM_H) + list(APPEND EXTRA_DEFS "-DHAVE_SYS_PARAM_H") + CHECK_INCLUDE_FILES("sys/types.h sys/param.h sys/sysctl.h" HAVE_SYS_SYSCTL_H) +else() + CHECK_INCLUDE_FILES("sys/types.h sys/sysctl.h" HAVE_SYS_SYSCTL_H) +endif() +if(HAVE_SYS_TIME_H) + list(APPEND EXTRA_DEFS "-DHAVE_SYS_TIME_H") + CHECK_SYMBOL_EXISTS(gettimeofday sys/time.h HAVE_GETTIMEOFDAY) +else() + CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY) +endif() +if(HAVE_GETTIMEOFDAY) + list(APPEND EXTRA_DEFS "-DHAVE_GETTIMEOFDAY") +endif() +if(HAVE_UNISTD_H) + list(APPEND EXTRA_DEFS "-DHAVE_UNISTD_H") + CHECK_SYMBOL_EXISTS(getopt unistd.h HAVE_GETOPT) +else() + CHECK_FUNCTION_EXISTS(getopt HAVE_GETOPT) +endif() + +#CHECK_C_SOURCE_COMPILES("int foo __attribute__((aligned(16))); int main() {return 0;}" HAVE_ATTRIBUTE_ALIGNED) +CHECK_C_SOURCE_COMPILES("int __attribute__((aligned(16))) foo; int main() {return 0;}" HAVE_ATTRIBUTE_ALIGNED) +CHECK_C_SOURCE_COMPILES("int __declspec(align(16)) foo; int main() {return 0;}" HAVE_DECLSPEC_ALIGN) +CHECK_C_SOURCE_COMPILES("inline void foo(void) { } int main() {return 0;}" HAVE_INLINE) +if(NOT HAVE_INLINE) + CHECK_C_SOURCE_COMPILES("__inline void foo(void) { } int main() {return 0;}" HAVE___INLINE) + if(HAVE___INLINE) + list(APPEND EXTRA_DEFS "-Dinline=__inline") + else() + CHECK_C_SOURCE_COMPILES("__inline__ void foo(void) { } int main() {return 0;}" HAVE___INLINE__) + if(HAVE___INLINE__) + list(APPEND EXTRA_DEFS "-Dinline=__inline__") + else() + message(FATAL_ERROR "No inline keyword found!") + endif() + endif(HAVE___INLINE) +endif(NOT HAVE_INLINE) + +#include(CheckCCompilerFlag) +#CHECK_C_COMPILER_FLAG(-std=c99 HAVE_STD_C99) +#if(HAVE_STD_C99) +# set(CMAKE_C_FLAGS "-std=c99 ${CMAKE_C_FLAGS}") +#endif() + +CHECK_C_SOURCE_COMPILES("int main() { +#ifdef __i386__ +return 0; +#else +macroisundefinederror +#endif +}" HAVE___I386__) + +CHECK_C_SOURCE_COMPILES("int main() { +#ifdef __x86_64__ +return 0; +#else +macroisundefinederror +#endif +}" HAVE___X86_64__) + +CHECK_C_SOURCE_COMPILES("int main() { +#if defined(__arm__) && defined(__APCS_32__) +return 0; +#else +macroisundefinederror +#endif +}" HAVE___ARM__APCS_32) + +CHECK_C_SOURCE_COMPILES("int main() { +#if (defined(__powerpc__) || defined(__ppc__) || defined(__PPC__)) +return 0; +#else +macroisundefinederror +#endif +}" HAVE_PPC) + +CHECK_C_SOURCE_COMPILES("int main() {asm(\"vmovdqa %ymm0, %ymm1\");return 0;}" HAVE_AVX) +CHECK_C_SOURCE_COMPILES("int main() {asm(\"vprotd \$7, %xmm0, %xmm1\");return 0;}" HAVE_XOP) +CHECK_C_SOURCE_COMPILES("int main() {asm(\"vpaddd %ymm0, %ymm1, %ymm2\");return 0;}" HAVE_AVX2) + +if(CMAKE_COMPILER_IS_GNUCC) + if(HAVE___X86_64__) + set(ASM_FILES ${X64_FILES}) + elseif(HAVE___I386__) + set(ASM_FILES ${X86_FILES}) + elseif(HAVE___ARM__APCS_32) + set(ASM_FILES ${ARM_FILES}) + elseif(HAVE_PPC) + set(ASM_FILES ${PPC_FILES}) + endif() + if(USE_ASM AND ASM_FILES) + enable_language(ASM) + list(APPEND EXTRA_DEFS "-DUSE_ASM") + if(HAVE___X86_64__) + if(HAVE_AVX AND USE_AVX) + list(APPEND EXTRA_DEFS "-DUSE_AVX") + endif() + if(HAVE_XOP AND USE_XOP) + list(APPEND EXTRA_DEFS "-DUSE_XOP") + endif() + if(HAVE_AVX2 AND USE_AVX2) + list(APPEND EXTRA_DEFS "-DUSE_AVX2") + endif() + endif() + set(ASM_SRC_FILES ${ASM_FILES}) + endif(USE_ASM AND ASM_FILES) + + list(APPEND EXTRA_CFLAGS "-O3") + list(APPEND EXTRA_CFLAGS "-fno-strict-aliasing") +endif(CMAKE_COMPILER_IS_GNUCC) + +if(WIN32) + list(APPEND EXTRA_DEFS "-DWIN32_LEAN_AND_MEAN") + #windows sockets library + CHECK_LIBRARY_EXISTS(ws2_32 getch "" HAVE_LIBWS2_32) + if(HAVE_LIBWS2_32) + list(APPEND EXTRA_LIBS "ws2_32") + endif() +endif() + +if(MSVC) + #basetsd.h is required for SSIZE_T to define ssize_t + CHECK_INCLUDE_FILES(basetsd.h HAVE_BASETSD_H) + CHECK_INCLUDE_FILES(malloc.h HAVE_MALLOC_H) + CHECK_INCLUDE_FILES(winsock2.h HAVE_WINSOCK2_H) + + if(HAVE_MALLOC_H) + CHECK_SYMBOL_EXISTS(_alloca malloc.h HAVE__ALLOCA) + endif() +# if(HAVE_WINSOCK2_H) +# list(APPEND EXTRA_LIBS "ws2_32") +# endif() + if(HAVE_STRING_H) + CHECK_SYMBOL_EXISTS(_strnicmp string.h HAVE__STRNICMP) + CHECK_SYMBOL_EXISTS(_stricmp string.h HAVE__STRICMP) + else() + CHECK_FUNCTION_EXISTS(_strnicmp HAVE__STRNICMP) + CHECK_FUNCTION_EXISTS(_stricmp HAVE__STRICMP) + endif() + if(NOT HAVE__STRNICMP) + message(WARNING "No case-insensitive size-limitted string compare function found! strncasecmp()") + endif() + if(NOT HAVE__STRICMP) + message(WARNING "No case-insensitive string compare function found! strcasecmp()") + endif() + + list(APPEND EXTRA_DEFS "-D_CRT_SECURE_NO_WARNINGS") + if(NOT HAVE_GETOPT AND NOT HAVE_GETOPT_LONG) + set(HAVE_GETOPT_LONG TRUE) + message(WARNING "Ignoring missing function getopt_long()! Manually add getopt.h") + endif() + + if(USE_ASM AND ASM_FILES) + enable_language(ASM_MASM) + list(APPEND EXTRA_DEFS "-DUSE_ASM") + set(ASM_SRC_FILES ${ASM_FILES}) + endif(USE_ASM AND ASM_FILES) +endif() + +if(NOT JANSSON_FORCE) + find_package(JANSSON) + if(NOT JANSSON_FOUND) + pkg_search_module(JANSSON QUIET jansson libjansson) + endif() +endif() +if(JANSSON_FOUND) + set(HAVE_JANSSON_H TRUE) + include_directories(${JANSSON_INCLUDE_DIRS}) + list(APPEND EXTRA_LIBS ${JANSSON_LIBRARIES}) +else(JANSSON_FOUND) + if(EXISTS "${CMAKE_SOURCE_DIR}/compat/jansson/CMakeLists.txt") + add_subdirectory("${CMAKE_SOURCE_DIR}/compat/jansson") + set(JANSSON_COMPAT TRUE) + include_directories("${CMAKE_BINARY_DIR}/compat/jansson/include") + list(APPEND EXTRA_LIBS jansson) + elseif(EXISTS "${CMAKE_SOURCE_DIR}/compat/jansson-2.9/CMakeLists.txt") + add_subdirectory("${CMAKE_SOURCE_DIR}/compat/jansson-2.9") + list(APPEND EXTRA_LIBS jansson) + include_directories("${CMAKE_BINARY_DIR}/compat/jansson-2.9/include") + else() + message(WARNING "jansson library not found!") + endif() + +endif(JANSSON_FOUND) + +if(NOT CURL_FORCE) + find_package(CURL 7.15.2) + if(NOT CURL_FOUND) + pkg_search_module(CURL QUIET curl>=7.15.2 libcurl>=7.15.2) + endif() +endif() +if(CURL_FOUND) + set(HAVE_CURL_CURL_H TRUE) + include_directories(${CURL_INCLUDE_DIRS}) + list(APPEND EXTRA_LIBS ${CURL_LIBRARIES}) +endif() + +set(CMAKE_THREAD_PREFER_PTHREAD TRUE) +find_package(Threads) +if(CMAKE_USE_PTHREADS_INIT) + set(HAVE_PTHREAD_H TRUE) + list(APPEND EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT}) +else() + pkg_search_module(PTHREAD QUIET pthread libpthread) + if(PTHREAD_FOUND) + set(HAVE_PTHREAD_H TRUE) + include_directories(${PTHREAD_INCLUDE_DIRS}) + list(APPEND EXTRA_LIBS ${PTHREAD_LIBRARIES}) + else() + CHECK_INCLUDE_FILES(pthread.h HAVE_PTHREAD_H) + if(MSVC AND NOT HAVE_PTHREAD_H) + pkg_search_module(PTHREAD QUIET pthreads-win32 pthreads4w) + if(PTHREAD_FOUND) + set(HAVE_PTHREAD_H TRUE) + include_directories(${PTHREAD_INCLUDE_DIRS}) + list(APPEND EXTRA_LIBS ${PTHREAD_LIBRARIES}) + endif() + endif() + endif(PTHREAD_FOUND) +endif(CMAKE_USE_PTHREADS_INIT) + +#grouping sources for the project +source_group("Source Files" FILES ${SRC_FILES} ${ASM_SRC_FILES}) +source_group("Header Files" FILES ${HEADER_FILES}) + +add_executable("${PACKAGE_TARGET}" ${SRC_FILES} ${HEADER_FILES} ${ASM_SRC_FILES}) +target_compile_definitions("${PACKAGE_TARGET}" PRIVATE ${EXTRA_DEFS}) +target_compile_options("${PACKAGE_TARGET}" PRIVATE ${EXTRA_CFLAGS}) +target_link_libraries("${PACKAGE_TARGET}" ${EXTRA_LIBS} ${EXTRA_LDFLAGS}) + +if(MSVC) + #set default MSVC project + set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT "${PACKAGE_TARGET}") + + list(APPEND EXTRA_STATIC_DEFS "-DCURL_STATICLIB") + #runtime library multi-threaded (/MT) + list(APPEND EXTRA_STATIC_CFLAGS "/MT") + + add_executable("${PACKAGE_STATIC_TARGET}" ${SRC_FILES} ${HEADER_FILES} ${ASM_SRC_FILES}) + target_compile_definitions("${PACKAGE_STATIC_TARGET}" PRIVATE ${EXTRA_DEFS} ${EXTRA_STATIC_DEFS}) + target_compile_options("${PACKAGE_STATIC_TARGET}" PRIVATE ${EXTRA_CFLAGS} ${EXTRA_STATIC_CFLAGS}) + target_link_libraries("${PACKAGE_STATIC_TARGET}" ${EXTRA_LIBS} ${EXTRA_LDFLAGS} ${EXTRA_STATIC_LDFLAGS}) + +endif(MSVC) \ No newline at end of file diff --git a/compat.h b/compat.h index 283fc9b61..a5c51f4b5 100644 --- a/compat.h +++ b/compat.h @@ -1,6 +1,16 @@ #ifndef __COMPAT_H__ #define __COMPAT_H__ +#ifndef ATTRALIGN +#if defined(__GNUC__) || defined(HAVE_ATTRIBUTE_ALIGNED) +#define ATTRALIGN(x) __attribute__((aligned(x))) +#elif defined(_MSC_VER) +#define ATTRALIGN(x) __declspec(align(x)) +#else +#define ATTRALIGN(x) +#endif /* __GNUC__ */ +#endif /* ATTRALIGN */ + #ifdef WIN32 #include @@ -18,4 +28,44 @@ static inline int setpriority(int which, int who, int prio) #endif /* WIN32 */ +#ifdef _MSC_VER + +#ifndef strcasecmp +#define strcasecmp _stricmp +#endif + +#ifndef strncasecmp +#define strncasecmp _strnicmp +#endif + +#include + +#ifndef HAVE_GETTIMEOFDAY +static inline int gettimeofday(struct timeval* tv, void* tz) +{ + tv->tv_sec = (long)time(NULL); + tv->tv_usec = 0; + + return (0); +} +#endif /* HAVE_GETTIMEOFDAY */ + +#ifdef HAVE_BASETSD_H +#ifndef SSIZE_T +#include +typedef SSIZE_T ssize_t; +#endif +#else +#ifndef HAVE_SSIZE_T +typedef long ssize_t; +#endif +#endif + +#ifndef HAVE_GETOPT_H +#define HAVE_GETOPT_LONG 1 +//#include "getopt.h" +#endif + +#endif /* _MSC_VER */ + #endif /* __COMPAT_H__ */ diff --git a/scrypt.c b/scrypt.c index b8dce87ab..a83d58fec 100644 --- a/scrypt.c +++ b/scrypt.c @@ -29,7 +29,7 @@ #include "cpuminer-config.h" #include "miner.h" - +#include "compat.h" #include #include #include @@ -158,7 +158,7 @@ static const uint32_t outerpad_4way[4 * 8] = { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000300, 0x00000300, 0x00000300, 0x00000300 }; -static const uint32_t finalblk_4way[4 * 16] __attribute__((aligned(16))) = { +static const uint32_t ATTRALIGN(16) finalblk_4way[4 * 16] = { 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, @@ -180,8 +180,8 @@ static const uint32_t finalblk_4way[4 * 16] __attribute__((aligned(16))) = { static inline void HMAC_SHA256_80_init_4way(const uint32_t *key, uint32_t *tstate, uint32_t *ostate) { - uint32_t ihash[4 * 8] __attribute__((aligned(16))); - uint32_t pad[4 * 16] __attribute__((aligned(16))); + uint32_t ATTRALIGN(16) ihash[4 * 8]; + uint32_t ATTRALIGN(16) pad[4 * 16]; int i; /* tstate is assumed to contain the midstate of key */ @@ -208,10 +208,10 @@ static inline void HMAC_SHA256_80_init_4way(const uint32_t *key, static inline void PBKDF2_SHA256_80_128_4way(const uint32_t *tstate, const uint32_t *ostate, const uint32_t *salt, uint32_t *output) { - uint32_t istate[4 * 8] __attribute__((aligned(16))); - uint32_t ostate2[4 * 8] __attribute__((aligned(16))); - uint32_t ibuf[4 * 16] __attribute__((aligned(16))); - uint32_t obuf[4 * 16] __attribute__((aligned(16))); + uint32_t ATTRALIGN(16) istate[4 * 8]; + uint32_t ATTRALIGN(16) ostate2[4 * 8]; + uint32_t ATTRALIGN(16) ibuf[4 * 16]; + uint32_t ATTRALIGN(16) obuf[4 * 16]; int i, j; memcpy(istate, tstate, 4 * 32); @@ -239,7 +239,7 @@ static inline void PBKDF2_SHA256_80_128_4way(const uint32_t *tstate, static inline void PBKDF2_SHA256_128_32_4way(uint32_t *tstate, uint32_t *ostate, const uint32_t *salt, uint32_t *output) { - uint32_t buf[4 * 16] __attribute__((aligned(16))); + uint32_t ATTRALIGN(16) buf[4 * 16]; int i; sha256_transform_4way(tstate, salt, 1); @@ -258,7 +258,7 @@ static inline void PBKDF2_SHA256_128_32_4way(uint32_t *tstate, #ifdef HAVE_SHA256_8WAY -static const uint32_t finalblk_8way[8 * 16] __attribute__((aligned(32))) = { +static const uint32_t ATTRALIGN(32) finalblk_8way[8 * 16] = { 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x00000001, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, @@ -280,8 +280,8 @@ static const uint32_t finalblk_8way[8 * 16] __attribute__((aligned(32))) = { static inline void HMAC_SHA256_80_init_8way(const uint32_t *key, uint32_t *tstate, uint32_t *ostate) { - uint32_t ihash[8 * 8] __attribute__((aligned(32))); - uint32_t pad[8 * 16] __attribute__((aligned(32))); + uint32_t ATTRALIGN(32) ihash[8 * 8]; + uint32_t ATTRALIGN(32) pad[8 * 16]; int i; /* tstate is assumed to contain the midstate of key */ @@ -312,10 +312,10 @@ static inline void HMAC_SHA256_80_init_8way(const uint32_t *key, static inline void PBKDF2_SHA256_80_128_8way(const uint32_t *tstate, const uint32_t *ostate, const uint32_t *salt, uint32_t *output) { - uint32_t istate[8 * 8] __attribute__((aligned(32))); - uint32_t ostate2[8 * 8] __attribute__((aligned(32))); - uint32_t ibuf[8 * 16] __attribute__((aligned(32))); - uint32_t obuf[8 * 16] __attribute__((aligned(32))); + uint32_t ATTRALIGN(32) istate[8 * 8]; + uint32_t ATTRALIGN(32) ostate2[8 * 8]; + uint32_t ATTRALIGN(32) ibuf[8 * 16]; + uint32_t ATTRALIGN(32) obuf[8 * 16]; int i, j; memcpy(istate, tstate, 8 * 32); @@ -356,7 +356,7 @@ static inline void PBKDF2_SHA256_80_128_8way(const uint32_t *tstate, static inline void PBKDF2_SHA256_128_32_8way(uint32_t *tstate, uint32_t *ostate, const uint32_t *salt, uint32_t *output) { - uint32_t buf[8 * 16] __attribute__((aligned(32))); + uint32_t ATTRALIGN(32) buf[8 * 16]; int i; sha256_transform_8way(tstate, salt, 1); @@ -519,7 +519,7 @@ static void scrypt_1024_1_1_256(const uint32_t *input, uint32_t *output, uint32_t *midstate, unsigned char *scratchpad, int N) { uint32_t tstate[8], ostate[8]; - uint32_t X[32] __attribute__((aligned(128))); + uint32_t ATTRALIGN(128) X[32]; uint32_t *V; V = (uint32_t *)(((uintptr_t)(scratchpad) + 63) & ~ (uintptr_t)(63)); @@ -537,10 +537,10 @@ static void scrypt_1024_1_1_256(const uint32_t *input, uint32_t *output, static void scrypt_1024_1_1_256_4way(const uint32_t *input, uint32_t *output, uint32_t *midstate, unsigned char *scratchpad, int N) { - uint32_t tstate[4 * 8] __attribute__((aligned(128))); - uint32_t ostate[4 * 8] __attribute__((aligned(128))); - uint32_t W[4 * 32] __attribute__((aligned(128))); - uint32_t X[4 * 32] __attribute__((aligned(128))); + uint32_t ATTRALIGN(128) tstate[4 * 8]; + uint32_t ATTRALIGN(128) ostate[4 * 8]; + uint32_t ATTRALIGN(128) W[4 * 32]; + uint32_t ATTRALIGN(128) X[4 * 32]; uint32_t *V; int i, k; @@ -577,7 +577,7 @@ static void scrypt_1024_1_1_256_3way(const uint32_t *input, uint32_t *output, uint32_t *midstate, unsigned char *scratchpad, int N) { uint32_t tstate[3 * 8], ostate[3 * 8]; - uint32_t X[3 * 32] __attribute__((aligned(64))); + uint32_t ATTRALIGN(64) X[3 * 32]; uint32_t *V; V = (uint32_t *)(((uintptr_t)(scratchpad) + 63) & ~ (uintptr_t)(63)); @@ -603,10 +603,10 @@ static void scrypt_1024_1_1_256_3way(const uint32_t *input, static void scrypt_1024_1_1_256_12way(const uint32_t *input, uint32_t *output, uint32_t *midstate, unsigned char *scratchpad, int N) { - uint32_t tstate[12 * 8] __attribute__((aligned(128))); - uint32_t ostate[12 * 8] __attribute__((aligned(128))); - uint32_t W[12 * 32] __attribute__((aligned(128))); - uint32_t X[12 * 32] __attribute__((aligned(128))); + uint32_t ATTRALIGN(128) tstate[12 * 8]; + uint32_t ATTRALIGN(128) ostate[12 * 8]; + uint32_t ATTRALIGN(128) W[12 * 32]; + uint32_t ATTRALIGN(128) X[12 * 32]; uint32_t *V; int i, j, k; @@ -654,10 +654,10 @@ static void scrypt_1024_1_1_256_12way(const uint32_t *input, static void scrypt_1024_1_1_256_24way(const uint32_t *input, uint32_t *output, uint32_t *midstate, unsigned char *scratchpad, int N) { - uint32_t tstate[24 * 8] __attribute__((aligned(128))); - uint32_t ostate[24 * 8] __attribute__((aligned(128))); - uint32_t W[24 * 32] __attribute__((aligned(128))); - uint32_t X[24 * 32] __attribute__((aligned(128))); + uint32_t ATTRALIGN(128) tstate[24 * 8]; + uint32_t ATTRALIGN(128) ostate[24 * 8]; + uint32_t ATTRALIGN(128) W[24 * 32]; + uint32_t ATTRALIGN(128) X[24 * 32]; uint32_t *V; int i, j, k; diff --git a/sha2.c b/sha2.c index 9447abb45..f5565f192 100644 --- a/sha2.c +++ b/sha2.c @@ -10,7 +10,7 @@ #include "cpuminer-config.h" #include "miner.h" - +#include "compat.h" #include #include @@ -474,10 +474,10 @@ void sha256d_ms_4way(uint32_t *hash, uint32_t *data, static inline int scanhash_sha256d_4way(int thr_id, uint32_t *pdata, const uint32_t *ptarget, uint32_t max_nonce, unsigned long *hashes_done) { - uint32_t data[4 * 64] __attribute__((aligned(128))); - uint32_t hash[4 * 8] __attribute__((aligned(32))); - uint32_t midstate[4 * 8] __attribute__((aligned(32))); - uint32_t prehash[4 * 8] __attribute__((aligned(32))); + uint32_t ATTRALIGN(128) data[4 * 64]; + uint32_t ATTRALIGN(32) hash[4 * 8]; + uint32_t ATTRALIGN(32) midstate[4 * 8]; + uint32_t ATTRALIGN(32) prehash[4 * 8]; uint32_t n = pdata[19] - 1; const uint32_t first_nonce = pdata[19]; const uint32_t Htarg = ptarget[7]; @@ -533,10 +533,10 @@ void sha256d_ms_8way(uint32_t *hash, uint32_t *data, static inline int scanhash_sha256d_8way(int thr_id, uint32_t *pdata, const uint32_t *ptarget, uint32_t max_nonce, unsigned long *hashes_done) { - uint32_t data[8 * 64] __attribute__((aligned(128))); - uint32_t hash[8 * 8] __attribute__((aligned(32))); - uint32_t midstate[8 * 8] __attribute__((aligned(32))); - uint32_t prehash[8 * 8] __attribute__((aligned(32))); + uint32_t ATTRALIGN(128) data[8 * 64]; + uint32_t ATTRALIGN(32) hash[8 * 8]; + uint32_t ATTRALIGN(32) midstate[8 * 8]; + uint32_t ATTRALIGN(32) prehash[8 * 8]; uint32_t n = pdata[19] - 1; const uint32_t first_nonce = pdata[19]; const uint32_t Htarg = ptarget[7]; @@ -587,10 +587,10 @@ static inline int scanhash_sha256d_8way(int thr_id, uint32_t *pdata, int scanhash_sha256d(int thr_id, uint32_t *pdata, const uint32_t *ptarget, uint32_t max_nonce, unsigned long *hashes_done) { - uint32_t data[64] __attribute__((aligned(128))); - uint32_t hash[8] __attribute__((aligned(32))); - uint32_t midstate[8] __attribute__((aligned(32))); - uint32_t prehash[8] __attribute__((aligned(32))); + uint32_t ATTRALIGN(128) data[64]; + uint32_t ATTRALIGN(32) hash[8]; + uint32_t ATTRALIGN(32) midstate[8]; + uint32_t ATTRALIGN(32) prehash[8]; uint32_t n = pdata[19] - 1; const uint32_t first_nonce = pdata[19]; const uint32_t Htarg = ptarget[7]; diff --git a/util.c b/util.c index 0dca27884..2d2cfbf71 100644 --- a/util.c +++ b/util.c @@ -224,8 +224,8 @@ static size_t all_data_cb(const void *ptr, size_t size, size_t nmemb, db->allocated = newalloc; } - memcpy(db->buf + db->len, ptr, len); /* append new data */ - memcpy(db->buf + db->len + len, &zero, 1); /* null terminate */ + memcpy((char*)db->buf + db->len, ptr, len); /* append new data */ + memcpy((char*)db->buf + db->len + len, &zero, 1); /* null terminate */ db->len += len; @@ -247,13 +247,13 @@ static size_t resp_hdr_cb(void *ptr, size_t size, size_t nmemb, void *user_data) tmp = memchr(ptr, ':', ptrlen); if (!tmp || (tmp == ptr)) /* skip empty keys / blanks */ goto out; - slen = tmp - ptr; + slen = (char*)tmp - (char*)ptr; if ((slen + 1) == ptrlen) /* skip key w/ no value */ goto out; memcpy(key, ptr, slen); /* store & nul term key */ key[slen] = 0; - rem = ptr + slen + 1; /* trim value's leading whitespace */ + rem = (char*)ptr + slen + 1; /* trim value's leading whitespace */ remlen = ptrlen - slen - 1; while ((remlen > 0) && (isspace(*rem))) { remlen--;