Skip to content

Commit

Permalink
Merge #328
Browse files Browse the repository at this point in the history
328: Prevent underflow when calling delay(n) with n<2 r=jonas-schievink a=ovidiusabou

Calling delay(1) causes a very long wait (freeze) otherwise.
86cd463 introduced this behaviour by
changing the cycle count from n / 4 + 1 to n / 2 which forces an
underflow when n<2.

Co-authored-by: Ovidiu Sabou <ovidiu@sabou.org>
Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
  • Loading branch information
3 people authored Feb 9, 2021
2 parents c714cdf + fdc3ab0 commit 2281fd6
Show file tree
Hide file tree
Showing 15 changed files with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion asm/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ pub unsafe fn __delay(cyc: u32) {
// The loop will normally take 3 to 4 CPU cycles per iteration, but superscalar cores
// (eg. Cortex-M7) can potentially do it in 2, so we use that as the lower bound, since delaying
// for more cycles is okay.
let real_cyc = cyc / 2;
// Add 1 to prevent an integer underflow which would cause a long freeze
let real_cyc = 1 + cyc / 2;
asm!(
// Use local labels to avoid R_ARM_THM_JUMP8 relocations which fail on thumbv6m.
"1:",
Expand Down
Binary file modified bin/thumbv6m-none-eabi-lto.a
Binary file not shown.
Binary file modified bin/thumbv6m-none-eabi.a
Binary file not shown.
Binary file modified bin/thumbv7em-none-eabi-lto.a
Binary file not shown.
Binary file modified bin/thumbv7em-none-eabi.a
Binary file not shown.
Binary file modified bin/thumbv7em-none-eabihf-lto.a
Binary file not shown.
Binary file modified bin/thumbv7em-none-eabihf.a
Binary file not shown.
Binary file modified bin/thumbv7m-none-eabi-lto.a
Binary file not shown.
Binary file modified bin/thumbv7m-none-eabi.a
Binary file not shown.
Binary file modified bin/thumbv8m.base-none-eabi-lto.a
Binary file not shown.
Binary file modified bin/thumbv8m.base-none-eabi.a
Binary file not shown.
Binary file modified bin/thumbv8m.main-none-eabi-lto.a
Binary file not shown.
Binary file modified bin/thumbv8m.main-none-eabi.a
Binary file not shown.
Binary file modified bin/thumbv8m.main-none-eabihf-lto.a
Binary file not shown.
Binary file modified bin/thumbv8m.main-none-eabihf.a
Binary file not shown.

0 comments on commit 2281fd6

Please sign in to comment.