Skip to content

Instantly share code, notes, and snippets.

@OlivierLi
Last active October 6, 2017 15:18
Show Gist options
  • Save OlivierLi/b0d3530b0a9470d4424d627d0b7e20ce to your computer and use it in GitHub Desktop.
Save OlivierLi/b0d3530b0a9470d4424d627d0b7e20ce to your computer and use it in GitHub Desktop.
#include <iostream>
#include <atomic>
#include <vector>
#include <thread>
// The point of this exercise is to implement a minimal demonstration and then quickly discuss the performance and correctness
// implications of the technique, if any.
// Example for loop unrolling:
// This function will multiply the fist 4 numbers of the array by 4
void loop_unroll(int* values){
// Loop form
for(size_t i=0;i<4;++i){
values[i]*=4;
}
// Unrolled form
values[0]*=4;
values[1]*=4;
values[2]*=4;
values[4]*=4;
}
// Dicusion
/*
The goal of the unrolling is to save execution time by avoiding the overhead of the loop control.
Realistically using a modern compiler in this example the unrolling will have zero effect as both forms
will get vectorized in the same way.
*/
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Atomics
void atomics(){
return;
}
// Return value optimization
void rvo(){
return;
}
#define likely(x) __builtin_expect((x),1)
#define unlikely(x) __builtin_expect((x),0)
// Branch prediction hints
void branch_predict( char* value = nullptr){
return;
}
// Executing a function asynchronously
void async(char * value){
return;
}
// Small string optimization
class sso_string_t{
};
__int64 _mm_popcnt_u64 (unsigned __int64 a);
// Inline assembly
void inline_asm(){
return;
}
// Weak pointers
void weak_ptr(){
return;
}
// std algorithms
void std_algo(){
return;
}
// Template meta progamming
template<typename T>
void template_meta(){
return;
}
// Constexpr functions
constexpr void func(){
return;
}
// static assert
void assert(){
return;
}
// struct packing
void pack(){
return;
}
// lambdas
void lambda(){
return;
}
// bit manipulation
void bit_manip(){
return;
}
// Divide and conquer type algorithm
void d_and_c(){
return;
}
// unions
void unions(){
return;
}
// move semantics
void move_sem(){
return;
}
int main(int argc, char** argv) {
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment