Simd.cpp 117 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #include "../precompiled.h"
  21. #pragma hdrstop
  22. #include "Simd_Generic.h"
  23. #include "Simd_MMX.h"
  24. #include "Simd_3DNow.h"
  25. #include "Simd_SSE.h"
  26. #include "Simd_SSE2.h"
  27. #include "Simd_SSE3.h"
  28. #include "Simd_AltiVec.h"
  29. idSIMDProcessor * processor = NULL; // pointer to SIMD processor
  30. idSIMDProcessor * generic = NULL; // pointer to generic SIMD implementation
  31. idSIMDProcessor * SIMDProcessor = NULL;
  32. /*
  33. ================
  34. idSIMD::Init
  35. ================
  36. */
  37. void idSIMD::Init( void ) {
  38. generic = new idSIMD_Generic;
  39. generic->cpuid = CPUID_GENERIC;
  40. processor = NULL;
  41. SIMDProcessor = generic;
  42. }
  43. /*
  44. ============
  45. idSIMD::InitProcessor
  46. ============
  47. */
  48. void idSIMD::InitProcessor( const char *module, bool forceGeneric ) {
  49. cpuid_t cpuid;
  50. idSIMDProcessor *newProcessor;
  51. cpuid = idLib::sys->GetProcessorId();
  52. if ( forceGeneric ) {
  53. newProcessor = generic;
  54. } else {
  55. if ( !processor ) {
  56. if ( ( cpuid & CPUID_ALTIVEC ) ) {
  57. processor = new idSIMD_AltiVec;
  58. } else if ( ( cpuid & CPUID_MMX ) && ( cpuid & CPUID_SSE ) && ( cpuid & CPUID_SSE2 ) && ( cpuid & CPUID_SSE3 ) ) {
  59. processor = new idSIMD_SSE3;
  60. } else if ( ( cpuid & CPUID_MMX ) && ( cpuid & CPUID_SSE ) && ( cpuid & CPUID_SSE2 ) ) {
  61. processor = new idSIMD_SSE2;
  62. } else if ( ( cpuid & CPUID_MMX ) && ( cpuid & CPUID_SSE ) ) {
  63. processor = new idSIMD_SSE;
  64. } else if ( ( cpuid & CPUID_MMX ) && ( cpuid & CPUID_3DNOW ) ) {
  65. processor = new idSIMD_3DNow;
  66. } else if ( ( cpuid & CPUID_MMX ) ) {
  67. processor = new idSIMD_MMX;
  68. } else {
  69. processor = generic;
  70. }
  71. processor->cpuid = cpuid;
  72. }
  73. newProcessor = processor;
  74. }
  75. if ( newProcessor != SIMDProcessor ) {
  76. SIMDProcessor = newProcessor;
  77. idLib::common->Printf( "%s using %s for SIMD processing\n", module, SIMDProcessor->GetName() );
  78. }
  79. if ( cpuid & CPUID_FTZ ) {
  80. idLib::sys->FPU_SetFTZ( true );
  81. idLib::common->Printf( "enabled Flush-To-Zero mode\n" );
  82. }
  83. if ( cpuid & CPUID_DAZ ) {
  84. idLib::sys->FPU_SetDAZ( true );
  85. idLib::common->Printf( "enabled Denormals-Are-Zero mode\n" );
  86. }
  87. }
  88. /*
  89. ================
  90. idSIMD::Shutdown
  91. ================
  92. */
  93. void idSIMD::Shutdown( void ) {
  94. if ( processor != generic ) {
  95. delete processor;
  96. }
  97. delete generic;
  98. generic = NULL;
  99. processor = NULL;
  100. SIMDProcessor = NULL;
  101. }
  102. //===============================================================
  103. //
  104. // Test code
  105. //
  106. //===============================================================
  107. #define COUNT 1024 // data count
  108. #define NUMTESTS 2048 // number of tests
  109. #define RANDOM_SEED 1013904223L //((int)idLib::sys->GetClockTicks())
  110. idSIMDProcessor *p_simd;
  111. idSIMDProcessor *p_generic;
  112. long baseClocks = 0;
  113. #ifdef _WIN32
  114. #define TIME_TYPE int
  115. #pragma warning(disable : 4731) // frame pointer register 'ebx' modified by inline assembly code
  116. long saved_ebx = 0;
  117. #define StartRecordTime( start ) \
  118. __asm mov saved_ebx, ebx \
  119. __asm xor eax, eax \
  120. __asm cpuid \
  121. __asm rdtsc \
  122. __asm mov start, eax \
  123. __asm xor eax, eax \
  124. __asm cpuid
  125. #define StopRecordTime( end ) \
  126. __asm xor eax, eax \
  127. __asm cpuid \
  128. __asm rdtsc \
  129. __asm mov end, eax \
  130. __asm mov ebx, saved_ebx \
  131. __asm xor eax, eax \
  132. __asm cpuid
  133. #elif MACOS_X
  134. #include <stdlib.h>
  135. #include <unistd.h> // this is for sleep()
  136. #include <sys/time.h>
  137. #include <sys/resource.h>
  138. #include <mach/mach_time.h>
  139. double ticksPerNanosecond;
  140. #define TIME_TYPE uint64_t
  141. #ifdef __MWERKS__ //time_in_millisec is missing
  142. /*
  143. .text
  144. .align 2
  145. .globl _GetTB
  146. _GetTB:
  147. loop:
  148. mftbu r4 ; load from TBU
  149. mftb r5 ; load from TBL
  150. mftbu r6 ; load from TBU
  151. cmpw r6, r4 ; see if old == new
  152. bne loop ; if not, carry occured, therefore loop
  153. stw r4, 0(r3)
  154. stw r5, 4(r3)
  155. done:
  156. blr ; return
  157. */
  158. typedef struct {
  159. unsigned int hi;
  160. unsigned int lo;
  161. } U64;
  162. asm void GetTB(U64 *in)
  163. {
  164. nofralloc // suppress prolog
  165. machine 603 // allows the use of mftb & mftbu functions
  166. loop:
  167. mftbu r5 // grab the upper time base register (TBU)
  168. mftb r4 // grab the lower time base register (TBL)
  169. mftbu r6 // grab the upper time base register (TBU) again
  170. cmpw r6,r5 // see if old TBU == new TBU
  171. bne- loop // loop if carry occurred (predict branch not taken)
  172. stw r4,4(r3) // store TBL in the low 32 bits of the return value
  173. stw r5,0(r3) // store TBU in the high 32 bits of the return value
  174. blr
  175. }
  176. double TBToDoubleNano( U64 startTime, U64 stopTime, double ticksPerNanosecond );
  177. #if __MWERKS__
  178. asm void GetTB( U64 * );
  179. #else
  180. void GetTB( U64 * );
  181. #endif
  182. double TBToDoubleNano( U64 startTime, U64 stopTime, double ticksPerNanosecond ) {
  183. #define K_2POWER32 4294967296.0
  184. #define TICKS_PER_NANOSECOND 0.025
  185. double nanoTime;
  186. U64 diffTime;
  187. // calc the difference in TB ticks
  188. diffTime.hi = stopTime.hi - startTime.hi;
  189. diffTime.lo = stopTime.lo - startTime.lo;
  190. // convert TB ticks into time
  191. nanoTime = (double)(diffTime.hi)*((double)K_2POWER32) + (double)(diffTime.lo);
  192. nanoTime = nanoTime/ticksPerNanosecond;
  193. return (nanoTime);
  194. }
  195. TIME_TYPE time_in_millisec( void ) {
  196. #define K_2POWER32 4294967296.0
  197. #define TICKS_PER_NANOSECOND 0.025
  198. U64 the_time;
  199. double nanoTime, milliTime;
  200. GetTB( &the_time );
  201. // convert TB ticks into time
  202. nanoTime = (double)(the_time.hi)*((double)K_2POWER32) + (double)(the_time.lo);
  203. nanoTime = nanoTime/ticksPerNanosecond;
  204. // nanoseconds are 1 billionth of a second. I want milliseconds
  205. milliTime = nanoTime * 1000000.0;
  206. printf( "ticks per nanosec -- %lf\n", ticksPerNanosecond );
  207. printf( "nanoTime is %lf -- milliTime is %lf -- as int is %i\n", nanoTime, milliTime, (int)milliTime );
  208. return (int)milliTime;
  209. }
  210. #define StartRecordTime( start ) \
  211. start = time_in_millisec();
  212. #define StopRecordTime( end ) \
  213. end = time_in_millisec();
  214. #else
  215. #define StartRecordTime( start ) \
  216. start = mach_absolute_time();
  217. #define StopRecordTime( end ) \
  218. end = mach_absolute_time();
  219. #endif
  220. #else
  221. #define TIME_TYPE int
  222. #define StartRecordTime( start ) \
  223. start = 0;
  224. #define StopRecordTime( end ) \
  225. end = 1;
  226. #endif
  227. #define GetBest( start, end, best ) \
  228. if ( !best || end - start < best ) { \
  229. best = end - start; \
  230. }
  231. /*
  232. ============
  233. PrintClocks
  234. ============
  235. */
  236. void PrintClocks( char *string, int dataCount, int clocks, int otherClocks = 0 ) {
  237. int i;
  238. idLib::common->Printf( string );
  239. for ( i = idStr::LengthWithoutColors(string); i < 48; i++ ) {
  240. idLib::common->Printf(" ");
  241. }
  242. clocks -= baseClocks;
  243. if ( otherClocks && clocks ) {
  244. otherClocks -= baseClocks;
  245. int p = (int) ( (float) ( otherClocks - clocks ) * 100.0f / (float) otherClocks );
  246. idLib::common->Printf( "c = %4d, clcks = %5d, %d%%\n", dataCount, clocks, p );
  247. } else {
  248. idLib::common->Printf( "c = %4d, clcks = %5d\n", dataCount, clocks );
  249. }
  250. }
  251. /*
  252. ============
  253. GetBaseClocks
  254. ============
  255. */
  256. void GetBaseClocks( void ) {
  257. int i, start, end, bestClocks;
  258. bestClocks = 0;
  259. for ( i = 0; i < NUMTESTS; i++ ) {
  260. StartRecordTime( start );
  261. StopRecordTime( end );
  262. GetBest( start, end, bestClocks );
  263. }
  264. baseClocks = bestClocks;
  265. }
  266. /*
  267. ============
  268. TestAdd
  269. ============
  270. */
  271. void TestAdd( void ) {
  272. int i;
  273. TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
  274. ALIGN16( float fdst0[COUNT] );
  275. ALIGN16( float fdst1[COUNT] );
  276. ALIGN16( float fsrc0[COUNT] );
  277. ALIGN16( float fsrc1[COUNT] );
  278. const char *result;
  279. idRandom srnd( RANDOM_SEED );
  280. for ( i = 0; i < COUNT; i++ ) {
  281. fsrc0[i] = srnd.CRandomFloat() * 10.0f;
  282. fsrc1[i] = srnd.CRandomFloat() * 10.0f;
  283. }
  284. idLib::common->Printf("====================================\n" );
  285. bestClocksGeneric = 0;
  286. for ( i = 0; i < NUMTESTS; i++ ) {
  287. StartRecordTime( start );
  288. p_generic->Add( fdst0, 4.0f, fsrc1, COUNT );
  289. StopRecordTime( end );
  290. GetBest( start, end, bestClocksGeneric );
  291. }
  292. PrintClocks( "generic->Add( float + float[] )", COUNT, bestClocksGeneric );
  293. bestClocksSIMD = 0;
  294. for ( i = 0; i < NUMTESTS; i++ ) {
  295. StartRecordTime( start );
  296. p_simd->Add( fdst1, 4.0f, fsrc1, COUNT );
  297. StopRecordTime( end );
  298. GetBest( start, end, bestClocksSIMD );
  299. }
  300. for ( i = 0; i < COUNT; i++ ) {
  301. if ( idMath::Fabs( fdst0[i] - fdst1[i] ) > 1e-5f ) {
  302. break;
  303. }
  304. }
  305. result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
  306. PrintClocks( va( " simd->Add( float + float[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
  307. bestClocksGeneric = 0;
  308. for ( i = 0; i < NUMTESTS; i++ ) {
  309. StartRecordTime( start );
  310. p_generic->Add( fdst0, fsrc0, fsrc1, COUNT );
  311. StopRecordTime( end );
  312. GetBest( start, end, bestClocksGeneric );
  313. }
  314. PrintClocks( "generic->Add( float[] + float[] )", COUNT, bestClocksGeneric );
  315. bestClocksSIMD = 0;
  316. for ( i = 0; i < NUMTESTS; i++ ) {
  317. StartRecordTime( start );
  318. p_simd->Add( fdst1, fsrc0, fsrc1, COUNT );
  319. StopRecordTime( end );
  320. GetBest( start, end, bestClocksSIMD );
  321. }
  322. for ( i = 0; i < COUNT; i++ ) {
  323. if ( idMath::Fabs( fdst0[i] - fdst1[i] ) > 1e-5f ) {
  324. break;
  325. }
  326. }
  327. result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
  328. PrintClocks( va( " simd->Add( float[] + float[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
  329. }
  330. /*
  331. ============
  332. TestSub
  333. ============
  334. */
  335. void TestSub( void ) {
  336. int i;
  337. TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
  338. ALIGN16( float fdst0[COUNT] );
  339. ALIGN16( float fdst1[COUNT] );
  340. ALIGN16( float fsrc0[COUNT] );
  341. ALIGN16( float fsrc1[COUNT] );
  342. const char *result;
  343. idRandom srnd( RANDOM_SEED );
  344. for ( i = 0; i < COUNT; i++ ) {
  345. fsrc0[i] = srnd.CRandomFloat() * 10.0f;
  346. fsrc1[i] = srnd.CRandomFloat() * 10.0f;
  347. }
  348. idLib::common->Printf("====================================\n" );
  349. bestClocksGeneric = 0;
  350. for ( i = 0; i < NUMTESTS; i++ ) {
  351. StartRecordTime( start );
  352. p_generic->Sub( fdst0, 4.0f, fsrc1, COUNT );
  353. StopRecordTime( end );
  354. GetBest( start, end, bestClocksGeneric );
  355. }
  356. PrintClocks( "generic->Sub( float + float[] )", COUNT, bestClocksGeneric );
  357. bestClocksSIMD = 0;
  358. for ( i = 0; i < NUMTESTS; i++ ) {
  359. StartRecordTime( start );
  360. p_simd->Sub( fdst1, 4.0f, fsrc1, COUNT );
  361. StopRecordTime( end );
  362. GetBest( start, end, bestClocksSIMD );
  363. }
  364. for ( i = 0; i < COUNT; i++ ) {
  365. if ( idMath::Fabs( fdst0[i] - fdst1[i] ) > 1e-5f ) {
  366. break;
  367. }
  368. }
  369. result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
  370. PrintClocks( va( " simd->Sub( float + float[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
  371. bestClocksGeneric = 0;
  372. for ( i = 0; i < NUMTESTS; i++ ) {
  373. StartRecordTime( start );
  374. p_generic->Sub( fdst0, fsrc0, fsrc1, COUNT );
  375. StopRecordTime( end );
  376. GetBest( start, end, bestClocksGeneric );
  377. }
  378. PrintClocks( "generic->Sub( float[] + float[] )", COUNT, bestClocksGeneric );
  379. bestClocksSIMD = 0;
  380. for ( i = 0; i < NUMTESTS; i++ ) {
  381. StartRecordTime( start );
  382. p_simd->Sub( fdst1, fsrc0, fsrc1, COUNT );
  383. StopRecordTime( end );
  384. GetBest( start, end, bestClocksSIMD );
  385. }
  386. for ( i = 0; i < COUNT; i++ ) {
  387. if ( idMath::Fabs( fdst0[i] - fdst1[i] ) > 1e-5f ) {
  388. break;
  389. }
  390. }
  391. result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
  392. PrintClocks( va( " simd->Sub( float[] + float[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
  393. }
  394. /*
  395. ============
  396. TestMul
  397. ============
  398. */
  399. void TestMul( void ) {
  400. int i;
  401. TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
  402. ALIGN16( float fdst0[COUNT] );
  403. ALIGN16( float fdst1[COUNT] );
  404. ALIGN16( float fsrc0[COUNT] );
  405. ALIGN16( float fsrc1[COUNT] );
  406. const char *result;
  407. idRandom srnd( RANDOM_SEED );
  408. for ( i = 0; i < COUNT; i++ ) {
  409. fsrc0[i] = srnd.CRandomFloat() * 10.0f;
  410. fsrc1[i] = srnd.CRandomFloat() * 10.0f;
  411. }
  412. idLib::common->Printf("====================================\n" );
  413. bestClocksGeneric = 0;
  414. for ( i = 0; i < NUMTESTS; i++ ) {
  415. StartRecordTime( start );
  416. p_generic->Mul( fdst0, 4.0f, fsrc1, COUNT );
  417. StopRecordTime( end );
  418. GetBest( start, end, bestClocksGeneric );
  419. }
  420. PrintClocks( "generic->Mul( float * float[] )", COUNT, bestClocksGeneric );
  421. bestClocksSIMD = 0;
  422. for ( i = 0; i < NUMTESTS; i++ ) {
  423. StartRecordTime( start );
  424. p_simd->Mul( fdst1, 4.0f, fsrc1, COUNT );
  425. StopRecordTime( end );
  426. GetBest( start, end, bestClocksSIMD );
  427. }
  428. for ( i = 0; i < COUNT; i++ ) {
  429. if ( idMath::Fabs( fdst0[i] - fdst1[i] ) > 1e-5f ) {
  430. break;
  431. }
  432. }
  433. result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
  434. PrintClocks( va( " simd->Mul( float * float[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
  435. bestClocksGeneric = 0;
  436. for ( i = 0; i < NUMTESTS; i++ ) {
  437. StartRecordTime( start );
  438. p_generic->Mul( fdst0, fsrc0, fsrc1, COUNT );
  439. StopRecordTime( end );
  440. GetBest( start, end, bestClocksGeneric );
  441. }
  442. PrintClocks( "generic->Mul( float[] * float[] )", COUNT, bestClocksGeneric );
  443. bestClocksSIMD = 0;
  444. for ( i = 0; i < NUMTESTS; i++ ) {
  445. StartRecordTime( start );
  446. p_simd->Mul( fdst1, fsrc0, fsrc1, COUNT );
  447. StopRecordTime( end );
  448. GetBest( start, end, bestClocksSIMD );
  449. }
  450. for ( i = 0; i < COUNT; i++ ) {
  451. if ( idMath::Fabs( fdst0[i] - fdst1[i] ) > 1e-5f ) {
  452. break;
  453. }
  454. }
  455. result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
  456. PrintClocks( va( " simd->Mul( float[] * float[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
  457. }
  458. /*
  459. ============
  460. TestDiv
  461. ============
  462. */
  463. void TestDiv( void ) {
  464. int i;
  465. TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
  466. ALIGN16( float fdst0[COUNT] );
  467. ALIGN16( float fdst1[COUNT] );
  468. ALIGN16( float fsrc0[COUNT] );
  469. ALIGN16( float fsrc1[COUNT] );
  470. const char *result;
  471. idRandom srnd( RANDOM_SEED );
  472. for ( i = 0; i < COUNT; i++ ) {
  473. fsrc0[i] = srnd.CRandomFloat() * 10.0f;
  474. do {
  475. fsrc1[i] = srnd.CRandomFloat() * 10.0f;
  476. } while( idMath::Fabs( fsrc1[i] ) < 0.1f );
  477. }
  478. idLib::common->Printf("====================================\n" );
  479. bestClocksGeneric = 0;
  480. for ( i = 0; i < NUMTESTS; i++ ) {
  481. StartRecordTime( start );
  482. p_generic->Div( fdst0, 4.0f, fsrc1, COUNT );
  483. StopRecordTime( end );
  484. GetBest( start, end, bestClocksGeneric );
  485. }
  486. PrintClocks( "generic->Div( float * float[] )", COUNT, bestClocksGeneric );
  487. bestClocksSIMD = 0;
  488. for ( i = 0; i < NUMTESTS; i++ ) {
  489. StartRecordTime( start );
  490. p_simd->Div( fdst1, 4.0f, fsrc1, COUNT );
  491. StopRecordTime( end );
  492. GetBest( start, end, bestClocksSIMD );
  493. }
  494. for ( i = 0; i < COUNT; i++ ) {
  495. if ( idMath::Fabs( fdst0[i] - fdst1[i] ) > 1e-5f ) {
  496. break;
  497. }
  498. }
  499. result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
  500. PrintClocks( va( " simd->Div( float * float[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
  501. bestClocksGeneric = 0;
  502. for ( i = 0; i < NUMTESTS; i++ ) {
  503. StartRecordTime( start );
  504. p_generic->Div( fdst0, fsrc0, fsrc1, COUNT );
  505. StopRecordTime( end );
  506. GetBest( start, end, bestClocksGeneric );
  507. }
  508. PrintClocks( "generic->Div( float[] * float[] )", COUNT, bestClocksGeneric );
  509. bestClocksSIMD = 0;
  510. for ( i = 0; i < NUMTESTS; i++ ) {
  511. StartRecordTime( start );
  512. p_simd->Div( fdst1, fsrc0, fsrc1, COUNT );
  513. StopRecordTime( end );
  514. GetBest( start, end, bestClocksSIMD );
  515. }
  516. for ( i = 0; i < COUNT; i++ ) {
  517. if ( idMath::Fabs( fdst0[i] - fdst1[i] ) > 1e-3f ) {
  518. break;
  519. }
  520. }
  521. result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
  522. PrintClocks( va( " simd->Div( float[] * float[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
  523. }
  524. /*
  525. ============
  526. TestMulAdd
  527. ============
  528. */
  529. void TestMulAdd( void ) {
  530. int i, j;
  531. TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
  532. ALIGN16( float fdst0[COUNT] );
  533. ALIGN16( float fdst1[COUNT] );
  534. ALIGN16( float fsrc0[COUNT] );
  535. const char *result;
  536. idRandom srnd( RANDOM_SEED );
  537. for ( i = 0; i < COUNT; i++ ) {
  538. fsrc0[i] = srnd.CRandomFloat() * 10.0f;
  539. }
  540. idLib::common->Printf("====================================\n" );
  541. for ( j = 0; j < 50 && j < COUNT; j++ ) {
  542. bestClocksGeneric = 0;
  543. for ( i = 0; i < NUMTESTS; i++ ) {
  544. for ( int k = 0; k < COUNT; k++ ) {
  545. fdst0[k] = k;
  546. }
  547. StartRecordTime( start );
  548. p_generic->MulAdd( fdst0, 0.123f, fsrc0, j );
  549. StopRecordTime( end );
  550. GetBest( start, end, bestClocksGeneric );
  551. }
  552. PrintClocks( va( "generic->MulAdd( float * float[%2d] )", j ), 1, bestClocksGeneric );
  553. bestClocksSIMD = 0;
  554. for ( i = 0; i < NUMTESTS; i++ ) {
  555. for ( int k = 0; k < COUNT; k++ ) {
  556. fdst1[k] = k;
  557. }
  558. StartRecordTime( start );
  559. p_simd->MulAdd( fdst1, 0.123f, fsrc0, j );
  560. StopRecordTime( end );
  561. GetBest( start, end, bestClocksSIMD );
  562. }
  563. for ( i = 0; i < COUNT; i++ ) {
  564. if ( idMath::Fabs( fdst0[i] - fdst1[i] ) > 1e-5f ) {
  565. break;
  566. }
  567. }
  568. result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
  569. PrintClocks( va( " simd->MulAdd( float * float[%2d] ) %s", j, result ), 1, bestClocksSIMD, bestClocksGeneric );
  570. }
  571. }
  572. /*
  573. ============
  574. TestMulSub
  575. ============
  576. */
  577. void TestMulSub( void ) {
  578. int i, j;
  579. TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
  580. ALIGN16( float fdst0[COUNT] );
  581. ALIGN16( float fdst1[COUNT] );
  582. ALIGN16( float fsrc0[COUNT] );
  583. const char *result;
  584. idRandom srnd( RANDOM_SEED );
  585. for ( i = 0; i < COUNT; i++ ) {
  586. fsrc0[i] = srnd.CRandomFloat() * 10.0f;
  587. }
  588. idLib::common->Printf("====================================\n" );
  589. for ( j = 0; j < 50 && j < COUNT; j++ ) {
  590. bestClocksGeneric = 0;
  591. for ( i = 0; i < NUMTESTS; i++ ) {
  592. for ( int k = 0; k < COUNT; k++ ) {
  593. fdst0[k] = k;
  594. }
  595. StartRecordTime( start );
  596. p_generic->MulSub( fdst0, 0.123f, fsrc0, j );
  597. StopRecordTime( end );
  598. GetBest( start, end, bestClocksGeneric );
  599. }
  600. PrintClocks( va( "generic->MulSub( float * float[%2d] )", j ), 1, bestClocksGeneric );
  601. bestClocksSIMD = 0;
  602. for ( i = 0; i < NUMTESTS; i++ ) {
  603. for ( int k = 0; k < COUNT; k++ ) {
  604. fdst1[k] = k;
  605. }
  606. StartRecordTime( start );
  607. p_simd->MulSub( fdst1, 0.123f, fsrc0, j );
  608. StopRecordTime( end );
  609. GetBest( start, end, bestClocksSIMD );
  610. }
  611. for ( i = 0; i < COUNT; i++ ) {
  612. if ( idMath::Fabs( fdst0[i] - fdst1[i] ) > 1e-5f ) {
  613. break;
  614. }
  615. }
  616. result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
  617. PrintClocks( va( " simd->MulSub( float * float[%2d] ) %s", j, result ), 1, bestClocksSIMD, bestClocksGeneric );
  618. }
  619. }
  620. /*
  621. ============
  622. TestDot
  623. ============
  624. */
  625. void TestDot( void ) {
  626. int i, j;
  627. TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
  628. ALIGN16( float fdst0[COUNT] );
  629. ALIGN16( float fdst1[COUNT] );
  630. ALIGN16( float fsrc0[COUNT] );
  631. ALIGN16( float fsrc1[COUNT] );
  632. ALIGN16( idVec3 v3src0[COUNT] );
  633. ALIGN16( idVec3 v3src1[COUNT] );
  634. ALIGN16( idVec3 v3constant ) ( 1.0f, 2.0f, 3.0f );
  635. ALIGN16( idPlane v4src0[COUNT] );
  636. ALIGN16( idPlane v4constant ) (1.0f, 2.0f, 3.0f, 4.0f);
  637. ALIGN16( idDrawVert drawVerts[COUNT] );
  638. const char *result;
  639. idRandom srnd( RANDOM_SEED );
  640. for ( i = 0; i < COUNT; i++ ) {
  641. fsrc0[i] = srnd.CRandomFloat() * 10.0f;
  642. fsrc1[i] = srnd.CRandomFloat() * 10.0f;
  643. v3src0[i][0] = srnd.CRandomFloat() * 10.0f;
  644. v3src0[i][1] = srnd.CRandomFloat() * 10.0f;
  645. v3src0[i][2] = srnd.CRandomFloat() * 10.0f;
  646. v3src1[i][0] = srnd.CRandomFloat() * 10.0f;
  647. v3src1[i][1] = srnd.CRandomFloat() * 10.0f;
  648. v3src1[i][2] = srnd.CRandomFloat() * 10.0f;
  649. v4src0[i] = v3src0[i];
  650. v4src0[i][3] = srnd.CRandomFloat() * 10.0f;
  651. drawVerts[i].xyz = v3src0[i];
  652. }
  653. idLib::common->Printf("====================================\n" );
  654. bestClocksGeneric = 0;
  655. for ( i = 0; i < NUMTESTS; i++ ) {
  656. StartRecordTime( start );
  657. p_generic->Dot( fdst0, v3constant, v3src0, COUNT );
  658. StopRecordTime( end );
  659. GetBest( start, end, bestClocksGeneric );
  660. }
  661. PrintClocks( "generic->Dot( idVec3 * idVec3[] )", COUNT, bestClocksGeneric );
  662. bestClocksSIMD = 0;
  663. for ( i = 0; i < NUMTESTS; i++ ) {
  664. StartRecordTime( start );
  665. p_simd->Dot( fdst1, v3constant, v3src0, COUNT );
  666. StopRecordTime( end );
  667. GetBest( start, end, bestClocksSIMD );
  668. }
  669. for ( i = 0; i < COUNT; i++ ) {
  670. if ( idMath::Fabs( fdst0[i] - fdst1[i] ) > 1e-5f ) {
  671. break;
  672. }
  673. }
  674. result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
  675. PrintClocks( va( " simd->Dot( idVec3 * idVec3[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
  676. bestClocksGeneric = 0;
  677. for ( i = 0; i < NUMTESTS; i++ ) {
  678. StartRecordTime( start );
  679. p_generic->Dot( fdst0, v3constant, v4src0, COUNT );
  680. StopRecordTime( end );
  681. GetBest( start, end, bestClocksGeneric );
  682. }
  683. PrintClocks( "generic->Dot( idVec3 * idPlane[] )", COUNT, bestClocksGeneric );
  684. bestClocksSIMD = 0;
  685. for ( i = 0; i < NUMTESTS; i++ ) {
  686. StartRecordTime( start );
  687. p_simd->Dot( fdst1, v3constant, v4src0, COUNT );
  688. StopRecordTime( end );
  689. GetBest( start, end, bestClocksSIMD );
  690. }
  691. for ( i = 0; i < COUNT; i++ ) {
  692. if ( idMath::Fabs( fdst0[i] - fdst1[i] ) > 1e-5f ) {
  693. break;
  694. }
  695. }
  696. result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
  697. PrintClocks( va( " simd->Dot( idVec3 * idPlane[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
  698. bestClocksGeneric = 0;
  699. for ( i = 0; i < NUMTESTS; i++ ) {
  700. StartRecordTime( start );
  701. p_generic->Dot( fdst0, v3constant, drawVerts, COUNT );
  702. StopRecordTime( end );
  703. GetBest( start, end, bestClocksGeneric );
  704. }
  705. PrintClocks( "generic->Dot( idVec3 * idDrawVert[] )", COUNT, bestClocksGeneric );
  706. bestClocksSIMD = 0;
  707. for ( i = 0; i < NUMTESTS; i++ ) {
  708. StartRecordTime( start );
  709. p_simd->Dot( fdst1, v3constant, drawVerts, COUNT );
  710. StopRecordTime( end );
  711. GetBest( start, end, bestClocksSIMD );
  712. }
  713. for ( i = 0; i < COUNT; i++ ) {
  714. if ( idMath::Fabs( fdst0[i] - fdst1[i] ) > 1e-5f ) {
  715. break;
  716. }
  717. }
  718. result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
  719. PrintClocks( va( " simd->Dot( idVec3 * idDrawVert[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
  720. bestClocksGeneric = 0;
  721. for ( i = 0; i < NUMTESTS; i++ ) {
  722. StartRecordTime( start );
  723. p_generic->Dot( fdst0, v4constant, v3src0, COUNT );
  724. StopRecordTime( end );
  725. GetBest( start, end, bestClocksGeneric );
  726. }
  727. PrintClocks( "generic->Dot( idPlane * idVec3[] )", COUNT, bestClocksGeneric );
  728. bestClocksSIMD = 0;
  729. for ( i = 0; i < NUMTESTS; i++ ) {
  730. StartRecordTime( start );
  731. p_simd->Dot( fdst1, v4constant, v3src0, COUNT );
  732. StopRecordTime( end );
  733. GetBest( start, end, bestClocksSIMD );
  734. }
  735. for ( i = 0; i < COUNT; i++ ) {
  736. if ( idMath::Fabs( fdst0[i] - fdst1[i] ) > 1e-5f ) {
  737. break;
  738. }
  739. }
  740. result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
  741. PrintClocks( va( " simd->Dot( idPlane * idVec3[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
  742. bestClocksGeneric = 0;
  743. for ( i = 0; i < NUMTESTS; i++ ) {
  744. StartRecordTime( start );
  745. p_generic->Dot( fdst0, v4constant, v4src0, COUNT );
  746. StopRecordTime( end );
  747. GetBest( start, end, bestClocksGeneric );
  748. }
  749. PrintClocks( "generic->Dot( idPlane * idPlane[] )", COUNT, bestClocksGeneric );
  750. bestClocksSIMD = 0;
  751. for ( i = 0; i < NUMTESTS; i++ ) {
  752. StartRecordTime( start );
  753. p_simd->Dot( fdst1, v4constant, v4src0, COUNT );
  754. StopRecordTime( end );
  755. GetBest( start, end, bestClocksSIMD );
  756. }
  757. for ( i = 0; i < COUNT; i++ ) {
  758. if ( idMath::Fabs( fdst0[i] - fdst1[i] ) > 1e-5f ) {
  759. break;
  760. }
  761. }
  762. result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
  763. PrintClocks( va( " simd->Dot( idPlane * idPlane[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
  764. bestClocksGeneric = 0;
  765. for ( i = 0; i < NUMTESTS; i++ ) {
  766. StartRecordTime( start );
  767. p_generic->Dot( fdst0, v4constant, drawVerts, COUNT );
  768. StopRecordTime( end );
  769. GetBest( start, end, bestClocksGeneric );
  770. }
  771. PrintClocks( "generic->Dot( idPlane * idDrawVert[] )", COUNT, bestClocksGeneric );
  772. bestClocksSIMD = 0;
  773. for ( i = 0; i < NUMTESTS; i++ ) {
  774. StartRecordTime( start );
  775. p_simd->Dot( fdst1, v4constant, drawVerts, COUNT );
  776. StopRecordTime( end );
  777. GetBest( start, end, bestClocksSIMD );
  778. }
  779. for ( i = 0; i < COUNT; i++ ) {
  780. if ( idMath::Fabs( fdst0[i] - fdst1[i] ) > 1e-5f ) {
  781. break;
  782. }
  783. }
  784. result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
  785. PrintClocks( va( " simd->Dot( idPlane * idDrawVert[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
  786. bestClocksGeneric = 0;
  787. for ( i = 0; i < NUMTESTS; i++ ) {
  788. StartRecordTime( start );
  789. p_generic->Dot( fdst0, v3src0, v3src1, COUNT );
  790. StopRecordTime( end );
  791. GetBest( start, end, bestClocksGeneric );
  792. }
  793. PrintClocks( "generic->Dot( idVec3[] * idVec3[] )", COUNT, bestClocksGeneric );
  794. bestClocksSIMD = 0;
  795. for ( i = 0; i < NUMTESTS; i++ ) {
  796. StartRecordTime( start );
  797. p_simd->Dot( fdst1, v3src0, v3src1, COUNT );
  798. StopRecordTime( end );
  799. GetBest( start, end, bestClocksSIMD );
  800. }
  801. for ( i = 0; i < COUNT; i++ ) {
  802. if ( idMath::Fabs( fdst0[i] - fdst1[i] ) > 1e-4f ) {
  803. break;
  804. }
  805. }
  806. result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
  807. PrintClocks( va( " simd->Dot( idVec3[] * idVec3[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
  808. idLib::common->Printf("====================================\n" );
  809. float dot1 = 0.0f, dot2 = 0.0f;
  810. for ( j = 0; j < 50 && j < COUNT; j++ ) {
  811. bestClocksGeneric = 0;
  812. for ( i = 0; i < NUMTESTS; i++ ) {
  813. StartRecordTime( start );
  814. p_generic->Dot( dot1, fsrc0, fsrc1, j );
  815. StopRecordTime( end );
  816. GetBest( start, end, bestClocksGeneric );
  817. }
  818. PrintClocks( va( "generic->Dot( float[%2d] * float[%2d] )", j, j ), 1, bestClocksGeneric );
  819. bestClocksSIMD = 0;
  820. for ( i = 0; i < NUMTESTS; i++ ) {
  821. StartRecordTime( start );
  822. p_simd->Dot( dot2, fsrc0, fsrc1, j );
  823. StopRecordTime( end );
  824. GetBest( start, end, bestClocksSIMD );
  825. }
  826. result = idMath::Fabs( dot1 - dot2 ) < 1e-4f ? "ok" : S_COLOR_RED"X";
  827. PrintClocks( va( " simd->Dot( float[%2d] * float[%2d] ) %s", j, j, result ), 1, bestClocksSIMD, bestClocksGeneric );
  828. }
  829. }
  830. /*
  831. ============
  832. TestCompare
  833. ============
  834. */
  835. void TestCompare( void ) {
  836. int i;
  837. TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
  838. ALIGN16( float fsrc0[COUNT] );
  839. ALIGN16( byte bytedst[COUNT] );
  840. ALIGN16( byte bytedst2[COUNT] );
  841. const char *result;
  842. idRandom srnd( RANDOM_SEED );
  843. for ( i = 0; i < COUNT; i++ ) {
  844. fsrc0[i] = srnd.CRandomFloat() * 10.0f;
  845. }
  846. idLib::common->Printf("====================================\n" );
  847. bestClocksGeneric = 0;
  848. for ( i = 0; i < NUMTESTS; i++ ) {
  849. StartRecordTime( start );
  850. p_generic->CmpGT( bytedst, fsrc0, 0.0f, COUNT );
  851. StopRecordTime( end );
  852. GetBest( start, end, bestClocksGeneric );
  853. }
  854. PrintClocks( "generic->CmpGT( float[] >= float )", COUNT, bestClocksGeneric );
  855. bestClocksSIMD = 0;
  856. for ( i = 0; i < NUMTESTS; i++ ) {
  857. StartRecordTime( start );
  858. p_simd->CmpGT( bytedst2, fsrc0, 0.0f, COUNT );
  859. StopRecordTime( end );
  860. GetBest( start, end, bestClocksSIMD );
  861. }
  862. for ( i = 0; i < COUNT; i++ ) {
  863. if ( bytedst[i] != bytedst2[i] ) {
  864. break;
  865. }
  866. }
  867. result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
  868. PrintClocks( va( " simd->CmpGT( float[] >= float ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
  869. bestClocksGeneric = 0;
  870. for ( i = 0; i < NUMTESTS; i++ ) {
  871. memset( bytedst, 0, COUNT );
  872. StartRecordTime( start );
  873. p_generic->CmpGT( bytedst, 2, fsrc0, 0.0f, COUNT );
  874. StopRecordTime( end );
  875. GetBest( start, end, bestClocksGeneric );
  876. }
  877. PrintClocks( "generic->CmpGT( 2, float[] >= float )", COUNT, bestClocksGeneric );
  878. bestClocksSIMD = 0;
  879. for ( i = 0; i < NUMTESTS; i++ ) {
  880. memset( bytedst2, 0, COUNT );
  881. StartRecordTime( start );
  882. p_simd->CmpGT( bytedst2, 2, fsrc0, 0.0f, COUNT );
  883. StopRecordTime( end );
  884. GetBest( start, end, bestClocksSIMD );
  885. }
  886. for ( i = 0; i < COUNT; i++ ) {
  887. if ( bytedst[i] != bytedst2[i] ) {
  888. break;
  889. }
  890. }
  891. result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
  892. PrintClocks( va( " simd->CmpGT( 2, float[] >= float ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
  893. // ======================
  894. bestClocksGeneric = 0;
  895. for ( i = 0; i < NUMTESTS; i++ ) {
  896. StartRecordTime( start );
  897. p_generic->CmpGE( bytedst, fsrc0, 0.0f, COUNT );
  898. StopRecordTime( end );
  899. GetBest( start, end, bestClocksGeneric );
  900. }
  901. PrintClocks( "generic->CmpGE( float[] >= float )", COUNT, bestClocksGeneric );
  902. bestClocksSIMD = 0;
  903. for ( i = 0; i < NUMTESTS; i++ ) {
  904. StartRecordTime( start );
  905. p_simd->CmpGE( bytedst2, fsrc0, 0.0f, COUNT );
  906. StopRecordTime( end );
  907. GetBest( start, end, bestClocksSIMD );
  908. }
  909. for ( i = 0; i < COUNT; i++ ) {
  910. if ( bytedst[i] != bytedst2[i] ) {
  911. break;
  912. }
  913. }
  914. result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
  915. PrintClocks( va( " simd->CmpGE( float[] >= float ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
  916. bestClocksGeneric = 0;
  917. for ( i = 0; i < NUMTESTS; i++ ) {
  918. memset( bytedst, 0, COUNT );
  919. StartRecordTime( start );
  920. p_generic->CmpGE( bytedst, 2, fsrc0, 0.0f, COUNT );
  921. StopRecordTime( end );
  922. GetBest( start, end, bestClocksGeneric );
  923. }
  924. PrintClocks( "generic->CmpGE( 2, float[] >= float )", COUNT, bestClocksGeneric );
  925. bestClocksSIMD = 0;
  926. for ( i = 0; i < NUMTESTS; i++ ) {
  927. memset( bytedst2, 0, COUNT );
  928. StartRecordTime( start );
  929. p_simd->CmpGE( bytedst2, 2, fsrc0, 0.0f, COUNT );
  930. StopRecordTime( end );
  931. GetBest( start, end, bestClocksSIMD );
  932. }
  933. for ( i = 0; i < COUNT; i++ ) {
  934. if ( bytedst[i] != bytedst2[i] ) {
  935. break;
  936. }
  937. }
  938. result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
  939. PrintClocks( va( " simd->CmpGE( 2, float[] >= float ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
  940. // ======================
  941. bestClocksGeneric = 0;
  942. for ( i = 0; i < NUMTESTS; i++ ) {
  943. StartRecordTime( start );
  944. p_generic->CmpLT( bytedst, fsrc0, 0.0f, COUNT );
  945. StopRecordTime( end );
  946. GetBest( start, end, bestClocksGeneric );
  947. }
  948. PrintClocks( "generic->CmpLT( float[] >= float )", COUNT, bestClocksGeneric );
  949. bestClocksSIMD = 0;
  950. for ( i = 0; i < NUMTESTS; i++ ) {
  951. StartRecordTime( start );
  952. p_simd->CmpLT( bytedst2, fsrc0, 0.0f, COUNT );
  953. StopRecordTime( end );
  954. GetBest( start, end, bestClocksSIMD );
  955. }
  956. for ( i = 0; i < COUNT; i++ ) {
  957. if ( bytedst[i] != bytedst2[i] ) {
  958. break;
  959. }
  960. }
  961. result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
  962. PrintClocks( va( " simd->CmpLT( float[] >= float ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
  963. bestClocksGeneric = 0;
  964. for ( i = 0; i < NUMTESTS; i++ ) {
  965. memset( bytedst, 0, COUNT );
  966. StartRecordTime( start );
  967. p_generic->CmpLT( bytedst, 2, fsrc0, 0.0f, COUNT );
  968. StopRecordTime( end );
  969. GetBest( start, end, bestClocksGeneric );
  970. }
  971. PrintClocks( "generic->CmpLT( 2, float[] >= float )", COUNT, bestClocksGeneric );
  972. bestClocksSIMD = 0;
  973. for ( i = 0; i < NUMTESTS; i++ ) {
  974. memset( bytedst2, 0, COUNT );
  975. StartRecordTime( start );
  976. p_simd->CmpLT( bytedst2, 2, fsrc0, 0.0f, COUNT );
  977. StopRecordTime( end );
  978. GetBest( start, end, bestClocksSIMD );
  979. }
  980. for ( i = 0; i < COUNT; i++ ) {
  981. if ( bytedst[i] != bytedst2[i] ) {
  982. break;
  983. }
  984. }
  985. result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
  986. PrintClocks( va( " simd->CmpLT( 2, float[] >= float ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
  987. // ======================
  988. bestClocksGeneric = 0;
  989. for ( i = 0; i < NUMTESTS; i++ ) {
  990. StartRecordTime( start );
  991. p_generic->CmpLE( bytedst, fsrc0, 0.0f, COUNT );
  992. StopRecordTime( end );
  993. GetBest( start, end, bestClocksGeneric );
  994. }
  995. PrintClocks( "generic->CmpLE( float[] >= float )", COUNT, bestClocksGeneric );
  996. bestClocksSIMD = 0;
  997. for ( i = 0; i < NUMTESTS; i++ ) {
  998. StartRecordTime( start );
  999. p_simd->CmpLE( bytedst2, fsrc0, 0.0f, COUNT );
  1000. StopRecordTime( end );
  1001. GetBest( start, end, bestClocksSIMD );
  1002. }
  1003. for ( i = 0; i < COUNT; i++ ) {
  1004. if ( bytedst[i] != bytedst2[i] ) {
  1005. break;
  1006. }
  1007. }
  1008. result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
  1009. PrintClocks( va( " simd->CmpLE( float[] >= float ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
  1010. bestClocksGeneric = 0;
  1011. for ( i = 0; i < NUMTESTS; i++ ) {
  1012. memset( bytedst, 0, COUNT );
  1013. StartRecordTime( start );
  1014. p_generic->CmpLE( bytedst, 2, fsrc0, 0.0f, COUNT );
  1015. StopRecordTime( end );
  1016. GetBest( start, end, bestClocksGeneric );
  1017. }
  1018. PrintClocks( "generic->CmpLE( 2, float[] >= float )", COUNT, bestClocksGeneric );
  1019. bestClocksSIMD = 0;
  1020. for ( i = 0; i < NUMTESTS; i++ ) {
  1021. memset( bytedst2, 0, COUNT );
  1022. StartRecordTime( start );
  1023. p_simd->CmpLE( bytedst2, 2, fsrc0, 0.0f, COUNT );
  1024. StopRecordTime( end );
  1025. GetBest( start, end, bestClocksSIMD );
  1026. }
  1027. for ( i = 0; i < COUNT; i++ ) {
  1028. if ( bytedst[i] != bytedst2[i] ) {
  1029. break;
  1030. }
  1031. }
  1032. result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
  1033. PrintClocks( va( " simd->CmpLE( 2, float[] >= float ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
  1034. }
  1035. /*
  1036. ============
  1037. TestMinMax
  1038. ============
  1039. */
  1040. void TestMinMax( void ) {
  1041. int i;
  1042. TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
  1043. ALIGN16( float fsrc0[COUNT] );
  1044. ALIGN16( idVec2 v2src0[COUNT] );
  1045. ALIGN16( idVec3 v3src0[COUNT] );
  1046. ALIGN16( idDrawVert drawVerts[COUNT] );
  1047. ALIGN16( int indexes[COUNT] );
  1048. float min = 0.0f, max = 0.0f, min2 = 0.0f, max2 = 0.0f;
  1049. idVec2 v2min, v2max, v2min2, v2max2;
  1050. idVec3 vmin, vmax, vmin2, vmax2;
  1051. const char *result;
  1052. idRandom srnd( RANDOM_SEED );
  1053. for ( i = 0; i < COUNT; i++ ) {
  1054. fsrc0[i] = srnd.CRandomFloat() * 10.0f;
  1055. v2src0[i][0] = srnd.CRandomFloat() * 10.0f;
  1056. v2src0[i][1] = srnd.CRandomFloat() * 10.0f;
  1057. v3src0[i][0] = srnd.CRandomFloat() * 10.0f;
  1058. v3src0[i][1] = srnd.CRandomFloat() * 10.0f;
  1059. v3src0[i][2] = srnd.CRandomFloat() * 10.0f;
  1060. drawVerts[i].xyz = v3src0[i];
  1061. indexes[i] = i;
  1062. }
  1063. idLib::common->Printf("====================================\n" );
  1064. bestClocksGeneric = 0;
  1065. for ( i = 0; i < NUMTESTS; i++ ) {
  1066. min = idMath::INFINITY;
  1067. max = -idMath::INFINITY;
  1068. StartRecordTime( start );
  1069. p_generic->MinMax( min, max, fsrc0, COUNT );
  1070. StopRecordTime( end );
  1071. GetBest( start, end, bestClocksGeneric );
  1072. }
  1073. PrintClocks( "generic->MinMax( float[] )", COUNT, bestClocksGeneric );
  1074. bestClocksSIMD = 0;
  1075. for ( i = 0; i < NUMTESTS; i++ ) {
  1076. StartRecordTime( start );
  1077. p_simd->MinMax( min2, max2, fsrc0, COUNT );
  1078. StopRecordTime( end );
  1079. GetBest( start, end, bestClocksSIMD );
  1080. }
  1081. result = ( min == min2 && max == max2 ) ? "ok" : S_COLOR_RED"X";
  1082. PrintClocks( va( " simd->MinMax( float[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
  1083. bestClocksGeneric = 0;
  1084. for ( i = 0; i < NUMTESTS; i++ ) {
  1085. StartRecordTime( start );
  1086. p_generic->MinMax( v2min, v2max, v2src0, COUNT );
  1087. StopRecordTime( end );
  1088. GetBest( start, end, bestClocksGeneric );
  1089. }
  1090. PrintClocks( "generic->MinMax( idVec2[] )", COUNT, bestClocksGeneric );
  1091. bestClocksSIMD = 0;
  1092. for ( i = 0; i < NUMTESTS; i++ ) {
  1093. StartRecordTime( start );
  1094. p_simd->MinMax( v2min2, v2max2, v2src0, COUNT );
  1095. StopRecordTime( end );
  1096. GetBest( start, end, bestClocksSIMD );
  1097. }
  1098. result = ( v2min == v2min2 && v2max == v2max2 ) ? "ok" : S_COLOR_RED"X";
  1099. PrintClocks( va( " simd->MinMax( idVec2[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
  1100. bestClocksGeneric = 0;
  1101. for ( i = 0; i < NUMTESTS; i++ ) {
  1102. StartRecordTime( start );
  1103. p_generic->MinMax( vmin, vmax, v3src0, COUNT );
  1104. StopRecordTime( end );
  1105. GetBest( start, end, bestClocksGeneric );
  1106. }
  1107. PrintClocks( "generic->MinMax( idVec3[] )", COUNT, bestClocksGeneric );
  1108. bestClocksSIMD = 0;
  1109. for ( i = 0; i < NUMTESTS; i++ ) {
  1110. StartRecordTime( start );
  1111. p_simd->MinMax( vmin2, vmax2, v3src0, COUNT );
  1112. StopRecordTime( end );
  1113. GetBest( start, end, bestClocksSIMD );
  1114. }
  1115. result = ( vmin == vmin2 && vmax == vmax2 ) ? "ok" : S_COLOR_RED"X";
  1116. PrintClocks( va( " simd->MinMax( idVec3[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
  1117. bestClocksGeneric = 0;
  1118. for ( i = 0; i < NUMTESTS; i++ ) {
  1119. StartRecordTime( start );
  1120. p_generic->MinMax( vmin, vmax, drawVerts, COUNT );
  1121. StopRecordTime( end );
  1122. GetBest( start, end, bestClocksGeneric );
  1123. }
  1124. PrintClocks( "generic->MinMax( idDrawVert[] )", COUNT, bestClocksGeneric );
  1125. bestClocksSIMD = 0;
  1126. for ( i = 0; i < NUMTESTS; i++ ) {
  1127. StartRecordTime( start );
  1128. p_simd->MinMax( vmin2, vmax2, drawVerts, COUNT );
  1129. StopRecordTime( end );
  1130. GetBest( start, end, bestClocksSIMD );
  1131. }
  1132. result = ( vmin == vmin2 && vmax == vmax2 ) ? "ok" : S_COLOR_RED"X";
  1133. PrintClocks( va( " simd->MinMax( idDrawVert[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
  1134. bestClocksGeneric = 0;
  1135. for ( i = 0; i < NUMTESTS; i++ ) {
  1136. StartRecordTime( start );
  1137. p_generic->MinMax( vmin, vmax, drawVerts, indexes, COUNT );
  1138. StopRecordTime( end );
  1139. GetBest( start, end, bestClocksGeneric );
  1140. }
  1141. PrintClocks( "generic->MinMax( idDrawVert[], indexes[] )", COUNT, bestClocksGeneric );
  1142. bestClocksSIMD = 0;
  1143. for ( i = 0; i < NUMTESTS; i++ ) {
  1144. StartRecordTime( start );
  1145. p_simd->MinMax( vmin2, vmax2, drawVerts, indexes, COUNT );
  1146. StopRecordTime( end );
  1147. GetBest( start, end, bestClocksSIMD );
  1148. }
  1149. result = ( vmin == vmin2 && vmax == vmax2 ) ? "ok" : S_COLOR_RED"X";
  1150. PrintClocks( va( " simd->MinMax( idDrawVert[], indexes[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
  1151. }
  1152. /*
  1153. ============
  1154. TestClamp
  1155. ============
  1156. */
  1157. void TestClamp( void ) {
  1158. int i;
  1159. TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
  1160. ALIGN16( float fdst0[COUNT] );
  1161. ALIGN16( float fdst1[COUNT] );
  1162. ALIGN16( float fsrc0[COUNT] );
  1163. const char *result;
  1164. idRandom srnd( RANDOM_SEED );
  1165. for ( i = 0; i < COUNT; i++ ) {
  1166. fsrc0[i] = srnd.CRandomFloat() * 10.0f;
  1167. }
  1168. idLib::common->Printf("====================================\n" );
  1169. bestClocksGeneric = 0;
  1170. for ( i = 0; i < NUMTESTS; i++ ) {
  1171. StartRecordTime( start );
  1172. p_generic->Clamp( fdst0, fsrc0, -1.0f, 1.0f, COUNT );
  1173. StopRecordTime( end );
  1174. GetBest( start, end, bestClocksGeneric );
  1175. }
  1176. PrintClocks( "generic->Clamp( float[] )", COUNT, bestClocksGeneric );
  1177. bestClocksSIMD = 0;
  1178. for ( i = 0; i < NUMTESTS; i++ ) {
  1179. StartRecordTime( start );
  1180. p_simd->Clamp( fdst1, fsrc0, -1.0f, 1.0f, COUNT );
  1181. StopRecordTime( end );
  1182. GetBest( start, end, bestClocksSIMD );
  1183. }
  1184. for ( i = 0; i < COUNT; i++ ) {
  1185. if ( fdst0[i] != fdst1[i] ) {
  1186. break;
  1187. }
  1188. }
  1189. result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
  1190. PrintClocks( va( " simd->Clamp( float[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
  1191. bestClocksGeneric = 0;
  1192. for ( i = 0; i < NUMTESTS; i++ ) {
  1193. StartRecordTime( start );
  1194. p_generic->ClampMin( fdst0, fsrc0, -1.0f, COUNT );
  1195. StopRecordTime( end );
  1196. GetBest( start, end, bestClocksGeneric );
  1197. }
  1198. PrintClocks( "generic->ClampMin( float[] )", COUNT, bestClocksGeneric );
  1199. bestClocksSIMD = 0;
  1200. for ( i = 0; i < NUMTESTS; i++ ) {
  1201. StartRecordTime( start );
  1202. p_simd->ClampMin( fdst1, fsrc0, -1.0f, COUNT );
  1203. StopRecordTime( end );
  1204. GetBest( start, end, bestClocksSIMD );
  1205. }
  1206. for ( i = 0; i < COUNT; i++ ) {
  1207. if ( fdst0[i] != fdst1[i] ) {
  1208. break;
  1209. }
  1210. }
  1211. result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
  1212. PrintClocks( va( " simd->ClampMin( float[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
  1213. bestClocksGeneric = 0;
  1214. for ( i = 0; i < NUMTESTS; i++ ) {
  1215. StartRecordTime( start );
  1216. p_generic->ClampMax( fdst0, fsrc0, 1.0f, COUNT );
  1217. StopRecordTime( end );
  1218. GetBest( start, end, bestClocksGeneric );
  1219. }
  1220. PrintClocks( "generic->ClampMax( float[] )", COUNT, bestClocksGeneric );
  1221. bestClocksSIMD = 0;
  1222. for ( i = 0; i < NUMTESTS; i++ ) {
  1223. StartRecordTime( start );
  1224. p_simd->ClampMax( fdst1, fsrc0, 1.0f, COUNT );
  1225. StopRecordTime( end );
  1226. GetBest( start, end, bestClocksSIMD );
  1227. }
  1228. for ( i = 0; i < COUNT; i++ ) {
  1229. if ( fdst0[i] != fdst1[i] ) {
  1230. break;
  1231. }
  1232. }
  1233. result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
  1234. PrintClocks( va( " simd->ClampMax( float[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
  1235. }
  1236. /*
  1237. ============
  1238. TestMemcpy
  1239. ============
  1240. */
  1241. void TestMemcpy( void ) {
  1242. int i, j;
  1243. byte test0[8192];
  1244. byte test1[8192];
  1245. idRandom random( RANDOM_SEED );
  1246. idLib::common->Printf("====================================\n" );
  1247. for ( i = 5; i < 8192; i += 31 ) {
  1248. for ( j = 0; j < i; j++ ) {
  1249. test0[j] = random.RandomInt( 255 );
  1250. }
  1251. p_simd->Memcpy( test1, test0, 8192 );
  1252. for ( j = 0; j < i; j++ ) {
  1253. if ( test1[j] != test0[j] ) {
  1254. idLib::common->Printf( " simd->Memcpy() "S_COLOR_RED"X\n" );
  1255. return;
  1256. }
  1257. }
  1258. }
  1259. idLib::common->Printf( " simd->Memcpy() ok\n" );
  1260. }
  1261. /*
  1262. ============
  1263. TestMemset
  1264. ============
  1265. */
  1266. void TestMemset( void ) {
  1267. int i, j, k;
  1268. byte test[8192];
  1269. for ( i = 0; i < 8192; i++ ) {
  1270. test[i] = 0;
  1271. }
  1272. for ( i = 5; i < 8192; i += 31 ) {
  1273. for ( j = -1; j <= 1; j++ ) {
  1274. p_simd->Memset( test, j, i );
  1275. for ( k = 0; k < i; k++ ) {
  1276. if ( test[k] != (byte)j ) {
  1277. idLib::common->Printf( " simd->Memset() "S_COLOR_RED"X\n" );
  1278. return;
  1279. }
  1280. }
  1281. }
  1282. }
  1283. idLib::common->Printf( " simd->Memset() ok\n" );
  1284. }
  1285. #define MATX_SIMD_EPSILON 1e-5f
  1286. /*
  1287. ============
  1288. TestMatXMultiplyVecX
  1289. ============
  1290. */
  1291. void TestMatXMultiplyVecX( void ) {
  1292. int i, j;
  1293. TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
  1294. const char *result;
  1295. idMatX mat;
  1296. idVecX src(6);
  1297. idVecX dst(6);
  1298. idVecX tst(6);
  1299. src[0] = 1.0f;
  1300. src[1] = 2.0f;
  1301. src[2] = 3.0f;
  1302. src[3] = 4.0f;
  1303. src[4] = 5.0f;
  1304. src[5] = 6.0f;
  1305. idLib::common->Printf("================= NxN * Nx1 ===================\n" );
  1306. for ( i = 1; i <= 6; i++ ) {
  1307. mat.Random( i, i, RANDOM_SEED, -10.0f, 10.0f );
  1308. bestClocksGeneric = 0;
  1309. for ( j = 0; j < NUMTESTS; j++ ) {
  1310. dst.Zero();
  1311. StartRecordTime( start );
  1312. p_generic->MatX_MultiplyVecX( dst, mat, src );
  1313. StopRecordTime( end );
  1314. GetBest( start, end, bestClocksGeneric );
  1315. }
  1316. tst = dst;
  1317. PrintClocks( va( "generic->MatX_MultiplyVecX %dx%d*%dx1", i, i, i ), 1, bestClocksGeneric );
  1318. bestClocksSIMD = 0;
  1319. for ( j = 0; j < NUMTESTS; j++ ) {
  1320. dst.Zero();
  1321. StartRecordTime( start );
  1322. p_simd->MatX_MultiplyVecX( dst, mat, src );
  1323. StopRecordTime( end );
  1324. GetBest( start, end, bestClocksSIMD );
  1325. }
  1326. result = dst.Compare( tst, MATX_SIMD_EPSILON ) ? "ok" : S_COLOR_RED"X";
  1327. PrintClocks( va( " simd->MatX_MultiplyVecX %dx%d*%dx1 %s", i, i, i, result ), 1, bestClocksSIMD, bestClocksGeneric );
  1328. }
  1329. idLib::common->Printf("================= Nx6 * 6x1 ===================\n" );
  1330. for ( i = 1; i <= 6; i++ ) {
  1331. mat.Random( i, 6, RANDOM_SEED, -10.0f, 10.0f );
  1332. bestClocksGeneric = 0;
  1333. for ( j = 0; j < NUMTESTS; j++ ) {
  1334. dst.Zero();
  1335. StartRecordTime( start );
  1336. p_generic->MatX_MultiplyVecX( dst, mat, src );
  1337. StopRecordTime( end );
  1338. GetBest( start, end, bestClocksGeneric );
  1339. }
  1340. tst = dst;
  1341. PrintClocks( va( "generic->MatX_MultiplyVecX %dx6*6x1", i ), 1, bestClocksGeneric );
  1342. bestClocksSIMD = 0;
  1343. for ( j = 0; j < NUMTESTS; j++ ) {
  1344. dst.Zero();
  1345. StartRecordTime( start );
  1346. p_simd->MatX_MultiplyVecX( dst, mat, src );
  1347. StopRecordTime( end );
  1348. GetBest( start, end, bestClocksSIMD );
  1349. }
  1350. result = dst.Compare( tst, MATX_SIMD_EPSILON ) ? "ok" : S_COLOR_RED"X";
  1351. PrintClocks( va( " simd->MatX_MultiplyVecX %dx6*6x1 %s", i, result ), 1, bestClocksSIMD, bestClocksGeneric );
  1352. }
  1353. idLib::common->Printf("================= 6xN * Nx1 ===================\n" );
  1354. for ( i = 1; i <= 6; i++ ) {
  1355. mat.Random( 6, i, RANDOM_SEED, -10.0f, 10.0f );
  1356. bestClocksGeneric = 0;
  1357. for ( j = 0; j < NUMTESTS; j++ ) {
  1358. dst.Zero();
  1359. StartRecordTime( start );
  1360. p_generic->MatX_MultiplyVecX( dst, mat, src );
  1361. StopRecordTime( end );
  1362. GetBest( start, end, bestClocksGeneric );
  1363. }
  1364. tst = dst;
  1365. PrintClocks( va( "generic->MatX_MultiplyVecX 6x%d*%dx1", i, i ), 1, bestClocksGeneric );
  1366. bestClocksSIMD = 0;
  1367. for ( j = 0; j < NUMTESTS; j++ ) {
  1368. StartRecordTime( start );
  1369. p_simd->MatX_MultiplyVecX( dst, mat, src );
  1370. StopRecordTime( end );
  1371. GetBest( start, end, bestClocksSIMD );
  1372. }
  1373. result = dst.Compare( tst, MATX_SIMD_EPSILON ) ? "ok" : S_COLOR_RED"X";
  1374. PrintClocks( va( " simd->MatX_MultiplyVecX 6x%d*%dx1 %s", i, i, result ), 1, bestClocksSIMD, bestClocksGeneric );
  1375. }
  1376. }
  1377. /*
  1378. ============
  1379. TestMatXMultiplyAddVecX
  1380. ============
  1381. */
  1382. void TestMatXMultiplyAddVecX( void ) {
  1383. int i, j;
  1384. TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
  1385. const char *result;
  1386. idMatX mat;
  1387. idVecX src(6);
  1388. idVecX dst(6);
  1389. idVecX tst(6);
  1390. src[0] = 1.0f;
  1391. src[1] = 2.0f;
  1392. src[2] = 3.0f;
  1393. src[3] = 4.0f;
  1394. src[4] = 5.0f;
  1395. src[5] = 6.0f;
  1396. idLib::common->Printf("================= NxN * Nx1 ===================\n" );
  1397. for ( i = 1; i <= 6; i++ ) {
  1398. mat.Random( i, i, RANDOM_SEED, -10.0f, 10.0f );
  1399. bestClocksGeneric = 0;
  1400. for ( j = 0; j < NUMTESTS; j++ ) {
  1401. dst.Zero();
  1402. StartRecordTime( start );
  1403. p_generic->MatX_MultiplyAddVecX( dst, mat, src );
  1404. StopRecordTime( end );
  1405. GetBest( start, end, bestClocksGeneric );
  1406. }
  1407. tst = dst;
  1408. PrintClocks( va( "generic->MatX_MultiplyAddVecX %dx%d*%dx1", i, i, i ), 1, bestClocksGeneric );
  1409. bestClocksSIMD = 0;
  1410. for ( j = 0; j < NUMTESTS; j++ ) {
  1411. dst.Zero();
  1412. StartRecordTime( start );
  1413. p_simd->MatX_MultiplyAddVecX( dst, mat, src );
  1414. StopRecordTime( end );
  1415. GetBest( start, end, bestClocksSIMD );
  1416. }
  1417. result = dst.Compare( tst, MATX_SIMD_EPSILON ) ? "ok" : S_COLOR_RED"X";
  1418. PrintClocks( va( " simd->MatX_MultiplyAddVecX %dx%d*%dx1 %s", i, i, i, result ), 1, bestClocksSIMD, bestClocksGeneric );
  1419. }
  1420. idLib::common->Printf("================= Nx6 * 6x1 ===================\n" );
  1421. for ( i = 1; i <= 6; i++ ) {
  1422. mat.Random( i, 6, RANDOM_SEED, -10.0f, 10.0f );
  1423. bestClocksGeneric = 0;
  1424. for ( j = 0; j < NUMTESTS; j++ ) {
  1425. dst.Zero();
  1426. StartRecordTime( start );
  1427. p_generic->MatX_MultiplyAddVecX( dst, mat, src );
  1428. StopRecordTime( end );
  1429. GetBest( start, end, bestClocksGeneric );
  1430. }
  1431. tst = dst;
  1432. PrintClocks( va( "generic->MatX_MultiplyAddVecX %dx6*6x1", i ), 1, bestClocksGeneric );
  1433. bestClocksSIMD = 0;
  1434. for ( j = 0; j < NUMTESTS; j++ ) {
  1435. dst.Zero();
  1436. StartRecordTime( start );
  1437. p_simd->MatX_MultiplyAddVecX( dst, mat, src );
  1438. StopRecordTime( end );
  1439. GetBest( start, end, bestClocksSIMD );
  1440. }
  1441. result = dst.Compare( tst, MATX_SIMD_EPSILON ) ? "ok" : S_COLOR_RED"X";
  1442. PrintClocks( va( " simd->MatX_MultiplyAddVecX %dx6*6x1 %s", i, result ), 1, bestClocksSIMD, bestClocksGeneric );
  1443. }
  1444. idLib::common->Printf("================= 6xN * Nx1 ===================\n" );
  1445. for ( i = 1; i <= 6; i++ ) {
  1446. mat.Random( 6, i, RANDOM_SEED, -10.0f, 10.0f );
  1447. bestClocksGeneric = 0;
  1448. for ( j = 0; j < NUMTESTS; j++ ) {
  1449. dst.Zero();
  1450. StartRecordTime( start );
  1451. p_generic->MatX_MultiplyAddVecX( dst, mat, src );
  1452. StopRecordTime( end );
  1453. GetBest( start, end, bestClocksGeneric );
  1454. }
  1455. tst = dst;
  1456. PrintClocks( va( "generic->MatX_MultiplyAddVecX 6x%d*%dx1", i, i ), 1, bestClocksGeneric );
  1457. bestClocksSIMD = 0;
  1458. for ( j = 0; j < NUMTESTS; j++ ) {
  1459. dst.Zero();
  1460. StartRecordTime( start );
  1461. p_simd->MatX_MultiplyAddVecX( dst, mat, src );
  1462. StopRecordTime( end );
  1463. GetBest( start, end, bestClocksSIMD );
  1464. }
  1465. result = dst.Compare( tst, MATX_SIMD_EPSILON ) ? "ok" : S_COLOR_RED"X";
  1466. PrintClocks( va( " simd->MatX_MultiplyAddVecX 6x%d*%dx1 %s", i, i, result ), 1, bestClocksSIMD, bestClocksGeneric );
  1467. }
  1468. }
  1469. /*
  1470. ============
  1471. TestMatXTransposeMultiplyVecX
  1472. ============
  1473. */
  1474. void TestMatXTransposeMultiplyVecX( void ) {
  1475. int i, j;
  1476. TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
  1477. const char *result;
  1478. idMatX mat;
  1479. idVecX src(6);
  1480. idVecX dst(6);
  1481. idVecX tst(6);
  1482. src[0] = 1.0f;
  1483. src[1] = 2.0f;
  1484. src[2] = 3.0f;
  1485. src[3] = 4.0f;
  1486. src[4] = 5.0f;
  1487. src[5] = 6.0f;
  1488. idLib::common->Printf("================= Nx6 * Nx1 ===================\n" );
  1489. for ( i = 1; i <= 6; i++ ) {
  1490. mat.Random( i, 6, RANDOM_SEED, -10.0f, 10.0f );
  1491. bestClocksGeneric = 0;
  1492. for ( j = 0; j < NUMTESTS; j++ ) {
  1493. dst.Zero();
  1494. StartRecordTime( start );
  1495. p_generic->MatX_TransposeMultiplyVecX( dst, mat, src );
  1496. StopRecordTime( end );
  1497. GetBest( start, end, bestClocksGeneric );
  1498. }
  1499. tst = dst;
  1500. PrintClocks( va( "generic->MatX_TransposeMulVecX %dx6*%dx1", i, i ), 1, bestClocksGeneric );
  1501. bestClocksSIMD = 0;
  1502. for ( j = 0; j < NUMTESTS; j++ ) {
  1503. dst.Zero();
  1504. StartRecordTime( start );
  1505. p_simd->MatX_TransposeMultiplyVecX( dst, mat, src );
  1506. StopRecordTime( end );
  1507. GetBest( start, end, bestClocksSIMD );
  1508. }
  1509. result = dst.Compare( tst, MATX_SIMD_EPSILON ) ? "ok" : S_COLOR_RED"X";
  1510. PrintClocks( va( " simd->MatX_TransposeMulVecX %dx6*%dx1 %s", i, i, result ), 1, bestClocksSIMD, bestClocksGeneric );
  1511. }
  1512. idLib::common->Printf("================= 6xN * 6x1 ===================\n" );
  1513. for ( i = 1; i <= 6; i++ ) {
  1514. mat.Random( 6, i, RANDOM_SEED, -10.0f, 10.0f );
  1515. bestClocksGeneric = 0;
  1516. for ( j = 0; j < NUMTESTS; j++ ) {
  1517. dst.Zero();
  1518. StartRecordTime( start );
  1519. p_generic->MatX_TransposeMultiplyVecX( dst, mat, src );
  1520. StopRecordTime( end );
  1521. GetBest( start, end, bestClocksGeneric );
  1522. }
  1523. tst = dst;
  1524. PrintClocks( va( "generic->MatX_TransposeMulVecX 6x%d*6x1", i ), 1, bestClocksGeneric );
  1525. bestClocksSIMD = 0;
  1526. for ( j = 0; j < NUMTESTS; j++ ) {
  1527. dst.Zero();
  1528. StartRecordTime( start );
  1529. p_simd->MatX_TransposeMultiplyVecX( dst, mat, src );
  1530. StopRecordTime( end );
  1531. GetBest( start, end, bestClocksSIMD );
  1532. }
  1533. result = dst.Compare( tst, MATX_SIMD_EPSILON ) ? "ok" : S_COLOR_RED"X";
  1534. PrintClocks( va( " simd->MatX_TransposeMulVecX 6x%d*6x1 %s", i, result ), 1, bestClocksSIMD, bestClocksGeneric );
  1535. }
  1536. }
  1537. /*
  1538. ============
  1539. TestMatXTransposeMultiplyAddVecX
  1540. ============
  1541. */
  1542. void TestMatXTransposeMultiplyAddVecX( void ) {
  1543. int i, j;
  1544. TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
  1545. const char *result;
  1546. idMatX mat;
  1547. idVecX src(6);
  1548. idVecX dst(6);
  1549. idVecX tst(6);
  1550. src[0] = 1.0f;
  1551. src[1] = 2.0f;
  1552. src[2] = 3.0f;
  1553. src[3] = 4.0f;
  1554. src[4] = 5.0f;
  1555. src[5] = 6.0f;
  1556. idLib::common->Printf("================= Nx6 * Nx1 ===================\n" );
  1557. for ( i = 1; i <= 6; i++ ) {
  1558. mat.Random( i, 6, RANDOM_SEED, -10.0f, 10.0f );
  1559. bestClocksGeneric = 0;
  1560. for ( j = 0; j < NUMTESTS; j++ ) {
  1561. dst.Zero();
  1562. StartRecordTime( start );
  1563. p_generic->MatX_TransposeMultiplyAddVecX( dst, mat, src );
  1564. StopRecordTime( end );
  1565. GetBest( start, end, bestClocksGeneric );
  1566. }
  1567. tst = dst;
  1568. PrintClocks( va( "generic->MatX_TransposeMulAddVecX %dx6*%dx1", i, i ), 1, bestClocksGeneric );
  1569. bestClocksSIMD = 0;
  1570. for ( j = 0; j < NUMTESTS; j++ ) {
  1571. dst.Zero();
  1572. StartRecordTime( start );
  1573. p_simd->MatX_TransposeMultiplyAddVecX( dst, mat, src );
  1574. StopRecordTime( end );
  1575. GetBest( start, end, bestClocksSIMD );
  1576. }
  1577. result = dst.Compare( tst, MATX_SIMD_EPSILON ) ? "ok" : S_COLOR_RED"X";
  1578. PrintClocks( va( " simd->MatX_TransposeMulAddVecX %dx6*%dx1 %s", i, i, result ), 1, bestClocksSIMD, bestClocksGeneric );
  1579. }
  1580. idLib::common->Printf("================= 6xN * 6x1 ===================\n" );
  1581. for ( i = 1; i <= 6; i++ ) {
  1582. mat.Random( 6, i, RANDOM_SEED, -10.0f, 10.0f );
  1583. bestClocksGeneric = 0;
  1584. for ( j = 0; j < NUMTESTS; j++ ) {
  1585. dst.Zero();
  1586. StartRecordTime( start );
  1587. p_generic->MatX_TransposeMultiplyAddVecX( dst, mat, src );
  1588. StopRecordTime( end );
  1589. GetBest( start, end, bestClocksGeneric );
  1590. }
  1591. tst = dst;
  1592. PrintClocks( va( "generic->MatX_TransposeMulAddVecX 6x%d*6x1", i ), 1, bestClocksGeneric );
  1593. bestClocksSIMD = 0;
  1594. for ( j = 0; j < NUMTESTS; j++ ) {
  1595. dst.Zero();
  1596. StartRecordTime( start );
  1597. p_simd->MatX_TransposeMultiplyAddVecX( dst, mat, src );
  1598. StopRecordTime( end );
  1599. GetBest( start, end, bestClocksSIMD );
  1600. }
  1601. result = dst.Compare( tst, MATX_SIMD_EPSILON ) ? "ok" : S_COLOR_RED"X";
  1602. PrintClocks( va( " simd->MatX_TransposeMulAddVecX 6x%d*6x1 %s", i, result ), 1, bestClocksSIMD, bestClocksGeneric );
  1603. }
  1604. }
  1605. /*
  1606. ============
  1607. TestMatXMultiplyMatX
  1608. ============
  1609. */
  1610. #define TEST_VALUE_RANGE 10.0f
  1611. #define MATX_MATX_SIMD_EPSILON 1e-4f
  1612. void TestMatXMultiplyMatX( void ) {
  1613. int i, j;
  1614. TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
  1615. const char *result;
  1616. idMatX m1, m2, dst, tst;
  1617. idLib::common->Printf("================= NxN * Nx6 ===================\n" );
  1618. // NxN * Nx6
  1619. for ( i = 1; i <= 5; i++ ) {
  1620. m1.Random( i, i, RANDOM_SEED, -TEST_VALUE_RANGE, TEST_VALUE_RANGE );
  1621. m2.Random( i, 6, RANDOM_SEED, -TEST_VALUE_RANGE, TEST_VALUE_RANGE );
  1622. dst.SetSize( i, 6 );
  1623. bestClocksGeneric = 0;
  1624. for ( j = 0; j < NUMTESTS; j++ ) {
  1625. StartRecordTime( start );
  1626. p_generic->MatX_MultiplyMatX( dst, m1, m2 );
  1627. StopRecordTime( end );
  1628. GetBest( start, end, bestClocksGeneric );
  1629. }
  1630. tst = dst;
  1631. PrintClocks( va( "generic->MatX_MultiplyMatX %dx%d*%dx6", i, i, i ), 1, bestClocksGeneric );
  1632. bestClocksSIMD = 0;
  1633. for ( j = 0; j < NUMTESTS; j++ ) {
  1634. StartRecordTime( start );
  1635. p_simd->MatX_MultiplyMatX( dst, m1, m2 );
  1636. StopRecordTime( end );
  1637. GetBest( start, end, bestClocksSIMD );
  1638. }
  1639. result = dst.Compare( tst, MATX_MATX_SIMD_EPSILON ) ? "ok" : S_COLOR_RED"X";
  1640. PrintClocks( va( " simd->MatX_MultiplyMatX %dx%d*%dx6 %s", i, i, i, result ), 1, bestClocksSIMD, bestClocksGeneric );
  1641. }
  1642. idLib::common->Printf("================= 6xN * Nx6 ===================\n" );
  1643. // 6xN * Nx6
  1644. for ( i = 1; i <= 5; i++ ) {
  1645. m1.Random( 6, i, RANDOM_SEED, -TEST_VALUE_RANGE, TEST_VALUE_RANGE );
  1646. m2.Random( i, 6, RANDOM_SEED, -TEST_VALUE_RANGE, TEST_VALUE_RANGE );
  1647. dst.SetSize( 6, 6 );
  1648. bestClocksGeneric = 0;
  1649. for ( j = 0; j < NUMTESTS; j++ ) {
  1650. StartRecordTime( start );
  1651. p_generic->MatX_MultiplyMatX( dst, m1, m2 );
  1652. StopRecordTime( end );
  1653. GetBest( start, end, bestClocksGeneric );
  1654. }
  1655. tst = dst;
  1656. PrintClocks( va( "generic->MatX_MultiplyMatX 6x%d*%dx6", i, i ), 1, bestClocksGeneric );
  1657. bestClocksSIMD = 0;
  1658. for ( j = 0; j < NUMTESTS; j++ ) {
  1659. StartRecordTime( start );
  1660. p_simd->MatX_MultiplyMatX( dst, m1, m2 );
  1661. StopRecordTime( end );
  1662. GetBest( start, end, bestClocksSIMD );
  1663. }
  1664. result = dst.Compare( tst, MATX_MATX_SIMD_EPSILON ) ? "ok" : S_COLOR_RED"X";
  1665. PrintClocks( va( " simd->MatX_MultiplyMatX 6x%d*%dx6 %s", i, i, result ), 1, bestClocksSIMD, bestClocksGeneric );
  1666. }
  1667. idLib::common->Printf("================= Nx6 * 6xN ===================\n" );
  1668. // Nx6 * 6xN
  1669. for ( i = 1; i <= 5; i++ ) {
  1670. m1.Random( i, 6, RANDOM_SEED, -TEST_VALUE_RANGE, TEST_VALUE_RANGE );
  1671. m2.Random( 6, i, RANDOM_SEED, -TEST_VALUE_RANGE, TEST_VALUE_RANGE );
  1672. dst.SetSize( i, i );
  1673. bestClocksGeneric = 0;
  1674. for ( j = 0; j < NUMTESTS; j++ ) {
  1675. StartRecordTime( start );
  1676. p_generic->MatX_MultiplyMatX( dst, m1, m2 );
  1677. StopRecordTime( end );
  1678. GetBest( start, end, bestClocksGeneric );
  1679. }
  1680. tst = dst;
  1681. PrintClocks( va( "generic->MatX_MultiplyMatX %dx6*6x%d", i, i ), 1, bestClocksGeneric );
  1682. bestClocksSIMD = 0;
  1683. for ( j = 0; j < NUMTESTS; j++ ) {
  1684. StartRecordTime( start );
  1685. p_simd->MatX_MultiplyMatX( dst, m1, m2 );
  1686. StopRecordTime( end );
  1687. GetBest( start, end, bestClocksSIMD );
  1688. }
  1689. result = dst.Compare( tst, MATX_MATX_SIMD_EPSILON ) ? "ok" : S_COLOR_RED"X";
  1690. PrintClocks( va( " simd->MatX_MultiplyMatX %dx6*6x%d %s", i, i, result ), 1, bestClocksSIMD, bestClocksGeneric );
  1691. }
  1692. idLib::common->Printf("================= 6x6 * 6xN ===================\n" );
  1693. // 6x6 * 6xN
  1694. for ( i = 1; i <= 6; i++ ) {
  1695. m1.Random( 6, 6, RANDOM_SEED, -TEST_VALUE_RANGE, TEST_VALUE_RANGE );
  1696. m2.Random( 6, i, RANDOM_SEED, -TEST_VALUE_RANGE, TEST_VALUE_RANGE );
  1697. dst.SetSize( 6, i );
  1698. bestClocksGeneric = 0;
  1699. for ( j = 0; j < NUMTESTS; j++ ) {
  1700. StartRecordTime( start );
  1701. p_generic->MatX_MultiplyMatX( dst, m1, m2 );
  1702. StopRecordTime( end );
  1703. GetBest( start, end, bestClocksGeneric );
  1704. }
  1705. tst = dst;
  1706. PrintClocks( va( "generic->MatX_MultiplyMatX 6x6*6x%d", i ), 1, bestClocksGeneric );
  1707. bestClocksSIMD = 0;
  1708. for ( j = 0; j < NUMTESTS; j++ ) {
  1709. StartRecordTime( start );
  1710. p_simd->MatX_MultiplyMatX( dst, m1, m2 );
  1711. StopRecordTime( end );
  1712. GetBest( start, end, bestClocksSIMD );
  1713. }
  1714. result = dst.Compare( tst, MATX_MATX_SIMD_EPSILON ) ? "ok" : S_COLOR_RED"X";
  1715. PrintClocks( va( " simd->MatX_MultiplyMatX 6x6*6x%d %s", i, result ), 1, bestClocksSIMD, bestClocksGeneric );
  1716. }
  1717. }
  1718. /*
  1719. ============
  1720. TestMatXTransposeMultiplyMatX
  1721. ============
  1722. */
  1723. void TestMatXTransposeMultiplyMatX( void ) {
  1724. int i, j;
  1725. TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
  1726. const char *result;
  1727. idMatX m1, m2, dst, tst;
  1728. idLib::common->Printf("================= Nx6 * NxN ===================\n" );
  1729. // Nx6 * NxN
  1730. for ( i = 1; i <= 5; i++ ) {
  1731. m1.Random( i, 6, RANDOM_SEED, -TEST_VALUE_RANGE, TEST_VALUE_RANGE );
  1732. m2.Random( i, i, RANDOM_SEED, -TEST_VALUE_RANGE, TEST_VALUE_RANGE );
  1733. dst.SetSize( 6, i );
  1734. bestClocksGeneric = 0;
  1735. for ( j = 0; j < NUMTESTS; j++ ) {
  1736. StartRecordTime( start );
  1737. p_generic->MatX_TransposeMultiplyMatX( dst, m1, m2 );
  1738. StopRecordTime( end );
  1739. GetBest( start, end, bestClocksGeneric );
  1740. }
  1741. tst = dst;
  1742. PrintClocks( va( "generic->MatX_TransMultiplyMatX %dx6*%dx%d", i, i, i ), 1, bestClocksGeneric );
  1743. bestClocksSIMD = 0;
  1744. for ( j = 0; j < NUMTESTS; j++ ) {
  1745. StartRecordTime( start );
  1746. p_simd->MatX_TransposeMultiplyMatX( dst, m1, m2 );
  1747. StopRecordTime( end );
  1748. GetBest( start, end, bestClocksSIMD );
  1749. }
  1750. result = dst.Compare( tst, MATX_MATX_SIMD_EPSILON ) ? "ok" : S_COLOR_RED"X";
  1751. PrintClocks( va( " simd->MatX_TransMultiplyMatX %dx6*%dx%d %s", i, i, i, result ), 1, bestClocksSIMD, bestClocksGeneric );
  1752. }
  1753. idLib::common->Printf("================= 6xN * 6x6 ===================\n" );
  1754. // 6xN * 6x6
  1755. for ( i = 1; i <= 6; i++ ) {
  1756. m1.Random( 6, i, RANDOM_SEED, -TEST_VALUE_RANGE, TEST_VALUE_RANGE );
  1757. m2.Random( 6, 6, RANDOM_SEED, -TEST_VALUE_RANGE, TEST_VALUE_RANGE );
  1758. dst.SetSize( i, 6 );
  1759. bestClocksGeneric = 0;
  1760. for ( j = 0; j < NUMTESTS; j++ ) {
  1761. StartRecordTime( start );
  1762. p_generic->MatX_TransposeMultiplyMatX( dst, m1, m2 );
  1763. StopRecordTime( end );
  1764. GetBest( start, end, bestClocksGeneric );
  1765. }
  1766. tst = dst;
  1767. PrintClocks( va( "generic->MatX_TransMultiplyMatX 6x%d*6x6", i ), 1, bestClocksGeneric );
  1768. bestClocksSIMD = 0;
  1769. for ( j = 0; j < NUMTESTS; j++ ) {
  1770. StartRecordTime( start );
  1771. p_simd->MatX_TransposeMultiplyMatX( dst, m1, m2 );
  1772. StopRecordTime( end );
  1773. GetBest( start, end, bestClocksSIMD );
  1774. }
  1775. result = dst.Compare( tst, MATX_MATX_SIMD_EPSILON ) ? "ok" : S_COLOR_RED"X";
  1776. PrintClocks( va( " simd->MatX_TransMultiplyMatX 6x%d*6x6 %s", i, result ), 1, bestClocksSIMD, bestClocksGeneric );
  1777. }
  1778. }
  1779. #define MATX_LTS_SIMD_EPSILON 1.0f
  1780. #define MATX_LTS_SOLVE_SIZE 100
  1781. /*
  1782. ============
  1783. TestMatXLowerTriangularSolve
  1784. ============
  1785. */
  1786. void TestMatXLowerTriangularSolve( void ) {
  1787. int i, j;
  1788. TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
  1789. const char *result;
  1790. idMatX L;
  1791. idVecX x, b, tst;
  1792. idLib::common->Printf("====================================\n" );
  1793. L.Random( MATX_LTS_SOLVE_SIZE, MATX_LTS_SOLVE_SIZE, 0, -1.0f, 1.0f );
  1794. x.SetSize( MATX_LTS_SOLVE_SIZE );
  1795. b.Random( MATX_LTS_SOLVE_SIZE, 0, -1.0f, 1.0f );
  1796. for ( i = 1; i < MATX_LTS_SOLVE_SIZE; i++ ) {
  1797. x.Zero( i );
  1798. bestClocksGeneric = 0;
  1799. for ( j = 0; j < NUMTESTS; j++ ) {
  1800. StartRecordTime( start );
  1801. p_generic->MatX_LowerTriangularSolve( L, x.ToFloatPtr(), b.ToFloatPtr(), i );
  1802. StopRecordTime( end );
  1803. GetBest( start, end, bestClocksGeneric );
  1804. }
  1805. tst = x;
  1806. x.Zero();
  1807. PrintClocks( va( "generic->MatX_LowerTriangularSolve %dx%d", i, i ), 1, bestClocksGeneric );
  1808. bestClocksSIMD = 0;
  1809. for ( j = 0; j < NUMTESTS; j++ ) {
  1810. StartRecordTime( start );
  1811. p_simd->MatX_LowerTriangularSolve( L, x.ToFloatPtr(), b.ToFloatPtr(), i );
  1812. StopRecordTime( end );
  1813. GetBest( start, end, bestClocksSIMD );
  1814. }
  1815. result = x.Compare( tst, MATX_LTS_SIMD_EPSILON ) ? "ok" : S_COLOR_RED"X";
  1816. PrintClocks( va( " simd->MatX_LowerTriangularSolve %dx%d %s", i, i, result ), 1, bestClocksSIMD, bestClocksGeneric );
  1817. }
  1818. }
  1819. /*
  1820. ============
  1821. TestMatXLowerTriangularSolveTranspose
  1822. ============
  1823. */
  1824. void TestMatXLowerTriangularSolveTranspose( void ) {
  1825. int i, j;
  1826. TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
  1827. const char *result;
  1828. idMatX L;
  1829. idVecX x, b, tst;
  1830. idLib::common->Printf("====================================\n" );
  1831. L.Random( MATX_LTS_SOLVE_SIZE, MATX_LTS_SOLVE_SIZE, 0, -1.0f, 1.0f );
  1832. x.SetSize( MATX_LTS_SOLVE_SIZE );
  1833. b.Random( MATX_LTS_SOLVE_SIZE, 0, -1.0f, 1.0f );
  1834. for ( i = 1; i < MATX_LTS_SOLVE_SIZE; i++ ) {
  1835. x.Zero( i );
  1836. bestClocksGeneric = 0;
  1837. for ( j = 0; j < NUMTESTS; j++ ) {
  1838. StartRecordTime( start );
  1839. p_generic->MatX_LowerTriangularSolveTranspose( L, x.ToFloatPtr(), b.ToFloatPtr(), i );
  1840. StopRecordTime( end );
  1841. GetBest( start, end, bestClocksGeneric );
  1842. }
  1843. tst = x;
  1844. x.Zero();
  1845. PrintClocks( va( "generic->MatX_LowerTriangularSolveT %dx%d", i, i ), 1, bestClocksGeneric );
  1846. bestClocksSIMD = 0;
  1847. for ( j = 0; j < NUMTESTS; j++ ) {
  1848. StartRecordTime( start );
  1849. p_simd->MatX_LowerTriangularSolveTranspose( L, x.ToFloatPtr(), b.ToFloatPtr(), i );
  1850. StopRecordTime( end );
  1851. GetBest( start, end, bestClocksSIMD );
  1852. }
  1853. result = x.Compare( tst, MATX_LTS_SIMD_EPSILON ) ? "ok" : S_COLOR_RED"X";
  1854. PrintClocks( va( " simd->MatX_LowerTriangularSolveT %dx%d %s", i, i, result ), 1, bestClocksSIMD, bestClocksGeneric );
  1855. }
  1856. }
  1857. #define MATX_LDLT_SIMD_EPSILON 0.1f
  1858. #define MATX_LDLT_FACTOR_SOLVE_SIZE 64
  1859. /*
  1860. ============
  1861. TestMatXLDLTFactor
  1862. ============
  1863. */
  1864. void TestMatXLDLTFactor( void ) {
  1865. int i, j;
  1866. TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
  1867. const char *result;
  1868. idMatX src, original, mat1, mat2;
  1869. idVecX invDiag1, invDiag2;
  1870. idLib::common->Printf("====================================\n" );
  1871. original.SetSize( MATX_LDLT_FACTOR_SOLVE_SIZE, MATX_LDLT_FACTOR_SOLVE_SIZE );
  1872. src.Random( MATX_LDLT_FACTOR_SOLVE_SIZE, MATX_LDLT_FACTOR_SOLVE_SIZE, 0, -1.0f, 1.0f );
  1873. src.TransposeMultiply( original, src );
  1874. for ( i = 1; i < MATX_LDLT_FACTOR_SOLVE_SIZE; i++ ) {
  1875. bestClocksGeneric = 0;
  1876. for ( j = 0; j < NUMTESTS; j++ ) {
  1877. mat1 = original;
  1878. invDiag1.Zero( MATX_LDLT_FACTOR_SOLVE_SIZE );
  1879. StartRecordTime( start );
  1880. p_generic->MatX_LDLTFactor( mat1, invDiag1, i );
  1881. StopRecordTime( end );
  1882. GetBest( start, end, bestClocksGeneric );
  1883. }
  1884. PrintClocks( va( "generic->MatX_LDLTFactor %dx%d", i, i ), 1, bestClocksGeneric );
  1885. bestClocksSIMD = 0;
  1886. for ( j = 0; j < NUMTESTS; j++ ) {
  1887. mat2 = original;
  1888. invDiag2.Zero( MATX_LDLT_FACTOR_SOLVE_SIZE );
  1889. StartRecordTime( start );
  1890. p_simd->MatX_LDLTFactor( mat2, invDiag2, i );
  1891. StopRecordTime( end );
  1892. GetBest( start, end, bestClocksSIMD );
  1893. }
  1894. result = mat1.Compare( mat2, MATX_LDLT_SIMD_EPSILON ) && invDiag1.Compare( invDiag2, MATX_LDLT_SIMD_EPSILON ) ? "ok" : S_COLOR_RED"X";
  1895. PrintClocks( va( " simd->MatX_LDLTFactor %dx%d %s", i, i, result ), 1, bestClocksSIMD, bestClocksGeneric );
  1896. }
  1897. }
  1898. /*
  1899. ============
  1900. TestBlendJoints
  1901. ============
  1902. */
  1903. void TestBlendJoints( void ) {
  1904. int i, j;
  1905. TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
  1906. ALIGN16( idJointQuat baseJoints[COUNT] );
  1907. ALIGN16( idJointQuat joints1[COUNT] );
  1908. ALIGN16( idJointQuat joints2[COUNT] );
  1909. ALIGN16( idJointQuat blendJoints[COUNT] );
  1910. ALIGN16( int index[COUNT] );
  1911. float lerp = 0.3f;
  1912. const char *result;
  1913. idRandom srnd( RANDOM_SEED );
  1914. for ( i = 0; i < COUNT; i++ ) {
  1915. idAngles angles;
  1916. angles[0] = srnd.CRandomFloat() * 180.0f;
  1917. angles[1] = srnd.CRandomFloat() * 180.0f;
  1918. angles[2] = srnd.CRandomFloat() * 180.0f;
  1919. baseJoints[i].q = angles.ToQuat();
  1920. baseJoints[i].t[0] = srnd.CRandomFloat() * 10.0f;
  1921. baseJoints[i].t[1] = srnd.CRandomFloat() * 10.0f;
  1922. baseJoints[i].t[2] = srnd.CRandomFloat() * 10.0f;
  1923. angles[0] = srnd.CRandomFloat() * 180.0f;
  1924. angles[1] = srnd.CRandomFloat() * 180.0f;
  1925. angles[2] = srnd.CRandomFloat() * 180.0f;
  1926. blendJoints[i].q = angles.ToQuat();
  1927. blendJoints[i].t[0] = srnd.CRandomFloat() * 10.0f;
  1928. blendJoints[i].t[1] = srnd.CRandomFloat() * 10.0f;
  1929. blendJoints[i].t[2] = srnd.CRandomFloat() * 10.0f;
  1930. index[i] = i;
  1931. }
  1932. bestClocksGeneric = 0;
  1933. for ( i = 0; i < NUMTESTS; i++ ) {
  1934. for ( j = 0; j < COUNT; j++ ) {
  1935. joints1[j] = baseJoints[j];
  1936. }
  1937. StartRecordTime( start );
  1938. p_generic->BlendJoints( joints1, blendJoints, lerp, index, COUNT );
  1939. StopRecordTime( end );
  1940. GetBest( start, end, bestClocksGeneric );
  1941. }
  1942. PrintClocks( "generic->BlendJoints()", COUNT, bestClocksGeneric );
  1943. bestClocksSIMD = 0;
  1944. for ( i = 0; i < NUMTESTS; i++ ) {
  1945. for ( j = 0; j < COUNT; j++ ) {
  1946. joints2[j] = baseJoints[j];
  1947. }
  1948. StartRecordTime( start );
  1949. p_simd->BlendJoints( joints2, blendJoints, lerp, index, COUNT );
  1950. StopRecordTime( end );
  1951. GetBest( start, end, bestClocksSIMD );
  1952. }
  1953. for ( i = 0; i < COUNT; i++ ) {
  1954. if ( !joints1[i].t.Compare( joints2[i].t, 1e-3f ) ) {
  1955. break;
  1956. }
  1957. if ( !joints1[i].q.Compare( joints2[i].q, 1e-2f ) ) {
  1958. break;
  1959. }
  1960. }
  1961. result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
  1962. PrintClocks( va( " simd->BlendJoints() %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
  1963. }
  1964. /*
  1965. ============
  1966. TestConvertJointQuatsToJointMats
  1967. ============
  1968. */
  1969. void TestConvertJointQuatsToJointMats( void ) {
  1970. int i;
  1971. TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
  1972. ALIGN16( idJointQuat baseJoints[COUNT] );
  1973. ALIGN16( idJointMat joints1[COUNT] );
  1974. ALIGN16( idJointMat joints2[COUNT] );
  1975. const char *result;
  1976. idRandom srnd( RANDOM_SEED );
  1977. for ( i = 0; i < COUNT; i++ ) {
  1978. idAngles angles;
  1979. angles[0] = srnd.CRandomFloat() * 180.0f;
  1980. angles[1] = srnd.CRandomFloat() * 180.0f;
  1981. angles[2] = srnd.CRandomFloat() * 180.0f;
  1982. baseJoints[i].q = angles.ToQuat();
  1983. baseJoints[i].t[0] = srnd.CRandomFloat() * 10.0f;
  1984. baseJoints[i].t[1] = srnd.CRandomFloat() * 10.0f;
  1985. baseJoints[i].t[2] = srnd.CRandomFloat() * 10.0f;
  1986. }
  1987. bestClocksGeneric = 0;
  1988. for ( i = 0; i < NUMTESTS; i++ ) {
  1989. StartRecordTime( start );
  1990. p_generic->ConvertJointQuatsToJointMats( joints1, baseJoints, COUNT );
  1991. StopRecordTime( end );
  1992. GetBest( start, end, bestClocksGeneric );
  1993. }
  1994. PrintClocks( "generic->ConvertJointQuatsToJointMats()", COUNT, bestClocksGeneric );
  1995. bestClocksSIMD = 0;
  1996. for ( i = 0; i < NUMTESTS; i++ ) {
  1997. StartRecordTime( start );
  1998. p_simd->ConvertJointQuatsToJointMats( joints2, baseJoints, COUNT );
  1999. StopRecordTime( end );
  2000. GetBest( start, end, bestClocksSIMD );
  2001. }
  2002. for ( i = 0; i < COUNT; i++ ) {
  2003. if ( !joints1[i].Compare( joints2[i], 1e-4f ) ) {
  2004. break;
  2005. }
  2006. }
  2007. result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
  2008. PrintClocks( va( " simd->ConvertJointQuatsToJointMats() %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
  2009. }
  2010. /*
  2011. ============
  2012. TestConvertJointMatsToJointQuats
  2013. ============
  2014. */
  2015. void TestConvertJointMatsToJointQuats( void ) {
  2016. int i;
  2017. TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
  2018. ALIGN16( idJointMat baseJoints[COUNT] );
  2019. ALIGN16( idJointQuat joints1[COUNT] );
  2020. ALIGN16( idJointQuat joints2[COUNT] );
  2021. const char *result;
  2022. idRandom srnd( RANDOM_SEED );
  2023. for ( i = 0; i < COUNT; i++ ) {
  2024. idAngles angles;
  2025. angles[0] = srnd.CRandomFloat() * 180.0f;
  2026. angles[1] = srnd.CRandomFloat() * 180.0f;
  2027. angles[2] = srnd.CRandomFloat() * 180.0f;
  2028. baseJoints[i].SetRotation( angles.ToMat3() );
  2029. idVec3 v;
  2030. v[0] = srnd.CRandomFloat() * 10.0f;
  2031. v[1] = srnd.CRandomFloat() * 10.0f;
  2032. v[2] = srnd.CRandomFloat() * 10.0f;
  2033. baseJoints[i].SetTranslation( v );
  2034. }
  2035. bestClocksGeneric = 0;
  2036. for ( i = 0; i < NUMTESTS; i++ ) {
  2037. StartRecordTime( start );
  2038. p_generic->ConvertJointMatsToJointQuats( joints1, baseJoints, COUNT );
  2039. StopRecordTime( end );
  2040. GetBest( start, end, bestClocksGeneric );
  2041. }
  2042. PrintClocks( "generic->ConvertJointMatsToJointQuats()", COUNT, bestClocksGeneric );
  2043. bestClocksSIMD = 0;
  2044. for ( i = 0; i < NUMTESTS; i++ ) {
  2045. StartRecordTime( start );
  2046. p_simd->ConvertJointMatsToJointQuats( joints2, baseJoints, COUNT );
  2047. StopRecordTime( end );
  2048. GetBest( start, end, bestClocksSIMD );
  2049. }
  2050. for ( i = 0; i < COUNT; i++ ) {
  2051. if ( !joints1[i].q.Compare( joints2[i].q, 1e-4f ) ) {
  2052. idLib::common->Printf("ConvertJointMatsToJointQuats: broken q %i\n", i );
  2053. break;
  2054. }
  2055. if ( !joints1[i].t.Compare( joints2[i].t, 1e-4f ) ) {
  2056. idLib::common->Printf("ConvertJointMatsToJointQuats: broken t %i\n", i );
  2057. break;
  2058. }
  2059. }
  2060. result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
  2061. PrintClocks( va( " simd->ConvertJointMatsToJointQuats() %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
  2062. }
  2063. /*
  2064. ============
  2065. TestTransformJoints
  2066. ============
  2067. */
  2068. void TestTransformJoints( void ) {
  2069. int i, j;
  2070. TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
  2071. ALIGN16( idJointMat joints[COUNT+1] );
  2072. ALIGN16( idJointMat joints1[COUNT+1] );
  2073. ALIGN16( idJointMat joints2[COUNT+1] );
  2074. ALIGN16( int parents[COUNT+1] );
  2075. const char *result;
  2076. idRandom srnd( RANDOM_SEED );
  2077. for ( i = 0; i <= COUNT; i++ ) {
  2078. idAngles angles;
  2079. angles[0] = srnd.CRandomFloat() * 180.0f;
  2080. angles[1] = srnd.CRandomFloat() * 180.0f;
  2081. angles[2] = srnd.CRandomFloat() * 180.0f;
  2082. joints[i].SetRotation( angles.ToMat3() );
  2083. idVec3 v;
  2084. v[0] = srnd.CRandomFloat() * 2.0f;
  2085. v[1] = srnd.CRandomFloat() * 2.0f;
  2086. v[2] = srnd.CRandomFloat() * 2.0f;
  2087. joints[i].SetTranslation( v );
  2088. parents[i] = i - 1;
  2089. }
  2090. bestClocksGeneric = 0;
  2091. for ( i = 0; i < NUMTESTS; i++ ) {
  2092. for ( j = 0; j <= COUNT; j++ ) {
  2093. joints1[j] = joints[j];
  2094. }
  2095. StartRecordTime( start );
  2096. p_generic->TransformJoints( joints1, parents, 1, COUNT );
  2097. StopRecordTime( end );
  2098. GetBest( start, end, bestClocksGeneric );
  2099. }
  2100. PrintClocks( "generic->TransformJoints()", COUNT, bestClocksGeneric );
  2101. bestClocksSIMD = 0;
  2102. for ( i = 0; i < NUMTESTS; i++ ) {
  2103. for ( j = 0; j <= COUNT; j++ ) {
  2104. joints2[j] = joints[j];
  2105. }
  2106. StartRecordTime( start );
  2107. p_simd->TransformJoints( joints2, parents, 1, COUNT );
  2108. StopRecordTime( end );
  2109. GetBest( start, end, bestClocksSIMD );
  2110. }
  2111. for ( i = 0; i < COUNT; i++ ) {
  2112. if ( !joints1[i+1].Compare( joints2[i+1], 1e-4f ) ) {
  2113. break;
  2114. }
  2115. }
  2116. result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
  2117. PrintClocks( va( " simd->TransformJoints() %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
  2118. }
  2119. /*
  2120. ============
  2121. TestUntransformJoints
  2122. ============
  2123. */
  2124. void TestUntransformJoints( void ) {
  2125. int i, j;
  2126. TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
  2127. ALIGN16( idJointMat joints[COUNT+1] );
  2128. ALIGN16( idJointMat joints1[COUNT+1] );
  2129. ALIGN16( idJointMat joints2[COUNT+1] );
  2130. ALIGN16( int parents[COUNT+1] );
  2131. const char *result;
  2132. idRandom srnd( RANDOM_SEED );
  2133. for ( i = 0; i <= COUNT; i++ ) {
  2134. idAngles angles;
  2135. angles[0] = srnd.CRandomFloat() * 180.0f;
  2136. angles[1] = srnd.CRandomFloat() * 180.0f;
  2137. angles[2] = srnd.CRandomFloat() * 180.0f;
  2138. joints[i].SetRotation( angles.ToMat3() );
  2139. idVec3 v;
  2140. v[0] = srnd.CRandomFloat() * 2.0f;
  2141. v[1] = srnd.CRandomFloat() * 2.0f;
  2142. v[2] = srnd.CRandomFloat() * 2.0f;
  2143. joints[i].SetTranslation( v );
  2144. parents[i] = i - 1;
  2145. }
  2146. bestClocksGeneric = 0;
  2147. for ( i = 0; i < NUMTESTS; i++ ) {
  2148. for ( j = 0; j <= COUNT; j++ ) {
  2149. joints1[j] = joints[j];
  2150. }
  2151. StartRecordTime( start );
  2152. p_generic->UntransformJoints( joints1, parents, 1, COUNT );
  2153. StopRecordTime( end );
  2154. GetBest( start, end, bestClocksGeneric );
  2155. }
  2156. PrintClocks( "generic->UntransformJoints()", COUNT, bestClocksGeneric );
  2157. bestClocksSIMD = 0;
  2158. for ( i = 0; i < NUMTESTS; i++ ) {
  2159. for ( j = 0; j <= COUNT; j++ ) {
  2160. joints2[j] = joints[j];
  2161. }
  2162. StartRecordTime( start );
  2163. p_simd->UntransformJoints( joints2, parents, 1, COUNT );
  2164. StopRecordTime( end );
  2165. GetBest( start, end, bestClocksSIMD );
  2166. }
  2167. for ( i = 0; i < COUNT; i++ ) {
  2168. if ( !joints1[i+1].Compare( joints2[i+1], 1e-4f ) ) {
  2169. break;
  2170. }
  2171. }
  2172. result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
  2173. PrintClocks( va( " simd->UntransformJoints() %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
  2174. }
  2175. /*
  2176. ============
  2177. TestTransformVerts
  2178. ============
  2179. */
  2180. #define NUMJOINTS 64
  2181. #define NUMVERTS COUNT/2
  2182. void TestTransformVerts( void ) {
  2183. int i;
  2184. TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
  2185. ALIGN16( idDrawVert drawVerts1[NUMVERTS] );
  2186. ALIGN16( idDrawVert drawVerts2[NUMVERTS] );
  2187. ALIGN16( idJointMat joints[NUMJOINTS] );
  2188. ALIGN16( idVec4 weights[COUNT] );
  2189. ALIGN16( int weightIndex[COUNT*2] );
  2190. const char *result;
  2191. idRandom srnd( RANDOM_SEED );
  2192. for ( i = 0; i < NUMJOINTS; i++ ) {
  2193. idAngles angles;
  2194. angles[0] = srnd.CRandomFloat() * 180.0f;
  2195. angles[1] = srnd.CRandomFloat() * 180.0f;
  2196. angles[2] = srnd.CRandomFloat() * 180.0f;
  2197. joints[i].SetRotation( angles.ToMat3() );
  2198. idVec3 v;
  2199. v[0] = srnd.CRandomFloat() * 2.0f;
  2200. v[1] = srnd.CRandomFloat() * 2.0f;
  2201. v[2] = srnd.CRandomFloat() * 2.0f;
  2202. joints[i].SetTranslation( v );
  2203. }
  2204. for ( i = 0; i < COUNT; i++ ) {
  2205. weights[i][0] = srnd.CRandomFloat() * 2.0f;
  2206. weights[i][1] = srnd.CRandomFloat() * 2.0f;
  2207. weights[i][2] = srnd.CRandomFloat() * 2.0f;
  2208. weights[i][3] = srnd.CRandomFloat();
  2209. weightIndex[i*2+0] = ( i * NUMJOINTS / COUNT ) * sizeof( idJointMat );
  2210. weightIndex[i*2+1] = i & 1;
  2211. }
  2212. bestClocksGeneric = 0;
  2213. for ( i = 0; i < NUMTESTS; i++ ) {
  2214. StartRecordTime( start );
  2215. p_generic->TransformVerts( drawVerts1, NUMVERTS, joints, weights, weightIndex, COUNT );
  2216. StopRecordTime( end );
  2217. GetBest( start, end, bestClocksGeneric );
  2218. }
  2219. PrintClocks( "generic->TransformVerts()", COUNT, bestClocksGeneric );
  2220. bestClocksSIMD = 0;
  2221. for ( i = 0; i < NUMTESTS; i++ ) {
  2222. StartRecordTime( start );
  2223. p_simd->TransformVerts( drawVerts2, NUMVERTS, joints, weights, weightIndex, COUNT );
  2224. StopRecordTime( end );
  2225. GetBest( start, end, bestClocksSIMD );
  2226. }
  2227. for ( i = 0; i < NUMVERTS; i++ ) {
  2228. if ( !drawVerts1[i].xyz.Compare( drawVerts2[i].xyz, 0.5f ) ) {
  2229. break;
  2230. }
  2231. }
  2232. result = ( i >= NUMVERTS ) ? "ok" : S_COLOR_RED"X";
  2233. PrintClocks( va( " simd->TransformVerts() %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
  2234. }
  2235. /*
  2236. ============
  2237. TestTracePointCull
  2238. ============
  2239. */
  2240. void TestTracePointCull( void ) {
  2241. int i, j;
  2242. TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
  2243. ALIGN16( idPlane planes[4] );
  2244. ALIGN16( idDrawVert drawVerts[COUNT] );
  2245. ALIGN16( byte cullBits1[COUNT] );
  2246. ALIGN16( byte cullBits2[COUNT] );
  2247. byte totalOr1 = 0, totalOr2 = 0;
  2248. const char *result;
  2249. idRandom srnd( RANDOM_SEED );
  2250. planes[0].SetNormal( idVec3( 1, 0, 0 ) );
  2251. planes[1].SetNormal( idVec3( -1, 0, 0 ) );
  2252. planes[2].SetNormal( idVec3( 0, 1, 0 ) );
  2253. planes[3].SetNormal( idVec3( 0, -1, 0 ) );
  2254. planes[0][3] = -5.3f;
  2255. planes[1][3] = 5.3f;
  2256. planes[2][3] = -3.4f;
  2257. planes[3][3] = 3.4f;
  2258. for ( i = 0; i < COUNT; i++ ) {
  2259. for ( j = 0; j < 3; j++ ) {
  2260. drawVerts[i].xyz[j] = srnd.CRandomFloat() * 10.0f;
  2261. }
  2262. }
  2263. bestClocksGeneric = 0;
  2264. for ( i = 0; i < NUMTESTS; i++ ) {
  2265. StartRecordTime( start );
  2266. p_generic->TracePointCull( cullBits1, totalOr1, 0.0f, planes, drawVerts, COUNT );
  2267. StopRecordTime( end );
  2268. GetBest( start, end, bestClocksGeneric );
  2269. }
  2270. PrintClocks( "generic->TracePointCull()", COUNT, bestClocksGeneric );
  2271. bestClocksSIMD = 0;
  2272. for ( i = 0; i < NUMTESTS; i++ ) {
  2273. StartRecordTime( start );
  2274. p_simd->TracePointCull( cullBits2, totalOr2, 0.0f, planes, drawVerts, COUNT );
  2275. StopRecordTime( end );
  2276. GetBest( start, end, bestClocksSIMD );
  2277. }
  2278. for ( i = 0; i < COUNT; i++ ) {
  2279. if ( cullBits1[i] != cullBits2[i] ) {
  2280. break;
  2281. }
  2282. }
  2283. result = ( i >= COUNT && totalOr1 == totalOr2 ) ? "ok" : S_COLOR_RED"X";
  2284. PrintClocks( va( " simd->TracePointCull() %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
  2285. }
  2286. /*
  2287. ============
  2288. TestDecalPointCull
  2289. ============
  2290. */
  2291. void TestDecalPointCull( void ) {
  2292. int i, j;
  2293. TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
  2294. ALIGN16( idPlane planes[6] );
  2295. ALIGN16( idDrawVert drawVerts[COUNT] );
  2296. ALIGN16( byte cullBits1[COUNT] );
  2297. ALIGN16( byte cullBits2[COUNT] );
  2298. const char *result;
  2299. idRandom srnd( RANDOM_SEED );
  2300. planes[0].SetNormal( idVec3( 1, 0, 0 ) );
  2301. planes[1].SetNormal( idVec3( -1, 0, 0 ) );
  2302. planes[2].SetNormal( idVec3( 0, 1, 0 ) );
  2303. planes[3].SetNormal( idVec3( 0, -1, 0 ) );
  2304. planes[4].SetNormal( idVec3( 0, 0, 1 ) );
  2305. planes[5].SetNormal( idVec3( 0, 0, -1 ) );
  2306. planes[0][3] = -5.3f;
  2307. planes[1][3] = 5.3f;
  2308. planes[2][3] = -4.4f;
  2309. planes[3][3] = 4.4f;
  2310. planes[4][3] = -3.5f;
  2311. planes[5][3] = 3.5f;
  2312. for ( i = 0; i < COUNT; i++ ) {
  2313. for ( j = 0; j < 3; j++ ) {
  2314. drawVerts[i].xyz[j] = srnd.CRandomFloat() * 10.0f;
  2315. }
  2316. }
  2317. bestClocksGeneric = 0;
  2318. for ( i = 0; i < NUMTESTS; i++ ) {
  2319. StartRecordTime( start );
  2320. p_generic->DecalPointCull( cullBits1, planes, drawVerts, COUNT );
  2321. StopRecordTime( end );
  2322. GetBest( start, end, bestClocksGeneric );
  2323. }
  2324. PrintClocks( "generic->DecalPointCull()", COUNT, bestClocksGeneric );
  2325. bestClocksSIMD = 0;
  2326. for ( i = 0; i < NUMTESTS; i++ ) {
  2327. StartRecordTime( start );
  2328. p_simd->DecalPointCull( cullBits2, planes, drawVerts, COUNT );
  2329. StopRecordTime( end );
  2330. GetBest( start, end, bestClocksSIMD );
  2331. }
  2332. for ( i = 0; i < COUNT; i++ ) {
  2333. if ( cullBits1[i] != cullBits2[i] ) {
  2334. break;
  2335. }
  2336. }
  2337. result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
  2338. PrintClocks( va( " simd->DecalPointCull() %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
  2339. }
  2340. /*
  2341. ============
  2342. TestOverlayPointCull
  2343. ============
  2344. */
  2345. void TestOverlayPointCull( void ) {
  2346. int i, j;
  2347. TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
  2348. ALIGN16( idPlane planes[2] );
  2349. ALIGN16( idDrawVert drawVerts[COUNT] );
  2350. ALIGN16( byte cullBits1[COUNT] );
  2351. ALIGN16( byte cullBits2[COUNT] );
  2352. ALIGN16( idVec2 texCoords1[COUNT] );
  2353. ALIGN16( idVec2 texCoords2[COUNT] );
  2354. const char *result;
  2355. idRandom srnd( RANDOM_SEED );
  2356. planes[0].SetNormal( idVec3( 0.3f, 0.2f, 0.9f ) );
  2357. planes[1].SetNormal( idVec3( 0.9f, 0.2f, 0.3f ) );
  2358. planes[0][3] = -5.3f;
  2359. planes[1][3] = -4.3f;
  2360. for ( i = 0; i < COUNT; i++ ) {
  2361. for ( j = 0; j < 3; j++ ) {
  2362. drawVerts[i].xyz[j] = srnd.CRandomFloat() * 10.0f;
  2363. }
  2364. }
  2365. bestClocksGeneric = 0;
  2366. for ( i = 0; i < NUMTESTS; i++ ) {
  2367. StartRecordTime( start );
  2368. p_generic->OverlayPointCull( cullBits1, texCoords1, planes, drawVerts, COUNT );
  2369. StopRecordTime( end );
  2370. GetBest( start, end, bestClocksGeneric );
  2371. }
  2372. PrintClocks( "generic->OverlayPointCull()", COUNT, bestClocksGeneric );
  2373. bestClocksSIMD = 0;
  2374. for ( i = 0; i < NUMTESTS; i++ ) {
  2375. StartRecordTime( start );
  2376. p_simd->OverlayPointCull( cullBits2, texCoords2, planes, drawVerts, COUNT );
  2377. StopRecordTime( end );
  2378. GetBest( start, end, bestClocksSIMD );
  2379. }
  2380. for ( i = 0; i < COUNT; i++ ) {
  2381. if ( cullBits1[i] != cullBits2[i] ) {
  2382. break;
  2383. }
  2384. if ( !texCoords1[i].Compare( texCoords2[i], 1e-4f ) ) {
  2385. break;
  2386. }
  2387. }
  2388. result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
  2389. PrintClocks( va( " simd->OverlayPointCull() %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
  2390. }
  2391. /*
  2392. ============
  2393. TestDeriveTriPlanes
  2394. ============
  2395. */
  2396. void TestDeriveTriPlanes( void ) {
  2397. int i, j;
  2398. TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
  2399. ALIGN16( idDrawVert drawVerts1[COUNT] );
  2400. ALIGN16( idDrawVert drawVerts2[COUNT] );
  2401. ALIGN16( idPlane planes1[COUNT] );
  2402. ALIGN16( idPlane planes2[COUNT] );
  2403. ALIGN16( int indexes[COUNT*3] );
  2404. const char *result;
  2405. idRandom srnd( RANDOM_SEED );
  2406. for ( i = 0; i < COUNT; i++ ) {
  2407. for ( j = 0; j < 3; j++ ) {
  2408. drawVerts1[i].xyz[j] = srnd.CRandomFloat() * 10.0f;
  2409. }
  2410. for ( j = 0; j < 2; j++ ) {
  2411. drawVerts1[i].st[j] = srnd.CRandomFloat();
  2412. }
  2413. drawVerts2[i] = drawVerts1[i];
  2414. }
  2415. for ( i = 0; i < COUNT; i++ ) {
  2416. indexes[i*3+0] = ( i + 0 ) % COUNT;
  2417. indexes[i*3+1] = ( i + 1 ) % COUNT;
  2418. indexes[i*3+2] = ( i + 2 ) % COUNT;
  2419. }
  2420. bestClocksGeneric = 0;
  2421. for ( i = 0; i < NUMTESTS; i++ ) {
  2422. StartRecordTime( start );
  2423. p_generic->DeriveTriPlanes( planes1, drawVerts1, COUNT, indexes, COUNT*3 );
  2424. StopRecordTime( end );
  2425. GetBest( start, end, bestClocksGeneric );
  2426. }
  2427. PrintClocks( "generic->DeriveTriPlanes()", COUNT, bestClocksGeneric );
  2428. bestClocksSIMD = 0;
  2429. for ( i = 0; i < NUMTESTS; i++ ) {
  2430. StartRecordTime( start );
  2431. p_simd->DeriveTriPlanes( planes2, drawVerts2, COUNT, indexes, COUNT*3 );
  2432. StopRecordTime( end );
  2433. GetBest( start, end, bestClocksSIMD );
  2434. }
  2435. for ( i = 0; i < COUNT; i++ ) {
  2436. if ( !planes1[i].Compare( planes2[i], 1e-1f, 1e-1f ) ) {
  2437. break;
  2438. }
  2439. }
  2440. result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
  2441. PrintClocks( va( " simd->DeriveTriPlanes() %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
  2442. }
  2443. /*
  2444. ============
  2445. TestDeriveTangents
  2446. ============
  2447. */
  2448. void TestDeriveTangents( void ) {
  2449. int i, j;
  2450. TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
  2451. ALIGN16( idDrawVert drawVerts1[COUNT] );
  2452. ALIGN16( idDrawVert drawVerts2[COUNT] );
  2453. ALIGN16( idPlane planes1[COUNT] );
  2454. ALIGN16( idPlane planes2[COUNT] );
  2455. ALIGN16( int indexes[COUNT*3] );
  2456. const char *result;
  2457. idRandom srnd( RANDOM_SEED );
  2458. for ( i = 0; i < COUNT; i++ ) {
  2459. for ( j = 0; j < 3; j++ ) {
  2460. drawVerts1[i].xyz[j] = srnd.CRandomFloat() * 10.0f;
  2461. }
  2462. for ( j = 0; j < 2; j++ ) {
  2463. drawVerts1[i].st[j] = srnd.CRandomFloat();
  2464. }
  2465. drawVerts2[i] = drawVerts1[i];
  2466. }
  2467. for ( i = 0; i < COUNT; i++ ) {
  2468. indexes[i*3+0] = ( i + 0 ) % COUNT;
  2469. indexes[i*3+1] = ( i + 1 ) % COUNT;
  2470. indexes[i*3+2] = ( i + 2 ) % COUNT;
  2471. }
  2472. bestClocksGeneric = 0;
  2473. for ( i = 0; i < NUMTESTS; i++ ) {
  2474. StartRecordTime( start );
  2475. p_generic->DeriveTangents( planes1, drawVerts1, COUNT, indexes, COUNT*3 );
  2476. StopRecordTime( end );
  2477. GetBest( start, end, bestClocksGeneric );
  2478. }
  2479. PrintClocks( "generic->DeriveTangents()", COUNT, bestClocksGeneric );
  2480. bestClocksSIMD = 0;
  2481. for ( i = 0; i < NUMTESTS; i++ ) {
  2482. StartRecordTime( start );
  2483. p_simd->DeriveTangents( planes2, drawVerts2, COUNT, indexes, COUNT*3 );
  2484. StopRecordTime( end );
  2485. GetBest( start, end, bestClocksSIMD );
  2486. }
  2487. for ( i = 0; i < COUNT; i++ ) {
  2488. idVec3 v1, v2;
  2489. v1 = drawVerts1[i].normal;
  2490. v1.Normalize();
  2491. v2 = drawVerts2[i].normal;
  2492. v2.Normalize();
  2493. if ( !v1.Compare( v2, 1e-1f ) ) {
  2494. idLib::common->Printf("DeriveTangents: broken at normal %i\n -- expecting %s got %s", i, v1.ToString(), v2.ToString());
  2495. break;
  2496. }
  2497. v1 = drawVerts1[i].tangents[0];
  2498. v1.Normalize();
  2499. v2 = drawVerts2[i].tangents[0];
  2500. v2.Normalize();
  2501. if ( !v1.Compare( v2, 1e-1f ) ) {
  2502. idLib::common->Printf("DeriveTangents: broken at tangent0 %i -- expecting %s got %s\n", i, v1.ToString(), v2.ToString() );
  2503. break;
  2504. }
  2505. v1 = drawVerts1[i].tangents[1];
  2506. v1.Normalize();
  2507. v2 = drawVerts2[i].tangents[1];
  2508. v2.Normalize();
  2509. if ( !v1.Compare( v2, 1e-1f ) ) {
  2510. idLib::common->Printf("DeriveTangents: broken at tangent1 %i -- expecting %s got %s\n", i, v1.ToString(), v2.ToString() );
  2511. break;
  2512. }
  2513. if ( !planes1[i].Compare( planes2[i], 1e-1f, 1e-1f ) ) {
  2514. break;
  2515. }
  2516. }
  2517. result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
  2518. PrintClocks( va( " simd->DeriveTangents() %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
  2519. }
  2520. /*
  2521. ============
  2522. TestDeriveUnsmoothedTangents
  2523. ============
  2524. */
  2525. void TestDeriveUnsmoothedTangents( void ) {
  2526. int i, j;
  2527. TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
  2528. ALIGN16( idDrawVert drawVerts1[COUNT] );
  2529. ALIGN16( idDrawVert drawVerts2[COUNT] );
  2530. ALIGN16( dominantTri_s dominantTris[COUNT] );
  2531. const char *result;
  2532. idRandom srnd( RANDOM_SEED );
  2533. for ( i = 0; i < COUNT; i++ ) {
  2534. for ( j = 0; j < 3; j++ ) {
  2535. drawVerts1[i].xyz[j] = srnd.CRandomFloat() * 10.0f;
  2536. }
  2537. for ( j = 0; j < 2; j++ ) {
  2538. drawVerts1[i].st[j] = srnd.CRandomFloat();
  2539. }
  2540. drawVerts2[i] = drawVerts1[i];
  2541. dominantTris[i].v2 = ( i + 1 + srnd.RandomInt( 8 ) ) % COUNT;
  2542. dominantTris[i].v3 = ( i + 9 + srnd.RandomInt( 8 ) ) % COUNT;
  2543. dominantTris[i].normalizationScale[0] = srnd.CRandomFloat();
  2544. dominantTris[i].normalizationScale[1] = srnd.CRandomFloat();
  2545. dominantTris[i].normalizationScale[2] = srnd.CRandomFloat();
  2546. }
  2547. bestClocksGeneric = 0;
  2548. for ( i = 0; i < NUMTESTS; i++ ) {
  2549. StartRecordTime( start );
  2550. p_generic->DeriveUnsmoothedTangents( drawVerts1, dominantTris, COUNT );
  2551. StopRecordTime( end );
  2552. GetBest( start, end, bestClocksGeneric );
  2553. }
  2554. PrintClocks( "generic->DeriveUnsmoothedTangents()", COUNT, bestClocksGeneric );
  2555. bestClocksSIMD = 0;
  2556. for ( i = 0; i < NUMTESTS; i++ ) {
  2557. StartRecordTime( start );
  2558. p_simd->DeriveUnsmoothedTangents( drawVerts2, dominantTris, COUNT );
  2559. StopRecordTime( end );
  2560. GetBest( start, end, bestClocksSIMD );
  2561. }
  2562. for ( i = 0; i < COUNT; i++ ) {
  2563. idVec3 v1, v2;
  2564. v1 = drawVerts1[i].normal;
  2565. v1.Normalize();
  2566. v2 = drawVerts2[i].normal;
  2567. v2.Normalize();
  2568. if ( !v1.Compare( v2, 1e-1f ) ) {
  2569. break;
  2570. }
  2571. v1 = drawVerts1[i].tangents[0];
  2572. v1.Normalize();
  2573. v2 = drawVerts2[i].tangents[0];
  2574. v2.Normalize();
  2575. if ( !v1.Compare( v2, 1e-1f ) ) {
  2576. break;
  2577. }
  2578. v1 = drawVerts1[i].tangents[1];
  2579. v1.Normalize();
  2580. v2 = drawVerts2[i].tangents[1];
  2581. v2.Normalize();
  2582. if ( !v1.Compare( v2, 1e-1f ) ) {
  2583. break;
  2584. }
  2585. }
  2586. result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
  2587. PrintClocks( va( " simd->DeriveUnsmoothedTangents() %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
  2588. }
  2589. /*
  2590. ============
  2591. TestNormalizeTangents
  2592. ============
  2593. */
  2594. void TestNormalizeTangents( void ) {
  2595. int i, j;
  2596. TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
  2597. ALIGN16( idDrawVert drawVerts1[COUNT] );
  2598. ALIGN16( idDrawVert drawVerts2[COUNT] );
  2599. const char *result;
  2600. idRandom srnd( RANDOM_SEED );
  2601. for ( i = 0; i < COUNT; i++ ) {
  2602. for ( j = 0; j < 3; j++ ) {
  2603. drawVerts1[i].normal[j] = srnd.CRandomFloat() * 10.0f;
  2604. drawVerts1[i].tangents[0][j] = srnd.CRandomFloat() * 10.0f;
  2605. drawVerts1[i].tangents[1][j] = srnd.CRandomFloat() * 10.0f;
  2606. }
  2607. drawVerts2[i] = drawVerts1[i];
  2608. }
  2609. bestClocksGeneric = 0;
  2610. for ( i = 0; i < NUMTESTS; i++ ) {
  2611. StartRecordTime( start );
  2612. p_generic->NormalizeTangents( drawVerts1, COUNT );
  2613. StopRecordTime( end );
  2614. GetBest( start, end, bestClocksGeneric );
  2615. }
  2616. PrintClocks( "generic->NormalizeTangents()", COUNT, bestClocksGeneric );
  2617. bestClocksSIMD = 0;
  2618. for ( i = 0; i < NUMTESTS; i++ ) {
  2619. StartRecordTime( start );
  2620. p_simd->NormalizeTangents( drawVerts2, COUNT );
  2621. StopRecordTime( end );
  2622. GetBest( start, end, bestClocksSIMD );
  2623. }
  2624. for ( i = 0; i < COUNT; i++ ) {
  2625. if ( !drawVerts1[i].normal.Compare( drawVerts2[i].normal, 1e-2f ) ) {
  2626. break;
  2627. }
  2628. if ( !drawVerts1[i].tangents[0].Compare( drawVerts2[i].tangents[0], 1e-2f ) ) {
  2629. break;
  2630. }
  2631. if ( !drawVerts1[i].tangents[1].Compare( drawVerts2[i].tangents[1], 1e-2f ) ) {
  2632. break;
  2633. }
  2634. // since we're doing a lot of unaligned work, added this check to
  2635. // make sure xyz wasn't getting overwritten
  2636. if ( !drawVerts1[i].xyz.Compare( drawVerts2[i].xyz, 1e-2f ) ) {
  2637. break;
  2638. }
  2639. }
  2640. result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
  2641. PrintClocks( va( " simd->NormalizeTangents() %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
  2642. }
  2643. /*
  2644. ============
  2645. TestGetTextureSpaceLightVectors
  2646. ============
  2647. */
  2648. void TestGetTextureSpaceLightVectors( void ) {
  2649. int i, j;
  2650. TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
  2651. ALIGN16( idDrawVert drawVerts[COUNT] );
  2652. ALIGN16( idVec4 texCoords1[COUNT] );
  2653. ALIGN16( idVec4 texCoords2[COUNT] );
  2654. ALIGN16( int indexes[COUNT*3] );
  2655. ALIGN16( idVec3 lightVectors1[COUNT] );
  2656. ALIGN16( idVec3 lightVectors2[COUNT] );
  2657. idVec3 lightOrigin;
  2658. const char *result;
  2659. idRandom srnd( RANDOM_SEED );
  2660. for ( i = 0; i < COUNT; i++ ) {
  2661. for ( j = 0; j < 3; j++ ) {
  2662. drawVerts[i].xyz[j] = srnd.CRandomFloat() * 100.0f;
  2663. drawVerts[i].normal[j] = srnd.CRandomFloat();
  2664. drawVerts[i].tangents[0][j] = srnd.CRandomFloat();
  2665. drawVerts[i].tangents[1][j] = srnd.CRandomFloat();
  2666. }
  2667. }
  2668. for ( i = 0; i < COUNT; i++ ) {
  2669. indexes[i*3+0] = ( i + 0 ) % COUNT;
  2670. indexes[i*3+1] = ( i + 1 ) % COUNT;
  2671. indexes[i*3+2] = ( i + 2 ) % COUNT;
  2672. }
  2673. lightOrigin[0] = srnd.CRandomFloat() * 100.0f;
  2674. lightOrigin[1] = srnd.CRandomFloat() * 100.0f;
  2675. lightOrigin[2] = srnd.CRandomFloat() * 100.0f;
  2676. bestClocksGeneric = 0;
  2677. for ( i = 0; i < NUMTESTS; i++ ) {
  2678. StartRecordTime( start );
  2679. p_generic->CreateTextureSpaceLightVectors( lightVectors1, lightOrigin, drawVerts, COUNT, indexes, COUNT*3 );
  2680. StopRecordTime( end );
  2681. GetBest( start, end, bestClocksGeneric );
  2682. }
  2683. PrintClocks( "generic->CreateTextureSpaceLightVectors()", COUNT, bestClocksGeneric );
  2684. bestClocksSIMD = 0;
  2685. for ( i = 0; i < NUMTESTS; i++ ) {
  2686. StartRecordTime( start );
  2687. p_simd->CreateTextureSpaceLightVectors( lightVectors2, lightOrigin, drawVerts, COUNT, indexes, COUNT*3 );
  2688. StopRecordTime( end );
  2689. GetBest( start, end, bestClocksSIMD );
  2690. }
  2691. for ( i = 0; i < COUNT; i++ ) {
  2692. if ( !lightVectors1[i].Compare( lightVectors2[i], 1e-4f ) ) {
  2693. break;
  2694. }
  2695. }
  2696. result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
  2697. PrintClocks( va( " simd->CreateTextureSpaceLightVectors() %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
  2698. }
  2699. /*
  2700. ============
  2701. TestGetSpecularTextureCoords
  2702. ============
  2703. */
  2704. void TestGetSpecularTextureCoords( void ) {
  2705. int i, j;
  2706. TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
  2707. ALIGN16( idDrawVert drawVerts[COUNT] );
  2708. ALIGN16( idVec4 texCoords1[COUNT] );
  2709. ALIGN16( idVec4 texCoords2[COUNT] );
  2710. ALIGN16( int indexes[COUNT*3] );
  2711. ALIGN16( idVec3 lightVectors1[COUNT] );
  2712. ALIGN16( idVec3 lightVectors2[COUNT] );
  2713. idVec3 lightOrigin, viewOrigin;
  2714. const char *result;
  2715. idRandom srnd( RANDOM_SEED );
  2716. for ( i = 0; i < COUNT; i++ ) {
  2717. for ( j = 0; j < 3; j++ ) {
  2718. drawVerts[i].xyz[j] = srnd.CRandomFloat() * 100.0f;
  2719. drawVerts[i].normal[j] = srnd.CRandomFloat();
  2720. drawVerts[i].tangents[0][j] = srnd.CRandomFloat();
  2721. drawVerts[i].tangents[1][j] = srnd.CRandomFloat();
  2722. }
  2723. }
  2724. for ( i = 0; i < COUNT; i++ ) {
  2725. indexes[i*3+0] = ( i + 0 ) % COUNT;
  2726. indexes[i*3+1] = ( i + 1 ) % COUNT;
  2727. indexes[i*3+2] = ( i + 2 ) % COUNT;
  2728. }
  2729. lightOrigin[0] = srnd.CRandomFloat() * 100.0f;
  2730. lightOrigin[1] = srnd.CRandomFloat() * 100.0f;
  2731. lightOrigin[2] = srnd.CRandomFloat() * 100.0f;
  2732. viewOrigin[0] = srnd.CRandomFloat() * 100.0f;
  2733. viewOrigin[1] = srnd.CRandomFloat() * 100.0f;
  2734. viewOrigin[2] = srnd.CRandomFloat() * 100.0f;
  2735. bestClocksGeneric = 0;
  2736. for ( i = 0; i < NUMTESTS; i++ ) {
  2737. StartRecordTime( start );
  2738. p_generic->CreateSpecularTextureCoords( texCoords1, lightOrigin, viewOrigin, drawVerts, COUNT, indexes, COUNT*3 );
  2739. StopRecordTime( end );
  2740. GetBest( start, end, bestClocksGeneric );
  2741. }
  2742. PrintClocks( "generic->CreateSpecularTextureCoords()", COUNT, bestClocksGeneric );
  2743. bestClocksSIMD = 0;
  2744. for ( i = 0; i < NUMTESTS; i++ ) {
  2745. StartRecordTime( start );
  2746. p_simd->CreateSpecularTextureCoords( texCoords2, lightOrigin, viewOrigin, drawVerts, COUNT, indexes, COUNT*3 );
  2747. StopRecordTime( end );
  2748. GetBest( start, end, bestClocksSIMD );
  2749. }
  2750. for ( i = 0; i < COUNT; i++ ) {
  2751. if ( !texCoords1[i].Compare( texCoords2[i], 1e-2f ) ) {
  2752. break;
  2753. }
  2754. }
  2755. result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
  2756. PrintClocks( va( " simd->CreateSpecularTextureCoords() %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
  2757. }
  2758. /*
  2759. ============
  2760. TestCreateShadowCache
  2761. ============
  2762. */
  2763. void TestCreateShadowCache( void ) {
  2764. int i, j;
  2765. TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
  2766. ALIGN16( idDrawVert drawVerts[COUNT] );
  2767. ALIGN16( idVec4 vertexCache1[COUNT*2] );
  2768. ALIGN16( idVec4 vertexCache2[COUNT*2] );
  2769. ALIGN16( int originalVertRemap[COUNT] );
  2770. ALIGN16( int vertRemap1[COUNT] );
  2771. ALIGN16( int vertRemap2[COUNT] );
  2772. ALIGN16( idVec3 lightOrigin );
  2773. int numVerts1 = 0, numVerts2 = 0;
  2774. const char *result;
  2775. idRandom srnd( RANDOM_SEED );
  2776. for ( i = 0; i < COUNT; i++ ) {
  2777. drawVerts[i].xyz[0] = srnd.CRandomFloat() * 100.0f;
  2778. drawVerts[i].xyz[1] = srnd.CRandomFloat() * 100.0f;
  2779. drawVerts[i].xyz[2] = srnd.CRandomFloat() * 100.0f;
  2780. originalVertRemap[i] = ( srnd.CRandomFloat() > 0.0f ) ? -1 : 0;
  2781. }
  2782. lightOrigin[0] = srnd.CRandomFloat() * 100.0f;
  2783. lightOrigin[1] = srnd.CRandomFloat() * 100.0f;
  2784. lightOrigin[2] = srnd.CRandomFloat() * 100.0f;
  2785. bestClocksGeneric = 0;
  2786. for ( i = 0; i < NUMTESTS; i++ ) {
  2787. for ( j = 0; j < COUNT; j++ ) {
  2788. vertRemap1[j] = originalVertRemap[j];
  2789. }
  2790. StartRecordTime( start );
  2791. numVerts1 =p_generic->CreateShadowCache( vertexCache1, vertRemap1, lightOrigin, drawVerts, COUNT );
  2792. StopRecordTime( end );
  2793. GetBest( start, end, bestClocksGeneric );
  2794. }
  2795. PrintClocks( "generic->CreateShadowCache()", COUNT, bestClocksGeneric );
  2796. bestClocksSIMD = 0;
  2797. for ( i = 0; i < NUMTESTS; i++ ) {
  2798. for ( j = 0; j < COUNT; j++ ) {
  2799. vertRemap2[j] = originalVertRemap[j];
  2800. }
  2801. StartRecordTime( start );
  2802. numVerts2 = p_simd->CreateShadowCache( vertexCache2, vertRemap2, lightOrigin, drawVerts, COUNT );
  2803. StopRecordTime( end );
  2804. GetBest( start, end, bestClocksSIMD );
  2805. }
  2806. for ( i = 0; i < COUNT; i++ ) {
  2807. if ( i < ( numVerts1 / 2 ) ) {
  2808. if ( !vertexCache1[i*2+0].Compare( vertexCache2[i*2+0], 1e-2f ) ) {
  2809. break;
  2810. }
  2811. if ( !vertexCache1[i*2+1].Compare( vertexCache2[i*2+1], 1e-2f ) ) {
  2812. break;
  2813. }
  2814. }
  2815. if ( vertRemap1[i] != vertRemap2[i] ) {
  2816. break;
  2817. }
  2818. }
  2819. result = ( i >= COUNT && numVerts1 == numVerts2 ) ? "ok" : S_COLOR_RED"X";
  2820. PrintClocks( va( " simd->CreateShadowCache() %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
  2821. bestClocksGeneric = 0;
  2822. for ( i = 0; i < NUMTESTS; i++ ) {
  2823. StartRecordTime( start );
  2824. p_generic->CreateVertexProgramShadowCache( vertexCache1, drawVerts, COUNT );
  2825. StopRecordTime( end );
  2826. GetBest( start, end, bestClocksGeneric );
  2827. }
  2828. PrintClocks( "generic->CreateVertexProgramShadowCache()", COUNT, bestClocksGeneric );
  2829. bestClocksSIMD = 0;
  2830. for ( i = 0; i < NUMTESTS; i++ ) {
  2831. StartRecordTime( start );
  2832. p_simd->CreateVertexProgramShadowCache( vertexCache2, drawVerts, COUNT );
  2833. StopRecordTime( end );
  2834. GetBest( start, end, bestClocksSIMD );
  2835. }
  2836. for ( i = 0; i < COUNT; i++ ) {
  2837. if ( !vertexCache1[i*2+0].Compare( vertexCache2[i*2+0], 1e-2f ) ) {
  2838. break;
  2839. }
  2840. if ( !vertexCache1[i*2+1].Compare( vertexCache2[i*2+1], 1e-2f ) ) {
  2841. break;
  2842. }
  2843. }
  2844. result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
  2845. PrintClocks( va( " simd->CreateVertexProgramShadowCache() %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
  2846. }
  2847. /*
  2848. ============
  2849. TestSoundUpSampling
  2850. ============
  2851. */
  2852. #define SOUND_UPSAMPLE_EPSILON 1.0f
  2853. void TestSoundUpSampling( void ) {
  2854. int i;
  2855. TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
  2856. ALIGN16( short pcm[MIXBUFFER_SAMPLES*2] );
  2857. ALIGN16( float ogg0[MIXBUFFER_SAMPLES*2] );
  2858. ALIGN16( float ogg1[MIXBUFFER_SAMPLES*2] );
  2859. ALIGN16( float samples1[MIXBUFFER_SAMPLES*2] );
  2860. ALIGN16( float samples2[MIXBUFFER_SAMPLES*2] );
  2861. float *ogg[2];
  2862. int kHz, numSpeakers;
  2863. const char *result;
  2864. idRandom srnd( RANDOM_SEED );
  2865. for ( i = 0; i < MIXBUFFER_SAMPLES*2; i++ ) {
  2866. pcm[i] = srnd.RandomInt( (1<<16) ) - (1<<15);
  2867. ogg0[i] = srnd.RandomFloat();
  2868. ogg1[i] = srnd.RandomFloat();
  2869. }
  2870. ogg[0] = ogg0;
  2871. ogg[1] = ogg1;
  2872. for ( numSpeakers = 1; numSpeakers <= 2; numSpeakers++ ) {
  2873. for ( kHz = 11025; kHz <= 44100; kHz *= 2 ) {
  2874. bestClocksGeneric = 0;
  2875. for ( i = 0; i < NUMTESTS; i++ ) {
  2876. StartRecordTime( start );
  2877. p_generic->UpSamplePCMTo44kHz( samples1, pcm, MIXBUFFER_SAMPLES*numSpeakers*kHz/44100, kHz, numSpeakers );
  2878. StopRecordTime( end );
  2879. GetBest( start, end, bestClocksGeneric );
  2880. }
  2881. PrintClocks( va( "generic->UpSamplePCMTo44kHz( %d, %d )", kHz, numSpeakers ), MIXBUFFER_SAMPLES*numSpeakers*kHz/44100, bestClocksGeneric );
  2882. bestClocksSIMD = 0;
  2883. for ( i = 0; i < NUMTESTS; i++ ) {
  2884. StartRecordTime( start );
  2885. p_simd->UpSamplePCMTo44kHz( samples2, pcm, MIXBUFFER_SAMPLES*numSpeakers*kHz/44100, kHz, numSpeakers );
  2886. StopRecordTime( end );
  2887. GetBest( start, end, bestClocksSIMD );
  2888. }
  2889. for ( i = 0; i < MIXBUFFER_SAMPLES*numSpeakers; i++ ) {
  2890. if ( idMath::Fabs( samples1[i] - samples2[i] ) > SOUND_UPSAMPLE_EPSILON ) {
  2891. break;
  2892. }
  2893. }
  2894. result = ( i >= MIXBUFFER_SAMPLES*numSpeakers ) ? "ok" : S_COLOR_RED"X";
  2895. PrintClocks( va( " simd->UpSamplePCMTo44kHz( %d, %d ) %s", kHz, numSpeakers, result ), MIXBUFFER_SAMPLES*numSpeakers*kHz/44100, bestClocksSIMD, bestClocksGeneric );
  2896. }
  2897. }
  2898. for ( numSpeakers = 1; numSpeakers <= 2; numSpeakers++ ) {
  2899. for ( kHz = 11025; kHz <= 44100; kHz *= 2 ) {
  2900. bestClocksGeneric = 0;
  2901. for ( i = 0; i < NUMTESTS; i++ ) {
  2902. StartRecordTime( start );
  2903. p_generic->UpSampleOGGTo44kHz( samples1, ogg, MIXBUFFER_SAMPLES*numSpeakers*kHz/44100, kHz, numSpeakers );
  2904. StopRecordTime( end );
  2905. GetBest( start, end, bestClocksGeneric );
  2906. }
  2907. PrintClocks( va( "generic->UpSampleOGGTo44kHz( %d, %d )", kHz, numSpeakers ), MIXBUFFER_SAMPLES*numSpeakers*kHz/44100, bestClocksGeneric );
  2908. bestClocksSIMD = 0;
  2909. for ( i = 0; i < NUMTESTS; i++ ) {
  2910. StartRecordTime( start );
  2911. p_simd->UpSampleOGGTo44kHz( samples2, ogg, MIXBUFFER_SAMPLES*numSpeakers*kHz/44100, kHz, numSpeakers );
  2912. StopRecordTime( end );
  2913. GetBest( start, end, bestClocksSIMD );
  2914. }
  2915. for ( i = 0; i < MIXBUFFER_SAMPLES*numSpeakers; i++ ) {
  2916. if ( idMath::Fabs( samples1[i] - samples2[i] ) > SOUND_UPSAMPLE_EPSILON ) {
  2917. break;
  2918. }
  2919. }
  2920. result = ( i >= MIXBUFFER_SAMPLES ) ? "ok" : S_COLOR_RED"X";
  2921. PrintClocks( va( " simd->UpSampleOGGTo44kHz( %d, %d ) %s", kHz, numSpeakers, result ), MIXBUFFER_SAMPLES*numSpeakers*kHz/44100, bestClocksSIMD, bestClocksGeneric );
  2922. }
  2923. }
  2924. }
  2925. /*
  2926. ============
  2927. TestSoundMixing
  2928. ============
  2929. */
  2930. #define SOUND_MIX_EPSILON 2.0f
  2931. void TestSoundMixing( void ) {
  2932. int i, j;
  2933. TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
  2934. ALIGN16( float origMixBuffer[MIXBUFFER_SAMPLES*6] );
  2935. ALIGN16( float mixBuffer1[MIXBUFFER_SAMPLES*6] );
  2936. ALIGN16( float mixBuffer2[MIXBUFFER_SAMPLES*6] );
  2937. ALIGN16( float samples[MIXBUFFER_SAMPLES*6] );
  2938. ALIGN16( short outSamples1[MIXBUFFER_SAMPLES*6] );
  2939. ALIGN16( short outSamples2[MIXBUFFER_SAMPLES*6] );
  2940. float lastV[6];
  2941. float currentV[6];
  2942. const char *result;
  2943. idRandom srnd( RANDOM_SEED );
  2944. for ( i = 0; i < 6; i++ ) {
  2945. lastV[i] = srnd.CRandomFloat();
  2946. currentV[i] = srnd.CRandomFloat();
  2947. }
  2948. for ( i = 0; i < MIXBUFFER_SAMPLES*6; i++ ) {
  2949. origMixBuffer[i] = srnd.CRandomFloat();
  2950. samples[i] = srnd.RandomInt( (1<<16) ) - (1<<15);
  2951. }
  2952. bestClocksGeneric = 0;
  2953. for ( i = 0; i < NUMTESTS; i++ ) {
  2954. for ( j = 0; j < MIXBUFFER_SAMPLES*6; j++ ) {
  2955. mixBuffer1[j] = origMixBuffer[j];
  2956. }
  2957. StartRecordTime( start );
  2958. p_generic->MixSoundTwoSpeakerMono( mixBuffer1, samples, MIXBUFFER_SAMPLES, lastV, currentV );
  2959. StopRecordTime( end );
  2960. GetBest( start, end, bestClocksGeneric );
  2961. }
  2962. PrintClocks( "generic->MixSoundTwoSpeakerMono()", MIXBUFFER_SAMPLES, bestClocksGeneric );
  2963. bestClocksSIMD = 0;
  2964. for ( i = 0; i < NUMTESTS; i++ ) {
  2965. for ( j = 0; j < MIXBUFFER_SAMPLES*6; j++ ) {
  2966. mixBuffer2[j] = origMixBuffer[j];
  2967. }
  2968. StartRecordTime( start );
  2969. p_simd->MixSoundTwoSpeakerMono( mixBuffer2, samples, MIXBUFFER_SAMPLES, lastV, currentV );
  2970. StopRecordTime( end );
  2971. GetBest( start, end, bestClocksSIMD );
  2972. }
  2973. for ( i = 0; i < MIXBUFFER_SAMPLES*6; i++ ) {
  2974. if ( idMath::Fabs( mixBuffer1[i] - mixBuffer2[i] ) > SOUND_MIX_EPSILON ) {
  2975. break;
  2976. }
  2977. }
  2978. result = ( i >= MIXBUFFER_SAMPLES*6 ) ? "ok" : S_COLOR_RED"X";
  2979. PrintClocks( va( " simd->MixSoundTwoSpeakerMono() %s", result ), MIXBUFFER_SAMPLES, bestClocksSIMD, bestClocksGeneric );
  2980. bestClocksGeneric = 0;
  2981. for ( i = 0; i < NUMTESTS; i++ ) {
  2982. for ( j = 0; j < MIXBUFFER_SAMPLES*6; j++ ) {
  2983. mixBuffer1[j] = origMixBuffer[j];
  2984. }
  2985. StartRecordTime( start );
  2986. p_generic->MixSoundTwoSpeakerStereo( mixBuffer1, samples, MIXBUFFER_SAMPLES, lastV, currentV );
  2987. StopRecordTime( end );
  2988. GetBest( start, end, bestClocksGeneric );
  2989. }
  2990. PrintClocks( "generic->MixSoundTwoSpeakerStereo()", MIXBUFFER_SAMPLES, bestClocksGeneric );
  2991. bestClocksSIMD = 0;
  2992. for ( i = 0; i < NUMTESTS; i++ ) {
  2993. for ( j = 0; j < MIXBUFFER_SAMPLES*6; j++ ) {
  2994. mixBuffer2[j] = origMixBuffer[j];
  2995. }
  2996. StartRecordTime( start );
  2997. p_simd->MixSoundTwoSpeakerStereo( mixBuffer2, samples, MIXBUFFER_SAMPLES, lastV, currentV );
  2998. StopRecordTime( end );
  2999. GetBest( start, end, bestClocksSIMD );
  3000. }
  3001. for ( i = 0; i < MIXBUFFER_SAMPLES*6; i++ ) {
  3002. if ( idMath::Fabs( mixBuffer1[i] - mixBuffer2[i] ) > SOUND_MIX_EPSILON ) {
  3003. break;
  3004. }
  3005. }
  3006. result = ( i >= MIXBUFFER_SAMPLES*6 ) ? "ok" : S_COLOR_RED"X";
  3007. PrintClocks( va( " simd->MixSoundTwoSpeakerStereo() %s", result ), MIXBUFFER_SAMPLES, bestClocksSIMD, bestClocksGeneric );
  3008. bestClocksGeneric = 0;
  3009. for ( i = 0; i < NUMTESTS; i++ ) {
  3010. for ( j = 0; j < MIXBUFFER_SAMPLES*6; j++ ) {
  3011. mixBuffer1[j] = origMixBuffer[j];
  3012. }
  3013. StartRecordTime( start );
  3014. p_generic->MixSoundSixSpeakerMono( mixBuffer1, samples, MIXBUFFER_SAMPLES, lastV, currentV );
  3015. StopRecordTime( end );
  3016. GetBest( start, end, bestClocksGeneric );
  3017. }
  3018. PrintClocks( "generic->MixSoundSixSpeakerMono()", MIXBUFFER_SAMPLES, bestClocksGeneric );
  3019. bestClocksSIMD = 0;
  3020. for ( i = 0; i < NUMTESTS; i++ ) {
  3021. for ( j = 0; j < MIXBUFFER_SAMPLES*6; j++ ) {
  3022. mixBuffer2[j] = origMixBuffer[j];
  3023. }
  3024. StartRecordTime( start );
  3025. p_simd->MixSoundSixSpeakerMono( mixBuffer2, samples, MIXBUFFER_SAMPLES, lastV, currentV );
  3026. StopRecordTime( end );
  3027. GetBest( start, end, bestClocksSIMD );
  3028. }
  3029. for ( i = 0; i < MIXBUFFER_SAMPLES*6; i++ ) {
  3030. if ( idMath::Fabs( mixBuffer1[i] - mixBuffer2[i] ) > SOUND_MIX_EPSILON ) {
  3031. break;
  3032. }
  3033. }
  3034. result = ( i >= MIXBUFFER_SAMPLES*6 ) ? "ok" : S_COLOR_RED"X";
  3035. PrintClocks( va( " simd->MixSoundSixSpeakerMono() %s", result ), MIXBUFFER_SAMPLES, bestClocksSIMD, bestClocksGeneric );
  3036. bestClocksGeneric = 0;
  3037. for ( i = 0; i < NUMTESTS; i++ ) {
  3038. for ( j = 0; j < MIXBUFFER_SAMPLES*6; j++ ) {
  3039. mixBuffer1[j] = origMixBuffer[j];
  3040. }
  3041. StartRecordTime( start );
  3042. p_generic->MixSoundSixSpeakerStereo( mixBuffer1, samples, MIXBUFFER_SAMPLES, lastV, currentV );
  3043. StopRecordTime( end );
  3044. GetBest( start, end, bestClocksGeneric );
  3045. }
  3046. PrintClocks( "generic->MixSoundSixSpeakerStereo()", MIXBUFFER_SAMPLES, bestClocksGeneric );
  3047. bestClocksSIMD = 0;
  3048. for ( i = 0; i < NUMTESTS; i++ ) {
  3049. for ( j = 0; j < MIXBUFFER_SAMPLES*6; j++ ) {
  3050. mixBuffer2[j] = origMixBuffer[j];
  3051. }
  3052. StartRecordTime( start );
  3053. p_simd->MixSoundSixSpeakerStereo( mixBuffer2, samples, MIXBUFFER_SAMPLES, lastV, currentV );
  3054. StopRecordTime( end );
  3055. GetBest( start, end, bestClocksSIMD );
  3056. }
  3057. for ( i = 0; i < MIXBUFFER_SAMPLES*6; i++ ) {
  3058. if ( idMath::Fabs( mixBuffer1[i] - mixBuffer2[i] ) > SOUND_MIX_EPSILON ) {
  3059. break;
  3060. }
  3061. }
  3062. result = ( i >= MIXBUFFER_SAMPLES*6 ) ? "ok" : S_COLOR_RED"X";
  3063. PrintClocks( va( " simd->MixSoundSixSpeakerStereo() %s", result ), MIXBUFFER_SAMPLES, bestClocksSIMD, bestClocksGeneric );
  3064. for ( i = 0; i < MIXBUFFER_SAMPLES*6; i++ ) {
  3065. origMixBuffer[i] = srnd.RandomInt( (1<<17) ) - (1<<16);
  3066. }
  3067. bestClocksGeneric = 0;
  3068. for ( i = 0; i < NUMTESTS; i++ ) {
  3069. for ( j = 0; j < MIXBUFFER_SAMPLES*6; j++ ) {
  3070. mixBuffer1[j] = origMixBuffer[j];
  3071. }
  3072. StartRecordTime( start );
  3073. p_generic->MixedSoundToSamples( outSamples1, mixBuffer1, MIXBUFFER_SAMPLES*6 );
  3074. StopRecordTime( end );
  3075. GetBest( start, end, bestClocksGeneric );
  3076. }
  3077. PrintClocks( "generic->MixedSoundToSamples()", MIXBUFFER_SAMPLES, bestClocksGeneric );
  3078. bestClocksSIMD = 0;
  3079. for ( i = 0; i < NUMTESTS; i++ ) {
  3080. for ( j = 0; j < MIXBUFFER_SAMPLES*6; j++ ) {
  3081. mixBuffer2[j] = origMixBuffer[j];
  3082. }
  3083. StartRecordTime( start );
  3084. p_simd->MixedSoundToSamples( outSamples2, mixBuffer2, MIXBUFFER_SAMPLES*6 );
  3085. StopRecordTime( end );
  3086. GetBest( start, end, bestClocksSIMD );
  3087. }
  3088. for ( i = 0; i < MIXBUFFER_SAMPLES*6; i++ ) {
  3089. if ( outSamples1[i] != outSamples2[i] ) {
  3090. break;
  3091. }
  3092. }
  3093. result = ( i >= MIXBUFFER_SAMPLES*6 ) ? "ok" : S_COLOR_RED"X";
  3094. PrintClocks( va( " simd->MixedSoundToSamples() %s", result ), MIXBUFFER_SAMPLES, bestClocksSIMD, bestClocksGeneric );
  3095. }
  3096. /*
  3097. ============
  3098. TestMath
  3099. ============
  3100. */
  3101. void TestMath( void ) {
  3102. int i;
  3103. TIME_TYPE start, end, bestClocks;
  3104. idLib::common->Printf("====================================\n" );
  3105. float tst = -1.0f;
  3106. float tst2 = 1.0f;
  3107. float testvar = 1.0f;
  3108. idRandom rnd;
  3109. bestClocks = 0;
  3110. tst = rnd.CRandomFloat();
  3111. for ( i = 0; i < NUMTESTS; i++ ) {
  3112. StartRecordTime( start );
  3113. tst = fabs( tst );
  3114. StopRecordTime( end );
  3115. GetBest( start, end, bestClocks );
  3116. testvar = ( testvar + tst ) * tst;
  3117. tst = rnd.CRandomFloat();
  3118. }
  3119. PrintClocks( " fabs( tst )", 1, bestClocks );
  3120. bestClocks = 0;
  3121. tst = rnd.CRandomFloat();
  3122. for ( i = 0; i < NUMTESTS; i++ ) {
  3123. StartRecordTime( start );
  3124. int tmp = * ( int * ) &tst;
  3125. tmp &= 0x7FFFFFFF;
  3126. tst = * ( float * ) &tmp;
  3127. StopRecordTime( end );
  3128. GetBest( start, end, bestClocks );
  3129. testvar = ( testvar + tst ) * tst;
  3130. tst = rnd.CRandomFloat();
  3131. }
  3132. PrintClocks( " idMath::Fabs( tst )", 1, bestClocks );
  3133. bestClocks = 0;
  3134. tst = 10.0f + 100.0f * rnd.RandomFloat();
  3135. for ( i = 0; i < NUMTESTS; i++ ) {
  3136. StartRecordTime( start );
  3137. tst = sqrt( tst );
  3138. StopRecordTime( end );
  3139. GetBest( start, end, bestClocks );
  3140. testvar = ( testvar + tst ) * tst * 0.01f;
  3141. tst = 10.0f + 100.0f * rnd.RandomFloat();
  3142. }
  3143. PrintClocks( " sqrt( tst )", 1, bestClocks );
  3144. bestClocks = 0;
  3145. tst = rnd.RandomFloat();
  3146. for ( i = 0; i < NUMTESTS; i++ ) {
  3147. StartRecordTime( start );
  3148. tst = idMath::Sqrt( tst );
  3149. StopRecordTime( end );
  3150. GetBest( start, end, bestClocks );
  3151. testvar = ( testvar + tst ) * tst;
  3152. tst = rnd.RandomFloat();
  3153. }
  3154. PrintClocks( " idMath::Sqrt( tst )", 1, bestClocks );
  3155. bestClocks = 0;
  3156. tst = rnd.RandomFloat();
  3157. for ( i = 0; i < NUMTESTS; i++ ) {
  3158. StartRecordTime( start );
  3159. tst = idMath::Sqrt16( tst );
  3160. StopRecordTime( end );
  3161. GetBest( start, end, bestClocks );
  3162. testvar = ( testvar + tst ) * tst;
  3163. tst = rnd.RandomFloat();
  3164. }
  3165. PrintClocks( " idMath::Sqrt16( tst )", 1, bestClocks );
  3166. bestClocks = 0;
  3167. tst = rnd.RandomFloat();
  3168. for ( i = 0; i < NUMTESTS; i++ ) {
  3169. StartRecordTime( start );
  3170. tst = idMath::Sqrt64( tst );
  3171. StopRecordTime( end );
  3172. GetBest( start, end, bestClocks );
  3173. testvar = ( testvar + tst ) * tst;
  3174. tst = rnd.RandomFloat();
  3175. }
  3176. PrintClocks( " idMath::Sqrt64( tst )", 1, bestClocks );
  3177. bestClocks = 0;
  3178. tst = rnd.RandomFloat();
  3179. for ( i = 0; i < NUMTESTS; i++ ) {
  3180. StartRecordTime( start );
  3181. tst = tst * idMath::RSqrt( tst );
  3182. StopRecordTime( end );
  3183. GetBest( start, end, bestClocks );
  3184. testvar = ( testvar + tst ) * tst;
  3185. tst = rnd.RandomFloat();
  3186. }
  3187. PrintClocks( " idMath::RSqrt( tst )", 1, bestClocks );
  3188. bestClocks = 0;
  3189. tst = rnd.CRandomFloat();
  3190. for ( i = 0; i < NUMTESTS; i++ ) {
  3191. StartRecordTime( start );
  3192. tst = idMath::Sin( tst );
  3193. StopRecordTime( end );
  3194. GetBest( start, end, bestClocks );
  3195. testvar = ( testvar + tst ) * tst;
  3196. tst = rnd.CRandomFloat();
  3197. }
  3198. PrintClocks( " idMath::Sin( tst )", 1, bestClocks );
  3199. bestClocks = 0;
  3200. tst = rnd.CRandomFloat();
  3201. for ( i = 0; i < NUMTESTS; i++ ) {
  3202. StartRecordTime( start );
  3203. tst = idMath::Sin16( tst );
  3204. StopRecordTime( end );
  3205. GetBest( start, end, bestClocks );
  3206. testvar = ( testvar + tst ) * tst;
  3207. tst = rnd.CRandomFloat();
  3208. }
  3209. PrintClocks( " idMath::Sin16( tst )", 1, bestClocks );
  3210. bestClocks = 0;
  3211. tst = rnd.CRandomFloat();
  3212. for ( i = 0; i < NUMTESTS; i++ ) {
  3213. StartRecordTime( start );
  3214. tst = idMath::Cos( tst );
  3215. StopRecordTime( end );
  3216. GetBest( start, end, bestClocks );
  3217. testvar = ( testvar + tst ) * tst;
  3218. tst = rnd.CRandomFloat();
  3219. }
  3220. PrintClocks( " idMath::Cos( tst )", 1, bestClocks );
  3221. bestClocks = 0;
  3222. tst = rnd.CRandomFloat();
  3223. for ( i = 0; i < NUMTESTS; i++ ) {
  3224. StartRecordTime( start );
  3225. tst = idMath::Cos16( tst );
  3226. StopRecordTime( end );
  3227. GetBest( start, end, bestClocks );
  3228. testvar = ( testvar + tst ) * tst;
  3229. tst = rnd.CRandomFloat();
  3230. }
  3231. PrintClocks( " idMath::Cos16( tst )", 1, bestClocks );
  3232. bestClocks = 0;
  3233. tst = rnd.CRandomFloat();
  3234. for ( i = 0; i < NUMTESTS; i++ ) {
  3235. StartRecordTime( start );
  3236. idMath::SinCos( tst, tst, tst2 );
  3237. StopRecordTime( end );
  3238. GetBest( start, end, bestClocks );
  3239. testvar = ( testvar + tst ) * tst;
  3240. tst = rnd.CRandomFloat();
  3241. }
  3242. PrintClocks( " idMath::SinCos( tst )", 1, bestClocks );
  3243. bestClocks = 0;
  3244. tst = rnd.CRandomFloat();
  3245. for ( i = 0; i < NUMTESTS; i++ ) {
  3246. StartRecordTime( start );
  3247. idMath::SinCos16( tst, tst, tst2 );
  3248. StopRecordTime( end );
  3249. GetBest( start, end, bestClocks );
  3250. testvar = ( testvar + tst ) * tst;
  3251. tst = rnd.CRandomFloat();
  3252. }
  3253. PrintClocks( "idMath::SinCos16( tst )", 1, bestClocks );
  3254. bestClocks = 0;
  3255. tst = rnd.CRandomFloat();
  3256. for ( i = 0; i < NUMTESTS; i++ ) {
  3257. StartRecordTime( start );
  3258. tst = idMath::Tan( tst );
  3259. StopRecordTime( end );
  3260. GetBest( start, end, bestClocks );
  3261. testvar = ( testvar + tst ) * tst;
  3262. tst = rnd.CRandomFloat();
  3263. }
  3264. PrintClocks( " idMath::Tan( tst )", 1, bestClocks );
  3265. bestClocks = 0;
  3266. tst = rnd.CRandomFloat();
  3267. for ( i = 0; i < NUMTESTS; i++ ) {
  3268. StartRecordTime( start );
  3269. tst = idMath::Tan16( tst );
  3270. StopRecordTime( end );
  3271. GetBest( start, end, bestClocks );
  3272. testvar = ( testvar + tst ) * tst;
  3273. tst = rnd.CRandomFloat();
  3274. }
  3275. PrintClocks( " idMath::Tan16( tst )", 1, bestClocks );
  3276. bestClocks = 0;
  3277. tst = rnd.CRandomFloat();
  3278. for ( i = 0; i < NUMTESTS; i++ ) {
  3279. StartRecordTime( start );
  3280. tst = idMath::ASin( tst );
  3281. StopRecordTime( end );
  3282. GetBest( start, end, bestClocks );
  3283. testvar = ( testvar + tst ) * tst * ( 1.0f / idMath::PI );
  3284. tst = rnd.CRandomFloat();
  3285. }
  3286. PrintClocks( " idMath::ASin( tst )", 1, bestClocks );
  3287. bestClocks = 0;
  3288. tst = rnd.CRandomFloat();
  3289. for ( i = 0; i < NUMTESTS; i++ ) {
  3290. StartRecordTime( start );
  3291. tst = idMath::ASin16( tst );
  3292. StopRecordTime( end );
  3293. GetBest( start, end, bestClocks );
  3294. testvar = ( testvar + tst ) * tst * ( 1.0f / idMath::PI );
  3295. tst = rnd.CRandomFloat();
  3296. }
  3297. PrintClocks( " idMath::ASin16( tst )", 1, bestClocks );
  3298. bestClocks = 0;
  3299. tst = rnd.CRandomFloat();
  3300. for ( i = 0; i < NUMTESTS; i++ ) {
  3301. StartRecordTime( start );
  3302. tst = idMath::ACos( tst );
  3303. StopRecordTime( end );
  3304. GetBest( start, end, bestClocks );
  3305. testvar = ( testvar + tst ) * tst * ( 1.0f / idMath::PI );
  3306. tst = rnd.CRandomFloat();
  3307. }
  3308. PrintClocks( " idMath::ACos( tst )", 1, bestClocks );
  3309. bestClocks = 0;
  3310. tst = rnd.CRandomFloat();
  3311. for ( i = 0; i < NUMTESTS; i++ ) {
  3312. StartRecordTime( start );
  3313. tst = idMath::ACos16( tst );
  3314. StopRecordTime( end );
  3315. GetBest( start, end, bestClocks );
  3316. testvar = ( testvar + tst ) * tst * ( 1.0f / idMath::PI );
  3317. tst = rnd.CRandomFloat();
  3318. }
  3319. PrintClocks( " idMath::ACos16( tst )", 1, bestClocks );
  3320. bestClocks = 0;
  3321. tst = rnd.CRandomFloat();
  3322. for ( i = 0; i < NUMTESTS; i++ ) {
  3323. StartRecordTime( start );
  3324. tst = idMath::ATan( tst );
  3325. StopRecordTime( end );
  3326. GetBest( start, end, bestClocks );
  3327. testvar = ( testvar + tst ) * tst;
  3328. tst = rnd.CRandomFloat();
  3329. }
  3330. PrintClocks( " idMath::ATan( tst )", 1, bestClocks );
  3331. bestClocks = 0;
  3332. tst = rnd.CRandomFloat();
  3333. for ( i = 0; i < NUMTESTS; i++ ) {
  3334. StartRecordTime( start );
  3335. tst = idMath::ATan16( tst );
  3336. StopRecordTime( end );
  3337. GetBest( start, end, bestClocks );
  3338. testvar = ( testvar + tst ) * tst;
  3339. tst = rnd.CRandomFloat();
  3340. }
  3341. PrintClocks( " idMath::ATan16( tst )", 1, bestClocks );
  3342. bestClocks = 0;
  3343. tst = rnd.CRandomFloat();
  3344. for ( i = 0; i < NUMTESTS; i++ ) {
  3345. StartRecordTime( start );
  3346. tst = idMath::Pow( 2.7f, tst );
  3347. StopRecordTime( end );
  3348. GetBest( start, end, bestClocks );
  3349. testvar = ( testvar + tst ) * tst * 0.1f;
  3350. tst = rnd.CRandomFloat();
  3351. }
  3352. PrintClocks( " idMath::Pow( tst )", 1, bestClocks );
  3353. bestClocks = 0;
  3354. tst = rnd.CRandomFloat();
  3355. for ( i = 0; i < NUMTESTS; i++ ) {
  3356. StartRecordTime( start );
  3357. tst = idMath::Pow16( 2.7f, tst );
  3358. StopRecordTime( end );
  3359. GetBest( start, end, bestClocks );
  3360. testvar = ( testvar + tst ) * tst * 0.1f;
  3361. tst = rnd.CRandomFloat();
  3362. }
  3363. PrintClocks( " idMath::Pow16( tst )", 1, bestClocks );
  3364. bestClocks = 0;
  3365. tst = rnd.CRandomFloat();
  3366. for ( i = 0; i < NUMTESTS; i++ ) {
  3367. StartRecordTime( start );
  3368. tst = idMath::Exp( tst );
  3369. StopRecordTime( end );
  3370. GetBest( start, end, bestClocks );
  3371. testvar = ( testvar + tst ) * tst * 0.1f;
  3372. tst = rnd.CRandomFloat();
  3373. }
  3374. PrintClocks( " idMath::Exp( tst )", 1, bestClocks );
  3375. bestClocks = 0;
  3376. tst = rnd.CRandomFloat();
  3377. for ( i = 0; i < NUMTESTS; i++ ) {
  3378. StartRecordTime( start );
  3379. tst = idMath::Exp16( tst );
  3380. StopRecordTime( end );
  3381. GetBest( start, end, bestClocks );
  3382. testvar = ( testvar + tst ) * tst * 0.1f;
  3383. tst = rnd.CRandomFloat();
  3384. }
  3385. PrintClocks( " idMath::Exp16( tst )", 1, bestClocks );
  3386. bestClocks = 0;
  3387. tst = rnd.CRandomFloat();
  3388. for ( i = 0; i < NUMTESTS; i++ ) {
  3389. tst = fabs( tst ) + 1.0f;
  3390. StartRecordTime( start );
  3391. tst = idMath::Log( tst );
  3392. StopRecordTime( end );
  3393. GetBest( start, end, bestClocks );
  3394. testvar = ( testvar + tst ) * tst;
  3395. tst = rnd.CRandomFloat();
  3396. }
  3397. PrintClocks( " idMath::Log( tst )", 1, bestClocks );
  3398. bestClocks = 0;
  3399. tst = rnd.CRandomFloat();
  3400. for ( i = 0; i < NUMTESTS; i++ ) {
  3401. tst = fabs( tst ) + 1.0f;
  3402. StartRecordTime( start );
  3403. tst = idMath::Log16( tst );
  3404. StopRecordTime( end );
  3405. GetBest( start, end, bestClocks );
  3406. testvar = ( testvar + tst ) * tst;
  3407. tst = rnd.CRandomFloat();
  3408. }
  3409. PrintClocks( " idMath::Log16( tst )", 1, bestClocks );
  3410. idLib::common->Printf( "testvar = %f\n", testvar );
  3411. idMat3 resultMat3;
  3412. idQuat fromQuat, toQuat, resultQuat;
  3413. idCQuat cq;
  3414. idAngles ang;
  3415. fromQuat = idAngles( 30, 45, 0 ).ToQuat();
  3416. toQuat = idAngles( 45, 0, 0 ).ToQuat();
  3417. cq = idAngles( 30, 45, 0 ).ToQuat().ToCQuat();
  3418. ang = idAngles( 30, 40, 50 );
  3419. bestClocks = 0;
  3420. for ( i = 0; i < NUMTESTS; i++ ) {
  3421. StartRecordTime( start );
  3422. resultMat3 = fromQuat.ToMat3();
  3423. StopRecordTime( end );
  3424. GetBest( start, end, bestClocks );
  3425. }
  3426. PrintClocks( " idQuat::ToMat3()", 1, bestClocks );
  3427. bestClocks = 0;
  3428. for ( i = 0; i < NUMTESTS; i++ ) {
  3429. StartRecordTime( start );
  3430. resultQuat.Slerp( fromQuat, toQuat, 0.3f );
  3431. StopRecordTime( end );
  3432. GetBest( start, end, bestClocks );
  3433. }
  3434. PrintClocks( " idQuat::Slerp()", 1, bestClocks );
  3435. bestClocks = 0;
  3436. for ( i = 0; i < NUMTESTS; i++ ) {
  3437. StartRecordTime( start );
  3438. resultQuat = cq.ToQuat();
  3439. StopRecordTime( end );
  3440. GetBest( start, end, bestClocks );
  3441. }
  3442. PrintClocks( " idCQuat::ToQuat()", 1, bestClocks );
  3443. bestClocks = 0;
  3444. for ( i = 0; i < NUMTESTS; i++ ) {
  3445. StartRecordTime( start );
  3446. resultQuat = ang.ToQuat();
  3447. StopRecordTime( end );
  3448. GetBest( start, end, bestClocks );
  3449. }
  3450. PrintClocks( " idAngles::ToQuat()", 1, bestClocks );
  3451. bestClocks = 0;
  3452. for ( i = 0; i < NUMTESTS; i++ ) {
  3453. StartRecordTime( start );
  3454. resultMat3 = ang.ToMat3();
  3455. StopRecordTime( end );
  3456. GetBest( start, end, bestClocks );
  3457. }
  3458. PrintClocks( " idAngles::ToMat3()", 1, bestClocks );
  3459. }
  3460. /*
  3461. ============
  3462. TestNegate
  3463. ============
  3464. */
  3465. // this wasn't previously in the test
  3466. void TestNegate( void ) {
  3467. int i;
  3468. TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
  3469. ALIGN16( float fsrc0[COUNT] );
  3470. ALIGN16( float fsrc1[COUNT] );
  3471. ALIGN16( float fsrc2[COUNT] );
  3472. const char *result;
  3473. idRandom srnd( RANDOM_SEED );
  3474. for ( i = 0; i < COUNT; i++ ) {
  3475. fsrc0[i] = fsrc1[i] = fsrc2[i] = srnd.CRandomFloat() * 10.0f;
  3476. //fsrc1[i] = srnd.CRandomFloat() * 10.0f;
  3477. }
  3478. idLib::common->Printf("====================================\n" );
  3479. bestClocksGeneric = 0;
  3480. for ( i = 0; i < NUMTESTS; i++ ) {
  3481. memcpy( &fsrc1[0], &fsrc0[0], COUNT * sizeof(float) );
  3482. StartRecordTime( start );
  3483. p_generic->Negate16( fsrc1, COUNT );
  3484. StopRecordTime( end );
  3485. GetBest( start, end, bestClocksGeneric );
  3486. }
  3487. PrintClocks( "generic->Negate16( float[] )", COUNT, bestClocksGeneric );
  3488. bestClocksSIMD = 0;
  3489. for ( i = 0; i < NUMTESTS; i++ ) {
  3490. memcpy( &fsrc2[0], &fsrc0[0], COUNT * sizeof(float) );
  3491. StartRecordTime( start );
  3492. p_simd->Negate16( fsrc2, COUNT );
  3493. StopRecordTime( end );
  3494. GetBest( start, end, bestClocksSIMD );
  3495. }
  3496. for ( i = 0; i < COUNT; i++ ) {
  3497. if ( fsrc1[i] != fsrc2[i] ) {
  3498. break;
  3499. }
  3500. }
  3501. result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
  3502. PrintClocks( va( " simd->Negate16( float[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
  3503. }
  3504. /*
  3505. ============
  3506. idSIMD::Test_f
  3507. ============
  3508. */
  3509. void idSIMD::Test_f( const idCmdArgs &args ) {
  3510. #ifdef _WIN32
  3511. SetThreadPriority( GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL );
  3512. #endif /* _WIN32 */
  3513. p_simd = processor;
  3514. p_generic = generic;
  3515. if ( idStr::Length( args.Argv( 1 ) ) != 0 ) {
  3516. cpuid_t cpuid = idLib::sys->GetProcessorId();
  3517. idStr argString = args.Args();
  3518. argString.Replace( " ", "" );
  3519. if ( idStr::Icmp( argString, "MMX" ) == 0 ) {
  3520. if ( !( cpuid & CPUID_MMX ) ) {
  3521. common->Printf( "CPU does not support MMX\n" );
  3522. return;
  3523. }
  3524. p_simd = new idSIMD_MMX;
  3525. } else if ( idStr::Icmp( argString, "3DNow" ) == 0 ) {
  3526. if ( !( cpuid & CPUID_MMX ) || !( cpuid & CPUID_3DNOW ) ) {
  3527. common->Printf( "CPU does not support MMX & 3DNow\n" );
  3528. return;
  3529. }
  3530. p_simd = new idSIMD_3DNow;
  3531. } else if ( idStr::Icmp( argString, "SSE" ) == 0 ) {
  3532. if ( !( cpuid & CPUID_MMX ) || !( cpuid & CPUID_SSE ) ) {
  3533. common->Printf( "CPU does not support MMX & SSE\n" );
  3534. return;
  3535. }
  3536. p_simd = new idSIMD_SSE;
  3537. } else if ( idStr::Icmp( argString, "SSE2" ) == 0 ) {
  3538. if ( !( cpuid & CPUID_MMX ) || !( cpuid & CPUID_SSE ) || !( cpuid & CPUID_SSE2 ) ) {
  3539. common->Printf( "CPU does not support MMX & SSE & SSE2\n" );
  3540. return;
  3541. }
  3542. p_simd = new idSIMD_SSE2;
  3543. } else if ( idStr::Icmp( argString, "SSE3" ) == 0 ) {
  3544. if ( !( cpuid & CPUID_MMX ) || !( cpuid & CPUID_SSE ) || !( cpuid & CPUID_SSE2 ) || !( cpuid & CPUID_SSE3 ) ) {
  3545. common->Printf( "CPU does not support MMX & SSE & SSE2 & SSE3\n" );
  3546. return;
  3547. }
  3548. p_simd = new idSIMD_SSE3();
  3549. } else if ( idStr::Icmp( argString, "AltiVec" ) == 0 ) {
  3550. if ( !( cpuid & CPUID_ALTIVEC ) ) {
  3551. common->Printf( "CPU does not support AltiVec\n" );
  3552. return;
  3553. }
  3554. p_simd = new idSIMD_AltiVec();
  3555. } else {
  3556. common->Printf( "invalid argument, use: MMX, 3DNow, SSE, SSE2, SSE3, AltiVec\n" );
  3557. return;
  3558. }
  3559. }
  3560. idLib::common->SetRefreshOnPrint( true );
  3561. idLib::common->Printf( "using %s for SIMD processing\n", p_simd->GetName() );
  3562. GetBaseClocks();
  3563. TestMath();
  3564. TestAdd();
  3565. TestSub();
  3566. TestMul();
  3567. TestDiv();
  3568. TestMulAdd();
  3569. TestMulSub();
  3570. TestDot();
  3571. TestCompare();
  3572. TestMinMax();
  3573. TestClamp();
  3574. TestMemcpy();
  3575. TestMemset();
  3576. TestNegate();
  3577. TestMatXMultiplyVecX();
  3578. TestMatXMultiplyAddVecX();
  3579. TestMatXTransposeMultiplyVecX();
  3580. TestMatXTransposeMultiplyAddVecX();
  3581. TestMatXMultiplyMatX();
  3582. TestMatXTransposeMultiplyMatX();
  3583. TestMatXLowerTriangularSolve();
  3584. TestMatXLowerTriangularSolveTranspose();
  3585. TestMatXLDLTFactor();
  3586. idLib::common->Printf("====================================\n" );
  3587. TestBlendJoints();
  3588. TestConvertJointQuatsToJointMats();
  3589. TestConvertJointMatsToJointQuats();
  3590. TestTransformJoints();
  3591. TestUntransformJoints();
  3592. TestTransformVerts();
  3593. TestTracePointCull();
  3594. TestDecalPointCull();
  3595. TestOverlayPointCull();
  3596. TestDeriveTriPlanes();
  3597. TestDeriveTangents();
  3598. TestDeriveUnsmoothedTangents();
  3599. TestNormalizeTangents();
  3600. TestGetTextureSpaceLightVectors();
  3601. TestGetSpecularTextureCoords();
  3602. TestCreateShadowCache();
  3603. idLib::common->Printf("====================================\n" );
  3604. TestSoundUpSampling();
  3605. TestSoundMixing();
  3606. idLib::common->SetRefreshOnPrint( false );
  3607. if ( p_simd != processor ) {
  3608. delete p_simd;
  3609. }
  3610. p_simd = NULL;
  3611. p_generic = NULL;
  3612. #ifdef _WIN32
  3613. SetThreadPriority( GetCurrentThread(), THREAD_PRIORITY_NORMAL );
  3614. #endif /* _WIN32 */
  3615. }