Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package test
- import (
- "math"
- "testing"
- )
- //go:noinline
- func test64And(x uint64) uint64 {
- return (x &^ (1 << 63)) & 0x0F
- }
- func Benchmark64Bit(b *testing.B) {
- for i := 0; i < b.N; i++ {
- _ = test64And(uint64(i))
- }
- }
- //go:noinline
- func test32And(x uint32) uint32 {
- return (x &^ (1 << 31)) & 0x0F
- }
- func Benchmark32Bit(b *testing.B) {
- for i := 0; i < b.N; i++ {
- _ = test32And(uint32(i))
- }
- }
- //go:noinline
- func test16And(x uint16) uint16 {
- return (x &^ (1 << 15)) & 0x0F
- }
- func Benchmark16Bit(b *testing.B) {
- for i := 0; i < b.N; i++ {
- _ = test16And(uint16(i))
- }
- }
- //go:noinline
- func test8And(x uint8) uint8 {
- return ((x &^ (1 << 7)) & 0x0F)
- }
- func Benchmark8Bit(b *testing.B) {
- for i := 0; i < b.N; i++ {
- _ = test8And(uint8(i))
- }
- }
- //go:noinline
- func Abs_ssa(x float64) float64 {
- return math.Float64frombits(math.Float64bits(x) &^ (1 << 63))
- }
- func BenchmarkAbs(b *testing.B) {
- for i := 0; i < b.N; i++ {
- _ = Abs_ssa(-1)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement