Skip to content

Commit 14bcc44

Browse files
Runtime.stackAlloc should grow down for wasm (#1073)
* Runtime.stackAlloc should grow down for wasm * stackAlloc should align properly; update tests
1 parent 21e08ee commit 14bcc44

85 files changed

Lines changed: 256 additions & 512 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/wasm-emscripten.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,12 @@ void generateStackAllocFunction(LinkerObject& linker) {
119119
SetLocal* setStackLocal = builder.makeSetLocal(1, loadStack);
120120
GetLocal* getStackLocal = builder.makeGetLocal(1, i32);
121121
GetLocal* getSizeArg = builder.makeGetLocal(0, i32);
122-
Binary* add = builder.makeBinary(AddInt32, getStackLocal, getSizeArg);
122+
Binary* sub = builder.makeBinary(SubInt32, getStackLocal, getSizeArg);
123123
const static uint32_t bitAlignment = 16;
124124
const static uint32_t bitMask = bitAlignment - 1;
125-
Const* addConst = builder.makeConst(Literal(bitMask));
126-
Binary* maskedAdd = builder.makeBinary(
127-
AndInt32,
128-
builder.makeBinary(AddInt32, add, addConst),
129-
builder.makeConst(Literal(~bitMask))
130-
);
131-
Store* storeStack = generateStoreStackPointer(builder, linker, maskedAdd);
125+
Const* subConst = builder.makeConst(Literal(~bitMask));
126+
Binary* maskedSub = builder.makeBinary(AndInt32, sub, subConst);
127+
Store* storeStack = generateStoreStackPointer(builder, linker, maskedSub);
132128

133129
Block* block = builder.makeBlock();
134130
block->list.push_back(setStackLocal);

test/dot_s/alias.wast

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,9 @@
4343
(i32.store offset=4
4444
(i32.const 0)
4545
(i32.and
46-
(i32.add
47-
(i32.add
48-
(get_local $1)
49-
(get_local $0)
50-
)
51-
(i32.const 15)
46+
(i32.sub
47+
(get_local $1)
48+
(get_local $0)
5249
)
5350
(i32.const -16)
5451
)

test/dot_s/alternate-lcomm.wast

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,9 @@
1919
(i32.store offset=4
2020
(i32.const 0)
2121
(i32.and
22-
(i32.add
23-
(i32.add
24-
(get_local $1)
25-
(get_local $0)
26-
)
27-
(i32.const 15)
22+
(i32.sub
23+
(get_local $1)
24+
(get_local $0)
2825
)
2926
(i32.const -16)
3027
)

test/dot_s/asm_const.wast

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,9 @@
3131
(i32.store offset=4
3232
(i32.const 0)
3333
(i32.and
34-
(i32.add
35-
(i32.add
36-
(get_local $1)
37-
(get_local $0)
38-
)
39-
(i32.const 15)
34+
(i32.sub
35+
(get_local $1)
36+
(get_local $0)
4037
)
4138
(i32.const -16)
4239
)

test/dot_s/basics.wast

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,9 @@
112112
(i32.store offset=4
113113
(i32.const 0)
114114
(i32.and
115-
(i32.add
116-
(i32.add
117-
(get_local $1)
118-
(get_local $0)
119-
)
120-
(i32.const 15)
115+
(i32.sub
116+
(get_local $1)
117+
(get_local $0)
121118
)
122119
(i32.const -16)
123120
)

test/dot_s/bcp-1.wast

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -324,12 +324,9 @@
324324
(i32.store offset=4
325325
(i32.const 0)
326326
(i32.and
327-
(i32.add
328-
(i32.add
329-
(get_local $1)
330-
(get_local $0)
331-
)
332-
(i32.const 15)
327+
(i32.sub
328+
(get_local $1)
329+
(get_local $0)
333330
)
334331
(i32.const -16)
335332
)

test/dot_s/data-offset-folding.wast

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,9 @@
2121
(i32.store offset=4
2222
(i32.const 0)
2323
(i32.and
24-
(i32.add
25-
(i32.add
26-
(get_local $1)
27-
(get_local $0)
28-
)
29-
(i32.const 15)
24+
(i32.sub
25+
(get_local $1)
26+
(get_local $0)
3027
)
3128
(i32.const -16)
3229
)

test/dot_s/debug.wast

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,9 @@
7171
(i32.store offset=4
7272
(i32.const 0)
7373
(i32.and
74-
(i32.add
75-
(i32.add
76-
(get_local $1)
77-
(get_local $0)
78-
)
79-
(i32.const 15)
74+
(i32.sub
75+
(get_local $1)
76+
(get_local $0)
8077
)
8178
(i32.const -16)
8279
)

test/dot_s/dso_handle.wast

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,9 @@
2525
(i32.store offset=4
2626
(i32.const 0)
2727
(i32.and
28-
(i32.add
29-
(i32.add
30-
(get_local $1)
31-
(get_local $0)
32-
)
33-
(i32.const 15)
28+
(i32.sub
29+
(get_local $1)
30+
(get_local $0)
3431
)
3532
(i32.const -16)
3633
)

test/dot_s/dyncall.wast

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,9 @@
6565
(i32.store offset=4
6666
(i32.const 0)
6767
(i32.and
68-
(i32.add
69-
(i32.add
70-
(get_local $1)
71-
(get_local $0)
72-
)
73-
(i32.const 15)
68+
(i32.sub
69+
(get_local $1)
70+
(get_local $0)
7471
)
7572
(i32.const -16)
7673
)

0 commit comments

Comments
 (0)