-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: new reflect impl for non-amd64 arch
use `FRUGAL_NO_JIT` env var to enable the reflect impl on amd64
- Loading branch information
Showing
28 changed files
with
3,336 additions
and
256 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright 2024 CloudWeGo Authors | ||
* | ||
* 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 reflect | ||
|
||
import ( | ||
"reflect" | ||
"unsafe" | ||
) | ||
|
||
// rvUnsafePointer backports rv.UnsafePointer for go1.17 | ||
// TODO: remove this func and use rv.UnsafePointer() directly when >= go1.18 | ||
func rvUnsafePointer(rv reflect.Value) unsafe.Pointer { | ||
return unsafe.Pointer(rv.Pointer()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright 2024 CloudWeGo Authors | ||
* | ||
* 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 reflect | ||
|
||
import "sync" | ||
|
||
type bitset struct { | ||
data [1024]uint64 // 635536 bits for field id | ||
} | ||
|
||
var bitsetPool = sync.Pool{ | ||
New: func() interface{} { | ||
return &bitset{} | ||
}, | ||
} | ||
|
||
func (s *bitset) set(i uint16) { | ||
x, y := i>>8, i&7 // i/64, i%64 | ||
s.data[x] |= 1 << y | ||
} | ||
|
||
func (s *bitset) unset(i uint16) { | ||
x, y := i>>8, i&7 // i/64, i%64 | ||
s.data[x] &= ^(1 << y) | ||
} | ||
|
||
func (s *bitset) test(i uint16) bool { | ||
x, y := i>>8, i&7 // i/64, i%64 | ||
return (s.data[x] & (1 << y)) != 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright 2024 CloudWeGo Authors | ||
* | ||
* 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 reflect | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestBitset(t *testing.T) { | ||
s := &bitset{} | ||
for i := uint16(0); i < ^uint16(0); i++ { | ||
if i%2 == 0 { | ||
s.set(i) | ||
} | ||
if i%4 == 0 { | ||
s.unset(i) | ||
} | ||
} | ||
for i := uint16(0); i < ^uint16(0); i++ { | ||
if i%4 == 0 { | ||
require.False(t, s.test(i)) | ||
} else if i%2 == 0 { | ||
require.True(t, s.test(i)) | ||
} else { | ||
require.False(t, s.test(i)) | ||
} | ||
} | ||
} |
Oops, something went wrong.