Skip to content

Commit cb1fdec

Browse files
authored
Merge pull request #53 from WebAssembly/logarithmic_rep
Use logarithm of page size in intermediate representation
2 parents 604baa1 + 677f291 commit cb1fdec

File tree

6 files changed

+7
-11
lines changed

6 files changed

+7
-11
lines changed

interpreter/binary/decode.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ let globaltype s =
296296

297297
let memorytype s =
298298
let at, lim = limits u64 s in
299-
MemoryT (at, lim, PageT 0x10000) (* TODO(custom-page-sizes) *)
299+
MemoryT (at, lim, PageT 16) (* TODO(custom-page-sizes) *)
300300

301301
let tabletype s =
302302
let t = reftype s in

interpreter/host/spectest.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ let table64 =
2828
ExternTable (Table.alloc tt (NullRef FuncHT))
2929

3030
let memory =
31-
let mt = MemoryT (I32AT, {min = 1L; max = Some 2L}, PageT 0x10000) in
31+
let mt = MemoryT (I32AT, {min = 1L; max = Some 2L}, PageT 16) in
3232
ExternMemory (Memory.alloc mt)
3333

3434
let func f ts1 ts2 =

interpreter/runtime/memory.ml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ exception SizeOverflow
1717
exception SizeLimit
1818
exception OutOfMemory
1919

20-
let page_size = 0x10000L (* 64 KiB *)
21-
2220
let valid_limits {min; max} =
2321
match max with
2422
| None -> true
@@ -31,7 +29,7 @@ let valid_size at i =
3129

3230
let create n (PageT ps) =
3331
try
34-
let size = Int64.(mul n (Int64.of_int ps)) in
32+
let size = Int64.(shift_left n ps) in
3533
let mem = Array1_64.create Int8_unsigned C_layout size in
3634
Array1.fill mem 0;
3735
mem
@@ -47,7 +45,7 @@ let bound mem =
4745
Array1_64.dim mem.content
4846

4947
let pagesize mem =
50-
let MemoryT (_, _, PageT x) = mem.ty in Int64.of_int x
48+
let MemoryT (_, _, PageT x) = mem.ty in (Int64.shift_left 1L x)
5149

5250
let size mem =
5351
Int64.(div (bound mem) (pagesize mem))

interpreter/runtime/memory.mli

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ exception SizeOverflow
1414
exception SizeLimit
1515
exception OutOfMemory
1616

17-
val page_size : int64
18-
1917
val alloc : memorytype -> memory (* raises Type, SizeOverflow, OutOfMemory *)
2018
val type_of : memory -> memorytype
2119
val addrtype_of : memory -> addrtype

interpreter/text/parser.mly

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ tabletype :
466466
| addrtype limits reftype { fun c -> TableT ($1, $2, $3 c) }
467467

468468
memorytype :
469-
| addrtype limits { fun c -> MemoryT ($1, $2, PageT 0x10000) }
469+
| addrtype limits { fun c -> MemoryT ($1, $2, PageT 16) }
470470

471471
limits :
472472
| NAT { {min = nat64 $1 $loc($1); max = None} }
@@ -1130,7 +1130,7 @@ memory_fields :
11301130
{ fun c x loc ->
11311131
let size = Int64.(div (add (of_int (String.length $4)) 65535L) 65536L) in
11321132
let offset = [at_const $1 (0L @@ loc) @@ loc] @@ loc in
1133-
[Memory (MemoryT ($1, {min = size; max = Some size}, PageT 0x10000)) @@ loc],
1133+
[Memory (MemoryT ($1, {min = size; max = Some size}, PageT 16)) @@ loc],
11341134
[Data ($4, Active (x, offset) @@ loc) @@ loc],
11351135
[], [] }
11361136

interpreter/valid/valid.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ let check_limits {min; max} range at msg =
105105
"size minimum must not be greater than maximum"
106106

107107
let check_pagetype (PageT ps) at =
108-
require (ps = 0x10000 || ps = 1) at "page size must be 1 or 64KiB"
108+
require (ps = 16 || ps = 0) at "page size must be 1 or 64KiB"
109109

110110
let check_numtype (c : context) (t : numtype) at =
111111
()

0 commit comments

Comments
 (0)