Skip to content

Instantly share code, notes, and snippets.

@MarekKnapek
MarekKnapek / timer.c
Created November 21, 2025 19:26
Timer code reaction on Daniel Hirsch YouTube video.
#include <stddef.h> /* NULL */
#include <stdio.h> /* printf fflush */
#include <stdlib.h> /* abort */
#include <errno.h> /* errno EINTR */
#include <poll.h> /* pollfd poll */
#include <sys/timerfd.h> /* timerfd_create CLOCK_MONOTONIC timerfd_settime */
#include <time.h> /* itimerspec timespec */
#include <unistd.h> /* close */
@MarekKnapek
MarekKnapek / sha256_x86.cpp
Created September 19, 2025 02:41
SHA-256 x86
#include <assert.h> /* assert */
#include <stdint.h> /* uintptr_t */
#include <string.h> /* memset memcpy */
#include <emmintrin.h> /* SSE2 _mm_add_epi32 _mm_load_si128 _mm_set_epi64x _mm_shuffle_epi32 _mm_store_si128 */
#include <tmmintrin.h> /* SSSE3 _mm_alignr_epi8 _mm_shuffle_epi8 */
#include <smmintrin.h> /* SSE4.1 _mm_blend_epi16 */
#include <immintrin.h> /* SHA _mm_sha256msg1_epu32 _mm_sha256msg2_epu32 _mm_sha256rnds2_epu32 */
@MarekKnapek
MarekKnapek / sha1_constexpr.cpp
Created September 18, 2025 02:23
SHA-1 C++ constexpr
void xxxxxxxxxx() noexcept(true) = delete;
#define my_assert(x) ((!!(x)) ? ((void)(0)) : ((void)(xxxxxxxxxx())))
typedef decltype(1uz) my_usize_t;
typedef unsigned char my_uint8_t;
typedef unsigned int my_uint32_t;
typedef unsigned long long int my_uint64_t;
struct my_string_view
#include <stdbool.h> /* false */
#include <stdio.h> /* printf */
#include <stdlib.h> /* malloc free exit srand rand NULL */
#include <time.h> /* time_t time */
#define width 12
#define height 8
#define elem_size 3
@MarekKnapek
MarekKnapek / cpp
Created May 13, 2024 00:24
quick_and_dirty_test_of_bcomp.cpp
#include <string.h>
#define crash(x) do{ if(!(x)){ __debugbreak(); int volatile* volatile ptr; ptr = 0; *ptr = 0; } }while(false)
#define min(a, b) (((b) < (a)) ? (b) : (a))
void test_1(unsigned char const* const data, size_t const size) noexcept
{
uint8_t state[256];
struct bcomp_state state_out;
uint16_t bcomp_bits;
@MarekKnapek
MarekKnapek / mkcc-performance.md
Created November 24, 2023 16:13
mkcc-performance
@MarekKnapek
MarekKnapek / fib500.c
Last active November 20, 2023 04:55
Fib500
#define mk_lang_jumbo_want 1
/* You need my library from https://github.com/marekKnapek/mk_clib for this. */
#include "mk_sl_uint32.h"
#include "mk_lang_div_roundup.h"
#define mk_sl_cui_t_name big_fib
#define mk_sl_cui_t_base mk_sl_cui_uint32
#define mk_sl_cui_t_count mk_lang_div_roundup(346, 32)
#include "mk_sl_cui_inl_fileh.h"
#include "mk_sl_cui_inl_filec.h"
@MarekKnapek
MarekKnapek / five_million.c
Created November 9, 2023 02:09
Five Million Digit Number
/* you need my library from */
/* https://github.com/MarekKnapek/mk_clib */
/* https://www.reddit.com/r/C_Programming/comments/17qgg6u/storing_extremely_large_numbers_in_c/ */
#define mk_lang_jumbo_want 1
#include "mk_lang_charbit.h"
#include "mk_lang_sizeof.h"
@MarekKnapek
MarekKnapek / blake3.cpp
Created August 14, 2023 02:36
BLAKE3 constexpr
#include "mk_lib_crypto_hash_stream_blake3.h"
#include <array> /* std::array */
#include <string_view> /* std::string_view */
constexpr auto blake3_constexpr(std::string_view const& str_a, char const& char_a, std::string_view const& str_b, char const& char_b)
{
mk_lib_crypto_hash_stream_blake3_t hash{};
std::size_t i{};
@MarekKnapek
MarekKnapek / increment.cpp
Last active May 28, 2021 15:37
const vs non-const in post increment operator
#define WANT_CONST 1
#include <cstdio>
class my_type
{
public:
my_type() noexcept;