FAQ
I created a Go implementation of the Parks–McClellan filter design
algorithm. C and Ruby implementations were compared. There's a Fortran
example too but I'm not going to try compiling code from 1972.

The source is here:
https://github.com/AE9RB/firpm

Times from a 3.0GHz Core 2 Duo:

          C: 2.07ms
         Go: 3.03ms
Ruby 2.0.0: 85.50ms
Ruby 1.9.2: 190.02ms


If you check that the computed results match you will find that they do not. Sin and Cos in Go uses a different algorithm than clang (and probably gcc). See for yourself:


package main

// #include <math.h>

import "C"

import "fmt"

import "math"

func main() {

  fmt.Println(C.cos(math.Pi / 2))

  fmt.Println(math.Cos(math.Pi / 2))

}


In practice, the firpm results are accurate enough that the filters will perform identically. However, writing tests against a C reference implementation is difficult. It's possible there's a bug introducing inaccuracy beyond Sin and Cos differences. I suppose I could swap in a new math library that made C calls for testing. But I won't yet because I just wanted a rough idea of Go performance for the kinds of problems I was hoping to use it for.


Looking at the Go source I see a lot of i386 assembly for math which uses FPU hardware but the amd64 uses Go code. I'm probably going to write a float32 math library so I'll have to learn more about why this is.


-david from OreGOn


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Ian Lance Taylor at Mar 7, 2014 at 7:28 pm

    On Fri, Mar 7, 2014 at 11:19 AM, David Turnbull wrote:
    Looking at the Go source I see a lot of i386 assembly for math which uses
    FPU hardware but the amd64 uses Go code. I'm probably going to write a
    float32 math library so I'll have to learn more about why this is.
    On i386 we use assembly in order to use the 387 fsin instruction.

    On amd64 we use the SSE floating point registers so the Go code is a
    better choice.

    Ian

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedMar 7, '14 at 7:19p
activeMar 7, '14 at 7:28p
posts2
users2
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase