Skip to content

Instantly share code, notes, and snippets.

View lemire's full-sized avatar
🚀
working hard and fast

Daniel Lemire lemire

🚀
working hard and fast
View GitHub Profile
/* 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 */
#ifndef SIMDUTF_COMPILER_CHECK_H
#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;
out.close();
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 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 https://github.com/RcppCore/Rcpp/tree/master/docker/ci-3.4 )

@lemire
lemire / load.c
Created March 6, 2021 16:09
Simple C program to load a file
#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");
.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 August 17, 2020 15:33
One-cmake simdjson example
# 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
lemire / createsimd.c
Created May 5, 2020 18:53
make_uint8x16_t
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 23:58
Running perf under docker
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
@lemire
lemire / is_utf8_continuing.c
Created April 30, 2020 23:41
is_utf8_continuing
// 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;
}