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

popcnt stuck in a loop on M1 and singlepass compiler #3210

Closed
grishasobol opened this issue Sep 30, 2022 · 2 comments
Closed

popcnt stuck in a loop on M1 and singlepass compiler #3210

grishasobol opened this issue Sep 30, 2022 · 2 comments
Assignees
Labels
bug Something isn't working priority-medium Medium priority issue
Milestone

Comments

@grishasobol
Copy link
Contributor

Describe the bug

Using M1 + singlepass compiler causes stucking in loop for that code for example:

(module
  (func $popcnt (export "popcnt") (param i32) (result i32)
      local.get 0
      i32.popcnt
  )
)

If param == 1, then function popcnt call execution lasts forever.

Environment

Use wasmer in Cargo.toml like this:

wasmer = { version = "2.3.0", default-features = false, features = ["default-singlepass", "default-universal", "wat", "sys"] }
$ rustc -V
rustc 1.65.0-nightly (17cbdfd07 2022-09-13)

$ uname -a
... MacBook-Pro.local 21.6.0 Darwin Kernel Version 21.6.0 ... RELEASE_ARM64_T6000 arm64

Steps to reproduce

  1. Clone repo https://github.com/grishasobol/wasmer-fail .
  2. Make cargo test on machine with M1 processor (see Environment above).
  3. Tests must stuck in a loop.

Additional context

This happen because this assembler execution on M1 result conflicts with Aarch64 documentation:

mov w1, 32
mov w2, 1
lsl w3, w2, w1

There will be 1 in w3, but due documentation must be 0. (The same for 64 registers)

You can reproduce this:

  1. take file arm.s.zip
  2. build it
$ as -o arm.o arm.s && ld -o arm arm.o -lSystem -syslibroot `xcrun -sdk macosx --show-sdk-path` -e _start -arch arm64
  1. run it and print return code
$ ./arm ; echo $?
1
@grishasobol grishasobol added the bug Something isn't working label Sep 30, 2022
@syrusakbary syrusakbary added the priority-medium Medium priority issue label Oct 4, 2022
@syrusakbary syrusakbary added this to the v3.0 milestone Oct 4, 2022
bors bot added a commit that referenced this issue Oct 5, 2022
3211: fix popcnt for aarch64 r=ptitSeb a=grishasobol

# Description
Fix problem with infinite `popcnt` WASM instruction execution on M1 processor. See details in corresponded issue: #3210

# Review
1) Make fix for `i32.popcnt`. Use additional execution branch if `src` register equal to `1`:
```
if src == 0 => goto exit_label
if src == 1 => goto src_is_one_label

loop_label:
... // popcnt loop body

goto exit_label

src_is_one_label:
mov dest, 1

exit_label:
```


Co-authored-by: Gregory Sobol <grishasobol@mail.ru>
@syrusakbary
Copy link
Member

This should be fixed by #3211

bors bot added a commit that referenced this issue Oct 5, 2022
3211: fix popcnt for aarch64 r=ptitSeb a=grishasobol

# Description
Fix problem with infinite `popcnt` WASM instruction execution on M1 processor. See details in corresponded issue: #3210

# Review
1) Make fix for `i32.popcnt`. Use additional execution branch if `src` register equal to `1`:
```
if src == 0 => goto exit_label
if src == 1 => goto src_is_one_label

loop_label:
... // popcnt loop body

goto exit_label

src_is_one_label:
mov dest, 1

exit_label:
```


Co-authored-by: Gregory Sobol <grishasobol@mail.ru>
@ptitSeb
Copy link
Contributor

ptitSeb commented Oct 13, 2022

@grishasobol can you confirm the ticket can be closed?

@ptitSeb ptitSeb closed this as completed Nov 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority-medium Medium priority issue
Projects
None yet
Development

No branches or pull requests

3 participants