Header only collection of common macro functionality for C++ 20.
Clone (as a submodule or otherwise):
git submodule add [email protected]:nvsl/cpp-common.git vendor/cpp-common
Add the directory as a include directory:
g++ -iquote"vendor/cpp-common/include" main.cc -o main
PMemOps provides convinient functions to flush and drain arbitrary sized address range.
#include "nvsl/pmemops.hh"
int main() {
nvsl::PmemOps *pmemops = new nvsl::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"
int main() {
nvsl::PmemOps *pmemops = new nvsl::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 (const auto 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
:
using namespace nvsl;
char *buf = "some string";
std::string buf_str = S(buf);
std::string num = S(1);
void do_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"
void nvsl_fatal(const char *fmt, ...);
int nvsl_is_log_enabled(int check_lvl);
int nvsl_log(const int lvl, const char *fmt, ...);
Docs available at https://nvsl.github.io/cpp-common/.