Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.arch > #32659 > unrolled thread
| Started by | "Skybuck Flying" <skybuck2000@hotmail.com> |
|---|---|
| First post | 2016-01-11 16:44 +0100 |
| Last post | 2016-01-11 23:46 -0800 |
| Articles | 20 on this page of 192 — 45 participants |
Back to article view | Back to comp.arch
Intel's Skylake Prime Number Bug. "Skybuck Flying" <skybuck2000@hotmail.com> - 2016-01-11 16:44 +0100
Re: Intel's Skylake Prime Number Bug. Larc <larc@notmyaddress.com> - 2016-01-11 11:10 -0500
Re: Intel's Skylake Prime Number Bug. "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-01-11 10:16 -0800
Re: Intel's Skylake Prime Number Bug. "Skybuck Flying" <skybuck2000@hotmail.com> - 2016-01-11 21:44 +0100
Re: Intel's Skylake Prime Number Bug. "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-01-11 13:06 -0800
Re: Intel's Skylake Prime Number Bug. "Skybuck Flying" <skybuck2000@hotmail.com> - 2016-01-12 16:35 +0100
Re: Intel's Skylake Prime Number Bug. DecadentLinuxUserNumeroUno <DLU1@DecadentLinuxUser.org> - 2016-01-12 12:53 -0500
Re: Intel's Skylake Prime Number Bug. Mark - <nonemail@spamspamapam.net> - 2016-01-12 20:00 +0000
Re: Intel's Skylake Prime Number Bug. Larc <larc@notmyaddress.com> - 2016-01-12 16:54 -0500
Re: Intel's Skylake Prime Number Bug. Mark - <nonemail@spamspamapam.net> - 2016-01-12 22:14 +0000
Re: Intel's Skylake Prime Number Bug. "wolfgang kern" <nowhere@never.at> - 2016-01-12 19:53 +0100
Re: Intel's Skylake Prime Number Bug. Paul <nospam@needed.com> - 2016-01-11 16:55 -0500
Re: Intel's Skylake Prime Number Bug. B00ze <B00ze64@hotmail.com> - 2016-01-11 23:48 -0500
Re: Intel's Skylake Prime Number Bug. John Larkin <jjlarkin@highlandtechnology.com> - 2016-01-11 10:22 -0800
Re: Intel's Skylake Prime Number Bug. Jerry Stuckle <jstucklex@attglobal.net> - 2016-01-11 13:42 -0500
Re: Intel's Skylake Prime Number Bug. John Larkin <jjlarkin@highlandtechnology.com> - 2016-01-11 11:12 -0800
Re: Intel's Skylake Prime Number Bug. David Brown <david.brown@hesbynett.no> - 2016-01-12 11:06 +0100
Re: Intel's Skylake Prime Number Bug. Richard Heathfield <rjh@cpax.org.uk> - 2016-01-12 10:21 +0000
Re: Intel's Skylake Prime Number Bug. David Brown <david.brown@hesbynett.no> - 2016-01-12 11:42 +0100
t cluttered John Larkin <jjlarkin@highlandtechnology.com> - 2016-01-12 09:25 -0800
Re: t cluttered David Brown <david.brown@hesbynett.no> - 2016-01-12 22:05 +0100
Re: t cluttered Ivan Godard <ivan@millcomputing.com> - 2016-01-12 14:03 -0800
Re: t cluttered Stephen Fuld <SFuld@alumni.cmu.edu.invalid> - 2016-01-12 21:44 -0800
Re: t cluttered Terje Mathisen <terje.mathisen@tmsw.no> - 2016-01-13 15:41 +0800
Re: t cluttered krw <krw@nowhere.com> - 2016-01-13 21:39 -0500
Re: t cluttered Quadibloc <jsavard@ecn.ab.ca> - 2016-01-13 00:52 -0800
Re: t cluttered already5chosen@yahoo.com - 2016-01-13 02:39 -0800
Re: t cluttered Rick Jones <rick.jones2@hpe.com> - 2016-01-12 22:41 +0000
Re: t cluttered nmm@wheeler.UUCP (Nick Maclaren) - 2016-01-12 23:01 +0000
Re: t cluttered Ivan Godard <ivan@millcomputing.com> - 2016-01-12 16:16 -0800
Re: t cluttered nmm@wheeler.UUCP (Nick Maclaren) - 2016-01-13 10:35 +0000
Re: t cluttered Anonymous <no_email@invalid.invalid> - 2016-01-13 14:36 +0000
Re: t cluttered Robert Wessel <robertwessel2@yahoo.com> - 2016-01-14 02:48 -0600
Re: t cluttered nmm@wheeler.UUCP (Nick Maclaren) - 2016-01-14 10:50 +0000
Re: t cluttered Quadibloc <jsavard@ecn.ab.ca> - 2016-01-14 05:25 -0800
Re: t cluttered Bruce Hoult <bruce.hoult@gmail.com> - 2016-01-14 07:23 -0800
Re: t cluttered "James Van Buskirk" <not_valid@comcast.net> - 2016-01-14 09:17 -0700
Re: t cluttered nmm@wheeler.UUCP (Nick Maclaren) - 2016-01-14 16:30 +0000
Re: t cluttered Bruce Hoult <bruce.hoult@gmail.com> - 2016-01-14 12:02 -0800
Re: t cluttered nmm@wheeler.UUCP (Nick Maclaren) - 2016-01-14 21:22 +0000
Re: t cluttered Terje Mathisen <terje.mathisen@tmsw.no> - 2016-01-15 10:06 +0800
Re: t cluttered Terje Mathisen <terje.mathisen@tmsw.no> - 2016-01-15 09:48 +0800
Re: t cluttered Bruce Hoult <bruce.hoult@gmail.com> - 2016-01-14 11:57 -0800
Re: t cluttered "James Van Buskirk" <not_valid@comcast.net> - 2016-01-14 19:16 -0700
Re: t cluttered Quadibloc <jsavard@ecn.ab.ca> - 2016-01-14 08:29 -0800
Re: t cluttered Bruce Hoult <bruce.hoult@gmail.com> - 2016-01-14 12:13 -0800
Re: t cluttered Stephen Fuld <SFuld@alumni.cmu.edu.invalid> - 2016-01-14 12:24 -0800
Re: t cluttered Bruce Hoult <bruce.hoult@gmail.com> - 2016-01-14 12:48 -0800
Re: t cluttered Stephen Fuld <SFuld@alumni.cmu.edu.invalid> - 2016-01-14 13:06 -0800
Re: t cluttered Terje Mathisen <terje.mathisen@tmsw.no> - 2016-01-15 10:14 +0800
Re: t cluttered anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-01-15 14:33 +0000
Re: t cluttered nmm@wheeler.UUCP (Nick Maclaren) - 2016-01-16 09:39 +0000
Re: t cluttered Terje Mathisen <terje.mathisen@tmsw.no> - 2016-01-17 00:15 +0800
Re: t cluttered nmm@wheeler.UUCP (Nick Maclaren) - 2016-01-16 19:24 +0000
Re: t cluttered Ivan Godard <ivan@millcomputing.com> - 2016-01-16 12:18 -0800
Re: t cluttered Terje Mathisen <terje.mathisen@tmsw.no> - 2016-01-17 17:46 +0800
Re: t cluttered Ivan Godard <ivan@millcomputing.com> - 2016-01-17 02:53 -0800
Re: t cluttered Stefan Monnier <monnier@iro.umontreal.ca> - 2016-01-18 12:20 -0500
Re: t cluttered paul wallich <pw@panix.com> - 2016-01-18 14:42 -0500
Re: t cluttered Erik Trulsson <erikt@Update.UU.SE> - 2016-01-19 13:05 +0000
Re: t cluttered paul wallich <pw@panix.com> - 2016-01-19 08:29 -0500
Re: t cluttered nmm@wheeler.UUCP (Nick Maclaren) - 2016-01-19 13:48 +0000
Re: t cluttered anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-01-19 17:04 +0000
Re: t cluttered already5chosen@yahoo.com - 2016-01-19 10:27 -0800
Re: t cluttered David Brown <david.brown@hesbynett.no> - 2016-01-20 11:30 +0100
Re: t cluttered already5chosen@yahoo.com - 2016-01-20 03:55 -0800
Re: t cluttered David Brown <david.brown@hesbynett.no> - 2016-01-20 15:17 +0100
Re: t cluttered already5chosen@yahoo.com - 2016-01-20 07:15 -0800
Re: t cluttered anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-01-20 16:17 +0000
Re: t cluttered EricP <ThatWouldBeTelling@thevillage.com> - 2016-01-19 15:37 -0500
Re: t cluttered anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-01-16 16:46 +0000
Re: t cluttered Quadibloc <jsavard@ecn.ab.ca> - 2016-01-16 10:10 -0800
Re: t cluttered Quadibloc <jsavard@ecn.ab.ca> - 2016-01-16 10:11 -0800
Re: t cluttered nmm@wheeler.UUCP (Nick Maclaren) - 2016-01-16 19:42 +0000
Re: t cluttered anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-01-17 17:51 +0000
Re: t cluttered rpw3@rpw3.org (Rob Warnock) - 2016-01-17 08:21 +0000
Re: t cluttered anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-01-17 17:41 +0000
Re: t cluttered Melzzzzz <mel@zzzzz.com> - 2016-01-17 20:03 +0100
Re: t cluttered rpw3@rpw3.org (Rob Warnock) - 2016-01-18 12:13 +0000
Re: t cluttered anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-01-18 14:24 +0000
Re: t cluttered nmm@wheeler.UUCP (Nick Maclaren) - 2016-01-18 14:40 +0000
Re: t cluttered Megol <golem960@gmail.com> - 2016-01-16 06:25 -0800
Re: t cluttered nmm@wheeler.UUCP (Nick Maclaren) - 2016-01-16 15:09 +0000
Re: t cluttered Terje Mathisen <terje.mathisen@tmsw.no> - 2016-01-17 00:21 +0800
Re: t cluttered anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-01-16 16:34 +0000
Re: t cluttered Quadibloc <jsavard@ecn.ab.ca> - 2016-01-14 08:33 -0800
Re: t cluttered Terje Mathisen <terje.mathisen@tmsw.no> - 2016-01-15 09:38 +0800
Re: t cluttered jgk@panix.com (Joe keane) - 2016-01-17 19:25 +0000
Re: t cluttered already5chosen@yahoo.com - 2016-01-17 11:38 -0800
Re: t cluttered Quadibloc <jsavard@ecn.ab.ca> - 2016-01-17 14:21 -0800
Re: t cluttered nmm@wheeler.UUCP (Nick Maclaren) - 2016-01-17 23:21 +0000
Re: t cluttered nmm@wheeler.UUCP (Nick Maclaren) - 2016-01-14 16:29 +0000
Re: t cluttered Quadibloc <jsavard@ecn.ab.ca> - 2016-01-14 08:39 -0800
Re: t cluttered nmm@wheeler.UUCP (Nick Maclaren) - 2016-01-14 16:45 +0000
Re: t cluttered already5chosen@yahoo.com - 2016-01-14 11:35 -0800
Re: t cluttered nmm@wheeler.UUCP (Nick Maclaren) - 2016-01-14 21:32 +0000
Re: t cluttered MitchAlsup <MitchAlsup@aol.com> - 2016-01-14 15:08 -0800
Re: t cluttered Quadibloc <jsavard@ecn.ab.ca> - 2016-01-14 20:21 -0800
Re: t cluttered Quadibloc <jsavard@ecn.ab.ca> - 2016-01-14 20:20 -0800
Re: t cluttered anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-01-14 16:48 +0000
Re: t cluttered nmm@wheeler.UUCP (Nick Maclaren) - 2016-01-14 18:05 +0000
Re: t cluttered anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-01-15 10:17 +0000
Re: t cluttered Ivan Godard <ivan@millcomputing.com> - 2016-01-13 11:54 -0800
Re: t cluttered nmm@wheeler.UUCP (Nick Maclaren) - 2016-01-13 20:41 +0000
Re: t cluttered MitchAlsup <MitchAlsup@aol.com> - 2016-01-13 17:57 -0800
Re: t cluttered mrs@kithrup.com (Mike Stump) - 2016-01-18 13:37 +0000
Re: t cluttered Terje Mathisen <terje.mathisen@tmsw.no> - 2016-01-19 00:06 +0800
Re: t cluttered Ivan Godard <ivan@millcomputing.com> - 2016-01-18 15:27 -0800
Re: t cluttered nmm@wheeler.UUCP (Nick Maclaren) - 2016-01-19 09:43 +0000
Re: t cluttered Terje Mathisen <terje.mathisen@tmsw.no> - 2016-01-19 18:00 +0800
Re: t cluttered already5chosen@yahoo.com - 2016-01-19 02:47 -0800
Re: t cluttered Bruce Hoult <bruce.hoult@gmail.com> - 2016-01-19 03:01 -0800
Re: t cluttered already5chosen@yahoo.com - 2016-01-19 04:43 -0800
Re: t cluttered jgk@panix.com (Joe keane) - 2016-01-21 17:35 +0000
Re: t cluttered Stefan Monnier <monnier@iro.umontreal.ca> - 2016-01-21 14:45 -0500
Re: t cluttered nmm@wheeler.UUCP (Nick Maclaren) - 2016-01-22 09:49 +0000
Re: hashes and b-trees, was't cluttered John Levine <johnl@iecc.com> - 2016-01-22 16:53 +0000
Re: hashes and b-trees, was't cluttered "James Van Buskirk" <not_valid@comcast.net> - 2016-01-22 10:34 -0700
Re: hashes and b-trees, was't cluttered nmm@wheeler.UUCP (Nick Maclaren) - 2016-01-22 18:00 +0000
Re: t cluttered Stefan Monnier <monnier@iro.umontreal.ca> - 2016-01-25 14:03 -0500
Re: t cluttered nmm@wheeler.UUCP (Nick Maclaren) - 2016-01-25 19:57 +0000
Re: t cluttered Bruce Hoult <bruce.hoult@gmail.com> - 2016-01-26 00:17 -0800
Re: t cluttered nmm@wheeler.UUCP (Nick Maclaren) - 2016-01-26 10:00 +0000
Re: t cluttered jgk@panix.com (Joe keane) - 2016-01-23 18:59 +0000
Re: t cluttered Terje Mathisen <terje.mathisen@tmsw.no> - 2016-01-19 19:28 +0700
Re: t cluttered already5chosen@yahoo.com - 2016-01-19 15:41 -0800
Re: t cluttered Terje Mathisen <terje.mathisen@tmsw.no> - 2016-01-20 15:20 +0100
Re: t cluttered nmm@wheeler.UUCP (Nick Maclaren) - 2016-01-19 11:25 +0000
Re: t cluttered Terje Mathisen <terje.mathisen@tmsw.no> - 2016-01-19 19:48 +0700
Re: t cluttered Walter Banks <walter@bytecraft.com> - 2016-01-19 09:54 -0500
Re: t cluttered nmm@wheeler.UUCP (Nick Maclaren) - 2016-01-19 16:49 +0000
Re: t cluttered Quadibloc <jsavard@ecn.ab.ca> - 2016-01-19 17:25 -0800
Re: t cluttered Quadibloc <jsavard@ecn.ab.ca> - 2016-01-19 17:43 -0800
Re: t cluttered Terje Mathisen <terje.mathisen@tmsw.no> - 2016-01-20 14:52 +0100
Re: t cluttered already5chosen@yahoo.com - 2016-01-19 02:14 -0800
Re: t cluttered Ivan Godard <ivan@millcomputing.com> - 2016-01-19 02:33 -0800
Re: t cluttered already5chosen@yahoo.com - 2016-01-19 02:57 -0800
Re: t cluttered nmm@wheeler.UUCP (Nick Maclaren) - 2016-01-19 11:34 +0000
Re: t cluttered already5chosen@yahoo.com - 2016-01-19 05:24 -0800
Re: t cluttered "James Van Buskirk" <not_valid@comcast.net> - 2016-01-19 15:46 -0700
Re: t cluttered already5chosen@yahoo.com - 2016-01-19 16:14 -0800
Re: t cluttered "James Van Buskirk" <not_valid@comcast.net> - 2016-01-19 18:37 -0700
Re: t cluttered already5chosen@yahoo.com - 2016-01-20 03:32 -0800
Re: t cluttered "James Van Buskirk" <not_valid@comcast.net> - 2016-01-20 11:04 -0700
Re: t cluttered Melzzzzz <mel@zzzzz.com> - 2016-01-20 06:56 +0100
Re: t cluttered "James Van Buskirk" <not_valid@comcast.net> - 2016-01-20 00:55 -0700
Re: t cluttered "James Van Buskirk" <not_valid@comcast.net> - 2016-01-20 01:27 -0700
Re: t cluttered Melzzzzz <mel@zzzzz.com> - 2016-01-20 13:55 +0100
Re: t cluttered already5chosen@yahoo.com - 2016-01-20 08:50 -0800
Re: t cluttered "James Van Buskirk" <not_valid@comcast.net> - 2016-01-20 11:34 -0700
Re: t cluttered already5chosen@yahoo.com - 2016-01-20 11:13 -0800
Re: t cluttered already5chosen@yahoo.com - 2016-01-20 15:15 -0800
Re: t cluttered "James Van Buskirk" <not_valid@comcast.net> - 2016-01-20 17:29 -0700
Re: t cluttered Terje Mathisen <terje.mathisen@tmsw.no> - 2016-01-21 08:42 +0100
Re: t cluttered already5chosen@yahoo.com - 2016-01-21 03:15 -0800
Re: t cluttered already5chosen@yahoo.com - 2016-01-21 05:03 -0800
Re: t cluttered Quadibloc <jsavard@ecn.ab.ca> - 2016-01-21 06:42 -0800
Re: t cluttered already5chosen@yahoo.com - 2016-01-21 07:45 -0800
Re: t cluttered Terje Mathisen <terje.mathisen@tmsw.no> - 2016-01-21 21:30 +0100
Re: t cluttered MitchAlsup <MitchAlsup@aol.com> - 2016-01-21 16:17 -0800
Re: t cluttered Terje Mathisen <terje.mathisen@tmsw.no> - 2016-01-22 07:57 +0100
Re: t cluttered nmm@wheeler.UUCP (Nick Maclaren) - 2016-01-22 13:18 +0000
Re: t cluttered Terje Mathisen <terje.mathisen@tmsw.no> - 2016-01-22 14:51 +0100
Re: t cluttered nmm@wheeler.UUCP (Nick Maclaren) - 2016-01-22 14:14 +0000
Re: t cluttered already5chosen@yahoo.com - 2016-01-22 05:52 -0800
Re: t cluttered already5chosen@yahoo.com - 2016-01-22 06:33 -0800
Re: t cluttered "James Van Buskirk" <not_valid@comcast.net> - 2016-01-22 10:48 -0700
Re: t cluttered Terje Mathisen <terje.mathisen@tmsw.no> - 2016-01-22 19:30 +0100
Re: t cluttered already5chosen@yahoo.com - 2016-01-21 02:18 -0800
Re: t cluttered Terje Mathisen <terje.mathisen@tmsw.no> - 2016-01-19 19:10 +0700
Re: t cluttered MitchAlsup <MitchAlsup@aol.com> - 2016-01-19 06:35 -0800
Re: t cluttered Ivan Godard <ivan@millcomputing.com> - 2016-01-19 10:49 -0800
Re: t cluttered krw <krw@nowhere.com> - 2016-01-12 20:53 -0500
Re: t cluttered Dennis <dennis@none.none> - 2016-01-13 14:56 -0600
Re: t cluttered krw <krw@nowhere.com> - 2016-01-13 21:43 -0500
Re: t cluttered Terje Mathisen <terje.mathisen@tmsw.no> - 2016-01-13 13:24 +0800
Re: t cluttered upsidedown@downunder.com - 2016-01-13 10:15 +0200
Re: Intel's Skylake Prime Number Bug. JJ <jj4public@vfemail.net> - 2016-01-12 13:11 +0700
Re: Intel's Skylake Prime Number Bug. "Tom Del Rosso" <fizzbintuesday@that-google-mail-domain.com> - 2016-01-12 02:45 -0500
Re: Intel's Skylake Prime Number Bug. Paul <nospam@needed.com> - 2016-01-12 04:38 -0500
Re: Intel's Skylake Prime Number Bug. MitchAlsup <MitchAlsup@aol.com> - 2016-01-12 06:33 -0800
Re: Intel's Skylake Prime Number Bug. krw <krw@nowhere.com> - 2016-01-12 12:35 -0500
Re: Intel's Skylake Prime Number Bug. EricP <ThatWouldBeTelling@thevillage.com> - 2016-01-11 14:33 -0500
Re: Intel's Skylake Prime Number Bug. Casper H.S. Dik <Casper.Dik@OrSPaMcle.COM> - 2016-01-12 17:27 +0000
Re: Intel's Skylake Prime Number Bug. Quadibloc <jsavard@ecn.ab.ca> - 2016-01-11 13:54 -0800
Re: Intel's Skylake Prime Number Bug. Martin Brown <|||newspam|||@nezumi.demon.co.uk> - 2016-01-11 22:21 +0000
Re: Intel's Skylake Prime Number Bug. krw <krw@nowhere.com> - 2016-01-11 21:38 -0500
Re: Intel's Skylake Prime Number Bug. krw <krw@nowhere.com> - 2016-01-11 21:37 -0500
Re: Intel's Skylake Prime Number Bug. Robert Baer <robertbaer@localnet.com> - 2016-01-12 20:23 -0800
Re: Intel's Skylake Prime Number Bug. John Levine <johnl@iecc.com> - 2016-01-13 05:19 +0000
Re: Intel's Skylake Prime Number Bug. already5chosen@yahoo.com - 2016-01-13 01:55 -0800
Re: Intel's Skylake Prime Number Bug. Keith Thompson <kst-u@mib.org> - 2016-01-11 23:46 -0800
Page 8 of 10 — ← Prev page 1 … 6 7 [8] 9 10 Next page →
| From | already5chosen@yahoo.com |
|---|---|
| Date | 2016-01-19 16:14 -0800 |
| Subject | Re: t cluttered |
| Message-ID | <241481f8-e576-4b04-9cb3-d724f597f057@googlegroups.com> |
| In reply to | #32928 |
On Wednesday, January 20, 2016 at 12:46:41 AM UTC+2, James Van Buskirk wrote: > wrote in message > news:5ae638bc-3f6e-439d-953e-399f1a4774b7@googlegroups.com... > > > Unfortunately, on x86/DP it is too true. x86 ISA, at least up > > to and including AVX2, provides no good tools for initial > > approximation of reciprocal of double-precision floating > > point numbers. > > ARMv7 (VPF and NEON) is no better. > > ARMv8 *is* better. > > AVX2 is fine. It can get a relative error 2.5-sqrt(6.0) in 3 clock > cycles Cool trick (it would be fine if you provide a little explanation of the magic) but 4 bits in 3 clocks are not nearly as good as 11.5 bits in 4 clocks that are available for single precision. Also, what's going on with special cases - zero, subnormal, NaN, infinity? > and it only takes 25 clock cycles for 4 Newton-Raphson > iterations to clean up the mess. As I said above, latency is much (twice) slower than 14 clocks of DIVSD. How about throughput? Your code can produce new result every 6-7 clocks, right? That's pretty good, a little better than VDIVPD on skylake and much better than Broadwell. > > D:\gfortran\clf\reciprocal>type recip.asm > format MS64 coff > > public recip > section '.text' code readable executable > recip: > ; Load constants and input > vmovdqa [rsp+8], xmm6 > vbroadcastsd ymm1, [one] > vbroadcastsd ymm2, [two] > vpbroadcastq ymm3, [hibit] > vpbroadcastq ymm4, [magic] > vmovdqa ymm0, [rcx] > ; ymm0 is input > ; Begin approximation > vpand ymm5, ymm3, ymm0 > vpandn ymm6, ymm3, ymm0 > vpsubq ymm6, ymm4, ymm6 > vpor ymm6, ymm6, ymm5 > ; ymm6 is initial approximation > ; First N-R iteration > vmovaps ymm5, ymm1 > vfnmadd231pd ymm5, ymm0, ymm6 > vfnmadd132pd ymm0, ymm2, ymm6 > vmulpd ymm5, ymm5, ymm5 > vmulpd ymm0, ymm6, ymm0 > ; Second N-R iteration > vfmadd132pd ymm0, ymm0, ymm5 > vmulpd ymm5, ymm5, ymm5 > ; Third N-R iteration > vfmadd132pd ymm0, ymm0, ymm5 > vmulpd ymm5, ymm5, ymm5 > ; Fourth N-R iteration > vfmadd132pd ymm0, ymm0, ymm5 > ; Store output > vmovaps [rcx], ymm0 > vmovdqa xmm6, [rsp+8] > ret > > section '.data' readable writeable align 16 > one dq 3FF0000000000000h > two dq 4000000000000000h > hibit dq 8000000000000000h > magic dq 7FDE6238502484BAh > > D:\gfortran\clf\reciprocal>fasm recip.asm > flat assembler version 1.71.49 (1048576 kilobytes memory) > 3 passes, 348 bytes. > > D:\gfortran\clf\reciprocal>type test.f90 > program test > use ISO_FORTRAN_ENV > implicit none > interface > subroutine recip(x) bind(C,name='recip') > import > implicit none > real(REAL64) x(4) > end subroutine recip > end interface > real(REAL64) x(108), y(108), r1 > integer i > > r1 = 4/(sqrt(6.0_REAL64)+2) > x(1) = 1 > x(2) = nearest(x(1),x(1)) > x(3:46) = [(1+1.0e-2_REAL64*i,i=1,44)] > x(47) = 1+r1/2 > x(48:92) = [(1+1.0e-2_REAL64*i,i=45,89)] > x(93) = 1+r1 > x(94:98) = [(1+1.0e-2_REAL64*i,i=90,94)] > x(99) = (3+r1)/2 > x(100:104) = [(1+1.0e-2_REAL64*i,i=95,99)] > x(106:108) = [(1+1.0e-2_REAL64*i,i=100,102)] > x(105) = nearest(x(106),-x(106)) > y = x > do i = 1, size(y), 4 > call recip(y(i)) > end do > do i = 1, size(x) > write(*,*) x(i), y(i), 1/x(i) > end do > end program test > > D:\gfortran\clf\reciprocal>ifort /QxCORE-AVX2 /nologo test.f90 recip.obj > > D:\gfortran\clf\reciprocal>test > 1.00000000000000 1.00000000000000 1.00000000000000 > 1.00000000000000 1.00000000000000 1.00000000000000 > 1.01000000000000 0.990099009900990 0.990099009900990 > 1.02000000000000 0.980392156862745 0.980392156862745 > 1.03000000000000 0.970873786407767 0.970873786407767 > 1.04000000000000 0.961538461538461 0.961538461538461 > 1.05000000000000 0.952380952380952 0.952380952380952 > 1.06000000000000 0.943396226415094 0.943396226415094 > 1.07000000000000 0.934579439252336 0.934579439252336 > 1.08000000000000 0.925925925925926 0.925925925925926 > 1.09000000000000 0.917431192660550 0.917431192660550 > 1.10000000000000 0.909090909090909 0.909090909090909 > 1.11000000000000 0.900900900900901 0.900900900900901 > 1.12000000000000 0.892857142857143 0.892857142857143 > 1.13000000000000 0.884955752212389 0.884955752212389 > 1.14000000000000 0.877192982456140 0.877192982456140 > 1.15000000000000 0.869565217391304 0.869565217391304 > 1.16000000000000 0.862068965517241 0.862068965517241 > 1.17000000000000 0.854700854700855 0.854700854700855 > 1.18000000000000 0.847457627118644 0.847457627118644 > 1.19000000000000 0.840336134453782 0.840336134453782 > 1.20000000000000 0.833333333333333 0.833333333333333 > 1.21000000000000 0.826446280991736 0.826446280991736 > 1.22000000000000 0.819672131147541 0.819672131147541 > 1.23000000000000 0.813008130081301 0.813008130081301 > 1.24000000000000 0.806451612903226 0.806451612903226 > 1.25000000000000 0.800000000000000 0.800000000000000 > 1.26000000000000 0.793650793650794 0.793650793650794 > 1.27000000000000 0.787401574803150 0.787401574803150 > 1.28000000000000 0.781250000000000 0.781250000000000 > 1.29000000000000 0.775193798449612 0.775193798449612 > 1.30000000000000 0.769230769230769 0.769230769230769 > 1.31000000000000 0.763358778625954 0.763358778625954 > 1.32000000000000 0.757575757575757 0.757575757575758 > 1.33000000000000 0.751879699248120 0.751879699248120 > 1.34000000000000 0.746268656716418 0.746268656716418 > 1.35000000000000 0.740740740740741 0.740740740740741 > 1.36000000000000 0.735294117647059 0.735294117647059 > 1.37000000000000 0.729927007299270 0.729927007299270 > 1.38000000000000 0.724637681159420 0.724637681159420 > 1.39000000000000 0.719424460431655 0.719424460431655 > 1.40000000000000 0.714285714285714 0.714285714285714 > 1.41000000000000 0.709219858156028 0.709219858156028 > 1.42000000000000 0.704225352112676 0.704225352112676 > 1.43000000000000 0.699300699300699 0.699300699300699 > 1.44000000000000 0.694444444444445 0.694444444444444 > 1.44948974278318 0.689897948556636 0.689897948556636 > 1.45000000000000 0.689655172413793 0.689655172413793 > 1.46000000000000 0.684931506849315 0.684931506849315 > 1.47000000000000 0.680272108843537 0.680272108843537 > 1.48000000000000 0.675675675675676 0.675675675675676 > 1.49000000000000 0.671140939597315 0.671140939597315 > 1.50000000000000 0.666666666666667 0.666666666666667 > 1.51000000000000 0.662251655629139 0.662251655629139 > 1.52000000000000 0.657894736842105 0.657894736842105 > 1.53000000000000 0.653594771241830 0.653594771241830 > 1.54000000000000 0.649350649350649 0.649350649350649 > 1.55000000000000 0.645161290322581 0.645161290322581 > 1.56000000000000 0.641025641025641 0.641025641025641 > 1.57000000000000 0.636942675159236 0.636942675159236 > 1.58000000000000 0.632911392405063 0.632911392405063 > 1.59000000000000 0.628930817610063 0.628930817610063 > 1.60000000000000 0.625000000000000 0.625000000000000 > 1.61000000000000 0.621118012422360 0.621118012422360 > 1.62000000000000 0.617283950617284 0.617283950617284 > 1.63000000000000 0.613496932515337 0.613496932515337 > 1.64000000000000 0.609756097560975 0.609756097560976 > 1.65000000000000 0.606060606060606 0.606060606060606 > 1.66000000000000 0.602409638554217 0.602409638554217 > 1.67000000000000 0.598802395209581 0.598802395209581 > 1.68000000000000 0.595238095238095 0.595238095238095 > 1.69000000000000 0.591715976331361 0.591715976331361 > 1.70000000000000 0.588235294117647 0.588235294117647 > 1.71000000000000 0.584795321637427 0.584795321637427 > 1.72000000000000 0.581395348837209 0.581395348837209 > 1.73000000000000 0.578034682080925 0.578034682080925 > 1.74000000000000 0.574712643678161 0.574712643678161 > 1.75000000000000 0.571428571428571 0.571428571428571 > 1.76000000000000 0.568181818181818 0.568181818181818 > 1.77000000000000 0.564971751412429 0.564971751412429 > 1.78000000000000 0.561797752808989 0.561797752808989 > 1.79000000000000 0.558659217877095 0.558659217877095 > 1.80000000000000 0.555555555555556 0.555555555555556 > 1.81000000000000 0.552486187845304 0.552486187845304 > 1.82000000000000 0.549450549450549 0.549450549450549 > 1.83000000000000 0.546448087431694 0.546448087431694 > 1.84000000000000 0.543478260869565 0.543478260869565 > 1.85000000000000 0.540540540540541 0.540540540540540 > 1.86000000000000 0.537634408602151 0.537634408602151 > 1.87000000000000 0.534759358288770 0.534759358288770 > 1.88000000000000 0.531914893617021 0.531914893617021 > 1.89000000000000 0.529100529100529 0.529100529100529 > 1.89897948556636 0.526598632371090 0.526598632371090 > 1.90000000000000 0.526315789473684 0.526315789473684 > 1.91000000000000 0.523560209424084 0.523560209424084 > 1.92000000000000 0.520833333333333 0.520833333333333 > 1.93000000000000 0.518134715025907 0.518134715025907 > 1.94000000000000 0.515463917525773 0.515463917525773 > 1.94948974278318 0.512954737875335 0.512954737875335 > 1.95000000000000 0.512820512820513 0.512820512820513 > 1.96000000000000 0.510204081632653 0.510204081632653 > 1.97000000000000 0.507614213197970 0.507614213197970 > 1.98000000000000 0.505050505050505 0.505050505050505 > 1.99000000000000 0.502512562814070 0.502512562814070 > 2.00000000000000 0.500000000000000 0.500000000000000 > 2.00000000000000 0.500000000000000 0.500000000000000 > 2.01000000000000 0.497512437810945 0.497512437810945 > 2.02000000000000 0.495049504950495 0.495049504950495
[toc] | [prev] | [next] | [standalone]
| From | "James Van Buskirk" <not_valid@comcast.net> |
|---|---|
| Date | 2016-01-19 18:37 -0700 |
| Subject | Re: t cluttered |
| Message-ID | <n7mo97$2ea$1@dont-email.me> |
| In reply to | #32930 |
wrote in message news:241481f8-e576-4b04-9cb3-d724f597f057@googlegroups.com... > On Wednesday, January 20, 2016 at 12:46:41 AM UTC+2, James Van Buskirk > wrote: > > wrote in message > > news:5ae638bc-3f6e-439d-953e-399f1a4774b7@googlegroups.com... > > > Unfortunately, on x86/DP it is too true. x86 ISA, at least up > > > to and including AVX2, provides no good tools for initial > > > approximation of reciprocal of double-precision floating > > > point numbers. > > > ARMv7 (VPF and NEON) is no better. > > > ARMv8 *is* better. > > AVX2 is fine. It can get a relative error 2.5-sqrt(6.0) in 3 clock > > cycles > Cool trick (it would be fine if you provide a little explanation > of the magic) but 4 bits in 3 clocks are not nearly as good as > 11.5 bits in 4 clocks that are available for single precision. The trick is that once we can find a magic integer to subtract from the initial approximation will be good for all positive numbers, so we only have to split out the sign bit to handle negative numbers. Come to think of it, splitting out that sign bit was unnecessary so the initial approximation could have gone through in 1 clock cycle instead of 3. I tried: format MS64 coff public recip section '.text' code readable executable recip: ; Load constants and input vbroadcastsd ymm1, [one] vpbroadcastq ymm4, [magic] vmovdqa ymm0, [rcx] ; ymm0 is input ; Begin approximation vpsubq ymm2, ymm4, ymm0 ; ymm2 is initial approximation ; First N-R iteration vmovaps ymm5, ymm1 vfnmadd231pd ymm5, ymm0, ymm2 vfmadd132pd ymm2, ymm2, ymm5 vmulpd ymm5, ymm5, ymm5 ; Second N-R iteration vfmadd132pd ymm2, ymm2, ymm5 vmulpd ymm5, ymm5, ymm5 ; Third N-R iteration vfmadd132pd ymm2, ymm2, ymm5 vmulpd ymm5, ymm5, ymm5 ; Fourth N-R iteration vfmadd132pd ymm2, ymm2, ymm5 ; Store output vmovaps [rcx], ymm2 ret section '.data' readable writeable align 16 one dq 3FF0000000000000h magic dq 7FDE6238502484BAh With the same results as before. Anyhow, if a number is between 1 and 2, we can represent it as R = 1+r, where 1 is the implicit leading digit and r is the visible mantissa. We will subtract it from magic = 2**E*(1+r1) where E will be chosen such that the exponents work out OK and r1 is the visible mantissa. Now if 0 < r < r1, we will get x0 = (1/2)*(1+r1-r), while if r1 < r < 1, we arrive at x0 = (1/4)*(2+r1-r). Plugging x0 into epsilon = x0*R-1 for the relative error, we see that for r = 0, r = r1, and r = 1 (the extreme and kink points) epsilon = (1/2)(r1-1) in all 3 cases. If 0 < r < r1, epsilon = (1/2)*(1+r1-r)*(1+r) is extreme when r = r1/2, epsilon = (1/8)*(r1**2+4*r1-4). If r1 < r < 1, we get epsilon = (1/4)*(2+r1-r)*(1+r)-1 is extreme when r = (1/2)*(1+r1), epsilon = (1/16)*(r1**2+6*r1-7). This is always negative, so it will not enter into determining optimal r1. So we find out when (1/8)*(r1**2+4*r1-4) = -(1/2)*(r1-1) and this happens when r1 = 2*sqrt(6)-4. Thus to find our magic number we write out 1+r1 in hex and get 3FFE6238502484BA and adjusting the exponent results in 7FDE6238502484BA. We know our max absolute error is (1-r1)/2 = 5/2-sqrt(6) = 0.05051025721682190180271592529411. The problem with the single precision approximation is that it takes 5+7+5 = 17 clocks on Haswell to convert to single, VRCPPS, and convert back to double and it only saves you one iteration, which was 5 clocks on Haswell. > Also, what's going on with special cases - zero, subnormal, NaN, > infinity? Yeah, well, that's a problem for emulation. If input or output is denormal the above isn't going to work. Zero, infinity, NaN also are problems, but I think the hardware division might slow down for special cases as well. > > and it only takes 25 clock cycles for 4 Newton-Raphson > > iterations to clean up the mess. > As I said above, latency is much (twice) slower than 14 clocks of > DIVSD. > How about throughput? Your code can produce new result > every 6-7 clocks, right? That's pretty good, a little better than > VDIVPD on skylake and much better than Broadwell. Looks like latency for VDIVPD is 26/35/23/14 for N-R/Haswell/ Broadwell/Skylake and reciprocal throughput is 5/28/16/8, but of course I haven't timed any of this.
[toc] | [prev] | [next] | [standalone]
| From | already5chosen@yahoo.com |
|---|---|
| Date | 2016-01-20 03:32 -0800 |
| Subject | Re: t cluttered |
| Message-ID | <8c7d3b0b-4d7c-4dc7-b87e-954924bd6441@googlegroups.com> |
| In reply to | #32932 |
On Wednesday, January 20, 2016 at 3:38:24 AM UTC+2, James Van Buskirk wrote: > wrote in message > news:241481f8-e576-4b04-9cb3-d724f597f057@googlegroups.com... > > > On Wednesday, January 20, 2016 at 12:46:41 AM UTC+2, James Van Buskirk > > wrote: > > > wrote in message > > > news:5ae638bc-3f6e-439d-953e-399f1a4774b7@googlegroups.com... > > > > > Unfortunately, on x86/DP it is too true. x86 ISA, at least up > > > > to and including AVX2, provides no good tools for initial > > > > approximation of reciprocal of double-precision floating > > > > point numbers. > > > > ARMv7 (VPF and NEON) is no better. > > > > ARMv8 *is* better. > > > > AVX2 is fine. It can get a relative error 2.5-sqrt(6.0) in 3 clock > > > cycles > > > Cool trick (it would be fine if you provide a little explanation > > of the magic) but 4 bits in 3 clocks are not nearly as good as > > 11.5 bits in 4 clocks that are available for single precision. > > The trick is that once we can find a magic integer to subtract > from the initial approximation will be good for all positive > numbers, so we only have to split out the sign bit to handle > negative numbers. Come to think of it, splitting out that sign > bit was unnecessary so the initial approximation could have > gone through in 1 clock cycle instead of 3. I tried: > > format MS64 coff > > public recip > section '.text' code readable executable > recip: > ; Load constants and input > vbroadcastsd ymm1, [one] > vpbroadcastq ymm4, [magic] > vmovdqa ymm0, [rcx] > ; ymm0 is input > ; Begin approximation > vpsubq ymm2, ymm4, ymm0 > ; ymm2 is initial approximation > ; First N-R iteration > vmovaps ymm5, ymm1 > vfnmadd231pd ymm5, ymm0, ymm2 > vfmadd132pd ymm2, ymm2, ymm5 > vmulpd ymm5, ymm5, ymm5 > ; Second N-R iteration > vfmadd132pd ymm2, ymm2, ymm5 > vmulpd ymm5, ymm5, ymm5 > ; Third N-R iteration > vfmadd132pd ymm2, ymm2, ymm5 > vmulpd ymm5, ymm5, ymm5 > ; Fourth N-R iteration > vfmadd132pd ymm2, ymm2, ymm5 > ; Store output > vmovaps [rcx], ymm2 > ret > > section '.data' readable writeable align 16 > one dq 3FF0000000000000h > magic dq 7FDE6238502484BAh > > With the same results as before. > > Anyhow, if a number is between 1 and 2, we can represent it as > R = 1+r, where 1 is the implicit leading digit and r is the visible > mantissa. We will subtract it from magic = 2**E*(1+r1) where E > will be chosen such that the exponents work out OK and r1 is the > visible mantissa. Now if 0 < r < r1, we will get x0 = (1/2)*(1+r1-r), > while if r1 < r < 1, we arrive at x0 = (1/4)*(2+r1-r). > > Plugging x0 into epsilon = x0*R-1 for the relative error, we see > that for r = 0, r = r1, and r = 1 (the extreme and kink points) > epsilon = (1/2)(r1-1) in all 3 cases. > > If 0 < r < r1, epsilon = (1/2)*(1+r1-r)*(1+r) is extreme when r = r1/2, > epsilon = (1/8)*(r1**2+4*r1-4). > > If r1 < r < 1, we get epsilon = (1/4)*(2+r1-r)*(1+r)-1 is extreme when > r = (1/2)*(1+r1), epsilon = (1/16)*(r1**2+6*r1-7). This is always > negative, so it will not enter into determining optimal r1. > > So we find out when (1/8)*(r1**2+4*r1-4) = -(1/2)*(r1-1) and > this happens when r1 = 2*sqrt(6)-4. Thus to find our magic > number we write out 1+r1 in hex and get 3FFE6238502484BA > and adjusting the exponent results in 7FDE6238502484BA. > We know our max absolute error is (1-r1)/2 = 5/2-sqrt(6) = > 0.05051025721682190180271592529411. > > The problem with the single precision approximation is that > it takes 5+7+5 = 17 clocks on Haswell to convert to single, VRCPPS, > and convert back to double and it only saves you one iteration, > which was 5 clocks on Haswell. > According to my copy of the manual Vector case: VCVTPD2PS (HSW/BRD/SKL) = 6/6/7 VRCPPS (HSW/BRD/SKL) = 7/7/4 VCVTPS2PD (HSW/BRD/SKL) = 4/4/7 Scalar case is better: CVTSD2SS (HSW/BRD/SKL) = 4/4/5 RCPSS (HSW/BRD/SKL) = 5/5/4 VCVTPS2PD (HSW/BRD/SKL) = 2/2/5 But I don't see a timing like a serious problem. When in the post above I said that x86 ISA, provides no good tools for initial approximation of reciprocal of double-precision floating point numbers I meant that 3-instr sequence above works only for double-precision numbers that fit in single-precision range. For a general "normal" case you will have to add a lot of fiddling with exponent bits. It become even more tedious if you also want to handle denormal/inf/Nan. When Intel were designing original AVX they could have easily added RCPSD/VRCPPD instructions, 95% of required hardware was already here. But, it seems, they saw no point in doing it. Even with RCPSD/VRCPPD the latency wouldn't be as good as their HW divisor and the throughput of double-precision division is probably not important for their main customers. To make RCPSD/VRCPPD somewhat useful they would have to increase a precision of the estimate from 11.5 bits to 13.5-14 bits, but that does take a new hardware. Personally, I mostly agree with their conclusion. The instruction that I really miss is not an *approximate* RCPSD, but a *precise* P_RSQRTSS/P_RSQRTSD/P_RSQRTPS/P_RSQRTPD. Those can be really useful and likely require very small additions to the hardware. > > Also, what's going on with special cases - zero, subnormal, NaN, > > infinity? > > Yeah, well, that's a problem for emulation. If input or output is > denormal the above isn't going to work. Zero, infinity, NaN also > are problems, but I think the hardware division might slow down > for special cases as well. > > > > and it only takes 25 clock cycles for 4 Newton-Raphson > > > iterations to clean up the mess. > > > As I said above, latency is much (twice) slower than 14 clocks of > > DIVSD. > > > How about throughput? Your code can produce new result > > every 6-7 clocks, right? That's pretty good, a little better than > > VDIVPD on skylake and much better than Broadwell. > > Looks like latency for VDIVPD is 26/35/23/14 for N-R/Haswell/ > Broadwell/Skylake and reciprocal throughput is 5/28/16/8, > but of course I haven't timed any of this. Actual measurement are certainly interesting. Without them your whole exercise feel incomplete.
[toc] | [prev] | [next] | [standalone]
| From | "James Van Buskirk" <not_valid@comcast.net> |
|---|---|
| Date | 2016-01-20 11:04 -0700 |
| Subject | Re: t cluttered |
| Message-ID | <n7oi27$t66$1@dont-email.me> |
| In reply to | #32941 |
wrote in message news:8c7d3b0b-4d7c-4dc7-b87e-954924bd6441@googlegroups.com... > On Wednesday, January 20, 2016 at 3:38:24 AM UTC+2, James Van Buskirk > wrote: > > wrote in message > > news:241481f8-e576-4b04-9cb3-d724f597f057@googlegroups.com... > > > How about throughput? Your code can produce new result > > > every 6-7 clocks, right? That's pretty good, a little better than > > > VDIVPD on skylake and much better than Broadwell. > > Looks like latency for VDIVPD is 26/35/23/14 for N-R/Haswell/ > > Broadwell/Skylake and reciprocal throughput is 5/28/16/8, > > but of course I haven't timed any of this. > Actual measurement are certainly interesting. Without them your whole > exercise feel incomplete. Unfortunately I have already blown too much time on this exercise and I have lots of more interesting projects that have fallen behind. My final version that I posted last night has advantages in that the input and output registers are now the same so that latency could be timed more easily by computing the reciprocal of the reciprocal a few times. Also throughput would be easier to measure because each instruction stream would now only use two registers so a lot of instruction streams could be slopped together to saturate the FMA units. But it looks like another interested party will have to do this.
[toc] | [prev] | [next] | [standalone]
| From | Melzzzzz <mel@zzzzz.com> |
|---|---|
| Date | 2016-01-20 06:56 +0100 |
| Subject | Re: t cluttered |
| Message-ID | <20160120065614.3a7fdedd@maxa-pc> |
| In reply to | #32928 |
On Tue, 19 Jan 2016 15:46:11 -0700 "James Van Buskirk" <not_valid@comcast.net> wrote: > wrote in message > news:5ae638bc-3f6e-439d-953e-399f1a4774b7@googlegroups.com... > > > Unfortunately, on x86/DP it is too true. x86 ISA, at least up > > to and including AVX2, provides no good tools for initial > > approximation of reciprocal of double-precision floating > > point numbers. > > ARMv7 (VPF and NEON) is no better. > > ARMv8 *is* better. > > AVX2 is fine. It can get a relative error 2.5-sqrt(6.0) in 3 clock > cycles and it only takes 25 clock cycles for 4 Newton-Raphson > iterations to clean up the mess. > > D:\gfortran\clf\reciprocal>type recip.asm > format MS64 coff > > public recip > section '.text' code readable executable > recip: > ; Load constants and input > vmovdqa [rsp+8], xmm6 > vbroadcastsd ymm1, [one] > vbroadcastsd ymm2, [two] > vpbroadcastq ymm3, [hibit] > vpbroadcastq ymm4, [magic] > vmovdqa ymm0, [rcx] > ; ymm0 is input > ; Begin approximation > vpand ymm5, ymm3, ymm0 > vpandn ymm6, ymm3, ymm0 > vpsubq ymm6, ymm4, ymm6 > vpor ymm6, ymm6, ymm5 > ; ymm6 is initial approximation > ; First N-R iteration > vmovaps ymm5, ymm1 > vfnmadd231pd ymm5, ymm0, ymm6 > vfnmadd132pd ymm0, ymm2, ymm6 > vmulpd ymm5, ymm5, ymm5 > vmulpd ymm0, ymm6, ymm0 > ; Second N-R iteration > vfmadd132pd ymm0, ymm0, ymm5 > vmulpd ymm5, ymm5, ymm5 > ; Third N-R iteration > vfmadd132pd ymm0, ymm0, ymm5 > vmulpd ymm5, ymm5, ymm5 > ; Fourth N-R iteration > vfmadd132pd ymm0, ymm0, ymm5 > ; Store output > vmovaps [rcx], ymm0 > vmovdqa xmm6, [rsp+8] > ret > > section '.data' readable writeable align 16 > one dq 3FF0000000000000h > two dq 4000000000000000h > hibit dq 8000000000000000h > magic dq 7FDE6238502484BAh > > D:\gfortran\clf\reciprocal>fasm recip.asm > flat assembler version 1.71.49 (1048576 kilobytes memory) > 3 passes, 348 bytes. > > D:\gfortran\clf\reciprocal>type test.f90 > program test > use ISO_FORTRAN_ENV > implicit none > interface > subroutine recip(x) bind(C,name='recip') > import > implicit none > real(REAL64) x(4) > end subroutine recip > end interface > real(REAL64) x(108), y(108), r1 > integer i > > r1 = 4/(sqrt(6.0_REAL64)+2) > x(1) = 1 > x(2) = nearest(x(1),x(1)) > x(3:46) = [(1+1.0e-2_REAL64*i,i=1,44)] > x(47) = 1+r1/2 > x(48:92) = [(1+1.0e-2_REAL64*i,i=45,89)] > x(93) = 1+r1 > x(94:98) = [(1+1.0e-2_REAL64*i,i=90,94)] > x(99) = (3+r1)/2 > x(100:104) = [(1+1.0e-2_REAL64*i,i=95,99)] > x(106:108) = [(1+1.0e-2_REAL64*i,i=100,102)] > x(105) = nearest(x(106),-x(106)) > y = x > do i = 1, size(y), 4 > call recip(y(i)) > end do > do i = 1, size(x) > write(*,*) x(i), y(i), 1/x(i) > end do > end program test > > D:\gfortran\clf\reciprocal>ifort /QxCORE-AVX2 /nologo test.f90 > recip.obj > > D:\gfortran\clf\reciprocal>test > 1.00000000000000 1.00000000000000 1.00000000000000 > 1.00000000000000 1.00000000000000 1.00000000000000 > 1.01000000000000 0.990099009900990 0.990099009900990 > 1.02000000000000 0.980392156862745 0.980392156862745 > 1.03000000000000 0.970873786407767 0.970873786407767 > 1.04000000000000 0.961538461538461 0.961538461538461 > 1.05000000000000 0.952380952380952 0.952380952380952 > 1.06000000000000 0.943396226415094 0.943396226415094 > 1.07000000000000 0.934579439252336 0.934579439252336 > 1.08000000000000 0.925925925925926 0.925925925925926 > 1.09000000000000 0.917431192660550 0.917431192660550 > 1.10000000000000 0.909090909090909 0.909090909090909 > 1.11000000000000 0.900900900900901 0.900900900900901 > 1.12000000000000 0.892857142857143 0.892857142857143 > 1.13000000000000 0.884955752212389 0.884955752212389 > 1.14000000000000 0.877192982456140 0.877192982456140 > 1.15000000000000 0.869565217391304 0.869565217391304 > 1.16000000000000 0.862068965517241 0.862068965517241 > 1.17000000000000 0.854700854700855 0.854700854700855 > 1.18000000000000 0.847457627118644 0.847457627118644 > 1.19000000000000 0.840336134453782 0.840336134453782 > 1.20000000000000 0.833333333333333 0.833333333333333 > 1.21000000000000 0.826446280991736 0.826446280991736 > 1.22000000000000 0.819672131147541 0.819672131147541 > 1.23000000000000 0.813008130081301 0.813008130081301 > 1.24000000000000 0.806451612903226 0.806451612903226 > 1.25000000000000 0.800000000000000 0.800000000000000 > 1.26000000000000 0.793650793650794 0.793650793650794 > 1.27000000000000 0.787401574803150 0.787401574803150 > 1.28000000000000 0.781250000000000 0.781250000000000 > 1.29000000000000 0.775193798449612 0.775193798449612 > 1.30000000000000 0.769230769230769 0.769230769230769 > 1.31000000000000 0.763358778625954 0.763358778625954 > 1.32000000000000 0.757575757575757 0.757575757575758 > 1.33000000000000 0.751879699248120 0.751879699248120 > 1.34000000000000 0.746268656716418 0.746268656716418 > 1.35000000000000 0.740740740740741 0.740740740740741 > 1.36000000000000 0.735294117647059 0.735294117647059 > 1.37000000000000 0.729927007299270 0.729927007299270 > 1.38000000000000 0.724637681159420 0.724637681159420 > 1.39000000000000 0.719424460431655 0.719424460431655 > 1.40000000000000 0.714285714285714 0.714285714285714 > 1.41000000000000 0.709219858156028 0.709219858156028 > 1.42000000000000 0.704225352112676 0.704225352112676 > 1.43000000000000 0.699300699300699 0.699300699300699 > 1.44000000000000 0.694444444444445 0.694444444444444 > 1.44948974278318 0.689897948556636 0.689897948556636 > 1.45000000000000 0.689655172413793 0.689655172413793 > 1.46000000000000 0.684931506849315 0.684931506849315 > 1.47000000000000 0.680272108843537 0.680272108843537 > 1.48000000000000 0.675675675675676 0.675675675675676 > 1.49000000000000 0.671140939597315 0.671140939597315 > 1.50000000000000 0.666666666666667 0.666666666666667 > 1.51000000000000 0.662251655629139 0.662251655629139 > 1.52000000000000 0.657894736842105 0.657894736842105 > 1.53000000000000 0.653594771241830 0.653594771241830 > 1.54000000000000 0.649350649350649 0.649350649350649 > 1.55000000000000 0.645161290322581 0.645161290322581 > 1.56000000000000 0.641025641025641 0.641025641025641 > 1.57000000000000 0.636942675159236 0.636942675159236 > 1.58000000000000 0.632911392405063 0.632911392405063 > 1.59000000000000 0.628930817610063 0.628930817610063 > 1.60000000000000 0.625000000000000 0.625000000000000 > 1.61000000000000 0.621118012422360 0.621118012422360 > 1.62000000000000 0.617283950617284 0.617283950617284 > 1.63000000000000 0.613496932515337 0.613496932515337 > 1.64000000000000 0.609756097560975 0.609756097560976 > 1.65000000000000 0.606060606060606 0.606060606060606 > 1.66000000000000 0.602409638554217 0.602409638554217 > 1.67000000000000 0.598802395209581 0.598802395209581 > 1.68000000000000 0.595238095238095 0.595238095238095 > 1.69000000000000 0.591715976331361 0.591715976331361 > 1.70000000000000 0.588235294117647 0.588235294117647 > 1.71000000000000 0.584795321637427 0.584795321637427 > 1.72000000000000 0.581395348837209 0.581395348837209 > 1.73000000000000 0.578034682080925 0.578034682080925 > 1.74000000000000 0.574712643678161 0.574712643678161 > 1.75000000000000 0.571428571428571 0.571428571428571 > 1.76000000000000 0.568181818181818 0.568181818181818 > 1.77000000000000 0.564971751412429 0.564971751412429 > 1.78000000000000 0.561797752808989 0.561797752808989 > 1.79000000000000 0.558659217877095 0.558659217877095 > 1.80000000000000 0.555555555555556 0.555555555555556 > 1.81000000000000 0.552486187845304 0.552486187845304 > 1.82000000000000 0.549450549450549 0.549450549450549 > 1.83000000000000 0.546448087431694 0.546448087431694 > 1.84000000000000 0.543478260869565 0.543478260869565 > 1.85000000000000 0.540540540540541 0.540540540540540 > 1.86000000000000 0.537634408602151 0.537634408602151 > 1.87000000000000 0.534759358288770 0.534759358288770 > 1.88000000000000 0.531914893617021 0.531914893617021 > 1.89000000000000 0.529100529100529 0.529100529100529 > 1.89897948556636 0.526598632371090 0.526598632371090 > 1.90000000000000 0.526315789473684 0.526315789473684 > 1.91000000000000 0.523560209424084 0.523560209424084 > 1.92000000000000 0.520833333333333 0.520833333333333 > 1.93000000000000 0.518134715025907 0.518134715025907 > 1.94000000000000 0.515463917525773 0.515463917525773 > 1.94948974278318 0.512954737875335 0.512954737875335 > 1.95000000000000 0.512820512820513 0.512820512820513 > 1.96000000000000 0.510204081632653 0.510204081632653 > 1.97000000000000 0.507614213197970 0.507614213197970 > 1.98000000000000 0.505050505050505 0.505050505050505 > 1.99000000000000 0.502512562814070 0.502512562814070 > 2.00000000000000 0.500000000000000 0.500000000000000 > 2.00000000000000 0.500000000000000 0.500000000000000 > 2.01000000000000 0.497512437810945 0.497512437810945 > 2.02000000000000 0.495049504950495 0.495049504950495 > I get quite different results with gfortran on Linux: [bmaxa@maxa-pc assembler]$ ./recip 1.0000000000000000 1.0000000000000000 1.0000000000000000 1.0000000000000002 0.99999999999999989 0.99999999999999978 1.0100000000000000 0.99009900990099009 0.99009900990099009 1.0200000000000000 0.98039215686274506 0.98039215686274506 1.0300000000000000 0.97087378640776689 0.97087378640776700 1.0400000000000000 0.96153846153846145 0.96153846153846145 1.0500000000000000 0.95238095238095222 0.95238095238095233 1.0600000000000001 0.94339622641509435 0.94339622641509424 1.0700000000000001 0.93457943925233633 0.93457943925233644 1.0800000000000001 0.92592592592592582 0.92592592592592582 1.0900000000000001 0.91743119266055040 0.91743119266055040 1.1000000000000001 0.90909090909090895 0.90909090909090906 1.1100000000000001 0.90090090090090069 0.90090090090090080 1.1200000000000001 0.89285714285714290 0.89285714285714279 1.1299999999999999 0.88495575221238942 0.88495575221238942 1.1400000000000001 0.87719298245614030 0.87719298245614030 1.1499999999999999 0.86956521739130443 0.86956521739130443 1.1599999999999999 0.86206896551724133 0.86206896551724144 1.1699999999999999 0.85470085470085466 0.85470085470085477 1.1799999999999999 0.84745762711864414 0.84745762711864414 1.1899999999999999 0.84033613445378152 0.84033613445378152 1.2000000000000000 0.83333333333333348 0.83333333333333337 1.2100000000000000 0.82644628099173556 0.82644628099173556 1.2200000000000000 0.81967213114754089 0.81967213114754101 1.2300000000000000 0.81300813008130091 0.81300813008130079 1.2400000000000000 0.80645161290322576 0.80645161290322587 1.2500000000000000 0.80000000000000016 0.80000000000000004 1.2600000000000000 0.79365079365079361 0.79365079365079361 1.2700000000000000 0.78740157480314954 0.78740157480314954 1.2800000000000000 0.78124999999999989 0.78125000000000000 1.2900000000000000 0.77519379844961245 0.77519379844961234 1.3000000000000000 0.76923076923076927 0.76923076923076916 1.3100000000000001 0.76335877862595403 0.76335877862595414 1.3200000000000001 0.75757575757575746 0.75757575757575757 1.3300000000000001 0.75187969924812015 0.75187969924812026 1.3400000000000001 0.74626865671641773 0.74626865671641784 1.3500000000000001 0.74074074074074070 0.74074074074074070 1.3599999999999999 0.73529411764705888 0.73529411764705888 1.3700000000000001 0.72992700729927007 0.72992700729927007 1.3799999999999999 0.72463768115942040 0.72463768115942040 1.3900000000000001 0.71942446043165464 0.71942446043165464 1.3999999999999999 0.71428571428571430 0.71428571428571430 1.4100000000000001 0.70921985815602828 0.70921985815602828 1.4199999999999999 0.70422535211267612 0.70422535211267612 1.4299999999999999 0.69930069930069938 0.69930069930069938 1.4399999999999999 0.69444444444444453 0.69444444444444442 1.4494897427831781 0.68989794855663567 0.68989794855663567 1.4500000000000000 0.68965517241379315 0.68965517241379315 1.4600000000000000 0.68493150684931503 0.68493150684931503 1.4700000000000000 0.68027210884353739 0.68027210884353739 1.4800000000000000 0.67567567567567566 0.67567567567567566 1.4900000000000000 0.67114093959731547 0.67114093959731547 1.5000000000000000 0.66666666666666663 0.66666666666666663 1.5100000000000000 0.66225165562913901 0.66225165562913912 1.5200000000000000 0.65789473684210520 0.65789473684210531 1.5300000000000000 0.65359477124182996 0.65359477124183007 1.5400000000000000 0.64935064935064934 0.64935064935064934 1.5500000000000000 0.64516129032258063 0.64516129032258063 1.5600000000000001 0.64102564102564108 0.64102564102564097 1.5700000000000001 0.63694267515923564 0.63694267515923564 1.5800000000000001 0.63291139240506322 0.63291139240506322 1.5899999999999999 0.62893081761006298 0.62893081761006298 1.6000000000000001 0.62500000000000000 0.62500000000000000 1.6099999999999999 0.62111801242236031 0.62111801242236031 1.6200000000000001 0.61728395061728392 0.61728395061728392 1.6299999999999999 0.61349693251533743 0.61349693251533743 1.6400000000000001 0.60975609756097549 0.60975609756097560 1.6499999999999999 0.60606060606060608 0.60606060606060608 1.6600000000000001 0.60240963855421681 0.60240963855421681 1.6699999999999999 0.59880239520958090 0.59880239520958090 1.6800000000000002 0.59523809523809512 0.59523809523809523 1.6899999999999999 0.59171597633136086 0.59171597633136097 1.7000000000000002 0.58823529411764697 0.58823529411764697 1.7100000000000000 0.58479532163742698 0.58479532163742687 1.7200000000000000 0.58139534883720922 0.58139534883720934 1.7300000000000000 0.57803468208092490 0.57803468208092490 1.7400000000000000 0.57471264367816099 0.57471264367816088 1.7500000000000000 0.57142857142857140 0.57142857142857140 1.7600000000000000 0.56818181818181812 0.56818181818181823 1.7700000000000000 0.56497175141242939 0.56497175141242939 1.7800000000000000 0.56179775280898880 0.56179775280898880 1.7900000000000000 0.55865921787709494 0.55865921787709494 1.8000000000000000 0.55555555555555558 0.55555555555555558 1.8100000000000001 0.55248618784530390 0.55248618784530390 1.8200000000000001 0.54945054945054939 0.54945054945054939 1.8300000000000001 0.54644808743169393 0.54644808743169393 1.8399999999999999 0.54347826086956530 0.54347826086956530 1.8500000000000001 0.54054054054054057 0.54054054054054046 1.8599999999999999 0.53763440860215062 0.53763440860215062 1.8700000000000001 0.53475935828877008 0.53475935828876997 1.8799999999999999 0.53191489361702138 0.53191489361702127 1.8900000000000001 0.52910052910052896 0.52910052910052907 1.8989794855663562 0.52659863237109039 0.52659863237109039 1.8999999999999999 0.52631578947368418 0.52631578947368418 1.9100000000000001 0.52356020942408377 0.52356020942408377 1.9199999999999999 0.52083333333333337 0.52083333333333337 1.9300000000000002 0.51813471502590669 0.51813471502590669 1.9399999999999999 0.51546391752577314 0.51546391752577325 1.9494897427831781 0.51295473787533519 0.51295473787533530 1.9500000000000002 0.51282051282051277 0.51282051282051277 1.9600000000000000 0.51020408163265307 0.51020408163265307 1.9700000000000000 0.50761421319796951 0.50761421319796951 1.9800000000000000 0.50505050505050508 0.50505050505050508 1.9900000000000000 0.50251256281407031 0.50251256281407031 1.9999999999999998 0.50000000000000011 0.50000000000000011 2.0000000000000000 0.50000000000000000 0.50000000000000000 2.0099999999999998 0.49751243781094523 0.49751243781094534 2.0200000000000000 0.49504950495049505 0.49504950495049505 gcc version 5.3.0 (GCC)
[toc] | [prev] | [next] | [standalone]
| From | "James Van Buskirk" <not_valid@comcast.net> |
|---|---|
| Date | 2016-01-20 00:55 -0700 |
| Subject | Re: t cluttered |
| Message-ID | <n7ned1$n00$1@dont-email.me> |
| In reply to | #32934 |
"Melzzzzz" wrote in message news:20160120065614.3a7fdedd@maxa-pc...
> On Tue, 19 Jan 2016 15:46:11 -0700
> "James Van Buskirk" <not_valid@comcast.net> wrote:
> > AVX2 is fine. It can get a relative error 2.5-sqrt(6.0) in 3 clock
> > cycles and it only takes 25 clock cycles for 4 Newton-Raphson
> > iterations to clean up the mess.
> > do i = 1, size(x)
> > write(*,*) x(i), y(i), 1/x(i)
> > end do
> > 2.00000000000000 0.500000000000000 0.500000000000000
> > 2.00000000000000 0.500000000000000 0.500000000000000
> > 2.01000000000000 0.497512437810945 0.497512437810945
> > 2.02000000000000 0.495049504950495 0.495049504950495
> I get quite different results with gfortran on Linux:
> 1.9999999999999998 0.50000000000000011 0.50000000000000011
> 2.0000000000000000 0.50000000000000000 0.50000000000000000
> 2.0099999999999998 0.49751243781094523 0.49751243781094534
> 2.0200000000000000 0.49504950495049505 0.49504950495049505
> gcc version 5.3.0 (GCC)
Looks identical to me. gfortran just prints out two more digits than ifort
does.
Version 5.2.0 on Windows segfaults on the first call to recip. One ulp
seems to
correspond to 11 in the last two digits in the outputs above except possibly
for the output for 2.01. Try running the Fortran program with the output
loop
changed to:
do i = 1, size(x)
! write(*,*) x(i), y(i), 1/x(i)
write(*,'(f16.14,2(1x,Z16.16))') x(i), transfer([y(i),
1/x(i)],[1.0_REAL64])
end do
So that you can see how many ulps the two disagree by. 108 lines is a
lot of output, so please just post the last four unless you detect a
discrepancy of more than 1 ulp. ifort on Windows says:
2.00000000000000 3FE0000000000001 3FE0000000000001
2.00000000000000 3FE0000000000000 3FE0000000000000
2.01000000000000 3FDFD73E6870145F 3FDFD73E68701460
2.02000000000000 3FDFAEE41E6A7498 3FDFAEE41E6A7498
Now, I'm a little worried because an ulp should be half as big
once the outputs get below 0.5, so your output looks like the
N-R code is 2 ulps low whereas the hex dump above indicates
it's only one ulp low.
OK, I just got gfortran to work by forcing alignment of the y
array. Last four lines:
2.00000000000000 3FE0000000000001 3FE0000000000001
2.00000000000000 3FE0000000000000 3FE0000000000000
2.01000000000000 3FDFD73E68701461 3FDFD73E68701462
2.02000000000000 3FDFAEE41E6A7498 3FDFAEE41E6A7498
So I am still only one ulp low. In decimal I still get:
1.9999999999999998 0.50000000000000011 0.50000000000000011
2.0000000000000000 0.50000000000000000 0.50000000000000000
2.0099999999999998 0.49751243781094528 0.49751243781094534
2.0200000000000000 0.49504950495049505 0.49504950495049505
That's really quite odd because our middle columns should agree
exactly because we are using the same assembly code. Oh, I guess
we aren't because I improved my assembly code a couple of posts
later. Indeed, with the code you quoted the 2.01 result is two ulps
low. The improved code, posted downstream of that, was only one
ulp low and used less data and one less FMA operation and fewer
SIMD integer operations, so perhaps it could attain a reciprocal
throughput of 4 clock cycles. Faster always means more accurate,
right? :)
[toc] | [prev] | [next] | [standalone]
| From | "James Van Buskirk" <not_valid@comcast.net> |
|---|---|
| Date | 2016-01-20 01:27 -0700 |
| Subject | Re: t cluttered |
| Message-ID | <n7ng9j$sj7$1@dont-email.me> |
| In reply to | #32935 |
"James Van Buskirk" wrote in message news:n7ned1$n00$1@dont-email.me... > Version 5.2.0 on Windows segfaults on the first call to recip. The problem was that I unintentionally used vmovdqa and vmovaps instructions instead of vmovdqu and vmovups, thus imposing alignment requirements that I didn't intend. The cleaned up version of the code is therefore: format MS64 coff public recip section '.text' code readable executable recip: ; Load constants and input vbroadcastsd ymm1, [one] vpbroadcastq ymm4, [magic] vmovdqu ymm0, [rcx] ; ymm0 is input ; Begin approximation vpsubq ymm2, ymm4, ymm0 ; ymm2 is initial approximation ; First N-R iteration vfnmadd213pd ymm0, ymm2, ymm1 vfmadd132pd ymm2, ymm2, ymm0 vmulpd ymm0, ymm0, ymm0 ; Second N-R iteration vfmadd132pd ymm2, ymm2, ymm0 vmulpd ymm0, ymm0, ymm0 ; Third N-R iteration vfmadd132pd ymm2, ymm2, ymm0 vmulpd ymm0, ymm0, ymm0 ; Fourth N-R iteration vfmadd132pd ymm0, ymm2, ymm2 ; Store output vmovups [rcx], ymm0 ret section '.data' readable writeable align 16 align 16 one dq 3FF0000000000000h magic dq 7FDE6238502484BAh
[toc] | [prev] | [next] | [standalone]
| From | Melzzzzz <mel@zzzzz.com> |
|---|---|
| Date | 2016-01-20 13:55 +0100 |
| Subject | Re: t cluttered |
| Message-ID | <20160120135538.257d4a31@maxa-pc> |
| In reply to | #32935 |
On Wed, 20 Jan 2016 00:55:22 -0700 "James Van Buskirk" <not_valid@comcast.net> wrote: > > OK, I just got gfortran to work by forcing alignment of the y > array. Last four lines: > > 2.00000000000000 3FE0000000000001 3FE0000000000001 > 2.00000000000000 3FE0000000000000 3FE0000000000000 > 2.01000000000000 3FDFD73E68701461 3FDFD73E68701462 > 2.02000000000000 3FDFAEE41E6A7498 3FDFAEE41E6A7498 > > So I am still only one ulp low. In decimal I still get: > > 1.9999999999999998 0.50000000000000011 0.50000000000000011 > 2.0000000000000000 0.50000000000000000 0.50000000000000000 > 2.0099999999999998 0.49751243781094528 0.49751243781094534 > 2.0200000000000000 0.49504950495049505 0.49504950495049505 > > That's really quite odd because our middle columns should agree > exactly because we are using the same assembly code. Oh, I guess > we aren't because I improved my assembly code a couple of posts > later. Indeed, with the code you quoted the 2.01 result is two ulps > low. The improved code, posted downstream of that, was only one > ulp low and used less data and one less FMA operation and fewer > SIMD integer operations, so perhaps it could attain a reciprocal > throughput of 4 clock cycles. Faster always means more accurate, > right? :) > With improved asm version: 2.00000000000000 3FE0000000000001 3FE0000000000001 2.00000000000000 3FE0000000000000 3FE0000000000000 2.01000000000000 3FDFD73E68701461 3FDFD73E68701462 2.02000000000000 3FDFAEE41E6A7498 3FDFAEE41E6A7498
[toc] | [prev] | [next] | [standalone]
| From | already5chosen@yahoo.com |
|---|---|
| Date | 2016-01-20 08:50 -0800 |
| Subject | Re: t cluttered |
| Message-ID | <227ce46c-6178-4cf3-8716-45f8cb5e0bf5@googlegroups.com> |
| In reply to | #32928 |
On Wednesday, January 20, 2016 at 12:46:41 AM UTC+2, James Van Buskirk wrote: > wrote in message > news:5ae638bc-3f6e-439d-953e-399f1a4774b7@googlegroups.com... > > > Unfortunately, on x86/DP it is too true. x86 ISA, at least up > > to and including AVX2, provides no good tools for initial > > approximation of reciprocal of double-precision floating > > point numbers. > > ARMv7 (VPF and NEON) is no better. > > ARMv8 *is* better. > > AVX2 is fine. It can get a relative error 2.5-sqrt(6.0) in 3 clock > cycles and it only takes 25 clock cycles for 4 Newton-Raphson > iterations to clean up the mess. > > D:\gfortran\clf\reciprocal>type recip.asm > format MS64 coff > > public recip > section '.text' code readable executable > recip: > ; Load constants and input > vmovdqa [rsp+8], xmm6 > vbroadcastsd ymm1, [one] > vbroadcastsd ymm2, [two] > vpbroadcastq ymm3, [hibit] > vpbroadcastq ymm4, [magic] > vmovdqa ymm0, [rcx] > ; ymm0 is input > ; Begin approximation > vpand ymm5, ymm3, ymm0 > vpandn ymm6, ymm3, ymm0 > vpsubq ymm6, ymm4, ymm6 > vpor ymm6, ymm6, ymm5 > ; ymm6 is initial approximation > ; First N-R iteration > vmovaps ymm5, ymm1 > vfnmadd231pd ymm5, ymm0, ymm6 > vfnmadd132pd ymm0, ymm2, ymm6 > vmulpd ymm5, ymm5, ymm5 > vmulpd ymm0, ymm6, ymm0 > ; Second N-R iteration > vfmadd132pd ymm0, ymm0, ymm5 > vmulpd ymm5, ymm5, ymm5 > ; Third N-R iteration > vfmadd132pd ymm0, ymm0, ymm5 > vmulpd ymm5, ymm5, ymm5 > ; Fourth N-R iteration > vfmadd132pd ymm0, ymm0, ymm5 > ; Store output > vmovaps [rcx], ymm0 > vmovdqa xmm6, [rsp+8] > ret > > section '.data' readable writeable align 16 > one dq 3FF0000000000000h > two dq 4000000000000000h > hibit dq 8000000000000000h > magic dq 7FDE6238502484BAh > > D:\gfortran\clf\reciprocal>fasm recip.asm > flat assembler version 1.71.49 (1048576 kilobytes memory) > 3 passes, 348 bytes. > > D:\gfortran\clf\reciprocal>type test.f90 > program test > use ISO_FORTRAN_ENV > implicit none > interface > subroutine recip(x) bind(C,name='recip') > import > implicit none > real(REAL64) x(4) > end subroutine recip > end interface > real(REAL64) x(108), y(108), r1 > integer i > > r1 = 4/(sqrt(6.0_REAL64)+2) > x(1) = 1 > x(2) = nearest(x(1),x(1)) > x(3:46) = [(1+1.0e-2_REAL64*i,i=1,44)] > x(47) = 1+r1/2 > x(48:92) = [(1+1.0e-2_REAL64*i,i=45,89)] > x(93) = 1+r1 > x(94:98) = [(1+1.0e-2_REAL64*i,i=90,94)] > x(99) = (3+r1)/2 > x(100:104) = [(1+1.0e-2_REAL64*i,i=95,99)] > x(106:108) = [(1+1.0e-2_REAL64*i,i=100,102)] > x(105) = nearest(x(106),-x(106)) > y = x > do i = 1, size(y), 4 > call recip(y(i)) > end do > do i = 1, size(x) > write(*,*) x(i), y(i), 1/x(i) > end do > end program test > > D:\gfortran\clf\reciprocal>ifort /QxCORE-AVX2 /nologo test.f90 recip.obj > > D:\gfortran\clf\reciprocal>test > 1.00000000000000 1.00000000000000 1.00000000000000 > 1.00000000000000 1.00000000000000 1.00000000000000 <snip> Looking at your code, I don't understand how such algorithm can possibly deliver the result to 1ulp. May be, I didn't understand something, but it looks like your run all you steps starting from lines vfnmadd231pd ymm5, ymm0, ymm6 ; ymm5 = x*y - 1 vfnmadd132pd ymm0, ymm2, ymm6 ; ymm0 = 2.0 - x*y in what I would call "open loop". So, rounding errors accumulate. I expect that in the worst case rounding errors would accumulate to something like 4 ulp in the end. I'd rather do iteration 1-3 in open loop, because, as you demonstrated, it saves latency, but on the last iteration I'd return to closed loop vs original input value. I suppose, it will cost 5 more clocks in latency (or 4 clocks on Skylake), but as they say, it does not matter how fast we are able to calculate a wrong result.
[toc] | [prev] | [next] | [standalone]
| From | "James Van Buskirk" <not_valid@comcast.net> |
|---|---|
| Date | 2016-01-20 11:34 -0700 |
| Subject | Re: t cluttered |
| Message-ID | <n7ojrv$4vq$1@dont-email.me> |
| In reply to | #32960 |
wrote in message news:227ce46c-6178-4cf3-8716-45f8cb5e0bf5@googlegroups.com... > Looking at your code, I don't understand how such > algorithm can possibly deliver the result to 1ulp. >May be, I didn't understand something, but it looks like > your run all you steps starting from lines > vfnmadd231pd ymm5, ymm0, ymm6 ; ymm5 = x*y - 1 > vfnmadd132pd ymm0, ymm2, ymm6 ; ymm0 = 2.0 - x*y > in what I would call "open loop". So, rounding errors accumulate. > I expect that in the worst case rounding errors would accumulate > to something like 4 ulp in the end. > I'd rather do iteration 1-3 in open loop, because, as you > demonstrated, it saves latency, but on the last iteration I'd > return to closed loop vs original input value. I suppose, it will > cost 5 more clocks in latency (or 4 clocks on Skylake), but as > they say, it does not matter how fast we are able to calculate > a wrong result. The problem with your analysis is that you aren't thinking in FMA mode. The algorithm is, given R and an initial approximation to its reciprocal x0 to compute x1 = 2*x0-R*x0**2. In the improved version, first we compute y0 = 1-R*x0, then x1 = x0+x0*y0. Then we can move ahead and calculate y1 = 1-R*x1 = 1-R*(x0+x0*y0) = 1-R*x0-R*x0*(1-R*x0) = (1-R*x0)**2 = y0**2. so now y1 is ready at the same time as x1, so we can crunch out x2 and y2 at the same time. I take it that you have followed this so far from looking at my code. But what gives this algorithm surprising accuracy is the fact that we are calculating y0 = 1-R*x0 via an FMA, which Intel claims "adds the negated infinite precision intermediate result to the two or four packed double-precision floating-point values in the second source operand, performs rounding and stores the resulting two or four packed double- precision floating-point values to the destination operand" Thus in an expression where one would expect loss of precision due to subtracting two nearly equal values (and the farthest apart they can be is about 5% in the first iteration) in fact no precision is lost so it's like performing the calculation in extended precision. The result may be a little shaky in its last ulp, but in the context where it will be used (multiplied by x0 with the result added to x0 in a single FMA operation) that last ulp gets shifted out by at least 4 bits in the first iteration, many more in subsequent iterations. Thus even if y3 is out by 8 ulps or so, the error is shifted out so far that it is a long way from making a big effect on x4. That said, it would be interesting to do the last iteration like the first: y3 = 1-R*x3, then x4 = x4+y3*x3, and compare accuracy with perfectly rounded results because according to Intel's statement it should have the effect of carrying out that calculation in quad precision, but sadly that's an exercise I will have to leave to others.
[toc] | [prev] | [next] | [standalone]
| From | already5chosen@yahoo.com |
|---|---|
| Date | 2016-01-20 11:13 -0800 |
| Subject | Re: t cluttered |
| Message-ID | <3e961c0f-a836-4934-a8e4-b2e506a3871e@googlegroups.com> |
| In reply to | #32967 |
On Wednesday, January 20, 2016 at 8:35:19 PM UTC+2, James Van Buskirk wrote: > wrote in message > news:227ce46c-6178-4cf3-8716-45f8cb5e0bf5@googlegroups.com... > > > Looking at your code, I don't understand how such > > algorithm can possibly deliver the result to 1ulp. > >May be, I didn't understand something, but it looks like > > your run all you steps starting from lines > > vfnmadd231pd ymm5, ymm0, ymm6 ; ymm5 = x*y - 1 > > vfnmadd132pd ymm0, ymm2, ymm6 ; ymm0 = 2.0 - x*y > > in what I would call "open loop". So, rounding errors accumulate. > > I expect that in the worst case rounding errors would accumulate > > to something like 4 ulp in the end. > > > I'd rather do iteration 1-3 in open loop, because, as you > > demonstrated, it saves latency, but on the last iteration I'd > > return to closed loop vs original input value. I suppose, it will > > cost 5 more clocks in latency (or 4 clocks on Skylake), but as > > they say, it does not matter how fast we are able to calculate > > a wrong result. > > The problem with your analysis is that you aren't thinking in > FMA mode. I think, I took it into account. That's why I said wrst case = 4 ulp rather than 6-7 ulp. > The algorithm is, given R and an initial approximation > to its reciprocal x0 to compute x1 = 2*x0-R*x0**2. In the improved > version, first we compute y0 = 1-R*x0, then x1 = x0+x0*y0. Then > we can move ahead and calculate > y1 = 1-R*x1 = 1-R*(x0+x0*y0) = 1-R*x0-R*x0*(1-R*x0) = (1-R*x0)**2 = y0**2. > so now y1 is ready at the same time as x1, so we can crunch out > x2 and y2 at the same time. > > I take it that you have followed this so far from looking at my code. > But what gives this algorithm surprising accuracy is the fact that > we are calculating y0 = 1-R*x0 via an FMA, which Intel claims > > "adds the negated infinite precision intermediate result > to the two or four packed double-precision floating-point > values in the second source operand, performs rounding > and stores the resulting two or four packed double- > precision floating-point values to the destination operand" > > Thus in an expression where one would expect loss of > precision due to subtracting two nearly equal values (and > the farthest apart they can be is about 5% in the first > iteration) in fact no precision is lost so it's like performing > the calculation in extended precision. The result may be a > little shaky in its last ulp, but in the context where it will be > used (multiplied by x0 with the result added to x0 in a single > FMA operation) that last ulp gets shifted out by at least 4 > bits in the first iteration, many more in subsequent > iterations. Thus even if y3 is out by 8 ulps or so, the error > is shifted out so far that it is a long way from making a big > effect on x4. > At the end, you calculate a correction factor as a polynomial of 8th degree with the argument eps = x0*y-1 and then multiply x0 by correction factor. The fact that you do it gradually does not change the fact that it's what you are doing. May be, I overestimated the worst case for the error, may be, it's only 2 ulp, but I can't see how it could be 1 ulp. > That said, it would be interesting to do the last iteration like > the first: y3 = 1-R*x3, then x4 = x4+y3*x3, and compare > accuracy with perfectly rounded results because according > to Intel's statement it should have the effect of carrying out > that calculation in quad precision, but sadly that's an exercise > I will have to leave to others. Unfortunately, I have no FMA-capable HW at home. And doing tests at work would not be fair to my employer. So, I also have to leave it to others.
[toc] | [prev] | [next] | [standalone]
| From | already5chosen@yahoo.com |
|---|---|
| Date | 2016-01-20 15:15 -0800 |
| Subject | Re: t cluttered |
| Message-ID | <be793758-07b7-4b47-84fd-4938f18838e6@googlegroups.com> |
| In reply to | #32969 |
On Wednesday, January 20, 2016 at 9:13:51 PM UTC+2, already...@yahoo.com wrote: > On Wednesday, January 20, 2016 at 8:35:19 PM UTC+2, James Van Buskirk wrote: > > wrote in message > > news:227ce46c-6178-4cf3-8716-45f8cb5e0bf5@googlegroups.com... > > > > > Looking at your code, I don't understand how such > > > algorithm can possibly deliver the result to 1ulp. > > >May be, I didn't understand something, but it looks like > > > your run all you steps starting from lines > > > vfnmadd231pd ymm5, ymm0, ymm6 ; ymm5 = x*y - 1 > > > vfnmadd132pd ymm0, ymm2, ymm6 ; ymm0 = 2.0 - x*y > > > in what I would call "open loop". So, rounding errors accumulate. > > > I expect that in the worst case rounding errors would accumulate > > > to something like 4 ulp in the end. > > > > > I'd rather do iteration 1-3 in open loop, because, as you > > > demonstrated, it saves latency, but on the last iteration I'd > > > return to closed loop vs original input value. I suppose, it will > > > cost 5 more clocks in latency (or 4 clocks on Skylake), but as > > > they say, it does not matter how fast we are able to calculate > > > a wrong result. > > > > The problem with your analysis is that you aren't thinking in > > FMA mode. > > I think, I took it into account. That's why I said wrst case = 4 ulp rather than 6-7 ulp. > > > The algorithm is, given R and an initial approximation > > to its reciprocal x0 to compute x1 = 2*x0-R*x0**2. In the improved > > version, first we compute y0 = 1-R*x0, then x1 = x0+x0*y0. Then > > we can move ahead and calculate > > y1 = 1-R*x1 = 1-R*(x0+x0*y0) = 1-R*x0-R*x0*(1-R*x0) = (1-R*x0)**2 = y0**2. > > so now y1 is ready at the same time as x1, so we can crunch out > > x2 and y2 at the same time. > > > > I take it that you have followed this so far from looking at my code. > > But what gives this algorithm surprising accuracy is the fact that > > we are calculating y0 = 1-R*x0 via an FMA, which Intel claims > > > > "adds the negated infinite precision intermediate result > > to the two or four packed double-precision floating-point > > values in the second source operand, performs rounding > > and stores the resulting two or four packed double- > > precision floating-point values to the destination operand" > > > > Thus in an expression where one would expect loss of > > precision due to subtracting two nearly equal values (and > > the farthest apart they can be is about 5% in the first > > iteration) in fact no precision is lost so it's like performing > > the calculation in extended precision. The result may be a > > little shaky in its last ulp, but in the context where it will be > > used (multiplied by x0 with the result added to x0 in a single > > FMA operation) that last ulp gets shifted out by at least 4 > > bits in the first iteration, many more in subsequent > > iterations. Thus even if y3 is out by 8 ulps or so, the error > > is shifted out so far that it is a long way from making a big > > effect on x4. > > > > At the end, you calculate a correction factor as a polynomial of 8th degree with the argument eps = x0*y-1 and then multiply x0 by correction factor. The fact that you do it gradually does not change the fact that it's what you are doing. > May be, I overestimated the worst case for the error, may be, it's only 2 ulp, but I can't see how it could be 1 ulp. > > > That said, it would be interesting to do the last iteration like > > the first: y3 = 1-R*x3, then x4 = x4+y3*x3, and compare > > accuracy with perfectly rounded results because according > > to Intel's statement it should have the effect of carrying out > > that calculation in quad precision, but sadly that's an exercise > > I will have to leave to others. > > Unfortunately, I have no FMA-capable HW at home. And doing tests at work would not be fair to my employer. > So, I also have to leave it to others. After a little thinking I found a way to test it at home. I emulated FMA with gcc use of __float128 for intermediate result. Since a mantissa of __float128 is more than twice wider than IEEE double such emulation should be sufficient. The results are very close to what I expected. The worst case error of your algorithm in the ranges it works = 3 ulp. Here are few arguments that produce error = 3 ULP: 1.00030175425301750000 1.00107950051079490000 1.00259220252592200000 1.00415579054155790000 1.00416244041662430000 1.00440299241903010000 1.00498586842485870000 1.00805377383053800000 1.00981049734810500000 1.01012680010126820000 The worst case error after my modification (replacement of last iteration by x *= fmsub(2.0, x, y); ) brings the error down to 1 ULP. There were also defects that I didn't expect: 1. The precision blows for arguments above DBL_MAX/4 2. The output is non-monotonic. Both defects are not fixed by my modification. In fact, after my modification violations of monotonocity become even more frequent.
[toc] | [prev] | [next] | [standalone]
| From | "James Van Buskirk" <not_valid@comcast.net> |
|---|---|
| Date | 2016-01-20 17:29 -0700 |
| Subject | Re: t cluttered |
| Message-ID | <n7p8l0$nsa$1@dont-email.me> |
| In reply to | #32984 |
wrote in message
news:be793758-07b7-4b47-84fd-4938f18838e6@googlegroups.com...
> On Wednesday, January 20, 2016 at 9:13:51 PM UTC+2, already...@yahoo.com
> wrote:
> > On Wednesday, January 20, 2016 at 8:35:19 PM UTC+2, James Van Buskirk
> > wrote:
> > > That said, it would be interesting to do the last iteration like
> > > the first: y3 = 1-R*x3, then x4 = x4+y3*x3, and compare
> > > accuracy with perfectly rounded results because according
> > > to Intel's statement it should have the effect of carrying out
> > > that calculation in quad precision, but sadly that's an exercise
> > > I will have to leave to others.
> > Unfortunately, I have no FMA-capable HW at home. And doing
> > tests at work would not be fair to my employer.
> > So, I also have to leave it to others.
> After a little thinking I found a way to test it at home.
> I emulated FMA with gcc use of __float128 for intermediate result. Since
> a mantissa of __float128 is more than twice wider than IEEE double such
> emulation should be sufficient.
> The results are very close to what I expected.
> The worst case error of your algorithm in the ranges it works = 3 ulp.
> Here are few arguments that produce error = 3 ULP:
> 1.00030175425301750000
> 1.00107950051079490000
> 1.00259220252592200000
> 1.00415579054155790000
> 1.00416244041662430000
> 1.00440299241903010000
> 1.00498586842485870000
> 1.00805377383053800000
> 1.00981049734810500000
> 1.01012680010126820000
> The worst case error after my modification (replacement of last iteration
> by x *= fmsub(2.0, x, y); ) brings the error down to 1 ULP.
> There were also defects that I didn't expect:
> 1. The precision blows for arguments above DBL_MAX/4
> 2. The output is non-monotonic.
> Both defects are not fixed by my modification. In fact, after my
> modification
> violations of monotonocity become even more frequent.
I hate myself. I am an assembly language whore with no sense of self-
discipline. :(
D:\gfortran\clf\reciprocal>type recip2.asm
; recip2.asm -- clean version
format MS64 coff
public recip
section '.text' code readable executable
recip:
; Load constants and input
vbroadcastsd ymm1, [one]
vpbroadcastq ymm4, [magic]
vmovdqu ymm0, [rcx]
; ymm0 is input
; Begin approximation
vpsubq ymm2, ymm4, ymm0
; ymm2 is initial approximation
; First N-R iteration
vfnmadd213pd ymm0, ymm2, ymm1
vfmadd132pd ymm2, ymm2, ymm0
vmulpd ymm0, ymm0, ymm0
; Second N-R iteration
vfmadd132pd ymm2, ymm2, ymm0
vmulpd ymm0, ymm0, ymm0
; Third N-R iteration
vfmadd132pd ymm2, ymm2, ymm0
vmulpd ymm0, ymm0, ymm0
; Fourth N-R iteration
vfmadd132pd ymm0, ymm2, ymm2
; Store output
vmovups [rcx], ymm0
ret
section '.data' readable writeable align 16
align 16
one dq 3FF0000000000000h
magic dq 7FDE6238502484BAh
D:\gfortran\clf\reciprocal>type recip3.asm
; recip3.asm -- accurate version
format MS64 coff
public recip
section '.text' code readable executable
recip:
; Load constants and input
vbroadcastsd ymm1, [one]
vpbroadcastq ymm4, [magic]
vmovdqu ymm0, [rcx]
; ymm0 is input
; Begin approximation
vpsubq ymm2, ymm4, ymm0
; ymm2 is initial approximation
; First N-R iteration
vfnmadd213pd ymm0, ymm2, ymm1
vfmadd132pd ymm2, ymm2, ymm0
vmulpd ymm0, ymm0, ymm0
; Second N-R iteration
vfmadd132pd ymm2, ymm2, ymm0
vmulpd ymm0, ymm0, ymm0
; Third N-R iteration
vfmadd132pd ymm0, ymm2, ymm2
; Fourth N-R iteration
vmovups ymm2, [rcx]
vfnmadd213pd ymm2, ymm0, ymm1
vfmadd231pd ymm0, ymm2, ymm0
; Store output
vmovups [rcx], ymm0
ret
section '.data' readable writeable align 16
align 16
one dq 3FF0000000000000h
magic dq 7FDE6238502484BAh
D:\gfortran\clf\reciprocal>type ulps.f90
program ulps
use ISO_FORTRAN_ENV
implicit none
interface
subroutine recip(x) bind(C,name='recip')
import
implicit none
real(REAL64) x(4)
end subroutine recip
end interface
integer i, j
real(REAL64) x(4), y(4), e(4)
real(REAL128) z(4)
integer b(4), h(-31:31)
! Randomizes in ifort -- more difficult in gfortran
call random_seed()
h = 0
do i = 1, 10000000
call random_number(x)
x = x+1
y = x
call recip(y)
z = x
z = 1/z
e = (y-z)/spacing(y)
b = nint(10*e)
b = min(max(b,lbound(h,1)),ubound(h,1))
do j = 1, 4
h(b(j)) = h(b(j))+1
end do
end do
do j = lbound(h,1),ubound(h,1)
write(*,*) j, h(j)
end do
end program ulps
D:\gfortran\clf\reciprocal>type ulps.txt
Results for 4e7 random inputs.
Bins are 0.1 ulps wide.
Clean version:
-31 0
-30 0
-29 0
-28 0
-27 0
-26 0
-25 0
-24 0
-23 0
-22 0
-21 0
-20 9
-19 797
-18 5171
-17 16807
-16 39430
-15 76588
-14 135177
-13 219552
-12 330655
-11 477925
-10 660440
-9 879433
-8 1128662
-7 1397261
-6 1668195
-5 1937880
-4 2188852
-3 2398981
-2 2560148
-1 2662296
0 2698265
1 2654846
2 2543898
3 2376599
4 2160164
5 1908524
6 1638941
7 1367804
8 1104850
9 857508
10 642918
11 462662
12 320888
13 211468
14 130684
15 75092
16 38324
17 16501
18 5015
19 775
20 15
21 0
22 0
23 0
24 0
25 0
26 0
27 0
28 0
29 0
30 0
31 0
Accurate version:
-31 0
-30 0
-29 0
-28 0
-27 0
-26 0
-25 0
-24 0
-23 0
-22 0
-21 0
-20 0
-19 0
-18 0
-17 0
-16 0
-15 0
-14 0
-13 0
-12 0
-11 0
-10 0
-9 0
-8 0
-7 0
-6 0
-5 1998410
-4 3998147
-3 4001437
-2 3998365
-1 3998460
0 4002489
1 4000235
2 4002090
3 3999992
4 3999175
5 2001200
6 0
7 0
8 0
9 0
10 0
11 0
12 0
13 0
14 0
15 0
16 0
17 0
18 0
19 0
20 0
21 0
22 0
23 0
24 0
25 0
26 0
27 0
28 0
29 0
30 0
31 0
D:\gfortran\clf\reciprocal>type recip4.asm
; recip4.asm -- latency test
format MS64 coff
public recip
public _rdtsc
section '.text' code readable executable
recip:
; Load constants and input
vbroadcastsd ymm1, [one]
vpbroadcastq ymm4, [magic]
vmovdqu ymm0, [rcx]
; 100 iterations
mov eax, 101
.loop:
vpsubq ymm2, ymm4, ymm0
vfnmadd213pd ymm0, ymm2, ymm1
vfmadd132pd ymm2, ymm2, ymm0
vmulpd ymm0, ymm0, ymm0
vfmadd132pd ymm2, ymm2, ymm0
vmulpd ymm0, ymm0, ymm0
vfmadd132pd ymm2, ymm2, ymm0
vmulpd ymm0, ymm0, ymm0
vfmadd132pd ymm0, ymm2, ymm2
dec eax
jnz .loop
vmovups [rcx], ymm0
ret
_rdtsc:
rdtsc
shl rdx, 32
or rax, rdx
ret
section '.data' readable writeable align 16
align 16
one dq 3FF0000000000000h
magic dq 7FDE6238502484BAh
D:\gfortran\clf\reciprocal>type latency.f90
program latency
use ISO_FORTRAN_ENV
implicit none
interface
subroutine recip(x) bind(C,name='recip')
import
implicit none
real(REAL64) x(4)
end subroutine recip
function rdtsc() bind(C,name='_rdtsc')
import
implicit none
integer(INT64) rdtsc
end function rdtsc
end interface
integer i
integer, parameter :: N = 11
integer(INT64) t0(N),t1(N),t2(N)
real(REAL64) x(4), y(4)
! Randomizes in ifort -- more difficult in gfortran
call random_seed()
call random_number(x)
x = x+1
y = x
do i = 1, N
t0(i) = rdtsc()
t1(i) = rdtsc()
call recip(y)
t2(i) = rdtsc()
end do
do i = 1, 4
write(*,'(g0,2(1x,Z16.16))') x(i),transfer([y(i),1/x(i)],t0)
end do
do i = 1, N
write(*,*) t1(i)-t0(i),t2(i)-t1(i)
end do
end program latency
D:\gfortran\clf\reciprocal>type latency.txt
Timing results for 101 iterations
1.800036018715733 3FE1C70521904A6F 3FE1C70521904A5F
1.717589637262335 3FE2A17979BBA438 3FE2A17979BBA437
1.116468334989533 3FECA96C2FE79D00 3FECA96C2FE79CFF
1.903738008261531 3FE0CF1CF56B3632 3FE0CF1CF56B3632
460 5172
24 34272
24 2952
24 2952
24 2952
24 2952
24 2952
24 2952
24 2952
24 2952
24 2952
D:\gfortran\clf\reciprocal>type recip5.asm
; recip5.asm -- throughput test
format MS64 coff
public recip
public _rdtsc
section '.text' code readable executable
recip:
; Load constants and input
vbroadcastsd ymm1, [one]
vpbroadcastq ymm4, [magic]
xor eax, eax
.loop:
vmovdqu ymm0, [rcx+rax]
vpsubq ymm2, ymm4, ymm0
vfnmadd213pd ymm0, ymm2, ymm1
vfmadd132pd ymm2, ymm2, ymm0
vmulpd ymm0, ymm0, ymm0
vfmadd132pd ymm2, ymm2, ymm0
vmulpd ymm0, ymm0, ymm0
vfmadd132pd ymm2, ymm2, ymm0
vmulpd ymm0, ymm0, ymm0
vfmadd132pd ymm0, ymm2, ymm2
vmovups [rcx+rax], ymm0
vmovdqu ymm3, [rcx+rax+32]
vpsubq ymm10, ymm4, ymm3
vfnmadd213pd ymm3, ymm10, ymm1
vfmadd132pd ymm10, ymm10, ymm3
vmulpd ymm3, ymm3, ymm3
vfmadd132pd ymm10, ymm10, ymm3
vmulpd ymm3, ymm3, ymm3
vfmadd132pd ymm10, ymm10, ymm3
vmulpd ymm3, ymm3, ymm3
vfmadd132pd ymm3, ymm10, ymm10
vmovups [rcx+rax+32], ymm3
vmovdqu ymm5, [rcx+rax+64]
vpsubq ymm11, ymm4, ymm5
vfnmadd213pd ymm5, ymm11, ymm1
vfmadd132pd ymm11, ymm11, ymm5
vmulpd ymm5, ymm5, ymm5
vfmadd132pd ymm11, ymm11, ymm5
vmulpd ymm5, ymm5, ymm5
vfmadd132pd ymm11, ymm11, ymm5
vmulpd ymm5, ymm5, ymm5
vfmadd132pd ymm5, ymm11, ymm11
vmovups [rcx+rax+64], ymm5
vmovdqu ymm6, [rcx+rax+96]
vpsubq ymm12, ymm4, ymm6
vfnmadd213pd ymm6, ymm12, ymm1
vfmadd132pd ymm12, ymm12, ymm6
vmulpd ymm6, ymm6, ymm6
vfmadd132pd ymm12, ymm12, ymm6
vmulpd ymm6, ymm6, ymm6
vfmadd132pd ymm12, ymm12, ymm6
vmulpd ymm6, ymm6, ymm6
vfmadd132pd ymm6, ymm12, ymm12
vmovups [rcx+rax+96], ymm6
vmovdqu ymm7, [rcx+rax+128]
vpsubq ymm13, ymm4, ymm7
vfnmadd213pd ymm7, ymm13, ymm1
vfmadd132pd ymm13, ymm13, ymm7
vmulpd ymm7, ymm7, ymm7
vfmadd132pd ymm13, ymm13, ymm7
vmulpd ymm7, ymm7, ymm7
vfmadd132pd ymm13, ymm13, ymm7
vmulpd ymm7, ymm7, ymm7
vfmadd132pd ymm7, ymm13, ymm13
vmovups [rcx+rax+128], ymm7
vmovdqu ymm8, [rcx+rax+160]
vpsubq ymm14, ymm4, ymm8
vfnmadd213pd ymm8, ymm14, ymm1
vfmadd132pd ymm14, ymm14, ymm8
vmulpd ymm8, ymm8, ymm8
vfmadd132pd ymm14, ymm14, ymm8
vmulpd ymm8, ymm8, ymm8
vfmadd132pd ymm14, ymm14, ymm8
vmulpd ymm8, ymm8, ymm8
vfmadd132pd ymm8, ymm14, ymm14
vmovups [rcx+rax+160], ymm8
vmovdqu ymm9, [rcx+rax+192]
vpsubq ymm15, ymm4, ymm9
vfnmadd213pd ymm9, ymm15, ymm1
vfmadd132pd ymm15, ymm15, ymm9
vmulpd ymm9, ymm9, ymm9
vfmadd132pd ymm15, ymm15, ymm9
vmulpd ymm9, ymm9, ymm9
vfmadd132pd ymm15, ymm15, ymm9
vmulpd ymm9, ymm9, ymm9
vfmadd132pd ymm9, ymm15, ymm15
vmovups [rcx+rax+192], ymm9
add rax, 224
cmp rax, 4032
jl .loop
ret
_rdtsc:
rdtsc
shl rdx, 32
or rax, rdx
ret
section '.data' readable writeable align 16
align 16
one dq 3FF0000000000000h
magic dq 7FDE6238502484BAh
D:\gfortran\clf\reciprocal>type throughput.f90
program throughput
use ISO_FORTRAN_ENV
implicit none
interface
subroutine recip(x) bind(C,name='recip')
import
implicit none
real(REAL64) x(504)
end subroutine recip
function rdtsc() bind(C,name='_rdtsc')
import
implicit none
integer(INT64) rdtsc
end function rdtsc
end interface
integer, parameter :: N = 11
integer(INT64) t0(N),t1(N),t2(N)
real(REAL64) x(504), y(504)
integer i
real(REAL64) e(N)
! Randomizes in ifort -- more difficult in gfortran
call random_seed()
do i = 1, N
call random_number(x)
x = x+1
y = x
t0(i) = rdtsc()
t1(i) = rdtsc()
call recip(y)
t2(i) = rdtsc()
e(i) = maxval(abs(x*y-1))
end do
do i = 1, N
write(*,*) e(i),t1(i)-t0(i),t2(i)-t1(i)
end do
end program throughput
D:\gfortran\clf\reciprocal>type throughput.txt
Throughput test -- times are for 126 4-wide reciprocals
3.245960970242422E-016 32 1000
3.335530364899758E-016 24 672
3.609633370502643E-016 24 692
3.288326655173688E-016 32 636
2.739967408823667E-016 28 648
3.125845080721156E-016 28 632
2.827280702585918E-016 32 644
2.946925082685644E-016 28 640
3.598911741818497E-016 32 648
3.324698544377006E-016 32 636
2.942004556645072E-016 28 636
So accuracy is an error of up to 2 ulps for the 'clean' version
and 0.5 ulps for the accurate version with a full ab initio N-R
iteration #4.
Latency is almost 29 clocks, 3 worse than my estimate and
reciprocal throughput is 4.9 clocks, almost 1 whole clock
worse than my estimate. Happy now?
[toc] | [prev] | [next] | [standalone]
| From | Terje Mathisen <terje.mathisen@tmsw.no> |
|---|---|
| Date | 2016-01-21 08:42 +0100 |
| Subject | Re: t cluttered |
| Message-ID | <n7q254$12jm$2@gioia.aioe.org> |
| In reply to | #32985 |
James Van Buskirk wrote: > wrote in message > news:be793758-07b7-4b47-84fd-4938f18838e6@googlegroups.com... At the very end you wrote: > Latency is almost 29 clocks, 3 worse than my estimate and > reciprocal throughput is 4.9 clocks, almost 1 whole clock > worse than my estimate. Happy now? I am extremely happy James, the 0.5 ulp maximum error you found with random testing means that except for a few possible extreme borderline cases your code produces IEEE results. This would indeed be useful in any kind of vectorized division operation. Thanks you! Terje > D:\gfortran\clf\reciprocal>type recip2.asm > ; recip2.asm -- clean version > format MS64 coff > > public recip > section '.text' code readable executable > recip: > ; Load constants and input > vbroadcastsd ymm1, [one] > vpbroadcastq ymm4, [magic] > vmovdqu ymm0, [rcx] > ; ymm0 is input > ; Begin approximation > vpsubq ymm2, ymm4, ymm0 > ; ymm2 is initial approximation > ; First N-R iteration > vfnmadd213pd ymm0, ymm2, ymm1 > vfmadd132pd ymm2, ymm2, ymm0 > vmulpd ymm0, ymm0, ymm0 > ; Second N-R iteration > vfmadd132pd ymm2, ymm2, ymm0 > vmulpd ymm0, ymm0, ymm0 > ; Third N-R iteration > vfmadd132pd ymm2, ymm2, ymm0 > vmulpd ymm0, ymm0, ymm0 > ; Fourth N-R iteration > vfmadd132pd ymm0, ymm2, ymm2 > ; Store output > vmovups [rcx], ymm0 > ret > > section '.data' readable writeable align 16 > align 16 > one dq 3FF0000000000000h > magic dq 7FDE6238502484BAh > > D:\gfortran\clf\reciprocal>type recip3.asm > ; recip3.asm -- accurate version > format MS64 coff > > public recip > section '.text' code readable executable > recip: > ; Load constants and input > vbroadcastsd ymm1, [one] > vpbroadcastq ymm4, [magic] > vmovdqu ymm0, [rcx] > ; ymm0 is input > ; Begin approximation > vpsubq ymm2, ymm4, ymm0 > ; ymm2 is initial approximation > ; First N-R iteration > vfnmadd213pd ymm0, ymm2, ymm1 > vfmadd132pd ymm2, ymm2, ymm0 > vmulpd ymm0, ymm0, ymm0 > ; Second N-R iteration > vfmadd132pd ymm2, ymm2, ymm0 > vmulpd ymm0, ymm0, ymm0 > ; Third N-R iteration > vfmadd132pd ymm0, ymm2, ymm2 > ; Fourth N-R iteration > vmovups ymm2, [rcx] > vfnmadd213pd ymm2, ymm0, ymm1 > vfmadd231pd ymm0, ymm2, ymm0 > ; Store output > vmovups [rcx], ymm0 > ret > -- - <Terje.Mathisen at tmsw.no> "almost all programming can be viewed as an exercise in caching"
[toc] | [prev] | [next] | [standalone]
| From | already5chosen@yahoo.com |
|---|---|
| Date | 2016-01-21 03:15 -0800 |
| Subject | Re: t cluttered |
| Message-ID | <a43728d0-42e3-422e-94b4-84813fd45efe@googlegroups.com> |
| In reply to | #32989 |
On Thursday, January 21, 2016 at 9:42:36 AM UTC+2, Terje Mathisen wrote:
> James Van Buskirk wrote:
> > wrote in message
> > news:be793758-07b7-4b47-84fd-4938f18838e6@googlegroups.com...
>
> At the very end you wrote:
> > Latency is almost 29 clocks, 3 worse than my estimate and
> > reciprocal throughput is 4.9 clocks, almost 1 whole clock
> > worse than my estimate. Happy now?
>
> I am extremely happy James, the 0.5 ulp maximum error you found with
> random testing means that except for a few possible extreme borderline
> cases your code produces IEEE results. This would indeed be useful in
> any kind of vectorized division operation.
>
> Thanks you!
>
> Terje
>
I think, James's tests illustrate following points:
1. Even when we cut corners on input range and on IEEE compliance, N-R division can't match the latency of uber-competent SRT division. But it can come very close if the hardware will assist it with [fast] 14-bit initial approximation.
2. N-R division has great potential for throughput-bound vector case.
3. But if we want to use it in general-purpose libraries rather than in our own applications that know exactly what is the range of the arguments and for *division* rather than for reciprocal then we have to take care of arguments in range [DBL_MAX/4..DBL_MAX]. If application was a mere reciprocal then providing initial approximation that is as good in this range as it is in other ranges would be sufficient. But for division it is not good enough, because with such implementation in the case of dividends >4 we will have an error of up to 3 ULP, may be, 4 ULP even when our reciprocal step is infinitely precise.
There can be several solutions to this problems, but it seems that if we want fast vector throughput then some hardware assist is necessary or at least highly desirable.
Something like the code below can be done very easily in HW as two independent instructions with latency of 1 clock each, but it will take several dependent instructions in current AVX2.
if (fabs(src1) >= 1 && fabs(src2) >= 1) {
dst1 = src1 / 4;
dst2 = src2 / 4;
} else {
dst1 = src1;
dst2 = src2;
}
[toc] | [prev] | [next] | [standalone]
| From | already5chosen@yahoo.com |
|---|---|
| Date | 2016-01-21 05:03 -0800 |
| Subject | Re: t cluttered |
| Message-ID | <c2d6451a-2a8b-4a95-9793-93050f5e9968@googlegroups.com> |
| In reply to | #32996 |
On Thursday, January 21, 2016 at 1:15:10 PM UTC+2, already...@yahoo.com wrote:
> On Thursday, January 21, 2016 at 9:42:36 AM UTC+2, Terje Mathisen wrote:
> > James Van Buskirk wrote:
> > > wrote in message
> > > news:be793758-07b7-4b47-84fd-4938f18838e6@googlegroups.com...
> >
> > At the very end you wrote:
> > > Latency is almost 29 clocks, 3 worse than my estimate and
> > > reciprocal throughput is 4.9 clocks, almost 1 whole clock
> > > worse than my estimate. Happy now?
> >
> > I am extremely happy James, the 0.5 ulp maximum error you found with
> > random testing means that except for a few possible extreme borderline
> > cases your code produces IEEE results. This would indeed be useful in
> > any kind of vectorized division operation.
> >
> > Thanks you!
> >
> > Terje
> >
>
> I think, James's tests illustrate following points:
>
> 1. Even when we cut corners on input range and on IEEE compliance, N-R division can't match the latency of uber-competent SRT division. But it can come very close if the hardware will assist it with [fast] 14-bit initial approximation.
>
> 2. N-R division has great potential for throughput-bound vector case.
>
> 3. But if we want to use it in general-purpose libraries rather than in our own applications that know exactly what is the range of the arguments and for *division* rather than for reciprocal then we have to take care of arguments in range [DBL_MAX/4..DBL_MAX]. If application was a mere reciprocal then providing initial approximation that is as good in this range as it is in other ranges would be sufficient. But for division it is not good enough, because with such implementation in the case of dividends >4 we will have an error of up to 3 ULP, may be, 4 ULP even when our reciprocal step is infinitely precise.
> There can be several solutions to this problems, but it seems that if we want fast vector throughput then some hardware assist is necessary or at least highly desirable.
> Something like the code below can be done very easily in HW as two independent instructions with latency of 1 clock each, but it will take several dependent instructions in current AVX2.
> if (fabs(src1) >= 1 && fabs(src2) >= 1) {
> dst1 = src1 / 4;
> dst2 = src2 / 4;
> } else {
> dst1 = src1;
> dst2 = src2;
> }
Well, after further thinking, my 3rd point is probably wrong. I was thinking about division in terms of calculating reciprocal of the denominator and then multiplying numirator by reciprocal. But that is a wrong approach. The correct approach is integration of multiplication into last N-R iteration.
Something like:
r = approxiamate_reciprocal(denom); // calcualted with >26.5 bits of precision, may be, few more bits needed, I'm not sure
res = num*r;
err = a - res * denom; // FMA
res = res - err * r; // FMA
With such arrangement the fact that r is a subnormal (a "big" subnormal in range [DBL_MIN/4..DBL_MIN], so there are least 51 significant bits) bears no negative impact on precision of the result.
Now when I think about it, a really problematic case is subnormal denominator input in range (0..1/DBL_MAX) in this case a reciprocal is non-representative by IEEE double. So, may be, instead of assist from my previous post, we need something completely different:
if (fabs(src1) < DBL_MIN) {
dst1 = src1 * 2^53;
dst2 = src2 * 2^53; // result can be Inf. It's o.k.
} else {
dst1 = src1;
dst2 = src2;
}
[toc] | [prev] | [next] | [standalone]
| From | Quadibloc <jsavard@ecn.ab.ca> |
|---|---|
| Date | 2016-01-21 06:42 -0800 |
| Subject | Re: t cluttered |
| Message-ID | <b2c5b1d3-89e6-4f48-8756-18acb8ed4aa4@googlegroups.com> |
| In reply to | #32996 |
On Thursday, January 21, 2016 at 4:15:10 AM UTC-7, already...@yahoo.com wrote: > 1. Even when we cut corners on input range and on IEEE compliance, N-R division > can't match the latency of uber-competent SRT division. I'm astounded to hear that, since SRT division is still done digit by digit, thus it's a "slow" division algorithm, while both Newton-Raphson and Goldschmidt divisions are "fast" algorithms, where the number of correct digits doubles with each iteration. Thus, SRT should only win for relatively low precisions. Of course, Newton-Raphson division in _software_ can't match SRT division in _hardware_ since one has vast amounts of overhead in fetching and decoding instructions and so on and so forth. Although apparently it approaches closely enough, even under that enormous handicap, that the people in Intel were able to think it a reasonable design decision to omit a division instruction from the Itanium. John Savard
[toc] | [prev] | [next] | [standalone]
| From | already5chosen@yahoo.com |
|---|---|
| Date | 2016-01-21 07:45 -0800 |
| Subject | Re: t cluttered |
| Message-ID | <b9ef2d5b-604d-4792-98cf-6409ec74d30e@googlegroups.com> |
| In reply to | #33002 |
On Thursday, January 21, 2016 at 4:42:12 PM UTC+2, Quadibloc wrote: > On Thursday, January 21, 2016 at 4:15:10 AM UTC-7, already...@yahoo.com wrote: > > > 1. Even when we cut corners on input range and on IEEE compliance, N-R division > > can't match the latency of uber-competent SRT division. > > I'm astounded to hear that, since SRT division is still done digit by digit, thus > it's a "slow" division algorithm, while both Newton-Raphson and Goldschmidt > divisions are "fast" algorithms, where the number of correct digits doubles with > each iteration. > > Thus, SRT should only win for relatively low precisions. Correct. I am talking about IEEE double. Can't say anything about higher precision. > > Of course, Newton-Raphson division in _software_ can't match SRT division in > _hardware_ since one has vast amounts of overhead in fetching and decoding > instructions and so on and so forth. I disagree. Fetching and decoding is irrelevant as long as there are no mispredicted branches. The real latency disadvatage of the software relatively to hardware are scheduling and register file access. But the significance of the former practically eliminated by the fact that we are talking about instructions with relatively long and fixed latency. And the later mostly eliminated by forwarding network. So, at the end, you couldn't do double-precision FMA in hardware with latency that is significantly better than the latency seen by the software. Now consider that your design is clocked so latency is discrete rather than continuous. So, at the end, the latency of dedicated "division" FMA will be at best 1 clock faster than the latency of FMA as seen by software, but in majority of designs it will be the same. Anyway, nobody here suggests dedicated FMA for sole purpose of division so the above paragraph has no practical meaning. > Although apparently it approaches closely > enough, even under that enormous handicap, Imaginary enormous handicap > that the people in Intel were able > to think it a reasonable design decision to omit a division instruction from > the Itanium. > > John Savard They did it back in the days when state-of-the-art SRT used much smaller radix than it is using today. And they had 82-bit floating-point execution units that made emulation significantly simpler than on 64-bit units that are present in most of the other CPUs. Also, on Itanium fma traditionally took 4 clocks. That's not uncommon on other families, but 5-6 clocks appear more common. BTW, their approximation of reciprocal has precision of slightly less than 9 bits. Looks like they were optimizing for 82-bit case (64-bit mantissa) rather than for 64-bit case, otherwise they would probably go with either 7 or 14 bits. I took a look in Itanium Software development manual at how they handle special cases. The answer is - with software assist, slowly. But detection of special case is fast and integrated into initial approximation of reciprocal.
[toc] | [prev] | [next] | [standalone]
| From | Terje Mathisen <terje.mathisen@tmsw.no> |
|---|---|
| Date | 2016-01-21 21:30 +0100 |
| Subject | Re: t cluttered |
| Message-ID | <n7rf4s$1uo2$1@gioia.aioe.org> |
| In reply to | #33006 |
already5chosen@yahoo.com wrote:
> I took a look in Itanium Software development manual at how they
> handle special cases. The answer is - with software assist, slowly.
> But detection of special case is fast and integrated into initial
> approximation of reciprocal.
This is the crucial difference between hw and sw fp implementations:
The actual calculations are relatively easy to emulate, the hard parts
are detecting and handling all the special cases!
Since I have spent significant time on sw emulation of IEEE FP
operations on small Mills now I feel competent to state that as long as
you have hw assists for those parts that are easy to do in hw but
complicated in sw (mostly manyway compare/branch logic) a modern cpu
with fast unsigned MUL can emulate the FP hardware with pretty
reasonable performance.
BTW, for detecting special cases I like the following logic:
bool is_special(double x)
{
uint64_t xi;
memcpy(xi, x, sizeof(x));
return ((xi + HIDDENBIT_VALUE) & ~SIGNBIT_VALUE <
HIDDENBIT_VALUE*2);
}
I.e. take the fp value as an unsigned integer, add 1 to the exponent
field and mask away the sign bit:
If the input is +/-Inf or NaN then the exp will wrap around to zero.
If x == +/-0 then we get a single 1 bit in the bottom of the exponent
and a zero mantissa.
If x == +/-Denorm then we have the same as above but a non-zero mantissa
All normal inputs result in a value >= 2 in the exponent field.
A hw helper can easily separate out all the special values in a single
cycle, without having to do any actual addition, mask or compare, just
checking for exp == 0 or exp == max, along with mant == 0.
Terje
--
- <Terje.Mathisen at tmsw.no>
"almost all programming can be viewed as an exercise in caching"
[toc] | [prev] | [next] | [standalone]
| From | MitchAlsup <MitchAlsup@aol.com> |
|---|---|
| Date | 2016-01-21 16:17 -0800 |
| Subject | Re: t cluttered |
| Message-ID | <a7ba101f-82ee-42b8-8e34-798efe22e8e9@googlegroups.com> |
| In reply to | #33006 |
On Thursday, January 21, 2016 at 9:45:46 AM UTC-6, already...@yahoo.com wrote: > > Of course, Newton-Raphson division in _software_ can't match SRT division in > > _hardware_ since one has vast amounts of overhead in fetching and decoding > > instructions and so on and so forth. > > I disagree. > Fetching and decoding is irrelevant as long as there are no mispredicted branches. The real latency disadvatage of the software relatively to hardware are scheduling and register file access. In 32-bit IEEE floating point: A) perhaps this would be a good time to state that GPUs are performing a 1.5 ULP reciprocation in the same latency as an FMAD instruction (4 cycles). B) I coded up a HW reciprocation that was 1.0 ULP that was a single cycle longer. A would take 2 NR iterations to achieve 0.5 ULP, while B takes only 1. A pipelined SRT divider was coded that would take 10 or 11 total cycles that the HW accelerated SW above. This particular SRT did radix 16 as 2 stages of radix 4 per cycle at 7 gates per SRT step. This SRT was fully pipelined and could start a new division every cycle.
[toc] | [prev] | [next] | [standalone]
Page 8 of 10 — ← Prev page 1 … 6 7 [8] 9 10 Next page →
Back to top | Article view | comp.arch
csiph-web