Fix lar and sar, which were horribly, horribly broken. Add tests.

This commit is contained in:
David Given 2018-09-17 18:44:17 +01:00
parent abb7e3e105
commit f61500c51b
6 changed files with 208 additions and 11 deletions

View file

@ -14,7 +14,7 @@
jal .aar4 jal .aar4
nop nop
/* pass r2 = size from .aar4 to .los4 /* pass r2 = size from .aar4 to .los4 */
jal .los4 jal .los4
nop nop

View file

@ -11,7 +11,7 @@
.sect .text .sect .text
.define .los4 .define .los4
.los4: .los4:
lw r4, 0(sp) ! r4 = address lw r4, 0(sp) ! r4 = address of source block
! Sizes 1 and 2 are handled specially. ! Sizes 1 and 2 are handled specially.
@ -26,14 +26,14 @@
! Else the size must be a multiple of 4. ! Else the size must be a multiple of 4.
srl r5, r2, 2 ! r5 = number of words srl r5, r2, 2 ! r5 = number of words
addiu sp, sp, 4 ! adjust to end of block addiu sp, sp, 4 ! retract over address
subu sp, sp, r4 ! sp = start of block subu sp, sp, r2 ! allocate space for destination block
mov r6, sp ! r6 = start of block mov r6, sp ! r6 = start of destination block
1: 1:
lw at, 0(r2) lw at, 0(r4)
sw at, 0(r6) sw at, 0(r6)
addiu r2, r2, 4 addiu r4, r4, 4
addiu r6, r6, 4 addiu r6, r6, 4
addiu r5, r5, -1 addiu r5, r5, -1
bne r5, zero, 1b bne r5, zero, 1b
@ -43,13 +43,13 @@
nop nop
byte_sized: byte_sized:
lb at, 0(r4) lbu at, 0(r4)
sw at, 0(sp) sw at, 0(sp)
jr ra jr ra
nop nop
word_sized: word_sized:
lh at, 0(r4) lhu at, 0(r4)
sw at, 0(sp) sw at, 0(sp)
jr ra jr ra
nop nop

View file

@ -14,7 +14,7 @@
jal .aar4 jal .aar4
nop nop
/* pass r2 = size from .aar4 to .sts4 /* pass r2 = size from .aar4 to .sts4 */
jal .sts4 jal .sts4
nop nop

View file

@ -71,6 +71,5 @@ descriptor
3 3
cal $finished cal $finished
end end

73
tests/plat/core/lar_e.e Normal file
View file

@ -0,0 +1,73 @@
#
mes 2, EM_WSIZE, EM_PSIZE
/*
* Does basic testing of lar. Unfortunately, lar throws ERANGE on
* error, which we can't catch (or at least, the platforms I've looked at
* don't allow it to be caught, those platforms which actually throw it on
* error). So we just test the non-throwing cases, not the negative ones.
*/
#define ARRAY_SIZE 3*EM_WSIZE
array
con 1
con 2
con 3
descriptor
con -1 ; lower bound
con 3 ; range
con EM_WSIZE ; size of element
exp $_m_a_i_n
pro $_m_a_i_n, 0
/* Read element -1 */
lae array
loc -1
lae descriptor
lar EM_WSIZE
loc 1
beq *1
loc __LINE__
cal $fail
ass EM_WSIZE
1
/* Read element 0 */
lae array
loc 0
lae descriptor
lar EM_WSIZE
loc 2
beq *2
loc __LINE__
cal $fail
ass EM_WSIZE
2
/* Read element 1 */
lae array
loc 1
lae descriptor
lar EM_WSIZE
loc 3
beq *3
loc __LINE__
cal $fail
ass EM_WSIZE
3
cal $finished
end

125
tests/plat/core/sar_e.e Normal file
View file

@ -0,0 +1,125 @@
#
mes 2, EM_WSIZE, EM_PSIZE
/*
* Does basic testing of sar. Unfortunately, sar throws ERANGE on
* error, which we can't catch (or at least, the platforms I've looked at
* don't allow it to be caught, those platforms which actually throw it on
* error). So we just test the non-throwing cases, not the negative ones.
*/
#define ARRAY_SIZE 3*EM_WSIZE
array
bss ARRAY_SIZE, 0, 0
descriptor
con -1 ; lower bound
con 3 ; range
con EM_WSIZE ; size of element
element0
con 1
con 0
con 0
element1
con 0
con 1
con 0
element2
con 0
con 0
con 1
exp $_m_a_i_n
pro $_m_a_i_n, 0
/* Write element -1 */
cal $clear_array
loc 1
lae array
loc -1
lae descriptor
sar EM_WSIZE
lae array
loi ARRAY_SIZE
lae element0
loi ARRAY_SIZE
loc ARRAY_SIZE
cms
zeq *1
loc __LINE__
cal $fail
ass EM_WSIZE
1
/* Write element 0 */
cal $clear_array
loc 1
lae array
loc 0
lae descriptor
sar EM_WSIZE
lae array
loi ARRAY_SIZE
lae element1
loi ARRAY_SIZE
loc ARRAY_SIZE
cms
zeq *2
loc __LINE__
cal $fail
ass EM_WSIZE
2
/* Write element 1 */
cal $clear_array
loc 1
lae array
loc 1
lae descriptor
sar EM_WSIZE
lae array
loi ARRAY_SIZE
lae element2
loi ARRAY_SIZE
loc ARRAY_SIZE
cms
zeq *3
loc __LINE__
cal $fail
ass EM_WSIZE
3
cal $finished
end
exp $clear_array
pro $clear_array, 0
loc 0
lae array + EM_WSIZE*0
sti EM_WSIZE
loc 0
lae array + EM_WSIZE*1
sti EM_WSIZE
loc 0
lae array + EM_WSIZE*2
sti EM_WSIZE
ret 0
end