Skip to content

Commit da1cddb

Browse files
committed
Add Interpreter implementation for atomic loads
Cleanup Uses of ArrayBufferView type
1 parent 36f8ccd commit da1cddb

13 files changed

+248
-231
lines changed

lib/Parser/rterrors.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ RT_ERROR_MSG(WASMERR_InvalidImportModule, 7026, "Import module '%s' is invalid",
409409
RT_ERROR_MSG(WASMERR_InvalidImport, 7027, "Import '%s.%s' is invalid. Expected type %s", "Import is invalid", kjstTypeError, 0)
410410
RT_ERROR_MSG(WASMERR_InvalidInitialSize, 7028, "Imported %s initial size (%u) is smaller than declared (%u)", "Invalid initial size", kjstWebAssemblyLinkError, 0)
411411
RT_ERROR_MSG(WASMERR_InvalidMaximumSize, 7029, "Imported %s maximum size (%u) is larger than declared (%u)", "Invalid initial size", kjstWebAssemblyLinkError, 0)
412+
RT_ERROR_MSG(WASMERR_UnalignedAtomicAccess, 7030, "", "Atomic memory access is unaligned", kjstWebAssemblyRuntimeError, 0)
412413

413414
// Wabt Errors
414415
RT_ERROR_MSG(WABTERR_WabtError, 7200, "%s", "Wabt Error.", kjstTypeError, 0)

lib/Runtime/ByteCode/AsmJsByteCodeDumper.cpp

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -517,36 +517,8 @@ namespace Js
517517
{
518518
switch (type)
519519
{
520-
case ArrayBufferView::TYPE_INT8:
521-
tag->heapTag = _u("HEAP8"); tag->valueTag = 'I'; break;
522-
case ArrayBufferView::TYPE_UINT8:
523-
tag->heapTag = _u("HEAPU8"); tag->valueTag = 'U'; break;
524-
case ArrayBufferView::TYPE_INT16:
525-
tag->heapTag = _u("HEAP16"); tag->valueTag = 'I'; break;
526-
case ArrayBufferView::TYPE_UINT16:
527-
tag->heapTag = _u("HEAPU16"); tag->valueTag = 'U'; break;
528-
case ArrayBufferView::TYPE_INT32:
529-
tag->heapTag = _u("HEAP32"); tag->valueTag = 'I'; break;
530-
case ArrayBufferView::TYPE_UINT32:
531-
tag->heapTag = _u("HEAPU32"); tag->valueTag = 'U'; break;
532-
case ArrayBufferView::TYPE_FLOAT32:
533-
tag->heapTag = _u("HEAPF32"); tag->valueTag = 'F'; break;
534-
case ArrayBufferView::TYPE_FLOAT64:
535-
tag->heapTag = _u("HEAPF64"); tag->valueTag = 'D'; break;
536-
case ArrayBufferView::TYPE_INT64:
537-
tag->heapTag = _u("HEAPI64"); tag->valueTag = 'L'; break;
538-
case ArrayBufferView::TYPE_INT8_TO_INT64:
539-
tag->heapTag = _u("HEAP8"); tag->valueTag = 'L'; break;
540-
case ArrayBufferView::TYPE_UINT8_TO_INT64:
541-
tag->heapTag = _u("HEAPU8"); tag->valueTag = 'L'; break;
542-
case ArrayBufferView::TYPE_INT16_TO_INT64:
543-
tag->heapTag = _u("HEAP16"); tag->valueTag = 'L'; break;
544-
case ArrayBufferView::TYPE_UINT16_TO_INT64:
545-
tag->heapTag = _u("HEAPU16"); tag->valueTag = 'L'; break;
546-
case ArrayBufferView::TYPE_INT32_TO_INT64:
547-
tag->heapTag = _u("HEAP32"); tag->valueTag = 'L'; break;
548-
case ArrayBufferView::TYPE_UINT32_TO_INT64:
549-
tag->heapTag = _u("HEAPU32"); tag->valueTag = 'L'; break;
520+
#define ARRAYBUFFER_VIEW(name, align, reg, mem, t1, t2) case ArrayBufferView::TYPE_##name: tag->heapTag = _u(#t1); tag->valueTag = _u(t2); break;
521+
#include "Language/AsmJsArrayBufferViews.h"
550522
default:
551523
Assume(UNREACHED);
552524
}
@@ -580,8 +552,10 @@ namespace Js
580552
switch (op)
581553
{
582554
case OpCodeAsmJs::LdArrWasm:
555+
case OpCodeAsmJs::LdArrAtomic:
583556
Output::Print(_u(" %c%d = %s[I%d + %d]"), tag.valueTag, data->Value, tag.heapTag, data->SlotIndex, data->Offset); break;
584557
case OpCodeAsmJs::StArrWasm:
558+
case OpCodeAsmJs::StArrAtomic:
585559
Output::Print(_u(" %s[I%d + %d] = %c%d"), tag.heapTag, data->SlotIndex, data->Offset, tag.valueTag, data->Value); break;
586560
default:
587561
Assume(UNREACHED);

lib/Runtime/ByteCode/OpCodesAsmJs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ MACRO_WMS ( CheckSignature , Reg1IntConst1 , None
144144
// Array Buffer manipulations
145145
MACRO_WMS ( LdArrWasm , WasmMemAccess , None )
146146
MACRO_WMS ( StArrWasm , WasmMemAccess , None )
147+
MACRO_EXTEND_WMS( LdArrAtomic , WasmMemAccess , None )
148+
MACRO_EXTEND_WMS( StArrAtomic , WasmMemAccess , None )
147149
MACRO_WMS ( LdArr , AsmTypedArr , None )
148150
MACRO_WMS ( LdArrConst , AsmTypedArr , None )
149151
MACRO_WMS ( StArr , AsmTypedArr , None )
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//-------------------------------------------------------------------------------------------------------
2+
// Copyright (C) Microsoft Corporation and contributors. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
4+
// Portions of this file are copyright 2014 Mozilla Foundation, available under the Apache 2.0 license.
5+
//-------------------------------------------------------------------------------------------------------
6+
7+
#ifndef ARRAYBUFFER_VIEW
8+
#error ARRAYBUFFER_VIEW Macro must be defined before including this file
9+
// ARRAYBUFFER_VIEW(name, align, reg, mem, heapTag, valueTag)
10+
#endif
11+
12+
// (Name , NaturalAlignment, reg , mem , heapTag, valueTag)
13+
ARRAYBUFFER_VIEW(INT8 , 0 , int32, int8, HEAP8 , 'I' )
14+
ARRAYBUFFER_VIEW(UINT8 , 0 , int32, uint8, HEAPU8 , 'U' )
15+
ARRAYBUFFER_VIEW(INT16 , 1 , int32, int16, HEAP16 , 'I' )
16+
ARRAYBUFFER_VIEW(UINT16 , 1 , int32, uint16, HEAPU16, 'U' )
17+
ARRAYBUFFER_VIEW(INT32 , 2 , int32, int32, HEAP32 , 'I' )
18+
ARRAYBUFFER_VIEW(UINT32 , 2 , int32, uint32, HEAPU32, 'U' )
19+
ARRAYBUFFER_VIEW(FLOAT32 , 2 , float, float, HEAPF32, 'F' )
20+
ARRAYBUFFER_VIEW(FLOAT64 , 3 , double, double, HEAPF64, 'D' )
21+
ARRAYBUFFER_VIEW(INT64 , 3 , int64, int64, HEAPI64, 'L' )
22+
ARRAYBUFFER_VIEW(INT8_TO_INT64 , 0 , int64, int8, HEAP8 , 'L' )
23+
ARRAYBUFFER_VIEW(UINT8_TO_INT64 , 0 , int64, uint8, HEAPU8 , 'L' )
24+
ARRAYBUFFER_VIEW(INT16_TO_INT64 , 1 , int64, int16, HEAP16 , 'L' )
25+
ARRAYBUFFER_VIEW(UINT16_TO_INT64 , 1 , int64, uint16, HEAPU16, 'L' )
26+
ARRAYBUFFER_VIEW(INT32_TO_INT64 , 2 , int64, int32, HEAP32 , 'L' )
27+
ARRAYBUFFER_VIEW(UINT32_TO_INT64 , 2 , int64, uint32, HEAPU32, 'L' )
28+
29+
#undef ARRAYBUFFER_VIEW

lib/Runtime/Language/AsmJsTypes.h

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -59,41 +59,22 @@ namespace Js
5959
{
6060
enum ViewType: uint8
6161
{
62-
TYPE_INT8 = 0,
63-
TYPE_UINT8,
64-
TYPE_INT16,
65-
TYPE_UINT16,
66-
TYPE_INT32,
67-
TYPE_UINT32,
68-
TYPE_FLOAT32,
69-
TYPE_FLOAT64,
70-
TYPE_INT64,
71-
TYPE_INT8_TO_INT64,
72-
TYPE_UINT8_TO_INT64,
73-
TYPE_INT16_TO_INT64,
74-
TYPE_UINT16_TO_INT64,
75-
TYPE_INT32_TO_INT64,
76-
TYPE_UINT32_TO_INT64,
62+
#define ARRAYBUFFER_VIEW(name, ...) TYPE_##name,
63+
#include "AsmJsArrayBufferViews.h"
7764
TYPE_COUNT
7865
};
7966

67+
const uint32 NaturalAlignment[ArrayBufferView::TYPE_COUNT] =
68+
{
69+
#define ARRAYBUFFER_VIEW(name, align, ...) align,
70+
#include "AsmJsArrayBufferViews.h"
71+
};
72+
73+
#define ARRAYBUFFER_VIEW_MASK(align) ((uint32)~((1 << align) - 1))
8074
const uint32 ViewMask[] =
8175
{
82-
(uint32)~0 //TYPE_INT8
83-
, (uint32)~0 //TYPE_UINT8
84-
, (uint32)~1 //TYPE_INT16
85-
, (uint32)~1 //TYPE_UINT16
86-
, (uint32)~3 //TYPE_INT32
87-
, (uint32)~3 //TYPE_UINT32
88-
, (uint32)~3 //TYPE_FLOAT32
89-
, (uint32)~7 //TYPE_FLOAT64
90-
, (uint32)~7 //TYPE_INT64
91-
, (uint32)~0 //TYPE_INT8_TO_INT64
92-
, (uint32)~0 //TYPE_UINT8_TO_UINT64
93-
, (uint32)~1 //TYPE_INT16_TO_INT64
94-
, (uint32)~1 //TYPE_UINT16_TO_UINT64
95-
, (uint32)~3 //TYPE_INT32_TO_INT64
96-
, (uint32)~3 //TYPE_UINT32_TO_UINT64
76+
#define ARRAYBUFFER_VIEW(name, align, ...) ARRAYBUFFER_VIEW_MASK(align),
77+
#include "AsmJsArrayBufferViews.h"
9778
};
9879

9980
} /* namespace ArrayBufferView */

lib/Runtime/Language/Chakra.Runtime.Language.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@
188188
<ExcludedFromBuild Condition="'$(Platform)'!='ARM'">true</ExcludedFromBuild>
189189
</ClInclude>
190190
<ClInclude Include="AsmJs.h" />
191+
<ClInclude Include="AsmJsArrayBufferViews.h" />
191192
<ClInclude Include="AsmJsByteCodeGenerator.h" />
192193
<ClInclude Include="AsmJsCodeGenerator.h" />
193194
<ClInclude Include="AsmJsEncoder.h">

lib/Runtime/Language/Chakra.Runtime.Language.vcxproj.filters

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<ItemGroup>
44
<ClCompile Include="$(MsBuildThisFileDirectory)AsmJS.cpp" />
@@ -149,6 +149,7 @@
149149
<ClInclude Include="ModuleNamespaceEnumerator.h" />
150150
<ClInclude Include="WebAssemblySource.h" />
151151
<ClInclude Include="ConstructorCache.h" />
152+
<ClInclude Include="AsmJsArrayBufferViews.h" />
152153
</ItemGroup>
153154
<ItemGroup>
154155
<MASM Include="$(MSBuildThisFileDirectory)amd64\amd64_Thunks.asm">
@@ -215,4 +216,4 @@
215216
<Filter>arm64</Filter>
216217
</ARMASM>
217218
</ItemGroup>
218-
</Project>
219+
</Project>

lib/Runtime/Language/InterpreterHandlerAsmJs.inl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ EXDEF2 (NOPASMJS , InvalidOpCode, Empty
5252
DEF3_WMS( CUSTOM_ASMJS , LdArr , OP_LdArrGeneric , AsmTypedArr )
5353
DEF3_WMS( CUSTOM_ASMJS , LdArrWasm , OP_LdArrWasm , WasmMemAccess )
5454
DEF3_WMS( CUSTOM_ASMJS , StArrWasm , OP_StArrWasm , WasmMemAccess )
55+
EXDEF3_WMS( CUSTOM_ASMJS , LdArrAtomic , OP_LdArrAtomic , WasmMemAccess )
56+
EXDEF3_WMS( CUSTOM_ASMJS , StArrAtomic , OP_StArrAtomic , WasmMemAccess )
5557
DEF3_WMS( CUSTOM_ASMJS , LdArrConst , OP_LdArrConstIndex , AsmTypedArr )
5658
DEF3_WMS( CUSTOM_ASMJS , StArr , OP_StArrGeneric , AsmTypedArr )
5759
DEF3_WMS( CUSTOM_ASMJS , StArrConst , OP_StArrConstIndex , AsmTypedArr )

0 commit comments

Comments
 (0)