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

Use fixed point math instead of floating. #10

Open
nigeltao opened this issue Aug 20, 2016 · 3 comments
Open

Use fixed point math instead of floating. #10

nigeltao opened this issue Aug 20, 2016 · 3 comments

Comments

@nigeltao
Copy link

I've ported font-rs to the Go programming language.

Using fixed point math instead of floating sped up my rasterization benchmarks by between 1.2x and 1.4x.

Perhaps font-rs should do that too.

The font-go commit: google/font-go@4bf4d10

@raphlinus
Copy link
Owner

Thanks! This definitely looks worth investigating.

@jrmuizel
Copy link

How did you decide on 20.12 split?

@nigeltao
Copy link
Author

The 20.12 split is what happens when you multiply two 26.6 fixed point values.

The 26.6 split is arbitrary, but Go's extended standard library already had a 26.6 fixed point integer type (in the golang.org/x/image/math/fixed package), so it was easy to start with that.

Since then, I've moved to 22.10 instead of 26.6 (adding some ad hoc int64 instead of int32 math) so when you multiply you get 12.20. This (and other patches) reduced some rounding errors, so that the fixed point rasterizer, when rasterizing a regular polygon, yields 0x00 pixels in the corners and an 0xff pixel in the center, all the way up to 2048 ppem. Previously, you would sometimes see a 0x01 or 0x05, say, in the corners or a 0xfe in the center, which isn't noticable to the naked eye, but is clearly incorrect.

Net some other changes, the fixed point code is still around 1.3x faster than the floating point code.

See recent commits in https://github.com/google/font-go for more details.

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

3 participants