c - Why does MSVS not optimize away +0? Instead, it turns it into a denormalized float? -
this question demonstrates interesting phenomenon: denormalized floats slow down code more order of magnitude.
the behavior explained in accepted answer. however, there 1 comment, 48 upvotes, cannot find satisfactory answer to:
why isn't compiler dropping +/- 0 in case?!? – michael dorgan
side note: have impression 0f is/must representable (furthermore - it's binary representation must zeroes), can't find such claim in c11 standard. quote proving this, or argument disproving claim, welcome. regardless, michael's question main question here.
an implementation may give 0 , values not floating-point numbers (such infinities , nans) sign or may leave them unsigned.
the compiler cannot eliminate addition of floating-point positive 0 because not identity operation. ieee 754 rules, result of adding +0. -0. not -0.; +0.
the compiler may eliminate subtraction of +0. or addition of -0. because identity operations.
for example, when compile this:
double foo(double x) { return x + 0.; }
with apple gnu c 4.2.1 using -o3
on intel mac, resulting assembly code contains addsd lc0(%rip), %xmm0
. when compile this:
double foo(double x) { return x - 0.; }
there no add instruction; assembly merely returns input.
so, code in original question contained add instruction statement:
y[i] = y[i] + 0;
but contained no instruction statement:
y[i] = y[i] - 0;
however, first statement involved arithmetic subnormal values in y[i]
, sufficient slow down program.
Comments
Post a Comment