worlda.s 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. Copyright (C) 1996-1997 Id Software, Inc.
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. See the GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. //
  16. // worlda.s
  17. // x86 assembly-language server testing stuff
  18. //
  19. #define GLQUAKE 1 // don't include unneeded defs
  20. #include "asm_i386.h"
  21. #include "quakeasm.h"
  22. #include "d_ifacea.h"
  23. #if id386
  24. .data
  25. Ltemp: .long 0
  26. .text
  27. //----------------------------------------------------------------------
  28. // hull-point test
  29. //----------------------------------------------------------------------
  30. #define hull 4+8 // because only partially pushed
  31. #define num 8+4 // because only partially pushed
  32. #define p 12+12 // because only partially pushed
  33. .align 4
  34. .globl C(SV_HullPointContents)
  35. C(SV_HullPointContents):
  36. pushl %edi // preserve register variables
  37. movl num(%esp),%eax
  38. testl %eax,%eax
  39. js Lhquickout
  40. // float d;
  41. // dclipnode_t *node;
  42. // mplane_t *plane;
  43. pushl %ebx
  44. movl hull(%esp),%ebx
  45. pushl %ebp
  46. movl p(%esp),%edx
  47. movl hu_clipnodes(%ebx),%edi
  48. movl hu_planes(%ebx),%ebp
  49. subl %ebx,%ebx
  50. pushl %esi
  51. // %ebx: 0
  52. // %eax: num
  53. // %edx: p
  54. // %edi: hull->clipnodes
  55. // %ebp: hull->planes
  56. // while (num >= 0)
  57. // {
  58. Lhloop:
  59. // node = hull->clipnodes + num;
  60. // plane = hull->planes + node->planenum;
  61. // !!! if the size of dclipnode_t changes, the scaling of %eax needs to be
  62. // changed !!!
  63. movl nd_planenum(%edi,%eax,8),%ecx
  64. movl nd_children(%edi,%eax,8),%eax
  65. movl %eax,%esi
  66. rorl $16,%eax
  67. leal (%ecx,%ecx,4),%ecx
  68. // if (plane->type < 3)
  69. // d = p[plane->type] - plane->dist;
  70. movb pl_type(%ebp,%ecx,4),%bl
  71. cmpb $3,%bl
  72. jb Lnodot
  73. // else
  74. // d = DotProduct (plane->normal, p) - plane->dist;
  75. flds pl_normal(%ebp,%ecx,4)
  76. fmuls 0(%edx)
  77. flds pl_normal+4(%ebp,%ecx,4)
  78. fmuls 4(%edx)
  79. flds pl_normal+8(%ebp,%ecx,4)
  80. fmuls 8(%edx)
  81. fxch %st(1)
  82. faddp %st(0),%st(2)
  83. faddp %st(0),%st(1)
  84. fsubs pl_dist(%ebp,%ecx,4)
  85. jmp Lsub
  86. Lnodot:
  87. flds pl_dist(%ebp,%ecx,4)
  88. fsubrs (%edx,%ebx,4)
  89. Lsub:
  90. sarl $16,%eax
  91. sarl $16,%esi
  92. // if (d < 0)
  93. // num = node->children[1];
  94. // else
  95. // num = node->children[0];
  96. fstps Ltemp
  97. movl Ltemp,%ecx
  98. sarl $31,%ecx
  99. andl %ecx,%esi
  100. xorl $0xFFFFFFFF,%ecx
  101. andl %ecx,%eax
  102. orl %esi,%eax
  103. jns Lhloop
  104. // return num;
  105. Lhdone:
  106. popl %esi
  107. popl %ebp
  108. popl %ebx // restore register variables
  109. Lhquickout:
  110. popl %edi
  111. ret
  112. #endif // id386