Last change
on this file since 133 was
81,
checked in by rosiere, 17 years ago
|
- Finish Environment (and test)
- Continue predictor_unit
- Add external tools
- svn keyword "Id" set
|
-
Property svn:keywords set to
Id
|
File size:
1.2 KB
|
Line | |
---|
1 | #include "func_math.h" |
---|
2 | |
---|
3 | //-----[ Multiplication ]-------------------------------------------------- |
---|
4 | |
---|
5 | // Multiplication rapide |
---|
6 | unsigned int mul_soft(unsigned int op1, |
---|
7 | unsigned int op2) |
---|
8 | { |
---|
9 | unsigned int num_bit,carry; |
---|
10 | unsigned int op2_aux = op2; |
---|
11 | unsigned int res = 0; |
---|
12 | |
---|
13 | for(num_bit=0;num_bit<32; num_bit++) |
---|
14 | { |
---|
15 | if (op2_aux == 0) |
---|
16 | break; |
---|
17 | |
---|
18 | carry = op2_aux & 1; |
---|
19 | op2_aux = op2_aux >> 1; |
---|
20 | |
---|
21 | if (carry!=0) |
---|
22 | res += (op1 << num_bit); |
---|
23 | } |
---|
24 | return res; |
---|
25 | } |
---|
26 | |
---|
27 | unsigned int mul_hard(unsigned int op1, |
---|
28 | unsigned int op2) |
---|
29 | { |
---|
30 | return op1*op2; |
---|
31 | } |
---|
32 | |
---|
33 | //-----[ Division ]-------------------------------------------------------- |
---|
34 | |
---|
35 | unsigned int div_soft( unsigned int op1, |
---|
36 | unsigned int op2) |
---|
37 | { |
---|
38 | unsigned res; |
---|
39 | |
---|
40 | if (op2 == 0) |
---|
41 | return 0; |
---|
42 | |
---|
43 | for (res = 0; op1 >= op2; res ++) |
---|
44 | op1 -= op2; |
---|
45 | |
---|
46 | return res; |
---|
47 | } |
---|
48 | |
---|
49 | unsigned int div_hard( unsigned int op1, |
---|
50 | unsigned int op2) |
---|
51 | { |
---|
52 | //return (op1/op2); |
---|
53 | return div_soft(op1,op2); |
---|
54 | } |
---|
55 | |
---|
56 | //-----[ Modulo ]---------------------------------------------------------- |
---|
57 | |
---|
58 | unsigned int modulo( unsigned int x, |
---|
59 | unsigned int base) |
---|
60 | { |
---|
61 | if (base==0) |
---|
62 | return 0; |
---|
63 | |
---|
64 | while(x >= base) |
---|
65 | x -= base; |
---|
66 | |
---|
67 | return x; |
---|
68 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.