diff options
author | FormerLurker <hochgebe@gmail.com> | 2021-01-03 23:18:02 +0300 |
---|---|---|
committer | FormerLurker <hochgebe@gmail.com> | 2021-01-03 23:18:02 +0300 |
commit | d4852e3e537ab891309f4a6c6d25cae4954c9225 (patch) | |
tree | 1969a95f3bcc01d06f19f63370fc33c15587c8cc /GcodeProcessorLib | |
parent | b0ffde1402a0fe3b1fd448bd00f0a18a0050d678 (diff) |
Add static linking for windows exe. Remove mingw build. Add copyright notices for fpconv to exe output.
Diffstat (limited to 'GcodeProcessorLib')
-rw-r--r-- | GcodeProcessorLib/CMakeLists.txt | 7 | ||||
-rw-r--r-- | GcodeProcessorLib/fpconv.cpp | 42 | ||||
-rw-r--r-- | GcodeProcessorLib/fpconv.h | 7 |
3 files changed, 29 insertions, 27 deletions
diff --git a/GcodeProcessorLib/CMakeLists.txt b/GcodeProcessorLib/CMakeLists.txt index 41b729e..8e1ed3e 100644 --- a/GcodeProcessorLib/CMakeLists.txt +++ b/GcodeProcessorLib/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required (VERSION "3.13") +cmake_minimum_required (VERSION "3.15") project(GcodeProcessorLib C CXX) @@ -61,6 +61,11 @@ option(USE_CXX_EXCEPTIONS "Enable C++ exception support" ON) # GcodeProcessorLibSources variable include(sourcelist.cmake) +if(MSVC) + # link to the msvc runtime statically, keeping debug info if we are in debug config + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>") +endif() + # Add a library using our GcodeProcessorLibSources variable from our sourcelist file add_library(${PROJECT_NAME} STATIC ${GcodeProcessorLibSources}) diff --git a/GcodeProcessorLib/fpconv.cpp b/GcodeProcessorLib/fpconv.cpp index 5d34203..e22731a 100644 --- a/GcodeProcessorLib/fpconv.cpp +++ b/GcodeProcessorLib/fpconv.cpp @@ -51,9 +51,7 @@ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include <stdbool.h> #include <string.h> - #include "fpconv.h" #define fracmask 0x000FFFFFFFFFFFFFU @@ -65,7 +63,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define absv(n) ((n) < 0 ? -(n) : (n)) #define minv(a, b) ((a) < (b) ? (a) : (b)) -static uint64_t tens[] = { +static unsigned long long tens[] = { 10000000000000000000U, 1000000000000000000U, 100000000000000000U, 10000000000000000U, 1000000000000000U, 100000000000000U, 10000000000000U, 1000000000000U, 100000000000U, @@ -75,11 +73,11 @@ static uint64_t tens[] = { 10U, 1U }; -static /*inline */uint64_t get_dbits(double d) +static /*inline */unsigned long long get_dbits(double d) { union { double dbl; - uint64_t i; + unsigned long long i; } dbl_bits = { d }; return dbl_bits.i; @@ -87,7 +85,7 @@ static /*inline */uint64_t get_dbits(double d) static Fp build_fp(double d) { - uint64_t bits = get_dbits(d); + unsigned long long bits = get_dbits(d); Fp fp; fp.frac = bits & fracmask; @@ -145,14 +143,14 @@ static void get_normalized_boundaries(Fp* fp, Fp* lower, Fp* upper) static Fp multiply(Fp* a, Fp* b) { - const uint64_t lomask = 0x00000000FFFFFFFF; + const unsigned long long lomask = 0x00000000FFFFFFFF; - uint64_t ah_bl = (a->frac >> 32) * (b->frac & lomask); - uint64_t al_bh = (a->frac & lomask) * (b->frac >> 32); - uint64_t al_bl = (a->frac & lomask) * (b->frac & lomask); - uint64_t ah_bh = (a->frac >> 32) * (b->frac >> 32); + unsigned long long ah_bl = (a->frac >> 32) * (b->frac & lomask); + unsigned long long al_bh = (a->frac & lomask) * (b->frac >> 32); + unsigned long long al_bl = (a->frac & lomask) * (b->frac & lomask); + unsigned long long ah_bh = (a->frac >> 32) * (b->frac >> 32); - uint64_t tmp = (ah_bl & lomask) + (al_bh & lomask) + (al_bl >> 32); + unsigned long long tmp = (ah_bl & lomask) + (al_bh & lomask) + (al_bl >> 32); /* round up */ tmp += 1U << 31; @@ -164,7 +162,7 @@ static Fp multiply(Fp* a, Fp* b) return fp; } -static void round_digit(char* digits, int ndigits, uint64_t delta, uint64_t rem, uint64_t kappa, uint64_t frac) +static void round_digit(char* digits, int ndigits, unsigned long long delta, unsigned long long rem, unsigned long long kappa, unsigned long long frac) { while (rem < frac && delta - rem >= kappa && (rem + kappa < frac || frac - rem > rem + kappa - frac)) { @@ -176,22 +174,22 @@ static void round_digit(char* digits, int ndigits, uint64_t delta, uint64_t rem, static int generate_digits(Fp* fp, Fp* upper, Fp* lower, char* digits, int* K) { - uint64_t wfrac = upper->frac - fp->frac; - uint64_t delta = upper->frac - lower->frac; + unsigned long long wfrac = upper->frac - fp->frac; + unsigned long long delta = upper->frac - lower->frac; Fp one; one.frac = 1ULL << -upper->exp; one.exp = upper->exp; - uint64_t part1 = upper->frac >> -one.exp; - uint64_t part2 = upper->frac & (one.frac - 1); + unsigned long long part1 = upper->frac >> -one.exp; + unsigned long long part2 = upper->frac & (one.frac - 1); int idx = 0, kappa = 10; - uint64_t* divp; + unsigned long long* divp; /* 1000000000 */ for (divp = tens + 10; kappa > 0; divp++) { - uint64_t div = *divp; + unsigned long long div = *divp; unsigned digit = part1 / div; if (digit || idx) { @@ -201,7 +199,7 @@ static int generate_digits(Fp* fp, Fp* upper, Fp* lower, char* digits, int* K) part1 -= digit * div; kappa--; - uint64_t tmp = (part1 << -one.exp) + part2; + unsigned long long tmp = (part1 << -one.exp) + part2; if (tmp <= delta) { *K += kappa; round_digit(digits, idx, delta, tmp, div << -one.exp, wfrac); @@ -211,7 +209,7 @@ static int generate_digits(Fp* fp, Fp* upper, Fp* lower, char* digits, int* K) } /* 10 */ - uint64_t* unit = tens + 18; + unsigned long long* unit = tens + 18; while (true) { part2 *= 10; @@ -458,7 +456,7 @@ static int filter_special(double fp, char* dest) return 1; } - uint64_t bits = get_dbits(fp); + unsigned long long bits = get_dbits(fp); bool nan = (bits & expmask) == expmask; diff --git a/GcodeProcessorLib/fpconv.h b/GcodeProcessorLib/fpconv.h index 2156eb5..6896a3a 100644 --- a/GcodeProcessorLib/fpconv.h +++ b/GcodeProcessorLib/fpconv.h @@ -52,8 +52,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #ifndef FPCONV_H #define FPCONV_H - -#include <stdint.h> /* Fast and accurate double to string conversion based on Florian Loitsch's * Grisu-algorithm[1]. * @@ -96,7 +94,7 @@ int fpconv_dtos(double fp, char dest[24], unsigned char precision); typedef struct Fp { - uint64_t frac; + unsigned long long frac; int exp; } Fp; @@ -171,4 +169,5 @@ static Fp find_cachedpow10(int exp, int* k) return powers_ten[idx]; } -}
\ No newline at end of file +} + |