12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226 |
- /*
- ===========================================================================
- Doom 3 GPL Source Code
- Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
- This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
- Doom 3 Source Code is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- Doom 3 Source Code is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
- 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.
- 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.
- ===========================================================================
- */
- #include "../precompiled.h"
- #pragma hdrstop
- #include "Simd_Generic.h"
- #include "Simd_MMX.h"
- #include "Simd_3DNow.h"
- #include "Simd_SSE.h"
- #include "Simd_SSE2.h"
- #include "Simd_SSE3.h"
- #include "Simd_AltiVec.h"
- idSIMDProcessor * processor = NULL; // pointer to SIMD processor
- idSIMDProcessor * generic = NULL; // pointer to generic SIMD implementation
- idSIMDProcessor * SIMDProcessor = NULL;
- /*
- ================
- idSIMD::Init
- ================
- */
- void idSIMD::Init( void ) {
- generic = new idSIMD_Generic;
- generic->cpuid = CPUID_GENERIC;
- processor = NULL;
- SIMDProcessor = generic;
- }
- /*
- ============
- idSIMD::InitProcessor
- ============
- */
- void idSIMD::InitProcessor( const char *module, bool forceGeneric ) {
- cpuid_t cpuid;
- idSIMDProcessor *newProcessor;
- cpuid = idLib::sys->GetProcessorId();
- if ( forceGeneric ) {
- newProcessor = generic;
- } else {
- if ( !processor ) {
- if ( ( cpuid & CPUID_ALTIVEC ) ) {
- processor = new idSIMD_AltiVec;
- } else if ( ( cpuid & CPUID_MMX ) && ( cpuid & CPUID_SSE ) && ( cpuid & CPUID_SSE2 ) && ( cpuid & CPUID_SSE3 ) ) {
- processor = new idSIMD_SSE3;
- } else if ( ( cpuid & CPUID_MMX ) && ( cpuid & CPUID_SSE ) && ( cpuid & CPUID_SSE2 ) ) {
- processor = new idSIMD_SSE2;
- } else if ( ( cpuid & CPUID_MMX ) && ( cpuid & CPUID_SSE ) ) {
- processor = new idSIMD_SSE;
- } else if ( ( cpuid & CPUID_MMX ) && ( cpuid & CPUID_3DNOW ) ) {
- processor = new idSIMD_3DNow;
- } else if ( ( cpuid & CPUID_MMX ) ) {
- processor = new idSIMD_MMX;
- } else {
- processor = generic;
- }
- processor->cpuid = cpuid;
- }
- newProcessor = processor;
- }
- if ( newProcessor != SIMDProcessor ) {
- SIMDProcessor = newProcessor;
- idLib::common->Printf( "%s using %s for SIMD processing\n", module, SIMDProcessor->GetName() );
- }
- if ( cpuid & CPUID_FTZ ) {
- idLib::sys->FPU_SetFTZ( true );
- idLib::common->Printf( "enabled Flush-To-Zero mode\n" );
- }
- if ( cpuid & CPUID_DAZ ) {
- idLib::sys->FPU_SetDAZ( true );
- idLib::common->Printf( "enabled Denormals-Are-Zero mode\n" );
- }
- }
- /*
- ================
- idSIMD::Shutdown
- ================
- */
- void idSIMD::Shutdown( void ) {
- if ( processor != generic ) {
- delete processor;
- }
- delete generic;
- generic = NULL;
- processor = NULL;
- SIMDProcessor = NULL;
- }
- //===============================================================
- //
- // Test code
- //
- //===============================================================
- #define COUNT 1024 // data count
- #define NUMTESTS 2048 // number of tests
- #define RANDOM_SEED 1013904223L //((int)idLib::sys->GetClockTicks())
- idSIMDProcessor *p_simd;
- idSIMDProcessor *p_generic;
- long baseClocks = 0;
- #ifdef _WIN32
- #define TIME_TYPE int
- #pragma warning(disable : 4731) // frame pointer register 'ebx' modified by inline assembly code
- long saved_ebx = 0;
- #define StartRecordTime( start ) \
- __asm mov saved_ebx, ebx \
- __asm xor eax, eax \
- __asm cpuid \
- __asm rdtsc \
- __asm mov start, eax \
- __asm xor eax, eax \
- __asm cpuid
- #define StopRecordTime( end ) \
- __asm xor eax, eax \
- __asm cpuid \
- __asm rdtsc \
- __asm mov end, eax \
- __asm mov ebx, saved_ebx \
- __asm xor eax, eax \
- __asm cpuid
- #elif MACOS_X
- #include <stdlib.h>
- #include <unistd.h> // this is for sleep()
- #include <sys/time.h>
- #include <sys/resource.h>
- #include <mach/mach_time.h>
- double ticksPerNanosecond;
- #define TIME_TYPE uint64_t
- #ifdef __MWERKS__ //time_in_millisec is missing
- /*
- .text
- .align 2
- .globl _GetTB
- _GetTB:
- loop:
- mftbu r4 ; load from TBU
- mftb r5 ; load from TBL
- mftbu r6 ; load from TBU
- cmpw r6, r4 ; see if old == new
- bne loop ; if not, carry occured, therefore loop
- stw r4, 0(r3)
- stw r5, 4(r3)
- done:
- blr ; return
- */
- typedef struct {
- unsigned int hi;
- unsigned int lo;
- } U64;
- asm void GetTB(U64 *in)
- {
- nofralloc // suppress prolog
- machine 603 // allows the use of mftb & mftbu functions
-
- loop:
- mftbu r5 // grab the upper time base register (TBU)
- mftb r4 // grab the lower time base register (TBL)
- mftbu r6 // grab the upper time base register (TBU) again
-
- cmpw r6,r5 // see if old TBU == new TBU
- bne- loop // loop if carry occurred (predict branch not taken)
-
- stw r4,4(r3) // store TBL in the low 32 bits of the return value
- stw r5,0(r3) // store TBU in the high 32 bits of the return value
- blr
- }
- double TBToDoubleNano( U64 startTime, U64 stopTime, double ticksPerNanosecond );
- #if __MWERKS__
- asm void GetTB( U64 * );
- #else
- void GetTB( U64 * );
- #endif
- double TBToDoubleNano( U64 startTime, U64 stopTime, double ticksPerNanosecond ) {
- #define K_2POWER32 4294967296.0
- #define TICKS_PER_NANOSECOND 0.025
- double nanoTime;
- U64 diffTime;
- // calc the difference in TB ticks
- diffTime.hi = stopTime.hi - startTime.hi;
- diffTime.lo = stopTime.lo - startTime.lo;
- // convert TB ticks into time
- nanoTime = (double)(diffTime.hi)*((double)K_2POWER32) + (double)(diffTime.lo);
- nanoTime = nanoTime/ticksPerNanosecond;
- return (nanoTime);
- }
- TIME_TYPE time_in_millisec( void ) {
- #define K_2POWER32 4294967296.0
- #define TICKS_PER_NANOSECOND 0.025
- U64 the_time;
- double nanoTime, milliTime;
- GetTB( &the_time );
- // convert TB ticks into time
- nanoTime = (double)(the_time.hi)*((double)K_2POWER32) + (double)(the_time.lo);
- nanoTime = nanoTime/ticksPerNanosecond;
- // nanoseconds are 1 billionth of a second. I want milliseconds
- milliTime = nanoTime * 1000000.0;
- printf( "ticks per nanosec -- %lf\n", ticksPerNanosecond );
- printf( "nanoTime is %lf -- milliTime is %lf -- as int is %i\n", nanoTime, milliTime, (int)milliTime );
- return (int)milliTime;
- }
- #define StartRecordTime( start ) \
- start = time_in_millisec();
- #define StopRecordTime( end ) \
- end = time_in_millisec();
- #else
- #define StartRecordTime( start ) \
- start = mach_absolute_time();
- #define StopRecordTime( end ) \
- end = mach_absolute_time();
- #endif
- #else
- #define TIME_TYPE int
- #define StartRecordTime( start ) \
- start = 0;
- #define StopRecordTime( end ) \
- end = 1;
- #endif
- #define GetBest( start, end, best ) \
- if ( !best || end - start < best ) { \
- best = end - start; \
- }
- /*
- ============
- PrintClocks
- ============
- */
- void PrintClocks( char *string, int dataCount, int clocks, int otherClocks = 0 ) {
- int i;
- idLib::common->Printf( string );
- for ( i = idStr::LengthWithoutColors(string); i < 48; i++ ) {
- idLib::common->Printf(" ");
- }
- clocks -= baseClocks;
- if ( otherClocks && clocks ) {
- otherClocks -= baseClocks;
- int p = (int) ( (float) ( otherClocks - clocks ) * 100.0f / (float) otherClocks );
- idLib::common->Printf( "c = %4d, clcks = %5d, %d%%\n", dataCount, clocks, p );
- } else {
- idLib::common->Printf( "c = %4d, clcks = %5d\n", dataCount, clocks );
- }
- }
- /*
- ============
- GetBaseClocks
- ============
- */
- void GetBaseClocks( void ) {
- int i, start, end, bestClocks;
- bestClocks = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- StopRecordTime( end );
- GetBest( start, end, bestClocks );
- }
- baseClocks = bestClocks;
- }
- /*
- ============
- TestAdd
- ============
- */
- void TestAdd( void ) {
- int i;
- TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
- ALIGN16( float fdst0[COUNT] );
- ALIGN16( float fdst1[COUNT] );
- ALIGN16( float fsrc0[COUNT] );
- ALIGN16( float fsrc1[COUNT] );
- const char *result;
- idRandom srnd( RANDOM_SEED );
- for ( i = 0; i < COUNT; i++ ) {
- fsrc0[i] = srnd.CRandomFloat() * 10.0f;
- fsrc1[i] = srnd.CRandomFloat() * 10.0f;
- }
- idLib::common->Printf("====================================\n" );
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_generic->Add( fdst0, 4.0f, fsrc1, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->Add( float + float[] )", COUNT, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_simd->Add( fdst1, 4.0f, fsrc1, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < COUNT; i++ ) {
- if ( idMath::Fabs( fdst0[i] - fdst1[i] ) > 1e-5f ) {
- break;
- }
- }
- result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->Add( float + float[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_generic->Add( fdst0, fsrc0, fsrc1, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->Add( float[] + float[] )", COUNT, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_simd->Add( fdst1, fsrc0, fsrc1, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < COUNT; i++ ) {
- if ( idMath::Fabs( fdst0[i] - fdst1[i] ) > 1e-5f ) {
- break;
- }
- }
- result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->Add( float[] + float[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
- }
- /*
- ============
- TestSub
- ============
- */
- void TestSub( void ) {
- int i;
- TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
- ALIGN16( float fdst0[COUNT] );
- ALIGN16( float fdst1[COUNT] );
- ALIGN16( float fsrc0[COUNT] );
- ALIGN16( float fsrc1[COUNT] );
- const char *result;
- idRandom srnd( RANDOM_SEED );
- for ( i = 0; i < COUNT; i++ ) {
- fsrc0[i] = srnd.CRandomFloat() * 10.0f;
- fsrc1[i] = srnd.CRandomFloat() * 10.0f;
- }
- idLib::common->Printf("====================================\n" );
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_generic->Sub( fdst0, 4.0f, fsrc1, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->Sub( float + float[] )", COUNT, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_simd->Sub( fdst1, 4.0f, fsrc1, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < COUNT; i++ ) {
- if ( idMath::Fabs( fdst0[i] - fdst1[i] ) > 1e-5f ) {
- break;
- }
- }
- result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->Sub( float + float[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_generic->Sub( fdst0, fsrc0, fsrc1, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->Sub( float[] + float[] )", COUNT, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_simd->Sub( fdst1, fsrc0, fsrc1, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < COUNT; i++ ) {
- if ( idMath::Fabs( fdst0[i] - fdst1[i] ) > 1e-5f ) {
- break;
- }
- }
- result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->Sub( float[] + float[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
- }
- /*
- ============
- TestMul
- ============
- */
- void TestMul( void ) {
- int i;
- TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
- ALIGN16( float fdst0[COUNT] );
- ALIGN16( float fdst1[COUNT] );
- ALIGN16( float fsrc0[COUNT] );
- ALIGN16( float fsrc1[COUNT] );
- const char *result;
- idRandom srnd( RANDOM_SEED );
- for ( i = 0; i < COUNT; i++ ) {
- fsrc0[i] = srnd.CRandomFloat() * 10.0f;
- fsrc1[i] = srnd.CRandomFloat() * 10.0f;
- }
- idLib::common->Printf("====================================\n" );
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_generic->Mul( fdst0, 4.0f, fsrc1, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->Mul( float * float[] )", COUNT, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_simd->Mul( fdst1, 4.0f, fsrc1, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < COUNT; i++ ) {
- if ( idMath::Fabs( fdst0[i] - fdst1[i] ) > 1e-5f ) {
- break;
- }
- }
- result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->Mul( float * float[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_generic->Mul( fdst0, fsrc0, fsrc1, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->Mul( float[] * float[] )", COUNT, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_simd->Mul( fdst1, fsrc0, fsrc1, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < COUNT; i++ ) {
- if ( idMath::Fabs( fdst0[i] - fdst1[i] ) > 1e-5f ) {
- break;
- }
- }
- result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->Mul( float[] * float[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
- }
- /*
- ============
- TestDiv
- ============
- */
- void TestDiv( void ) {
- int i;
- TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
- ALIGN16( float fdst0[COUNT] );
- ALIGN16( float fdst1[COUNT] );
- ALIGN16( float fsrc0[COUNT] );
- ALIGN16( float fsrc1[COUNT] );
- const char *result;
- idRandom srnd( RANDOM_SEED );
- for ( i = 0; i < COUNT; i++ ) {
- fsrc0[i] = srnd.CRandomFloat() * 10.0f;
- do {
- fsrc1[i] = srnd.CRandomFloat() * 10.0f;
- } while( idMath::Fabs( fsrc1[i] ) < 0.1f );
- }
- idLib::common->Printf("====================================\n" );
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_generic->Div( fdst0, 4.0f, fsrc1, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->Div( float * float[] )", COUNT, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_simd->Div( fdst1, 4.0f, fsrc1, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < COUNT; i++ ) {
- if ( idMath::Fabs( fdst0[i] - fdst1[i] ) > 1e-5f ) {
- break;
- }
- }
- result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->Div( float * float[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_generic->Div( fdst0, fsrc0, fsrc1, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->Div( float[] * float[] )", COUNT, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_simd->Div( fdst1, fsrc0, fsrc1, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < COUNT; i++ ) {
- if ( idMath::Fabs( fdst0[i] - fdst1[i] ) > 1e-3f ) {
- break;
- }
- }
- result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->Div( float[] * float[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
- }
- /*
- ============
- TestMulAdd
- ============
- */
- void TestMulAdd( void ) {
- int i, j;
- TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
- ALIGN16( float fdst0[COUNT] );
- ALIGN16( float fdst1[COUNT] );
- ALIGN16( float fsrc0[COUNT] );
- const char *result;
- idRandom srnd( RANDOM_SEED );
- for ( i = 0; i < COUNT; i++ ) {
- fsrc0[i] = srnd.CRandomFloat() * 10.0f;
- }
- idLib::common->Printf("====================================\n" );
- for ( j = 0; j < 50 && j < COUNT; j++ ) {
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- for ( int k = 0; k < COUNT; k++ ) {
- fdst0[k] = k;
- }
- StartRecordTime( start );
- p_generic->MulAdd( fdst0, 0.123f, fsrc0, j );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( va( "generic->MulAdd( float * float[%2d] )", j ), 1, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- for ( int k = 0; k < COUNT; k++ ) {
- fdst1[k] = k;
- }
- StartRecordTime( start );
- p_simd->MulAdd( fdst1, 0.123f, fsrc0, j );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < COUNT; i++ ) {
- if ( idMath::Fabs( fdst0[i] - fdst1[i] ) > 1e-5f ) {
- break;
- }
- }
- result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->MulAdd( float * float[%2d] ) %s", j, result ), 1, bestClocksSIMD, bestClocksGeneric );
- }
- }
- /*
- ============
- TestMulSub
- ============
- */
- void TestMulSub( void ) {
- int i, j;
- TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
- ALIGN16( float fdst0[COUNT] );
- ALIGN16( float fdst1[COUNT] );
- ALIGN16( float fsrc0[COUNT] );
- const char *result;
- idRandom srnd( RANDOM_SEED );
- for ( i = 0; i < COUNT; i++ ) {
- fsrc0[i] = srnd.CRandomFloat() * 10.0f;
- }
- idLib::common->Printf("====================================\n" );
- for ( j = 0; j < 50 && j < COUNT; j++ ) {
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- for ( int k = 0; k < COUNT; k++ ) {
- fdst0[k] = k;
- }
- StartRecordTime( start );
- p_generic->MulSub( fdst0, 0.123f, fsrc0, j );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( va( "generic->MulSub( float * float[%2d] )", j ), 1, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- for ( int k = 0; k < COUNT; k++ ) {
- fdst1[k] = k;
- }
- StartRecordTime( start );
- p_simd->MulSub( fdst1, 0.123f, fsrc0, j );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < COUNT; i++ ) {
- if ( idMath::Fabs( fdst0[i] - fdst1[i] ) > 1e-5f ) {
- break;
- }
- }
- result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->MulSub( float * float[%2d] ) %s", j, result ), 1, bestClocksSIMD, bestClocksGeneric );
- }
- }
- /*
- ============
- TestDot
- ============
- */
- void TestDot( void ) {
- int i, j;
- TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
- ALIGN16( float fdst0[COUNT] );
- ALIGN16( float fdst1[COUNT] );
- ALIGN16( float fsrc0[COUNT] );
- ALIGN16( float fsrc1[COUNT] );
- ALIGN16( idVec3 v3src0[COUNT] );
- ALIGN16( idVec3 v3src1[COUNT] );
- ALIGN16( idVec3 v3constant ) ( 1.0f, 2.0f, 3.0f );
- ALIGN16( idPlane v4src0[COUNT] );
- ALIGN16( idPlane v4constant ) (1.0f, 2.0f, 3.0f, 4.0f);
- ALIGN16( idDrawVert drawVerts[COUNT] );
- const char *result;
- idRandom srnd( RANDOM_SEED );
- for ( i = 0; i < COUNT; i++ ) {
- fsrc0[i] = srnd.CRandomFloat() * 10.0f;
- fsrc1[i] = srnd.CRandomFloat() * 10.0f;
- v3src0[i][0] = srnd.CRandomFloat() * 10.0f;
- v3src0[i][1] = srnd.CRandomFloat() * 10.0f;
- v3src0[i][2] = srnd.CRandomFloat() * 10.0f;
- v3src1[i][0] = srnd.CRandomFloat() * 10.0f;
- v3src1[i][1] = srnd.CRandomFloat() * 10.0f;
- v3src1[i][2] = srnd.CRandomFloat() * 10.0f;
- v4src0[i] = v3src0[i];
- v4src0[i][3] = srnd.CRandomFloat() * 10.0f;
- drawVerts[i].xyz = v3src0[i];
- }
- idLib::common->Printf("====================================\n" );
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_generic->Dot( fdst0, v3constant, v3src0, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->Dot( idVec3 * idVec3[] )", COUNT, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_simd->Dot( fdst1, v3constant, v3src0, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < COUNT; i++ ) {
- if ( idMath::Fabs( fdst0[i] - fdst1[i] ) > 1e-5f ) {
- break;
- }
- }
- result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->Dot( idVec3 * idVec3[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_generic->Dot( fdst0, v3constant, v4src0, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->Dot( idVec3 * idPlane[] )", COUNT, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_simd->Dot( fdst1, v3constant, v4src0, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < COUNT; i++ ) {
- if ( idMath::Fabs( fdst0[i] - fdst1[i] ) > 1e-5f ) {
- break;
- }
- }
- result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->Dot( idVec3 * idPlane[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_generic->Dot( fdst0, v3constant, drawVerts, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->Dot( idVec3 * idDrawVert[] )", COUNT, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_simd->Dot( fdst1, v3constant, drawVerts, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < COUNT; i++ ) {
- if ( idMath::Fabs( fdst0[i] - fdst1[i] ) > 1e-5f ) {
- break;
- }
- }
- result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->Dot( idVec3 * idDrawVert[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_generic->Dot( fdst0, v4constant, v3src0, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->Dot( idPlane * idVec3[] )", COUNT, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_simd->Dot( fdst1, v4constant, v3src0, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < COUNT; i++ ) {
- if ( idMath::Fabs( fdst0[i] - fdst1[i] ) > 1e-5f ) {
- break;
- }
- }
- result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->Dot( idPlane * idVec3[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_generic->Dot( fdst0, v4constant, v4src0, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->Dot( idPlane * idPlane[] )", COUNT, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_simd->Dot( fdst1, v4constant, v4src0, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < COUNT; i++ ) {
- if ( idMath::Fabs( fdst0[i] - fdst1[i] ) > 1e-5f ) {
- break;
- }
- }
- result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->Dot( idPlane * idPlane[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_generic->Dot( fdst0, v4constant, drawVerts, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->Dot( idPlane * idDrawVert[] )", COUNT, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_simd->Dot( fdst1, v4constant, drawVerts, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < COUNT; i++ ) {
- if ( idMath::Fabs( fdst0[i] - fdst1[i] ) > 1e-5f ) {
- break;
- }
- }
- result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->Dot( idPlane * idDrawVert[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_generic->Dot( fdst0, v3src0, v3src1, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->Dot( idVec3[] * idVec3[] )", COUNT, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_simd->Dot( fdst1, v3src0, v3src1, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < COUNT; i++ ) {
- if ( idMath::Fabs( fdst0[i] - fdst1[i] ) > 1e-4f ) {
- break;
- }
- }
- result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->Dot( idVec3[] * idVec3[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
- idLib::common->Printf("====================================\n" );
- float dot1 = 0.0f, dot2 = 0.0f;
- for ( j = 0; j < 50 && j < COUNT; j++ ) {
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_generic->Dot( dot1, fsrc0, fsrc1, j );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( va( "generic->Dot( float[%2d] * float[%2d] )", j, j ), 1, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_simd->Dot( dot2, fsrc0, fsrc1, j );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- result = idMath::Fabs( dot1 - dot2 ) < 1e-4f ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->Dot( float[%2d] * float[%2d] ) %s", j, j, result ), 1, bestClocksSIMD, bestClocksGeneric );
- }
- }
- /*
- ============
- TestCompare
- ============
- */
- void TestCompare( void ) {
- int i;
- TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
- ALIGN16( float fsrc0[COUNT] );
- ALIGN16( byte bytedst[COUNT] );
- ALIGN16( byte bytedst2[COUNT] );
- const char *result;
- idRandom srnd( RANDOM_SEED );
- for ( i = 0; i < COUNT; i++ ) {
- fsrc0[i] = srnd.CRandomFloat() * 10.0f;
- }
- idLib::common->Printf("====================================\n" );
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_generic->CmpGT( bytedst, fsrc0, 0.0f, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->CmpGT( float[] >= float )", COUNT, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_simd->CmpGT( bytedst2, fsrc0, 0.0f, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < COUNT; i++ ) {
- if ( bytedst[i] != bytedst2[i] ) {
- break;
- }
- }
- result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->CmpGT( float[] >= float ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- memset( bytedst, 0, COUNT );
- StartRecordTime( start );
- p_generic->CmpGT( bytedst, 2, fsrc0, 0.0f, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->CmpGT( 2, float[] >= float )", COUNT, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- memset( bytedst2, 0, COUNT );
- StartRecordTime( start );
- p_simd->CmpGT( bytedst2, 2, fsrc0, 0.0f, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < COUNT; i++ ) {
- if ( bytedst[i] != bytedst2[i] ) {
- break;
- }
- }
- result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->CmpGT( 2, float[] >= float ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
- // ======================
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_generic->CmpGE( bytedst, fsrc0, 0.0f, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->CmpGE( float[] >= float )", COUNT, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_simd->CmpGE( bytedst2, fsrc0, 0.0f, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < COUNT; i++ ) {
- if ( bytedst[i] != bytedst2[i] ) {
- break;
- }
- }
- result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->CmpGE( float[] >= float ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- memset( bytedst, 0, COUNT );
- StartRecordTime( start );
- p_generic->CmpGE( bytedst, 2, fsrc0, 0.0f, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->CmpGE( 2, float[] >= float )", COUNT, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- memset( bytedst2, 0, COUNT );
- StartRecordTime( start );
- p_simd->CmpGE( bytedst2, 2, fsrc0, 0.0f, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < COUNT; i++ ) {
- if ( bytedst[i] != bytedst2[i] ) {
- break;
- }
- }
- result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->CmpGE( 2, float[] >= float ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
- // ======================
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_generic->CmpLT( bytedst, fsrc0, 0.0f, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->CmpLT( float[] >= float )", COUNT, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_simd->CmpLT( bytedst2, fsrc0, 0.0f, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < COUNT; i++ ) {
- if ( bytedst[i] != bytedst2[i] ) {
- break;
- }
- }
- result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->CmpLT( float[] >= float ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- memset( bytedst, 0, COUNT );
- StartRecordTime( start );
- p_generic->CmpLT( bytedst, 2, fsrc0, 0.0f, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->CmpLT( 2, float[] >= float )", COUNT, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- memset( bytedst2, 0, COUNT );
- StartRecordTime( start );
- p_simd->CmpLT( bytedst2, 2, fsrc0, 0.0f, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < COUNT; i++ ) {
- if ( bytedst[i] != bytedst2[i] ) {
- break;
- }
- }
- result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->CmpLT( 2, float[] >= float ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
- // ======================
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_generic->CmpLE( bytedst, fsrc0, 0.0f, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->CmpLE( float[] >= float )", COUNT, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_simd->CmpLE( bytedst2, fsrc0, 0.0f, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < COUNT; i++ ) {
- if ( bytedst[i] != bytedst2[i] ) {
- break;
- }
- }
- result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->CmpLE( float[] >= float ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- memset( bytedst, 0, COUNT );
- StartRecordTime( start );
- p_generic->CmpLE( bytedst, 2, fsrc0, 0.0f, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->CmpLE( 2, float[] >= float )", COUNT, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- memset( bytedst2, 0, COUNT );
- StartRecordTime( start );
- p_simd->CmpLE( bytedst2, 2, fsrc0, 0.0f, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < COUNT; i++ ) {
- if ( bytedst[i] != bytedst2[i] ) {
- break;
- }
- }
- result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->CmpLE( 2, float[] >= float ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
- }
- /*
- ============
- TestMinMax
- ============
- */
- void TestMinMax( void ) {
- int i;
- TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
- ALIGN16( float fsrc0[COUNT] );
- ALIGN16( idVec2 v2src0[COUNT] );
- ALIGN16( idVec3 v3src0[COUNT] );
- ALIGN16( idDrawVert drawVerts[COUNT] );
- ALIGN16( int indexes[COUNT] );
- float min = 0.0f, max = 0.0f, min2 = 0.0f, max2 = 0.0f;
- idVec2 v2min, v2max, v2min2, v2max2;
- idVec3 vmin, vmax, vmin2, vmax2;
- const char *result;
- idRandom srnd( RANDOM_SEED );
- for ( i = 0; i < COUNT; i++ ) {
- fsrc0[i] = srnd.CRandomFloat() * 10.0f;
- v2src0[i][0] = srnd.CRandomFloat() * 10.0f;
- v2src0[i][1] = srnd.CRandomFloat() * 10.0f;
- v3src0[i][0] = srnd.CRandomFloat() * 10.0f;
- v3src0[i][1] = srnd.CRandomFloat() * 10.0f;
- v3src0[i][2] = srnd.CRandomFloat() * 10.0f;
- drawVerts[i].xyz = v3src0[i];
- indexes[i] = i;
- }
- idLib::common->Printf("====================================\n" );
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- min = idMath::INFINITY;
- max = -idMath::INFINITY;
- StartRecordTime( start );
- p_generic->MinMax( min, max, fsrc0, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->MinMax( float[] )", COUNT, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_simd->MinMax( min2, max2, fsrc0, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- result = ( min == min2 && max == max2 ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->MinMax( float[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_generic->MinMax( v2min, v2max, v2src0, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->MinMax( idVec2[] )", COUNT, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_simd->MinMax( v2min2, v2max2, v2src0, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- result = ( v2min == v2min2 && v2max == v2max2 ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->MinMax( idVec2[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_generic->MinMax( vmin, vmax, v3src0, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->MinMax( idVec3[] )", COUNT, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_simd->MinMax( vmin2, vmax2, v3src0, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- result = ( vmin == vmin2 && vmax == vmax2 ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->MinMax( idVec3[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_generic->MinMax( vmin, vmax, drawVerts, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->MinMax( idDrawVert[] )", COUNT, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_simd->MinMax( vmin2, vmax2, drawVerts, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- result = ( vmin == vmin2 && vmax == vmax2 ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->MinMax( idDrawVert[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_generic->MinMax( vmin, vmax, drawVerts, indexes, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->MinMax( idDrawVert[], indexes[] )", COUNT, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_simd->MinMax( vmin2, vmax2, drawVerts, indexes, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- result = ( vmin == vmin2 && vmax == vmax2 ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->MinMax( idDrawVert[], indexes[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
- }
- /*
- ============
- TestClamp
- ============
- */
- void TestClamp( void ) {
- int i;
- TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
- ALIGN16( float fdst0[COUNT] );
- ALIGN16( float fdst1[COUNT] );
- ALIGN16( float fsrc0[COUNT] );
- const char *result;
- idRandom srnd( RANDOM_SEED );
- for ( i = 0; i < COUNT; i++ ) {
- fsrc0[i] = srnd.CRandomFloat() * 10.0f;
- }
- idLib::common->Printf("====================================\n" );
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_generic->Clamp( fdst0, fsrc0, -1.0f, 1.0f, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->Clamp( float[] )", COUNT, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_simd->Clamp( fdst1, fsrc0, -1.0f, 1.0f, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < COUNT; i++ ) {
- if ( fdst0[i] != fdst1[i] ) {
- break;
- }
- }
- result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->Clamp( float[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_generic->ClampMin( fdst0, fsrc0, -1.0f, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->ClampMin( float[] )", COUNT, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_simd->ClampMin( fdst1, fsrc0, -1.0f, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < COUNT; i++ ) {
- if ( fdst0[i] != fdst1[i] ) {
- break;
- }
- }
- result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->ClampMin( float[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_generic->ClampMax( fdst0, fsrc0, 1.0f, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->ClampMax( float[] )", COUNT, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_simd->ClampMax( fdst1, fsrc0, 1.0f, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < COUNT; i++ ) {
- if ( fdst0[i] != fdst1[i] ) {
- break;
- }
- }
- result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->ClampMax( float[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
- }
- /*
- ============
- TestMemcpy
- ============
- */
- void TestMemcpy( void ) {
- int i, j;
- byte test0[8192];
- byte test1[8192];
- idRandom random( RANDOM_SEED );
- idLib::common->Printf("====================================\n" );
- for ( i = 5; i < 8192; i += 31 ) {
- for ( j = 0; j < i; j++ ) {
- test0[j] = random.RandomInt( 255 );
- }
- p_simd->Memcpy( test1, test0, 8192 );
- for ( j = 0; j < i; j++ ) {
- if ( test1[j] != test0[j] ) {
- idLib::common->Printf( " simd->Memcpy() "S_COLOR_RED"X\n" );
- return;
- }
- }
- }
- idLib::common->Printf( " simd->Memcpy() ok\n" );
- }
- /*
- ============
- TestMemset
- ============
- */
- void TestMemset( void ) {
- int i, j, k;
- byte test[8192];
- for ( i = 0; i < 8192; i++ ) {
- test[i] = 0;
- }
- for ( i = 5; i < 8192; i += 31 ) {
- for ( j = -1; j <= 1; j++ ) {
- p_simd->Memset( test, j, i );
- for ( k = 0; k < i; k++ ) {
- if ( test[k] != (byte)j ) {
- idLib::common->Printf( " simd->Memset() "S_COLOR_RED"X\n" );
- return;
- }
- }
- }
- }
- idLib::common->Printf( " simd->Memset() ok\n" );
- }
- #define MATX_SIMD_EPSILON 1e-5f
- /*
- ============
- TestMatXMultiplyVecX
- ============
- */
- void TestMatXMultiplyVecX( void ) {
- int i, j;
- TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
- const char *result;
- idMatX mat;
- idVecX src(6);
- idVecX dst(6);
- idVecX tst(6);
- src[0] = 1.0f;
- src[1] = 2.0f;
- src[2] = 3.0f;
- src[3] = 4.0f;
- src[4] = 5.0f;
- src[5] = 6.0f;
- idLib::common->Printf("================= NxN * Nx1 ===================\n" );
- for ( i = 1; i <= 6; i++ ) {
- mat.Random( i, i, RANDOM_SEED, -10.0f, 10.0f );
- bestClocksGeneric = 0;
- for ( j = 0; j < NUMTESTS; j++ ) {
- dst.Zero();
- StartRecordTime( start );
- p_generic->MatX_MultiplyVecX( dst, mat, src );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- tst = dst;
- PrintClocks( va( "generic->MatX_MultiplyVecX %dx%d*%dx1", i, i, i ), 1, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( j = 0; j < NUMTESTS; j++ ) {
- dst.Zero();
- StartRecordTime( start );
- p_simd->MatX_MultiplyVecX( dst, mat, src );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- result = dst.Compare( tst, MATX_SIMD_EPSILON ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->MatX_MultiplyVecX %dx%d*%dx1 %s", i, i, i, result ), 1, bestClocksSIMD, bestClocksGeneric );
- }
- idLib::common->Printf("================= Nx6 * 6x1 ===================\n" );
- for ( i = 1; i <= 6; i++ ) {
- mat.Random( i, 6, RANDOM_SEED, -10.0f, 10.0f );
- bestClocksGeneric = 0;
- for ( j = 0; j < NUMTESTS; j++ ) {
- dst.Zero();
- StartRecordTime( start );
- p_generic->MatX_MultiplyVecX( dst, mat, src );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- tst = dst;
- PrintClocks( va( "generic->MatX_MultiplyVecX %dx6*6x1", i ), 1, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( j = 0; j < NUMTESTS; j++ ) {
- dst.Zero();
- StartRecordTime( start );
- p_simd->MatX_MultiplyVecX( dst, mat, src );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- result = dst.Compare( tst, MATX_SIMD_EPSILON ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->MatX_MultiplyVecX %dx6*6x1 %s", i, result ), 1, bestClocksSIMD, bestClocksGeneric );
- }
- idLib::common->Printf("================= 6xN * Nx1 ===================\n" );
- for ( i = 1; i <= 6; i++ ) {
- mat.Random( 6, i, RANDOM_SEED, -10.0f, 10.0f );
- bestClocksGeneric = 0;
- for ( j = 0; j < NUMTESTS; j++ ) {
- dst.Zero();
- StartRecordTime( start );
- p_generic->MatX_MultiplyVecX( dst, mat, src );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- tst = dst;
- PrintClocks( va( "generic->MatX_MultiplyVecX 6x%d*%dx1", i, i ), 1, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( j = 0; j < NUMTESTS; j++ ) {
- StartRecordTime( start );
- p_simd->MatX_MultiplyVecX( dst, mat, src );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- result = dst.Compare( tst, MATX_SIMD_EPSILON ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->MatX_MultiplyVecX 6x%d*%dx1 %s", i, i, result ), 1, bestClocksSIMD, bestClocksGeneric );
- }
- }
- /*
- ============
- TestMatXMultiplyAddVecX
- ============
- */
- void TestMatXMultiplyAddVecX( void ) {
- int i, j;
- TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
- const char *result;
- idMatX mat;
- idVecX src(6);
- idVecX dst(6);
- idVecX tst(6);
- src[0] = 1.0f;
- src[1] = 2.0f;
- src[2] = 3.0f;
- src[3] = 4.0f;
- src[4] = 5.0f;
- src[5] = 6.0f;
- idLib::common->Printf("================= NxN * Nx1 ===================\n" );
- for ( i = 1; i <= 6; i++ ) {
- mat.Random( i, i, RANDOM_SEED, -10.0f, 10.0f );
- bestClocksGeneric = 0;
- for ( j = 0; j < NUMTESTS; j++ ) {
- dst.Zero();
- StartRecordTime( start );
- p_generic->MatX_MultiplyAddVecX( dst, mat, src );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- tst = dst;
- PrintClocks( va( "generic->MatX_MultiplyAddVecX %dx%d*%dx1", i, i, i ), 1, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( j = 0; j < NUMTESTS; j++ ) {
- dst.Zero();
- StartRecordTime( start );
- p_simd->MatX_MultiplyAddVecX( dst, mat, src );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- result = dst.Compare( tst, MATX_SIMD_EPSILON ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->MatX_MultiplyAddVecX %dx%d*%dx1 %s", i, i, i, result ), 1, bestClocksSIMD, bestClocksGeneric );
- }
- idLib::common->Printf("================= Nx6 * 6x1 ===================\n" );
- for ( i = 1; i <= 6; i++ ) {
- mat.Random( i, 6, RANDOM_SEED, -10.0f, 10.0f );
- bestClocksGeneric = 0;
- for ( j = 0; j < NUMTESTS; j++ ) {
- dst.Zero();
- StartRecordTime( start );
- p_generic->MatX_MultiplyAddVecX( dst, mat, src );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- tst = dst;
- PrintClocks( va( "generic->MatX_MultiplyAddVecX %dx6*6x1", i ), 1, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( j = 0; j < NUMTESTS; j++ ) {
- dst.Zero();
- StartRecordTime( start );
- p_simd->MatX_MultiplyAddVecX( dst, mat, src );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- result = dst.Compare( tst, MATX_SIMD_EPSILON ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->MatX_MultiplyAddVecX %dx6*6x1 %s", i, result ), 1, bestClocksSIMD, bestClocksGeneric );
- }
- idLib::common->Printf("================= 6xN * Nx1 ===================\n" );
- for ( i = 1; i <= 6; i++ ) {
- mat.Random( 6, i, RANDOM_SEED, -10.0f, 10.0f );
- bestClocksGeneric = 0;
- for ( j = 0; j < NUMTESTS; j++ ) {
- dst.Zero();
- StartRecordTime( start );
- p_generic->MatX_MultiplyAddVecX( dst, mat, src );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- tst = dst;
- PrintClocks( va( "generic->MatX_MultiplyAddVecX 6x%d*%dx1", i, i ), 1, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( j = 0; j < NUMTESTS; j++ ) {
- dst.Zero();
- StartRecordTime( start );
- p_simd->MatX_MultiplyAddVecX( dst, mat, src );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- result = dst.Compare( tst, MATX_SIMD_EPSILON ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->MatX_MultiplyAddVecX 6x%d*%dx1 %s", i, i, result ), 1, bestClocksSIMD, bestClocksGeneric );
- }
- }
- /*
- ============
- TestMatXTransposeMultiplyVecX
- ============
- */
- void TestMatXTransposeMultiplyVecX( void ) {
- int i, j;
- TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
- const char *result;
- idMatX mat;
- idVecX src(6);
- idVecX dst(6);
- idVecX tst(6);
- src[0] = 1.0f;
- src[1] = 2.0f;
- src[2] = 3.0f;
- src[3] = 4.0f;
- src[4] = 5.0f;
- src[5] = 6.0f;
- idLib::common->Printf("================= Nx6 * Nx1 ===================\n" );
- for ( i = 1; i <= 6; i++ ) {
- mat.Random( i, 6, RANDOM_SEED, -10.0f, 10.0f );
- bestClocksGeneric = 0;
- for ( j = 0; j < NUMTESTS; j++ ) {
- dst.Zero();
- StartRecordTime( start );
- p_generic->MatX_TransposeMultiplyVecX( dst, mat, src );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- tst = dst;
- PrintClocks( va( "generic->MatX_TransposeMulVecX %dx6*%dx1", i, i ), 1, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( j = 0; j < NUMTESTS; j++ ) {
- dst.Zero();
- StartRecordTime( start );
- p_simd->MatX_TransposeMultiplyVecX( dst, mat, src );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- result = dst.Compare( tst, MATX_SIMD_EPSILON ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->MatX_TransposeMulVecX %dx6*%dx1 %s", i, i, result ), 1, bestClocksSIMD, bestClocksGeneric );
- }
- idLib::common->Printf("================= 6xN * 6x1 ===================\n" );
- for ( i = 1; i <= 6; i++ ) {
- mat.Random( 6, i, RANDOM_SEED, -10.0f, 10.0f );
- bestClocksGeneric = 0;
- for ( j = 0; j < NUMTESTS; j++ ) {
- dst.Zero();
- StartRecordTime( start );
- p_generic->MatX_TransposeMultiplyVecX( dst, mat, src );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- tst = dst;
- PrintClocks( va( "generic->MatX_TransposeMulVecX 6x%d*6x1", i ), 1, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( j = 0; j < NUMTESTS; j++ ) {
- dst.Zero();
- StartRecordTime( start );
- p_simd->MatX_TransposeMultiplyVecX( dst, mat, src );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- result = dst.Compare( tst, MATX_SIMD_EPSILON ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->MatX_TransposeMulVecX 6x%d*6x1 %s", i, result ), 1, bestClocksSIMD, bestClocksGeneric );
- }
- }
- /*
- ============
- TestMatXTransposeMultiplyAddVecX
- ============
- */
- void TestMatXTransposeMultiplyAddVecX( void ) {
- int i, j;
- TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
- const char *result;
- idMatX mat;
- idVecX src(6);
- idVecX dst(6);
- idVecX tst(6);
- src[0] = 1.0f;
- src[1] = 2.0f;
- src[2] = 3.0f;
- src[3] = 4.0f;
- src[4] = 5.0f;
- src[5] = 6.0f;
- idLib::common->Printf("================= Nx6 * Nx1 ===================\n" );
- for ( i = 1; i <= 6; i++ ) {
- mat.Random( i, 6, RANDOM_SEED, -10.0f, 10.0f );
- bestClocksGeneric = 0;
- for ( j = 0; j < NUMTESTS; j++ ) {
- dst.Zero();
- StartRecordTime( start );
- p_generic->MatX_TransposeMultiplyAddVecX( dst, mat, src );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- tst = dst;
- PrintClocks( va( "generic->MatX_TransposeMulAddVecX %dx6*%dx1", i, i ), 1, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( j = 0; j < NUMTESTS; j++ ) {
- dst.Zero();
- StartRecordTime( start );
- p_simd->MatX_TransposeMultiplyAddVecX( dst, mat, src );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- result = dst.Compare( tst, MATX_SIMD_EPSILON ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->MatX_TransposeMulAddVecX %dx6*%dx1 %s", i, i, result ), 1, bestClocksSIMD, bestClocksGeneric );
- }
- idLib::common->Printf("================= 6xN * 6x1 ===================\n" );
- for ( i = 1; i <= 6; i++ ) {
- mat.Random( 6, i, RANDOM_SEED, -10.0f, 10.0f );
- bestClocksGeneric = 0;
- for ( j = 0; j < NUMTESTS; j++ ) {
- dst.Zero();
- StartRecordTime( start );
- p_generic->MatX_TransposeMultiplyAddVecX( dst, mat, src );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- tst = dst;
- PrintClocks( va( "generic->MatX_TransposeMulAddVecX 6x%d*6x1", i ), 1, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( j = 0; j < NUMTESTS; j++ ) {
- dst.Zero();
- StartRecordTime( start );
- p_simd->MatX_TransposeMultiplyAddVecX( dst, mat, src );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- result = dst.Compare( tst, MATX_SIMD_EPSILON ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->MatX_TransposeMulAddVecX 6x%d*6x1 %s", i, result ), 1, bestClocksSIMD, bestClocksGeneric );
- }
- }
- /*
- ============
- TestMatXMultiplyMatX
- ============
- */
- #define TEST_VALUE_RANGE 10.0f
- #define MATX_MATX_SIMD_EPSILON 1e-4f
- void TestMatXMultiplyMatX( void ) {
- int i, j;
- TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
- const char *result;
- idMatX m1, m2, dst, tst;
- idLib::common->Printf("================= NxN * Nx6 ===================\n" );
- // NxN * Nx6
- for ( i = 1; i <= 5; i++ ) {
- m1.Random( i, i, RANDOM_SEED, -TEST_VALUE_RANGE, TEST_VALUE_RANGE );
- m2.Random( i, 6, RANDOM_SEED, -TEST_VALUE_RANGE, TEST_VALUE_RANGE );
- dst.SetSize( i, 6 );
- bestClocksGeneric = 0;
- for ( j = 0; j < NUMTESTS; j++ ) {
- StartRecordTime( start );
- p_generic->MatX_MultiplyMatX( dst, m1, m2 );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- tst = dst;
- PrintClocks( va( "generic->MatX_MultiplyMatX %dx%d*%dx6", i, i, i ), 1, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( j = 0; j < NUMTESTS; j++ ) {
- StartRecordTime( start );
- p_simd->MatX_MultiplyMatX( dst, m1, m2 );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- result = dst.Compare( tst, MATX_MATX_SIMD_EPSILON ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->MatX_MultiplyMatX %dx%d*%dx6 %s", i, i, i, result ), 1, bestClocksSIMD, bestClocksGeneric );
- }
- idLib::common->Printf("================= 6xN * Nx6 ===================\n" );
- // 6xN * Nx6
- for ( i = 1; i <= 5; i++ ) {
- m1.Random( 6, i, RANDOM_SEED, -TEST_VALUE_RANGE, TEST_VALUE_RANGE );
- m2.Random( i, 6, RANDOM_SEED, -TEST_VALUE_RANGE, TEST_VALUE_RANGE );
- dst.SetSize( 6, 6 );
- bestClocksGeneric = 0;
- for ( j = 0; j < NUMTESTS; j++ ) {
- StartRecordTime( start );
- p_generic->MatX_MultiplyMatX( dst, m1, m2 );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- tst = dst;
- PrintClocks( va( "generic->MatX_MultiplyMatX 6x%d*%dx6", i, i ), 1, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( j = 0; j < NUMTESTS; j++ ) {
- StartRecordTime( start );
- p_simd->MatX_MultiplyMatX( dst, m1, m2 );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- result = dst.Compare( tst, MATX_MATX_SIMD_EPSILON ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->MatX_MultiplyMatX 6x%d*%dx6 %s", i, i, result ), 1, bestClocksSIMD, bestClocksGeneric );
- }
- idLib::common->Printf("================= Nx6 * 6xN ===================\n" );
- // Nx6 * 6xN
- for ( i = 1; i <= 5; i++ ) {
- m1.Random( i, 6, RANDOM_SEED, -TEST_VALUE_RANGE, TEST_VALUE_RANGE );
- m2.Random( 6, i, RANDOM_SEED, -TEST_VALUE_RANGE, TEST_VALUE_RANGE );
- dst.SetSize( i, i );
- bestClocksGeneric = 0;
- for ( j = 0; j < NUMTESTS; j++ ) {
- StartRecordTime( start );
- p_generic->MatX_MultiplyMatX( dst, m1, m2 );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- tst = dst;
- PrintClocks( va( "generic->MatX_MultiplyMatX %dx6*6x%d", i, i ), 1, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( j = 0; j < NUMTESTS; j++ ) {
- StartRecordTime( start );
- p_simd->MatX_MultiplyMatX( dst, m1, m2 );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- result = dst.Compare( tst, MATX_MATX_SIMD_EPSILON ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->MatX_MultiplyMatX %dx6*6x%d %s", i, i, result ), 1, bestClocksSIMD, bestClocksGeneric );
- }
- idLib::common->Printf("================= 6x6 * 6xN ===================\n" );
- // 6x6 * 6xN
- for ( i = 1; i <= 6; i++ ) {
- m1.Random( 6, 6, RANDOM_SEED, -TEST_VALUE_RANGE, TEST_VALUE_RANGE );
- m2.Random( 6, i, RANDOM_SEED, -TEST_VALUE_RANGE, TEST_VALUE_RANGE );
- dst.SetSize( 6, i );
- bestClocksGeneric = 0;
- for ( j = 0; j < NUMTESTS; j++ ) {
- StartRecordTime( start );
- p_generic->MatX_MultiplyMatX( dst, m1, m2 );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- tst = dst;
- PrintClocks( va( "generic->MatX_MultiplyMatX 6x6*6x%d", i ), 1, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( j = 0; j < NUMTESTS; j++ ) {
- StartRecordTime( start );
- p_simd->MatX_MultiplyMatX( dst, m1, m2 );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- result = dst.Compare( tst, MATX_MATX_SIMD_EPSILON ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->MatX_MultiplyMatX 6x6*6x%d %s", i, result ), 1, bestClocksSIMD, bestClocksGeneric );
- }
- }
- /*
- ============
- TestMatXTransposeMultiplyMatX
- ============
- */
- void TestMatXTransposeMultiplyMatX( void ) {
- int i, j;
- TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
- const char *result;
- idMatX m1, m2, dst, tst;
- idLib::common->Printf("================= Nx6 * NxN ===================\n" );
- // Nx6 * NxN
- for ( i = 1; i <= 5; i++ ) {
- m1.Random( i, 6, RANDOM_SEED, -TEST_VALUE_RANGE, TEST_VALUE_RANGE );
- m2.Random( i, i, RANDOM_SEED, -TEST_VALUE_RANGE, TEST_VALUE_RANGE );
- dst.SetSize( 6, i );
- bestClocksGeneric = 0;
- for ( j = 0; j < NUMTESTS; j++ ) {
- StartRecordTime( start );
- p_generic->MatX_TransposeMultiplyMatX( dst, m1, m2 );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- tst = dst;
- PrintClocks( va( "generic->MatX_TransMultiplyMatX %dx6*%dx%d", i, i, i ), 1, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( j = 0; j < NUMTESTS; j++ ) {
- StartRecordTime( start );
- p_simd->MatX_TransposeMultiplyMatX( dst, m1, m2 );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- result = dst.Compare( tst, MATX_MATX_SIMD_EPSILON ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->MatX_TransMultiplyMatX %dx6*%dx%d %s", i, i, i, result ), 1, bestClocksSIMD, bestClocksGeneric );
- }
- idLib::common->Printf("================= 6xN * 6x6 ===================\n" );
- // 6xN * 6x6
- for ( i = 1; i <= 6; i++ ) {
- m1.Random( 6, i, RANDOM_SEED, -TEST_VALUE_RANGE, TEST_VALUE_RANGE );
- m2.Random( 6, 6, RANDOM_SEED, -TEST_VALUE_RANGE, TEST_VALUE_RANGE );
- dst.SetSize( i, 6 );
- bestClocksGeneric = 0;
- for ( j = 0; j < NUMTESTS; j++ ) {
- StartRecordTime( start );
- p_generic->MatX_TransposeMultiplyMatX( dst, m1, m2 );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- tst = dst;
- PrintClocks( va( "generic->MatX_TransMultiplyMatX 6x%d*6x6", i ), 1, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( j = 0; j < NUMTESTS; j++ ) {
- StartRecordTime( start );
- p_simd->MatX_TransposeMultiplyMatX( dst, m1, m2 );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- result = dst.Compare( tst, MATX_MATX_SIMD_EPSILON ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->MatX_TransMultiplyMatX 6x%d*6x6 %s", i, result ), 1, bestClocksSIMD, bestClocksGeneric );
- }
- }
- #define MATX_LTS_SIMD_EPSILON 1.0f
- #define MATX_LTS_SOLVE_SIZE 100
- /*
- ============
- TestMatXLowerTriangularSolve
- ============
- */
- void TestMatXLowerTriangularSolve( void ) {
- int i, j;
- TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
- const char *result;
- idMatX L;
- idVecX x, b, tst;
- idLib::common->Printf("====================================\n" );
- L.Random( MATX_LTS_SOLVE_SIZE, MATX_LTS_SOLVE_SIZE, 0, -1.0f, 1.0f );
- x.SetSize( MATX_LTS_SOLVE_SIZE );
- b.Random( MATX_LTS_SOLVE_SIZE, 0, -1.0f, 1.0f );
- for ( i = 1; i < MATX_LTS_SOLVE_SIZE; i++ ) {
- x.Zero( i );
- bestClocksGeneric = 0;
- for ( j = 0; j < NUMTESTS; j++ ) {
- StartRecordTime( start );
- p_generic->MatX_LowerTriangularSolve( L, x.ToFloatPtr(), b.ToFloatPtr(), i );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- tst = x;
- x.Zero();
- PrintClocks( va( "generic->MatX_LowerTriangularSolve %dx%d", i, i ), 1, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( j = 0; j < NUMTESTS; j++ ) {
- StartRecordTime( start );
- p_simd->MatX_LowerTriangularSolve( L, x.ToFloatPtr(), b.ToFloatPtr(), i );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- result = x.Compare( tst, MATX_LTS_SIMD_EPSILON ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->MatX_LowerTriangularSolve %dx%d %s", i, i, result ), 1, bestClocksSIMD, bestClocksGeneric );
- }
- }
- /*
- ============
- TestMatXLowerTriangularSolveTranspose
- ============
- */
- void TestMatXLowerTriangularSolveTranspose( void ) {
- int i, j;
- TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
- const char *result;
- idMatX L;
- idVecX x, b, tst;
- idLib::common->Printf("====================================\n" );
- L.Random( MATX_LTS_SOLVE_SIZE, MATX_LTS_SOLVE_SIZE, 0, -1.0f, 1.0f );
- x.SetSize( MATX_LTS_SOLVE_SIZE );
- b.Random( MATX_LTS_SOLVE_SIZE, 0, -1.0f, 1.0f );
- for ( i = 1; i < MATX_LTS_SOLVE_SIZE; i++ ) {
- x.Zero( i );
- bestClocksGeneric = 0;
- for ( j = 0; j < NUMTESTS; j++ ) {
- StartRecordTime( start );
- p_generic->MatX_LowerTriangularSolveTranspose( L, x.ToFloatPtr(), b.ToFloatPtr(), i );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- tst = x;
- x.Zero();
- PrintClocks( va( "generic->MatX_LowerTriangularSolveT %dx%d", i, i ), 1, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( j = 0; j < NUMTESTS; j++ ) {
- StartRecordTime( start );
- p_simd->MatX_LowerTriangularSolveTranspose( L, x.ToFloatPtr(), b.ToFloatPtr(), i );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- result = x.Compare( tst, MATX_LTS_SIMD_EPSILON ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->MatX_LowerTriangularSolveT %dx%d %s", i, i, result ), 1, bestClocksSIMD, bestClocksGeneric );
- }
- }
- #define MATX_LDLT_SIMD_EPSILON 0.1f
- #define MATX_LDLT_FACTOR_SOLVE_SIZE 64
- /*
- ============
- TestMatXLDLTFactor
- ============
- */
- void TestMatXLDLTFactor( void ) {
- int i, j;
- TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
- const char *result;
- idMatX src, original, mat1, mat2;
- idVecX invDiag1, invDiag2;
- idLib::common->Printf("====================================\n" );
- original.SetSize( MATX_LDLT_FACTOR_SOLVE_SIZE, MATX_LDLT_FACTOR_SOLVE_SIZE );
- src.Random( MATX_LDLT_FACTOR_SOLVE_SIZE, MATX_LDLT_FACTOR_SOLVE_SIZE, 0, -1.0f, 1.0f );
- src.TransposeMultiply( original, src );
- for ( i = 1; i < MATX_LDLT_FACTOR_SOLVE_SIZE; i++ ) {
- bestClocksGeneric = 0;
- for ( j = 0; j < NUMTESTS; j++ ) {
- mat1 = original;
- invDiag1.Zero( MATX_LDLT_FACTOR_SOLVE_SIZE );
- StartRecordTime( start );
- p_generic->MatX_LDLTFactor( mat1, invDiag1, i );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( va( "generic->MatX_LDLTFactor %dx%d", i, i ), 1, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( j = 0; j < NUMTESTS; j++ ) {
- mat2 = original;
- invDiag2.Zero( MATX_LDLT_FACTOR_SOLVE_SIZE );
- StartRecordTime( start );
- p_simd->MatX_LDLTFactor( mat2, invDiag2, i );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- result = mat1.Compare( mat2, MATX_LDLT_SIMD_EPSILON ) && invDiag1.Compare( invDiag2, MATX_LDLT_SIMD_EPSILON ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->MatX_LDLTFactor %dx%d %s", i, i, result ), 1, bestClocksSIMD, bestClocksGeneric );
- }
- }
- /*
- ============
- TestBlendJoints
- ============
- */
- void TestBlendJoints( void ) {
- int i, j;
- TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
- ALIGN16( idJointQuat baseJoints[COUNT] );
- ALIGN16( idJointQuat joints1[COUNT] );
- ALIGN16( idJointQuat joints2[COUNT] );
- ALIGN16( idJointQuat blendJoints[COUNT] );
- ALIGN16( int index[COUNT] );
- float lerp = 0.3f;
- const char *result;
- idRandom srnd( RANDOM_SEED );
- for ( i = 0; i < COUNT; i++ ) {
- idAngles angles;
- angles[0] = srnd.CRandomFloat() * 180.0f;
- angles[1] = srnd.CRandomFloat() * 180.0f;
- angles[2] = srnd.CRandomFloat() * 180.0f;
- baseJoints[i].q = angles.ToQuat();
- baseJoints[i].t[0] = srnd.CRandomFloat() * 10.0f;
- baseJoints[i].t[1] = srnd.CRandomFloat() * 10.0f;
- baseJoints[i].t[2] = srnd.CRandomFloat() * 10.0f;
- angles[0] = srnd.CRandomFloat() * 180.0f;
- angles[1] = srnd.CRandomFloat() * 180.0f;
- angles[2] = srnd.CRandomFloat() * 180.0f;
- blendJoints[i].q = angles.ToQuat();
- blendJoints[i].t[0] = srnd.CRandomFloat() * 10.0f;
- blendJoints[i].t[1] = srnd.CRandomFloat() * 10.0f;
- blendJoints[i].t[2] = srnd.CRandomFloat() * 10.0f;
- index[i] = i;
- }
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- for ( j = 0; j < COUNT; j++ ) {
- joints1[j] = baseJoints[j];
- }
- StartRecordTime( start );
- p_generic->BlendJoints( joints1, blendJoints, lerp, index, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->BlendJoints()", COUNT, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- for ( j = 0; j < COUNT; j++ ) {
- joints2[j] = baseJoints[j];
- }
- StartRecordTime( start );
- p_simd->BlendJoints( joints2, blendJoints, lerp, index, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < COUNT; i++ ) {
- if ( !joints1[i].t.Compare( joints2[i].t, 1e-3f ) ) {
- break;
- }
- if ( !joints1[i].q.Compare( joints2[i].q, 1e-2f ) ) {
- break;
- }
- }
- result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->BlendJoints() %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
- }
- /*
- ============
- TestConvertJointQuatsToJointMats
- ============
- */
- void TestConvertJointQuatsToJointMats( void ) {
- int i;
- TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
- ALIGN16( idJointQuat baseJoints[COUNT] );
- ALIGN16( idJointMat joints1[COUNT] );
- ALIGN16( idJointMat joints2[COUNT] );
- const char *result;
- idRandom srnd( RANDOM_SEED );
- for ( i = 0; i < COUNT; i++ ) {
- idAngles angles;
- angles[0] = srnd.CRandomFloat() * 180.0f;
- angles[1] = srnd.CRandomFloat() * 180.0f;
- angles[2] = srnd.CRandomFloat() * 180.0f;
- baseJoints[i].q = angles.ToQuat();
- baseJoints[i].t[0] = srnd.CRandomFloat() * 10.0f;
- baseJoints[i].t[1] = srnd.CRandomFloat() * 10.0f;
- baseJoints[i].t[2] = srnd.CRandomFloat() * 10.0f;
- }
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_generic->ConvertJointQuatsToJointMats( joints1, baseJoints, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->ConvertJointQuatsToJointMats()", COUNT, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_simd->ConvertJointQuatsToJointMats( joints2, baseJoints, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < COUNT; i++ ) {
- if ( !joints1[i].Compare( joints2[i], 1e-4f ) ) {
- break;
- }
- }
- result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->ConvertJointQuatsToJointMats() %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
- }
- /*
- ============
- TestConvertJointMatsToJointQuats
- ============
- */
- void TestConvertJointMatsToJointQuats( void ) {
- int i;
- TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
- ALIGN16( idJointMat baseJoints[COUNT] );
- ALIGN16( idJointQuat joints1[COUNT] );
- ALIGN16( idJointQuat joints2[COUNT] );
- const char *result;
- idRandom srnd( RANDOM_SEED );
- for ( i = 0; i < COUNT; i++ ) {
- idAngles angles;
- angles[0] = srnd.CRandomFloat() * 180.0f;
- angles[1] = srnd.CRandomFloat() * 180.0f;
- angles[2] = srnd.CRandomFloat() * 180.0f;
- baseJoints[i].SetRotation( angles.ToMat3() );
- idVec3 v;
- v[0] = srnd.CRandomFloat() * 10.0f;
- v[1] = srnd.CRandomFloat() * 10.0f;
- v[2] = srnd.CRandomFloat() * 10.0f;
- baseJoints[i].SetTranslation( v );
- }
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_generic->ConvertJointMatsToJointQuats( joints1, baseJoints, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->ConvertJointMatsToJointQuats()", COUNT, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_simd->ConvertJointMatsToJointQuats( joints2, baseJoints, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < COUNT; i++ ) {
- if ( !joints1[i].q.Compare( joints2[i].q, 1e-4f ) ) {
- idLib::common->Printf("ConvertJointMatsToJointQuats: broken q %i\n", i );
- break;
- }
- if ( !joints1[i].t.Compare( joints2[i].t, 1e-4f ) ) {
- idLib::common->Printf("ConvertJointMatsToJointQuats: broken t %i\n", i );
- break;
- }
- }
- result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->ConvertJointMatsToJointQuats() %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
- }
- /*
- ============
- TestTransformJoints
- ============
- */
- void TestTransformJoints( void ) {
- int i, j;
- TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
- ALIGN16( idJointMat joints[COUNT+1] );
- ALIGN16( idJointMat joints1[COUNT+1] );
- ALIGN16( idJointMat joints2[COUNT+1] );
- ALIGN16( int parents[COUNT+1] );
- const char *result;
- idRandom srnd( RANDOM_SEED );
- for ( i = 0; i <= COUNT; i++ ) {
- idAngles angles;
- angles[0] = srnd.CRandomFloat() * 180.0f;
- angles[1] = srnd.CRandomFloat() * 180.0f;
- angles[2] = srnd.CRandomFloat() * 180.0f;
- joints[i].SetRotation( angles.ToMat3() );
- idVec3 v;
- v[0] = srnd.CRandomFloat() * 2.0f;
- v[1] = srnd.CRandomFloat() * 2.0f;
- v[2] = srnd.CRandomFloat() * 2.0f;
- joints[i].SetTranslation( v );
- parents[i] = i - 1;
- }
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- for ( j = 0; j <= COUNT; j++ ) {
- joints1[j] = joints[j];
- }
- StartRecordTime( start );
- p_generic->TransformJoints( joints1, parents, 1, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->TransformJoints()", COUNT, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- for ( j = 0; j <= COUNT; j++ ) {
- joints2[j] = joints[j];
- }
- StartRecordTime( start );
- p_simd->TransformJoints( joints2, parents, 1, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < COUNT; i++ ) {
- if ( !joints1[i+1].Compare( joints2[i+1], 1e-4f ) ) {
- break;
- }
- }
- result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->TransformJoints() %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
- }
- /*
- ============
- TestUntransformJoints
- ============
- */
- void TestUntransformJoints( void ) {
- int i, j;
- TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
- ALIGN16( idJointMat joints[COUNT+1] );
- ALIGN16( idJointMat joints1[COUNT+1] );
- ALIGN16( idJointMat joints2[COUNT+1] );
- ALIGN16( int parents[COUNT+1] );
- const char *result;
- idRandom srnd( RANDOM_SEED );
- for ( i = 0; i <= COUNT; i++ ) {
- idAngles angles;
- angles[0] = srnd.CRandomFloat() * 180.0f;
- angles[1] = srnd.CRandomFloat() * 180.0f;
- angles[2] = srnd.CRandomFloat() * 180.0f;
- joints[i].SetRotation( angles.ToMat3() );
- idVec3 v;
- v[0] = srnd.CRandomFloat() * 2.0f;
- v[1] = srnd.CRandomFloat() * 2.0f;
- v[2] = srnd.CRandomFloat() * 2.0f;
- joints[i].SetTranslation( v );
- parents[i] = i - 1;
- }
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- for ( j = 0; j <= COUNT; j++ ) {
- joints1[j] = joints[j];
- }
- StartRecordTime( start );
- p_generic->UntransformJoints( joints1, parents, 1, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->UntransformJoints()", COUNT, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- for ( j = 0; j <= COUNT; j++ ) {
- joints2[j] = joints[j];
- }
- StartRecordTime( start );
- p_simd->UntransformJoints( joints2, parents, 1, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < COUNT; i++ ) {
- if ( !joints1[i+1].Compare( joints2[i+1], 1e-4f ) ) {
- break;
- }
- }
- result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->UntransformJoints() %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
- }
- /*
- ============
- TestTransformVerts
- ============
- */
- #define NUMJOINTS 64
- #define NUMVERTS COUNT/2
- void TestTransformVerts( void ) {
- int i;
- TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
- ALIGN16( idDrawVert drawVerts1[NUMVERTS] );
- ALIGN16( idDrawVert drawVerts2[NUMVERTS] );
- ALIGN16( idJointMat joints[NUMJOINTS] );
- ALIGN16( idVec4 weights[COUNT] );
- ALIGN16( int weightIndex[COUNT*2] );
- const char *result;
- idRandom srnd( RANDOM_SEED );
- for ( i = 0; i < NUMJOINTS; i++ ) {
- idAngles angles;
- angles[0] = srnd.CRandomFloat() * 180.0f;
- angles[1] = srnd.CRandomFloat() * 180.0f;
- angles[2] = srnd.CRandomFloat() * 180.0f;
- joints[i].SetRotation( angles.ToMat3() );
- idVec3 v;
- v[0] = srnd.CRandomFloat() * 2.0f;
- v[1] = srnd.CRandomFloat() * 2.0f;
- v[2] = srnd.CRandomFloat() * 2.0f;
- joints[i].SetTranslation( v );
- }
- for ( i = 0; i < COUNT; i++ ) {
- weights[i][0] = srnd.CRandomFloat() * 2.0f;
- weights[i][1] = srnd.CRandomFloat() * 2.0f;
- weights[i][2] = srnd.CRandomFloat() * 2.0f;
- weights[i][3] = srnd.CRandomFloat();
- weightIndex[i*2+0] = ( i * NUMJOINTS / COUNT ) * sizeof( idJointMat );
- weightIndex[i*2+1] = i & 1;
- }
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_generic->TransformVerts( drawVerts1, NUMVERTS, joints, weights, weightIndex, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->TransformVerts()", COUNT, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_simd->TransformVerts( drawVerts2, NUMVERTS, joints, weights, weightIndex, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < NUMVERTS; i++ ) {
- if ( !drawVerts1[i].xyz.Compare( drawVerts2[i].xyz, 0.5f ) ) {
- break;
- }
- }
- result = ( i >= NUMVERTS ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->TransformVerts() %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
- }
- /*
- ============
- TestTracePointCull
- ============
- */
- void TestTracePointCull( void ) {
- int i, j;
- TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
- ALIGN16( idPlane planes[4] );
- ALIGN16( idDrawVert drawVerts[COUNT] );
- ALIGN16( byte cullBits1[COUNT] );
- ALIGN16( byte cullBits2[COUNT] );
- byte totalOr1 = 0, totalOr2 = 0;
- const char *result;
- idRandom srnd( RANDOM_SEED );
- planes[0].SetNormal( idVec3( 1, 0, 0 ) );
- planes[1].SetNormal( idVec3( -1, 0, 0 ) );
- planes[2].SetNormal( idVec3( 0, 1, 0 ) );
- planes[3].SetNormal( idVec3( 0, -1, 0 ) );
- planes[0][3] = -5.3f;
- planes[1][3] = 5.3f;
- planes[2][3] = -3.4f;
- planes[3][3] = 3.4f;
- for ( i = 0; i < COUNT; i++ ) {
- for ( j = 0; j < 3; j++ ) {
- drawVerts[i].xyz[j] = srnd.CRandomFloat() * 10.0f;
- }
- }
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_generic->TracePointCull( cullBits1, totalOr1, 0.0f, planes, drawVerts, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->TracePointCull()", COUNT, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_simd->TracePointCull( cullBits2, totalOr2, 0.0f, planes, drawVerts, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < COUNT; i++ ) {
- if ( cullBits1[i] != cullBits2[i] ) {
- break;
- }
- }
- result = ( i >= COUNT && totalOr1 == totalOr2 ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->TracePointCull() %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
- }
- /*
- ============
- TestDecalPointCull
- ============
- */
- void TestDecalPointCull( void ) {
- int i, j;
- TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
- ALIGN16( idPlane planes[6] );
- ALIGN16( idDrawVert drawVerts[COUNT] );
- ALIGN16( byte cullBits1[COUNT] );
- ALIGN16( byte cullBits2[COUNT] );
- const char *result;
- idRandom srnd( RANDOM_SEED );
- planes[0].SetNormal( idVec3( 1, 0, 0 ) );
- planes[1].SetNormal( idVec3( -1, 0, 0 ) );
- planes[2].SetNormal( idVec3( 0, 1, 0 ) );
- planes[3].SetNormal( idVec3( 0, -1, 0 ) );
- planes[4].SetNormal( idVec3( 0, 0, 1 ) );
- planes[5].SetNormal( idVec3( 0, 0, -1 ) );
- planes[0][3] = -5.3f;
- planes[1][3] = 5.3f;
- planes[2][3] = -4.4f;
- planes[3][3] = 4.4f;
- planes[4][3] = -3.5f;
- planes[5][3] = 3.5f;
- for ( i = 0; i < COUNT; i++ ) {
- for ( j = 0; j < 3; j++ ) {
- drawVerts[i].xyz[j] = srnd.CRandomFloat() * 10.0f;
- }
- }
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_generic->DecalPointCull( cullBits1, planes, drawVerts, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->DecalPointCull()", COUNT, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_simd->DecalPointCull( cullBits2, planes, drawVerts, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < COUNT; i++ ) {
- if ( cullBits1[i] != cullBits2[i] ) {
- break;
- }
- }
- result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->DecalPointCull() %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
- }
- /*
- ============
- TestOverlayPointCull
- ============
- */
- void TestOverlayPointCull( void ) {
- int i, j;
- TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
- ALIGN16( idPlane planes[2] );
- ALIGN16( idDrawVert drawVerts[COUNT] );
- ALIGN16( byte cullBits1[COUNT] );
- ALIGN16( byte cullBits2[COUNT] );
- ALIGN16( idVec2 texCoords1[COUNT] );
- ALIGN16( idVec2 texCoords2[COUNT] );
- const char *result;
- idRandom srnd( RANDOM_SEED );
- planes[0].SetNormal( idVec3( 0.3f, 0.2f, 0.9f ) );
- planes[1].SetNormal( idVec3( 0.9f, 0.2f, 0.3f ) );
- planes[0][3] = -5.3f;
- planes[1][3] = -4.3f;
- for ( i = 0; i < COUNT; i++ ) {
- for ( j = 0; j < 3; j++ ) {
- drawVerts[i].xyz[j] = srnd.CRandomFloat() * 10.0f;
- }
- }
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_generic->OverlayPointCull( cullBits1, texCoords1, planes, drawVerts, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->OverlayPointCull()", COUNT, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_simd->OverlayPointCull( cullBits2, texCoords2, planes, drawVerts, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < COUNT; i++ ) {
- if ( cullBits1[i] != cullBits2[i] ) {
- break;
- }
- if ( !texCoords1[i].Compare( texCoords2[i], 1e-4f ) ) {
- break;
- }
- }
- result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->OverlayPointCull() %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
- }
- /*
- ============
- TestDeriveTriPlanes
- ============
- */
- void TestDeriveTriPlanes( void ) {
- int i, j;
- TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
- ALIGN16( idDrawVert drawVerts1[COUNT] );
- ALIGN16( idDrawVert drawVerts2[COUNT] );
- ALIGN16( idPlane planes1[COUNT] );
- ALIGN16( idPlane planes2[COUNT] );
- ALIGN16( int indexes[COUNT*3] );
- const char *result;
- idRandom srnd( RANDOM_SEED );
- for ( i = 0; i < COUNT; i++ ) {
- for ( j = 0; j < 3; j++ ) {
- drawVerts1[i].xyz[j] = srnd.CRandomFloat() * 10.0f;
- }
- for ( j = 0; j < 2; j++ ) {
- drawVerts1[i].st[j] = srnd.CRandomFloat();
- }
- drawVerts2[i] = drawVerts1[i];
- }
- for ( i = 0; i < COUNT; i++ ) {
- indexes[i*3+0] = ( i + 0 ) % COUNT;
- indexes[i*3+1] = ( i + 1 ) % COUNT;
- indexes[i*3+2] = ( i + 2 ) % COUNT;
- }
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_generic->DeriveTriPlanes( planes1, drawVerts1, COUNT, indexes, COUNT*3 );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->DeriveTriPlanes()", COUNT, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_simd->DeriveTriPlanes( planes2, drawVerts2, COUNT, indexes, COUNT*3 );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < COUNT; i++ ) {
- if ( !planes1[i].Compare( planes2[i], 1e-1f, 1e-1f ) ) {
- break;
- }
- }
- result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->DeriveTriPlanes() %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
- }
- /*
- ============
- TestDeriveTangents
- ============
- */
- void TestDeriveTangents( void ) {
- int i, j;
- TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
- ALIGN16( idDrawVert drawVerts1[COUNT] );
- ALIGN16( idDrawVert drawVerts2[COUNT] );
- ALIGN16( idPlane planes1[COUNT] );
- ALIGN16( idPlane planes2[COUNT] );
- ALIGN16( int indexes[COUNT*3] );
- const char *result;
- idRandom srnd( RANDOM_SEED );
- for ( i = 0; i < COUNT; i++ ) {
- for ( j = 0; j < 3; j++ ) {
- drawVerts1[i].xyz[j] = srnd.CRandomFloat() * 10.0f;
- }
- for ( j = 0; j < 2; j++ ) {
- drawVerts1[i].st[j] = srnd.CRandomFloat();
- }
- drawVerts2[i] = drawVerts1[i];
- }
- for ( i = 0; i < COUNT; i++ ) {
- indexes[i*3+0] = ( i + 0 ) % COUNT;
- indexes[i*3+1] = ( i + 1 ) % COUNT;
- indexes[i*3+2] = ( i + 2 ) % COUNT;
- }
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_generic->DeriveTangents( planes1, drawVerts1, COUNT, indexes, COUNT*3 );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->DeriveTangents()", COUNT, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_simd->DeriveTangents( planes2, drawVerts2, COUNT, indexes, COUNT*3 );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < COUNT; i++ ) {
- idVec3 v1, v2;
- v1 = drawVerts1[i].normal;
- v1.Normalize();
- v2 = drawVerts2[i].normal;
- v2.Normalize();
- if ( !v1.Compare( v2, 1e-1f ) ) {
- idLib::common->Printf("DeriveTangents: broken at normal %i\n -- expecting %s got %s", i, v1.ToString(), v2.ToString());
- break;
- }
- v1 = drawVerts1[i].tangents[0];
- v1.Normalize();
- v2 = drawVerts2[i].tangents[0];
- v2.Normalize();
- if ( !v1.Compare( v2, 1e-1f ) ) {
- idLib::common->Printf("DeriveTangents: broken at tangent0 %i -- expecting %s got %s\n", i, v1.ToString(), v2.ToString() );
- break;
- }
- v1 = drawVerts1[i].tangents[1];
- v1.Normalize();
- v2 = drawVerts2[i].tangents[1];
- v2.Normalize();
- if ( !v1.Compare( v2, 1e-1f ) ) {
- idLib::common->Printf("DeriveTangents: broken at tangent1 %i -- expecting %s got %s\n", i, v1.ToString(), v2.ToString() );
- break;
- }
- if ( !planes1[i].Compare( planes2[i], 1e-1f, 1e-1f ) ) {
- break;
- }
- }
- result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->DeriveTangents() %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
- }
- /*
- ============
- TestDeriveUnsmoothedTangents
- ============
- */
- void TestDeriveUnsmoothedTangents( void ) {
- int i, j;
- TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
- ALIGN16( idDrawVert drawVerts1[COUNT] );
- ALIGN16( idDrawVert drawVerts2[COUNT] );
- ALIGN16( dominantTri_s dominantTris[COUNT] );
- const char *result;
- idRandom srnd( RANDOM_SEED );
- for ( i = 0; i < COUNT; i++ ) {
- for ( j = 0; j < 3; j++ ) {
- drawVerts1[i].xyz[j] = srnd.CRandomFloat() * 10.0f;
- }
- for ( j = 0; j < 2; j++ ) {
- drawVerts1[i].st[j] = srnd.CRandomFloat();
- }
- drawVerts2[i] = drawVerts1[i];
- dominantTris[i].v2 = ( i + 1 + srnd.RandomInt( 8 ) ) % COUNT;
- dominantTris[i].v3 = ( i + 9 + srnd.RandomInt( 8 ) ) % COUNT;
- dominantTris[i].normalizationScale[0] = srnd.CRandomFloat();
- dominantTris[i].normalizationScale[1] = srnd.CRandomFloat();
- dominantTris[i].normalizationScale[2] = srnd.CRandomFloat();
- }
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_generic->DeriveUnsmoothedTangents( drawVerts1, dominantTris, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->DeriveUnsmoothedTangents()", COUNT, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_simd->DeriveUnsmoothedTangents( drawVerts2, dominantTris, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < COUNT; i++ ) {
- idVec3 v1, v2;
- v1 = drawVerts1[i].normal;
- v1.Normalize();
- v2 = drawVerts2[i].normal;
- v2.Normalize();
- if ( !v1.Compare( v2, 1e-1f ) ) {
- break;
- }
- v1 = drawVerts1[i].tangents[0];
- v1.Normalize();
- v2 = drawVerts2[i].tangents[0];
- v2.Normalize();
- if ( !v1.Compare( v2, 1e-1f ) ) {
- break;
- }
- v1 = drawVerts1[i].tangents[1];
- v1.Normalize();
- v2 = drawVerts2[i].tangents[1];
- v2.Normalize();
- if ( !v1.Compare( v2, 1e-1f ) ) {
- break;
- }
- }
- result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->DeriveUnsmoothedTangents() %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
- }
- /*
- ============
- TestNormalizeTangents
- ============
- */
- void TestNormalizeTangents( void ) {
- int i, j;
- TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
- ALIGN16( idDrawVert drawVerts1[COUNT] );
- ALIGN16( idDrawVert drawVerts2[COUNT] );
- const char *result;
- idRandom srnd( RANDOM_SEED );
- for ( i = 0; i < COUNT; i++ ) {
- for ( j = 0; j < 3; j++ ) {
- drawVerts1[i].normal[j] = srnd.CRandomFloat() * 10.0f;
- drawVerts1[i].tangents[0][j] = srnd.CRandomFloat() * 10.0f;
- drawVerts1[i].tangents[1][j] = srnd.CRandomFloat() * 10.0f;
- }
- drawVerts2[i] = drawVerts1[i];
- }
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_generic->NormalizeTangents( drawVerts1, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->NormalizeTangents()", COUNT, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_simd->NormalizeTangents( drawVerts2, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < COUNT; i++ ) {
- if ( !drawVerts1[i].normal.Compare( drawVerts2[i].normal, 1e-2f ) ) {
- break;
- }
- if ( !drawVerts1[i].tangents[0].Compare( drawVerts2[i].tangents[0], 1e-2f ) ) {
- break;
- }
- if ( !drawVerts1[i].tangents[1].Compare( drawVerts2[i].tangents[1], 1e-2f ) ) {
- break;
- }
-
- // since we're doing a lot of unaligned work, added this check to
- // make sure xyz wasn't getting overwritten
- if ( !drawVerts1[i].xyz.Compare( drawVerts2[i].xyz, 1e-2f ) ) {
- break;
- }
- }
- result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->NormalizeTangents() %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
- }
- /*
- ============
- TestGetTextureSpaceLightVectors
- ============
- */
- void TestGetTextureSpaceLightVectors( void ) {
- int i, j;
- TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
- ALIGN16( idDrawVert drawVerts[COUNT] );
- ALIGN16( idVec4 texCoords1[COUNT] );
- ALIGN16( idVec4 texCoords2[COUNT] );
- ALIGN16( int indexes[COUNT*3] );
- ALIGN16( idVec3 lightVectors1[COUNT] );
- ALIGN16( idVec3 lightVectors2[COUNT] );
- idVec3 lightOrigin;
- const char *result;
- idRandom srnd( RANDOM_SEED );
- for ( i = 0; i < COUNT; i++ ) {
- for ( j = 0; j < 3; j++ ) {
- drawVerts[i].xyz[j] = srnd.CRandomFloat() * 100.0f;
- drawVerts[i].normal[j] = srnd.CRandomFloat();
- drawVerts[i].tangents[0][j] = srnd.CRandomFloat();
- drawVerts[i].tangents[1][j] = srnd.CRandomFloat();
- }
- }
- for ( i = 0; i < COUNT; i++ ) {
- indexes[i*3+0] = ( i + 0 ) % COUNT;
- indexes[i*3+1] = ( i + 1 ) % COUNT;
- indexes[i*3+2] = ( i + 2 ) % COUNT;
- }
- lightOrigin[0] = srnd.CRandomFloat() * 100.0f;
- lightOrigin[1] = srnd.CRandomFloat() * 100.0f;
- lightOrigin[2] = srnd.CRandomFloat() * 100.0f;
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_generic->CreateTextureSpaceLightVectors( lightVectors1, lightOrigin, drawVerts, COUNT, indexes, COUNT*3 );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->CreateTextureSpaceLightVectors()", COUNT, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_simd->CreateTextureSpaceLightVectors( lightVectors2, lightOrigin, drawVerts, COUNT, indexes, COUNT*3 );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < COUNT; i++ ) {
- if ( !lightVectors1[i].Compare( lightVectors2[i], 1e-4f ) ) {
- break;
- }
- }
- result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->CreateTextureSpaceLightVectors() %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
- }
- /*
- ============
- TestGetSpecularTextureCoords
- ============
- */
- void TestGetSpecularTextureCoords( void ) {
- int i, j;
- TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
- ALIGN16( idDrawVert drawVerts[COUNT] );
- ALIGN16( idVec4 texCoords1[COUNT] );
- ALIGN16( idVec4 texCoords2[COUNT] );
- ALIGN16( int indexes[COUNT*3] );
- ALIGN16( idVec3 lightVectors1[COUNT] );
- ALIGN16( idVec3 lightVectors2[COUNT] );
- idVec3 lightOrigin, viewOrigin;
- const char *result;
- idRandom srnd( RANDOM_SEED );
- for ( i = 0; i < COUNT; i++ ) {
- for ( j = 0; j < 3; j++ ) {
- drawVerts[i].xyz[j] = srnd.CRandomFloat() * 100.0f;
- drawVerts[i].normal[j] = srnd.CRandomFloat();
- drawVerts[i].tangents[0][j] = srnd.CRandomFloat();
- drawVerts[i].tangents[1][j] = srnd.CRandomFloat();
- }
- }
- for ( i = 0; i < COUNT; i++ ) {
- indexes[i*3+0] = ( i + 0 ) % COUNT;
- indexes[i*3+1] = ( i + 1 ) % COUNT;
- indexes[i*3+2] = ( i + 2 ) % COUNT;
- }
- lightOrigin[0] = srnd.CRandomFloat() * 100.0f;
- lightOrigin[1] = srnd.CRandomFloat() * 100.0f;
- lightOrigin[2] = srnd.CRandomFloat() * 100.0f;
- viewOrigin[0] = srnd.CRandomFloat() * 100.0f;
- viewOrigin[1] = srnd.CRandomFloat() * 100.0f;
- viewOrigin[2] = srnd.CRandomFloat() * 100.0f;
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_generic->CreateSpecularTextureCoords( texCoords1, lightOrigin, viewOrigin, drawVerts, COUNT, indexes, COUNT*3 );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->CreateSpecularTextureCoords()", COUNT, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_simd->CreateSpecularTextureCoords( texCoords2, lightOrigin, viewOrigin, drawVerts, COUNT, indexes, COUNT*3 );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < COUNT; i++ ) {
- if ( !texCoords1[i].Compare( texCoords2[i], 1e-2f ) ) {
- break;
- }
- }
- result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->CreateSpecularTextureCoords() %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
- }
- /*
- ============
- TestCreateShadowCache
- ============
- */
- void TestCreateShadowCache( void ) {
- int i, j;
- TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
- ALIGN16( idDrawVert drawVerts[COUNT] );
- ALIGN16( idVec4 vertexCache1[COUNT*2] );
- ALIGN16( idVec4 vertexCache2[COUNT*2] );
- ALIGN16( int originalVertRemap[COUNT] );
- ALIGN16( int vertRemap1[COUNT] );
- ALIGN16( int vertRemap2[COUNT] );
- ALIGN16( idVec3 lightOrigin );
- int numVerts1 = 0, numVerts2 = 0;
- const char *result;
- idRandom srnd( RANDOM_SEED );
- for ( i = 0; i < COUNT; i++ ) {
- drawVerts[i].xyz[0] = srnd.CRandomFloat() * 100.0f;
- drawVerts[i].xyz[1] = srnd.CRandomFloat() * 100.0f;
- drawVerts[i].xyz[2] = srnd.CRandomFloat() * 100.0f;
- originalVertRemap[i] = ( srnd.CRandomFloat() > 0.0f ) ? -1 : 0;
- }
- lightOrigin[0] = srnd.CRandomFloat() * 100.0f;
- lightOrigin[1] = srnd.CRandomFloat() * 100.0f;
- lightOrigin[2] = srnd.CRandomFloat() * 100.0f;
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- for ( j = 0; j < COUNT; j++ ) {
- vertRemap1[j] = originalVertRemap[j];
- }
- StartRecordTime( start );
- numVerts1 =p_generic->CreateShadowCache( vertexCache1, vertRemap1, lightOrigin, drawVerts, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->CreateShadowCache()", COUNT, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- for ( j = 0; j < COUNT; j++ ) {
- vertRemap2[j] = originalVertRemap[j];
- }
- StartRecordTime( start );
- numVerts2 = p_simd->CreateShadowCache( vertexCache2, vertRemap2, lightOrigin, drawVerts, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < COUNT; i++ ) {
- if ( i < ( numVerts1 / 2 ) ) {
- if ( !vertexCache1[i*2+0].Compare( vertexCache2[i*2+0], 1e-2f ) ) {
- break;
- }
- if ( !vertexCache1[i*2+1].Compare( vertexCache2[i*2+1], 1e-2f ) ) {
- break;
- }
- }
- if ( vertRemap1[i] != vertRemap2[i] ) {
- break;
- }
- }
- result = ( i >= COUNT && numVerts1 == numVerts2 ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->CreateShadowCache() %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_generic->CreateVertexProgramShadowCache( vertexCache1, drawVerts, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->CreateVertexProgramShadowCache()", COUNT, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_simd->CreateVertexProgramShadowCache( vertexCache2, drawVerts, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < COUNT; i++ ) {
- if ( !vertexCache1[i*2+0].Compare( vertexCache2[i*2+0], 1e-2f ) ) {
- break;
- }
- if ( !vertexCache1[i*2+1].Compare( vertexCache2[i*2+1], 1e-2f ) ) {
- break;
- }
- }
- result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->CreateVertexProgramShadowCache() %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
- }
- /*
- ============
- TestSoundUpSampling
- ============
- */
- #define SOUND_UPSAMPLE_EPSILON 1.0f
- void TestSoundUpSampling( void ) {
- int i;
- TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
- ALIGN16( short pcm[MIXBUFFER_SAMPLES*2] );
- ALIGN16( float ogg0[MIXBUFFER_SAMPLES*2] );
- ALIGN16( float ogg1[MIXBUFFER_SAMPLES*2] );
- ALIGN16( float samples1[MIXBUFFER_SAMPLES*2] );
- ALIGN16( float samples2[MIXBUFFER_SAMPLES*2] );
- float *ogg[2];
- int kHz, numSpeakers;
- const char *result;
- idRandom srnd( RANDOM_SEED );
- for ( i = 0; i < MIXBUFFER_SAMPLES*2; i++ ) {
- pcm[i] = srnd.RandomInt( (1<<16) ) - (1<<15);
- ogg0[i] = srnd.RandomFloat();
- ogg1[i] = srnd.RandomFloat();
- }
- ogg[0] = ogg0;
- ogg[1] = ogg1;
- for ( numSpeakers = 1; numSpeakers <= 2; numSpeakers++ ) {
- for ( kHz = 11025; kHz <= 44100; kHz *= 2 ) {
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_generic->UpSamplePCMTo44kHz( samples1, pcm, MIXBUFFER_SAMPLES*numSpeakers*kHz/44100, kHz, numSpeakers );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( va( "generic->UpSamplePCMTo44kHz( %d, %d )", kHz, numSpeakers ), MIXBUFFER_SAMPLES*numSpeakers*kHz/44100, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_simd->UpSamplePCMTo44kHz( samples2, pcm, MIXBUFFER_SAMPLES*numSpeakers*kHz/44100, kHz, numSpeakers );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < MIXBUFFER_SAMPLES*numSpeakers; i++ ) {
- if ( idMath::Fabs( samples1[i] - samples2[i] ) > SOUND_UPSAMPLE_EPSILON ) {
- break;
- }
- }
- result = ( i >= MIXBUFFER_SAMPLES*numSpeakers ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->UpSamplePCMTo44kHz( %d, %d ) %s", kHz, numSpeakers, result ), MIXBUFFER_SAMPLES*numSpeakers*kHz/44100, bestClocksSIMD, bestClocksGeneric );
- }
- }
- for ( numSpeakers = 1; numSpeakers <= 2; numSpeakers++ ) {
- for ( kHz = 11025; kHz <= 44100; kHz *= 2 ) {
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_generic->UpSampleOGGTo44kHz( samples1, ogg, MIXBUFFER_SAMPLES*numSpeakers*kHz/44100, kHz, numSpeakers );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( va( "generic->UpSampleOGGTo44kHz( %d, %d )", kHz, numSpeakers ), MIXBUFFER_SAMPLES*numSpeakers*kHz/44100, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- p_simd->UpSampleOGGTo44kHz( samples2, ogg, MIXBUFFER_SAMPLES*numSpeakers*kHz/44100, kHz, numSpeakers );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < MIXBUFFER_SAMPLES*numSpeakers; i++ ) {
- if ( idMath::Fabs( samples1[i] - samples2[i] ) > SOUND_UPSAMPLE_EPSILON ) {
- break;
- }
- }
- result = ( i >= MIXBUFFER_SAMPLES ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->UpSampleOGGTo44kHz( %d, %d ) %s", kHz, numSpeakers, result ), MIXBUFFER_SAMPLES*numSpeakers*kHz/44100, bestClocksSIMD, bestClocksGeneric );
- }
- }
- }
- /*
- ============
- TestSoundMixing
- ============
- */
- #define SOUND_MIX_EPSILON 2.0f
- void TestSoundMixing( void ) {
- int i, j;
- TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
- ALIGN16( float origMixBuffer[MIXBUFFER_SAMPLES*6] );
- ALIGN16( float mixBuffer1[MIXBUFFER_SAMPLES*6] );
- ALIGN16( float mixBuffer2[MIXBUFFER_SAMPLES*6] );
- ALIGN16( float samples[MIXBUFFER_SAMPLES*6] );
- ALIGN16( short outSamples1[MIXBUFFER_SAMPLES*6] );
- ALIGN16( short outSamples2[MIXBUFFER_SAMPLES*6] );
- float lastV[6];
- float currentV[6];
- const char *result;
- idRandom srnd( RANDOM_SEED );
- for ( i = 0; i < 6; i++ ) {
- lastV[i] = srnd.CRandomFloat();
- currentV[i] = srnd.CRandomFloat();
- }
- for ( i = 0; i < MIXBUFFER_SAMPLES*6; i++ ) {
- origMixBuffer[i] = srnd.CRandomFloat();
- samples[i] = srnd.RandomInt( (1<<16) ) - (1<<15);
- }
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- for ( j = 0; j < MIXBUFFER_SAMPLES*6; j++ ) {
- mixBuffer1[j] = origMixBuffer[j];
- }
- StartRecordTime( start );
- p_generic->MixSoundTwoSpeakerMono( mixBuffer1, samples, MIXBUFFER_SAMPLES, lastV, currentV );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->MixSoundTwoSpeakerMono()", MIXBUFFER_SAMPLES, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- for ( j = 0; j < MIXBUFFER_SAMPLES*6; j++ ) {
- mixBuffer2[j] = origMixBuffer[j];
- }
- StartRecordTime( start );
- p_simd->MixSoundTwoSpeakerMono( mixBuffer2, samples, MIXBUFFER_SAMPLES, lastV, currentV );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < MIXBUFFER_SAMPLES*6; i++ ) {
- if ( idMath::Fabs( mixBuffer1[i] - mixBuffer2[i] ) > SOUND_MIX_EPSILON ) {
- break;
- }
- }
- result = ( i >= MIXBUFFER_SAMPLES*6 ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->MixSoundTwoSpeakerMono() %s", result ), MIXBUFFER_SAMPLES, bestClocksSIMD, bestClocksGeneric );
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- for ( j = 0; j < MIXBUFFER_SAMPLES*6; j++ ) {
- mixBuffer1[j] = origMixBuffer[j];
- }
- StartRecordTime( start );
- p_generic->MixSoundTwoSpeakerStereo( mixBuffer1, samples, MIXBUFFER_SAMPLES, lastV, currentV );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->MixSoundTwoSpeakerStereo()", MIXBUFFER_SAMPLES, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- for ( j = 0; j < MIXBUFFER_SAMPLES*6; j++ ) {
- mixBuffer2[j] = origMixBuffer[j];
- }
- StartRecordTime( start );
- p_simd->MixSoundTwoSpeakerStereo( mixBuffer2, samples, MIXBUFFER_SAMPLES, lastV, currentV );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < MIXBUFFER_SAMPLES*6; i++ ) {
- if ( idMath::Fabs( mixBuffer1[i] - mixBuffer2[i] ) > SOUND_MIX_EPSILON ) {
- break;
- }
- }
- result = ( i >= MIXBUFFER_SAMPLES*6 ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->MixSoundTwoSpeakerStereo() %s", result ), MIXBUFFER_SAMPLES, bestClocksSIMD, bestClocksGeneric );
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- for ( j = 0; j < MIXBUFFER_SAMPLES*6; j++ ) {
- mixBuffer1[j] = origMixBuffer[j];
- }
- StartRecordTime( start );
- p_generic->MixSoundSixSpeakerMono( mixBuffer1, samples, MIXBUFFER_SAMPLES, lastV, currentV );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->MixSoundSixSpeakerMono()", MIXBUFFER_SAMPLES, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- for ( j = 0; j < MIXBUFFER_SAMPLES*6; j++ ) {
- mixBuffer2[j] = origMixBuffer[j];
- }
- StartRecordTime( start );
- p_simd->MixSoundSixSpeakerMono( mixBuffer2, samples, MIXBUFFER_SAMPLES, lastV, currentV );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < MIXBUFFER_SAMPLES*6; i++ ) {
- if ( idMath::Fabs( mixBuffer1[i] - mixBuffer2[i] ) > SOUND_MIX_EPSILON ) {
- break;
- }
- }
- result = ( i >= MIXBUFFER_SAMPLES*6 ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->MixSoundSixSpeakerMono() %s", result ), MIXBUFFER_SAMPLES, bestClocksSIMD, bestClocksGeneric );
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- for ( j = 0; j < MIXBUFFER_SAMPLES*6; j++ ) {
- mixBuffer1[j] = origMixBuffer[j];
- }
- StartRecordTime( start );
- p_generic->MixSoundSixSpeakerStereo( mixBuffer1, samples, MIXBUFFER_SAMPLES, lastV, currentV );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->MixSoundSixSpeakerStereo()", MIXBUFFER_SAMPLES, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- for ( j = 0; j < MIXBUFFER_SAMPLES*6; j++ ) {
- mixBuffer2[j] = origMixBuffer[j];
- }
- StartRecordTime( start );
- p_simd->MixSoundSixSpeakerStereo( mixBuffer2, samples, MIXBUFFER_SAMPLES, lastV, currentV );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < MIXBUFFER_SAMPLES*6; i++ ) {
- if ( idMath::Fabs( mixBuffer1[i] - mixBuffer2[i] ) > SOUND_MIX_EPSILON ) {
- break;
- }
- }
- result = ( i >= MIXBUFFER_SAMPLES*6 ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->MixSoundSixSpeakerStereo() %s", result ), MIXBUFFER_SAMPLES, bestClocksSIMD, bestClocksGeneric );
- for ( i = 0; i < MIXBUFFER_SAMPLES*6; i++ ) {
- origMixBuffer[i] = srnd.RandomInt( (1<<17) ) - (1<<16);
- }
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- for ( j = 0; j < MIXBUFFER_SAMPLES*6; j++ ) {
- mixBuffer1[j] = origMixBuffer[j];
- }
- StartRecordTime( start );
- p_generic->MixedSoundToSamples( outSamples1, mixBuffer1, MIXBUFFER_SAMPLES*6 );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->MixedSoundToSamples()", MIXBUFFER_SAMPLES, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- for ( j = 0; j < MIXBUFFER_SAMPLES*6; j++ ) {
- mixBuffer2[j] = origMixBuffer[j];
- }
- StartRecordTime( start );
- p_simd->MixedSoundToSamples( outSamples2, mixBuffer2, MIXBUFFER_SAMPLES*6 );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < MIXBUFFER_SAMPLES*6; i++ ) {
- if ( outSamples1[i] != outSamples2[i] ) {
- break;
- }
- }
- result = ( i >= MIXBUFFER_SAMPLES*6 ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->MixedSoundToSamples() %s", result ), MIXBUFFER_SAMPLES, bestClocksSIMD, bestClocksGeneric );
- }
- /*
- ============
- TestMath
- ============
- */
- void TestMath( void ) {
- int i;
- TIME_TYPE start, end, bestClocks;
- idLib::common->Printf("====================================\n" );
- float tst = -1.0f;
- float tst2 = 1.0f;
- float testvar = 1.0f;
- idRandom rnd;
- bestClocks = 0;
- tst = rnd.CRandomFloat();
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- tst = fabs( tst );
- StopRecordTime( end );
- GetBest( start, end, bestClocks );
- testvar = ( testvar + tst ) * tst;
- tst = rnd.CRandomFloat();
- }
- PrintClocks( " fabs( tst )", 1, bestClocks );
- bestClocks = 0;
- tst = rnd.CRandomFloat();
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- int tmp = * ( int * ) &tst;
- tmp &= 0x7FFFFFFF;
- tst = * ( float * ) &tmp;
- StopRecordTime( end );
- GetBest( start, end, bestClocks );
- testvar = ( testvar + tst ) * tst;
- tst = rnd.CRandomFloat();
- }
- PrintClocks( " idMath::Fabs( tst )", 1, bestClocks );
- bestClocks = 0;
- tst = 10.0f + 100.0f * rnd.RandomFloat();
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- tst = sqrt( tst );
- StopRecordTime( end );
- GetBest( start, end, bestClocks );
- testvar = ( testvar + tst ) * tst * 0.01f;
- tst = 10.0f + 100.0f * rnd.RandomFloat();
- }
- PrintClocks( " sqrt( tst )", 1, bestClocks );
- bestClocks = 0;
- tst = rnd.RandomFloat();
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- tst = idMath::Sqrt( tst );
- StopRecordTime( end );
- GetBest( start, end, bestClocks );
- testvar = ( testvar + tst ) * tst;
- tst = rnd.RandomFloat();
- }
- PrintClocks( " idMath::Sqrt( tst )", 1, bestClocks );
- bestClocks = 0;
- tst = rnd.RandomFloat();
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- tst = idMath::Sqrt16( tst );
- StopRecordTime( end );
- GetBest( start, end, bestClocks );
- testvar = ( testvar + tst ) * tst;
- tst = rnd.RandomFloat();
- }
- PrintClocks( " idMath::Sqrt16( tst )", 1, bestClocks );
- bestClocks = 0;
- tst = rnd.RandomFloat();
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- tst = idMath::Sqrt64( tst );
- StopRecordTime( end );
- GetBest( start, end, bestClocks );
- testvar = ( testvar + tst ) * tst;
- tst = rnd.RandomFloat();
- }
- PrintClocks( " idMath::Sqrt64( tst )", 1, bestClocks );
- bestClocks = 0;
- tst = rnd.RandomFloat();
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- tst = tst * idMath::RSqrt( tst );
- StopRecordTime( end );
- GetBest( start, end, bestClocks );
- testvar = ( testvar + tst ) * tst;
- tst = rnd.RandomFloat();
- }
- PrintClocks( " idMath::RSqrt( tst )", 1, bestClocks );
- bestClocks = 0;
- tst = rnd.CRandomFloat();
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- tst = idMath::Sin( tst );
- StopRecordTime( end );
- GetBest( start, end, bestClocks );
- testvar = ( testvar + tst ) * tst;
- tst = rnd.CRandomFloat();
- }
- PrintClocks( " idMath::Sin( tst )", 1, bestClocks );
- bestClocks = 0;
- tst = rnd.CRandomFloat();
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- tst = idMath::Sin16( tst );
- StopRecordTime( end );
- GetBest( start, end, bestClocks );
- testvar = ( testvar + tst ) * tst;
- tst = rnd.CRandomFloat();
- }
- PrintClocks( " idMath::Sin16( tst )", 1, bestClocks );
- bestClocks = 0;
- tst = rnd.CRandomFloat();
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- tst = idMath::Cos( tst );
- StopRecordTime( end );
- GetBest( start, end, bestClocks );
- testvar = ( testvar + tst ) * tst;
- tst = rnd.CRandomFloat();
- }
- PrintClocks( " idMath::Cos( tst )", 1, bestClocks );
- bestClocks = 0;
- tst = rnd.CRandomFloat();
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- tst = idMath::Cos16( tst );
- StopRecordTime( end );
- GetBest( start, end, bestClocks );
- testvar = ( testvar + tst ) * tst;
- tst = rnd.CRandomFloat();
- }
- PrintClocks( " idMath::Cos16( tst )", 1, bestClocks );
- bestClocks = 0;
- tst = rnd.CRandomFloat();
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- idMath::SinCos( tst, tst, tst2 );
- StopRecordTime( end );
- GetBest( start, end, bestClocks );
- testvar = ( testvar + tst ) * tst;
- tst = rnd.CRandomFloat();
- }
- PrintClocks( " idMath::SinCos( tst )", 1, bestClocks );
- bestClocks = 0;
- tst = rnd.CRandomFloat();
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- idMath::SinCos16( tst, tst, tst2 );
- StopRecordTime( end );
- GetBest( start, end, bestClocks );
- testvar = ( testvar + tst ) * tst;
- tst = rnd.CRandomFloat();
- }
- PrintClocks( "idMath::SinCos16( tst )", 1, bestClocks );
- bestClocks = 0;
- tst = rnd.CRandomFloat();
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- tst = idMath::Tan( tst );
- StopRecordTime( end );
- GetBest( start, end, bestClocks );
- testvar = ( testvar + tst ) * tst;
- tst = rnd.CRandomFloat();
- }
- PrintClocks( " idMath::Tan( tst )", 1, bestClocks );
- bestClocks = 0;
- tst = rnd.CRandomFloat();
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- tst = idMath::Tan16( tst );
- StopRecordTime( end );
- GetBest( start, end, bestClocks );
- testvar = ( testvar + tst ) * tst;
- tst = rnd.CRandomFloat();
- }
- PrintClocks( " idMath::Tan16( tst )", 1, bestClocks );
- bestClocks = 0;
- tst = rnd.CRandomFloat();
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- tst = idMath::ASin( tst );
- StopRecordTime( end );
- GetBest( start, end, bestClocks );
- testvar = ( testvar + tst ) * tst * ( 1.0f / idMath::PI );
- tst = rnd.CRandomFloat();
- }
- PrintClocks( " idMath::ASin( tst )", 1, bestClocks );
- bestClocks = 0;
- tst = rnd.CRandomFloat();
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- tst = idMath::ASin16( tst );
- StopRecordTime( end );
- GetBest( start, end, bestClocks );
- testvar = ( testvar + tst ) * tst * ( 1.0f / idMath::PI );
- tst = rnd.CRandomFloat();
- }
- PrintClocks( " idMath::ASin16( tst )", 1, bestClocks );
- bestClocks = 0;
- tst = rnd.CRandomFloat();
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- tst = idMath::ACos( tst );
- StopRecordTime( end );
- GetBest( start, end, bestClocks );
- testvar = ( testvar + tst ) * tst * ( 1.0f / idMath::PI );
- tst = rnd.CRandomFloat();
- }
- PrintClocks( " idMath::ACos( tst )", 1, bestClocks );
- bestClocks = 0;
- tst = rnd.CRandomFloat();
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- tst = idMath::ACos16( tst );
- StopRecordTime( end );
- GetBest( start, end, bestClocks );
- testvar = ( testvar + tst ) * tst * ( 1.0f / idMath::PI );
- tst = rnd.CRandomFloat();
- }
- PrintClocks( " idMath::ACos16( tst )", 1, bestClocks );
- bestClocks = 0;
- tst = rnd.CRandomFloat();
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- tst = idMath::ATan( tst );
- StopRecordTime( end );
- GetBest( start, end, bestClocks );
- testvar = ( testvar + tst ) * tst;
- tst = rnd.CRandomFloat();
- }
- PrintClocks( " idMath::ATan( tst )", 1, bestClocks );
- bestClocks = 0;
- tst = rnd.CRandomFloat();
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- tst = idMath::ATan16( tst );
- StopRecordTime( end );
- GetBest( start, end, bestClocks );
- testvar = ( testvar + tst ) * tst;
- tst = rnd.CRandomFloat();
- }
- PrintClocks( " idMath::ATan16( tst )", 1, bestClocks );
- bestClocks = 0;
- tst = rnd.CRandomFloat();
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- tst = idMath::Pow( 2.7f, tst );
- StopRecordTime( end );
- GetBest( start, end, bestClocks );
- testvar = ( testvar + tst ) * tst * 0.1f;
- tst = rnd.CRandomFloat();
- }
- PrintClocks( " idMath::Pow( tst )", 1, bestClocks );
- bestClocks = 0;
- tst = rnd.CRandomFloat();
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- tst = idMath::Pow16( 2.7f, tst );
- StopRecordTime( end );
- GetBest( start, end, bestClocks );
- testvar = ( testvar + tst ) * tst * 0.1f;
- tst = rnd.CRandomFloat();
- }
- PrintClocks( " idMath::Pow16( tst )", 1, bestClocks );
- bestClocks = 0;
- tst = rnd.CRandomFloat();
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- tst = idMath::Exp( tst );
- StopRecordTime( end );
- GetBest( start, end, bestClocks );
- testvar = ( testvar + tst ) * tst * 0.1f;
- tst = rnd.CRandomFloat();
- }
- PrintClocks( " idMath::Exp( tst )", 1, bestClocks );
- bestClocks = 0;
- tst = rnd.CRandomFloat();
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- tst = idMath::Exp16( tst );
- StopRecordTime( end );
- GetBest( start, end, bestClocks );
- testvar = ( testvar + tst ) * tst * 0.1f;
- tst = rnd.CRandomFloat();
- }
- PrintClocks( " idMath::Exp16( tst )", 1, bestClocks );
- bestClocks = 0;
- tst = rnd.CRandomFloat();
- for ( i = 0; i < NUMTESTS; i++ ) {
- tst = fabs( tst ) + 1.0f;
- StartRecordTime( start );
- tst = idMath::Log( tst );
- StopRecordTime( end );
- GetBest( start, end, bestClocks );
- testvar = ( testvar + tst ) * tst;
- tst = rnd.CRandomFloat();
- }
- PrintClocks( " idMath::Log( tst )", 1, bestClocks );
- bestClocks = 0;
- tst = rnd.CRandomFloat();
- for ( i = 0; i < NUMTESTS; i++ ) {
- tst = fabs( tst ) + 1.0f;
- StartRecordTime( start );
- tst = idMath::Log16( tst );
- StopRecordTime( end );
- GetBest( start, end, bestClocks );
- testvar = ( testvar + tst ) * tst;
- tst = rnd.CRandomFloat();
- }
- PrintClocks( " idMath::Log16( tst )", 1, bestClocks );
- idLib::common->Printf( "testvar = %f\n", testvar );
- idMat3 resultMat3;
- idQuat fromQuat, toQuat, resultQuat;
- idCQuat cq;
- idAngles ang;
- fromQuat = idAngles( 30, 45, 0 ).ToQuat();
- toQuat = idAngles( 45, 0, 0 ).ToQuat();
- cq = idAngles( 30, 45, 0 ).ToQuat().ToCQuat();
- ang = idAngles( 30, 40, 50 );
- bestClocks = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- resultMat3 = fromQuat.ToMat3();
- StopRecordTime( end );
- GetBest( start, end, bestClocks );
- }
- PrintClocks( " idQuat::ToMat3()", 1, bestClocks );
- bestClocks = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- resultQuat.Slerp( fromQuat, toQuat, 0.3f );
- StopRecordTime( end );
- GetBest( start, end, bestClocks );
- }
- PrintClocks( " idQuat::Slerp()", 1, bestClocks );
- bestClocks = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- resultQuat = cq.ToQuat();
- StopRecordTime( end );
- GetBest( start, end, bestClocks );
- }
- PrintClocks( " idCQuat::ToQuat()", 1, bestClocks );
- bestClocks = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- resultQuat = ang.ToQuat();
- StopRecordTime( end );
- GetBest( start, end, bestClocks );
- }
- PrintClocks( " idAngles::ToQuat()", 1, bestClocks );
- bestClocks = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
- StartRecordTime( start );
- resultMat3 = ang.ToMat3();
- StopRecordTime( end );
- GetBest( start, end, bestClocks );
- }
- PrintClocks( " idAngles::ToMat3()", 1, bestClocks );
- }
- /*
- ============
- TestNegate
- ============
- */
- // this wasn't previously in the test
- void TestNegate( void ) {
- int i;
- TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD;
- ALIGN16( float fsrc0[COUNT] );
- ALIGN16( float fsrc1[COUNT] );
- ALIGN16( float fsrc2[COUNT] );
-
- const char *result;
- idRandom srnd( RANDOM_SEED );
- for ( i = 0; i < COUNT; i++ ) {
- fsrc0[i] = fsrc1[i] = fsrc2[i] = srnd.CRandomFloat() * 10.0f;
- //fsrc1[i] = srnd.CRandomFloat() * 10.0f;
- }
- idLib::common->Printf("====================================\n" );
- bestClocksGeneric = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
-
- memcpy( &fsrc1[0], &fsrc0[0], COUNT * sizeof(float) );
-
- StartRecordTime( start );
- p_generic->Negate16( fsrc1, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksGeneric );
- }
- PrintClocks( "generic->Negate16( float[] )", COUNT, bestClocksGeneric );
- bestClocksSIMD = 0;
- for ( i = 0; i < NUMTESTS; i++ ) {
-
- memcpy( &fsrc2[0], &fsrc0[0], COUNT * sizeof(float) );
-
- StartRecordTime( start );
- p_simd->Negate16( fsrc2, COUNT );
- StopRecordTime( end );
- GetBest( start, end, bestClocksSIMD );
- }
- for ( i = 0; i < COUNT; i++ ) {
- if ( fsrc1[i] != fsrc2[i] ) {
- break;
- }
- }
- result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X";
- PrintClocks( va( " simd->Negate16( float[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric );
- }
- /*
- ============
- idSIMD::Test_f
- ============
- */
- void idSIMD::Test_f( const idCmdArgs &args ) {
- #ifdef _WIN32
- SetThreadPriority( GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL );
- #endif /* _WIN32 */
- p_simd = processor;
- p_generic = generic;
- if ( idStr::Length( args.Argv( 1 ) ) != 0 ) {
- cpuid_t cpuid = idLib::sys->GetProcessorId();
- idStr argString = args.Args();
- argString.Replace( " ", "" );
- if ( idStr::Icmp( argString, "MMX" ) == 0 ) {
- if ( !( cpuid & CPUID_MMX ) ) {
- common->Printf( "CPU does not support MMX\n" );
- return;
- }
- p_simd = new idSIMD_MMX;
- } else if ( idStr::Icmp( argString, "3DNow" ) == 0 ) {
- if ( !( cpuid & CPUID_MMX ) || !( cpuid & CPUID_3DNOW ) ) {
- common->Printf( "CPU does not support MMX & 3DNow\n" );
- return;
- }
- p_simd = new idSIMD_3DNow;
- } else if ( idStr::Icmp( argString, "SSE" ) == 0 ) {
- if ( !( cpuid & CPUID_MMX ) || !( cpuid & CPUID_SSE ) ) {
- common->Printf( "CPU does not support MMX & SSE\n" );
- return;
- }
- p_simd = new idSIMD_SSE;
- } else if ( idStr::Icmp( argString, "SSE2" ) == 0 ) {
- if ( !( cpuid & CPUID_MMX ) || !( cpuid & CPUID_SSE ) || !( cpuid & CPUID_SSE2 ) ) {
- common->Printf( "CPU does not support MMX & SSE & SSE2\n" );
- return;
- }
- p_simd = new idSIMD_SSE2;
- } else if ( idStr::Icmp( argString, "SSE3" ) == 0 ) {
- if ( !( cpuid & CPUID_MMX ) || !( cpuid & CPUID_SSE ) || !( cpuid & CPUID_SSE2 ) || !( cpuid & CPUID_SSE3 ) ) {
- common->Printf( "CPU does not support MMX & SSE & SSE2 & SSE3\n" );
- return;
- }
- p_simd = new idSIMD_SSE3();
- } else if ( idStr::Icmp( argString, "AltiVec" ) == 0 ) {
- if ( !( cpuid & CPUID_ALTIVEC ) ) {
- common->Printf( "CPU does not support AltiVec\n" );
- return;
- }
- p_simd = new idSIMD_AltiVec();
- } else {
- common->Printf( "invalid argument, use: MMX, 3DNow, SSE, SSE2, SSE3, AltiVec\n" );
- return;
- }
- }
- idLib::common->SetRefreshOnPrint( true );
- idLib::common->Printf( "using %s for SIMD processing\n", p_simd->GetName() );
- GetBaseClocks();
- TestMath();
- TestAdd();
- TestSub();
- TestMul();
- TestDiv();
- TestMulAdd();
- TestMulSub();
- TestDot();
- TestCompare();
- TestMinMax();
- TestClamp();
- TestMemcpy();
- TestMemset();
- TestNegate();
- TestMatXMultiplyVecX();
- TestMatXMultiplyAddVecX();
- TestMatXTransposeMultiplyVecX();
- TestMatXTransposeMultiplyAddVecX();
- TestMatXMultiplyMatX();
- TestMatXTransposeMultiplyMatX();
- TestMatXLowerTriangularSolve();
- TestMatXLowerTriangularSolveTranspose();
- TestMatXLDLTFactor();
- idLib::common->Printf("====================================\n" );
- TestBlendJoints();
- TestConvertJointQuatsToJointMats();
- TestConvertJointMatsToJointQuats();
- TestTransformJoints();
- TestUntransformJoints();
- TestTransformVerts();
- TestTracePointCull();
- TestDecalPointCull();
- TestOverlayPointCull();
- TestDeriveTriPlanes();
- TestDeriveTangents();
- TestDeriveUnsmoothedTangents();
- TestNormalizeTangents();
- TestGetTextureSpaceLightVectors();
- TestGetSpecularTextureCoords();
- TestCreateShadowCache();
- idLib::common->Printf("====================================\n" );
- TestSoundUpSampling();
- TestSoundMixing();
- idLib::common->SetRefreshOnPrint( false );
- if ( p_simd != processor ) {
- delete p_simd;
- }
- p_simd = NULL;
- p_generic = NULL;
- #ifdef _WIN32
- SetThreadPriority( GetCurrentThread(), THREAD_PRIORITY_NORMAL );
- #endif /* _WIN32 */
- }
|