From ab197698b9e6bdfca62f31fab48d33f1dc3c7f25 Mon Sep 17 00:00:00 2001 From: titzer Date: Wed, 23 Sep 2015 14:22:13 +0200 Subject: [PATCH 1/4] Update AstSemantics.md --- AstSemantics.md | 73 +++++++++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 32 deletions(-) diff --git a/AstSemantics.md b/AstSemantics.md index b778c2aa..fde0504a 100644 --- a/AstSemantics.md +++ b/AstSemantics.md @@ -82,38 +82,47 @@ only communicate through messaging, e.g. in browsers using `postMessage`. It will be possible to share linear memory between threads of execution when [threads](PostMVP.md#threads) are added. -### Linear Memory Operations - -Linear memory operations are annotated with a memory type and perform a -conversion between that memory type and a local type. - -Loads read data from linear memory, convert from their memory type to a basic -type, and return the result: - - * `i32.load8_s`: sign-extend i8 to i32 - * `i32.load8_u`: zero-extend i8 to i32 - * `i32.load16_s`: sign-extend i16 to i32 - * `i32.load16_u`: zero-extend i16 to i32 - * `i32.load`: (no conversion) - * `i64.load`: (no conversion) - * `f32.load`: (no conversion) - * `f64.load`: (no conversion) - -Stores have an operand providing a value to store. They convert from the value's -local type to their memory type, and write the resulting value to linear memory: - - * `i32.store8`: wrap i32 to i8 - * `i32.store16`: wrap i32 to i16 - * `i32.store`: (no conversion) - * `i64.store`: (no conversion) - * `f32.store`: (no conversion) - * `f64.store`: (no conversion) - -Wrapping of integers simply discards any upper bits; i.e. wrapping does not -perform saturation, trap on overflow, etc. - -In addition to storing a value to linear memory, store instructions also -reproduce their value operand, with no conversion applied. +### Linear Memory Accesses + +Linear memory access is accomplished with explicit `load` and `store` operations that +accept as input an `index` operand that is interpreted as a unsigned byte offset into the +linear memory. + +Integer loads can specify a size which is smaller than the result type as well as a +signedness. Such integer loads perform an implicit sign- or zero-extension as specified below. + + * `i32.load8_s`: load 1 byte and sign-extend i8 to i32 + * `i32.load8_u`: load 1 byte and zero-extend i8 to i32 + * `i32.load16_s`: load 2 bytes and sign-extend i16 to i32 + * `i32.load16_u`: load 2 bytes and zero-extend i16 to i32 + * `i32.load`: load 4 bytes as i32 + * `i64.load8_s`: load 1 byte and sign-extend i8 to i64 + * `i64.load8_u`: load 1 byte and zero-extend i8 to i64 + * `i64.load16_s`: load 2 bytes and sign-extend i16 to i64 + * `i64.load16_u`: load 2 bytes and zero-extend i16 to i64 + * `i64.load32_s`: load 4 bytes and sign-extend i32 to i64 + * `i64.load32_u`: load 4 bytes and zero-extend i32 to i64 + * `i64.load`: load 8 bytes as i64 + * `f32.load`: load 4 bytes as f32 + * `f64.load`: load 8 bytes as f64 + +In addition to an `index` operand, stores have an additional input operand which is the +`value` to store to memory. Like loads, integer stores may specify a smaller size than the +operand size and include an implicit integer wrap operation which discards the upper bits. +Stores write only the bytes in the linear memory corresponding to their size. + + * `i32.store8`: wrap i32 to i8 and store 1 byte + * `i32.store16`: wrap i32 to i16 and store 2 bytes + * `i32.store`: (no conversion) store 4 bytes + * `i64.store8`: wrap i64 to i8 and store 1 byte + * `i64.store16`: wrap i64 to i16 and store 2 bytes + * `i64.store32`: wrap i64 to i32 and store 4 bytes + * `i64.store`: (no conversion) store 8 bytes + * `f32.store`: (no conversion) store 4 bytes + * `f64.store`: (no conversion) store 8 bytes + +In addition to storing to memory, store instructions produce a value which is their +input operand without conversion. ### Addressing From 3633b92bc26ed00f2dda87ea024e4e5375507847 Mon Sep 17 00:00:00 2001 From: titzer Date: Wed, 23 Sep 2015 15:34:42 +0200 Subject: [PATCH 2/4] Update AstSemantics.md --- AstSemantics.md | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/AstSemantics.md b/AstSemantics.md index fde0504a..5fd97c1a 100644 --- a/AstSemantics.md +++ b/AstSemantics.md @@ -84,10 +84,7 @@ will be possible to share linear memory between threads of execution when ### Linear Memory Accesses -Linear memory access is accomplished with explicit `load` and `store` operations that -accept as input an `index` operand that is interpreted as a unsigned byte offset into the -linear memory. - +Linear memory access is accomplished with explicit `load` and `store` operations. Integer loads can specify a size which is smaller than the result type as well as a signedness. Such integer loads perform an implicit sign- or zero-extension as specified below. @@ -106,8 +103,8 @@ signedness. Such integer loads perform an implicit sign- or zero-extension as sp * `f32.load`: load 4 bytes as f32 * `f64.load`: load 8 bytes as f64 -In addition to an `index` operand, stores have an additional input operand which is the -`value` to store to memory. Like loads, integer stores may specify a smaller size than the +Stores have an additional input operand which is the `value` to store to memory. +Like loads, integer stores may specify a smaller size than the operand size and include an implicit integer wrap operation which discards the upper bits. Stores write only the bytes in the linear memory corresponding to their size. From 0050c509077978d81ee5740cb97664d558e8ed49 Mon Sep 17 00:00:00 2001 From: titzer Date: Wed, 23 Sep 2015 15:35:27 +0200 Subject: [PATCH 3/4] Update AstSemantics.md --- AstSemantics.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AstSemantics.md b/AstSemantics.md index 5fd97c1a..10443b3f 100644 --- a/AstSemantics.md +++ b/AstSemantics.md @@ -118,8 +118,8 @@ Stores write only the bytes in the linear memory corresponding to their size. * `f32.store`: (no conversion) store 4 bytes * `f64.store`: (no conversion) store 8 bytes -In addition to storing to memory, store instructions produce a value which is their -input operand without conversion. +In addition to storing to memory, store instructions produce a value which is their +`value` input operand without conversion. ### Addressing From 23fabe448e9eba74ff2a5b02cac2e5f5cc5eb85f Mon Sep 17 00:00:00 2001 From: titzer Date: Wed, 23 Sep 2015 15:36:19 +0200 Subject: [PATCH 4/4] Update AstSemantics.md --- AstSemantics.md | 1 - 1 file changed, 1 deletion(-) diff --git a/AstSemantics.md b/AstSemantics.md index 10443b3f..7455052d 100644 --- a/AstSemantics.md +++ b/AstSemantics.md @@ -106,7 +106,6 @@ signedness. Such integer loads perform an implicit sign- or zero-extension as sp Stores have an additional input operand which is the `value` to store to memory. Like loads, integer stores may specify a smaller size than the operand size and include an implicit integer wrap operation which discards the upper bits. -Stores write only the bytes in the linear memory corresponding to their size. * `i32.store8`: wrap i32 to i8 and store 1 byte * `i32.store16`: wrap i32 to i16 and store 2 bytes