This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function code_big_function(n::Int) | |
code = [:( $(Symbol("x$k")) = $(Symbol("x$(k-1)")) + 1 ) for k=1:n] | |
quote | |
let | |
function f(x0) | |
$(code...) | |
return $(Symbol("x$n")) | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module TestSLP | |
function rmw!{T}(dest::Ptr{T}, src::Ptr{T}) | |
s1 = unsafe_load(src, 1) | |
s2 = unsafe_load(src, 2) | |
d1 = unsafe_load(dest, 1) | |
d2 = unsafe_load(dest, 2) | |
d1 $= s1 | |
d2 $= s2 | |
unsafe_store!(dest, d1, 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module TestSIMD5 | |
typealias Uint64x2 NTuple{2, Uint64} | |
function ($)(x::Uint64x2, y::Uint64x2) | |
Base.llvmcall("""%3 = xor <2 x i64> %1, %0 | |
ret <2 x i64> %3""", | |
Uint64x2, (Uint64x2, Uint64x2), x, y) | |
end | |
unsafe_aligned_load(p::Ptr{Uint64}, i::Int) = unsafe_aligned_load(ptradd(p, (i-1)*sizeof(Uint64)*2)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module TestSIMD2 | |
# requires Julia 0.4 for llvmcall | |
typealias Uint64x2 NTuple{2, Uint64} | |
function ($)(x::Uint64x2, y::Uint64x2) | |
Base.llvmcall("""%3 = xor <2 x i64> %1, %0 | |
ret <2 x i64> %3""", | |
Uint64x2, (Uint64x2, Uint64x2), x, y) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module TestSIMD | |
immutable TypeConst{T} end | |
function innerloop!{T, M}(dest::Vector{T}, dest_ofs, src::Vector{T}, src_ofs, ::TypeConst{M}) | |
@simd for i=1:M | |
@inbounds dest[i + dest_ofs] $= src[i + src_ofs] | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright (c) 2014: Toivo Henningsson | |
# | |
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | |
# | |
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | |
# | |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_ _ _(_)_ | A fresh approach to technical computing | |
(_) | (_) (_) | Documentation: http://docs.julialang.org | |
_ _ _| |_ __ _ | Type "help()" to list help topics | |
| | | | | | |/ _` | | | |
| | |_| | | | (_| | | Version 0.0.0+105549818.rb65f | |
_/ |\__'_|_|_|\__'_| | Commit b65f0478b4 (2012-12-26 20:02:44) | |
|__/ | | |
julia> include("test_show_dispatch.jl") | |
type error: subtype: expected Type{T<:Top}, got (CompositeKind,{:i0, Int64, #undef, #undef, #undef … :vals, Array{Any,1}, :#s176, Int64}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
is_expr(ex, head::Symbol) = (isa(ex, Expr) && (ex.head == head)) | |
is_expr(ex, head::Symbol, n::Int) = is_expr(ex, head) && length(ex.args) == n | |
# simple syntax version | |
macro get!(d, k, default) | |
quote | |
d, k = $(esc(d)), $(esc(k)) | |
has(d, k) ? d[k] : (d[k] = $(esc(default))) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ---- @sexpr: S-expression to AST conversion ---- | |
is_expr(ex, head::Symbol) = (isa(ex, Expr) && (ex.head == head)) | |
is_expr(ex, head::Symbol, n::Int) = is_expr(ex, head) && length(ex.args) == n | |
macro sexpr(ex) | |
esc(sexpr_to_expr(ex)) | |
end | |
sexpr_to_expr(ex) = expr(:quote, ex) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
show_sexpr(ex) = show_sexpr(OUTPUT_STREAM, ex) | |
show_sexpr(io::IO, ex) = show_sexpr(io, ex, 0) | |
show_sexpr(io::IO, ex, indent::Int) = show(io, ex) | |
const sexpr_indent_width = 2 | |
function show_sexpr(io::IO, ex::Expr, indent::Int) | |
inner = indent + sexpr_indent_width | |
if (ex.head === :block) inter, post = ("\n"*" "^inner, "\n"*" "^indent) | |
else inter, post = (" ", "") |
NewerOlder