VirtualBox

Changeset 46992 in vbox for trunk


Ignore:
Timestamp:
Jul 5, 2013 8:00:06 AM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
87007
Message:

8-bit idiv overflow checks.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMAll/IEMAllAImpl.asm

    r46958 r46992  
    13311331        PROLOGUE_3_ARGS
    13321332
     1333        ; div by chainsaw check.
    13331334        test    A1_8, A1_8
    13341335        jz      .div_zero
     1336
     1337        ; Overflow check - unsigned division is simple to verify, haven't
     1338        ; found a simple way to check signed division yet unfortunately.
    13351339 %if %4 == 0
    13361340        cmp     [A0 + 1], A1_8
    13371341        jae     .div_overflow
    13381342 %else
    1339 ;        js      .divisor_negative
    1340 ;.divisor_positive:
    1341 ;        mov     ax, [A0]
    1342 ;        test    ax, ax
    1343 ;        js      .divisor_positive_dividend_negative
    1344 ;
    1345 ;.both_positive:
    1346 ;        shl     ax, 1
    1347 ;        cmp     ah, A1_8
    1348 ;        jae     .div_overflow
    1349 ;        jmp     .div_no_overflow
    1350 ;.both_negative:
    1351 ;        neg     ax
    1352 ;        shl     ax, 1
    1353 ;        mov     al, A1_8
    1354 ;        neg     al
    1355 ;        cmp     ah, al
    1356 ;        jae     .div_overflow
    1357 ;        jmp     .div_no_overflow
    1358 ;
    1359 ;.divisor_positive_dividend_negative:
    1360 ;        jmp     .div_no_overflow
    1361 ;.divisor_negative:
    1362 ;        test    ax, ax
    1363 ;        js      .both_negative
    1364 ;.divisor_negative_dividend_positive:
    1365 ;        jmp     .div_no_overflow
    1366 ;.div_no_overflow:
     1343        mov     T0_16, [A0]             ; T0 = dividend
     1344        mov     T1_8, A1_8              ; T1 = divisor
     1345        test    T1_16, T1_16
     1346        js      .divisor_negative
     1347        test    T0_16, T0_16
     1348        jns     .both_positive
     1349        neg     T0_16
     1350.one_of_each:                           ; OK range is 2^(result-with - 1) + (divisor - 1).
     1351        push    T0                      ; Start off like unsigned below.
     1352        shr     T0_16, 7
     1353        cmp     T0_8, T1_8
     1354        pop     T0
     1355        jb      .div_no_overflow
     1356        ja      .div_overflow
     1357        and     T0_8, 0x7f              ; Special case for covering (divisor - 1).
     1358        cmp     T0_8, T1_8
     1359        jae     .div_overflow
     1360        jmp     .div_no_overflow
     1361
     1362.divisor_negative:
     1363        neg     T1_8
     1364        test    T0_16, T0_16
     1365        jns     .one_of_each
     1366        neg     T0_16
     1367.both_positive:                         ; Same as unsigned shifted by sign indicator bit.
     1368        shr     T0_16, 7
     1369        cmp     T0_8, T1_8
     1370        jae     .div_overflow
     1371.div_no_overflow:
    13671372 %endif
    13681373
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette