Edit PowerPC assembly for .and, .cms, .ior, .xor, .zer

Remove one addi instruction from some loops.  These loops had
increased 2 pointers, they now increase 1 index.  I must initialize
the index, so I add "li r6, 0" before each loop.

Change .zer to use subf instead of neg, add.

Change .xor to take the size on the real stack, as .and and .or have
done since 81c677d.
This commit is contained in:
George Koehler 2017-02-11 18:00:56 -05:00
parent 13beb5e336
commit c578c495bb
6 changed files with 59 additions and 64 deletions

View file

@ -5,20 +5,18 @@
.define .and .define .and
.and: .and:
lwz r3, 0 (sp) ! r3 = size lwz r3, 0(sp) ! r3 = size
addi sp, sp, 4 srwi r7, r3, 2
mtspr ctr, r7 ! ctr = size / 4
mr r4, sp ! r4 = ptr to set a addi r4, sp, 4 ! r4 = ptr to set a
add r5, sp, r3 ! r5 = ptr to set b add r5, r4, r3 ! r5 = ptr to set b
srwi r6, r3, 2 li r6, 0 ! r6 = index
mtspr ctr, r6 ! ctr = r3 / 4
1: 1:
lwz r7, 0(r4) lwzx r7, r4, r6
lwz r8, 0(r5) lwzx r8, r5, r6
and r8, r7, r8 ! intersection of words and r8, r7, r8 ! intersection of words
stw r8, 0(r5) stwx r8, r5, r6
addi r4, r4, 4 addi r6, r6, 4
addi r5, r5, 4
bdnz 1b ! loop ctr times bdnz 1b ! loop ctr times
add sp, sp, r3 mr sp, r5
blr blr

View file

@ -7,24 +7,23 @@
.define .cms .define .cms
.cms: .cms:
srwi r7, r3, 2
mtspr ctr, r7 ! ctr = size / 4
mr r4, sp ! r4 = ptr to set a mr r4, sp ! r4 = ptr to set a
add r5, sp, r3 ! r5 = ptr to set b add r5, sp, r3 ! r5 = ptr to set b
mr r6, r3 ! r6 = size li r6, 0 ! r6 = index
srwi r3, r3, 2 add r9, r5, r3 ! r9 = future sp
mtspr ctr, r3 ! ctr = size / 4
1: 1:
lwz r7, 0(r4) lwzx r7, r4, r6
lwz r8, 0(r5) lwzx r8, r5, r6
cmpw cr0, r7, r8 ! compare words in sets cmpw cr0, r7, r8 ! compare words in sets
addi r4, r4, 4 addi r6, r6, 4
addi r5, r5, 4
bne cr0, 2f ! branch if not equal bne cr0, 2f ! branch if not equal
bdnz 1b ! loop ctr times bdnz 1b ! loop ctr times
addi r3, r0, 0 ! equal: return 0 li r3, 0 ! equal: return 0
b 3f b 3f
2: 2:
addi r3, r0, 1 ! not equal: return 1 li r3, 1 ! not equal: return 1
3: 3:
slwi r6, r6, 1 ! r6 = size * 2 mr sp, r9 ! remove sets from stack
add sp, sp, r6 ! remove sets from stack
blr blr

View file

@ -5,20 +5,18 @@
.define .ior .define .ior
.ior: .ior:
lwz r3, 0 (sp) lwz r3, 0(sp) ! r3 = size
addi sp, sp, 4 srwi r7, r3, 2
mtspr ctr, r7 ! ctr = size / 4
mr r4, sp ! r4 = ptr to set a addi r4, sp, 4 ! r4 = ptr to set a
add r5, sp, r3 ! r5 = ptr to set b add r5, r4, r3 ! r5 = ptr to set b
srwi r6, r3, 2 li r6, 0 ! r6 = index
mtspr ctr, r6 ! ctr = r3 / 4
1: 1:
lwz r7, 0(r4) lwzx r7, r4, r6
lwz r8, 0(r5) lwzx r8, r5, r6
or r8, r7, r8 ! union of words or r8, r7, r8 ! union of words
stw r8, 0(r5) stwx r8, r5, r6
addi r4, r4, 4 addi r6, r6, 4
addi r5, r5, 4
bdnz 1b ! loop ctr times bdnz 1b ! loop ctr times
add sp, sp, r3 mr sp, r5
blr blr

View file

@ -1,22 +1,22 @@
.sect .text .sect .text
! Set symmetric difference. ! Set symmetric difference.
! Stack: ( b a -- a/b ) ! Stack: ( b a size -- a/b )
! With r3 = size of set
.define .xor .define .xor
.xor: .xor:
mr r4, sp ! r4 = ptr to set a lwz r3, 0(sp) ! r3 = size
add r5, sp, r3 ! r5 = ptr to set b srwi r7, r3, 2
srwi r6, r3, 2 mtspr ctr, r7 ! ctr = size / 4
mtspr ctr, r6 ! ctr = r3 / 4 addi r4, sp, 4 ! r4 = ptr to set a
add r5, r4, r3 ! r5 = ptr to set b
li r6, 0 ! r6 = index
1: 1:
lwz r7, 0(r4) lwzx r7, r4, r6
lwz r8, 0(r5) lwzx r8, r5, r6
xor r8, r7, r8 ! symmetric difference of words xor r8, r7, r8 ! symmetric difference of words
stw r8, 0(r5) stwx r8, r5, r6
addi r4, r4, 4 addi r6, r6, 4
addi r5, r5, 4
bdnz 1b ! loop ctr times bdnz 1b ! loop ctr times
add sp, sp, r3 mr sp, r5
blr blr

View file

@ -5,17 +5,15 @@
.define .zer .define .zer
.zer: .zer:
lwz r3, 0(sp) lwz r3, 0(sp) ! r3 = size
srwi r5, r3, 2
mtspr ctr, r5 ! ctr = word size - 4
li r4, 0 ! r4 = 0
addi sp, sp, 4 addi sp, sp, 4
subf sp, r3, sp ! sp = ptr to new set
srwi r7, r3, 2 li r6, 0 ! r6 = index
li r4, 0 ! r4 = zero
neg r5, r3
add sp, sp, r5 ! allocate set
mr r6, sp ! r6 = ptr to set
mtspr ctr, r7 ! ctr = r3 / 4
1: 1:
stw r4, 0(r6) ! store zero in set stwx r4, sp, r6 ! store zero in set
addi r6, r6, 4 addi r6, r6, 4
bdnz 1b ! loop ctr times bdnz 1b ! loop ctr times
blr blr

View file

@ -1374,11 +1374,13 @@ PATTERNS
yields {XOR_RC, %2, lo(%1.val)} yields {XOR_RC, %2, lo(%1.val)}
pat xor defined($1) /* XOR set */ pat xor defined($1) /* XOR set */
with STACK leaving
kills ALL loc $1
gen cal ".xor"
move {CONST, $1}, R3
bl {LABEL, ".xor"} pat xor !defined($1)
leaving
cal ".xor"
pat com $1==INT32 /* NOT word */ pat com $1==INT32 /* NOT word */
with AND_RR with AND_RR