Skip to content

Update Binaryen #1700

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
Mar 5, 2021
Merged

Update Binaryen #1700

merged 24 commits into from
Mar 5, 2021

Conversation

dcodeIO
Copy link
Member

@dcodeIO dcodeIO commented Feb 23, 2021

As usual, this gets us up to date with the latest changes in Binaryen. Quite a bit of chaos here with missing C-APIs that may be good to tackle.

  • I've read the contributing guidelines

@dcodeIO
Copy link
Member Author

dcodeIO commented Feb 23, 2021

Some notes I made so I don't forget

// Features (WebAssembly/binaryen#3603)

  • _BinaryenFeatureTypedFunctionReferences
SIMD constants

// Unary

  • _BinaryenPopcntVecI8x16
  • _BinaryenBitmaskVecI64x2
  • _BinaryenExtAddPairwiseSVecI8x16ToI16x8
  • _BinaryenExtAddPairwiseUVecI8x16ToI16x8
  • _BinaryenExtAddPairwiseSVecI16x8ToI32x4
  • _BinaryenExtAddPairwiseUVecI16x8ToI32x4
  • _BinaryenWidenLowSVecI32x4ToVecI64x2
  • _BinaryenWidenHighSVecI32x4ToVecI64x2
  • _BinaryenWidenLowUVecI32x4ToVecI64x2
  • _BinaryenWidenHighUVecI32x4ToVecI64x2
  • _BinaryenConvertLowSVecI32x4ToVecF64x2
  • _BinaryenConvertLowUVecI32x4ToVecF64x2
  • _BinaryenTruncSatZeroSVecF64x2ToVecI32x4
  • _BinaryenTruncSatZeroUVecF64x2ToVecI32x4
  • _BinaryenDemoteZeroVecF64x2ToVecF32x4
  • _BinaryenPromoteLowVecF32x4ToVecF64x2

// Binary

  • _BinaryenQ15MulrSatSVecI16x8
  • _BinaryenExtMulLowSVecI16x8
  • _BinaryenExtMulHighSVecI16x8
  • _BinaryenExtMulLowUVecI16x8
  • _BinaryenExtMulHighUVecI16x8
  • _BinaryenExtMulLowSVecI64x2
  • _BinaryenExtMulHighSVecI64x2
  • _BinaryenExtMulLowUVecI64x2
  • _BinaryenExtMulHighUVecI64x2

// SIMDTernary

  • _BinaryenSignSelectVec8x16
  • _BinaryenSignSelectVec16x8
  • _BinaryenSignSelectVec32x4
  • _BinaryenSignSelectVec64x2

// SIMDLoad

  • _BinaryenLoad32Zero
  • _BinaryenLoad64Zero

// SIMDLoadStoreLane

  • _BinaryenLoadLaneVec8x16
  • _BinaryenLoadLaneVec16x8
  • _BinaryenLoadLaneVec32x4
  • _BinaryenLoadLaneVec64x2
  • _BinaryenStoreLaneVec8x16
  • _BinaryenStoreLaneVec16x8
  • _BinaryenStoreLaneVec32x4
  • _BinaryenStoreLaneVec64x2

// SIMDWiden

  • _BinaryenWidenSVecI8x16ToVecI32x4
  • _BinaryenWidenUVecI8x16ToVecI32x4

// Prefetch (obsolete)

  • _BinaryenPrefetchTemporal
  • _BinaryenPrefetchNontemporal

// RefAs (WebAssembly/binaryen#3628)

  • API
  • _BinaryenRefAsNonNull
  • _BinaryenRefAsFunc
  • _BinaryenRefAsData
  • _BinaryenRefAsI31

// BrOn

  • API
  • _BinaryenBrOnNull
  • _BinaryenBrOnCast
  • _BinaryenBrOnFunc
  • _BinaryenBrOnData
  • _BinaryenBrOnI31

// RefIs (WebAssembly/binaryen#3605)

  • _BinaryenRefIsGetOp
  • _BinaryenRefIsSetOp

// I31New

  • API

// I31Get

  • API

