V8 Project
v8::base::internal Namespace Reference

Classes

struct  MaxExponent
 
struct  StaticDstRangeRelationToSrcRange
 
struct  StaticDstRangeRelationToSrcRange< Dst, Src, Sign, Sign >
 
struct  StaticDstRangeRelationToSrcRange< Dst, Src, INTEGER_REPRESENTATION_SIGNED, INTEGER_REPRESENTATION_UNSIGNED >
 
struct  StaticDstRangeRelationToSrcRange< Dst, Src, INTEGER_REPRESENTATION_UNSIGNED, INTEGER_REPRESENTATION_SIGNED >
 
struct  DstRangeRelationToSrcRangeImpl
 
struct  DstRangeRelationToSrcRangeImpl< Dst, Src, DstSign, SrcSign, NUMERIC_RANGE_CONTAINED >
 
struct  DstRangeRelationToSrcRangeImpl< Dst, Src, INTEGER_REPRESENTATION_SIGNED, INTEGER_REPRESENTATION_SIGNED, NUMERIC_RANGE_NOT_CONTAINED >
 
struct  DstRangeRelationToSrcRangeImpl< Dst, Src, INTEGER_REPRESENTATION_UNSIGNED, INTEGER_REPRESENTATION_UNSIGNED, NUMERIC_RANGE_NOT_CONTAINED >
 
struct  DstRangeRelationToSrcRangeImpl< Dst, Src, INTEGER_REPRESENTATION_SIGNED, INTEGER_REPRESENTATION_UNSIGNED, NUMERIC_RANGE_NOT_CONTAINED >
 
struct  DstRangeRelationToSrcRangeImpl< Dst, Src, INTEGER_REPRESENTATION_UNSIGNED, INTEGER_REPRESENTATION_SIGNED, NUMERIC_RANGE_NOT_CONTAINED >
 
class  CheckedNumeric
 
struct  integral_constant
 
struct  is_same
 
struct  is_same< T, T >
 
struct  enable_if
 
struct  enable_if< true, T >
 
struct  IntegerForSizeAndSign
 
struct  IntegerForSizeAndSign< 1, true >
 
struct  IntegerForSizeAndSign< 1, false >
 
struct  IntegerForSizeAndSign< 2, true >
 
struct  IntegerForSizeAndSign< 2, false >
 
struct  IntegerForSizeAndSign< 4, true >
 
struct  IntegerForSizeAndSign< 4, false >
 
struct  IntegerForSizeAndSign< 8, true >
 
struct  IntegerForSizeAndSign< 8, false >
 
struct  UnsignedIntegerForSize
 
struct  SignedIntegerForSize
 
struct  TwiceWiderInteger
 
struct  PositionOfSignBit
 
struct  GetNumericRepresentation
 
class  CheckedNumericState
 
class  CheckedNumericState< T, NUMERIC_INTEGER >
 
class  CheckedNumericState< T, NUMERIC_FLOATING >
 
struct  ArithmeticPromotion
 
struct  ArithmeticPromotion< Lhs, Rhs, LEFT_PROMOTION >
 
struct  ArithmeticPromotion< Lhs, Rhs, RIGHT_PROMOTION >
 
struct  ArithmeticPromotion< Lhs, Rhs, DEFAULT_PROMOTION >
 
struct  IsIntegerArithmeticSafe
 

Typedefs

typedef integral_constant< bool, truetrue_type
 
typedef integral_constant< bool, falsefalse_type
 

Enumerations

enum  IntegerRepresentation { INTEGER_REPRESENTATION_UNSIGNED , INTEGER_REPRESENTATION_SIGNED }
 
enum  NumericRangeRepresentation { NUMERIC_RANGE_NOT_CONTAINED , NUMERIC_RANGE_CONTAINED }
 
enum  RangeConstraint { RANGE_VALID = 0x0 , RANGE_UNDERFLOW = 0x1 , RANGE_OVERFLOW = 0x2 , RANGE_INVALID = RANGE_UNDERFLOW | RANGE_OVERFLOW }
 
enum  NumericRepresentation { NUMERIC_INTEGER , NUMERIC_FLOATING , NUMERIC_UNKNOWN }
 
enum  ArithmeticPromotionCategory { LEFT_PROMOTION , RIGHT_PROMOTION , DEFAULT_PROMOTION }
 

Functions

RangeConstraint GetRangeConstraint (int integer_range_constraint)
 
RangeConstraint GetRangeConstraint (bool is_in_upper_bound, bool is_in_lower_bound)
 
template<typename Dst , typename Src >
RangeConstraint DstRangeRelationToSrcRange (Src value)
 
template<typename T >
bool HasSignBit (T x)
 
template<typename T >
T BinaryComplement (T x)
 
