@@ -2048,35 +2048,43 @@ macro_rules! uint_impl {
20482048 #[ must_use = "this returns the result of the operation, \
20492049 without modifying the original"]
20502050 #[ inline]
2051+ #[ rustc_allow_const_fn_unstable( is_val_statically_known) ]
20512052 pub const fn wrapping_pow( self , mut exp: u32 ) -> Self {
20522053 let mut base = self ;
20532054
2054- // Unroll multiplications for small exponent values.
2055- // This gives the optimizer a way to efficiently inline call sites
2056- // for the most common use cases with constant exponents.
2057- // Currently, LLVM is unable to unroll the loop below.
2058- match exp {
2059- 0 => return 1 ,
2060- 1 => return base,
2061- 2 => return base. wrapping_mul( base) ,
2062- 3 => {
2063- let squared = base. wrapping_mul( base) ;
2064- return squared. wrapping_mul( base) ;
2065- }
2066- 4 => {
2067- let squared = base. wrapping_mul( base) ;
2068- return squared. wrapping_mul( squared) ;
2069- }
2070- 5 => {
2071- let squared = base. wrapping_mul( base) ;
2072- return squared. wrapping_mul( squared) . wrapping_mul( base) ;
2055+ if intrinsics:: is_val_statically_known( exp) {
2056+ // Unroll multiplications for small exponent values.
2057+ // This gives the optimizer a way to efficiently inline call sites
2058+ // for the most common use cases with constant exponents.
2059+ // Currently, LLVM is unable to unroll the loop below.
2060+ match exp {
2061+ 0 => return 1 ,
2062+ 1 => return base,
2063+ 2 => return base. wrapping_mul( base) ,
2064+ 3 => {
2065+ let squared = base. wrapping_mul( base) ;
2066+ return squared. wrapping_mul( base) ;
2067+ }
2068+ 4 => {
2069+ let squared = base. wrapping_mul( base) ;
2070+ return squared. wrapping_mul( squared) ;
2071+ }
2072+ 5 => {
2073+ let squared = base. wrapping_mul( base) ;
2074+ return squared. wrapping_mul( squared) . wrapping_mul( base) ;
2075+ }
2076+ 6 => {
2077+ let cubed = base. wrapping_mul( base) . wrapping_mul( base) ;
2078+ return cubed. wrapping_mul( cubed) ;
2079+ }
2080+ _ => { }
20732081 }
2074- 6 => {
2075- let cubed = base . wrapping_mul ( base ) . wrapping_mul ( base ) ;
2076- return cubed . wrapping_mul ( cubed ) ;
2082+ } else {
2083+ if exp == 0 {
2084+ return 1 ;
20772085 }
2078- _ => { }
20792086 }
2087+ debug_assert!( exp != 0 ) ;
20802088
20812089 let mut acc: Self = 1 ;
20822090
@@ -2568,35 +2576,43 @@ macro_rules! uint_impl {
25682576 without modifying the original"]
25692577 #[ inline]
25702578 #[ rustc_inherit_overflow_checks]
2579+ #[ rustc_allow_const_fn_unstable( is_val_statically_known) ]
25712580 pub const fn pow( self , mut exp: u32 ) -> Self {
25722581 let mut base = self ;
25732582
2574- // Unroll multiplications for small exponent values.
2575- // This gives the optimizer a way to efficiently inline call sites
2576- // for the most common use cases with constant exponents.
2577- // Currently, LLVM is unable to unroll the loop below.
2578- match exp {
2579- 0 => return 1 ,
2580- 1 => return base,
2581- 2 => return base * base,
2582- 3 => {
2583- let squared = base * base;
2584- return squared * base;
2585- }
2586- 4 => {
2587- let squared = base * base;
2588- return squared * squared;
2589- }
2590- 5 => {
2591- let squared = base * base;
2592- return squared * squared * base;
2583+ if intrinsics:: is_val_statically_known( exp) {
2584+ // Unroll multiplications for small exponent values.
2585+ // This gives the optimizer a way to efficiently inline call sites
2586+ // for the most common use cases with constant exponents.
2587+ // Currently, LLVM is unable to unroll the loop below.
2588+ match exp {
2589+ 0 => return 1 ,
2590+ 1 => return base,
2591+ 2 => return base * base,
2592+ 3 => {
2593+ let squared = base * base;
2594+ return squared * base;
2595+ }
2596+ 4 => {
2597+ let squared = base * base;
2598+ return squared * squared;
2599+ }
2600+ 5 => {
2601+ let squared = base * base;
2602+ return squared * squared * base;
2603+ }
2604+ 6 => {
2605+ let cubed = base * base * base;
2606+ return cubed * cubed;
2607+ }
2608+ _ => { }
25932609 }
2594- 6 => {
2595- let cubed = base * base * base ;
2596- return cubed * cubed ;
2610+ } else {
2611+ if exp == 0 {
2612+ return 1 ;
25972613 }
2598- _ => { }
25992614 }
2615+ debug_assert!( exp != 0 ) ;
26002616
26012617 let mut acc = 1 ;
26022618
0 commit comments