Skip to content

Instantly share code, notes, and snippets.

namespace InlineTest
module MyArray =
let inline fold<'T,'State> (f : 'State -> 'T -> 'State) (acc: 'State) (array:'T[]) =
let mutable state = acc
let len = array.Length
for i = 0 to len - 1 do
state <- f state array.[i]
state
let inline sumBy (f: ^U -> _) array =
@ranma42
ranma42 / InlineTest.fs
Created December 7, 2013 01:45
Test for inline functions which try to access properties
namespace InlineTest
module Types =
type IFace =
abstract member Prop : obj
type IFace1 =
inherit IFace
abstract member Prop : int
@ranma42
ranma42 / let-in.fs
Created February 3, 2014 10:06
Counter-intuitive behaviour of the let-in construct
let working () =
let a = 6 in
begin // or (
printfn "%A" a
let a = 5 in
printfn "%A" a
end // or )
let b = a in
printfn "%A" b
@ranma42
ranma42 / let-in-interactive.fsx
Created February 3, 2014 10:37
Different combinations of let[-in] expression in the F# interactive
let a = 3
a + 4
;;
(* =>
val a : int = 3
val it : int = 7
*)
a + 5
;;
@ranma42
ranma42 / bench-slice-cmp.rs
Created September 16, 2015 07:26
Benchmark for slice comparison in Rust
#![feature(iter_order)]
#![feature(test)]
extern crate test;
macro_rules! gen_bench {
($name:ident, $x: expr, $y: expr) => {
#[bench]
fn $name(b: &mut Bencher) {
b.iter(|| { black_box($x).$name(black_box($y)) })
}
@ranma42
ranma42 / enum4.ll
Created September 30, 2015 09:30
Experiments with removal of identical code blocks
; ModuleID = 'enum4.0.rs'
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-darwin"
%E32 = type { i32, [0 x i32], [1 x i32] }
; Function Attrs: inlinehint nounwind readonly uwtable
define zeroext i1 @_ZN25E32...std..cmp..PartialEq2eq20h5da5b35084c7cd82taaE(%E32* noalias nocapture readonly dereferenceable(8), %E32* noalias nocapture readonly dereferenceable(8)) unnamed_addr #0 {
entry-block:
%2 = getelementptr inbounds %E32, %E32* %0, i64 0, i32 0
test.o: file format elf32-i386
Disassembly of section .text:
00000000 <add>:
0: 83 ec 0c sub $0xc,%esp
3: f2 0f 10 44 24 10 movsd 0x10(%esp),%xmm0
9: f2 0f 58 44 24 18 addsd 0x18(%esp),%xmm0
@ranma42
ranma42 / 0001-Combine-GEPs.patch
Last active December 2, 2016 15:50
Patch to combine GEPs
From fe155df2fd7778c6602696055f7ebd0ddf433c3d Mon Sep 17 00:00:00 2001
From: Andrea Canciani <ranma42@gmail.com>
Date: Fri, 2 Dec 2016 16:21:02 +0100
Subject: [PATCH] Combine GEPs
---
lib/Transforms/InstCombine/InstructionCombining.cpp | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/lib/Transforms/InstCombine/InstructionCombining.cpp b/lib/Transforms/InstCombine/InstructionCombining.cpp
@ranma42
ranma42 / bluss.s
Created December 3, 2016 10:10
Assembly output of the original example for https://github.com/rust-lang/rust/pull/37921
.text
.file "bluss.cgu-0.rs"
.section .text._ZN5bluss16round_trip_slice17h8927e0fb49da9351E,"ax",@progbits
.globl _ZN5bluss16round_trip_slice17h8927e0fb49da9351E
.p2align 4, 0x90
.type _ZN5bluss16round_trip_slice17h8927e0fb49da9351E,@function
_ZN5bluss16round_trip_slice17h8927e0fb49da9351E:
.cfi_startproc
movq %rdi, %rax
movq %rsi, %rdx
@ranma42
ranma42 / HOMEBREW_MAKE_JOBS=1 VERBOSE=1 brew install cairo
Created January 19, 2017 11:16
Installing cairo on tigerbrew (without python 2.5)
==> Installing dependencies for cairo: glib
==> Installing cairo dependency: glib
==> Downloading https://download.gnome.org/sources/glib/2.50/glib-2.50.1.tar.xz
Already downloaded: /Library/Caches/Homebrew/glib-2.50.1.tar.xz
==> Verifying glib-2.50.1.tar.xz checksum
==> Downloading https://raw.githubusercontent.com/Homebrew/patches/59e4d327791d4fe3423c2c871adb98e3f3f07633/glib/hardcoded-paths.diff
Already downloaded: /Library/Caches/Homebrew/glib--patch-a4cb96b5861672ec0750cb30ecebe1d417d38052cac12fbb8a77dbf04a886fcb.diff
==> Verifying glib--patch-a4cb96b5861672ec0750cb30ecebe1d417d38052cac12fbb8a77dbf04a886fcb.diff checksum
==> Downloading https://raw.githubusercontent.com/Homebrew/formula-patches/a39dec26/glib/gio.patch
Already downloaded: /Library/Caches/Homebrew/glib--patch-284cbf626f814c21f30167699e6e59dcc0d31000d71151f25862b997a8c8493d.patch