Fixed move instruction encoding on arm64
This commit is contained in:
parent
22cbc15cdd
commit
bdf41ead5c
7 changed files with 108 additions and 74 deletions
|
@ -3,15 +3,17 @@ package sizeof
|
|||
import "math"
|
||||
|
||||
// Unsigned tells you how many bytes are needed to encode this unsigned number.
|
||||
func Unsigned(number uint64) int {
|
||||
func Unsigned[T uint | uint8 | uint16 | uint32 | uint64 | int | int8 | int16 | int32 | int64](number T) int {
|
||||
x := uint64(number)
|
||||
|
||||
switch {
|
||||
case number <= math.MaxUint8:
|
||||
case x <= math.MaxUint8:
|
||||
return 1
|
||||
|
||||
case number <= math.MaxUint16:
|
||||
case x <= math.MaxUint16:
|
||||
return 2
|
||||
|
||||
case number <= math.MaxUint32:
|
||||
case x <= math.MaxUint32:
|
||||
return 4
|
||||
|
||||
default:
|
||||
|
|
|
@ -11,7 +11,9 @@ import (
|
|||
func TestUnsigned(t *testing.T) {
|
||||
assert.Equal(t, sizeof.Unsigned(0), 1)
|
||||
assert.Equal(t, sizeof.Unsigned(math.MaxUint8), 1)
|
||||
assert.Equal(t, sizeof.Unsigned(math.MaxUint8+1), 2)
|
||||
assert.Equal(t, sizeof.Unsigned(math.MaxUint16), 2)
|
||||
assert.Equal(t, sizeof.Unsigned(math.MaxUint16+1), 4)
|
||||
assert.Equal(t, sizeof.Unsigned(math.MaxUint32), 4)
|
||||
assert.Equal(t, sizeof.Unsigned(math.MaxUint64), 8)
|
||||
assert.Equal(t, sizeof.Unsigned(math.MaxUint32+1), 8)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue