| 1 |
; This test covers the behavior of 40-bit mode for a variety of values. |
| 2 |
; It takes a while to run completely (~5 minutes), but progress is indicated via mail shown at the |
| 3 |
; top of the screen in DSPSpy. The value will go from 80000000 to 8041ffff. |
| 4 |
incdir "tests" |
| 5 |
include "dsp_base.inc" |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
test_main: |
| 10 |
LRI $ar0, #0 |
| 11 |
LRI $ar1, #0 |
| 12 |
LRI $ar2, #0 |
| 13 |
LRI $ar3, #0 |
| 14 |
LRI $ix0, #0 |
| 15 |
LRI $ix1, #0 |
| 16 |
LRI $ix2, #0 |
| 17 |
LRI $ix3, #0 |
| 18 |
|
| 19 |
; Test with $ac0.l from 0xfff0 to 0x0010 |
| 20 |
LRI $ac0.l, #0xfff0 |
| 21 |
BLOOPI #0x21, first_loop_last_ins |
| 22 |
CALL test_saturation |
| 23 |
IAR $ar0 |
| 24 |
first_loop_last_ins: |
| 25 |
INC $acc0 |
| 26 |
|
| 27 |
; Test with $ac0.l from 0x7ff0 to 0x8010 |
| 28 |
LRI $ac0.l, #0xfff0 |
| 29 |
BLOOPI #0x21, second_loop_last_ins |
| 30 |
CALL test_saturation |
| 31 |
IAR $ar0 |
| 32 |
second_loop_last_ins: |
| 33 |
INC $acc0 |
| 34 |
|
| 35 |
; We're done. Report the test results. |
| 36 |
; $ix1 should be 0, or else saturation occurred on $ac0.l or $ac0.h. |
| 37 |
; $ix2 should be 0, or else sign-extension occurred on $ac0.l or $ac0.h. |
| 38 |
; $ix3 should be 0, or else we incorrectly predicted saturation on $ac0.m. |
| 39 |
; $ar1/$ar2/$ar3 records the number of times it happened |
| 40 |
CALL send_back |
| 41 |
|
| 42 |
; We're done, DO NOT DELETE THIS LINE |
| 43 |
JMP end_of_test |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
test_saturation: |
| 48 |
; We start with $ac0.h at -0x80 since we can use the overflow flag to check when wrapping around |
| 49 |
; occurs; starting at 0 and ending when it wraps back to 0 doesn't work since we can't check the |
| 50 |
; zero flag since $ac0.l may be nonzero ($ac0.l is used as an input to this subroutine) |
| 51 |
LRI $ac0.m, #0 |
| 52 |
LRI $ac0.h, #-0x80 |
| 53 |
|
| 54 |
loop_start: |
| 55 |
; Compare the value of $ac0.m when in SET16 mode and in SET40 mode |
| 56 |
SET40 |
| 57 |
; Reading $ac0.m in SET40 mode results in saturation if $ac0.h doesn't match the sign-extension |
| 58 |
; of $ac0.h. Also, storing to $ac1.m in SET40 mode clears $ac1.l and sets $ac1.h to the |
| 59 |
; sign-extension of $ac1.m, and $ac1.l. |
| 60 |
MRR $ac1.m, $ac0.m |
| 61 |
SET16 |
| 62 |
; Attempt to compute the saturated value of $ac1.m in $ax1.h, |
| 63 |
; using what we know of $acc0. |
| 64 |
TST'MV $acc0 : $ax1.h, $ac0.m |
| 65 |
JL negative_acc0 |
| 66 |
; $acc0 is nonnegative. |
| 67 |
JMPx8 check_saturated_ax1h ; If the above s32 bit is not set, we don't need to saturate |
| 68 |
; If the above s32 bit _is_ set, then saturate $ax1.h. |
| 69 |
LRI $ax1.h, #0x7fff |
| 70 |
JMP check_saturated_ax1h |
| 71 |
|
| 72 |
negative_acc0: |
| 73 |
JMPx8 check_saturated_ax1h ; If the above s32 bit is not set, we don't need to saturate |
| 74 |
LRI $ax1.h, #0x8000 |
| 75 |
; Fall through to check_saturated_ax1h |
| 76 |
|
| 77 |
check_saturated_ax1h: |
| 78 |
; $acc1 has the value of $ac0.m in SET40 mode. |
| 79 |
; And, $ax1.h has what we computed that value should be, and CMPAXH always sign-extends $ax1.h |
| 80 |
; (and ignores $ax1.l), so we can compare using it directly. |
| 81 |
CMPAXH $acc1, $ax1.h |
| 82 |
JZ check_read_low |
| 83 |
; Our prediction was wrong (shouldn't happen) |
| 84 |
LRI $ix3, #1 |
| 85 |
IAR $ar3 |
| 86 |
TST $acc0 |
| 87 |
CALL send_back |
| 88 |
; Fall through to check_read_low |
| 89 |
|
| 90 |
check_read_low: |
| 91 |
SET40 |
| 92 |
MRR $ac1.m, $ac0.l |
| 93 |
SET16 |
| 94 |
MRR $ax1.h, $ac0.l |
| 95 |
CMPAXH $acc1, $ax1.h |
| 96 |
JZ check_read_high |
| 97 |
; Reading $ac0.l gave different results in SET40 and SET16 modes (shouldn't happen) |
| 98 |
LRI $ix1, #1 |
| 99 |
IAR $ar1 |
| 100 |
TST $acc0 |
| 101 |
CALL send_back |
| 102 |
; Fall through to check_read_high |
| 103 |
|
| 104 |
check_read_high: |
| 105 |
SET40 |
| 106 |
MRR $ac1.m, $ac0.h |
| 107 |
SET16 |
| 108 |
MRR $ax1.h, $ac0.h |
| 109 |
CMPAXH $acc1, $ax1.h |
| 110 |
JZ check_write_low |
| 111 |
; Reading $ac0.h gave different results in SET40 and SET16 modes (shouldn't happen) |
| 112 |
LRI $ix1, #1 |
| 113 |
IAR $ar1 |
| 114 |
TST $acc0 |
| 115 |
CALL send_back |
| 116 |
; Fall through to check_write_low |
| 117 |
|
| 118 |
check_write_low: |
| 119 |
MOV $acc1, $acc0 |
| 120 |
SET40 |
| 121 |
MRR $ac1.l, $ac0.l |
| 122 |
SET16 |
| 123 |
CMP |
| 124 |
JZ check_write_high |
| 125 |
; Writing to $ac1.l caused $acc1 to not match $acc0 (shouldn't happen) |
| 126 |
LRI $ix2, #1 |
| 127 |
IAR $ar2 |
| 128 |
CALL send_back |
| 129 |
; Fall through to check_write_high |
| 130 |
|
| 131 |
check_write_high: |
| 132 |
MOV $acc1, $acc0 |
| 133 |
SET40 |
| 134 |
MRR $ac1.h, $ac0.h |
| 135 |
SET16 |
| 136 |
CMP |
| 137 |
JZ increment_loop |
| 138 |
; Writing to $ac1.h caused $acc1 to not match $acc0 (shouldn't happen) |
| 139 |
LRI $ix2, #1 |
| 140 |
IAR $ar2 |
| 141 |
CALL send_back |
| 142 |
; Fall through to increment_loop |
| 143 |
|
| 144 |
increment_loop: |
| 145 |
INCM $ac0.m |
| 146 |
; If incrementing results in overflowing, then we're done. |
| 147 |
RETO |
| 148 |
|
| 149 |
; If ($ac0.m & 0x00ff) != 0, continue the loop without sending mail. |
| 150 |
ANDF $ac0.m, #0x00ff |
| 151 |
JLNZ loop_start |
| 152 |
; Otherwise, send mail to report the progress. (This shows at the top of the screen in DSPSpy, |
| 153 |
; but otherwise isn't handled in any meaningful way.) |
| 154 |
MOV $acc1, $acc0 |
| 155 |
LSR $acc1, #-8 |
| 156 |
; Compensate for starting at INT_MIN (0x80'0000'0000) and ending at INT_MAX (0x7f'0000'0000) |
| 157 |
; instead of going from 0 (0x00'0000'0000) to -1 (0xff'ffff'ffff) |
| 158 |
XORI $ac1.m, #0x8000 |
| 159 |
|
| 160 |
SR @DMBH, $ar0 |
| 161 |
SR @DMBL, $ac1.m |
| 162 |
SI @DIRQ, #0x0001 |
| 163 |
; We don't wait for the mail to be read, because we don't care about the response. |
| 164 |
JMP loop_start |