-
Notifications
You must be signed in to change notification settings - Fork 201
Implement vconst instruction for x86 #868
Implement vconst instruction for x86 #868
Conversation
sunfishcode
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, overall this looks really good!
c7dc251 to
380ccfa
Compare
380ccfa to
1e0ab76
Compare
|
After talking to @yurydelendik (thanks for the help!) and debugging the execution of these instructions in wasmtime, I realized that the relocation offsets I initially implemented for constants were not going to work. I mirrored the jump table implementation in cranelift as best I could without fully understanding how wasmtime does relocation. After talking to @yurydelendik I realized that wasmtime is currently not relocating the jump tables from where they are emitted in by running the following: The breaking change from this PR that wasmtime (and other cranelift users) will have to absorb is the new |
|
@arunetm, here is a |
|
@sunfishcode, @bnjbvr: as we discussed, I added code in cranelift-wasm to keep track of the values from |
2d5865a to
13cca99
Compare
|
@sunfishcode rebased this as well and is ready for review; as a reminder, we will have to update |
sunfishcode
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good, just a few comments below:
d5a679c to
cb4bfec
Compare
sunfishcode
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, overall this looks good, just a few comments below:
| let constants: Vec<Constant> = func.dfg.constants.iter().map(|(h, _)| h.clone()).collect(); | ||
| for constant_handle in constants { | ||
| func.dfg.constants.set_offset(constant_handle, offset); | ||
| offset += func.dfg.constants.get(constant_handle).len() as u32 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use try_from() to convert to u32 here. It may not be possible to create a 4 GiB constant today, but if anyone ever could, silent wraparound here would be a subtle bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
cranelift-codegen/src/ir/constant.rs
Outdated
| /// its constant data (i.e. [ConstantData](ir::constant::ConstantData)) | ||
| #[derive(Clone)] | ||
| pub struct ConstantPool { | ||
| // this mapping maintains the insertion order as long as Constants are created with sequentially increasing integers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a comment forms a substantial sentence, please capitalize it and end it with a period.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Went through and added periods to all the comments in this file.
Examining wasm-objdump revealed that it stores SIMD constants in little-endian order, e.g.: 000071 func[2] <test_const>: 000072: fd 02 01 00 00 00 02 00 00 | v128.const 0x00000001 0x00000002 0x00000003 0x00000004 00007b: 00 03 00 00 00 04 00 00 00 | 000084: fd 0d 03 | i32x4.extract_lane 3 000087: 0b | end This change avoids confusion by making the CLIF representation use little-endian order as well.
By default, constants added by SIMD's v128.const will be typed as I8x16 in CLIF. This type must be changed to the appropriate vector type before use to satisfy cranelift's type checking. To do this, we track what SSA values are created by v128.const and convert them with a raw_bitcast immediately before use in the currently implemented SIMD instructions.
To do so we must use a new version of wabt-rs that allows us to enable features (e.g. SIMD) when translating the wasmtests
86aa687 to
5128e19
Compare
sunfishcode
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
This PR also adds a simple constant pool implementation based on the discussion in abrown#2. Some form of constant pool is necessary because vector constants of 128-bits (the current cranelift vector size) must be emitted separately--in
rodatamemory--for the x86 instructions to move them in to the XMM registers.This PR depends on commits waiting to be merged in #855.