aboutsummaryrefslogtreecommitdiff
path: root/system/mmx/pixel_ca_s1.s
blob: 29db6251f0b8df54eb36f6f45a2f89e6701ead77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#    Pure Data Packet mmx routine.
#    Copyright (c) by Tom Schouten <tom@zwizwa.be>
# 
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
# 
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
# 
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#

	# this file contains assembler routines for 2D 1 bit cellular automata
	# processing. it is organized around a feeder kernel and a
	# stack based bit processor (virtual forth machine)
	#
	# the feeder kernel is responsable for loading/storing CA cells
	# from/to memory. data in memory is organized as a scanline
	# encoded toroidial bitplane (lsb = left). to simplify the kernel, the top
	# left corner of the rectangular grid of pixels will shift down
	# every processing step.
	#
	# the stack machine has the following architecture:
	# CA stack:	%esi, TOS: %mm0 (32x2 pixels. lsw = top row)
	# CA horizon:	%mm4-%mm7 (64x4 pixels. %mm4 = top row)
	#
	# the stack size / organization is not known to the stack machine. 
	# it can be thought of as operating on a 3x3 cell neightbourhood.
	# the only purpose of forth program is to determine the CA local update rule.
	#
	# the machine is supposed to be very minimal. no looping control.
	# no adressing modes. no conditional code (hey, this is an experiment!)
	# so recursion is not allowed (no way to stop it)
	# there are 9 words to load the cell neigbourhood on the stack.
	# the rest is just logic and stack manips.


	# this file contains pure asm macros. it is to be included before assembly
	# after scaforth.pl has processed the .scaf file
	

	# *************************** CA CELL ACCESS MACROS *****************************
	# fetchTL - fetchBR

	# shift / load rectangle macros:

	# shift rectangle horizontal	
	# result is in reg1
	.macro shift reg1 reg2 count
	psllq $(32+\count), \reg1
	psrlq $(32-\count), \reg2
	psrlq $32, \reg1
	psllq $32, \reg2
	por \reg2, \reg1
	.endm

	.macro ldtop reg1 reg2
	movq %mm4, \reg1
	movq %mm5, \reg2
	.endm

	.macro ldcenter reg1 reg2
	movq %mm5, \reg1
	movq %mm6, \reg2
	.endm

	.macro ldbottom reg1 reg2
	movq %mm6, \reg1
	movq %mm7, \reg2
	.endm
	

	# fetch from top row

	# fetch the top left square
	.macro fetchTL
	ldtop %mm0, %mm1
	shift %mm0, %mm1, -1
	.endm

	# fetch the top mid square
	.macro fetchTM
	ldtop %mm0, %mm1
	shift %mm0, %mm1, 0
	.endm

	# fetch the top right square
	.macro fetchTR
	ldtop %mm0, %mm1
	shift %mm0, %mm1, 1
	.endm


	
	# fetch from center row

	# fetch the mid left square
	.macro fetchML
	ldcenter %mm0, %mm1
	shift %mm0, %mm1, -1
	.endm

	# fetch the mid mid square
	.macro fetchMM
	ldcenter %mm0, %mm1
	shift %mm0, %mm1, 0
	.endm

	# fetch the mid right square
	.macro fetchMR
	ldcenter %mm0, %mm1
	shift %mm0, %mm1, 1
	.endm


	

			
	# fetch from bottom row

	# fetch the bottom left square
	.macro fetchBL
	ldbottom %mm0, %mm1
	shift %mm0, %mm1, -1
	.endm

	# fetch the bottom mid square
	.macro fetchBM
	ldbottom %mm0, %mm1
	shift %mm0, %mm1, 0
	.endm

	# fetch the bottom right square
	.macro fetchBR
	ldbottom %mm0, %mm1
	shift %mm0, %mm1, 1
	.endm



	# *************************** CA STACK MANIP MACROS *****************************
	# dup drop dropdup swap nip dropover

	.macro dup
	lea -8(%esi), %esi
	movq %mm0, (%esi)	
	.endm

	.macro drop
	movq (%esi), %mm0
	lea 8(%esi), %esi
	.endm

	.macro dropdup
	movq (%esi), %mm0
	.endm

	.macro swap
	movq (%esi), %mm1
	movq %mm0, (%esi)
	movq %mm1, %mm0
	.endm

	.macro nip
	lea 8(%esi), %esi
	.endm

	.macro dropover
	movq 8(%esi), %mm0
	.endm


	# *************************** CA BOOLEAN LOGIC MACROS *****************************
	# overxor 
	
	.macro overxor
	pxor (%esi), %mm0
	.endm