Header only collection of common macro functionality for C++ 20.
Clone (as a submodule or otherwise):
git submodule add git@github.com:nvsl/cpp-common.git vendor/cpp-commonAdd the directory as a include directory:
g++ -iquote"vendor/cpp-common/include" main.cc -o mainPMemOps provides convinient functions to flush and drain arbitrary sized address range.
#include"nvsl/pmemops.hh"intmain() {
nvsl::PmemOps *pmemops = newnvsl::PmemOpsClwb();
/* uint64_t *val = pmalloc(sizeof(uint64_t)); */// CLWB
pmemops->flush(val, sizeof(*val));
// SFENCE
pmemops->drain();
}
PMemOps supports streaming writes (NT stores) to perform memcpy.streaming_wr() automatically selects the right instruction depending on the
number of bytes being copied.
#include"nvsl/pmemops.hh"intmain() {
nvsl::PmemOps *pmemops = newnvsl::PmemOpsClwb();
/* * uint64_t *src = pmalloc(100 * sizeof(uint64_t)); * uint64_t *dst = pmalloc(100 * sizeof(uint64_t)); */// NT stores to do memcpy
pmemops->streaming_wr(dst, src, 100*sizeof(uint64_t));
}Use the files in your project:
#include "nvsl/string.hh"
for (constauto tok : split("Hello! World.", "")) {
std::cout << tok << std::endl;
}Prints:
Hello!
World
std::cout << zip({"1", "2", "3"}, ", ")) << std::endl;Prints:
1, 2, 3
Convert char*, numbers or floats to std::string:
usingnamespacenvsl;char *buf = "some string";
std::string buf_str = S(buf);
std::string num = S(1);voiddo_something() {
nvsl::Clock clk;
clk.tick();
sleep(1);
clk.tock();
clk.reconcile();
std::cout << "Execution summary" << clk.summarize() << std::endl;
}#include"nvsl/c-common.h"voidnvsl_fatal(constchar*fmt, ...);
intnvsl_is_log_enabled(intcheck_lvl);
intnvsl_log(constintlvl, constchar*fmt, ...);Docs available at https://nvsl.github.io/cpp-common/.