m_fixed.c (1352B)
1 2 /* m_fixed.c -- fixed point implementation */ 3 4 #include "i_main.h" 5 #include "doomdef.h" 6 #include "p_spec.h" 7 #include "r_local.h" 8 9 /* 10 =============== 11 = 12 = FixedDiv 13 = 14 =============== 15 */ 16 17 fixed_t FixedDiv(fixed_t a, fixed_t b) // 80002BF8 18 { 19 fixed_t aa, bb; 20 unsigned c; 21 int sign; 22 23 sign = a^b; 24 25 if (a < 0) 26 aa = -a; 27 else 28 aa = a; 29 30 if (b < 0) 31 bb = -b; 32 else 33 bb = b; 34 35 if ((unsigned)(aa >> 14) >= bb) 36 { 37 if (sign < 0) 38 c = MININT; 39 else 40 c = MAXINT; 41 } 42 else 43 c = (fixed_t) FixedDiv2(a, b); 44 45 return c; 46 } 47 48 /* 49 =============== 50 = 51 = FixedMul 52 = 53 =============== 54 */ 55 56 fixed_t FixedMul(fixed_t a, fixed_t b) // 800044D0 57 { 58 s64 result = ((s64) a * (s64) b) >> 16; 59 60 return (fixed_t) result; 61 } 62 63 #if 0 64 s64 FixedMul2(s64 a, s64 b) // 800044D0 65 { 66 register s64 flo; 67 68 //asm(".set noreorder"); 69 asm("dmult $4, $5"); 70 asm("mflo $3"); 71 asm("dsra $3, 16"); 72 asm("move %0, $3":"=r" (flo):); 73 74 return (fixed_t) flo; 75 76 /* 77 dmult $4, $5 78 mflo $2 79 dsra $2, $2, 16 80 jr $31 81 nop 82 */ 83 } 84 #endif // 0 85 86 /* 87 =============== 88 = 89 = FixedDiv2 90 = 91 =============== 92 */ 93 94 fixed_t FixedDiv2(fixed_t a, fixed_t b) // 800044E4 95 { 96 s64 result = ((s64) a << 16) / (s64)b; 97 98 return (fixed_t) result; 99 }