Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

801 lines
23 KiB

  1. ;-----------------------------------------------------------------------------
  2. ;
  3. ; Monolith 21. Perspective Correct Bi-linear gouraud modulated
  4. ; X888 input texture 16 bit Z buffered (LE or GT)
  5. ; X888 output.
  6. ;
  7. ; Exactly the same as monolith 7 except color input is 32 bits and
  8. ; output is 32 bits
  9. ;
  10. ;-----------------------------------------------------------------------------
  11. INCLUDE iammx.inc
  12. INCLUDE offs_acp.inc
  13. ; Names are read LSB to MSB, so B5G6R5 means five bits of blue starting
  14. ; at the LSB, then six bits of green, then five bits of red.
  15. ;TBD check to see if this value is correct.
  16. COLOR_SHIFT equ 8
  17. .586
  18. .model flat
  19. ; Big seperating lines seperate code into span code
  20. ; and loop code. If span and loop are not going to
  21. ; end up being combined then it will be easy to
  22. ; seperate the code.
  23. .data
  24. ; Need externs for all of the variables that are needed for various beads
  25. EXTERN IncHighandLow16:MMWORD
  26. EXTERN UFracVFracMask:MMWORD
  27. EXTERN UV32to15Mask:MMWORD
  28. EXTERN Makelow16one:MMWORD
  29. EXTERN MaskKeepUValues:MMWORD
  30. EXTERN MaskKeepVValues:MMWORD
  31. EXTERN UFrac:MMWORD
  32. EXTERN VFrac:MMWORD
  33. EXTERN Zero:MMWORD
  34. EXTERN memD3DTFG_POINT:MMWORD
  35. EXTERN GiveUp:MMWORD
  36. EXTERN LastW:MMWORD
  37. EXTERN Val0x000a000a:MMWORD
  38. EXTERN Val0xffff:MMWORD
  39. EXTERN Val0x0000002000000020:MMWORD
  40. EXTERN Val0x0000ffff0000ffff:MMWORD
  41. EXTERN MaskRed565to888:MMWORD
  42. EXTERN MaskGreen565to888:MMWORD
  43. EXTERN MaskBlue565to888:MMWORD
  44. EXTERN MaskRed555to888:MMWORD
  45. EXTERN MaskGreen555to888:MMWORD
  46. EXTERN MaskBlue555to888:MMWORD
  47. EXTERN MaskAlpha1555to8888:MMWORD
  48. EXTERN MaskRed1555to8888:MMWORD
  49. EXTERN MaskGreen1555to8888:MMWORD
  50. EXTERN MaskBlue1555to8888:MMWORD
  51. ; TBD. I think that I want to do 0xffff instead of 0xff. This will
  52. ; have to be checked. There is a value very similiar to this in
  53. ; buf write.
  54. EXTERN SetAlphato0xffff:MMWORD
  55. EXTERN SetAlphato0xff:MMWORD
  56. ; TODO This equate are identical to the ones in texread.mas. Maybe they should be in a common .inc file.
  57. RedShift565to888 equ 8
  58. GreenShift565to888 equ 5
  59. BlueShift565to888 equ 3
  60. RedShift555to888 equ 9
  61. GreenShift555to888 equ 6
  62. BlueShift555to888 equ 3
  63. AlphaShift1555to8888 equ 16
  64. RedShift1555to8888 equ 9
  65. GreenShift1555to8888 equ 6
  66. BlueShift1555to8888 equ 3
  67. ; BEGIN *** Lee Hamel code optimization ***
  68. EXTERN BilinearMaskRed565to888:MMWORD
  69. EXTERN BilinearMaskGreen565to888:MMWORD
  70. EXTERN BilinearMaskBlue565to888:MMWORD
  71. EXTERN BilinearShiftRed565to888:MMWORD
  72. EXTERN BilinearShiftGreen565to888:MMWORD
  73. EXTERN BilinearShiftBlue565to888:MMWORD
  74. ; END *** Lee Hamel code optimization ***
  75. EXTERN Zero:MMWORD
  76. EXTERN DW_One_One:MMWORD
  77. EXTERN MaskOffAlpha:MMWORD
  78. EXTERN ShiftTA:MMWORD
  79. EXTERN Val0x00ff00ff00ff00ff:MMWORD
  80. EXTERN Val0x000000ff00ff00ff:MMWORD
  81. EXTERN Val0X0000000001000000:MMWORD
  82. EXTERN AlphaVal128:MMWORD
  83. EXTERN RGBVal128:MMWORD
  84. EXTERN g_uDitherValue:MMWORD
  85. EXTERN SetAlphato0xff:MMWORD
  86. EXTERN u888to565RedBlueMask:MMWORD
  87. EXTERN u888to565GreenMask:MMWORD
  88. EXTERN u888to565Multiplier:MMWORD
  89. EXTERN uVal0x000007ff03ff07ff:MMWORD
  90. EXTERN uVal0x0000078003c00780:MMWORD
  91. EXTERN u888to555RedBlueMask:MMWORD
  92. EXTERN u888to555GreenMask:MMWORD
  93. EXTERN u888to555Multiplier:MMWORD
  94. EXTERN uVal0x000007ff07ff07ff:MMWORD
  95. EXTERN uVal0x0000078007800780:MMWORD
  96. ;-----------------------------------------------------------------------------
  97. ; Span Variables
  98. StackPos dd ?
  99. uSpans dd ?
  100. ;-----------------------------------------------------------------------------
  101. ;-----------------------------------------------------------------------------
  102. ; Loop Variables
  103. iSurfaceStep dd ?
  104. iZStep dd ?
  105. uPix dd ?
  106. ;-----------------------------------------------------------------------------
  107. .code
  108. PUBLIC _MMXMLRast_21
  109. _MMXMLRast_21:
  110. push ebp
  111. mov StackPos, esp
  112. mov eax, esp
  113. sub esp, 0Ch ; This will need to change if stack frame size changes.
  114. push ebx
  115. push esi
  116. push edi
  117. ; Put pCtx into ebx
  118. mov ebx, [eax+8]
  119. ;PD3DI_RASTPRIM pP = pCtx->pPrim;
  120. mov ecx, [ebx+RASTCTX_pPrim]
  121. ;while (pP)
  122. ;{
  123. PrimLoop:
  124. cmp ecx, 0
  125. je ExitPrimLoop
  126. ;UINT16 uSpans = pP->uSpans;
  127. movzx eax, word ptr [ecx+RASTPRIM_uSpans]
  128. mov uSpans, eax
  129. ;PD3DI_RASTSPAN pS = (PD3DI_RASTSPAN)(pP + 1);
  130. mov ebp, ecx
  131. add ebp, SIZEOF_RASTPRIM
  132. ;while (uSpans-- > 0)
  133. ;{
  134. SpanLoop:
  135. mov edx, uSpans
  136. mov eax, edx
  137. dec eax
  138. mov uSpans, eax
  139. test edx, edx
  140. jle ExitSpanLoop
  141. ;pCtx->pfnBegin(pCtx, pP, pS);
  142. ;-----------------------------------------------------------------------------
  143. ; LoopAny code inserted here. This is to get rid of an extra
  144. ; jump.
  145. ;-----------------------------------------------------------------------------
  146. ; Setup Code begins
  147. ; get values to iterate
  148. ;uPix = pS->uPix;
  149. movzx eax, word ptr [ebp+RASTSPAN_uPix]
  150. mov uPix, eax
  151. ;pCtx->SI.iDW = 0x0;
  152. mov dword ptr [ebx+RASTCTX_SI+SPANITER_iDW], 0
  153. mov esi, [ebp+RASTSPAN_iW]
  154. movq mm5, MMWORD PTR [ebp+RASTSPAN_iUoW1]
  155. ;pCtx->SI.iUd_TexNum = d_WTimesUVoW(pS->iW,pS->iUoW1);
  156. ;pCtx->SI.iVd_TexNum = d_WTimesUVoW(pS->iW,pS->iVoW1);
  157. pslld mm5, 8
  158. shl esi, 4
  159. movd eax, mm5
  160. psrlq mm5, 32
  161. imul esi
  162. mov [ebx+RASTCTX_SI+SPANITER_iU1], edx
  163. movd eax, mm5
  164. imul esi
  165. mov [ebx+RASTCTX_SI+SPANITER_iV1], edx
  166. ;if (pP->iDOoWDX > 0)
  167. ;{
  168. cmp dword ptr [ecx+RASTPRIM_iDOoWDX], 0
  169. jg SpecialWLastMonTest
  170. ;// iSpecialW should be negative for the first 3 pixels of span
  171. ;pCtx->SI.iSpecialW = -3;
  172. mov word ptr [ebx+RASTCTX_SI+SPANITER_iSpecialW], -3
  173. jmp DoneSpecialWifMonTest
  174. ;}
  175. ;else
  176. ;{
  177. SpecialWLastMonTest:
  178. ;// iSpecialW should be negative for the last 3 pixels of span
  179. ;pCtx->SI.iSpecialW = 0x7fff - uPix;
  180. mov eax, 07fffh
  181. sub eax, uPix
  182. ;pCtx->SI.iSpecialW += 5; // this may wrap, but it should
  183. add eax, 5
  184. mov [ebx+RASTCTX_SI+SPANITER_iSpecialW], eax
  185. ;}
  186. DoneSpecialWifMonTest:
  187. ;if (pP->uFlags & D3DI_RASTPRIM_X_DEC)
  188. ;{
  189. mov eax, [ecx+RASTPRIM_uFlags]
  190. and eax, D3DI_RASTPRIM_X_DEC
  191. test eax, eax
  192. jz LeftToRightSpan
  193. ;iZStep = -pCtx->iZStep;
  194. mov eax, [ebx+RASTCTX_iZStep]
  195. neg eax
  196. mov iZStep, eax
  197. ;iSurfaceStep = -pCtx->iSurfaceStep;
  198. mov eax, [ebx+RASTCTX_iSurfaceStep]
  199. neg eax
  200. mov iSurfaceStep, eax
  201. ;}
  202. jmp DoneSpanDirif
  203. ;else
  204. ;{
  205. LeftToRightSpan:
  206. ;iZStep = pCtx->iZStep;
  207. mov eax, [ebx+RASTCTX_iZStep]
  208. mov iZStep, eax
  209. ;iSurfaceStep = pCtx->iSurfaceStep;
  210. mov eax, [ebx+RASTCTX_iSurfaceStep]
  211. mov iSurfaceStep, eax
  212. ;}
  213. DoneSpanDirif:
  214. ; Setup Code Ends
  215. ; ----------------------------------------------------------------------------------------------------------------
  216. ; Loop Code Begins
  217. ;//while (1)
  218. ;//{
  219. PixelLoop:
  220. ; Ztestcode
  221. ; edx is uZ
  222. ; eax is uZB
  223. ; 16 bit unsigned format
  224. ;UINT16 uZ = (UINT16)(pS->uZ>>15);
  225. ;UINT16 uZB = *((UINT16*)pS->pZ);
  226. mov edx, [ebp+RASTSPAN_uZ]
  227. movd mm4, edx
  228. mov esi, [ebp+RASTSPAN_pZ]
  229. shr edx, 15
  230. movzx eax, word ptr [esi]
  231. ;pS->uZ += pP->iDZDX;
  232. ;if ((pCtx->iZXorMask)^(uZ > uZB))
  233. ; !(uZ > uZB) <==>
  234. ; (uZ <= uZB) <==>
  235. ; (uZ < uZB+1) <==>
  236. ;
  237. sub eax, edx
  238. paddd mm4, [ecx+RASTPRIM_iDZDX]
  239. movd [ebp+RASTSPAN_uZ], mm4
  240. xor eax, [ebx+RASTCTX_iZXorMask]
  241. test eax, eax
  242. js FailLabel
  243. mov word ptr [esi], dx
  244. ; texturecode
  245. ;---------------------------------------------------------------------------
  246. ;void Tex1Addr_TexAddrWrapMirror_Persp_Bilinear_NoMip(PD3DI_RASTCTX pCtx, PD3DI_RASTPRIM pP,
  247. ; PD3DI_RASTSPAN pS)
  248. ;{
  249. ;PD3DI_SPANTEX pTex = &pCtx->Texture[0];
  250. mov esi, [ebx+RASTCTX_pTexture]
  251. ; ----------------------------------------
  252. ; Doing UV calculation a little more accurate
  253. ; Exactly like C code.
  254. ; I shift iU and iV to the right not by (TEX_FINAL_SHIFT - iShiftU0) but by
  255. ; (TEX_FINAL_SHIFT - iShiftU0 - 6). iShiftU0 = pTex->iShiftU - iLOD0
  256. ; (TEX_FINAL_SHIFT - (pTex->iShiftU - iLOD0))
  257. ; (TEX_FINAL_SHIFT + iLOD0 - pTex->iShiftU)
  258. ; COMMENT1**
  259. ; If textures have a max of 1024 then shiftU0 would be at most 10 which would
  260. ; make (TEXT_FINAL_SHIFT - iShiftU - 6) at most zero. This is why I choose 6
  261. ; It will also give bi-linear 6 bits of precision I think it was said that
  262. ; only five was needed.
  263. ;INT16 iShiftU0 = pTex->iShiftU - iLOD0;
  264. ;INT16 iShiftV0 = pTex->iShiftV - iLOD0;
  265. movq mm5, MMWORD PTR Val0x000a000a ; This is TEX_FINAL_SHIFT - 6 = 10.
  266. ;iLOD0 is zero in monolithic case so no subtraction needed.
  267. movd mm4, [esi+SPANTEX_iShiftU]
  268. psubw mm5, mm4
  269. movq mm4, mm5
  270. pand mm5, MMWORD PTR Val0xffff
  271. psrld mm4, 16
  272. movd mm1, [ebx+RASTCTX_SI+SPANITER_iU1]
  273. psrad mm1, mm5
  274. movd mm2, [ebx+RASTCTX_SI+SPANITER_iV1]
  275. psrad mm2, mm4
  276. punpckldq mm1, mm2
  277. psubd mm1, MMWORD PTR Val0x0000002000000020
  278. ; Texture Pitch cannot be calculated so it must be looked up in the iShiftPitch table
  279. ; ----------------- Start of hack
  280. ; ATTENTION This is really hacked right now. Just to get it working
  281. ; Pitch would be better for me, instead of shift pitch.
  282. ; With actual pitch, this would be two moves and a shift.
  283. ;shl eax, 1
  284. movzx edx, word ptr [esi+SPANTEX_iShiftPitch]
  285. add edx, 16
  286. movd mm2, edx
  287. movq mm5, MMWORD ptr Makelow16one
  288. pslld mm5, mm2
  289. ;pslld mm5, 16 ;. Use this after hack.
  290. ; not needed in hacked version since i add to shifted value.
  291. ; ----------------- End of hack
  292. por mm5, MMWORD ptr Makelow16one
  293. ; Make the low 16 bits of dword one
  294. ; This helps in calculating texture address.
  295. ; Gets U and V value into mm1 so that it can be mirrored, wrapped or
  296. ; clamped. This can be done for two values in the point case
  297. ; or four values in the bilinear case.
  298. ;INT32 iUFrac = iU00 & 0x03f;
  299. ;INT32 iVFrac = iV00 & 0x03f;
  300. ;iU00 >>= 6;
  301. ;iV00 >>= 6;
  302. movq mm2, mm1
  303. psrad mm1, 6
  304. ;pand mm1, MMWORD PTR Val0x0000ffff0000ffff
  305. pand mm2, dword ptr UFracVFracMask ; UFracVFracMask = 0x0000003f0000003f
  306. ; Going to use only 8 bits for bi-linear so that I can do a pmullw.
  307. ; Currently at 6 bits so shift up by 2.
  308. psllw mm2, 2
  309. movq mm0, mm2
  310. ; Replicate VFrac value for bilinear
  311. punpckhwd mm2, mm2
  312. punpcklwd mm2, mm2
  313. ; Replicate UFrac Value for bilinear
  314. punpcklwd mm0, mm0
  315. punpcklwd mm0, mm0
  316. movq dword ptr VFrac, mm2
  317. movq dword ptr UFrac, mm0
  318. ;INT32 iU01 = iU00 + 1;
  319. ;INT32 iV01 = iV00 + 1;
  320. packssdw mm1, mm1 ; replicate U and V value to upper 16 bit locations
  321. paddw mm1, dword ptr IncHighandLow16
  322. ; This will make texture values be (High word to low word):
  323. ; iV01, iU00, iV00, iU01
  324. ; Need to do this to make texture look up for bilinear easier.
  325. ; I have to combine to get all combinations anyway. It just
  326. ; happens to be better for me to have iV00, iU01 pair first.
  327. ;UINT16 uMaskU0 = pTex->uMaskU >> iLOD0; UINT16 uMaskV0 = pTex->uMaskV >> iLOD0;
  328. ; put mask in mm3 and replicate to match location for wrap/mirror/clamp
  329. movd mm0, [esi+SPANTEX_uMaskU] ; Load U and V mask
  330. ; replicate mask if doing bilinear
  331. punpckldq mm0, mm0
  332. ;INT16 iFlip;
  333. ; MM1 should contain 16 bit iU and iV for both texture locations
  334. ; End Result is MM1 value wrapped or mirrored
  335. ; in Bilinear Case, four values can be done
  336. ; iU00, iV00, iU01, iV01
  337. ; This code really does alot for the bilinear case and is kinda wasteful
  338. ; in the normal mode.
  339. ;iU00 &= uMaskU0; ;iV00 &= uMaskV0; ;iU01 &= uMaskU0; ;iV01 &= uMaskV0;
  340. pand mm1, mm0
  341. ; Result in mm1 now since TexAddrAll ends up that way.
  342. ; Making other two cases for texture addressing has to be simplier than
  343. ; this and not use so many registers. Puts U1 V0 U0 V1 into mm3.
  344. ; TBD Make this better.
  345. ; values are still stored as iV01, iU00, iV00, iU01
  346. movq mm2, mm1
  347. movq mm3, mm1
  348. ; Calculate 1st and 3rd texel addresses
  349. pmaddwd mm1, mm5 ; Throw in first address calculation.
  350. ; values are being changed to iV01, iU01, iV00, iU00
  351. ; seven instructions for this seems excessive.
  352. pand mm2, MMWORD ptr MaskKeepUValues
  353. pand mm3, MMWORD ptr MaskKeepVValues
  354. movq mm4, mm2
  355. psllq mm2, 32
  356. psrlq mm4, 32
  357. por mm3, mm2
  358. por mm3, mm4
  359. ; From here until mov edi is code that is needed for border.
  360. ; all sign bits are stored in bytes so that border code can tell if uv went below zero.
  361. ; Calculate 2nd and 4th texel addresses
  362. pmaddwd mm3, mm5 ; Calculates iU1+iV0*iShiftU0 and iU0+iV1*iShiftU0
  363. mov edi, [esi+SPANTEX_pBits]
  364. ;D3DCOLOR TexRead_B5G6R5_NoBorder(INT32 iU, INT32 iV, INT32 iShiftU, PUINT8 pBits, PD3DI_SPANTEX pTex)
  365. ;{
  366. pxor mm2, mm2
  367. ; 1st (mm1) and 2nd (mm3) texel
  368. movd eax, mm3 ; load 2nd texel address
  369. movd mm4, dword ptr [edi+4*eax] ; mm4 = 2nd texel
  370. movd eax, mm1 ; load 1st texel address
  371. movd mm7, dword ptr [edi+4*eax] ; mm7 = 1st texel
  372. ; mm4 calculated from high 32 bits of mm3 (2nd texel)
  373. ; pad high 8 bits of each component with zeros because D3DCOLOR has 16
  374. ; bits for each color component
  375. punpcklbw mm4, mm2
  376. ; mm7 calculated from low 32 bits of mm1 (1st texel)
  377. ; pad high 8 bits of each component with zeros because D3DCOLOR has 16
  378. ; bits for each color component
  379. punpcklbw mm7, mm2
  380. psrlq mm3, 32 ; shift 4th texel address into low 32 bits
  381. ; mm7 = final calc on 1st and 2nd texel
  382. psubw mm7, mm4
  383. psllw mm4, 8
  384. pmullw mm7, dword ptr UFrac
  385. paddw mm7, mm4
  386. ; 3rd (mm1) and 4th (mm3) texel
  387. movd eax, mm3 ; load 4th texel address
  388. psrlq mm1, 32 ; shift 3rd texel address into low 32 bits
  389. movd mm6, dword ptr [edi+4*eax] ; mm6 = 4th texel
  390. movd eax, mm1 ; load 3rd texel address
  391. movd mm4, dword ptr [edi+4*eax] ; mm4 = 3rd texel
  392. ; mm6 = 4th texel (high 32 bits), 3rd texel (low 32 bits)
  393. ; mm4 calculated from high 32 bits of mm3 (4th texel)
  394. ; pad high 8 bits of each component with zeros because D3DCOLOR has 16
  395. ; bits for each color component
  396. punpcklbw mm4, mm2
  397. ; mm6 calculated from low 32 bits of mm1 (3rd texel)
  398. ; pad high 8 bits of each component with zeros because D3DCOLOR has 16
  399. ; bits for each color component
  400. punpcklbw mm6, mm2
  401. psubw mm6, mm4
  402. psllw mm4, 8
  403. pmullw mm6, dword ptr UFrac
  404. movq mm1, mm7
  405. ; mm6 = final calc on 3rd and 4th texel
  406. paddw mm6, mm4
  407. ; mm1 = final calc on 1st+2nd texel and 3rd+4th texel
  408. psrlw mm6, 8
  409. psrlw mm7, 8
  410. psubw mm6, mm7
  411. pmullw mm6, dword ptr VFrac
  412. paddw mm1, mm6
  413. psrlw mm1, 8
  414. ;modulate
  415. ;UINT16 uB = pS->uB>>COLOR_SHIFT;
  416. ;UINT16 uG = pS->uG>>COLOR_SHIFT;
  417. ;UINT16 uR = pS->uR>>COLOR_SHIFT;
  418. movq mm4, [ebp+RASTSPAN_uB]
  419. psrlw mm4, COLOR_SHIFT ; COLOR_SHIFT is set to 8.
  420. ;UINT16 uTB = (UINT16)(RGBA_GETBLUE(pCtx->SI.TexCol[0]));
  421. ;UINT16 uTG = (UINT16)(RGBA_GETGREEN(pCtx->SI.TexCol[0]));
  422. ;UINT16 uTR = (UINT16)(RGBA_GETRED(pCtx->SI.TexCol[0]));
  423. ;UINT16 uTA = (UINT16)(RGBA_GETALPHA(pCtx->SI.TexCol[0]));
  424. ; this is a PMULLW, which works on unsigned 16 bit quantities
  425. ;pCtx->SI.uBB = uB*uTB;
  426. ;pCtx->SI.uBG = uG*uTG;
  427. ;pCtx->SI.uBR = uR*uTR;
  428. ;pCtx->SI.uBA = uTA<<COLOR_SHIFT;
  429. pmullw mm4, mm1
  430. ; write
  431. ;*(PUINT16)pS->pSurface =
  432. ; ((pCtx->SI.uBR >> 0) & 0xf800) |
  433. ; ((pCtx->SI.uBG >> 5) & 0x07e0) |
  434. ; ((pCtx->SI.uBB >> 11) & 0x001f);
  435. mov edi, [ebp+RASTSPAN_pSurface]
  436. psrlw mm4, 8 ; Convert color1 from 8.8 two 0.8
  437. packuswb mm4, mm7 ; pack one color
  438. movd edx, mm4
  439. and edx, 000ffffffh
  440. mov [edi], edx
  441. FailLabel:
  442. ;//if (--uPix <= 0)
  443. ;// break;
  444. dec uPix ;// BUG BUG?? uPix should never start as zero should it?
  445. ;// if so, this is a bug.
  446. jle ExitPixelLoop
  447. ; Doing update code after span length test so that an extra update is not done.
  448. ;void TestFail_Gouraud_PerspTex1_NoSpecularFog(PD3DI_RASTCTX pCtx, PD3DI_RASTPRIM pP,
  449. ; PD3DI_RASTSPAN pS)
  450. ;{
  451. ;pS->uB += pP->iDBDX; pS->uG += pP->iDGDX;
  452. ;pS->uR += pP->iDRDX; pS->uA += pP->iDADX;
  453. movq mm1, [ebp+RASTSPAN_uB]
  454. paddw mm1, [ecx+RASTPRIM_iDBDX]
  455. movq [ebp+RASTSPAN_uB], mm1
  456. ;pS->iUoW1 += pP->iDUoW1DX;
  457. ;pS->iVoW1 += pP->iDVoW1DX;
  458. movq mm5, [ebp+RASTSPAN_iUoW1]
  459. paddd mm5, [ecx+RASTPRIM_iDUoW1DX]
  460. movq [ebp+RASTSPAN_iUoW1], mm5
  461. ;pS->iOoW += pP->iDOoWDX;
  462. mov eax, [ebp+RASTSPAN_iOoW]
  463. add eax, [ecx+RASTPRIM_iDOoWDX]
  464. mov [ebp+RASTSPAN_iOoW], eax
  465. ;INT32 iWn0 = pS->iW + pCtx->SI.iDW; // 1.15.16
  466. ; TODO Could do this and OoW Add at same time with MMX.
  467. mov edx, [ebp+RASTSPAN_iW]
  468. mov LastW, edx ; Save iW to calc iDW for next time.
  469. add edx, [ebx+RASTCTX_SI+SPANITER_iDW]
  470. ;if (pCtx->SI.iSpecialW < 0)
  471. ;{
  472. xor edi, edi
  473. cmp di, word ptr [ebx+RASTCTX_SI+SPANITER_iSpecialW]
  474. jle DontDoSpecialW1
  475. ;DoSpecialW1:
  476. ; This label is a left over from when
  477. ;if (iWn0 < 0)
  478. ;{
  479. cmp edx, edi
  480. jl WOutOfRange1
  481. ;iWn0 = pS->iW >> 1; // use iW/2 as a guess, instead
  482. mov edx, LastW
  483. sar edx, 1
  484. ;}
  485. WOutOfRange1:
  486. ;VAL32 iWn1;
  487. ;INT16 iWnOld = iWn0 + 0x100; // make sure while fails first time
  488. ; Dont need to make sure it fails. I do a post test which guarentees it will execute once.
  489. ;INT32 iGiveUp = 7;
  490. mov GiveUp, 8 ; Pre decrementing instead of post decrementing.
  491. ;while((abs(iWnOld - iWn0) > 0x20) && (iGiveUp-- > 0))
  492. ;{
  493. SpecW1Loop1:
  494. ; Could move this to bottom of loop and combine results somehow.
  495. ; TBD look at it more.
  496. dec GiveUp
  497. jz ExitSpecWLoop1
  498. ; Shift iOoW by one since imul cannot have sign bit set
  499. ; OoW cannot reach one, only 0x7fffffff
  500. ;shr eax, 1 ; 1.31 >> 1 = 1.30
  501. ; Get ready to do Two minus iOoW*iW
  502. mov esi, (1 SHL 16)
  503. ;iWnOld = iWn0;
  504. mov edi, edx
  505. ; Result should be close to one so we want most of the
  506. ; precision in the low bits. Need to give more bits
  507. ; leaway since these are the bad cases.
  508. ; iWn1 = imul32h(pS->iOoW, iWn0); // 1.31*1.15.16 = 1.16.47 >> 32 = 1.16.15
  509. imul edx
  510. ;iWn1 = (1L<<16) - iWn1; // 2.0 - iWn1
  511. sub esi, edx
  512. ;while(iWn1.i < 0)
  513. ;{
  514. SpecW1Loop2:
  515. test esi, esi
  516. jns SpecW1ExitLoop2 ; This jump should be predicted correctly most of the time.
  517. ;iWn1=(iWn1+(1L<<15))>>1; // iWn1 = (iWn1 + 1.0)/2
  518. add esi, (1 SHL 15)
  519. sar esi, 1
  520. jmp SpecW1Loop2
  521. ;}
  522. SpecW1ExitLoop2:
  523. ;iWn1 <<= 15; // 1.16.15 << 15 = 1.1.30
  524. mov eax, edi
  525. shl eax, 5 ; 1.15.16 << 5 = 1.10.21 TBD Can I shift off upper bits??
  526. shl esi, 12 ; 4.15 << 12 = 4.27 ;
  527. ;iWn0 = imul32h(iWn1, iWn0)<<2; // 1.1.30 * 1.15.16 = 1.17.46 >> 32 = 1.17.14 << 2 = 1.15.16
  528. ; Actually 4.27 * 1.10.21 = 1.14.48 >> 32 = 1.14.16. No need for post shift.
  529. mul esi
  530. ; Have to do (abs(iWnOld - iWn0) > 0x20) code here.
  531. sub edi, edx
  532. ; These four lines are abs code.
  533. mov eax, edi
  534. sar eax, 31
  535. xor edi, eax
  536. sub edi, eax
  537. cmp edi, 020h ;Assuming that loop will only happen once.
  538. jbe ExitSpecWLoop1
  539. ; Reload eax with iOoW.
  540. mov eax, [ebp+RASTSPAN_iOoW]
  541. jmp SpecW1Loop1
  542. ;}
  543. ;else
  544. ;{
  545. DontDoSpecialW1:
  546. ; Everything should be positive in Non-SpecialW case.
  547. ;INT32 iWn1;
  548. mov esi, (1 SHL 16)
  549. mov edi, edx
  550. ; This should be close to one so Low bits are most important.
  551. ;iWn1 = (iOoW*iWn0)>>15; // 1.31*0.15.16 == 0.16.47 >> 32 = 0.16.15
  552. mul edx
  553. ;iWn1 = (1L<<16) - iWn1; // 2.0 - iWn1
  554. sub esi, edx
  555. ;iWn1 <<= 15; // 1.16.15 << 15 = 1.1.30
  556. shl esi, 15 ; 0.16.15 << 15 = 0.2.30
  557. mov eax, esi
  558. ;iWn0 = imul32h(iWn1, iWn0)<<2; // 1.1.30 * 1.15.16 = 1.17.46 >> 32 = 1.17.14 << 2 = 1.15.16
  559. mul edi ; 0.2.30 * 1.15.16 = 1.17.46 >> 32 = 1.17.14
  560. shl edx, 2 ; 1.17.14 << 2 = 1.15.16
  561. ;}
  562. ;}
  563. ExitSpecWLoop1:
  564. ;pCtx->SI.iDW = iWn0 - (UINT16)pS->iW;
  565. ;pS->iW = iWn0;
  566. mov [ebp+RASTSPAN_iW], edx
  567. mov esi, edx ; Save W for multiplying by UoW and VoW
  568. sub edx, LastW
  569. mov [ebx+RASTCTX_SI+SPANITER_iDW], edx
  570. ;pCtx->SI.iSpecialW += 1; // this is supposed to wrap past 0x7fff sometimes
  571. inc word ptr [ebx+RASTCTX_SI+SPANITER_iSpecialW]
  572. ;pCtx->SI.iU1 = d_WTimesUVoW(pS->iW,pS->iUoW1);
  573. ;pCtx->SI.iV1 = d_WTimesUVoW(pS->iW,pS->iVoW1);
  574. pslld mm5, 8
  575. shl esi, 4
  576. movd eax, mm5
  577. psrlq mm5, 32
  578. imul esi
  579. mov [ebx+RASTCTX_SI+SPANITER_iU1], edx
  580. movd eax, mm5
  581. imul esi
  582. mov [ebx+RASTCTX_SI+SPANITER_iV1], edx
  583. ;//pS->pZ += iZStep;
  584. ;//pS->pSurface += iSurfaceStep;
  585. mov eax, dword ptr [ebp+RASTSPAN_pZ]
  586. mov edx, dword ptr [ebp+RASTSPAN_pSurface]
  587. add eax, iZStep
  588. add edx, iSurfaceStep
  589. mov dword ptr [ebp+RASTSPAN_pZ], eax
  590. mov dword ptr [ebp+RASTSPAN_pSurface], edx
  591. ;#ifdef DBG
  592. ;// handy for debug to see where we are
  593. ;//pS->uX += (INT16)pCtx->SI.iXStep;
  594. ;#endif
  595. ;// } // while
  596. jmp PixelLoop
  597. ExitPixelLoop:
  598. ; Loop code ends
  599. ;-----------------------------------------------------------------------------
  600. ; LoopAny code ends here
  601. ;-----------------------------------------------------------------------------
  602. ;pS++;
  603. add ebp, SIZEOF_RASTSPAN
  604. ;}
  605. jmp SpanLoop
  606. ExitSpanLoop:
  607. ;pP = pP->pNext;
  608. mov ecx, [ecx+RASTPRIM_pNext]
  609. ;}
  610. jmp PrimLoop
  611. ExitPrimLoop:
  612. ;_asm{
  613. emms
  614. ;}
  615. ;return S_OK;
  616. xor eax, eax
  617. ;}
  618. pop edi
  619. pop esi
  620. pop ebx
  621. mov esp, StackPos
  622. pop ebp
  623. ret
  624. END