diff --git a/vlib/encoding/binary/binary.v b/vlib/encoding/binary/binary.v index d5d6579e55..05c819e01f 100644 --- a/vlib/encoding/binary/binary.v +++ b/vlib/encoding/binary/binary.v @@ -6,23 +6,26 @@ module binary // Little Endian +[inline] pub fn little_endian_endian_u16(b []byte) u16 { _ := b[1] // bounds check return u16(b[0]) | u16(u16(b[1])<> u16(8)) } +[inline] pub fn little_endian_u32(b []byte) u32 { _ := b[3] // bounds check return u32(b[0]) | u32(u32(b[1])<> u32(24)) } +[inline] pub fn little_endian_u64(b []byte) u64 { _ := b[7] // bounds check return u64(b[0]) | u64(u64(b[1])<> u16(8)) b[1] = byte(v) } +[inline] pub fn big_endian_u32(b []byte) u32 { _ := b[3] // bounds check return u32(b[3]) | u32(u32(b[2])<> u32(24)) @@ -74,12 +83,14 @@ pub fn big_endian_put_u32(b mut []byte, v u32) { b[3] = byte(v) } +[inline] pub fn big_endian_u64(b []byte) u64 { _ := b[7] // bounds check return u64(b[7]) | u64(u64(b[6])<> u64(56)) diff --git a/vlib/math/bits/bits.v b/vlib/math/bits/bits.v index d25d9c9a4f..9d4b288936 100644 --- a/vlib/math/bits/bits.v +++ b/vlib/math/bits/bits.v @@ -10,6 +10,7 @@ module bits // To rotate x right by k bits, call rotate_left_8(x, -k). // // This function's execution time does not depend on the inputs. +[inline] pub fn rotate_left_8(x byte, k int) byte { n := byte(8) s := byte(k) & byte(n - byte(1)) @@ -20,6 +21,7 @@ pub fn rotate_left_8(x byte, k int) byte { // To rotate x right by k bits, call rotate_left_16(x, -k). // // This function's execution time does not depend on the inputs. +[inline] pub fn rotate_left_16(x u16, k int) u16 { n := u16(16) s := u16(k) & (n - u16(1)) @@ -30,6 +32,7 @@ pub fn rotate_left_16(x u16, k int) u16 { // To rotate x right by k bits, call rotate_left_32(x, -k). // // This function's execution time does not depend on the inputs. +[inline] pub fn rotate_left_32(x u32, k int) u32 { n := u32(32) s := u32(k) & (n - u32(1)) @@ -40,6 +43,7 @@ pub fn rotate_left_32(x u32, k int) u32 { // To rotate x right by k bits, call rotate_left_64(x, -k). // // This function's execution time does not depend on the inputs. +[inline] pub fn rotate_left_64(x u64, k int) u64 { n := u64(64) s := u64(k) & (n - u64(1))