diff --git a/.gitignore b/.gitignore index 6eab03e..6953907 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ test* obj/ hexview +profile/ diff --git a/Makefile b/Makefile index f2aa21d..33af327 100644 --- a/Makefile +++ b/Makefile @@ -11,20 +11,37 @@ LDFLAGS+= -lfmt PROJ = hexview OBJ = $(addprefix obj/,$(SRC:.cpp=.o)) +PROF_OBJ = $(addprefix profile/,$(SRC:.cpp=.o)) .PHONY: all all: dirs $(PROJ) dirs: @mkdir -p obj/src + @mkdir -p profile/src obj/%.o: %.cpp $(CXX) -c $< $(_HX_FEAT) $(CXXFLAGS) -o $@ $(LDFLAGS) +profile/%.o: %.cpp + $(CXX) -c $< $(_HX_FEAT) $(CXXFLAGS) -fprofile-generate -o $@ $(LDFLAGS) + $(PROJ): $(OBJ) $(CXX) $^ $(CXXFLAGS) -o $@ $(LDFLAGS) strip $@ +pgo-generate: $(PROF_OBJ) + $(CXX) $^ $(CXXFLAGS) -fprofile-generate -o $@ $(LDFLAGS) + +pgo-profile: pgo-generate + for i in {1..32}; do \ + dd if=/dev/urandom of=./pgo-test bs=1024 count=1024 \ + ./pgo-generate ./pgo-test + done + rm ./pgo-test + clean: rm -f $(PROJ) rm -rf obj + rm -rf profile + rm -f pgo-generate diff --git a/src/hex.cpp b/src/hex.cpp index 3a0521d..e0a23de 100644 --- a/src/hex.cpp +++ b/src/hex.cpp @@ -53,12 +53,18 @@ inline __attribute__((always_inline)) void prints(const S&... strings) (fputs((const char*)strings, stdout), ...); } -inline void hex02(std::uint8_t byte, char buffer[3]) +inline void hex02(std::uint8_t byte, char buffer[2]) { buffer[0] =hex_map[byte][0]; buffer[1] =hex_map[byte][1]; } +template +inline __attribute__((always_inline)) void print_exact(const char (&ar)[N]) +{ + fwrite(ar, N, 1, stdout); +} + namespace hv { void print_screen(const span memory, unsigned long offset) { @@ -71,28 +77,34 @@ namespace hv { fmt::print("0x{:016x} ", offset); char hxbuf[3]; std::size_t i=0; - char ascii[1 + ROW_SZ]; - - ascii[ROW_SZ] = 0; - hxbuf[2] = 0; + char r_ascii[2 + ROW_SZ]; + r_ascii[0] = ' '; + r_ascii[1] = ' '; + char* ascii = r_ascii + 2; + + hxbuf[2] = ' '; for(;i