Skip to content

Instantly share code, notes, and snippets.

working hard and fast

Daniel Lemire lemire

working hard and fast
View GitHub Profile
lemire / simdutf_on_node.txt
Last active December 17, 2022 02:17
How one might include simdutf in node js
View simdutf_on_node.txt
AVX-512 is a collection of instruction sets. The AVX-512 kernel in simdutf relies on VBMI2, one of the AVX-512
instruction sets. The simdutf library determines at runtime whether the processor supports VBMI2. If not, other (slower)
kernels are used, depending on the processor.
Not all compilers support the AVX-512 intrinsics that the simdutf library requires. Thus at compile-time, the library
checks for Visual Studio 2019 or better, or for the presence of the header 'avx512vbmi2intrin.h'.
At compile-time, it is thus assumed that if the compiler has access to 'avx512vbmi2intrin.h', then it can compile
the functions that are part of it and produce a VBMI2 code kernel. This should be a safe assumption.
lemire / functionalcpp.cpp
Created October 27, 2022 13:35
Passing lambdas as values
View functionalcpp.cpp
#include <functional>
int g(int x, int y) {
auto lambda = [] <typename T>(std::function<T(T,T)> f, T x, T y) { return f(x,y); };
std::function<int(int,int)> f = [](int x, int y)->int {return x + y;};
return lambda(f, x,y);
View simdutf.cpp
/* auto-generated on 2022-10-06 13:43:02 +0000. Do not edit! */
// dofile: invoked with prepath=/home/lemire/CVS/github/simdutf/include, filename=simdutf.h
/* begin file include/simdutf.h */
#ifndef SIMDUTF_H
#define SIMDUTF_H
#include <cstring>
// dofile: invoked with prepath=/home/lemire/CVS/github/simdutf/include, filename=simdutf/compiler_check.h
/* begin file include/simdutf/compiler_check.h */
View writeutf16le.cpp
#include <fstream>
#include <iostream>
int main() {
char16_t output_buffer[] = u"hello world";
size_t len = sizeof(output_buffer) / sizeof(char16_t);
std::ofstream out("output.ut16.txt", std::ios::binary | std::ios::trunc);
out.write(reinterpret_cast<char *>(output_buffer), len * sizeof(char16_t));
std::cout << "wrote " << out.tellp() << " bytes" << std::endl;
from math import *
def convert_to_degree(x):
return [int(x[0] / (2 * pi) *360),int(x[1] / (2 * pi) *360),int(x[2] / (2 * pi) *360)]
def toangles(q):
sqw = q[3] * q[3]
sqx = q[0] * q[0]
sqy = q[1] * q[1]
sqz = q[2] * q[2]
lemire /
Last active September 7, 2021 19:47
hacking rcppsimdjson

Here is how to test rcppsimdjson.

  • Install docker.
  • Grab rcppsimdjson from GitHub.

Next, you want to create a file called 'Dockerfile'. You may put this file inside the root rcppsimdjson repository.

The file may have the following content: (there are more examples at )

lemire / load.c
Created March 6, 2021 16:09
Simple C program to load a file
View load.c
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
if (argc < 2) {
perror("provide a file argument");
FILE *pFile = fopen(argv[1], "rb");
if (pFile == NULL)
perror("Error opening file");
View two_or_three.s
.globl _compute_two ; -- Begin function compute_two
.p2align 2
_compute_two: ; @compute_two
; %bb.0:
adrp x8, _M@PAGE
ldr x8, [x8, _M@PAGEOFF]
tst x8, #0x7fffffffffffffff
lemire / CMakeLists.txt
Last active August 17, 2020 15:33
One-cmake simdjson example
View CMakeLists.txt
# Copy this file as CMakeLists.txt in
# some directory. With a recent CMake
# (at least 3.15), in this directory do
# cmake -B build .
# cmake --build build
# ./build/repro
cmake_minimum_required(VERSION 3.15)
lemire / createsimd.c
Created May 5, 2020 18:53
View createsimd.c
namespace {
* make_uint8x16_t initializes a SIMD register (uint8x16_t).
* This is needed because, incredibly, the syntax uint8x16_t x = {1,2,3...}
* is not recognized under Visual Studio! This is a workaround.
* Using a std::initializer_list<uint8_t> as a parameter resulted in
* inefficient code. With the current approach, if the parameters are
* compile-time constants,
* GNU GCC compiles it to ldr, the same as uint8x16_t x = {1,2,3...}.