mirror of
https://github.com/italicsjenga/gba.git
synced 2025-01-11 11:31:31 +11:00
Drop the quickcheck usage
Some day we can split the software math into its own crate and do quickcheck there, until then the test code must be fully no_std because otherwise the examples won't build (sadly, dev-dependencies applies to both tests and examples)
This commit is contained in:
parent
1ff25ca2b7
commit
fdf0eebb69
|
@ -15,8 +15,9 @@ publish = false
|
||||||
typenum = "1.10"
|
typenum = "1.10"
|
||||||
gba-proc-macro = "0.2.1"
|
gba-proc-macro = "0.2.1"
|
||||||
|
|
||||||
[dev-dependencies]
|
#[dev-dependencies]
|
||||||
quickcheck="0.7"
|
#quickcheck="0.7"
|
||||||
|
# TODO: F
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
lto = true
|
lto = true
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
#[cfg(any(target_pointer_width = "16", target_pointer_width = "32", target_pointer_width = "64"))]
|
#[cfg(any(target_pointer_width = "16", target_pointer_width = "32", target_pointer_width = "64"))]
|
||||||
pub extern "C" fn __clzsi2(mut x: usize) -> usize {
|
pub extern "C" fn __clzsi2(mut x: usize) -> usize {
|
||||||
|
// TODO: const this? Requires const if
|
||||||
let mut y: usize;
|
let mut y: usize;
|
||||||
let mut n: usize = {
|
let mut n: usize = {
|
||||||
#[cfg(target_pointer_width = "64")]
|
#[cfg(target_pointer_width = "64")]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//! Things that I wish were in core, but aren't.
|
//! Things that I wish were in core, but aren't.
|
||||||
|
|
||||||
//TODO(Lokathor): reorganize as gba::core::fixed and gba::core::volatile ?
|
//TODO(Lokathor): reorganize as gba::core_extras::fixed_point and gba::core_extras::volatile ?
|
||||||
|
|
||||||
use core::{cmp::Ordering, iter::FusedIterator, marker::PhantomData, num::NonZeroUsize};
|
use core::{cmp::Ordering, iter::FusedIterator, marker::PhantomData, num::NonZeroUsize};
|
||||||
|
|
||||||
|
@ -263,12 +263,11 @@ impl<T> VolAddressBlock<T> {
|
||||||
VolAddressBlock { vol_address, slots }
|
VolAddressBlock { vol_address, slots }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Checked "indexing" style access of the block, giving either a `VolAddress` or a panic.
|
/// Gives an iterator over this block's slots.
|
||||||
pub fn index(self, slot: usize) -> VolAddress<T> {
|
pub const fn iter(self) -> VolAddressIter<T> {
|
||||||
if slot < self.slots {
|
VolAddressIter {
|
||||||
unsafe { self.vol_address.offset(slot as isize) }
|
vol_address: self.vol_address,
|
||||||
} else {
|
slots: self.slots,
|
||||||
panic!("Index Requested: {} >= Bound: {}", slot, self.slots)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -282,6 +281,15 @@ impl<T> VolAddressBlock<T> {
|
||||||
self.vol_address.offset(slot as isize)
|
self.vol_address.offset(slot as isize)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Checked "indexing" style access of the block, giving either a `VolAddress` or a panic.
|
||||||
|
pub fn index(self, slot: usize) -> VolAddress<T> {
|
||||||
|
if slot < self.slots {
|
||||||
|
unsafe { self.vol_address.offset(slot as isize) }
|
||||||
|
} else {
|
||||||
|
panic!("Index Requested: {} >= Bound: {}", slot, self.slots)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Checked "getting" style access of the block, giving an Option value.
|
/// Checked "getting" style access of the block, giving an Option value.
|
||||||
pub fn get(self, slot: usize) -> Option<VolAddress<T>> {
|
pub fn get(self, slot: usize) -> Option<VolAddress<T>> {
|
||||||
if slot < self.slots {
|
if slot < self.slots {
|
||||||
|
@ -290,12 +298,4 @@ impl<T> VolAddressBlock<T> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gives an iterator over the block's slots.
|
|
||||||
pub const fn iter(self) -> VolAddressIter<T> {
|
|
||||||
VolAddressIter {
|
|
||||||
vol_address: self.vol_address,
|
|
||||||
slots: self.slots,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,6 +73,7 @@ pub(crate) use crate::video_ram::*;
|
||||||
|
|
||||||
/// Performs unsigned divide and remainder, gives None if dividing by 0.
|
/// Performs unsigned divide and remainder, gives None if dividing by 0.
|
||||||
pub fn divrem_u32(numer: u32, denom: u32) -> Option<(u32, u32)> {
|
pub fn divrem_u32(numer: u32, denom: u32) -> Option<(u32, u32)> {
|
||||||
|
// TODO: const this? Requires const if
|
||||||
if denom == 0 {
|
if denom == 0 {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
@ -88,6 +89,7 @@ pub fn divrem_u32(numer: u32, denom: u32) -> Option<(u32, u32)> {
|
||||||
/// defined (not literal UB) including but not limited to: an infinite loop,
|
/// defined (not literal UB) including but not limited to: an infinite loop,
|
||||||
/// panic on overflow, or incorrect output.
|
/// panic on overflow, or incorrect output.
|
||||||
pub unsafe fn divrem_u32_unchecked(numer: u32, denom: u32) -> (u32, u32) {
|
pub unsafe fn divrem_u32_unchecked(numer: u32, denom: u32) -> (u32, u32) {
|
||||||
|
// TODO: const this? Requires const if
|
||||||
if (numer >> 5) < denom {
|
if (numer >> 5) < denom {
|
||||||
divrem_u32_simple(numer, denom)
|
divrem_u32_simple(numer, denom)
|
||||||
} else {
|
} else {
|
||||||
|
@ -99,6 +101,7 @@ pub unsafe fn divrem_u32_unchecked(numer: u32, denom: u32) -> (u32, u32) {
|
||||||
/// extremely slow. If N is close enough to D then it will likely be faster than
|
/// extremely slow. If N is close enough to D then it will likely be faster than
|
||||||
/// the non_restoring form.
|
/// the non_restoring form.
|
||||||
fn divrem_u32_simple(mut numer: u32, denom: u32) -> (u32, u32) {
|
fn divrem_u32_simple(mut numer: u32, denom: u32) -> (u32, u32) {
|
||||||
|
// TODO: const this? Requires const if
|
||||||
let mut quot = 0;
|
let mut quot = 0;
|
||||||
while numer >= denom {
|
while numer >= denom {
|
||||||
numer -= denom;
|
numer -= denom;
|
||||||
|
@ -110,6 +113,7 @@ fn divrem_u32_simple(mut numer: u32, denom: u32) -> (u32, u32) {
|
||||||
/// Takes a fixed quantity of time based on the bit width of the number (in this
|
/// Takes a fixed quantity of time based on the bit width of the number (in this
|
||||||
/// case 32).
|
/// case 32).
|
||||||
fn divrem_u32_non_restoring(numer: u32, denom: u32) -> (u32, u32) {
|
fn divrem_u32_non_restoring(numer: u32, denom: u32) -> (u32, u32) {
|
||||||
|
// TODO: const this? Requires const if
|
||||||
let mut r: i64 = numer as i64;
|
let mut r: i64 = numer as i64;
|
||||||
let d: i64 = (denom as i64) << 32;
|
let d: i64 = (denom as i64) << 32;
|
||||||
let mut q: u32 = 0;
|
let mut q: u32 = 0;
|
||||||
|
@ -129,6 +133,7 @@ fn divrem_u32_non_restoring(numer: u32, denom: u32) -> (u32, u32) {
|
||||||
r = r + d;
|
r = r + d;
|
||||||
}
|
}
|
||||||
r = r >> 32;
|
r = r >> 32;
|
||||||
|
// TODO: remove this once we've done more checks here.
|
||||||
debug_assert!(r >= 0);
|
debug_assert!(r >= 0);
|
||||||
debug_assert!(r <= core::u32::MAX as i64);
|
debug_assert!(r <= core::u32::MAX as i64);
|
||||||
(q, r as u32)
|
(q, r as u32)
|
||||||
|
@ -154,6 +159,7 @@ pub fn divrem_i32(numer: i32, denom: i32) -> Option<(i32, i32)> {
|
||||||
/// * If you call this with `MIN/-1` you'll get a panic in debug or just `MIN`
|
/// * If you call this with `MIN/-1` you'll get a panic in debug or just `MIN`
|
||||||
/// in release (which is incorrect), because of how twos-compliment works.
|
/// in release (which is incorrect), because of how twos-compliment works.
|
||||||
pub unsafe fn divrem_i32_unchecked(numer: i32, denom: i32) -> (i32, i32) {
|
pub unsafe fn divrem_i32_unchecked(numer: i32, denom: i32) -> (i32, i32) {
|
||||||
|
// TODO: const this? Requires const if
|
||||||
let unsigned_numer = numer.abs() as u32;
|
let unsigned_numer = numer.abs() as u32;
|
||||||
let unsigned_denom = denom.abs() as u32;
|
let unsigned_denom = denom.abs() as u32;
|
||||||
let opposite_sign = (numer ^ denom) < 0;
|
let opposite_sign = (numer ^ denom) < 0;
|
||||||
|
@ -177,6 +183,7 @@ pub unsafe fn divrem_i32_unchecked(numer: i32, denom: i32) -> (i32, i32) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -226,3 +233,4 @@ mod tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
Loading…
Reference in a new issue