Skip to content
Permalink
Browse files

Add buf8.write-uint128

  • Loading branch information...
lizmat committed Dec 13, 2018
1 parent af96fbb commit 5cc0e02d42bea7d1fa14c93a62cbc11188469cf9
Showing with 12 additions and 1 deletion.
  1. +12 −1 src/core/Buf.pm6
@@ -690,11 +690,22 @@ my role Buf[::T = uint8] does Blob[T] is repr('VMArray') is array_type(T) {
nqp::bitor_i(BINARY_SIZE_32_BIT,$endian))
}
method write-uint64(
int $offset, uint64 $value, Endian $endian = NativeEndian --> Nil
int $offset, UInt $value, Endian $endian = NativeEndian --> Nil
) is raw {
nqp::writeuint(self,$offset,$value,
nqp::bitor_i(BINARY_SIZE_64_BIT,$endian))
}
method write-uint128(
int $offset, UInt $value, Endian $endian = NativeEndian --> Nil
) is raw {
my \first := $value +> 64;
my \second := $value +& ( 1 +< 64 - 1 );
my $be = $endian == BigEndian
|| ($endian == NativeEndian && Kernel.endian == BigEndian);

self.write-uint64($offset, $be ?? first !! second, $endian);
self.write-uint64($offset + 8, $be ?? second !! first, $endian);
}
method write-num32(
int $offset, num32 $value, Endian $endian = NativeEndian --> Nil
) is raw {

3 comments on commit 5cc0e02

@MasterDuke17

This comment has been minimized.

Copy link
Contributor

replied Dec 13, 2018

Is it safe to make these UInt vs uint? Couldn't the value be more than 128-bit?

@lizmat

This comment has been minimized.

Copy link
Contributor Author

replied Dec 13, 2018

@MasterDuke17: there is no native support for 128 bit integers in any implementation of Perl 6. Also, currently there is a bug with uint64 only accepting 63-bit wide values. Therefore the use of UInt in those cases.

@MasterDuke17

This comment has been minimized.

Copy link
Contributor

replied Dec 13, 2018

Yeah, I wasn't clear. I mean that since a UInt is just a subset of Int, couldn't its value be greater than could be represented by a 128-bit native?

Please sign in to comment.
You can’t perform that action at this time.