[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
## Re: integer overflow during divl instruction

**From**: |
Bruno Haible |

**Subject**: |
Re: integer overflow during divl instruction |

**Date**: |
Mon, 22 Feb 2021 16:03:52 +0100 |

**User-agent**: |
KMail/5.1.3 (Linux/4.4.0-201-generic; KDE/5.18.0; x86_64; ; ) |

Jose E. Marchesi wrote:
>* In Poke we have integer values of any number of bits from 1 to 63. If*
>* we were to define what happens when signed overflow occurs (like raising*
>* an exception E_overflow) that would need to happen also when a, say,*
>* 4-bit signed integer is overflown by an operation.*
>* *
>* So we need something more complex than that.*
Addition and subtraction for a signed integer type with N bits (1 ≤ N ≤ 64)
works like this:
add (x, y) := add_int64_t (x << (64-N), y << (64-N)) >> (64-N).
sub (x, y) := sub_int64_t (x << (64-N), y << (64-N)) >> (64-N).
mul (x, y) := mul_int64_t (x << (64-N), y) >> (64-N).
where add_int64_t, sub_int64_t, mul_int64_t check for overflow (intprops.h
macros INT_ADD_OVERFLOW, INT_SUBTRACT_OVERFLOW, INT_MULTIPLY_OVERFLOW)
and >> is a signed right-shift.
Bruno