Black Lives Matter. Support the Equal Justice Initiative.

Source file src/runtime/internal/sys/intrinsics_test.go

Documentation: runtime/internal/sys

     1  package sys_test
     2  
     3  import (
     4  	"runtime/internal/sys"
     5  	"testing"
     6  )
     7  
     8  func TestCtz64(t *testing.T) {
     9  	for i := 0; i <= 64; i++ {
    10  		x := uint64(5) << uint(i)
    11  		if got := sys.Ctz64(x); got != i {
    12  			t.Errorf("Ctz64(%d)=%d, want %d", x, got, i)
    13  		}
    14  	}
    15  }
    16  func TestCtz32(t *testing.T) {
    17  	for i := 0; i <= 32; i++ {
    18  		x := uint32(5) << uint(i)
    19  		if got := sys.Ctz32(x); got != i {
    20  			t.Errorf("Ctz32(%d)=%d, want %d", x, got, i)
    21  		}
    22  	}
    23  }
    24  
    25  func TestBswap64(t *testing.T) {
    26  	x := uint64(0x1122334455667788)
    27  	y := sys.Bswap64(x)
    28  	if y != 0x8877665544332211 {
    29  		t.Errorf("Bswap(%x)=%x, want 0x8877665544332211", x, y)
    30  	}
    31  }
    32  func TestBswap32(t *testing.T) {
    33  	x := uint32(0x11223344)
    34  	y := sys.Bswap32(x)
    35  	if y != 0x44332211 {
    36  		t.Errorf("Bswap(%x)=%x, want 0x44332211", x, y)
    37  	}
    38  }
    39  

View as plain text