4 @EXPORT = qw(LOGL, UNLOGL, LOGU32, UNLOGU32, LLOGU32, LUNLOGU32, LOGU64, UNLOGU64, LLOGU64, LUNLOGU64);
7 return ($_[0] + 3) & ~0x3;
11 return ($_[0] + 3) & ~0x7;
17 # padd to 32bit alignment move $_[1] forward
20 my $len = length($_[2]);
21 my $rlen = round_len($len);
22 my $padd = $rlen + $off - length($_[0]);
25 $_[0] .= pack "x$padd";
27 substr $_[0], $_[1], $len, $_[2];
31 # pack $_[2], a u32, into $_[0] at offset $_[1]
33 if ($_[1] != round_len($_[1])) {
34 confess "packing I on non-word boundary";
36 my $padd = 4 + $off - length($_[0]);
39 $_[0] .= pack "L", $_[2];
41 substr $_[0], $_[1], $len, pack "L", $_[2];
46 # pack $_[2], a u32, into $_[0] at offset $_[1]
49 if ($_[1] != round_len($_[1])) {
50 confess "packing V on non-word boundary";
52 my $padd = 4 + $off - length($_[0]);
55 $_[0] .= pack "V", $_[2];
57 substr $_[0], $_[1], $len, pack "V", $_[2];
63 if ($_[1] != roundq_len($_[1])) {
64 confess "packing Q on non-word boundary";
66 my $padd = 8 + $off - length($_[0]);
69 $_[0] .= pack "VV", $_[3], $_[2];
71 substr $_[0], $_[1], $len, pack "VV", $_[3], $_[2];
77 if ($_[1] != roundq_len($_[1])) {
78 confess "packing Q on non-word boundary";
80 my $padd = 8 + $off - length($_[0]);
83 $_[0] .= pack "LL", $_[3], $_[2];
85 substr $_[0], $_[1], $len, pack "LL", $_[3], $_[2];
91 if (length($_[0]) < $_[1] + round_len($_[2]) ) {
92 confess "unpacking buf beyond string length";
95 $_[3] = unpack "x$_[1]a$_[2]", $_[0];
96 $_[1] += round_len($_[2]);
101 if (length($_[0]) < $_[1] + 4) {
102 confess "unpacking u32 beyond string length";
105 $_[2] = unpack "x$_[1]L", $_[0];
111 if (length($_[0]) < $_[1] + 4) {
112 confess "lunpacking u32 beyond string length";
114 $_[2] = unpack "x$_[1]V", $_[0];
120 if (length($_[0]) < $_[1] + 8) {
121 confess "unpacking u64 beyond string length";
124 ($_[3], $_[2]) = unpack "x$_[1]LL", $_[0];
126 return ($_[2], $_[3]);
130 if (length($_[0]) < $_[1] + 8) {
131 confess "lunpacking u64 beyond string length";
134 ($_[3], $_[2]) = unpack "x$_[1]VV", $_[0];
136 return ($_[2], $_[3]);
143 LOGL($buf, $off, "moose");
145 printf "len %d\n", length($buf);
146 LLOGU64($buf, $off, 0x01020304, 0x05060708);
148 printf "len %d\n", length($buf);
149 LLOGU32($buf, $off, 0x01020304);
151 printf "len %d\n", length($buf);
153 UNLOGL($buf, $off, length("moose"), $str);
154 print "off $off $str\n";
155 LUNLOGU64($buf, $off, $high, $low);
156 printf "off $off high %x low %x\n", $high, $low;
157 LUNLOGU32($buf, $off, $low);
158 printf "off $off long %x\n", $low;
161 $str = UNLOGL($buf, $off, length("moose"));
162 print "assigned off $off $str\n";
163 ($high, $low) = LUNLOGU64($buf, $off);
164 printf "assigned off $off high %x low %x\n", $high, $low;
165 $low = LUNLOGU32($buf, $off, $low);
166 printf "assigned off $off long %x\n", $low;
168 sysopen F, "/tmp/out", 2;
169 syswrite F, $buf, length($buf);