|
Message-ID: <20210814234612.GH37904@port70.net> Date: Sun, 15 Aug 2021 01:46:12 +0200 From: Szabolcs Nagy <nsz@...t70.net> To: Stefan Kanthak <stefan.kanthak@...go.de> Cc: musl@...ts.openwall.com Subject: Re: [PATCH #2] Properly simplified nextafter() * Stefan Kanthak <stefan.kanthak@...go.de> [2021-08-13 14:04:51 +0200]: > Szabolcs Nagy <nsz@...t70.net> wrote on 2021-08-10 at 23:34: > > it's target dependent if float compares are fast or not. > > It's also target dependent whether the FP additions and multiplies > used to raise overflow/underflow are SLOOOWWW: how can you justify > them, especially for targets using soft-float? for fenv side-effects, using fp arithmetic or conversion operations are ideal. i pointed out the new subnormal handling cases your patch introduced because it was not clear that you considered it. i'm mainly concerned about the performance of the common cases, not rare special cases. > > (the i386 machine where i originally tested this preferred int > > cmp and float cmp was very slow in the subnormal range > > This also and still holds for i386 FPU fadd/fmul as well as SSE > addsd/addss/mulss/mulsd additions/multiplies! they are avoided in the common case, and only used to create fenv side-effects. > --- -/src/math/nextafter.c > +++ +/src/math/nextafter.c > @@ -10,13 +10,13 @@ > return x + y; > if (ux.i == uy.i) > return y; > - ax = ux.i & -1ULL/2; > - ay = uy.i & -1ULL/2; > + ax = ux.i << 2; > + ay = uy.i << 2; the << 2 looks wrong, the top bit of the exponent is lost. > if (ax == 0) { > if (ay == 0) > return y; > ux.i = (uy.i & 1ULL<<63) | 1; > - } else if (ax > ay || ((ux.i ^ uy.i) & 1ULL<<63)) > + } else if ((ax < ay) == ((int64_t) ux.i < 0)) > ux.i--; > else > ux.i++; ... > How do you compare these 60 instructions/252 bytes to the code I posted > (23 instructions/72 bytes)? you should benchmark, but the second best is to look at the longest dependency chain in the hot path and add up the instruction latencies.
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.