Skip to content

Commit 01d0031

Browse files
committed
mandelbrot: correct wrong formula (i² == -1!)
1 parent 22df88a commit 01d0031

4 files changed

+30
-18
lines changed

formula.txt

+6-5
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ concrete:
44
x_next + i*y_next = (x + i*y)^2 + cx + i*cy
55

66
distribute square:
7-
x_next + i*y_next = x*x + i*2*xy + y*y + cx + i*cy
7+
x_next + i*y_next = x*x + i*2*xy - y*y + cx + i*cy
88

99
separate real/imaginary:
10-
x_next = x*x + y*y + cx
10+
x_next = x*x - y*y + cx
1111
y_next = 2*x*y + cy
1212

1313
pipeline
@@ -17,12 +17,13 @@ stage 1:
1717
2xy_stage1 = 2*x*y
1818

1919
stage 2:
20-
xx_plus_yy = xx_stage_1 + yy_stage1
20+
xx_plus_yy = xx_stage_1 + yy_stage1
21+
xx_minus_yy = xx_stage_1 - yy_stage1
2122
2xy_stage2 = 2xy_stage1
2223

2324
stage 3:
24-
x_next = xx_plus_yy + cx
25-
y_next = 2xy_stage2 + cy
25+
x_next = xx_minus_yy + cx
26+
y_next = 2xy_stage2 + cy
2627

2728
stage 4:
2829
x = x_next

fractalmanager_basic_test.gtkw

+17-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
[*]
22
[*] GTKWave Analyzer v3.3.111 (w)1999-2020 BSI
3-
[*] Tue Oct 12 21:54:23 2021
3+
[*] Tue Oct 12 23:08:00 2021
44
[*]
5-
[dumpfile] "test_FractalManagerTest_test_basic.vcd"
6-
[dumpfile_mtime] "Sat Oct 9 06:13:22 2021"
7-
[dumpfile_size] 40250
8-
[savefile] "fractalmanager_basic_test.gtkw"
9-
[timestart] 281600
5+
[dumpfile] "/devel/HDL/src/deca-mandelbrot/test_FractalManagerTest_test_basic.vcd"
6+
[dumpfile_mtime] "Tue Oct 12 23:01:21 2021"
7+
[dumpfile_size] 850573
8+
[savefile] "/devel/HDL/src/deca-mandelbrot/fractalmanager_basic_test.gtkw"
9+
[timestart] 0
1010
[size] 3828 2090
1111
[pos] -1 -1
12-
*-15.404525 21425000 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
12+
*-21.404526 455600 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
1313
[treeopen] top.
1414
[sst_width] 357
1515
[signals_width] 450
@@ -131,13 +131,18 @@ top.current_y[63:0]
131131
-Core0
132132
@28
133133
top.core_0.fsm_state
134-
@25
134+
@24
135135
top.core_0.iterations_out[31:0]
136136
@40000420
137137
[fpshift_count] 56
138138
top.core_0.cx_in[63:0]
139139
[fpshift_count] 56
140140
top.core_0.cy_in[63:0]
141+
@24
142+
top.pixelx_0[63:0]
143+
@25
144+
top.pixely_0[63:0]
145+
@40000420
141146
[fpshift_count] 56
142147
top.core_0.x[63:0]
143148
[fpshift_count] 56
@@ -156,6 +161,10 @@ top.core_1.iterations_out[31:0]
156161
top.core_1.cx_in[63:0]
157162
[fpshift_count] 56
158163
top.core_1.cy_in[63:0]
164+
@22
165+
top.pixelx_1[63:0]
166+
top.pixely_1[63:0]
167+
@40000420
159168
[fpshift_count] 56
160169
top.core_1.x[63:0]
161170
[fpshift_count] 56

mandelbrot.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def elaborate(self, platform: Platform) -> Module:
4848

4949
# pipeline stage 2
5050
xx_plus_yy = Signal(signed(bitwidth))
51+
xx_minus_yy = Signal(signed(bitwidth))
5152
two_xy_stage2 = Signal(signed(bitwidth))
5253

5354
# pipeline stage 3
@@ -96,12 +97,13 @@ def elaborate(self, platform: Platform) -> Module:
9697
# stage 2
9798
two_xy_stage2 .eq(two_xy_stage1),
9899
xx_plus_yy .eq(xx + yy),
100+
xx_minus_yy .eq(xx - yy),
99101
]
100102

101103
with m.If(stage_enable[2]):
102104
m.d.sync += [
103105
# stage 3
104-
x .eq(xx_plus_yy + self.cx_in),
106+
x .eq(xx_minus_yy + self.cx_in),
105107
y .eq(two_xy_stage2 + self.cy_in),
106108
escape .eq(xx_plus_yy > four),
107109
iteration .eq(iteration + 1),
@@ -163,7 +165,7 @@ def iterate_mandel(self, scale, dut, start_x, start_y, check=True):
163165
done = 0
164166
yield from self.advance_cycles(3)
165167
while done == 0:
166-
x = ((x * x) >> scale) + start_x
168+
x = ((x * x) >> scale) - ((y * y) >> scale) + start_x
167169
y = ((x * y) >> (scale - 1)) + start_y
168170
dut_x = (yield dut.x)
169171
dut_y = (yield dut.y)

mandelbrot_basic_test.gtkw

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[*]
22
[*] GTKWave Analyzer v3.3.111 (w)1999-2020 BSI
3-
[*] Sat Oct 9 05:49:48 2021
3+
[*] Wed Oct 13 00:52:29 2021
44
[*]
55
[dumpfile] "test_MandelbrotTest_test_basic.vcd"
66
[dumpfile_mtime] "Sat Oct 9 01:11:25 2021"
@@ -19,6 +19,8 @@
1919
top.clk
2020
@40000420
2121
[fpshift_count] 56
22+
top.four[63:0]
23+
[fpshift_count] 56
2224
top.cx_in[63:0]
2325
[fpshift_count] 56
2426
top.cy_in[63:0]
@@ -30,10 +32,8 @@ top.fsm_state
3032
top.busy_out
3133
[color] 3
3234
top.result_ready_out
33-
@29
3435
[color] 3
3536
top.result_read_in
36-
@28
3737
[color] 3
3838
top.result_read
3939
[color] 3

0 commit comments

Comments
 (0)