source: golgotha/src/render/software/inline_fpu.hh

Last change on this file was 80, checked in by Sam Hocevar, 11 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 2.7 KB
Line 
1/********************************************************************** <BR>
2  This file is part of Crack dot Com's free source code release of
3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
4  information about compiling & licensing issues visit this URL</a>
5  <PRE> If that doesn't help, contact Jonathan Clark at
6  golgotha_source@usa.net (Subject should have "GOLG" in it)
7***********************************************************************/
8
9#ifndef INLINE_FPU_HH
10#define INLINE_FPU_HH
11
12#include "software/r1_software_globals.hh"
13
14#define bit(i) (1<<i)
15
16inline void start_ceil()
17{
18  //keep these bits, set all others to 0
19  w32 fpuand = bit(15) | bit(14) | bit(13) | bit(12) | bit(9) | bit(8) | 255;
20 
21  //then set bit 11 (round up, ceil for positive numbers)
22  w32 fpuor  = bit(11);
23 
24  _asm
25  {
26    xor     eax,eax
27    fstcw   word ptr [old_ceil_word]
28    mov     ax, word ptr [old_ceil_word]
29    and     eax, dword ptr [fpuand]
30    or      eax, dword ptr [fpuor]
31    mov     word ptr [new_ceil_word],ax
32    fldcw   word ptr [new_ceil_word]
33  }
34}
35
36inline void start_trunc()
37{
38  //keep these bits, set all others to 0
39  w32 fpuand = bit(15) | bit(14) | bit(13) | bit(12) | bit(9) | bit(8) | 255;
40 
41  //then set bit 11 and bit 10 (chop, true truncate)
42  w32 fpuor  = bit(11) | bit(10);
43 
44  _asm
45  {
46    xor     eax,eax
47    fstcw   word ptr [old_trunc_word]
48    mov     ax, word ptr [old_trunc_word]
49    and     eax, dword ptr [fpuand]
50    or      eax, dword ptr [fpuor]
51    mov     word ptr [new_trunc_word],ax
52    fldcw   word ptr [new_trunc_word]
53  }
54}
55
56//this doesnt interfere with the truncation or ceil control words,
57//so it can be used in conjunction (start_ceil(), start_single(), stop_single(), stop_ceil())
58
59inline void start_single()
60{
61  //keep these bits, set all others to 0
62  w32 fpuand = bit(15) | bit(14) | bit(13) | bit(12) | bit(11) | bit(10) | 255;
63 
64  //leave bits 8 and 9 off
65  w32 fpuor  = 0;
66 
67  _asm
68  {
69    xor     eax,eax
70    fstcw   word ptr [old_single_word]
71    mov     ax, word ptr [old_single_word]
72    and     eax, dword ptr [fpuand]
73    or      eax, dword ptr [fpuor]
74    mov     word ptr [new_single_word],ax
75    fldcw   word ptr [new_single_word]
76  }
77}
78
79inline void stop_single()
80{
81  _asm
82  {
83    fldcw dword ptr [old_single_word]
84  }
85}
86
87inline void stop_trunc()
88{
89  _asm
90  {
91    fldcw dword ptr [old_trunc_word]
92  }
93}
94
95inline void stop_ceil()
96{
97  _asm
98  {
99    fldcw dword ptr [old_ceil_word]
100  }
101}
102
103inline sw32 qftoi(float a)
104{
105  sw32 res;
106 
107  _asm
108  {
109    fld dword ptr [a]
110    fistp dword ptr [res]
111  }
112 
113  return res;
114}
115
116#endif
Note: See TracBrowser for help on using the repository browser.