Skip to content

Instantly share code, notes, and snippets.

View amsharifian's full-sized avatar

Amirali Sharifian amsharifian

View GitHub Profile
@amsharifian
amsharifian / WhatIsStrictAliasingAndWhyDoWeCare.md
Created October 31, 2018 01:12 — forked from shafik/WhatIsStrictAliasingAndWhyDoWeCare.md
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

@amsharifian
amsharifian / gist:2ced74227a5bfc1ad583486227b5c51d
Created January 29, 2019 17:04
mac-os: Using a home-built compiler leads to fatal error: 'stdio.h' file not found
I've found a way. If we are using Xcode 10, you will notice that if you navigate to the /usr in the Finder, you will not see a folder called 'include' any more, which is why the terminal complains of the absence of the header files which is contained inside the 'include' folder. In the Xcode 10.0 Release Notes, it says there is a package:
/Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
and you should install that package to have the /usr/include folder installed. Then you should be good to go.
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
Epic code example:
class BasicBlockNoMaskFastNode(BID: Int, val NumInputs: Int = 1, val NumOuts: Int)
(implicit val p: Parameters,
name: sourcecode.Name,
file: sourcecode.File)
extends Module with CoreParams with UniformPrintfs {
val io = IO(new BasicBlockNoMaskFastVecIO(NumInputs, NumOuts)(p))
pip install compdb
compdb -p build/ list > compile_commands.json
@amsharifian
amsharifian / fun.cpp
Created February 18, 2019 19:34 — forked from dant3/fun.cpp
Some fun with C++ 11 - fold, map, reduce, mkString for std::vector<T>
#include <iostream>
#include <sstream>
#include <functional>
#include <vector>
template <typename T, typename U>
U foldLeft(const std::vector<T>& data,
const U& initialValue,
const std::function<U(U,T)>& foldFn) {
typedef typename std::vector<T>::const_iterator Iterator;
#include <iostream>
#include <vector>
namespace std17
{
template<class InputIt, class T, class BinaryOp, class UnaryOp>
T transform_reduce(InputIt first ,
InputIt last ,
T init ,
BinaryOp binop ,
### Keybase proof
I hereby claim:
* I am amsharifian on github.
* I am amsharifian (https://keybase.io/amsharifian) on keybase.
* I have a public key ASAM9Ph09U_FHJk-IRIo9zSp-yKThhLrPgbWYfARqKj3jAo
To claim this, I am signing this object:
@amsharifian
amsharifian / gist:e3493182ea535be96c7bb39d60c31c44
Created June 5, 2019 21:43 — forked from jagregory/gist:710671
How to move to a fork after cloning
So you've cloned somebody's repo from github, but now you want to fork it and contribute back. Never fear!
Technically, when you fork "origin" should be your fork and "upstream" should be the project you forked; however, if you're willing to break this convention then it's easy.
* Off the top of my head *
1. Fork their repo on Github
2. In your local, add a new remote to your fork; then fetch it, and push your changes up to it
git remote add my-fork [email protected]
@amsharifian
amsharifian / gist:f1b50a46e5512b183e5db1d2daeaebd9
Created June 24, 2019 04:17 — forked from jimbojsb/gist:1630790
Code highlighting for Keynote presentations

Step 0:

Get Homebrew installed on your mac if you don't already have it

Step 1:

Install highlight. "brew install highlight". (This brings down Lua and Boost as well)

Step 2:

@amsharifian
amsharifian / delete_git_submodule.md
Created February 4, 2020 21:36 — forked from myusuf3/delete_git_submodule.md
How effectively delete a git submodule.

To remove a submodule you need to:

  • Delete the relevant section from the .gitmodules file.
  • Stage the .gitmodules changes git add .gitmodules
  • Delete the relevant section from .git/config.
  • Run git rm --cached path_to_submodule (no trailing slash).
  • Run rm -rf .git/modules/path_to_submodule (no trailing slash).
  • Commit git commit -m "Removed submodule "
  • Delete the now untracked submodule files rm -rf path_to_submodule