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.

769 lines
23 KiB

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