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

**From**: |
Jose E. Marchesi |

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

**Date**: |
Mon, 22 Feb 2021 17:19:07 +0100 |

**User-agent**: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |

>* 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.*
I just thought that we should also make casts to signed integral types
overflow:
8 as uint<3> -> This evals to (uint <3>) 0, and is ok.
8 as int<3> -> This should error on overflow.