Skip to content

Commit 35732ee

Browse files
author
Jianchun Xu
committed
[MERGE #641] xplat: build lib/Runtime/Language, lib/Runtime/Math
Merge pull request #641 from jianchun:lang Notable changes: - InterpreterStackFrame.cpp: refactor code to get rid of a "goto", which was illegal as it skipped other variable initialization. - TaggedInt.cpp: replaced __try/__except with explict test to deal with a floating point exception case. - JavascriptMath.cpp: "and", "or" are reserved keywords and not allowed for variable names. - pal_mstypes.h: LARGE_INTEGER should have an unnamed union member. To be addressed: - implement _ultow_s, _ui64tow_s - design/implement xplat stack walker (RtlVirtualUnwind, ...) - Simd only partially builds. The rest needs lots of functions declared in emmintrin.h/xmmintrin.h. But PAL conflicts with it. We have been copying some functions by hand into palrt.h, but that seems not maintainable.
2 parents 4f1a81c + 8c4a147 commit 35732ee

21 files changed

+121
-117
lines changed

lib/Common/CommonPal.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ typedef wchar_t char16;
3131
#else // !_WIN32
3232

3333
#define USING_PAL_STDLIB 1
34-
3534
#include "inc/pal.h"
3635
#include "inc/rt/palrt.h"
3736
#include "inc/rt/no_sal2.h"
@@ -296,8 +295,9 @@ BOOL WINAPI GetModuleHandleEx(
296295
// and then use the stack size to calculate the stack base
297296
int GetCurrentThreadStackBounds(char** stackBase, char** stackEnd);
298297

299-
// xplat-todo: cryptographically secure PRNG?
300298
errno_t rand_s(unsigned int* randomValue);
299+
errno_t __cdecl _ultow_s(unsigned _Value, WCHAR *_Dst, size_t _SizeInWords, int _Radix);
300+
errno_t __cdecl _ui64tow_s(unsigned __int64 _Value, WCHAR *_Dst, size_t _SizeInWords, int _Radix);
301301

302302
#define MAXUINT32 ((uint32_t)~((uint32_t)0))
303303
#define MAXINT32 ((int32_t)(MAXUINT32 >> 1))
@@ -337,6 +337,13 @@ errno_t rand_s(unsigned int* randomValue);
337337
#define _NOEXCEPT_ noexcept
338338
#endif
339339

340+
#ifdef _MSC_VER
341+
extern "C" PVOID _ReturnAddress(VOID);
342+
#pragma intrinsic(_ReturnAddress)
343+
#else
344+
#define _ReturnAddress() __builtin_return_address(0)
345+
#endif
346+
340347
// xplat-todo: can we get rid of this for clang?
341348
// Including xmmintrin.h right now creates a ton of
342349
// compile errors, so temporarily defining this for clang

lib/Common/Memory/RecyclerFastAllocator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class RecyclerFastAllocator
4949
#endif
5050
size_t sizeCat = GetAlignedAllocSize();
5151
Assert(HeapInfo::IsSmallObject(sizeCat));
52-
char * memBlock = allocator.InlinedAlloc<(ObjectInfoBits)(attributes & InternalObjectInfoBitMask)>(recycler, sizeCat);
52+
char * memBlock = allocator.template InlinedAlloc<(ObjectInfoBits)(attributes & InternalObjectInfoBitMask)>(recycler, sizeCat);
5353

5454
if (memBlock == nullptr)
5555
{

lib/Runtime/Base/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# xplat-todo: This is a skeleton make file and not used in build yet.
2-
# Please add this to build and fix issues.
3-
41
add_library (Chakra.Runtime.Base
52
CallInfo.cpp
63
CharStringCache.cpp

lib/Runtime/Base/ScriptContext.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -741,8 +741,8 @@ namespace Js
741741
#ifdef ENABLE_GLOBALIZATION
742742
TIME_ZONE_INFORMATION timeZoneInfo;
743743
uint lastTimeZoneUpdateTickCount;
744-
DaylightTimeHelper daylightTimeHelper;
745744
#endif // ENABLE_GLOBALIZATION
745+
DaylightTimeHelper daylightTimeHelper;
746746

747747
HostScriptContext * hostScriptContext;
748748
HaltCallback* scriptEngineHaltCallback;
@@ -860,9 +860,7 @@ namespace Js
860860
bool isRootTrackerScriptContext;
861861
#endif
862862

863-
#ifdef ENABLE_GLOBALIZATION
864863
DaylightTimeHelper *GetDaylightTimeHelper() { return &daylightTimeHelper; }
865-
#endif // ENABLE_GLOBALIZATION
866864

867865
bool IsClosed() const { return isClosed; }
868866
bool IsActuallyClosed() const { return isScriptContextActuallyClosed; }

lib/Runtime/ByteCode/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# xplat-todo: This is a skeleton make file and not used in build yet.
2-
# Please add this to build and fix issues.
3-
41
add_library (Chakra.Runtime.ByteCode
52
AsmJsByteCodeDumper.cpp
63
AsmJsByteCodeWriter.cpp

lib/Runtime/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ include_directories(
1010

1111
add_subdirectory (Base)
1212
add_subdirectory (ByteCode)
13+
add_subdirectory (Language)
14+
add_subdirectory (Math)

lib/Runtime/Language/CMakeLists.txt

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# xplat-todo: This is a skeleton make file and not used in build yet.
2-
# Please add this to build and fix issues.
3-
41
add_library (Chakra.Runtime.Language
52
AsmJs.cpp
63
AsmJsByteCodeGenerator.cpp
@@ -31,39 +28,43 @@ add_library (Chakra.Runtime.Language
3128
ReadOnlyDynamicProfileInfo.cpp
3229
RuntimeLanguagePch.cpp
3330
SimdBool16x8Operation.cpp
34-
SimdBool16x8OperationX86X64.cpp
31+
# SimdBool16x8OperationX86X64.cpp
3532
SimdBool32x4Operation.cpp
36-
SimdBool32x4OperationX86X64.cpp
33+
# SimdBool32x4OperationX86X64.cpp
3734
SimdBool8x16Operation.cpp
38-
SimdBool8x16OperationX86X64.cpp
35+
# SimdBool8x16OperationX86X64.cpp
3936
SimdFloat32x4Operation.cpp
40-
SimdFloat32x4OperationX86X64.cpp
37+
# SimdFloat32x4OperationX86X64.cpp
4138
SimdFloat64x2Operation.cpp
42-
SimdFloat64x2OperationX86X64.cpp
39+
# SimdFloat64x2OperationX86X64.cpp
4340
SimdInt16x8Operation.cpp
44-
SimdInt16x8OperationX86X64.cpp
41+
# SimdInt16x8OperationX86X64.cpp
4542
SimdInt32x4Operation.cpp
46-
SimdInt32x4OperationX86X64.cpp
43+
# SimdInt32x4OperationX86X64.cpp
4744
SimdInt8x16Operation.cpp
48-
SimdInt8x16OperationX86X64.cpp
45+
# SimdInt8x16OperationX86X64.cpp
4946
SimdUint16x8Operation.cpp
50-
SimdUint16x8OperationX86X64.cpp
47+
# SimdUint16x8OperationX86X64.cpp
5148
SimdUint32x4Operation.cpp
52-
SimdUint32x4OperationX86X64.cpp
49+
# SimdUint32x4OperationX86X64.cpp
5350
SimdUint8x16Operation.cpp
54-
SimdUint8x16OperationX86X64.cpp
55-
SimdUtils.cpp
51+
# SimdUint8x16OperationX86X64.cpp
52+
# SimdUtils.cpp
5653
SourceDynamicProfileManager.cpp
5754
SourceTextModuleRecord.cpp
5855
StackTraceArguments.cpp
5956
TaggedInt.cpp
6057
ValueType.cpp
61-
amd64\AsmJsJitTemplate.cpp
62-
amd64\StackFrame.cpp
63-
arm64\StackFrame.cpp
64-
arm\StackFrame.cpp
65-
i386\AsmJsJitTemplate.cpp
66-
i386\StackFrame.cpp
58+
amd64/AsmJsJitTemplate.cpp
59+
# amd64/StackFrame.cpp
60+
# arm64/StackFrame.cpp
61+
# arm/StackFrame.cpp
62+
# i386/AsmJsJitTemplate.cpp
63+
# i386/StackFrame.cpp
64+
)
65+
66+
include_directories (
67+
../Math
6768
)
6869

6970
target_include_directories (

lib/Runtime/Language/CacheOperators.inl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ namespace Js
435435
// polymorphic inline cache. Once resized, bailouts would populate only the new set of caches and full JIT would
436436
// continue to use to old set of caches.
437437
Assert(!info->AllowResizingPolymorphicInlineCache() || info->GetFunctionBody());
438-
if((includeTypePropertyCache && !createTypePropertyCache || info->AllowResizingPolymorphicInlineCache()) &&
438+
if(((includeTypePropertyCache && !createTypePropertyCache) || info->AllowResizingPolymorphicInlineCache()) &&
439439
polymorphicInlineCache->HasDifferentType<IsAccessor>(isProto, type, typeWithoutProperty))
440440
{
441441
if(info->AllowResizingPolymorphicInlineCache() && polymorphicInlineCache->CanAllocateBigger())

lib/Runtime/Language/InterpreterStackFrame.cpp

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,7 +1833,7 @@ namespace Js
18331833
// Allocate invalidVar on GC instead of stack since this InterpreterStackFrame will out live the current real frame
18341834
Js::RecyclableObject* invalidVar = (Js::RecyclableObject*)RecyclerNewPlusLeaf(functionScriptContext->GetRecycler(), sizeof(Js::RecyclableObject), Var);
18351835
AnalysisAssert(invalidVar);
1836-
memset(invalidVar, 0xFE, sizeof(Js::RecyclableObject));
1836+
memset(reinterpret_cast<void*>(invalidVar), 0xFE, sizeof(Js::RecyclableObject));
18371837
newInstance = setup.InitializeAllocation(allocation, executeFunction->GetHasImplicitArgIns(), doProfile, loopHeaderArray, stackAddr, invalidVar);
18381838
#else
18391839
newInstance = setup.InitializeAllocation(allocation, executeFunction->GetHasImplicitArgIns(), doProfile, loopHeaderArray, stackAddr);
@@ -1894,7 +1894,7 @@ namespace Js
18941894

18951895
#if DBG
18961896
Js::RecyclableObject * invalidStackVar = (Js::RecyclableObject*)_alloca(sizeof(Js::RecyclableObject));
1897-
memset(invalidStackVar, 0xFE, sizeof(Js::RecyclableObject));
1897+
memset(reinterpret_cast<void*>(invalidStackVar), 0xFE, sizeof(Js::RecyclableObject));
18981898
newInstance = setup.InitializeAllocation(allocation, executeFunction->GetHasImplicitArgIns() && !isAsmJs, doProfile, loopHeaderArray, stackAddr, invalidStackVar);
18991899
#else
19001900
newInstance = setup.InitializeAllocation(allocation, executeFunction->GetHasImplicitArgIns() && !isAsmJs, doProfile, loopHeaderArray, stackAddr);
@@ -2769,7 +2769,7 @@ namespace Js
27692769
Output::Print(_u("\n"));
27702770
}
27712771

2772-
#ifndef TEMP_DISABLE_ASMJS
2772+
#ifndef TEMP_DISABLE_ASMJS
27732773
// Function memory allocation should be done the same way as
27742774
// T AsmJsCommunEntryPoint(Js::ScriptFunction* func, ...) (AsmJSJitTemplate.cpp)
27752775
// update any changes there
@@ -3718,7 +3718,7 @@ namespace Js
37183718
{
37193719
flags |= CallFlags_NotUsed;
37203720
Arguments args(CallInfo((CallFlags)flags, playout->ArgCount), m_outParams);
3721-
AssertMsg(args.Info.Flags == flags, "Flags don't fit into the CallInfo field?");
3721+
AssertMsg(static_cast<unsigned>(args.Info.Flags) == flags, "Flags don't fit into the CallInfo field?");
37223722
if (spreadIndices != nullptr)
37233723
{
37243724
JavascriptFunction::CallSpreadFunction(function, function->GetEntryPoint(), args, spreadIndices);
@@ -3732,7 +3732,7 @@ namespace Js
37323732
{
37333733
flags |= CallFlags_Value;
37343734
Arguments args(CallInfo((CallFlags)flags, playout->ArgCount), m_outParams);
3735-
AssertMsg(args.Info.Flags == flags, "Flags don't fit into the CallInfo field?");
3735+
AssertMsg(static_cast<unsigned>(args.Info.Flags) == flags, "Flags don't fit into the CallInfo field?");
37363736
if (spreadIndices != nullptr)
37373737
{
37383738
SetReg((RegSlot)playout->Return, JavascriptFunction::CallSpreadFunction(function, function->GetEntryPoint(), args, spreadIndices));
@@ -5298,21 +5298,17 @@ namespace Js
52985298

52995299
Assert(VirtualTableInfo<JavascriptArray>::HasVirtualTable(array));
53005300
SparseArraySegment<Var>* lastUsedSeg = (SparseArraySegment<Var>*)array->GetLastUsedSegment();
5301-
if (index < lastUsedSeg->left)
5301+
if (index >= lastUsedSeg->left)
53025302
{
5303-
goto helper;
5304-
}
5305-
5306-
uint32 index2 = index - lastUsedSeg->left;
5307-
5308-
if (index2 < lastUsedSeg->size)
5309-
{
5310-
// Successful fastpath
5311-
array->DirectSetItemInLastUsedSegmentAt(index2, value);
5312-
return;
5303+
uint32 index2 = index - lastUsedSeg->left;
5304+
if (index2 < lastUsedSeg->size)
5305+
{
5306+
// Successful fastpath
5307+
array->DirectSetItemInLastUsedSegmentAt(index2, value);
5308+
return;
5309+
}
53135310
}
53145311

5315-
helper:
53165312
ScriptContext* scriptContext = array->GetScriptContext();
53175313
JavascriptOperators::SetItem(array, array, index, value, scriptContext);
53185314
}
@@ -7588,7 +7584,7 @@ const byte * InterpreterStackFrame::OP_ProfiledLoopBodyStart(const byte * ip)
75887584
values[5] = (int16) GetRegRawInt(playout->I6);
75897585
values[6] = (int16) GetRegRawInt(playout->I7);
75907586
values[7] = (int16) GetRegRawInt(playout->I8);
7591-
7587+
75927588
AsmJsSIMDValue result = SIMDInt16x8Operation::OpInt16x8(values);
75937589
SetRegRawSimd(playout->I8_0, result);
75947590
}
@@ -7621,7 +7617,7 @@ const byte * InterpreterStackFrame::OP_ProfiledLoopBodyStart(const byte * ip)
76217617
template <class T>
76227618
void InterpreterStackFrame::OP_SimdUint16x8(const unaligned T* playout)
76237619
{
7624-
7620+
76257621
uint16 values[8];
76267622
values[0] = (uint16) GetRegRawInt(playout->I1);
76277623
values[1] = (uint16) GetRegRawInt(playout->I2);
@@ -7631,7 +7627,7 @@ const byte * InterpreterStackFrame::OP_ProfiledLoopBodyStart(const byte * ip)
76317627
values[5] = (uint16) GetRegRawInt(playout->I6);
76327628
values[6] = (uint16) GetRegRawInt(playout->I7);
76337629
values[7] = (uint16) GetRegRawInt(playout->I8);
7634-
7630+
76357631
AsmJsSIMDValue result = SIMDUint16x8Operation::OpUint16x8(values);
76367632
SetRegRawSimd(playout->U8_0, result);
76377633
}
@@ -7686,7 +7682,7 @@ const byte * InterpreterStackFrame::OP_ProfiledLoopBodyStart(const byte * ip)
76867682
values[5] = GetRegRawInt(playout->I6) ? true : false;
76877683
values[6] = GetRegRawInt(playout->I7) ? true : false;
76887684
values[7] = GetRegRawInt(playout->I8) ? true : false;
7689-
7685+
76907686
AsmJsSIMDValue result = SIMDBool16x8Operation::OpBool16x8(values);
76917687
SetRegRawSimd(playout->B8_0, result);
76927688
}
@@ -7711,7 +7707,7 @@ const byte * InterpreterStackFrame::OP_ProfiledLoopBodyStart(const byte * ip)
77117707
values[13] = GetRegRawInt(playout->I14) ? true : false;
77127708
values[14] = GetRegRawInt(playout->I15) ? true : false;
77137709
values[15] = GetRegRawInt(playout->I16) ? true : false;
7714-
7710+
77157711
AsmJsSIMDValue result = SIMDBool8x16Operation::OpBool8x16(values);
77167712
SetRegRawSimd(playout->B16_0, result);
77177713
}
@@ -8334,7 +8330,7 @@ const byte * InterpreterStackFrame::OP_ProfiledLoopBodyStart(const byte * ip)
83348330
return JavascriptOperators::OP_ResumeYield(yieldData, iterator);
83358331
}
83368332

8337-
void* InterpreterStackFrame::operator new(size_t byteSize, void* previousAllocation)
8333+
void* InterpreterStackFrame::operator new(size_t byteSize, void* previousAllocation) throw()
83388334
{
83398335
//
83408336
// Placement 'new' is used by InterpreterStackFrame to initialize the C++ object on the RcInterpreter's
@@ -8350,7 +8346,7 @@ const byte * InterpreterStackFrame::OP_ProfiledLoopBodyStart(const byte * ip)
83508346
return previousAllocation;
83518347
}
83528348

8353-
void __cdecl InterpreterStackFrame::operator delete(void * allocationToFree, void * previousAllocation)
8349+
void __cdecl InterpreterStackFrame::operator delete(void * allocationToFree, void * previousAllocation) throw()
83548350
{
83558351
AssertMsg(allocationToFree == previousAllocation, "Memory locations should match");
83568352
AssertMsg(false, "This function should never actually be called");

lib/Runtime/Language/JavascriptConversion.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
#include "Library/DateImplementation.h"
1010
#include "Library/JavascriptDate.h"
1111

12-
extern "C" PVOID _ReturnAddress(VOID);
13-
#pragma intrinsic(_ReturnAddress)
14-
1512
namespace Js
1613
{
1714
static const double k_2to16 = 65536.0;

0 commit comments

Comments
 (0)