Add the bitset helpers. We now have enough helpers for the tests to run (and
massively fail).
This commit is contained in:
parent
2f8fe3ce6e
commit
0ce368324e
30
mach/mips/libem/and.s
Normal file
30
mach/mips/libem/and.s
Normal file
|
@ -0,0 +1,30 @@
|
|||
#
|
||||
.sect .text; .sect .rom; .sect .data; .sect .bss
|
||||
|
||||
/*
|
||||
* Set intersection.
|
||||
* Stack: ( a b size -- a&b )
|
||||
*/
|
||||
|
||||
.sect .text
|
||||
.define .and
|
||||
.and:
|
||||
lw r4, 0(sp) ! r4 = size
|
||||
addiu sp, sp, 4 ! sp points at b
|
||||
addu r5, sp, r4 ! r5 points at a
|
||||
srl r4, r4, 2 ! r4 = count of words
|
||||
|
||||
1:
|
||||
lw at, 0(r5) ! load a
|
||||
lw r6, 0(sp) ! load b
|
||||
and at, at, r6 ! combine
|
||||
sw at, 0(r5) ! write back to a
|
||||
addiu r5, r5, 4
|
||||
addiu sp, sp, 4
|
||||
addiu r4, r4, -1
|
||||
bne r4, zero, 1b
|
||||
nop
|
||||
|
||||
jr ra
|
||||
nop
|
||||
|
27
mach/mips/libem/com.s
Normal file
27
mach/mips/libem/com.s
Normal file
|
@ -0,0 +1,27 @@
|
|||
#
|
||||
.sect .text; .sect .rom; .sect .data; .sect .bss
|
||||
|
||||
/*
|
||||
* Set complement.
|
||||
* Stack: ( a size -- ~a )
|
||||
*/
|
||||
|
||||
.sect .text
|
||||
.define .com
|
||||
.com:
|
||||
lw r4, 0(sp) ! r4 = size
|
||||
addiu sp, sp, 4
|
||||
mov r5, sp ! r5 points to set
|
||||
srl r4, r4, 2 ! r4 = word count
|
||||
|
||||
1:
|
||||
lw at, 0(r5)
|
||||
nor at, zero, at
|
||||
sw at, 0(r5)
|
||||
addiu r5, r5, 4
|
||||
addiu r4, r4, -1
|
||||
bne r4, zero, 1b
|
||||
|
||||
jr ra
|
||||
nop
|
||||
|
30
mach/mips/libem/ior.s
Normal file
30
mach/mips/libem/ior.s
Normal file
|
@ -0,0 +1,30 @@
|
|||
#
|
||||
.sect .text; .sect .rom; .sect .data; .sect .bss
|
||||
|
||||
/*
|
||||
* Set union.
|
||||
* Stack: ( a b size -- a|b )
|
||||
*/
|
||||
|
||||
.sect .text
|
||||
.define .ior
|
||||
.ior:
|
||||
lw r4, 0(sp) ! r4 = size
|
||||
addiu sp, sp, 4 ! sp points at b
|
||||
addu r5, sp, r4 ! r5 points at a
|
||||
srl r4, r4, 2 ! r4 = count of words
|
||||
|
||||
1:
|
||||
lw at, 0(r5) ! load a
|
||||
lw r6, 0(sp) ! load b
|
||||
or at, at, r6 ! combine
|
||||
sw at, 0(r5) ! write back to a
|
||||
addiu r5, r5, 4
|
||||
addiu sp, sp, 4
|
||||
addiu r4, r4, -1
|
||||
bne r4, zero, 1b
|
||||
nop
|
||||
|
||||
jr ra
|
||||
nop
|
||||
|
37
mach/mips/libem/set.s
Normal file
37
mach/mips/libem/set.s
Normal file
|
@ -0,0 +1,37 @@
|
|||
#
|
||||
.sect .text; .sect .rom; .sect .data; .sect .bss
|
||||
|
||||
/*
|
||||
* Create singleton set.
|
||||
* Stack: ( bitnumber size -- set )
|
||||
*/
|
||||
|
||||
.sect .text
|
||||
.define .set
|
||||
.set:
|
||||
lw r4, 0(sp) ! r4 = size
|
||||
lw r5, 4(sp) ! r5 = bit number
|
||||
addiu sp, sp, 4
|
||||
srl r4, r4, 2 ! r4 = word count
|
||||
|
||||
! Create an empty set.
|
||||
|
||||
1:
|
||||
addiu sp, sp, -4
|
||||
sw zero, 0(sp)
|
||||
addiu r4, r4, -1
|
||||
bne r4, zero, 1b
|
||||
|
||||
! sp now points at the set.
|
||||
|
||||
srl r6, r5, 3 ! r6 = offset of word in set
|
||||
addu r6, sp, r6 ! r6 = address of word in set
|
||||
|
||||
ext r7, r5, 0, 3 ! r7 = bit number within word
|
||||
li r8, 1
|
||||
sllv r8, r8, r7 ! r8 = word with 1 set
|
||||
sw r8, 0(r6) ! write to set
|
||||
|
||||
jr ra
|
||||
nop
|
||||
|
24
mach/mips/libem/zer.s
Normal file
24
mach/mips/libem/zer.s
Normal file
|
@ -0,0 +1,24 @@
|
|||
#
|
||||
.sect .text; .sect .rom; .sect .data; .sect .bss
|
||||
|
||||
/*
|
||||
* Create empty set.
|
||||
* Stack: ( size -- set )
|
||||
*/
|
||||
|
||||
.sect .text
|
||||
.define .zer
|
||||
.zer:
|
||||
lw r4, 0(sp) ! r4 = size
|
||||
addiu sp, sp, 4
|
||||
srl r4, r4, 2 ! r4 = word count
|
||||
|
||||
1:
|
||||
addiu sp, sp, -4
|
||||
sw zero, 0(sp)
|
||||
addiu r4, r4, -1
|
||||
bne r4, zero, 1b
|
||||
|
||||
jr ra
|
||||
nop
|
||||
|
Loading…
Reference in a new issue