Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider finding (or writing if need be) a float32 native math library #28

Open
UserAB1236872 opened this issue Aug 3, 2014 · 8 comments

Comments

@UserAB1236872
Copy link
Member

After writing some benchmarks today (not for this package, just dicking around with benchmarking fast inverse square root compared to Go's stdlib and such), it's become clear that the rampant type conversions are a significant performance hit. "Significant" is in relative terms, but code of the form:

float32(1.0 / math.Sqrt(float64(n)))

takes about 15.5 ns/op compared to 3.5 ns/op for float64-native. I suspected this, hence why this library generally takes a "convert as infrequently as possible" approach. However, I would consider this significant enough to be worth worrying about.

While Go's standard library is written partially in assembly, I don't think it should be too difficult to rewrite (I think most of the assembly conversions would amount to "swap a letter in the instruction names to do 32-bit operations instead"). However, I'd like to look into existing options if they exist before undertaking this.

I did find this, but the repository was deleted for some ominous reason.

@ghost
Copy link

ghost commented May 8, 2015

Couldnt we just download all the files from the original math package and do a fancy find and replace for float64->float32 then fix the 2-3 other mistakes it caused ?

@UserAB1236872
Copy link
Member Author

It's largely in assembly, so it's not quite that simple.

On Fri, May 8, 2015 at 12:45 PM, Olivier Gagnon [email protected]
wrote:

Couldnt we just download all the files from the original math package and
do a fancy find and replace for float64->float32 then fix the 2-3 other
mistakes it caused ?


Reply to this email directly or view it on GitHub
#28 (comment).

@UserAB1236872
Copy link
Member Author

Granted, we could possibly do a find+replace on the assembly instructions
too, but we'd have to do a lot of testing to ensure we didn't bork
something.

On Fri, May 8, 2015 at 1:11 PM, Jeff Juozapaitis [email protected]
wrote:

It's largely in assembly, so it's not quite that simple.

On Fri, May 8, 2015 at 12:45 PM, Olivier Gagnon [email protected]
wrote:

Couldnt we just download all the files from the original math package and
do a fancy find and replace for float64->float32 then fix the 2-3 other
mistakes it caused ?


Reply to this email directly or view it on GitHub
#28 (comment).

@ghost
Copy link

ghost commented May 8, 2015

Yeah im working on it

@ghost
Copy link

ghost commented May 8, 2015

Benchmark32Sqrt 1000000000           2.52 ns/op
Benchmark64Sqrt 300000000            4.98 ns/op
ok      math32  4.786s

First results look promising

@ghost
Copy link

ghost commented May 13, 2015

@ghost
Copy link

ghost commented Jul 18, 2015

No seriously are we getting anywhere on this.

@UserAB1236872
Copy link
Member Author

If you (or someone) submits a PR, I'd be happy to accept it. It should be a relatively straightforward patch to the generator code to sub your library for native match for the f32 version. I don't have time at the moment due to PhD stuff.

@dmitshur dmitshur mentioned this issue Apr 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant