5 ms·
The author admits this ia a contrived demo, but I'm still trying to understand its ostensible logic. The FTZ/DAZ problem is on line 20: if (x >= nextafter
by an1sotropy 4y ago
The author admits this ia a contrived demo, but I'm still trying to understand its ostensible logic. The FTZ/DAZ problem is on line 20:
if (x >= nextafterf(0.0, INFINITY)) {
I think the idea here is: test if x is large enough so that the subsequent ceilf() will give you an integer i_x >= 1 (because the actual array index will be PIXBUF_WIDTH - i_x, and the max array index is PIXBUF_WIDTH-1). With FTZ/DAZ, nextafterf(0.0, INFINITY) == 0, which breaks the test.
But in this scenario, wouldn't you just test "if (x > 0)", since that implies that ceilf(x) must be >= 1?
- moyix 4y agoUpdates welcome to make it less contrived! :) It's clearly very confused code, but it does work under normal FP behavior.
- an1sotropy 4y agoThank you for creating and sharing this example. I think the fact of merely loading a shared library as modifying the FP behavior is the real shocker, more than any particular FP computation that hinges on denormals. Still, I think one of the great wins with denormals is that they make "x == y iff x-y == 0" true; absent denormals you can have two normalized x and y, x != y, such y-x evaluates to 0. So for an example, maybe something that involves y > x and yet ceil(y-x) == 0, which is surprising. The only setting I can think of is something like making a histogram (with flipped indices, like your pixel row) of differences of values, so that ceil(y-x) == 0 leads to an invalid histogram index. Some values are x=1e-32 and y=1.0000011e-32, which parse (via sscanf) to: x = 0:00010100:10011111011000100011111 = (-1)^0 * 2^( 20-127) * (1+5222687/2^23) y = 0:00010100:10011111011000100101110 = (-1)^0 * 2^( 20-127) * (1+5222702/2^23) and then the denormalized difference d = x-y should be: d = 0:00000000:11110000000000000000000 = (-1)^0 * 2^(1-127) * (0+7864320/2^23) Having some specific values sidesteps concerns about nextafterf(). In this case I think y is many ulps above x, not just 1.
- moyix 4y agoThanks for this excellent idea! I implemented it in this histogram plotting demo: https://github.com/moyix/2_ffast_2_furious https://github.com/moyix/2_ffast_2_furious
- an1sotropy 4y agoHoly moly you've converted my little idea into a lovely demo! Thanks for showcasing this and sorry to be slow to notice.