Skip to content

Instantly share code, notes, and snippets.

View mohamed's full-sized avatar

Mohamed A. Bamakhrama mohamed

View GitHub Profile
@shafik
shafik / WhatIsStrictAliasingAndWhyDoWeCare.md
Last active March 28, 2024 20:47
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

@cb372
cb372 / riscv.md
Last active March 22, 2024 23:48
Writing an OS in Rust to run on RISC-V

(This is a translation of the original article in Japanese by moratorium08.)

(UPDATE (22/3/2019): Added some corrections provided by the original author.)

Writing your own OS to run on a handmade CPU is a pretty ambitious project, but I've managed to get it working pretty well so I'm going to write some notes about how I did it.

module corescore_emitter_uart
#(
parameter clk_freq_hz = 0,
parameter baud_rate = 57600)
(
input wire i_clk,
input wire i_rst,
input wire [7:0] i_data,
input wire i_valid,
output reg o_ready,
@hyperupcall
hyperupcall / settings.jsonc
Last active March 6, 2024 02:41
VSCode config to disable popular extensions' annoyances (telemetry, notifications, welcome pages, etc.)
// I'm tired of extensions that automatically:
// - show welcome pages / walkthroughs
// - show release notes
// - send telemetry
// - recommend things
//
// This disables all of that stuff.
// If you have more config, leave a comment so I can add it!!
{