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

cmd/compile: the loong64 intrinsic for CompareAndSwapUint32 function needs to sign extend its "old" argument. #57282

Closed
abner-chenc opened this issue Dec 13, 2022 · 8 comments
Labels
arch-loong64 Issues solely affecting the loongson architecture. arch-mips arch-riscv Issues solely affecting the riscv64 architecture. compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@abner-chenc
Copy link
Contributor

What version of Go are you using (go version)?

$ go version
go version devel go1.20-b16e94d13d Mon Dec 12 23:10:52 2022 +0000 linux/loong64

Does this issue reproduce with the latest release?

What operating system and processor architecture are you using (go env)?

go env Output
$ go env

What did you do?

package main

import (
	"fmt"
	. "sync/atomic"
)

const (
	_magic = 0xfbcdefaf
)

func main() {
	var x struct {
		before uint32
		i      uint32
		after  uint32

		o uint32
		n uint32
	}

	x.before = _magic
	x.after = _magic

	for t := uint32(0x7FFFFFF0); t < 0x80000003; t += 1 {
		x.i = t + 0
		x.o = t + 0
		x.n = t + 1

		if !CompareAndSwapUint32(&x.i, x.o, x.n) {
			panic(fmt.Sprintf("should have swapped %#x %#x", x.o, x.n))
		}

		if x.i != x.n {
			panic(fmt.Sprintf("wrong x.i after swap: x.i=%#x x.n=%#x", x.i, x.n))
		}

		if x.before != _magic || x.after != _magic {
			panic(fmt.Sprintf("wrong magic: %#x _ %#x != %#x _ %#x", x.before, x.after, _magic, _magic))
		}
	}
}

What did you expect to see?


(i.e. no output)

What did you see instead?

panic: should have swapped 0x80000000 0x80000001

goroutine 1 [running]:
main.main()
	/home/chenguoqi/atomic.go:31 +0x31c
@gopherbot
Copy link

Change https://go.dev/cl/457135 mentions this issue: cmd/compile: sign extension the 2nd argument of the AtomicCas32 op on loong64

@abner-chenc
Copy link
Contributor Author

@golang/loong64

@wdvxdr1123
Copy link
Contributor

I reproduced this issue on linux/riscv64.

@thanm thanm added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Dec 13, 2022
@gopherbot
Copy link

Change https://go.dev/cl/457535 mentions this issue: cmd/compile: sign extension the 2nd argument of the AtomicCas32 op on mips64x

@gopherbot
Copy link

Change https://go.dev/cl/457536 mentions this issue: cmd/compile: sign extension the 2nd argument of the AtomicCas32 op on riscv64

@dr2chase
Copy link
Contributor

Checked that it does NOT repro on ppc64le (seemed unlikely, however trust-but-verify).

@dr2chase dr2chase changed the title sync/atomic:The execution result of the CompareAndSwapUint32 function is unexpected on linux/loong64 cmd/compile: the loong64 intrinsic for CompareAndSwapUint32 function needs to sign extend its "old" argument. Dec 15, 2022
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Dec 15, 2022
@dr2chase
Copy link
Contributor

@gopherbot please open backport issues.

@gopherbot
Copy link

Backport issue(s) opened: #57344 (for 1.18), #57345 (for 1.19).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases.

@XiaodongLoong XiaodongLoong added the arch-loong64 Issues solely affecting the loongson architecture. label Dec 18, 2022
@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. arch-riscv Issues solely affecting the riscv64 architecture. arch-mips and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Dec 28, 2022
@dmitshur dmitshur added this to the Go1.20 milestone Dec 28, 2022
@golang golang locked and limited conversation to collaborators Dec 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-loong64 Issues solely affecting the loongson architecture. arch-mips arch-riscv Issues solely affecting the riscv64 architecture. compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

7 participants