Skip to content

Instantly share code, notes, and snippets.

View silvesthu's full-sized avatar

Ken Hu silvesthu

  • Japan
View GitHub Profile
@silvesthu
silvesthu / WhatIsStrictAliasingAndWhyDoWeCare.md
Created January 7, 2023 07:59 — forked from shafik/WhatIsStrictAliasingAndWhyDoWeCare.md
What is Strict Aliasing and Why do we Care?
View WhatIsStrictAliasingAndWhyDoWeCare.md

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

@silvesthu
silvesthu / VtxAniExport.ms
Last active April 9, 2022 13:10
Vertex Animation Export Maxscript
View VtxAniExport.ms
macroScript VtxAniExport
category: "VertexAnimation"
-- Export texture and a set of parameters to enable vertex animation
-- Reference: https://github.com/apras/Unity-VertexTextureFetchAnimation/blob/master/Assets/Model/VTF.ms
-- Reference: https://docs.unrealengine.com/latest/INT/Engine/Animation/Tools/VertexAnimationTool/
(
rollout _rollout "Vertex Animation Export"
(
label objectName "Object" align:#center
@silvesthu
silvesthu / ComputePressure.cpp
Created July 11, 2021 11:42
Generate code to apply multiple iteration in one pass for ShaderToy
View ComputePressure.cpp
#include <iostream>
#include <vector>
struct Sample
{
int x = 0;
int y = 0;
unsigned __int64 count = 0;
};