template<typename T >
enable_if< std::numeric_limits< T >::is_integer, T >::type CheckedAdd (T x, T y, RangeConstraint *validity)
 
template<typename T >
enable_if< std::numeric_limits< T >::is_integer, T >::type CheckedSub (T x, T y, RangeConstraint *validity)
 
template<typename T >
enable_if< std::numeric_limits< T >::is_integer &&!std::numeric_limits< T >::is_signed &&(sizeof(T) *2 > sizeof(uintmax_t)), T >::type CheckedMul (T x, T y, RangeConstraint *validity)
 
template<typename T >
T CheckedDiv (T x, T y, RangeConstraint *validity, typename enable_if< std::numeric_limits< T >::is_integer, int >::type=0)
 
template<typename T >
enable_if< std::numeric_limits< T >::is_integer &&std::numeric_limits< T >::is_signed, T >::type CheckedMod (T x, T y, RangeConstraint *validity)
 
template<typename T >
enable_if< std::numeric_limits< T >::is_integer &&!std::numeric_limits< T >::is_signed, T >::type CheckedMod (T x, T y, RangeConstraint *validity)
 
template<typename T >
enable_if< std::numeric_limits< T >::is_integer &&std::numeric_limits< T >::is_signed, T >::type CheckedNeg (T value, RangeConstraint *validity)
 
template<typename T >
enable_if< std::numeric_limits< T >::is_integer &&!std::numeric_limits< T >::is_signed, T >::type CheckedNeg (T value, RangeConstraint *validity)
 
template<typename T >
enable_if< std::numeric_limits< T >::is_integer &&std::numeric_limits< T >::is_signed, T >::type CheckedAbs (T value, RangeConstraint *validity)
 
template<typename T >
enable_if< std::numeric_limits< T >::is_integer &&!std::numeric_limits< T >::is_signed, T >::type CheckedAbs (T value, RangeConstraint *validity)
 
template<typename T >
enable_if< std::numeric_limits< T >::is_iec559, T >::type CheckedNeg (T value, RangeConstraint *)
 
template<typename T >
enable_if< std::numeric_limits< T >::is_iec559, T >::type CheckedAbs (T value, RangeConstraint *)
 

Variables

else * validity
 
return x * y
 

Typedef Documentation

◆ false_type

◆ true_type

Enumeration Type Documentation

◆ ArithmeticPromotionCategory

Enumerator
LEFT_PROMOTION 
RIGHT_PROMOTION 
DEFAULT_PROMOTION 

Definition at line 479 of file safe_math_impl.h.

◆ IntegerRepresentation

Enumerator
INTEGER_REPRESENTATION_UNSIGNED 
INTEGER_REPRESENTATION_SIGNED 

Definition at line 31 of file safe_conversions_impl.h.

◆ NumericRangeRepresentation

Enumerator
NUMERIC_RANGE_NOT_CONTAINED 
NUMERIC_RANGE_CONTAINED 

Definition at line 41 of file safe_conversions_impl.h.

◆ NumericRepresentation

Enumerator
NUMERIC_INTEGER 
NUMERIC_FLOATING 
NUMERIC_UNKNOWN 

Definition at line 359 of file safe_math_impl.h.

◆ RangeConstraint

Enumerator
RANGE_VALID 
RANGE_UNDERFLOW 
RANGE_OVERFLOW 
RANGE_INVALID 

Definition at line 93 of file safe_conversions_impl.h.

93  {
94  RANGE_VALID = 0x0, // Value can be represented by the destination type.
95  RANGE_UNDERFLOW = 0x1, // Value would overflow.
96  RANGE_OVERFLOW = 0x2, // Value would underflow.
97  RANGE_INVALID = RANGE_UNDERFLOW | RANGE_OVERFLOW // Invalid (i.e. NaN).
98 };

Function Documentation

◆ BinaryComplement()

template<typename T >
T v8::base::internal::BinaryComplement ( T  x)

Definition at line 135 of file safe_math_impl.h.

135  {
136  return ~x;
137 }

Referenced by CheckedAdd(), and CheckedSub().

+ Here is the caller graph for this function:

◆ CheckedAbs() [1/3]

template<typename T >
enable_if<std::numeric_limits<T>::is_iec559, T>::type v8::base::internal::CheckedAbs ( T  value,
RangeConstraint  
)

Definition at line 350 of file safe_math_impl.h.

352  {
353  return std::abs(value);
354 }

◆ CheckedAbs() [2/3]

template<typename T >
enable_if< std::numeric_limits<T>::is_integer && std::numeric_limits<T>::is_signed, T>::type v8::base::internal::CheckedAbs ( T  value,
RangeConstraint validity 
)

Definition at line 308 of file safe_math_impl.h.

