Skip to content

Commit

Permalink
Bug 1559965 - Wasm: Implement new atomic.fence instruction. r=bbouvier
Browse files Browse the repository at this point in the history
This commit implements the 'atomic.fence' Wasm instruction.

Issue: WebAssembly/threads#140
Overview: WebAssembly/threads#141

The instruction is encoded as, 0xFE 0x03, with a reserved byte trailing for a future
memory order immediate. The instruction is implemented by emitting a memoryBarrier
through the macro assembler.

Differential Revision: https://phabricator.services.mozilla.com/D39264

UltraBlame original commit: d32c27f13f21b0927cbfb7ce6f8509c0dea6bf09
  • Loading branch information
marco-c committed Oct 4, 2019
1 parent c75dd93 commit 6841db4
Show file tree
Hide file tree
Showing 14 changed files with 639 additions and 1 deletion.
2 changes: 1 addition & 1 deletion js/src/jit-test/tests/wasm/binary.js
Original file line number Diff line number Diff line change
Expand Up @@ -3565,7 +3565,7 @@ for
let
i
=
3
0x4
;
i
<
Expand Down
70 changes: 70 additions & 0 deletions js/src/jit-test/tests/wasm/fence.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
wasmFullPass
(
(
module
(
func
atomic
.
fence
)
(
export
"
run
"
0
)
)
)
;
wasmFullPass
(
(
module
(
memory
1
)
(
func
atomic
.
fence
)
(
export
"
run
"
0
)
)
)
;
wasmFullPass
(
(
module
(
memory
1
1
shared
)
(
func
atomic
.
fence
)
(
export
"
run
"
0
)
)
)
;
29 changes: 29 additions & 0 deletions js/src/jit/CodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88089,6 +88089,35 @@ types
)
;
}
void
CodeGenerator
:
:
visitWasmFence
(
LWasmFence
*
lir
)
{
MOZ_ASSERT
(
gen
-
>
compilingWasm
(
)
)
;
masm
.
memoryBarrier
(
MembarFull
)
;
}
static_assert
(
!
Expand Down
24 changes: 24 additions & 0 deletions js/src/jit/Lowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36364,6 +36364,30 @@ TrueExprIndex
)
;
}
void
LIRGenerator
:
:
visitWasmFence
(
MWasmFence
*
ins
)
{
add
(
new
(
alloc
(
)
)
LWasmFence
ins
)
;
}
static_assert
(
!
Expand Down
51 changes: 51 additions & 0 deletions js/src/jit/MIR.h
Original file line number Diff line number Diff line change
Expand Up @@ -55460,6 +55460,57 @@ WasmHeap
}
;
class
MWasmFence
:
public
MNullaryInstruction
{
protected
:
MWasmFence
(
)
:
MNullaryInstruction
(
classOpcode
)
{
setGuard
(
)
;
}
public
:
INSTRUCTION_HEADER
(
WasmFence
)
TRIVIAL_NEW_WRAPPERS
AliasSet
getAliasSet
(
)
const
override
{
return
AliasSet
:
:
None
(
)
;
}
ALLOW_CLONE
(
MWasmFence
)
}
;
class
MWasmCompareExchangeHeap
:
public
Expand Down
31 changes: 31 additions & 0 deletions js/src/jit/shared/LIR-shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -34386,6 +34386,37 @@ toWasmCompareExchangeHeap
}
;
class
LWasmFence
:
public
LInstructionHelper
<
0
0
0
>
{
public
:
LIR_HEADER
(
WasmFence
)
;
explicit
LWasmFence
(
)
:
LInstructionHelper
(
classOpcode
)
{
}
}
;
class
LWasmAtomicExchangeHeap
:
public
Expand Down
35 changes: 35 additions & 0 deletions js/src/wasm/WasmAST.h
Original file line number Diff line number Diff line change
Expand Up @@ -2281,6 +2281,7 @@ UnaryOperator
Unreachable
Wait
Wake
Fence
}
;
class
Expand Down Expand Up @@ -4418,6 +4419,40 @@ count_
}
}
;
struct
AstFence
:
AstExpr
{
static
const
AstExprKind
Kind
=
AstExprKind
:
:
Fence
;
AstFence
(
)
:
AstExpr
(
AstExprKind
:
:
Fence
ExprType
:
:
Void
)
{
}
}
;
class
AstMemOrTableCopy
:
Expand Down
64 changes: 64 additions & 0 deletions js/src/wasm/WasmBaselineCompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32990,6 +32990,12 @@ emitWake
;
MOZ_MUST_USE
bool
emitFence
(
)
;
MOZ_MUST_USE
bool
emitAtomicXchg
(
ValType
Expand Down Expand Up @@ -48962,6 +48968,48 @@ bool
BaseCompiler
:
:
emitFence
(
)
{
if
(
!
iter_
.
readFence
(
)
)
{
return
false
;
}
if
(
deadCode_
)
{
return
true
;
}
masm
.
memoryBarrier
(
MembarFull
)
;
return
true
;
}
bool
BaseCompiler
:
:
bulkmemOpsEnabled
(
)
Expand Down Expand Up @@ -57329,6 +57377,22 @@ uint32_t
ThreadOp
:
:
Fence
)
:
CHECK_NEXT
(
emitFence
(
)
)
;
case
uint32_t
(
ThreadOp
:
:
I32AtomicLoad
)
:
Expand Down
3 changes: 3 additions & 0 deletions js/src/wasm/WasmConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,9 @@ I32Wait
I64Wait
=
0x02
Fence
=
0x03
I32AtomicLoad
=
0x10
Expand Down
Loading

0 comments on commit 6841db4

Please sign in to comment.