Skip to content
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

Fix vector's Narrow intrinsics #81843

Merged
merged 1 commit into from
Feb 9, 2023

Conversation

radekdoulik
Copy link
Member

The BCL Vector classes have non-saturating Narrow methods, while wasm instructions are saturating. AFAIK wasm does not have non-saturating narrow instructions. So instead of

i8x16.narrow_i16x8_s
i8x16.narrow_i16x8_u
i16x8.narrow_i32x4_s
i16x8.narrow_i32x4_u

use v8x16.shuffle instruction to implement the extract narrow operation.

This fixes System.Numerics.Tests.GenericVectorTests.Narrow[U]Int* tests.

The BCL Vector classes have non-saturating Narrow methods, while wasm
instructions are saturating. AFAIK wasm doesn;t have non-saturating
narrow instructions. So instead of using

    i8x16.narrow_i16x8_s
    i8x16.narrow_i16x8_u
    i16x8.narrow_i32x4_s
    i16x8.narrow_i32x4_u

instructions, use `v8x16.shuffle` instruction to implement the extract
narrow operation.

This fixes `System.Numerics.Tests.GenericVectorTests.Narrow[U]Int*`
tests.
@radekdoulik
Copy link
Member Author

Example of emitted code:

> wa-info.exe -d -f Narrow.*16 dotnet.wasm
  ...
  local.get $2
  local.get $2
  v128.load offset:80 align:4    [SIMD]
  local.get $2
  v128.load offset:96 align:4    [SIMD]
  i8x16.shuffle 0x1e1c1a18161412100e0c0a0806040200    [SIMD]
  v128.store offset:112 align:4    [SIMD]
  ...

@tannergooding
Copy link
Member

Worth noting that saturating narrow is coming: #75724

So might be worth keeping the logic easily accessible so we can turn it back on when the new APIs are added.

@EgorBo
Copy link
Member

EgorBo commented Feb 8, 2023

@radekdoulik what is the easiest option to check codegen/LLVM IR for a SIMD operation in WASM? I assume I need to use one of the WASM samples but how/where do I specify MONO_VERBOSE_METHOD ?

@radekdoulik
Copy link
Member Author

@radekdoulik what is the easiest option to check codegen/LLVM IR for a SIMD operation in WASM? I assume I need to use one of the WASM samples but how/where do I specify MONO_VERBOSE_METHOD ?

I usually use llvm-dis on .bc files. Sometime I call mono aot crosscompiler by hand and then it should be possible to use MONO_VERBOSE_METHOD.

For checking generated wasm code I use wa-info -d -f .... https://github.com/radekdoulik/wa-info#installation

@EgorBo
Copy link
Member

EgorBo commented Feb 8, 2023

@radekdoulik what is the easiest option to check codegen/LLVM IR for a SIMD operation in WASM? I assume I need to use one of the WASM samples but how/where do I specify MONO_VERBOSE_METHOD ?

I usually use llvm-dis on .bc files. Sometime I call mono aot crosscompiler by hand and then it should be possible to use MONO_VERBOSE_METHOD.

For checking generated wasm code I use wa-info -d -f .... https://github.com/radekdoulik/wa-info#installation

which sample would you recommend to use for that?

@vargaz
Copy link
Contributor

vargaz commented Feb 9, 2023

The easiest is probably src/mono/samples/wasm/console-v8.
Build it using make AOT=1
The .bc files are in
artifacts/obj/mono/Wasm.Console.V8.Sample/wasm/Release/browser-wasm/wasm/for-publish/.

@vargaz
Copy link
Contributor

vargaz commented Feb 9, 2023

If you want to run the cross compiler by hand, build the sample using:
make AOT=1 MSBUILD_ARGS="/v:d"
then grep MONO_PATH in the output to find the cross compiler invocations.

@radekdoulik
Copy link
Member Author

The failing build is #81859

@radekdoulik radekdoulik merged commit 4da62e4 into dotnet:main Feb 9, 2023
@runfoapp runfoapp bot mentioned this pull request Feb 9, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Mar 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants