-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
compiler-rt: alu: add signed remainder for i8
Implement the following polyfill: - `__llvm_srem_i8_i8` The implementation is done by extending the existing sdiv implementation by the calculation of a remainder and then using that division-with-reminder calculation for both `__llvm_srem_i8_i8` and `__llvm_sdiv_i8_i8` to avoid code duplication. Signed-off-by: Wojciech Zmuda <[email protected]>
- Loading branch information
Showing
5 changed files
with
363 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,5 +25,6 @@ pub mod smul_with_overflow; | |
pub mod udiv; | ||
pub mod sdiv; | ||
pub mod urem; | ||
pub mod srem; | ||
|
||
mod test_case; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
pub mod srem_i8; | ||
|
||
use core::num::traits::{BitSize, Bounded}; | ||
use crate::alu::sdiv::divide_with_remainder_signed; | ||
|
||
// Perform the `srem` operation. | ||
// | ||
// This is a generic implementation for every data type. Its specialized versions | ||
// are defined and tested in the srem/srem_<type>.cairo files. | ||
fn srem< | ||
T, | ||
// The trait bounds are chosen so that: | ||
// | ||
// - BitSize<T>: we can determine the length of the data type in bits, | ||
// - Bounded<T>: we can determine min and max value of the type, | ||
// - TryInto<u128, T>, Into<T, u128> - we can convert the type from/to u128, | ||
// - Destruct<T>: the type can be dropped as the result of the downcasting check. | ||
// | ||
// Overall these trait bounds allow any unsigned integer to be used as the concrete type. | ||
impl TBitSize: BitSize<T>, | ||
impl TBounded: Bounded<T>, | ||
impl TTryInto: TryInto<u128, T>, | ||
impl TInto: Into<T, u128>, | ||
impl TDestruct: Destruct<T>, | ||
>( | ||
lhs: u128, rhs: u128, | ||
) -> u128 { | ||
let (_, remainder) = divide_with_remainder_signed::<T>(lhs, rhs); | ||
remainder | ||
} |
Oops, something went wrong.