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 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!

Thanks!

-- thorpej



Home | Main Index | Thread Index | Old Index