Skip to content

Instantly share code, notes, and snippets.

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
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 September 22, 2017 18:41
No virtual member function templates in C++03 through C++14
#include <iostream>
#include <memory>
struct A {
virtual void foo() const {
std::cout << "virtual A::foo()'s called" << std::endl;
}
};
struct B {
@ramntry
ramntry / timus1469.cpp
Created December 9, 2012 11:15
SweepLine
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
using namespace std;
typedef int RingElement;
struct Vector
var arr = [];
for (var i = 0; i < 30000; i++) {
arr.push(Math.round(Math.random() * 1.0e9).toString());
}
Array.prototype.diff = function(a) {
return this.filter(function(i) { return !(a.indexOf(i) > -1); });
};
for (var i = 0; i < 20; ++i) {
var arr = [];
for (var i = 0, l = 100*1000; i < l; i++) {
arr.push(Math.round(Math.random() * l))
}
Array.prototype.diff = function(a) {
return this.filter(function(i) {return !(a.indexOf(i) > -1);});
};
for (var i = 0; i < 10; ++i) {
.CODE
CpuidTestBit MACRO REG, BITNUM
mov r8, rbx
mov rax, 1
cpuid
xor rax, rax
bt REG, BITNUM
setc al
mov rbx, r8
@ramntry
ramntry / generic.c
Created November 7, 2013 10:43
_Generic in C11
#include <stdio.h>
#define NUMTOSTR_DEF_IMPL_FOR(type) \
const char *numtostr_impl_for_##type(type num, const char *format) \
{ \
static char buf[64]; \
sprintf(buf, format, num); \
return buf; \
}
let discriminant a b c =
b * b - 4 * a * c
#include <iostream>
long long fib_00(int n) {
if (n < 3)
return 1;
return fib_00(n - 1) + fib_00(n - 2);
}
long long fib_01(int n) {
if (n < 3)