From b1369040c3d6d6a8704bdb17d9de99f36a108e07 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Tue, 26 May 2020 13:53:10 -0400 Subject: Improvements around hashing (#1355) * Fields from upper to lower case in slang-ast-decl.h * Lower camel field names in slang-ast-stmt.h * Fix fields in slang-ast-expr.h * slang-ast-type.h make fields lowerCamel. * slang-ast-base.h members functions lowerCamel. * Method names in slang-ast-type.h to lowerCamel. * GetCanonicalType -> getCanonicalType * Substitute -> substitute * Equals -> equals ToString -> toString * ParentDecl -> parentDecl Members -> members * * Make hash code types explicit * Use HashCode as return type of GetHashCode * Added conversion from double to int64_t * Split Stable from other hash functions * toHash32/64 to convert a HashCode to the other styles. GetHashCode32/64 -> getHashCode32/64 GetStableHashCode32/64 -> getStableHashCode32/64 * Other Get/Stable/HashCode32/64 fixes * GetHashCode -> getHashCode * Equals -> equals * CreateCanonicalType -> createCanonicalType * Catches of polymorphic types should be through references otherwise slicing can occur. * Fixes for newer verison of gcc. Fix hashing problem on gcc for Dictionary. * Another fix for GetHashPos * Fix signed issue around GetHashPos --- source/core/slang-math.h | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'source/core/slang-math.h') diff --git a/source/core/slang-math.h b/source/core/slang-math.h index 7d3a741a4..2378b73a0 100644 --- a/source/core/slang-math.h +++ b/source/core/slang-math.h @@ -21,10 +21,16 @@ namespace Slang float fvalue; int ivalue; - inline static FloatIntUnion makeFromInt(int i) { FloatIntUnion cast; cast.ivalue = i; return cast; } - inline static FloatIntUnion makeFromFloat(float f) { FloatIntUnion cast; cast.fvalue = f; return cast; } + SLANG_FORCE_INLINE static FloatIntUnion makeFromInt(int i) { FloatIntUnion cast; cast.ivalue = i; return cast; } + SLANG_FORCE_INLINE static FloatIntUnion makeFromFloat(float f) { FloatIntUnion cast; cast.fvalue = f; return cast; } + }; + union DoubleInt64Union + { + double dvalue; + int64_t ivalue; + SLANG_FORCE_INLINE static DoubleInt64Union makeFromInt64(int64_t i) { DoubleInt64Union cast; cast.ivalue = i; return cast; } + SLANG_FORCE_INLINE static DoubleInt64Union makeFromDouble(double d) { DoubleInt64Union cast; cast.dvalue = d; return cast; } }; - static const float Pi; @@ -171,6 +177,15 @@ namespace Slang return Math::FloatIntUnion::makeFromInt(val).fvalue; } + SLANG_FORCE_INLINE int64_t DoubleAsInt64(double val) + { + return Math::DoubleInt64Union::makeFromDouble(val).ivalue; + } + SLANG_FORCE_INLINE double Int64AsDouble(int64_t value) + { + return Math::DoubleInt64Union::makeFromInt64(value).dvalue; + } + inline unsigned short FloatToHalf(float val) { const auto x = FloatAsInt(val); -- cgit v1.2.3