// Table (WebAssembly/binaryen#3604)

  • _BinaryenTableSetName
  • _BinaryenTableGetInitial -> int is BinaryenIndex
  • _BinaryenTableSetInitial
  • _BinaryenTableGetMax -> int is BinaryenIndex
  • _BinaryenTableSetMax
  • _BinaryenSetFunctionTable before Add/ImportTable breaks ("already exists")

Turns out that most of the Unary/Binary/SIMD constants fall under SIMD, and have TODO comments in Binaryen. While I found the implementation status document meanwhile, I'll wait a bit on these so I don't accidentally get into the way.

@MaxGraey
Copy link
Member

MaxGraey commented Feb 23, 2021

Seems it still slower on 1.7 times for binaryen's optimization compared with v98. Could we create issue about this in Binaryen repo?

@dcodeIO
Copy link
Member Author

dcodeIO commented Feb 24, 2021

I haven't investigated the slowdown myself, so I guess you have more information on it than I have. Could you make one? :)

@AurelienRibon
Copy link

Impressive work. How to do implement such migration? Updating the lib version and seeing what fails?

@dcodeIO
Copy link
Member Author

dcodeIO commented Feb 24, 2021

My process there is typically:

  • Blindly upgrade the Binaryen dependency to the latest version
  • Go to src/binaryen-c.h in the Binaryen repo and click "History"
  • Work my way through what has changed or is new
    • Update src/glue/binaryen.d.ts
    • Refactor name and API changes in the compiler to mirror the d.ts
  • Run scripts/update-constants to sync the constants, which will print errors if something is still off
  • Run the test suite and evaluate fixture changes
  • Fix or improve Binaryen
  • Bonus: Implement new features in AS

@AurelienRibon
Copy link

Interesting, thank you, that's really a nice update process.

@MaxGraey
Copy link
Member

I'm wondering may be this WebAssembly/binaryen#3609 fix issue with not always de-dupllicate functions?

@dcodeIO
Copy link
Member Author

dcodeIO commented Feb 25, 2021

Going to check once we have a build :)

@tlively
Copy link

tlively commented Feb 26, 2021

@MaxGraey it would be great if you could file a Binaryen issue for the slowdown.

@dcodeIO
Copy link
Member Author

dcodeIO commented Feb 26, 2021

I'm wondering may be this WebAssembly/binaryen#3609 fix issue with not always de-dupllicate functions?

Seems the fixtures didn't change

@dcodeIO
Copy link
Member Author

dcodeIO commented Feb 26, 2021

Making myself a handy list of SIMD instructions so I don't forget to check one

// Memory

  • v128.load
  • v128.load8x8_s
  • v128.load8x8_u
  • v128.load16x4_s
  • v128.load16x4_u
  • v128.load32x2_s
  • v128.load32x2_u
  • v128.load8_splat
  • v128.load16_splat
  • v128.load32_splat
  • v128.load64_splat
  • v128.store

// Basic

  • v128.const
  • i8x16.shuffle
  • i8x16.swizzle

// Splat

  • i8x16.splat
  • i16x8.splat
  • i32x4.splat
  • i64x2.splat
  • f32x4.splat
  • f64x2.splat

// Lane

  • i8x16.extract_lane_s
  • i8x16.extract_lane_u
  • i8x16.replace_lane
  • i16x8.extract_lane_s
  • i16x8.extract_lane_u
  • i16x8.replace_lane
  • i32x4.extract_lane
  • i32x4.replace_lane
  • i64x2.extract_lane
  • i64x2.replace_lane
  • f32x4.extract_lane
  • f32x4.replace_lane
  • f64x2.extract_lane
  • f64x2.replace_lane

// Cmp

  • i8x16.eq
  • i16x8.eq
  • i32x4.eq
  • i8x16.ne
  • i16x8.ne
  • i32x4.ne
  • i8x16.lt_s
  • i16x8.lt_s
  • i32x4.lt_s
  • i8x16.lt_u
  • i16x8.lt_u
  • i32x4.lt_u
  • i8x16.gt_s
  • i16x8.gt_s
  • i32x4.gt_s
  • i8x16.gt_u
  • i16x8.gt_u
  • i32x4.gt_u
  • i8x16.le_s
  • i16x8.le_s
  • i32x4.le_s
  • i8x16.le_u
  • i16x8.le_u
  • i32x4.le_u
  • i8x16.ge_s
  • i16x8.ge_s
  • i32x4.ge_s
  • i8x16.ge_u
  • i16x8.ge_u
  • i32x4.ge_u
  • f32x4.eq
  • f64x2.eq
  • f32x4.ne
  • f64x2.ne
  • f32x4.lt
  • f64x2.lt
  • f32x4.gt
  • f64x2.gt
  • f32x4.le
  • f64x2.le
  • f32x4.ge
  • f64x2.ge

