Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 10 pull requests #93009

Merged
merged 32 commits into from
Jan 18, 2022
Merged
Changes from 2 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
470b49b
Clarify how to quote and respond to the target tier policy requirements
joshtriplett Nov 2, 2021
9a016ba
Clarify dependency requirements in the face of cross-compilation
joshtriplett Nov 2, 2021
1aeb3f9
Clarify documentation about running binaries
joshtriplett Nov 2, 2021
10420ef
Point to platform-support/ for target-specific documentation
joshtriplett Nov 2, 2021
f863e4c
Add a template for target-specific documentation
joshtriplett Nov 2, 2021
5ab40c8
Implement `#[rustc_must_implement_one_of]` attribute
WaffleLapkin Dec 21, 2021
e6bc0ac
Add test for misused `#[rustc_must_implement_one_of]`
WaffleLapkin Jan 3, 2022
268ae9a
Move `#[rustc_must_implement_one_of]` tests to fix tidy check
WaffleLapkin Jan 3, 2022
96b2f8a
Apply suggestions from code review
WaffleLapkin Jan 4, 2022
f64daff
Fix `#[rustc_must_implement_one_of]`
WaffleLapkin Jan 10, 2022
4ccfa97
Add a test for ungated `#[rustc_must_implement_one_of]`
WaffleLapkin Jan 11, 2022
842bf71
fix(compiler): correct minor typos in some long error code explanations
jamestiotio Jan 11, 2022
68515cb
Rename environment variable for overriding rustc version
pierwill Jan 12, 2022
606d9c0
Remove LLVMRustMarkAllFunctionsNounwind
Amanieu Jan 14, 2022
c30ec5a
Check for duplicate arguments in `#[rustc_must_implement_one_of]`
WaffleLapkin Jan 14, 2022
f9174e1
Do not use `HashSet` for `#[rustc_must_implement_one_of]`
WaffleLapkin Jan 14, 2022
28edd7a
Use `Symbol` for dup check in `#[rustc_must_implement_one_of]`
WaffleLapkin Jan 14, 2022
4d5a6c9
Enable wrapping words by default
jsha Jan 12, 2022
07fd90e
Remove `collect`
vacuus Jan 15, 2022
3dfcc66
Add `log2` and `log10` to `NonZeroU*`
scottmcm Jan 16, 2022
e0e15c9
Use `carrying_{mul|add}` in `num::bignum`
scottmcm Jan 16, 2022
9a79ab6
rustc_codegen_llvm: Remove (almost) unused span parameter from many f…
michaelwoerister Jan 10, 2022
67bcbde
Rollup merge of #90498 - joshtriplett:target-tier-policy-draft-update…
matthiaskrgr Jan 17, 2022
32d85c0
Rollup merge of #92164 - WaffleLapkin:rustc_must_implement_one_of_att…
matthiaskrgr Jan 17, 2022
97743d9
Rollup merge of #92729 - michaelwoerister:remove-unused-span-debuginf…
matthiaskrgr Jan 17, 2022
4de63e7
Rollup merge of #92752 - jamestiotio:error-codes-typos, r=nagisa
matthiaskrgr Jan 17, 2022
51aa20d
Rollup merge of #92801 - jsha:overflow-wrap, r=GuillaumeGomez
matthiaskrgr Jan 17, 2022
6acb704
Rollup merge of #92825 - pierwill:rustc-version-force-rename, r=Mark-…
matthiaskrgr Jan 17, 2022
7f02604
Rollup merge of #92877 - Amanieu:remove_llvm_nounwind, r=Mark-Simulacrum
matthiaskrgr Jan 17, 2022
25f73b7
Rollup merge of #92936 - vacuus:html-markdown-parse, r=GuillaumeGomez
matthiaskrgr Jan 17, 2022
731af70
Rollup merge of #92956 - scottmcm:nonzero-log2, r=dtolnay
matthiaskrgr Jan 17, 2022
68d47de
Rollup merge of #92960 - scottmcm:carrying-bignum, r=Mark-Simulacrum
matthiaskrgr Jan 17, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
247 changes: 123 additions & 124 deletions library/core/src/num/int_log10.rs
Original file line number Diff line number Diff line change
@@ -1,141 +1,140 @@
mod unchecked {
// 0 < val <= u8::MAX
#[inline]
pub const fn u8(val: u8) -> u32 {
let val = val as u32;

// For better performance, avoid branches by assembling the solution
// in the bits above the low 8 bits.

// Adding c1 to val gives 10 in the top bits for val < 10, 11 for val >= 10
const C1: u32 = 0b11_00000000 - 10; // 758
// Adding c2 to val gives 01 in the top bits for val < 100, 10 for val >= 100
const C2: u32 = 0b10_00000000 - 100; // 412

// Value of top bits:
// +c1 +c2 1&2
// 0..=9 10 01 00 = 0
// 10..=99 11 01 01 = 1
// 100..=255 11 10 10 = 2
((val + C1) & (val + C2)) >> 8
}
/// These functions compute the integer logarithm of their type, assuming
/// that someone has already checked that the the value is strictly positive.

// 0 < val <= u8::MAX
#[inline]
pub const fn u8(val: u8) -> u32 {
let val = val as u32;

// For better performance, avoid branches by assembling the solution
// in the bits above the low 8 bits.

// Adding c1 to val gives 10 in the top bits for val < 10, 11 for val >= 10
const C1: u32 = 0b11_00000000 - 10; // 758
// Adding c2 to val gives 01 in the top bits for val < 100, 10 for val >= 100
const C2: u32 = 0b10_00000000 - 100; // 412

// Value of top bits:
// +c1 +c2 1&2
// 0..=9 10 01 00 = 0
// 10..=99 11 01 01 = 1
// 100..=255 11 10 10 = 2
((val + C1) & (val + C2)) >> 8
}

// 0 < val < 100_000
#[inline]
const fn less_than_5(val: u32) -> u32 {
// Similar to u8, when adding one of these constants to val,
// we get two possible bit patterns above the low 17 bits,
// depending on whether val is below or above the threshold.
const C1: u32 = 0b011_00000000000000000 - 10; // 393206
const C2: u32 = 0b100_00000000000000000 - 100; // 524188
const C3: u32 = 0b111_00000000000000000 - 1000; // 916504
const C4: u32 = 0b100_00000000000000000 - 10000; // 514288

// Value of top bits:
// +c1 +c2 1&2 +c3 +c4 3&4 ^
// 0..=9 010 011 010 110 011 010 000 = 0
// 10..=99 011 011 011 110 011 010 001 = 1
// 100..=999 011 100 000 110 011 010 010 = 2
// 1000..=9999 011 100 000 111 011 011 011 = 3
// 10000..=99999 011 100 000 111 100 100 100 = 4
(((val + C1) & (val + C2)) ^ ((val + C3) & (val + C4))) >> 17
}
// 0 < val < 100_000
#[inline]
const fn less_than_5(val: u32) -> u32 {
// Similar to u8, when adding one of these constants to val,
// we get two possible bit patterns above the low 17 bits,
// depending on whether val is below or above the threshold.
const C1: u32 = 0b011_00000000000000000 - 10; // 393206
const C2: u32 = 0b100_00000000000000000 - 100; // 524188
const C3: u32 = 0b111_00000000000000000 - 1000; // 916504
const C4: u32 = 0b100_00000000000000000 - 10000; // 514288

// Value of top bits:
// +c1 +c2 1&2 +c3 +c4 3&4 ^
// 0..=9 010 011 010 110 011 010 000 = 0
// 10..=99 011 011 011 110 011 010 001 = 1
// 100..=999 011 100 000 110 011 010 010 = 2
// 1000..=9999 011 100 000 111 011 011 011 = 3
// 10000..=99999 011 100 000 111 100 100 100 = 4
(((val + C1) & (val + C2)) ^ ((val + C3) & (val + C4))) >> 17
}

// 0 < val <= u16::MAX
#[inline]
pub const fn u16(val: u16) -> u32 {
less_than_5(val as u32)
}
// 0 < val <= u16::MAX
#[inline]
pub const fn u16(val: u16) -> u32 {
less_than_5(val as u32)
}

// 0 < val <= u32::MAX
#[inline]
pub const fn u32(mut val: u32) -> u32 {
let mut log = 0;
if val >= 100_000 {
val /= 100_000;
log += 5;
}
log + less_than_5(val)
// 0 < val <= u32::MAX
#[inline]
pub const fn u32(mut val: u32) -> u32 {
let mut log = 0;
if val >= 100_000 {
val /= 100_000;
log += 5;
}
log + less_than_5(val)
}

// 0 < val <= u64::MAX
#[inline]
pub const fn u64(mut val: u64) -> u32 {
let mut log = 0;
if val >= 10_000_000_000 {
val /= 10_000_000_000;
log += 10;
}
if val >= 100_000 {
val /= 100_000;
log += 5;
}
log + less_than_5(val as u32)
// 0 < val <= u64::MAX
#[inline]
pub const fn u64(mut val: u64) -> u32 {
let mut log = 0;
if val >= 10_000_000_000 {
val /= 10_000_000_000;
log += 10;
}

// 0 < val <= u128::MAX
#[inline]
pub const fn u128(mut val: u128) -> u32 {
let mut log = 0;
if val >= 100_000_000_000_000_000_000_000_000_000_000 {
val /= 100_000_000_000_000_000_000_000_000_000_000;
log += 32;
return log + u32(val as u32);
}
if val >= 10_000_000_000_000_000 {
val /= 10_000_000_000_000_000;
log += 16;
}
log + u64(val as u64)
if val >= 100_000 {
val /= 100_000;
log += 5;
}
log + less_than_5(val as u32)
}

// 0 < val <= i8::MAX
#[inline]
pub const fn i8(val: i8) -> u32 {
u8(val as u8)
// 0 < val <= u128::MAX
#[inline]
pub const fn u128(mut val: u128) -> u32 {
let mut log = 0;
if val >= 100_000_000_000_000_000_000_000_000_000_000 {
val /= 100_000_000_000_000_000_000_000_000_000_000;
log += 32;
return log + u32(val as u32);
}

// 0 < val <= i16::MAX
#[inline]
pub const fn i16(val: i16) -> u32 {
u16(val as u16)
if val >= 10_000_000_000_000_000 {
val /= 10_000_000_000_000_000;
log += 16;
}
log + u64(val as u64)
}

// 0 < val <= i32::MAX
#[inline]
pub const fn i32(val: i32) -> u32 {
u32(val as u32)
}
#[cfg(target_pointer_width = "16")]
#[inline]
pub const fn usize(val: usize) -> u32 {
u16(val as _)
}

// 0 < val <= i64::MAX
#[inline]
pub const fn i64(val: i64) -> u32 {
u64(val as u64)
}
#[cfg(target_pointer_width = "32")]
#[inline]
pub const fn usize(val: usize) -> u32 {
u32(val as _)
}

// 0 < val <= i128::MAX
#[inline]
pub const fn i128(val: i128) -> u32 {
u128(val as u128)
}
#[cfg(target_pointer_width = "64")]
#[inline]
pub const fn usize(val: usize) -> u32 {
u64(val as _)
}

// 0 < val <= i8::MAX
#[inline]
pub const fn i8(val: i8) -> u32 {
u8(val as u8)
}

macro_rules! impl_checked {
($T:ident) => {
#[inline]
pub const fn $T(val: $T) -> Option<u32> {
if val > 0 { Some(unchecked::$T(val)) } else { None }
}
};
// 0 < val <= i16::MAX
#[inline]
pub const fn i16(val: i16) -> u32 {
u16(val as u16)
}

impl_checked! { u8 }
impl_checked! { u16 }
impl_checked! { u32 }
impl_checked! { u64 }
impl_checked! { u128 }
impl_checked! { i8 }
impl_checked! { i16 }
impl_checked! { i32 }
impl_checked! { i64 }
impl_checked! { i128 }
// 0 < val <= i32::MAX
#[inline]
pub const fn i32(val: i32) -> u32 {
u32(val as u32)
}

// 0 < val <= i64::MAX
#[inline]
pub const fn i64(val: i64) -> u32 {
u64(val as u64)
}

// 0 < val <= i128::MAX
#[inline]
pub const fn i128(val: i128) -> u32 {
u128(val as u128)
}
6 changes: 5 additions & 1 deletion library/core/src/num/int_macros.rs
Original file line number Diff line number Diff line change
@@ -2362,7 +2362,11 @@ macro_rules! int_impl {
without modifying the original"]
#[inline]
pub const fn checked_log10(self) -> Option<u32> {
int_log10::$ActualT(self as $ActualT)
if self > 0 {
Some(int_log10::$ActualT(self as $ActualT))
} else {
None
}
}

/// Computes the absolute value of `self`.
16 changes: 8 additions & 8 deletions library/core/src/num/mod.rs
Original file line number Diff line number Diff line change
@@ -264,7 +264,7 @@ const ASCII_CASE_MASK: u8 = 0b0010_0000;

#[lang = "u8"]
impl u8 {
uint_impl! { u8, u8, i8, 8, 255, 2, "0x82", "0xa", "0x12", "0x12", "0x48", "[0x12]",
uint_impl! { u8, u8, i8, NonZeroU8, 8, 255, 2, "0x82", "0xa", "0x12", "0x12", "0x48", "[0x12]",
"[0x12]", "", "" }
widening_impl! { u8, u16, 8, unsigned }

@@ -813,21 +813,21 @@ impl u8 {

#[lang = "u16"]
impl u16 {
uint_impl! { u16, u16, i16, 16, 65535, 4, "0xa003", "0x3a", "0x1234", "0x3412", "0x2c48",
uint_impl! { u16, u16, i16, NonZeroU16, 16, 65535, 4, "0xa003", "0x3a", "0x1234", "0x3412", "0x2c48",
"[0x34, 0x12]", "[0x12, 0x34]", "", "" }
widening_impl! { u16, u32, 16, unsigned }
}

#[lang = "u32"]
impl u32 {
uint_impl! { u32, u32, i32, 32, 4294967295, 8, "0x10000b3", "0xb301", "0x12345678",
uint_impl! { u32, u32, i32, NonZeroU32, 32, 4294967295, 8, "0x10000b3", "0xb301", "0x12345678",
"0x78563412", "0x1e6a2c48", "[0x78, 0x56, 0x34, 0x12]", "[0x12, 0x34, 0x56, 0x78]", "", "" }
widening_impl! { u32, u64, 32, unsigned }
}

#[lang = "u64"]
impl u64 {
uint_impl! { u64, u64, i64, 64, 18446744073709551615, 12, "0xaa00000000006e1", "0x6e10aa",
uint_impl! { u64, u64, i64, NonZeroU64, 64, 18446744073709551615, 12, "0xaa00000000006e1", "0x6e10aa",
"0x1234567890123456", "0x5634129078563412", "0x6a2c48091e6a2c48",
"[0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12]",
"[0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56]",
@@ -837,7 +837,7 @@ impl u64 {

#[lang = "u128"]
impl u128 {
uint_impl! { u128, u128, i128, 128, 340282366920938463463374607431768211455, 16,
uint_impl! { u128, u128, i128, NonZeroU128, 128, 340282366920938463463374607431768211455, 16,
"0x13f40000000000000000000000004f76", "0x4f7613f4", "0x12345678901234567890123456789012",
"0x12907856341290785634129078563412", "0x48091e6a2c48091e6a2c48091e6a2c48",
"[0x12, 0x90, 0x78, 0x56, 0x34, 0x12, 0x90, 0x78, \
@@ -850,15 +850,15 @@ impl u128 {
#[cfg(target_pointer_width = "16")]
#[lang = "usize"]
impl usize {
uint_impl! { usize, u16, isize, 16, 65535, 4, "0xa003", "0x3a", "0x1234", "0x3412", "0x2c48",
uint_impl! { usize, u16, isize, NonZeroUsize, 16, 65535, 4, "0xa003", "0x3a", "0x1234", "0x3412", "0x2c48",
"[0x34, 0x12]", "[0x12, 0x34]",
usize_isize_to_xe_bytes_doc!(), usize_isize_from_xe_bytes_doc!() }
widening_impl! { usize, u32, 16, unsigned }
}
#[cfg(target_pointer_width = "32")]
#[lang = "usize"]
impl usize {
uint_impl! { usize, u32, isize, 32, 4294967295, 8, "0x10000b3", "0xb301", "0x12345678",
uint_impl! { usize, u32, isize, NonZeroUsize, 32, 4294967295, 8, "0x10000b3", "0xb301", "0x12345678",
"0x78563412", "0x1e6a2c48", "[0x78, 0x56, 0x34, 0x12]", "[0x12, 0x34, 0x56, 0x78]",
usize_isize_to_xe_bytes_doc!(), usize_isize_from_xe_bytes_doc!() }
widening_impl! { usize, u64, 32, unsigned }
@@ -867,7 +867,7 @@ impl usize {
#[cfg(target_pointer_width = "64")]
#[lang = "usize"]
impl usize {
uint_impl! { usize, u64, isize, 64, 18446744073709551615, 12, "0xaa00000000006e1", "0x6e10aa",
uint_impl! { usize, u64, isize, NonZeroUsize, 64, 18446744073709551615, 12, "0xaa00000000006e1", "0x6e10aa",
"0x1234567890123456", "0x5634129078563412", "0x6a2c48091e6a2c48",
"[0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12]",
"[0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56]",
Loading