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 sincos(x) | |
psin = Cdouble[0]; pcos = Cdouble[0] | |
ccall(:sincos, Void, (Cdouble, Ptr{Cdouble}, Ptr{Cdouble}), x, psin, pcos) | |
psin[1], pcos[1] | |
end | |
function foo(X) | |
ta = 0.0 | |
tb = 0.0 | |
for x in X |
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 getmxcsr() | |
Base.llvmcall("""%ptr = alloca i32 | |
call void @llvm.x86.sse.stmxcsr(i32 * %ptr) | |
%curval = load i32 * %ptr | |
ret i32 %curval""", UInt32, ()) | |
end | |
function setmxcsr(u::UInt32) | |
Base.llvmcall("""%ptr = alloca i32 | |
store i32 %0, i32 * %ptr |
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 rint_llvm(x::Float64) | |
Base.llvmcall("""%x = call double @llvm.rint.f64(double %0) | |
ret double %x""",Float64,(Float64,),x) | |
end | |
function trunc_llvm(x::Float64) | |
Base.llvmcall("""%x = call double @llvm.trunc.f64(double %0) | |
ret double %x""",Float64,(Float64,),x) | |
end | |
# warm up llvmcall: ignore errors |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
# use floating point AND instructions (andps/andpd) | |
# https://github.com/JuliaLang/julia/issues/9868 | |
function and_float(x::Float64,y::Float64) | |
Base.llvmcall("""%av = insertelement<2 x double> undef, double %0, i32 0 | |
%bv = insertelement<2 x double> undef, double %1, i32 0 | |
%ai = bitcast <2 x double> %av to <2 x i64> | |
%bi = bitcast <2 x double> %bv to <2 x i64> | |
%and.i = and <2 x i64> %ai, %bi | |
%cf = bitcast <2 x i64> %and.i to <2 x double> | |
%cfe = extractelement<2 x double> %cf, i32 0 |
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
#include <stdio.h> | |
#include <math.h> | |
int main() { | |
volatile double a = 0.1; | |
volatile double x = a + 0.2; | |
printf("%.20f\n", x); | |
volatile double y = fma(a, 1.0, 0.0); | |
printf("%.20f\n", y); | |
volatile double z = y + 0.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
include <stdio.h> | |
#include <stdlib.h> | |
#include <math.h> | |
static double fct (double a) | |
{ | |
double x = fma(a,a,-a); | |
return 1.0 - x; | |
} |
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 sincos(x::Float64) | |
s = Ref{Float64}() | |
c = Ref{Float64}() | |
ccall((:sincos,Base.Math.libm),Void,(Float64,Ref{Float64},Ref{Float64}),x,s,c) | |
return s.x, c.x | |
end | |
function test_sep(X) | |
t = 0.0 |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 winenvs(var) | |
# Win: ansi | |
len = ccall(:GetEnvironmentVariableA,stdcall,Uint32,(Ptr{Uint8},Ptr{Uint8},Uint32),var,C_NULL,0) | |
if len > 0 | |
val=zeros(Uint8,len) | |
ccall(:GetEnvironmentVariableA,stdcall,Uint32,(Ptr{Uint8},Ptr{Uint8},Uint32),var,val,len) | |
win_a = bytestring(val) | |
else | |
win_a = "" |
OlderNewer