Skip to content

Instantly share code, notes, and snippets.

@easyaspi314
easyaspi314 / xxh3_aarch64_sve.S
Last active March 10, 2022 16:00
XXH3 sve implementation
/// Adapted from Haojian Zhuang's code.
.arch armv8-a+sve
#include "asmdefs.h"
// Since SVE support in C compilers is fairly new and not very optimized, the SVE routines
// are written in assembly.
/// Perform a single round of XXH_accumulate_512().
/// \acc = XXH3_accumulate_512_round(\acc, LDR(x1, \memoffs), LDR(x2, \memoffs))
/// The code is specialized to the various SVE vector sizes to avoid loading from memory.
@easyaspi314
easyaspi314 / xxh3-rust.rs
Created July 8, 2019 04:53
xxh3_64bits in Rust
///
/// xxHash - Extremely Fast Hash algorithm
/// Rust implementation of XXH3_64bits
/// Copyright (C) 2019-present, Yann Collet.
///
/// BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
///
/// Redistribution and use in source and binary forms, with or without
/// modification, are permitted provided that the following conditions are
/// met:
@easyaspi314
easyaspi314 / gimpcairo.c
Created May 7, 2019 00:53
gimpcairo.c reformat
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpcairo.c
* Copyright (C) 2007 Sven Neumann <[email protected]>
* 2010-2012 Michael Natterer <[email protected]>
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
@easyaspi314
easyaspi314 / Product.c
Created April 8, 2019 21:28
Faversaver project in C
#include "Product.h"
#include "ErrorState.h"
#include "iProduct.h"
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static const struct iProductVtable Product_vtable;
@easyaspi314
easyaspi314 / README.md
Last active March 18, 2019 18:58
gets, but safer thanks to GNU extensions

gets but safer

This is like gets. It is a drop in for gets. It is smarter though.

gets_safe, which is aliased to gets for convenience, takes an optional length argument, but it also uses GCC and Clang's __builtin_object_size builtin to calculate the length.

The length will not always be calculated properly, but for static arrays and malloc'd pointers in the current block with a fixed size (only with optimizations), it will usually pick up on it.

This also has a safety feature: If it can properly calculate the length and the supplied length is larger than the one it calculated, it will be an error. Additionally, when both the optional length parameter are omitted and the length cannot be calculated at compile time, it is an error.

@easyaspi314
easyaspi314 / assembler.c
Last active March 8, 2019 21:53
A WIP Thumb-like 8-bit assembly language which interprets C structs
#include <stdio.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#if __STDC_VERSION__ >= 201112L
# include <stdnoreturn.h>
#elif defined(__GNUC__)
# define noreturn __attribute__((__noreturn__))
@easyaspi314
easyaspi314 / README.md
Last active February 25, 2019 08:03
C+: Another Better C

C+: Another Better C

C+ is like halfway between C11 and C++.

Unlike C++, C+ remains a procedural language, and some things are intentionally left out.

Here are some potential ideas.

First, what will be removed:

@easyaspi314
easyaspi314 / _README.md
Last active May 19, 2021 15:40
iostream.h: cin and cout for C using GCC and C11 extensions

iostream.h

iostream.h (ab?)uses _Generic, __builtin_choose_expr, __typeof__, statement expressions, and recursive variadic macro expansion to create a cin and cout for C11+GCC extension compilers.

Should you use this? Of course not. But it's pretty f***ing cool.

Usage

@easyaspi314
easyaspi314 / change_case_simd.c
Created February 6, 2019 06:06
SIMD functions to apply toupper/tolower to each character in a string
/* Created by easyaspi314. Released into the public domain. */
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef __SSE2__
#include <immintrin.h>
@easyaspi314
easyaspi314 / tolowersimd.c
Created February 6, 2019 05:52
tolower SIMD implementation
/* Created by easyaspi314.
* Released into the public domain. */
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef __SSE2__
#include <immintrin.h>