Skip to content

Instantly share code, notes, and snippets.

Mārtiņš Možeiko mmozeiko

  • San Jose, CA
Block or report user

Report or block mmozeiko

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mmozeiko
mmozeiko / floor.c
Last active Jun 18, 2018
various floor functions with SSE1 or SSE2
View floor.c
// various SSE1 and SSE2 floor function for float
// assumes only normal input values
// does not handle NAN or INF - they may or may not work
// only guarantee is that 0, subnormal or normal float values will work
#include <emmintrin.h>
#ifdef _MSC_VER
#include <intrin.h>
#define NOINLINE __declspec(noinline)
@mmozeiko
mmozeiko / hook.c
Last active Jan 27, 2019
reads process stdout + stderr and prints it out as it becomes available
View hook.c
// compile this to hook.dll
// for example, with MSVC: cl.exe /LD /MT /O2 hook.c /Fehook.dll
#include <windows.h>
// get this from https://github.com/kubo/plthook
#include "plthook_win32.c"
static plthook_t* hook;
@mmozeiko
mmozeiko / makefile
Created Sep 28, 2017
TwitchNotify gcc makefile
View makefile
CFLAGS=-Wall -Werror -Wextra -Wno-unused-function -mwindows
# Order matters. Shlwapi must appear before shell32 or else we get a runtime
# error for StrCpyNW.
LFLAGS=-nostartfiles -lkernel32 -luser32 -lShlwapi -lshell32 -lwininet -lole32 -lwindowscodecs
DEBUG_CFLAGS=-g -D_DEBUG
.PHONY: all clean
all: TwitchNotify.exe
@mmozeiko
mmozeiko / test.c
Last active Dec 5, 2018
gtk widget from x11 window
View test.c
// gcc test.c `pkg-config --cflags --libs gtk+-3.0 gdk-3.0` -lX11 && ./a.out
#include <X11/Xlib.h>
#include <unistd.h>
#include <stdio.h>
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
static void my_gtk_realize(GtkWidget* widget, gpointer user)
@mmozeiko
mmozeiko / neon_despace_branchless.c
Last active Jul 8, 2017
branchless ARM neon despacer
View neon_despace_branchless.c
static const uint8_t __attribute__((aligned(16))) mask_shuffle[256*8] = {
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 1,0,0,0,0,0,0,0, 0,1,0,0,0,0,0,0,
2,0,0,0,0,0,0,0, 0,2,0,0,0,0,0,0, 1,2,0,0,0,0,0,0, 0,1,2,0,0,0,0,0,
3,0,0,0,0,0,0,0, 0,3,0,0,0,0,0,0, 1,3,0,0,0,0,0,0, 0,1,3,0,0,0,0,0,
2,3,0,0,0,0,0,0, 0,2,3,0,0,0,0,0, 1,2,3,0,0,0,0,0, 0,1,2,3,0,0,0,0,
4,0,0,0,0,0,0,0, 0,4,0,0,0,0,0,0, 1,4,0,0,0,0,0,0, 0,1,4,0,0,0,0,0,
2,4,0,0,0,0,0,0, 0,2,4,0,0,0,0,0, 1,2,4,0,0,0,0,0, 0,1,2,4,0,0,0,0,
3,4,0,0,0,0,0,0, 0,3,4,0,0,0,0,0, 1,3,4,0,0,0,0,0, 0,1,3,4,0,0,0,0,
2,3,4,0,0,0,0,0, 0,2,3,4,0,0,0,0, 1,2,3,4,0,0,0,0, 0,1,2,3,4,0,0,0,
5,0,0,0,0,0,0,0, 0,5,0,0,0,0,0,0, 1,5,0,0,0,0,0,0, 0,1,5,0,0,0,0,0,
@mmozeiko
mmozeiko / neon_despace_branchless.c
Created Jul 4, 2017
ARM neon branchless despacer
View neon_despace_branchless.c
static const uint8_t __attribute__((aligned(16))) shuffle_arr[256*8] = {
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
1,0,0,0,0,0,0,0,
0,1,0,0,0,0,0,0,
2,0,0,0,0,0,0,0,
0,2,0,0,0,0,0,0,
1,2,0,0,0,0,0,0,
0,1,2,0,0,0,0,0,
3,0,0,0,0,0,0,0,
@mmozeiko
mmozeiko / crt.cpp
Created Jan 16, 2017
MSVC CRT startup
View crt.cpp
#include <windows.h>
extern "C"
{
#pragma section(".CRT$XIA",long,read)
#pragma section(".CRT$XIZ",long,read)
#pragma section(".CRT$XCA",long,read)
#pragma section(".CRT$XCZ",long,read)
#pragma section(".CRT$XPA",long,read)
#pragma section(".CRT$XPZ",long,read)
View output.txt
WaitForSingleObject - 0msec
ReadFile - 14msec
- IO pending, event is set
WaitForSingleObject - 0msec
GetOverlappedResult - 0msec
got 33554432 bytes
ReadFile - 8msec
- IO pending, event is set
WaitForSingleObject - 0msec
GetOverlappedResult - 0msec
@mmozeiko
mmozeiko / test.cpp
Created Jan 10, 2017
overlapped file i/o test
View test.cpp
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>
static LARGE_INTEGER f;
static void printTime(const char* name, LARGE_INTEGER t1, LARGE_INTEGER t2)
{
printf("%s - %I64umsec\n", name, (t2.QuadPart - t1.QuadPart) * 1000 / f.QuadPart);
}
@mmozeiko
mmozeiko / build.bat
Created Dec 18, 2016
build.bat with caching
View build.bat
@echo off
setlocal EnableDelayedExpansion
set ARCH=amd64
set BUILD_CACHE=%~dp0\_build_cache.cmd
if exist "!BUILD_CACHE!" (
call "!BUILD_CACHE!"
) else (
call "%VS120COMNTOOLS%..\..\VC\vcvarsall.bat" !ARCH!
You can’t perform that action at this time.