Fixed move instruction encoding on arm64

This commit is contained in:
Eduard Urbach 2025-03-15 13:49:30 +01:00
parent 22cbc15cdd
commit bdf41ead5c
Signed by: eduard
GPG key ID: 49226B848C78F6C8
7 changed files with 108 additions and 74 deletions

View file

@ -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:

View file

@ -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)
}