OSDN Git Service

Remove as sg.exe is not a open source product.
[nxt-jsp/etrobo-atk.git] / lejos_osek / lejos_nxj / src / nxtvm / javavm / op_arithmetic.hc
1 /**
2  * This is included inside a switch statement.
3  */
4
5 case OP_ISUB:
6   // Arguments: 0
7   // Stack: -2 +1
8   just_set_top_word (-word2jint(get_top_word()));
9   // Fall through!
10 case OP_IADD:
11   // Arguments: 0
12   // Stack: -2 +1
13   tempStackWord = pop_word();
14   just_set_top_word (word2jint(get_top_word()) + word2jint(tempStackWord));
15   goto LABEL_ENGINELOOP;
16 case OP_IMUL:
17   // Arguments: 0
18   // Stack: -2 +1
19   tempStackWord = pop_word();
20   just_set_top_word (word2jint(get_top_word()) * word2jint(tempStackWord));
21   goto LABEL_ENGINELOOP;
22
23 case OP_IDIV:
24 case OP_IREM:
25   tempInt = word2jint(pop_word());
26   if (tempInt == 0)
27   {
28     throw_exception (arithmeticException);
29     goto LABEL_ENGINELOOP;
30   }
31   just_set_top_word ((*(pc-1) == OP_IDIV) ? word2jint(get_top_word()) / tempInt :
32                                             word2jint(get_top_word()) % tempInt);
33   goto LABEL_ENGINELOOP;
34
35 case OP_INEG:
36   just_set_top_word (-word2jint(get_top_word()));
37   goto LABEL_ENGINELOOP;
38
39 #if FP_ARITHMETIC
40
41 case OP_FSUB:
42   just_set_top_word (jfloat2word(-word2jfloat(get_top_word())));
43   // Fall through!
44 case OP_FADD:
45   tempStackWord = pop_word();
46   just_set_top_word (jfloat2word(word2jfloat(get_top_word()) + 
47                      word2jfloat(tempStackWord)));
48   goto LABEL_ENGINELOOP;
49 case OP_FMUL:
50   tempStackWord = pop_word();
51   just_set_top_word (jfloat2word(word2jfloat(get_top_word()) * 
52                      word2jfloat(tempStackWord)));
53   goto LABEL_ENGINELOOP;
54 case OP_FDIV:
55   // TBD: no division by zero?
56   tempStackWord = pop_word();
57   just_set_top_word (jfloat2word(word2jfloat(get_top_word()) / 
58                      word2jfloat(tempStackWord)));
59   goto LABEL_ENGINELOOP;
60 case OP_FNEG:
61 case OP_DNEG:
62   just_set_top_word (jfloat2word(-word2jfloat(get_top_word())));
63   goto LABEL_ENGINELOOP;
64 case OP_DSUB:
65   just_set_top_word (jfloat2word(-word2jfloat(get_top_word())));
66   // Fall through!
67 case OP_DADD:
68   tempStackWord = get_top_word();
69   pop_words(2);
70   just_set_top_word (jfloat2word(word2jfloat(get_top_word()) +
71                     word2jfloat(tempStackWord)));
72   goto LABEL_ENGINELOOP;
73 case OP_DMUL:
74   tempStackWord = get_top_word();
75   pop_words(2);
76   just_set_top_word (jfloat2word(word2jfloat(get_top_word()) *
77                     word2jfloat(tempStackWord)));
78   goto LABEL_ENGINELOOP;
79 case OP_DDIV:
80   // TBD: no division by zero?
81   tempStackWord = get_top_word();
82   pop_words(2);
83   just_set_top_word (jfloat2word(word2jfloat(get_top_word()) /
84                     word2jfloat(tempStackWord)));
85   goto LABEL_ENGINELOOP;
86
87 #endif // FP_ARITHMETIC
88
89 // Notes:
90 // - Not supported: LADD, LSUB, LMUL, LREM, FREM, DREM
91 // - Operations on doubles are truncated to low float
92
93 /*end*/
94
95
96
97
98
99
100