Port-m68k archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: Help with integer division overflow issue
(re-send in proper encoding)
thorpej@ wrote:
>
> > # cc -o test-ccr test-ccr.c
> > # ./test-ccr
> > val = -2147483648 (0x80000000)
> > ccr = 0x80000008
> > #
>
> Wait, WAAAT?
>
> So, not only is the V flag not set, but N is set (yah, I guess the result is negative, but it should have overflowed!) and some random upper bit in the "int ccr;" variable is set???
>
> Help me to understand!
@moveccr said V was cleared by movel following divsl and
the upper bit is a garbage of the previous result in %d0:
2698: 42ae fff8 clrl %fp@(-8)
269c: 202e fffc movel %fp@(-4),%d0
26a0: 4c79 0800 0000 divsll 4a50 <divisor>,%d0,%d0
26a6: 4a50
26a8: 2d40 fffc movel %d0,%fp@(-4)
^^^^^^^^^^^^^^^^^^
26ac: 42c0 movew %ccr,%d0
^^^^^^^^^^^^^^
26ae: 2d40 fff8 movel %d0,%fp@(-8)
26b2: 2f2e fffc movel %fp@(-4),%sp@-
26b6: 2f2e fffc movel %fp@(-4),%sp@-
26ba: 4879 0000 27bc pea 27bc <_fini+0x1c>
26c0: 4eb9 0000 24cc jsr 24cc <printf@plt>
With the following asm, N and V seem set:
---
__asm __volatile(" \
movel %0,%%d0 ;\
divsl divisor,%%d0 ;\
movew %%ccr,%%d1 ; \
movel %%d0,%0 ; \
movew %%d1,%1"
: "=r" (val) , "=r" (ccr)
: "0" (val)
: "d0", "d1");
---
2698: 42ae fff8 clrl %fp@(-8)
269c: 202e fffc movel %fp@(-4),%d0
26a0: 2040 moveal %d0,%a0
26a2: 2008 movel %a0,%d0
26a4: 4c79 0800 0000 divsll 4a58 <divisor>,%d0,%d0
26aa: 4a58
26ac: 42c1 movew %ccr,%d1
26ae: 2040 moveal %d0,%a0
26b0: 3241 moveaw %d1,%a1
26b2: 2d48 fffc movel %a0,%fp@(-4)
26b6: 2d49 fff8 movel %a1,%fp@(-8)
26ba: 2f2e fffc movel %fp@(-4),%sp@-
26be: 2f2e fffc movel %fp@(-4),%sp@-
26c2: 4879 0000 27c4 pea 27c4 <_fini+0x1c>
26c8: 4eb9 0000 24cc jsr 24cc <printf@plt>
---
milan-% ./test-ccr
val = -2147483648 (0x80000000)
ccr = 0x0a
milan-%
---
---
Izumi Tsutsui
Home |
Main Index |
Thread Index |
Old Index