Skip to content

Instantly share code, notes, and snippets.

@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 / xbatalarm
Created May 8, 2017 01:45
Hopefully functional Xbatalarm for nonfunctional ACPI. Copy to /usr/bin/xbatalarm and reboot. Original file by QuaLaPinna.
#!/bin/bash
# Copyright (C) QuaLaPinna team (Gius & Whitesnow, repository: http://qualapinna.dyndns.org/repo, blog: http://qualapinna.dyndns.org)
# April 2014, license: GPL3 and any later versions
# Credits: Puppy Linux forum user josejp2424 for input and collaboration in NLS development (see es_AR localized file).
# Xbatalarm version 2.0
export TEXTDOMAIN=xbatalarm
export OUTPUT_CHARSET=UTF-8
f_get_values() {
@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 / README.md
Last active May 30, 2021 17:23
C style void pointer/malloc wrapper for C++

C Style Malloc in C aka Void Pointers

One of the most annoying things about C++ is the incompatibility with C's void * conversion. In C, void * can be cast implicitly to any pointer type, but C++ needs an explicit cast.

Most C code is valid C++ code, but the most common issue is malloc, which returns void *.

For example, this is valid C code, but not valid C++ code:

struct Foo *x = malloc(sizeof(struct Foo));
@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 / orthodoxc++.md
Created July 18, 2018 19:56 — forked from bkaradzic/orthodoxc++.md
Orthodox C++

Orthodox C++

What is Orthodox C++?

Orthodox C++ (sometimes referred as C+) is minimal subset of C++ that improves C, but avoids all unnecessary things from so called Modern C++. It's exactly opposite of what Modern C++ suppose to be.

Why not Modern C++?

@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 <sven@gimp.org>
* 2010-2012 Michael Natterer <mitch@gimp.org>
*
* 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.