Skip to content

Instantly share code, notes, and snippets.

Avatar
🚀
working hard and fast

Daniel Lemire lemire

🚀
working hard and fast
View GitHub Profile
View rollyawpitch.py
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
lemire / hacking.md
Last active Sep 7, 2021
hacking rcppsimdjson
View hacking.md

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 https://github.com/RcppCore/Rcpp/tree/master/docker/ci-3.4 )

@lemire
lemire / load.c
Created Mar 6, 2021
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
.cfi_startproc
; %bb.0:
Lloh0:
adrp x8, _M@PAGE
Lloh1:
ldr x8, [x8, _M@PAGEOFF]
tst x8, #0x7fffffffffffffff
@lemire
lemire / CMakeLists.txt
Last active Aug 17, 2020
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)
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...}.
@lemire
lemire / perfdocker.bash
Created May 3, 2020
Running perf under docker
View perfdocker.bash
docker run -it --privileged ubuntu bash
apt-get update
apt-get install linux-tools-generic
/usr/lib/linux-tools/5.4.0-28-generic/perf stat ls
View is_utf8_continuing.c
// returns true if the provided byte value is a
// "continuing" UTF-8 value, that is, if it starts with
// 0b10...
static inline bool is_utf8_continuing(char c) {
// in 2 complement's notation, values start at 0b10000 (-128)... and
// go up to 0b11111 (-1)... so we want all values from -128 to -65 (which is 0b10111111)
return ((signed char)c) <= -65;
}
View portable_prefetch.c
// prefetching can be useful for large documents
// where page walking becomes a significant overhead
#ifdef _MSC_VER
// annoyingly, Visual Studio does not appear to have a portable
// prefetch
#ifdef IS_ARM64
inline void prefetch(const void * p) {
__prefetch(p);
}
View gosetbenchmark_test.go
package Main
import (
"math"
"reflect"
"testing"
"github.com/RoaringBitmap/roaring"
"github.com/willf/bitset"
)