ReactOS  0.4.15-dev-2956-g61e7ea5
__rt_div.c File Reference

Go to the source code of this file.

Classes

struct  _ARM_UDIVRESULT
 
struct  _ARM_SDIVRESULT
 

Typedefs

typedef struct _ARM_UDIVRESULT ARM_UDIVRESULT
 
typedef struct _ARM_SDIVRESULT ARM_SDIVRESULT
 

Functions

__forceinline void __brkdiv0 (void)
 
__forceinline void __rt_udiv_internal (ARM_UDIVRESULT *result, unsigned int divisor, unsigned int dividend)
 
ARM_UDIVRESULT __rt_udiv (unsigned int divisor, unsigned int dividend)
 
ARM_SDIVRESULT __rt_sdiv (int divisor, int dividend)
 

Typedef Documentation

◆ ARM_SDIVRESULT

◆ ARM_UDIVRESULT

Function Documentation

◆ __brkdiv0()

__forceinline void __brkdiv0 ( void  )

Definition at line 19 of file __rt_div.c.

20 {
21  __emit(0xDEF9);
22 }

Referenced by __rt_udiv_internal().

◆ __rt_sdiv()

ARM_SDIVRESULT __rt_sdiv ( int  divisor,
int  dividend 
)

Definition at line 94 of file __rt_div.c.

97 {
99  int divisor_sign, dividend_sign;
100 
101  dividend_sign = divisor & 0x80000000;
102  if (dividend_sign)
103  {
104  dividend = -dividend;
105  }
106 
107  divisor_sign = divisor & 0x80000000;
108  if (divisor_sign)
109  {
110  divisor = -divisor;
111  }
112 
114 
115  if (dividend_sign ^ divisor_sign)
116  {
117  result.quotient = -result.quotient;
118  }
119 
120  if (dividend_sign)
121  {
122  result.modulus = -result.modulus;
123  }
124 
125  return result;
126 }
GLuint64EXT * result
Definition: glext.h:11304
__forceinline void __rt_udiv_internal(ARM_UDIVRESULT *result, unsigned int divisor, unsigned int dividend)
Definition: __rt_div.c:26
GLuint divisor
Definition: glext.h:6313

◆ __rt_udiv()

ARM_UDIVRESULT __rt_udiv ( unsigned int  divisor,
unsigned int  dividend 
)

Definition at line 77 of file __rt_div.c.

80 {
82 
83  __rt_udiv_internal(&result, divisor, dividend);
84  return result;
85 }
GLuint64EXT * result
Definition: glext.h:11304
__forceinline void __rt_udiv_internal(ARM_UDIVRESULT *result, unsigned int divisor, unsigned int dividend)
Definition: __rt_div.c:26
GLuint divisor
Definition: glext.h:6313

◆ __rt_udiv_internal()

__forceinline void __rt_udiv_internal ( ARM_UDIVRESULT result,
unsigned int  divisor,
unsigned int  dividend 
)

Definition at line 26 of file __rt_div.c.

30 {
31  unsigned int shift;
32  unsigned int mask;
33  unsigned int quotient;
34 
35  if (divisor == 0)
36  {
37  /* Raise divide by zero error */
38  __brkdiv0();
39  }
40 
41  if (divisor > dividend)
42  {
43  result->quotient = 0;
44  result->modulus = divisor;
45  return;
46  }
47 
48  /* Get the difference in count of leading zeros between dividend and divisor */
50  shift -= _CountLeadingZeros(dividend);
51 
52  /* Shift the divisor to the left, so that it's highest bit is the same
53  as the highest bit of the dividend */
54  divisor <<= shift;
55 
56  mask = 1 << shift;
57 
58  quotient = 0;
59  do
60  {
61  if (dividend >= divisor)
62  {
63  quotient |= mask;
64  dividend -= divisor;
65  }
66  divisor >>= 1;
67  mask >>= 1;
68  }
69  while (mask);
70 
71  result->quotient = quotient;
72  result->modulus = dividend;
73  return;
74 }
#define shift
Definition: input.c:1756
GLuint64EXT * result
Definition: glext.h:11304
__INTRIN_INLINE unsigned _CountLeadingZeros(long Mask)
Definition: intrin_arm.h:47
GLenum GLint GLuint mask
Definition: glext.h:6028
__forceinline void __brkdiv0(void)
Definition: __rt_div.c:19
GLuint divisor
Definition: glext.h:6313

Referenced by __rt_sdiv(), and __rt_udiv().