fix: support network manager connection profiles (#23469)

Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
Jian Qiu
2025-10-03 09:25:34 +08:00
committed by GitHub
parent 30b8491ef5
commit 77aa8a7f96
52 changed files with 6978 additions and 91 deletions

4
go.mod
View File

@@ -73,6 +73,7 @@ require (
github.com/vishvananda/netns v0.0.5-0.20240412164733-9469873f4601
github.com/vmihailenco/msgpack v4.0.4+incompatible
github.com/xuri/excelize/v2 v2.7.1
github.com/zeebo/xxh3 v1.0.2
github.com/zexi/influxql-to-metricsql v0.1.1
go.etcd.io/etcd/api/v3 v3.5.0
go.etcd.io/etcd/client/v3 v3.5.0
@@ -96,7 +97,7 @@ require (
k8s.io/cri-api v0.22.17
k8s.io/klog/v2 v2.20.0
moul.io/http2curl/v2 v2.3.0
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250930065031-d469e632afc7
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250930105820-7f5a2ad54a65
yunion.io/x/executor v0.0.0-20250518005516-5402e9e0bed0
yunion.io/x/jsonutils v1.0.1-0.20250507052344-1abcf4f443b1
yunion.io/x/log v1.0.1-0.20240305175729-7cf2d6cd5a91
@@ -228,6 +229,7 @@ require (
github.com/jtolds/gls v4.20.0+incompatible // indirect
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 // indirect
github.com/karrick/godirwalk v1.16.1 // indirect
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/kr/fs v0.1.0 // indirect
github.com/ks3sdklib/aws-sdk-go v1.8.1 // indirect
github.com/leodido/go-urn v1.2.0 // indirect

10
go.sum
View File

@@ -571,6 +571,8 @@ github.com/karrick/godirwalk v1.16.1/go.mod h1:j4mkqPuvaLI8mp1DroR3P6ad7cyYd4c1q
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/koding/websocketproxy v0.0.0-20181220232114-7ed82d81a28c h1:N7A4JCA2G+j5fuFxCsJqjFU/sZe0mj8H0sSoSwbaikw=
github.com/koding/websocketproxy v0.0.0-20181220232114-7ed82d81a28c/go.mod h1:Nn5wlyECw3iJrzi0AhIWg+AJUb4PlRQVW4/3XHH1LZA=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
@@ -925,6 +927,10 @@ github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
github.com/yusufpapurcu/wmi v1.2.2 h1:KBNDSne4vP5mbSWnJbO+51IMOXJB67QiYCSBrubbPRg=
github.com/yusufpapurcu/wmi v1.2.2/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
github.com/zeebo/assert v1.3.0 h1:g7C04CbJuIDKNPFHmsk4hwZDO5O+kntRxzaUoNXj+IQ=
github.com/zeebo/assert v1.3.0/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN/wJ0=
github.com/zeebo/xxh3 v1.0.2 h1:xZmwmqxHZA8AI603jOQ0tMqmBr9lPeFwGg6d+xy9DC0=
github.com/zeebo/xxh3 v1.0.2/go.mod h1:5NWz9Sef7zIDm2JHfFlcQvNekmcEl9ekUZQQKCYaDcA=
github.com/zexi/influxql-to-metricsql v0.1.1 h1:dXnVzlxVLuo88zGkDca7erEnmvprGWjzsBcs8qIoQGQ=
github.com/zexi/influxql-to-metricsql v0.1.1/go.mod h1:JlC5FY+6De9ZPxG47G5DOgva8P9X1VaKS4ExzCmhSCc=
github.com/zexi/promql/v2 v2.12.1 h1:crHKpULdLLsBZ9b78Rg6qQkugzlk6BHeCj93tw/F5RU=
@@ -1426,8 +1432,8 @@ sigs.k8s.io/structured-merge-diff/v4 v4.0.1/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250930065031-d469e632afc7 h1:s330bg28iOB9+D3cPtuwG5eeG9qHKkjicPh5P+ri4Ko=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250930065031-d469e632afc7/go.mod h1:R5iP/4nGCluuekoa30B5hM/49IfPpGHXwFK3yT7m6Vw=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250930105820-7f5a2ad54a65 h1:oNR+HA9LXZ+bN9r147ryqqaa4ubJATy1Vn95fUijrsQ=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250930105820-7f5a2ad54a65/go.mod h1:R5iP/4nGCluuekoa30B5hM/49IfPpGHXwFK3yT7m6Vw=
yunion.io/x/executor v0.0.0-20250518005516-5402e9e0bed0 h1:msG4SiDSVU7CrXH06WuHlNEZXIooTcmNbfrIGHuIHBU=
yunion.io/x/executor v0.0.0-20250518005516-5402e9e0bed0/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634=

View File

@@ -1033,7 +1033,7 @@ func (d *sDebianLikeRootFs) DeployNetworkingScripts(rootFs IDiskPartition, nics
cmds.WriteString(fmt.Sprintf(" up ip -6 route add %s/%d via %s || true\n", r.Prefix, r.PrefixLen, r.Gateway))
cmds.WriteString(fmt.Sprintf(" down ip -6 route del %s/%d via %s || true\n", r.Prefix, r.PrefixLen, r.Gateway))
}
dnslist := netutils2.GetNicDns(nicDesc)
dnslist, _ := netutils2.GetNicDns(nicDesc)
if len(dnslist) > 0 {
cmds.WriteString(fmt.Sprintf(" dns-nameservers %s\n", strings.Join(dnslist, " ")))
dnss = append(dnss, dnslist...)
@@ -1044,15 +1044,6 @@ func (d *sDebianLikeRootFs) DeployNetworkingScripts(rootFs IDiskPartition, nics
if nicDesc.Mtu > 0 {
cmds.WriteString(fmt.Sprintf(" mtu %d\n", nicDesc.Mtu))
}
dnslist := netutils2.GetNicDns(nicDesc)
if len(dnslist) > 0 {
cmds.WriteString(fmt.Sprintf(" dns-nameservers %s\n", strings.Join(dnslist, " ")))
dnss = append(dnss, dnslist...)
if len(nicDesc.Domain) > 0 {
cmds.WriteString(fmt.Sprintf(" dns-search %s\n", nicDesc.Domain))
domains = append(domains, nicDesc.Domain)
}
}
if len(nicDesc.TeamingSlaves) > 0 {
cmds.WriteString(getNicTeamingConfigCmds(nicDesc.TeamingSlaves))
}
@@ -1066,6 +1057,15 @@ func (d *sDebianLikeRootFs) DeployNetworkingScripts(rootFs IDiskPartition, nics
if len(nicDesc.Gateway6) > 0 && nicDesc.Ip == mainIp {
cmds.WriteString(fmt.Sprintf(" gateway %s\n", nicDesc.Gateway6))
}
_, dnslist := netutils2.GetNicDns(nicDesc)
if len(dnslist) > 0 {
cmds.WriteString(fmt.Sprintf(" dns-nameservers %s\n", strings.Join(dnslist, " ")))
dnss = append(dnss, dnslist...)
if len(nicDesc.Domain) > 0 {
cmds.WriteString(fmt.Sprintf(" dns-search %s\n", nicDesc.Domain))
domains = append(domains, nicDesc.Domain)
}
}
cmds.WriteString("\n")
}
} else {
@@ -1327,8 +1327,24 @@ func (r *sRedhatLikeRootFs) PrepareFsForTemplate(rootFs IDiskPartition) error {
return r.CleanNetworkScripts(rootFs)
}
func (r *sRedhatLikeRootFs) cleanNetworkManagerConfigurations(rootFs IDiskPartition) error {
networkPath := "/etc/NetworkManager/system-connections"
if !rootFs.Exists(networkPath, false) {
return nil
}
files := rootFs.ListDir(networkPath, false)
for _, f := range files {
rootFs.Remove(filepath.Join(networkPath, f), false)
}
return nil
}
func (r *sRedhatLikeRootFs) CleanNetworkScripts(rootFs IDiskPartition) error {
networkPath := "/etc/sysconfig/network-scripts"
if !rootFs.Exists(networkPath, false) {
return r.cleanNetworkManagerConfigurations(rootFs)
}
files := rootFs.ListDir(networkPath, false)
for i := 0; i < len(files); i++ {
if strings.HasPrefix(files[i], "ifcfg-") && files[i] != "ifcfg-lo" {
@@ -1344,16 +1360,18 @@ func (r *sRedhatLikeRootFs) CleanNetworkScripts(rootFs IDiskPartition) error {
func (r *sRedhatLikeRootFs) RootSignatures() []string {
sig := r.sLinuxRootFs.RootSignatures()
return append([]string{"/etc/sysconfig/network", "/etc/redhat-release"}, sig...)
return append([]string{"/etc/redhat-release"}, sig...)
}
func (r *sRedhatLikeRootFs) DeployHostname(rootFs IDiskPartition, hn, domain string) error {
var sPath = "/etc/sysconfig/network"
centosHn := ""
centosHn += "NETWORKING=yes\n"
centosHn += fmt.Sprintf("HOSTNAME=%s\n", getHostname(hn, domain))
if err := rootFs.FilePutContents(sPath, centosHn, false, false); err != nil {
return errors.Wrapf(err, "DeployHostname %s", sPath)
if r.rootFs.Exists(sPath, false) {
centosHn := ""
centosHn += "NETWORKING=yes\n"
centosHn += fmt.Sprintf("HOSTNAME=%s\n", getHostname(hn, domain))
if err := rootFs.FilePutContents(sPath, centosHn, false, false); err != nil {
return errors.Wrapf(err, "DeployHostname %s", sPath)
}
}
if err := rootFs.FilePutContents("/etc/hostname", hn, false, false); err != nil {
return errors.Wrapf(err, "DeployHostname %s", "/etc/hostname")
@@ -1422,17 +1440,47 @@ func (r *sRedhatLikeRootFs) isNetworkManagerEnabled(rootFs IDiskPartition) bool
return rootFs.Exists("/etc/systemd/system/multi-user.target.wants/NetworkManager.service", false)
}
func (r *sRedhatLikeRootFs) deployNetworkingScripts(rootFs IDiskPartition, nics []*types.SServerNic, relInfo *deployapi.ReleaseInfo) error {
// remove all ifcfg-*
const scriptPath = "/etc/sysconfig/network-scripts"
func (r *sRedhatLikeRootFs) deployNetworkManagerConfigurations(rootFs IDiskPartition, nics []*types.SServerNic, relInfo *deployapi.ReleaseInfo) error {
const scriptPath = "/etc/NetworkManager/system-connections"
if !rootFs.Exists(scriptPath, false) {
return errors.Wrap(errors.ErrNotSupported, "unsupported system, neither network-scripts nor NetworkManager")
}
// remove all connections profiles
files := rootFs.ListDir(scriptPath, false)
for _, f := range files {
if strings.HasPrefix(f, "ifcfg-") && f != "ifcfg-lo" {
log.Infof("remove %s in %s", f, scriptPath)
rootFs.Remove(filepath.Join(scriptPath, f), false)
log.Infof("remove %s in %s", f, scriptPath)
rootFs.Remove(filepath.Join(scriptPath, f), false)
}
allNics, bondNics := convertNicConfigs(nics)
if len(bondNics) > 0 {
err := r.enableBondingModule(rootFs, bondNics)
if err != nil {
return errors.Wrap(err, "enableBondingModule")
}
}
// nicCnt := len(allNics) - len(bondNics)
mainNic := getMainNic(allNics)
var mainIp, mainIp6 string
if mainNic != nil {
mainIp = mainNic.Ip
mainIp6 = mainNic.Ip6
}
for i := range allNics {
nicDesc := allNics[i]
profile := nicDescToNetworkManager(nicDesc, mainIp, mainIp6)
var fn = fmt.Sprintf("%s/%s.nmconnection", scriptPath, nicDesc.Name)
if err := rootFs.FilePutContents(fn, profile, false, false); err != nil {
return err
}
}
return nil
}
func (r *sRedhatLikeRootFs) deployNetworkingScripts(rootFs IDiskPartition, nics []*types.SServerNic, relInfo *deployapi.ReleaseInfo) error {
ver := strings.Split(relInfo.Version, ".")
iv, err := strconv.ParseInt(ver[0], 10, 0)
if err == nil && iv < 6 {
@@ -1443,6 +1491,21 @@ func (r *sRedhatLikeRootFs) deployNetworkingScripts(rootFs IDiskPartition, nics
if err != nil {
return errors.Wrap(err, "DeployNetworkingScripts")
}
const scriptPath = "/etc/sysconfig/network-scripts"
if !rootFs.Exists(scriptPath, false) {
// NetworkManager is enabled, but no network-scripts directory, deploy NetworkManager configurations
return r.deployNetworkManagerConfigurations(rootFs, nics, relInfo)
}
// remove all ifcfg-*
files := rootFs.ListDir(scriptPath, false)
for _, f := range files {
if strings.HasPrefix(f, "ifcfg-") && f != "ifcfg-lo" {
log.Infof("remove %s in %s", f, scriptPath)
rootFs.Remove(filepath.Join(scriptPath, f), false)
}
}
// ToServerNics(nics)
allNics, bondNics := convertNicConfigs(nics)
if len(bondNics) > 0 {
@@ -1495,7 +1558,7 @@ func (r *sRedhatLikeRootFs) deployNetworkingScripts(rootFs IDiskPartition, nics
cmds.WriteString("\n")
}
if len(nicDesc.TeamingSlaves) > 0 {
// bonding
// bonding master
cmds.WriteString(`BONDING_OPTS="mode=4 miimon=100"`)
cmds.WriteString("\n")
}
@@ -1532,15 +1595,6 @@ func (r *sRedhatLikeRootFs) deployNetworkingScripts(rootFs IDiskPartition, nics
cmds.WriteString("\n")
}
}
if len(nicDesc.Ip6) > 0 {
cmds.WriteString("IPV6INIT=yes\n")
cmds.WriteString("DHCPV6C=no\n")
cmds.WriteString("IPV6_AUTOCONF=no\n")
cmds.WriteString(fmt.Sprintf("IPV6ADDR=%s/%d\n", nicDesc.Ip6, nicDesc.Masklen6))
if len(nicDesc.Gateway6) > 0 && nicDesc.Ip6 == mainIp6 {
cmds.WriteString(fmt.Sprintf("IPV6_DEFAULTGW=%s\n", nicDesc.Gateway6))
}
}
routes4 := make([]netutils2.SRouteInfo, 0)
routes6 := make([]netutils2.SRouteInfo, 0)
routes4, routes6 = netutils2.AddNicRoutes(routes4, routes6, nicDesc, mainIp, mainIp6, nicCnt)
@@ -1567,15 +1621,30 @@ func (r *sRedhatLikeRootFs) deployNetworkingScripts(rootFs IDiskPartition, nics
if err := rootFs.FilePutContents(fn, rtblStr, false, false); err != nil {
return err
}
dnslist := netutils2.GetNicDns(nicDesc)
if len(dnslist) > 0 {
cmds.WriteString("PEERDNS=yes\n")
for i := 0; i < len(dnslist); i++ {
cmds.WriteString(fmt.Sprintf("DNS%d=%s\n", i+1, dnslist[i]))
}
if len(nicDesc.Domain) > 0 {
cmds.WriteString(fmt.Sprintf("DOMAIN=%s\n", nicDesc.Domain))
}
}
dns4list, dns6list := netutils2.GetNicDns(nicDesc)
if len(dns4list)+len(dns6list) > 0 {
cmds.WriteString("PEERDNS=yes\n")
dnsIdx := 1
for i := 0; i < len(dns4list); i++ {
cmds.WriteString(fmt.Sprintf("DNS%d=%s\n", dnsIdx, dns4list[i]))
dnsIdx += 1
}
for i := 0; i < len(dns6list); i++ {
cmds.WriteString(fmt.Sprintf("DNS%d=%s\n", dnsIdx, dns6list[i]))
dnsIdx += 1
}
if len(nicDesc.Domain) > 0 {
cmds.WriteString(fmt.Sprintf("DOMAIN=%s\n", nicDesc.Domain))
}
}
if len(nicDesc.Ip6) > 0 {
cmds.WriteString("IPV6INIT=yes\n")
cmds.WriteString("DHCPV6C=no\n")
cmds.WriteString("IPV6_AUTOCONF=no\n")
cmds.WriteString(fmt.Sprintf("IPV6ADDR=%s/%d\n", nicDesc.Ip6, nicDesc.Masklen6))
if len(nicDesc.Gateway6) > 0 && nicDesc.Ip6 == mainIp6 {
cmds.WriteString(fmt.Sprintf("IPV6_DEFAULTGW=%s\n", nicDesc.Gateway6))
}
}
}
@@ -1667,11 +1736,17 @@ func (r *sRedhatLikeRootFs) deployVlanNetworkingScripts(rootFs IDiskPartition, s
return err
}
}
dnslist := netutils2.GetNicDns(nicDesc)
if len(dnslist) > 0 {
dns4list, dns6list := netutils2.GetNicDns(nicDesc)
if len(dns4list)+len(dns6list) > 0 {
cmds.WriteString("PEERDNS=yes\n")
for i := 0; i < len(dnslist); i++ {
cmds.WriteString(fmt.Sprintf("DNS%d=%s\n", i+1, dnslist[i]))
dnsIdx := 1
for i := 0; i < len(dns4list); i++ {
cmds.WriteString(fmt.Sprintf("DNS%d=%s\n", dnsIdx, dns4list[i]))
dnsIdx += 1
}
for i := 0; i < len(dns6list); i++ {
cmds.WriteString(fmt.Sprintf("DNS%d=%s\n", dnsIdx, dns6list[i]))
dnsIdx += 1
}
if len(nicDesc.Domain) > 0 {
cmds.WriteString(fmt.Sprintf("DOMAIN=%s\n", nicDesc.Domain))

View File

@@ -144,10 +144,13 @@ func getNetplanEthernetConfig(nic *types.SServerNic, isBond bool, mainIp, mainIp
})
}
dns4list, dns6list := netutils2.GetNicDns(nic)
dnslist := append(dns4list, dns6list...)
nicConf = netplan.NewStaticEthernetConfig(
addr, addr6, gateway, gateway6,
[]string{nic.Domain},
netutils2.GetNicDns(nic),
dnslist,
routes,
)
nicConf.MacAddress = nic.Mac

View File

@@ -0,0 +1,126 @@
// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package fsdriver
import (
"fmt"
"strings"
api "yunion.io/x/onecloud/pkg/apis/compute"
"yunion.io/x/onecloud/pkg/cloudcommon/types"
"yunion.io/x/onecloud/pkg/util/netutils2"
"yunion.io/x/onecloud/pkg/util/stringutils2"
)
func nicDescToNetworkManager(nicDesc *types.SServerNic, mainIp string, mainIp6 string) string {
var profile strings.Builder
profile.WriteString("[connection]\n")
profile.WriteString(fmt.Sprintf("id=%s\n", nicDesc.Name))
profile.WriteString(fmt.Sprintf("uuid=%s\n", stringutils2.GenUuid(nicDesc.Name, nicDesc.Mac)))
profile.WriteString(fmt.Sprintf("interface-name=%s\n", nicDesc.Name))
if len(nicDesc.TeamingSlaves) > 0 {
// bonding master
profile.WriteString("type=bond\n")
profile.WriteString("autoconnect=true\n")
} else {
profile.WriteString("type=ethernet\n")
if nicDesc.TeamingMaster != nil {
// bonding slave
profile.WriteString(fmt.Sprintf("master=%s\n", nicDesc.TeamingMaster.Name))
profile.WriteString("slave-type=bond\n")
} else {
// normal interface
profile.WriteString("autoconnect=true\n")
}
}
profile.WriteString("\n")
if len(nicDesc.TeamingSlaves) > 0 {
profile.WriteString("[bond]\n")
profile.WriteString("mode=802.3ad\n")
profile.WriteString("miimon=100\n")
profile.WriteString("\n")
}
if len(nicDesc.Mac) > 0 && nicDesc.NicType != api.NIC_TYPE_INFINIBAND {
profile.WriteString("[ethernet]\n")
if len(nicDesc.TeamingSlaves) == 0 {
// only real physical nic can set HWADDR
// cmds.WriteString("HWADDR=")
// cmds.WriteString(nicDesc.Mac)
// cmds.WriteString("\n")
}
profile.WriteString(fmt.Sprintf("mac-address=%s\n", nicDesc.Mac))
if nicDesc.Mtu > 0 {
profile.WriteString(fmt.Sprintf("mtu=%d\n", nicDesc.Mtu))
}
profile.WriteString("\n")
}
if nicDesc.TeamingMaster != nil {
// slave interface
profile.WriteString("[ipv4]\n")
profile.WriteString("method=disabled\n\n")
profile.WriteString("[ipv6]\n")
profile.WriteString("method=disabled\n\n")
} else if nicDesc.Virtual {
// virtual interface
profile.WriteString("[ipv4]\n")
profile.WriteString("method=manual\n")
profile.WriteString(fmt.Sprintf("address1=%s/32\n", netutils2.PSEUDO_VIP))
profile.WriteString("\n")
} else if nicDesc.Manual {
// manual interface
if len(nicDesc.Ip) > 0 {
profile.WriteString("[ipv4]\n")
profile.WriteString("method=manual\n")
profile.WriteString(fmt.Sprintf("address1=%s/%d\n", nicDesc.Ip, nicDesc.Masklen))
if len(nicDesc.Gateway) > 0 && nicDesc.Ip == mainIp {
profile.WriteString(fmt.Sprintf("gateway=%s\n", nicDesc.Gateway))
}
dnslist, _ := netutils2.GetNicDns(nicDesc)
if len(dnslist) > 0 {
profile.WriteString(fmt.Sprintf("dns=%s\n", strings.Join(dnslist, ",")))
}
profile.WriteString("\n")
}
if len(nicDesc.Ip6) > 0 {
profile.WriteString("[ipv6]\n")
profile.WriteString("method=manual\n")
profile.WriteString(fmt.Sprintf("address1=%s/%d\n", nicDesc.Ip6, nicDesc.Masklen6))
if len(nicDesc.Gateway6) > 0 && nicDesc.Ip6 == mainIp6 {
profile.WriteString(fmt.Sprintf("gateway=%s\n", nicDesc.Gateway6))
}
_, dns6list := netutils2.GetNicDns(nicDesc)
if len(dns6list) > 0 {
profile.WriteString(fmt.Sprintf("dns=%s\n", strings.Join(dns6list, ",")))
}
profile.WriteString("\n")
}
} else {
// dhcp interface
if len(nicDesc.Ip) > 0 {
profile.WriteString("[ipv4]\n")
profile.WriteString("method=auto\n\n")
}
if len(nicDesc.Ip6) > 0 {
profile.WriteString("[ipv6]\n")
profile.WriteString("method=auto\n\n")
}
}
return profile.String()
}

View File

@@ -0,0 +1,228 @@
// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package fsdriver
import (
"testing"
"yunion.io/x/onecloud/pkg/cloudcommon/types"
)
func TestNicDescToNetworkManager(t *testing.T) {
cases := []struct {
nicDesc *types.SServerNic
mainIp string
mainIp6 string
want string
}{
{
nicDesc: &types.SServerNic{
Name: "eth0",
Ip: "192.168.1.100",
Masklen: 24,
Gateway: "192.168.1.1",
Ip6: "2001:db8::200",
Masklen6: 64,
Gateway6: "2001:db8::1",
Mac: "00:22:0a:0b:0c:0d",
Manual: false,
Mtu: 1440,
},
mainIp: "192.168.1.100",
mainIp6: "2001:db8::1",
want: `[connection]
id=eth0
uuid=de05e375-af25-9477-66ca-d4f41fe5e750
interface-name=eth0
type=ethernet
autoconnect=true
[ethernet]
mac-address=00:22:0a:0b:0c:0d
mtu=1440
[ipv4]
method=auto
[ipv6]
method=auto
`,
},
{
nicDesc: &types.SServerNic{
Name: "eth0",
Ip: "192.168.1.100",
Masklen: 24,
Gateway: "192.168.1.1",
Ip6: "2001:db8::200",
Masklen6: 64,
Gateway6: "2001:db8::1",
Mac: "00:22:0a:0b:0c:0d",
Manual: true,
},
mainIp: "192.168.1.100",
mainIp6: "2001:db8::200",
want: `[connection]
id=eth0
uuid=de05e375-af25-9477-66ca-d4f41fe5e750
interface-name=eth0
type=ethernet
autoconnect=true
[ethernet]
mac-address=00:22:0a:0b:0c:0d
[ipv4]
method=manual
address1=192.168.1.100/24
gateway=192.168.1.1
[ipv6]
method=manual
address1=2001:db8::200/64
gateway=2001:db8::1
`,
},
{
nicDesc: &types.SServerNic{
Name: "eth0",
Ip: "192.168.1.100",
Masklen: 24,
Gateway: "192.168.1.1",
Ip6: "2001:db8::200",
Masklen6: 64,
Gateway6: "2001:db8::1",
Mac: "00:22:0a:0b:0c:0d",
Domain: "onecloud.io",
Dns: "192.168.1.1,192.168.1.2,fc00::3fe:1",
Manual: true,
},
mainIp: "192.168.2.100",
mainIp6: "2001:db7::100",
want: `[connection]
id=eth0
uuid=de05e375-af25-9477-66ca-d4f41fe5e750
interface-name=eth0
type=ethernet
autoconnect=true
[ethernet]
mac-address=00:22:0a:0b:0c:0d
[ipv4]
method=manual
address1=192.168.1.100/24
dns=192.168.1.1,192.168.1.2
[ipv6]
method=manual
address1=2001:db8::200/64
dns=fc00::3fe:1
`,
},
{
nicDesc: &types.SServerNic{
Name: "bond0",
Ip: "192.168.1.100",
Masklen: 24,
Gateway: "192.168.1.1",
Ip6: "2001:db8::200",
Masklen6: 64,
Gateway6: "2001:db8::1",
Mac: "00:22:0a:0b:0c:0d",
Domain: "onecloud.io",
Dns: "192.168.1.1,192.168.1.2,fc00::3fe:1",
TeamingSlaves: []*types.SServerNic{
{
Name: "eth0",
},
{
Name: "eth1",
},
},
},
mainIp: "192.168.2.100",
mainIp6: "2001:db7::100",
want: `[connection]
id=bond0
uuid=01bf7157-f43f-58f4-15b0-cfb6d6dfdb5b
interface-name=bond0
type=bond
autoconnect=true
[bond]
mode=802.3ad
miimon=100
[ethernet]
mac-address=00:22:0a:0b:0c:0d
[ipv4]
method=auto
[ipv6]
method=auto
`,
},
{
nicDesc: &types.SServerNic{
Name: "eth0",
Ip: "192.168.1.100",
Masklen: 24,
Gateway: "192.168.1.1",
Ip6: "2001:db8::200",
Masklen6: 64,
Gateway6: "2001:db8::1",
Mac: "00:22:0a:0b:0c:0d",
Domain: "onecloud.io",
Dns: "192.168.1.1,192.168.1.2,fc00::3fe:1",
TeamingMaster: &types.SServerNic{
Name: "bond0",
},
},
mainIp: "192.168.2.100",
mainIp6: "2001:db7::100",
want: `[connection]
id=eth0
uuid=de05e375-af25-9477-66ca-d4f41fe5e750
interface-name=eth0
type=ethernet
master=bond0
slave-type=bond
[ethernet]
mac-address=00:22:0a:0b:0c:0d
[ipv4]
method=disabled
[ipv6]
method=disabled
`,
},
}
for _, c := range cases {
got := nicDescToNetworkManager(c.nicDesc, c.mainIp, c.mainIp6)
if got != c.want {
t.Errorf("[[got]]\n%s\n[[want]]\n%s\n[[end]]", got, c.want)
}
}
}

View File

@@ -41,7 +41,7 @@ func (d *SRockyRootFs) String() string {
func (d *SRockyRootFs) RootSignatures() []string {
sig := d.sLinuxRootFs.RootSignatures()
return append([]string{"/etc/sysconfig/network", "/etc/rocky-release"}, sig...)
return append([]string{"/etc/rocky-release"}, sig...)
}
func (d *SRockyRootFs) GetReleaseInfo(rootFs IDiskPartition) *deployapi.ReleaseInfo {

View File

@@ -152,10 +152,15 @@ func (r *sSuseLikeRootFs) deployVlanNetworkingScripts(rootFs IDiskPartition, scr
}
}
dnslist := netutils2.GetNicDns(nicDesc)
for i := 0; i < len(dnslist); i++ {
if !utils.IsInArray(dnslist[i], dnsSrv) {
dnsSrv = append(dnsSrv, dnslist[i])
dns4list, dns6list := netutils2.GetNicDns(nicDesc)
for i := 0; i < len(dns4list); i++ {
if !utils.IsInArray(dns4list[i], dnsSrv) {
dnsSrv = append(dnsSrv, dns4list[i])
}
}
for i := 0; i < len(dns6list); i++ {
if !utils.IsInArray(dns6list[i], dnsSrv) {
dnsSrv = append(dnsSrv, dns6list[i])
}
}
@@ -165,6 +170,25 @@ func (r *sSuseLikeRootFs) deployVlanNetworkingScripts(rootFs IDiskPartition, scr
return err
}
if len(dnsSrv) > 0 {
cont, err := rootFs.FileGetContents("/etc/sysconfig/network/config", false)
if err != nil {
return errors.Wrap(err, "FileGetContents config")
}
lines := strings.Split(string(cont), "\n")
for i := range lines {
line := strings.TrimSpace(lines[i])
if strings.HasPrefix(line, "NETCONFIG_DNS_STATIC_SERVERS=") {
lines[i] = fmt.Sprintf("NETCONFIG_DNS_STATIC_SERVERS=\"%s\"", strings.Join(dnsSrv, " "))
}
}
err = rootFs.FilePutContents("/etc/sysconfig/network/config", strings.Join(lines, "\n"), false, false)
if err != nil {
return errors.Wrap(err, "FilePutContents config")
}
}
return nil
}
@@ -286,12 +310,17 @@ func (r *sSuseLikeRootFs) deployNetworkingScripts(rootFs IDiskPartition, nics []
if err := rootFs.FilePutContents(fn, rtblStr, false, false); err != nil {
return err
}
}
dnslist := netutils2.GetNicDns(nicDesc)
for i := 0; i < len(dnslist); i++ {
if !utils.IsInArray(dnslist[i], dnsSrv) {
dnsSrv = append(dnsSrv, dnslist[i])
}
dns4list, dns6list := netutils2.GetNicDns(nicDesc)
for i := 0; i < len(dns4list); i++ {
if !utils.IsInArray(dns4list[i], dnsSrv) {
dnsSrv = append(dnsSrv, dns4list[i])
}
}
for i := 0; i < len(dns6list); i++ {
if !utils.IsInArray(dns6list[i], dnsSrv) {
dnsSrv = append(dnsSrv, dns6list[i])
}
}

View File

@@ -351,13 +351,22 @@ func (w *SWindowsRootFs) DeployNetworkingScripts(rootfs IDiskPartition, nics []*
for _, r := range routes6 {
lines = append(lines, fmt.Sprintf(` netsh interface ipv6 add route %s/%d %s "%%%%b"`, r.Prefix, r.PrefixLen, r.Gateway.String()))
}
dnslist := netutils2.GetNicDns(snic)
if len(dnslist) > 0 {
dns4list, dns6list := netutils2.GetNicDns(snic)
if len(dns4list) > 0 {
lines = append(lines, fmt.Sprintf(
` netsh interface ip set dns name="%%%%b" source=static addr=%s`, dnslist[0]))
if len(dnslist) > 1 {
for i := 1; i < len(dnslist); i++ {
lines = append(lines, fmt.Sprintf(` netsh interface ip add dns "%%%%b" %s index=%d`, dnslist[i], i+1))
` netsh interface ip set dns name="%%%%b" source=static addr=%s`, dns4list[0]))
if len(dns4list) > 1 {
for i := 1; i < len(dns4list); i++ {
lines = append(lines, fmt.Sprintf(` netsh interface ip add dns "%%%%b" %s index=%d`, dns4list[i], i+1))
}
}
}
if len(dns6list) > 0 {
lines = append(lines, fmt.Sprintf(
` netsh interface ipv6 set dns name="%%%%b" source=static addr=%s`, dns6list[0]))
if len(dns6list) > 1 {
for i := 1; i < len(dns6list); i++ {
lines = append(lines, fmt.Sprintf(` netsh interface ip add dns "%%%%b" %s index=%d`, dns6list[i], i+1))
}
}
}

View File

@@ -415,14 +415,19 @@ func AddNicRoutes(routes4 []SRouteInfo, routes6 []SRouteInfo, nicDesc *types.SSe
return routes4, routes6
}
func GetNicDns(nicdesc *types.SServerNic) []string {
dnslist := []string{}
func GetNicDns(nicdesc *types.SServerNic) ([]string, []string) {
dns4list := []string{}
dns6list := []string{}
if len(nicdesc.Dns) > 0 {
for _, dns := range strings.Split(nicdesc.Dns, ",") {
dnslist = append(dnslist, dns)
if regutils.MatchIP6Addr(dns) {
dns6list = append(dns6list, dns)
} else {
dns4list = append(dns4list, dns)
}
}
}
return dnslist
return dns4list, dns6list
}
func NetBytes2Mask(mask []byte) string {

View File

@@ -17,6 +17,10 @@ package stringutils2
import (
"crypto/sha256"
"fmt"
"strings"
"github.com/google/uuid"
"github.com/zeebo/xxh3"
)
func GenId(ids ...string) string {
@@ -26,3 +30,9 @@ func GenId(ids ...string) string {
}
return fmt.Sprintf("%x", h.Sum(nil))
}
func GenUuid(ids ...string) string {
h := xxh3.HashString128(strings.Join(ids, "")).Bytes()
guid, _ := uuid.FromBytes(h[:])
return guid.String()
}

24
vendor/github.com/klauspost/cpuid/v2/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,24 @@
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so
# Folders
_obj
_test
# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out
*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*
_testmain.go
*.exe
*.test
*.prof

74
vendor/github.com/klauspost/cpuid/v2/.goreleaser.yml generated vendored Normal file
View File

@@ -0,0 +1,74 @@
# This is an example goreleaser.yaml file with some sane defaults.
# Make sure to check the documentation at http://goreleaser.com
builds:
-
id: "cpuid"
binary: cpuid
main: ./cmd/cpuid/main.go
env:
- CGO_ENABLED=0
flags:
- -ldflags=-s -w
goos:
- aix
- linux
- freebsd
- netbsd
- windows
- darwin
goarch:
- 386
- amd64
- arm64
goarm:
- 7
archives:
-
id: cpuid
name_template: "cpuid-{{ .Os }}_{{ .Arch }}_{{ .Version }}"
replacements:
aix: AIX
darwin: OSX
linux: Linux
windows: Windows
386: i386
amd64: x86_64
freebsd: FreeBSD
netbsd: NetBSD
format_overrides:
- goos: windows
format: zip
files:
- LICENSE
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
sort: asc
filters:
exclude:
- '^doc:'
- '^docs:'
- '^test:'
- '^tests:'
- '^Update\sREADME.md'
nfpms:
-
file_name_template: "cpuid_package_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
vendor: Klaus Post
homepage: https://github.com/klauspost/cpuid
maintainer: Klaus Post <klauspost@gmail.com>
description: CPUID Tool
license: BSD 3-Clause
formats:
- deb
- rpm
replacements:
darwin: Darwin
linux: Linux
freebsd: FreeBSD
amd64: x86_64

35
vendor/github.com/klauspost/cpuid/v2/CONTRIBUTING.txt generated vendored Normal file
View File

@@ -0,0 +1,35 @@
Developer Certificate of Origin
Version 1.1
Copyright (C) 2015- Klaus Post & Contributors.
Email: klauspost@gmail.com
Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.
Developer's Certificate of Origin 1.1
By making a contribution to this project, I certify that:
(a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license
indicated in the file; or
(b) The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source
license and I have the right under that license to submit that
work with modifications, whether created in whole or in part
by me, under the same open source license (unless I am
permitted to submit under a different license), as indicated
in the file; or
(c) The contribution was provided directly to me by some other
person who certified (a), (b) or (c) and I have not modified
it.
(d) I understand and agree that this project and the contribution
are public and that a record of the contribution (including all
personal information I submit with it, including my sign-off) is
maintained indefinitely and may be redistributed consistent with
this project or the open source license(s) involved.

22
vendor/github.com/klauspost/cpuid/v2/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,22 @@
The MIT License (MIT)
Copyright (c) 2015 Klaus Post
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

137
vendor/github.com/klauspost/cpuid/v2/README.md generated vendored Normal file
View File

@@ -0,0 +1,137 @@
# cpuid
Package cpuid provides information about the CPU running the current program.
CPU features are detected on startup, and kept for fast access through the life of the application.
Currently x86 / x64 (AMD64/i386) and ARM (ARM64) is supported, and no external C (cgo) code is used, which should make the library very easy to use.
You can access the CPU information by accessing the shared CPU variable of the cpuid library.
Package home: https://github.com/klauspost/cpuid
[![PkgGoDev](https://pkg.go.dev/badge/github.com/klauspost/cpuid)](https://pkg.go.dev/github.com/klauspost/cpuid/v2)
[![Build Status][3]][4]
[3]: https://travis-ci.org/klauspost/cpuid.svg?branch=master
[4]: https://travis-ci.org/klauspost/cpuid
## installing
`go get -u github.com/klauspost/cpuid/v2` using modules.
Drop `v2` for others.
## example
```Go
package main
import (
"fmt"
"strings"
. "github.com/klauspost/cpuid/v2"
)
func main() {
// Print basic CPU information:
fmt.Println("Name:", CPU.BrandName)
fmt.Println("PhysicalCores:", CPU.PhysicalCores)
fmt.Println("ThreadsPerCore:", CPU.ThreadsPerCore)
fmt.Println("LogicalCores:", CPU.LogicalCores)
fmt.Println("Family", CPU.Family, "Model:", CPU.Model, "Vendor ID:", CPU.VendorID)
fmt.Println("Features:", fmt.Sprintf(strings.Join(CPU.FeatureSet(), ",")))
fmt.Println("Cacheline bytes:", CPU.CacheLine)
fmt.Println("L1 Data Cache:", CPU.Cache.L1D, "bytes")
fmt.Println("L1 Instruction Cache:", CPU.Cache.L1D, "bytes")
fmt.Println("L2 Cache:", CPU.Cache.L2, "bytes")
fmt.Println("L3 Cache:", CPU.Cache.L3, "bytes")
fmt.Println("Frequency", CPU.Hz, "hz")
// Test if we have these specific features:
if CPU.Supports(SSE, SSE2) {
fmt.Println("We have Streaming SIMD 2 Extensions")
}
}
```
Sample output:
```
>go run main.go
Name: AMD Ryzen 9 3950X 16-Core Processor
PhysicalCores: 16
ThreadsPerCore: 2
LogicalCores: 32
Family 23 Model: 113 Vendor ID: AMD
Features: ADX,AESNI,AVX,AVX2,BMI1,BMI2,CLMUL,CMOV,CX16,F16C,FMA3,HTT,HYPERVISOR,LZCNT,MMX,MMXEXT,NX,POPCNT,RDRAND,RDSEED,RDTSCP,SHA,SSE,SSE2,SSE3,SSE4,SSE42,SSE4A,SSSE3
Cacheline bytes: 64
L1 Data Cache: 32768 bytes
L1 Instruction Cache: 32768 bytes
L2 Cache: 524288 bytes
L3 Cache: 16777216 bytes
Frequency 0 hz
We have Streaming SIMD 2 Extensions
```
# usage
The `cpuid.CPU` provides access to CPU features. Use `cpuid.CPU.Supports()` to check for CPU features.
A faster `cpuid.CPU.Has()` is provided which will usually be inlined by the gc compiler.
Note that for some cpu/os combinations some features will not be detected.
`amd64` has rather good support and should work reliably on all platforms.
Note that hypervisors may not pass through all CPU features.
## arm64 feature detection
Not all operating systems provide ARM features directly
and there is no safe way to do so for the rest.
Currently `arm64/linux` and `arm64/freebsd` should be quite reliable.
`arm64/darwin` adds features expected from the M1 processor, but a lot remains undetected.
A `DetectARM()` can be used if you are able to control your deployment,
it will detect CPU features, but may crash if the OS doesn't intercept the calls.
A `-cpu.arm` flag for detecting unsafe ARM features can be added. See below.
Note that currently only features are detected on ARM,
no additional information is currently available.
## flags
It is possible to add flags that affects cpu detection.
For this the `Flags()` command is provided.
This must be called *before* `flag.Parse()` AND after the flags have been parsed `Detect()` must be called.
This means that any detection used in `init()` functions will not contain these flags.
Example:
```Go
package main
import (
"flag"
"fmt"
"strings"
"github.com/klauspost/cpuid/v2"
)
func main() {
cpuid.Flags()
flag.Parse()
cpuid.Detect()
// Test if we have these specific features:
if cpuid.CPU.Supports(cpuid.SSE, cpuid.SSE2) {
fmt.Println("We have Streaming SIMD 2 Extensions")
}
}
```
# license
This code is published under an MIT license. See LICENSE file for more information.

1070
vendor/github.com/klauspost/cpuid/v2/cpuid.go generated vendored Normal file

File diff suppressed because it is too large Load Diff

47
vendor/github.com/klauspost/cpuid/v2/cpuid_386.s generated vendored Normal file
View File

@@ -0,0 +1,47 @@
// Copyright (c) 2015 Klaus Post, released under MIT License. See LICENSE file.
//+build 386,!gccgo,!noasm,!appengine
// func asmCpuid(op uint32) (eax, ebx, ecx, edx uint32)
TEXT ·asmCpuid(SB), 7, $0
XORL CX, CX
MOVL op+0(FP), AX
CPUID
MOVL AX, eax+4(FP)
MOVL BX, ebx+8(FP)
MOVL CX, ecx+12(FP)
MOVL DX, edx+16(FP)
RET
// func asmCpuidex(op, op2 uint32) (eax, ebx, ecx, edx uint32)
TEXT ·asmCpuidex(SB), 7, $0
MOVL op+0(FP), AX
MOVL op2+4(FP), CX
CPUID
MOVL AX, eax+8(FP)
MOVL BX, ebx+12(FP)
MOVL CX, ecx+16(FP)
MOVL DX, edx+20(FP)
RET
// func xgetbv(index uint32) (eax, edx uint32)
TEXT ·asmXgetbv(SB), 7, $0
MOVL index+0(FP), CX
BYTE $0x0f; BYTE $0x01; BYTE $0xd0 // XGETBV
MOVL AX, eax+4(FP)
MOVL DX, edx+8(FP)
RET
// func asmRdtscpAsm() (eax, ebx, ecx, edx uint32)
TEXT ·asmRdtscpAsm(SB), 7, $0
BYTE $0x0F; BYTE $0x01; BYTE $0xF9 // RDTSCP
MOVL AX, eax+0(FP)
MOVL BX, ebx+4(FP)
MOVL CX, ecx+8(FP)
MOVL DX, edx+12(FP)
RET
// func asmDarwinHasAVX512() bool
TEXT ·asmDarwinHasAVX512(SB), 7, $0
MOVL $0, eax+0(FP)
RET

72
vendor/github.com/klauspost/cpuid/v2/cpuid_amd64.s generated vendored Normal file
View File

@@ -0,0 +1,72 @@
// Copyright (c) 2015 Klaus Post, released under MIT License. See LICENSE file.
//+build amd64,!gccgo,!noasm,!appengine
// func asmCpuid(op uint32) (eax, ebx, ecx, edx uint32)
TEXT ·asmCpuid(SB), 7, $0
XORQ CX, CX
MOVL op+0(FP), AX
CPUID
MOVL AX, eax+8(FP)
MOVL BX, ebx+12(FP)
MOVL CX, ecx+16(FP)
MOVL DX, edx+20(FP)
RET
// func asmCpuidex(op, op2 uint32) (eax, ebx, ecx, edx uint32)
TEXT ·asmCpuidex(SB), 7, $0
MOVL op+0(FP), AX
MOVL op2+4(FP), CX
CPUID
MOVL AX, eax+8(FP)
MOVL BX, ebx+12(FP)
MOVL CX, ecx+16(FP)
MOVL DX, edx+20(FP)
RET
// func asmXgetbv(index uint32) (eax, edx uint32)
TEXT ·asmXgetbv(SB), 7, $0
MOVL index+0(FP), CX
BYTE $0x0f; BYTE $0x01; BYTE $0xd0 // XGETBV
MOVL AX, eax+8(FP)
MOVL DX, edx+12(FP)
RET
// func asmRdtscpAsm() (eax, ebx, ecx, edx uint32)
TEXT ·asmRdtscpAsm(SB), 7, $0
BYTE $0x0F; BYTE $0x01; BYTE $0xF9 // RDTSCP
MOVL AX, eax+0(FP)
MOVL BX, ebx+4(FP)
MOVL CX, ecx+8(FP)
MOVL DX, edx+12(FP)
RET
// From https://go-review.googlesource.com/c/sys/+/285572/
// func asmDarwinHasAVX512() bool
TEXT ·asmDarwinHasAVX512(SB), 7, $0-1
MOVB $0, ret+0(FP) // default to false
#ifdef GOOS_darwin // return if not darwin
#ifdef GOARCH_amd64 // return if not amd64
// These values from:
// https://github.com/apple/darwin-xnu/blob/xnu-4570.1.46/osfmk/i386/cpu_capabilities.h
#define commpage64_base_address 0x00007fffffe00000
#define commpage64_cpu_capabilities64 (commpage64_base_address+0x010)
#define commpage64_version (commpage64_base_address+0x01E)
#define hasAVX512F 0x0000004000000000
MOVQ $commpage64_version, BX
MOVW (BX), AX
CMPW AX, $13 // versions < 13 do not support AVX512
JL no_avx512
MOVQ $commpage64_cpu_capabilities64, BX
MOVQ (BX), AX
MOVQ $hasAVX512F, CX
ANDQ CX, AX
JZ no_avx512
MOVB $1, ret+0(FP)
no_avx512:
#endif
#endif
RET

26
vendor/github.com/klauspost/cpuid/v2/cpuid_arm64.s generated vendored Normal file
View File

@@ -0,0 +1,26 @@
// Copyright (c) 2015 Klaus Post, released under MIT License. See LICENSE file.
//+build arm64,!gccgo,!noasm,!appengine
// See https://www.kernel.org/doc/Documentation/arm64/cpu-feature-registers.txt
// func getMidr
TEXT ·getMidr(SB), 7, $0
WORD $0xd5380000 // mrs x0, midr_el1 /* Main ID Register */
MOVD R0, midr+0(FP)
RET
// func getProcFeatures
TEXT ·getProcFeatures(SB), 7, $0
WORD $0xd5380400 // mrs x0, id_aa64pfr0_el1 /* Processor Feature Register 0 */
MOVD R0, procFeatures+0(FP)
RET
// func getInstAttributes
TEXT ·getInstAttributes(SB), 7, $0
WORD $0xd5380600 // mrs x0, id_aa64isar0_el1 /* Instruction Set Attribute Register 0 */
WORD $0xd5380621 // mrs x1, id_aa64isar1_el1 /* Instruction Set Attribute Register 1 */
MOVD R0, instAttrReg0+0(FP)
MOVD R1, instAttrReg1+8(FP)
RET

246
vendor/github.com/klauspost/cpuid/v2/detect_arm64.go generated vendored Normal file
View File

@@ -0,0 +1,246 @@
// Copyright (c) 2015 Klaus Post, released under MIT License. See LICENSE file.
//+build arm64,!gccgo,!noasm,!appengine
package cpuid
import "runtime"
func getMidr() (midr uint64)
func getProcFeatures() (procFeatures uint64)
func getInstAttributes() (instAttrReg0, instAttrReg1 uint64)
func initCPU() {
cpuid = func(uint32) (a, b, c, d uint32) { return 0, 0, 0, 0 }
cpuidex = func(x, y uint32) (a, b, c, d uint32) { return 0, 0, 0, 0 }
xgetbv = func(uint32) (a, b uint32) { return 0, 0 }
rdtscpAsm = func() (a, b, c, d uint32) { return 0, 0, 0, 0 }
}
func addInfo(c *CPUInfo, safe bool) {
// Seems to be safe to assume on ARM64
c.CacheLine = 64
detectOS(c)
// ARM64 disabled since it may crash if interrupt is not intercepted by OS.
if safe && !c.Supports(ARMCPUID) && runtime.GOOS != "freebsd" {
return
}
midr := getMidr()
// MIDR_EL1 - Main ID Register
// https://developer.arm.com/docs/ddi0595/h/aarch64-system-registers/midr_el1
// x--------------------------------------------------x
// | Name | bits | visible |
// |--------------------------------------------------|
// | Implementer | [31-24] | y |
// |--------------------------------------------------|
// | Variant | [23-20] | y |
// |--------------------------------------------------|
// | Architecture | [19-16] | y |
// |--------------------------------------------------|
// | PartNum | [15-4] | y |
// |--------------------------------------------------|
// | Revision | [3-0] | y |
// x--------------------------------------------------x
switch (midr >> 24) & 0xff {
case 0xC0:
c.VendorString = "Ampere Computing"
c.VendorID = Ampere
case 0x41:
c.VendorString = "Arm Limited"
c.VendorID = ARM
case 0x42:
c.VendorString = "Broadcom Corporation"
c.VendorID = Broadcom
case 0x43:
c.VendorString = "Cavium Inc"
c.VendorID = Cavium
case 0x44:
c.VendorString = "Digital Equipment Corporation"
c.VendorID = DEC
case 0x46:
c.VendorString = "Fujitsu Ltd"
c.VendorID = Fujitsu
case 0x49:
c.VendorString = "Infineon Technologies AG"
c.VendorID = Infineon
case 0x4D:
c.VendorString = "Motorola or Freescale Semiconductor Inc"
c.VendorID = Motorola
case 0x4E:
c.VendorString = "NVIDIA Corporation"
c.VendorID = NVIDIA
case 0x50:
c.VendorString = "Applied Micro Circuits Corporation"
c.VendorID = AMCC
case 0x51:
c.VendorString = "Qualcomm Inc"
c.VendorID = Qualcomm
case 0x56:
c.VendorString = "Marvell International Ltd"
c.VendorID = Marvell
case 0x69:
c.VendorString = "Intel Corporation"
c.VendorID = Intel
}
// Lower 4 bits: Architecture
// Architecture Meaning
// 0b0001 Armv4.
// 0b0010 Armv4T.
// 0b0011 Armv5 (obsolete).
// 0b0100 Armv5T.
// 0b0101 Armv5TE.
// 0b0110 Armv5TEJ.
// 0b0111 Armv6.
// 0b1111 Architectural features are individually identified in the ID_* registers, see 'ID registers'.
// Upper 4 bit: Variant
// An IMPLEMENTATION DEFINED variant number.
// Typically, this field is used to distinguish between different product variants, or major revisions of a product.
c.Family = int(midr>>16) & 0xff
// PartNum, bits [15:4]
// An IMPLEMENTATION DEFINED primary part number for the device.
// On processors implemented by Arm, if the top four bits of the primary
// part number are 0x0 or 0x7, the variant and architecture are encoded differently.
// Revision, bits [3:0]
// An IMPLEMENTATION DEFINED revision number for the device.
c.Model = int(midr) & 0xffff
procFeatures := getProcFeatures()
// ID_AA64PFR0_EL1 - Processor Feature Register 0
// x--------------------------------------------------x
// | Name | bits | visible |
// |--------------------------------------------------|
// | DIT | [51-48] | y |
// |--------------------------------------------------|
// | SVE | [35-32] | y |
// |--------------------------------------------------|
// | GIC | [27-24] | n |
// |--------------------------------------------------|
// | AdvSIMD | [23-20] | y |
// |--------------------------------------------------|
// | FP | [19-16] | y |
// |--------------------------------------------------|
// | EL3 | [15-12] | n |
// |--------------------------------------------------|
// | EL2 | [11-8] | n |
// |--------------------------------------------------|
// | EL1 | [7-4] | n |
// |--------------------------------------------------|
// | EL0 | [3-0] | n |
// x--------------------------------------------------x
var f flagSet
// if procFeatures&(0xf<<48) != 0 {
// fmt.Println("DIT")
// }
f.setIf(procFeatures&(0xf<<32) != 0, SVE)
if procFeatures&(0xf<<20) != 15<<20 {
f.set(ASIMD)
// https://developer.arm.com/docs/ddi0595/b/aarch64-system-registers/id_aa64pfr0_el1
// 0b0001 --> As for 0b0000, and also includes support for half-precision floating-point arithmetic.
f.setIf(procFeatures&(0xf<<20) == 1<<20, FPHP, ASIMDHP)
}
f.setIf(procFeatures&(0xf<<16) != 0, FP)
instAttrReg0, instAttrReg1 := getInstAttributes()
// https://developer.arm.com/docs/ddi0595/b/aarch64-system-registers/id_aa64isar0_el1
//
// ID_AA64ISAR0_EL1 - Instruction Set Attribute Register 0
// x--------------------------------------------------x
// | Name | bits | visible |
// |--------------------------------------------------|
// | TS | [55-52] | y |
// |--------------------------------------------------|
// | FHM | [51-48] | y |
// |--------------------------------------------------|
// | DP | [47-44] | y |
// |--------------------------------------------------|
// | SM4 | [43-40] | y |
// |--------------------------------------------------|
// | SM3 | [39-36] | y |
// |--------------------------------------------------|
// | SHA3 | [35-32] | y |
// |--------------------------------------------------|
// | RDM | [31-28] | y |
// |--------------------------------------------------|
// | ATOMICS | [23-20] | y |
// |--------------------------------------------------|
// | CRC32 | [19-16] | y |
// |--------------------------------------------------|
// | SHA2 | [15-12] | y |
// |--------------------------------------------------|
// | SHA1 | [11-8] | y |
// |--------------------------------------------------|
// | AES | [7-4] | y |
// x--------------------------------------------------x
// if instAttrReg0&(0xf<<52) != 0 {
// fmt.Println("TS")
// }
// if instAttrReg0&(0xf<<48) != 0 {
// fmt.Println("FHM")
// }
f.setIf(instAttrReg0&(0xf<<44) != 0, ASIMDDP)
f.setIf(instAttrReg0&(0xf<<40) != 0, SM4)
f.setIf(instAttrReg0&(0xf<<36) != 0, SM3)
f.setIf(instAttrReg0&(0xf<<32) != 0, SHA3)
f.setIf(instAttrReg0&(0xf<<28) != 0, ASIMDRDM)
f.setIf(instAttrReg0&(0xf<<20) != 0, ATOMICS)
f.setIf(instAttrReg0&(0xf<<16) != 0, CRC32)
f.setIf(instAttrReg0&(0xf<<12) != 0, SHA2)
// https://developer.arm.com/docs/ddi0595/b/aarch64-system-registers/id_aa64isar0_el1
// 0b0010 --> As 0b0001, plus SHA512H, SHA512H2, SHA512SU0, and SHA512SU1 instructions implemented.
f.setIf(instAttrReg0&(0xf<<12) == 2<<12, SHA512)
f.setIf(instAttrReg0&(0xf<<8) != 0, SHA1)
f.setIf(instAttrReg0&(0xf<<4) != 0, AESARM)
// https://developer.arm.com/docs/ddi0595/b/aarch64-system-registers/id_aa64isar0_el1
// 0b0010 --> As for 0b0001, plus PMULL/PMULL2 instructions operating on 64-bit data quantities.
f.setIf(instAttrReg0&(0xf<<4) == 2<<4, PMULL)
// https://developer.arm.com/docs/ddi0595/b/aarch64-system-registers/id_aa64isar1_el1
//
// ID_AA64ISAR1_EL1 - Instruction set attribute register 1
// x--------------------------------------------------x
// | Name | bits | visible |
// |--------------------------------------------------|
// | GPI | [31-28] | y |
// |--------------------------------------------------|
// | GPA | [27-24] | y |
// |--------------------------------------------------|
// | LRCPC | [23-20] | y |
// |--------------------------------------------------|
// | FCMA | [19-16] | y |
// |--------------------------------------------------|
// | JSCVT | [15-12] | y |
// |--------------------------------------------------|
// | API | [11-8] | y |
// |--------------------------------------------------|
// | APA | [7-4] | y |
// |--------------------------------------------------|
// | DPB | [3-0] | y |
// x--------------------------------------------------x
// if instAttrReg1&(0xf<<28) != 0 {
// fmt.Println("GPI")
// }
f.setIf(instAttrReg1&(0xf<<28) != 24, GPA)
f.setIf(instAttrReg1&(0xf<<20) != 0, LRCPC)
f.setIf(instAttrReg1&(0xf<<16) != 0, FCMA)
f.setIf(instAttrReg1&(0xf<<12) != 0, JSCVT)
// if instAttrReg1&(0xf<<8) != 0 {
// fmt.Println("API")
// }
// if instAttrReg1&(0xf<<4) != 0 {
// fmt.Println("APA")
// }
f.setIf(instAttrReg1&(0xf<<0) != 0, DCPOP)
// Store
c.featureSet.or(f)
}

14
vendor/github.com/klauspost/cpuid/v2/detect_ref.go generated vendored Normal file
View File

@@ -0,0 +1,14 @@
// Copyright (c) 2015 Klaus Post, released under MIT License. See LICENSE file.
//+build !amd64,!386,!arm64 gccgo noasm appengine
package cpuid
func initCPU() {
cpuid = func(uint32) (a, b, c, d uint32) { return 0, 0, 0, 0 }
cpuidex = func(x, y uint32) (a, b, c, d uint32) { return 0, 0, 0, 0 }
xgetbv = func(uint32) (a, b uint32) { return 0, 0 }
rdtscpAsm = func() (a, b, c, d uint32) { return 0, 0, 0, 0 }
}
func addInfo(info *CPUInfo, safe bool) {}

35
vendor/github.com/klauspost/cpuid/v2/detect_x86.go generated vendored Normal file
View File

@@ -0,0 +1,35 @@
// Copyright (c) 2015 Klaus Post, released under MIT License. See LICENSE file.
//+build 386,!gccgo,!noasm,!appengine amd64,!gccgo,!noasm,!appengine
package cpuid
func asmCpuid(op uint32) (eax, ebx, ecx, edx uint32)
func asmCpuidex(op, op2 uint32) (eax, ebx, ecx, edx uint32)
func asmXgetbv(index uint32) (eax, edx uint32)
func asmRdtscpAsm() (eax, ebx, ecx, edx uint32)
func asmDarwinHasAVX512() bool
func initCPU() {
cpuid = asmCpuid
cpuidex = asmCpuidex
xgetbv = asmXgetbv
rdtscpAsm = asmRdtscpAsm
darwinHasAVX512 = asmDarwinHasAVX512
}
func addInfo(c *CPUInfo, safe bool) {
c.maxFunc = maxFunctionID()
c.maxExFunc = maxExtendedFunction()
c.BrandName = brandName()
c.CacheLine = cacheLine()
c.Family, c.Model = familyModel()
c.featureSet = support()
c.SGX = hasSGX(c.featureSet.inSet(SGX), c.featureSet.inSet(SGXLC))
c.ThreadsPerCore = threadsPerCore()
c.LogicalCores = logicalCores()
c.PhysicalCores = physicalCores()
c.VendorID, c.VendorString = vendorID()
c.cacheSize()
c.frequencies()
}

View File

@@ -0,0 +1,185 @@
// Code generated by "stringer -type=FeatureID,Vendor"; DO NOT EDIT.
package cpuid
import "strconv"
func _() {
// An "invalid array index" compiler error signifies that the constant values have changed.
// Re-run the stringer command to generate them again.
var x [1]struct{}
_ = x[ADX-1]
_ = x[AESNI-2]
_ = x[AMD3DNOW-3]
_ = x[AMD3DNOWEXT-4]
_ = x[AMXBF16-5]
_ = x[AMXINT8-6]
_ = x[AMXTILE-7]
_ = x[AVX-8]
_ = x[AVX2-9]
_ = x[AVX512BF16-10]
_ = x[AVX512BITALG-11]
_ = x[AVX512BW-12]
_ = x[AVX512CD-13]
_ = x[AVX512DQ-14]
_ = x[AVX512ER-15]
_ = x[AVX512F-16]
_ = x[AVX512FP16-17]
_ = x[AVX512IFMA-18]
_ = x[AVX512PF-19]
_ = x[AVX512VBMI-20]
_ = x[AVX512VBMI2-21]
_ = x[AVX512VL-22]
_ = x[AVX512VNNI-23]
_ = x[AVX512VP2INTERSECT-24]
_ = x[AVX512VPOPCNTDQ-25]
_ = x[AVXSLOW-26]
_ = x[BMI1-27]
_ = x[BMI2-28]
_ = x[CLDEMOTE-29]
_ = x[CLMUL-30]
_ = x[CLZERO-31]
_ = x[CMOV-32]
_ = x[CPBOOST-33]
_ = x[CX16-34]
_ = x[ENQCMD-35]
_ = x[ERMS-36]
_ = x[F16C-37]
_ = x[FMA3-38]
_ = x[FMA4-39]
_ = x[GFNI-40]
_ = x[HLE-41]
_ = x[HTT-42]
_ = x[HWA-43]
_ = x[HYPERVISOR-44]
_ = x[IBPB-45]
_ = x[IBS-46]
_ = x[IBSBRNTRGT-47]
_ = x[IBSFETCHSAM-48]
_ = x[IBSFFV-49]
_ = x[IBSOPCNT-50]
_ = x[IBSOPCNTEXT-51]
_ = x[IBSOPSAM-52]
_ = x[IBSRDWROPCNT-53]
_ = x[IBSRIPINVALIDCHK-54]
_ = x[INT_WBINVD-55]
_ = x[INVLPGB-56]
_ = x[LZCNT-57]
_ = x[MCAOVERFLOW-58]
_ = x[MCOMMIT-59]
_ = x[MMX-60]
_ = x[MMXEXT-61]
_ = x[MOVDIR64B-62]
_ = x[MOVDIRI-63]
_ = x[MPX-64]
_ = x[MSRIRC-65]
_ = x[NX-66]
_ = x[POPCNT-67]
_ = x[RDPRU-68]
_ = x[RDRAND-69]
_ = x[RDSEED-70]
_ = x[RDTSCP-71]
_ = x[RTM-72]
_ = x[RTM_ALWAYS_ABORT-73]
_ = x[SERIALIZE-74]
_ = x[SGX-75]
_ = x[SGXLC-76]
_ = x[SHA-77]
_ = x[SSE-78]
_ = x[SSE2-79]
_ = x[SSE3-80]
_ = x[SSE4-81]
_ = x[SSE42-82]
_ = x[SSE4A-83]
_ = x[SSSE3-84]
_ = x[STIBP-85]
_ = x[SUCCOR-86]
_ = x[TBM-87]
_ = x[TSXLDTRK-88]
_ = x[VAES-89]
_ = x[VMX-90]
_ = x[VPCLMULQDQ-91]
_ = x[WAITPKG-92]
_ = x[WBNOINVD-93]
_ = x[XOP-94]
_ = x[AESARM-95]
_ = x[ARMCPUID-96]
_ = x[ASIMD-97]
_ = x[ASIMDDP-98]
_ = x[ASIMDHP-99]
_ = x[ASIMDRDM-100]
_ = x[ATOMICS-101]
_ = x[CRC32-102]
_ = x[DCPOP-103]
_ = x[EVTSTRM-104]
_ = x[FCMA-105]
_ = x[FP-106]
_ = x[FPHP-107]
_ = x[GPA-108]
_ = x[JSCVT-109]
_ = x[LRCPC-110]
_ = x[PMULL-111]
_ = x[SHA1-112]
_ = x[SHA2-113]
_ = x[SHA3-114]
_ = x[SHA512-115]
_ = x[SM3-116]
_ = x[SM4-117]
_ = x[SVE-118]
_ = x[lastID-119]
_ = x[firstID-0]
}
const _FeatureID_name = "firstIDADXAESNIAMD3DNOWAMD3DNOWEXTAMXBF16AMXINT8AMXTILEAVXAVX2AVX512BF16AVX512BITALGAVX512BWAVX512CDAVX512DQAVX512ERAVX512FAVX512FP16AVX512IFMAAVX512PFAVX512VBMIAVX512VBMI2AVX512VLAVX512VNNIAVX512VP2INTERSECTAVX512VPOPCNTDQAVXSLOWBMI1BMI2CLDEMOTECLMULCLZEROCMOVCPBOOSTCX16ENQCMDERMSF16CFMA3FMA4GFNIHLEHTTHWAHYPERVISORIBPBIBSIBSBRNTRGTIBSFETCHSAMIBSFFVIBSOPCNTIBSOPCNTEXTIBSOPSAMIBSRDWROPCNTIBSRIPINVALIDCHKINT_WBINVDINVLPGBLZCNTMCAOVERFLOWMCOMMITMMXMMXEXTMOVDIR64BMOVDIRIMPXMSRIRCNXPOPCNTRDPRURDRANDRDSEEDRDTSCPRTMRTM_ALWAYS_ABORTSERIALIZESGXSGXLCSHASSESSE2SSE3SSE4SSE42SSE4ASSSE3STIBPSUCCORTBMTSXLDTRKVAESVMXVPCLMULQDQWAITPKGWBNOINVDXOPAESARMARMCPUIDASIMDASIMDDPASIMDHPASIMDRDMATOMICSCRC32DCPOPEVTSTRMFCMAFPFPHPGPAJSCVTLRCPCPMULLSHA1SHA2SHA3SHA512SM3SM4SVElastID"
var _FeatureID_index = [...]uint16{0, 7, 10, 15, 23, 34, 41, 48, 55, 58, 62, 72, 84, 92, 100, 108, 116, 123, 133, 143, 151, 161, 172, 180, 190, 208, 223, 230, 234, 238, 246, 251, 257, 261, 268, 272, 278, 282, 286, 290, 294, 298, 301, 304, 307, 317, 321, 324, 334, 345, 351, 359, 370, 378, 390, 406, 416, 423, 428, 439, 446, 449, 455, 464, 471, 474, 480, 482, 488, 493, 499, 505, 511, 514, 530, 539, 542, 547, 550, 553, 557, 561, 565, 570, 575, 580, 585, 591, 594, 602, 606, 609, 619, 626, 634, 637, 643, 651, 656, 663, 670, 678, 685, 690, 695, 702, 706, 708, 712, 715, 720, 725, 730, 734, 738, 742, 748, 751, 754, 757, 763}
func (i FeatureID) String() string {
if i < 0 || i >= FeatureID(len(_FeatureID_index)-1) {
return "FeatureID(" + strconv.FormatInt(int64(i), 10) + ")"
}
return _FeatureID_name[_FeatureID_index[i]:_FeatureID_index[i+1]]
}
func _() {
// An "invalid array index" compiler error signifies that the constant values have changed.
// Re-run the stringer command to generate them again.
var x [1]struct{}
_ = x[VendorUnknown-0]
_ = x[Intel-1]
_ = x[AMD-2]
_ = x[VIA-3]
_ = x[Transmeta-4]
_ = x[NSC-5]
_ = x[KVM-6]
_ = x[MSVM-7]
_ = x[VMware-8]
_ = x[XenHVM-9]
_ = x[Bhyve-10]
_ = x[Hygon-11]
_ = x[SiS-12]
_ = x[RDC-13]
_ = x[Ampere-14]
_ = x[ARM-15]
_ = x[Broadcom-16]
_ = x[Cavium-17]
_ = x[DEC-18]
_ = x[Fujitsu-19]
_ = x[Infineon-20]
_ = x[Motorola-21]
_ = x[NVIDIA-22]
_ = x[AMCC-23]
_ = x[Qualcomm-24]
_ = x[Marvell-25]
_ = x[lastVendor-26]
}
const _Vendor_name = "VendorUnknownIntelAMDVIATransmetaNSCKVMMSVMVMwareXenHVMBhyveHygonSiSRDCAmpereARMBroadcomCaviumDECFujitsuInfineonMotorolaNVIDIAAMCCQualcommMarvelllastVendor"
var _Vendor_index = [...]uint8{0, 13, 18, 21, 24, 33, 36, 39, 43, 49, 55, 60, 65, 68, 71, 77, 80, 88, 94, 97, 104, 112, 120, 126, 130, 138, 145, 155}
func (i Vendor) String() string {
if i < 0 || i >= Vendor(len(_Vendor_index)-1) {
return "Vendor(" + strconv.FormatInt(int64(i), 10) + ")"
}
return _Vendor_name[_Vendor_index[i]:_Vendor_index[i+1]]
}

View File

@@ -0,0 +1,19 @@
// Copyright (c) 2020 Klaus Post, released under MIT License. See LICENSE file.
package cpuid
import "runtime"
func detectOS(c *CPUInfo) bool {
// There are no hw.optional sysctl values for the below features on Mac OS 11.0
// to detect their supported state dynamically. Assume the CPU features that
// Apple Silicon M1 supports to be available as a minimal set of features
// to all Go programs running on darwin/arm64.
// TODO: Add more if we know them.
c.featureSet.setIf(runtime.GOOS != "ios", AESARM, PMULL, SHA1, SHA2)
c.PhysicalCores = runtime.NumCPU()
// For now assuming 1 thread per core...
c.ThreadsPerCore = 1
c.LogicalCores = c.PhysicalCores
return true
}

130
vendor/github.com/klauspost/cpuid/v2/os_linux_arm64.go generated vendored Normal file
View File

@@ -0,0 +1,130 @@
// Copyright (c) 2020 Klaus Post, released under MIT License. See LICENSE file.
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file located
// here https://github.com/golang/sys/blob/master/LICENSE
package cpuid
import (
"encoding/binary"
"io/ioutil"
"runtime"
)
// HWCAP bits.
const (
hwcap_FP = 1 << 0
hwcap_ASIMD = 1 << 1
hwcap_EVTSTRM = 1 << 2
hwcap_AES = 1 << 3
hwcap_PMULL = 1 << 4
hwcap_SHA1 = 1 << 5
hwcap_SHA2 = 1 << 6
hwcap_CRC32 = 1 << 7
hwcap_ATOMICS = 1 << 8
hwcap_FPHP = 1 << 9
hwcap_ASIMDHP = 1 << 10
hwcap_CPUID = 1 << 11
hwcap_ASIMDRDM = 1 << 12
hwcap_JSCVT = 1 << 13
hwcap_FCMA = 1 << 14
hwcap_LRCPC = 1 << 15
hwcap_DCPOP = 1 << 16
hwcap_SHA3 = 1 << 17
hwcap_SM3 = 1 << 18
hwcap_SM4 = 1 << 19
hwcap_ASIMDDP = 1 << 20
hwcap_SHA512 = 1 << 21
hwcap_SVE = 1 << 22
hwcap_ASIMDFHM = 1 << 23
)
func detectOS(c *CPUInfo) bool {
// For now assuming no hyperthreading is reasonable.
c.LogicalCores = runtime.NumCPU()
c.PhysicalCores = c.LogicalCores
c.ThreadsPerCore = 1
if hwcap == 0 {
// We did not get values from the runtime.
// Try reading /proc/self/auxv
// From https://github.com/golang/sys
const (
_AT_HWCAP = 16
_AT_HWCAP2 = 26
uintSize = int(32 << (^uint(0) >> 63))
)
buf, err := ioutil.ReadFile("/proc/self/auxv")
if err != nil {
// e.g. on android /proc/self/auxv is not accessible, so silently
// ignore the error and leave Initialized = false. On some
// architectures (e.g. arm64) doinit() implements a fallback
// readout and will set Initialized = true again.
return false
}
bo := binary.LittleEndian
for len(buf) >= 2*(uintSize/8) {
var tag, val uint
switch uintSize {
case 32:
tag = uint(bo.Uint32(buf[0:]))
val = uint(bo.Uint32(buf[4:]))
buf = buf[8:]
case 64:
tag = uint(bo.Uint64(buf[0:]))
val = uint(bo.Uint64(buf[8:]))
buf = buf[16:]
}
switch tag {
case _AT_HWCAP:
hwcap = val
case _AT_HWCAP2:
// Not used
}
}
if hwcap == 0 {
return false
}
}
// HWCap was populated by the runtime from the auxiliary vector.
// Use HWCap information since reading aarch64 system registers
// is not supported in user space on older linux kernels.
c.featureSet.setIf(isSet(hwcap, hwcap_AES), AESARM)
c.featureSet.setIf(isSet(hwcap, hwcap_ASIMD), ASIMD)
c.featureSet.setIf(isSet(hwcap, hwcap_ASIMDDP), ASIMDDP)
c.featureSet.setIf(isSet(hwcap, hwcap_ASIMDHP), ASIMDHP)
c.featureSet.setIf(isSet(hwcap, hwcap_ASIMDRDM), ASIMDRDM)
c.featureSet.setIf(isSet(hwcap, hwcap_CPUID), ARMCPUID)
c.featureSet.setIf(isSet(hwcap, hwcap_CRC32), CRC32)
c.featureSet.setIf(isSet(hwcap, hwcap_DCPOP), DCPOP)
c.featureSet.setIf(isSet(hwcap, hwcap_EVTSTRM), EVTSTRM)
c.featureSet.setIf(isSet(hwcap, hwcap_FCMA), FCMA)
c.featureSet.setIf(isSet(hwcap, hwcap_FP), FP)
c.featureSet.setIf(isSet(hwcap, hwcap_FPHP), FPHP)
c.featureSet.setIf(isSet(hwcap, hwcap_JSCVT), JSCVT)
c.featureSet.setIf(isSet(hwcap, hwcap_LRCPC), LRCPC)
c.featureSet.setIf(isSet(hwcap, hwcap_PMULL), PMULL)
c.featureSet.setIf(isSet(hwcap, hwcap_SHA1), SHA1)
c.featureSet.setIf(isSet(hwcap, hwcap_SHA2), SHA2)
c.featureSet.setIf(isSet(hwcap, hwcap_SHA3), SHA3)
c.featureSet.setIf(isSet(hwcap, hwcap_SHA512), SHA512)
c.featureSet.setIf(isSet(hwcap, hwcap_SM3), SM3)
c.featureSet.setIf(isSet(hwcap, hwcap_SM4), SM4)
c.featureSet.setIf(isSet(hwcap, hwcap_SVE), SVE)
// The Samsung S9+ kernel reports support for atomics, but not all cores
// actually support them, resulting in SIGILL. See issue #28431.
// TODO(elias.naur): Only disable the optimization on bad chipsets on android.
c.featureSet.setIf(isSet(hwcap, hwcap_ATOMICS) && runtime.GOOS != "android", ATOMICS)
return true
}
func isSet(hwc uint, value uint) bool {
return hwc&value != 0
}

17
vendor/github.com/klauspost/cpuid/v2/os_other_arm64.go generated vendored Normal file
View File

@@ -0,0 +1,17 @@
// Copyright (c) 2020 Klaus Post, released under MIT License. See LICENSE file.
// +build arm64
// +build !linux
// +build !darwin
package cpuid
import "runtime"
func detectOS(c *CPUInfo) bool {
c.PhysicalCores = runtime.NumCPU()
// For now assuming 1 thread per core...
c.ThreadsPerCore = 1
c.LogicalCores = c.PhysicalCores
return false
}

View File

@@ -0,0 +1,7 @@
// Copyright (c) 2021 Klaus Post, released under MIT License. See LICENSE file.
//+build nounsafe
package cpuid
var hwcap uint

View File

@@ -0,0 +1,10 @@
// Copyright (c) 2021 Klaus Post, released under MIT License. See LICENSE file.
//+build !nounsafe
package cpuid
import _ "unsafe" // needed for go:linkname
//go:linkname hwcap internal/cpu.HWCap
var hwcap uint

View File

@@ -0,0 +1,15 @@
#!/bin/sh
set -e
go tool dist list | while IFS=/ read os arch; do
echo "Checking $os/$arch..."
echo " normal"
GOARCH=$arch GOOS=$os go build -o /dev/null .
echo " noasm"
GOARCH=$arch GOOS=$os go build -tags noasm -o /dev/null .
echo " appengine"
GOARCH=$arch GOOS=$os go build -tags appengine -o /dev/null .
echo " noasm,appengine"
GOARCH=$arch GOOS=$os go build -tags 'appengine noasm' -o /dev/null .
done

6
vendor/github.com/zeebo/xxh3/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,6 @@
upstream
*.pprof
xxh3.test
.vscode
*.txt
_compat

25
vendor/github.com/zeebo/xxh3/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,25 @@
xxHash Library
Copyright (c) 2012-2014, Yann Collet
Copyright (c) 2019, Jeff Wendling
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

27
vendor/github.com/zeebo/xxh3/Makefile generated vendored Normal file
View File

@@ -0,0 +1,27 @@
.PHONY: all vet
all: genasm _compat
genasm: avo/avx.go avo/sse.go
cd ./avo; go generate gen.go
clean:
rm accum_vector_avx_amd64.s
rm accum_vector_sse_amd64.s
rm _compat
upstream/xxhash.o: upstream/xxhash.h
( cd upstream && make )
_compat: _compat.c upstream/xxhash.o
gcc -o _compat _compat.c ./upstream/xxhash.o
vet:
GOOS=linux GOARCH=386 GO386=softfloat go vet ./...
GOOS=windows GOARCH=386 GO386=softfloat go vet ./...
GOOS=linux GOARCH=amd64 go vet ./...
GOOS=windows GOARCH=amd64 go vet ./...
GOOS=darwin GOARCH=amd64 go vet ./...
GOOS=linux GOARCH=arm go vet ./...
GOOS=linux GOARCH=arm64 go vet ./...
GOOS=windows GOARCH=arm64 go vet ./...
GOOS=darwin GOARCH=arm64 go vet ./...

38
vendor/github.com/zeebo/xxh3/README.md generated vendored Normal file
View File

@@ -0,0 +1,38 @@
# XXH3
[![GoDoc](https://godoc.org/github.com/zeebo/xxh3?status.svg)](https://godoc.org/github.com/zeebo/xxh3)
[![Sourcegraph](https://sourcegraph.com/github.com/zeebo/xxh3/-/badge.svg)](https://sourcegraph.com/github.com/zeebo/xxh3?badge)
[![Go Report Card](https://goreportcard.com/badge/github.com/zeebo/xxh3)](https://goreportcard.com/report/github.com/zeebo/xxh3)
This package is a port of the [xxh3](https://github.com/Cyan4973/xxHash) library to Go.
Upstream has fixed the output as of v0.8.0, and this package matches that.
---
# Benchmarks
Run on my `i7-8850H CPU @ 2.60GHz`
## Small Sizes
| Bytes | Rate |
|-----------|--------------------------------------|
|` 0 ` |` 0.74 ns/op ` |
|` 1-3 ` |` 4.19 ns/op (0.24 GB/s - 0.71 GB/s) `|
|` 4-8 ` |` 4.16 ns/op (0.97 GB/s - 1.98 GB/s) `|
|` 9-16 ` |` 4.46 ns/op (2.02 GB/s - 3.58 GB/s) `|
|` 17-32 ` |` 6.22 ns/op (2.76 GB/s - 5.15 GB/s) `|
|` 33-64 ` |` 8.00 ns/op (4.13 GB/s - 8.13 GB/s) `|
|` 65-96 ` |` 11.0 ns/op (5.91 GB/s - 8.84 GB/s) `|
|` 97-128 ` |` 12.8 ns/op (7.68 GB/s - 10.0 GB/s) `|
## Large Sizes
| Bytes | Rate | SSE2 Rate | AVX2 Rate |
|---------|--------------------------|--------------------------|--------------------------|
|` 129 ` |` 13.6 ns/op (9.45 GB/s) `| | |
|` 240 ` |` 23.8 ns/op (10.1 GB/s) `| | |
|` 241 ` |` 40.5 ns/op (5.97 GB/s) `|` 23.3 ns/op (10.4 GB/s) `|` 20.1 ns/op (12.0 GB/s) `|
|` 512 ` |` 69.8 ns/op (7.34 GB/s) `|` 30.4 ns/op (16.9 GB/s) `|` 24.7 ns/op (20.7 GB/s) `|
|` 1024 ` |` 132 ns/op (7.77 GB/s) `|` 48.9 ns/op (20.9 GB/s) `|` 37.7 ns/op (27.2 GB/s) `|
|` 100KB `|` 13.0 us/op (7.88 GB/s) `|` 4.05 us/op (25.3 GB/s) `|` 2.31 us/op (44.3 GB/s) `|

39
vendor/github.com/zeebo/xxh3/_compat.c generated vendored Normal file
View File

@@ -0,0 +1,39 @@
#include "upstream/xxhash.h"
#include <stdio.h>
int main() {
unsigned char buf[4096];
for (int i = 0; i < 4096; i++) {
buf[i] = (unsigned char)((i+1)%251);
}
printf("var testVecs64 = []uint64{\n");
for (int i = 0; i < 4096; i++) {
if (i % 4 == 0) {
printf("\t");
}
uint64_t h = XXH3_64bits(buf, (size_t)i);
printf("0x%lx, ", h);
if (i % 4 == 3) {
printf("\n\t");
}
}
printf("}\n\n");
printf("var testVecs128 = [][2]uint64{\n");
for (int i = 0; i < 4096; i++) {
if (i % 4 == 0) {
printf("\t");
}
XXH128_hash_t h = XXH3_128bits(buf, (size_t)i);
printf("{0x%lx, 0x%lx}, ", h.high64, h.low64);
if (i % 4 == 3) {
printf("\n");
}
}
printf("}\n\n");
}

542
vendor/github.com/zeebo/xxh3/accum_generic.go generated vendored Normal file
View File

@@ -0,0 +1,542 @@
package xxh3
// avx512Switch is the size at which the avx512 code is used.
// Bigger blocks benefit more.
const avx512Switch = 1 << 10
func accumScalar(accs *[8]u64, p, secret ptr, l u64) {
if secret != key {
accumScalarSeed(accs, p, secret, l)
return
}
for l > _block {
k := secret
// accs
for i := 0; i < 16; i++ {
dv0 := readU64(p, 8*0)
dk0 := dv0 ^ readU64(k, 8*0)
accs[1] += dv0
accs[0] += (dk0 & 0xffffffff) * (dk0 >> 32)
dv1 := readU64(p, 8*1)
dk1 := dv1 ^ readU64(k, 8*1)
accs[0] += dv1
accs[1] += (dk1 & 0xffffffff) * (dk1 >> 32)
dv2 := readU64(p, 8*2)
dk2 := dv2 ^ readU64(k, 8*2)
accs[3] += dv2
accs[2] += (dk2 & 0xffffffff) * (dk2 >> 32)
dv3 := readU64(p, 8*3)
dk3 := dv3 ^ readU64(k, 8*3)
accs[2] += dv3
accs[3] += (dk3 & 0xffffffff) * (dk3 >> 32)
dv4 := readU64(p, 8*4)
dk4 := dv4 ^ readU64(k, 8*4)
accs[5] += dv4
accs[4] += (dk4 & 0xffffffff) * (dk4 >> 32)
dv5 := readU64(p, 8*5)
dk5 := dv5 ^ readU64(k, 8*5)
accs[4] += dv5
accs[5] += (dk5 & 0xffffffff) * (dk5 >> 32)
dv6 := readU64(p, 8*6)
dk6 := dv6 ^ readU64(k, 8*6)
accs[7] += dv6
accs[6] += (dk6 & 0xffffffff) * (dk6 >> 32)
dv7 := readU64(p, 8*7)
dk7 := dv7 ^ readU64(k, 8*7)
accs[6] += dv7
accs[7] += (dk7 & 0xffffffff) * (dk7 >> 32)
l -= _stripe
if l > 0 {
p, k = ptr(ui(p)+_stripe), ptr(ui(k)+8)
}
}
// scramble accs
accs[0] ^= accs[0] >> 47
accs[0] ^= key64_128
accs[0] *= prime32_1
accs[1] ^= accs[1] >> 47
accs[1] ^= key64_136
accs[1] *= prime32_1
accs[2] ^= accs[2] >> 47
accs[2] ^= key64_144
accs[2] *= prime32_1
accs[3] ^= accs[3] >> 47
accs[3] ^= key64_152
accs[3] *= prime32_1
accs[4] ^= accs[4] >> 47
accs[4] ^= key64_160
accs[4] *= prime32_1
accs[5] ^= accs[5] >> 47
accs[5] ^= key64_168
accs[5] *= prime32_1
accs[6] ^= accs[6] >> 47
accs[6] ^= key64_176
accs[6] *= prime32_1
accs[7] ^= accs[7] >> 47
accs[7] ^= key64_184
accs[7] *= prime32_1
}
if l > 0 {
t, k := (l-1)/_stripe, secret
for i := u64(0); i < t; i++ {
dv0 := readU64(p, 8*0)
dk0 := dv0 ^ readU64(k, 8*0)
accs[1] += dv0
accs[0] += (dk0 & 0xffffffff) * (dk0 >> 32)
dv1 := readU64(p, 8*1)
dk1 := dv1 ^ readU64(k, 8*1)
accs[0] += dv1
accs[1] += (dk1 & 0xffffffff) * (dk1 >> 32)
dv2 := readU64(p, 8*2)
dk2 := dv2 ^ readU64(k, 8*2)
accs[3] += dv2
accs[2] += (dk2 & 0xffffffff) * (dk2 >> 32)
dv3 := readU64(p, 8*3)
dk3 := dv3 ^ readU64(k, 8*3)
accs[2] += dv3
accs[3] += (dk3 & 0xffffffff) * (dk3 >> 32)
dv4 := readU64(p, 8*4)
dk4 := dv4 ^ readU64(k, 8*4)
accs[5] += dv4
accs[4] += (dk4 & 0xffffffff) * (dk4 >> 32)
dv5 := readU64(p, 8*5)
dk5 := dv5 ^ readU64(k, 8*5)
accs[4] += dv5
accs[5] += (dk5 & 0xffffffff) * (dk5 >> 32)
dv6 := readU64(p, 8*6)
dk6 := dv6 ^ readU64(k, 8*6)
accs[7] += dv6
accs[6] += (dk6 & 0xffffffff) * (dk6 >> 32)
dv7 := readU64(p, 8*7)
dk7 := dv7 ^ readU64(k, 8*7)
accs[6] += dv7
accs[7] += (dk7 & 0xffffffff) * (dk7 >> 32)
l -= _stripe
if l > 0 {
p, k = ptr(ui(p)+_stripe), ptr(ui(k)+8)
}
}
if l > 0 {
p = ptr(ui(p) - uintptr(_stripe-l))
dv0 := readU64(p, 8*0)
dk0 := dv0 ^ key64_121
accs[1] += dv0
accs[0] += (dk0 & 0xffffffff) * (dk0 >> 32)
dv1 := readU64(p, 8*1)
dk1 := dv1 ^ key64_129
accs[0] += dv1
accs[1] += (dk1 & 0xffffffff) * (dk1 >> 32)
dv2 := readU64(p, 8*2)
dk2 := dv2 ^ key64_137
accs[3] += dv2
accs[2] += (dk2 & 0xffffffff) * (dk2 >> 32)
dv3 := readU64(p, 8*3)
dk3 := dv3 ^ key64_145
accs[2] += dv3
accs[3] += (dk3 & 0xffffffff) * (dk3 >> 32)
dv4 := readU64(p, 8*4)
dk4 := dv4 ^ key64_153
accs[5] += dv4
accs[4] += (dk4 & 0xffffffff) * (dk4 >> 32)
dv5 := readU64(p, 8*5)
dk5 := dv5 ^ key64_161
accs[4] += dv5
accs[5] += (dk5 & 0xffffffff) * (dk5 >> 32)
dv6 := readU64(p, 8*6)
dk6 := dv6 ^ key64_169
accs[7] += dv6
accs[6] += (dk6 & 0xffffffff) * (dk6 >> 32)
dv7 := readU64(p, 8*7)
dk7 := dv7 ^ key64_177
accs[6] += dv7
accs[7] += (dk7 & 0xffffffff) * (dk7 >> 32)
}
}
}
func accumBlockScalar(accs *[8]u64, p, secret ptr) {
if secret != key {
accumBlockScalarSeed(accs, p, secret)
return
}
// accs
for i := 0; i < 16; i++ {
dv0 := readU64(p, 8*0)
dk0 := dv0 ^ readU64(secret, 8*0)
accs[1] += dv0
accs[0] += (dk0 & 0xffffffff) * (dk0 >> 32)
dv1 := readU64(p, 8*1)
dk1 := dv1 ^ readU64(secret, 8*1)
accs[0] += dv1
accs[1] += (dk1 & 0xffffffff) * (dk1 >> 32)
dv2 := readU64(p, 8*2)
dk2 := dv2 ^ readU64(secret, 8*2)
accs[3] += dv2
accs[2] += (dk2 & 0xffffffff) * (dk2 >> 32)
dv3 := readU64(p, 8*3)
dk3 := dv3 ^ readU64(secret, 8*3)
accs[2] += dv3
accs[3] += (dk3 & 0xffffffff) * (dk3 >> 32)
dv4 := readU64(p, 8*4)
dk4 := dv4 ^ readU64(secret, 8*4)
accs[5] += dv4
accs[4] += (dk4 & 0xffffffff) * (dk4 >> 32)
dv5 := readU64(p, 8*5)
dk5 := dv5 ^ readU64(secret, 8*5)
accs[4] += dv5
accs[5] += (dk5 & 0xffffffff) * (dk5 >> 32)
dv6 := readU64(p, 8*6)
dk6 := dv6 ^ readU64(secret, 8*6)
accs[7] += dv6
accs[6] += (dk6 & 0xffffffff) * (dk6 >> 32)
dv7 := readU64(p, 8*7)
dk7 := dv7 ^ readU64(secret, 8*7)
accs[6] += dv7
accs[7] += (dk7 & 0xffffffff) * (dk7 >> 32)
p, secret = ptr(ui(p)+_stripe), ptr(ui(secret)+8)
}
// scramble accs
accs[0] ^= accs[0] >> 47
accs[0] ^= key64_128
accs[0] *= prime32_1
accs[1] ^= accs[1] >> 47
accs[1] ^= key64_136
accs[1] *= prime32_1
accs[2] ^= accs[2] >> 47
accs[2] ^= key64_144
accs[2] *= prime32_1
accs[3] ^= accs[3] >> 47
accs[3] ^= key64_152
accs[3] *= prime32_1
accs[4] ^= accs[4] >> 47
accs[4] ^= key64_160
accs[4] *= prime32_1
accs[5] ^= accs[5] >> 47
accs[5] ^= key64_168
accs[5] *= prime32_1
accs[6] ^= accs[6] >> 47
accs[6] ^= key64_176
accs[6] *= prime32_1
accs[7] ^= accs[7] >> 47
accs[7] ^= key64_184
accs[7] *= prime32_1
}
// accumScalarSeed should be used with custom key.
func accumScalarSeed(accs *[8]u64, p, secret ptr, l u64) {
for l > _block {
k := secret
// accs
for i := 0; i < 16; i++ {
dv0 := readU64(p, 8*0)
dk0 := dv0 ^ readU64(k, 8*0)
accs[1] += dv0
accs[0] += (dk0 & 0xffffffff) * (dk0 >> 32)
dv1 := readU64(p, 8*1)
dk1 := dv1 ^ readU64(k, 8*1)
accs[0] += dv1
accs[1] += (dk1 & 0xffffffff) * (dk1 >> 32)
dv2 := readU64(p, 8*2)
dk2 := dv2 ^ readU64(k, 8*2)
accs[3] += dv2
accs[2] += (dk2 & 0xffffffff) * (dk2 >> 32)
dv3 := readU64(p, 8*3)
dk3 := dv3 ^ readU64(k, 8*3)
accs[2] += dv3
accs[3] += (dk3 & 0xffffffff) * (dk3 >> 32)
dv4 := readU64(p, 8*4)
dk4 := dv4 ^ readU64(k, 8*4)
accs[5] += dv4
accs[4] += (dk4 & 0xffffffff) * (dk4 >> 32)
dv5 := readU64(p, 8*5)
dk5 := dv5 ^ readU64(k, 8*5)
accs[4] += dv5
accs[5] += (dk5 & 0xffffffff) * (dk5 >> 32)
dv6 := readU64(p, 8*6)
dk6 := dv6 ^ readU64(k, 8*6)
accs[7] += dv6
accs[6] += (dk6 & 0xffffffff) * (dk6 >> 32)
dv7 := readU64(p, 8*7)
dk7 := dv7 ^ readU64(k, 8*7)
accs[6] += dv7
accs[7] += (dk7 & 0xffffffff) * (dk7 >> 32)
l -= _stripe
if l > 0 {
p, k = ptr(ui(p)+_stripe), ptr(ui(k)+8)
}
}
// scramble accs
accs[0] ^= accs[0] >> 47
accs[0] ^= readU64(secret, 128)
accs[0] *= prime32_1
accs[1] ^= accs[1] >> 47
accs[1] ^= readU64(secret, 136)
accs[1] *= prime32_1
accs[2] ^= accs[2] >> 47
accs[2] ^= readU64(secret, 144)
accs[2] *= prime32_1
accs[3] ^= accs[3] >> 47
accs[3] ^= readU64(secret, 152)
accs[3] *= prime32_1
accs[4] ^= accs[4] >> 47
accs[4] ^= readU64(secret, 160)
accs[4] *= prime32_1
accs[5] ^= accs[5] >> 47
accs[5] ^= readU64(secret, 168)
accs[5] *= prime32_1
accs[6] ^= accs[6] >> 47
accs[6] ^= readU64(secret, 176)
accs[6] *= prime32_1
accs[7] ^= accs[7] >> 47
accs[7] ^= readU64(secret, 184)
accs[7] *= prime32_1
}
if l > 0 {
t, k := (l-1)/_stripe, secret
for i := u64(0); i < t; i++ {
dv0 := readU64(p, 8*0)
dk0 := dv0 ^ readU64(k, 8*0)
accs[1] += dv0
accs[0] += (dk0 & 0xffffffff) * (dk0 >> 32)
dv1 := readU64(p, 8*1)
dk1 := dv1 ^ readU64(k, 8*1)
accs[0] += dv1
accs[1] += (dk1 & 0xffffffff) * (dk1 >> 32)
dv2 := readU64(p, 8*2)
dk2 := dv2 ^ readU64(k, 8*2)
accs[3] += dv2
accs[2] += (dk2 & 0xffffffff) * (dk2 >> 32)
dv3 := readU64(p, 8*3)
dk3 := dv3 ^ readU64(k, 8*3)
accs[2] += dv3
accs[3] += (dk3 & 0xffffffff) * (dk3 >> 32)
dv4 := readU64(p, 8*4)
dk4 := dv4 ^ readU64(k, 8*4)
accs[5] += dv4
accs[4] += (dk4 & 0xffffffff) * (dk4 >> 32)
dv5 := readU64(p, 8*5)
dk5 := dv5 ^ readU64(k, 8*5)
accs[4] += dv5
accs[5] += (dk5 & 0xffffffff) * (dk5 >> 32)
dv6 := readU64(p, 8*6)
dk6 := dv6 ^ readU64(k, 8*6)
accs[7] += dv6
accs[6] += (dk6 & 0xffffffff) * (dk6 >> 32)
dv7 := readU64(p, 8*7)
dk7 := dv7 ^ readU64(k, 8*7)
accs[6] += dv7
accs[7] += (dk7 & 0xffffffff) * (dk7 >> 32)
l -= _stripe
if l > 0 {
p, k = ptr(ui(p)+_stripe), ptr(ui(k)+8)
}
}
if l > 0 {
p = ptr(ui(p) - uintptr(_stripe-l))
dv0 := readU64(p, 8*0)
dk0 := dv0 ^ readU64(secret, 121)
accs[1] += dv0
accs[0] += (dk0 & 0xffffffff) * (dk0 >> 32)
dv1 := readU64(p, 8*1)
dk1 := dv1 ^ readU64(secret, 129)
accs[0] += dv1
accs[1] += (dk1 & 0xffffffff) * (dk1 >> 32)
dv2 := readU64(p, 8*2)
dk2 := dv2 ^ readU64(secret, 137)
accs[3] += dv2
accs[2] += (dk2 & 0xffffffff) * (dk2 >> 32)
dv3 := readU64(p, 8*3)
dk3 := dv3 ^ readU64(secret, 145)
accs[2] += dv3
accs[3] += (dk3 & 0xffffffff) * (dk3 >> 32)
dv4 := readU64(p, 8*4)
dk4 := dv4 ^ readU64(secret, 153)
accs[5] += dv4
accs[4] += (dk4 & 0xffffffff) * (dk4 >> 32)
dv5 := readU64(p, 8*5)
dk5 := dv5 ^ readU64(secret, 161)
accs[4] += dv5
accs[5] += (dk5 & 0xffffffff) * (dk5 >> 32)
dv6 := readU64(p, 8*6)
dk6 := dv6 ^ readU64(secret, 169)
accs[7] += dv6
accs[6] += (dk6 & 0xffffffff) * (dk6 >> 32)
dv7 := readU64(p, 8*7)
dk7 := dv7 ^ readU64(secret, 177)
accs[6] += dv7
accs[7] += (dk7 & 0xffffffff) * (dk7 >> 32)
}
}
}
// accumBlockScalarSeed should be used with custom key.
func accumBlockScalarSeed(accs *[8]u64, p, secret ptr) {
// accs
{
secret := secret
for i := 0; i < 16; i++ {
dv0 := readU64(p, 8*0)
dk0 := dv0 ^ readU64(secret, 8*0)
accs[1] += dv0
accs[0] += (dk0 & 0xffffffff) * (dk0 >> 32)
dv1 := readU64(p, 8*1)
dk1 := dv1 ^ readU64(secret, 8*1)
accs[0] += dv1
accs[1] += (dk1 & 0xffffffff) * (dk1 >> 32)
dv2 := readU64(p, 8*2)
dk2 := dv2 ^ readU64(secret, 8*2)
accs[3] += dv2
accs[2] += (dk2 & 0xffffffff) * (dk2 >> 32)
dv3 := readU64(p, 8*3)
dk3 := dv3 ^ readU64(secret, 8*3)
accs[2] += dv3
accs[3] += (dk3 & 0xffffffff) * (dk3 >> 32)
dv4 := readU64(p, 8*4)
dk4 := dv4 ^ readU64(secret, 8*4)
accs[5] += dv4
accs[4] += (dk4 & 0xffffffff) * (dk4 >> 32)
dv5 := readU64(p, 8*5)
dk5 := dv5 ^ readU64(secret, 8*5)
accs[4] += dv5
accs[5] += (dk5 & 0xffffffff) * (dk5 >> 32)
dv6 := readU64(p, 8*6)
dk6 := dv6 ^ readU64(secret, 8*6)
accs[7] += dv6
accs[6] += (dk6 & 0xffffffff) * (dk6 >> 32)
dv7 := readU64(p, 8*7)
dk7 := dv7 ^ readU64(secret, 8*7)
accs[6] += dv7
accs[7] += (dk7 & 0xffffffff) * (dk7 >> 32)
p, secret = ptr(ui(p)+_stripe), ptr(ui(secret)+8)
}
}
// scramble accs
accs[0] ^= accs[0] >> 47
accs[0] ^= readU64(secret, 128)
accs[0] *= prime32_1
accs[1] ^= accs[1] >> 47
accs[1] ^= readU64(secret, 136)
accs[1] *= prime32_1
accs[2] ^= accs[2] >> 47
accs[2] ^= readU64(secret, 144)
accs[2] *= prime32_1
accs[3] ^= accs[3] >> 47
accs[3] ^= readU64(secret, 152)
accs[3] *= prime32_1
accs[4] ^= accs[4] >> 47
accs[4] ^= readU64(secret, 160)
accs[4] *= prime32_1
accs[5] ^= accs[5] >> 47
accs[5] ^= readU64(secret, 168)
accs[5] *= prime32_1
accs[6] ^= accs[6] >> 47
accs[6] ^= readU64(secret, 176)
accs[6] *= prime32_1
accs[7] ^= accs[7] >> 47
accs[7] ^= readU64(secret, 184)
accs[7] *= prime32_1
}

40
vendor/github.com/zeebo/xxh3/accum_stubs_amd64.go generated vendored Normal file
View File

@@ -0,0 +1,40 @@
package xxh3
import (
"unsafe"
"github.com/klauspost/cpuid/v2"
)
var (
hasAVX2 = cpuid.CPU.Has(cpuid.AVX2)
hasSSE2 = cpuid.CPU.Has(cpuid.SSE2) // Always true on amd64
hasAVX512 = cpuid.CPU.Has(cpuid.AVX512F)
)
//go:noescape
func accumAVX2(acc *[8]u64, data, key unsafe.Pointer, len u64)
//go:noescape
func accumAVX512(acc *[8]u64, data, key unsafe.Pointer, len u64)
//go:noescape
func accumSSE(acc *[8]u64, data, key unsafe.Pointer, len u64)
//go:noescape
func accumBlockAVX2(acc *[8]u64, data, key unsafe.Pointer)
//go:noescape
func accumBlockSSE(acc *[8]u64, data, key unsafe.Pointer)
func withOverrides(avx512, avx2, sse2 bool, cb func()) {
avx512Orig, avx2Orig, sse2Orig := hasAVX512, hasAVX2, hasSSE2
hasAVX512, hasAVX2, hasSSE2 = avx512, avx2, sse2
defer func() { hasAVX512, hasAVX2, hasSSE2 = avx512Orig, avx2Orig, sse2Orig }()
cb()
}
func withAVX512(cb func()) { withOverrides(hasAVX512, false, false, cb) }
func withAVX2(cb func()) { withOverrides(false, hasAVX2, false, cb) }
func withSSE2(cb func()) { withOverrides(false, false, hasSSE2, cb) }
func withGeneric(cb func()) { withOverrides(false, false, false, cb) }

25
vendor/github.com/zeebo/xxh3/accum_stubs_other.go generated vendored Normal file
View File

@@ -0,0 +1,25 @@
//go:build !amd64
// +build !amd64
package xxh3
import (
"unsafe"
)
const (
hasAVX2 = false
hasSSE2 = false
hasAVX512 = false
)
func accumAVX2(acc *[8]u64, data, key unsafe.Pointer, len u64) { panic("unreachable") }
func accumSSE(acc *[8]u64, data, key unsafe.Pointer, len u64) { panic("unreachable") }
func accumBlockAVX2(acc *[8]u64, data, key unsafe.Pointer) { panic("unreachable") }
func accumBlockSSE(acc *[8]u64, data, key unsafe.Pointer) { panic("unreachable") }
func accumAVX512(acc *[8]u64, data, key unsafe.Pointer, len u64) { panic("unreachable") }
func withAVX512(cb func()) { cb() }
func withAVX2(cb func()) { cb() }
func withSSE2(cb func()) { cb() }
func withGeneric(cb func()) { cb() }

View File

@@ -0,0 +1,379 @@
// Code generated by command: go run gen.go -avx512 -out ../accum_vector_avx512_amd64.s -pkg xxh3. DO NOT EDIT.
#include "textflag.h"
DATA prime_avx512<>+0(SB)/8, $0x000000009e3779b1
DATA prime_avx512<>+8(SB)/8, $0x000000009e3779b1
DATA prime_avx512<>+16(SB)/8, $0x000000009e3779b1
DATA prime_avx512<>+24(SB)/8, $0x000000009e3779b1
DATA prime_avx512<>+32(SB)/8, $0x000000009e3779b1
DATA prime_avx512<>+40(SB)/8, $0x000000009e3779b1
DATA prime_avx512<>+48(SB)/8, $0x000000009e3779b1
DATA prime_avx512<>+56(SB)/8, $0x000000009e3779b1
GLOBL prime_avx512<>(SB), RODATA|NOPTR, $64
// func accumAVX512(acc *[8]uint64, data *byte, key *byte, len uint64)
// Requires: AVX, AVX512F, MMX+
TEXT ·accumAVX512(SB), NOSPLIT, $0-32
MOVQ acc+0(FP), AX
MOVQ data+8(FP), CX
MOVQ key+16(FP), DX
MOVQ len+24(FP), BX
VMOVDQU64 (AX), Z1
VMOVDQU64 prime_avx512<>+0(SB), Z0
VMOVDQU64 (DX), Z2
VMOVDQU64 8(DX), Z3
VMOVDQU64 16(DX), Z4
VMOVDQU64 24(DX), Z5
VMOVDQU64 32(DX), Z6
VMOVDQU64 40(DX), Z7
VMOVDQU64 48(DX), Z8
VMOVDQU64 56(DX), Z9
VMOVDQU64 64(DX), Z10
VMOVDQU64 72(DX), Z11
VMOVDQU64 80(DX), Z12
VMOVDQU64 88(DX), Z13
VMOVDQU64 96(DX), Z14
VMOVDQU64 104(DX), Z15
VMOVDQU64 112(DX), Z16
VMOVDQU64 120(DX), Z17
VMOVDQU64 128(DX), Z18
VMOVDQU64 121(DX), Z19
accum_large:
CMPQ BX, $0x00000400
JLE accum
VMOVDQU64 (CX), Z20
PREFETCHT0 1024(CX)
VPXORD Z2, Z20, Z21
VPSHUFD $0x31, Z21, Z22
VPMULUDQ Z21, Z22, Z21
VPSHUFD $0x4e, Z20, Z20
VPADDQ Z1, Z20, Z1
VPADDQ Z1, Z21, Z1
VMOVDQU64 64(CX), Z20
PREFETCHT0 1088(CX)
VPXORD Z3, Z20, Z21
VPSHUFD $0x31, Z21, Z22
VPMULUDQ Z21, Z22, Z21
VPSHUFD $0x4e, Z20, Z20
VPADDQ Z1, Z20, Z1
VPADDQ Z1, Z21, Z1
VMOVDQU64 128(CX), Z20
PREFETCHT0 1152(CX)
VPXORD Z4, Z20, Z21
VPSHUFD $0x31, Z21, Z22
VPMULUDQ Z21, Z22, Z21
VPSHUFD $0x4e, Z20, Z20
VPADDQ Z1, Z20, Z1
VPADDQ Z1, Z21, Z1
VMOVDQU64 192(CX), Z20
PREFETCHT0 1216(CX)
VPXORD Z5, Z20, Z21
VPSHUFD $0x31, Z21, Z22
VPMULUDQ Z21, Z22, Z21
VPSHUFD $0x4e, Z20, Z20
VPADDQ Z1, Z20, Z1
VPADDQ Z1, Z21, Z1
VMOVDQU64 256(CX), Z20
PREFETCHT0 1280(CX)
VPXORD Z6, Z20, Z21
VPSHUFD $0x31, Z21, Z22
VPMULUDQ Z21, Z22, Z21
VPSHUFD $0x4e, Z20, Z20
VPADDQ Z1, Z20, Z1
VPADDQ Z1, Z21, Z1
VMOVDQU64 320(CX), Z20
PREFETCHT0 1344(CX)
VPXORD Z7, Z20, Z21
VPSHUFD $0x31, Z21, Z22
VPMULUDQ Z21, Z22, Z21
VPSHUFD $0x4e, Z20, Z20
VPADDQ Z1, Z20, Z1
VPADDQ Z1, Z21, Z1
VMOVDQU64 384(CX), Z20
PREFETCHT0 1408(CX)
VPXORD Z8, Z20, Z21
VPSHUFD $0x31, Z21, Z22
VPMULUDQ Z21, Z22, Z21
VPSHUFD $0x4e, Z20, Z20
VPADDQ Z1, Z20, Z1
VPADDQ Z1, Z21, Z1
VMOVDQU64 448(CX), Z20
PREFETCHT0 1472(CX)
VPXORD Z9, Z20, Z21
VPSHUFD $0x31, Z21, Z22
VPMULUDQ Z21, Z22, Z21
VPSHUFD $0x4e, Z20, Z20
VPADDQ Z1, Z20, Z1
VPADDQ Z1, Z21, Z1
VMOVDQU64 512(CX), Z20
PREFETCHT0 1536(CX)
VPXORD Z10, Z20, Z21
VPSHUFD $0x31, Z21, Z22
VPMULUDQ Z21, Z22, Z21
VPSHUFD $0x4e, Z20, Z20
VPADDQ Z1, Z20, Z1
VPADDQ Z1, Z21, Z1
VMOVDQU64 576(CX), Z20
PREFETCHT0 1600(CX)
VPXORD Z11, Z20, Z21
VPSHUFD $0x31, Z21, Z22
VPMULUDQ Z21, Z22, Z21
VPSHUFD $0x4e, Z20, Z20
VPADDQ Z1, Z20, Z1
VPADDQ Z1, Z21, Z1
VMOVDQU64 640(CX), Z20
PREFETCHT0 1664(CX)
VPXORD Z12, Z20, Z21
VPSHUFD $0x31, Z21, Z22
VPMULUDQ Z21, Z22, Z21
VPSHUFD $0x4e, Z20, Z20
VPADDQ Z1, Z20, Z1
VPADDQ Z1, Z21, Z1
VMOVDQU64 704(CX), Z20
PREFETCHT0 1728(CX)
VPXORD Z13, Z20, Z21
VPSHUFD $0x31, Z21, Z22
VPMULUDQ Z21, Z22, Z21
VPSHUFD $0x4e, Z20, Z20
VPADDQ Z1, Z20, Z1
VPADDQ Z1, Z21, Z1
VMOVDQU64 768(CX), Z20
PREFETCHT0 1792(CX)
VPXORD Z14, Z20, Z21
VPSHUFD $0x31, Z21, Z22
VPMULUDQ Z21, Z22, Z21
VPSHUFD $0x4e, Z20, Z20
VPADDQ Z1, Z20, Z1
VPADDQ Z1, Z21, Z1
VMOVDQU64 832(CX), Z20
PREFETCHT0 1856(CX)
VPXORD Z15, Z20, Z21
VPSHUFD $0x31, Z21, Z22
VPMULUDQ Z21, Z22, Z21
VPSHUFD $0x4e, Z20, Z20
VPADDQ Z1, Z20, Z1
VPADDQ Z1, Z21, Z1
VMOVDQU64 896(CX), Z20
PREFETCHT0 1920(CX)
VPXORD Z16, Z20, Z21
VPSHUFD $0x31, Z21, Z22
VPMULUDQ Z21, Z22, Z21
VPSHUFD $0x4e, Z20, Z20
VPADDQ Z1, Z20, Z1
VPADDQ Z1, Z21, Z1
VMOVDQU64 960(CX), Z20
PREFETCHT0 1984(CX)
VPXORD Z17, Z20, Z21
VPSHUFD $0x31, Z21, Z22
VPMULUDQ Z21, Z22, Z21
VPSHUFD $0x4e, Z20, Z20
VPADDQ Z1, Z20, Z1
VPADDQ Z1, Z21, Z1
ADDQ $0x00000400, CX
SUBQ $0x00000400, BX
VPSRLQ $0x2f, Z1, Z20
VPTERNLOGD $0x96, Z1, Z18, Z20
VPMULUDQ Z0, Z20, Z1
VPSHUFD $0xf5, Z20, Z20
VPMULUDQ Z0, Z20, Z20
VPSLLQ $0x20, Z20, Z20
VPADDQ Z1, Z20, Z1
JMP accum_large
accum:
CMPQ BX, $0x40
JLE finalize
VMOVDQU64 (CX), Z0
VPXORD Z2, Z0, Z2
VPSHUFD $0x31, Z2, Z18
VPMULUDQ Z2, Z18, Z2
VPSHUFD $0x4e, Z0, Z0
VPADDQ Z1, Z0, Z1
VPADDQ Z1, Z2, Z1
ADDQ $0x00000040, CX
SUBQ $0x00000040, BX
CMPQ BX, $0x40
JLE finalize
VMOVDQU64 (CX), Z0
VPXORD Z3, Z0, Z2
VPSHUFD $0x31, Z2, Z3
VPMULUDQ Z2, Z3, Z2
VPSHUFD $0x4e, Z0, Z0
VPADDQ Z1, Z0, Z1
VPADDQ Z1, Z2, Z1
ADDQ $0x00000040, CX
SUBQ $0x00000040, BX
CMPQ BX, $0x40
JLE finalize
VMOVDQU64 (CX), Z0
VPXORD Z4, Z0, Z2
VPSHUFD $0x31, Z2, Z3
VPMULUDQ Z2, Z3, Z2
VPSHUFD $0x4e, Z0, Z0
VPADDQ Z1, Z0, Z1
VPADDQ Z1, Z2, Z1
ADDQ $0x00000040, CX
SUBQ $0x00000040, BX
CMPQ BX, $0x40
JLE finalize
VMOVDQU64 (CX), Z0
VPXORD Z5, Z0, Z2
VPSHUFD $0x31, Z2, Z3
VPMULUDQ Z2, Z3, Z2
VPSHUFD $0x4e, Z0, Z0
VPADDQ Z1, Z0, Z1
VPADDQ Z1, Z2, Z1
ADDQ $0x00000040, CX
SUBQ $0x00000040, BX
CMPQ BX, $0x40
JLE finalize
VMOVDQU64 (CX), Z0
VPXORD Z6, Z0, Z2
VPSHUFD $0x31, Z2, Z3
VPMULUDQ Z2, Z3, Z2
VPSHUFD $0x4e, Z0, Z0
VPADDQ Z1, Z0, Z1
VPADDQ Z1, Z2, Z1
ADDQ $0x00000040, CX
SUBQ $0x00000040, BX
CMPQ BX, $0x40
JLE finalize
VMOVDQU64 (CX), Z0
VPXORD Z7, Z0, Z2
VPSHUFD $0x31, Z2, Z3
VPMULUDQ Z2, Z3, Z2
VPSHUFD $0x4e, Z0, Z0
VPADDQ Z1, Z0, Z1
VPADDQ Z1, Z2, Z1
ADDQ $0x00000040, CX
SUBQ $0x00000040, BX
CMPQ BX, $0x40
JLE finalize
VMOVDQU64 (CX), Z0
VPXORD Z8, Z0, Z2
VPSHUFD $0x31, Z2, Z3
VPMULUDQ Z2, Z3, Z2
VPSHUFD $0x4e, Z0, Z0
VPADDQ Z1, Z0, Z1
VPADDQ Z1, Z2, Z1
ADDQ $0x00000040, CX
SUBQ $0x00000040, BX
CMPQ BX, $0x40
JLE finalize
VMOVDQU64 (CX), Z0
VPXORD Z9, Z0, Z2
VPSHUFD $0x31, Z2, Z3
VPMULUDQ Z2, Z3, Z2
VPSHUFD $0x4e, Z0, Z0
VPADDQ Z1, Z0, Z1
VPADDQ Z1, Z2, Z1
ADDQ $0x00000040, CX
SUBQ $0x00000040, BX
CMPQ BX, $0x40
JLE finalize
VMOVDQU64 (CX), Z0
VPXORD Z10, Z0, Z2
VPSHUFD $0x31, Z2, Z3
VPMULUDQ Z2, Z3, Z2
VPSHUFD $0x4e, Z0, Z0
VPADDQ Z1, Z0, Z1
VPADDQ Z1, Z2, Z1
ADDQ $0x00000040, CX
SUBQ $0x00000040, BX
CMPQ BX, $0x40
JLE finalize
VMOVDQU64 (CX), Z0
VPXORD Z11, Z0, Z2
VPSHUFD $0x31, Z2, Z3
VPMULUDQ Z2, Z3, Z2
VPSHUFD $0x4e, Z0, Z0
VPADDQ Z1, Z0, Z1
VPADDQ Z1, Z2, Z1
ADDQ $0x00000040, CX
SUBQ $0x00000040, BX
CMPQ BX, $0x40
JLE finalize
VMOVDQU64 (CX), Z0
VPXORD Z12, Z0, Z2
VPSHUFD $0x31, Z2, Z3
VPMULUDQ Z2, Z3, Z2
VPSHUFD $0x4e, Z0, Z0
VPADDQ Z1, Z0, Z1
VPADDQ Z1, Z2, Z1
ADDQ $0x00000040, CX
SUBQ $0x00000040, BX
CMPQ BX, $0x40
JLE finalize
VMOVDQU64 (CX), Z0
VPXORD Z13, Z0, Z2
VPSHUFD $0x31, Z2, Z3
VPMULUDQ Z2, Z3, Z2
VPSHUFD $0x4e, Z0, Z0
VPADDQ Z1, Z0, Z1
VPADDQ Z1, Z2, Z1
ADDQ $0x00000040, CX
SUBQ $0x00000040, BX
CMPQ BX, $0x40
JLE finalize
VMOVDQU64 (CX), Z0
VPXORD Z14, Z0, Z2
VPSHUFD $0x31, Z2, Z3
VPMULUDQ Z2, Z3, Z2
VPSHUFD $0x4e, Z0, Z0
VPADDQ Z1, Z0, Z1
VPADDQ Z1, Z2, Z1
ADDQ $0x00000040, CX
SUBQ $0x00000040, BX
CMPQ BX, $0x40
JLE finalize
VMOVDQU64 (CX), Z0
VPXORD Z15, Z0, Z2
VPSHUFD $0x31, Z2, Z3
VPMULUDQ Z2, Z3, Z2
VPSHUFD $0x4e, Z0, Z0
VPADDQ Z1, Z0, Z1
VPADDQ Z1, Z2, Z1
ADDQ $0x00000040, CX
SUBQ $0x00000040, BX
CMPQ BX, $0x40
JLE finalize
VMOVDQU64 (CX), Z0
VPXORD Z16, Z0, Z2
VPSHUFD $0x31, Z2, Z3
VPMULUDQ Z2, Z3, Z2
VPSHUFD $0x4e, Z0, Z0
VPADDQ Z1, Z0, Z1
VPADDQ Z1, Z2, Z1
ADDQ $0x00000040, CX
SUBQ $0x00000040, BX
CMPQ BX, $0x40
JLE finalize
VMOVDQU64 (CX), Z0
VPXORD Z17, Z0, Z2
VPSHUFD $0x31, Z2, Z3
VPMULUDQ Z2, Z3, Z2
VPSHUFD $0x4e, Z0, Z0
VPADDQ Z1, Z0, Z1
VPADDQ Z1, Z2, Z1
ADDQ $0x00000040, CX
SUBQ $0x00000040, BX
finalize:
CMPQ BX, $0x00
JE return
SUBQ $0x40, CX
ADDQ BX, CX
VMOVDQU64 (CX), Z0
VPXORD Z19, Z0, Z2
VPSHUFD $0x31, Z2, Z3
VPMULUDQ Z2, Z3, Z2
VPSHUFD $0x4e, Z0, Z0
VPADDQ Z1, Z0, Z1
VPADDQ Z1, Z2, Z1
return:
VMOVDQU64 Z1, (AX)
VZEROUPPER
RET

586
vendor/github.com/zeebo/xxh3/accum_vector_avx_amd64.s generated vendored Normal file
View File

@@ -0,0 +1,586 @@
// Code generated by command: go run gen.go -avx -out ../accum_vector_avx_amd64.s -pkg xxh3. DO NOT EDIT.
#include "textflag.h"
DATA prime_avx<>+0(SB)/8, $0x000000009e3779b1
DATA prime_avx<>+8(SB)/8, $0x000000009e3779b1
DATA prime_avx<>+16(SB)/8, $0x000000009e3779b1
DATA prime_avx<>+24(SB)/8, $0x000000009e3779b1
GLOBL prime_avx<>(SB), RODATA|NOPTR, $32
// func accumAVX2(acc *[8]uint64, data *byte, key *byte, len uint64)
// Requires: AVX, AVX2, MMX+
TEXT ·accumAVX2(SB), NOSPLIT, $0-32
MOVQ acc+0(FP), AX
MOVQ data+8(FP), CX
MOVQ key+16(FP), DX
MOVQ key+16(FP), BX
MOVQ len+24(FP), SI
VMOVDQU (AX), Y1
VMOVDQU 32(AX), Y2
VMOVDQU prime_avx<>+0(SB), Y0
accum_large:
CMPQ SI, $0x00000400
JLE accum
VMOVDQU (CX), Y3
VMOVDQU 32(CX), Y6
PREFETCHT0 512(CX)
VPXOR (DX), Y3, Y4
VPXOR 32(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 64(CX), Y3
VMOVDQU 96(CX), Y6
PREFETCHT0 576(CX)
VPXOR 8(DX), Y3, Y4
VPXOR 40(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 128(CX), Y3
VMOVDQU 160(CX), Y6
PREFETCHT0 640(CX)
VPXOR 16(DX), Y3, Y4
VPXOR 48(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 192(CX), Y3
VMOVDQU 224(CX), Y6
PREFETCHT0 704(CX)
VPXOR 24(DX), Y3, Y4
VPXOR 56(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 256(CX), Y3
VMOVDQU 288(CX), Y6
PREFETCHT0 768(CX)
VPXOR 32(DX), Y3, Y4
VPXOR 64(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 320(CX), Y3
VMOVDQU 352(CX), Y6
PREFETCHT0 832(CX)
VPXOR 40(DX), Y3, Y4
VPXOR 72(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 384(CX), Y3
VMOVDQU 416(CX), Y6
PREFETCHT0 896(CX)
VPXOR 48(DX), Y3, Y4
VPXOR 80(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 448(CX), Y3
VMOVDQU 480(CX), Y6
PREFETCHT0 960(CX)
VPXOR 56(DX), Y3, Y4
VPXOR 88(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 512(CX), Y3
VMOVDQU 544(CX), Y6
PREFETCHT0 1024(CX)
VPXOR 64(DX), Y3, Y4
VPXOR 96(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 576(CX), Y3
VMOVDQU 608(CX), Y6
PREFETCHT0 1088(CX)
VPXOR 72(DX), Y3, Y4
VPXOR 104(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 640(CX), Y3
VMOVDQU 672(CX), Y6
PREFETCHT0 1152(CX)
VPXOR 80(DX), Y3, Y4
VPXOR 112(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 704(CX), Y3
VMOVDQU 736(CX), Y6
PREFETCHT0 1216(CX)
VPXOR 88(DX), Y3, Y4
VPXOR 120(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 768(CX), Y3
VMOVDQU 800(CX), Y6
PREFETCHT0 1280(CX)
VPXOR 96(DX), Y3, Y4
VPXOR 128(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 832(CX), Y3
VMOVDQU 864(CX), Y6
PREFETCHT0 1344(CX)
VPXOR 104(DX), Y3, Y4
VPXOR 136(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 896(CX), Y3
VMOVDQU 928(CX), Y6
PREFETCHT0 1408(CX)
VPXOR 112(DX), Y3, Y4
VPXOR 144(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 960(CX), Y3
VMOVDQU 992(CX), Y6
PREFETCHT0 1472(CX)
VPXOR 120(DX), Y3, Y4
VPXOR 152(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
ADDQ $0x00000400, CX
SUBQ $0x00000400, SI
VPSRLQ $0x2f, Y1, Y3
VPXOR Y1, Y3, Y3
VPXOR 128(DX), Y3, Y3
VPMULUDQ Y0, Y3, Y1
VPSHUFD $0xf5, Y3, Y3
VPMULUDQ Y0, Y3, Y3
VPSLLQ $0x20, Y3, Y3
VPADDQ Y1, Y3, Y1
VPSRLQ $0x2f, Y2, Y3
VPXOR Y2, Y3, Y3
VPXOR 160(DX), Y3, Y3
VPMULUDQ Y0, Y3, Y2
VPSHUFD $0xf5, Y3, Y3
VPMULUDQ Y0, Y3, Y3
VPSLLQ $0x20, Y3, Y3
VPADDQ Y2, Y3, Y2
JMP accum_large
accum:
CMPQ SI, $0x40
JLE finalize
VMOVDQU (CX), Y0
VMOVDQU 32(CX), Y5
VPXOR (BX), Y0, Y3
VPXOR 32(BX), Y5, Y6
VPSHUFD $0x31, Y3, Y4
VPSHUFD $0x31, Y6, Y7
VPMULUDQ Y3, Y4, Y3
VPMULUDQ Y6, Y7, Y6
VPSHUFD $0x4e, Y0, Y0
VPSHUFD $0x4e, Y5, Y5
VPADDQ Y1, Y0, Y1
VPADDQ Y1, Y3, Y1
VPADDQ Y2, Y5, Y2
VPADDQ Y2, Y6, Y2
ADDQ $0x00000040, CX
SUBQ $0x00000040, SI
ADDQ $0x00000008, BX
JMP accum
finalize:
CMPQ SI, $0x00
JE return
SUBQ $0x40, CX
ADDQ SI, CX
VMOVDQU (CX), Y0
VMOVDQU 32(CX), Y5
VPXOR 121(DX), Y0, Y3
VPXOR 153(DX), Y5, Y6
VPSHUFD $0x31, Y3, Y4
VPSHUFD $0x31, Y6, Y7
VPMULUDQ Y3, Y4, Y3
VPMULUDQ Y6, Y7, Y6
VPSHUFD $0x4e, Y0, Y0
VPSHUFD $0x4e, Y5, Y5
VPADDQ Y1, Y0, Y1
VPADDQ Y1, Y3, Y1
VPADDQ Y2, Y5, Y2
VPADDQ Y2, Y6, Y2
return:
VMOVDQU Y1, (AX)
VMOVDQU Y2, 32(AX)
VZEROUPPER
RET
// func accumBlockAVX2(acc *[8]uint64, data *byte, key *byte)
// Requires: AVX, AVX2
TEXT ·accumBlockAVX2(SB), NOSPLIT, $0-24
MOVQ acc+0(FP), AX
MOVQ data+8(FP), CX
MOVQ key+16(FP), DX
VMOVDQU (AX), Y1
VMOVDQU 32(AX), Y2
VMOVDQU prime_avx<>+0(SB), Y0
VMOVDQU (CX), Y3
VMOVDQU 32(CX), Y6
VPXOR (DX), Y3, Y4
VPXOR 32(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 64(CX), Y3
VMOVDQU 96(CX), Y6
VPXOR 8(DX), Y3, Y4
VPXOR 40(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 128(CX), Y3
VMOVDQU 160(CX), Y6
VPXOR 16(DX), Y3, Y4
VPXOR 48(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 192(CX), Y3
VMOVDQU 224(CX), Y6
VPXOR 24(DX), Y3, Y4
VPXOR 56(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 256(CX), Y3
VMOVDQU 288(CX), Y6
VPXOR 32(DX), Y3, Y4
VPXOR 64(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 320(CX), Y3
VMOVDQU 352(CX), Y6
VPXOR 40(DX), Y3, Y4
VPXOR 72(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 384(CX), Y3
VMOVDQU 416(CX), Y6
VPXOR 48(DX), Y3, Y4
VPXOR 80(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 448(CX), Y3
VMOVDQU 480(CX), Y6
VPXOR 56(DX), Y3, Y4
VPXOR 88(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 512(CX), Y3
VMOVDQU 544(CX), Y6
VPXOR 64(DX), Y3, Y4
VPXOR 96(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 576(CX), Y3
VMOVDQU 608(CX), Y6
VPXOR 72(DX), Y3, Y4
VPXOR 104(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 640(CX), Y3
VMOVDQU 672(CX), Y6
VPXOR 80(DX), Y3, Y4
VPXOR 112(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 704(CX), Y3
VMOVDQU 736(CX), Y6
VPXOR 88(DX), Y3, Y4
VPXOR 120(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 768(CX), Y3
VMOVDQU 800(CX), Y6
VPXOR 96(DX), Y3, Y4
VPXOR 128(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 832(CX), Y3
VMOVDQU 864(CX), Y6
VPXOR 104(DX), Y3, Y4
VPXOR 136(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 896(CX), Y3
VMOVDQU 928(CX), Y6
VPXOR 112(DX), Y3, Y4
VPXOR 144(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VMOVDQU 960(CX), Y3
VMOVDQU 992(CX), Y6
VPXOR 120(DX), Y3, Y4
VPXOR 152(DX), Y6, Y7
VPSHUFD $0x31, Y4, Y5
VPSHUFD $0x31, Y7, Y8
VPMULUDQ Y4, Y5, Y4
VPMULUDQ Y7, Y8, Y7
VPSHUFD $0x4e, Y3, Y3
VPSHUFD $0x4e, Y6, Y6
VPADDQ Y1, Y3, Y1
VPADDQ Y1, Y4, Y1
VPADDQ Y2, Y6, Y2
VPADDQ Y2, Y7, Y2
VPSRLQ $0x2f, Y1, Y3
VPXOR Y1, Y3, Y3
VPXOR 128(DX), Y3, Y3
VPMULUDQ Y0, Y3, Y1
VPSHUFD $0xf5, Y3, Y3
VPMULUDQ Y0, Y3, Y3
VPSLLQ $0x20, Y3, Y3
VPADDQ Y1, Y3, Y1
VPSRLQ $0x2f, Y2, Y3
VPXOR Y2, Y3, Y3
VPXOR 160(DX), Y3, Y3
VPMULUDQ Y0, Y3, Y2
VPSHUFD $0xf5, Y3, Y3
VPMULUDQ Y0, Y3, Y3
VPSLLQ $0x20, Y3, Y3
VPADDQ Y2, Y3, Y2
VMOVDQU Y1, (AX)
VMOVDQU Y2, 32(AX)
VZEROUPPER
RET

1236
vendor/github.com/zeebo/xxh3/accum_vector_sse_amd64.s generated vendored Normal file

File diff suppressed because it is too large Load Diff

97
vendor/github.com/zeebo/xxh3/consts.go generated vendored Normal file
View File

@@ -0,0 +1,97 @@
package xxh3
const (
_stripe = 64
_block = 1024
prime32_1 = 2654435761
prime32_2 = 2246822519
prime32_3 = 3266489917
prime64_1 = 11400714785074694791
prime64_2 = 14029467366897019727
prime64_3 = 1609587929392839161
prime64_4 = 9650029242287828579
prime64_5 = 2870177450012600261
)
var key = ptr(&[...]u8{
0xb8, 0xfe, 0x6c, 0x39, 0x23, 0xa4, 0x4b, 0xbe /* 8 */, 0x7c, 0x01, 0x81, 0x2c, 0xf7, 0x21, 0xad, 0x1c, /* 16 */
0xde, 0xd4, 0x6d, 0xe9, 0x83, 0x90, 0x97, 0xdb /* 24 */, 0x72, 0x40, 0xa4, 0xa4, 0xb7, 0xb3, 0x67, 0x1f, /* 32 */
0xcb, 0x79, 0xe6, 0x4e, 0xcc, 0xc0, 0xe5, 0x78 /* 40 */, 0x82, 0x5a, 0xd0, 0x7d, 0xcc, 0xff, 0x72, 0x21, /* 48 */
0xb8, 0x08, 0x46, 0x74, 0xf7, 0x43, 0x24, 0x8e /* 56 */, 0xe0, 0x35, 0x90, 0xe6, 0x81, 0x3a, 0x26, 0x4c, /* 64 */
0x3c, 0x28, 0x52, 0xbb, 0x91, 0xc3, 0x00, 0xcb /* 72 */, 0x88, 0xd0, 0x65, 0x8b, 0x1b, 0x53, 0x2e, 0xa3, /* 80 */
0x71, 0x64, 0x48, 0x97, 0xa2, 0x0d, 0xf9, 0x4e /* 88 */, 0x38, 0x19, 0xef, 0x46, 0xa9, 0xde, 0xac, 0xd8, /* 96 */
0xa8, 0xfa, 0x76, 0x3f, 0xe3, 0x9c, 0x34, 0x3f /* 104 */, 0xf9, 0xdc, 0xbb, 0xc7, 0xc7, 0x0b, 0x4f, 0x1d, /* 112 */
0x8a, 0x51, 0xe0, 0x4b, 0xcd, 0xb4, 0x59, 0x31 /* 120 */, 0xc8, 0x9f, 0x7e, 0xc9, 0xd9, 0x78, 0x73, 0x64, /* 128 */
0xea, 0xc5, 0xac, 0x83, 0x34, 0xd3, 0xeb, 0xc3 /* 136 */, 0xc5, 0x81, 0xa0, 0xff, 0xfa, 0x13, 0x63, 0xeb, /* 144 */
0x17, 0x0d, 0xdd, 0x51, 0xb7, 0xf0, 0xda, 0x49 /* 152 */, 0xd3, 0x16, 0x55, 0x26, 0x29, 0xd4, 0x68, 0x9e, /* 160 */
0x2b, 0x16, 0xbe, 0x58, 0x7d, 0x47, 0xa1, 0xfc /* 168 */, 0x8f, 0xf8, 0xb8, 0xd1, 0x7a, 0xd0, 0x31, 0xce, /* 176 */
0x45, 0xcb, 0x3a, 0x8f, 0x95, 0x16, 0x04, 0x28 /* 184 */, 0xaf, 0xd7, 0xfb, 0xca, 0xbb, 0x4b, 0x40, 0x7e, /* 192 */
})
const (
key64_000 u64 = 0xbe4ba423396cfeb8
key64_008 u64 = 0x1cad21f72c81017c
key64_016 u64 = 0xdb979083e96dd4de
key64_024 u64 = 0x1f67b3b7a4a44072
key64_032 u64 = 0x78e5c0cc4ee679cb
key64_040 u64 = 0x2172ffcc7dd05a82
key64_048 u64 = 0x8e2443f7744608b8
key64_056 u64 = 0x4c263a81e69035e0
key64_064 u64 = 0xcb00c391bb52283c
key64_072 u64 = 0xa32e531b8b65d088
key64_080 u64 = 0x4ef90da297486471
key64_088 u64 = 0xd8acdea946ef1938
key64_096 u64 = 0x3f349ce33f76faa8
key64_104 u64 = 0x1d4f0bc7c7bbdcf9
key64_112 u64 = 0x3159b4cd4be0518a
key64_120 u64 = 0x647378d9c97e9fc8
key64_128 u64 = 0xc3ebd33483acc5ea
key64_136 u64 = 0xeb6313faffa081c5
key64_144 u64 = 0x49daf0b751dd0d17
key64_152 u64 = 0x9e68d429265516d3
key64_160 u64 = 0xfca1477d58be162b
key64_168 u64 = 0xce31d07ad1b8f88f
key64_176 u64 = 0x280416958f3acb45
key64_184 u64 = 0x7e404bbbcafbd7af
key64_103 u64 = 0x4f0bc7c7bbdcf93f
key64_111 u64 = 0x59b4cd4be0518a1d
key64_119 u64 = 0x7378d9c97e9fc831
key64_127 u64 = 0xebd33483acc5ea64
key64_121 u64 = 0xea647378d9c97e9f
key64_129 u64 = 0xc5c3ebd33483acc5
key64_137 u64 = 0x17eb6313faffa081
key64_145 u64 = 0xd349daf0b751dd0d
key64_153 u64 = 0x2b9e68d429265516
key64_161 u64 = 0x8ffca1477d58be16
key64_169 u64 = 0x45ce31d07ad1b8f8
key64_177 u64 = 0xaf280416958f3acb
key64_011 = 0x6dd4de1cad21f72c
key64_019 = 0xa44072db979083e9
key64_027 = 0xe679cb1f67b3b7a4
key64_035 = 0xd05a8278e5c0cc4e
key64_043 = 0x4608b82172ffcc7d
key64_051 = 0x9035e08e2443f774
key64_059 = 0x52283c4c263a81e6
key64_067 = 0x65d088cb00c391bb
key64_117 = 0xd9c97e9fc83159b4
key64_125 = 0x3483acc5ea647378
key64_133 = 0xfaffa081c5c3ebd3
key64_141 = 0xb751dd0d17eb6313
key64_149 = 0x29265516d349daf0
key64_157 = 0x7d58be162b9e68d4
key64_165 = 0x7ad1b8f88ffca147
key64_173 = 0x958f3acb45ce31d0
)
const (
key32_000 u32 = 0xbe4ba423
key32_004 u32 = 0x396cfeb8
key32_008 u32 = 0x1cad21f7
key32_012 u32 = 0x2c81017c
)

253
vendor/github.com/zeebo/xxh3/hash128.go generated vendored Normal file
View File

@@ -0,0 +1,253 @@
package xxh3
import (
"math/bits"
)
// Hash128 returns the 128-bit hash of the byte slice.
func Hash128(b []byte) Uint128 {
return hashAny128(*(*str)(ptr(&b)))
}
// HashString128 returns the 128-bit hash of the string slice.
func HashString128(s string) Uint128 {
return hashAny128(*(*str)(ptr(&s)))
}
func hashAny128(s str) (acc u128) {
p, l := s.p, s.l
switch {
case l <= 16:
switch {
case l > 8: // 9-16
const bitflipl = key64_032 ^ key64_040
const bitfliph = key64_048 ^ key64_056
input_lo := readU64(p, 0)
input_hi := readU64(p, ui(l)-8)
m128_h, m128_l := bits.Mul64(input_lo^input_hi^bitflipl, prime64_1)
m128_l += uint64(l-1) << 54
input_hi ^= bitfliph
m128_h += input_hi + uint64(uint32(input_hi))*(prime32_2-1)
m128_l ^= bits.ReverseBytes64(m128_h)
acc.Hi, acc.Lo = bits.Mul64(m128_l, prime64_2)
acc.Hi += m128_h * prime64_2
acc.Lo = xxh3Avalanche(acc.Lo)
acc.Hi = xxh3Avalanche(acc.Hi)
return acc
case l > 3: // 4-8
const bitflip = key64_016 ^ key64_024
input_lo := readU32(p, 0)
input_hi := readU32(p, ui(l)-4)
input_64 := u64(input_lo) + u64(input_hi)<<32
keyed := input_64 ^ bitflip
acc.Hi, acc.Lo = bits.Mul64(keyed, prime64_1+(uint64(l)<<2))
acc.Hi += acc.Lo << 1
acc.Lo ^= acc.Hi >> 3
acc.Lo ^= acc.Lo >> 35
acc.Lo *= 0x9fb21c651e98df25
acc.Lo ^= acc.Lo >> 28
acc.Hi = xxh3Avalanche(acc.Hi)
return acc
case l == 3: // 3
c12 := u64(readU16(p, 0))
c3 := u64(readU8(p, 2))
acc.Lo = c12<<16 + c3 + 3<<8
case l > 1: // 2
c12 := u64(readU16(p, 0))
acc.Lo = c12*(1<<24+1)>>8 + 2<<8
case l == 1: // 1
c1 := u64(readU8(p, 0))
acc.Lo = c1*(1<<24+1<<16+1) + 1<<8
default: // 0
return u128{0x99aa06d3014798d8, 0x6001c324468d497f}
}
acc.Hi = uint64(bits.RotateLeft32(bits.ReverseBytes32(uint32(acc.Lo)), 13))
acc.Lo ^= uint64(key32_000 ^ key32_004)
acc.Hi ^= uint64(key32_008 ^ key32_012)
acc.Lo = xxh64AvalancheSmall(acc.Lo)
acc.Hi = xxh64AvalancheSmall(acc.Hi)
return acc
case l <= 128:
acc.Lo = u64(l) * prime64_1
if l > 32 {
if l > 64 {
if l > 96 {
in8, in7 := readU64(p, ui(l)-8*8), readU64(p, ui(l)-7*8)
i6, i7 := readU64(p, 6*8), readU64(p, 7*8)
acc.Hi += mulFold64(in8^key64_112, in7^key64_120)
acc.Hi ^= i6 + i7
acc.Lo += mulFold64(i6^key64_096, i7^key64_104)
acc.Lo ^= in8 + in7
} // 96
in6, in5 := readU64(p, ui(l)-6*8), readU64(p, ui(l)-5*8)
i4, i5 := readU64(p, 4*8), readU64(p, 5*8)
acc.Hi += mulFold64(in6^key64_080, in5^key64_088)
acc.Hi ^= i4 + i5
acc.Lo += mulFold64(i4^key64_064, i5^key64_072)
acc.Lo ^= in6 + in5
} // 64
in4, in3 := readU64(p, ui(l)-4*8), readU64(p, ui(l)-3*8)
i2, i3 := readU64(p, 2*8), readU64(p, 3*8)
acc.Hi += mulFold64(in4^key64_048, in3^key64_056)
acc.Hi ^= i2 + i3
acc.Lo += mulFold64(i2^key64_032, i3^key64_040)
acc.Lo ^= in4 + in3
} // 32
in2, in1 := readU64(p, ui(l)-2*8), readU64(p, ui(l)-1*8)
i0, i1 := readU64(p, 0*8), readU64(p, 1*8)
acc.Hi += mulFold64(in2^key64_016, in1^key64_024)
acc.Hi ^= i0 + i1
acc.Lo += mulFold64(i0^key64_000, i1^key64_008)
acc.Lo ^= in2 + in1
acc.Hi, acc.Lo = (acc.Lo*prime64_1)+(acc.Hi*prime64_4)+(u64(l)*prime64_2), acc.Hi+acc.Lo
acc.Hi = -xxh3Avalanche(acc.Hi)
acc.Lo = xxh3Avalanche(acc.Lo)
return acc
case l <= 240:
acc.Lo = u64(l) * prime64_1
{
i0, i1, i2, i3 := readU64(p, 0*8), readU64(p, 1*8), readU64(p, 2*8), readU64(p, 3*8)
acc.Hi += mulFold64(i2^key64_016, i3^key64_024)
acc.Hi ^= i0 + i1
acc.Lo += mulFold64(i0^key64_000, i1^key64_008)
acc.Lo ^= i2 + i3
}
{
i0, i1, i2, i3 := readU64(p, 4*8), readU64(p, 5*8), readU64(p, 6*8), readU64(p, 7*8)
acc.Hi += mulFold64(i2^key64_048, i3^key64_056)
acc.Hi ^= i0 + i1
acc.Lo += mulFold64(i0^key64_032, i1^key64_040)
acc.Lo ^= i2 + i3
}
{
i0, i1, i2, i3 := readU64(p, 8*8), readU64(p, 9*8), readU64(p, 10*8), readU64(p, 11*8)
acc.Hi += mulFold64(i2^key64_080, i3^key64_088)
acc.Hi ^= i0 + i1
acc.Lo += mulFold64(i0^key64_064, i1^key64_072)
acc.Lo ^= i2 + i3
}
{
i0, i1, i2, i3 := readU64(p, 12*8), readU64(p, 13*8), readU64(p, 14*8), readU64(p, 15*8)
acc.Hi += mulFold64(i2^key64_112, i3^key64_120)
acc.Hi ^= i0 + i1
acc.Lo += mulFold64(i0^key64_096, i1^key64_104)
acc.Lo ^= i2 + i3
}
// avalanche
acc.Hi = xxh3Avalanche(acc.Hi)
acc.Lo = xxh3Avalanche(acc.Lo)
// trailing groups after 128
top := ui(l) &^ 31
for i := ui(4 * 32); i < top; i += 32 {
i0, i1, i2, i3 := readU64(p, i+0), readU64(p, i+8), readU64(p, i+16), readU64(p, i+24)
k0, k1, k2, k3 := readU64(key, i-125), readU64(key, i-117), readU64(key, i-109), readU64(key, i-101)
acc.Hi += mulFold64(i2^k2, i3^k3)
acc.Hi ^= i0 + i1
acc.Lo += mulFold64(i0^k0, i1^k1)
acc.Lo ^= i2 + i3
}
// last 32 bytes
{
i0, i1, i2, i3 := readU64(p, ui(l)-32), readU64(p, ui(l)-24), readU64(p, ui(l)-16), readU64(p, ui(l)-8)
acc.Hi += mulFold64(i0^key64_119, i1^key64_127)
acc.Hi ^= i2 + i3
acc.Lo += mulFold64(i2^key64_103, i3^key64_111)
acc.Lo ^= i0 + i1
}
acc.Hi, acc.Lo = (acc.Lo*prime64_1)+(acc.Hi*prime64_4)+(u64(l)*prime64_2), acc.Hi+acc.Lo
acc.Hi = -xxh3Avalanche(acc.Hi)
acc.Lo = xxh3Avalanche(acc.Lo)
return acc
default:
acc.Lo = u64(l) * prime64_1
acc.Hi = ^(u64(l) * prime64_2)
accs := [8]u64{
prime32_3, prime64_1, prime64_2, prime64_3,
prime64_4, prime32_2, prime64_5, prime32_1,
}
if hasAVX512 && l >= avx512Switch {
accumAVX512(&accs, p, key, u64(l))
} else if hasAVX2 {
accumAVX2(&accs, p, key, u64(l))
} else if hasSSE2 {
accumSSE(&accs, p, key, u64(l))
} else {
accumScalar(&accs, p, key, u64(l))
}
// merge accs
acc.Lo += mulFold64(accs[0]^key64_011, accs[1]^key64_019)
acc.Hi += mulFold64(accs[0]^key64_117, accs[1]^key64_125)
acc.Lo += mulFold64(accs[2]^key64_027, accs[3]^key64_035)
acc.Hi += mulFold64(accs[2]^key64_133, accs[3]^key64_141)
acc.Lo += mulFold64(accs[4]^key64_043, accs[5]^key64_051)
acc.Hi += mulFold64(accs[4]^key64_149, accs[5]^key64_157)
acc.Lo += mulFold64(accs[6]^key64_059, accs[7]^key64_067)
acc.Hi += mulFold64(accs[6]^key64_165, accs[7]^key64_173)
acc.Lo = xxh3Avalanche(acc.Lo)
acc.Hi = xxh3Avalanche(acc.Hi)
return acc
}
}

264
vendor/github.com/zeebo/xxh3/hash128_seed.go generated vendored Normal file
View File

@@ -0,0 +1,264 @@
package xxh3
import (
"math/bits"
)
// Hash128Seed returns the 128-bit hash of the byte slice.
func Hash128Seed(b []byte, seed uint64) Uint128 {
return hashAny128Seed(*(*str)(ptr(&b)), seed)
}
// HashString128Seed returns the 128-bit hash of the string slice.
func HashString128Seed(s string, seed uint64) Uint128 {
return hashAny128Seed(*(*str)(ptr(&s)), seed)
}
func hashAny128Seed(s str, seed uint64) (acc u128) {
p, l := s.p, s.l
switch {
case l <= 16:
switch {
case l > 8: // 9-16
bitflipl := (key64_032 ^ key64_040) - seed
bitfliph := (key64_048 ^ key64_056) + seed
input_lo := readU64(p, 0)
input_hi := readU64(p, ui(l)-8)
m128_h, m128_l := bits.Mul64(input_lo^input_hi^bitflipl, prime64_1)
m128_l += uint64(l-1) << 54
input_hi ^= bitfliph
m128_h += input_hi + uint64(uint32(input_hi))*(prime32_2-1)
m128_l ^= bits.ReverseBytes64(m128_h)
acc.Hi, acc.Lo = bits.Mul64(m128_l, prime64_2)
acc.Hi += m128_h * prime64_2
acc.Lo = xxh3Avalanche(acc.Lo)
acc.Hi = xxh3Avalanche(acc.Hi)
return acc
case l > 3: // 4-8
seed ^= u64(bits.ReverseBytes32(u32(seed))) << 32
bitflip := (key64_016 ^ key64_024) + seed
input_lo := readU32(p, 0)
input_hi := readU32(p, ui(l)-4)
input_64 := u64(input_lo) + u64(input_hi)<<32
keyed := input_64 ^ bitflip
acc.Hi, acc.Lo = bits.Mul64(keyed, prime64_1+(uint64(l)<<2))
acc.Hi += acc.Lo << 1
acc.Lo ^= acc.Hi >> 3
acc.Lo ^= acc.Lo >> 35
acc.Lo *= 0x9fb21c651e98df25
acc.Lo ^= acc.Lo >> 28
acc.Hi = xxh3Avalanche(acc.Hi)
return acc
case l == 3: // 3
c12 := u64(readU16(p, 0))
c3 := u64(readU8(p, 2))
acc.Lo = c12<<16 + c3 + 3<<8
case l > 1: // 2
c12 := u64(readU16(p, 0))
acc.Lo = c12*(1<<24+1)>>8 + 2<<8
case l == 1: // 1
c1 := u64(readU8(p, 0))
acc.Lo = c1*(1<<24+1<<16+1) + 1<<8
default: // 0
bitflipl := key64_064 ^ key64_072 ^ seed
bitfliph := key64_080 ^ key64_088 ^ seed
return u128{Lo: xxh64AvalancheFull(bitflipl), Hi: xxh64AvalancheFull(bitfliph)}
}
acc.Hi = uint64(bits.RotateLeft32(bits.ReverseBytes32(uint32(acc.Lo)), 13))
acc.Lo ^= uint64(key32_000^key32_004) + seed
acc.Hi ^= uint64(key32_008^key32_012) - seed
acc.Lo = xxh64AvalancheFull(acc.Lo)
acc.Hi = xxh64AvalancheFull(acc.Hi)
return acc
case l <= 128:
acc.Lo = u64(l) * prime64_1
if l > 32 {
if l > 64 {
if l > 96 {
in8, in7 := readU64(p, ui(l)-8*8), readU64(p, ui(l)-7*8)
i6, i7 := readU64(p, 6*8), readU64(p, 7*8)
acc.Hi += mulFold64(in8^(key64_112+seed), in7^(key64_120-seed))
acc.Hi ^= i6 + i7
acc.Lo += mulFold64(i6^(key64_096+seed), i7^(key64_104-seed))
acc.Lo ^= in8 + in7
} // 96
in6, in5 := readU64(p, ui(l)-6*8), readU64(p, ui(l)-5*8)
i4, i5 := readU64(p, 4*8), readU64(p, 5*8)
acc.Hi += mulFold64(in6^(key64_080+seed), in5^(key64_088-seed))
acc.Hi ^= i4 + i5
acc.Lo += mulFold64(i4^(key64_064+seed), i5^(key64_072-seed))
acc.Lo ^= in6 + in5
} // 64
in4, in3 := readU64(p, ui(l)-4*8), readU64(p, ui(l)-3*8)
i2, i3 := readU64(p, 2*8), readU64(p, 3*8)
acc.Hi += mulFold64(in4^(key64_048+seed), in3^(key64_056-seed))
acc.Hi ^= i2 + i3
acc.Lo += mulFold64(i2^(key64_032+seed), i3^(key64_040-seed))
acc.Lo ^= in4 + in3
} // 32
in2, in1 := readU64(p, ui(l)-2*8), readU64(p, ui(l)-1*8)
i0, i1 := readU64(p, 0*8), readU64(p, 1*8)
acc.Hi += mulFold64(in2^(key64_016+seed), in1^(key64_024-seed))
acc.Hi ^= i0 + i1
acc.Lo += mulFold64(i0^(key64_000+seed), i1^(key64_008-seed))
acc.Lo ^= in2 + in1
acc.Hi, acc.Lo = (acc.Lo*prime64_1)+(acc.Hi*prime64_4)+((u64(l)-seed)*prime64_2), acc.Hi+acc.Lo
acc.Hi = -xxh3Avalanche(acc.Hi)
acc.Lo = xxh3Avalanche(acc.Lo)
return acc
case l <= 240:
acc.Lo = u64(l) * prime64_1
{
i0, i1, i2, i3 := readU64(p, 0*8), readU64(p, 1*8), readU64(p, 2*8), readU64(p, 3*8)
acc.Hi += mulFold64(i2^(key64_016+seed), i3^(key64_024-seed))
acc.Hi ^= i0 + i1
acc.Lo += mulFold64(i0^(key64_000+seed), i1^(key64_008-seed))
acc.Lo ^= i2 + i3
}
{
i0, i1, i2, i3 := readU64(p, 4*8), readU64(p, 5*8), readU64(p, 6*8), readU64(p, 7*8)
acc.Hi += mulFold64(i2^(key64_048+seed), i3^(key64_056-seed))
acc.Hi ^= i0 + i1
acc.Lo += mulFold64(i0^(key64_032+seed), i1^(key64_040-seed))
acc.Lo ^= i2 + i3
}
{
i0, i1, i2, i3 := readU64(p, 8*8), readU64(p, 9*8), readU64(p, 10*8), readU64(p, 11*8)
acc.Hi += mulFold64(i2^(key64_080+seed), i3^(key64_088-seed))
acc.Hi ^= i0 + i1
acc.Lo += mulFold64(i0^(key64_064+seed), i1^(key64_072-seed))
acc.Lo ^= i2 + i3
}
{
i0, i1, i2, i3 := readU64(p, 12*8), readU64(p, 13*8), readU64(p, 14*8), readU64(p, 15*8)
acc.Hi += mulFold64(i2^(key64_112+seed), i3^(key64_120-seed))
acc.Hi ^= i0 + i1
acc.Lo += mulFold64(i0^(key64_096+seed), i1^(key64_104-seed))
acc.Lo ^= i2 + i3
}
// avalanche
acc.Hi = xxh3Avalanche(acc.Hi)
acc.Lo = xxh3Avalanche(acc.Lo)
// trailing groups after 128
top := ui(l) &^ 31
for i := ui(4 * 32); i < top; i += 32 {
i0, i1, i2, i3 := readU64(p, i+0), readU64(p, i+8), readU64(p, i+16), readU64(p, i+24)
k0, k1, k2, k3 := readU64(key, i-125)+seed, readU64(key, i-117)-seed, readU64(key, i-109)+seed, readU64(key, i-101)-seed
acc.Hi += mulFold64(i2^k2, i3^k3)
acc.Hi ^= i0 + i1
acc.Lo += mulFold64(i0^k0, i1^k1)
acc.Lo ^= i2 + i3
}
// last 32 bytes
{
i0, i1, i2, i3 := readU64(p, ui(l)-32), readU64(p, ui(l)-24), readU64(p, ui(l)-16), readU64(p, ui(l)-8)
seed := 0 - seed
acc.Hi += mulFold64(i0^(key64_119+seed), i1^(key64_127-seed))
acc.Hi ^= i2 + i3
acc.Lo += mulFold64(i2^(key64_103+seed), i3^(key64_111-seed))
acc.Lo ^= i0 + i1
}
acc.Hi, acc.Lo = (acc.Lo*prime64_1)+(acc.Hi*prime64_4)+((u64(l)-seed)*prime64_2), acc.Hi+acc.Lo
acc.Hi = -xxh3Avalanche(acc.Hi)
acc.Lo = xxh3Avalanche(acc.Lo)
return acc
default:
acc.Lo = u64(l) * prime64_1
acc.Hi = ^(u64(l) * prime64_2)
secret := key
if seed != 0 {
secret = ptr(&[secretSize]byte{})
initSecret(secret, seed)
}
accs := [8]u64{
prime32_3, prime64_1, prime64_2, prime64_3,
prime64_4, prime32_2, prime64_5, prime32_1,
}
if hasAVX512 && l >= avx512Switch {
accumAVX512(&accs, p, secret, u64(l))
} else if hasAVX2 {
accumAVX2(&accs, p, secret, u64(l))
} else if hasSSE2 {
accumSSE(&accs, p, secret, u64(l))
} else {
accumScalar(&accs, p, secret, u64(l))
}
// merge accs
const hi_off = 117 - 11
acc.Lo += mulFold64(accs[0]^readU64(secret, 11), accs[1]^readU64(secret, 19))
acc.Hi += mulFold64(accs[0]^readU64(secret, 11+hi_off), accs[1]^readU64(secret, 19+hi_off))
acc.Lo += mulFold64(accs[2]^readU64(secret, 27), accs[3]^readU64(secret, 35))
acc.Hi += mulFold64(accs[2]^readU64(secret, 27+hi_off), accs[3]^readU64(secret, 35+hi_off))
acc.Lo += mulFold64(accs[4]^readU64(secret, 43), accs[5]^readU64(secret, 51))
acc.Hi += mulFold64(accs[4]^readU64(secret, 43+hi_off), accs[5]^readU64(secret, 51+hi_off))
acc.Lo += mulFold64(accs[6]^readU64(secret, 59), accs[7]^readU64(secret, 67))
acc.Hi += mulFold64(accs[6]^readU64(secret, 59+hi_off), accs[7]^readU64(secret, 67+hi_off))
acc.Lo = xxh3Avalanche(acc.Lo)
acc.Hi = xxh3Avalanche(acc.Hi)
return acc
}
}

126
vendor/github.com/zeebo/xxh3/hash64.go generated vendored Normal file
View File

@@ -0,0 +1,126 @@
package xxh3
import "math/bits"
// Hash returns the hash of the byte slice.
func Hash(b []byte) uint64 {
return hashAny(*(*str)(ptr(&b)))
}
// Hash returns the hash of the string slice.
func HashString(s string) uint64 {
return hashAny(*(*str)(ptr(&s)))
}
func hashAny(s str) (acc u64) {
p, l := s.p, s.l
switch {
case l <= 16:
switch {
case l > 8: // 9-16
inputlo := readU64(p, 0) ^ (key64_024 ^ key64_032)
inputhi := readU64(p, ui(l)-8) ^ (key64_040 ^ key64_048)
folded := mulFold64(inputlo, inputhi)
return xxh3Avalanche(u64(l) + bits.ReverseBytes64(inputlo) + inputhi + folded)
case l > 3: // 4-8
input1 := readU32(p, 0)
input2 := readU32(p, ui(l)-4)
input64 := u64(input2) + u64(input1)<<32
keyed := input64 ^ (key64_008 ^ key64_016)
return rrmxmx(keyed, u64(l))
case l == 3: // 3
c12 := u64(readU16(p, 0))
c3 := u64(readU8(p, 2))
acc = c12<<16 + c3 + 3<<8
case l > 1: // 2
c12 := u64(readU16(p, 0))
acc = c12*(1<<24+1)>>8 + 2<<8
case l == 1: // 1
c1 := u64(readU8(p, 0))
acc = c1*(1<<24+1<<16+1) + 1<<8
default: // 0
return 0x2d06800538d394c2 // xxh_avalanche(key64_056 ^ key64_064)
}
acc ^= u64(key32_000 ^ key32_004)
return xxhAvalancheSmall(acc)
case l <= 128:
acc = u64(l) * prime64_1
if l > 32 {
if l > 64 {
if l > 96 {
acc += mulFold64(readU64(p, 6*8)^key64_096, readU64(p, 7*8)^key64_104)
acc += mulFold64(readU64(p, ui(l)-8*8)^key64_112, readU64(p, ui(l)-7*8)^key64_120)
} // 96
acc += mulFold64(readU64(p, 4*8)^key64_064, readU64(p, 5*8)^key64_072)
acc += mulFold64(readU64(p, ui(l)-6*8)^key64_080, readU64(p, ui(l)-5*8)^key64_088)
} // 64
acc += mulFold64(readU64(p, 2*8)^key64_032, readU64(p, 3*8)^key64_040)
acc += mulFold64(readU64(p, ui(l)-4*8)^key64_048, readU64(p, ui(l)-3*8)^key64_056)
} // 32
acc += mulFold64(readU64(p, 0*8)^key64_000, readU64(p, 1*8)^key64_008)
acc += mulFold64(readU64(p, ui(l)-2*8)^key64_016, readU64(p, ui(l)-1*8)^key64_024)
return xxh3Avalanche(acc)
case l <= 240:
acc = u64(l) * prime64_1
acc += mulFold64(readU64(p, 0*16+0)^key64_000, readU64(p, 0*16+8)^key64_008)
acc += mulFold64(readU64(p, 1*16+0)^key64_016, readU64(p, 1*16+8)^key64_024)
acc += mulFold64(readU64(p, 2*16+0)^key64_032, readU64(p, 2*16+8)^key64_040)
acc += mulFold64(readU64(p, 3*16+0)^key64_048, readU64(p, 3*16+8)^key64_056)
acc += mulFold64(readU64(p, 4*16+0)^key64_064, readU64(p, 4*16+8)^key64_072)
acc += mulFold64(readU64(p, 5*16+0)^key64_080, readU64(p, 5*16+8)^key64_088)
acc += mulFold64(readU64(p, 6*16+0)^key64_096, readU64(p, 6*16+8)^key64_104)
acc += mulFold64(readU64(p, 7*16+0)^key64_112, readU64(p, 7*16+8)^key64_120)
// avalanche
acc = xxh3Avalanche(acc)
// trailing groups after 128
top := ui(l) &^ 15
for i := ui(8 * 16); i < top; i += 16 {
acc += mulFold64(readU64(p, i+0)^readU64(key, i-125), readU64(p, i+8)^readU64(key, i-117))
}
// last 16 bytes
acc += mulFold64(readU64(p, ui(l)-16)^key64_119, readU64(p, ui(l)-8)^key64_127)
return xxh3Avalanche(acc)
default:
acc = u64(l) * prime64_1
accs := [8]u64{
prime32_3, prime64_1, prime64_2, prime64_3,
prime64_4, prime32_2, prime64_5, prime32_1,
}
if hasAVX512 && l >= avx512Switch {
accumAVX512(&accs, p, key, u64(l))
} else if hasAVX2 {
accumAVX2(&accs, p, key, u64(l))
} else if hasSSE2 {
accumSSE(&accs, p, key, u64(l))
} else {
accumScalar(&accs, p, key, u64(l))
}
// merge accs
acc += mulFold64(accs[0]^key64_011, accs[1]^key64_019)
acc += mulFold64(accs[2]^key64_027, accs[3]^key64_035)
acc += mulFold64(accs[4]^key64_043, accs[5]^key64_051)
acc += mulFold64(accs[6]^key64_059, accs[7]^key64_067)
return xxh3Avalanche(acc)
}
}

134
vendor/github.com/zeebo/xxh3/hash64_seed.go generated vendored Normal file
View File

@@ -0,0 +1,134 @@
package xxh3
import "math/bits"
// HashSeed returns the hash of the byte slice with given seed.
func HashSeed(b []byte, seed uint64) uint64 {
return hashAnySeed(*(*str)(ptr(&b)), seed)
}
// HashStringSeed returns the hash of the string slice with given seed.
func HashStringSeed(s string, seed uint64) uint64 {
return hashAnySeed(*(*str)(ptr(&s)), seed)
}
func hashAnySeed(s str, seed uint64) (acc u64) {
p, l := s.p, s.l
switch {
case l <= 16:
switch {
case l > 8:
inputlo := readU64(p, 0) ^ (key64_024 ^ key64_032 + seed)
inputhi := readU64(p, ui(l)-8) ^ (key64_040 ^ key64_048 - seed)
folded := mulFold64(inputlo, inputhi)
return xxh3Avalanche(u64(l) + bits.ReverseBytes64(inputlo) + inputhi + folded)
case l > 3:
seed ^= u64(bits.ReverseBytes32(u32(seed))) << 32
input1 := readU32(p, 0)
input2 := readU32(p, ui(l)-4)
input64 := u64(input2) + u64(input1)<<32
keyed := input64 ^ (key64_008 ^ key64_016 - seed)
return rrmxmx(keyed, u64(l))
case l == 3: // 3
c12 := u64(readU16(p, 0))
c3 := u64(readU8(p, 2))
acc = c12<<16 + c3 + 3<<8
case l > 1: // 2
c12 := u64(readU16(p, 0))
acc = c12*(1<<24+1)>>8 + 2<<8
case l == 1: // 1
c1 := u64(readU8(p, 0))
acc = c1*(1<<24+1<<16+1) + 1<<8
default:
return xxhAvalancheSmall(seed ^ key64_056 ^ key64_064)
}
acc ^= u64(key32_000^key32_004) + seed
return xxhAvalancheSmall(acc)
case l <= 128:
acc = u64(l) * prime64_1
if l > 32 {
if l > 64 {
if l > 96 {
acc += mulFold64(readU64(p, 6*8)^(key64_096+seed), readU64(p, 7*8)^(key64_104-seed))
acc += mulFold64(readU64(p, ui(l)-8*8)^(key64_112+seed), readU64(p, ui(l)-7*8)^(key64_120-seed))
} // 96
acc += mulFold64(readU64(p, 4*8)^(key64_064+seed), readU64(p, 5*8)^(key64_072-seed))
acc += mulFold64(readU64(p, ui(l)-6*8)^(key64_080+seed), readU64(p, ui(l)-5*8)^(key64_088-seed))
} // 64
acc += mulFold64(readU64(p, 2*8)^(key64_032+seed), readU64(p, 3*8)^(key64_040-seed))
acc += mulFold64(readU64(p, ui(l)-4*8)^(key64_048+seed), readU64(p, ui(l)-3*8)^(key64_056-seed))
} // 32
acc += mulFold64(readU64(p, 0*8)^(key64_000+seed), readU64(p, 1*8)^(key64_008-seed))
acc += mulFold64(readU64(p, ui(l)-2*8)^(key64_016+seed), readU64(p, ui(l)-1*8)^(key64_024-seed))
return xxh3Avalanche(acc)
case l <= 240:
acc = u64(l) * prime64_1
acc += mulFold64(readU64(p, 0*16+0)^(key64_000+seed), readU64(p, 0*16+8)^(key64_008-seed))
acc += mulFold64(readU64(p, 1*16+0)^(key64_016+seed), readU64(p, 1*16+8)^(key64_024-seed))
acc += mulFold64(readU64(p, 2*16+0)^(key64_032+seed), readU64(p, 2*16+8)^(key64_040-seed))
acc += mulFold64(readU64(p, 3*16+0)^(key64_048+seed), readU64(p, 3*16+8)^(key64_056-seed))
acc += mulFold64(readU64(p, 4*16+0)^(key64_064+seed), readU64(p, 4*16+8)^(key64_072-seed))
acc += mulFold64(readU64(p, 5*16+0)^(key64_080+seed), readU64(p, 5*16+8)^(key64_088-seed))
acc += mulFold64(readU64(p, 6*16+0)^(key64_096+seed), readU64(p, 6*16+8)^(key64_104-seed))
acc += mulFold64(readU64(p, 7*16+0)^(key64_112+seed), readU64(p, 7*16+8)^(key64_120-seed))
// avalanche
acc = xxh3Avalanche(acc)
// trailing groups after 128
top := ui(l) &^ 15
for i := ui(8 * 16); i < top; i += 16 {
acc += mulFold64(readU64(p, i+0)^(readU64(key, i-125)+seed), readU64(p, i+8)^(readU64(key, i-117)-seed))
}
// last 16 bytes
acc += mulFold64(readU64(p, ui(l)-16)^(key64_119+seed), readU64(p, ui(l)-8)^(key64_127-seed))
return xxh3Avalanche(acc)
default:
acc = u64(l) * prime64_1
secret := key
if seed != 0 {
secret = ptr(&[secretSize]byte{})
initSecret(secret, seed)
}
accs := [8]u64{
prime32_3, prime64_1, prime64_2, prime64_3,
prime64_4, prime32_2, prime64_5, prime32_1,
}
if hasAVX512 && l >= avx512Switch {
accumAVX512(&accs, p, secret, u64(l))
} else if hasAVX2 {
accumAVX2(&accs, p, secret, u64(l))
} else if hasSSE2 {
accumSSE(&accs, p, secret, u64(l))
} else {
accumScalarSeed(&accs, p, secret, u64(l))
}
// merge accs
acc += mulFold64(accs[0]^readU64(secret, 11), accs[1]^readU64(secret, 19))
acc += mulFold64(accs[2]^readU64(secret, 27), accs[3]^readU64(secret, 35))
acc += mulFold64(accs[4]^readU64(secret, 43), accs[5]^readU64(secret, 51))
acc += mulFold64(accs[6]^readU64(secret, 59), accs[7]^readU64(secret, 67))
return xxh3Avalanche(acc)
}
}

239
vendor/github.com/zeebo/xxh3/hasher.go generated vendored Normal file
View File

@@ -0,0 +1,239 @@
package xxh3
import (
"encoding/binary"
"hash"
)
// Hasher implements the hash.Hash interface
type Hasher struct {
acc [8]u64
blk u64
len u64
key ptr
buf [_block + _stripe]byte
seed u64
}
var (
_ hash.Hash = (*Hasher)(nil)
_ hash.Hash64 = (*Hasher)(nil)
)
// New returns a new Hasher that implements the hash.Hash interface.
func New() *Hasher {
return new(Hasher)
}
// NewSeed returns a new Hasher that implements the hash.Hash interface.
func NewSeed(seed uint64) *Hasher {
var h Hasher
h.Reset()
h.seed = seed
h.key = key
// Only initiate once, not on reset.
if seed != 0 {
h.key = ptr(&[secretSize]byte{})
initSecret(h.key, seed)
}
return &h
}
// Reset resets the Hash to its initial state.
func (h *Hasher) Reset() {
h.acc = [8]u64{
prime32_3, prime64_1, prime64_2, prime64_3,
prime64_4, prime32_2, prime64_5, prime32_1,
}
h.blk = 0
h.len = 0
}
// BlockSize returns the hash's underlying block size.
// The Write method will accept any amount of data, but
// it may operate more efficiently if all writes are a
// multiple of the block size.
func (h *Hasher) BlockSize() int { return _stripe }
// Size returns the number of bytes Sum will return.
func (h *Hasher) Size() int { return 8 }
// Sum appends the current hash to b and returns the resulting slice.
// It does not change the underlying hash state.
func (h *Hasher) Sum(b []byte) []byte {
var tmp [8]byte
binary.BigEndian.PutUint64(tmp[:], h.Sum64())
return append(b, tmp[:]...)
}
// Write adds more data to the running hash.
// It never returns an error.
func (h *Hasher) Write(buf []byte) (int, error) {
h.update(buf)
return len(buf), nil
}
// WriteString adds more data to the running hash.
// It never returns an error.
func (h *Hasher) WriteString(buf string) (int, error) {
h.updateString(buf)
return len(buf), nil
}
func (h *Hasher) update(buf []byte) {
// relies on the data pointer being the first word in the string header
h.updateString(*(*string)(ptr(&buf)))
}
func (h *Hasher) updateString(buf string) {
if h.key == nil {
h.key = key
h.Reset()
}
// On first write, if more than 1 block, process without copy.
for h.len == 0 && len(buf) > len(h.buf) {
if hasAVX2 {
accumBlockAVX2(&h.acc, *(*ptr)(ptr(&buf)), h.key)
} else if hasSSE2 {
accumBlockSSE(&h.acc, *(*ptr)(ptr(&buf)), h.key)
} else {
accumBlockScalar(&h.acc, *(*ptr)(ptr(&buf)), h.key)
}
buf = buf[_block:]
h.blk++
}
for len(buf) > 0 {
if h.len < u64(len(h.buf)) {
n := copy(h.buf[h.len:], buf)
h.len += u64(n)
buf = buf[n:]
continue
}
if hasAVX2 {
accumBlockAVX2(&h.acc, ptr(&h.buf), h.key)
} else if hasSSE2 {
accumBlockSSE(&h.acc, ptr(&h.buf), h.key)
} else {
accumBlockScalar(&h.acc, ptr(&h.buf), h.key)
}
h.blk++
h.len = _stripe
copy(h.buf[:_stripe], h.buf[_block:])
}
}
// Sum64 returns the 64-bit hash of the written data.
func (h *Hasher) Sum64() uint64 {
if h.key == nil {
h.key = key
h.Reset()
}
if h.blk == 0 {
if h.seed == 0 {
return Hash(h.buf[:h.len])
}
return HashSeed(h.buf[:h.len], h.seed)
}
l := h.blk*_block + h.len
acc := l * prime64_1
accs := h.acc
if h.len > 0 {
// We are only ever doing 1 block here, so no avx512.
if hasAVX2 {
accumAVX2(&accs, ptr(&h.buf[0]), h.key, h.len)
} else if hasSSE2 {
accumSSE(&accs, ptr(&h.buf[0]), h.key, h.len)
} else {
accumScalar(&accs, ptr(&h.buf[0]), h.key, h.len)
}
}
if h.seed == 0 {
acc += mulFold64(accs[0]^key64_011, accs[1]^key64_019)
acc += mulFold64(accs[2]^key64_027, accs[3]^key64_035)
acc += mulFold64(accs[4]^key64_043, accs[5]^key64_051)
acc += mulFold64(accs[6]^key64_059, accs[7]^key64_067)
} else {
secret := h.key
acc += mulFold64(accs[0]^readU64(secret, 11), accs[1]^readU64(secret, 19))
acc += mulFold64(accs[2]^readU64(secret, 27), accs[3]^readU64(secret, 35))
acc += mulFold64(accs[4]^readU64(secret, 43), accs[5]^readU64(secret, 51))
acc += mulFold64(accs[6]^readU64(secret, 59), accs[7]^readU64(secret, 67))
}
acc = xxh3Avalanche(acc)
return acc
}
// Sum128 returns the 128-bit hash of the written data.
func (h *Hasher) Sum128() Uint128 {
if h.key == nil {
h.key = key
h.Reset()
}
if h.blk == 0 {
if h.seed == 0 {
return Hash128(h.buf[:h.len])
}
return Hash128Seed(h.buf[:h.len], h.seed)
}
l := h.blk*_block + h.len
acc := Uint128{Lo: l * prime64_1, Hi: ^(l * prime64_2)}
accs := h.acc
if h.len > 0 {
// We are only ever doing 1 block here, so no avx512.
if hasAVX2 {
accumAVX2(&accs, ptr(&h.buf[0]), h.key, h.len)
} else if hasSSE2 {
accumSSE(&accs, ptr(&h.buf[0]), h.key, h.len)
} else {
accumScalar(&accs, ptr(&h.buf[0]), h.key, h.len)
}
}
if h.seed == 0 {
acc.Lo += mulFold64(accs[0]^key64_011, accs[1]^key64_019)
acc.Hi += mulFold64(accs[0]^key64_117, accs[1]^key64_125)
acc.Lo += mulFold64(accs[2]^key64_027, accs[3]^key64_035)
acc.Hi += mulFold64(accs[2]^key64_133, accs[3]^key64_141)
acc.Lo += mulFold64(accs[4]^key64_043, accs[5]^key64_051)
acc.Hi += mulFold64(accs[4]^key64_149, accs[5]^key64_157)
acc.Lo += mulFold64(accs[6]^key64_059, accs[7]^key64_067)
acc.Hi += mulFold64(accs[6]^key64_165, accs[7]^key64_173)
} else {
secret := h.key
const hi_off = 117 - 11
acc.Lo += mulFold64(accs[0]^readU64(secret, 11), accs[1]^readU64(secret, 19))
acc.Hi += mulFold64(accs[0]^readU64(secret, 11+hi_off), accs[1]^readU64(secret, 19+hi_off))
acc.Lo += mulFold64(accs[2]^readU64(secret, 27), accs[3]^readU64(secret, 35))
acc.Hi += mulFold64(accs[2]^readU64(secret, 27+hi_off), accs[3]^readU64(secret, 35+hi_off))
acc.Lo += mulFold64(accs[4]^readU64(secret, 43), accs[5]^readU64(secret, 51))
acc.Hi += mulFold64(accs[4]^readU64(secret, 43+hi_off), accs[5]^readU64(secret, 51+hi_off))
acc.Lo += mulFold64(accs[6]^readU64(secret, 59), accs[7]^readU64(secret, 67))
acc.Hi += mulFold64(accs[6]^readU64(secret, 59+hi_off), accs[7]^readU64(secret, 67+hi_off))
}
acc.Lo = xxh3Avalanche(acc.Lo)
acc.Hi = xxh3Avalanche(acc.Hi)
return acc
}

129
vendor/github.com/zeebo/xxh3/utils.go generated vendored Normal file
View File

@@ -0,0 +1,129 @@
package xxh3
import (
"math/bits"
"unsafe"
)
// Uint128 is a 128 bit value.
// The actual value can be thought of as u.Hi<<64 | u.Lo.
type Uint128 struct {
Hi, Lo uint64
}
// Bytes returns the uint128 as an array of bytes in canonical form (big-endian encoded).
func (u Uint128) Bytes() [16]byte {
return [16]byte{
byte(u.Hi >> 0x38), byte(u.Hi >> 0x30), byte(u.Hi >> 0x28), byte(u.Hi >> 0x20),
byte(u.Hi >> 0x18), byte(u.Hi >> 0x10), byte(u.Hi >> 0x08), byte(u.Hi),
byte(u.Lo >> 0x38), byte(u.Lo >> 0x30), byte(u.Lo >> 0x28), byte(u.Lo >> 0x20),
byte(u.Lo >> 0x18), byte(u.Lo >> 0x10), byte(u.Lo >> 0x08), byte(u.Lo),
}
}
type (
ptr = unsafe.Pointer
ui = uintptr
u8 = uint8
u32 = uint32
u64 = uint64
u128 = Uint128
)
type str struct {
p ptr
l uint
}
func readU8(p ptr, o ui) uint8 {
return *(*uint8)(ptr(ui(p) + o))
}
func readU16(p ptr, o ui) uint16 {
b := (*[2]byte)(ptr(ui(p) + o))
return uint16(b[0]) | uint16(b[1])<<8
}
func readU32(p ptr, o ui) uint32 {
b := (*[4]byte)(ptr(ui(p) + o))
return uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24
}
func readU64(p ptr, o ui) uint64 {
b := (*[8]byte)(ptr(ui(p) + o))
return uint64(b[0]) | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24 |
uint64(b[4])<<32 | uint64(b[5])<<40 | uint64(b[6])<<48 | uint64(b[7])<<56
}
func writeU64(p ptr, o ui, v u64) {
b := (*[8]byte)(ptr(ui(p) + o))
b[0] = byte(v)
b[1] = byte(v >> 8)
b[2] = byte(v >> 16)
b[3] = byte(v >> 24)
b[4] = byte(v >> 32)
b[5] = byte(v >> 40)
b[6] = byte(v >> 48)
b[7] = byte(v >> 56)
}
const secretSize = 192
func initSecret(secret ptr, seed u64) {
for i := ui(0); i < secretSize/16; i++ {
lo := readU64(key, 16*i) + seed
hi := readU64(key, 16*i+8) - seed
writeU64(secret, 16*i, lo)
writeU64(secret, 16*i+8, hi)
}
}
func xxh64AvalancheSmall(x u64) u64 {
// x ^= x >> 33 // x must be < 32 bits
// x ^= u64(key32_000 ^ key32_004) // caller must do this
x *= prime64_2
x ^= x >> 29
x *= prime64_3
x ^= x >> 32
return x
}
func xxhAvalancheSmall(x u64) u64 {
x ^= x >> 33
x *= prime64_2
x ^= x >> 29
x *= prime64_3
x ^= x >> 32
return x
}
func xxh64AvalancheFull(x u64) u64 {
x ^= x >> 33
x *= prime64_2
x ^= x >> 29
x *= prime64_3
x ^= x >> 32
return x
}
func xxh3Avalanche(x u64) u64 {
x ^= x >> 37
x *= 0x165667919e3779f9
x ^= x >> 32
return x
}
func rrmxmx(h64 u64, len u64) u64 {
h64 ^= bits.RotateLeft64(h64, 49) ^ bits.RotateLeft64(h64, 24)
h64 *= 0x9fb21c651e98df25
h64 ^= (h64 >> 35) + len
h64 *= 0x9fb21c651e98df25
h64 ^= (h64 >> 28)
return h64
}
func mulFold64(x, y u64) u64 {
hi, lo := bits.Mul64(x, y)
return hi ^ lo
}

8
vendor/modules.txt vendored
View File

@@ -843,6 +843,9 @@ github.com/kardianos/osext
# github.com/karrick/godirwalk v1.16.1
## explicit; go 1.13
github.com/karrick/godirwalk
# github.com/klauspost/cpuid/v2 v2.0.9
## explicit; go 1.13
github.com/klauspost/cpuid/v2
# github.com/koding/websocketproxy v0.0.0-20181220232114-7ed82d81a28c
## explicit
github.com/koding/websocketproxy
@@ -1342,6 +1345,9 @@ github.com/yosida95/uritemplate/v3
# github.com/yusufpapurcu/wmi v1.2.2
## explicit; go 1.16
github.com/yusufpapurcu/wmi
# github.com/zeebo/xxh3 v1.0.2
## explicit; go 1.17
github.com/zeebo/xxh3
# github.com/zexi/influxql-to-metricsql v0.1.1
## explicit; go 1.18
github.com/zexi/influxql-to-metricsql/converter
@@ -1900,7 +1906,7 @@ sigs.k8s.io/structured-merge-diff/v4/value
# sigs.k8s.io/yaml v1.2.0
## explicit; go 1.12
sigs.k8s.io/yaml
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250930065031-d469e632afc7
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250930105820-7f5a2ad54a65
## explicit; go 1.24
yunion.io/x/cloudmux/pkg/apis
yunion.io/x/cloudmux/pkg/apis/billing

View File

@@ -142,13 +142,13 @@ func (region *SRegion) GetISnapshots() ([]cloudprovider.ICloudSnapshot, error) {
ret := []cloudprovider.ICloudSnapshot{}
for i := 0; i < len(snapshots); i += 1 {
snapshots[i].region = region
ret[i] = &snapshots[i]
ret = append(ret, &snapshots[i])
}
return ret, nil
}
func (self *SSnapshot) Delete() error {
return self.region.DeleteSnapshot(self.SnapshotId)
func (snap *SSnapshot) Delete() error {
return snap.region.DeleteSnapshot(snap.SnapshotId)
}
func (region *SRegion) CreateSnapshot(diskId, name, desc string) (*SSnapshot, error) {

View File

@@ -31,6 +31,7 @@ type SStorage struct {
zone *SZone
StorageType string
available bool
}
func (storage *SStorage) GetId() string {
@@ -91,7 +92,7 @@ func (storage *SStorage) GetStorageConf() jsonutils.JSONObject {
}
func (storage *SStorage) GetEnabled() bool {
return true
return storage.available
}
func (storage *SStorage) CreateIDisk(opts *cloudprovider.DiskCreateConfig) (cloudprovider.ICloudDisk, error) {
@@ -138,5 +139,8 @@ func (storage *SStorage) GetIStoragecache() cloudprovider.ICloudStoragecache {
}
func (storage *SStorage) GetStatus() string {
if !storage.available {
return api.STORAGE_OFFLINE
}
return api.STORAGE_ONLINE
}

View File

@@ -147,31 +147,45 @@ func (zone *SZone) GetDescription() string {
}
func (zone *SZone) GetStorages() ([]SStorage, error) {
zoneDiskType := []string{}
for i := range api.KSYUN_STORAGES {
if api.KSYUN_STORAGES[i] == api.STORAGE_KSYUN_LOCAL_SSD {
zoneDiskType = append(zoneDiskType, api.KSYUN_STORAGES[i])
zoneDiskType := map[string]bool{}
for _, storageType := range api.KSYUN_STORAGES {
if storageType == api.STORAGE_KSYUN_LOCAL_SSD {
zoneDiskType[storageType] = true
continue
}
params := map[string]interface{}{
"VolumeType": api.KSYUN_STORAGES[i],
}
resp, err := zone.region.ebsRequest("DescribeAvailabilityZones", params)
zoneList, err := zone.region.GetZonesByDiskType(storageType)
if err != nil {
return nil, errors.Wrapf(err, "%s:ValidateAttachInstance", api.KSYUN_STORAGES[i])
}
zoneList := []string{}
err = resp.Unmarshal(&zoneList, "AvailabilityZones")
if err != nil {
return nil, errors.Wrap(err, "unmarshal zoneList")
return nil, errors.Wrapf(err, "GetZonesByDiskType: %s", storageType)
}
if utils.IsInStringArray(zone.GetName(), zoneList) {
zoneDiskType = append(zoneDiskType, api.KSYUN_STORAGES[i])
zoneDiskType[storageType] = true
} else {
zoneDiskType[storageType] = false
}
}
storages := []SStorage{}
for i := range zoneDiskType {
storages = append(storages, SStorage{zone: zone, StorageType: zoneDiskType[i]})
for storageType, available := range zoneDiskType {
storage := SStorage{zone: zone, StorageType: storageType, available: available}
storages = append(storages, storage)
}
return storages, nil
}
func (region *SRegion) GetZonesByDiskType(diskType string) ([]string, error) {
params := map[string]interface{}{
"VolumeType": diskType,
}
resp, err := region.ebsRequest("DescribeAvailabilityZones", params)
if err != nil {
return nil, errors.Wrap(err, "DescribeAvailabilityZones")
}
ret := struct {
AvailabilityZones []string `json:"AvailabilityZones"`
}{}
err = resp.Unmarshal(&ret)
if err != nil {
return nil, errors.Wrap(err, "unmarshal zoneList")
}
return ret.AvailabilityZones, nil
}