Skip to content

Commit

Permalink
[referencesource] Import System.Double and System.Simple
Browse files Browse the repository at this point in the history
  • Loading branch information
luhenry committed May 13, 2015
1 parent 45d61b6 commit 1886cdc
Show file tree
Hide file tree
Showing 14 changed files with 421 additions and 3,478 deletions.
2 changes: 1 addition & 1 deletion external/referencesource
Submodule referencesource updated 1 files
+6 −10 mscorlib/system/number.cs
4 changes: 2 additions & 2 deletions mcs/class/corlib/corlib.dll.sources
Expand Up @@ -96,7 +96,6 @@ System/CrossAppDomainDelegate.cs
System/Delegate.cs
System/DelegateSerializationHolder.cs
System/DomainManagerInitializationFlags.cs
System/Double.cs
System/EmptyArray.cs
System/Environment.cs
System/EnvironmentVariableTarget.cs
Expand Down Expand Up @@ -132,7 +131,6 @@ System/RuntimeFieldHandle.cs
System/RuntimeMethodHandle.cs
System/RuntimeTypeHandle.cs
System/ModuleHandle.cs
System/Single.cs
System/StringComparison.cs
System/TermInfoBooleans.cs
System/TermInfoDriver.cs
Expand Down Expand Up @@ -974,6 +972,7 @@ ReferenceSources/SharedStatics.cs
../../../external/referencesource/mscorlib/system/dbnull.cs
../../../external/referencesource/mscorlib/system/dividebyzeroexception.cs
../../../external/referencesource/mscorlib/system/dllnotfoundexception.cs
../../../external/referencesource/mscorlib/system/double.cs
../../../external/referencesource/mscorlib/system/duplicatewaitobjectexception.cs
../../../external/referencesource/mscorlib/system/empty.cs
../../../external/referencesource/mscorlib/system/enum.cs
Expand Down Expand Up @@ -1039,6 +1038,7 @@ ReferenceSources/SharedStatics.cs
../../../external/referencesource/mscorlib/system/sbyte.cs
../../../external/referencesource/mscorlib/system/serializableattribute.cs
../../../external/referencesource/mscorlib/system/stackoverflowexception.cs
../../../external/referencesource/mscorlib/system/single.cs
../../../external/referencesource/mscorlib/system/string.cs
../../../external/referencesource/mscorlib/system/stringcomparer.cs
../../../external/referencesource/mscorlib/system/stringfreezingattribute.cs
Expand Down
2 changes: 2 additions & 0 deletions mono/metadata/Makefile.am
Expand Up @@ -175,6 +175,8 @@ common_sources = \
nacl-stub.c \
normalization-tables.h \
number-formatter.h \
number-ms.c \
number-ms.h \
object-internals.h \
opcodes.c \
socket-io.c \
Expand Down
4 changes: 0 additions & 4 deletions mono/metadata/appdomain.c
Expand Up @@ -90,8 +90,6 @@ typedef struct

mono_mutex_t mono_delegate_section;

mono_mutex_t mono_strtod_mutex;

static gunichar2 process_guid [36];
static gboolean process_guid_set = FALSE;

