1 /* The common simulator framework for GDB, the GNU Debugger.
3 Copyright 2002 Free Software Foundation, Inc.
5 Contributed by Andrew Cagney and Red Hat.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
31 /* INTEGER ALU MODULE:
33 This module provides an implementation of 2's complement arithmetic
34 including the recording of carry and overflow status bits.
39 Code using this module includes it into sim-main.h and then, as a
40 convention, defines macro's ALU*_END that records the result of any
41 arithmetic performed. Ex:
44 #define ALU32_END(RES) \
45 (RES) = ALU32_OVERFLOW_RESULT; \
46 carry = ALU32_HAD_CARRY_BORROW; \
47 overflow = ALU32_HAD_OVERFLOW
49 The macro's are then used vis:
60 Macros exist for efficiently computing 8, 16, 32 and 64 bit
61 arithmetic - ALU8_*, ALU16_*, .... In addition, according to
62 TARGET_WORD_BITSIZE a set of short-hand macros are defined - ALU_*
66 ALU*_BEGIN(ACC): Declare initialize the ALU accumulator with ACC.
70 The calculation of the final result may be computed a number
71 of different ways. Three different overflow macro's are
72 defined, the most efficient one to use depends on which other
73 outputs from the alu are being used.
75 ALU*_RESULT: Generic ALU result output.
77 ALU*_HAD_OVERFLOW: Returns a nonzero value if signed overflow
80 ALU*_OVERFLOW_RESULT: If the macro ALU*_HAD_OVERFLOW is being
81 used this is the most efficient result available. Ex:
83 #define ALU16_END(RES) \
84 if (ALU16_HAD_OVERFLOW) \
85 sim_engine_halt (...); \
86 (RES) = ALU16_OVERFLOW_RESULT
88 ALU*_HAD_CARRY_BORROW: Returns a nonzero value if unsigned
89 overflow or underflow (also referred to as carry and borrow)
92 ALU*_CARRY_BORROW_RESULT: If the macro ALU*_HAD_CARRY_BORROW is being
93 used this is the most efficient result available. Ex:
95 #define ALU64_END(RES) \
96 State.carry = ALU64_HAD_CARRY_BORROW; \
97 (RES) = ALU64_CARRY_BORROW_RESULT
102 ALU*_ADD(VAL): Add VAL to the ALU accumulator. Record any
103 overflow as well as the final result.
105 ALU*_ADDC(VAL): Add VAL to the ALU accumulator. Record any
106 carry-out or overflow as well as the final result.
108 ALU*_ADDC_C(VAL,CI): Add VAL and CI (carry-in). Record any
109 carry-out or overflow as well as the final result.
113 ALU*_SUB(VAL): Subtract VAL from the ALU accumulator. Record
114 any underflow as well as the final result.
116 ALU*_SUBC(VAL): Subtract VAL from the ALU accumulator using
117 negated addition. Record any underflow or carry-out as well
120 ALU*_SUBB(VAL): Subtract VAL from the ALU accumulator using
121 direct subtraction (ACC+~VAL+1). Record any underflow or
122 borrow-out as well as the final result.
124 ALU*_SUBC_X(VAL,CI): Subtract VAL and CI (carry-in) from the
125 ALU accumulator using extended negated addition (ACC+~VAL+CI).
126 Record any underflow or carry-out as well as the final result.
128 ALU*_SUBB_B(VAL,BI): Subtract VAL and BI (borrow-in) from the
129 ALU accumulator using direct subtraction. Record any
130 underflow or borrow-out as well as the final result.
137 /* Twos complement arithmetic - addition/subtraction - carry/borrow
138 (or you thought you knew the answer to 0-0)
142 Notation and Properties:
145 Xn denotes the value X stored in N bits.
147 MSBn (X): The most significant (sign) bit of X treated as an N bit
150 SEXTn (X): The infinite sign extension of X treated as an N bit
153 MAXn, MINn: The upper and lower bound of a signed, two's
154 complement N bit value.
156 UMAXn: The upper bound of an unsigned N bit value (the lower
157 bound is always zero).
159 Un: UMAXn + 1. Unsigned arithmetic is computed `modulo (Un)'.
161 X[p]: Is bit P of X. X[0] denotes the least significant bit.
163 ~X[p]: Is the inversion of bit X[p]. Also equal to 1-X[p],
168 Addition - Overflow - Introduction:
171 Overflow/Overflow indicates an error in computation of signed
172 arithmetic. i.e. given X,Y in [MINn..MAXn]; overflow
173 indicates that the result X+Y > MAXn or X+Y < MIN_INTx.
175 Hardware traditionally implements overflow by computing the XOR of
176 carry-in/carry-out of the most significant bit of the ALU. Here
177 other methods need to be found.
181 Addition - Overflow - method 1:
184 Overflow occurs when the sign (most significant bit) of the two N
185 bit operands is identical but different to the sign of the result:
188 V = MSBn (~(Xn ^ Yn) & (Rn ^ Xn))
192 Addition - Overflow - method 2:
195 The two N bit operands are sign extended to M>N bits and then
196 added. Overflow occurs when SIGN_BIT<n> and SIGN_BIT<m> do not
199 Rm = (SEXTn (Xn) + SEXTn (Yn))
200 V = MSBn ((Rm >> (M - N)) ^ Rm)
204 Addition - Overflow - method 3:
207 The two N bit operands are sign extended to M>N bits and then
208 added. Overflow occurs when the result is outside of the sign
209 extended range [MINn .. MAXn].
213 Addition - Overflow - method 4:
216 Given the Result and Carry-out bits, the oVerflow from the addition
217 of X, Y and carry-In can be computed using the equation:
220 V = (MSBn ((Xn ^ Yn) ^ Rn)) ^ C)
222 As shown in the table below:
224 I X Y R C | V | X^Y ^R ^C
225 ---------------+---+-------------
226 0 0 0 0 0 | 0 | 0 0 0
227 0 0 1 1 0 | 0 | 1 0 0
228 0 1 0 1 0 | 0 | 1 0 0
229 0 1 1 0 1 | 1 | 0 0 1
230 1 0 0 1 0 | 1 | 0 1 1
231 1 0 1 0 1 | 0 | 1 1 0
232 1 1 0 0 1 | 0 | 1 1 0
233 1 1 1 1 1 | 0 | 0 1 0
237 Addition - Carry - Introduction:
240 Carry (poorly named) indicates that an overflow occurred for
241 unsigned N bit addition. i.e. given X, Y in [0..UMAXn] then
242 carry indicates X+Y > UMAXn or X+Y >= Un.
244 The following table lists the output for all given inputs into a
258 (carry-In, X, Y, Result, Carry-out):
262 Addition - Carry - method 1:
265 Looking at the terms X, Y and R we want an equation for C.
274 This giving us the sum-of-prod equation:
276 MSBn ((Xn & Yn) | (Xn & ~Rn) | (Yn & ~Rn))
280 I X Y R | C | X&Y X&~R Y&~R
281 ------------+---+---------------
293 Addition - Carry - method 2:
296 Given two signed N bit numbers, a carry can be detected by treating
297 the numbers as N bit unsigned and adding them using M>N unsigned
298 arithmetic. Carry is indicated by bit (1 << N) being set (result
303 Addition - Carry - method 3:
306 Given the oVerflow bit. The carry can be computed from:
312 Addition - Carry - method 4:
314 Given two signed numbers. Treating them as unsigned we have:
316 0 <= X < Un, 0 <= Y < Un
319 Consider Y when carry occurs:
322 ==> (Un - X) <= Y < Un # rearrange
323 ==> Un <= X + Y < Un + X < 2 Un # add Xn
324 ==> 0 <= (X + Y) mod Un < X mod Un
326 or when carry as occurred:
328 (X + Y) mod Un < X mod Un
330 Consider Y when carry does not occur:
335 ==> X mod Un <= (X + Y) mod Un
337 or when carry has not occurred:
339 ! ( (X + Y) mod Un < X mod Un)
341 hence we get carry by computing in N bit unsigned arithmetic.
343 carry <- (Xn + Yn) < Xn
347 Subtraction - Introduction
350 There are two different ways of computing the signed two's
351 complement difference of two numbers. The first is based on
352 negative addition, the second on direct subtraction.
356 Subtraction - Carry - Introduction - Negated Addition
359 The equation X - Y can be computed using:
362 ==> X + ~Y + 1 # -Y = ~Y + 1
364 In addition to the result, the equation produces Carry-out. For
365 succeeding extended precision calculations, the more general
366 equation can be used:
368 C[p]:R[p] = X[p] + ~Y[p] + C[p-1]
369 where C[0]:R[0] = X[0] + ~Y[0] + 1
373 Subtraction - Borrow - Introduction - Direct Subtraction
376 The alternative to negative addition is direct subtraction where
377 `X-Y is computed directly. In addition to the result of the
378 calculation, a Borrow bit is produced. In general terms:
380 B[p]:R[p] = X[p] - Y[p] - B[p-1]
381 where B[0]:R[0] = X[0] - Y[0]
383 The Borrow bit is the complement of the Carry bit produced by
384 Negated Addition above. A dodgy proof follows:
387 C[0]:R[0] = X[0] + ~Y[0] + 1
388 ==> C[0]:R[0] = X[0] + 1 - Y[0] + 1 # ~Y[0] = (1 - Y[0])?
389 ==> C[0]:R[0] = 2 + X[0] - Y[0]
390 ==> C[0]:R[0] = 2 + B[0]:R[0]
391 ==> C[0]:R[0] = (1 + B[0]):R[0]
392 ==> C[0] = ~B[0] # (1 + B[0]) mod 2 = ~B[0]?
395 C[p]:R[p] = X[p] + ~Y[p] + C[p-1]
396 ==> C[p]:R[p] = X[p] + 1 - Y[0] + 1 - B[p-1]
397 ==> C[p]:R[p] = 2 + X[p] - Y[0] - B[p-1]
398 ==> C[p]:R[p] = 2 + B[p]:R[p]
399 ==> C[p]:R[p] = (1 + B[p]):R[p]
402 The table below lists all possible inputs/outputs for a
417 Subtraction - Method 1
420 Treating Xn and Yn as unsigned values then a borrow (unsigned
421 underflow) occurs when:
430 /* 8 bit target expressions:
432 Since the host's natural bitsize > 8 bits, carry method 2 and
433 overflow method 2 are used. */
435 #define ALU8_BEGIN(VAL) \
436 unsigned alu8_cr = (unsigned8) (VAL); \
437 signed alu8_vr = (signed8) (alu8_cr)
439 #define ALU8_SET(VAL) \
440 alu8_cr = (unsigned8) (VAL); \
441 alu8_vr = (signed8) (alu8_cr)
443 #define ALU8_SET_CARRY_BORROW(CARRY) \
446 alu8_cr |= ((signed)-1) << 8; \
451 #define ALU8_HAD_CARRY_BORROW (alu8_cr & LSBIT32(8))
452 #define ALU8_HAD_OVERFLOW (((alu8_vr >> 8) ^ alu8_vr) & LSBIT32 (8-1))
454 #define ALU8_RESULT ((unsigned8) alu8_cr)
455 #define ALU8_CARRY_BORROW_RESULT ((unsigned8) alu8_cr)
456 #define ALU8_OVERFLOW_RESULT ((unsigned8) alu8_vr)
458 /* #define ALU8_END ????? - target dependant */
462 /* 16 bit target expressions:
464 Since the host's natural bitsize > 16 bits, carry method 2 and
465 overflow method 2 are used. */
467 #define ALU16_BEGIN(VAL) \
468 signed alu16_cr = (unsigned16) (VAL); \
469 unsigned alu16_vr = (signed16) (alu16_cr)
471 #define ALU16_SET(VAL) \
472 alu16_cr = (unsigned16) (VAL); \
473 alu16_vr = (signed16) (alu16_cr)
475 #define ALU16_SET_CARRY_BORROW(CARRY) \
478 alu16_cr |= ((signed)-1) << 16; \
480 alu16_cr &= 0xffff; \
483 #define ALU16_HAD_CARRY_BORROW (alu16_cr & LSBIT32(16))
484 #define ALU16_HAD_OVERFLOW (((alu16_vr >> 16) ^ alu16_vr) & LSBIT32 (16-1))
486 #define ALU16_RESULT ((unsigned16) alu16_cr)
487 #define ALU16_CARRY_BORROW_RESULT ((unsigned16) alu16_cr)
488 #define ALU16_OVERFLOW_RESULT ((unsigned16) alu16_vr)
490 /* #define ALU16_END ????? - target dependant */
494 /* 32 bit target expressions:
496 Since most hosts do not support 64 (> 32) bit arithmetic, carry
497 method 4 and overflow method 4 are used. */
499 #define ALU32_BEGIN(VAL) \
500 unsigned32 alu32_r = (VAL); \
504 #define ALU32_SET(VAL) \
509 #define ALU32_SET_CARRY_BORROW(CARRY) alu32_c = (CARRY)
511 #define ALU32_HAD_CARRY_BORROW (alu32_c)
512 #define ALU32_HAD_OVERFLOW (alu32_v)
514 #define ALU32_RESULT (alu32_r)
515 #define ALU32_CARRY_BORROW_RESULT (alu32_r)
516 #define ALU32_OVERFLOW_RESULT (alu32_r)
520 /* 64 bit target expressions:
522 Even though the host typically doesn't support native 64 bit
523 arithmetic, it is still used. */
525 #define ALU64_BEGIN(VAL) \
526 unsigned64 alu64_r = (VAL); \
530 #define ALU64_SET(VAL) \
535 #define ALU64_SET_CARRY_BORROW(CARRY) alu64_c = (CARRY)
537 #define ALU64_HAD_CARRY_BORROW (alu64_c)
538 #define ALU64_HAD_OVERFLOW (alu64_v)
540 #define ALU64_RESULT (alu64_r)
541 #define ALU64_CARRY_BORROW_RESULT (alu64_r)
542 #define ALU64_OVERFLOW_RESULT (alu64_r)
546 /* Generic versions of above macros */
548 #define ALU_BEGIN XCONCAT3(ALU,WITH_TARGET_WORD_BITSIZE,_BEGIN)
549 #define ALU_SET XCONCAT3(ALU,WITH_TARGET_WORD_BITSIZE,_SET)
550 #define ALU_SET_CARRY XCONCAT3(ALU,WITH_TARGET_WORD_BITSIZE,_SET_CARRY)
552 #define ALU_HAD_OVERFLOW XCONCAT3(ALU,WITH_TARGET_WORD_BITSIZE,_HAD_OVERFLOW)
553 #define ALU_HAD_CARRY XCONCAT3(ALU,WITH_TARGET_WORD_BITSIZE,_HAD_CARRY)
555 #define ALU_RESULT XCONCAT3(ALU,WITH_TARGET_WORD_BITSIZE,_RESULT)
556 #define ALU_OVERFLOW_RESULT XCONCAT3(ALU,WITH_TARGET_WORD_BITSIZE,_OVERFLOW_RESULT)
557 #define ALU_CARRY_RESULT XCONCAT3(ALU,WITH_TARGET_WORD_BITSIZE,_CARRY_RESULT)
561 /* Basic operation - add (overflowing) */
563 #define ALU8_ADD(VAL) \
565 unsigned8 alu8add_val = (VAL); \
566 ALU8_ADDC (alu8add_val); \
569 #define ALU16_ADD(VAL) \
571 unsigned16 alu16add_val = (VAL); \
572 ALU16_ADDC (alu8add_val); \
575 #define ALU32_ADD(VAL) \
577 unsigned32 alu32add_val = (VAL); \
578 ALU32_ADDC (alu32add_val); \
581 #define ALU64_ADD(VAL) \
583 unsigned64 alu64add_val = (unsigned64) (VAL); \
584 ALU64_ADDC (alu64add_val); \
587 #define ALU_ADD XCONCAT3(ALU,WITH_TARGET_WORD_BITSIZE,_ADD)
591 /* Basic operation - add carrying (and overflowing) */
593 #define ALU8_ADDC(VAL) \
595 unsigned8 alu8addc_val = (VAL); \
596 alu8_cr += (unsigned8)(alu8addc_val); \
597 alu8_vr += (signed8)(alu8addc_val); \
600 #define ALU16_ADDC(VAL) \
602 unsigned16 alu16addc_val = (VAL); \
603 alu16_cr += (unsigned16)(alu16addc_val); \
604 alu16_vr += (signed16)(alu16addc_val); \
607 #define ALU32_ADDC(VAL) \
609 unsigned32 alu32addc_val = (VAL); \
610 unsigned32 alu32addc_sign = alu32addc_val ^ alu32_r; \
611 alu32_r += (alu32addc_val); \
612 alu32_c = (alu32_r < alu32addc_val); \
613 alu32_v = ((alu32addc_sign ^ - (unsigned32)alu32_c) ^ alu32_r) >> 31; \
616 #define ALU64_ADDC(VAL) \
618 unsigned64 alu64addc_val = (unsigned64) (VAL); \
619 unsigned64 alu64addc_sign = alu64addc_val ^ alu64_r; \
620 alu64_r += (alu64addc_val); \
621 alu64_c = (alu64_r < alu64addc_val); \
622 alu64_v = ((alu64addc_sign ^ - (unsigned64)alu64_c) ^ alu64_r) >> 63; \
625 #define ALU_ADDC XCONCAT3(ALU,WITH_TARGET_WORD_BITSIZE,_ADDC)
629 /* Compound operation - add carrying (and overflowing) with carry-in */
631 #define ALU8_ADDC_C(VAL,C) \
633 unsigned8 alu8addcc_val = (VAL); \
634 unsigned8 alu8addcc_c = (C); \
635 alu8_cr += (unsigned)(unsigned8)alu8addcc_val + alu8addcc_c; \
636 alu8_vr += (signed)(signed8)(alu8addcc_val) + alu8addcc_c; \
639 #define ALU16_ADDC_C(VAL,C) \
641 unsigned16 alu16addcc_val = (VAL); \
642 unsigned16 alu16addcc_c = (C); \
643 alu16_cr += (unsigned)(unsigned16)alu16addcc_val + alu16addcc_c; \
644 alu16_vr += (signed)(signed16)(alu16addcc_val) + alu16addcc_c; \
647 #define ALU32_ADDC_C(VAL,C) \
649 unsigned32 alu32addcc_val = (VAL); \
650 unsigned32 alu32addcc_c = (C); \
651 unsigned32 alu32addcc_sign = (alu32addcc_val ^ alu32_r); \
652 alu32_r += (alu32addcc_val + alu32addcc_c); \
653 alu32_c = ((alu32_r < alu32addcc_val) \
654 || (alu32addcc_c && alu32_r == alu32addcc_val)); \
655 alu32_v = ((alu32addcc_sign ^ - (unsigned32)alu32_c) ^ alu32_r) >> 31;\
658 #define ALU64_ADDC_C(VAL,C) \
660 unsigned64 alu64addcc_val = (VAL); \
661 unsigned64 alu64addcc_c = (C); \
662 unsigned64 alu64addcc_sign = (alu64addcc_val ^ alu64_r); \
663 alu64_r += (alu64addcc_val + alu64addcc_c); \
664 alu64_c = ((alu64_r < alu64addcc_val) \
665 || (alu64addcc_c && alu64_r == alu64addcc_val)); \
666 alu64_v = ((alu64addcc_sign ^ - (unsigned64)alu64_c) ^ alu64_r) >> 63;\
669 #define ALU_ADDC_C XCONCAT3(ALU,WITH_TARGET_WORD_BITSIZE,_ADDC_C)
673 /* Basic operation - subtract (overflowing) */
675 #define ALU8_SUB(VAL) \
677 unsigned8 alu8sub_val = (VAL); \
678 ALU8_ADDC_C (~alu8sub_val, 1); \
681 #define ALU16_SUB(VAL) \
683 unsigned16 alu16sub_val = (VAL); \
684 ALU16_ADDC_C (~alu16sub_val, 1); \
687 #define ALU32_SUB(VAL) \
689 unsigned32 alu32sub_val = (VAL); \
690 ALU32_ADDC_C (~alu32sub_val, 1); \
693 #define ALU64_SUB(VAL) \
695 unsigned64 alu64sub_val = (VAL); \
696 ALU64_ADDC_C (~alu64sub_val, 1); \
699 #define ALU_SUB XCONCAT3(ALU,WITH_TARGET_WORD_BITSIZE,_SUB)
703 /* Basic operation - subtract carrying (and overflowing) */
705 #define ALU8_SUBC(VAL) \
707 unsigned8 alu8subc_val = (VAL); \
708 ALU8_ADDC_C (~alu8subc_val, 1); \
711 #define ALU16_SUBC(VAL) \
713 unsigned16 alu16subc_val = (VAL); \
714 ALU16_ADDC_C (~alu16subc_val, 1); \
717 #define ALU32_SUBC(VAL) \
719 unsigned32 alu32subc_val = (VAL); \
720 ALU32_ADDC_C (~alu32subc_val, 1); \
723 #define ALU64_SUBC(VAL) \
725 unsigned64 alu64subc_val = (VAL); \
726 ALU64_ADDC_C (~alu64subc_val, 1); \
729 #define ALU_SUBC XCONCAT3(ALU,WITH_TARGET_WORD_BITSIZE,_SUBC)
733 /* Compound operation - subtract carrying (and overflowing), extended */
735 #define ALU8_SUBC_X(VAL,C) \
737 unsigned8 alu8subcx_val = (VAL); \
738 unsigned8 alu8subcx_c = (C); \
739 ALU8_ADDC_C (~alu8subcx_val, alu8subcx_c); \
742 #define ALU16_SUBC_X(VAL,C) \
744 unsigned16 alu16subcx_val = (VAL); \
745 unsigned16 alu16subcx_c = (C); \
746 ALU16_ADDC_C (~alu16subcx_val, alu16subcx_c); \
749 #define ALU32_SUBC_X(VAL,C) \
751 unsigned32 alu32subcx_val = (VAL); \
752 unsigned32 alu32subcx_c = (C); \
753 ALU32_ADDC_C (~alu32subcx_val, alu32subcx_c); \
756 #define ALU64_SUBC_X(VAL,C) \
758 unsigned64 alu64subcx_val = (VAL); \
759 unsigned64 alu64subcx_c = (C); \
760 ALU64_ADDC_C (~alu64subcx_val, alu64subcx_c); \
763 #define ALU_SUBC_X XCONCAT3(ALU,WITH_TARGET_WORD_BITSIZE,_SUBC_X)
767 /* Basic operation - subtract borrowing (and overflowing) */
769 #define ALU8_SUBB(VAL) \
771 unsigned8 alu8subb_val = (VAL); \
772 alu8_cr -= (unsigned)(unsigned8)alu8subb_val; \
773 alu8_vr -= (signed)(signed8)alu8subb_val; \
776 #define ALU16_SUBB(VAL) \
778 unsigned16 alu16subb_val = (VAL); \
779 alu16_cr -= (unsigned)(unsigned16)alu16subb_val; \
780 alu16_vr -= (signed)(signed16)alu16subb_val; \
783 #define ALU32_SUBB(VAL) \
785 unsigned32 alu32subb_val = (VAL); \
786 unsigned32 alu32subb_sign = alu32subb_val ^ alu32_r; \
787 alu32_c = (alu32_r < alu32subb_val); \
788 alu32_r -= (alu32subb_val); \
789 alu32_v = ((alu32subb_sign ^ - (unsigned32)alu32_c) ^ alu32_r) >> 31; \
792 #define ALU64_SUBB(VAL) \
794 unsigned64 alu64subb_val = (VAL); \
795 unsigned64 alu64subb_sign = alu64subb_val ^ alu64_r; \
796 alu64_c = (alu64_r < alu64subb_val); \
797 alu64_r -= (alu64subb_val); \
798 alu64_v = ((alu64subb_sign ^ - (unsigned64)alu64_c) ^ alu64_r) >> 31; \
801 #define ALU_SUBB XCONCAT3(ALU,WITH_TARGET_WORD_BITSIZE,_SUBB)
805 /* Compound operation - subtract borrowing (and overflowing) with borrow-in */
807 #define ALU8_SUBB_B(VAL,B) \
809 unsigned8 alu8subbb_val = (VAL); \
810 unsigned8 alu8subbb_b = (B); \
811 alu8_cr -= (unsigned)(unsigned8)alu8subbb_val; \
812 alu8_cr -= (unsigned)(unsigned8)alu8subbb_b; \
813 alu8_vr -= (signed)(signed8)alu8subbb_val + alu8subbb_b; \
816 #define ALU16_SUBB_B(VAL,B) \
818 unsigned16 alu16subbb_val = (VAL); \
819 unsigned16 alu16subbb_b = (B); \
820 alu16_cr -= (unsigned)(unsigned16)alu16subbb_val; \
821 alu16_cr -= (unsigned)(unsigned16)alu16subbb_b; \
822 alu16_vr -= (signed)(signed16)alu16subbb_val + alu16subbb_b; \
825 #define ALU32_SUBB_B(VAL,B) \
827 unsigned32 alu32subbb_val = (VAL); \
828 unsigned32 alu32subbb_b = (B); \
829 ALU32_ADDC_C (~alu32subbb_val, !alu32subbb_b); \
830 alu32_c = !alu32_c; \
833 #define ALU64_SUBB_B(VAL,B) \
835 unsigned64 alu64subbb_val = (VAL); \
836 unsigned64 alu64subbb_b = (B); \
837 ALU64_ADDC_C (~alu64subbb_val, !alu64subbb_b); \
838 alu64_c = !alu64_c; \
841 #define ALU_SUBB_B XCONCAT3(ALU,WITH_TARGET_WORD_BITSIZE,_SUBB_B)
845 /* Basic operation - negate (overflowing) */
849 signed alu8neg_val = (ALU8_RESULT); \
851 ALU8_ADDC (~alu8neg_val); \
854 #define ALU16_NEG() \
856 signed alu16neg_val = (ALU16_RESULT); \
858 ALU16_ADDC (~alu16neg_val); \
861 #define ALU32_NEG() \
863 unsigned32 alu32neg_val = (ALU32_RESULT); \
865 ALU32_ADDC (~alu32neg_val); \
868 #define ALU64_NEG() \
870 unsigned64 alu64neg_val = (ALU64_RESULT); \
872 ALU64_ADDC (~alu64neg_val); \
875 #define ALU_NEG XCONCAT3(ALU,WITH_TARGET_WORD_BITSIZE,_NEG)
880 /* Basic operation - negate carrying (and overflowing) */
882 #define ALU8_NEGC() \
884 signed alu8negc_val = (ALU8_RESULT); \
886 ALU8_ADDC (~alu8negc_val); \
889 #define ALU16_NEGC() \
891 signed alu16negc_val = (ALU16_RESULT); \
893 ALU16_ADDC (~alu16negc_val); \
896 #define ALU32_NEGC() \
898 unsigned32 alu32negc_val = (ALU32_RESULT); \
900 ALU32_ADDC (~alu32negc_val); \
903 #define ALU64_NEGC() \
905 unsigned64 alu64negc_val = (ALU64_RESULT); \
907 ALU64_ADDC (~alu64negc_val); \
910 #define ALU_NEGC XCONCAT3(ALU,WITH_TARGET_WORD_BITSIZE,_NEGC)
915 /* Basic operation - negate borrowing (and overflowing) */
917 #define ALU8_NEGB() \
919 signed alu8negb_val = (ALU8_RESULT); \
921 ALU8_SUBB (alu8negb_val); \
924 #define ALU16_NEGB() \
926 signed alu16negb_val = (ALU16_RESULT); \
928 ALU16_SUBB (alu16negb_val); \
931 #define ALU32_NEGB() \
933 unsigned32 alu32negb_val = (ALU32_RESULT); \
935 ALU32_SUBB (alu32negb_val); \
938 #define ALU64_NEGB() \
940 unsigned64 alu64negb_val = (ALU64_RESULT); \
942 ALU64_SUBB (alu64negb_val); \
945 #define ALU_NEGB XCONCAT3(ALU,WITH_TARGET_WORD_BITSIZE,_NEGB)
952 #define ALU8_OR(VAL) \
957 #define ALU16_OR(VAL) \
962 #define ALU32_OR(VAL) \
969 #define ALU64_OR(VAL) \
976 #define ALU_OR(VAL) XCONCAT3(ALU,WITH_TARGET_WORD_BITSIZE,_OR)(VAL)
980 #define ALU16_XOR(VAL) \
982 error("ALU16_XOR"); \
985 #define ALU32_XOR(VAL) \
992 #define ALU64_XOR(VAL) \
999 #define ALU_XOR(VAL) XCONCAT3(ALU,WITH_TARGET_WORD_BITSIZE,_XOR)(VAL)
1004 #define ALU16_AND(VAL) \
1006 error("ALU_AND16"); \
1009 #define ALU32_AND(VAL) \
1016 #define ALU64_AND(VAL) \
1023 #define ALU_AND(VAL) XCONCAT3(ALU,WITH_TARGET_WORD_BITSIZE,_AND)(VAL)
1028 #define ALU16_NOT(VAL) \
1030 error("ALU_NOT16"); \
1035 alu32_r = ~alu32_r; \
1042 alu64_r = ~alu64_r; \
1047 #define ALU_NOT XCONCAT3(ALU,WITH_TARGET_WORD_BITSIZE,_NOT)