Port-m68k archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: Help with integer division overflow issue
On Thu, Jan 11, 2024 at 06:39:41PM -0800, Jason Thorpe wrote:
>
> > On Jan 9, 2024, at 7:22?AM, Jason Thorpe <thorpej%me.com@localhost> wrote:
> >
> >> On Jan 9, 2024, at 7:14?AM, Izumi Tsutsui <tsutsui%ceres.dti.ne.jp@localhost> wrote:
> >>
> >> milan-% cc -o test test.c
> >> milan-% ./test
> >> milan-%
> >> ---
> >>
> >> I.e. at least looks no exception.
> >
> > Yes, same with TME emulating a Sun3/160.
>
> Ok, can you try this one?
>
> #include <limits.h>
> #include <stdlib.h>
> #include <stdio.h>
>
> int divisor = -1;
>
> int
> main(int argc, char *argv[])
> {
> int val = INT_MIN;
> int ccr = 0;
>
> __asm __volatile("divsl divisor,%1" : "=r" (val) : "0" (val));
> __asm __volatile("move %%ccr,%0" : "=r" (ccr));
>
> printf("val = %d (0x%08x)\n", val, val);
> printf("ccr = 0x%02x\n", ccr);
>
> return 0;
> }
>
> On TME, the result is:
>
> sun3-160$ ./a.out
> val = -2147483648 (0x80000000)
> ccr = 0x02
> sun3-160$
>
> The V flag is set?but I?m a little surprised that the N flag is not set!
Although that seems legal from the docs I have?
...
DIVS, DIVSL
... Overflow may be detected and set before the instruction completes. If the in-
struction detects an overflow, it sets the overflow condition code, and the oper-
ands are unaffected.
...
N - Set if the quotient is negative; cleared otherwise; undefined if overflow or divide
by zero occurs.
Z - Set if the quotient is zero; cleared otherwise; undefined if overflow or divide by
zero occurs.
V - Set if division overflow occurs; undefined if divide by zero occurs; cleared oth-
erwise.
--
Paul Ripke
"Great minds discuss ideas, average minds discuss events, small minds
discuss people."
-- Disputed: Often attributed to Eleanor Roosevelt. 1948.
Home |
Main Index |
Thread Index |
Old Index