Double conv. can now be enable for debugging purposes.

This commit is contained in:
Daniel Lemire 2018-07-28 21:13:09 -04:00
parent f7531d6a81
commit 52fdd7ce2b
2 changed files with 30 additions and 4 deletions

View File

@ -6,20 +6,21 @@
.PHONY: clean cleandist
CXXFLAGS = -std=c++11 -O2 -march=native -Wall -Wextra -Wshadow -Idependencies/double-conversion -Ldependencies/double-conversion/release/libdouble-conversion.a
CXXFLAGS = -std=c++11 -O2 -march=native -Wall -Wextra -Wshadow -Idependencies/double-conversion -Ldependencies/double-conversion/release -ldouble-conversion
#CXXFLAGS = -std=c++11 -O2 -march=native -Wall -Wextra -Wshadow -Wno-implicit-function-declaration
EXECUTABLES=parse
EXTRA_EXECUTABLES=parsenocheesy parsenodep8
LIDDOUBLE:=dependencies/double-conversion/release/libdouble-conversion.a
LIBS=dependencies/double-conversion/release/libdouble-conversion.a
LIBS=$(LIDDOUBLE)
all: $(LIBS) $(EXECUTABLES)
all: $(LIBS) $(EXECUTABLES)
-./parse
dependencies/double-conversion/release/libdouble-conversion.a : dependencies/double-conversion/README.md
$(LIDDOUBLE) : dependencies/double-conversion/README.md
cd dependencies/double-conversion/ && mkdir -p release && cd release && cmake .. && make
parse: main.cpp common_defs.h linux-perf-events.h

View File

@ -22,6 +22,15 @@
#include "common_defs.h"
#include "linux-perf-events.h"
/// Fixme: enable doube conv
// #define DOUBLECONV
#ifdef DOUBLECONV
#include "double-conversion/double-conversion.h"
#include "double-conversion/ieee.h"
using namespace double_conversion;
#endif
using namespace std;
//#define DEBUG
@ -865,6 +874,11 @@ really_inline bool parse_string(const u8 * buf, UNUSED size_t len, UNUSED Parsed
return true;
}
#ifdef DOUBLECONV
static StringToDoubleConverter converter(StringToDoubleConverter::ALLOW_TRAILING_JUNK, 2000000.0, Double::NaN(), NULL, NULL);
#endif
// put a parsed version of number (either as a double or a signed long) into the number buffer,
// put a 'tag' indicating which type and where it is back onto the tape at that location
// return false if we can't parse the number which means either
@ -877,6 +891,17 @@ really_inline bool parse_string(const u8 * buf, UNUSED size_t len, UNUSED Parsed
// have a generic scratch - would need to align before using for this
really_inline bool parse_number(const u8 * buf, UNUSED size_t len, UNUSED ParsedJson & pj, u32 tape_loc, UNUSED bool found_zero, bool found_minus) {
u32 offset = tape[tape_loc] & 0xffffff;
////////////////
// This is temporary... but it illustrates how one could use Google's double conv.
///
#ifdef DOUBLECONV
int processed_characters_count;
double result = converter.StringToDouble((const char*)( buf+offset), 10, &processed_characters_count);
printf("number is %f and used %d chars \n", result, processed_characters_count);
#endif
////////////////
// end of double conv temporary stuff.
////////////////
if (found_minus) {
offset++;
}