Skip to content

Instantly share code, notes, and snippets.

View matias-eduardo's full-sized avatar
🏝️
🇵🇷

matias matias-eduardo

🏝️
🇵🇷
View GitHub Profile
// Estimating CPU frequency...
// CPU frequency: 4.52 GHz
// sum1: value = 15182118497126522709, 0.31 secs, 5.14 cycles/elem
// sum2: value = 15182118497126522709, 0.17 secs, 2.93 cycles/elem
#define RW(x) asm("" : "+r"(x))
typedef struct Node {
u64 value;
struct Node *next;
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#if defined(__x86_64__)
#define BREAK asm("int3")
#else
#error Implement macros for your CPU.
#endif
@pervognsen
pervognsen / shift_dfa.md
Last active April 21, 2025 19:59
Shift-based DFAs

A traditional table-based DFA implementation looks like this:

uint8_t table[NUM_STATES][256]

uint8_t run(const uint8_t *start, const uint8_t *end, uint8_t state) {
    for (const uint8_t *s = start; s != end; s++)
        state = table[state][*s];
    return state;
}
#include <stdint.h>
typedef unsigned char U8;
typedef unsigned short U16;
typedef unsigned int U32;
typedef unsigned long long U64;
typedef intptr_t SINTa;
struct KernelState
{
@mmozeiko
mmozeiko / shader.hlsl
Last active November 7, 2024 20:23
compute shader for rendering monospaced glyphs in grid
//
struct TerminalCell
{
// cell index into GlyphTexture, should be two 16-bit (x,y) values packed: "x | (y << 16)"
uint GlyphIndex;
// 0xAABBGGRR encoded colors, nonzero alpha for Foreground indicates to render colored-glyph
// which means use RGB values from GlyphTexture directly as output, not as ClearType blending weights
uint Foreground;
@mmozeiko
mmozeiko / image2clipboard.c
Last active October 13, 2024 00:49
example how to put RGBA image in clipboard
#define STB_IMAGE_STATIC
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h" // get from https://raw.githubusercontent.com/nothings/stb/master/stb_image.h
#include <windows.h>
int main(int argc, char* argv[])
{
int w, h;
stbi_uc* data = stbi_load(argv[1], &w, &h, NULL, 4);
@mmozeiko
mmozeiko / win32_d3d11.c
Last active April 20, 2025 08:17
setting up and using D3D11 in C
// example how to set up D3D11 rendering on Windows in C
#define COBJMACROS
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <d3d11.h>
#include <dxgi1_3.h>
#include <d3dcompiler.h>
#include <dxgidebug.h>
@mmozeiko
mmozeiko / d3d11_pixels.c
Last active November 22, 2024 03:04
drawing pixels in software & showing them to window by uploading via D3D11
#define COBJMACROS
#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <d3d11.h>
#include <stdint.h>
#include <string.h>
#include <intrin.h>
/*
* m1racle-poc: a basic proof of concept for the M1RACLES vulnerability in the Apple M1.
*
* This program allows you to read and write the state of the s3_5_c15_c10_1 CPU register.
*
* Please visit m1racles.com for more information.
*
* Licensed under the MIT license.
*/
@Sharlock93
Sharlock93 / ttf_rasterization.md
Last active November 23, 2024 02:46
Reading TTF files and rasterizing them using a handmade approach, Part 2: Rasterization

Reading TTF files and rasterizing them using a handmade approach, Part 2: Rasterization

I streamed this entire post writing on twitch.tv/Sharlock93 please do drop by if you want to see someone stumble their way into writing code and learning stuff. If you have any questions don't hesitate to ask here or on twitter @Sharlock93 more than happy to answer everyone.

If you find any mistakes in this post or have any feedback please don't hesitate to let me know.

Introduction

This is the 2nd part to my previous article about Font reading and Rasterization, this part is about rasterizing the outlines. The overall general topics covered in this part is: