Path: csiph.com!news.mixmin.net!news.albasani.net!.POSTED!not-for-mail From: Melzzzzz Newsgroups: comp.arch Subject: Re: t cluttered Date: Wed, 20 Jan 2016 06:56:14 +0100 Organization: albasani.net Lines: 329 Message-ID: <20160120065614.3a7fdedd@maxa-pc> References: <856a220d-2367-4c07-8e27-a1307dbe5b55@googlegroups.com> <5ae638bc-3f6e-439d-953e-399f1a4774b7@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Trace: news.albasani.net TxPPhASlqS1BOwXav8v95GLcXfB/0Z4D3COXr1x8RS6f3jb1xdzuJt9iQgPZ9hhF32N30vbarJkGP0ebSjbVTg== NNTP-Posting-Date: Wed, 20 Jan 2016 05:56:14 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="U4eYymuI45ECUVM37fDyDttGPUTmA35en4EKIEspTSK3qi8oobTnkAKmSpLP/7uV2fQJYHFO0ZbYoZdxqaTi1nW4HVbjsxtA0wDBDTcUIyLjOzxyTojDSeMCKF1HSh1C"; mail-complaints-to="abuse@albasani.net" X-Newsreader: Claws Mail 3.13.1 (GTK+ 2.24.29; x86_64-unknown-linux-gnu) Cancel-Lock: sha1:bjijs/tUC57wqO3IgSMT6dIBpg8= Xref: csiph.com comp.arch:32934 On Tue, 19 Jan 2016 15:46:11 -0700 "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 > 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)