308  {
309  *validity =
311  return std::abs(value);
312 }
static int min(int a, int b)
Definition: liveedit.cc:273

References v8::internal::min(), RANGE_OVERFLOW, RANGE_VALID, and validity.

Referenced by v8::base::internal::CheckedNumeric< T >::Abs().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CheckedAbs() [3/3]

template<typename T >
enable_if< std::numeric_limits<T>::is_integer && !std::numeric_limits<T>::is_signed, T>::type v8::base::internal::CheckedAbs ( T  value,
RangeConstraint validity 
)

Definition at line 318 of file safe_math_impl.h.

318  {
319  // Absolute value of a positive is just its identiy.
321  return value;
322 }

References RANGE_VALID, and validity.

◆ CheckedAdd()

template<typename T >
enable_if<std::numeric_limits<T>::is_integer, T>::type v8::base::internal::CheckedAdd ( T  x,
T  y,
RangeConstraint validity 
)

Definition at line 145 of file safe_math_impl.h.

145  {
146  // Since the value of x+y is undefined if we have a signed type, we compute
147  // it using the unsigned type of the same size.
148  typedef typename UnsignedIntegerForSize<T>::type UnsignedDst;
149  UnsignedDst ux = static_cast<UnsignedDst>(x);
150  UnsignedDst uy = static_cast<UnsignedDst>(y);
151  UnsignedDst uresult = ux + uy;
152  // Addition is valid if the sign of (x + y) is equal to either that of x or
153  // that of y.
154  if (std::numeric_limits<T>::is_signed) {
155  if (HasSignBit(BinaryComplement((uresult ^ ux) & (uresult ^ uy))))
157  else // Direction of wrap is inverse of result sign.
159 
160  } else { // Unsigned is either valid or overflow.
162  }
163  return static_cast<T>(uresult);
164 }
#define T(name, string, precedence)
Definition: token.cc:25

References BinaryComplement(), HasSignBit(), RANGE_OVERFLOW, RANGE_UNDERFLOW, RANGE_VALID, T, validity, and y.

+ Here is the call graph for this function:

◆ CheckedDiv()

template<typename T >
T v8::base::internal::CheckedDiv ( T  x,
T  y,
RangeConstraint validity,
typename enable_if< std::numeric_limits< T >::is_integer, int >::type  = 0 
)

Definition at line 249 of file safe_math_impl.h.

253  {
254  if (std::numeric_limits<T>::is_signed && x == std::numeric_limits<T>::min() &&
255  y == static_cast<T>(-1)) {
258  }
259 
261  return x / y;
262 }

References v8::internal::min(), RANGE_OVERFLOW, RANGE_VALID, T, validity, and y.

+ Here is the call graph for this function:

◆ CheckedMod() [1/2]

template<typename T >
enable_if< std::numeric_limits<T>::is_integer && std::numeric_limits<T>::is_signed, T>::type v8::base::internal::CheckedMod ( T  x,
T  y,
RangeConstraint validity 
)

Definition at line 268 of file safe_math_impl.h.

268  {
269  *validity = y > 0 ? RANGE_VALID : RANGE_INVALID;
270  return x % y;
271 }

References RANGE_INVALID, RANGE_VALID, validity, and y.

◆ CheckedMod() [2/2]

template<typename T >
enable_if< std::numeric_limits<T>::is_integer && !std::numeric_limits<T>::is_signed, T>::type v8::base::internal::CheckedMod ( T  x,
T  y,
RangeConstraint validity 
)

Definition at line 277 of file safe_math_impl.h.

277  {
279  return x % y;
280 }

References RANGE_VALID, validity, and y.

◆ CheckedMul()

template<typename T >
enable_if<std::numeric_limits<T>::is_integer && !std::numeric_limits<T>::is_signed && (sizeof(T) * 2 > sizeof(uintmax_t)), T>::type v8::base::internal::CheckedMul ( T  x,
T  y,
RangeConstraint validity 
)

Definition at line 240 of file safe_math_impl.h.

240  {
241  *validity = (y == 0 || x <= std::numeric_limits<T>::max() / y)
242  ? RANGE_VALID
243  : RANGE_OVERFLOW;
244  return x * y;
245 }

References RANGE_OVERFLOW, RANGE_VALID, validity, and y.

◆ CheckedNeg() [1/3]

template<typename T >
enable_if<std::numeric_limits<T>::is_iec559, T>::type v8::base::internal::CheckedNeg ( T  value,
RangeConstraint  
)

Definition at line 343 of file safe_math_impl.h.

345  {
346  return -value;
347 }

◆ CheckedNeg() [2/3]

template<typename T >
enable_if< std::numeric_limits<T>::is_integer && std::numeric_limits<T>::is_signed, T>::type v8::base::internal::CheckedNeg ( T  value,
RangeConstraint validity 
)

