Skip to content

Instantly share code, notes, and snippets.

@ramntry
ramntry / main.cpp
Created May 5, 2019
Very pretty triangle (OpenGL)
View main.cpp
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdocumentation"
#define GLEW_STATIC
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#pragma clang diagnostic pop
#include <iostream>
@ramntry
ramntry / float.cpp
Last active Aug 9, 2018
IEEE-754 single precision software implementation
View float.cpp
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <bitset>
#include <limits>
#include <cassert>
using namespace std;
struct single {
View slp.c
double foo(double *a, int n) {
double x = 0.0;
double y = 0.0;
for (int i = 0; i < n; i += 2) {
x += a[i];
y += a[i + 1];
}
return x * y;
}
View SCEV.md
  // |  Expression   |     ConstantRange      |       KnownBits       |
  // |---------------|------------------------|-----------------------|
  // | i8 4 * X      | [L: 0, U: 253)         | XXXX XX00             |
  // |               |   => Min: 0, Max: 252  |   => Min: 0, Max: 252 |
  // |               |                        |                       |
  // | i8 4 * X + 5  | [L: 5, U: 2) (wrapped) | YYYY YY01             |
  // |         (101) |   => Min: 0, Max: 255  |   => Min: 1, Max: 253 |
View isItPythonOrJavaScript.m
#import <Foundation/Foundation.h>
#include <stdio.h>
@interface NSString (MyPrintable)
- (const char *)toCString;
@end
@implementation NSString (MyPrintable)
// NSString is a library provided class that doesn't have
// a toCString method. We're dynamically extending the class
View set_difference_size.cpp
#include <algorithm>
#include <iostream>
#include <iterator>
#include <list>
template <typename T>
class Counter : public std::iterator<std::output_iterator_tag, T> {
size_t &Value;
public:
View test_cons.ll
%dag = type { { { i8, { i8 } }, { { i8, { i8 } }, { i8 } } }, { { i8, { i8 } }, { i8 } } }
define void @test_const(%dag* %dst) {
entry:
%updated = insertvalue
; Check that we're visiting constants with shared parts
; (deduplicated via LLVMContext, forming a proper DAG) correctly:
%dag {
{ { i8, { i8 } }, { { i8, { i8 } }, { i8 } } } {
{ i8, { i8 } } {
View test_phi_loop.ll
define i64 @test_phi_loop(i32 %n) {
entry:
br label %loop
loop:
%counter = phi i32 [ %n, %entry ], [ %counter.dec, %loop ]
%elem = phi { i64, i64 } [ { i64 0, i64 1 }, %entry ], [ %updated, %loop ]
%prev = extractvalue { i64, i64 } %elem, 0
%curr = extractvalue { i64, i64 } %elem, 1
%next = add i64 %prev, %curr
View test_phi_diamond.ll
define void @test_phi_diamond({ i8, i16, i32 }* %a.ptr, { i8, i16, i32 }* %b.ptr, i1 %selector, { i8, i16, i32 }* %dst) {
entry:
br i1 %selector, label %store.a, label %store.b
store.a:
%a = load { i8, i16, i32 }, { i8, i16, i32 }* %a.ptr
br label %join
store.b:
%b = load { i8, i16, i32 }, { i8, i16, i32 }* %b.ptr
@ramntry
ramntry / main.cpp
Created Sep 22, 2017
No virtual member function templates in C++03 through C++14
View main.cpp
#include <iostream>
#include <memory>
struct A {
virtual void foo() const {
std::cout << "virtual A::foo()'s called" << std::endl;
}
};
struct B {
You can’t perform that action at this time.