Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:adapts to Mac M1 #280

Merged
merged 7 commits into from Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions Makefile
Expand Up @@ -14,24 +14,28 @@
# limitations under the License.
#

ARCH := avx avx2
ARCH := avx avx2 sse4
TMP_DIR := output
OUT_DIR := internal/native
SRC_FILE := native/native.c

CPU_avx := amd64
CPU_avx2 := amd64
CPU_sse4 := amd64

TMPL_avx := fastint_amd64_test fastfloat_amd64_test native_amd64_test native_export_amd64
TMPL_avx2 := fastint_amd64_test fastfloat_amd64_test native_amd64_test native_export_amd64
TMPL_sse4 := fastint_amd64_test fastfloat_amd64_test native_amd64_test native_export_amd64

CFLAGS_avx := -msse4 -mavx -mno-avx2 -DUSE_AVX=1 -DUSE_AVX2=0
CFLAGS_avx2 := -msse4 -mavx -mavx2 -DUSE_AVX=1 -DUSE_AVX2=1
CFLAGS_avx2 := -msse4 -mavx -mavx2 -DUSE_AVX=1 -DUSE_AVX2=1
CFLAGS_sse4 := -msse4 -mno-avx -mno-avx2

CC_amd64 := clang
ASM2ASM_amd64 := tools/asm2asm/asm2asm.py

CFLAGS := -mno-red-zone
CFLAGS += -arch x86_64
CFLAGS += -fno-asynchronous-unwind-tables
CFLAGS += -fno-builtin
CFLAGS += -fno-exceptions
Expand Down Expand Up @@ -95,8 +99,8 @@ endef
all: ${ARCH}

clean:
rm -vfr ${TMP_DIR}/{sse,avx,avx2}
rm -vfr ${OUT_DIR}/{sse,avx,avx2}
rm -vfr ${TMP_DIR}/{sse4,avx,avx2}
rm -vfr ${OUT_DIR}/{sse4,avx,avx2}

$(foreach \
arch, \
Expand Down
2 changes: 1 addition & 1 deletion bench.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python3

# Copyright 2021 ByteDance Inc.
# Copyright 2022 ByteDance Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
4 changes: 2 additions & 2 deletions decoder/decoder.go
Expand Up @@ -21,9 +21,9 @@ import (
`reflect`
`runtime`

`github.com/bytedance/sonic/internal/rt`
`github.com/bytedance/sonic/internal/native`
`github.com/bytedance/sonic/internal/native/types`
`github.com/bytedance/sonic/internal/rt`
`github.com/bytedance/sonic/option`
)

Expand Down Expand Up @@ -203,7 +203,7 @@ func pretouchRec(vtm map[reflect.Type]bool, opts option.CompileOptions) error {
}

// Skip skips only one json value, and returns first non-blank character position and its ending position if it is valid.
// Otherwise returns negative error code using start and invalid character position using end
// Otherwise, returns negative error code using start and invalid character position using end
func Skip(data []byte) (start int, end int) {
s := rt.Mem2Str(data)
p := 0
Expand Down
2 changes: 1 addition & 1 deletion fuzz/Makefile
Expand Up @@ -6,7 +6,7 @@ fuzz:
file2fuzz -o ./testdata/fuzz/FuzzMain ./go-fuzz-corpus/json/corpus/* ./corpus/*

run:
go test -fuzz=Fuzz -v
GOARCH=amd64 go test -fuzz=Fuzz -v

clean:
rm -rf ./go-fuzz-corpus/
Expand Down
4 changes: 3 additions & 1 deletion internal/cpu/features.go
Expand Up @@ -26,13 +26,15 @@ import (
var (
HasAVX = cpuid.CPU.Has(cpuid.AVX)
HasAVX2 = cpuid.CPU.Has(cpuid.AVX2)
HasSSE4 = cpuid.CPU.Has(cpuid.SSE4)
)

func init() {
switch v := os.Getenv("SONIC_MODE"); v {
case "" : break
case "auto" : break
case "noavx" : HasAVX = false; fallthrough
case "noavx2" : HasAVX2 = false
default : panic(fmt.Sprintf("invalid mode: '%s', should be one of 'auto', 'noavx2'", v))
default : panic(fmt.Sprintf("invalid mode: '%s', should be one of 'auto', 'noavx', 'noavx2'", v))
}
}