Live data from Hacker News

Fixed Point Arithmetic

vha3.github.io

51–60 of 61 posts

Re: Fixed Point Arithmetic

#51

Earlier quoted context omitted.

They are still popular for multiplayer games that has a synced game state. In all clients you want to get exact same results when they run same code which is not possible with fp

“fp” is an unfortunate abbreviation for floating point when contrasted with fixed point.

Hah, thanks for pointing that out, I haven't noticed it

Re: Fixed Point Arithmetic

#52
post #16

I know fixed point was very important back in the days when CPUs didn't have dedicated floating point instructions. How important is it now, when most common CPUs have fast floating point operations? Is there still a performance win? Do games and similar software use them today?

And one additional advantage: in a game I worked on our fixed point class had a fractional part that is in base 10 and it was in thousands (0b1 == 1/1000). This was making fractional numbers add up in the way you expect them in base 10

For example if you have 10 buildings that gives 0.1 crystal everyday, you would gain exactly 1 crystal per day. In the user interface you wouldn't see something like "0.999 crystal per day". And it is not just for pretty tooltips, if there is a game logic that checks ">= 1.0 crystal per day" then that condition is guaranteed to be satisfied after 10 crystal buildings

Re: Fixed Point Arithmetic

#53
Whenever I hear "fixed point arithmetic", it reminds me of the jittery graphics on PSX.

Can't find a more official source than Reddit, but here goes:

> It's because the position of each polygon's vertex (corner) is only calculated at a very low precision. Once the polygon moves (or the camera) the vertexes will stay at the same point, until they're closer to the next and suddenly "jump" to the new position without transition. Newer graphics hardware could interpolate smoothly here with more in-between states (that's where all the talk about "floating point precision" came from in graphics).

0. https://www.reddit.com/r/gaming/comments/bkedc/heres_a_quest...

Re: Fixed Point Arithmetic

#54
post #16

I know fixed point was very important back in the days when CPUs didn't have dedicated floating point instructions. How important is it now, when most common CPUs have fast floating point operations? Is there still a performance win? Do games and similar software use them today?

> Is there still a performance win?

Sometimes. Rarely. Specifically, it's a performance win when you don't need 32 bit of precision, when 8 or 16 bits is enough in these integers. When it happens, you can pack twice as many lanes in the SIMD vectors, and use instructions which view 16-byte vectors as 8 int16_t lanes, or 16 uint8_t lanes.

FP32 is much faster to multiply and especially to divide, compared to Int32.

> Do games and similar software use them today?

Image and video processing code which for some weird reason runs on CPU definitely does.

Re: Fixed Point Arithmetic

#55
post #16

I know fixed point was very important back in the days when CPUs didn't have dedicated floating point instructions. How important is it now, when most common CPUs have fast floating point operations? Is there still a performance win? Do games and similar software use them today?

They are still popular for multiplayer games that has a synced game state. In all clients you want to get exact same results when they run same code which is not possible with fp

Is it really not possible to guarantee the same floating point behavior across different CPUs? I was under the impression that compilers had flags for that kind of thing.

Re: Fixed Point Arithmetic

#56
post #27
post #12

Earlier quoted context omitted.

Do you have numbers for x86? A web search didn't give me a clear answer, especially for non-vectorized code.

In general, recent consumer x86 CPUs will be faster at floating point code than fixed point code. Floating point multiply is already faster than integer multiply; fixed point has the additional cost of the bitshift. (which is very small, but non-zero) Addition/subtraction are similar. Mid-range smartphones will generally have acceptable floating point units, and you should stick to floating point math. If you're targ…

> Fixed point is generally only still useful on embedded.

Also multimedia. Modern CPUs compute FP32 floats equally fast as integers. However, when you only need 8 or 16 bits of precision, RAM bandwidth often dominates computations. Most image and video codecs are still using 8 bits per channel.

Profit from fixed point can be quite large for these use cases. That’s assuming the implementation is good, with SSE2, AVX2 or NEON SIMD.

Re: Fixed Point Arithmetic

#57

Earlier quoted context omitted.

They are still popular for multiplayer games that has a synced game state. In all clients you want to get exact same results when they run same code which is not possible with fp

Is it really not possible to guarantee the same floating point behavior across different CPUs? I was under the impression that compilers had flags for that kind of thing.

I am not the expert but looks like there are some answers (atq2119 and newpavlov) under this thread: https://news.ycombinator.com/item?id=28901751

tldr: it is hard. I was wrong by saying it is "not possible". But I wonder if it is possible if your target platform includes various consoles?

Re: Fixed Point Arithmetic

#58
post #53

Whenever I hear "fixed point arithmetic", it reminds me of the jittery graphics on PSX. Can't find a more official source than Reddit, but here goes: > It's because the position of each polygon's vertex (corner) is only calculated at a very low precision. Once the polygon moves (or the camera) the vertexes will stay at the same point, until they're closer to the next and suddenly "jump" to the new position without tr…

The “jitter” of PSX graphics is caused by a number of factors: https://retrocomputing.stackexchange.com/a/5021

Incidentally, the Nintendo 64 also used fixed point numbers in RDP graphics instructions, but did not exhibit the same visual artifacts as the PlayStation.

Re: Fixed Point Arithmetic

#59
post #45
post #16

I know fixed point was very important back in the days when CPUs didn't have dedicated floating point instructions. How important is it now, when most common CPUs have fast floating point operations? Is there still a performance win? Do games and similar software use them today?

You are correct. This article, written in 2021, does not apply with the motivation stated in the article anymore, outside of niche applications. FP is actually faster in many situations nowadays (for example divisions). If you account for the extra shifts you need for fixed point operations, then FP is certainly faster. Ignoring the reduced range, you can perfectly store integers in FP variables. Even banks could sto…

FP abbreviation is probably not a good idea here, while talking of Floating Point and Fixed Point, a little bit confusing.

Re: Fixed Point Arithmetic

#60
post #47
post #37

Earlier quoted context omitted.

> I know fixed point was very important back in the day So you don't care if your bank account is out by a percent or two? Well, others do.

Sarcasm does not become you. :-) I'm well aware of decimal types, which is what I'd use for currency values. That or "fixed point" integer cents.

Thank you for taking the time to comment, rather than simply down-voting. You are right. I should not comment at the end of a day.
Post reply on HN