// v128

  • v128.not
  • v128.and
  • v128.andnot
  • v128.or
  • v128.xor
  • v128.bitselect
  • v128.any_true

// Load lane

  • v128.load8_lane (missing in Binaryen)
  • v128.load16_lane (missing in Binaryen)
  • v128.load32_lane (missing in Binaryen)
  • v128.load64_lane (missing in Binaryen)
  • v128.store8_lane (missing in Binaryen)
  • v128.store16_lane (missing in Binaryen)
  • v128.store32_lane (missing in Binaryen)
  • v128.store64_lane (missing in Binaryen)
  • v128.load32_zero (missing in Binaryen)
  • v128.load64_zero (missing in Binaryen)

// Float conversion

  • f32x4.demote_f64x2_zero (missing in Binaryen)
  • f64x2.promote_low_f32x4 (missing in Binaryen)

// iAxB

  • i8x16.abs
  • i16x8.abs
  • i32x4.abs
  • i64x2.abs (missing in Binaryen)
  • i8x16.neg
  • i16x8.neg
  • i32x4.neg
  • i64x2.neg
  • i8x16.popcnt (missing in Binaryen)
  • i16x8.q15mulr_sat_s (missing in Binaryen)
  • i8x16.all_true
  • i16x8.all_true
  • i32x4.all_true
  • i64x2.all_true
  • i8x16.bitmask
  • i16x8.bitmask
  • i32x4.bitmask
  • i64x2.bitmask (missing in Binaryen)
  • i8x16.narrow_i16x8_s
  • i16x8.narrow_i32x4_s
  • i8x16.narrow_i16x8_u
  • i16x8.narrow_i32x4_u
  • f32x4.ceil
  • i16x8.extend_low_i8x16_s
  • i32x4.extend_low_i16x8_s
  • i64x2.extend_low_i32x4_s
  • f32x4.floor
  • i16x8.extend_high_i8x16_s
  • i32x4.extend_high_i16x8_s
  • i64x2.extend_high_i32x4_s
  • f32x4.trunc
  • i16x8.extend_low_i8x16_u
  • i32x4.extend_low_i16x8_u
  • i64x2.extend_low_i32x4_u
  • f32x4.nearest
  • i16x8.extend_high_i8x16_u
  • i32x4.extend_high_i16x8_u
  • i64x2.extend_high_i32x4_u
  • i8x16.shl
  • i16x8.shl
  • i32x4.shl
  • i64x2.shl
  • i8x16.shr_s
  • i16x8.shr_s
  • i32x4.shr_s
  • i64x2.shr_s
  • i8x16.shr_u
  • i16x8.shr_u
  • i32x4.shr_u
  • i64x2.shr_u
  • i8x16.add
  • i16x8.add
  • i32x4.add
  • i64x2.add
  • i8x16.add_sat_s
  • i16x8.add_sat_s
  • i8x16.add_sat_u
  • i16x8.add_sat_u
  • i8x16.sub
  • i16x8.sub
  • i32x4.sub
  • i64x2.sub
  • i8x16.sub_sat_s
  • i16x8.sub_sat_s
  • i8x16.sub_sat_u
  • i16x8.sub_sat_u
  • f64x2.ceil
  • f64x2.nearest
  • f64x2.floor
  • i16x8.mul
  • i32x4.mul
  • i64x2.mul (missing in Binaryen)
  • i8x16.min_s
  • i16x8.min_s
  • i32x4.min_s
  • i64x2.eq (missing in Binaryen)
  • i8x16.min_u
  • i16x8.min_u
  • i32x4.min_u
  • i64x2.ne (missing in Binaryen)
  • i8x16.max_s
  • i16x8.max_s
  • i32x4.max_s
  • i64x2.lt_s (missing in Binaryen)
  • i8x16.max_u
  • i16x8.max_u
  • i32x4.max_u
  • i64x2.gt_s (missing in Binaryen)
  • f64x2.trunc
  • i32x4.dot_i16x8_s
  • i64x2.le_s (missing in Binaryen)
  • i8x16.avgr_u
  • i16x8.avgr_u
  • i64x2.ge_s (missing in Binaryen)
  • i16x8.extadd_pairwise_i8x16_s (missing in Binaryen)
  • i16x8.extmul_low_i8x16_s (missing in Binaryen)
  • i32x4.extmul_low_i16x8_s (missing in Binaryen)
  • i64x2.extmul_low_i32x4_s (missing in Binaryen)
  • i16x8.extadd_pairwise_i8x16_u (missing in Binaryen)
  • i16x8.extmul_high_i8x16_s (missing in Binaryen)
  • i32x4.extmul_high_i16x8_s (missing in Binaryen)
  • i64x2.extmul_high_i32x4_s (missing in Binaryen)
  • i32x4.extadd_pairwise_i16x8_s (missing in Binaryen)
  • i16x8.extmul_low_i8x16_u (missing in Binaryen)
  • i32x4.extmul_low_i16x8_u (missing in Binaryen)
  • i64x2.extmul_low_i32x4_u (missing in Binaryen)
  • i32x4.extadd_pairwise_i16x8_u (missing in Binaryen)
  • i16x8.extmul_high_i8x16_u (missing in Binaryen)
  • i32x4.extmul_high_i16x8_u (missing in Binaryen)
  • i64x2.extmul_high_i32x4_u (missing in Binaryen)

// fAxB

  • f32x4.abs
  • f64x2.abs
  • f32x4.neg
  • f64x2.neg
  • f32x4.sqrt
  • f64x2.sqrt
  • f32x4.add
  • f64x2.add
  • f32x4.sub
  • f64x2.sub
  • f32x4.mul
  • f64x2.mul
  • f32x4.div
  • f64x2.div
  • f32x4.min
  • f64x2.min
  • f32x4.max
  • f64x2.max
  • f32x4.pmin
  • f64x2.pmin
  • f32x4.pmax
  • f64x2.pmax

// Conversion

  • i32x4.trunc_sat_f32x4_s
  • i32x4.trunc_sat_f32x4_u
  • f32x4.convert_i32x4_s
  • f32x4.convert_i32x4_u
  • i32x4.trunc_sat_f64x2_s_zero (missing in Binaryen)
  • i32x4.trunc_sat_f64x2_u_zero (missing in Binaryen)
  • f64x2.convert_low_i32x4_s (missing in Binaryen)
  • f64x2.convert_low_i32x4_u (missing in Binaryen)

TODO

  • i8x16.mul removed
  • add_saturate_s/u renamed to add_sat_s/u
  • A.any_true unified to v128.any_true -> currently generic
  • i64x2.trunc_sat_f64x2_s/u removed
  • f32x4/f64x2.qfma/qfms removed
  • f64x2.convert_i64x2_s/u removed

@dcodeIO
Copy link
Member Author

dcodeIO commented Mar 3, 2021

I guess this one is fine to go now, given that the remaining constants and bindings are missing, we don't have a cast story for GC types yet, so I'll have to look into this again anyhow. The lists above should be useful then.

@dcodeIO dcodeIO requested a review from MaxGraey March 3, 2021 12:28
@MaxGraey
Copy link
Member

MaxGraey commented Mar 3, 2021

@dcodeIO Thanks for this excellent job! I'll check little bit later. But I'm would like report about slowdown issue of binaryen. Try to bisect version when this happened

Copy link
Member

@MaxGraey MaxGraey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw couple missed pieces for ref_is / ref_as. I guess this still not implemented on binaryen?

LGTM.

@dcodeIO
Copy link
Member Author

dcodeIO commented Mar 5, 2021

Right, we cannot yet make proper use of these without an initial implementation of Wasm GC, but it's good to keep the bindings up to date already so everything's there once we can :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants