Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/cmd/compile/internal/ssa/_gen/ARM64.rules
Original file line number Diff line number Diff line change
Expand Up @@ -1389,6 +1389,11 @@
(GreaterThanF (InvertFlags x)) => (LessThanF x)
(GreaterEqualF (InvertFlags x)) => (LessEqualF x)

(GreaterEqual (CMPconst x [0])) => (XORconst [1] (SRLconst <v.Type> [63] x))
(LessThan (CMPconst x [0])) => (SRLconst [63] x)
(GreaterEqual (CMPWconst x [0])) => (XORconst [1] (UBFX <v.Type> [armBFAuxInt(31,1)] x))
(LessThan (CMPWconst x [0])) => (UBFX [armBFAuxInt(31,1)] x)

// Don't bother extending if we're not using the higher bits.
(MOV(B|BU)reg x) && v.Type.Size() <= 1 => x
(MOV(H|HU)reg x) && v.Type.Size() <= 2 => x
Expand Down
54 changes: 54 additions & 0 deletions src/cmd/compile/internal/ssa/rewriteARM64.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions src/cmd/go/internal/telemetrystats/telemetrystats.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ func incrementConfig() {
counter.Inc("go/cgo:disabled")
}

counter.Inc("go/platform/target/goos:" + cfg.Goos)
counter.Inc("go/platform/target/goarch:" + cfg.Goarch)
counter.Inc("go/platform/target/port:" + cfg.Goos + "-" + cfg.Goarch)
switch cfg.Goarch {
case "386":
Expand Down
15 changes: 14 additions & 1 deletion src/cmd/internal/script/cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func DefaultCmds() map[string]Cmd {
"cp": Cp(),
"echo": Echo(),
"env": Env(),
"exec": Exec(func(cmd *exec.Cmd) error { return cmd.Process.Signal(os.Interrupt) }, 100*time.Millisecond), // arbitrary grace period
"exec": Exec(func(cmd *exec.Cmd) error { return InterruptCmd(cmd) }, 100*time.Millisecond), // arbitrary grace period
"exists": Exists(),
"grep": Grep(),
"help": Help(),
Expand All @@ -53,6 +53,19 @@ func DefaultCmds() map[string]Cmd {
}
}

// InterruptCmd interrupts cmd process.
// InterruptCmd kills the process on Windows, because
// cmd.Process.Signal(os.Interrupt) is not supported on Windows.
func InterruptCmd(cmd *exec.Cmd) error {
if runtime.GOOS == "windows" {
// windows does not implement cmd.Process.Signal
return cmd.Process.Kill()
}
// TODO(thepudds): currently cmd/go/script_test.go uses a platform-specific cancel
// that we could consider emulating here.
return cmd.Process.Signal(os.Interrupt)
}

// Command returns a new Cmd with a Usage method that returns a copy of the
// given CmdUsage and a Run method calls the given function.
func Command(usage CmdUsage, run func(*State, ...string) (WaitFunc, error)) Cmd {
Expand Down
66 changes: 66 additions & 0 deletions src/cmd/internal/script/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,76 @@ package script

import (
"context"
"fmt"
"internal/testenv"
"io"
"os"
"os/exec"
"runtime"
"slices"
"testing"
"time"
)

func TestInterruptCmd(t *testing.T) {
if runtime.GOOS == "js" || runtime.GOOS == "wasip1" {
t.Skip(runtime.GOOS + " does not support executables")
}

const msg = "Hello world\n"

if os.Getenv("GO_WANT_HELPER_PROCESS") == "1" {
fmt.Printf(msg)
time.Sleep(24 * time.Hour) // sleep forever
os.Exit(3)
}

exe := testenv.Executable(t)
cmd := testenv.CommandContext(t, t.Context(), exe, "-test.run=^TestInterruptCmd$")
cmd = testenv.CleanCmdEnv(cmd)
cmd.Env = append(cmd.Env, "GO_WANT_HELPER_PROCESS=1")

stdout, err := cmd.StdoutPipe()
if err != nil {
t.Fatal(err)
}

if err := cmd.Start(); err != nil {
t.Fatal(err)
}

buf := make([]byte, len(msg))
n, err := io.ReadFull(stdout, buf)
if n != len(buf) || err != nil || string(buf) != msg {
t.Fatalf("ReadFull = %d, %v, %q", n, err, buf[:n])
}

interruptCmdErr := make(chan error)
go func() {
interruptCmdErr <- InterruptCmd(cmd)
}()

err = cmd.Wait()
if err == nil {
t.Fatal("expected Wait failure")
} else if err, ok := err.(*exec.ExitError); ok {
expectedError := "signal: interrupt"
if runtime.GOOS == "windows" {
expectedError = "exit status 1"
}
if err.Error() != expectedError {
t.Fatalf("unexpected error while exiting executable: got=%q, want=%q", err.Error(), expectedError)
}
} else {
t.Fatalf("unexpected error while running executable: %s\n%s", err, string(buf))
}

err = <-interruptCmdErr
if err != nil {
t.Errorf("InterruptCmd failed: %v", err)
}
}

func FuzzQuoteArgs(f *testing.F) {
state, err := NewState(context.Background(), f.TempDir(), nil /* env */)
if err != nil {
Expand Down
10 changes: 2 additions & 8 deletions src/cmd/internal/script/scripttest/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,11 @@ func NewEngine(t *testing.T, repls []ToolReplacement) (*script.Engine, []string)
return env
}

interrupt := func(cmd *exec.Cmd) error {
// TODO(thepudds): currently cmd/go/script_test.go uses a platform-specific cancel
// that we could consider emulating here.
return cmd.Process.Signal(os.Interrupt)
}

// Customize the subprocess termination grace period to reduce flakes on busy builders (#76685).
// The grace period is the max of 100ms or 5% of the time remaining until any t.Deadline.
gracePeriod := subprocessGracePeriod(t.Deadline())

cmdExec := script.Exec(interrupt, gracePeriod)
cmdExec := script.Exec(script.InterruptCmd, gracePeriod)
cmds["exec"] = cmdExec

// Set up an alternate go root for running script tests, since it
Expand All @@ -130,7 +124,7 @@ func NewEngine(t *testing.T, repls []ToolReplacement) (*script.Engine, []string)

// Add in commands for "go" and "cc".
testgo := filepath.Join(tgr, "bin", "go")
gocmd := script.Program(testgo, interrupt, gracePeriod)
gocmd := script.Program(testgo, script.InterruptCmd, gracePeriod)
addcmd("go", gocmd)
addcmd("cc", scriptCC(cmdExec, goEnv("CC")))

Expand Down
21 changes: 19 additions & 2 deletions test/codegen/comparisons.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,23 @@ func CmpToOneU_ex2(a uint8, b uint16, c uint32, d uint64) int {
return 0
}

func int64LtZero(x int64) bool {
// arm64: `LSR [$]63`
return x < 0
}
func int64GeZero(x int64) bool {
// arm64: `LSR [$]63` `EOR [$]1`
return x >= 0
}
func int32LtZero(x int32) bool {
// arm64: `UBFX [$]31, R[0-9]+, [$]1,`
return x < 0
}
func int32GeZero(x int32) bool {
// arm64: `UBFX [$]31, R[0-9]+, [$]1,` `EOR [$]1`
return x >= 0
}

// Check that small memequals are replaced with eq instructions

func equalConstString1() bool {
Expand Down Expand Up @@ -748,7 +765,7 @@ func cmpToCmnLessThan(a, b, c, d int) int {
if a*b+c < 0 {
c3 = 1
}
// arm64:`MSUB` `CSET LT` -`CMN`
// arm64:`MSUB` `LSR`
if a-b*c < 0 {
c4 = 1
}
Expand Down Expand Up @@ -817,7 +834,7 @@ func cmpToCmnGreaterThanEqual(a, b, c, d int) int {
if a*b+c >= 0 {
c3 = 1
}
// arm64:`MSUB` `CSET GE` -`CMN`
// arm64:`MSUB` `LSR` `EOR [$]1`
if a-b*c >= 0 {
c4 = 1
}
Expand Down
Loading