Differential D3094 Diff 14018 ps/trunk/libraries/source/spidermonkey/include-win32-debug/mozilla/Casting.h
Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/libraries/source/spidermonkey/include-win32-debug/mozilla/Casting.h
Show All 11 Lines | |||||
#include "mozilla/Assertions.h" | #include "mozilla/Assertions.h" | ||||
#include "mozilla/TypeTraits.h" | #include "mozilla/TypeTraits.h" | ||||
#include <limits.h> | #include <limits.h> | ||||
namespace mozilla { | namespace mozilla { | ||||
/** | /** | ||||
* Return a value of type |To|, containing the underlying bit pattern of | * Sets the outparam value of type |To| with the same underlying bit pattern of | ||||
* |aFrom|. | * |aFrom|. | ||||
* | * | ||||
* |To| and |From| must be types of the same size; be careful of cross-platform | * |To| and |From| must be types of the same size; be careful of cross-platform | ||||
* size differences, or this might fail to compile on some but not all | * size differences, or this might fail to compile on some but not all | ||||
* platforms. | * platforms. | ||||
* | |||||
* There is also a variant that returns the value directly. In most cases, the | |||||
* two variants should be identical. However, in the specific case of x86 | |||||
* chips, the behavior differs: returning floating-point values directly is done | |||||
* through the x87 stack, and x87 loads and stores turn signaling NaNs into | |||||
* quiet NaNs... silently. Returning floating-point values via outparam, | |||||
* however, is done entirely within the SSE registers when SSE2 floating-point | |||||
* is enabled in the compiler, which has semantics-preserving behavior you would | |||||
* expect. | |||||
* | |||||
* If preserving the distinction between signaling NaNs and quiet NaNs is | |||||
* important to you, you should use the outparam version. In all other cases, | |||||
* you should use the direct return version. | |||||
*/ | */ | ||||
template<typename To, typename From> | template<typename To, typename From> | ||||
inline To | inline void | ||||
BitwiseCast(const From aFrom) | BitwiseCast(const From aFrom, To* aResult) | ||||
{ | { | ||||
static_assert(sizeof(From) == sizeof(To), | static_assert(sizeof(From) == sizeof(To), | ||||
"To and From must have the same size"); | "To and From must have the same size"); | ||||
union | union | ||||
{ | { | ||||
From mFrom; | From mFrom; | ||||
To mTo; | To mTo; | ||||
} u; | } u; | ||||
u.mFrom = aFrom; | u.mFrom = aFrom; | ||||
return u.mTo; | *aResult = u.mTo; | ||||
} | |||||
template<typename To, typename From> | |||||
inline To | |||||
BitwiseCast(const From aFrom) | |||||
{ | |||||
To temp; | |||||
BitwiseCast<To, From>(aFrom, &temp); | |||||
return temp; | |||||
} | } | ||||
namespace detail { | namespace detail { | ||||
enum ToSignedness { ToIsSigned, ToIsUnsigned }; | enum ToSignedness { ToIsSigned, ToIsUnsigned }; | ||||
enum FromSignedness { FromIsSigned, FromIsUnsigned }; | enum FromSignedness { FromIsSigned, FromIsUnsigned }; | ||||
template<typename From, | template<typename From, | ||||
▲ Show 20 Lines • Show All 174 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator