Skip to content
Permalink
Browse files

Fix Cortex-M4 build for conway, rotozoom, tunnel.

My portability refactoring broke the microcontroller demos. :-)

Problems:

1. In both conway and rotozoom, I "refactored" the call to
   vga.video_on() into...nothing.

2. In conway and tunnel, I changed code from using references to
   fixed-size arrays, into code using slices. This produced a bunch of
   bounds checks, which dropped us to 30fps in both cases. I have
   hoisted the bounds checks to the top of each render routine.
  • Loading branch information...
cbiffle committed Jun 2, 2019
1 parent aeaed02 commit 2c2fede34ea236f091d8e1a5a268b69f55e19102
Showing with 21 additions and 1 deletion.
  1. +3 −0 fx/conway/src/conway.rs
  2. +15 −0 fx/tunnel/src/render.rs
  3. +1 −0 m4demos/src/bin/conway.rs
  4. +2 −1 m4demos/src/bin/rotozoom.rs
@@ -75,6 +75,9 @@ const HEIGHT: usize = 600;
/// state.
/// - next_map is a framebuffer (bitmap) that will be filled in.
pub fn step(current_map: &Buffer, next_map: &mut Buffer) {
let current_map = &current_map[..WIDTH * HEIGHT];
let next_map = &mut next_map[..WIDTH * HEIGHT];

// We keep sliding windows of state in these arrays.
let mut above = [0; 3];
let mut current = [0; 3];
@@ -7,6 +7,21 @@ pub fn render(table: &table::Table, fb: &mut [u8], frame: usize) {

let frame = frame as f32;

// Hey look, it's a rare case where I have to optimize bounds checking!
// This routine originally operated upon a fixed-length array, ensuring that
// bounds checking for predictable indices (like those generated in the loop
// below) got compiled out. I switched it to a dynamic slice during the
// portability sprint...and lost 30fps on the microcontroller.
//
// Why?
//
// Because I had asked it to be slower. Well, not in so few words, but: each
// index into `fb` below is a bounds-check. The algorithm as written says
// "get as much of this done as you can, until you panic at the end of fb."
// That isn't useful, or what I intended, so the following line moves the
// bounds check to the top of the loop. Back to 60fps.
let fb = &mut fb[..super::BUFFER_WORDS * 4];

// The distance we have traveled into the tunnel.
let z = frame * DSPEED;
// The angle of the tunnel's rotation.
@@ -63,6 +63,7 @@ fn main() -> ! {
vga.sync_to_vblank();
render.render_frame(frame, thread);
frame += 1;
vga.video_on();
}
},
)
@@ -56,9 +56,10 @@ fn main() -> ! {
let thread = priority::Thread::new_checked().unwrap();

loop {
vga.sync_to_vblank();
render.render_frame(frame, thread);
vga.sync_to_vblank();
frame += 1;
vga.video_on();
}
},
)

0 comments on commit 2c2fede

Please sign in to comment.
You can’t perform that action at this time.