Skip to content

Instantly share code, notes, and snippets.

View steakhal's full-sized avatar

Balazs Benics steakhal

View GitHub Profile
@MattPD
MattPD / analysis.draft.md
Last active June 22, 2024 07:19
Program Analysis Resources (WIP draft)
@trietptm
trietptm / assemble_and_emulate.py
Created June 6, 2018 07:35 — forked from Stean/assemble_and_emulate.py
script for assembly execution via keystone, capstone and unicorn engine
#!/usr/bin/env python
# allows print() behavior as in python3
from __future__ import print_function
# required for assembly
from keystone import *
# required for emulation
from unicorn import *
from unicorn.x86_const import *
@shafik
shafik / WhatIsStrictAliasingAndWhyDoWeCare.md
Last active June 17, 2024 09:54
What is Strict Aliasing and Why do we Care?

What is the Strict Aliasing Rule and Why do we care?

(OR Type Punning, Undefined Behavior and Alignment, Oh My!)

What is strict aliasing? First we will describe what is aliasing and then we can learn what being strict about it means.

In C and C++ aliasing has to do with what expression types we are allowed to access stored values through. In both C and C++ the standard specifies which expression types are allowed to alias which types. The compiler and optimizer are allowed to assume we follow the aliasing rules strictly, hence the term strict aliasing rule. If we attempt to access a value using a type not allowed it is classified as undefined behavior(UB). Once we have undefined behavior all bets are off, the results of our program are no longer reliable.

Unfortunately with strict aliasing violations, we will often obtain the results we expect, leaving the possibility the a future version of a compiler with a new optimization will break code we th

@shafik
shafik / bit_cast_array.md
Last active June 29, 2021 14:45
How to use bit_cast to type pun a unsigned char array

In C++20 we will hopefully get bit_cast see the proposal and reference implementation. This utility should give us a simple and safe way to type pun.

The one issue I ran into with this utility is that is requires the size of the To and From type to be the same, as well as checking that To and From types are trivially copyable. The static_assert version of the check is as follows:

# define BIT_CAST_STATIC_ASSERTS(TO, FROM) do {                         \
    static_assert(sizeof(TO) == sizeof(FROM));                          \             
    static_assert(std::is_trivially_copyable<TO>::value);               \
    static_assert(std::is_trivially_copyable<FROM>::value);             \
} while (false)
@xsnpdngv
xsnpdngv / cpufreq-sh
Last active September 8, 2020 08:49
Set CPU governor to powersave on Ubuntu
#!/bin/sh
sudo apt-get install cpufrequtils
echo 'GOVERNOR="powersave"' | sudo tee /etc/defaults/cpufrequtils
sudo /etc/init.d/cpufrequtils restart
cpufreq-info
@P7h
P7h / Bash_command_line_shortcuts.md
Created September 13, 2016 14:44
Bash command line Shortcuts

Bash command line Shortcuts

Picked these from here

Command Editing Shortcuts

Command Note
Ctrl + a go to the start of the command line
Ctrl + e go to the end of the command line
Ctrl + k delete from cursor to the end of the command line
@application2000
application2000 / how-to-install-latest-gcc-on-ubuntu-lts.txt
Last active May 23, 2024 07:53
How to install latest gcc on Ubuntu LTS (12.04, 14.04, 16.04)
These commands are based on a askubuntu answer http://askubuntu.com/a/581497
To install gcc-6 (gcc-6.1.1), I had to do more stuff as shown below.
USE THOSE COMMANDS AT YOUR OWN RISK. I SHALL NOT BE RESPONSIBLE FOR ANYTHING.
ABSOLUTELY NO WARRANTY.
If you are still reading let's carry on with the code.
sudo apt-get update && \
sudo apt-get install build-essential software-properties-common -y && \
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y && \
@Shauren
Shauren / CMakeCache.txt
Last active July 5, 2022 08:31
build boost with clang
# This is the CMakeCache file.
# For build in directory: /home/shauren/projects/TrinityCore/build
# It was generated by CMake: /usr/bin/cmake
# You can edit this file to change values found and used by cmake.
# If you do not want to change any of the values, simply exit the editor.
# If you do want to change a value, simply edit, save, and exit the editor.
# The syntax for the file is as follows:
# KEY:TYPE=VALUE
# KEY is the name of a variable in the cache.
# TYPE is a hint to GUIs for the type of VALUE, DO NOT EDIT TYPE!.
@ax3l
ax3l / CUDA_Compilers.md
Last active June 19, 2024 00:51
CUDA Compilers
@jboner
jboner / latency.txt
Last active June 22, 2024 06:13
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD