|
30 | 30 | INSTRUCTION (l_add) { |
31 | 31 | orreg_t temp1, temp2, temp3; |
32 | 32 | int8_t temp4; |
33 | | - |
| 33 | + |
34 | 34 | temp2 = (orreg_t)PARAM2; |
35 | 35 | temp3 = (orreg_t)PARAM1; |
36 | 36 | temp1 = temp2 + temp3; |
37 | 37 | SET_PARAM0 (temp1); |
38 | 38 |
|
39 | 39 | /* Set overflow if two negative values gave a positive sum, or if two |
40 | 40 | positive values gave a negative sum. Otherwise clear it */ |
41 | | - if ((((long int) temp2 < 0) && |
42 | | - ((long int) temp3 < 0) && |
43 | | - ((long int) temp1 >= 0)) || |
44 | | - (((long int) temp2 >= 0) && |
45 | | - ((long int) temp3 >= 0) && |
46 | | - ((long int) temp1 < 0))) |
| 41 | + if (__builtin_add_overflow_p (temp2, temp3, temp1)) |
47 | 42 | { |
48 | 43 | cpu_state.sprs[SPR_SR] |= SPR_SR_OV; |
49 | 44 | } |
@@ -119,12 +114,8 @@ INSTRUCTION (l_addc) { |
119 | 114 | positive values gave a negative sum. Otherwise clear it. There are no |
120 | 115 | corner cases with the extra bit carried in (unlike the carry flag - see |
121 | 116 | below). */ |
122 | | - if ((((long int) temp2 < 0) && |
123 | | - ((long int) temp3 < 0) && |
124 | | - ((long int) temp1 >= 0)) || |
125 | | - (((long int) temp2 >= 0) && |
126 | | - ((long int) temp3 >= 0) && |
127 | | - ((long int) temp1 < 0))) |
| 117 | + if (((temp2 < 0) && (temp3 < 0) && (temp1 >= 0)) || |
| 118 | + ((temp2 >= 0) && (temp3 >= 0) && (temp1 < 0))) |
128 | 119 | { |
129 | 120 | cpu_state.sprs[SPR_SR] |= SPR_SR_OV; |
130 | 121 | } |
@@ -336,12 +327,7 @@ INSTRUCTION (l_sub) { |
336 | 327 | /* Set overflow if a negative value minus a positive value gave a positive |
337 | 328 | sum, or if a positive value minus a negative value gave a negative |
338 | 329 | sum. Otherwise clear it */ |
339 | | - if ((((long int) temp2 < 0) && |
340 | | - ((long int) temp3 >= 0) && |
341 | | - ((long int) temp1 >= 0)) || |
342 | | - (((long int) temp2 >= 0) && |
343 | | - ((long int) temp3 < 0) && |
344 | | - ((long int) temp1 < 0))) |
| 330 | + if (__builtin_sub_overflow_p (temp2, temp3, temp1)) |
345 | 331 | { |
346 | 332 | cpu_state.sprs[SPR_SR] |= SPR_SR_OV; |
347 | 333 | } |
@@ -974,12 +960,7 @@ INSTRUCTION (l_mac) { |
974 | 960 |
|
975 | 961 | /* Set overflow if two negative values gave a positive sum, or if two |
976 | 962 | positive values gave a negative sum. Otherwise clear it */ |
977 | | - if (((acc < 0) && |
978 | | - (prod < 0) && |
979 | | - (tmp >= 0)) || |
980 | | - ((acc >= 0) && |
981 | | - (prod >= 0) && |
982 | | - (tmp < 0))) |
| 963 | + if (__builtin_add_overflow_p (acc, prod, tmp)) |
983 | 964 | { |
984 | 965 | cpu_state.sprs[SPR_SR] |= SPR_SR_OV; |
985 | 966 | } |
@@ -1042,12 +1023,7 @@ INSTRUCTION (l_msb) { |
1042 | 1023 | /* Set overflow if a negative value minus a positive value gave a positive |
1043 | 1024 | sum, or if a positive value minus a negative value gave a negative |
1044 | 1025 | sum. Otherwise clear it */ |
1045 | | - if (((acc < 0) && |
1046 | | - (prod >= 0) && |
1047 | | - (tmp >= 0)) || |
1048 | | - ((acc >= 0) && |
1049 | | - (prod < 0) && |
1050 | | - (tmp < 0))) |
| 1026 | + if (__builtin_sub_overflow_p (acc, prod, tmp)) |
1051 | 1027 | { |
1052 | 1028 | cpu_state.sprs[SPR_SR] |= SPR_SR_OV; |
1053 | 1029 | } |
|
0 commit comments