diff --git a/8006-Add-goexperiment.StepOpt2-for-optimized-step-functio.patch b/8006-Add-goexperiment.StepOpt2-for-optimized-step-functio.patch new file mode 100644 index 0000000000000000000000000000000000000000..5fc95b5201ea0d712689045409c2beb1e6345ad0 --- /dev/null +++ b/8006-Add-goexperiment.StepOpt2-for-optimized-step-functio.patch @@ -0,0 +1,130 @@ +From 395d6b5005b8e3854aa628ad98757dc053a8549c Mon Sep 17 00:00:00 2001 +From: chenyifan +Date: Tue, 18 Nov 2025 19:35:07 +0800 +Subject: [PATCH] Add goexperiment.StepOpt2 for optimized step function in + runtime + +--- + src/internal/goexperiment/exp_stepopt2_off.go | 8 ++++ + src/internal/goexperiment/exp_stepopt2_on.go | 8 ++++ + src/internal/goexperiment/flags.go | 3 ++ + src/runtime/symtab.go | 47 +++++++++++++++++++ + 4 files changed, 66 insertions(+) + create mode 100644 src/internal/goexperiment/exp_stepopt2_off.go + create mode 100644 src/internal/goexperiment/exp_stepopt2_on.go + +diff --git a/src/internal/goexperiment/exp_stepopt2_off.go b/src/internal/goexperiment/exp_stepopt2_off.go +new file mode 100644 +index 00000000..7a06da83 +--- /dev/null ++++ b/src/internal/goexperiment/exp_stepopt2_off.go +@@ -0,0 +1,8 @@ ++// Code generated by mkconsts.go. DO NOT EDIT. ++ ++//go:build !goexperiment.stepopt2 ++ ++package goexperiment ++ ++const StepOpt2 = false ++const StepOpt2Int = 0 +diff --git a/src/internal/goexperiment/exp_stepopt2_on.go b/src/internal/goexperiment/exp_stepopt2_on.go +new file mode 100644 +index 00000000..1cd2d7d6 +--- /dev/null ++++ b/src/internal/goexperiment/exp_stepopt2_on.go +@@ -0,0 +1,8 @@ ++// Code generated by mkconsts.go. DO NOT EDIT. ++ ++//go:build goexperiment.stepopt2 ++ ++package goexperiment ++ ++const StepOpt2 = true ++const StepOpt2Int = 1 +diff --git a/src/internal/goexperiment/flags.go b/src/internal/goexperiment/flags.go +index 87ddd355..f39a282f 100644 +--- a/src/internal/goexperiment/flags.go ++++ b/src/internal/goexperiment/flags.go +@@ -115,4 +115,7 @@ type Flags struct { + + //PageNum enables 128k span size + PageNum bool ++ ++ // StepOpt2 enables optimization for func step in package runtime ++ StepOpt2 bool + } +diff --git a/src/runtime/symtab.go b/src/runtime/symtab.go +index b47f2d83..ef216344 100644 +--- a/src/runtime/symtab.go ++++ b/src/runtime/symtab.go +@@ -7,6 +7,7 @@ package runtime + import ( + "internal/abi" + "internal/goarch" ++ "internal/goexperiment" + "runtime/internal/atomic" + "runtime/internal/sys" + "unsafe" +@@ -1069,6 +1070,9 @@ func funcdata(f funcInfo, i uint8) unsafe.Pointer { + + // step advances to the next pc, value pair in the encoded table. + func step(p []byte, pc *uintptr, val *int32, first bool) (newp []byte, ok bool) { ++ if goexperiment.StepOpt2 { ++ return step_exp2(p, pc, val, first) ++ } + // For both uvdelta and pcdelta, the common case (~70%) + // is that they are a single byte. If so, avoid calling readvarint. + uvdelta := uint32(p[0]) +@@ -1092,6 +1096,49 @@ func step(p []byte, pc *uintptr, val *int32, first bool) (newp []byte, ok bool) + return p, true + } + ++func step_exp2(p []byte, pc *uintptr, val *int32, first bool) (newp []byte, ok bool) { ++ // For both uvdelta and pcdelta, the common case (~70%) ++ // is that they are a single byte. If so, avoid calling readvarint. ++ var n uint32 ++ uvdelta := uint32(p[0]) ++ if uvdelta == 0 && !first { ++ return nil, false ++ } ++ if uvdelta&0x80 == 0 { ++ n = 1 ++ *val += int32(-(uvdelta & 1) ^ (uvdelta >> 1)) ++ p = p[n:] ++ } else { ++ a := uint32(p[1]) ++ if a&0x80 == 0 { ++ uvdelta = (uvdelta & 0x7f) | (a << 7) ++ n = 2 ++ } else { ++ n, uvdelta = readvarint(p) ++ } ++ *val += int32(-(uvdelta & 1) ^ (uvdelta >> 1)) ++ p = p[n:] ++ } ++ ++ pcdelta := uint32(p[0]) // load 2-byte once ++ if pcdelta&0x80 == 0 { ++ n = 1 ++ *pc += uintptr((pcdelta & 0xff) * sys.PCQuantum) ++ p = p[n:] ++ } else { ++ a := uint32(p[1]) ++ if a&0x80 == 0 { ++ pcdelta = (pcdelta & 0x7f) | (a << 7) ++ n = 2 ++ } else { ++ n, pcdelta = readvarint(p) ++ } ++ p = p[n:] ++ *pc += uintptr(pcdelta * sys.PCQuantum) ++ } ++ return p, true ++} ++ + // readvarint reads a varint from p. + func readvarint(p []byte) (read uint32, val uint32) { + var v, shift, n uint32 +-- +2.33.0 + diff --git a/golang.spec b/golang.spec index d6b475408af77741fb1e3ba1898980a708e15a55..00862909e169a66ac6835f49487d117f0b6fe9c2 100644 --- a/golang.spec +++ b/golang.spec @@ -69,7 +69,7 @@ Name: golang Version: 1.21.4 -Release: 41 +Release: 42 Summary: The Go Programming Language License: BSD and Public Domain URL: https://golang.org/ @@ -187,6 +187,7 @@ Patch8002: 8002-cmd-go-Use-AI-to-guide-optimization.patch Patch8003: 8003-internal-buildcfg-add-Kunpeng-atomic-optimize.patch Patch8004: 8004-runtime-add-gcRatio-option.patch Patch8005: 8005-PAGENUM-enable-custom-span-size.patch +Patch8006: 8006-Add-goexperiment.StepOpt2-for-optimized-step-functio.patch # Part 2000 ~ 2119 # RISC-V RVA23 support backport @@ -549,6 +550,12 @@ fi %files devel -f go-tests.list -f go-misc.list -f go-src.list %changelog +* Tue Nov 18 2025 huang-xiaoquan - 1.21.4-42 +- Type:Feature +- CVE:NA +- SUG:NA +- DESC: [stepopt2] Add goexperiment.StepOpt2 for optimized step function in runtime + * Tue Nov 18 2025 huang-xiaoquan - 1.21.4-41 - Type:Feature - CVE:NA