Created
June 6, 2015 00:45
-
-
Save apense/5fb468db7289b19474d2 to your computer and use it in GitHub Desktop.
FMA intrinsics with Nim
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
{.passC: "-march=native".} | |
type m128d {.importc: "__m128d", nodecl.} = object | |
proc fma(x,y,z: float32): float32 {.importc: "fma", header: "<math.h>".} | |
proc fma(x,y,z: float64): float64 {.importc: "fmaf", header: "<math.h>".} | |
proc fmadd(x,y,z: m128d): m128d {.importc: "_mm_fmadd_sd", header: "<intrin.h>".} | |
proc loadpd(x: pointer): m128d {.importc: "_mm_load_pd", header: "<intrin.h>".} | |
converter tom128d(f: float): m128d = | |
{.emit: "result = _mm_load_pd(&`f`);".} | |
proc makem128d(s: float): m128d = | |
{.emit: "result = _mm_load_pd(&`s`);".} | |
converter toFloat(m: m128d): float = | |
{.emit: "result = _mm_cvtsd_f64(`m`);".} | |
proc `$`(m: m128d): string = | |
result = $toFloat(m) | |
var | |
o: m128d = 1.0 | |
t: m128d = 2.0 | |
t2: m128d = 3.0 | |
for i in 0..<1000: | |
echo (fmadd(i.toFloat,2.0,3.0)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this is not a good way to do this