Expand Down Expand Up @@ -258,8 +256,6 @@ mono_runtime_init (MonoDomain *domain, MonoThreadStartCB start_cb,
domain->setup = setup;

mono_mutex_init_recursive (&mono_delegate_section);

mono_mutex_init_recursive (&mono_strtod_mutex);

mono_thread_attach (domain);

Expand Down
82 changes: 17 additions & 65 deletions mono/metadata/decimal-ms.c
Expand Up @@ -29,6 +29,7 @@
#include <intrin.h>
#endif
#include "decimal-ms.h"
#include "number-ms.h"

#define min(a, b) (((a) < (b)) ? (a) : (b))

Expand Down Expand Up @@ -93,50 +94,8 @@ typedef union {
} SPLIT64;

static const SPLIT64 ten_to_eighteen = { 1000000000000000000ULL };
// Double Bias
#define DBLBIAS 1022

// Structure to access an encoded double floating point
typedef union{
struct {
#if BYTE_ORDER == G_BIG_ENDIAN
unsigned int sign:1;
unsigned int exp:11;
unsigned int mantHi:20;
unsigned int mantLo;
#else // BIGENDIAN
unsigned int mantLo;
unsigned int mantHi:20;
unsigned int exp:11;
unsigned int sign:1;
#endif
} u;
double dbl;
} DoubleStructure;

#if BYTE_ORDER == G_BIG_ENDIAN
#define DEFDS(Lo, Hi, exp, sign) { {sign, exp, Hi, Lo } }
#else
#define DEFDS(Lo, Hi, exp, sign) { {Lo, Hi, exp, sign} }
#endif

const DoubleStructure ds2to64 = DEFDS(0, 0, DBLBIAS + 65, 0);

// Single floating point Bias
#define SNGBIAS 126

// Structure to access an encoded single floating point
typedef struct {
#if BYTE_ORDER == G_BIG_ENDIAN
unsigned int sign:1;
unsigned int exp:8;
unsigned int mant:23;
#else
unsigned int mant:23;
unsigned int exp:8;
unsigned int sign:1;
#endif
} SingleStructure;
const MonoDouble_double ds2to64 = { .s = { .sign = 0, .exp = MONO_DOUBLE_BIAS + 65, .mantHi = 0, .mantLo = 0 } };

//
// Data tables
Expand Down Expand Up @@ -1822,7 +1781,7 @@ mono_decimal_round_result(MonoDecimal *input, int cDecimals, MonoDecimal *result
//
// Returns MONO_DECIMAL_OK or MONO_DECIMAL_OVERFLOW
static MonoDecimalStatus
mono_decimal_from_float (float input, MonoDecimal* result)
mono_decimal_from_float (float input_f, MonoDecimal* result)
{
int exp; // number of bits to left of binary point
int power;
Expand All @@ -1831,12 +1790,13 @@ mono_decimal_from_float (float input, MonoDecimal* result)
SPLIT64 sdlLo;
SPLIT64 sdlHi;
int lmax, cur; // temps used during scale reduction

MonoSingle_float input = { .f = input_f };

// The most we can scale by is 10^28, which is just slightly more
// than 2^93. So a float with an exponent of -94 could just
// barely reach 0.5, but smaller exponents will always round to zero.
//
if ((exp = ((SingleStructure *)&input)->exp - SNGBIAS) < -94 ) {
if ((exp = input.s.exp - MONO_SINGLE_BIAS) < -94 ) {
DECIMAL_SETZERO(*result);
return MONO_DECIMAL_OK;
}
Expand All @@ -1852,7 +1812,7 @@ mono_decimal_from_float (float input, MonoDecimal* result)
// the exponent by log10(2). Using scaled integer multiplcation,
// log10(2) * 2 ^ 16 = .30103 * 65536 = 19728.3.
//
dbl = fabs(input);
dbl = fabs(input.f);
power = 6 - ((exp * 19728) >> 16);

if (power >= 0) {
Expand Down Expand Up @@ -1956,13 +1916,13 @@ mono_decimal_from_float (float input, MonoDecimal* result)
DECIMAL_SCALE(*result) = power;
}

DECIMAL_SIGN(*result) = (char)((SingleStructure *)&input)->sign << 7;
DECIMAL_SIGN(*result) = (char)input.s.sign << 7;
return MONO_DECIMAL_OK;
}

// Returns MONO_DECIMAL_OK or MONO_DECIMAL_OVERFLOW
static MonoDecimalStatus
mono_decimal_from_double (double input, MonoDecimal *result)
mono_decimal_from_double (double input_d, MonoDecimal *result)
{
int exp; // number of bits to left of binary point
int power; // power-of-10 scale factor
Expand All @@ -1972,13 +1932,13 @@ mono_decimal_from_double (double input, MonoDecimal *result)
int lmax, cur; // temps used during scale reduction
uint32_t pwr_cur;
uint32_t quo;

MonoDouble_double input = { .d = input_d };

// The most we can scale by is 10^28, which is just slightly more
// than 2^93. So a float with an exponent of -94 could just
// barely reach 0.5, but smaller exponents will always round to zero.
//
if ((exp = ((DoubleStructure *)&input)->u.exp - DBLBIAS) < -94) {
if ((exp = input.s.exp - MONO_DOUBLE_BIAS) < -94) {
DECIMAL_SETZERO(*result);
return MONO_DECIMAL_OK;
}
Expand All @@ -1994,7 +1954,7 @@ mono_decimal_from_double (double input, MonoDecimal *result)
// the exponent by log10(2). Using scaled integer multiplcation,
// log10(2) * 2 ^ 16 = .30103 * 65536 = 19728.3.
//
dbl = fabs(input);
dbl = fabs(input.d);
power = 14 - ((exp * 19728) >> 16);

if (power >= 0) {
Expand Down Expand Up @@ -2105,7 +2065,7 @@ mono_decimal_from_double (double input, MonoDecimal *result)
DECIMAL_MID32(*result) = sdlMant.u.Hi;
}

DECIMAL_SIGN(*result) = (char)((DoubleStructure *)&input)->u.sign << 7;
DECIMAL_SIGN(*result) = (char)input.s.sign << 7;
return MONO_DECIMAL_OK;
}

Expand All @@ -2123,11 +2083,11 @@ mono_decimal_to_double_result(MonoDecimal *input, double *result)
tmp.u.Hi = DECIMAL_MID32(*input);

if ((int32_t)DECIMAL_MID32(*input) < 0)
dbl = (ds2to64.dbl + (double)(int64_t)tmp.int64 +
(double)DECIMAL_HI32(*input) * ds2to64.dbl) / fnDblPower10(DECIMAL_SCALE(*input)) ;
dbl = (ds2to64.d + (double)(int64_t)tmp.int64 +
(double)DECIMAL_HI32(*input) * ds2to64.d) / fnDblPower10(DECIMAL_SCALE(*input)) ;
else
dbl = ((double)(int64_t)tmp.int64 +
(double)DECIMAL_HI32(*input) * ds2to64.dbl) / fnDblPower10(DECIMAL_SCALE(*input));
(double)DECIMAL_HI32(*input) * ds2to64.d) / fnDblPower10(DECIMAL_SCALE(*input));

if (DECIMAL_SIGN(*input))
dbl = -dbl;
Expand Down Expand Up @@ -3066,19 +3026,11 @@ mono_decimal_divide (MonoDecimal *left, MonoDecimal *right)
}

#define DECIMAL_PRECISION 29
#define NUMBER_MAXDIGITS 50
typedef struct {
int32_t precision;
int32_t scale;
int32_t sign;
uint16_t digits[NUMBER_MAXDIGITS + 1];
uint16_t* allDigits;
} CLRNumber;

int
mono_decimal_from_number (void *from, MonoDecimal *target)
{
CLRNumber *number = (CLRNumber *) from;
MonoNumber *number = (MonoNumber *) from;
uint16_t* p = number->digits;
MonoDecimal d;
int e = number->scale;
Expand Down
3 changes: 2 additions & 1 deletion mono/metadata/decimal-ms.h
@@ -1,6 +1,7 @@
#ifndef __MONO_DECIMAL_MS_H__
#define __MONO_DECIMAL_MS_H__
typedef struct tagDECIMAL {

typedef struct {
// Decimal.cs treats the first two shorts as one long
// And they seriable the data so we need to little endian
// seriliazation
Expand Down
1 change: 0 additions & 1 deletion mono/metadata/domain-internals.h
Expand Up @@ -18,7 +18,6 @@


extern mono_mutex_t mono_delegate_section;
extern mono_mutex_t mono_strtod_mutex;

/*
* If this is set, the memory belonging to appdomains is not freed when a domain is
Expand Down
5 changes: 2 additions & 3 deletions mono/metadata/icall-def.h
Expand Up @@ -214,9 +214,6 @@ ICALL(SFRAME_1, "GetILOffsetFromFile", ves_icall_System_StackFrame_GetILOffsetFr
ICALL_TYPE(STOPWATCH, "System.Diagnostics.Stopwatch", STOPWATCH_1)
ICALL(STOPWATCH_1, "GetTimestamp", mono_100ns_ticks)

ICALL_TYPE(DOUBLE, "System.Double", DOUBLE_1)
ICALL(DOUBLE_1, "ParseImpl", mono_double_ParseImpl)

ICALL_TYPE(ENUM, "System.Enum", ENUM_1)
ICALL(ENUM_1, "GetEnumValuesAndNames", ves_icall_System_Enum_GetEnumValuesAndNames)
ICALL(ENUM_2, "InternalBoxEnum", ves_icall_System_Enum_ToObject)
Expand Down Expand Up @@ -445,6 +442,8 @@ ICALL(SOCKEX_1, "WSAGetLastError_internal", ves_icall_System_Net_Sockets_SocketE

ICALL_TYPE(NUMBER, "System.Number", NUMBER_1)
ICALL(NUMBER_1, "NumberBufferToDecimal", mono_decimal_from_number)
ICALL(NUMBER_2, "NumberBufferToDouble", mono_double_from_number)

ICALL_TYPE(NUMBER_FORMATTER, "System.NumberFormatter", NUMBER_FORMATTER_1)
ICALL(NUMBER_FORMATTER_1, "GetFormatterTables", ves_icall_System_NumberFormatter_GetFormatterTables)

Expand Down
24 changes: 1 addition & 23 deletions mono/metadata/icall.c
Expand Up @@ -81,7 +81,6 @@
#include <mono/metadata/file-mmap.h>
#include <mono/metadata/seq-points-data.h>
#include <mono/io-layer/io-layer.h>
#include <mono/utils/strtod.h>
#include <mono/utils/monobitset.h>
#include <mono/utils/mono-time.h>
#include <mono/utils/mono-proclib.h>
Expand All @@ -99,6 +98,7 @@
#include <shlobj.h>
#endif
#include "decimal-ms.h"
#include "number-ms.h"

extern MonoString* ves_icall_System_Environment_GetOSVersionString (void);

Expand All @@ -120,28 +120,6 @@ mono_class_init_or_throw (MonoClass *klass)
mono_raise_exception (mono_class_get_exception_for_failure (klass));
}

/*
* We expect a pointer to a char, not a string
*/
ICALL_EXPORT gboolean
mono_double_ParseImpl (char *ptr, double *result)
{
gchar *endptr = NULL;
*result = 0.0;

if (*ptr){
/* mono_strtod () is not thread-safe */
mono_mutex_lock (&mono_strtod_mutex);
*result = mono_strtod (ptr, &endptr);
mono_mutex_unlock (&mono_strtod_mutex);
}

if (!*ptr || (endptr && *endptr))
return FALSE;

return TRUE;
}

ICALL_EXPORT MonoObject *
ves_icall_System_Array_GetValueImpl (MonoObject *this, guint32 pos)
{
Expand Down

0 comments on commit 1886cdc

Please sign in to comment.