Wasmtime: Add x64 lowering support to new cranelift backend

Created on 10 Jun 2020  路  16Comments  路  Source: bytecodealliance/wasmtime

Wasm instructions
Wasm Instruction | Primary Clif | Planned Start | Patch Pushed | Patch Merged | Comments
------------ | ------------- | ------------- | ------------- | ------------- | -------------
f32.add | Fadd |@jlb6740 | #1665 | [x] |
f64.add | Fadd | | | [] |
f32.sub | Fsub |@jlb6740 | #1665 | [x] |
f64.sub | Fsub | | | [ ] |
f32.mul | Fmul |@jlb6740 | #1797 | [x] |
f64.mul | Fmul | | | [ ] |
f32.div | Fdiv |@jlb6740 | #1797 | [x] |
f64.div | Fdiv | | | [ ] |
f32.sqrt | Sqrt | | | [ ] |
f64.sqrt | Sqrt | | | [ ] |
f32.min | Fmin |@jlb6740 | | [ ] |
f64.min | Fmin | | | [ ] |
f32.max | Fmax | @jlb6740 | | [ ] |
f64.max | Fmax | | | [ ] |
f32.ceil | Ceil | | | [ ] |
f64.ceil | Ceil | | | [ ] |
f32.floor | Floor | | | [ ] |
f64.floor | Floor | | | [ ] |
f32.trunc | Trunc | | | [ ] |
f64.trunc | Trunc | | | [ ] |
f32.nearest | Nearest | | | [ ] |
f64.nearest | Nearest || | [ ] |
f32.abs | Fabs | | | [ ] |
f64.abs | Fabs | | | [ ] |
f32.neg | Fneg | | | [ ] |
f64.neg | Fneg | | | [ ] |
f32.copysign | Fcopysign |@jlb6740 | #1837 | [x ] |
f64.copysign | Fcopysign | | | [ ] |

Other Related Clif Instruction
Clif Instruction | How Used | Planned Start | Patch Pushed | Patch Merged | Comments
------------ | ------------ | ------------- | ------------- | ------------- | -------------
Store | trampoline | @bnjbvr / @jlb6740 (flt) |#1915, #1862| [ ] |
Load | trampoline | @bnjbvr / @jlb6740 (flt) |#1915, #1932| [ ] |
Call | | @bnjbvr | | [ ] |
CallIndirect | trampoline |@bnjbvr | | [ ] |
StackStore | | | | [ ] |
StackAddr| | @bnjbvr | | [ ] |
StackLoad | | | | [ ] |
Select | | @bnjbvr | | [ ] |
Trap/DebugTrap | trap handling | @bnjbvr | | |
Band/Bor | | @bnjbvr | | |
BranchTable | | @bnjbvr | | |

cranelift

Most helpful comment

I've done all of the above, and there might not be a lot remaining, so I'm happy to pick up all the remaining opcodes required for the wasm mvp support! There might be small subtle bugs in the integer support, so that'll be my next task, unless somebody found them before i get to it.

All 16 comments

For cg_clif:

  • [ ] stack_addr, stack_load and stack_store
  • [ ] select

@julian-seward1 @bnjbvr
Hi @bjorn3 thanks I've added these. Are you working on these now or planning to? Not sure there is such a thing as a publicly editable comment, but I will keep this table updated based on comments and patches I see.

Are you working on these now or planning to?

I am not working on them.

I'll work on direct and indirect calls.

I have a local patch that contains enough to compile and run integer-based code in wasmtime (a recursive fibonacci function), so I had to implement lowering for integer stores/loads and a few more; I've updated the table and should put up the patch for review tomorrow.

Fwiw, I've updated the table again; I plan to implement all the integer + control flow opcodes, so if somebody wants to help with those, let's sync :-)

Fwiw, I've updated the table again; I plan to implement all the integer + control flow opcodes, so if somebody wants to help with those, let's sync :-)

Currently I am looking at the next flt, most likely min/max but with example I'm sure I could help here.

Subscribe to Label Action

cc @bnjbvr


This issue or pull request has been labeled: "cranelift"

Thus the following users have been cc'd because of the following labels:

  • bnjbvr: cranelift

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

I've started implementing FP support in #2004, and plan to add the following (unless somebody beats me to it :-)) : Fcmp, Bitcast, float cmove, FCvtFromSint.

I've started implementing FP support in #2004, and plan to add the following (unless somebody beats me to it :-)) : Fcmp, Bitcast, float cmove, FCvtFromSint.

Note I've submitted a start to Fcmp here: https://github.com/bytecodealliance/wasmtime/pull/2011

Also started on Bitcast.

I'm done with float cmove; my planned next steps should be, in this order:

  • fcvt_to_sint
  • fcvt_to_uint
  • fabs
  • fneg
  • floor (and probably the few other friends ceil etc.)

I've done all of the above, and there might not be a lot remaining, so I'm happy to pick up all the remaining opcodes required for the wasm mvp support! There might be small subtle bugs in the integer support, so that'll be my next task, unless somebody found them before i get to it.

