// This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. #![allow(overflowing_literals)] /// FFFFFF00/8000 /// 00100 FF000000 /// 01010 7F00FFFF #[test] fn divs() { let dst: i32 = 0xFFFF_FF00; let src: i32 = 0xFFFF_8000; let mut value = dst as i32 as u64; for _ in 0..32 { value <<= 1; let a = (value >> 32) as i32; let (res, v) = a.overflowing_sub(src); if v { continue; } value = (res as u64) << 32 | value as u32 as u64; value |= !v as u64; } let quot = value as u32; let rem = (value >> 32) as u32; println!("divs {:#X} {:#X} {quot:#X} {rem:#X}", dst / src, dst % src); } #[test] fn divu() { // let dst: u32 = 1729; // let src: u32 = 10; let dst: u32 = 0x7FFF_FFFF; let src: u32 = 0x8000; let mut value = dst as u64; for _ in 0..32 { value <<= 1; let a = (value >> 32) as u32; let (res, v) = a.overflowing_sub(src); if v { continue; } value = (res as u64) << 32 | value as u32 as u64; value |= !v as u64; } let quot = value as u32; let rem = (value >> 32) as u32; println!("divu {:#X} {:#X} {quot:#X} {rem:#X}", dst / src, dst % src); }