diff options
| author | Huon Wilson <dbau.pp+github@gmail.com> | 2014-04-14 20:04:14 +1000 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-04-15 19:45:00 -0700 |
| commit | 54ec04f1c12c7fb4dbe5f01fdeb73d1079fef53d (patch) | |
| tree | efe91e930ac4527e3057fe65571df112ef5b8607 /src/libstd/num | |
| parent | 93dc55518840ee3cbd570c0d85aa7a445752af8b (diff) | |
| download | rust-54ec04f1c12c7fb4dbe5f01fdeb73d1079fef53d.tar.gz rust-54ec04f1c12c7fb4dbe5f01fdeb73d1079fef53d.zip | |
Use the unsigned integer types for bitwise intrinsics.
Exposing ctpop, ctlz, cttz and bswap as taking signed i8/i16/... is just exposing the internal LLVM names pointlessly (LLVM doesn't have "signed integers" or "unsigned integers", it just has sized integer types with (un)signed *operations*). These operations are semantically working with raw bytes, which the unsigned types model better.
Diffstat (limited to 'src/libstd/num')
| -rw-r--r-- | src/libstd/num/i16.rs | 6 | ||||
| -rw-r--r-- | src/libstd/num/i32.rs | 6 | ||||
| -rw-r--r-- | src/libstd/num/i64.rs | 6 | ||||
| -rw-r--r-- | src/libstd/num/i8.rs | 6 |
4 files changed, 12 insertions, 12 deletions
diff --git a/src/libstd/num/i16.rs b/src/libstd/num/i16.rs index 42710a8b459..79827421f92 100644 --- a/src/libstd/num/i16.rs +++ b/src/libstd/num/i16.rs @@ -28,17 +28,17 @@ int_module!(i16, 16) impl Bitwise for i16 { /// Returns the number of ones in the binary representation of the number. #[inline] - fn count_ones(&self) -> i16 { unsafe { intrinsics::ctpop16(*self) } } + fn count_ones(&self) -> i16 { unsafe { intrinsics::ctpop16(*self as u16) as i16 } } /// Returns the number of leading zeros in the in the binary representation /// of the number. #[inline] - fn leading_zeros(&self) -> i16 { unsafe { intrinsics::ctlz16(*self) } } + fn leading_zeros(&self) -> i16 { unsafe { intrinsics::ctlz16(*self as u16) as i16 } } /// Returns the number of trailing zeros in the in the binary representation /// of the number. #[inline] - fn trailing_zeros(&self) -> i16 { unsafe { intrinsics::cttz16(*self) } } + fn trailing_zeros(&self) -> i16 { unsafe { intrinsics::cttz16(*self as u16) as i16 } } } impl CheckedAdd for i16 { diff --git a/src/libstd/num/i32.rs b/src/libstd/num/i32.rs index 69d4b0639f7..97f03299b87 100644 --- a/src/libstd/num/i32.rs +++ b/src/libstd/num/i32.rs @@ -28,17 +28,17 @@ int_module!(i32, 32) impl Bitwise for i32 { /// Returns the number of ones in the binary representation of the number. #[inline] - fn count_ones(&self) -> i32 { unsafe { intrinsics::ctpop32(*self) } } + fn count_ones(&self) -> i32 { unsafe { intrinsics::ctpop32(*self as u32) as i32 } } /// Returns the number of leading zeros in the in the binary representation /// of the number. #[inline] - fn leading_zeros(&self) -> i32 { unsafe { intrinsics::ctlz32(*self) } } + fn leading_zeros(&self) -> i32 { unsafe { intrinsics::ctlz32(*self as u32) as i32 } } /// Returns the number of trailing zeros in the in the binary representation /// of the number. #[inline] - fn trailing_zeros(&self) -> i32 { unsafe { intrinsics::cttz32(*self) } } + fn trailing_zeros(&self) -> i32 { unsafe { intrinsics::cttz32(*self as u32) as i32 } } } impl CheckedAdd for i32 { diff --git a/src/libstd/num/i64.rs b/src/libstd/num/i64.rs index 1f7066c25db..00823aa22c2 100644 --- a/src/libstd/num/i64.rs +++ b/src/libstd/num/i64.rs @@ -30,16 +30,16 @@ int_module!(i64, 64) impl Bitwise for i64 { /// Returns the number of ones in the binary representation of the number. #[inline] - fn count_ones(&self) -> i64 { unsafe { intrinsics::ctpop64(*self) } } + fn count_ones(&self) -> i64 { unsafe { intrinsics::ctpop64(*self as u64) as i64 } } /// Returns the number of leading zeros in the in the binary representation /// of the number. #[inline] - fn leading_zeros(&self) -> i64 { unsafe { intrinsics::ctlz64(*self) } } + fn leading_zeros(&self) -> i64 { unsafe { intrinsics::ctlz64(*self as u64) as i64 } } /// Counts the number of trailing zeros. #[inline] - fn trailing_zeros(&self) -> i64 { unsafe { intrinsics::cttz64(*self) } } + fn trailing_zeros(&self) -> i64 { unsafe { intrinsics::cttz64(*self as u64) as i64 } } } impl CheckedAdd for i64 { diff --git a/src/libstd/num/i8.rs b/src/libstd/num/i8.rs index 061ffddf231..2d349fa7f4f 100644 --- a/src/libstd/num/i8.rs +++ b/src/libstd/num/i8.rs @@ -28,17 +28,17 @@ int_module!(i8, 8) impl Bitwise for i8 { /// Returns the number of ones in the binary representation of the number. #[inline] - fn count_ones(&self) -> i8 { unsafe { intrinsics::ctpop8(*self) } } + fn count_ones(&self) -> i8 { unsafe { intrinsics::ctpop8(*self as u8) as i8 } } /// Returns the number of leading zeros in the in the binary representation /// of the number. #[inline] - fn leading_zeros(&self) -> i8 { unsafe { intrinsics::ctlz8(*self) } } + fn leading_zeros(&self) -> i8 { unsafe { intrinsics::ctlz8(*self as u8) as i8 } } /// Returns the number of trailing zeros in the in the binary representation /// of the number. #[inline] - fn trailing_zeros(&self) -> i8 { unsafe { intrinsics::cttz8(*self) } } + fn trailing_zeros(&self) -> i8 { unsafe { intrinsics::cttz8(*self as u8) as i8 } } } impl CheckedAdd for i8 { |