@Bnjbvr Sorry I've blinked and now you've moved much faster than me on these implementations. I didn't see a PR for those you listed? I'd like to contribute to at least a few more of what's left. I started Fmin and Fmax a while ago but abandoned them ... can try to add those again if you haven't started?

Really not much FP remaining but I can help on what is there or other int related ones. Just doing a comparison with ARM this is what I see left where probably over half are nops and or are Vector/SIMD related.

// Probably need some kind of implementation
Opcode::BConst
Opcode::Null
Opcode::UaddSat
Opcode::SaddSat
Opcode::UsubSat
Opcode::SsubSat
Opcode::Ineg
Opcode::Bnot
Opcode::BandNot
Opcode::BorNot
Opcode::BxorNot
Opcode::Bitrev
Opcode::Cls
Opcode::Sload8x8
Opcode::Uload8x8
Opcode::Sload16x4
Opcode::Uload16x4
Opcode::Sload32x2
Opcode::Uload32x2
Opcode::ConstAddr
Opcode::Nop // Trivial
Opcode::Bitselect
Opcode::Trueif
Opcode::Trueff
Opcode::IsNull
Opcode::IsInvalid
Opcode::Copy
Opcode::Bint
Opcode::Bmask
Opcode::Debugtrap
Opcode::Trapif
Opcode::Trapff
Opcode::Safepoint
Opcode::Brif
Opcode::Brff
Opcode::IndirectJumpTableBr
Opcode::BrTable
Opcode::Vconst
Opcode::RawBitcast
Opcode::Extractlane
Opcode::Splat
Opcode::VanyTrue
Opcode::VallTrue
Opcode::Shuffle
Opcode::Vsplit
Opcode::Vconcat
Opcode::Vselect
Opcode::Insertlane
Opcode::ScalarToVector
Opcode::Swizzle
Opcode::Uload8x8Complex
Opcode::Sload8x8Complex
Opcode::Uload16x4Complex
Opcode::Sload16x4Complex
Opcode::Uload32x2Complex
Opcode::Sload32x2Complex
Opcode::Isplit
Opcode::Iconcat
Opcode::Imax
Opcode::Umax
Opcode::Umin
Opcode::Imin
Opcode::Fmin
Opcode::Fmax
Opcode::Ceil
Opcode::Floor
Opcode::Trunc
Opcode::Nearest
Opcode::Fma
Opcode::FcvtFromUint
Opcode::FcvtFromSint
Opcode::FcvtToUintSat
Opcode::FcvtToSintSat
Opcode::IaddIfcout // Why implemented for AArch64 but should not appear for x64?
Opcode::IcmpImm
Opcode::IfcmpImm
Opcode::DummySargT
Opcode::Iabs
Opcode::AvgRound
Opcode::Snarrow
Opcode::Unarrow
Opcode::SwidenLow
Opcode::SwidenHigh
Opcode::UwidenLow
Opcode::UwidenHigh
Opcode::TlsValue

// Likely not used (legalization, etc)
Opcode::StackLoad
Opcode::StackStore
Opcode::TableAddr
Opcode::Ifcmp
Opcode::Ffcmp
Opcode::JumpTableEntry
Opcode::JumpTableBase
Opcode::Trapz
Opcode::Trapnz
Opcode::ResumableTrapnz
Opcode::GlobalValue
Opcode::Spill
Opcode::Fill
Opcode::FillNop
Opcode::Regmove
Opcode::CopySpecial
Opcode::CopyToSsa
Opcode::CopyNop
Opcode::AdjustSpDown
Opcode::AdjustSpUpImm
Opcode::AdjustSpDownImm
Opcode::IfcmpSp
Opcode::Regspill
Opcode::Regfill
Opcode::Vconst

// Known TODOs
Opcode::F64const
Opcode::F32const

No worries! I'll open the PR today, so we can sync better. I haven't tested using Wasmtime yet, so more work might be needed for this, and help would be appreciated.

Opcode::IaddIfcout // Why implemented for AArch64 but should not appear for x64?

Probably an outdated comment in x64; it might happen if the cranelift user requested explicit bounds checks, if i remember correctly.

No worries! I'll open the PR today, so we can sync better. I haven't tested using Wasmtime yet, so more work might be needed for this, and help would be appreciated.

Opcode::IaddIfcout // Why implemented for AArch64 but should not appear for x64?

Probably an outdated comment in x64; it might happen if the cranelift user requested explicit bounds checks, if i remember correctly.

Hi .. no sorry, that was my comment. There is a case for it in X64 that says should not appear,

https://github.com/bytecodealliance/wasmtime/blob/main/cranelift/codegen/src/isa/x64/lower.rs#L1428:L1446

but in AArch64 it is implemented:

https://github.com/bytecodealliance/wasmtime/blob/main/cranelift/codegen/src/isa/aarch64/lower_inst.rs#L2105:L2132

Not familiar with this opcode but I haven't seen cases where there needed to be an AArch64 implementation but not X64.

Obsolete

Was this page helpful?
0 / 5 - 0 ratings