1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785 |
- /*++
- Copyright (c) Microsoft Corporation. All rights reserved.
- Module Name:
- xnamathconvert.inl
- Abstract:
- XNA math library for Windows and Xbox 360: Conversion, loading, and storing functions.
- --*/
- #if defined(_MSC_VER) && (_MSC_VER > 1000)
- #pragma once
- #endif
- #ifndef __XNAMATHCONVERT_INL__
- #define __XNAMATHCONVERT_INL__
- #define XM_PACK_FACTOR (FLOAT)(1 << 22)
- #define XM_UNPACK_FACTOR_UNSIGNED (FLOAT)(1 << 23)
- #define XM_UNPACK_FACTOR_SIGNED XM_PACK_FACTOR
- #define XM_UNPACK_UNSIGNEDN_OFFSET(BitsX, BitsY, BitsZ, BitsW) \
- {-XM_UNPACK_FACTOR_UNSIGNED / (FLOAT)((1 << (BitsX)) - 1), \
- -XM_UNPACK_FACTOR_UNSIGNED / (FLOAT)((1 << (BitsY)) - 1), \
- -XM_UNPACK_FACTOR_UNSIGNED / (FLOAT)((1 << (BitsZ)) - 1), \
- -XM_UNPACK_FACTOR_UNSIGNED / (FLOAT)((1 << (BitsW)) - 1)}
- #define XM_UNPACK_UNSIGNEDN_SCALE(BitsX, BitsY, BitsZ, BitsW) \
- {XM_UNPACK_FACTOR_UNSIGNED / (FLOAT)((1 << (BitsX)) - 1), \
- XM_UNPACK_FACTOR_UNSIGNED / (FLOAT)((1 << (BitsY)) - 1), \
- XM_UNPACK_FACTOR_UNSIGNED / (FLOAT)((1 << (BitsZ)) - 1), \
- XM_UNPACK_FACTOR_UNSIGNED / (FLOAT)((1 << (BitsW)) - 1)}
- #define XM_UNPACK_SIGNEDN_SCALE(BitsX, BitsY, BitsZ, BitsW) \
- {-XM_UNPACK_FACTOR_SIGNED / (FLOAT)((1 << ((BitsX) - 1)) - 1), \
- -XM_UNPACK_FACTOR_SIGNED / (FLOAT)((1 << ((BitsY) - 1)) - 1), \
- -XM_UNPACK_FACTOR_SIGNED / (FLOAT)((1 << ((BitsZ) - 1)) - 1), \
- -XM_UNPACK_FACTOR_SIGNED / (FLOAT)((1 << ((BitsW) - 1)) - 1)}
- //#define XM_UNPACK_SIGNEDN_OFFSET(BitsX, BitsY, BitsZ, BitsW) \
- // {-XM_UNPACK_FACTOR_SIGNED / (FLOAT)((1 << ((BitsX) - 1)) - 1) * 3.0f, \
- // -XM_UNPACK_FACTOR_SIGNED / (FLOAT)((1 << ((BitsY) - 1)) - 1) * 3.0f, \
- // -XM_UNPACK_FACTOR_SIGNED / (FLOAT)((1 << ((BitsZ) - 1)) - 1) * 3.0f, \
- // -XM_UNPACK_FACTOR_SIGNED / (FLOAT)((1 << ((BitsW) - 1)) - 1) * 3.0f}
- #define XM_PACK_UNSIGNEDN_SCALE(BitsX, BitsY, BitsZ, BitsW) \
- {-(FLOAT)((1 << (BitsX)) - 1) / XM_PACK_FACTOR, \
- -(FLOAT)((1 << (BitsY)) - 1) / XM_PACK_FACTOR, \
- -(FLOAT)((1 << (BitsZ)) - 1) / XM_PACK_FACTOR, \
- -(FLOAT)((1 << (BitsW)) - 1) / XM_PACK_FACTOR}
- #define XM_PACK_SIGNEDN_SCALE(BitsX, BitsY, BitsZ, BitsW) \
- {-(FLOAT)((1 << ((BitsX) - 1)) - 1) / XM_PACK_FACTOR, \
- -(FLOAT)((1 << ((BitsY) - 1)) - 1) / XM_PACK_FACTOR, \
- -(FLOAT)((1 << ((BitsZ) - 1)) - 1) / XM_PACK_FACTOR, \
- -(FLOAT)((1 << ((BitsW) - 1)) - 1) / XM_PACK_FACTOR}
- #define XM_PACK_OFFSET XMVectorSplatConstant(3, 0)
- //#define XM_UNPACK_OFFSET XM_PACK_OFFSET
- /****************************************************************************
- *
- * Data conversion
- *
- ****************************************************************************/
- //------------------------------------------------------------------------------
- XMFINLINE FLOAT XMConvertHalfToFloat
- (
- HALF Value
- )
- {
- #if defined(_XM_NO_INTRINSICS_) || defined(_XM_SSE_INTRINSICS_)
- UINT Mantissa;
- UINT Exponent;
- UINT Result;
- Mantissa = (UINT)(Value & 0x03FF);
- if ((Value & 0x7C00) != 0) // The value is normalized
- {
- Exponent = (UINT)((Value >> 10) & 0x1F);
- }
- else if (Mantissa != 0) // The value is denormalized
- {
- // Normalize the value in the resulting float
- Exponent = 1;
- do
- {
- Exponent--;
- Mantissa <<= 1;
- } while ((Mantissa & 0x0400) == 0);
- Mantissa &= 0x03FF;
- }
- else // The value is zero
- {
- Exponent = (UINT)-112;
- }
- Result = ((Value & 0x8000) << 16) | // Sign
- ((Exponent + 112) << 23) | // Exponent
- (Mantissa << 13); // Mantissa
- return *(FLOAT*)&Result;
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif
- }
- //------------------------------------------------------------------------------
- XMINLINE FLOAT* XMConvertHalfToFloatStream
- (
- FLOAT* pOutputStream,
- UINT OutputStride,
- CONST HALF* pInputStream,
- UINT InputStride,
- UINT HalfCount
- )
- {
- #if defined(_XM_NO_INTRINSICS_) || defined(_XM_SSE_INTRINSICS_)
- UINT i;
- BYTE* pHalf = (BYTE*)pInputStream;
- BYTE* pFloat = (BYTE*)pOutputStream;
- XMASSERT(pOutputStream);
- XMASSERT(pInputStream);
- for (i = 0; i < HalfCount; i++)
- {
- *(FLOAT*)pFloat = XMConvertHalfToFloat(*(HALF*)pHalf);
- pHalf += InputStride;
- pFloat += OutputStride;
- }
- return pOutputStream;
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE HALF XMConvertFloatToHalf
- (
- FLOAT Value
- )
- {
- #if defined(_XM_NO_INTRINSICS_) || defined(_XM_SSE_INTRINSICS_)
- UINT Result;
- UINT IValue = ((UINT *)(&Value))[0];
- UINT Sign = (IValue & 0x80000000U) >> 16U;
- IValue = IValue & 0x7FFFFFFFU; // Hack off the sign
- if (IValue > 0x47FFEFFFU)
- {
- // The number is too large to be represented as a half. Saturate to infinity.
- Result = 0x7FFFU;
- }
- else
- {
- if (IValue < 0x38800000U)
- {
- // The number is too small to be represented as a normalized half.
- // Convert it to a denormalized value.
- UINT Shift = 113U - (IValue >> 23U);
- IValue = (0x800000U | (IValue & 0x7FFFFFU)) >> Shift;
- }
- else
- {
- // Rebias the exponent to represent the value as a normalized half.
- IValue += 0xC8000000U;
- }
- Result = ((IValue + 0x0FFFU + ((IValue >> 13U) & 1U)) >> 13U)&0x7FFFU;
- }
- return (HALF)(Result|Sign);
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif
- }
- //------------------------------------------------------------------------------
- XMINLINE HALF* XMConvertFloatToHalfStream
- (
- HALF* pOutputStream,
- UINT OutputStride,
- CONST FLOAT* pInputStream,
- UINT InputStride,
- UINT FloatCount
- )
- {
- #if defined(_XM_NO_INTRINSICS_) || defined(_XM_SSE_INTRINSICS_)
- UINT i;
- BYTE* pFloat = (BYTE*)pInputStream;
- BYTE* pHalf = (BYTE*)pOutputStream;
- XMASSERT(pOutputStream);
- XMASSERT(pInputStream);
- for (i = 0; i < FloatCount; i++)
- {
- *(HALF*)pHalf = XMConvertFloatToHalf(*(FLOAT*)pFloat);
- pFloat += InputStride;
- pHalf += OutputStride;
- }
- return pOutputStream;
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- #if defined(_XM_NO_INTRINSICS_) || defined(_XM_SSE_INTRINSICS_)
- // For VMX128, these routines are all defines in the main header
- #pragma warning(push)
- #pragma warning(disable:4701) // Prevent warnings about 'Result' potentially being used without having been initialized
- XMINLINE XMVECTOR XMConvertVectorIntToFloat
- (
- FXMVECTOR VInt,
- UINT DivExponent
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- UINT ElementIndex;
- FLOAT fScale;
- XMVECTOR Result;
- XMASSERT(DivExponent<32);
- fScale = 1.0f / (FLOAT)(1U << DivExponent);
- ElementIndex = 0;
- do {
- INT iTemp = (INT)VInt.vector4_u32[ElementIndex];
- Result.vector4_f32[ElementIndex] = ((FLOAT)iTemp) * fScale;
- } while (++ElementIndex<4);
- return Result;
- #else // _XM_SSE_INTRINSICS_
- XMASSERT(DivExponent<32);
- // Convert to floats
- XMVECTOR vResult = _mm_cvtepi32_ps(reinterpret_cast<const __m128i *>(&VInt)[0]);
- // Convert DivExponent into 1.0f/(1<<DivExponent)
- UINT uScale = 0x3F800000U - (DivExponent << 23);
- // Splat the scalar value
- __m128i vScale = _mm_set1_epi32(uScale);
- vResult = _mm_mul_ps(vResult,reinterpret_cast<const __m128 *>(&vScale)[0]);
- return vResult;
- #endif
- }
- //------------------------------------------------------------------------------
- XMINLINE XMVECTOR XMConvertVectorFloatToInt
- (
- FXMVECTOR VFloat,
- UINT MulExponent
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- UINT ElementIndex;
- XMVECTOR Result;
- FLOAT fScale;
- XMASSERT(MulExponent<32);
- // Get the scalar factor.
- fScale = (FLOAT)(1U << MulExponent);
- ElementIndex = 0;
- do {
- INT iResult;
- FLOAT fTemp = VFloat.vector4_f32[ElementIndex]*fScale;
- if (fTemp <= -(65536.0f*32768.0f)) {
- iResult = (-0x7FFFFFFF)-1;
- } else if (fTemp > (65536.0f*32768.0f)-128.0f) {
- iResult = 0x7FFFFFFF;
- } else {
- iResult = (INT)fTemp;
- }
- Result.vector4_u32[ElementIndex] = (UINT)iResult;
- } while (++ElementIndex<4);
- return Result;
- #else // _XM_SSE_INTRINSICS_
- XMASSERT(MulExponent<32);
- static const XMVECTORF32 MaxInt = {65536.0f*32768.0f-128.0f,65536.0f*32768.0f-128.0f,65536.0f*32768.0f-128.0f,65536.0f*32768.0f-128.0f};
- XMVECTOR vResult = _mm_set_ps1((FLOAT)(1U << MulExponent));
- vResult = _mm_mul_ps(vResult,VFloat);
- // In case of positive overflow, detect it
- XMVECTOR vOverflow = _mm_cmpgt_ps(vResult,MaxInt);
- // Float to int conversion
- __m128i vResulti = _mm_cvttps_epi32(vResult);
- // If there was positive overflow, set to 0x7FFFFFFF
- vResult = _mm_and_ps(vOverflow,g_XMAbsMask);
- vOverflow = _mm_andnot_ps(vOverflow,reinterpret_cast<const __m128 *>(&vResulti)[0]);
- vOverflow = _mm_or_ps(vOverflow,vResult);
- return vOverflow;
- #endif
- }
- //------------------------------------------------------------------------------
- XMINLINE XMVECTOR XMConvertVectorUIntToFloat
- (
- FXMVECTOR VUInt,
- UINT DivExponent
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- UINT ElementIndex;
- FLOAT fScale;
- XMVECTOR Result;
- XMASSERT(DivExponent<32);
- fScale = 1.0f / (FLOAT)(1U << DivExponent);
- ElementIndex = 0;
- do {
- Result.vector4_f32[ElementIndex] = (FLOAT)VUInt.vector4_u32[ElementIndex] * fScale;
- } while (++ElementIndex<4);
- return Result;
- #else // _XM_SSE_INTRINSICS_
- XMASSERT(DivExponent<32);
- static const XMVECTORF32 FixUnsigned = {32768.0f*65536.0f,32768.0f*65536.0f,32768.0f*65536.0f,32768.0f*65536.0f};
- // For the values that are higher than 0x7FFFFFFF, a fixup is needed
- // Determine which ones need the fix.
- XMVECTOR vMask = _mm_and_ps(VUInt,g_XMNegativeZero);
- // Force all values positive
- XMVECTOR vResult = _mm_xor_ps(VUInt,vMask);
- // Convert to floats
- vResult = _mm_cvtepi32_ps(reinterpret_cast<const __m128i *>(&vResult)[0]);
- // Convert 0x80000000 -> 0xFFFFFFFF
- __m128i iMask = _mm_srai_epi32(reinterpret_cast<const __m128i *>(&vMask)[0],31);
- // For only the ones that are too big, add the fixup
- vMask = _mm_and_ps(reinterpret_cast<const __m128 *>(&iMask)[0],FixUnsigned);
- vResult = _mm_add_ps(vResult,vMask);
- // Convert DivExponent into 1.0f/(1<<DivExponent)
- UINT uScale = 0x3F800000U - (DivExponent << 23);
- // Splat
- iMask = _mm_set1_epi32(uScale);
- vResult = _mm_mul_ps(vResult,reinterpret_cast<const __m128 *>(&iMask)[0]);
- return vResult;
- #endif
- }
- //------------------------------------------------------------------------------
- XMINLINE XMVECTOR XMConvertVectorFloatToUInt
- (
- FXMVECTOR VFloat,
- UINT MulExponent
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- UINT ElementIndex;
- XMVECTOR Result;
- FLOAT fScale;
- XMASSERT(MulExponent<32);
- // Get the scalar factor.
- fScale = (FLOAT)(1U << MulExponent);
- ElementIndex = 0;
- do {
- UINT uResult;
- FLOAT fTemp = VFloat.vector4_f32[ElementIndex]*fScale;
- if (fTemp <= 0.0f) {
- uResult = 0;
- } else if (fTemp >= (65536.0f*65536.0f)) {
- uResult = 0xFFFFFFFFU;
- } else {
- uResult = (UINT)fTemp;
- }
- Result.vector4_u32[ElementIndex] = uResult;
- } while (++ElementIndex<4);
- return Result;
- #else // _XM_SSE_INTRINSICS_
- XMASSERT(MulExponent<32);
- static const XMVECTORF32 MaxUInt = {65536.0f*65536.0f-256.0f,65536.0f*65536.0f-256.0f,65536.0f*65536.0f-256.0f,65536.0f*65536.0f-256.0f};
- static const XMVECTORF32 UnsignedFix = {32768.0f*65536.0f,32768.0f*65536.0f,32768.0f*65536.0f,32768.0f*65536.0f};
- XMVECTOR vResult = _mm_set_ps1(static_cast<float>(1U << MulExponent));
- vResult = _mm_mul_ps(vResult,VFloat);
- // Clamp to >=0
- vResult = _mm_max_ps(vResult,g_XMZero);
- // Any numbers that are too big, set to 0xFFFFFFFFU
- XMVECTOR vOverflow = _mm_cmpgt_ps(vResult,MaxUInt);
- XMVECTOR vValue = UnsignedFix;
- // Too large for a signed integer?
- XMVECTOR vMask = _mm_cmpge_ps(vResult,vValue);
- // Zero for number's lower than 0x80000000, 32768.0f*65536.0f otherwise
- vValue = _mm_and_ps(vValue,vMask);
- // Perform fixup only on numbers too large (Keeps low bit precision)
- vResult = _mm_sub_ps(vResult,vValue);
- __m128i vResulti = _mm_cvttps_epi32(vResult);
- // Convert from signed to unsigned pnly if greater than 0x80000000
- vMask = _mm_and_ps(vMask,g_XMNegativeZero);
- vResult = _mm_xor_ps(reinterpret_cast<const __m128 *>(&vResulti)[0],vMask);
- // On those that are too large, set to 0xFFFFFFFF
- vResult = _mm_or_ps(vResult,vOverflow);
- return vResult;
- #endif
- }
- #pragma warning(pop)
- #endif // _XM_NO_INTRINSICS_ || _XM_SSE_INTRINSICS_
- /****************************************************************************
- *
- * Vector and matrix load operations
- *
- ****************************************************************************/
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadInt(CONST UINT* pSource)
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR V;
- XMASSERT(pSource);
- XMASSERT(((UINT_PTR)pSource & 3) == 0);
- V.vector4_u32[0] = *pSource;
- return V;
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pSource);
- XMASSERT(((UINT_PTR)pSource & 3) == 0);
- return _mm_load_ss( (const float*)pSource );
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadFloat(CONST FLOAT* pSource)
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR V;
- XMASSERT(pSource);
- XMASSERT(((UINT_PTR)pSource & 3) == 0);
- V.vector4_f32[0] = *pSource;
- return V;
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pSource);
- XMASSERT(((UINT_PTR)pSource & 3) == 0);
- return _mm_load_ss( pSource );
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadInt2
- (
- CONST UINT* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR V;
- XMASSERT(pSource);
- V.vector4_u32[0] = pSource[0];
- V.vector4_u32[1] = pSource[1];
- return V;
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pSource);
- __m128 x = _mm_load_ss( (const float*)pSource );
- __m128 y = _mm_load_ss( (const float*)(pSource+1) );
- return _mm_unpacklo_ps( x, y );
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadInt2A
- (
- CONST UINT* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR V;
- XMASSERT(pSource);
- XMASSERT(((UINT_PTR)pSource & 0xF) == 0);
- V.vector4_u32[0] = pSource[0];
- V.vector4_u32[1] = pSource[1];
- return V;
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pSource);
- XMASSERT(((UINT_PTR)pSource & 0xF) == 0);
- __m128i V = _mm_loadl_epi64( (const __m128i*)pSource );
- return reinterpret_cast<__m128 *>(&V)[0];
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadFloat2
- (
- CONST XMFLOAT2* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR V;
- XMASSERT(pSource);
- ((UINT *)(&V.vector4_f32[0]))[0] = ((const UINT *)(&pSource->x))[0];
- ((UINT *)(&V.vector4_f32[1]))[0] = ((const UINT *)(&pSource->y))[0];
- return V;
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pSource);
- __m128 x = _mm_load_ss( &pSource->x );
- __m128 y = _mm_load_ss( &pSource->y );
- return _mm_unpacklo_ps( x, y );
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadFloat2A
- (
- CONST XMFLOAT2A* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR V;
- XMASSERT(pSource);
- XMASSERT(((UINT_PTR)pSource & 0xF) == 0);
- V.vector4_f32[0] = pSource->x;
- V.vector4_f32[1] = pSource->y;
- return V;
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pSource);
- XMASSERT(((UINT_PTR)pSource & 0xF) == 0);
- __m128i V = _mm_loadl_epi64( (const __m128i*)pSource );
- return reinterpret_cast<__m128 *>(&V)[0];
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
-
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadHalf2
- (
- CONST XMHALF2* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMASSERT(pSource);
- {
- XMVECTOR vResult = {
- XMConvertHalfToFloat(pSource->x),
- XMConvertHalfToFloat(pSource->y),
- 0.0f,
- 0.0f
- };
- return vResult;
- }
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pSource);
- XMVECTOR vResult = {
- XMConvertHalfToFloat(pSource->x),
- XMConvertHalfToFloat(pSource->y),
- 0.0f,
- 0.0f
- };
- return vResult;
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadShortN2
- (
- CONST XMSHORTN2* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMASSERT(pSource);
- XMASSERT(pSource->x != -32768);
- XMASSERT(pSource->y != -32768);
- {
- XMVECTOR vResult = {
- (FLOAT)pSource->x * (1.0f/32767.0f),
- (FLOAT)pSource->y * (1.0f/32767.0f),
- 0.0f,
- 0.0f
- };
- return vResult;
- }
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pSource);
- XMASSERT(pSource->x != -32768);
- XMASSERT(pSource->y != -32768);
- // Splat the two shorts in all four entries (WORD alignment okay,
- // DWORD alignment preferred)
- __m128 vTemp = _mm_load_ps1(reinterpret_cast<const float *>(&pSource->x));
- // Mask x&0xFFFF, y&0xFFFF0000,z&0,w&0
- vTemp = _mm_and_ps(vTemp,g_XMMaskX16Y16);
- // x needs to be sign extended
- vTemp = _mm_xor_ps(vTemp,g_XMFlipX16Y16);
- // Convert to floating point numbers
- vTemp = _mm_cvtepi32_ps(reinterpret_cast<const __m128i *>(&vTemp)[0]);
- // x - 0x8000 to undo the signed order.
- vTemp = _mm_add_ps(vTemp,g_XMFixX16Y16);
- // Convert 0-32767 to 0.0f-1.0f
- return _mm_mul_ps(vTemp,g_XMNormalizeX16Y16);
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadShort2
- (
- CONST XMSHORT2* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR V;
- XMASSERT(pSource);
- XMASSERT(pSource->x != -32768);
- XMASSERT(pSource->y != -32768);
- V.vector4_f32[0] = (FLOAT)pSource->x;
- V.vector4_f32[1] = (FLOAT)pSource->y;
- return V;
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pSource);
- XMASSERT(pSource->x != -32768);
- XMASSERT(pSource->y != -32768);
- // Splat the two shorts in all four entries (WORD alignment okay,
- // DWORD alignment preferred)
- __m128 vTemp = _mm_load_ps1(reinterpret_cast<const float *>(&pSource->x));
- // Mask x&0xFFFF, y&0xFFFF0000,z&0,w&0
- vTemp = _mm_and_ps(vTemp,g_XMMaskX16Y16);
- // x needs to be sign extended
- vTemp = _mm_xor_ps(vTemp,g_XMFlipX16Y16);
- // Convert to floating point numbers
- vTemp = _mm_cvtepi32_ps(reinterpret_cast<const __m128i *>(&vTemp)[0]);
- // x - 0x8000 to undo the signed order.
- vTemp = _mm_add_ps(vTemp,g_XMFixX16Y16);
- // Y is 65536 too large
- return _mm_mul_ps(vTemp,g_XMFixupY16);
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadUShortN2
- (
- CONST XMUSHORTN2* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR V;
- XMASSERT(pSource);
- V.vector4_f32[0] = (FLOAT)pSource->x / 65535.0f;
- V.vector4_f32[1] = (FLOAT)pSource->y / 65535.0f;
- return V;
- #elif defined(_XM_SSE_INTRINSICS_)
- static const XMVECTORF32 FixupY16 = {1.0f/65535.0f,1.0f/(65535.0f*65536.0f),0.0f,0.0f};
- static const XMVECTORF32 FixaddY16 = {0,32768.0f*65536.0f,0,0};
- XMASSERT(pSource);
- // Splat the two shorts in all four entries (WORD alignment okay,
- // DWORD alignment preferred)
- __m128 vTemp = _mm_load_ps1(reinterpret_cast<const float *>(&pSource->x));
- // Mask x&0xFFFF, y&0xFFFF0000,z&0,w&0
- vTemp = _mm_and_ps(vTemp,g_XMMaskX16Y16);
- // y needs to be sign flipped
- vTemp = _mm_xor_ps(vTemp,g_XMFlipY);
- // Convert to floating point numbers
- vTemp = _mm_cvtepi32_ps(reinterpret_cast<const __m128i *>(&vTemp)[0]);
- // y + 0x8000 to undo the signed order.
- vTemp = _mm_add_ps(vTemp,FixaddY16);
- // Y is 65536 times too large
- vTemp = _mm_mul_ps(vTemp,FixupY16);
- return vTemp;
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadUShort2
- (
- CONST XMUSHORT2* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR V;
- XMASSERT(pSource);
- V.vector4_f32[0] = (FLOAT)pSource->x;
- V.vector4_f32[1] = (FLOAT)pSource->y;
- return V;
- #elif defined(_XM_SSE_INTRINSICS_)
- static const XMVECTORF32 FixaddY16 = {0,32768.0f,0,0};
- XMASSERT(pSource);
- // Splat the two shorts in all four entries (WORD alignment okay,
- // DWORD alignment preferred)
- __m128 vTemp = _mm_load_ps1(reinterpret_cast<const float *>(&pSource->x));
- // Mask x&0xFFFF, y&0xFFFF0000,z&0,w&0
- vTemp = _mm_and_ps(vTemp,g_XMMaskX16Y16);
- // y needs to be sign flipped
- vTemp = _mm_xor_ps(vTemp,g_XMFlipY);
- // Convert to floating point numbers
- vTemp = _mm_cvtepi32_ps(reinterpret_cast<const __m128i *>(&vTemp)[0]);
- // Y is 65536 times too large
- vTemp = _mm_mul_ps(vTemp,g_XMFixupY16);
- // y + 0x8000 to undo the signed order.
- vTemp = _mm_add_ps(vTemp,FixaddY16);
- return vTemp;
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadInt3
- (
- CONST UINT* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR V;
- XMASSERT(pSource);
- V.vector4_u32[0] = pSource[0];
- V.vector4_u32[1] = pSource[1];
- V.vector4_u32[2] = pSource[2];
- return V;
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pSource);
- #ifdef _XM_ISVS2005_
- __m128i V = _mm_set_epi32( 0, *(pSource+2), *(pSource+1), *pSource );
- return reinterpret_cast<__m128 *>(&V)[0];
- #else
- __m128 x = _mm_load_ss( (const float*)pSource );
- __m128 y = _mm_load_ss( (const float*)(pSource+1) );
- __m128 z = _mm_load_ss( (const float*)(pSource+2) );
- __m128 xy = _mm_unpacklo_ps( x, y );
- return _mm_movelh_ps( xy, z );
- #endif // !_XM_ISVS2005_
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadInt3A
- (
- CONST UINT* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR V;
- XMASSERT(pSource);
- XMASSERT(((UINT_PTR)pSource & 0xF) == 0);
- V.vector4_u32[0] = pSource[0];
- V.vector4_u32[1] = pSource[1];
- V.vector4_u32[2] = pSource[2];
- return V;
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pSource);
- // Reads an extra integer that is 'undefined'
- __m128i V = _mm_load_si128( (const __m128i*)pSource );
- return reinterpret_cast<__m128 *>(&V)[0];
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadFloat3
- (
- CONST XMFLOAT3* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR V;
- XMASSERT(pSource);
- ((UINT *)(&V.vector4_f32[0]))[0] = ((const UINT *)(&pSource->x))[0];
- ((UINT *)(&V.vector4_f32[1]))[0] = ((const UINT *)(&pSource->y))[0];
- ((UINT *)(&V.vector4_f32[2]))[0] = ((const UINT *)(&pSource->z))[0];
- return V;
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pSource);
- #ifdef _XM_ISVS2005_
- // This reads 1 floats past the memory that should be ignored.
- // Need to continue to do this for VS 2005 due to compiler issue but prefer new method
- // to avoid triggering issues with memory debug tools (like AV)
- return _mm_loadu_ps( &pSource->x );
- #else
- __m128 x = _mm_load_ss( &pSource->x );
- __m128 y = _mm_load_ss( &pSource->y );
- __m128 z = _mm_load_ss( &pSource->z );
- __m128 xy = _mm_unpacklo_ps( x, y );
- return _mm_movelh_ps( xy, z );
- #endif // !_XM_ISVS2005_
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadFloat3A
- (
- CONST XMFLOAT3A* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR V;
- XMASSERT(pSource);
- XMASSERT(((UINT_PTR)pSource & 0xF) == 0);
- V.vector4_f32[0] = pSource->x;
- V.vector4_f32[1] = pSource->y;
- V.vector4_f32[2] = pSource->z;
- return V;
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pSource);
- XMASSERT(((UINT_PTR)pSource & 0xF) == 0);
- // This reads 1 floats past the memory that should be ignored.
- return _mm_load_ps( &pSource->x );
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadUHenDN3
- (
- CONST XMUHENDN3* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR V;
- UINT Element;
- XMASSERT(pSource);
- Element = pSource->v & 0x7FF;
- V.vector4_f32[0] = (FLOAT)Element / 2047.0f;
- Element = (pSource->v >> 11) & 0x7FF;
- V.vector4_f32[1] = (FLOAT)Element / 2047.0f;
- Element = (pSource->v >> 22) & 0x3FF;
- V.vector4_f32[2] = (FLOAT)Element / 1023.0f;
- return V;
- #elif defined(_XM_SSE_INTRINSICS_)
- static const XMVECTORF32 UHenDN3Mul = {1.0f/2047.0f,1.0f/(2047.0f*2048.0f),1.0f/(1023.0f*2048.0f*2048.0f),0};
- XMASSERT(pSource);
- // Get the 32 bit value and splat it
- XMVECTOR vResult = _mm_load_ps1(reinterpret_cast<const float *>(&pSource->v));
- // Mask off x, y and z
- vResult = _mm_and_ps(vResult,g_XMMaskHenD3);
- // Convert x and y to unsigned
- vResult = _mm_xor_ps(vResult,g_XMFlipZ);
- // Convert to float
- vResult = _mm_cvtepi32_ps(reinterpret_cast<const __m128i *>(&vResult)[0]);
- // Convert x and y back to signed
- vResult = _mm_add_ps(vResult,g_XMAddUHenD3);
- // Normalize x,y and z to -1.0f-1.0f
- vResult = _mm_mul_ps(vResult,UHenDN3Mul);
- return vResult;
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadUHenD3
- (
- CONST XMUHEND3* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR V;
- UINT Element;
- XMASSERT(pSource);
- Element = pSource->v & 0x7FF;
- V.vector4_f32[0] = (FLOAT)Element;
- Element = (pSource->v >> 11) & 0x7FF;
- V.vector4_f32[1] = (FLOAT)Element;
- Element = (pSource->v >> 22) & 0x3FF;
- V.vector4_f32[2] = (FLOAT)Element;
- return V;
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pSource);
- // Get the 32 bit value and splat it
- XMVECTOR vResult = _mm_load_ps1(reinterpret_cast<const float *>(&pSource->v));
- // Mask off x, y and z
- vResult = _mm_and_ps(vResult,g_XMMaskHenD3);
- // Convert x and y to unsigned
- vResult = _mm_xor_ps(vResult,g_XMFlipZ);
- // Convert to float
- vResult = _mm_cvtepi32_ps(reinterpret_cast<const __m128i *>(&vResult)[0]);
- // Convert x and y back to signed
- vResult = _mm_add_ps(vResult,g_XMAddUHenD3);
- // Normalize x and y to -1024-1023.0f and z to -512-511.0f
- vResult = _mm_mul_ps(vResult,g_XMMulHenD3);
- return vResult;
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadHenDN3
- (
- CONST XMHENDN3* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR V;
- UINT Element;
- static CONST UINT SignExtendXY[] = {0x00000000, 0xFFFFF800};
- static CONST UINT SignExtendZ[] = {0x00000000, 0xFFFFFC00};
- XMASSERT(pSource);
- XMASSERT((pSource->v & 0x7FF) != 0x400);
- XMASSERT(((pSource->v >> 11) & 0x7FF) != 0x400);
- XMASSERT(((pSource->v >> 22) & 0x3FF) != 0x200);
- Element = pSource->v & 0x7FF;
- V.vector4_f32[0] = (FLOAT)(SHORT)(Element | SignExtendXY[Element >> 10]) / 1023.0f;
- Element = (pSource->v >> 11) & 0x7FF;
- V.vector4_f32[1] = (FLOAT)(SHORT)(Element | SignExtendXY[Element >> 10]) / 1023.0f;
- Element = (pSource->v >> 22) & 0x3FF;
- V.vector4_f32[2] = (FLOAT)(SHORT)(Element | SignExtendZ[Element >> 9]) / 511.0f;
- return V;
- #elif defined(_XM_SSE_INTRINSICS_)
- static const XMVECTORF32 HenDN3Mul = {1.0f/1023.0f,1.0f/(1023.0f*2048.0f),1.0f/(511.0f*2048.0f*2048.0f),0};
- XMASSERT(pSource);
- XMASSERT((pSource->v & 0x7FF) != 0x400);
- XMASSERT(((pSource->v >> 11) & 0x7FF) != 0x400);
- XMASSERT(((pSource->v >> 22) & 0x3FF) != 0x200);
- // Get the 32 bit value and splat it
- XMVECTOR vResult = _mm_load_ps1(reinterpret_cast<const float *>(&pSource->v));
- // Mask off x, y and z
- vResult = _mm_and_ps(vResult,g_XMMaskHenD3);
- // Convert x and y to unsigned
- vResult = _mm_xor_ps(vResult,g_XMXorHenD3);
- // Convert to float
- vResult = _mm_cvtepi32_ps(reinterpret_cast<const __m128i *>(&vResult)[0]);
- // Convert x and y back to signed
- vResult = _mm_add_ps(vResult,g_XMAddHenD3);
- // Normalize x,y and z to -1.0f-1.0f
- vResult = _mm_mul_ps(vResult,HenDN3Mul);
- return vResult;
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadHenD3
- (
- CONST XMHEND3* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR V;
- UINT Element;
- static CONST UINT SignExtendXY[] = {0x00000000, 0xFFFFF800};
- static CONST UINT SignExtendZ[] = {0x00000000, 0xFFFFFC00};
- XMASSERT(pSource);
- XMASSERT((pSource->v & 0x7FF) != 0x400);
- XMASSERT(((pSource->v >> 11) & 0x7FF) != 0x400);
- XMASSERT(((pSource->v >> 22) & 0x3FF) != 0x200);
- Element = pSource->v & 0x7FF;
- V.vector4_f32[0] = (FLOAT)(SHORT)(Element | SignExtendXY[Element >> 10]);
- Element = (pSource->v >> 11) & 0x7FF;
- V.vector4_f32[1] = (FLOAT)(SHORT)(Element | SignExtendXY[Element >> 10]);
- Element = (pSource->v >> 22) & 0x3FF;
- V.vector4_f32[2] = (FLOAT)(SHORT)(Element | SignExtendZ[Element >> 9]);
- return V;
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pSource);
- XMASSERT((pSource->v & 0x7FF) != 0x400);
- XMASSERT(((pSource->v >> 11) & 0x7FF) != 0x400);
- XMASSERT(((pSource->v >> 22) & 0x3FF) != 0x200);
- // Get the 32 bit value and splat it
- XMVECTOR vResult = _mm_load_ps1(reinterpret_cast<const float *>(&pSource->v));
- // Mask off x, y and z
- vResult = _mm_and_ps(vResult,g_XMMaskHenD3);
- // Convert x and y to unsigned
- vResult = _mm_xor_ps(vResult,g_XMXorHenD3);
- // Convert to float
- vResult = _mm_cvtepi32_ps(reinterpret_cast<const __m128i *>(&vResult)[0]);
- // Convert x and y back to signed
- vResult = _mm_add_ps(vResult,g_XMAddHenD3);
- // Normalize x and y to -1024-1023.0f and z to -512-511.0f
- vResult = _mm_mul_ps(vResult,g_XMMulHenD3);
- return vResult;
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadUDHenN3
- (
- CONST XMUDHENN3* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR V;
- UINT Element;
- XMASSERT(pSource);
- Element = pSource->v & 0x3FF;
- V.vector4_f32[0] = (FLOAT)Element / 1023.0f;
- Element = (pSource->v >> 10) & 0x7FF;
- V.vector4_f32[1] = (FLOAT)Element / 2047.0f;
- Element = (pSource->v >> 21) & 0x7FF;
- V.vector4_f32[2] = (FLOAT)Element / 2047.0f;
- return V;
- #elif defined(_XM_SSE_INTRINSICS_)
- static const XMVECTORF32 UDHenN3Mul = {1.0f/1023.0f,1.0f/(2047.0f*1024.0f),1.0f/(2047.0f*1024.0f*2048.0f),0};
- XMASSERT(pSource);
- // Get the 32 bit value and splat it
- XMVECTOR vResult = _mm_load_ps1(reinterpret_cast<const float *>(&pSource->v));
- // Mask off x, y and z
- vResult = _mm_and_ps(vResult,g_XMMaskDHen3);
- // Convert x and y to unsigned
- vResult = _mm_xor_ps(vResult,g_XMFlipZ);
- // Convert to float
- vResult = _mm_cvtepi32_ps(reinterpret_cast<const __m128i *>(&vResult)[0]);
- // Convert x and y back to signed
- vResult = _mm_add_ps(vResult,g_XMAddUHenD3);
- // Normalize x,y and z to -1.0f-1.0f
- vResult = _mm_mul_ps(vResult,UDHenN3Mul);
- return vResult;
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadUDHen3
- (
- CONST XMUDHEN3* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR V;
- UINT Element;
- XMASSERT(pSource);
- Element = pSource->v & 0x3FF;
- V.vector4_f32[0] = (FLOAT)Element;
- Element = (pSource->v >> 10) & 0x7FF;
- V.vector4_f32[1] = (FLOAT)Element;
- Element = (pSource->v >> 21) & 0x7FF;
- V.vector4_f32[2] = (FLOAT)Element;
- return V;
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pSource);
- // Get the 32 bit value and splat it
- XMVECTOR vResult = _mm_load_ps1(reinterpret_cast<const float *>(&pSource->v));
- // Mask off x, y and z
- vResult = _mm_and_ps(vResult,g_XMMaskDHen3);
- // Convert x and y to unsigned
- vResult = _mm_xor_ps(vResult,g_XMFlipZ);
- // Convert to float
- vResult = _mm_cvtepi32_ps(reinterpret_cast<const __m128i *>(&vResult)[0]);
- // Convert x and y back to signed
- vResult = _mm_add_ps(vResult,g_XMAddUHenD3);
- // Normalize x to 0-1023.0f and y and z to 0-2047.0f
- vResult = _mm_mul_ps(vResult,g_XMMulDHen3);
- return vResult;
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadDHenN3
- (
- CONST XMDHENN3* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR V;
- UINT Element;
- static CONST UINT SignExtendX[] = {0x00000000, 0xFFFFFC00};
- static CONST UINT SignExtendYZ[] = {0x00000000, 0xFFFFF800};
- XMASSERT(pSource);
- XMASSERT((pSource->v & 0x3FF) != 0x200);
- XMASSERT(((pSource->v >> 10) & 0x7FF) != 0x400);
- XMASSERT(((pSource->v >> 21) & 0x7FF) != 0x400);
- Element = pSource->v & 0x3FF;
- V.vector4_f32[0] = (FLOAT)(SHORT)(Element | SignExtendX[Element >> 9]) / 511.0f;
- Element = (pSource->v >> 10) & 0x7FF;
- V.vector4_f32[1] = (FLOAT)(SHORT)(Element | SignExtendYZ[Element >> 10]) / 1023.0f;
- Element = (pSource->v >> 21) & 0x7FF;
- V.vector4_f32[2] = (FLOAT)(SHORT)(Element | SignExtendYZ[Element >> 10]) / 1023.0f;
- return V;
- #elif defined(_XM_SSE_INTRINSICS_)
- static const XMVECTORF32 DHenN3Mul = {1.0f/511.0f,1.0f/(1023.0f*1024.0f),1.0f/(1023.0f*1024.0f*2048.0f),0};
- XMASSERT(pSource);
- XMASSERT((pSource->v & 0x3FF) != 0x200);
- XMASSERT(((pSource->v >> 10) & 0x7FF) != 0x400);
- XMASSERT(((pSource->v >> 21) & 0x7FF) != 0x400);
- // Get the 32 bit value and splat it
- XMVECTOR vResult = _mm_load_ps1(reinterpret_cast<const float *>(&pSource->v));
- // Mask off x, y and z
- vResult = _mm_and_ps(vResult,g_XMMaskDHen3);
- // Convert x and y to unsigned
- vResult = _mm_xor_ps(vResult,g_XMXorDHen3);
- // Convert to float
- vResult = _mm_cvtepi32_ps(reinterpret_cast<const __m128i *>(&vResult)[0]);
- // Convert x and y back to signed
- vResult = _mm_add_ps(vResult,g_XMAddDHen3);
- // Normalize x,y and z to -1.0f-1.0f
- vResult = _mm_mul_ps(vResult,DHenN3Mul);
- return vResult;
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadDHen3
- (
- CONST XMDHEN3* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR V;
- UINT Element;
- static CONST UINT SignExtendX[] = {0x00000000, 0xFFFFFC00};
- static CONST UINT SignExtendYZ[] = {0x00000000, 0xFFFFF800};
- XMASSERT(pSource);
- XMASSERT((pSource->v & 0x3FF) != 0x200);
- XMASSERT(((pSource->v >> 10) & 0x7FF) != 0x400);
- XMASSERT(((pSource->v >> 21) & 0x7FF) != 0x400);
- Element = pSource->v & 0x3FF;
- V.vector4_f32[0] = (FLOAT)(SHORT)(Element | SignExtendX[Element >> 9]);
- Element = (pSource->v >> 10) & 0x7FF;
- V.vector4_f32[1] = (FLOAT)(SHORT)(Element | SignExtendYZ[Element >> 10]);
- Element = (pSource->v >> 21) & 0x7FF;
- V.vector4_f32[2] = (FLOAT)(SHORT)(Element | SignExtendYZ[Element >> 10]);
- return V;
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pSource);
- XMASSERT((pSource->v & 0x3FF) != 0x200);
- XMASSERT(((pSource->v >> 10) & 0x7FF) != 0x400);
- XMASSERT(((pSource->v >> 21) & 0x7FF) != 0x400);
- // Get the 32 bit value and splat it
- XMVECTOR vResult = _mm_load_ps1(reinterpret_cast<const float *>(&pSource->v));
- // Mask off x, y and z
- vResult = _mm_and_ps(vResult,g_XMMaskDHen3);
- // Convert x and y to unsigned
- vResult = _mm_xor_ps(vResult,g_XMXorDHen3);
- // Convert to float
- vResult = _mm_cvtepi32_ps(reinterpret_cast<const __m128i *>(&vResult)[0]);
- // Convert x and y back to signed
- vResult = _mm_add_ps(vResult,g_XMAddDHen3);
- // Normalize x to -210-511.0f and y and z to -1024-1023.0f
- vResult = _mm_mul_ps(vResult,g_XMMulDHen3);
- return vResult;
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadU565
- (
- CONST XMU565* pSource
- )
- {
- #if defined(_XM_SSE_INTRINSICS_) && !defined(_XM_NO_INTRINSICS_)
- static const XMVECTORI32 U565And = {0x1F,0x3F<<5,0x1F<<11,0};
- static const XMVECTORF32 U565Mul = {1.0f,1.0f/32.0f,1.0f/2048.f,0};
- XMASSERT(pSource);
- // Get the 32 bit value and splat it
- XMVECTOR vResult = _mm_load_ps1(reinterpret_cast<const float *>(&pSource->v));
- // Mask off x, y and z
- vResult = _mm_and_ps(vResult,U565And);
- // Convert to float
- vResult = _mm_cvtepi32_ps(reinterpret_cast<const __m128i *>(&vResult)[0]);
- // Normalize x, y, and z
- vResult = _mm_mul_ps(vResult,U565Mul);
- return vResult;
- #else
- XMVECTOR V;
- UINT Element;
- XMASSERT(pSource);
- Element = pSource->v & 0x1F;
- V.vector4_f32[0] = (FLOAT)Element;
- Element = (pSource->v >> 5) & 0x3F;
- V.vector4_f32[1] = (FLOAT)Element;
- Element = (pSource->v >> 11) & 0x1F;
- V.vector4_f32[2] = (FLOAT)Element;
- return V;
- #endif // !_XM_SSE_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadFloat3PK
- (
- CONST XMFLOAT3PK* pSource
- )
- {
- _DECLSPEC_ALIGN_16_ UINT Result[4];
- UINT Mantissa;
- UINT Exponent;
- XMASSERT(pSource);
- // X Channel (6-bit mantissa)
- Mantissa = pSource->xm;
- if ( pSource->xe == 0x1f ) // INF or NAN
- {
- Result[0] = 0x7f800000 | (pSource->xm << 17);
- }
- else
- {
- if ( pSource->xe != 0 ) // The value is normalized
- {
- Exponent = pSource->xe;
- }
- else if (Mantissa != 0) // The value is denormalized
- {
- // Normalize the value in the resulting float
- Exponent = 1;
-
- do
- {
- Exponent--;
- Mantissa <<= 1;
- } while ((Mantissa & 0x40) == 0);
-
- Mantissa &= 0x3F;
- }
- else // The value is zero
- {
- Exponent = (UINT)-112;
- }
-
- Result[0] = ((Exponent + 112) << 23) | (Mantissa << 17);
- }
- // Y Channel (6-bit mantissa)
- Mantissa = pSource->ym;
- if ( pSource->ye == 0x1f ) // INF or NAN
- {
- Result[1] = 0x7f800000 | (pSource->ym << 17);
- }
- else
- {
- if ( pSource->ye != 0 ) // The value is normalized
- {
- Exponent = pSource->ye;
- }
- else if (Mantissa != 0) // The value is denormalized
- {
- // Normalize the value in the resulting float
- Exponent = 1;
-
- do
- {
- Exponent--;
- Mantissa <<= 1;
- } while ((Mantissa & 0x40) == 0);
-
- Mantissa &= 0x3F;
- }
- else // The value is zero
- {
- Exponent = (UINT)-112;
- }
-
- Result[1] = ((Exponent + 112) << 23) | (Mantissa << 17);
- }
- // Z Channel (5-bit mantissa)
- Mantissa = pSource->zm;
- if ( pSource->ze == 0x1f ) // INF or NAN
- {
- Result[2] = 0x7f800000 | (pSource->zm << 17);
- }
- else
- {
- if ( pSource->ze != 0 ) // The value is normalized
- {
- Exponent = pSource->ze;
- }
- else if (Mantissa != 0) // The value is denormalized
- {
- // Normalize the value in the resulting float
- Exponent = 1;
-
- do
- {
- Exponent--;
- Mantissa <<= 1;
- } while ((Mantissa & 0x20) == 0);
-
- Mantissa &= 0x1F;
- }
- else // The value is zero
- {
- Exponent = (UINT)-112;
- }
- Result[2] = ((Exponent + 112) << 23) | (Mantissa << 18);
- }
- return XMLoadFloat3A( (XMFLOAT3A*)&Result );
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadFloat3SE
- (
- CONST XMFLOAT3SE* pSource
- )
- {
- _DECLSPEC_ALIGN_16_ UINT Result[4];
- UINT Mantissa;
- UINT Exponent, ExpBits;
- XMASSERT(pSource);
- if ( pSource->e == 0x1f ) // INF or NAN
- {
- Result[0] = 0x7f800000 | (pSource->xm << 14);
- Result[1] = 0x7f800000 | (pSource->ym << 14);
- Result[2] = 0x7f800000 | (pSource->zm << 14);
- }
- else if ( pSource->e != 0 ) // The values are all normalized
- {
- Exponent = pSource->e;
- ExpBits = (Exponent + 112) << 23;
- Mantissa = pSource->xm;
- Result[0] = ExpBits | (Mantissa << 14);
- Mantissa = pSource->ym;
- Result[1] = ExpBits | (Mantissa << 14);
- Mantissa = pSource->zm;
- Result[2] = ExpBits | (Mantissa << 14);
- }
- else
- {
- // X Channel
- Mantissa = pSource->xm;
- if (Mantissa != 0) // The value is denormalized
- {
- // Normalize the value in the resulting float
- Exponent = 1;
- do
- {
- Exponent--;
- Mantissa <<= 1;
- } while ((Mantissa & 0x200) == 0);
- Mantissa &= 0x1FF;
- }
- else // The value is zero
- {
- Exponent = (UINT)-112;
- }
- Result[0] = ((Exponent + 112) << 23) | (Mantissa << 14);
- // Y Channel
- Mantissa = pSource->ym;
- if (Mantissa != 0) // The value is denormalized
- {
- // Normalize the value in the resulting float
- Exponent = 1;
- do
- {
- Exponent--;
- Mantissa <<= 1;
- } while ((Mantissa & 0x200) == 0);
- Mantissa &= 0x1FF;
- }
- else // The value is zero
- {
- Exponent = (UINT)-112;
- }
- Result[1] = ((Exponent + 112) << 23) | (Mantissa << 14);
- // Z Channel
- Mantissa = pSource->zm;
- if (Mantissa != 0) // The value is denormalized
- {
- // Normalize the value in the resulting float
- Exponent = 1;
- do
- {
- Exponent--;
- Mantissa <<= 1;
- } while ((Mantissa & 0x200) == 0);
- Mantissa &= 0x1FF;
- }
- else // The value is zero
- {
- Exponent = (UINT)-112;
- }
- Result[2] = ((Exponent + 112) << 23) | (Mantissa << 14);
- }
- return XMLoadFloat3A( (XMFLOAT3A*)&Result );
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadInt4
- (
- CONST UINT* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR V;
- XMASSERT(pSource);
- V.vector4_u32[0] = pSource[0];
- V.vector4_u32[1] = pSource[1];
- V.vector4_u32[2] = pSource[2];
- V.vector4_u32[3] = pSource[3];
- return V;
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pSource);
- __m128i V = _mm_loadu_si128( (const __m128i*)pSource );
- return reinterpret_cast<__m128 *>(&V)[0];
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadInt4A
- (
- CONST UINT* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR V;
- XMASSERT(pSource);
- XMASSERT(((UINT_PTR)pSource & 0xF) == 0);
- V.vector4_u32[0] = pSource[0];
- V.vector4_u32[1] = pSource[1];
- V.vector4_u32[2] = pSource[2];
- V.vector4_u32[3] = pSource[3];
- return V;
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pSource);
- XMASSERT(((UINT_PTR)pSource & 0xF) == 0);
- __m128i V = _mm_load_si128( (const __m128i*)pSource );
- return reinterpret_cast<__m128 *>(&V)[0];
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadFloat4
- (
- CONST XMFLOAT4* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR V;
- XMASSERT(pSource);
- ((UINT *)(&V.vector4_f32[0]))[0] = ((const UINT *)(&pSource->x))[0];
- ((UINT *)(&V.vector4_f32[1]))[0] = ((const UINT *)(&pSource->y))[0];
- ((UINT *)(&V.vector4_f32[2]))[0] = ((const UINT *)(&pSource->z))[0];
- ((UINT *)(&V.vector4_f32[3]))[0] = ((const UINT *)(&pSource->w))[0];
- return V;
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pSource);
- return _mm_loadu_ps( &pSource->x );
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadFloat4A
- (
- CONST XMFLOAT4A* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR V;
- XMASSERT(pSource);
- XMASSERT(((UINT_PTR)pSource & 0xF) == 0);
- V.vector4_f32[0] = pSource->x;
- V.vector4_f32[1] = pSource->y;
- V.vector4_f32[2] = pSource->z;
- V.vector4_f32[3] = pSource->w;
- return V;
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pSource);
- XMASSERT(((UINT_PTR)pSource & 0xF) == 0);
- return _mm_load_ps( &pSource->x );
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadHalf4
- (
- CONST XMHALF4* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMASSERT(pSource);
- {
- XMVECTOR vResult = {
- XMConvertHalfToFloat(pSource->x),
- XMConvertHalfToFloat(pSource->y),
- XMConvertHalfToFloat(pSource->z),
- XMConvertHalfToFloat(pSource->w)
- };
- return vResult;
- }
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pSource);
- XMVECTOR vResult = {
- XMConvertHalfToFloat(pSource->x),
- XMConvertHalfToFloat(pSource->y),
- XMConvertHalfToFloat(pSource->z),
- XMConvertHalfToFloat(pSource->w)
- };
- return vResult;
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadShortN4
- (
- CONST XMSHORTN4* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMASSERT(pSource);
- XMASSERT(pSource->x != -32768);
- XMASSERT(pSource->y != -32768);
- XMASSERT(pSource->z != -32768);
- XMASSERT(pSource->w != -32768);
- {
- XMVECTOR vResult = {
- (FLOAT)pSource->x * (1.0f/32767.0f),
- (FLOAT)pSource->y * (1.0f/32767.0f),
- (FLOAT)pSource->z * (1.0f/32767.0f),
- (FLOAT)pSource->w * (1.0f/32767.0f)
- };
- return vResult;
- }
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pSource);
- XMASSERT(pSource->x != -32768);
- XMASSERT(pSource->y != -32768);
- XMASSERT(pSource->z != -32768);
- XMASSERT(pSource->w != -32768);
- // Splat the color in all four entries (x,z,y,w)
- __m128d vIntd = _mm_load1_pd(reinterpret_cast<const double *>(&pSource->x));
- // Shift x&0ffff,z&0xffff,y&0xffff0000,w&0xffff0000
- __m128 vTemp = _mm_and_ps(reinterpret_cast<const __m128 *>(&vIntd)[0],g_XMMaskX16Y16Z16W16);
- // x and z are unsigned! Flip the bits to convert the order to signed
- vTemp = _mm_xor_ps(vTemp,g_XMFlipX16Y16Z16W16);
- // Convert to floating point numbers
- vTemp = _mm_cvtepi32_ps(reinterpret_cast<const __m128i *>(&vTemp)[0]);
- // x and z - 0x8000 to complete the conversion
- vTemp = _mm_add_ps(vTemp,g_XMFixX16Y16Z16W16);
- // Convert -32767-32767 to -1.0f-1.0f
- vTemp = _mm_mul_ps(vTemp,g_XMNormalizeX16Y16Z16W16);
- // Very important! The entries are x,z,y,w, flip it to x,y,z,w
- vTemp = _mm_shuffle_ps(vTemp,vTemp,_MM_SHUFFLE(3,1,2,0));
- return vTemp;
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadShort4
- (
- CONST XMSHORT4* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR V;
- XMASSERT(pSource);
- XMASSERT(pSource->x != -32768);
- XMASSERT(pSource->y != -32768);
- XMASSERT(pSource->z != -32768);
- XMASSERT(pSource->w != -32768);
- V.vector4_f32[0] = (FLOAT)pSource->x;
- V.vector4_f32[1] = (FLOAT)pSource->y;
- V.vector4_f32[2] = (FLOAT)pSource->z;
- V.vector4_f32[3] = (FLOAT)pSource->w;
- return V;
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pSource);
- XMASSERT(pSource->x != -32768);
- XMASSERT(pSource->y != -32768);
- XMASSERT(pSource->z != -32768);
- XMASSERT(pSource->w != -32768);
- // Splat the color in all four entries (x,z,y,w)
- __m128d vIntd = _mm_load1_pd(reinterpret_cast<const double *>(&pSource->x));
- // Shift x&0ffff,z&0xffff,y&0xffff0000,w&0xffff0000
- __m128 vTemp = _mm_and_ps(reinterpret_cast<const __m128 *>(&vIntd)[0],g_XMMaskX16Y16Z16W16);
- // x and z are unsigned! Flip the bits to convert the order to signed
- vTemp = _mm_xor_ps(vTemp,g_XMFlipX16Y16Z16W16);
- // Convert to floating point numbers
- vTemp = _mm_cvtepi32_ps(reinterpret_cast<const __m128i *>(&vTemp)[0]);
- // x and z - 0x8000 to complete the conversion
- vTemp = _mm_add_ps(vTemp,g_XMFixX16Y16Z16W16);
- // Fix y and w because they are 65536 too large
- vTemp = _mm_mul_ps(vTemp,g_XMFixupY16W16);
- // Very important! The entries are x,z,y,w, flip it to x,y,z,w
- return _mm_shuffle_ps(vTemp,vTemp,_MM_SHUFFLE(3,1,2,0));
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadUShortN4
- (
- CONST XMUSHORTN4* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR V;
- XMASSERT(pSource);
- V.vector4_f32[0] = (FLOAT)pSource->x / 65535.0f;
- V.vector4_f32[1] = (FLOAT)pSource->y / 65535.0f;
- V.vector4_f32[2] = (FLOAT)pSource->z / 65535.0f;
- V.vector4_f32[3] = (FLOAT)pSource->w / 65535.0f;
- return V;
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pSource);
- static const XMVECTORF32 FixupY16W16 = {1.0f/65535.0f,1.0f/65535.0f,1.0f/(65535.0f*65536.0f),1.0f/(65535.0f*65536.0f)};
- static const XMVECTORF32 FixaddY16W16 = {0,0,32768.0f*65536.0f,32768.0f*65536.0f};
- XMASSERT(pSource);
- // Splat the color in all four entries (x,z,y,w)
- __m128d vIntd = _mm_load1_pd(reinterpret_cast<const double *>(&pSource->x));
- // Shift x&0ffff,z&0xffff,y&0xffff0000,w&0xffff0000
- __m128 vTemp = _mm_and_ps(reinterpret_cast<const __m128 *>(&vIntd)[0],g_XMMaskX16Y16Z16W16);
- // y and w are signed! Flip the bits to convert the order to unsigned
- vTemp = _mm_xor_ps(vTemp,g_XMFlipZW);
- // Convert to floating point numbers
- vTemp = _mm_cvtepi32_ps(reinterpret_cast<const __m128i *>(&vTemp)[0]);
- // y and w + 0x8000 to complete the conversion
- vTemp = _mm_add_ps(vTemp,FixaddY16W16);
- // Fix y and w because they are 65536 too large
- vTemp = _mm_mul_ps(vTemp,FixupY16W16);
- // Very important! The entries are x,z,y,w, flip it to x,y,z,w
- return _mm_shuffle_ps(vTemp,vTemp,_MM_SHUFFLE(3,1,2,0));
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadUShort4
- (
- CONST XMUSHORT4* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR V;
- XMASSERT(pSource);
- V.vector4_f32[0] = (FLOAT)pSource->x;
- V.vector4_f32[1] = (FLOAT)pSource->y;
- V.vector4_f32[2] = (FLOAT)pSource->z;
- V.vector4_f32[3] = (FLOAT)pSource->w;
- return V;
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pSource);
- static const XMVECTORF32 FixaddY16W16 = {0,0,32768.0f,32768.0f};
- XMASSERT(pSource);
- // Splat the color in all four entries (x,z,y,w)
- __m128d vIntd = _mm_load1_pd(reinterpret_cast<const double *>(&pSource->x));
- // Shift x&0ffff,z&0xffff,y&0xffff0000,w&0xffff0000
- __m128 vTemp = _mm_and_ps(reinterpret_cast<const __m128 *>(&vIntd)[0],g_XMMaskX16Y16Z16W16);
- // y and w are signed! Flip the bits to convert the order to unsigned
- vTemp = _mm_xor_ps(vTemp,g_XMFlipZW);
- // Convert to floating point numbers
- vTemp = _mm_cvtepi32_ps(reinterpret_cast<const __m128i *>(&vTemp)[0]);
- // Fix y and w because they are 65536 too large
- vTemp = _mm_mul_ps(vTemp,g_XMFixupY16W16);
- // y and w + 0x8000 to complete the conversion
- vTemp = _mm_add_ps(vTemp,FixaddY16W16);
- // Very important! The entries are x,z,y,w, flip it to x,y,z,w
- return _mm_shuffle_ps(vTemp,vTemp,_MM_SHUFFLE(3,1,2,0));
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadXIcoN4
- (
- CONST XMXICON4* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR V;
- UINT Element;
- static CONST UINT SignExtend[] = {0x00000000, 0xFFF00000};
- XMASSERT(pSource);
- XMASSERT((pSource->v & 0xFFFFFull) != 0x80000ull);
- XMASSERT(((pSource->v >> 20) & 0xFFFFFull) != 0x80000ull);
- XMASSERT(((pSource->v >> 40) & 0xFFFFFull) != 0x80000ull);
- Element = (UINT)(pSource->v & 0xFFFFF);
- V.vector4_f32[0] = (FLOAT)(INT)(Element | SignExtend[Element >> 19]) / 524287.0f;
- Element = (UINT)((pSource->v >> 20) & 0xFFFFF);
- V.vector4_f32[1] = (FLOAT)(INT)(Element | SignExtend[Element >> 19]) / 524287.0f;
- Element = (UINT)((pSource->v >> 40) & 0xFFFFF);
- V.vector4_f32[2] = (FLOAT)(INT)(Element | SignExtend[Element >> 19]) / 524287.0f;
- V.vector4_f32[3] = (FLOAT)(pSource->v >> 60) / 15.0f;
- return V;
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT((pSource->v & 0xFFFFFull) != 0x80000ull);
- XMASSERT(((pSource->v >> 20) & 0xFFFFFull) != 0x80000ull);
- XMASSERT(((pSource->v >> 40) & 0xFFFFFull) != 0x80000ull);
- static const XMVECTORF32 LoadXIcoN4Mul = {1.0f/524287.0f,1.0f/(524287.0f*4096.0f),1.0f/524287.0f,1.0f/(15.0f*4096.0f*65536.0f)};
- XMASSERT(pSource);
- // Grab the 64 bit structure
- __m128d vResultd = _mm_load_sd(reinterpret_cast<const double *>(&pSource->v));
- // By shifting down 8 bits, y and z are in seperate 32 bit elements
- __m128i vResulti = _mm_srli_si128(reinterpret_cast<const __m128i *>(&vResultd)[0],8/8);
- // vResultd has x and w, vResulti has y and z, merge into one as x,w,y,z
- XMVECTOR vTemp = _mm_shuffle_ps(reinterpret_cast<const __m128 *>(&vResultd)[0],reinterpret_cast<const __m128 *>(&vResulti)[0],_MM_SHUFFLE(1,0,1,0));
- // Fix the entries to x,y,z,w
- vTemp = _mm_shuffle_ps(vTemp,vTemp,_MM_SHUFFLE(1,3,2,0));
- // Mask x,y,z and w
- vTemp = _mm_and_ps(vTemp,g_XMMaskIco4);
- // x and z are unsigned! Flip the bits to convert the order to signed
- vTemp = _mm_xor_ps(vTemp,g_XMXorXIco4);
- // Convert to floating point numbers
- vTemp = _mm_cvtepi32_ps(reinterpret_cast<const __m128i *>(&vTemp)[0]);
- // x and z - 0x80 to complete the conversion
- vTemp = _mm_add_ps(vTemp,g_XMAddXIco4);
- // Fix y and w because they are too large
- vTemp = _mm_mul_ps(vTemp,LoadXIcoN4Mul);
- return vTemp;
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadXIco4
- (
- CONST XMXICO4* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR V;
- UINT Element;
- static CONST UINT SignExtend[] = {0x00000000, 0xFFF00000};
- XMASSERT(pSource);
- XMASSERT((pSource->v & 0xFFFFFull) != 0x80000ull);
- XMASSERT(((pSource->v >> 20) & 0xFFFFFull) != 0x80000ull);
- XMASSERT(((pSource->v >> 40) & 0xFFFFFull) != 0x80000ull);
- Element = (UINT)(pSource->v & 0xFFFFF);
- V.vector4_f32[0] = (FLOAT)(INT)(Element | SignExtend[Element >> 19]);
- Element = (UINT)((pSource->v >> 20) & 0xFFFFF);
- V.vector4_f32[1] = (FLOAT)(INT)(Element | SignExtend[Element >> 19]);
- Element = (UINT)((pSource->v >> 40) & 0xFFFFF);
- V.vector4_f32[2] = (FLOAT)(INT)(Element | SignExtend[Element >> 19]);
- V.vector4_f32[3] = (FLOAT)(pSource->v >> 60);
- return V;
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT((pSource->v & 0xFFFFFull) != 0x80000ull);
- XMASSERT(((pSource->v >> 20) & 0xFFFFFull) != 0x80000ull);
- XMASSERT(((pSource->v >> 40) & 0xFFFFFull) != 0x80000ull);
- XMASSERT(pSource);
- // Grab the 64 bit structure
- __m128d vResultd = _mm_load_sd(reinterpret_cast<const double *>(&pSource->v));
- // By shifting down 8 bits, y and z are in seperate 32 bit elements
- __m128i vResulti = _mm_srli_si128(reinterpret_cast<const __m128i *>(&vResultd)[0],8/8);
- // vResultd has x and w, vResulti has y and z, merge into one as x,w,y,z
- XMVECTOR vTemp = _mm_shuffle_ps(reinterpret_cast<const __m128 *>(&vResultd)[0],reinterpret_cast<const __m128 *>(&vResulti)[0],_MM_SHUFFLE(1,0,1,0));
- // Fix the entries to x,y,z,w
- vTemp = _mm_shuffle_ps(vTemp,vTemp,_MM_SHUFFLE(1,3,2,0));
- // Mask x,y,z and w
- vTemp = _mm_and_ps(vTemp,g_XMMaskIco4);
- // x and z are unsigned! Flip the bits to convert the order to signed
- vTemp = _mm_xor_ps(vTemp,g_XMXorXIco4);
- // Convert to floating point numbers
- vTemp = _mm_cvtepi32_ps(reinterpret_cast<const __m128i *>(&vTemp)[0]);
- // x and z - 0x80 to complete the conversion
- vTemp = _mm_add_ps(vTemp,g_XMAddXIco4);
- // Fix y and w because they are too large
- vTemp = _mm_mul_ps(vTemp,g_XMMulIco4);
- return vTemp;
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadUIcoN4
- (
- CONST XMUICON4* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR V;
- XMASSERT(pSource);
- V.vector4_f32[0] = (FLOAT)(pSource->v & 0xFFFFF) / 1048575.0f;
- V.vector4_f32[1] = (FLOAT)((pSource->v >> 20) & 0xFFFFF) / 1048575.0f;
- V.vector4_f32[2] = (FLOAT)((pSource->v >> 40) & 0xFFFFF) / 1048575.0f;
- V.vector4_f32[3] = (FLOAT)(pSource->v >> 60) / 15.0f;
- return V;
- #elif defined(_XM_SSE_INTRINSICS_)
- static const XMVECTORF32 LoadUIcoN4Mul = {1.0f/1048575.0f,1.0f/(1048575.0f*4096.0f),1.0f/1048575.0f,1.0f/(15.0f*4096.0f*65536.0f)};
- XMASSERT(pSource);
- // Grab the 64 bit structure
- __m128d vResultd = _mm_load_sd(reinterpret_cast<const double *>(&pSource->v));
- // By shifting down 8 bits, y and z are in seperate 32 bit elements
- __m128i vResulti = _mm_srli_si128(reinterpret_cast<const __m128i *>(&vResultd)[0],8/8);
- // vResultd has x and w, vResulti has y and z, merge into one as x,w,y,z
- XMVECTOR vTemp = _mm_shuffle_ps(reinterpret_cast<const __m128 *>(&vResultd)[0],reinterpret_cast<const __m128 *>(&vResulti)[0],_MM_SHUFFLE(1,0,1,0));
- // Fix the entries to x,y,z,w
- vTemp = _mm_shuffle_ps(vTemp,vTemp,_MM_SHUFFLE(1,3,2,0));
- // Mask x,y,z and w
- vTemp = _mm_and_ps(vTemp,g_XMMaskIco4);
- // x and z are unsigned! Flip the bits to convert the order to signed
- vTemp = _mm_xor_ps(vTemp,g_XMFlipYW);
- // Convert to floating point numbers
- vTemp = _mm_cvtepi32_ps(reinterpret_cast<const __m128i *>(&vTemp)[0]);
- // x and z - 0x80 to complete the conversion
- vTemp = _mm_add_ps(vTemp,g_XMAddUIco4);
- // Fix y and w because they are too large
- vTemp = _mm_mul_ps(vTemp,LoadUIcoN4Mul);
- return vTemp;
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadUIco4
- (
- CONST XMUICO4* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR V;
- XMASSERT(pSource);
- V.vector4_f32[0] = (FLOAT)(pSource->v & 0xFFFFF);
- V.vector4_f32[1] = (FLOAT)((pSource->v >> 20) & 0xFFFFF);
- V.vector4_f32[2] = (FLOAT)((pSource->v >> 40) & 0xFFFFF);
- V.vector4_f32[3] = (FLOAT)(pSource->v >> 60);
- return V;
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pSource);
- // Grab the 64 bit structure
- __m128d vResultd = _mm_load_sd(reinterpret_cast<const double *>(&pSource->v));
- // By shifting down 8 bits, y and z are in seperate 32 bit elements
- __m128i vResulti = _mm_srli_si128(reinterpret_cast<const __m128i *>(&vResultd)[0],8/8);
- // vResultd has x and w, vResulti has y and z, merge into one as x,w,y,z
- XMVECTOR vTemp = _mm_shuffle_ps(reinterpret_cast<const __m128 *>(&vResultd)[0],reinterpret_cast<const __m128 *>(&vResulti)[0],_MM_SHUFFLE(1,0,1,0));
- // Fix the entries to x,y,z,w
- vTemp = _mm_shuffle_ps(vTemp,vTemp,_MM_SHUFFLE(1,3,2,0));
- // Mask x,y,z and w
- vTemp = _mm_and_ps(vTemp,g_XMMaskIco4);
- // x and z are unsigned! Flip the bits to convert the order to signed
- vTemp = _mm_xor_ps(vTemp,g_XMFlipYW);
- // Convert to floating point numbers
- vTemp = _mm_cvtepi32_ps(reinterpret_cast<const __m128i *>(&vTemp)[0]);
- // x and z - 0x80 to complete the conversion
- vTemp = _mm_add_ps(vTemp,g_XMAddUIco4);
- // Fix y and w because they are too large
- vTemp = _mm_mul_ps(vTemp,g_XMMulIco4);
- return vTemp;
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadIcoN4
- (
- CONST XMICON4* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR V;
- UINT Element;
- static CONST UINT SignExtend[] = {0x00000000, 0xFFF00000};
- static CONST UINT SignExtendW[] = {0x00000000, 0xFFFFFFF0};
- XMASSERT(pSource);
- Element = (UINT)(pSource->v & 0xFFFFF);
- V.vector4_f32[0] = (FLOAT)(INT)(Element | SignExtend[Element >> 19]) / 524287.0f;
- Element = (UINT)((pSource->v >> 20) & 0xFFFFF);
- V.vector4_f32[1] = (FLOAT)(INT)(Element | SignExtend[Element >> 19]) / 524287.0f;
- Element = (UINT)((pSource->v >> 40) & 0xFFFFF);
- V.vector4_f32[2] = (FLOAT)(INT)(Element | SignExtend[Element >> 19]) / 524287.0f;
- Element = (UINT)(pSource->v >> 60);
- V.vector4_f32[3] = (FLOAT)(INT)(Element | SignExtendW[Element >> 3]) / 7.0f;
- return V;
- #elif defined(_XM_SSE_INTRINSICS_)
- static const XMVECTORF32 LoadIcoN4Mul = {1.0f/524287.0f,1.0f/(524287.0f*4096.0f),1.0f/524287.0f,1.0f/(7.0f*4096.0f*65536.0f)};
- XMASSERT(pSource);
- // Grab the 64 bit structure
- __m128d vResultd = _mm_load_sd(reinterpret_cast<const double *>(&pSource->v));
- // By shifting down 8 bits, y and z are in seperate 32 bit elements
- __m128i vResulti = _mm_srli_si128(reinterpret_cast<const __m128i *>(&vResultd)[0],8/8);
- // vResultd has x and w, vResulti has y and z, merge into one as x,w,y,z
- XMVECTOR vTemp = _mm_shuffle_ps(reinterpret_cast<const __m128 *>(&vResultd)[0],reinterpret_cast<const __m128 *>(&vResulti)[0],_MM_SHUFFLE(1,0,1,0));
- // Fix the entries to x,y,z,w
- vTemp = _mm_shuffle_ps(vTemp,vTemp,_MM_SHUFFLE(1,3,2,0));
- // Mask x,y,z and w
- vTemp = _mm_and_ps(vTemp,g_XMMaskIco4);
- // x and z are unsigned! Flip the bits to convert the order to signed
- vTemp = _mm_xor_ps(vTemp,g_XMXorIco4);
- // Convert to floating point numbers
- vTemp = _mm_cvtepi32_ps(reinterpret_cast<const __m128i *>(&vTemp)[0]);
- // x and z - 0x80 to complete the conversion
- vTemp = _mm_add_ps(vTemp,g_XMAddIco4);
- // Fix y and w because they are too large
- vTemp = _mm_mul_ps(vTemp,LoadIcoN4Mul);
- return vTemp;
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadIco4
- (
- CONST XMICO4* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR V;
- UINT Element;
- static CONST UINT SignExtend[] = {0x00000000, 0xFFF00000};
- static CONST UINT SignExtendW[] = {0x00000000, 0xFFFFFFF0};
- XMASSERT(pSource);
- Element = (UINT)(pSource->v & 0xFFFFF);
- V.vector4_f32[0] = (FLOAT)(INT)(Element | SignExtend[Element >> 19]);
- Element = (UINT)((pSource->v >> 20) & 0xFFFFF);
- V.vector4_f32[1] = (FLOAT)(INT)(Element | SignExtend[Element >> 19]);
- Element = (UINT)((pSource->v >> 40) & 0xFFFFF);
- V.vector4_f32[2] = (FLOAT)(INT)(Element | SignExtend[Element >> 19]);
- Element = (UINT)(pSource->v >> 60);
- V.vector4_f32[3] = (FLOAT)(INT)(Element | SignExtendW[Element >> 3]);
- return V;
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pSource);
- // Grab the 64 bit structure
- __m128d vResultd = _mm_load_sd(reinterpret_cast<const double *>(&pSource->v));
- // By shifting down 8 bits, y and z are in seperate 32 bit elements
- __m128i vResulti = _mm_srli_si128(reinterpret_cast<const __m128i *>(&vResultd)[0],8/8);
- // vResultd has x and w, vResulti has y and z, merge into one as x,w,y,z
- XMVECTOR vTemp = _mm_shuffle_ps(reinterpret_cast<const __m128 *>(&vResultd)[0],reinterpret_cast<const __m128 *>(&vResulti)[0],_MM_SHUFFLE(1,0,1,0));
- // Fix the entries to x,y,z,w
- vTemp = _mm_shuffle_ps(vTemp,vTemp,_MM_SHUFFLE(1,3,2,0));
- // Mask x,y,z and w
- vTemp = _mm_and_ps(vTemp,g_XMMaskIco4);
- // x and z are unsigned! Flip the bits to convert the order to signed
- vTemp = _mm_xor_ps(vTemp,g_XMXorIco4);
- // Convert to floating point numbers
- vTemp = _mm_cvtepi32_ps(reinterpret_cast<const __m128i *>(&vTemp)[0]);
- // x and z - 0x80 to complete the conversion
- vTemp = _mm_add_ps(vTemp,g_XMAddIco4);
- // Fix y and w because they are too large
- vTemp = _mm_mul_ps(vTemp,g_XMMulIco4);
- return vTemp;
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadXDecN4
- (
- CONST XMXDECN4* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR V;
- UINT Element;
- static CONST UINT SignExtend[] = {0x00000000, 0xFFFFFC00};
- XMASSERT(pSource);
- XMASSERT((pSource->v & 0x3FF) != 0x200);
- XMASSERT(((pSource->v >> 10) & 0x3FF) != 0x200);
- XMASSERT(((pSource->v >> 20) & 0x3FF) != 0x200);
- Element = pSource->v & 0x3FF;
- V.vector4_f32[0] = (FLOAT)(SHORT)(Element | SignExtend[Element >> 9]) / 511.0f;
- Element = (pSource->v >> 10) & 0x3FF;
- V.vector4_f32[1] = (FLOAT)(SHORT)(Element | SignExtend[Element >> 9]) / 511.0f;
- Element = (pSource->v >> 20) & 0x3FF;
- V.vector4_f32[2] = (FLOAT)(SHORT)(Element | SignExtend[Element >> 9]) / 511.0f;
- V.vector4_f32[3] = (FLOAT)(pSource->v >> 30) / 3.0f;
- return V;
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pSource);
- // Splat the color in all four entries
- __m128 vTemp = _mm_load_ps1(reinterpret_cast<const float *>(&pSource->v));
- // Shift R&0xFF0000, G&0xFF00, B&0xFF, A&0xFF000000
- vTemp = _mm_and_ps(vTemp,g_XMMaskA2B10G10R10);
- // a is unsigned! Flip the bit to convert the order to signed
- vTemp = _mm_xor_ps(vTemp,g_XMFlipA2B10G10R10);
- // Convert to floating point numbers
- vTemp = _mm_cvtepi32_ps(reinterpret_cast<const __m128i *>(&vTemp)[0]);
- // RGB + 0, A + 0x80000000.f to undo the signed order.
- vTemp = _mm_add_ps(vTemp,g_XMFixAA2B10G10R10);
- // Convert 0-255 to 0.0f-1.0f
- return _mm_mul_ps(vTemp,g_XMNormalizeA2B10G10R10);
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadXDec4
- (
- CONST XMXDEC4* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR V;
- UINT Element;
- static CONST UINT SignExtend[] = {0x00000000, 0xFFFFFC00};
- XMASSERT(pSource);
- XMASSERT((pSource->v & 0x3FF) != 0x200);
- XMASSERT(((pSource->v >> 10) & 0x3FF) != 0x200);
- XMASSERT(((pSource->v >> 20) & 0x3FF) != 0x200);
- Element = pSource->v & 0x3FF;
- V.vector4_f32[0] = (FLOAT)(SHORT)(Element | SignExtend[Element >> 9]);
- Element = (pSource->v >> 10) & 0x3FF;
- V.vector4_f32[1] = (FLOAT)(SHORT)(Element | SignExtend[Element >> 9]);
- Element = (pSource->v >> 20) & 0x3FF;
- V.vector4_f32[2] = (FLOAT)(SHORT)(Element | SignExtend[Element >> 9]);
- V.vector4_f32[3] = (FLOAT)(pSource->v >> 30);
- return V;
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT((pSource->v & 0x3FF) != 0x200);
- XMASSERT(((pSource->v >> 10) & 0x3FF) != 0x200);
- XMASSERT(((pSource->v >> 20) & 0x3FF) != 0x200);
- static const XMVECTORI32 XDec4Xor = {0x200, 0x200<<10, 0x200<<20, 0x80000000};
- static const XMVECTORF32 XDec4Add = {-512.0f,-512.0f*1024.0f,-512.0f*1024.0f*1024.0f,32768*65536.0f};
- XMASSERT(pSource);
- // Splat the color in all four entries
- XMVECTOR vTemp = _mm_load_ps1(reinterpret_cast<const float *>(&pSource->v));
- // Shift R&0xFF0000, G&0xFF00, B&0xFF, A&0xFF000000
- vTemp = _mm_and_ps(vTemp,g_XMMaskDec4);
- // a is unsigned! Flip the bit to convert the order to signed
- vTemp = _mm_xor_ps(vTemp,XDec4Xor);
- // Convert to floating point numbers
- vTemp = _mm_cvtepi32_ps(reinterpret_cast<const __m128i *>(&vTemp)[0]);
- // RGB + 0, A + 0x80000000.f to undo the signed order.
- vTemp = _mm_add_ps(vTemp,XDec4Add);
- // Convert 0-255 to 0.0f-1.0f
- vTemp = _mm_mul_ps(vTemp,g_XMMulDec4);
- return vTemp;
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadUDecN4
- (
- CONST XMUDECN4* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR V;
- UINT Element;
- XMASSERT(pSource);
- Element = pSource->v & 0x3FF;
- V.vector4_f32[0] = (FLOAT)Element / 1023.0f;
- Element = (pSource->v >> 10) & 0x3FF;
- V.vector4_f32[1] = (FLOAT)Element / 1023.0f;
- Element = (pSource->v >> 20) & 0x3FF;
- V.vector4_f32[2] = (FLOAT)Element / 1023.0f;
- V.vector4_f32[3] = (FLOAT)(pSource->v >> 30) / 3.0f;
- return V;
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pSource);
- static const XMVECTORF32 UDecN4Mul = {1.0f/1023.0f,1.0f/(1023.0f*1024.0f),1.0f/(1023.0f*1024.0f*1024.0f),1.0f/(3.0f*1024.0f*1024.0f*1024.0f)};
- // Splat the color in all four entries
- XMVECTOR vTemp = _mm_load_ps1(reinterpret_cast<const float *>(&pSource->v));
- // Shift R&0xFF0000, G&0xFF00, B&0xFF, A&0xFF000000
- vTemp = _mm_and_ps(vTemp,g_XMMaskDec4);
- // a is unsigned! Flip the bit to convert the order to signed
- vTemp = _mm_xor_ps(vTemp,g_XMFlipW);
- // Convert to floating point numbers
- vTemp = _mm_cvtepi32_ps(reinterpret_cast<const __m128i *>(&vTemp)[0]);
- // RGB + 0, A + 0x80000000.f to undo the signed order.
- vTemp = _mm_add_ps(vTemp,g_XMAddUDec4);
- // Convert 0-255 to 0.0f-1.0f
- vTemp = _mm_mul_ps(vTemp,UDecN4Mul);
- return vTemp;
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadUDec4
- (
- CONST XMUDEC4* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR V;
- UINT Element;
- XMASSERT(pSource);
- Element = pSource->v & 0x3FF;
- V.vector4_f32[0] = (FLOAT)Element;
- Element = (pSource->v >> 10) & 0x3FF;
- V.vector4_f32[1] = (FLOAT)Element;
- Element = (pSource->v >> 20) & 0x3FF;
- V.vector4_f32[2] = (FLOAT)Element;
- V.vector4_f32[3] = (FLOAT)(pSource->v >> 30);
- return V;
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pSource);
- // Splat the color in all four entries
- XMVECTOR vTemp = _mm_load_ps1(reinterpret_cast<const float *>(&pSource->v));
- // Shift R&0xFF0000, G&0xFF00, B&0xFF, A&0xFF000000
- vTemp = _mm_and_ps(vTemp,g_XMMaskDec4);
- // a is unsigned! Flip the bit to convert the order to signed
- vTemp = _mm_xor_ps(vTemp,g_XMFlipW);
- // Convert to floating point numbers
- vTemp = _mm_cvtepi32_ps(reinterpret_cast<const __m128i *>(&vTemp)[0]);
- // RGB + 0, A + 0x80000000.f to undo the signed order.
- vTemp = _mm_add_ps(vTemp,g_XMAddUDec4);
- // Convert 0-255 to 0.0f-1.0f
- vTemp = _mm_mul_ps(vTemp,g_XMMulDec4);
- return vTemp;
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadDecN4
- (
- CONST XMDECN4* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR V;
- UINT Element;
- static CONST UINT SignExtend[] = {0x00000000, 0xFFFFFC00};
- static CONST UINT SignExtendW[] = {0x00000000, 0xFFFFFFFC};
- XMASSERT(pSource);
- XMASSERT((pSource->v & 0x3FF) != 0x200);
- XMASSERT(((pSource->v >> 10) & 0x3FF) != 0x200);
- XMASSERT(((pSource->v >> 20) & 0x3FF) != 0x200);
- XMASSERT(((pSource->v >> 30) & 0x3) != 0x2);
- Element = pSource->v & 0x3FF;
- V.vector4_f32[0] = (FLOAT)(SHORT)(Element | SignExtend[Element >> 9]) / 511.0f;
- Element = (pSource->v >> 10) & 0x3FF;
- V.vector4_f32[1] = (FLOAT)(SHORT)(Element | SignExtend[Element >> 9]) / 511.0f;
- Element = (pSource->v >> 20) & 0x3FF;
- V.vector4_f32[2] = (FLOAT)(SHORT)(Element | SignExtend[Element >> 9]) / 511.0f;
- Element = pSource->v >> 30;
- V.vector4_f32[3] = (FLOAT)(SHORT)(Element | SignExtendW[Element >> 1]);
- return V;
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pSource);
- XMASSERT((pSource->v & 0x3FF) != 0x200);
- XMASSERT(((pSource->v >> 10) & 0x3FF) != 0x200);
- XMASSERT(((pSource->v >> 20) & 0x3FF) != 0x200);
- XMASSERT(((pSource->v >> 30) & 0x3) != 0x2);
- static const XMVECTORF32 DecN4Mul = {1.0f/511.0f,1.0f/(511.0f*1024.0f),1.0f/(511.0f*1024.0f*1024.0f),1.0f/(1024.0f*1024.0f*1024.0f)};
- // Splat the color in all four entries
- XMVECTOR vTemp = _mm_load_ps1(reinterpret_cast<const float *>(&pSource->v));
- // Shift R&0xFF0000, G&0xFF00, B&0xFF, A&0xFF000000
- vTemp = _mm_and_ps(vTemp,g_XMMaskDec4);
- // a is unsigned! Flip the bit to convert the order to signed
- vTemp = _mm_xor_ps(vTemp,g_XMXorDec4);
- // Convert to floating point numbers
- vTemp = _mm_cvtepi32_ps(reinterpret_cast<const __m128i *>(&vTemp)[0]);
- // RGB + 0, A + 0x80000000.f to undo the signed order.
- vTemp = _mm_add_ps(vTemp,g_XMAddDec4);
- // Convert 0-255 to 0.0f-1.0f
- vTemp = _mm_mul_ps(vTemp,DecN4Mul);
- return vTemp;
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadDec4
- (
- CONST XMDEC4* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR V;
- UINT Element;
- static CONST UINT SignExtend[] = {0x00000000, 0xFFFFFC00};
- static CONST UINT SignExtendW[] = {0x00000000, 0xFFFFFFFC};
- XMASSERT(pSource);
- XMASSERT((pSource->v & 0x3FF) != 0x200);
- XMASSERT(((pSource->v >> 10) & 0x3FF) != 0x200);
- XMASSERT(((pSource->v >> 20) & 0x3FF) != 0x200);
- XMASSERT(((pSource->v >> 30) & 0x3) != 0x2);
- Element = pSource->v & 0x3FF;
- V.vector4_f32[0] = (FLOAT)(SHORT)(Element | SignExtend[Element >> 9]);
- Element = (pSource->v >> 10) & 0x3FF;
- V.vector4_f32[1] = (FLOAT)(SHORT)(Element | SignExtend[Element >> 9]);
- Element = (pSource->v >> 20) & 0x3FF;
- V.vector4_f32[2] = (FLOAT)(SHORT)(Element | SignExtend[Element >> 9]);
- Element = pSource->v >> 30;
- V.vector4_f32[3] = (FLOAT)(SHORT)(Element | SignExtendW[Element >> 1]);
- return V;
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT((pSource->v & 0x3FF) != 0x200);
- XMASSERT(((pSource->v >> 10) & 0x3FF) != 0x200);
- XMASSERT(((pSource->v >> 20) & 0x3FF) != 0x200);
- XMASSERT(((pSource->v >> 30) & 0x3) != 0x2);
- XMASSERT(pSource);
- // Splat the color in all four entries
- XMVECTOR vTemp = _mm_load_ps1(reinterpret_cast<const float *>(&pSource->v));
- // Shift R&0xFF0000, G&0xFF00, B&0xFF, A&0xFF000000
- vTemp = _mm_and_ps(vTemp,g_XMMaskDec4);
- // a is unsigned! Flip the bit to convert the order to signed
- vTemp = _mm_xor_ps(vTemp,g_XMXorDec4);
- // Convert to floating point numbers
- vTemp = _mm_cvtepi32_ps(reinterpret_cast<const __m128i *>(&vTemp)[0]);
- // RGB + 0, A + 0x80000000.f to undo the signed order.
- vTemp = _mm_add_ps(vTemp,g_XMAddDec4);
- // Convert 0-255 to 0.0f-1.0f
- vTemp = _mm_mul_ps(vTemp,g_XMMulDec4);
- return vTemp;
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadUByteN4
- (
- CONST XMUBYTEN4* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR V;
- XMASSERT(pSource);
- V.vector4_f32[0] = (FLOAT)pSource->x / 255.0f;
- V.vector4_f32[1] = (FLOAT)pSource->y / 255.0f;
- V.vector4_f32[2] = (FLOAT)pSource->z / 255.0f;
- V.vector4_f32[3] = (FLOAT)pSource->w / 255.0f;
- return V;
- #elif defined(_XM_SSE_INTRINSICS_)
- static const XMVECTORF32 LoadUByteN4Mul = {1.0f/255.0f,1.0f/(255.0f*256.0f),1.0f/(255.0f*65536.0f),1.0f/(255.0f*65536.0f*256.0f)};
- XMASSERT(pSource);
- // Splat the color in all four entries (x,z,y,w)
- XMVECTOR vTemp = _mm_load1_ps(reinterpret_cast<const float *>(&pSource->x));
- // Mask x&0ff,y&0xff00,z&0xff0000,w&0xff000000
- vTemp = _mm_and_ps(vTemp,g_XMMaskByte4);
- // w is signed! Flip the bits to convert the order to unsigned
- vTemp = _mm_xor_ps(vTemp,g_XMFlipW);
- // Convert to floating point numbers
- vTemp = _mm_cvtepi32_ps(reinterpret_cast<const __m128i *>(&vTemp)[0]);
- // w + 0x80 to complete the conversion
- vTemp = _mm_add_ps(vTemp,g_XMAddUDec4);
- // Fix y, z and w because they are too large
- vTemp = _mm_mul_ps(vTemp,LoadUByteN4Mul);
- return vTemp;
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadUByte4
- (
- CONST XMUBYTE4* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR V;
- XMASSERT(pSource);
- V.vector4_f32[0] = (FLOAT)pSource->x;
- V.vector4_f32[1] = (FLOAT)pSource->y;
- V.vector4_f32[2] = (FLOAT)pSource->z;
- V.vector4_f32[3] = (FLOAT)pSource->w;
- return V;
- #elif defined(_XM_SSE_INTRINSICS_)
- static const XMVECTORF32 LoadUByte4Mul = {1.0f,1.0f/256.0f,1.0f/65536.0f,1.0f/(65536.0f*256.0f)};
- XMASSERT(pSource);
- // Splat the color in all four entries (x,z,y,w)
- XMVECTOR vTemp = _mm_load1_ps(reinterpret_cast<const float *>(&pSource->x));
- // Mask x&0ff,y&0xff00,z&0xff0000,w&0xff000000
- vTemp = _mm_and_ps(vTemp,g_XMMaskByte4);
- // w is signed! Flip the bits to convert the order to unsigned
- vTemp = _mm_xor_ps(vTemp,g_XMFlipW);
- // Convert to floating point numbers
- vTemp = _mm_cvtepi32_ps(reinterpret_cast<const __m128i *>(&vTemp)[0]);
- // w + 0x80 to complete the conversion
- vTemp = _mm_add_ps(vTemp,g_XMAddUDec4);
- // Fix y, z and w because they are too large
- vTemp = _mm_mul_ps(vTemp,LoadUByte4Mul);
- return vTemp;
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadByteN4
- (
- CONST XMBYTEN4* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR V;
- XMASSERT(pSource);
- XMASSERT(pSource->x != -128);
- XMASSERT(pSource->y != -128);
- XMASSERT(pSource->z != -128);
- XMASSERT(pSource->w != -128);
- V.vector4_f32[0] = (FLOAT)pSource->x / 127.0f;
- V.vector4_f32[1] = (FLOAT)pSource->y / 127.0f;
- V.vector4_f32[2] = (FLOAT)pSource->z / 127.0f;
- V.vector4_f32[3] = (FLOAT)pSource->w / 127.0f;
- return V;
- #elif defined(_XM_SSE_INTRINSICS_)
- static const XMVECTORF32 LoadByteN4Mul = {1.0f/127.0f,1.0f/(127.0f*256.0f),1.0f/(127.0f*65536.0f),1.0f/(127.0f*65536.0f*256.0f)};
- XMASSERT(pSource);
- XMASSERT(pSource->x != -128);
- XMASSERT(pSource->y != -128);
- XMASSERT(pSource->z != -128);
- XMASSERT(pSource->w != -128);
- // Splat the color in all four entries (x,z,y,w)
- XMVECTOR vTemp = _mm_load1_ps(reinterpret_cast<const float *>(&pSource->x));
- // Mask x&0ff,y&0xff00,z&0xff0000,w&0xff000000
- vTemp = _mm_and_ps(vTemp,g_XMMaskByte4);
- // x,y and z are unsigned! Flip the bits to convert the order to signed
- vTemp = _mm_xor_ps(vTemp,g_XMXorByte4);
- // Convert to floating point numbers
- vTemp = _mm_cvtepi32_ps(reinterpret_cast<const __m128i *>(&vTemp)[0]);
- // x, y and z - 0x80 to complete the conversion
- vTemp = _mm_add_ps(vTemp,g_XMAddByte4);
- // Fix y, z and w because they are too large
- vTemp = _mm_mul_ps(vTemp,LoadByteN4Mul);
- return vTemp;
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadByte4
- (
- CONST XMBYTE4* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR V;
- XMASSERT(pSource);
- XMASSERT(pSource->x != -128);
- XMASSERT(pSource->y != -128);
- XMASSERT(pSource->z != -128);
- XMASSERT(pSource->w != -128);
- V.vector4_f32[0] = (FLOAT)pSource->x;
- V.vector4_f32[1] = (FLOAT)pSource->y;
- V.vector4_f32[2] = (FLOAT)pSource->z;
- V.vector4_f32[3] = (FLOAT)pSource->w;
- return V;
- #elif defined(_XM_SSE_INTRINSICS_)
- static const XMVECTORF32 LoadByte4Mul = {1.0f,1.0f/256.0f,1.0f/65536.0f,1.0f/(65536.0f*256.0f)};
- XMASSERT(pSource);
- XMASSERT(pSource->x != -128);
- XMASSERT(pSource->y != -128);
- XMASSERT(pSource->z != -128);
- XMASSERT(pSource->w != -128);
- // Splat the color in all four entries (x,z,y,w)
- XMVECTOR vTemp = _mm_load1_ps(reinterpret_cast<const float *>(&pSource->x));
- // Mask x&0ff,y&0xff00,z&0xff0000,w&0xff000000
- vTemp = _mm_and_ps(vTemp,g_XMMaskByte4);
- // x,y and z are unsigned! Flip the bits to convert the order to signed
- vTemp = _mm_xor_ps(vTemp,g_XMXorByte4);
- // Convert to floating point numbers
- vTemp = _mm_cvtepi32_ps(reinterpret_cast<const __m128i *>(&vTemp)[0]);
- // x, y and z - 0x80 to complete the conversion
- vTemp = _mm_add_ps(vTemp,g_XMAddByte4);
- // Fix y, z and w because they are too large
- vTemp = _mm_mul_ps(vTemp,LoadByte4Mul);
- return vTemp;
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadUNibble4
- (
- CONST XMUNIBBLE4* pSource
- )
- {
- #if defined(_XM_SSE_INTRINSICS_) && !defined(_XM_NO_INTRINSICS_)
- static const XMVECTORI32 UNibble4And = {0xF,0xF0,0xF00,0xF000};
- static const XMVECTORF32 UNibble4Mul = {1.0f,1.0f/16.f,1.0f/256.f,1.0f/4096.f};
- XMASSERT(pSource);
- // Get the 32 bit value and splat it
- XMVECTOR vResult = _mm_load_ps1(reinterpret_cast<const float *>(&pSource->v));
- // Mask off x, y and z
- vResult = _mm_and_ps(vResult,UNibble4And);
- // Convert to float
- vResult = _mm_cvtepi32_ps(reinterpret_cast<const __m128i *>(&vResult)[0]);
- // Normalize x, y, and z
- vResult = _mm_mul_ps(vResult,UNibble4Mul);
- return vResult;
- #else
- XMVECTOR V;
- UINT Element;
- XMASSERT(pSource);
- Element = pSource->v & 0xF;
- V.vector4_f32[0] = (FLOAT)Element;
- Element = (pSource->v >> 4) & 0xF;
- V.vector4_f32[1] = (FLOAT)Element;
- Element = (pSource->v >> 8) & 0xF;
- V.vector4_f32[2] = (FLOAT)Element;
- Element = (pSource->v >> 12) & 0xF;
- V.vector4_f32[3] = (FLOAT)Element;
- return V;
- #endif // !_XM_SSE_INTRISICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadU555
- (
- CONST XMU555* pSource
- )
- {
- #if defined(_XM_SSE_INTRINSICS_) && !defined(_XM_NO_INTRINSICS_)
- static const XMVECTORI32 U555And = {0x1F,0x1F<<5,0x1F<<10,0x8000};
- static const XMVECTORF32 U555Mul = {1.0f,1.0f/32.f,1.0f/1024.f,1.0f/32768.f};
- XMASSERT(pSource);
- // Get the 32 bit value and splat it
- XMVECTOR vResult = _mm_load_ps1(reinterpret_cast<const float *>(&pSource->v));
- // Mask off x, y and z
- vResult = _mm_and_ps(vResult,U555And);
- // Convert to float
- vResult = _mm_cvtepi32_ps(reinterpret_cast<const __m128i *>(&vResult)[0]);
- // Normalize x, y, and z
- vResult = _mm_mul_ps(vResult,U555Mul);
- return vResult;
- #else
- XMVECTOR V;
- UINT Element;
- XMASSERT(pSource);
- Element = pSource->v & 0x1F;
- V.vector4_f32[0] = (FLOAT)Element;
- Element = (pSource->v >> 5) & 0x1F;
- V.vector4_f32[1] = (FLOAT)Element;
- Element = (pSource->v >> 10) & 0x1F;
- V.vector4_f32[2] = (FLOAT)Element;
- Element = (pSource->v >> 15) & 0x1;
- V.vector4_f32[3] = (FLOAT)Element;
- return V;
- #endif // !_XM_SSE_INTRISICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMVECTOR XMLoadColor
- (
- CONST XMCOLOR* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMASSERT(pSource);
- {
- // INT -> Float conversions are done in one instruction.
- // UINT -> Float calls a runtime function. Keep in INT
- INT iColor = (INT)(pSource->c);
- XMVECTOR vColor = {
- (FLOAT)((iColor >> 16) & 0xFF) * (1.0f/255.0f),
- (FLOAT)((iColor >> 8) & 0xFF) * (1.0f/255.0f),
- (FLOAT)(iColor & 0xFF) * (1.0f/255.0f),
- (FLOAT)((iColor >> 24) & 0xFF) * (1.0f/255.0f)
- };
- return vColor;
- }
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pSource);
- // Splat the color in all four entries
- __m128i vInt = _mm_set1_epi32(pSource->c);
- // Shift R&0xFF0000, G&0xFF00, B&0xFF, A&0xFF000000
- vInt = _mm_and_si128(vInt,g_XMMaskA8R8G8B8);
- // a is unsigned! Flip the bit to convert the order to signed
- vInt = _mm_xor_si128(vInt,g_XMFlipA8R8G8B8);
- // Convert to floating point numbers
- XMVECTOR vTemp = _mm_cvtepi32_ps(vInt);
- // RGB + 0, A + 0x80000000.f to undo the signed order.
- vTemp = _mm_add_ps(vTemp,g_XMFixAA8R8G8B8);
- // Convert 0-255 to 0.0f-1.0f
- return _mm_mul_ps(vTemp,g_XMNormalizeA8R8G8B8);
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMMATRIX XMLoadFloat3x3
- (
- CONST XMFLOAT3X3* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMMATRIX M;
- XMASSERT(pSource);
- M.r[0].vector4_f32[0] = pSource->m[0][0];
- M.r[0].vector4_f32[1] = pSource->m[0][1];
- M.r[0].vector4_f32[2] = pSource->m[0][2];
- M.r[0].vector4_f32[3] = 0.0f;
- M.r[1].vector4_f32[0] = pSource->m[1][0];
- M.r[1].vector4_f32[1] = pSource->m[1][1];
- M.r[1].vector4_f32[2] = pSource->m[1][2];
- M.r[1].vector4_f32[3] = 0.0f;
- M.r[2].vector4_f32[0] = pSource->m[2][0];
- M.r[2].vector4_f32[1] = pSource->m[2][1];
- M.r[2].vector4_f32[2] = pSource->m[2][2];
- M.r[2].vector4_f32[3] = 0.0f;
- M.r[3].vector4_f32[0] = 0.0f;
- M.r[3].vector4_f32[1] = 0.0f;
- M.r[3].vector4_f32[2] = 0.0f;
- M.r[3].vector4_f32[3] = 1.0f;
- return M;
- #elif defined(_XM_SSE_INTRINSICS_)
- XMMATRIX M;
- XMVECTOR V1, V2, V3, Z, T1, T2, T3, T4, T5;
- Z = _mm_setzero_ps();
- XMASSERT(pSource);
- V1 = _mm_loadu_ps( &pSource->m[0][0] );
- V2 = _mm_loadu_ps( &pSource->m[1][1] );
- V3 = _mm_load_ss( &pSource->m[2][2] );
- T1 = _mm_unpackhi_ps( V1, Z );
- T2 = _mm_unpacklo_ps( V2, Z );
- T3 = _mm_shuffle_ps( V3, T2, _MM_SHUFFLE( 0, 1, 0, 0 ) );
- T4 = _mm_movehl_ps( T2, T3 );
- T5 = _mm_movehl_ps( Z, T1 );
- M.r[0] = _mm_movelh_ps( V1, T1 );
- M.r[1] = _mm_add_ps( T4, T5 );
- M.r[2] = _mm_shuffle_ps( V2, V3, _MM_SHUFFLE(1, 0, 3, 2) );
- M.r[3] = g_XMIdentityR3;
- return M;
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMMATRIX XMLoadFloat4x3
- (
- CONST XMFLOAT4X3* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMMATRIX M;
- XMASSERT(pSource);
- ((UINT *)(&M.r[0].vector4_f32[0]))[0] = ((const UINT *)(&pSource->m[0][0]))[0];
- ((UINT *)(&M.r[0].vector4_f32[1]))[0] = ((const UINT *)(&pSource->m[0][1]))[0];
- ((UINT *)(&M.r[0].vector4_f32[2]))[0] = ((const UINT *)(&pSource->m[0][2]))[0];
- M.r[0].vector4_f32[3] = 0.0f;
- ((UINT *)(&M.r[1].vector4_f32[0]))[0] = ((const UINT *)(&pSource->m[1][0]))[0];
- ((UINT *)(&M.r[1].vector4_f32[1]))[0] = ((const UINT *)(&pSource->m[1][1]))[0];
- ((UINT *)(&M.r[1].vector4_f32[2]))[0] = ((const UINT *)(&pSource->m[1][2]))[0];
- M.r[1].vector4_f32[3] = 0.0f;
- ((UINT *)(&M.r[2].vector4_f32[0]))[0] = ((const UINT *)(&pSource->m[2][0]))[0];
- ((UINT *)(&M.r[2].vector4_f32[1]))[0] = ((const UINT *)(&pSource->m[2][1]))[0];
- ((UINT *)(&M.r[2].vector4_f32[2]))[0] = ((const UINT *)(&pSource->m[2][2]))[0];
- M.r[2].vector4_f32[3] = 0.0f;
- ((UINT *)(&M.r[3].vector4_f32[0]))[0] = ((const UINT *)(&pSource->m[3][0]))[0];
- ((UINT *)(&M.r[3].vector4_f32[1]))[0] = ((const UINT *)(&pSource->m[3][1]))[0];
- ((UINT *)(&M.r[3].vector4_f32[2]))[0] = ((const UINT *)(&pSource->m[3][2]))[0];
- M.r[3].vector4_f32[3] = 1.0f;
- return M;
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pSource);
- // Use unaligned load instructions to
- // load the 12 floats
- // vTemp1 = x1,y1,z1,x2
- XMVECTOR vTemp1 = _mm_loadu_ps(&pSource->m[0][0]);
- // vTemp2 = y2,z2,x3,y3
- XMVECTOR vTemp2 = _mm_loadu_ps(&pSource->m[1][1]);
- // vTemp4 = z3,x4,y4,z4
- XMVECTOR vTemp4 = _mm_loadu_ps(&pSource->m[2][2]);
- // vTemp3 = x3,y3,z3,z3
- XMVECTOR vTemp3 = _mm_shuffle_ps(vTemp2,vTemp4,_MM_SHUFFLE(0,0,3,2));
- // vTemp2 = y2,z2,x2,x2
- vTemp2 = _mm_shuffle_ps(vTemp2,vTemp1,_MM_SHUFFLE(3,3,1,0));
- // vTemp2 = x2,y2,z2,z2
- vTemp2 = _mm_shuffle_ps(vTemp2,vTemp2,_MM_SHUFFLE(1,1,0,2));
- // vTemp1 = x1,y1,z1,0
- vTemp1 = _mm_and_ps(vTemp1,g_XMMask3);
- // vTemp2 = x2,y2,z2,0
- vTemp2 = _mm_and_ps(vTemp2,g_XMMask3);
- // vTemp3 = x3,y3,z3,0
- vTemp3 = _mm_and_ps(vTemp3,g_XMMask3);
- // vTemp4i = x4,y4,z4,0
- __m128i vTemp4i = _mm_srli_si128(reinterpret_cast<const __m128i *>(&vTemp4)[0],32/8);
- // vTemp4i = x4,y4,z4,1.0f
- vTemp4i = _mm_or_si128(vTemp4i,g_XMIdentityR3);
- XMMATRIX M(vTemp1,
- vTemp2,
- vTemp3,
- reinterpret_cast<const __m128 *>(&vTemp4i)[0]);
- return M;
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMMATRIX XMLoadFloat4x3A
- (
- CONST XMFLOAT4X3A* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMMATRIX M;
- XMASSERT(pSource);
- XMASSERT(((UINT_PTR)pSource & 0xF) == 0);
- M.r[0].vector4_f32[0] = pSource->m[0][0];
- M.r[0].vector4_f32[1] = pSource->m[0][1];
- M.r[0].vector4_f32[2] = pSource->m[0][2];
- M.r[0].vector4_f32[3] = 0.0f;
- M.r[1].vector4_f32[0] = pSource->m[1][0];
- M.r[1].vector4_f32[1] = pSource->m[1][1];
- M.r[1].vector4_f32[2] = pSource->m[1][2];
- M.r[1].vector4_f32[3] = 0.0f;
- M.r[2].vector4_f32[0] = pSource->m[2][0];
- M.r[2].vector4_f32[1] = pSource->m[2][1];
- M.r[2].vector4_f32[2] = pSource->m[2][2];
- M.r[2].vector4_f32[3] = 0.0f;
- M.r[3].vector4_f32[0] = pSource->m[3][0];
- M.r[3].vector4_f32[1] = pSource->m[3][1];
- M.r[3].vector4_f32[2] = pSource->m[3][2];
- M.r[3].vector4_f32[3] = 1.0f;
- return M;
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pSource);
- // Use aligned load instructions to
- // load the 12 floats
- // vTemp1 = x1,y1,z1,x2
- XMVECTOR vTemp1 = _mm_load_ps(&pSource->m[0][0]);
- // vTemp2 = y2,z2,x3,y3
- XMVECTOR vTemp2 = _mm_load_ps(&pSource->m[1][1]);
- // vTemp4 = z3,x4,y4,z4
- XMVECTOR vTemp4 = _mm_load_ps(&pSource->m[2][2]);
- // vTemp3 = x3,y3,z3,z3
- XMVECTOR vTemp3 = _mm_shuffle_ps(vTemp2,vTemp4,_MM_SHUFFLE(0,0,3,2));
- // vTemp2 = y2,z2,x2,x2
- vTemp2 = _mm_shuffle_ps(vTemp2,vTemp1,_MM_SHUFFLE(3,3,1,0));
- // vTemp2 = x2,y2,z2,z2
- vTemp2 = _mm_shuffle_ps(vTemp2,vTemp2,_MM_SHUFFLE(1,1,0,2));
- // vTemp1 = x1,y1,z1,0
- vTemp1 = _mm_and_ps(vTemp1,g_XMMask3);
- // vTemp2 = x2,y2,z2,0
- vTemp2 = _mm_and_ps(vTemp2,g_XMMask3);
- // vTemp3 = x3,y3,z3,0
- vTemp3 = _mm_and_ps(vTemp3,g_XMMask3);
- // vTemp4i = x4,y4,z4,0
- __m128i vTemp4i = _mm_srli_si128(reinterpret_cast<const __m128i *>(&vTemp4)[0],32/8);
- // vTemp4i = x4,y4,z4,1.0f
- vTemp4i = _mm_or_si128(vTemp4i,g_XMIdentityR3);
- XMMATRIX M(vTemp1,
- vTemp2,
- vTemp3,
- reinterpret_cast<const __m128 *>(&vTemp4i)[0]);
- return M;
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMMATRIX XMLoadFloat4x4
- (
- CONST XMFLOAT4X4* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMMATRIX M;
- XMASSERT(pSource);
- ((UINT *)(&M.r[0].vector4_f32[0]))[0] = ((const UINT *)(&pSource->m[0][0]))[0];
- ((UINT *)(&M.r[0].vector4_f32[1]))[0] = ((const UINT *)(&pSource->m[0][1]))[0];
- ((UINT *)(&M.r[0].vector4_f32[2]))[0] = ((const UINT *)(&pSource->m[0][2]))[0];
- ((UINT *)(&M.r[0].vector4_f32[3]))[0] = ((const UINT *)(&pSource->m[0][3]))[0];
- ((UINT *)(&M.r[1].vector4_f32[0]))[0] = ((const UINT *)(&pSource->m[1][0]))[0];
- ((UINT *)(&M.r[1].vector4_f32[1]))[0] = ((const UINT *)(&pSource->m[1][1]))[0];
- ((UINT *)(&M.r[1].vector4_f32[2]))[0] = ((const UINT *)(&pSource->m[1][2]))[0];
- ((UINT *)(&M.r[1].vector4_f32[3]))[0] = ((const UINT *)(&pSource->m[1][3]))[0];
- ((UINT *)(&M.r[2].vector4_f32[0]))[0] = ((const UINT *)(&pSource->m[2][0]))[0];
- ((UINT *)(&M.r[2].vector4_f32[1]))[0] = ((const UINT *)(&pSource->m[2][1]))[0];
- ((UINT *)(&M.r[2].vector4_f32[2]))[0] = ((const UINT *)(&pSource->m[2][2]))[0];
- ((UINT *)(&M.r[2].vector4_f32[3]))[0] = ((const UINT *)(&pSource->m[2][3]))[0];
- ((UINT *)(&M.r[3].vector4_f32[0]))[0] = ((const UINT *)(&pSource->m[3][0]))[0];
- ((UINT *)(&M.r[3].vector4_f32[1]))[0] = ((const UINT *)(&pSource->m[3][1]))[0];
- ((UINT *)(&M.r[3].vector4_f32[2]))[0] = ((const UINT *)(&pSource->m[3][2]))[0];
- ((UINT *)(&M.r[3].vector4_f32[3]))[0] = ((const UINT *)(&pSource->m[3][3]))[0];
- return M;
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pSource);
- XMMATRIX M;
- M.r[0] = _mm_loadu_ps( &pSource->_11 );
- M.r[1] = _mm_loadu_ps( &pSource->_21 );
- M.r[2] = _mm_loadu_ps( &pSource->_31 );
- M.r[3] = _mm_loadu_ps( &pSource->_41 );
- return M;
- #elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE XMMATRIX XMLoadFloat4x4A
- (
- CONST XMFLOAT4X4A* pSource
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMMATRIX M;
- XMASSERT(pSource);
- XMASSERT(((UINT_PTR)pSource & 0xF) == 0);
- M.r[0].vector4_f32[0] = pSource->m[0][0];
- M.r[0].vector4_f32[1] = pSource->m[0][1];
- M.r[0].vector4_f32[2] = pSource->m[0][2];
- M.r[0].vector4_f32[3] = pSource->m[0][3];
- M.r[1].vector4_f32[0] = pSource->m[1][0];
- M.r[1].vector4_f32[1] = pSource->m[1][1];
- M.r[1].vector4_f32[2] = pSource->m[1][2];
- M.r[1].vector4_f32[3] = pSource->m[1][3];
- M.r[2].vector4_f32[0] = pSource->m[2][0];
- M.r[2].vector4_f32[1] = pSource->m[2][1];
- M.r[2].vector4_f32[2] = pSource->m[2][2];
- M.r[2].vector4_f32[3] = pSource->m[2][3];
- M.r[3].vector4_f32[0] = pSource->m[3][0];
- M.r[3].vector4_f32[1] = pSource->m[3][1];
- M.r[3].vector4_f32[2] = pSource->m[3][2];
- M.r[3].vector4_f32[3] = pSource->m[3][3];
- return M;
- #elif defined(_XM_SSE_INTRINSICS_)
- XMMATRIX M;
- XMASSERT(pSource);
- M.r[0] = _mm_load_ps( &pSource->_11 );
- M.r[1] = _mm_load_ps( &pSource->_21 );
- M.r[2] = _mm_load_ps( &pSource->_31 );
- M.r[3] = _mm_load_ps( &pSource->_41 );
- return M;
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- /****************************************************************************
- *
- * Vector and matrix store operations
- *
- ****************************************************************************/
- XMFINLINE VOID XMStoreInt
- (
- UINT* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMASSERT(pDestination);
- XMASSERT(((UINT_PTR)pDestination & 3) == 0);
- *pDestination = XMVectorGetIntX( V );
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- XMASSERT(((UINT_PTR)pDestination & 3) == 0);
- _mm_store_ss( (float*)pDestination, V );
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreFloat
- (
- FLOAT* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMASSERT(pDestination);
- XMASSERT(((UINT_PTR)pDestination & 3) == 0);
- *pDestination = XMVectorGetX( V );
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- XMASSERT(((UINT_PTR)pDestination & 3) == 0);
- _mm_store_ss( pDestination, V );
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreInt2
- (
- UINT* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMASSERT(pDestination);
- XMASSERT(((UINT_PTR)pDestination & 3) == 0);
- pDestination[0] = V.vector4_u32[0];
- pDestination[1] = V.vector4_u32[1];
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- XMASSERT(((UINT_PTR)pDestination & 3) == 0);
- XMVECTOR T = _mm_shuffle_ps( V, V, _MM_SHUFFLE( 1, 1, 1, 1 ) );
- _mm_store_ss( (float*)&pDestination[0], V );
- _mm_store_ss( (float*)&pDestination[1], T );
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreInt2A
- (
- UINT* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMASSERT(pDestination);
- XMASSERT(((UINT_PTR)pDestination & 0xF) == 0);
- pDestination[0] = V.vector4_u32[0];
- pDestination[1] = V.vector4_u32[1];
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- XMASSERT(((UINT_PTR)pDestination & 0xF) == 0);
- _mm_storel_epi64( (__m128i*)pDestination, reinterpret_cast<const __m128i *>(&V)[0] );
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreFloat2
- (
- XMFLOAT2* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMASSERT(pDestination);
- XMASSERT(((UINT_PTR)pDestination & 3) == 0);
- pDestination->x = V.vector4_f32[0];
- pDestination->y = V.vector4_f32[1];
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- XMASSERT(((UINT_PTR)pDestination & 3) == 0);
- XMVECTOR T = _mm_shuffle_ps( V, V, _MM_SHUFFLE( 1, 1, 1, 1 ) );
- _mm_store_ss( &pDestination->x, V );
- _mm_store_ss( &pDestination->y, T );
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreFloat2A
- (
- XMFLOAT2A* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMASSERT(pDestination);
- XMASSERT(((UINT_PTR)pDestination & 0xF) == 0);
- pDestination->x = V.vector4_f32[0];
- pDestination->y = V.vector4_f32[1];
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- XMASSERT(((UINT_PTR)pDestination & 0xF) == 0);
- _mm_storel_epi64( (__m128i*)pDestination, reinterpret_cast<const __m128i *>(&V)[0] );
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreHalf2
- (
- XMHALF2* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMASSERT(pDestination);
- pDestination->x = XMConvertFloatToHalf(V.vector4_f32[0]);
- pDestination->y = XMConvertFloatToHalf(V.vector4_f32[1]);
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- pDestination->x = XMConvertFloatToHalf(XMVectorGetX(V));
- pDestination->y = XMConvertFloatToHalf(XMVectorGetY(V));
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreShortN2
- (
- XMSHORTN2* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR N;
- static CONST XMVECTORF32 Scale = {32767.0f, 32767.0f, 32767.0f, 32767.0f};
- XMASSERT(pDestination);
- N = XMVectorClamp(V, g_XMNegativeOne.v, g_XMOne.v);
- N = XMVectorMultiply(N, Scale.v);
- N = XMVectorRound(N);
- pDestination->x = (SHORT)N.vector4_f32[0];
- pDestination->y = (SHORT)N.vector4_f32[1];
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- static CONST XMVECTORF32 Scale = {32767.0f, 32767.0f, 32767.0f, 32767.0f};
- XMVECTOR vResult = _mm_max_ps(V,g_XMNegativeOne);
- vResult = _mm_min_ps(vResult,g_XMOne);
- vResult = _mm_mul_ps(vResult,Scale);
- __m128i vResulti = _mm_cvtps_epi32(vResult);
- vResulti = _mm_packs_epi32(vResulti,vResulti);
- _mm_store_ss(reinterpret_cast<float *>(&pDestination->x),reinterpret_cast<const __m128 *>(&vResulti)[0]);
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreShort2
- (
- XMSHORT2* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR N;
- static CONST XMVECTOR Min = {-32767.0f, -32767.0f, -32767.0f, -32767.0f};
- static CONST XMVECTOR Max = {32767.0f, 32767.0f, 32767.0f, 32767.0f};
- XMASSERT(pDestination);
- N = XMVectorClamp(V, Min, Max);
- N = XMVectorRound(N);
- pDestination->x = (SHORT)N.vector4_f32[0];
- pDestination->y = (SHORT)N.vector4_f32[1];
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- static CONST XMVECTORF32 Min = {-32767.0f, -32767.0f, -32767.0f, -32767.0f};
- static CONST XMVECTORF32 Max = {32767.0f, 32767.0f, 32767.0f, 32767.0f};
- // Bounds check
- XMVECTOR vResult = _mm_max_ps(V,Min);
- vResult = _mm_min_ps(vResult,Max);
- // Convert to int with rounding
- __m128i vInt = _mm_cvtps_epi32(vResult);
- // Pack the ints into shorts
- vInt = _mm_packs_epi32(vInt,vInt);
- _mm_store_ss(reinterpret_cast<float *>(&pDestination->x),reinterpret_cast<const __m128 *>(&vInt)[0]);
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreUShortN2
- (
- XMUSHORTN2* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR N;
- static CONST XMVECTORF32 Scale = {65535.0f, 65535.0f, 65535.0f, 65535.0f};
- XMASSERT(pDestination);
- N = XMVectorClamp(V, XMVectorZero(), g_XMOne.v);
- N = XMVectorMultiplyAdd(N, Scale.v, g_XMOneHalf.v);
- N = XMVectorTruncate(N);
- pDestination->x = (SHORT)N.vector4_f32[0];
- pDestination->y = (SHORT)N.vector4_f32[1];
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- static CONST XMVECTORF32 Scale = {65535.0f, 65535.0f, 65535.0f, 65535.0f};
- // Bounds check
- XMVECTOR vResult = _mm_max_ps(V,g_XMZero);
- vResult = _mm_min_ps(vResult,g_XMOne);
- vResult = _mm_mul_ps(vResult,Scale);
- // Convert to int with rounding
- __m128i vInt = _mm_cvtps_epi32(vResult);
- // Since the SSE pack instruction clamps using signed rules,
- // manually extract the values to store them to memory
- pDestination->x = static_cast<SHORT>(_mm_extract_epi16(vInt,0));
- pDestination->y = static_cast<SHORT>(_mm_extract_epi16(vInt,2));
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreUShort2
- (
- XMUSHORT2* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR N;
- static CONST XMVECTOR Max = {65535.0f, 65535.0f, 65535.0f, 65535.0f};
- XMASSERT(pDestination);
- N = XMVectorClamp(V, XMVectorZero(), Max);
- N = XMVectorRound(N);
- pDestination->x = (SHORT)N.vector4_f32[0];
- pDestination->y = (SHORT)N.vector4_f32[1];
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- static CONST XMVECTORF32 Max = {65535.0f, 65535.0f, 65535.0f, 65535.0f};
- // Bounds check
- XMVECTOR vResult = _mm_max_ps(V,g_XMZero);
- vResult = _mm_min_ps(vResult,Max);
- // Convert to int with rounding
- __m128i vInt = _mm_cvtps_epi32(vResult);
- // Since the SSE pack instruction clamps using signed rules,
- // manually extract the values to store them to memory
- pDestination->x = static_cast<SHORT>(_mm_extract_epi16(vInt,0));
- pDestination->y = static_cast<SHORT>(_mm_extract_epi16(vInt,2));
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreInt3
- (
- UINT* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMASSERT(pDestination);
- XMASSERT(((UINT_PTR)pDestination & 3) == 0);
- pDestination[0] = V.vector4_u32[0];
- pDestination[1] = V.vector4_u32[1];
- pDestination[2] = V.vector4_u32[2];
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- XMASSERT(((UINT_PTR)pDestination & 3) == 0);
- XMVECTOR T1 = _mm_shuffle_ps(V,V,_MM_SHUFFLE(1,1,1,1));
- XMVECTOR T2 = _mm_shuffle_ps(V,V,_MM_SHUFFLE(2,2,2,2));
- _mm_store_ss( (float*)pDestination, V );
- _mm_store_ss( (float*)&pDestination[1], T1 );
- _mm_store_ss( (float*)&pDestination[2], T2 );
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreInt3A
- (
- UINT* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMASSERT(pDestination);
- XMASSERT(((UINT_PTR)pDestination & 0xF) == 0);
- pDestination[0] = V.vector4_u32[0];
- pDestination[1] = V.vector4_u32[1];
- pDestination[2] = V.vector4_u32[2];
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- XMASSERT(((UINT_PTR)pDestination & 0xF) == 0);
- XMVECTOR T = _mm_shuffle_ps(V,V,_MM_SHUFFLE(2,2,2,2));
- _mm_storel_epi64( (__m128i*)pDestination, reinterpret_cast<const __m128i *>(&V)[0] );
- _mm_store_ss( (float*)&pDestination[2], T );
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreFloat3
- (
- XMFLOAT3* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMASSERT(pDestination);
- XMASSERT(((UINT_PTR)pDestination & 3) == 0);
- pDestination->x = V.vector4_f32[0];
- pDestination->y = V.vector4_f32[1];
- pDestination->z = V.vector4_f32[2];
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- XMASSERT(((UINT_PTR)pDestination & 3) == 0);
- XMVECTOR T1 = _mm_shuffle_ps(V,V,_MM_SHUFFLE(1,1,1,1));
- XMVECTOR T2 = _mm_shuffle_ps(V,V,_MM_SHUFFLE(2,2,2,2));
- _mm_store_ss( &pDestination->x, V );
- _mm_store_ss( &pDestination->y, T1 );
- _mm_store_ss( &pDestination->z, T2 );
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreFloat3A
- (
- XMFLOAT3A* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMASSERT(pDestination);
- XMASSERT(((UINT_PTR)pDestination & 0xF) == 0);
- pDestination->x = V.vector4_f32[0];
- pDestination->y = V.vector4_f32[1];
- pDestination->z = V.vector4_f32[2];
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- XMASSERT(((UINT_PTR)pDestination & 0xF) == 0);
- XMVECTOR T = _mm_shuffle_ps(V,V,_MM_SHUFFLE(2,2,2,2));
- _mm_storel_epi64( (__m128i*)pDestination, reinterpret_cast<const __m128i *>(&V)[0] );
- _mm_store_ss( &pDestination->z, T );
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreUHenDN3
- (
- XMUHENDN3* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR N;
- static CONST XMVECTORF32 Scale = {2047.0f, 2047.0f, 1023.0f, 0.0f};
- XMASSERT(pDestination);
- N = XMVectorClamp(V, XMVectorZero(), g_XMOne.v);
- N = XMVectorMultiply(N, Scale.v);
- pDestination->v = (((UINT)N.vector4_f32[2] & 0x3FF) << 22) |
- (((UINT)N.vector4_f32[1] & 0x7FF) << 11) |
- (((UINT)N.vector4_f32[0] & 0x7FF));
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- static const XMVECTORF32 ScaleUHenDN3 = {2047.0f, 2047.0f*2048.0f,1023.0f*(2048.0f*2048.0f)/2.0f,1.0f};
- static const XMVECTORI32 MaskUHenDN3 = {0x7FF,0x7FF<<11,0x3FF<<(22-1),0};
- // Clamp to bounds
- XMVECTOR vResult = _mm_max_ps(V,g_XMZero);
- vResult = _mm_min_ps(vResult,g_XMOne);
- // Scale by multiplication
- vResult = _mm_mul_ps(vResult,ScaleUHenDN3);
- // Convert to int
- __m128i vResulti = _mm_cvttps_epi32(vResult);
- // Mask off any fraction
- vResulti = _mm_and_si128(vResulti,MaskUHenDN3);
- // Do a horizontal or of 3 entries
- __m128i vResulti2 = _mm_shuffle_epi32(vResulti,_MM_SHUFFLE(0,3,2,1));
- // i = x|y
- vResulti = _mm_or_si128(vResulti,vResulti2);
- // Move Z to the x position
- vResulti2 = _mm_shuffle_epi32(vResulti2,_MM_SHUFFLE(0,3,2,1));
- // Add Z to itself to perform a single bit left shift
- vResulti2 = _mm_add_epi32(vResulti2,vResulti2);
- // i = x|y|z
- vResulti = _mm_or_si128(vResulti,vResulti2);
- _mm_store_ss(reinterpret_cast<float *>(&pDestination->v),reinterpret_cast<const __m128 *>(&vResulti)[0]);
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreUHenD3
- (
- XMUHEND3* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR N;
- static CONST XMVECTOR Max = {2047.0f, 2047.0f, 1023.0f, 0.0f};
- XMASSERT(pDestination);
- N = XMVectorClamp(V, XMVectorZero(), Max);
- pDestination->v = (((UINT)N.vector4_f32[2] & 0x3FF) << 22) |
- (((UINT)N.vector4_f32[1] & 0x7FF) << 11) |
- (((UINT)N.vector4_f32[0] & 0x7FF));
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- static const XMVECTORF32 MaxUHenD3 = { 2047.0f, 2047.0f, 1023.0f, 1.0f};
- static const XMVECTORF32 ScaleUHenD3 = {1.0f, 2048.0f,(2048.0f*2048.0f)/2.0f,1.0f};
- static const XMVECTORI32 MaskUHenD3 = {0x7FF,0x7FF<<11,0x3FF<<(22-1),0};
- // Clamp to bounds
- XMVECTOR vResult = _mm_max_ps(V,g_XMZero);
- vResult = _mm_min_ps(vResult,MaxUHenD3);
- // Scale by multiplication
- vResult = _mm_mul_ps(vResult,ScaleUHenD3);
- // Convert to int
- __m128i vResulti = _mm_cvttps_epi32(vResult);
- // Mask off any fraction
- vResulti = _mm_and_si128(vResulti,MaskUHenD3);
- // Do a horizontal or of 3 entries
- __m128i vResulti2 = _mm_shuffle_epi32(vResulti,_MM_SHUFFLE(0,3,2,1));
- // i = x|y
- vResulti = _mm_or_si128(vResulti,vResulti2);
- // Move Z to the x position
- vResulti2 = _mm_shuffle_epi32(vResulti2,_MM_SHUFFLE(0,3,2,1));
- // Add Z to itself to perform a single bit left shift
- vResulti2 = _mm_add_epi32(vResulti2,vResulti2);
- // i = x|y|z
- vResulti = _mm_or_si128(vResulti,vResulti2);
- _mm_store_ss(reinterpret_cast<float *>(&pDestination->v),reinterpret_cast<const __m128 *>(&vResulti)[0]);
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreHenDN3
- (
- XMHENDN3* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR N;
- static CONST XMVECTORF32 Scale = {1023.0f, 1023.0f, 511.0f, 1.0f};
- XMASSERT(pDestination);
- N = XMVectorClamp(V, g_XMNegativeOne.v, g_XMOne.v);
- N = XMVectorMultiply(N, Scale.v);
- pDestination->v = (((INT)N.vector4_f32[2] & 0x3FF) << 22) |
- (((INT)N.vector4_f32[1] & 0x7FF) << 11) |
- (((INT)N.vector4_f32[0] & 0x7FF));
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- static const XMVECTORF32 ScaleHenDN3 = {1023.0f, 1023.0f*2048.0f,511.0f*(2048.0f*2048.0f),1.0f};
- // Clamp to bounds
- XMVECTOR vResult = _mm_max_ps(V,g_XMNegativeOne);
- vResult = _mm_min_ps(vResult,g_XMOne);
- // Scale by multiplication
- vResult = _mm_mul_ps(vResult,ScaleHenDN3);
- // Convert to int
- __m128i vResulti = _mm_cvttps_epi32(vResult);
- // Mask off any fraction
- vResulti = _mm_and_si128(vResulti,g_XMMaskHenD3);
- // Do a horizontal or of all 4 entries
- vResult = _mm_shuffle_ps(reinterpret_cast<const __m128 *>(&vResulti)[0],reinterpret_cast<const __m128 *>(&vResulti)[0],_MM_SHUFFLE(0,3,2,1));
- vResulti = _mm_or_si128(vResulti,reinterpret_cast<const __m128i *>(&vResult)[0]);
- vResult = _mm_shuffle_ps(vResult,vResult,_MM_SHUFFLE(0,3,2,1));
- vResulti = _mm_or_si128(vResulti,reinterpret_cast<const __m128i *>(&vResult)[0]);
- _mm_store_ss(reinterpret_cast<float *>(&pDestination->v),reinterpret_cast<const __m128 *>(&vResulti)[0]);
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreHenD3
- (
- XMHEND3* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR N;
- static CONST XMVECTOR Min = {-1023.0f, -1023.0f, -511.0f, -1.0f};
- static CONST XMVECTOR Max = {1023.0f, 1023.0f, 511.0f, 1.0f};
- XMASSERT(pDestination);
- N = XMVectorClamp(V, Min, Max);
- pDestination->v = (((INT)N.vector4_f32[2] & 0x3FF) << 22) |
- (((INT)N.vector4_f32[1] & 0x7FF) << 11) |
- (((INT)N.vector4_f32[0] & 0x7FF));
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- static const XMVECTORF32 MinHenD3 = {-1023.0f,-1023.0f,-511.0f,-1.0f};
- static const XMVECTORF32 MaxHenD3 = { 1023.0f, 1023.0f, 511.0f, 1.0f};
- static const XMVECTORF32 ScaleHenD3 = {1.0f, 2048.0f,(2048.0f*2048.0f),1.0f};
- // Clamp to bounds
- XMVECTOR vResult = _mm_max_ps(V,MinHenD3);
- vResult = _mm_min_ps(vResult,MaxHenD3);
- // Scale by multiplication
- vResult = _mm_mul_ps(vResult,ScaleHenD3);
- // Convert to int
- __m128i vResulti = _mm_cvttps_epi32(vResult);
- // Mask off any fraction
- vResulti = _mm_and_si128(vResulti,g_XMMaskHenD3);
- // Do a horizontal or of all 4 entries
- vResult = _mm_shuffle_ps(reinterpret_cast<const __m128 *>(&vResulti)[0],reinterpret_cast<const __m128 *>(&vResulti)[0],_MM_SHUFFLE(0,3,2,1));
- vResulti = _mm_or_si128(vResulti,reinterpret_cast<const __m128i *>(&vResult)[0]);
- vResult = _mm_shuffle_ps(vResult,vResult,_MM_SHUFFLE(0,3,2,1));
- vResulti = _mm_or_si128(vResulti,reinterpret_cast<const __m128i *>(&vResult)[0]);
- _mm_store_ss(reinterpret_cast<float *>(&pDestination->v),reinterpret_cast<const __m128 *>(&vResulti)[0]);
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreUDHenN3
- (
- XMUDHENN3* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR N;
- static CONST XMVECTORF32 Scale = {1023.0f, 2047.0f, 2047.0f, 0.0f};
- XMASSERT(pDestination);
- N = XMVectorClamp(V, XMVectorZero(), g_XMOne.v);
- N = XMVectorMultiply(N, Scale.v);
- pDestination->v = (((UINT)N.vector4_f32[2] & 0x7FF) << 21) |
- (((UINT)N.vector4_f32[1] & 0x7FF) << 10) |
- (((UINT)N.vector4_f32[0] & 0x3FF));
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- static const XMVECTORF32 ScaleUDHenN3 = {1023.0f,2047.0f*1024.0f,2047.0f*(1024.0f*2048.0f)/2.0f,1.0f};
- static const XMVECTORI32 MaskUDHenN3 = {0x3FF,0x7FF<<10,0x7FF<<(21-1),0};
- // Clamp to bounds
- XMVECTOR vResult = _mm_max_ps(V,g_XMZero);
- vResult = _mm_min_ps(vResult,g_XMOne);
- // Scale by multiplication
- vResult = _mm_mul_ps(vResult,ScaleUDHenN3);
- // Convert to int
- __m128i vResulti = _mm_cvttps_epi32(vResult);
- // Mask off any fraction
- vResulti = _mm_and_si128(vResulti,MaskUDHenN3);
- // Do a horizontal or of 3 entries
- __m128i vResulti2 = _mm_shuffle_epi32(vResulti,_MM_SHUFFLE(0,3,2,1));
- // i = x|y
- vResulti = _mm_or_si128(vResulti,vResulti2);
- // Move Z to the x position
- vResulti2 = _mm_shuffle_epi32(vResulti2,_MM_SHUFFLE(0,3,2,1));
- // Add Z to itself to perform a single bit left shift
- vResulti2 = _mm_add_epi32(vResulti2,vResulti2);
- // i = x|y|z
- vResulti = _mm_or_si128(vResulti,vResulti2);
- _mm_store_ss(reinterpret_cast<float *>(&pDestination->v),reinterpret_cast<const __m128 *>(&vResulti)[0]);
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreUDHen3
- (
- XMUDHEN3* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR N;
- static CONST XMVECTOR Max = {1023.0f, 2047.0f, 2047.0f, 0.0f};
- XMASSERT(pDestination);
- N = XMVectorClamp(V, XMVectorZero(), Max);
- pDestination->v = (((UINT)N.vector4_f32[2] & 0x7FF) << 21) |
- (((UINT)N.vector4_f32[1] & 0x7FF) << 10) |
- (((UINT)N.vector4_f32[0] & 0x3FF));
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- static const XMVECTORF32 MaxUDHen3 = { 1023.0f, 2047.0f, 2047.0f, 1.0f};
- static const XMVECTORF32 ScaleUDHen3 = {1.0f, 1024.0f,(1024.0f*2048.0f)/2.0f,1.0f};
- static const XMVECTORI32 MaskUDHen3 = {0x3FF,0x7FF<<10,0x7FF<<(21-1),0};
- // Clamp to bounds
- XMVECTOR vResult = _mm_max_ps(V,g_XMZero);
- vResult = _mm_min_ps(vResult,MaxUDHen3);
- // Scale by multiplication
- vResult = _mm_mul_ps(vResult,ScaleUDHen3);
- // Convert to int
- __m128i vResulti = _mm_cvttps_epi32(vResult);
- // Mask off any fraction
- vResulti = _mm_and_si128(vResulti,MaskUDHen3);
- // Do a horizontal or of 3 entries
- __m128i vResulti2 = _mm_shuffle_epi32(vResulti,_MM_SHUFFLE(0,3,2,1));
- // i = x|y
- vResulti = _mm_or_si128(vResulti,vResulti2);
- // Move Z to the x position
- vResulti2 = _mm_shuffle_epi32(vResulti2,_MM_SHUFFLE(0,3,2,1));
- // Add Z to itself to perform a single bit left shift
- vResulti2 = _mm_add_epi32(vResulti2,vResulti2);
- // i = x|y|z
- vResulti = _mm_or_si128(vResulti,vResulti2);
- _mm_store_ss(reinterpret_cast<float *>(&pDestination->v),reinterpret_cast<const __m128 *>(&vResulti)[0]);
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreDHenN3
- (
- XMDHENN3* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR N;
- static CONST XMVECTORF32 Scale = {511.0f, 1023.0f, 1023.0f, 1.0f};
- XMASSERT(pDestination);
- N = XMVectorClamp(V, g_XMNegativeOne.v, g_XMOne.v);
- N = XMVectorMultiply(N, Scale.v);
- pDestination->v = (((INT)N.vector4_f32[2] & 0x7FF) << 21) |
- (((INT)N.vector4_f32[1] & 0x7FF) << 10) |
- (((INT)N.vector4_f32[0] & 0x3FF));
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- static const XMVECTORF32 ScaleDHenN3 = {511.0f, 1023.0f*1024.0f,1023.0f*(1024.0f*2048.0f),1.0f};
- // Clamp to bounds
- XMVECTOR vResult = _mm_max_ps(V,g_XMNegativeOne);
- vResult = _mm_min_ps(vResult,g_XMOne);
- // Scale by multiplication
- vResult = _mm_mul_ps(vResult,ScaleDHenN3);
- // Convert to int
- __m128i vResulti = _mm_cvttps_epi32(vResult);
- // Mask off any fraction
- vResulti = _mm_and_si128(vResulti,g_XMMaskDHen3);
- // Do a horizontal or of all 4 entries
- vResult = _mm_shuffle_ps(reinterpret_cast<const __m128 *>(&vResulti)[0],reinterpret_cast<const __m128 *>(&vResulti)[0],_MM_SHUFFLE(0,3,2,1));
- vResulti = _mm_or_si128(vResulti,reinterpret_cast<const __m128i *>(&vResult)[0]);
- vResult = _mm_shuffle_ps(vResult,vResult,_MM_SHUFFLE(0,3,2,1));
- vResulti = _mm_or_si128(vResulti,reinterpret_cast<const __m128i *>(&vResult)[0]);
- _mm_store_ss(reinterpret_cast<float *>(&pDestination->v),reinterpret_cast<const __m128 *>(&vResulti)[0]);
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreDHen3
- (
- XMDHEN3* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR N;
- static CONST XMVECTOR Min = {-511.0f, -1023.0f, -1023.0f, -1.0f};
- static CONST XMVECTOR Max = {511.0f, 1023.0f, 1023.0f, 1.0f};
- XMASSERT(pDestination);
- N = XMVectorClamp(V, Min, Max);
- pDestination->v = (((INT)N.vector4_f32[2] & 0x7FF) << 21) |
- (((INT)N.vector4_f32[1] & 0x7FF) << 10) |
- (((INT)N.vector4_f32[0] & 0x3FF));
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- static const XMVECTORF32 MinDHen3 = {-511.0f,-1023.0f,-1023.0f,-1.0f};
- static const XMVECTORF32 MaxDHen3 = { 511.0f, 1023.0f, 1023.0f, 1.0f};
- static const XMVECTORF32 ScaleDHen3 = {1.0f, 1024.0f,(1024.0f*2048.0f),1.0f};
- // Clamp to bounds
- XMVECTOR vResult = _mm_max_ps(V,MinDHen3);
- vResult = _mm_min_ps(vResult,MaxDHen3);
- // Scale by multiplication
- vResult = _mm_mul_ps(vResult,ScaleDHen3);
- // Convert to int
- __m128i vResulti = _mm_cvttps_epi32(vResult);
- // Mask off any fraction
- vResulti = _mm_and_si128(vResulti,g_XMMaskDHen3);
- // Do a horizontal or of all 4 entries
- vResult = _mm_shuffle_ps(reinterpret_cast<const __m128 *>(&vResulti)[0],reinterpret_cast<const __m128 *>(&vResulti)[0],_MM_SHUFFLE(0,3,2,1));
- vResulti = _mm_or_si128(vResulti,reinterpret_cast<const __m128i *>(&vResult)[0]);
- vResult = _mm_shuffle_ps(vResult,vResult,_MM_SHUFFLE(0,3,2,1));
- vResulti = _mm_or_si128(vResulti,reinterpret_cast<const __m128i *>(&vResult)[0]);
- _mm_store_ss(reinterpret_cast<float *>(&pDestination->v),reinterpret_cast<const __m128 *>(&vResulti)[0]);
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreU565
- (
- XMU565* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_SSE_INTRINSICS_) && !defined(_XM_NO_INTRINSICS_)
- XMASSERT(pDestination);
- static CONST XMVECTORF32 Max = {31.0f, 63.0f, 31.0f, 0.0f};
- // Bounds check
- XMVECTOR vResult = _mm_max_ps(V,g_XMZero);
- vResult = _mm_min_ps(vResult,Max);
- // Convert to int with rounding
- __m128i vInt = _mm_cvtps_epi32(vResult);
- // No SSE operations will write to 16-bit values, so we have to extract them manually
- USHORT x = static_cast<USHORT>(_mm_extract_epi16(vInt,0));
- USHORT y = static_cast<USHORT>(_mm_extract_epi16(vInt,2));
- USHORT z = static_cast<USHORT>(_mm_extract_epi16(vInt,4));
- pDestination->v = ((z & 0x1F) << 11) |
- ((y & 0x3F) << 5) |
- ((x & 0x1F));
- #else
- XMVECTOR N;
- static CONST XMVECTORF32 Max = {31.0f, 63.0f, 31.0f, 0.0f};
- XMASSERT(pDestination);
- N = XMVectorClamp(V, XMVectorZero(), Max.v);
- N = XMVectorRound(N);
- pDestination->v = (((USHORT)N.vector4_f32[2] & 0x1F) << 11) |
- (((USHORT)N.vector4_f32[1] & 0x3F) << 5) |
- (((USHORT)N.vector4_f32[0] & 0x1F));
- #endif !_XM_SSE_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreFloat3PK
- (
- XMFLOAT3PK* pDestination,
- FXMVECTOR V
- )
- {
- _DECLSPEC_ALIGN_16_ UINT IValue[4];
- UINT I, Sign, j;
- UINT Result[3];
- XMASSERT(pDestination);
- XMStoreFloat3A( (XMFLOAT3A*)&IValue, V );
- // X & Y Channels (5-bit exponent, 6-bit mantissa)
- for(j=0; j < 2; ++j)
- {
- Sign = IValue[j] & 0x80000000;
- I = IValue[j] & 0x7FFFFFFF;
- if ((I & 0x7F800000) == 0x7F800000)
- {
- // INF or NAN
- Result[j] = 0x7c0;
- if (( I & 0x7FFFFF ) != 0)
- {
- Result[j] = 0x7c0 | (((I>>17)|(I>11)|(I>>6)|(I))&0x3f);
- }
- else if ( Sign )
- {
- // -INF is clamped to 0 since 3PK is positive only
- Result[j] = 0;
- }
- }
- else if ( Sign )
- {
- // 3PK is positive only, so clamp to zero
- Result[j] = 0;
- }
- else if (I > 0x477E0000U)
- {
- // The number is too large to be represented as a float11, set to max
- Result[j] = 0x7BF;
- }
- else
- {
- if (I < 0x38800000U)
- {
- // The number is too small to be represented as a normalized float11
- // Convert it to a denormalized value.
- UINT Shift = 113U - (I >> 23U);
- I = (0x800000U | (I & 0x7FFFFFU)) >> Shift;
- }
- else
- {
- // Rebias the exponent to represent the value as a normalized float11
- I += 0xC8000000U;
- }
-
- Result[j] = ((I + 0xFFFFU + ((I >> 17U) & 1U)) >> 17U)&0x7ffU;
- }
- }
- // Z Channel (5-bit exponent, 5-bit mantissa)
- Sign = IValue[2] & 0x80000000;
- I = IValue[2] & 0x7FFFFFFF;
- if ((I & 0x7F800000) == 0x7F800000)
- {
- // INF or NAN
- Result[2] = 0x3e0;
- if ( I & 0x7FFFFF )
- {
- Result[2] = 0x3e0 | (((I>>18)|(I>13)|(I>>3)|(I))&0x1f);
- }
- else if ( Sign )
- {
- // -INF is clamped to 0 since 3PK is positive only
- Result[2] = 0;
- }
- }
- else if ( Sign )
- {
- // 3PK is positive only, so clamp to zero
- Result[2] = 0;
- }
- else if (I > 0x477C0000U)
- {
- // The number is too large to be represented as a float10, set to max
- Result[2] = 0x3df;
- }
- else
- {
- if (I < 0x38800000U)
- {
- // The number is too small to be represented as a normalized float10
- // Convert it to a denormalized value.
- UINT Shift = 113U - (I >> 23U);
- I = (0x800000U | (I & 0x7FFFFFU)) >> Shift;
- }
- else
- {
- // Rebias the exponent to represent the value as a normalized float10
- I += 0xC8000000U;
- }
-
- Result[2] = ((I + 0x1FFFFU + ((I >> 18U) & 1U)) >> 18U)&0x3ffU;
- }
- // Pack Result into memory
- pDestination->v = (Result[0] & 0x7ff)
- | ( (Result[1] & 0x7ff) << 11 )
- | ( (Result[2] & 0x3ff) << 22 );
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreFloat3SE
- (
- XMFLOAT3SE* pDestination,
- FXMVECTOR V
- )
- {
- _DECLSPEC_ALIGN_16_ UINT IValue[4];
- UINT I, Sign, j, T;
- UINT Frac[3];
- UINT Exp[3];
-
- XMASSERT(pDestination);
- XMStoreFloat3A( (XMFLOAT3A*)&IValue, V );
- // X, Y, Z Channels (5-bit exponent, 9-bit mantissa)
- for(j=0; j < 3; ++j)
- {
- Sign = IValue[j] & 0x80000000;
- I = IValue[j] & 0x7FFFFFFF;
- if ((I & 0x7F800000) == 0x7F800000)
- {
- // INF or NAN
- Exp[j] = 0x1f;
- if (( I & 0x7FFFFF ) != 0)
- {
- Frac[j] = ((I>>14)|(I>5)|(I))&0x1ff;
- }
- else if ( Sign )
- {
- // -INF is clamped to 0 since 3SE is positive only
- Exp[j] = Frac[j] = 0;
- }
- }
- else if ( Sign )
- {
- // 3SE is positive only, so clamp to zero
- Exp[j] = Frac[j] = 0;
- }
- else if (I > 0x477FC000U)
- {
- // The number is too large, set to max
- Exp[j] = 0x1e;
- Frac[j] = 0x1ff;
- }
- else
- {
- if (I < 0x38800000U)
- {
- // The number is too small to be represented as a normalized float11
- // Convert it to a denormalized value.
- UINT Shift = 113U - (I >> 23U);
- I = (0x800000U | (I & 0x7FFFFFU)) >> Shift;
- }
- else
- {
- // Rebias the exponent to represent the value as a normalized float11
- I += 0xC8000000U;
- }
-
- T = ((I + 0x1FFFU + ((I >> 14U) & 1U)) >> 14U)&0x3fffU;
- Exp[j] = (T & 0x3E00) >> 9;
- Frac[j] = T & 0x1ff;
- }
- }
- // Adjust to a shared exponent
- T = XMMax( Exp[0], XMMax( Exp[1], Exp[2] ) );
- Frac[0] = Frac[0] >> (T - Exp[0]);
- Frac[1] = Frac[1] >> (T - Exp[1]);
- Frac[2] = Frac[2] >> (T - Exp[2]);
- // Store packed into memory
- pDestination->xm = Frac[0];
- pDestination->ym = Frac[1];
- pDestination->zm = Frac[2];
- pDestination->e = T;
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreInt4
- (
- UINT* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMASSERT(pDestination);
- pDestination[0] = V.vector4_u32[0];
- pDestination[1] = V.vector4_u32[1];
- pDestination[2] = V.vector4_u32[2];
- pDestination[3] = V.vector4_u32[3];
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
-
- _mm_storeu_si128( (__m128i*)pDestination, reinterpret_cast<const __m128i *>(&V)[0] );
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreInt4A
- (
- UINT* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMASSERT(pDestination);
- XMASSERT(((UINT_PTR)pDestination & 0xF) == 0);
- pDestination[0] = V.vector4_u32[0];
- pDestination[1] = V.vector4_u32[1];
- pDestination[2] = V.vector4_u32[2];
- pDestination[3] = V.vector4_u32[3];
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- XMASSERT(((UINT_PTR)pDestination & 0xF) == 0);
- _mm_store_si128( (__m128i*)pDestination, reinterpret_cast<const __m128i *>(&V)[0] );
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreInt4NC
- (
- UINT* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMASSERT(pDestination);
- XMASSERT(((UINT_PTR)pDestination & 3) == 0);
-
- pDestination[0] = V.vector4_u32[0];
- pDestination[1] = V.vector4_u32[1];
- pDestination[2] = V.vector4_u32[2];
- pDestination[3] = V.vector4_u32[3];
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- XMASSERT(((UINT_PTR)pDestination & 3) == 0);
-
- _mm_storeu_si128( (__m128i*)pDestination, reinterpret_cast<const __m128i *>(&V)[0] );
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreFloat4
- (
- XMFLOAT4* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMASSERT(pDestination);
-
- pDestination->x = V.vector4_f32[0];
- pDestination->y = V.vector4_f32[1];
- pDestination->z = V.vector4_f32[2];
- pDestination->w = V.vector4_f32[3];
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
-
- _mm_storeu_ps( &pDestination->x, V );
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreFloat4A
- (
- XMFLOAT4A* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMASSERT(pDestination);
- XMASSERT(((UINT_PTR)pDestination & 0xF) == 0);
- pDestination->x = V.vector4_f32[0];
- pDestination->y = V.vector4_f32[1];
- pDestination->z = V.vector4_f32[2];
- pDestination->w = V.vector4_f32[3];
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- XMASSERT(((UINT_PTR)pDestination & 0xF) == 0);
- _mm_store_ps( &pDestination->x, V );
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreFloat4NC
- (
- XMFLOAT4* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMASSERT(pDestination);
- XMASSERT(((UINT_PTR)pDestination & 3) == 0);
-
- pDestination->x = V.vector4_f32[0];
- pDestination->y = V.vector4_f32[1];
- pDestination->z = V.vector4_f32[2];
- pDestination->w = V.vector4_f32[3];
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- XMASSERT(((UINT_PTR)pDestination & 3) == 0);
-
- _mm_storeu_ps( &pDestination->x, V );
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreHalf4
- (
- XMHALF4* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMASSERT(pDestination);
- pDestination->x = XMConvertFloatToHalf(V.vector4_f32[0]);
- pDestination->y = XMConvertFloatToHalf(V.vector4_f32[1]);
- pDestination->z = XMConvertFloatToHalf(V.vector4_f32[2]);
- pDestination->w = XMConvertFloatToHalf(V.vector4_f32[3]);
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- pDestination->x = XMConvertFloatToHalf(XMVectorGetX(V));
- pDestination->y = XMConvertFloatToHalf(XMVectorGetY(V));
- pDestination->z = XMConvertFloatToHalf(XMVectorGetZ(V));
- pDestination->w = XMConvertFloatToHalf(XMVectorGetW(V));
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreShortN4
- (
- XMSHORTN4* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR N;
- static CONST XMVECTORF32 Scale = {32767.0f, 32767.0f, 32767.0f, 32767.0f};
- XMASSERT(pDestination);
- N = XMVectorClamp(V, g_XMNegativeOne.v, g_XMOne.v);
- N = XMVectorMultiply(N, Scale.v);
- N = XMVectorRound(N);
- pDestination->x = (SHORT)N.vector4_f32[0];
- pDestination->y = (SHORT)N.vector4_f32[1];
- pDestination->z = (SHORT)N.vector4_f32[2];
- pDestination->w = (SHORT)N.vector4_f32[3];
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- static CONST XMVECTORF32 Scale = {32767.0f, 32767.0f, 32767.0f, 32767.0f};
- XMVECTOR vResult = _mm_max_ps(V,g_XMNegativeOne);
- vResult = _mm_min_ps(vResult,g_XMOne);
- vResult = _mm_mul_ps(vResult,Scale);
- __m128i vResulti = _mm_cvtps_epi32(vResult);
- vResulti = _mm_packs_epi32(vResulti,vResulti);
- _mm_store_sd(reinterpret_cast<double *>(&pDestination->x),reinterpret_cast<const __m128d *>(&vResulti)[0]);
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreShort4
- (
- XMSHORT4* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR N;
- static CONST XMVECTOR Min = {-32767.0f, -32767.0f, -32767.0f, -32767.0f};
- static CONST XMVECTOR Max = {32767.0f, 32767.0f, 32767.0f, 32767.0f};
- XMASSERT(pDestination);
- N = XMVectorClamp(V, Min, Max);
- N = XMVectorRound(N);
- pDestination->x = (SHORT)N.vector4_f32[0];
- pDestination->y = (SHORT)N.vector4_f32[1];
- pDestination->z = (SHORT)N.vector4_f32[2];
- pDestination->w = (SHORT)N.vector4_f32[3];
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- static CONST XMVECTORF32 Min = {-32767.0f, -32767.0f, -32767.0f, -32767.0f};
- static CONST XMVECTORF32 Max = {32767.0f, 32767.0f, 32767.0f, 32767.0f};
- // Bounds check
- XMVECTOR vResult = _mm_max_ps(V,Min);
- vResult = _mm_min_ps(vResult,Max);
- // Convert to int with rounding
- __m128i vInt = _mm_cvtps_epi32(vResult);
- // Pack the ints into shorts
- vInt = _mm_packs_epi32(vInt,vInt);
- _mm_store_sd(reinterpret_cast<double *>(&pDestination->x),reinterpret_cast<const __m128d *>(&vInt)[0]);
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreUShortN4
- (
- XMUSHORTN4* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR N;
- static CONST XMVECTORF32 Scale = {65535.0f, 65535.0f, 65535.0f, 65535.0f};
- XMASSERT(pDestination);
- N = XMVectorClamp(V, XMVectorZero(), g_XMOne.v);
- N = XMVectorMultiplyAdd(N, Scale.v, g_XMOneHalf.v);
- N = XMVectorTruncate(N);
- pDestination->x = (SHORT)N.vector4_f32[0];
- pDestination->y = (SHORT)N.vector4_f32[1];
- pDestination->z = (SHORT)N.vector4_f32[2];
- pDestination->w = (SHORT)N.vector4_f32[3];
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- static CONST XMVECTORF32 Scale = {65535.0f, 65535.0f, 65535.0f, 65535.0f};
- // Bounds check
- XMVECTOR vResult = _mm_max_ps(V,g_XMZero);
- vResult = _mm_min_ps(vResult,g_XMOne);
- vResult = _mm_mul_ps(vResult,Scale);
- // Convert to int with rounding
- __m128i vInt = _mm_cvtps_epi32(vResult);
- // Since the SSE pack instruction clamps using signed rules,
- // manually extract the values to store them to memory
- pDestination->x = static_cast<SHORT>(_mm_extract_epi16(vInt,0));
- pDestination->y = static_cast<SHORT>(_mm_extract_epi16(vInt,2));
- pDestination->z = static_cast<SHORT>(_mm_extract_epi16(vInt,4));
- pDestination->w = static_cast<SHORT>(_mm_extract_epi16(vInt,6));
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreUShort4
- (
- XMUSHORT4* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR N;
- static CONST XMVECTOR Max = {65535.0f, 65535.0f, 65535.0f, 65535.0f};
- XMASSERT(pDestination);
- N = XMVectorClamp(V, XMVectorZero(), Max);
- N = XMVectorRound(N);
- pDestination->x = (SHORT)N.vector4_f32[0];
- pDestination->y = (SHORT)N.vector4_f32[1];
- pDestination->z = (SHORT)N.vector4_f32[2];
- pDestination->w = (SHORT)N.vector4_f32[3];
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- static CONST XMVECTORF32 Max = {65535.0f, 65535.0f, 65535.0f, 65535.0f};
- // Bounds check
- XMVECTOR vResult = _mm_max_ps(V,g_XMZero);
- vResult = _mm_min_ps(vResult,Max);
- // Convert to int with rounding
- __m128i vInt = _mm_cvtps_epi32(vResult);
- // Since the SSE pack instruction clamps using signed rules,
- // manually extract the values to store them to memory
- pDestination->x = static_cast<SHORT>(_mm_extract_epi16(vInt,0));
- pDestination->y = static_cast<SHORT>(_mm_extract_epi16(vInt,2));
- pDestination->z = static_cast<SHORT>(_mm_extract_epi16(vInt,4));
- pDestination->w = static_cast<SHORT>(_mm_extract_epi16(vInt,6));
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreXIcoN4
- (
- XMXICON4* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR N;
- static CONST XMVECTORF32 Min = {-1.0f, -1.0f, -1.0f, 0.0f};
- static CONST XMVECTORF32 Scale = {524287.0f, 524287.0f, 524287.0f, 15.0f};
- XMASSERT(pDestination);
- N = XMVectorClamp(V, Min.v, g_XMOne.v);
- N = XMVectorMultiply(N, Scale.v);
- N = XMVectorRound(N);
- pDestination->v = ((UINT64)N.vector4_f32[3] << 60) |
- (((INT64)N.vector4_f32[2] & 0xFFFFF) << 40) |
- (((INT64)N.vector4_f32[1] & 0xFFFFF) << 20) |
- (((INT64)N.vector4_f32[0] & 0xFFFFF));
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- // Note: Masks are x,w,y and z
- static const XMVECTORF32 MinXIcoN4 = {-1.0f, 0.0f,-1.0f,-1.0f};
- static const XMVECTORF32 ScaleXIcoN4 = {524287.0f,15.0f*4096.0f*65536.0f*0.5f,524287.0f*4096.0f,524287.0f};
- static const XMVECTORI32 MaskXIcoN4 = {0xFFFFF,0xF<<((60-32)-1),0xFFFFF000,0xFFFFF};
- // Clamp to bounds
- XMVECTOR vResult = _mm_shuffle_ps(V,V,_MM_SHUFFLE(2,1,3,0));
- vResult = _mm_max_ps(vResult,MinXIcoN4);
- vResult = _mm_min_ps(vResult,g_XMOne);
- // Scale by multiplication
- vResult = _mm_mul_ps(vResult,ScaleXIcoN4);
- // Convert to integer (w is unsigned)
- __m128i vResulti = _mm_cvttps_epi32(vResult);
- // Mask off unused bits
- vResulti = _mm_and_si128(vResulti,MaskXIcoN4);
- // Isolate Y
- __m128i vResulti2 = _mm_and_si128(vResulti,g_XMMaskY);
- // Double Y (Really W) to fixup for unsigned conversion
- vResulti = _mm_add_epi32(vResulti,vResulti2);
- // Shift y and z to straddle the 32-bit boundary
- vResulti2 = _mm_srli_si128(vResulti,(64+12)/8);
- // Shift it into place
- vResulti2 = _mm_slli_si128(vResulti2,20/8);
- // i = x|y<<20|z<<40|w<<60
- vResulti = _mm_or_si128(vResulti,vResulti2);
- _mm_store_sd(reinterpret_cast<double *>(&pDestination->v),reinterpret_cast<const __m128d *>(&vResulti)[0]);
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreXIco4
- (
- XMXICO4* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR N;
- static CONST XMVECTORF32 Min = {-524287.0f, -524287.0f, -524287.0f, 0.0f};
- static CONST XMVECTORF32 Max = {524287.0f, 524287.0f, 524287.0f, 15.0f};
- XMASSERT(pDestination);
- N = XMVectorClamp(V, Min.v, Max.v);
- pDestination->v = ((UINT64)N.vector4_f32[3] << 60) |
- (((INT64)N.vector4_f32[2] & 0xFFFFF) << 40) |
- (((INT64)N.vector4_f32[1] & 0xFFFFF) << 20) |
- (((INT64)N.vector4_f32[0] & 0xFFFFF));
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- // Note: Masks are x,w,y and z
- static const XMVECTORF32 MinXIco4 = {-524287.0f, 0.0f,-524287.0f,-524287.0f};
- static const XMVECTORF32 MaxXIco4 = { 524287.0f,15.0f, 524287.0f, 524287.0f};
- static const XMVECTORF32 ScaleXIco4 = {1.0f,4096.0f*65536.0f*0.5f,4096.0f,1.0f};
- static const XMVECTORI32 MaskXIco4 = {0xFFFFF,0xF<<((60-1)-32),0xFFFFF000,0xFFFFF};
- // Clamp to bounds
- XMVECTOR vResult = _mm_shuffle_ps(V,V,_MM_SHUFFLE(2,1,3,0));
- vResult = _mm_max_ps(vResult,MinXIco4);
- vResult = _mm_min_ps(vResult,MaxXIco4);
- // Scale by multiplication
- vResult = _mm_mul_ps(vResult,ScaleXIco4);
- // Convert to int
- __m128i vResulti = _mm_cvttps_epi32(vResult);
- // Mask off any fraction
- vResulti = _mm_and_si128(vResulti,MaskXIco4);
- // Isolate Y
- __m128i vResulti2 = _mm_and_si128(vResulti,g_XMMaskY);
- // Double Y (Really W) to fixup for unsigned conversion
- vResulti = _mm_add_epi32(vResulti,vResulti2);
- // Shift y and z to straddle the 32-bit boundary
- vResulti2 = _mm_srli_si128(vResulti,(64+12)/8);
- // Shift it into place
- vResulti2 = _mm_slli_si128(vResulti2,20/8);
- // i = x|y<<20|z<<40|w<<60
- vResulti = _mm_or_si128(vResulti,vResulti2);
- _mm_store_sd(reinterpret_cast<double *>(&pDestination->v),reinterpret_cast<const __m128d *>(&vResulti)[0]);
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreUIcoN4
- (
- XMUICON4* pDestination,
- FXMVECTOR V
- )
- {
- #define XM_URange ((FLOAT)(1 << 20))
- #define XM_URangeDiv2 ((FLOAT)(1 << 19))
- #define XM_UMaxXYZ ((FLOAT)((1 << 20) - 1))
- #define XM_UMaxW ((FLOAT)((1 << 4) - 1))
- #define XM_ScaleXYZ (-(FLOAT)((1 << 20) - 1) / XM_PACK_FACTOR)
- #define XM_ScaleW (-(FLOAT)((1 << 4) - 1) / XM_PACK_FACTOR)
- #define XM_Scale (-1.0f / XM_PACK_FACTOR)
- #define XM_Offset (3.0f)
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR N;
- static CONST XMVECTORF32 Scale = {1048575.0f, 1048575.0f, 1048575.0f, 15.0f};
- XMASSERT(pDestination);
- N = XMVectorClamp(V, XMVectorZero(), g_XMOne.v);
- N = XMVectorMultiplyAdd(N, Scale.v, g_XMOneHalf.v);
- pDestination->v = ((UINT64)N.vector4_f32[3] << 60) |
- (((UINT64)N.vector4_f32[2] & 0xFFFFF) << 40) |
- (((UINT64)N.vector4_f32[1] & 0xFFFFF) << 20) |
- (((UINT64)N.vector4_f32[0] & 0xFFFFF));
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- // Note: Masks are x,w,y and z
- static const XMVECTORF32 ScaleUIcoN4 = {1048575.0f,15.0f*4096.0f*65536.0f,1048575.0f*4096.0f,1048575.0f};
- static const XMVECTORI32 MaskUIcoN4 = {0xFFFFF,0xF<<(60-32),0xFFFFF000,0xFFFFF};
- static const XMVECTORF32 AddUIcoN4 = {0.0f,-32768.0f*65536.0f,-32768.0f*65536.0f,0.0f};
- // Clamp to bounds
- XMVECTOR vResult = _mm_shuffle_ps(V,V,_MM_SHUFFLE(2,1,3,0));
- vResult = _mm_max_ps(vResult,g_XMZero);
- vResult = _mm_min_ps(vResult,g_XMOne);
- // Scale by multiplication
- vResult = _mm_mul_ps(vResult,ScaleUIcoN4);
- // Adjust for unsigned entries
- vResult = _mm_add_ps(vResult,AddUIcoN4);
- // Convert to int
- __m128i vResulti = _mm_cvttps_epi32(vResult);
- // Fix the signs on the unsigned entries
- vResulti = _mm_xor_si128(vResulti,g_XMFlipYZ);
- // Mask off any fraction
- vResulti = _mm_and_si128(vResulti,MaskUIcoN4);
- // Shift y and z to straddle the 32-bit boundary
- __m128i vResulti2 = _mm_srli_si128(vResulti,(64+12)/8);
- // Shift it into place
- vResulti2 = _mm_slli_si128(vResulti2,20/8);
- // i = x|y<<20|z<<40|w<<60
- vResulti = _mm_or_si128(vResulti,vResulti2);
- _mm_store_sd(reinterpret_cast<double *>(&pDestination->v),reinterpret_cast<const __m128d *>(&vResulti)[0]);
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- #undef XM_URange
- #undef XM_URangeDiv2
- #undef XM_UMaxXYZ
- #undef XM_UMaxW
- #undef XM_ScaleXYZ
- #undef XM_ScaleW
- #undef XM_Scale
- #undef XM_Offset
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreUIco4
- (
- XMUICO4* pDestination,
- FXMVECTOR V
- )
- {
- #define XM_Scale (-1.0f / XM_PACK_FACTOR)
- #define XM_URange ((FLOAT)(1 << 20))
- #define XM_URangeDiv2 ((FLOAT)(1 << 19))
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR N;
- static CONST XMVECTOR Max = {1048575.0f, 1048575.0f, 1048575.0f, 15.0f};
- XMASSERT(pDestination);
- N = XMVectorClamp(V, XMVectorZero(), Max);
- N = XMVectorRound(N);
- pDestination->v = ((UINT64)N.vector4_f32[3] << 60) |
- (((UINT64)N.vector4_f32[2] & 0xFFFFF) << 40) |
- (((UINT64)N.vector4_f32[1] & 0xFFFFF) << 20) |
- (((UINT64)N.vector4_f32[0] & 0xFFFFF));
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- // Note: Masks are x,w,y and z
- static const XMVECTORF32 MaxUIco4 = { 1048575.0f, 15.0f, 1048575.0f, 1048575.0f};
- static const XMVECTORF32 ScaleUIco4 = {1.0f,4096.0f*65536.0f,4096.0f,1.0f};
- static const XMVECTORI32 MaskUIco4 = {0xFFFFF,0xF<<(60-32),0xFFFFF000,0xFFFFF};
- static const XMVECTORF32 AddUIco4 = {0.0f,-32768.0f*65536.0f,-32768.0f*65536.0f,0.0f};
- // Clamp to bounds
- XMVECTOR vResult = _mm_shuffle_ps(V,V,_MM_SHUFFLE(2,1,3,0));
- vResult = _mm_max_ps(vResult,g_XMZero);
- vResult = _mm_min_ps(vResult,MaxUIco4);
- // Scale by multiplication
- vResult = _mm_mul_ps(vResult,ScaleUIco4);
- vResult = _mm_add_ps(vResult,AddUIco4);
- // Convert to int
- __m128i vResulti = _mm_cvttps_epi32(vResult);
- vResulti = _mm_xor_si128(vResulti,g_XMFlipYZ);
- // Mask off any fraction
- vResulti = _mm_and_si128(vResulti,MaskUIco4);
- // Shift y and z to straddle the 32-bit boundary
- __m128i vResulti2 = _mm_srli_si128(vResulti,(64+12)/8);
- // Shift it into place
- vResulti2 = _mm_slli_si128(vResulti2,20/8);
- // i = x|y<<20|z<<40|w<<60
- vResulti = _mm_or_si128(vResulti,vResulti2);
- _mm_store_sd(reinterpret_cast<double *>(&pDestination->v),reinterpret_cast<const __m128d *>(&vResulti)[0]);
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- #undef XM_Scale
- #undef XM_URange
- #undef XM_URangeDiv2
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreIcoN4
- (
- XMICON4* pDestination,
- FXMVECTOR V
- )
- {
- #define XM_Scale (-1.0f / XM_PACK_FACTOR)
- #define XM_URange ((FLOAT)(1 << 4))
- #define XM_Offset (3.0f)
- #define XM_UMaxXYZ ((FLOAT)((1 << (20 - 1)) - 1))
- #define XM_UMaxW ((FLOAT)((1 << (4 - 1)) - 1))
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR N;
- static CONST XMVECTORF32 Scale = {524287.0f, 524287.0f, 524287.0f, 7.0f};
- XMASSERT(pDestination);
- N = XMVectorClamp(V, g_XMNegativeOne.v, g_XMOne.v);
- N = XMVectorMultiplyAdd(N, Scale.v, g_XMNegativeZero.v);
- N = XMVectorRound(N);
- pDestination->v = ((UINT64)N.vector4_f32[3] << 60) |
- (((UINT64)N.vector4_f32[2] & 0xFFFFF) << 40) |
- (((UINT64)N.vector4_f32[1] & 0xFFFFF) << 20) |
- (((UINT64)N.vector4_f32[0] & 0xFFFFF));
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- // Note: Masks are x,w,y and z
- static const XMVECTORF32 ScaleIcoN4 = {524287.0f,7.0f*4096.0f*65536.0f,524287.0f*4096.0f,524287.0f};
- static const XMVECTORI32 MaskIcoN4 = {0xFFFFF,0xF<<(60-32),0xFFFFF000,0xFFFFF};
- // Clamp to bounds
- XMVECTOR vResult = _mm_shuffle_ps(V,V,_MM_SHUFFLE(2,1,3,0));
- vResult = _mm_max_ps(vResult,g_XMNegativeOne);
- vResult = _mm_min_ps(vResult,g_XMOne);
- // Scale by multiplication
- vResult = _mm_mul_ps(vResult,ScaleIcoN4);
- // Convert to int
- __m128i vResulti = _mm_cvttps_epi32(vResult);
- // Mask off any fraction
- vResulti = _mm_and_si128(vResulti,MaskIcoN4);
- // Shift y and z to straddle the 32-bit boundary
- __m128i vResulti2 = _mm_srli_si128(vResulti,(64+12)/8);
- // Shift it into place
- vResulti2 = _mm_slli_si128(vResulti2,20/8);
- // i = x|y<<20|z<<40|w<<60
- vResulti = _mm_or_si128(vResulti,vResulti2);
- _mm_store_sd(reinterpret_cast<double *>(&pDestination->v),reinterpret_cast<const __m128d *>(&vResulti)[0]);
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- #undef XM_Scale
- #undef XM_URange
- #undef XM_Offset
- #undef XM_UMaxXYZ
- #undef XM_UMaxW
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreIco4
- (
- XMICO4* pDestination,
- FXMVECTOR V
- )
- {
- #define XM_Scale (-1.0f / XM_PACK_FACTOR)
- #define XM_URange ((FLOAT)(1 << 4))
- #define XM_Offset (3.0f)
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR N;
- static CONST XMVECTOR Min = {-524287.0f, -524287.0f, -524287.0f, -7.0f};
- static CONST XMVECTOR Max = {524287.0f, 524287.0f, 524287.0f, 7.0f};
- XMASSERT(pDestination);
- N = XMVectorClamp(V, Min, Max);
- N = XMVectorRound(N);
- pDestination->v = ((INT64)N.vector4_f32[3] << 60) |
- (((INT64)N.vector4_f32[2] & 0xFFFFF) << 40) |
- (((INT64)N.vector4_f32[1] & 0xFFFFF) << 20) |
- (((INT64)N.vector4_f32[0] & 0xFFFFF));
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- // Note: Masks are x,w,y and z
- static const XMVECTORF32 MinIco4 = {-524287.0f,-7.0f,-524287.0f,-524287.0f};
- static const XMVECTORF32 MaxIco4 = { 524287.0f, 7.0f, 524287.0f, 524287.0f};
- static const XMVECTORF32 ScaleIco4 = {1.0f,4096.0f*65536.0f,4096.0f,1.0f};
- static const XMVECTORI32 MaskIco4 = {0xFFFFF,0xF<<(60-32),0xFFFFF000,0xFFFFF};
- // Clamp to bounds
- XMVECTOR vResult = _mm_shuffle_ps(V,V,_MM_SHUFFLE(2,1,3,0));
- vResult = _mm_max_ps(vResult,MinIco4);
- vResult = _mm_min_ps(vResult,MaxIco4);
- // Scale by multiplication
- vResult = _mm_mul_ps(vResult,ScaleIco4);
- // Convert to int
- __m128i vResulti = _mm_cvttps_epi32(vResult);
- // Mask off any fraction
- vResulti = _mm_and_si128(vResulti,MaskIco4);
- // Shift y and z to straddle the 32-bit boundary
- __m128i vResulti2 = _mm_srli_si128(vResulti,(64+12)/8);
- // Shift it into place
- vResulti2 = _mm_slli_si128(vResulti2,20/8);
- // i = x|y<<20|z<<40|w<<60
- vResulti = _mm_or_si128(vResulti,vResulti2);
- _mm_store_sd(reinterpret_cast<double *>(&pDestination->v),reinterpret_cast<const __m128d *>(&vResulti)[0]);
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- #undef XM_Scale
- #undef XM_URange
- #undef XM_Offset
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreXDecN4
- (
- XMXDECN4* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR N;
- static CONST XMVECTORF32 Min = {-1.0f, -1.0f, -1.0f, 0.0f};
- static CONST XMVECTORF32 Scale = {511.0f, 511.0f, 511.0f, 3.0f};
- XMASSERT(pDestination);
- N = XMVectorClamp(V, Min.v, g_XMOne.v);
- N = XMVectorMultiply(N, Scale.v);
- N = XMVectorRound(N);
- pDestination->v = ((UINT)N.vector4_f32[3] << 30) |
- (((INT)N.vector4_f32[2] & 0x3FF) << 20) |
- (((INT)N.vector4_f32[1] & 0x3FF) << 10) |
- (((INT)N.vector4_f32[0] & 0x3FF));
- #elif defined(_XM_SSE_INTRINSICS_)
- static const XMVECTORF32 Min = {-1.0f, -1.0f, -1.0f, 0.0f};
- static const XMVECTORF32 Scale = {511.0f, 511.0f*1024.0f, 511.0f*1048576.0f,3.0f*536870912.0f};
- static const XMVECTORI32 ScaleMask = {0x3FF,0x3FF<<10,0x3FF<<20,0x3<<29};
- XMASSERT(pDestination);
- XMVECTOR vResult = _mm_max_ps(V,Min);
- vResult = _mm_min_ps(vResult,g_XMOne);
- // Scale by multiplication
- vResult = _mm_mul_ps(vResult,Scale);
- // Convert to int (W is unsigned)
- __m128i vResulti = _mm_cvtps_epi32(vResult);
- // Mask off any fraction
- vResulti = _mm_and_si128(vResulti,ScaleMask);
- // To fix W, add itself to shift it up to <<30 instead of <<29
- __m128i vResultw = _mm_and_si128(vResulti,g_XMMaskW);
- vResulti = _mm_add_epi32(vResulti,vResultw);
- // Do a horizontal or of all 4 entries
- vResult = _mm_shuffle_ps(reinterpret_cast<const __m128 *>(&vResulti)[0],reinterpret_cast<const __m128 *>(&vResulti)[0],_MM_SHUFFLE(0,3,2,1));
- vResulti = _mm_or_si128(vResulti,reinterpret_cast<const __m128i *>(&vResult)[0]);
- vResult = _mm_shuffle_ps(vResult,vResult,_MM_SHUFFLE(0,3,2,1));
- vResulti = _mm_or_si128(vResulti,reinterpret_cast<const __m128i *>(&vResult)[0]);
- vResult = _mm_shuffle_ps(vResult,vResult,_MM_SHUFFLE(0,3,2,1));
- vResulti = _mm_or_si128(vResulti,reinterpret_cast<const __m128i *>(&vResult)[0]);
- _mm_store_ss(reinterpret_cast<float *>(&pDestination->v),reinterpret_cast<const __m128 *>(&vResulti)[0]);
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreXDec4
- (
- XMXDEC4* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR N;
- static CONST XMVECTOR Min = {-511.0f, -511.0f, -511.0f, 0.0f};
- static CONST XMVECTOR Max = {511.0f, 511.0f, 511.0f, 3.0f};
- XMASSERT(pDestination);
- N = XMVectorClamp(V, Min, Max);
- pDestination->v = ((UINT)N.vector4_f32[3] << 30) |
- (((INT)N.vector4_f32[2] & 0x3FF) << 20) |
- (((INT)N.vector4_f32[1] & 0x3FF) << 10) |
- (((INT)N.vector4_f32[0] & 0x3FF));
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- static const XMVECTORF32 MinXDec4 = {-511.0f,-511.0f,-511.0f, 0.0f};
- static const XMVECTORF32 MaxXDec4 = { 511.0f, 511.0f, 511.0f, 3.0f};
- static const XMVECTORF32 ScaleXDec4 = {1.0f,1024.0f/2.0f,1024.0f*1024.0f,1024.0f*1024.0f*1024.0f/2.0f};
- static const XMVECTORI32 MaskXDec4= {0x3FF,0x3FF<<(10-1),0x3FF<<20,0x3<<(30-1)};
- // Clamp to bounds
- XMVECTOR vResult = _mm_max_ps(V,MinXDec4);
- vResult = _mm_min_ps(vResult,MaxXDec4);
- // Scale by multiplication
- vResult = _mm_mul_ps(vResult,ScaleXDec4);
- // Convert to int
- __m128i vResulti = _mm_cvttps_epi32(vResult);
- // Mask off any fraction
- vResulti = _mm_and_si128(vResulti,MaskXDec4);
- // Do a horizontal or of 4 entries
- __m128i vResulti2 = _mm_shuffle_epi32(vResulti,_MM_SHUFFLE(3,2,3,2));
- // x = x|z, y = y|w
- vResulti = _mm_or_si128(vResulti,vResulti2);
- // Move Z to the x position
- vResulti2 = _mm_shuffle_epi32(vResulti,_MM_SHUFFLE(1,1,1,1));
- // Perform a single bit left shift on y|w
- vResulti2 = _mm_add_epi32(vResulti2,vResulti2);
- // i = x|y|z|w
- vResulti = _mm_or_si128(vResulti,vResulti2);
- _mm_store_ss(reinterpret_cast<float *>(&pDestination->v),reinterpret_cast<const __m128 *>(&vResulti)[0]);
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreUDecN4
- (
- XMUDECN4* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR N;
- static CONST XMVECTORF32 Scale = {1023.0f, 1023.0f, 1023.0f, 3.0f};
- XMASSERT(pDestination);
- N = XMVectorClamp(V, XMVectorZero(), g_XMOne.v);
- N = XMVectorMultiply(N, Scale.v);
- pDestination->v = ((UINT)N.vector4_f32[3] << 30) |
- (((UINT)N.vector4_f32[2] & 0x3FF) << 20) |
- (((UINT)N.vector4_f32[1] & 0x3FF) << 10) |
- (((UINT)N.vector4_f32[0] & 0x3FF));
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- static const XMVECTORF32 ScaleUDecN4 = {1023.0f,1023.0f*1024.0f*0.5f,1023.0f*1024.0f*1024.0f,3.0f*1024.0f*1024.0f*1024.0f*0.5f};
- static const XMVECTORI32 MaskUDecN4= {0x3FF,0x3FF<<(10-1),0x3FF<<20,0x3<<(30-1)};
- // Clamp to bounds
- XMVECTOR vResult = _mm_max_ps(V,g_XMZero);
- vResult = _mm_min_ps(vResult,g_XMOne);
- // Scale by multiplication
- vResult = _mm_mul_ps(vResult,ScaleUDecN4);
- // Convert to int
- __m128i vResulti = _mm_cvttps_epi32(vResult);
- // Mask off any fraction
- vResulti = _mm_and_si128(vResulti,MaskUDecN4);
- // Do a horizontal or of 4 entries
- __m128i vResulti2 = _mm_shuffle_epi32(vResulti,_MM_SHUFFLE(3,2,3,2));
- // x = x|z, y = y|w
- vResulti = _mm_or_si128(vResulti,vResulti2);
- // Move Z to the x position
- vResulti2 = _mm_shuffle_epi32(vResulti,_MM_SHUFFLE(1,1,1,1));
- // Perform a left shift by one bit on y|w
- vResulti2 = _mm_add_epi32(vResulti2,vResulti2);
- // i = x|y|z|w
- vResulti = _mm_or_si128(vResulti,vResulti2);
- _mm_store_ss(reinterpret_cast<float *>(&pDestination->v),reinterpret_cast<const __m128 *>(&vResulti)[0]);
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreUDec4
- (
- XMUDEC4* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR N;
- static CONST XMVECTOR Max = {1023.0f, 1023.0f, 1023.0f, 3.0f};
- XMASSERT(pDestination);
- N = XMVectorClamp(V, XMVectorZero(), Max);
- pDestination->v = ((UINT)N.vector4_f32[3] << 30) |
- (((UINT)N.vector4_f32[2] & 0x3FF) << 20) |
- (((UINT)N.vector4_f32[1] & 0x3FF) << 10) |
- (((UINT)N.vector4_f32[0] & 0x3FF));
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- static const XMVECTORF32 MaxUDec4 = { 1023.0f, 1023.0f, 1023.0f, 3.0f};
- static const XMVECTORF32 ScaleUDec4 = {1.0f,1024.0f/2.0f,1024.0f*1024.0f,1024.0f*1024.0f*1024.0f/2.0f};
- static const XMVECTORI32 MaskUDec4= {0x3FF,0x3FF<<(10-1),0x3FF<<20,0x3<<(30-1)};
- // Clamp to bounds
- XMVECTOR vResult = _mm_max_ps(V,g_XMZero);
- vResult = _mm_min_ps(vResult,MaxUDec4);
- // Scale by multiplication
- vResult = _mm_mul_ps(vResult,ScaleUDec4);
- // Convert to int
- __m128i vResulti = _mm_cvttps_epi32(vResult);
- // Mask off any fraction
- vResulti = _mm_and_si128(vResulti,MaskUDec4);
- // Do a horizontal or of 4 entries
- __m128i vResulti2 = _mm_shuffle_epi32(vResulti,_MM_SHUFFLE(3,2,3,2));
- // x = x|z, y = y|w
- vResulti = _mm_or_si128(vResulti,vResulti2);
- // Move Z to the x position
- vResulti2 = _mm_shuffle_epi32(vResulti,_MM_SHUFFLE(1,1,1,1));
- // Perform a left shift by one bit on y|w
- vResulti2 = _mm_add_epi32(vResulti2,vResulti2);
- // i = x|y|z|w
- vResulti = _mm_or_si128(vResulti,vResulti2);
- _mm_store_ss(reinterpret_cast<float *>(&pDestination->v),reinterpret_cast<const __m128 *>(&vResulti)[0]);
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreDecN4
- (
- XMDECN4* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR N;
- static CONST XMVECTORF32 Scale = {511.0f, 511.0f, 511.0f, 1.0f};
- XMASSERT(pDestination);
- N = XMVectorClamp(V, g_XMNegativeOne.v, g_XMOne.v);
- N = XMVectorMultiply(N, Scale.v);
- pDestination->v = ((INT)N.vector4_f32[3] << 30) |
- (((INT)N.vector4_f32[2] & 0x3FF) << 20) |
- (((INT)N.vector4_f32[1] & 0x3FF) << 10) |
- (((INT)N.vector4_f32[0] & 0x3FF));
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- static const XMVECTORF32 ScaleDecN4 = {511.0f,511.0f*1024.0f,511.0f*1024.0f*1024.0f,1.0f*1024.0f*1024.0f*1024.0f};
- static const XMVECTORI32 MaskDecN4= {0x3FF,0x3FF<<10,0x3FF<<20,0x3<<30};
- // Clamp to bounds
- XMVECTOR vResult = _mm_max_ps(V,g_XMNegativeOne);
- vResult = _mm_min_ps(vResult,g_XMOne);
- // Scale by multiplication
- vResult = _mm_mul_ps(vResult,ScaleDecN4);
- // Convert to int
- __m128i vResulti = _mm_cvttps_epi32(vResult);
- // Mask off any fraction
- vResulti = _mm_and_si128(vResulti,MaskDecN4);
- // Do a horizontal or of 4 entries
- __m128i vResulti2 = _mm_shuffle_epi32(vResulti,_MM_SHUFFLE(3,2,3,2));
- // x = x|z, y = y|w
- vResulti = _mm_or_si128(vResulti,vResulti2);
- // Move Z to the x position
- vResulti2 = _mm_shuffle_epi32(vResulti,_MM_SHUFFLE(1,1,1,1));
- // i = x|y|z|w
- vResulti = _mm_or_si128(vResulti,vResulti2);
- _mm_store_ss(reinterpret_cast<float *>(&pDestination->v),reinterpret_cast<const __m128 *>(&vResulti)[0]);
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreDec4
- (
- XMDEC4* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR N;
- static CONST XMVECTOR Min = {-511.0f, -511.0f, -511.0f, -1.0f};
- static CONST XMVECTOR Max = {511.0f, 511.0f, 511.0f, 1.0f};
- XMASSERT(pDestination);
- N = XMVectorClamp(V, Min, Max);
- pDestination->v = ((INT)N.vector4_f32[3] << 30) |
- (((INT)N.vector4_f32[2] & 0x3FF) << 20) |
- (((INT)N.vector4_f32[1] & 0x3FF) << 10) |
- (((INT)N.vector4_f32[0] & 0x3FF));
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- static const XMVECTORF32 MinDec4 = {-511.0f,-511.0f,-511.0f,-1.0f};
- static const XMVECTORF32 MaxDec4 = { 511.0f, 511.0f, 511.0f, 1.0f};
- static const XMVECTORF32 ScaleDec4 = {1.0f,1024.0f,1024.0f*1024.0f,1024.0f*1024.0f*1024.0f};
- static const XMVECTORI32 MaskDec4= {0x3FF,0x3FF<<10,0x3FF<<20,0x3<<30};
- // Clamp to bounds
- XMVECTOR vResult = _mm_max_ps(V,MinDec4);
- vResult = _mm_min_ps(vResult,MaxDec4);
- // Scale by multiplication
- vResult = _mm_mul_ps(vResult,ScaleDec4);
- // Convert to int
- __m128i vResulti = _mm_cvttps_epi32(vResult);
- // Mask off any fraction
- vResulti = _mm_and_si128(vResulti,MaskDec4);
- // Do a horizontal or of 4 entries
- __m128i vResulti2 = _mm_shuffle_epi32(vResulti,_MM_SHUFFLE(3,2,3,2));
- // x = x|z, y = y|w
- vResulti = _mm_or_si128(vResulti,vResulti2);
- // Move Z to the x position
- vResulti2 = _mm_shuffle_epi32(vResulti,_MM_SHUFFLE(1,1,1,1));
- // i = x|y|z|w
- vResulti = _mm_or_si128(vResulti,vResulti2);
- _mm_store_ss(reinterpret_cast<float *>(&pDestination->v),reinterpret_cast<const __m128 *>(&vResulti)[0]);
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreUByteN4
- (
- XMUBYTEN4* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR N;
- static CONST XMVECTORF32 Scale = {255.0f, 255.0f, 255.0f, 255.0f};
- XMASSERT(pDestination);
- N = XMVectorSaturate(V);
- N = XMVectorMultiply(N, Scale.v);
- N = XMVectorRound(N);
- pDestination->x = (BYTE)N.vector4_f32[0];
- pDestination->y = (BYTE)N.vector4_f32[1];
- pDestination->z = (BYTE)N.vector4_f32[2];
- pDestination->w = (BYTE)N.vector4_f32[3];
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- static const XMVECTORF32 ScaleUByteN4 = {255.0f,255.0f*256.0f*0.5f,255.0f*256.0f*256.0f,255.0f*256.0f*256.0f*256.0f*0.5f};
- static const XMVECTORI32 MaskUByteN4 = {0xFF,0xFF<<(8-1),0xFF<<16,0xFF<<(24-1)};
- // Clamp to bounds
- XMVECTOR vResult = _mm_max_ps(V,g_XMZero);
- vResult = _mm_min_ps(vResult,g_XMOne);
- // Scale by multiplication
- vResult = _mm_mul_ps(vResult,ScaleUByteN4);
- // Convert to int
- __m128i vResulti = _mm_cvttps_epi32(vResult);
- // Mask off any fraction
- vResulti = _mm_and_si128(vResulti,MaskUByteN4);
- // Do a horizontal or of 4 entries
- __m128i vResulti2 = _mm_shuffle_epi32(vResulti,_MM_SHUFFLE(3,2,3,2));
- // x = x|z, y = y|w
- vResulti = _mm_or_si128(vResulti,vResulti2);
- // Move Z to the x position
- vResulti2 = _mm_shuffle_epi32(vResulti,_MM_SHUFFLE(1,1,1,1));
- // Perform a single bit left shift to fix y|w
- vResulti2 = _mm_add_epi32(vResulti2,vResulti2);
- // i = x|y|z|w
- vResulti = _mm_or_si128(vResulti,vResulti2);
- _mm_store_ss(reinterpret_cast<float *>(&pDestination->v),reinterpret_cast<const __m128 *>(&vResulti)[0]);
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreUByte4
- (
- XMUBYTE4* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR N;
- static CONST XMVECTOR Max = {255.0f, 255.0f, 255.0f, 255.0f};
- XMASSERT(pDestination);
- N = XMVectorClamp(V, XMVectorZero(), Max);
- N = XMVectorRound(N);
- pDestination->x = (BYTE)N.vector4_f32[0];
- pDestination->y = (BYTE)N.vector4_f32[1];
- pDestination->z = (BYTE)N.vector4_f32[2];
- pDestination->w = (BYTE)N.vector4_f32[3];
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- static const XMVECTORF32 MaxUByte4 = { 255.0f, 255.0f, 255.0f, 255.0f};
- static const XMVECTORF32 ScaleUByte4 = {1.0f,256.0f*0.5f,256.0f*256.0f,256.0f*256.0f*256.0f*0.5f};
- static const XMVECTORI32 MaskUByte4 = {0xFF,0xFF<<(8-1),0xFF<<16,0xFF<<(24-1)};
- // Clamp to bounds
- XMVECTOR vResult = _mm_max_ps(V,g_XMZero);
- vResult = _mm_min_ps(vResult,MaxUByte4);
- // Scale by multiplication
- vResult = _mm_mul_ps(vResult,ScaleUByte4);
- // Convert to int
- __m128i vResulti = _mm_cvttps_epi32(vResult);
- // Mask off any fraction
- vResulti = _mm_and_si128(vResulti,MaskUByte4);
- // Do a horizontal or of 4 entries
- __m128i vResulti2 = _mm_shuffle_epi32(vResulti,_MM_SHUFFLE(3,2,3,2));
- // x = x|z, y = y|w
- vResulti = _mm_or_si128(vResulti,vResulti2);
- // Move Z to the x position
- vResulti2 = _mm_shuffle_epi32(vResulti,_MM_SHUFFLE(1,1,1,1));
- // Perform a single bit left shift to fix y|w
- vResulti2 = _mm_add_epi32(vResulti2,vResulti2);
- // i = x|y|z|w
- vResulti = _mm_or_si128(vResulti,vResulti2);
- _mm_store_ss(reinterpret_cast<float *>(&pDestination->v),reinterpret_cast<const __m128 *>(&vResulti)[0]);
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreByteN4
- (
- XMBYTEN4* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR N;
- static CONST XMVECTORF32 Scale = {127.0f, 127.0f, 127.0f, 127.0f};
- XMASSERT(pDestination);
- N = XMVectorMultiply(V, Scale.v);
- N = XMVectorRound(N);
- pDestination->x = (CHAR)N.vector4_f32[0];
- pDestination->y = (CHAR)N.vector4_f32[1];
- pDestination->z = (CHAR)N.vector4_f32[2];
- pDestination->w = (CHAR)N.vector4_f32[3];
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- static const XMVECTORF32 ScaleByteN4 = {127.0f,127.0f*256.0f,127.0f*256.0f*256.0f,127.0f*256.0f*256.0f*256.0f};
- static const XMVECTORI32 MaskByteN4 = {0xFF,0xFF<<8,0xFF<<16,0xFF<<24};
- // Clamp to bounds
- XMVECTOR vResult = _mm_max_ps(V,g_XMNegativeOne);
- vResult = _mm_min_ps(vResult,g_XMOne);
- // Scale by multiplication
- vResult = _mm_mul_ps(vResult,ScaleByteN4);
- // Convert to int
- __m128i vResulti = _mm_cvttps_epi32(vResult);
- // Mask off any fraction
- vResulti = _mm_and_si128(vResulti,MaskByteN4);
- // Do a horizontal or of 4 entries
- __m128i vResulti2 = _mm_shuffle_epi32(vResulti,_MM_SHUFFLE(3,2,3,2));
- // x = x|z, y = y|w
- vResulti = _mm_or_si128(vResulti,vResulti2);
- // Move Z to the x position
- vResulti2 = _mm_shuffle_epi32(vResulti,_MM_SHUFFLE(1,1,1,1));
- // i = x|y|z|w
- vResulti = _mm_or_si128(vResulti,vResulti2);
- _mm_store_ss(reinterpret_cast<float *>(&pDestination->v),reinterpret_cast<const __m128 *>(&vResulti)[0]);
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreByte4
- (
- XMBYTE4* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR N;
- static CONST XMVECTOR Min = {-127.0f, -127.0f, -127.0f, -127.0f};
- static CONST XMVECTOR Max = {127.0f, 127.0f, 127.0f, 127.0f};
- XMASSERT(pDestination);
- N = XMVectorClamp(V, Min, Max);
- N = XMVectorRound(N);
- pDestination->x = (CHAR)N.vector4_f32[0];
- pDestination->y = (CHAR)N.vector4_f32[1];
- pDestination->z = (CHAR)N.vector4_f32[2];
- pDestination->w = (CHAR)N.vector4_f32[3];
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- static const XMVECTORF32 MinByte4 = {-127.0f,-127.0f,-127.0f,-127.0f};
- static const XMVECTORF32 MaxByte4 = { 127.0f, 127.0f, 127.0f, 127.0f};
- static const XMVECTORF32 ScaleByte4 = {1.0f,256.0f,256.0f*256.0f,256.0f*256.0f*256.0f};
- static const XMVECTORI32 MaskByte4 = {0xFF,0xFF<<8,0xFF<<16,0xFF<<24};
- // Clamp to bounds
- XMVECTOR vResult = _mm_max_ps(V,MinByte4);
- vResult = _mm_min_ps(vResult,MaxByte4);
- // Scale by multiplication
- vResult = _mm_mul_ps(vResult,ScaleByte4);
- // Convert to int
- __m128i vResulti = _mm_cvttps_epi32(vResult);
- // Mask off any fraction
- vResulti = _mm_and_si128(vResulti,MaskByte4);
- // Do a horizontal or of 4 entries
- __m128i vResulti2 = _mm_shuffle_epi32(vResulti,_MM_SHUFFLE(3,2,3,2));
- // x = x|z, y = y|w
- vResulti = _mm_or_si128(vResulti,vResulti2);
- // Move Z to the x position
- vResulti2 = _mm_shuffle_epi32(vResulti,_MM_SHUFFLE(1,1,1,1));
- // i = x|y|z|w
- vResulti = _mm_or_si128(vResulti,vResulti2);
- _mm_store_ss(reinterpret_cast<float *>(&pDestination->v),reinterpret_cast<const __m128 *>(&vResulti)[0]);
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreUNibble4
- (
- XMUNIBBLE4* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_SSE_INTRINSICS_) && !defined(_XM_NO_INTRINSICS_)
- XMASSERT(pDestination);
- static CONST XMVECTORF32 Max = {15.0f,15.0f,15.0f,15.0f};
- // Bounds check
- XMVECTOR vResult = _mm_max_ps(V,g_XMZero);
- vResult = _mm_min_ps(vResult,Max);
- // Convert to int with rounding
- __m128i vInt = _mm_cvtps_epi32(vResult);
- // No SSE operations will write to 16-bit values, so we have to extract them manually
- USHORT x = static_cast<USHORT>(_mm_extract_epi16(vInt,0));
- USHORT y = static_cast<USHORT>(_mm_extract_epi16(vInt,2));
- USHORT z = static_cast<USHORT>(_mm_extract_epi16(vInt,4));
- USHORT w = static_cast<USHORT>(_mm_extract_epi16(vInt,6));
- pDestination->v = ((w & 0xF) << 12) |
- ((z & 0xF) << 8) |
- ((y & 0xF) << 4) |
- ((x & 0xF));
- #else
- XMVECTOR N;
- static CONST XMVECTORF32 Max = {15.0f,15.0f,15.0f,15.0f};
- XMASSERT(pDestination);
- N = XMVectorClamp(V, XMVectorZero(), Max.v);
- N = XMVectorRound(N);
- pDestination->v = (((USHORT)N.vector4_f32[3] & 0xF) << 12) |
- (((USHORT)N.vector4_f32[2] & 0xF) << 8) |
- (((USHORT)N.vector4_f32[1] & 0xF) << 4) |
- (((USHORT)N.vector4_f32[0] & 0xF));
- #endif !_XM_SSE_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreU555(
- XMU555* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_SSE_INTRINSICS_) && !defined(_XM_NO_INTRINSICS_)
- XMASSERT(pDestination);
- static CONST XMVECTORF32 Max = {31.0f, 31.0f, 31.0f, 1.0f};
- // Bounds check
- XMVECTOR vResult = _mm_max_ps(V,g_XMZero);
- vResult = _mm_min_ps(vResult,Max);
- // Convert to int with rounding
- __m128i vInt = _mm_cvtps_epi32(vResult);
- // No SSE operations will write to 16-bit values, so we have to extract them manually
- USHORT x = static_cast<USHORT>(_mm_extract_epi16(vInt,0));
- USHORT y = static_cast<USHORT>(_mm_extract_epi16(vInt,2));
- USHORT z = static_cast<USHORT>(_mm_extract_epi16(vInt,4));
- USHORT w = static_cast<USHORT>(_mm_extract_epi16(vInt,6));
- pDestination->v = ((w) ? 0x8000 : 0) |
- ((z & 0x1F) << 10) |
- ((y & 0x1F) << 5) |
- ((x & 0x1F));
- #else
- XMVECTOR N;
- static CONST XMVECTORF32 Max = {31.0f, 31.0f, 31.0f, 1.0f};
- XMASSERT(pDestination);
- N = XMVectorClamp(V, XMVectorZero(), Max.v);
- N = XMVectorRound(N);
- pDestination->v = ((N.vector4_f32[3] > 0.f) ? 0x8000 : 0) |
- (((USHORT)N.vector4_f32[2] & 0x1F) << 10) |
- (((USHORT)N.vector4_f32[1] & 0x1F) << 5) |
- (((USHORT)N.vector4_f32[0] & 0x1F));
- #endif !_XM_SSE_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreColor
- (
- XMCOLOR* pDestination,
- FXMVECTOR V
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMVECTOR N;
- static CONST XMVECTORF32 Scale = {255.0f, 255.0f, 255.0f, 255.0f};
- XMASSERT(pDestination);
- N = XMVectorSaturate(V);
- N = XMVectorMultiply(N, Scale.v);
- N = XMVectorRound(N);
- pDestination->c = ((UINT)N.vector4_f32[3] << 24) |
- ((UINT)N.vector4_f32[0] << 16) |
- ((UINT)N.vector4_f32[1] << 8) |
- ((UINT)N.vector4_f32[2]);
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- static CONST XMVECTORF32 Scale = {255.0f,255.0f,255.0f,255.0f};
- // Set <0 to 0
- XMVECTOR vResult = _mm_max_ps(V,g_XMZero);
- // Set>1 to 1
- vResult = _mm_min_ps(vResult,g_XMOne);
- // Convert to 0-255
- vResult = _mm_mul_ps(vResult,Scale);
- // Shuffle RGBA to ARGB
- vResult = _mm_shuffle_ps(vResult,vResult,_MM_SHUFFLE(3,0,1,2));
- // Convert to int
- __m128i vInt = _mm_cvtps_epi32(vResult);
- // Mash to shorts
- vInt = _mm_packs_epi32(vInt,vInt);
- // Mash to bytes
- vInt = _mm_packus_epi16(vInt,vInt);
- // Store the color
- _mm_store_ss(reinterpret_cast<float *>(&pDestination->c),reinterpret_cast<__m128 *>(&vInt)[0]);
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreFloat3x3
- (
- XMFLOAT3X3* pDestination,
- CXMMATRIX M
- )
- {
- #if defined(_XM_NO_INTRINSICS_) || defined(XM_NO_MISALIGNED_VECTOR_ACCESS) || defined(_XM_SSE_INTRINSICS_)
- XMStoreFloat3x3NC(pDestination, M);
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreFloat3x3NC
- (
- XMFLOAT3X3* pDestination,
- CXMMATRIX M
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMASSERT(pDestination);
- pDestination->m[0][0] = M.r[0].vector4_f32[0];
- pDestination->m[0][1] = M.r[0].vector4_f32[1];
- pDestination->m[0][2] = M.r[0].vector4_f32[2];
- pDestination->m[1][0] = M.r[1].vector4_f32[0];
- pDestination->m[1][1] = M.r[1].vector4_f32[1];
- pDestination->m[1][2] = M.r[1].vector4_f32[2];
- pDestination->m[2][0] = M.r[2].vector4_f32[0];
- pDestination->m[2][1] = M.r[2].vector4_f32[1];
- pDestination->m[2][2] = M.r[2].vector4_f32[2];
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- XMVECTOR vTemp1 = M.r[0];
- XMVECTOR vTemp2 = M.r[1];
- XMVECTOR vTemp3 = M.r[2];
- XMVECTOR vWork = _mm_shuffle_ps(vTemp1,vTemp2,_MM_SHUFFLE(0,0,2,2));
- vTemp1 = _mm_shuffle_ps(vTemp1,vWork,_MM_SHUFFLE(2,0,1,0));
- _mm_storeu_ps(&pDestination->m[0][0],vTemp1);
- vTemp2 = _mm_shuffle_ps(vTemp2,vTemp3,_MM_SHUFFLE(1,0,2,1));
- _mm_storeu_ps(&pDestination->m[1][1],vTemp2);
- vTemp3 = _mm_shuffle_ps(vTemp3,vTemp3,_MM_SHUFFLE(2,2,2,2));
- _mm_store_ss(&pDestination->m[2][2],vTemp3);
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreFloat4x3
- (
- XMFLOAT4X3* pDestination,
- CXMMATRIX M
- )
- {
- #if defined(_XM_NO_INTRINSICS_) || defined(XM_NO_MISALIGNED_VECTOR_ACCESS) || defined(_XM_SSE_INTRINSICS_)
- XMStoreFloat4x3NC(pDestination, M);
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreFloat4x3A
- (
- XMFLOAT4X3A* pDestination,
- CXMMATRIX M
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMASSERT(pDestination);
- XMASSERT(((UINT_PTR)pDestination & 0xF) == 0);
- pDestination->m[0][0] = M.r[0].vector4_f32[0];
- pDestination->m[0][1] = M.r[0].vector4_f32[1];
- pDestination->m[0][2] = M.r[0].vector4_f32[2];
- pDestination->m[1][0] = M.r[1].vector4_f32[0];
- pDestination->m[1][1] = M.r[1].vector4_f32[1];
- pDestination->m[1][2] = M.r[1].vector4_f32[2];
- pDestination->m[2][0] = M.r[2].vector4_f32[0];
- pDestination->m[2][1] = M.r[2].vector4_f32[1];
- pDestination->m[2][2] = M.r[2].vector4_f32[2];
- pDestination->m[3][0] = M.r[3].vector4_f32[0];
- pDestination->m[3][1] = M.r[3].vector4_f32[1];
- pDestination->m[3][2] = M.r[3].vector4_f32[2];
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- XMASSERT(((UINT_PTR)pDestination & 0xF) == 0);
- // x1,y1,z1,w1
- XMVECTOR vTemp1 = M.r[0];
- // x2,y2,z2,w2
- XMVECTOR vTemp2 = M.r[1];
- // x3,y3,z3,w3
- XMVECTOR vTemp3 = M.r[2];
- // x4,y4,z4,w4
- XMVECTOR vTemp4 = M.r[3];
- // z1,z1,x2,y2
- XMVECTOR vTemp = _mm_shuffle_ps(vTemp1,vTemp2,_MM_SHUFFLE(1,0,2,2));
- // y2,z2,x3,y3 (Final)
- vTemp2 = _mm_shuffle_ps(vTemp2,vTemp3,_MM_SHUFFLE(1,0,2,1));
- // x1,y1,z1,x2 (Final)
- vTemp1 = _mm_shuffle_ps(vTemp1,vTemp,_MM_SHUFFLE(2,0,1,0));
- // z3,z3,x4,x4
- vTemp3 = _mm_shuffle_ps(vTemp3,vTemp4,_MM_SHUFFLE(0,0,2,2));
- // z3,x4,y4,z4 (Final)
- vTemp3 = _mm_shuffle_ps(vTemp3,vTemp4,_MM_SHUFFLE(2,1,2,0));
- // Store in 3 operations
- _mm_store_ps(&pDestination->m[0][0],vTemp1);
- _mm_store_ps(&pDestination->m[1][1],vTemp2);
- _mm_store_ps(&pDestination->m[2][2],vTemp3);
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreFloat4x3NC
- (
- XMFLOAT4X3* pDestination,
- CXMMATRIX M
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMASSERT(pDestination);
- pDestination->m[0][0] = M.r[0].vector4_f32[0];
- pDestination->m[0][1] = M.r[0].vector4_f32[1];
- pDestination->m[0][2] = M.r[0].vector4_f32[2];
- pDestination->m[1][0] = M.r[1].vector4_f32[0];
- pDestination->m[1][1] = M.r[1].vector4_f32[1];
- pDestination->m[1][2] = M.r[1].vector4_f32[2];
- pDestination->m[2][0] = M.r[2].vector4_f32[0];
- pDestination->m[2][1] = M.r[2].vector4_f32[1];
- pDestination->m[2][2] = M.r[2].vector4_f32[2];
- pDestination->m[3][0] = M.r[3].vector4_f32[0];
- pDestination->m[3][1] = M.r[3].vector4_f32[1];
- pDestination->m[3][2] = M.r[3].vector4_f32[2];
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- XMVECTOR vTemp1 = M.r[0];
- XMVECTOR vTemp2 = M.r[1];
- XMVECTOR vTemp3 = M.r[2];
- XMVECTOR vTemp4 = M.r[3];
- XMVECTOR vTemp2x = _mm_shuffle_ps(vTemp2,vTemp3,_MM_SHUFFLE(1,0,2,1));
- vTemp2 = _mm_shuffle_ps(vTemp2,vTemp1,_MM_SHUFFLE(2,2,0,0));
- vTemp1 = _mm_shuffle_ps(vTemp1,vTemp2,_MM_SHUFFLE(0,2,1,0));
- vTemp3 = _mm_shuffle_ps(vTemp3,vTemp4,_MM_SHUFFLE(0,0,2,2));
- vTemp3 = _mm_shuffle_ps(vTemp3,vTemp4,_MM_SHUFFLE(2,1,2,0));
- _mm_storeu_ps(&pDestination->m[0][0],vTemp1);
- _mm_storeu_ps(&pDestination->m[1][1],vTemp2x);
- _mm_storeu_ps(&pDestination->m[2][2],vTemp3);
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreFloat4x4
- (
- XMFLOAT4X4* pDestination,
- CXMMATRIX M
- )
- {
- #if defined(_XM_NO_INTRINSICS_) || defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
- XMStoreFloat4x4NC(pDestination, M);
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- _mm_storeu_ps( &pDestination->_11, M.r[0] );
- _mm_storeu_ps( &pDestination->_21, M.r[1] );
- _mm_storeu_ps( &pDestination->_31, M.r[2] );
- _mm_storeu_ps( &pDestination->_41, M.r[3] );
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreFloat4x4A
- (
- XMFLOAT4X4A* pDestination,
- CXMMATRIX M
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMASSERT(pDestination);
- XMASSERT(((UINT_PTR)pDestination & 0xF) == 0);
- pDestination->m[0][0] = M.r[0].vector4_f32[0];
- pDestination->m[0][1] = M.r[0].vector4_f32[1];
- pDestination->m[0][2] = M.r[0].vector4_f32[2];
- pDestination->m[0][3] = M.r[0].vector4_f32[3];
- pDestination->m[1][0] = M.r[1].vector4_f32[0];
- pDestination->m[1][1] = M.r[1].vector4_f32[1];
- pDestination->m[1][2] = M.r[1].vector4_f32[2];
- pDestination->m[1][3] = M.r[1].vector4_f32[3];
- pDestination->m[2][0] = M.r[2].vector4_f32[0];
- pDestination->m[2][1] = M.r[2].vector4_f32[1];
- pDestination->m[2][2] = M.r[2].vector4_f32[2];
- pDestination->m[2][3] = M.r[2].vector4_f32[3];
- pDestination->m[3][0] = M.r[3].vector4_f32[0];
- pDestination->m[3][1] = M.r[3].vector4_f32[1];
- pDestination->m[3][2] = M.r[3].vector4_f32[2];
- pDestination->m[3][3] = M.r[3].vector4_f32[3];
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- _mm_store_ps( &pDestination->_11, M.r[0] );
- _mm_store_ps( &pDestination->_21, M.r[1] );
- _mm_store_ps( &pDestination->_31, M.r[2] );
- _mm_store_ps( &pDestination->_41, M.r[3] );
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- //------------------------------------------------------------------------------
- XMFINLINE VOID XMStoreFloat4x4NC
- (
- XMFLOAT4X4* pDestination,
- CXMMATRIX M
- )
- {
- #if defined(_XM_NO_INTRINSICS_)
- XMASSERT(pDestination);
- pDestination->m[0][0] = M.r[0].vector4_f32[0];
- pDestination->m[0][1] = M.r[0].vector4_f32[1];
- pDestination->m[0][2] = M.r[0].vector4_f32[2];
- pDestination->m[0][3] = M.r[0].vector4_f32[3];
- pDestination->m[1][0] = M.r[1].vector4_f32[0];
- pDestination->m[1][1] = M.r[1].vector4_f32[1];
- pDestination->m[1][2] = M.r[1].vector4_f32[2];
- pDestination->m[1][3] = M.r[1].vector4_f32[3];
- pDestination->m[2][0] = M.r[2].vector4_f32[0];
- pDestination->m[2][1] = M.r[2].vector4_f32[1];
- pDestination->m[2][2] = M.r[2].vector4_f32[2];
- pDestination->m[2][3] = M.r[2].vector4_f32[3];
- pDestination->m[3][0] = M.r[3].vector4_f32[0];
- pDestination->m[3][1] = M.r[3].vector4_f32[1];
- pDestination->m[3][2] = M.r[3].vector4_f32[2];
- pDestination->m[3][3] = M.r[3].vector4_f32[3];
- #elif defined(_XM_SSE_INTRINSICS_)
- XMASSERT(pDestination);
- _mm_storeu_ps(&pDestination->m[0][0],M.r[0]);
- _mm_storeu_ps(&pDestination->m[1][0],M.r[1]);
- _mm_storeu_ps(&pDestination->m[2][0],M.r[2]);
- _mm_storeu_ps(&pDestination->m[3][0],M.r[3]);
- #else // _XM_VMX128_INTRINSICS_
- #endif // _XM_VMX128_INTRINSICS_
- }
- #endif // __XNAMATHCONVERT_INL__
|