Definition at line 286 of file safe_math_impl.h.

286  {
287  *validity =
289  // The negation of signed min is min, so catch that one.
290  return -value;
291 }

References v8::internal::min(), RANGE_OVERFLOW, RANGE_VALID, and validity.

Referenced by v8::base::internal::CheckedNumeric< T >::operator-().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CheckedNeg() [3/3]

template<typename T >
enable_if< std::numeric_limits<T>::is_integer && !std::numeric_limits<T>::is_signed, T>::type v8::base::internal::CheckedNeg ( T  value,
RangeConstraint validity 
)

Definition at line 297 of file safe_math_impl.h.

297  {
298  // The only legal unsigned negation is zero.
299  *validity = value ? RANGE_UNDERFLOW : RANGE_VALID;
300  return static_cast<T>(
301  -static_cast<typename SignedIntegerForSize<T>::type>(value));
302 }

References RANGE_UNDERFLOW, RANGE_VALID, T, and validity.

◆ CheckedSub()

template<typename T >
enable_if<std::numeric_limits<T>::is_integer, T>::type v8::base::internal::CheckedSub ( T  x,
T  y,
RangeConstraint validity 
)

Definition at line 168 of file safe_math_impl.h.

168  {
169  // Since the value of x+y is undefined if we have a signed type, we compute
170  // it using the unsigned type of the same size.
171  typedef typename UnsignedIntegerForSize<T>::type UnsignedDst;
172  UnsignedDst ux = static_cast<UnsignedDst>(x);
173  UnsignedDst uy = static_cast<UnsignedDst>(y);
174  UnsignedDst uresult = ux - uy;
175  // Subtraction is valid if either x and y have same sign, or (x-y) and x have
176  // the same sign.
177  if (std::numeric_limits<T>::is_signed) {
178  if (HasSignBit(BinaryComplement((uresult ^ ux) & (ux ^ uy))))
180  else // Direction of wrap is inverse of result sign.
182 
183  } else { // Unsigned is either valid or underflow.
185  }
186  return static_cast<T>(uresult);
187 }

References BinaryComplement(), HasSignBit(), RANGE_OVERFLOW, RANGE_UNDERFLOW, RANGE_VALID, T, validity, and y.

+ Here is the call graph for this function:

◆ DstRangeRelationToSrcRange()

template<typename Dst , typename Src >
RangeConstraint v8::base::internal::DstRangeRelationToSrcRange ( Src  value)
inline

Definition at line 209 of file safe_conversions_impl.h.

209  {
210  // Both source and destination must be numeric.
211  STATIC_ASSERT(std::numeric_limits<Src>::is_specialized);
212  STATIC_ASSERT(std::numeric_limits<Dst>::is_specialized);
213  return DstRangeRelationToSrcRangeImpl<Dst, Src>::Check(value);
214 }
#define STATIC_ASSERT(test)
Definition: macros.h:311

References STATIC_ASSERT.

◆ GetRangeConstraint() [1/2]

RangeConstraint v8::base::internal::GetRangeConstraint ( bool  is_in_upper_bound,
bool  is_in_lower_bound 
)
inline

Definition at line 110 of file safe_conversions_impl.h.

111  {
112  return GetRangeConstraint((is_in_upper_bound ? 0 : RANGE_OVERFLOW) |
113  (is_in_lower_bound ? 0 : RANGE_UNDERFLOW));
114 }
RangeConstraint GetRangeConstraint(bool is_in_upper_bound, bool is_in_lower_bound)

References GetRangeConstraint(), RANGE_OVERFLOW, and RANGE_UNDERFLOW.

+ Here is the call graph for this function:

◆ GetRangeConstraint() [2/2]

RangeConstraint v8::base::internal::GetRangeConstraint ( int  integer_range_constraint)
inline

◆ HasSignBit()

template<typename T >
bool v8::base::internal::HasSignBit ( T  x)

Definition at line 127 of file safe_math_impl.h.

127  {
128  // Cast to unsigned since right shift on signed is undefined.
129  return !!(static_cast<typename UnsignedIntegerForSize<T>::type>(x) >>
130  PositionOfSignBit<T>::value);
131 }

Referenced by CheckedAdd(), and CheckedSub().

+ Here is the caller graph for this function:

Variable Documentation

◆ validity

else* v8::base::internal::validity
Initial value:
=
y >= std::numeric_limits<T>::max() / x ? RANGE_VALID : RANGE_OVERFLOW

Definition at line 228 of file safe_math_impl.h.

Referenced by CheckedAbs(), CheckedAdd(), CheckedDiv(), CheckedMod(), CheckedMul(), CheckedNeg(), and CheckedSub().

◆ y