Skip to content

Instantly share code, notes, and snippets.

View dfyz's full-sized avatar

Ivan Komarov dfyz

View GitHub Profile
@dfyz
dfyz / gist:ba08c7257740c2afb0e4892877368691
Created February 4, 2019 00:21
Alpha LLVM test drive
$ cat fib.c
int fib(int n) {
int a = 0;
int b = 0;
int c = 1;
if (n <= 0) {
return 0;
}
from mpmath import mp, mpf
import struct
import sys
def cvt(f):
return struct.unpack('d', struct.pack('Q', f))[0]
def centroid(poly):
type Point = (f64, f64);
const POLY: &[Point] = &[
(40547359.805348977, 20991407.4519994),
(40547406.539216213, 20991408.345532853),
(40547405.607148655, 20991456.331498079),
(40547358.891922772, 20991455.404874228),
];
fn naive_centroid(poly: &[Point]) -> Point {
#include <iomanip>
#include <iostream>
#include <boost/geometry.hpp>
int main() {
using point_type = boost::geometry::model::d2::point_xy<double>;
using polygon_type = boost::geometry::model::polygon<point_type>;
polygon_type poly {{
{40547359.805348977, 20991407.4519994},
@dfyz
dfyz / boot.sh
Created August 5, 2019 22:23
QEMU for Alpha boot script
#! /bin/sh
sim=qemu-system-alpha # insert any needed path/prefix here
$sim -smp 4 -m 1024 \
-kernel vmlinux \
-nographic \
-serial null -monitor null \
-drive file=disk.img,if=virtio,media=disk,format=raw,index=0 \
-net nic,model=virtio -net tap,helper=/usr/libexec/qemu-bridge-helper,br=virbr0 \
@dfyz
dfyz / bench.txt
Last active August 5, 2019 23:17
DEC Alpha GCC vs. Clang benchmark
**************
*** X86_64 ***
**************
~/alpha-test-programs/fib $ time echo 40 | ./a.out
102334155
102334155
real 0m0.661s
user 0m0.658s
fn do_test(x: usize) {
let arr = vec![vec![0u8; 3]];
let mut z = Vec::new();
for arr_ref in arr {
for y in 0..x {
for _ in 0..1 {
z.extend(std::iter::repeat(0).take(x));
let a = y * x;
let b = (y + 1) * x - 1;
@dfyz
dfyz / main.ll
Created February 23, 2020 03:02
; ModuleID = 'main.7rcbfp3g-cgu.2'
source_filename = "main.7rcbfp3g-cgu.2"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
%"alloc::vec::Vec<i32>" = type { [0 x i64], { i32*, i64 }, [0 x i64], i64, [0 x i64] }
%"unwind::libunwind::_Unwind_Exception" = type { [0 x i64], i64, [0 x i64], void (i32, %"unwind::libunwind::_Unwind_Exception"*)*, [0 x i64], [6 x i64], [0 x i64] }
%"unwind::libunwind::_Unwind_Context" = type { [0 x i8] }
@vtable.0.llvm.14851218111650171626 = external hidden unnamed_addr constant { void (i8**)*, i64, i64, i32 (i8**)*, i32 (i8**)*, i32 (i8**)* }, align 8
fn do_test(x: usize) {
let arr = vec![vec![0u8; 3]];
let mut z = vec![0];
for arr_ref in arr {
for y in 0..x {
for _ in 0..1 {
z.reserve_exact(x);
let iterator = std::iter::repeat(0).take(x);
let mut cnt = 0;
#include <ctype.h>
#include <stdio.h>
int openbsd_check(const char* line) {
if (isdigit((int)*line) && *(line + 1) == '.' &&
isdigit((int)*line+2) && *(line + 3) == '.' &&
isdigit((int)*line+4) && isspace((int)*(line + 5)))
return 1;
else
return 0;