Merge pull request #28 from kernigh/pr-set-ppc

add Modula-2 set operations to PowerPC ncg
This commit is contained in:
David Given 2016-12-11 22:25:04 +01:00 committed by GitHub
commit 65fdb03231
9 changed files with 410 additions and 210 deletions

24
mach/powerpc/libem/and.s Normal file
View file

@ -0,0 +1,24 @@
#include "powerpc.h"
.sect .text
! Set intersection.
! Stack: ( b a -- a*b )
! With r3 = size of set
.define .and
.and:
mr r4, sp ! r4 = ptr to set a
add r5, sp, r3 ! r5 = ptr to set b
rlwinm r6, r3, 30, 2, 31
mtspr ctr, r6 ! ctr = r3 / 4
1:
lwz r7, 0(r4)
lwz r8, 0(r5)
and r8, r7, r8 ! intersection of words
stw r8, 0(r5)
addi r4, r4, 4
addi r5, r5, 4
bc DNZ, 0, 1b ! loop ctr times
add sp, sp, r3
bclr ALWAYS, 0, 0

View file

@ -7,7 +7,7 @@ for _, plat in ipairs(vars.plats) do
acklibrary {
name = "lib_"..plat,
srcs = {
"./*.s",
"./*.s", -- zer.s
"./*.e",
},
vars = { plat = plat },

32
mach/powerpc/libem/cms.s Normal file
View file

@ -0,0 +1,32 @@
#include "powerpc.h"
.sect .text
! Compare sets a, b.
! Stack: ( b a -- )
! With r3 = size of each set
! Yields r3 = 0 if equal, nonzero if not equal
.define .cms
.cms:
mr r4, sp ! r4 = ptr to set a
add r5, sp, r3 ! r5 = ptr to set b
mr r6, r3 ! r6 = size
rlwinm r3, r3, 30, 2, 31
mtspr ctr, r3 ! ctr = size / 4
1:
lwz r7, 0(r4)
lwz r8, 0(r5)
cmp cr0, 0, r7, r8 ! compare words in sets
addi r4, r4, 4
addi r5, r5, 4
bc IFFALSE, EQ, 2f ! branch if not equal
bc DNZ, 0, 1b ! loop ctr times
addi r3, r0, 0 ! equal: return 0
b 3f
2:
addi r3, r0, 1 ! not equal: return 1
3:
rlwinm r6, r6, 1, 0, 30 ! r6 = size * 2
add sp, sp, r6 ! remove sets from stack
bclr ALWAYS, 0, 0

20
mach/powerpc/libem/com.s Normal file
View file

@ -0,0 +1,20 @@
#include "powerpc.h"
.sect .text
! Set complement.
! Stack: ( a -- ~a )
! With r3 = size of set
.define .com
.com:
mr r4, sp ! r4 = pointer to set a
rlwinm r5, r3, 30, 2, 31
mtspr ctr, r5 ! ctr = r3 / 4
1:
lwz r6, 0(r4)
nor r6, r6, r6 ! complement of word
stw r6, 0(r4)
addi r4, r4, 4
bc DNZ, 0, 1b ! loop ctr times
bclr ALWAYS, 0, 0

24
mach/powerpc/libem/ior.s Normal file
View file

@ -0,0 +1,24 @@
#include "powerpc.h"
.sect .text
! Set union.
! Stack: ( b a -- a+b )
! With r3 = size of set
.define .ior
.ior:
mr r4, sp ! r4 = ptr to set a
add r5, sp, r3 ! r5 = ptr to set b
rlwinm r6, r3, 30, 2, 31
mtspr ctr, r6 ! ctr = r3 / 4
1:
lwz r7, 0(r4)
lwz r8, 0(r5)
or r8, r7, r8 ! union of words
stw r8, 0(r5)
addi r4, r4, 4
addi r5, r5, 4
bc DNZ, 0, 1b ! loop ctr times
add sp, sp, r3
bclr ALWAYS, 0, 0

29
mach/powerpc/libem/set.s Normal file
View file

@ -0,0 +1,29 @@
#include "powerpc.h"
.sect .text
! Create singleton set.
! Stack: ( -- set )
! With r3 = size of set, r4 = bit number
.define .set
.set:
rlwinm r7, r3, 30, 2, 31
neg r5, r3
add sp, sp, r5 ! allocate set
mr r6, sp ! r6 = ptr to set
mtspr ctr, r7 ! ctr = r3 / 4
1:
rlwinm. r7, r4, 0, 0, 26 ! r7 = r4 & ~31
bc IFTRUE, EQ, 2f ! branch if r4 in 0..31
addi r5, r0, 0 ! no bit, word is zero
b 3f
2:
addi r5, r0, 1
slw r5, r5, r4 ! yes bit, set bit in word
3:
stw r5, 0(r6) ! store word in set
addi r4, r4, -32
addi r6, r6, 4
bc DNZ, 0, 1b ! loop ctr times
bclr ALWAYS, 0, 0

24
mach/powerpc/libem/xor.s Normal file
View file

@ -0,0 +1,24 @@
#include "powerpc.h"
.sect .text
! Set symmetric difference.
! Stack: ( b a -- a/b )
! With r3 = size of set
.define .xor
.xor:
mr r4, sp ! r4 = ptr to set a
add r5, sp, r3 ! r5 = ptr to set b
rlwinm r6, r3, 30, 2, 31
mtspr ctr, r6 ! ctr = r3 / 4
1:
lwz r7, 0(r4)
lwz r8, 0(r5)
xor r8, r7, r8 ! symmetric difference of words
stw r8, 0(r5)
addi r4, r4, 4
addi r5, r5, 4
bc DNZ, 0, 1b ! loop ctr times
add sp, sp, r3
bclr ALWAYS, 0, 0

21
mach/powerpc/libem/zer.s Normal file
View file

@ -0,0 +1,21 @@
#include "powerpc.h"
.sect .text
! Create empty set.
! Stack: ( -- set )
! With r3 = size of set
.define .zer
.zer:
rlwinm r7, r3, 30, 2, 31
addi r4, r0, 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:
stw r4, 0(r6) ! store zero in set
addi r6, r6, 4
bc DNZ, 0, 1b ! loop ctr times
bclr ALWAYS, 0, 0

View file

@ -10,7 +10,7 @@ INT64 = 8
FP_OFFSET = 0 /* Offset of saved FP relative to our FP */
PC_OFFSET = 4 /* Offset of saved PC relative to our FP */
#define COMMENT(n) /* noop */
#define COMMENT(n) /* comment {LABEL, n} */
#define nicesize(x) ((x)==INT8 || (x)==INT16 || (x)==INT32 || (x)==INT64)
@ -389,7 +389,7 @@ MOVES
/* Constants */
from CONST_ALL smalls(%val) to GPR
from CONST_ALL + CONST smalls(%val) to GPR
gen
COMMENT("move CONST_ALL->GPR smalls")
addi %2, R0, {CONST, %1.val}
@ -1160,7 +1160,7 @@ PATTERNS
loc $1
los INT32
pat los /* Load arbitrary size */
pat los $1==INT32 /* Load arbitrary size */
with GPR3 GPR4 STACK
kills ALL
gen
@ -1283,7 +1283,7 @@ PATTERNS
loc $1
sts INT32
pat sts /* Store arbitrary size */
pat sts $1==INT32 /* Store arbitrary size */
with GPR3 GPR4 STACK
kills ALL
gen
@ -1463,9 +1463,11 @@ PATTERNS
andisX %a, %2, {CONST, hi(%1.val)}
yields %a
pat and !defined($1) /* AND set */
pat and defined($1) /* AND set */
with STACK
kills ALL
gen
move {CONST, $1}, R3
bl {LABEL, ".and"}
pat ior $1==4 /* OR word */
@ -1498,8 +1500,17 @@ PATTERNS
uses reusing %2, REG={OR_RIS, %2, hi(%1.val)}
yields {OR_RC, %2, lo(%1.val)}
pat ior !defined($1) /* OR set */
pat ior defined($1) /* OR set */
with STACK
kills ALL
gen
move {CONST, $1}, R3
bl {LABEL, ".ior"}
/* OR set (variable), used in lang/m2/libm2/LtoUset.e */
pat ior !defined($1)
with GPR3 STACK
kills ALL
gen
bl {LABEL, ".ior"}
@ -1523,9 +1534,11 @@ PATTERNS
uses reusing %2, REG={XOR_RIS, %2, hi(%1.val)}
yields {XOR_RC, %2, lo(%1.val)}
pat xor !defined($1) /* XOR set */
pat xor defined($1) /* XOR set */
with STACK
kills ALL
gen
move {CONST, $1}, R3
bl {LABEL, ".xor"}
pat com $1==INT32 /* NOT word */
@ -1547,11 +1560,23 @@ PATTERNS
with GPR
yields {NOT_R, %1}
pat com !defined($1) /* NOT set */
pat com defined($1) /* NOT set */
with STACK
gen
move {CONST, $1}, R3
bl {LABEL, ".com"}
pat zer $1==4 /* Push zero */
leaving
loc 0
pat zer defined($1) /* Create empty set */
with STACK
kills ALL
gen
move {CONST, $1}, R3
bl {LABEL, ".zer"}
pat sli $1==4 /* Shift left (second << top) */
with CONST_ALL GPR
uses reusing %2, REG
@ -1594,6 +1619,7 @@ PATTERNS
pat aar $1==INT32 /* Index array */
with GPR3 GPR4 GPR5
kills ALL
gen
bl {LABEL, ".aar4"}
yields R3
@ -1624,21 +1650,23 @@ PATTERNS
/* Sets */
pat set defined($1) /* Create word with set bit */
leaving
loc 1
exg INT32
sli INT32
pat set defined($1) /* Create singleton set */
with GPR4 STACK
kills ALL
gen
move {CONST, $1}, R3
bl {LABEL, ".set"}
pat set !defined($1) /* Create structure with set bit (variable) */
/* Create set (variable), used in lang/m2/libm2/LtoUset.e */
pat set !defined($1)
with GPR3 GPR4 STACK
kills ALL
gen
bl {LABEL, ".set"}
pat inn /* Test for set bit */
pat inn defined($1) /* Test for set bit */
with STACK
kills ALL
uses REG
@ -1648,7 +1676,6 @@ PATTERNS
bl {LABEL, ".inn"}
/* Boolean resolutions */
pat teq /* top = (top == 0) */
@ -1785,13 +1812,13 @@ PATTERNS
/* Compare and jump */
pat cmi /* Signed tristate compare */
pat cmi $1==INT32 /* Signed tristate compare */
with CONST_ALL GPR
yields {TRISTATE_RC_S, %2, %1.val}
with GPR GPR
yields {TRISTATE_RR_S, %2, %1}
pat cmu /* Unsigned tristate compare */
pat cmu $1==INT32 /* Unsigned tristate compare */
with CONST_ALL GPR
yields {TRISTATE_RC_U, %2, %1.val}
with GPR GPR
@ -1805,6 +1832,13 @@ PATTERNS
leaving
cmi INT32
pat cms defined($1)
with STACK
kills ALL
gen
move {CONST, $1}, R3
bl {LABEL, ".cms"}
yields R3
@ -1993,10 +2027,6 @@ PATTERNS
move SP, %a
yields %a
pat lor $1==2 /* Load HP */
leaving
loe ".reghp"
pat str $1==0 /* Store FP */
with GPR
gen
@ -2007,18 +2037,14 @@ PATTERNS
gen
move %1, SP
pat str $1==2 /* Store HP */
leaving
ste ".reghp"
pat loc ass $1==4 /* Drop 4 bytes from stack */
pat loc ass $1==4 && $2==4 /* Drop 4 bytes from stack */
with exact GPR
/* nop */
with STACK
gen
addi SP, SP, {CONST, 4}
pat ass /* Adjust stack by variable amount */
pat ass $1==4 /* Adjust stack by variable amount */
with CONST2 STACK
gen
move {SUM_RC, SP, %1.val}, SP
@ -2036,7 +2062,7 @@ PATTERNS
pat asp /* Adjust stack by constant amount */
leaving
loc $1
ass
ass 4