blib/lib/Nasm/X86.pm

filter: Statementstmt 3.1% 200 / 6389 Branchbran 0.6% 11 / 1592 Conditioncond 0.0% 0 / 358 MC/DCmcdc 0.0% 0 / 223 Subroutinesub 1.1% 16 / 1426 Podpod 23.3% 206 / 881 totaltotal 3.9% 433 / 10869 CC 991 SCAR 43.1
CC
991
Cov
3%
Assemble
2256.0
BEGIN
831.5
getBwdqFromMm
506.0
CRAP 74.6
↑ Summary Build »
1 #!/usr/bin/perl -I/home/phil/perl/cpan/DataTableText/lib/ -I. -I/home/phil/perl/cpan/AsmC/lib/
2 #-------------------------------------------------------------------------------
3 # Generate X86 assembler code using Perl as a macro pre-processor.
4 # Philip R Brenan at appaapps dot com, Appa Apps Ltd Inc., 2021
5 #-------------------------------------------------------------------------------
6 # podDocumentation
7 # Time: 39.37s, bytes: 3,615,792, execs: 1,844,146
8 # tree::print - speed up decision as to whether we are on a tree or not
9 # Replace empty in boolean arithmetic with boolean and then check it in If to confirm that we are testing a boolean value
10 # M: optimize PushR, would the print routines work better off the stack? Remove macro?
11 # Make all describe routines work like DescribeTree
12 # 0x401000 from sde-mix-out addresses to get offsets in z.txt
13 package Nasm::X86;
14 1 our $VERSION = "20210918";
15 1 ▶use warnings FATAL => qw(all);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Carp qw(confess cluck);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use Data::Dump qw(dump);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use Data::Table::Text qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use Asm::C qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use feature qw(say current_sub);
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 1 my %rodata; # Read only data already written
25 my %rodatas; # Read only string already written
26 1 my %subroutines; # Subroutines generated
27 1 my @rodata; # Read only data
28 1 my @data; # Data
29 1 my @bss; # Block started by symbol
30 1 my @text; # Code
31 1 my @extern; # External symbols imports for linking with C libraries
32 1 my @link; # Specify libraries which to link against in the final assembly stage
33 1 my $interpreter = q(-I /usr/lib64/ld-linux-x86-64.so.2); # The ld command needs an interpreter if we are linking with C.
34 1 my $develop = -e q(/home/phil/); # Developing
35 1 my $sdeMixOut = q(sde-mix-out.txt); # Emulator output file
36  
37 1 our $stdin = 0; # File descriptor for standard input
38 1 our $stdout = 1; # File descriptor for standard output
39 1 our $stderr = 2; # File descriptor for standard error
40  
41 1 my %Registers; # The names of all the registers
42 my %RegisterContaining; # The largest register containing a register
43 1 my @GeneralPurposeRegisters = (qw(rax rbx rcx rdx rsi rdi), map {"r$_"} 8..15); # General purpose registers
44 1 my @RegistersAvailable = ({map {$_=>1} @GeneralPurposeRegisters}); # A stack of hashes of registers that are currently free and this can be used without pushing and popping them.
45  
46 BEGIN{
47 1 ▶ my %r = ( map {$_=>[ 8, '8' ]} qw(al bl cl dl r8b r9b r10b r11b r12b r13b r14b r15b r8l r9l r10l r11l r12l r13l r14l r15l sil dil spl bpl ah bh ch dh));
Subroutine BEGIN: called CC=31 SCAR=67.2
48 1 %r = (%r, map {$_=>[16, 's' ]} qw(cs ds es fs gs ss));
49 1 %r = (%r, map {$_=>[16, '16' ]} qw(ax bx cx dx r8w r9w r10w r11w r12w r13w r14w r15w si di sp bp));
50 1 %r = (%r, map {$_=>[32, '32a']} qw(eax ebx ecx edx esi edi esp ebp));
51 1 %r = (%r, map {$_=>[32, '32b']} qw(r8d r9d r10d r11d r12d r13d r14d r15d));
52 1 %r = (%r, map {$_=>[80, 'f' ]} qw(st0 st1 st2 st3 st4 st5 st6 st7));
53 1 %r = (%r, map {$_=>[64, '64' ]} qw(rax rbx rcx rdx r8 r9 r10 r11 r12 r13 r14 r15 rsi rdi rsp rbp rip rflags));
54 1 %r = (%r, map {$_=>[64, '64m']} qw(mm0 mm1 mm2 mm3 mm4 mm5 mm6 mm7));
55 1 %r = (%r, map {$_=>[128, '128']} qw(xmm0 xmm1 xmm2 xmm3 xmm4 xmm5 xmm6 xmm7 xmm8 xmm9 xmm10 xmm11 xmm12 xmm13 xmm14 xmm15 xmm16 xmm17 xmm18 xmm19 xmm20 xmm21 xmm22 xmm23 xmm24 xmm25 xmm26 xmm27 xmm28 xmm29 xmm30 xmm31));
56 1 %r = (%r, map {$_=>[256, '256']} qw(ymm0 ymm1 ymm2 ymm3 ymm4 ymm5 ymm6 ymm7 ymm8 ymm9 ymm10 ymm11 ymm12 ymm13 ymm14 ymm15 ymm16 ymm17 ymm18 ymm19 ymm20 ymm21 ymm22 ymm23 ymm24 ymm25 ymm26 ymm27 ymm28 ymm29 ymm30 ymm31));
57 1 %r = (%r, map {$_=>[512, '512']} qw(zmm0 zmm1 zmm2 zmm3 zmm4 zmm5 zmm6 zmm7 zmm8 zmm9 zmm10 zmm11 zmm12 zmm13 zmm14 zmm15 zmm16 zmm17 zmm18 zmm19 zmm20 zmm21 zmm22 zmm23 zmm24 zmm25 zmm26 zmm27 zmm28 zmm29 zmm30 zmm31));
58 1 %r = (%r, map {$_=>[64, 'm' ]} qw(k0 k1 k2 k3 k4 k5 k6 k7));
59  
60 1 %Registers = %r; # Register names
61  
62 my sub registerContaining($@)
63 56 ▶ {my ($r, @r) = @_; # Register, contents
Subroutine registerContaining: called CC=2 SCAR=6.9
64 56 $RegisterContaining{$r} = $r; # A register contains itself
65 56 $RegisterContaining{$_} = $r for @r; # Registers contained by a register
66 }
67  
68 1 registerContaining("k$_") for 0..7;
69 1 registerContaining("zmm$_", "ymm$_", "xmm$_") for 0..31;
70 1 registerContaining("r${_}x", "e${_}x", "${_}x", "${_}l", "${_}h") for qw(a b c d);
71 1 registerContaining("r${_}", "r${_}l", "r${_}w", "r${_}b", "r${_}d") for 8..15;
72 1 registerContaining("r${_}p", "e${_}p", "${_}p", "${_}pl") for qw(s b);
73 1 registerContaining("r${_}i", "e${_}i", "${_}i", "${_}il") for qw(s d);
74 1 my @i0 = qw(cpuid lahf leave popfq pushfq rdtsc ret syscall); # Zero operand instructions
75  
76 1 my @i1 = split /\s+/, <<END; # Single operand instructions
77 bswap call dec idiv inc jmp ja jae jb jbe jc jcxz je jecxz jg jge jl jle
78 jna jnae jnb jnbe jnc jne jng jnge jnl jnle jno jnp jns jnz jo jp jpe jpo jrcxz
79 js jz loop neg not seta setae setb setbe setc sete setg setge setl setle setna setnae
80 setnb setnbe setnc setne setng setnge setnl setno setnp setns setnz seto setp
81 setpe setpo sets setz pop push
82 END
83  
84 1 my @i2 = split /\s+/, <<END; # Double operand instructions
85 add and bt btc btr bts
86 cmova cmovae cmovb cmovbe cmovc cmove cmovg cmovge cmovl cmovle
87 cmovna cmovnae cmovnb cmp
88 enter
89 imul
90 kmov knot kortest ktest lea lzcnt mov movdqa
91 or popcnt shl shr sub test tzcnt
92 vcvtudq2pd vcvtuqq2pd vcvtudq2ps vmovdqu vmovdqu32 vmovdqu64 vmovdqu8
93 vpcompressd vpcompressq vpexpandd vpexpandq xchg xor
94 vmovd vmovq
95 mulpd
96 pslldq psrldq
97 vsqrtpd
98 vmovdqa32 vmovdqa64
99 END
100 # print STDERR join ' ', sort @i2; exit;
101  
102 1 my @i2qdwb = split /\s+/, <<END; # Double operand instructions which have qdwb versions
103 vpbroadcast
104 END
105  
106 1 my @i3 = split /\s+/, <<END; # Triple operand instructions
107 andn
108 bzhi
109 kadd kand kandn kor kshiftl kshiftr kunpck kxnor kxor
110  
111 vdpps
112 vprolq
113 vgetmantps
114 vaddd
115 vmulpd vaddpd
116 END
117  
118 1 my @i3qdwb = split /\s+/, <<END; # Triple operand instructions which have qdwb versions
119 pinsr pextr vpand vpandn vpcmpeq vpor vpxor vptest vporvpcmpeq vpinsr vpextr vpadd vpsub vpmull
120 END
121  
122 1 my @i4 = split /\s+/, <<END; # Quadruple operand instructions
123 END
124  
125 1 my @i4qdwb = split /\s+/, <<END; # Quadruple operand instructions which have qdwb versions
126 vpcmpu
127 END
128  
129 1 if (1) # Add variants to mask instructions
130 1 {my @k2 = grep {m/\Ak/} @i2; @i2 = grep {!m/\Ak/} @i2;
131 1 my @k3 = grep {m/\Ak/} @i3; @i3 = grep {!m/\Ak/} @i3;
132 1 for my $s(qw(b w d q))
133 4 {push @i2, $_.$s for grep {m/\Ak/} @k2;
134 4 push @i3, $_.$s for grep {m/\Ak/} @k3;
135 }
136 }
137  
138 1 if (1) # Add qdwb versions of instructions
139 1 {for my $o(@i2qdwb)
140 1 {push @i2, $o.$_ for qw(b w d q);
141 }
142 1 for my $o(@i3qdwb)
143 14 {push @i3, $o.$_ for qw(b w d q);
144 }
145 1 for my $o(@i4qdwb)
146 1 {push @i4, $o.$_ for qw(b w d q);
147 }
148 }
149  
150 1 for my $r(sort keys %r) # Create register definitions
151 204 {if (1)
152 204 {my $s = "sub $r\{q($r)\}";
153 204 ▶ eval $s;
Subroutine ah: not called CC=1 SCAR=6.9
Subroutine al: not called CC=1 SCAR=6.9
Subroutine ax: not called CC=1 SCAR=6.9
Subroutine bh: not called CC=1 SCAR=6.9
Subroutine bl: not called CC=1 SCAR=6.9
Subroutine bp: not called CC=1 SCAR=6.9
Subroutine bpl: not called CC=1 SCAR=6.9
Subroutine bx: not called CC=1 SCAR=6.9
Subroutine ch: not called CC=1 SCAR=6.9
Subroutine cl: not called CC=1 SCAR=6.9
Subroutine cs: not called CC=1 SCAR=6.9
Subroutine cx: not called CC=1 SCAR=6.9
Subroutine dh: not called CC=1 SCAR=6.9
Subroutine di: not called CC=1 SCAR=6.9
Subroutine dil: not called CC=1 SCAR=6.9
Subroutine dl: not called CC=1 SCAR=6.9
Subroutine ds: not called CC=1 SCAR=6.9
Subroutine dx: not called CC=1 SCAR=6.9
Subroutine eax: not called CC=1 SCAR=6.9
Subroutine ebp: not called CC=1 SCAR=6.9
Subroutine ebx: not called CC=1 SCAR=6.9
Subroutine ecx: not called CC=1 SCAR=6.9
Subroutine edi: not called CC=1 SCAR=6.9
Subroutine edx: not called CC=1 SCAR=6.9
Subroutine es: not called CC=1 SCAR=6.9
Subroutine esi: not called CC=1 SCAR=6.9
Subroutine esp: not called CC=1 SCAR=6.9
Subroutine fs: not called CC=1 SCAR=6.9
Subroutine gs: not called CC=1 SCAR=6.9
Subroutine k0: not called CC=1 SCAR=6.9
Subroutine k1: not called CC=1 SCAR=6.9
Subroutine k2: not called CC=1 SCAR=6.9
Subroutine k3: not called CC=1 SCAR=6.9
Subroutine k4: not called CC=1 SCAR=6.9
Subroutine k5: not called CC=1 SCAR=6.9
Subroutine k6: not called CC=1 SCAR=6.9
Subroutine k7: not called CC=1 SCAR=6.9
Subroutine mm0: not called CC=1 SCAR=6.9
Subroutine mm1: not called CC=1 SCAR=6.9
Subroutine mm2: not called CC=1 SCAR=6.9
Subroutine mm3: not called CC=1 SCAR=6.9
Subroutine mm4: not called CC=1 SCAR=6.9
Subroutine mm5: not called CC=1 SCAR=6.9
Subroutine mm6: not called CC=1 SCAR=6.9
Subroutine mm7: not called CC=1 SCAR=6.9
Subroutine r10: not called CC=1 SCAR=6.9
Subroutine r10b: not called CC=1 SCAR=6.9
Subroutine r10d: not called CC=1 SCAR=6.9
Subroutine r10l: not called CC=1 SCAR=6.9
Subroutine r10w: not called CC=1 SCAR=6.9
Subroutine r11: not called CC=1 SCAR=6.9
Subroutine r11b: not called CC=1 SCAR=6.9
Subroutine r11d: not called CC=1 SCAR=6.9
Subroutine r11l: not called CC=1 SCAR=6.9
Subroutine r11w: not called CC=1 SCAR=6.9
Subroutine r12: not called CC=1 SCAR=6.9
Subroutine r12b: not called CC=1 SCAR=6.9
Subroutine r12d: not called CC=1 SCAR=6.9
Subroutine r12l: not called CC=1 SCAR=6.9
Subroutine r12w: not called CC=1 SCAR=6.9
Subroutine r13: not called CC=1 SCAR=6.9
Subroutine r13b: not called CC=1 SCAR=6.9
Subroutine r13d: not called CC=1 SCAR=6.9
Subroutine r13l: not called CC=1 SCAR=6.9
Subroutine r13w: not called CC=1 SCAR=6.9
Subroutine r14: not called CC=1 SCAR=6.9
Subroutine r14b: not called CC=1 SCAR=6.9
Subroutine r14d: not called CC=1 SCAR=6.9
Subroutine r14l: not called CC=1 SCAR=6.9
Subroutine r14w: not called CC=1 SCAR=6.9
Subroutine r15: not called CC=1 SCAR=6.9
Subroutine r15b: not called CC=1 SCAR=6.9
Subroutine r15d: not called CC=1 SCAR=6.9
Subroutine r15l: not called CC=1 SCAR=6.9
Subroutine r15w: not called CC=1 SCAR=6.9
Subroutine r8: not called CC=1 SCAR=6.9
Subroutine r8b: not called CC=1 SCAR=6.9
Subroutine r8d: not called CC=1 SCAR=6.9
Subroutine r8l: not called CC=1 SCAR=6.9
Subroutine r8w: not called CC=1 SCAR=6.9
Subroutine r9: not called CC=1 SCAR=6.9
Subroutine r9b: not called CC=1 SCAR=6.9
Subroutine r9d: not called CC=1 SCAR=6.9
Subroutine r9l: not called CC=1 SCAR=6.9
Subroutine r9w: not called CC=1 SCAR=6.9
Subroutine rax: not called CC=1 SCAR=6.9
Subroutine rbp: not called CC=1 SCAR=6.9
Subroutine rbx: not called CC=1 SCAR=6.9
Subroutine rcx: not called CC=1 SCAR=6.9
Subroutine rdi: not called CC=1 SCAR=6.9
Subroutine rdx: not called CC=1 SCAR=6.9
Subroutine rflags: not called CC=1 SCAR=6.9
Subroutine rip: not called CC=1 SCAR=6.9
Subroutine rsi: not called CC=1 SCAR=6.9
Subroutine rsp: not called CC=1 SCAR=6.9
Subroutine si: not called CC=1 SCAR=6.9
Subroutine sil: not called CC=1 SCAR=6.9
Subroutine sp: not called CC=1 SCAR=6.9
Subroutine spl: not called CC=1 SCAR=6.9
Subroutine ss: not called CC=1 SCAR=6.9
Subroutine st0: not called CC=1 SCAR=6.9
Subroutine st1: not called CC=1 SCAR=6.9
Subroutine st2: not called CC=1 SCAR=6.9
Subroutine st3: not called CC=1 SCAR=6.9
Subroutine st4: not called CC=1 SCAR=6.9
Subroutine st5: not called CC=1 SCAR=6.9
Subroutine st6: not called CC=1 SCAR=6.9
Subroutine st7: not called CC=1 SCAR=6.9
Subroutine xmm0: not called CC=1 SCAR=6.9
Subroutine xmm1: not called CC=1 SCAR=6.9
Subroutine xmm10: not called CC=1 SCAR=6.9
Subroutine xmm11: not called CC=1 SCAR=6.9
Subroutine xmm12: not called CC=1 SCAR=6.9
Subroutine xmm13: not called CC=1 SCAR=6.9
Subroutine xmm14: not called CC=1 SCAR=6.9
Subroutine xmm15: not called CC=1 SCAR=6.9
Subroutine xmm16: not called CC=1 SCAR=6.9
Subroutine xmm17: not called CC=1 SCAR=6.9
Subroutine xmm18: not called CC=1 SCAR=6.9
Subroutine xmm19: not called CC=1 SCAR=6.9
Subroutine xmm2: not called CC=1 SCAR=6.9
Subroutine xmm20: not called CC=1 SCAR=6.9
Subroutine xmm21: not called CC=1 SCAR=6.9
Subroutine xmm22: not called CC=1 SCAR=6.9
Subroutine xmm23: not called CC=1 SCAR=6.9
Subroutine xmm24: not called CC=1 SCAR=6.9
Subroutine xmm25: not called CC=1 SCAR=6.9
Subroutine xmm26: not called CC=1 SCAR=6.9
Subroutine xmm27: not called CC=1 SCAR=6.9
Subroutine xmm28: not called CC=1 SCAR=6.9
Subroutine xmm29: not called CC=1 SCAR=6.9
Subroutine xmm3: not called CC=1 SCAR=6.9
Subroutine xmm30: not called CC=1 SCAR=6.9
Subroutine xmm31: not called CC=1 SCAR=6.9
Subroutine xmm4: not called CC=1 SCAR=6.9
Subroutine xmm5: not called CC=1 SCAR=6.9
Subroutine xmm6: not called CC=1 SCAR=6.9
Subroutine xmm7: not called CC=1 SCAR=6.9
Subroutine xmm8: not called CC=1 SCAR=6.9
Subroutine xmm9: not called CC=1 SCAR=6.9
Subroutine ymm0: not called CC=1 SCAR=6.9
Subroutine ymm1: not called CC=1 SCAR=6.9
Subroutine ymm10: not called CC=1 SCAR=6.9
Subroutine ymm11: not called CC=1 SCAR=6.9
Subroutine ymm12: not called CC=1 SCAR=6.9
Subroutine ymm13: not called CC=1 SCAR=6.9
Subroutine ymm14: not called CC=1 SCAR=6.9
Subroutine ymm15: not called CC=1 SCAR=6.9
Subroutine ymm16: not called CC=1 SCAR=6.9
Subroutine ymm17: not called CC=1 SCAR=6.9
Subroutine ymm18: not called CC=1 SCAR=6.9
Subroutine ymm19: not called CC=1 SCAR=6.9
Subroutine ymm2: not called CC=1 SCAR=6.9
Subroutine ymm20: not called CC=1 SCAR=6.9
Subroutine ymm21: not called CC=1 SCAR=6.9
Subroutine ymm22: not called CC=1 SCAR=6.9
Subroutine ymm23: not called CC=1 SCAR=6.9
Subroutine ymm24: not called CC=1 SCAR=6.9
Subroutine ymm25: not called CC=1 SCAR=6.9
Subroutine ymm26: not called CC=1 SCAR=6.9
Subroutine ymm27: not called CC=1 SCAR=6.9
Subroutine ymm28: not called CC=1 SCAR=6.9
Subroutine ymm29: not called CC=1 SCAR=6.9
Subroutine ymm3: not called CC=1 SCAR=6.9
Subroutine ymm30: not called CC=1 SCAR=6.9
Subroutine ymm31: not called CC=1 SCAR=6.9
Subroutine ymm4: not called CC=1 SCAR=6.9
Subroutine ymm5: not called CC=1 SCAR=6.9
Subroutine ymm6: not called CC=1 SCAR=6.9
Subroutine ymm7: not called CC=1 SCAR=6.9
Subroutine ymm8: not called CC=1 SCAR=6.9
Subroutine ymm9: not called CC=1 SCAR=6.9
Subroutine zmm0: not called CC=1 SCAR=6.9
Subroutine zmm1: not called CC=1 SCAR=6.9
Subroutine zmm10: not called CC=1 SCAR=6.9
Subroutine zmm11: not called CC=1 SCAR=6.9
Subroutine zmm12: not called CC=1 SCAR=6.9
Subroutine zmm13: not called CC=1 SCAR=6.9
Subroutine zmm14: not called CC=1 SCAR=6.9
Subroutine zmm15: not called CC=1 SCAR=6.9
Subroutine zmm16: not called CC=1 SCAR=6.9
Subroutine zmm17: not called CC=1 SCAR=6.9
Subroutine zmm18: not called CC=1 SCAR=6.9
Subroutine zmm19: not called CC=1 SCAR=6.9
Subroutine zmm2: not called CC=1 SCAR=6.9
Subroutine zmm20: not called CC=1 SCAR=6.9
Subroutine zmm21: not called CC=1 SCAR=6.9
Subroutine zmm22: not called CC=1 SCAR=6.9
Subroutine zmm23: not called CC=1 SCAR=6.9
Subroutine zmm24: not called CC=1 SCAR=6.9
Subroutine zmm25: not called CC=1 SCAR=6.9
Subroutine zmm26: not called CC=1 SCAR=6.9
Subroutine zmm27: not called CC=1 SCAR=6.9
Subroutine zmm28: not called CC=1 SCAR=6.9
Subroutine zmm29: not called CC=1 SCAR=6.9
Subroutine zmm3: not called CC=1 SCAR=6.9
Subroutine zmm30: not called CC=1 SCAR=6.9
Subroutine zmm31: not called CC=1 SCAR=6.9
Subroutine zmm4: not called CC=1 SCAR=6.9
Subroutine zmm5: not called CC=1 SCAR=6.9
Subroutine zmm6: not called CC=1 SCAR=6.9
Subroutine zmm7: not called CC=1 SCAR=6.9
Subroutine zmm8: not called CC=1 SCAR=6.9
Subroutine zmm9: not called CC=1 SCAR=6.9
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
154 204 ▶ confess "$s$@ "if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 204 204
155 }
156 204 if (1)
157 204 {my $b = $r{$r}[0] / 8;
158 204 my $s = "sub ${r}Size\{$b}";
159 204 ▶ eval $s;
Subroutine ahSize: not called CC=1 SCAR=6.9
Subroutine alSize: not called CC=1 SCAR=6.9
Subroutine axSize: not called CC=1 SCAR=6.9
Subroutine bhSize: not called CC=1 SCAR=6.9
Subroutine blSize: not called CC=1 SCAR=6.9
Subroutine bpSize: not called CC=1 SCAR=6.9
Subroutine bplSize: not called CC=1 SCAR=6.9
Subroutine bxSize: not called CC=1 SCAR=6.9
Subroutine chSize: not called CC=1 SCAR=6.9
Subroutine clSize: not called CC=1 SCAR=6.9
Subroutine csSize: not called CC=1 SCAR=6.9
Subroutine cxSize: not called CC=1 SCAR=6.9
Subroutine dhSize: not called CC=1 SCAR=6.9
Subroutine diSize: not called CC=1 SCAR=6.9
Subroutine dilSize: not called CC=1 SCAR=6.9
Subroutine dlSize: not called CC=1 SCAR=6.9
Subroutine dsSize: not called CC=1 SCAR=6.9
Subroutine dxSize: not called CC=1 SCAR=6.9
Subroutine eaxSize: not called CC=1 SCAR=6.9
Subroutine ebpSize: not called CC=1 SCAR=6.9
Subroutine ebxSize: not called CC=1 SCAR=6.9
Subroutine ecxSize: not called CC=1 SCAR=6.9
Subroutine ediSize: not called CC=1 SCAR=6.9
Subroutine edxSize: not called CC=1 SCAR=6.9
Subroutine esSize: not called CC=1 SCAR=6.9
Subroutine esiSize: not called CC=1 SCAR=6.9
Subroutine espSize: not called CC=1 SCAR=6.9
Subroutine fsSize: not called CC=1 SCAR=6.9
Subroutine gsSize: not called CC=1 SCAR=6.9
Subroutine k0Size: not called CC=1 SCAR=6.9
Subroutine k1Size: not called CC=1 SCAR=6.9
Subroutine k2Size: not called CC=1 SCAR=6.9
Subroutine k3Size: not called CC=1 SCAR=6.9
Subroutine k4Size: not called CC=1 SCAR=6.9
Subroutine k5Size: not called CC=1 SCAR=6.9
Subroutine k6Size: not called CC=1 SCAR=6.9
Subroutine k7Size: not called CC=1 SCAR=6.9
Subroutine mm0Size: not called CC=1 SCAR=6.9
Subroutine mm1Size: not called CC=1 SCAR=6.9
Subroutine mm2Size: not called CC=1 SCAR=6.9
Subroutine mm3Size: not called CC=1 SCAR=6.9
Subroutine mm4Size: not called CC=1 SCAR=6.9
Subroutine mm5Size: not called CC=1 SCAR=6.9
Subroutine mm6Size: not called CC=1 SCAR=6.9
Subroutine mm7Size: not called CC=1 SCAR=6.9
Subroutine r10Size: not called CC=1 SCAR=6.9
Subroutine r10bSize: not called CC=1 SCAR=6.9
Subroutine r10dSize: not called CC=1 SCAR=6.9
Subroutine r10lSize: not called CC=1 SCAR=6.9
Subroutine r10wSize: not called CC=1 SCAR=6.9
Subroutine r11Size: not called CC=1 SCAR=6.9
Subroutine r11bSize: not called CC=1 SCAR=6.9
Subroutine r11dSize: not called CC=1 SCAR=6.9
Subroutine r11lSize: not called CC=1 SCAR=6.9
Subroutine r11wSize: not called CC=1 SCAR=6.9
Subroutine r12Size: not called CC=1 SCAR=6.9
Subroutine r12bSize: not called CC=1 SCAR=6.9
Subroutine r12dSize: not called CC=1 SCAR=6.9
Subroutine r12lSize: not called CC=1 SCAR=6.9
Subroutine r12wSize: not called CC=1 SCAR=6.9
Subroutine r13Size: not called CC=1 SCAR=6.9
Subroutine r13bSize: not called CC=1 SCAR=6.9
Subroutine r13dSize: not called CC=1 SCAR=6.9
Subroutine r13lSize: not called CC=1 SCAR=6.9
Subroutine r13wSize: not called CC=1 SCAR=6.9
Subroutine r14Size: not called CC=1 SCAR=6.9
Subroutine r14bSize: not called CC=1 SCAR=6.9
Subroutine r14dSize: not called CC=1 SCAR=6.9
Subroutine r14lSize: not called CC=1 SCAR=6.9
Subroutine r14wSize: not called CC=1 SCAR=6.9
Subroutine r15Size: not called CC=1 SCAR=6.9
Subroutine r15bSize: not called CC=1 SCAR=6.9
Subroutine r15dSize: not called CC=1 SCAR=6.9
Subroutine r15lSize: not called CC=1 SCAR=6.9
Subroutine r15wSize: not called CC=1 SCAR=6.9
Subroutine r8Size: not called CC=1 SCAR=6.9
Subroutine r8bSize: not called CC=1 SCAR=6.9
Subroutine r8dSize: not called CC=1 SCAR=6.9
Subroutine r8lSize: not called CC=1 SCAR=6.9
Subroutine r8wSize: not called CC=1 SCAR=6.9
Subroutine r9Size: not called CC=1 SCAR=6.9
Subroutine r9bSize: not called CC=1 SCAR=6.9
Subroutine r9dSize: not called CC=1 SCAR=6.9
Subroutine r9lSize: not called CC=1 SCAR=6.9
Subroutine r9wSize: not called CC=1 SCAR=6.9
Subroutine raxSize: not called CC=1 SCAR=6.9
Subroutine rbpSize: not called CC=1 SCAR=6.9
Subroutine rbxSize: not called CC=1 SCAR=6.9
Subroutine rcxSize: not called CC=1 SCAR=6.9
Subroutine rdiSize: not called CC=1 SCAR=6.9
Subroutine rdxSize: not called CC=1 SCAR=6.9
Subroutine rflagsSize: not called CC=1 SCAR=6.9
Subroutine ripSize: not called CC=1 SCAR=6.9
Subroutine rsiSize: not called CC=1 SCAR=6.9
Subroutine rspSize: not called CC=1 SCAR=6.9
Subroutine siSize: not called CC=1 SCAR=6.9
Subroutine silSize: not called CC=1 SCAR=6.9
Subroutine spSize: not called CC=1 SCAR=6.9
Subroutine splSize: not called CC=1 SCAR=6.9
Subroutine ssSize: not called CC=1 SCAR=6.9
Subroutine st0Size: not called CC=1 SCAR=6.9
Subroutine st1Size: not called CC=1 SCAR=6.9
Subroutine st2Size: not called CC=1 SCAR=6.9
Subroutine st3Size: not called CC=1 SCAR=6.9
Subroutine st4Size: not called CC=1 SCAR=6.9
Subroutine st5Size: not called CC=1 SCAR=6.9
Subroutine st6Size: not called CC=1 SCAR=6.9
Subroutine st7Size: not called CC=1 SCAR=6.9
Subroutine xmm0Size: not called CC=1 SCAR=6.9
Subroutine xmm10Size: not called CC=1 SCAR=6.9
Subroutine xmm11Size: not called CC=1 SCAR=6.9
Subroutine xmm12Size: not called CC=1 SCAR=6.9
Subroutine xmm13Size: not called CC=1 SCAR=6.9
Subroutine xmm14Size: not called CC=1 SCAR=6.9
Subroutine xmm15Size: not called CC=1 SCAR=6.9
Subroutine xmm16Size: not called CC=1 SCAR=6.9
Subroutine xmm17Size: not called CC=1 SCAR=6.9
Subroutine xmm18Size: not called CC=1 SCAR=6.9
Subroutine xmm19Size: not called CC=1 SCAR=6.9
Subroutine xmm1Size: not called CC=1 SCAR=6.9
Subroutine xmm20Size: not called CC=1 SCAR=6.9
Subroutine xmm21Size: not called CC=1 SCAR=6.9
Subroutine xmm22Size: not called CC=1 SCAR=6.9
Subroutine xmm23Size: not called CC=1 SCAR=6.9
Subroutine xmm24Size: not called CC=1 SCAR=6.9
Subroutine xmm25Size: not called CC=1 SCAR=6.9
Subroutine xmm26Size: not called CC=1 SCAR=6.9
Subroutine xmm27Size: not called CC=1 SCAR=6.9
Subroutine xmm28Size: not called CC=1 SCAR=6.9
Subroutine xmm29Size: not called CC=1 SCAR=6.9
Subroutine xmm2Size: not called CC=1 SCAR=6.9
Subroutine xmm30Size: not called CC=1 SCAR=6.9
Subroutine xmm31Size: not called CC=1 SCAR=6.9
Subroutine xmm3Size: not called CC=1 SCAR=6.9
Subroutine xmm4Size: not called CC=1 SCAR=6.9
Subroutine xmm5Size: not called CC=1 SCAR=6.9
Subroutine xmm6Size: not called CC=1 SCAR=6.9
Subroutine xmm7Size: not called CC=1 SCAR=6.9
Subroutine xmm8Size: not called CC=1 SCAR=6.9
Subroutine xmm9Size: not called CC=1 SCAR=6.9
Subroutine ymm0Size: not called CC=1 SCAR=6.9
Subroutine ymm10Size: not called CC=1 SCAR=6.9
Subroutine ymm11Size: not called CC=1 SCAR=6.9
Subroutine ymm12Size: not called CC=1 SCAR=6.9
Subroutine ymm13Size: not called CC=1 SCAR=6.9
Subroutine ymm14Size: not called CC=1 SCAR=6.9
Subroutine ymm15Size: not called CC=1 SCAR=6.9
Subroutine ymm16Size: not called CC=1 SCAR=6.9
Subroutine ymm17Size: not called CC=1 SCAR=6.9
Subroutine ymm18Size: not called CC=1 SCAR=6.9
Subroutine ymm19Size: not called CC=1 SCAR=6.9
Subroutine ymm1Size: not called CC=1 SCAR=6.9
Subroutine ymm20Size: not called CC=1 SCAR=6.9
Subroutine ymm21Size: not called CC=1 SCAR=6.9
Subroutine ymm22Size: not called CC=1 SCAR=6.9
Subroutine ymm23Size: not called CC=1 SCAR=6.9
Subroutine ymm24Size: not called CC=1 SCAR=6.9
Subroutine ymm25Size: not called CC=1 SCAR=6.9
Subroutine ymm26Size: not called CC=1 SCAR=6.9
Subroutine ymm27Size: not called CC=1 SCAR=6.9
Subroutine ymm28Size: not called CC=1 SCAR=6.9
Subroutine ymm29Size: not called CC=1 SCAR=6.9
Subroutine ymm2Size: not called CC=1 SCAR=6.9
Subroutine ymm30Size: not called CC=1 SCAR=6.9
Subroutine ymm31Size: not called CC=1 SCAR=6.9
Subroutine ymm3Size: not called CC=1 SCAR=6.9
Subroutine ymm4Size: not called CC=1 SCAR=6.9
Subroutine ymm5Size: not called CC=1 SCAR=6.9
Subroutine ymm6Size: not called CC=1 SCAR=6.9
Subroutine ymm7Size: not called CC=1 SCAR=6.9
Subroutine ymm8Size: not called CC=1 SCAR=6.9
Subroutine ymm9Size: not called CC=1 SCAR=6.9
Subroutine zmm0Size: not called CC=1 SCAR=6.9
Subroutine zmm10Size: not called CC=1 SCAR=6.9
Subroutine zmm11Size: not called CC=1 SCAR=6.9
Subroutine zmm12Size: not called CC=1 SCAR=6.9
Subroutine zmm13Size: not called CC=1 SCAR=6.9
Subroutine zmm14Size: not called CC=1 SCAR=6.9
Subroutine zmm15Size: not called CC=1 SCAR=6.9
Subroutine zmm16Size: not called CC=1 SCAR=6.9
Subroutine zmm17Size: not called CC=1 SCAR=6.9
Subroutine zmm18Size: not called CC=1 SCAR=6.9
Subroutine zmm19Size: not called CC=1 SCAR=6.9
Subroutine zmm1Size: not called CC=1 SCAR=6.9
Subroutine zmm20Size: not called CC=1 SCAR=6.9
Subroutine zmm21Size: not called CC=1 SCAR=6.9
Subroutine zmm22Size: not called CC=1 SCAR=6.9
Subroutine zmm23Size: not called CC=1 SCAR=6.9
Subroutine zmm24Size: not called CC=1 SCAR=6.9
Subroutine zmm25Size: not called CC=1 SCAR=6.9
Subroutine zmm26Size: not called CC=1 SCAR=6.9
Subroutine zmm27Size: not called CC=1 SCAR=6.9
Subroutine zmm28Size: not called CC=1 SCAR=6.9
Subroutine zmm29Size: not called CC=1 SCAR=6.9
Subroutine zmm2Size: not called CC=1 SCAR=6.9
Subroutine zmm30Size: not called CC=1 SCAR=6.9
Subroutine zmm31Size: not called CC=1 SCAR=6.9
Subroutine zmm3Size: not called CC=1 SCAR=6.9
Subroutine zmm4Size: not called CC=1 SCAR=6.9
Subroutine zmm5Size: not called CC=1 SCAR=6.9
Subroutine zmm6Size: not called CC=1 SCAR=6.9
Subroutine zmm7Size: not called CC=1 SCAR=6.9
Subroutine zmm8Size: not called CC=1 SCAR=6.9
Subroutine zmm9Size: not called CC=1 SCAR=6.9
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
160 204 ▶ confess "$s$@ "if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 204 204
161 }
162 }
163  
164 1 my %v = map {$$_[1]=>1} values %r;
165 1 for my $v(sort keys %v) # Types of register
166 12 {my @r = grep {$r{$_}[1] eq $v} sort keys %r;
167 12 my $s = "sub registers_$v\{".dump(\@r)."}";
168 12 ▶ eval $s;
Subroutine registers_128: not called CC=1 SCAR=5.8
Subroutine registers_16: not called CC=1 SCAR=5.8
Subroutine registers_256: not called CC=1 SCAR=5.8
Subroutine registers_32a: not called CC=1 SCAR=5.8
Subroutine registers_32b: not called CC=1 SCAR=5.8
Subroutine registers_512: not called CC=1 SCAR=5.8
Subroutine registers_64: not called CC=1 SCAR=5.8
Subroutine registers_64m: not called CC=1 SCAR=5.8
Subroutine registers_8: not called CC=1 SCAR=5.8
Subroutine registers_f: not called CC=1 SCAR=5.8
Subroutine registers_m: not called CC=1 SCAR=5.8
Subroutine registers_s: not called CC=1 SCAR=5.8
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
169 12 ▶ confess "$s$@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 12 12
170 }
171  
172 1 if (1) # Instructions that take zero operands
173 1 {my $s = '';
174 1 for my $i(@i0)
175 8 {my $I = ucfirst $i;
176 8 $s .= <<END;
177 sub $I()
178 {\@_ == 0 or confess "No arguments allowed";
179 my \$s = ' ' x scalar(my \@d = caller);
180 push \@text, qq(\${s}$i\\n);
181 }
182 END
183 }
184 1 ▶ eval $s;
Subroutine Cpuid: not called CC=2 SCAR=17.4
Subroutine Lahf: not called CC=2 SCAR=17.4
Subroutine Leave: not called CC=2 SCAR=17.4
Subroutine Popfq: not called CC=2 SCAR=17.4
Subroutine Pushfq: not called CC=2 SCAR=17.4
Subroutine Rdtsc: not called CC=2 SCAR=17.4
Subroutine Ret: not called CC=2 SCAR=17.4
Subroutine Syscall: not called CC=2 SCAR=17.4
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Branch: 8 branches
BranchTrueFalseTotal
@_ == 0 or confess("No arguments allowed") 0 0 0
@_ == 0 or confess("No arguments allowed") 0 0 0
@_ == 0 or confess("No arguments allowed") 0 0 0
@_ == 0 or confess("No arguments allowed") 0 0 0
@_ == 0 or confess("No arguments allowed") 0 0 0
@_ == 0 or confess("No arguments allowed") 0 0 0
@_ == 0 or confess("No arguments allowed") 0 0 0
@_ == 0 or confess("No arguments allowed") 0 0 0
185 1 ▶ confess "$s$@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 1 1
186 }
187  
188 1 if (1) # Instructions that take one operand
189 1 {my $s = '';
190 1 for my $i(@i1)
191 73 {my $I = ucfirst $i;
192 73 $s .= <<END;
193 sub $I(\$)
194 {my (\$target) = \@_;
195 \@_ == 1 or confess "One argument required";
196 my \$s = ' ' x scalar(my \@d = caller);
197 push \@text, qq(\${s}$i \$target\\n);
198 }
199 END
200 }
201 1 ▶ eval $s;
Subroutine Bswap: not called CC=2 SCAR=17.9
Subroutine Call: not called CC=2 SCAR=17.9
Subroutine Dec: not called CC=2 SCAR=17.9
Subroutine Idiv: not called CC=2 SCAR=17.9
Subroutine Inc: not called CC=2 SCAR=17.9
Subroutine Ja: not called CC=2 SCAR=17.9
Subroutine Jae: not called CC=2 SCAR=17.9
Subroutine Jb: not called CC=2 SCAR=17.9
Subroutine Jbe: not called CC=2 SCAR=17.9
Subroutine Jc: not called CC=2 SCAR=17.9
Subroutine Jcxz: not called CC=2 SCAR=17.9
Subroutine Je: not called CC=2 SCAR=17.9
Subroutine Jecxz: not called CC=2 SCAR=17.9
Subroutine Jg: not called CC=2 SCAR=17.9
Subroutine Jge: not called CC=2 SCAR=17.9
Subroutine Jl: not called CC=2 SCAR=17.9
Subroutine Jle: not called CC=2 SCAR=17.9
Subroutine Jmp: not called CC=2 SCAR=17.9
Subroutine Jna: not called CC=2 SCAR=17.9
Subroutine Jnae: not called CC=2 SCAR=17.9
Subroutine Jnb: not called CC=2 SCAR=17.9
Subroutine Jnbe: not called CC=2 SCAR=17.9
Subroutine Jnc: not called CC=2 SCAR=17.9
Subroutine Jne: not called CC=2 SCAR=17.9
Subroutine Jng: not called CC=2 SCAR=17.9
Subroutine Jnge: not called CC=2 SCAR=17.9
Subroutine Jnl: not called CC=2 SCAR=17.9
Subroutine Jnle: not called CC=2 SCAR=17.9
Subroutine Jno: not called CC=2 SCAR=17.9
Subroutine Jnp: not called CC=2 SCAR=17.9
Subroutine Jns: not called CC=2 SCAR=17.9
Subroutine Jnz: not called CC=2 SCAR=17.9
Subroutine Jo: not called CC=2 SCAR=17.9
Subroutine Jp: not called CC=2 SCAR=17.9
Subroutine Jpe: not called CC=2 SCAR=17.9
Subroutine Jpo: not called CC=2 SCAR=17.9
Subroutine Jrcxz: not called CC=2 SCAR=17.9
Subroutine Js: not called CC=2 SCAR=17.9
Subroutine Jz: not called CC=2 SCAR=17.9
Subroutine Loop: not called CC=2 SCAR=17.9
Subroutine Neg: not called CC=2 SCAR=17.9
Subroutine Not: not called CC=2 SCAR=17.9
Subroutine Pop: not called CC=2 SCAR=17.9
Subroutine Push: not called CC=2 SCAR=17.9
Subroutine Seta: not called CC=2 SCAR=17.9
Subroutine Setae: not called CC=2 SCAR=17.9
Subroutine Setb: not called CC=2 SCAR=17.9
Subroutine Setbe: not called CC=2 SCAR=17.9
Subroutine Setc: not called CC=2 SCAR=17.9
Subroutine Sete: not called CC=2 SCAR=17.9
Subroutine Setg: not called CC=2 SCAR=17.9
Subroutine Setge: not called CC=2 SCAR=17.9
Subroutine Setl: not called CC=2 SCAR=17.9
Subroutine Setle: not called CC=2 SCAR=17.9
Subroutine Setna: not called CC=2 SCAR=17.9
Subroutine Setnae: not called CC=2 SCAR=17.9
Subroutine Setnb: not called CC=2 SCAR=17.9
Subroutine Setnbe: not called CC=2 SCAR=17.9
Subroutine Setnc: not called CC=2 SCAR=17.9
Subroutine Setne: not called CC=2 SCAR=17.9
Subroutine Setng: not called CC=2 SCAR=17.9
Subroutine Setnge: not called CC=2 SCAR=17.9
Subroutine Setnl: not called CC=2 SCAR=17.9
Subroutine Setno: not called CC=2 SCAR=17.9
Subroutine Setnp: not called CC=2 SCAR=17.9
Subroutine Setns: not called CC=2 SCAR=17.9
Subroutine Setnz: not called CC=2 SCAR=17.9
Subroutine Seto: not called CC=2 SCAR=17.9
Subroutine Setp: not called CC=2 SCAR=17.9
Subroutine Setpe: not called CC=2 SCAR=17.9
Subroutine Setpo: not called CC=2 SCAR=17.9
Subroutine Sets: not called CC=2 SCAR=17.9
Subroutine Setz: not called CC=2 SCAR=17.9
Pod undocumented
Pod documented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod documented
Pod documented
Pod documented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Branch: 73 branches
BranchTrueFalseTotal
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
@_ == 1 or confess("One argument required") 0 0 0
202 1 ▶ confess "$s$@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 1 1
203 }
204  
205 1 if (1) # Instructions that take two operands
206 1 {my $s = '';
207 1 for my $i(@i2)
208 74 {my $I = ucfirst $i;
209 74 $s .= <<END;
210 sub $I(\$\$)
211 {my (\$target, \$source) = \@_;
212 \@_ == 2 or confess "Two arguments required";
213 #TEST Keep(\$target) if "$i" =~ m(\\Amov\\Z) and \$Registers{\$target};
214 #TEST KeepSet(\$source) if "$i" =~ m(\\Amov\\Z) and \$Registers{\$source};
215 my \$s = ' ' x scalar(my \@d = caller);
216 push \@text, qq(\${s}$i \$target, \$source\\n);
217 }
218 END
219 }
220 1 ▶ eval $s;
Subroutine Add: not called CC=2 SCAR=17.9
Subroutine And: not called CC=2 SCAR=17.9
Subroutine Bt: not called CC=2 SCAR=17.9
Subroutine Btc: not called CC=2 SCAR=17.9
Subroutine Btr: not called CC=2 SCAR=17.9
Subroutine Bts: not called CC=2 SCAR=17.9
Subroutine Cmova: not called CC=2 SCAR=17.9
Subroutine Cmovae: not called CC=2 SCAR=17.9
Subroutine Cmovb: not called CC=2 SCAR=17.9
Subroutine Cmovbe: not called CC=2 SCAR=17.9
Subroutine Cmovc: not called CC=2 SCAR=17.9
Subroutine Cmove: not called CC=2 SCAR=17.9
Subroutine Cmovg: not called CC=2 SCAR=17.9
Subroutine Cmovge: not called CC=2 SCAR=17.9
Subroutine Cmovl: not called CC=2 SCAR=17.9
Subroutine Cmovle: not called CC=2 SCAR=17.9
Subroutine Cmovna: not called CC=2 SCAR=17.9
Subroutine Cmovnae: not called CC=2 SCAR=17.9
Subroutine Cmovnb: not called CC=2 SCAR=17.9
Subroutine Cmp: not called CC=2 SCAR=17.9
Subroutine Enter: not called CC=2 SCAR=17.9
Subroutine Imul: not called CC=2 SCAR=17.9
Subroutine Kmovb: not called CC=2 SCAR=17.9
Subroutine Kmovd: not called CC=2 SCAR=17.9
Subroutine Kmovq: not called CC=2 SCAR=17.9
Subroutine Kmovw: not called CC=2 SCAR=17.9
Subroutine Knotb: not called CC=2 SCAR=17.9
Subroutine Knotd: not called CC=2 SCAR=17.9
Subroutine Knotq: not called CC=2 SCAR=17.9
Subroutine Knotw: not called CC=2 SCAR=17.9
Subroutine Kortestb: not called CC=2 SCAR=17.9
Subroutine Kortestd: not called CC=2 SCAR=17.9
Subroutine Kortestq: not called CC=2 SCAR=17.9
Subroutine Kortestw: not called CC=2 SCAR=17.9
Subroutine Ktestb: not called CC=2 SCAR=17.9
Subroutine Ktestd: not called CC=2 SCAR=17.9
Subroutine Ktestq: not called CC=2 SCAR=17.9
Subroutine Ktestw: not called CC=2 SCAR=17.9
Subroutine Lea: not called CC=2 SCAR=17.9
Subroutine Lzcnt: not called CC=2 SCAR=17.9
Subroutine Mov: not called CC=2 SCAR=17.9
Subroutine Movdqa: not called CC=2 SCAR=17.9
Subroutine Mulpd: not called CC=2 SCAR=17.9
Subroutine Or: not called CC=2 SCAR=17.9
Subroutine Popcnt: not called CC=2 SCAR=17.9
Subroutine Pslldq: not called CC=2 SCAR=17.9
Subroutine Psrldq: not called CC=2 SCAR=17.9
Subroutine Shl: not called CC=2 SCAR=17.9
Subroutine Shr: not called CC=2 SCAR=17.9
Subroutine Sub: not called CC=2 SCAR=17.9
Subroutine Test: not called CC=2 SCAR=17.9
Subroutine Tzcnt: not called CC=2 SCAR=17.9
Subroutine Vcvtudq2pd: not called CC=2 SCAR=17.9
Subroutine Vcvtudq2ps: not called CC=2 SCAR=17.9
Subroutine Vcvtuqq2pd: not called CC=2 SCAR=17.9
Subroutine Vmovd: not called CC=2 SCAR=17.9
Subroutine Vmovdqa32: not called CC=2 SCAR=17.9
Subroutine Vmovdqa64: not called CC=2 SCAR=17.9
Subroutine Vmovdqu: not called CC=2 SCAR=17.9
Subroutine Vmovdqu32: not called CC=2 SCAR=17.9
Subroutine Vmovdqu64: not called CC=2 SCAR=17.9
Subroutine Vmovdqu8: not called CC=2 SCAR=17.9
Subroutine Vmovq: not called CC=2 SCAR=17.9
Subroutine Vpbroadcastb: not called CC=2 SCAR=17.9
Subroutine Vpbroadcastd: not called CC=2 SCAR=17.9
Subroutine Vpbroadcastq: not called CC=2 SCAR=17.9
Subroutine Vpbroadcastw: not called CC=2 SCAR=17.9
Subroutine Vpcompressd: not called CC=2 SCAR=17.9
Subroutine Vpcompressq: not called CC=2 SCAR=17.9
Subroutine Vpexpandd: not called CC=2 SCAR=17.9
Subroutine Vpexpandq: not called CC=2 SCAR=17.9
Subroutine Vsqrtpd: not called CC=2 SCAR=17.9
Subroutine Xchg: not called CC=2 SCAR=17.9
Subroutine Xor: not called CC=2 SCAR=17.9
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod documented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Branch: 74 branches
BranchTrueFalseTotal
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
@_ == 2 or confess("Two arguments required") 0 0 0
221 1 ▶ confess "$s$@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 1 1
222 }
223  
224 1 if (1) # Instructions that take three operands
225 1 {my $s = '';
226 1 for my $i(@i3)
227 100 {my $I = ucfirst $i;
228 100 $s .= <<END;
229 sub $I(\$\$\$)
230 {my (\$target, \$source, \$bits) = \@_;
231 \@_ == 3 or confess "Three arguments required";
232 my \$s = ' ' x scalar(my \@d = caller);
233 push \@text, qq(\${s}$i \$target, \$source, \$bits\\n);
234 }
235 END
236 }
237 1 ▶ eval "$s$@";
Subroutine Andn: not called CC=2 SCAR=17.9
Subroutine Bzhi: not called CC=2 SCAR=17.9
Subroutine Kaddb: not called CC=2 SCAR=17.9
Subroutine Kaddd: not called CC=2 SCAR=17.9
Subroutine Kaddq: not called CC=2 SCAR=17.9
Subroutine Kaddw: not called CC=2 SCAR=17.9
Subroutine Kandb: not called CC=2 SCAR=17.9
Subroutine Kandd: not called CC=2 SCAR=17.9
Subroutine Kandnb: not called CC=2 SCAR=17.9
Subroutine Kandnd: not called CC=2 SCAR=17.9
Subroutine Kandnq: not called CC=2 SCAR=17.9
Subroutine Kandnw: not called CC=2 SCAR=17.9
Subroutine Kandq: not called CC=2 SCAR=17.9
Subroutine Kandw: not called CC=2 SCAR=17.9
Subroutine Korb: not called CC=2 SCAR=17.9
Subroutine Kord: not called CC=2 SCAR=17.9
Subroutine Korq: not called CC=2 SCAR=17.9
Subroutine Korw: not called CC=2 SCAR=17.9
Subroutine Kshiftlb: not called CC=2 SCAR=17.9
Subroutine Kshiftld: not called CC=2 SCAR=17.9
Subroutine Kshiftlq: not called CC=2 SCAR=17.9
Subroutine Kshiftlw: not called CC=2 SCAR=17.9
Subroutine Kshiftrb: not called CC=2 SCAR=17.9
Subroutine Kshiftrd: not called CC=2 SCAR=17.9
Subroutine Kshiftrq: not called CC=2 SCAR=17.9
Subroutine Kshiftrw: not called CC=2 SCAR=17.9
Subroutine Kunpckb: not called CC=2 SCAR=17.9
Subroutine Kunpckd: not called CC=2 SCAR=17.9
Subroutine Kunpckq: not called CC=2 SCAR=17.9
Subroutine Kunpckw: not called CC=2 SCAR=17.9
Subroutine Kxnorb: not called CC=2 SCAR=17.9
Subroutine Kxnord: not called CC=2 SCAR=17.9
Subroutine Kxnorq: not called CC=2 SCAR=17.9
Subroutine Kxnorw: not called CC=2 SCAR=17.9
Subroutine Kxorb: not called CC=2 SCAR=17.9
Subroutine Kxord: not called CC=2 SCAR=17.9
Subroutine Kxorq: not called CC=2 SCAR=17.9
Subroutine Kxorw: not called CC=2 SCAR=17.9
Subroutine Pextrb: not called CC=2 SCAR=17.9
Subroutine Pextrd: not called CC=2 SCAR=17.9
Subroutine Pextrq: not called CC=2 SCAR=17.9
Subroutine Pextrw: not called CC=2 SCAR=17.9
Subroutine Pinsrb: not called CC=2 SCAR=17.9
Subroutine Pinsrd: not called CC=2 SCAR=17.9
Subroutine Pinsrq: not called CC=2 SCAR=17.9
Subroutine Pinsrw: not called CC=2 SCAR=17.9
Subroutine Vaddd: not called CC=2 SCAR=17.9
Subroutine Vaddpd: not called CC=2 SCAR=17.9
Subroutine Vdpps: not called CC=2 SCAR=17.9
Subroutine Vgetmantps: not called CC=2 SCAR=17.9
Subroutine Vmulpd: not called CC=2 SCAR=17.9
Subroutine Vpaddb: not called CC=2 SCAR=17.9
Subroutine Vpaddd: not called CC=2 SCAR=17.9
Subroutine Vpaddq: not called CC=2 SCAR=17.9
Subroutine Vpaddw: not called CC=2 SCAR=17.9
Subroutine Vpandb: not called CC=2 SCAR=17.9
Subroutine Vpandd: not called CC=2 SCAR=17.9
Subroutine Vpandnb: not called CC=2 SCAR=17.9
Subroutine Vpandnd: not called CC=2 SCAR=17.9
Subroutine Vpandnq: not called CC=2 SCAR=17.9
Subroutine Vpandnw: not called CC=2 SCAR=17.9
Subroutine Vpandq: not called CC=2 SCAR=17.9
Subroutine Vpandw: not called CC=2 SCAR=17.9
Subroutine Vpcmpeqb: not called CC=2 SCAR=17.9
Subroutine Vpcmpeqd: not called CC=2 SCAR=17.9
Subroutine Vpcmpeqq: not called CC=2 SCAR=17.9
Subroutine Vpcmpeqw: not called CC=2 SCAR=17.9
Subroutine Vpextrb: not called CC=2 SCAR=17.9
Subroutine Vpextrd: not called CC=2 SCAR=17.9
Subroutine Vpextrq: not called CC=2 SCAR=17.9
Subroutine Vpextrw: not called CC=2 SCAR=17.9
Subroutine Vpinsrb: not called CC=2 SCAR=17.9
Subroutine Vpinsrd: not called CC=2 SCAR=17.9
Subroutine Vpinsrq: not called CC=2 SCAR=17.9
Subroutine Vpinsrw: not called CC=2 SCAR=17.9
Subroutine Vpmullb: not called CC=2 SCAR=17.9
Subroutine Vpmulld: not called CC=2 SCAR=17.9
Subroutine Vpmullq: not called CC=2 SCAR=17.9
Subroutine Vpmullw: not called CC=2 SCAR=17.9
Subroutine Vporb: not called CC=2 SCAR=17.9
Subroutine Vpord: not called CC=2 SCAR=17.9
Subroutine Vporq: not called CC=2 SCAR=17.9
Subroutine Vporvpcmpeqb: not called CC=2 SCAR=17.9
Subroutine Vporvpcmpeqd: not called CC=2 SCAR=17.9
Subroutine Vporvpcmpeqq: not called CC=2 SCAR=17.9
Subroutine Vporvpcmpeqw: not called CC=2 SCAR=17.9
Subroutine Vporw: not called CC=2 SCAR=17.9
Subroutine Vprolq: not called CC=2 SCAR=17.9
Subroutine Vpsubb: not called CC=2 SCAR=17.9
Subroutine Vpsubd: not called CC=2 SCAR=17.9
Subroutine Vpsubq: not called CC=2 SCAR=17.9
Subroutine Vpsubw: not called CC=2 SCAR=17.9
Subroutine Vptestb: not called CC=2 SCAR=17.9
Subroutine Vptestd: not called CC=2 SCAR=17.9
Subroutine Vptestq: not called CC=2 SCAR=17.9
Subroutine Vptestw: not called CC=2 SCAR=17.9
Subroutine Vpxorb: not called CC=2 SCAR=17.9
Subroutine Vpxord: not called CC=2 SCAR=17.9
Subroutine Vpxorq: not called CC=2 SCAR=17.9
Subroutine Vpxorw: not called CC=2 SCAR=17.9
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Branch: 100 branches
BranchTrueFalseTotal
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
@_ == 3 or confess("Three arguments required") 0 0 0
238 1 ▶ confess $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 1 1
239 }
240  
241 1 if (1) # Instructions that take four operands
242 1 {my $s = '';
243 1 for my $i(@i4)
244 4 {my $I = ucfirst $i;
245 4 $s .= <<END;
246 sub $I(\$\$\$\$)
247 {my (\$target, \$source, \$bits, \$zero) = \@_;
248 \@_ == 4 or confess "Four arguments required";
249 my \$s = ' ' x scalar(my \@d = caller);
250 push \@text, qq(\${s}$i \$target, \$source, \$bits, \$zero\\n);
251 }
252 END
253 }
254 1 ▶ eval "$s$@";
Subroutine Vpcmpub: not called CC=2 SCAR=17.1
Subroutine Vpcmpud: not called CC=2 SCAR=17.1
Subroutine Vpcmpuq: not called CC=2 SCAR=17.1
Subroutine Vpcmpuw: not called CC=2 SCAR=17.1
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Branch: 4 branches
BranchTrueFalseTotal
@_ == 4 or confess("Four arguments required") 0 0 0
@_ == 4 or confess("Four arguments required") 0 0 0
@_ == 4 or confess("Four arguments required") 0 0 0
@_ == 4 or confess("Four arguments required") 0 0 0
255 1 ▶ confess $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 1 1
256 }
257 }
258  
259 sub ClearRegisters(@); # Clear registers by setting them to zero.
260 sub Comment(@); # Insert a comment into the assembly code.
261 sub DComment(@); # Insert a comment into the data section.
262 sub RComment(@); # Insert a comment into the read only data section.
263 sub PeekR($); # Peek at the register on top of the stack.
264 sub PopR(@); # Pop a list of registers off the stack.
265 sub PopRR(@); # Pop a list of registers off the stack without tracking.
266 sub PrintErrStringNL(@); # Print a constant string followed by a new line to stderr.
267 sub PrintOutMemory; # Print the memory addressed by rax for a length of rdi.
268 sub PrintOutRegisterInHex(@); # Print any register as a hex string.
269 sub PrintOutStringNL(@); # Print a constant string to stdout followed by new line.
270 sub PrintString($@); # Print a constant string to the specified channel.
271 sub PushR(@); # Push a list of registers onto the stack.
272 sub PushRR(@); # Push a list of registers onto the stack without tracking.
273 sub Syscall(); # System call in linux 64 format.
274  
275 #D1 Data # Layout data
276  
277 1 my $Labels = 0;
278  
279 sub Label(;$) #P Create a unique label or reuse the one supplied.
280 0 ▶ {return "l".++$Labels unless @_; # Generate a label
Subroutine Label: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
281 0 $_[0]; # Use supplied label
282 }
283  
284 sub SetLabel(;$) # Create (if necessary) and set a label in the code section returning the label so set.
285 0 ▶ {my ($l) = @_; # Label
Subroutine SetLabel: not called CC=2 SCAR=17.9
Pod documented
286 0 ▶ $l //= Label;
Condition0%0/3
$l //= &Label()
l!l&&r!l&&!r
000
MC/DC0%0/2
$l //= &Label()
$l &Label()
Truth table0%0/3
A //= B
A= $lB= &Label()
ABresult
1X1
011
000
287 0 push @text, <<END; # Define bytes
288 $l:
289 END
290 0 $l # Return label name
291 }
292  
293 sub Ds(@) # Layout bytes in memory and return their label.
294 0 ▶ {my (@d) = @_; # Data to be laid out
Subroutine Ds: not called CC=1 SCAR=6.9
Pod documented
295 0 my $d = join '', @_;
296 0 $d =~ s(') (\')gs;
297 0 my $l = Label;
298 0 push @data, <<END; # Define bytes
299 $l: db '$d';
300 END
301 0 $l # Return label
302 }
303  
304 sub Rs(@) # Layout bytes in read only memory and return their label.
305 0 ▶ {my (@d) = @_; # Data to be laid out
Subroutine Rs: not called CC=4 SCAR=30.0
Pod documented
306 0 my $d = join '', @_;
307 0 my @e;
308 0 for my $e(split //, $d)
309 0 ▶ {if ($e !~ m([A-Z0-9])i) {push @e, sprintf("0x%x", ord($e))} else {push @e, qq('$e')}
Branch: 1 branch
BranchTrueFalseTotal
if (not $e =~ /[A-Z0-9]/i) { } 0 0 0
310 }
311 0 my $e = join ', ', @e;
312 0 my $L = $rodatas{$e};
313 0 ▶ return $L if defined $L; # Data already exists so return it
Branch: 1 branch
BranchTrueFalseTotal
if defined $L 0 0 0
314 0 my $l = Label; # New label for new data
315 0 $rodatas{$e} = $l; # Record label
316 0 push @rodata, <<END; # Define bytes
317 $l: db $e, 0;
318 END
319 0 $l # Return label
320 }
321  
322 sub Rutf8(@) # Layout a utf8 encoded string as bytes in read only memory and return their label.
323 0 ▶ {my (@d) = @_; # Data to be laid out
Subroutine Rutf8: not called CC=7 SCAR=40.3
Pod documented
324 0 ▶ confess unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
325 0 my $d = join '', @_;
326 0 my @e;
327 0 for my $e(split //, $d)
328 0 {my $o = ord $e; # Effectively the utf32 encoding of each character
329 0 my $u = convertUtf32ToUtf8($o);
330 0 my $x = sprintf("%08x", $u);
331 0 my $o1 = substr($x, 0, 2);
332 0 my $o2 = substr($x, 2, 2);
333 0 my $o3 = substr($x, 4, 2);
334 0 my $o4 = substr($x, 6, 2);
335 0 ▶ if ($o <= (1 << 7)) {push @e, $o4}
Branch: 3 branches
BranchTrueFalseTotal
if ($o <= 128) { } 0 0 0
elsif ($o <= 2048) { } 0 0 0
elsif ($o <= 65536) { } 0 0 0
336 0 elsif ($o <= (1 << 11)) {push @e, $o3, $o4}
337 0 elsif ($o <= (1 << 16)) {push @e, $o2, $o3, $o4}
338 0 else {push @e, $o1, $o2, $o3, $o4}
339 }
340  
341 0 my $e = join ', ',map {"0x$_"} @e;
342 0 my $L = $rodatas{$e};
343 0 ▶ return $L if defined $L; # Data already exists so return it
Branch: 1 branch
BranchTrueFalseTotal
if defined $L 0 0 0
344 0 my $l = Label; # New label for new data
345 0 $rodatas{$e} = $l; # Record label
346 0 push @rodata, <<END; # Define bytes
347 $l: db $e, 0;
348 END
349 0 $l # Return label
350 }
351  
352 sub Dbwdq($@) #P Layout data.
353 0 ▶ {my ($s, @d) = @_; # Element size, data to be laid out
Subroutine Dbwdq: not called CC=1 SCAR=6.9
Pod documented
354 0 my $d = join ', ', @d;
355 0 my $l = Label;
356 0 push @data, <<END;
357 $l: d$s $d
358 END
359 0 $l # Return label
360 }
361  
362 sub Db(@) # Layout bytes in the data segment and return their label.
363 0 ▶ {my (@bytes) = @_; # Bytes to layout
Subroutine Db: not called CC=1 SCAR=6.9
Pod documented
364 0 Dbwdq 'b', @_;
365 }
366 sub Dw(@) # Layout words in the data segment and return their label.
367 0 ▶ {my (@words) = @_; # Words to layout
Subroutine Dw: not called CC=1 SCAR=6.9
Pod documented
368 0 Dbwdq 'w', @_;
369 }
370 sub Dd(@) # Layout double words in the data segment and return their label.
371 0 ▶ {my (@dwords) = @_; # Double words to layout
Subroutine Dd: not called CC=1 SCAR=6.9
Pod documented
372 0 Dbwdq 'd', @_;
373 }
374 sub Dq(@) # Layout quad words in the data segment and return their label.
375 0 ▶ {my (@qwords) = @_; # Quad words to layout
Subroutine Dq: not called CC=1 SCAR=6.9
Pod documented
376 0 Dbwdq 'q', @_;
377 }
378  
379 sub Rbwdq($@) #P Layout data.
380 0 ▶ {my ($s, @d) = @_; # Element size, data to be laid out
Subroutine Rbwdq: not called CC=3 SCAR=24.8
Pod documented
381 0 ▶ my $d = join ', ', map {$_ =~ m(\A\d+\Z) ? sprintf "0x%x", $_ : $_} @d; # Data to be laid out
Branch: 1 branch
BranchTrueFalseTotal
$_ =~ /\A\d+\Z/ ? : 0 0 0
382 0 ▶ if (my $c = $rodata{$s}{$d}) # Data already exists so return it
Branch: 1 branch
BranchTrueFalseTotal
if (my $c = $rodata{$s}{$d}) 0 0 0
383 0 {return $c
384 }
385 0 my $l = Label; # New data - create a label
386 0 push @rodata, <<END; # Save in read only data
387 $l: d$s $d
388 END
389 0 $rodata{$s}{$d} = $l; # Record label
390 0 $l # Return label
391 }
392  
393 sub Rb(@) # Layout bytes in the data segment and return their label.
394 0 ▶ {my (@bytes) = @_; # Bytes to layout
Subroutine Rb: not called CC=1 SCAR=6.9
Pod documented
395 0 Rbwdq 'b', @_;
396 }
397 sub Rw(@) # Layout words in the data segment and return their label.
398 0 ▶ {my (@words) = @_; # Words to layout
Subroutine Rw: not called CC=1 SCAR=6.9
Pod documented
399 0 Rbwdq 'w', @_;
400 }
401 sub Rd(@) # Layout double words in the data segment and return their label.
402 0 ▶ {my (@dwords) = @_; # Double words to layout
Subroutine Rd: not called CC=1 SCAR=6.9
Pod documented
403 0 Rbwdq 'd', @_;
404 }
405 sub Rq(@) # Layout quad words in the data segment and return their label.
406 0 ▶ {my (@qwords) = @_; # Quad words to layout
Subroutine Rq: not called CC=1 SCAR=6.9
Pod documented
407 0 Rbwdq 'q', @_;
408 }
409  
410 1 my $Pi = "3.141592653589793238462";
411  
412 0 ▶sub Pi32 {Rd("__float32__($Pi)")} #P Pi as a 32 bit float.
Subroutine Pi32: not called CC=1 SCAR=6.9
Pod documented
413 0 ▶sub Pi64 {Rq("__float32__($Pi)")} #P Pi as a 64 bit float.
Subroutine Pi64: not called CC=1 SCAR=6.9
Pod documented
414  
415 #D1 Registers # Operations on registers
416  
417 sub xmm(@) # Add xmm to the front of a list of register expressions.
418 0 ▶ {my (@r) = @_; # Register numbers
Subroutine xmm: not called CC=1 SCAR=6.9
Pod documented
419 0 map {"xmm$_"} @_;
420 }
421  
422 sub ymm(@) # Add ymm to the front of a list of register expressions.
423 0 ▶ {my (@r) = @_; # Register numbers
Subroutine ymm: not called CC=1 SCAR=6.9
Pod documented
424 0 map {"ymm$_"} @_;
425 }
426  
427 sub zmm(@) # Add zmm to the front of a list of register expressions.
428 0 ▶ {my (@r) = @_; # Register numbers
Subroutine zmm: not called CC=1 SCAR=6.9
Pod documented
429 0 map {"zmm$_"} @_;
430 }
431  
432 sub ChooseRegisters($@) # Choose the specified numbers of registers excluding those on the specified list.
433 0 ▶ {my ($number, @registers) = @_; # Number of registers needed, Registers not to choose
Subroutine ChooseRegisters: not called CC=3 SCAR=24.8
Pod documented
434 0 my %r = (map {$_=>1} map {"r$_"} 8..15);
435 0 delete $r{$_} for @registers;
436 0 ▶ $number <= keys %r or confess "Not enough registers available";
Branch: 1 branch
BranchTrueFalseTotal
$number <= keys %r or confess("Not enough registers available") 0 0 0
437 0 sort keys %r
438 }
439  
440 sub RegistersAvailable(@) # Add a new set of registers that are available.
441 0 ▶ {my (@reg) = @_; # Registers known to be available at the moment
Subroutine RegistersAvailable: not called CC=1 SCAR=6.9
Pod documented
442 0 my %r = map {$_=>1} @reg;
443 0 push @RegistersAvailable, \%r;
444 }
445  
446 sub RegistersFree # Remove the current set of registers known to be free.
447 0 ▶ {@RegistersAvailable or confess "No registers to free";
Subroutine RegistersFree: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@RegistersAvailable or confess("No registers to free") 0 0 0
448 0 pop @RegistersAvailable;
449 }
450  
451 sub CheckGeneralPurposeRegister($) # Check that a register is in fact a general purpose register.
452 0 ▶ {my ($reg) = @_; # Mask register to check
Subroutine CheckGeneralPurposeRegister: not called CC=4 SCAR=30.0
Pod documented
453 0 ▶ @_ == 1 or confess "One parameter";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess("One parameter") 0 0 0
454 0 ▶ $Registers{$reg} && $reg =~ m(\Ar) or
Branch: 1 branch
BranchTrueFalseTotal
$Registers{$reg} and $reg =~ /\Ar/ or confess("Not a general purpose register: $reg") 0 0 0
Condition0%0/3
$Registers{$reg} and $reg =~ /\Ar/
!ll&&!rl&&r
000
MC/DC0%0/2
$Registers{$reg} and $reg =~ /\Ar/
$Registers{$reg} $reg =~ /\Ar/
Truth table0%0/3
A and B
A= $Registers{$reg}B= $reg =~ /\Ar/
ABresult
0X0
100
111
455 confess "Not a general purpose register: $reg";
456 }
457  
458 sub CheckNumberedGeneralPurposeRegister($) # Check that a register is in fact a numbered general purpose register.
459 0 ▶ {my ($reg) = @_; # Mask register to check
Subroutine CheckNumberedGeneralPurposeRegister: not called CC=4 SCAR=30.0
Pod documented
460 0 ▶ @_ == 1 or confess "One parameter";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess("One parameter") 0 0 0
461 0 ▶ $Registers{$reg} && $reg =~ m(\Ar\d+) or
Branch: 1 branch
BranchTrueFalseTotal
$Registers{$reg} and $reg =~ /\Ar\d+/ or confess("Not a numbered general purpose register: $reg") 0 0 0
Condition0%0/3
$Registers{$reg} and $reg =~ /\Ar\d+/
!ll&&!rl&&r
000
MC/DC0%0/2
$Registers{$reg} and $reg =~ /\Ar\d+/
$Registers{$reg} $reg =~ /\Ar\d+/
Truth table0%0/3
A and B
A= $Registers{$reg}B= $reg =~ /\Ar\d+/
ABresult
0X0
100
111
462 confess "Not a numbered general purpose register: $reg";
463 }
464  
465 sub InsertZeroIntoRegisterAtPoint($$) # Insert a zero into the specified register at the point indicated by another register.
466 0 ▶ {my ($point, $in) = @_; # Register with a single 1 at the insertion point, register to be inserted into.
Subroutine InsertZeroIntoRegisterAtPoint: not called CC=1 SCAR=6.9
Pod documented
467  
468 0 PushR my @s = my ($mask, $low, $high) = ChooseRegisters(3, $in, $point); # Choose three work registers and push them
469 0 Mov $mask, $point;
470 0 Sub $mask, 1;
471 0 Andn $high, $mask, $in;
472 0 Shl $high, 1;
473 0 Mov $low, $in;
474 0 And $low, $mask;
475 0 Or $low, $high;
476 0 Mov $in, $low;
477 0 PopR @s; # Restore stack
478 }
479  
480 sub InsertOneIntoRegisterAtPoint($$) # Insert a one into the specified register at the point indicated by another register.
481 0 ▶ {my ($point, $in) = @_; # Register with a single 1 at the insertion point, register to be inserted into.
Subroutine InsertOneIntoRegisterAtPoint: not called CC=1 SCAR=6.9
Pod documented
482 0 InsertZeroIntoRegisterAtPoint($point, $in); # Insert a zero
483 0 Or $in, $point; # Make the zero a one
484 }
485  
486 sub LoadZmm($@) # Load a numbered zmm with the specified bytes.
487 0 ▶ {my ($zmm, @bytes) = @_; # Numbered zmm, bytes
Subroutine LoadZmm: not called CC=1 SCAR=6.9
Pod documented
488 0 my $b = Rb(@bytes);
489 0 Vmovdqu8 "zmm$zmm", "[$b]";
490 }
491  
492 #D2 Save and Restore # Saving and restoring registers via the stack
493  
494 1 my @syscallSequence = qw(rax rdi rsi rdx r10 r8 r9); # The parameter list sequence for system calls
495  
496 sub SaveFirstFour(@) # Save the first 4 parameter registers making any parameter registers read only.
497 0 ▶ {my (@keep) = @_; # Registers to mark as read only
Subroutine SaveFirstFour: not called CC=2 SCAR=17.9
Pod documented
498 0 my $N = 4;
499 0 PushRR $_ for @syscallSequence[0..$N-1];
500 0 $N * &RegisterSize(rax); # Space occupied by push
501 }
502  
503 sub RestoreFirstFour() # Restore the first 4 parameter registers.
504 0 ▶ {my $N = 4;
Subroutine RestoreFirstFour: not called CC=2 SCAR=17.9
Pod documented
505 0 PopRR $_ for reverse @syscallSequence[0..$N-1];
506 }
507  
508 sub RestoreFirstFourExceptRax() # Restore the first 4 parameter registers except rax so it can return its value.
509 0 ▶ {my $N = 4;
Subroutine RestoreFirstFourExceptRax: not called CC=2 SCAR=17.9
Pod documented
510 0 PopRR $_ for reverse @syscallSequence[1..$N-1];
511 0 Add rsp, 1*RegisterSize(rax);
512 }
513  
514 sub RestoreFirstFourExceptRaxAndRdi() # Restore the first 4 parameter registers except rax and rdi so we can return a pair of values.
515 0 ▶ {my $N = 4;
Subroutine RestoreFirstFourExceptRaxAndRdi: not called CC=2 SCAR=17.9
Pod documented
516 0 PopRR $_ for reverse @syscallSequence[2..$N-1];
517 0 Add rsp, 2*RegisterSize(rax);
518 }
519  
520 sub SaveFirstSeven() # Save the first 7 parameter registers.
521 0 ▶ {my $N = 7;
Subroutine SaveFirstSeven: not called CC=2 SCAR=17.9
Pod documented
522 0 PushRR $_ for @syscallSequence[0..$N-1];
523 0 $N * 1*RegisterSize(rax); # Space occupied by push
524 }
525  
526 sub RestoreFirstSeven() # Restore the first 7 parameter registers.
527 0 ▶ {my $N = 7;
Subroutine RestoreFirstSeven: not called CC=2 SCAR=17.9
Pod documented
528 0 PopRR $_ for reverse @syscallSequence[0..$N-1];
529 }
530  
531 sub RestoreFirstSevenExceptRax() # Restore the first 7 parameter registers except rax which is being used to return the result.
532 0 ▶ {my $N = 7;
Subroutine RestoreFirstSevenExceptRax: not called CC=2 SCAR=17.9
Pod documented
533 0 PopRR $_ for reverse @syscallSequence[1..$N-1];
534 0 Add rsp, 1*RegisterSize(rax);
535 }
536  
537 sub RestoreFirstSevenExceptRaxAndRdi() # Restore the first 7 parameter registers except rax and rdi which are being used to return the results.
538 0 ▶ {my $N = 7;
Subroutine RestoreFirstSevenExceptRaxAndRdi: not called CC=2 SCAR=17.9
Pod documented
539 0 PopRR $_ for reverse @syscallSequence[2..$N-1];
540 0 Add rsp, 2*RegisterSize(rax); # Skip rdi and rax
541 }
542  
543 sub ReorderSyscallRegisters(@) # Map the list of registers provided to the 64 bit system call sequence.
544 0 ▶ {my (@registers) = @_; # Registers
Subroutine ReorderSyscallRegisters: not called CC=1 SCAR=6.9
Pod documented
545 0 PushRR @syscallSequence[0..$#registers];
546 0 PushRR @registers;
547 0 PopRR @syscallSequence[0..$#registers];
548 }
549  
550 sub UnReorderSyscallRegisters(@) # Recover the initial values in registers that were reordered.
551 0 ▶ {my (@registers) = @_; # Registers
Subroutine UnReorderSyscallRegisters: not called CC=1 SCAR=6.9
Pod documented
552 0 PopRR @syscallSequence[0..$#registers];
553 }
554  
555 sub RegisterSize($) # Return the size of a register.
556 0 ▶ {my ($r) = @_; # Register
Subroutine RegisterSize: not called CC=3 SCAR=24.8
Pod documented
557 0 ▶ defined($r) or confess;
Branch: 1 branch
BranchTrueFalseTotal
defined $r or confess() 0 0 0
558 0 ▶ defined($Registers{$r}) or confess;
Branch: 1 branch
BranchTrueFalseTotal
defined $Registers{$r} or confess() 0 0 0
559 0 eval "${r}Size()";
560 }
561  
562 sub ClearRegisters(@) # Clear registers by setting them to zero.
563 0 ▶ {my (@registers) = @_; # Registers
Subroutine ClearRegisters: not called CC=7 SCAR=40.3
Pod documented
564 0 for my $r(@registers) # Each register
565 0 {my $size = RegisterSize $r;
566 0 ▶ Xor $r, $r if $size == 8 and $r !~ m(\Ak);
Branch: 1 branch
BranchTrueFalseTotal
if $size == 8 and not $r =~ /\Ak/ 0 0 0
Condition0%0/3
$size == 8 and not $r =~ /\Ak/
!ll&&!rl&&r
000
MC/DC0%0/2
$size == 8 and not $r =~ /\Ak/
$size == 8 not $r =~ /\Ak/
Truth table0%0/3
A and not(B)
A= $size == 8B= not $r =~ /\Ak/
ABresult
0X0
100
111
567 0 ▶ Kxorq $r, $r, $r if $size == 8 and $r =~ m(\Ak);
Branch: 1 branch
BranchTrueFalseTotal
if $size == 8 and $r =~ /\Ak/ 0 0 0
Condition0%0/3
$size == 8 and $r =~ /\Ak/
!ll&&!rl&&r
000
MC/DC0%0/2
$size == 8 and $r =~ /\Ak/
$size == 8 $r =~ /\Ak/
Truth table0%0/3
A and B
A= $size == 8B= $r =~ /\Ak/
ABresult
0X0
100
111
568 0 ▶ Vpxorq $r, $r, $r if $size > 8;
Branch: 1 branch
BranchTrueFalseTotal
if $size > 8 0 0 0
569 }
570 }
571  
572 sub SetMaskRegister($$$) # Set the mask register to ones starting at the specified position for the specified length and zeroes elsewhere.
573 0 ▶ {my ($mask, $start, $length) = @_; # Mask register to set, register containing start position or 0 for position 0, register containing end position
Subroutine SetMaskRegister: not called CC=3 SCAR=24.8
Pod documented
574 0 ▶ @_ == 3 or confess "Three parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess("Three parameters") 0 0 0
575  
576 0 PushR (r15, r14);
577 0 Mov r15, -1;
578 0 ▶ if ($start) # Non zero start
Branch: 1 branch
BranchTrueFalseTotal
if ($start) { } 0 0 0
579 0 {Mov r14, $start;
580 0 Bzhi r15, r15, r14;
581 0 Not r15;
582 0 Add r14, $length;
583 }
584 else # Starting at zero
585 0 {Mov r14, $length;
586 }
587 0 Bzhi r15, r15, r14;
588 0 Kmovq $mask, r15;
589 0 PopR;
590 }
591  
592 sub SetZF() # Set the zero flag.
593 0 ▶ {Cmp rax, rax;
Subroutine SetZF: not called CC=1 SCAR=6.9
Pod documented
594 }
595  
596 sub ClearZF() # Clear the zero flag.
597 0 ▶ {PushR rax;
Subroutine ClearZF: not called CC=1 SCAR=6.9
Pod documented
598 0 Mov rax, 1;
599 0 Cmp rax, 0;
600 0 PopR rax;
601 }
602  
603 #D2 Mask # Operations on mask registers
604  
605 sub CheckMaskRegister($) # Check that a register is in fact a mask register.
606 0 ▶ {my ($mask) = @_; # Mask register to check
Subroutine CheckMaskRegister: not called CC=4 SCAR=30.0
Pod documented
607 0 ▶ @_ == 1 or confess "One parameter";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess("One parameter") 0 0 0
608 0 ▶ $Registers{$mask} && $mask =~ m(\Ak[0-7]\Z) or
Branch: 1 branch
BranchTrueFalseTotal
$Registers{$mask} and $mask =~ /\Ak[0-7]\Z/ or confess("Not a mask register: $mask") 0 0 0
Condition0%0/3
$Registers{$mask} and $mask =~ /\Ak[0-7]\Z/
!ll&&!rl&&r
000
MC/DC0%0/2
$Registers{$mask} and $mask =~ /\Ak[0-7]\Z/
$Registers{$mask} $mask =~ /\Ak[0-7]\Z/
Truth table0%0/3
A and B
A= $Registers{$mask}B= $mask =~ /\Ak[0-7]\Z/
ABresult
0X0
100
111
609 confess "Not a mask register: $mask";
610 }
611  
612 sub LoadConstantIntoMaskRegister($$$) # Set a mask register equal to a constant.
613 0 ▶ {my ($mask, $transfer, $value) = @_; # Mask register to load, transfer register, constant to load
Subroutine LoadConstantIntoMaskRegister: not called CC=2 SCAR=17.9
Pod documented
614 0 ▶ @_ == 3 or confess "Three parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess("Three parameters") 0 0 0
615 0 CheckMaskRegister $mask;
616 0 CheckGeneralPurposeRegister $transfer;
617 0 Mov $transfer, $value; # Load mask into a general purpose register
618 0 Kmovq $mask, $transfer; # Load mask register from general purpose register
619 }
620  
621 sub LoadBitsIntoMaskRegister($$$@) # Load a bit string specification into a mask register.
622 0 ▶ {my ($mask, $transfer, $prefix, @values) = @_; # Mask register to load, transfer register, prefix bits, +n 1 bits -n 0 bits
Subroutine LoadBitsIntoMaskRegister: not called CC=6 SCAR=37.4
Pod documented
623 0 ▶ @_ > 3 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ > 3 or confess() 0 0 0
624 0 CheckMaskRegister $mask;
625 0 CheckGeneralPurposeRegister $transfer;
626 0 my $b = "0b$prefix";
627 0 for my $v(@values) # String representation of bit string
628 0 ▶ {$b .= '1' x +$v if $v > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $v > 0 0 0 0
629 0 ▶ $b .= '0' x -$v if $v < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $v < 0 0 0 0
630 0 ▶ $v or confess "Count must be positive or negative bit not zero";
Branch: 1 branch
BranchTrueFalseTotal
$v or confess("Count must be positive or negative bit not zero") 0 0 0
631 }
632 0 LoadConstantIntoMaskRegister($mask, $transfer, eval $b)
633 }
634  
635 1 my $Vpcmp = genHash("NasmX86::CompareCodes", # Compare codes for "Vpcmp"
636 eq=>0, # Equal
637 lt=>1, # Less than
638 le=>2, # Less than or equals
639 ne=>4, # Not equals
640 ge=>5, # Greater than or equal
641 gt=>6, # Greater than
642 );
643  
644 #D1 Structured Programming # Structured programming constructs
645  
646 sub If($$;$) # If.
647 0 ▶ {my ($jump, $then, $else) = @_; # Jump op code of variable, then - required , else - optional
Subroutine If: not called CC=7 SCAR=40.3
Pod documented
648 0 ▶ @_ >= 2 && @_ <= 3 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 and @_ <= 3 or confess() 0 0 0
Condition0%0/3
@_ >= 2 and @_ <= 3
!ll&&!rl&&r
000
MC/DC0%0/2
@_ >= 2 and @_ <= 3
@_ >= 2 @_ <= 3
Truth table0%0/3
A and B
A= @_ >= 2B= @_ <= 3
ABresult
0X0
100
111
649  
650 0 ▶ ref($jump) or $jump =~ m(\AJ(c|e|g|ge|gt|h|l|le|nc|ne|nz|z)\Z)
Branch: 1 branch
BranchTrueFalseTotal
ref $jump or $jump =~ /\AJ(c|e|g|ge|gt|h|l|le|nc|ne|nz|z)\Z/ or confess("Invalid jump: $jump") 0 0 0
Condition0%0/3
ref $jump or $jump =~ /\AJ(c|e|g|ge|gt|h|l|le|nc|ne|nz|z)\Z/
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $jump or $jump =~ /\AJ(c|e|g|ge|gt|h|l|le|nc|ne|nz|z)\Z/
ref $jump $jump =~ /\AJ(c|e|g|ge|gt|h|l|le|nc|ne|nz|z)\Z/
Truth table0%0/3
A or B
A= ref $jumpB= $jump =~ /\AJ(c|e|g|ge|gt|h|l|le|nc|ne|nz|z)\Z/
ABresult
1X1
011
000
651 or confess "Invalid jump: $jump";
652  
653 0 ▶ if (ref($jump)) # Variable expression, if it is non zero perform the then block else the else block
Branch: 2 branches
BranchTrueFalseTotal
if (ref $jump) { } 0 0 0
elsif (not $else) { } 0 0 0
654 0 { __SUB__->(q(Jnz), $then, $else);
655 }
656 elsif (!$else) # No else
657 0 {my $end = Label;
658 0 push @text, <<END;
659 $jump $end;
660 END
661 0 &$then;
662 0 SetLabel $end;
663 }
664 else # With else
665 0 {my $endIf = Label;
666 0 my $startElse = Label;
667 0 push @text, <<END;
668 $jump $startElse
669 END
670 0 &$then;
671 0 Jmp $endIf;
672 0 SetLabel $startElse;
673 0 &$else;
674 0 SetLabel $endIf;
675 }
676 }
677  
678 sub Then(&) # Then block for an If statement.
679 0 ▶ {my ($block) = @_; # Then block
Subroutine Then: not called CC=1 SCAR=6.9
Pod documented
680 0 $block;
681 }
682  
683 sub Else(&) # Else block for an If statement.
684 0 ▶ {my ($block) = @_; # Else block
Subroutine Else: not called CC=1 SCAR=6.9
Pod documented
685 0 $block;
686 }
687  
688 sub Ef(&$;$) # Else if block for an If statement.
689 0 ▶ {my ($condition, $then, $else) = @_; # Condition, then block, else block
Subroutine Ef: not called CC=1 SCAR=6.9
Pod documented
690 sub
691 0 ▶ {If (&$condition, $then, $else);
Subroutine __ANON__: not called CC=1 SCAR=6.9
692 }
693 0 }
694  
695 sub IfEq($;$) # If equal execute the then block else the else block.
696 0 ▶ {my ($then, $else) = @_; # Then - required , else - optional
Subroutine IfEq: not called CC=1 SCAR=6.9
Pod documented
697 0 If(q(Jne), $then, $else); # Opposite code
698 }
699  
700 sub IfNe($;$) # If not equal execute the then block else the else block.
701 0 ▶ {my ($then, $else) = @_; # Then - required , else - optional
Subroutine IfNe: not called CC=1 SCAR=6.9
Pod documented
702 0 If(q(Je), $then, $else); # Opposite code
703 }
704  
705 sub IfNz($;$) # If the zero flag is not set then execute the then block else the else block.
706 0 ▶ {my ($then, $else) = @_; # Then - required , else - optional
Subroutine IfNz: not called CC=1 SCAR=6.9
Pod documented
707 0 If(q(Jz), $then, $else); # Opposite code
708 }
709  
710 sub IfZ($;$) # If the zero flag is set then execute the then block else the else block.
711 0 ▶ {my ($then, $else) = @_; # Then - required , else - optional
Subroutine IfZ: not called CC=1 SCAR=6.9
Pod documented
712 0 If(q(Jnz), $then, $else); # Opposite code
713 }
714  
715 sub IfC($;$) # If the carry flag is set then execute the then block else the else block.
716 0 ▶ {my ($then, $else) = @_; # Then - required , else - optional
Subroutine IfC: not called CC=1 SCAR=6.9
Pod documented
717 0 If(q(Jnc), $then, $else); # Opposite code
718 }
719  
720 sub IfNc($;$) # If the carry flag is not set then execute the then block else the else block.
721 0 ▶ {my ($then, $else) = @_; # Then - required , else - optional
Subroutine IfNc: not called CC=1 SCAR=6.9
Pod documented
722 0 If(q(Jc), $then, $else); # Opposite code
723 }
724  
725 sub IfLt($;$) # If less than execute the then block else the else block.
726 0 ▶ {my ($then, $else) = @_; # Then - required , else - optional
Subroutine IfLt: not called CC=1 SCAR=6.9
Pod documented
727 0 If(q(Jge), $then, $else); # Opposite code
728 }
729  
730 sub IfLe($;$) # If less than or equal execute the then block else the else block.
731 0 ▶ {my ($then, $else) = @_; # Then - required , else - optional
Subroutine IfLe: not called CC=1 SCAR=6.9
Pod documented
732 0 If(q(Jg), $then, $else); # Opposite code
733 }
734  
735 sub IfGt($;$) # If greater than execute the then block else the else block.
736 0 ▶ {my ($then, $else) = @_; # Then - required , else - optional
Subroutine IfGt: not called CC=1 SCAR=6.9
Pod documented
737 0 If(q(Jle), $then, $else); # Opposite code
738 }
739  
740 sub IfGe($;$) # If greater than or equal execute the then block else the else block.
741 0 ▶ {my ($then, $else) = @_; # Then - required , else - optional
Subroutine IfGe: not called CC=1 SCAR=6.9
Pod documented
742 0 If(q(Jl), $then, $else); # Opposite code
743 }
744  
745 sub Pass(&) # Pass block for an L<OrBlock>.
746 0 ▶ {my ($block) = @_; # Block
Subroutine Pass: not called CC=1 SCAR=6.9
Pod documented
747 0 $block;
748 }
749  
750 sub Fail(&) # Fail block for an L<AndBlock>.
751 0 ▶ {my ($block) = @_; # Block
Subroutine Fail: not called CC=1 SCAR=6.9
Pod documented
752 0 $block;
753 }
754  
755 sub AndBlock(&;$) # Short circuit B<and>: execute a block of code to test conditions which, if all of them pass, allows the first block to continue successfully else if one of the conditions fails we execute the optional fail block.
756 0 ▶ {my ($test, $fail) = @_; # Block, optional failure block
Subroutine AndBlock: not called CC=6 SCAR=37.4
Pod documented
757 0 ▶ @_ == 1 or @_ == 2 or confess "One or two parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or @_ == 2 or confess("One or two parameters") 0 0 0
Condition0%0/3
@_ == 1 or @_ == 2
l!l&&r!l&&!r
000
MC/DC0%0/2
@_ == 1 or @_ == 2
@_ == 1 @_ == 2
Truth table0%0/3
A or B
A= @_ == 1B= @_ == 2
ABresult
1X1
011
000
758 0 SetLabel(my $start = Label); # Start of test block
759 0 ▶ my $Fail = @_ == 2 ? Label : undef; # Start of fail block
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 ? : 0 0 0
760 0 my $end = Label; # End of both blocks
761 0 ▶ &$test(($Fail // $end), $end, $start); # Test code plus success code
Condition0%0/3
$Fail // $end
l!l&&r!l&&!r
000
MC/DC0%0/2
$Fail // $end
$Fail $end
Truth table0%0/3
A // B
A= $FailB= $end
ABresult
1X1
011
000
762 0 ▶ if ($fail)
Branch: 1 branch
BranchTrueFalseTotal
if ($fail) 0 0 0
763 0 {Jmp $end; # Skip the fail block if we succeed in reaching the end of the test block which is the expected behavior for short circuited B<and>.
764 0 SetLabel $Fail;
765 0 &$fail($end, $Fail, $start); # Execute when true
766 }
767 0 SetLabel $end; # Exit block
768 }
769  
770 sub OrBlock(&;$) # Short circuit B<or>: execute a block of code to test conditions which, if one of them is met, leads on to the execution of the pass block, if all of the tests fail we continue withe the test block.
771 0 ▶ {my ($test, $pass) = @_; # Tests, optional block to execute on success
Subroutine OrBlock: not called CC=6 SCAR=37.4
Pod documented
772 0 ▶ @_ == 1 or @_ == 2 or confess "One or two parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or @_ == 2 or confess("One or two parameters") 0 0 0
Condition0%0/3
@_ == 1 or @_ == 2
l!l&&r!l&&!r
000
MC/DC0%0/2
@_ == 1 or @_ == 2
@_ == 1 @_ == 2
Truth table0%0/3
A or B
A= @_ == 1B= @_ == 2
ABresult
1X1
011
000
773 0 SetLabel(my $start = Label); # Start of test block
774 0 ▶ my $Pass = @_ == 2 ? Label : undef; # Start of pass block
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 ? : 0 0 0
775 0 my $end = Label; # End of both blocks
776 0 ▶ &$test(($Pass // $end), $end, $start); # Test code plus fail code
Condition0%0/3
$Pass // $end
l!l&&r!l&&!r
000
MC/DC0%0/2
$Pass // $end
$Pass $end
Truth table0%0/3
A // B
A= $PassB= $end
ABresult
1X1
011
000
777 0 ▶ if ($pass)
Branch: 1 branch
BranchTrueFalseTotal
if ($pass) 0 0 0
778 0 {Jmp $end; # Skip the pass block if we succeed in reaching the end of the test block which is the expected behavior for short circuited B<or>.
779 0 SetLabel $Pass;
780 0 &$pass($end, $Pass, $start); # Execute when true
781 }
782 0 SetLabel $end; # Exit block
783 }
784  
785 sub For(&$$;$) # For - iterate the block as long as register is less than limit incrementing by increment each time. Nota Bene: The register is not explicitly set to zero as you might want to start at some other number.
786 0 ▶ {my ($block, $register, $limit, $increment) = @_; # Block, register, limit on loop, increment on each iteration
Subroutine For: not called CC=5 SCAR=34.0
Pod documented
787 0 ▶ @_ == 3 or @_ == 4 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or @_ == 4 or confess() 0 0 0
Condition0%0/3
@_ == 3 or @_ == 4
l!l&&r!l&&!r
000
MC/DC0%0/2
@_ == 3 or @_ == 4
@_ == 3 @_ == 4
Truth table0%0/3
A or B
A= @_ == 3B= @_ == 4
ABresult
1X1
011
000
788 0 ▶ $increment //= 1; # Default increment
Condition0%0/2
$increment //= 1
l!l
00
MC/DC0%0/1
$increment //= 1
$increment
Truth table0%0/2
A
A= $increment
Aresult
11
00
789 0 my $next = Label; # Next iteration
790 0 Comment "For $register $limit";
791 0 my $start = Label;
792 0 my $end = Label;
793 0 SetLabel $start;
794 0 Cmp $register, $limit;
795 0 Jge $end;
796  
797 0 &$block($start, $end, $next); # Start, end and next labels
798  
799 0 SetLabel $next; # Next iteration starting with after incrementing
800 0 ▶ if ($increment == 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($increment == 1) { } 0 0 0
801 0 {Inc $register;
802 }
803 else
804 0 {Add $register, $increment;
805 }
806 0 Jmp $start; # Restart loop
807 0 SetLabel $end; # Exit loop
808 }
809  
810 sub ForIn(&$$$$) # For - iterate the full block as long as register plus increment is less than than limit incrementing by increment each time then increment the last block for the last non full block.
811 0 ▶ {my ($full, $last, $register, $limitRegister, $increment) = @_; # Block for full block, block for last block , register, register containing upper limit of loop, increment on each iteration
Subroutine ForIn: not called CC=2 SCAR=17.9
Pod documented
812 0 ▶ @_ == 5 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 5 or confess() 0 0 0
813 0 my $start = Label;
814 0 my $end = Label;
815  
816 0 SetLabel $start; # Start of loop
817 0 PushR $register; # Save the register so we can test that there is still room
818 0 Add $register, $increment; # Add increment
819 0 Cmp $register, $limitRegister; # Test that we have room for increment
820 0 PopR $register; # Remove increment
821 0 Jge $end;
822  
823 0 &$full;
824  
825 0 Add $register, $increment; # Increment for real
826 0 Jmp $start;
827 0 SetLabel $end;
828  
829 0 Sub $limitRegister, $register; # Size of remainder
830 IfNz # Non remainder
831 Then
832 0 ▶ {&$last; # Process remainder
Subroutine __ANON__: not called CC=1 SCAR=6.9
833 }
834 0 }
835  
836 sub ForEver(&) # Iterate for ever.
837 0 ▶ {my ($block) = @_; # Block to iterate
Subroutine ForEver: not called CC=2 SCAR=17.9
Pod documented
838 0 ▶ @_ == 1 or confess "One parameter";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess("One parameter") 0 0 0
839 0 Comment "ForEver";
840 0 my $start = Label; # Start label
841 0 my $end = Label; # End label
842  
843 0 SetLabel $start; # Start of loop
844  
845 0 &$block($start, $end); # End of loop
846  
847 0 Jmp $start; # Restart loop
848 0 SetLabel $end; # End of loop
849 }
850  
851 sub Macro(&%) # Create a sub with optional parameters name=> the name of the subroutine so it can be reused rather than regenerated, comment=> a comment describing the sub.
852 0 ▶ {my ($block, %options) = @_; # Block, options.
Subroutine Macro: not called CC=7 SCAR=40.3
Pod documented
853  
854 0 ▶ @_ >= 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 1 or confess() 0 0 0
855 0 ▶ my $name = $options{name} // [caller(1)]->[3]; # Optional name for subroutine reuse
Condition0%0/3
$options{"name"} // [caller 1]->[3]
l!l&&r!l&&!r
000
MC/DC0%0/2
$options{"name"} // [caller 1]->[3]
$options{"name"} [caller 1]->[3]
Truth table0%0/3
A // B
A= $options{"name"}B= [caller 1]->[3]
ABresult
1X1
011
000
856 0 ▶ if ($name and !$options{keepOut} and my $n = $subroutines{$name}) {return $n} # Return the label of a pre-existing copy of the code
Branch: 1 branch
BranchTrueFalseTotal
if ($name and not $options{"keepOut"} and my $n = $subroutines{$name}) 0 0 0
Condition0%0/6
$name and not $options{"keepOut"} and my $n = $subroutines{$name}
!ll&&!rl&&r
000
$name and not $options{"keepOut"}
!ll&&!rl&&r
000
MC/DC0%0/3
$name and not $options{"keepOut"} and my $n = $subroutines{$name}
$name not $options{"keepOut"} my $n = $subroutines{$name}
Truth table0%0/4
A and not(B) and C
A= $nameB= not $options{"keepOut"}C= my $n = $subroutines{$name}
ABCresult
0XX0
10X0
1100
1111
857  
858 0 my $start = Label;
859 0 my $end = Label;
860 0 Jmp $end;
861 0 SetLabel $start;
862 0 &$block;
863 0 Ret;
864 0 SetLabel $end;
865 0 ▶ $subroutines{$name} = $start if $name; # Cache a reference to the generated code if a name was supplied
Branch: 1 branch
BranchTrueFalseTotal
if $name 0 0 0
866  
867 0 $start
868 }
869  
870 #D2 Call # Call a subroutine
871  
872 1 my @VariableStack = (1); # Counts the number of parameters and variables on the stack in each invocation of L<Subroutine>. There is at least one variable - the first holds the traceback.
873  
874 sub SubroutineStartStack() # Initialize a new stack frame. The first quad of each frame has the address of the name of the sub in the low dword, and the parameter count in the upper byte of the quad. This field is all zeroes in the initial frame.
875 0 ▶ {push @VariableStack, 1; # Counts the number of variables on the stack in each invocation of L<Subroutine>. The first quad provides the traceback.
Subroutine SubroutineStartStack: not called CC=1 SCAR=6.9
Pod documented
876 }
877  
878 sub Subroutine(&$%) # Create a subroutine that can be called in assembler code.
879 0 ▶ {my ($block, $parameters, %options) = @_; # Block, [parameters names], options.
Subroutine Subroutine: not called CC=10 SCAR=47.0
Pod documented
880 0 ▶ @_ >= 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 or confess() 0 0 0
881 0 ▶ !$parameters or ref($parameters) =~ m(array)i or
Branch: 1 branch
BranchTrueFalseTotal
not $parameters or ref($parameters) =~ /array/i or confess("Reference to array of parameter names required") 0 0 0
Condition0%0/3
not $parameters or ref($parameters) =~ /array/i
l!l&&r!l&&!r
000
MC/DC0%0/2
not $parameters or ref($parameters) =~ /array/i
not $parameters ref($parameters) =~ /array/i
Truth table0%0/3
not(A) or B
A= not $parametersB= ref($parameters) =~ /array/i
ABresult
1X1
011
000
882 confess "Reference to array of parameter names required";
883  
884 0 my $name = $options{name}; # Subroutine name
885 0 ▶ $name or confess "Name required for subroutine, use [], name=>";
Branch: 1 branch
BranchTrueFalseTotal
$name or confess("Name required for subroutine, use [], name=>") 0 0 0
886  
887 0 ▶ if ($name and my $n = $subroutines{$name}) {return $n} # Return the label of a pre-existing copy of the code
Branch: 1 branch
BranchTrueFalseTotal
if ($name and my $n = $subroutines{$name}) 0 0 0
Condition0%0/3
$name and my $n = $subroutines{$name}
!ll&&!rl&&r
000
MC/DC0%0/2
$name and my $n = $subroutines{$name}
$name my $n = $subroutines{$name}
Truth table0%0/3
A and B
A= $nameB= my $n = $subroutines{$name}
ABresult
0X0
100
111
888  
889 0 SubroutineStartStack; # Open new stack layout with references to parameters
890 0 my %p; $p{$_} = R($_) for @$parameters; # Reference each parameter
891  
892 0 my $end = Label; Jmp $end; # End label
893 0 my $start = SetLabel; # Start label
894  
895 my $s = $subroutines{$name} = genHash(__PACKAGE__."::Sub", # Subroutine definition
896 start => $start, # Start label for this subroutine
897 end => $start, # End label for this subroutine
898 name => $name, # Name of the subroutine from which the entry label is located
899 0 args => {map {$_=>1} @$parameters}, # Hash of {argument name, argument variable}
900 variables => {%p}, # Argument variables
901 options => \%options, # Options
902 parameters=> $parameters, # Parameters
903 vars => $VariableStack[-1], # Number of variables in subroutine
904 depth => scalar @VariableStack, # Lexical depth
905 nameString=> Rs($name), # Name of the sub as a string constant
906 );
907  
908 0 my $E = @text; # Code entry that will contain the Enter instruction
909 0 Enter 0, 0;
910 0 &$block({%p}, $s); # Code with parameters
911  
912 0 my $V = pop @VariableStack; # Number of variables
913 0 my $P = @$parameters; # Number of parameters supplied
914 0 my $N = $P + $V; # Size of stack frame
915  
916 0 ▶ Leave if $N; # Remove frame if there was one
Branch: 1 branch
BranchTrueFalseTotal
if $N 0 0 0
917  
918 0 Ret;
919 0 SetLabel $end;
920 0 ▶ $text[$E] = $N ? <<END : ''; # Rewrite enter instruction now that we know how much stack space we need
Branch: 1 branch
BranchTrueFalseTotal
$N ? : 0 0 0
921 Enter $N*8, 0
922 END
923  
924 0 $s # Subroutine definition
925 }
926  
927 sub Nasm::X86::Sub::callTo($$$@) #P Call a sub passing it some parameters.
928 0 ▶ {my ($sub, $mode, $label, @parameters) = @_; # Subroutine descriptor, mode 0 - direct call or 1 - indirect call, label of sub, parameter variables
Subroutine callTo: not called CC=16 SCAR=56.1
929  
930 0 my %p;
931 0 ▶ while(@parameters) # Copy parameters supplied by the caller
Branch: 1 branch
BranchTrueFalseTotal
if (@parameters) 0 0 0
932 0 {my $p = shift @parameters; # Check parameters provided by caller
933 0 ▶ my $n = ref($p) ? $p->name : $p;
Branch: 1 branch
BranchTrueFalseTotal
ref $p ? : 0 0 0
934 0 ▶ defined($n) or confess "No name or variable";
Branch: 1 branch
BranchTrueFalseTotal
defined $n or confess("No name or variable") 0 0 0
935 0 ▶ my $v = ref($p) ? $p : shift @parameters;
Branch: 1 branch
BranchTrueFalseTotal
ref $p ? : 0 0 0
936 0 ▶ unless ($sub->args->{$n}) # Describe valid parameters using a table
Branch: 1 branch
BranchTrueFalseTotal
unless ($sub->args->{$n}) 0 0 0
937 0 {my @t;
938 0 push @t, map {[$_]} keys $sub->args->%*;
939 0 my $t = formatTable([@t], [qw(Name)]);
940 0 confess "Invalid parameter: '$n'\n$t";
941 }
942 0 $p{$n} = $v;
943 }
944  
945 0 if (1) # Check for missing arguments
946 0 {my %m = map {$_=>1} keys $sub->args->%*; # Formal arguments
947 0 delete $m{$_} for sort keys %p; # Remove actual arguments
948 0 ▶ keys %m and confess "Missing arguments ".dump([sort keys %m]); # Print missing parameter names
Branch: 1 branch
BranchTrueFalseTotal
keys %m and confess('Missing arguments ' . Nasm::X86::dump([sort(keys %m)])) 0 0 0
949 }
950  
951 0 if (1) # Check for misnamed arguments
952 0 {my %m = map {$_=>1} keys %p; # Actual arguments
953 0 delete $m{$_} for sort keys $sub->args->%*; # Remove formal arguments
954 0 ▶ keys %m and confess "Invalid arguments ".dump([sort keys %m]); # Print misnamed arguments
Branch: 1 branch
BranchTrueFalseTotal
keys %m and confess('Invalid arguments ' . Nasm::X86::dump([sort(keys %m)])) 0 0 0
955 }
956  
957 0 my $w = RegisterSize r15;
958 0 PushR r15; # Use this register to transfer between the current frame and the next frame
959 0 Mov "dword[rsp -$w*3]", $sub->nameString; # Point to name
960 0 Mov "byte [rsp-1-$w*2]", scalar $sub->parameters->@*; # Number of parameters to enable traceback with parameters
961  
962 0 for my $p(sort keys %p) # Transfer parameters from current frame to next frame
963 {!ref($p{$p}) or ref($p{$p}) =~ m(variable)i or
964 0 ▶ confess "Variable required, not: ".ref($p{$p});
Branch: 1 branch
BranchTrueFalseTotal
not ref $p{$p} or ref($p{$p}) =~ /variable/i or confess('Variable required, not: ' . ref($p{$p})) 0 0 0
Condition0%0/3
not ref $p{$p} or ref($p{$p}) =~ /variable/i
l!l&&r!l&&!r
000
MC/DC0%0/2
not ref $p{$p} or ref($p{$p}) =~ /variable/i
not ref $p{$p} ref($p{$p}) =~ /variable/i
Truth table0%0/3
not(A) or B
A= not ref $p{$p}B= ref($p{$p}) =~ /variable/i
ABresult
1X1
011
000
965 0 my $P = $p{$p}->label; # Source in current frame
966 0 ▶ if (my $q = $sub->variables->{$p}) # Target in new frame
Branch: 1 branch
BranchTrueFalseTotal
if (my $q = $sub->variables->{$p}) 0 0 0
967 0 ▶ {if ($p{$p}->reference) # Source is a reference
Branch: 1 branch
BranchTrueFalseTotal
if ($p{$p}->reference) { } 0 0 0
968 0 {Mov r15, "[$P]";
969 }
970 else # Source is not a reference
971 0 {Lea r15, "[$P]";
972 }
973 0 my $Q = $q->label;
974 0 $Q =~ s(rbp) (rsp);
975 0 Mov "[$Q-$w*2]", r15;
976 }
977 }
978  
979 0 ▶ if ($mode) # Dereference and call
Branch: 1 branch
BranchTrueFalseTotal
if ($mode) { } 0 0 0
980 0 {Mov r15, $label;
981 0 Mov r15, "[r15]";
982 0 Call r15;
983 }
984 else # Call via label
985 0 {Call $label;
986 }
987 0 PopR;
988 }
989  
990 sub Nasm::X86::Sub::call($@) # Call a sub passing it some parameters.
991 0 ▶ {my ($sub, @parameters) = @_; # Subroutine descriptor, parameter variables
Subroutine call: not called CC=1 SCAR=6.9
992 0 $sub->callTo(0, $sub->start, @parameters); # Call the subroutine
993 }
994  
995 sub Nasm::X86::Sub::via($$@) # Call a sub by reference passing it some parameters.
996 0 ▶ {my ($sub, $ref, @parameters) = @_; # Subroutine descriptor, variable containing a reference to the sub, parameter variables
Subroutine via: not called CC=1 SCAR=6.9
997 0 PushR r15;
998 0 $sub->callTo(1, "[$$ref{label}]", @parameters); # Call the subroutine
999 0 PopR;
1000 }
1001  
1002 sub Nasm::X86::Sub::V($) # Put the address of a subroutine into a stack variable so that it can be passed as a parameter.
1003 0 ▶ {my ($sub) = @_; # Subroutine descriptor
Subroutine V: not called CC=1 SCAR=6.9
1004 0 V('call', $sub->start); # Address subroutine via a stack variable
1005 }
1006  
1007 sub PrintTraceBack($) # Trace the call stack.
1008 0 ▶ {my ($channel) = @_; # Channel to write on
Subroutine PrintTraceBack: not called CC=1 SCAR=6.9
Pod documented
1009 my $s = Subroutine
1010 0 ▶ {PushR my @save = (rax, rdi, r9, r10, r8, r12, r13, r14, r15);
Subroutine __ANON__: not called CC=1 SCAR=6.9
1011 0 my $stack = r15;
1012 0 my $count = r14;
1013 0 my $index = r13;
1014 0 my $parameter = r12; # Number of parameters
1015 0 my $maxCount = r8; # Maximum number of parameters - should be r11 when we have found out why r11 does not print correctly.
1016 0 my $depth = r10; # Depth of trace back
1017 0 ClearRegisters @save;
1018  
1019 0 Mov $stack, rbp; # Current stack frame
1020 AndBlock # Each level
1021 0 ▶ {my ($fail, $end, $start) = @_; # Fail block, end of fail block, start of test block
Subroutine __ANON__: not called CC=1 SCAR=6.9
1022 0 Mov $stack, "[$stack]"; # Up one level
1023 0 Mov rax, "[$stack-8]";
1024 0 Mov $count, rax;
1025 0 Shr $count, 56; # Top byte contains the parameter count
1026 0 Cmp $count, $maxCount; # Compare this count with maximum so far
1027 0 Cmovg $maxCount, $count; # Update count if greater
1028 0 Shl rax, 8; Shr rax, 8; # Remove parameter count
1029 0 Je $end; # Reached top of stack if rax is zero
1030 0 Inc $depth; # Depth of trace back
1031 0 Jmp $start; # Next level
1032 0 };
1033  
1034 0 Mov $stack, rbp; # Current stack frame
1035 0 &PrintNL($channel); # Print title
1036 0 &PrintString($channel, "Subroutine trace back, depth: ");
1037 0 PushR rax;
1038 0 Mov rax, $depth;
1039 0 &PrintRaxInHex($channel);
1040 0 PopR rax;
1041 0 &PrintNL($channel);
1042  
1043 AndBlock # Each level
1044 0 ▶ {my ($fail, $end, $start) = @_; # Fail block, end of fail block, start of test block
Subroutine __ANON__: not called CC=1 SCAR=6.9
1045 0 Mov $stack, "[$stack]"; # Up one level
1046 0 Mov rax, "[$stack-8]";
1047 0 Mov $count, rax;
1048 0 Shr $count, 56; # Top byte contains the parameter count
1049 0 Shl rax, 8; Shr rax, 8; # Remove parameter count
1050 0 Je $end; # Reached top of stack
1051 0 Cmp $count, 0; # Check for parameters
1052 IfGt
1053 Then # One or more parameters
1054 0 ▶ {Mov $index, 0;
Subroutine __ANON__: not called CC=1 SCAR=6.9
1055 For
1056 0 ▶ {my ($start, $end, $next) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
1057 0 Mov $parameter, $index;
1058 0 Add $parameter, 2; # Skip traceback
1059 0 Shl $parameter, 3; # Each parameter is a quad
1060 0 Neg $parameter; # Offset from stack
1061 0 Add $parameter, $stack; # Position on stack
1062 0 Mov $parameter, "[$parameter]"; # Parameter reference to variable
1063 0 Push rax;
1064 0 Mov rax, "[$parameter]"; # Variable content
1065 0 &PrintRaxInHex($channel);
1066 0 Pop rax;
1067 0 &PrintSpace($channel, 4);
1068 0 } $index, $count;
1069 For # Vertically align subroutine names
1070 0 ▶ {my ($start, $end, $next) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
1071 0 &PrintSpace($channel, 23);
1072 0 } $index, $maxCount;
1073 0 };
1074  
1075 0 Push $stack; # Print the name of the subroutine
1076 0 &Cstrlen(); # Length of name
1077 0 Mov rdi, $stack;
1078 0 Pop $stack;
1079 0 &PrintMemoryNL($channel); # Print name
1080 0 Jmp $start; # Next level
1081 0 };
1082 0 &PrintNL($channel);
1083 0 PopR;
1084 0 } [], name => 'SubroutineTraceBack';
1085  
1086 0 $s->call;
1087 }
1088  
1089 sub PrintErrTraceBack() # Print sub routine track back on stderr.
1090 0 ▶ {PrintTraceBack($stderr);
Subroutine PrintErrTraceBack: not called CC=1 SCAR=6.9
Pod documented
1091 }
1092  
1093 sub PrintOutTraceBack() # Print sub routine track back on stdout.
1094 0 ▶ {PrintTraceBack($stdout);
Subroutine PrintOutTraceBack: not called CC=1 SCAR=6.9
Pod documented
1095 }
1096  
1097 sub OnSegv() # Request a trace back followed by exit on a B<segv> signal.
1098 {my $s = Subroutine # Subroutine that will cause an error to occur to force a trace back to be printed
1099 0 ▶ {my $end = Label;
Subroutine __ANON__: not called CC=2 SCAR=17.9
1100 0 Jmp $end; # Jump over subroutine definition
1101 0 my $start = SetLabel;
1102 0 Enter 0, 0; # Inline code of signal handler
1103 0 Mov r15, rbp; # Preserve the new stack frame
1104 0 Mov rbp, "[rbp]"; # Restore our last stack frame
1105 0 PrintOutTraceBack; # Print our trace back
1106 0 Mov rbp, r15; # Restore supplied stack frame
1107 0 Exit(0); # Exit so we do not trampoline. Exit with code zero to show that the program is functioning correctly, else L<Assemble> will report an error.
1108 0 Leave;
1109 0 Ret;
1110 0 SetLabel $end;
1111  
1112 0 Mov r15, 0; # Push sufficient zeros onto the stack to make a structure B<sigaction> as described in: https://www.man7.org/linux/man-pages/man2/sigaction.2.html
1113 0 Push r15 for 1..16;
1114  
1115 0 Mov r15, $start; # Actual signal handler
1116 0 Mov "[rsp]", r15; # Show as signal handler
1117 0 Mov "[rsp+0x10]", r15; # Add as trampoline as well - which is fine because we exit in the handler so this will never be called
1118 0 Mov r15, 0x4000000; # Mask to show we have a trampoline which is, apparently, required on x86
1119 0 Mov "[rsp+0x8]", r15; # Confirm we have a trampoline
1120  
1121 0 Mov rax, 13; # B<Sigaction> from B<kill -l>
1122 0 Mov rdi, 11; # Confirmed B<SIGSEGV = 11> from B<kill -l> and tracing with B<sde64>
1123 0 Mov rsi, rsp; # Structure B<sigaction> structure on stack
1124 0 Mov rdx, 0; # Confirmed by trace
1125 0 Mov r10, 8; # Found by tracing B<signal.c> with B<sde64> it is the width of the signal set and mask. B<signal.c> is reproduced below.
1126 0 Syscall;
1127 0 Add rsp, 128;
1128 0 ▶ } [], name=>"on segv";
Subroutine OnSegv: not called CC=1 SCAR=6.9
Pod documented
1129  
1130 0 $s->call;
1131 }
1132  
1133 sub cr(&@) # Call a subroutine with a reordering of the registers.
1134 0 ▶ {my ($block, @registers) = @_; # Code to execute with reordered registers, registers to reorder
Subroutine cr: not called CC=1 SCAR=6.9
Pod documented
1135 0 ReorderSyscallRegisters @registers;
1136 0 &$block;
1137 0 UnReorderSyscallRegisters @registers;
1138 }
1139  
1140 #D1 Comments # Inserts comments into the generated assember code.
1141  
1142 sub CommentWithTraceBack(@) # Insert a comment into the assembly code with a traceback showing how it was generated.
1143 0 ▶ {my (@comment) = @_; # Text of comment
Subroutine CommentWithTraceBack: not called CC=1 SCAR=6.9
Pod documented
1144 0 my $c = join "", @comment;
1145 # eval {confess};
1146 # my $p = dump($@);
1147 0 my $p = &subNameTraceBack =~ s(Nasm::X86::) ()gsr;
1148 0 push @text, <<END;
1149 ; $c $p
1150 END
1151 }
1152  
1153 sub Comment(@) # Insert a comment into the assembly code.
1154 0 ▶ {my (@comment) = @_; # Text of comment
Subroutine Comment: not called CC=1 SCAR=6.9
Pod documented
1155 0 my $c = join "", @comment;
1156 0 my ($p, $f, $l) = caller;
1157 0 push @text, <<END;
1158 ; $c at $f line $l
1159 END
1160 }
1161  
1162 sub DComment(@) # Insert a comment into the data segment.
1163 0 ▶ {my (@comment) = @_; # Text of comment
Subroutine DComment: not called CC=1 SCAR=6.9
Pod documented
1164 0 my $c = join "", @comment;
1165 0 push @data, <<END;
1166 ; $c
1167 END
1168 }
1169  
1170 sub RComment(@) # Insert a comment into the read only data segment.
1171 0 ▶ {my (@comment) = @_; # Text of comment
Subroutine RComment: not called CC=1 SCAR=6.9
Pod documented
1172 0 my $c = join "", @comment;
1173 0 push @data, <<END;
1174 ; $c
1175 END
1176 }
1177  
1178 #D1 Print # Print
1179  
1180 sub PrintNL($) # Print a new line to stdout or stderr.
1181 0 ▶ {my ($channel) = @_; # Channel to write on
Subroutine PrintNL: not called CC=2 SCAR=17.9
Pod documented
1182 0 ▶ @_ == 1 or confess "One parameter";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess("One parameter") 0 0 0
1183 0 my $a = Rb(10);
1184  
1185 Call Macro
1186 0 ▶ {SaveFirstFour;
Subroutine __ANON__: not called CC=1 SCAR=6.9
1187 0 Mov rax, 1;
1188 0 Mov rdi, $channel;
1189 0 Mov rsi, $a;
1190 0 Mov rdx, 1;
1191 0 Syscall;
1192 0 RestoreFirstFour()
1193 0 } name => qq(PrintNL$channel);
1194 }
1195  
1196 sub PrintErrNL() # Print a new line to stderr.
1197 0 ▶ {@_ == 0 or confess;
Subroutine PrintErrNL: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 0 or confess() 0 0 0
1198 0 PrintNL($stderr);
1199 }
1200  
1201 sub PrintOutNL() # Print a new line to stderr.
1202 0 ▶ {@_ == 0 or confess;
Subroutine PrintOutNL: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 0 or confess() 0 0 0
1203 0 PrintNL($stdout);
1204 }
1205  
1206 sub PrintString($@) # Print a constant string to the specified channel.
1207 0 ▶ {my ($channel, @string) = @_; # Channel, Strings
Subroutine PrintString: not called CC=2 SCAR=17.9
Pod documented
1208 0 ▶ @_ >= 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 or confess() 0 0 0
1209  
1210 0 my $c = join ' ', @string;
1211 0 my $l = length($c);
1212 0 my $a = Rs($c);
1213  
1214 my $s = Subroutine
1215 0 ▶ {SaveFirstFour;
Subroutine __ANON__: not called CC=1 SCAR=6.9
1216 0 Mov rax, 1;
1217 0 Mov rdi, $channel;
1218 0 Mov rsi, $a;
1219 0 Mov rdx, $l;
1220 0 Syscall;
1221 0 RestoreFirstFour();
1222 0 } [], name => "PrintString_${channel}_${c}";
1223  
1224 0 $s->call;
1225 }
1226  
1227 sub PrintStringNL($@) # Print a constant string to the specified channel followed by a new line.
1228 0 ▶ {my ($channel, @string) = @_; # Channel, Strings
Subroutine PrintStringNL: not called CC=1 SCAR=6.9
Pod documented
1229 0 PrintString($channel, @string);
1230 0 PrintNL ($channel);
1231 }
1232  
1233 sub PrintErrString(@) # Print a constant string to stderr.
1234 0 ▶ {my (@string) = @_; # String
Subroutine PrintErrString: not called CC=1 SCAR=6.9
Pod documented
1235 0 PrintString($stderr, @string);
1236 }
1237  
1238 sub PrintOutString(@) # Print a constant string to stdout.
1239 0 ▶ {my (@string) = @_; # String
Subroutine PrintOutString: not called CC=1 SCAR=6.9
Pod documented
1240 0 PrintString($stdout, @string);
1241 }
1242  
1243 sub PrintSpace($;$) # Print one or more spaces to the specified channel.
1244 0 ▶ {my ($channel, $spaces) = @_; # Channel, number of spaces if not one.
Subroutine PrintSpace: not called CC=2 SCAR=17.9
Pod documented
1245 0 ▶ PrintString($channel, ' ' x ($spaces // 1));
Condition0%0/2
$spaces // 1
l!l
00
MC/DC0%0/1
$spaces // 1
$spaces
Truth table0%0/2
A
A= $spaces
Aresult
11
00
1246 }
1247  
1248 sub PrintErrSpace(;$) # Print one or more spaces to stderr.
1249 0 ▶ {my ($spaces) = @_; # Number of spaces if not one.
Subroutine PrintErrSpace: not called CC=1 SCAR=6.9
Pod documented
1250 0 PrintErrString(' ', $spaces);
1251 }
1252  
1253 sub PrintOutSpace(;$) # Print one or more spaces to stdout.
1254 0 ▶ {my ($spaces) = @_; # Number of spaces if not one.
Subroutine PrintOutSpace: not called CC=1 SCAR=6.9
Pod documented
1255 0 PrintOutString(' ', $spaces);
1256 }
1257  
1258 sub PrintErrStringNL(@) # Print a constant string followed by a new line to stderr.
1259 0 ▶ {my (@string) = @_; # Strings
Subroutine PrintErrStringNL: not called CC=1 SCAR=6.9
Pod documented
1260 0 PrintErrString(@string);
1261 0 PrintErrNL;
1262 }
1263  
1264 sub PrintOutStringNL(@) # Print a constant string followed by a new line to stdout.
1265 0 ▶ {my (@string) = @_; # Strings
Subroutine PrintOutStringNL: not called CC=1 SCAR=6.9
Pod documented
1266 0 PrintOutString(@string);
1267 0 PrintOutNL;
1268 }
1269  
1270 sub hexTranslateTable #P Create/address a hex translate table and return its label.
1271 0 ▶ {my $h = '0123456789ABCDEF';
Subroutine hexTranslateTable: not called CC=3 SCAR=24.8
Pod documented
1272 0 my @t;
1273 0 for my $i(split //, $h)
1274 0 {for my $j(split //, $h)
1275 0 {push @t, "$i$j";
1276 }
1277 }
1278 Rs @t # Constant strings are only saved if they are unique, else a read only copy is returned.
1279 0 }
1280  
1281 sub PrintRaxInHex($;$) # Write the content of register rax in hexadecimal in big endian notation to the specified channel.
1282 0 ▶ {my ($channel, $end) = @_; # Channel, optional end byte
Subroutine PrintRaxInHex: not called CC=4 SCAR=30.0
Pod documented
1283 0 ▶ @_ == 1 or @_ == 2 or confess "One or two parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or @_ == 2 or confess("One or two parameters") 0 0 0
Condition0%0/3
@_ == 1 or @_ == 2
l!l&&r!l&&!r
000
MC/DC0%0/2
@_ == 1 or @_ == 2
@_ == 1 @_ == 2
Truth table0%0/3
A or B
A= @_ == 1B= @_ == 2
ABresult
1X1
011
000
1284 0 my $hexTranslateTable = hexTranslateTable;
1285 0 ▶ $end //= 7; # Default end byte
Condition0%0/2
$end //= 7
l!l
00
MC/DC0%0/1
$end //= 7
$end
Truth table0%0/2
A
A= $end
Aresult
11
00
1286  
1287 my $sub = Macro
1288 0 ▶ {Comment "Print Rax In Hex on channel: $channel start";
Subroutine __ANON__: not called CC=4 SCAR=30.0
1289 0 SaveFirstFour rax; # Rax is a parameter
1290 0 Mov rdx, rax; # Content to be printed
1291 0 Mov rdi, 2; # Length of a byte in hex
1292  
1293 0 for my $i((7-$end)..7) # Each byte
1294 0 {my $s = 8*$i;
1295 0 Mov rax, rdx;
1296 0 Shl rax, $s; # Push selected byte high
1297 0 Shr rax, 56; # Push select byte low
1298 0 Shl rax, 1; # Multiply by two because each entry in the translation table is two bytes long
1299 0 Lea rax, "[$hexTranslateTable+rax]";
1300 0 PrintMemory($channel); # Print memory addressed by rax for length specified by rdi
1301 0 ▶ PrintString($channel, ' ') if $i % 2 and $i < 7;
Branch: 1 branch
BranchTrueFalseTotal
if $i % 2 and $i < 7 0 0 0
Condition0%0/3
$i % 2 and $i < 7
!ll&&!rl&&r
000
MC/DC0%0/2
$i % 2 and $i < 7
$i % 2 $i < 7
Truth table0%0/3
A and B
A= $i % 2B= $i < 7
ABresult
0X0
100
111
1302 }
1303 0 RestoreFirstFour;
1304 0 Comment "Print Rax In Hex on channel: $channel start";
1305 0 } name => "PrintOutRaxInHexOn-$channel-$end";
1306  
1307 0 Call $sub;
1308 }
1309  
1310 sub PrintErrRaxInHex() # Write the content of register rax in hexadecimal in big endian notation to stderr.
1311 0 ▶ {@_ == 0 or confess;
Subroutine PrintErrRaxInHex: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 0 or confess() 0 0 0
1312 0 PrintRaxInHex($stderr);
1313 }
1314  
1315 sub PrintOutRaxInHex() # Write the content of register rax in hexadecimal in big endian notation to stderr.
1316 0 ▶ {@_ == 0 or confess;
Subroutine PrintOutRaxInHex: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 0 or confess() 0 0 0
1317 0 PrintRaxInHex($stdout);
1318 }
1319  
1320 sub PrintOutRaxInReverseInHex # Write the content of register rax to stderr in hexadecimal in little endian notation.
1321 0 ▶ {@_ == 0 or confess;
Subroutine PrintOutRaxInReverseInHex: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 0 or confess() 0 0 0
1322 0 Comment "Print Rax In Reverse In Hex";
1323 0 Push rax;
1324 0 Bswap rax;
1325 0 PrintOutRaxInHex;
1326 0 Pop rax;
1327 }
1328  
1329 sub PrintOneRegisterInHex($$) # Print the named register as a hex strings.
1330 0 ▶ {my ($channel, $r) = @_; # Channel to print on, register to print
Subroutine PrintOneRegisterInHex: not called CC=2 SCAR=17.9
Pod documented
1331 0 ▶ @_ == 2 or confess "Two parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess("Two parameters") 0 0 0
1332  
1333 Call Macro # Print non general purpose registers
1334 0 ▶ {if ($r =~ m(\Ar)) # General purpose register
Subroutine __ANON__: not called CC=7 SCAR=40.3
Branch: 1 branch
BranchTrueFalseTotal
if ($r =~ /\Ar/) { } 0 0 0
1335 0 ▶ {if ($r =~ m(\Arax\Z))
Branch: 1 branch
BranchTrueFalseTotal
if ($r =~ /\Arax\Z/) { } 0 0 0
1336 0 {PrintRaxInHex($channel);
1337 }
1338 else
1339 0 {PushR rax;
1340 0 Mov rax, $r;
1341 0 PrintRaxInHex($channel);
1342 0 PopR rax;
1343 }
1344 }
1345 else
1346 {my sub printReg(@) # Print the contents of a register
1347 0 ▶ {my (@regs) = @_; # Size in bytes, work registers
Subroutine printReg: not called CC=4 SCAR=30.0
1348 0 my $s = RegisterSize $r; # Size of the register
1349 0 PushRR @regs; # Save work registers
1350 0 PushRR $r; # Place register contents on stack - might be a x|y|z - without tracking
1351 0 PopRR @regs; # Load work registers without tracking
1352 0 for my $i(keys @regs) # Print work registers to print input register
1353 0 {my $R = $regs[$i];
1354 0 ▶ if ($R !~ m(\Arax))
Branch: 1 branch
BranchTrueFalseTotal
unless ($R =~ /\Arax/) 0 0 0
1355 0 {PrintString($channel, " "); # Separate blocks of bytes with a space
1356 0 Mov rax, $R;
1357 }
1358 0 PrintRaxInHex($channel); # Print work register
1359 0 ▶ PrintString($channel, " ") unless $i == $#regs;
Branch: 1 branch
BranchTrueFalseTotal
unless $i == $#regs 0 0 0
1360 }
1361 0 PopRR @regs; # Balance the single push of what might be a large register
1362 };
1363 0 ▶ if ($r =~ m(\A[kr])) {printReg qw(rax)} # General purpose 64 bit register requested
Branch: 4 branches
BranchTrueFalseTotal
if ($r =~ /\A[kr]/) { } 0 0 0
elsif ($r =~ /\Ax/) { } 0 0 0
elsif ($r =~ /\Ay/) { } 0 0 0
elsif ($r =~ /\Az/) { } 0 0 0
1364 0 elsif ($r =~ m(\Ax)) {printReg qw(rax rbx)} # Xmm*
1365 0 elsif ($r =~ m(\Ay)) {printReg qw(rax rbx rcx rdx)} # Ymm*
1366 0 elsif ($r =~ m(\Az)) {printReg qw(rax rbx rcx rdx r8 r9 r10 r11)} # Zmm*
1367 }
1368 0 } name => "PrintOneRegister${r}InHexOn$channel"; # One routine per register printed
1369 }
1370  
1371 sub PrintRegisterInHex($@) # Print the named registers as hex strings.
1372 0 ▶ {my ($channel, @r) = @_; # Channel to print on, names of the registers to print
Subroutine PrintRegisterInHex: not called CC=3 SCAR=24.8
Pod documented
1373 0 ▶ @_ >= 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 or confess() 0 0 0
1374  
1375 0 for my $r(@r) # Each register to print
1376 0 {PrintString($channel, sprintf("%6s: ", $r)); # Register name
1377 0 PrintOneRegisterInHex $channel, $r;
1378 0 PrintNL($channel);
1379 }
1380 }
1381  
1382 sub PrintErrRegisterInHex(@) # Print the named registers as hex strings on stderr.
1383 0 ▶ {my (@r) = @_; # Names of the registers to print
Subroutine PrintErrRegisterInHex: not called CC=1 SCAR=6.9
Pod documented
1384 0 PrintRegisterInHex $stderr, @r;
1385 }
1386  
1387 sub PrintOutRegisterInHex(@) # Print the named registers as hex strings on stdout.
1388 0 ▶ {my (@r) = @_; # Names of the registers to print
Subroutine PrintOutRegisterInHex: not called CC=1 SCAR=6.9
Pod documented
1389 0 PrintRegisterInHex $stdout, @r;
1390 }
1391  
1392 sub PrintOutRipInHex #P Print the instruction pointer in hex.
1393 0 ▶ {@_ == 0 or confess;
Subroutine PrintOutRipInHex: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 0 or confess() 0 0 0
1394 0 my @regs = qw(rax);
1395 my $sub = Macro
1396 0 ▶ {PushR @regs;
Subroutine __ANON__: not called CC=1 SCAR=6.9
1397 0 my $l = Label;
1398 0 push @text, <<END;
1399 $l:
1400 END
1401 0 Lea rax, "[$l]"; # Current instruction pointer
1402 0 PrintOutString "rip: ";
1403 0 PrintOutRaxInHex;
1404 0 PrintOutNL;
1405 0 PopR @regs;
1406 0 } name=> "PrintOutRipInHex";
1407  
1408 0 Call $sub;
1409 }
1410  
1411 sub PrintOutRflagsInHex #P Print the flags register in hex.
1412 0 ▶ {@_ == 0 or confess;
Subroutine PrintOutRflagsInHex: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 0 or confess() 0 0 0
1413 0 my @regs = qw(rax);
1414  
1415 my $sub = Macro
1416 0 ▶ {PushR @regs;
Subroutine __ANON__: not called CC=1 SCAR=6.9
1417 0 Pushfq;
1418 0 Pop rax;
1419 0 PrintOutString "rfl: ";
1420 0 PrintOutRaxInHex;
1421 0 PrintOutNL;
1422 0 PopR @regs;
1423 0 } name=> "PrintOutRflagsInHex";
1424  
1425 0 Call $sub;
1426 }
1427  
1428 sub PrintOutRegistersInHex # Print the general purpose registers in hex.
1429 0 ▶ {@_ == 0 or confess;
Subroutine PrintOutRegistersInHex: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 0 or confess() 0 0 0
1430  
1431 my $sub = Macro
1432 0 ▶ {PrintOutRipInHex;
Subroutine __ANON__: not called CC=4 SCAR=30.0
1433 0 PrintOutRflagsInHex;
1434  
1435 0 my @regs = qw(rax);
1436 0 PushR @regs;
1437  
1438 0 my $w = registers_64();
1439 0 for my $r(sort @$w)
1440 0 ▶ {next if $r =~ m(rip|rflags);
Branch: 1 branch
BranchTrueFalseTotal
if $r =~ /rip|rflags/ 0 0 0
1441 0 ▶ if ($r eq rax)
Branch: 1 branch
BranchTrueFalseTotal
if ($r eq rax()) 0 0 0
1442 0 {Pop rax;
1443 0 Push rax
1444 }
1445 0 PrintOutString reverse(pad(reverse($r), 3)).": ";
1446 0 Mov rax, $r;
1447 0 PrintOutRaxInHex;
1448 0 PrintOutNL;
1449 }
1450 0 PopR @regs;
1451 0 } name=> "PrintOutRegistersInHex";
1452  
1453 0 Call $sub;
1454 }
1455  
1456 sub PrintErrZF # Print the zero flag without disturbing it on stderr.
1457 0 ▶ {@_ == 0 or confess;
Subroutine PrintErrZF: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 0 or confess() 0 0 0
1458  
1459 0 Pushfq;
1460 0 ▶ IfNz Then {PrintErrStringNL "ZF=0"}, Else {PrintErrStringNL "ZF=1"};
Subroutine __ANON__: not called CC=1 SCAR=6.9
1461 0 Popfq;
1462 }
1463  
1464 sub PrintOutZF # Print the zero flag without disturbing it on stdout.
1465 0 ▶ {@_ == 0 or confess;
Subroutine PrintOutZF: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 0 or confess() 0 0 0
1466  
1467 0 Pushfq;
1468 0 ▶ IfNz Then {PrintOutStringNL "ZF=0"}, Else {PrintOutStringNL "ZF=1"};
Subroutine __ANON__: not called CC=1 SCAR=6.9
1469 0 Popfq;
1470 }
1471  
1472 sub PrintUtf8Char($) # Print the utf 8 character addressed by rax to the specified channel. The character must be in little endian form.
1473 0 ▶ {my ($channel) = @_; # Channel
Subroutine PrintUtf8Char: not called CC=1 SCAR=6.9
Pod documented
1474  
1475 my $s = Subroutine
1476 0 ▶ {my ($p, $s) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
1477 0 PushR rax, rdi, r15;
1478 0 Mov r15d, "[rax]"; # Load character - this assumes that each utf8 character sits by itself, right adjusted, in a block of 4 bytes
1479 0 Lzcnt r15, r15; # Find width of utf 8 character
1480 0 Shr r15, 3; # From bits to bytes
1481 0 Mov rdi, RegisterSize r15; # Maximum number of bytes
1482 0 Sub rdi, r15; # Width in bytes
1483 0 PrintMemory($channel); # Print letter from stack
1484 0 PopR;
1485 0 } [], name => qq(Nasm::X86::printUtf8Char_$channel);
1486  
1487 0 $s->call();
1488 }
1489  
1490 sub PrintErrUtf8Char() # Print the utf 8 character addressed by rax to stderr.
1491 0 ▶ {PrintUtf8Char($stdout);
Subroutine PrintErrUtf8Char: not called CC=1 SCAR=6.9
Pod documented
1492 }
1493  
1494 sub PrintOutUtf8Char() # Print the utf 8 character addressed by rax to stdout.
1495 0 ▶ {PrintUtf8Char($stdout);
Subroutine PrintOutUtf8Char: not called CC=1 SCAR=6.9
Pod documented
1496 }
1497  
1498 sub PrintUtf32($$$) #P Print the specified number of utf32 characters at the specified address to the specified channel.
1499 0 ▶ {my ($channel, $size, $address) = @_; # Channel, variable: number of characters to print, variable: address of memory
Subroutine PrintUtf32: not called CC=2 SCAR=17.9
Pod documented
1500 0 ▶ @_ == 3 or confess "Three parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess("Three parameters") 0 0 0
1501  
1502 my $s = Subroutine # Subroutine
1503 0 ▶ {my ($p, $s) = @_; # Parameters, subroutine description
Subroutine __ANON__: not called CC=1 SCAR=6.9
1504  
1505 0 PushR (rax, r14, r15);
1506 0 my $count = $$p{size} / 2; my $count1 = $count - 1;
1507 $count->for(sub
1508 0 ▶ {my ($index, $start, $next, $end) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
1509 0 my $a = $$p{address} + $index * 8;
1510 0 $a->setReg(rax);
1511 0 Mov rax, "[rax]";
1512 0 Mov r14, rax;
1513 0 Mov r15, rax;
1514 0 Shl r15, 32;
1515 0 Shr r14, 32;
1516 0 Or r14,r15;
1517 0 Mov rax, r14;
1518 0 PrintOutRaxInHex;
1519 If $index % 8 == 7,
1520 Then
1521 0 ▶ {PrintOutNL;
Subroutine __ANON__: not called CC=1 SCAR=6.9
1522 },
1523 Else
1524 {If $index != $count1, sub
1525 0 ▶ {PrintOutString " ";
Subroutine __ANON__: not called CC=1 SCAR=6.9
1526 0 ▶ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
1527 0 };
1528 0 });
1529 0 PrintOutNL;
1530 0 PopR;
1531 0 } [qw(size address)], name => qq(Nasm::X86::printUtf32_$channel);
1532  
1533 0 $s->call(size => $size, address => $address);
1534 }
1535  
1536 sub PrintErrUtf32($$) # Print the utf 8 character addressed by rax to stderr.
1537 0 ▶ {my ($size, $address) = @_; # Variable: number of characters to print, variable: address of memory
Subroutine PrintErrUtf32: not called CC=2 SCAR=17.9
Pod documented
1538 0 ▶ @_ == 2 or confess "Two parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess("Two parameters") 0 0 0
1539 0 PrintUtf32($stderr, $size, $address);
1540 }
1541  
1542 sub PrintOutUtf32($$) # Print the utf 8 character addressed by rax to stdout.
1543 0 ▶ {my ($size, $address) = @_; # Variable: number of characters to print, variable: address of memory
Subroutine PrintOutUtf32: not called CC=2 SCAR=17.9
Pod documented
1544 0 ▶ @_ == 2 or confess "Two parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess("Two parameters") 0 0 0
1545 0 PrintUtf32($stderr, $size, $address);
1546 }
1547  
1548 #D1 Variables # Variable definitions and operations
1549  
1550 #D2 Definitions # Variable definitions
1551  
1552 sub Variable($;$%) # Create a new variable with the specified name initialized via an optional expression.
1553 0 ▶ {my ($name, $expr, %options) = @_; # Name of variable, optional expression initializing variable, options
Subroutine Variable: not called CC=11 SCAR=48.8
Pod documented
1554 0 my $size = 3; # Size of variable in bytes as a power of 2
1555 0 my $width = 2**$size; # Size of variable in bytes
1556 0 ▶ my $const = $options{constant} // 0; # Constant variable 0- implicitly global
Condition0%0/2
$options{"constant"} // 0
l!l
00
MC/DC0%0/1
$options{"constant"} // 0
$options{"constant"}
Truth table0%0/2
A
A= $options{"constant"}
Aresult
11
00
1557 0 ▶ my $global = $options{global} // 0; # Global variable
Condition0%0/2
$options{"global"} // 0
l!l
00
MC/DC0%0/1
$options{"global"} // 0
$options{"global"}
Truth table0%0/2
A
A= $options{"global"}
Aresult
11
00
1558  
1559 0 my $label;
1560 0 ▶ if ($const) # Constant variable
Branch: 2 branches
BranchTrueFalseTotal
if ($const) { } 0 0 0
elsif ($global) { } 0 0 0
1561 0 ▶ {defined($expr) or confess "Value required for constant";
Branch: 1 branch
BranchTrueFalseTotal
defined $expr or confess("Value required for constant") 0 0 0
1562 0 ▶ $expr =~ m(r) and confess
Branch: 1 branch
BranchTrueFalseTotal
$expr =~ /r/ and confess("Cannot use register expression $expr to initialize a constant") 0 0 0
1563 "Cannot use register expression $expr to initialize a constant";
1564 0 RComment qq(Constant name: "$name", value $expr);
1565 0 $label = Rq($expr);
1566 }
1567 elsif ($global) # Global variable
1568 0 ▶ {$label = Dq($expr // 0);
Condition0%0/2
$expr // 0
l!l
00
MC/DC0%0/1
$expr // 0
$expr
Truth table0%0/2
A
A= $expr
Aresult
11
00
1569 }
1570 else # Local variable: Position on stack of variable
1571 0 {my $stack = ++$VariableStack[-1];
1572 0 $label = "rbp-8*($stack)";
1573  
1574 0 ▶ if (defined $expr) # Initialize variable if an initializer was supplied
Branch: 1 branch
BranchTrueFalseTotal
if (defined $expr) 0 0 0
1575 0 ▶ {if ($Registers{$expr} and $expr =~ m(\Ar)) # Expression is ready to go
Branch: 1 branch
BranchTrueFalseTotal
if ($Registers{$expr} and $expr =~ /\Ar/) { } 0 0 0
Condition0%0/3
$Registers{$expr} and $expr =~ /\Ar/
!ll&&!rl&&r
000
MC/DC0%0/2
$Registers{$expr} and $expr =~ /\Ar/
$Registers{$expr} $expr =~ /\Ar/
Truth table0%0/3
A and B
A= $Registers{$expr}B= $expr =~ /\Ar/
ABresult
0X0
100
111
1576 0 {Mov "[$label]", $expr;
1577 }
1578 else # Transfer expression
1579 0 {PushR r15;
1580 0 Mov r15, $expr;
1581 0 Mov "[$label]", r15;
1582 0 PopR r15;
1583 }
1584 }
1585 }
1586  
1587 0 genHash(__PACKAGE__."::Variable", # Variable definition
1588 constant => $const, # Constant if true
1589 global => $global, # Global if true
1590 expr => $expr, # Expression that initializes the variable
1591 label => $label, # Address in memory
1592 name => $name, # Name of the variable
1593 level => scalar @VariableStack, # Lexical level
1594 reference => undef, # Reference to another variable
1595 );
1596 }
1597  
1598 sub G(*;$%) # Define a global variable.
1599 0 ▶ {my ($name, $expr, %options) = @_; # Name of variable, initializing expression, options
Subroutine G: not called CC=1 SCAR=6.9
Pod documented
1600 0 &Variable($name, $expr, global => 1, %options);
1601 }
1602  
1603 sub K(*;$%) # Define a constant variable.
1604 0 ▶ {my ($name, $expr, %options) = @_; # Name of variable, initializing expression, options
Subroutine K: not called CC=1 SCAR=6.9
Pod documented
1605 0 &Variable(@_, constant => 1, %options)
1606 }
1607  
1608 sub R(*) # Define a reference variable.
1609 0 ▶ {my ($name) = @_; # Name of variable
Subroutine R: not called CC=1 SCAR=6.9
Pod documented
1610 0 my $r = &Variable($name); # The referring variable is 64 bits wide
1611 0 $r->reference = 1; # Mark variable as a reference
1612 0 $r # Size of the referenced variable
1613 }
1614  
1615 sub V(*;$%) # Define a variable.
1616 0 ▶ {my ($name, $expr, %options) = @_; # Name of variable, initializing expression, options
Subroutine V: not called CC=1 SCAR=6.9
Pod documented
1617 0 &Variable(@_)
1618 }
1619  
1620 #D2 Print variables # Print the values of variables or the memory addressed by them
1621  
1622 sub Nasm::X86::Variable::dump($$$;$$) #P Dump the value of a variable to the specified channel adding an optional title and new line if requested.
1623 0 ▶ {my ($left, $channel, $newLine, $title1, $title2) = @_; # Left variable, channel, new line required, optional leading title, optional trailing title
Subroutine dump: not called CC=7 SCAR=40.3
1624 0 ▶ @_ >= 3 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 3 or confess() 0 0 0
1625 0 PushR my @regs = (rax, rdi);
1626 0 my $label = $left->label; # Address in memory
1627 0 Mov rax, "[$label]";
1628 0 ▶ Mov rax, "[rax]" if $left->reference;
Branch: 1 branch
BranchTrueFalseTotal
if $left->reference 0 0 0
1629 0 ▶ confess dump($channel) unless $channel =~ m(\A1|2\Z);
Branch: 1 branch
BranchTrueFalseTotal
unless $channel =~ /\A1|2\Z/ 0 0 0
1630 0 ▶ PrintString ($channel, $title1//$left->name.": ");
Condition0%0/2
$title1 // $left->name . ': '
l!l
00
MC/DC0%0/1
$title1 // $left->name . ': '
$title1
Truth table0%0/2
A
A= $title1
Aresult
11
00
1631 0 PrintRaxInHex($channel);
1632 0 ▶ PrintString ($channel, $title2) if defined $title2;
Branch: 1 branch
BranchTrueFalseTotal
if defined $title2 0 0 0
1633 0 ▶ PrintNL ($channel) if $newLine;
Branch: 1 branch
BranchTrueFalseTotal
if $newLine 0 0 0
1634 0 PopR @regs;
1635 }
1636  
1637 sub Nasm::X86::Variable::err($;$$) # Dump the value of a variable on stderr.
1638 0 ▶ {my ($left, $title1, $title2) = @_; # Left variable, optional leading title, optional trailing title
Subroutine err: not called CC=1 SCAR=6.9
1639 0 $left->dump($stderr, 0, $title1, $title2);
1640 }
1641  
1642 sub Nasm::X86::Variable::out($;$$) # Dump the value of a variable on stdout.
1643 0 ▶ {my ($left, $title1, $title2) = @_; # Left variable, optional leading title, optional trailing title
Subroutine out: not called CC=1 SCAR=6.9
1644 0 $left->dump($stdout, 0, $title1, $title2);
1645 }
1646  
1647 sub Nasm::X86::Variable::errNL($;$$) # Dump the value of a variable on stderr and append a new line.
1648 0 ▶ {my ($left, $title1, $title2) = @_; # Left variable, optional leading title, optional trailing title
Subroutine errNL: not called CC=1 SCAR=6.9
1649 0 $left->dump($stderr, 1, $title1, $title2);
1650 }
1651  
1652 sub Nasm::X86::Variable::d($;$$) # Dump the value of a variable on stderr and append a new line.
1653 0 ▶ {my ($left, $title1, $title2) = @_; # Left variable, optional leading title, optional trailing title
Subroutine d: not called CC=1 SCAR=6.9
1654 0 $left->dump($stderr, 1, $title1, $title2);
1655 }
1656  
1657 sub Nasm::X86::Variable::outNL($;$$) # Dump the value of a variable on stdout and append a new line.
1658 0 ▶ {my ($left, $title1, $title2) = @_; # Left variable, optional leading title, optional trailing title
Subroutine outNL: not called CC=1 SCAR=6.9
1659 0 $left->dump($stdout, 1, $title1, $title2);
1660 }
1661  
1662 sub Nasm::X86::Variable::debug($) # Dump the value of a variable on stdout with an indication of where the dump came from.
1663 0 ▶ {my ($left) = @_; # Left variable
Subroutine debug: not called CC=1 SCAR=6.9
1664 0 PushR my @regs = (rax, rdi);
1665 0 Mov rax, $left->label; # Address in memory
1666 0 Mov rax, "[rax]";
1667 0 &PrintErrString(pad($left->name, 32).": ");
1668 0 &PrintErrRaxInHex();
1669 0 my ($p, $f, $l) = caller(0); # Position of caller in file
1670 0 &PrintErrString(" at $f line $l");
1671 0 &PrintErrNL();
1672 0 PopR @regs;
1673 }
1674  
1675 sub Nasm::X86::Variable::printOutZeroString($) # Print the variable addressed zero terminated string on stdout.
1676 0 ▶ {my ($address) = @_; # Variable string address
Subroutine printOutZeroString: not called CC=1 SCAR=6.9
1677 0 PushR rax, rdi, r15;
1678 0 $address->setReg(rax); # Address of string
1679 0 &Cstrlen(); # Length of string
1680 0 Mov rdi, r15;
1681 0 &PrintOutMemoryNL(); # Print string
1682 0 PopR;
1683 }
1684  
1685 #D2 Operations # Variable operations
1686  
1687 1 if (1) # Define operator overloading for Variables
1688 {package Nasm::X86::Variable;
1689 use overload
1690 1 '+' => \&add,
1691 '-' => \&sub,
1692 '*' => \&times,
1693 '/' => \&divide,
1694 '%' => \&mod,
1695 '==' => \&eq,
1696 '!=' => \&ne,
1697 '>=' => \&ge,
1698 '>' => \&gt,
1699 '<=' => \&le,
1700 '<' => \&lt,
1701 '++' => \&inc,
1702 '--' => \&dec,
1703 '""' => \&str,
1704 # '&' => \&and, # We use the zero flag as the bit returned by a Boolean operation so we cannot implement & or | which were inuse becuase && and || an "and" and "or" are all disallowed in overloading.
1705 # '|' => \&or,
1706 '+=' => \&plusAssign,
1707 '-=' => \&minusAssign,
1708 '=' => \&equals,
1709 1 ▶ }
Subroutine BEGIN: called CC=1 SCAR=0.0
1710  
1711 sub Nasm::X86::Variable::address($;$) # Get the address of a variable with an optional offset.
1712 0 ▶ {my ($left, $offset) = @_; # Left variable, optional offset
Subroutine address: not called CC=2 SCAR=17.9
1713 0 ▶ my $o = $offset ? "+$offset" : "";
Branch: 1 branch
BranchTrueFalseTotal
$offset ? : 0 0 0
1714 0 "[".$left-> label."$o]"
1715 }
1716  
1717 sub Nasm::X86::Variable::copy($$;$) # Copy one variable into another.
1718 0 ▶ {my ($left, $right, $Transfer) = @_; # Left variable, right variable, optional transfer register
Subroutine copy: not called CC=11 SCAR=48.8
1719 0 ▶ @_ == 2 or @_ == 3 or confess "Two or three parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or @_ == 3 or confess("Two or three parameters") 0 0 0
Condition0%0/3
@_ == 2 or @_ == 3
l!l&&r!l&&!r
000
MC/DC0%0/2
@_ == 2 or @_ == 3
@_ == 2 @_ == 3
Truth table0%0/3
A or B
A= @_ == 2B= @_ == 3
ABresult
1X1
011
000
1720 0 ▶ CheckGeneralPurposeRegister $Transfer if $Transfer;
Branch: 1 branch
BranchTrueFalseTotal
if $Transfer 0 0 0
1721  
1722 0 ▶ my $transfer = $Transfer // r15; # Transfer register
Condition0%0/3
$Transfer // r15()
l!l&&r!l&&!r
000
MC/DC0%0/2
$Transfer // r15()
$Transfer r15()
Truth table0%0/3
A // B
A= $TransferB= r15()
ABresult
1X1
011
000
1723  
1724 # ref($right) =~ m(Variable) or confess "Variable required";
1725 0 my $l = $left ->address;
1726 0 ▶ my $r = ref($right) ? $right->address : $right; # Variable address or register expression (which might in fact be a constant)
Branch: 1 branch
BranchTrueFalseTotal
ref $right ? : 0 0 0
1727  
1728 0 ▶ PushR $transfer unless $Transfer;
Branch: 1 branch
BranchTrueFalseTotal
unless $Transfer 0 0 0
1729 0 Mov $transfer, $r; # Load right hand side
1730  
1731 0 ▶ if (ref($right) and $right->reference) # Dereference a reference
Branch: 1 branch
BranchTrueFalseTotal
if (ref $right and $right->reference) 0 0 0
Condition0%0/3
ref $right and $right->reference
!ll&&!rl&&r
000
MC/DC0%0/2
ref $right and $right->reference
ref $right $right->reference
Truth table0%0/3
A and B
A= ref $rightB= $right->reference
ABresult
0X0
100
111
1732 0 {Mov $transfer, "[$transfer]";
1733 }
1734  
1735 0 ▶ if ($left ->reference) # Copy a reference
Branch: 1 branch
BranchTrueFalseTotal
if ($left->reference) { } 0 0 0
1736 0 {my ($ref) = ChooseRegisters(1, $transfer);
1737 0 PushR $ref;
1738 0 Mov $ref, $l;
1739 0 Mov "[$ref]", $transfer;
1740 0 PopR $ref;
1741 }
1742 else # Copy a non reference
1743 0 {Mov $l, $transfer;
1744 }
1745 0 ▶ PopR $transfer unless $Transfer;
Branch: 1 branch
BranchTrueFalseTotal
unless $Transfer 0 0 0
1746 0 $left # Return the variable on the left now that it has had the right hand side copied into it.
1747 }
1748  
1749 sub Nasm::X86::Variable::copyRef($$;$) # Copy a reference to a variable.
1750 0 ▶ {my ($left, $right, $Transfer) = @_; # Left variable, right variable, optional transfer register
Subroutine copyRef: not called CC=7 SCAR=40.3
1751 0 ▶ CheckGeneralPurposeRegister $Transfer if $Transfer;
Branch: 1 branch
BranchTrueFalseTotal
if $Transfer 0 0 0
1752  
1753 0 ▶ my $transfer = $Transfer // r15;
Condition0%0/3
$Transfer // r15()
l!l&&r!l&&!r
000
MC/DC0%0/2
$Transfer // r15()
$Transfer r15()
Truth table0%0/3
A // B
A= $TransferB= r15()
ABresult
1X1
011
000
1754  
1755 0 ▶ $left->reference or confess "Left hand side must be a reference";
Branch: 1 branch
BranchTrueFalseTotal
$left->reference or confess("Left hand side must be a reference") 0 0 0
1756  
1757 0 my $l = $left ->address;
1758 0 my $r = $right->address;
1759  
1760 0 ▶ PushR $transfer unless $Transfer;
Branch: 1 branch
BranchTrueFalseTotal
unless $Transfer 0 0 0
1761 0 ▶ if ($right->reference) # Right is a reference so we copy its value to create a new reference to the original data
Branch: 1 branch
BranchTrueFalseTotal
if ($right->reference) { } 0 0 0
1762 0 {Mov $transfer, $r;
1763 }
1764 else # Right is not a reference so we copy its address to make a reference to the data
1765 0 {Lea $transfer, $r;
1766 }
1767 0 Mov $l, $transfer; # Save value of address in left
1768 0 ▶ PopR $transfer unless $Transfer;
Branch: 1 branch
BranchTrueFalseTotal
unless $Transfer 0 0 0
1769  
1770 0 $left; # Chain
1771 }
1772  
1773 sub Nasm::X86::Variable::copyZF($) # Copy the current state of the zero flag into a variable.
1774 0 ▶ {my ($var) = @_; # Variable
Subroutine copyZF: not called CC=2 SCAR=17.9
1775 0 ▶ @_ == 1 or confess "One parameter";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess("One parameter") 0 0 0
1776  
1777 0 my $a = $var->address; # Address of the variable
1778  
1779 0 PushR (rax);
1780 0 Lahf; # Save flags to ah: (SF:ZF:0:AF:0:PF:1:CF)
1781 0 Shr ah, 6; # Put zero flag in bit zero
1782 0 And ah, 1; # Isolate zero flag
1783 0 Mov $a, ah; # Save zero flag
1784 0 PopR;
1785 }
1786  
1787 sub Nasm::X86::Variable::copyZFInverted($) # Copy the opposite of the current state of the zero flag into a variable.
1788 0 ▶ {my ($var) = @_; # Variable
Subroutine copyZFInverted: not called CC=3 SCAR=24.8
1789 0 ▶ @_ == 1 or confess "One parameter";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess("One parameter") 0 0 0
1790  
1791 0 my $a = $var->address; # Address of the variable
1792  
1793 0 PushR (rax, r15);
1794 0 Lahf; # Save flags to ah: (SF:ZF:0:AF:0:PF:1:CF)
1795 0 Shr ah, 6; # Put zero flag in bit zero
1796 0 Not ah; # Invert zero flag
1797 0 And ah, 1; # Isolate zero flag
1798 0 ▶ if ($var->reference) # Dereference and save
Branch: 1 branch
BranchTrueFalseTotal
if ($var->reference) { } 0 0 0
1799 0 {PushR rdx;
1800 0 Mov rdx, $a;
1801 0 Mov "[rdx]", ah; # Save zero flag
1802 0 PopR rdx;
1803 }
1804 else # Save without dereferencing
1805 0 {Mov $a, ah; # Save zero flag
1806 }
1807 0 PopR;
1808 }
1809  
1810 sub Nasm::X86::Variable::equals($$$) # Equals operator.
1811 0 ▶ {my ($op, $left, $right) = @_; # Operator, left variable, right variable
Subroutine equals: not called CC=1 SCAR=6.9
1812 0 $op
1813 }
1814  
1815 sub Nasm::X86::Variable::assign($$$) # Assign to the left hand side the value of the right hand side.
1816 0 ▶ {my ($left, $op, $right) = @_; # Left variable, operator, right variable
Subroutine assign: not called CC=6 SCAR=37.4
1817 0 ▶ $left->constant and confess "cannot assign to a constant";
Branch: 1 branch
BranchTrueFalseTotal
$left->constant and confess("cannot assign to a constant") 0 0 0
1818  
1819 0 Comment "Variable assign";
1820 0 PushR (r14, r15);
1821 0 Mov r14, $left ->address;
1822 0 ▶ if ($left->reference) # Dereference left if necessary
Branch: 1 branch
BranchTrueFalseTotal
if ($left->reference) 0 0 0
1823 0 {Mov r14, "[r14]";
1824 }
1825 0 ▶ if (!ref($right)) # Load right constant
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $right) { } 0 0 0
1826 0 {Mov r15, $right;
1827 }
1828 else # Load right variable
1829 0 {Mov r15, $right->address;
1830 0 ▶ if ($right->reference) # Dereference right if necessary
Branch: 1 branch
BranchTrueFalseTotal
if ($right->reference) 0 0 0
1831 0 {Mov r15, "[r15]";
1832 }
1833 }
1834 0 &$op(r14, r15);
1835 0 ▶ if ($left->reference) # Store in reference on left if necessary
Branch: 1 branch
BranchTrueFalseTotal
if ($left->reference) { } 0 0 0
1836 0 {PushR r13;
1837 0 Mov r13, $left->address;
1838 0 Mov "[r13]", r14;
1839 0 PopR r13;
1840 }
1841 else # Store in variable
1842 0 {Mov $left ->address, r14;
1843 }
1844 0 PopR;
1845  
1846 0 $left;
1847 }
1848  
1849 sub Nasm::X86::Variable::plusAssign($$) # Implement plus and assign.
1850 0 ▶ {my ($left, $right) = @_; # Left variable, right variable
Subroutine plusAssign: not called CC=1 SCAR=6.9
1851 0 $left->assign(\&Add, $right);
1852 }
1853  
1854 sub Nasm::X86::Variable::minusAssign($$) # Implement minus and assign.
1855 0 ▶ {my ($left, $right) = @_; # Left variable, right variable
Subroutine minusAssign: not called CC=1 SCAR=6.9
1856 0 $left->assign(\&Sub, $right);
1857 }
1858  
1859 sub Nasm::X86::Variable::arithmetic($$$$) # Return a variable containing the result of an arithmetic operation on the left hand and right hand side variables.
1860 0 ▶ {my ($op, $name, $left, $right) = @_; # Operator, operator name, Left variable, right variable
Subroutine arithmetic: not called CC=6 SCAR=37.4
1861  
1862 0 my $l = $left ->address;
1863 0 ▶ my $r = ref($right) ? $right->address : $right; # Right can be either a variable reference or a constant
Branch: 1 branch
BranchTrueFalseTotal
ref $right ? : 0 0 0
1864  
1865 0 Comment "Arithmetic Start";
1866 0 PushR (r14, r15);
1867 0 Mov r15, $l;
1868 0 ▶ if ($left->reference) # Dereference left if necessary
Branch: 1 branch
BranchTrueFalseTotal
if ($left->reference) 0 0 0
1869 0 {Mov r15, "[r15]";
1870 }
1871 0 Mov r14, $r;
1872 0 ▶ if (ref($right) and $right->reference) # Dereference right if necessary
Branch: 1 branch
BranchTrueFalseTotal
if (ref $right and $right->reference) 0 0 0
Condition0%0/3
ref $right and $right->reference
!ll&&!rl&&r
000
MC/DC0%0/2
ref $right and $right->reference
ref $right $right->reference
Truth table0%0/3
A and B
A= ref $rightB= $right->reference
ABresult
0X0
100
111
1873 0 {Mov r14, "[r14]";
1874 }
1875 0 &$op(r15, r14);
1876 0 ▶ my $v = V(join(' ', '('.$left->name, $name, (ref($right) ? $right->name : $right).')'), r15);
Branch: 1 branch
BranchTrueFalseTotal
ref $right ? : 0 0 0
1877 0 PopR;
1878 0 Comment "Arithmetic End";
1879  
1880 0 return $v;
1881 }
1882  
1883 sub Nasm::X86::Variable::add($$) # Add the right hand variable to the left hand variable and return the result as a new variable.
1884 0 ▶ {my ($left, $right) = @_; # Left variable, right variable
Subroutine add: not called CC=1 SCAR=6.9
1885 0 Nasm::X86::Variable::arithmetic(\&Add, q(add), $left, $right);
1886 }
1887  
1888 sub Nasm::X86::Variable::sub($$) # Subtract the right hand variable from the left hand variable and return the result as a new variable.
1889 0 ▶ {my ($left, $right) = @_; # Left variable, right variable
Subroutine sub: not called CC=1 SCAR=6.9
1890 0 Nasm::X86::Variable::arithmetic(\&Sub, q(sub), $left, $right);
1891 }
1892  
1893 sub Nasm::X86::Variable::times($$) # Multiply the left hand variable by the right hand variable and return the result as a new variable.
1894 0 ▶ {my ($left, $right) = @_; # Left variable, right variable
Subroutine times: not called CC=1 SCAR=6.9
1895 0 Nasm::X86::Variable::arithmetic(\&Imul, q(times), $left, $right);
1896 }
1897  
1898 sub Nasm::X86::Variable::division($$$) # Return a variable containing the result or the remainder that occurs when the left hand side is divided by the right hand side.
1899 0 ▶ {my ($op, $left, $right) = @_; # Operator, Left variable, right variable
Subroutine division: not called CC=7 SCAR=40.3
1900  
1901 0 my $l = $left ->address;
1902 0 ▶ my $r = ref($right) ? $right->address : $right; # Right can be either a variable reference or a constant
Branch: 1 branch
BranchTrueFalseTotal
ref $right ? : 0 0 0
1903 0 PushR my @regs = (rax, rdx, r15);
1904 0 Mov rax, $l;
1905 0 ▶ Mov rax, "[rax]" if $left->reference;
Branch: 1 branch
BranchTrueFalseTotal
if $left->reference 0 0 0
1906 0 Mov r15, $r;
1907 0 ▶ Mov r15, "[r15]" if ref($right) and $right->reference;
Branch: 1 branch
BranchTrueFalseTotal
if ref $right and $right->reference 0 0 0
Condition0%0/3
ref $right and $right->reference
!ll&&!rl&&r
000
MC/DC0%0/2
ref $right and $right->reference
ref $right $right->reference
Truth table0%0/3
A and B
A= ref $rightB= $right->reference
ABresult
0X0
100
111
1908 0 Idiv r15;
1909 0 ▶ my $v = V(join(' ', '('.$left->name, $op, (ref($right) ? $right->name : '').')'), $op eq "%" ? rdx : rax);
Branch: 2 branches
BranchTrueFalseTotal
ref $right ? : 0 0 0
$op eq '%' ? : 0 0 0
1910 0 PopR @regs;
1911 0 $v;
1912 }
1913  
1914 sub Nasm::X86::Variable::divide($$) # Divide the left hand variable by the right hand variable and return the result as a new variable.
1915 0 ▶ {my ($left, $right) = @_; # Left variable, right variable
Subroutine divide: not called CC=1 SCAR=6.9
1916 0 Nasm::X86::Variable::division("/", $left, $right);
1917 }
1918  
1919 sub Nasm::X86::Variable::mod($$) # Divide the left hand variable by the right hand variable and return the remainder as a new variable.
1920 0 ▶ {my ($left, $right) = @_; # Left variable, right variable
Subroutine mod: not called CC=1 SCAR=6.9
1921 0 Nasm::X86::Variable::division("%", $left, $right);
1922 }
1923  
1924 sub Nasm::X86::Variable::boolean($$$$) # Combine the left hand variable with the right hand variable via a boolean operator.
1925 0 ▶ {my ($sub, $op, $left, $right) = @_; # Operator, operator name, Left variable, right variable
Subroutine boolean: not called CC=9 SCAR=45.0
1926  
1927 0 ▶ !ref($right) or ref($right) =~ m(Variable) or confess "Variable expected";
Branch: 1 branch
BranchTrueFalseTotal
not ref $right or ref($right) =~ /Variable/ or confess("Variable expected") 0 0 0
Condition0%0/3
not ref $right or ref($right) =~ /Variable/
l!l&&r!l&&!r
000
MC/DC0%0/2
not ref $right or ref($right) =~ /Variable/
not ref $right ref($right) =~ /Variable/
Truth table0%0/3
not(A) or B
A= not ref $rightB= ref($right) =~ /Variable/
ABresult
1X1
011
000
1928 0 ▶ my $r = ref($right) ? $right->address : $right; # Right can be either a variable reference or a constant
Branch: 1 branch
BranchTrueFalseTotal
ref $right ? : 0 0 0
1929  
1930 0 Comment "Boolean Arithmetic Start";
1931 0 PushR r15;
1932  
1933 0 Mov r15, $left ->address;
1934 0 ▶ if ($left->reference) # Dereference left if necessary
Branch: 1 branch
BranchTrueFalseTotal
if ($left->reference) 0 0 0
1935 0 {Mov r15, "[r15]";
1936 }
1937 0 ▶ if (ref($right) and $right->reference) # Dereference on right if necessary
Branch: 2 branches
BranchTrueFalseTotal
if (ref $right and $right->reference) { } 0 0 0
elsif (ref $right) { } 0 0 0
Condition0%0/3
ref $right and $right->reference
!ll&&!rl&&r
000
MC/DC0%0/2
ref $right and $right->reference
ref $right $right->reference
Truth table0%0/3
A and B
A= ref $rightB= $right->reference
ABresult
0X0
100
111
1938 0 {PushR r14;
1939 0 Mov r14, $right ->address;
1940 0 Mov r14, "[r14]";
1941 0 Cmp r15, r14;
1942 0 PopR r14;
1943 }
1944 elsif (ref($right)) # Variable but not a reference on the right
1945 0 {Cmp r15, $right->address;
1946 }
1947 else # Constant on the right
1948 0 {Cmp r15, $right;
1949 }
1950  
1951 0 ▶ &$sub(sub {Mov r15, 1}, sub {Mov r15, 0});
Subroutine __ANON__: not called CC=1 SCAR=6.9
1952 0 ▶ my $v = V(join(' ', '('.$left->name, $op, (ref($right) ? $right->name : '').')'), r15);
Branch: 1 branch
BranchTrueFalseTotal
ref $right ? : 0 0 0
1953  
1954 0 PopR r15;
1955 0 Comment "Boolean Arithmetic end";
1956  
1957 0 $v
1958 }
1959  
1960 sub Nasm::X86::Variable::booleanZF($$$$) # Combine the left hand variable with the right hand variable via a boolean operator and indicate the result by setting the zero flag if the result is true.
1961 0 ▶ {my ($sub, $op, $left, $right) = @_; # Operator, operator name, Left variable, right variable
Subroutine booleanZF: not called CC=8 SCAR=42.8
1962  
1963 0 ▶ !ref($right) or ref($right) =~ m(Variable) or confess "Variable expected";
Branch: 1 branch
BranchTrueFalseTotal
not ref $right or ref($right) =~ /Variable/ or confess("Variable expected") 0 0 0
Condition0%0/3
not ref $right or ref($right) =~ /Variable/
l!l&&r!l&&!r
000
MC/DC0%0/2
not ref $right or ref($right) =~ /Variable/
not ref $right ref($right) =~ /Variable/
Truth table0%0/3
not(A) or B
A= not ref $rightB= ref($right) =~ /Variable/
ABresult
1X1
011
000
1964 0 ▶ my $r = ref($right) ? $right->address : $right; # Right can be either a variable reference or a constant
Branch: 1 branch
BranchTrueFalseTotal
ref $right ? : 0 0 0
1965  
1966 0 Comment "Boolean ZF Arithmetic Start";
1967 0 PushR r15;
1968  
1969 0 Mov r15, $left ->address;
1970 0 ▶ if ($left->reference) # Dereference left if necessary
Branch: 1 branch
BranchTrueFalseTotal
if ($left->reference) 0 0 0
1971 0 {Mov r15, "[r15]";
1972 }
1973 0 ▶ if (ref($right) and $right->reference) # Dereference on right if necessary
Branch: 2 branches
BranchTrueFalseTotal
if (ref $right and $right->reference) { } 0 0 0
elsif (ref $right) { } 0 0 0
Condition0%0/3
ref $right and $right->reference
!ll&&!rl&&r
000
MC/DC0%0/2
ref $right and $right->reference
ref $right $right->reference
Truth table0%0/3
A and B
A= ref $rightB= $right->reference
ABresult
0X0
100
111
1974 0 {PushR r14;
1975 0 Mov r14, $right ->address;
1976 0 Mov r14, "[r14]";
1977 0 Cmp r15, r14;
1978 0 PopR r14;
1979 }
1980 elsif (ref($right)) # Variable but not a reference on the right
1981 0 {Cmp r15, $right->address;
1982 }
1983 else # Constant on the right
1984 0 {Cmp r15, $right;
1985 }
1986  
1987 0 ▶ &$sub(sub {Cmp rsp, rsp}, sub {Test rsp, rsp});
Subroutine __ANON__: not called CC=1 SCAR=6.9
1988  
1989 0 PopR r15;
1990 0 Comment "Boolean ZF Arithmetic end";
1991  
1992 0 V(empty); # Return an empty variable so that If regenerates the follow on code
1993 }
1994  
1995 sub Nasm::X86::Variable::booleanC($$$$) # Combine the left hand variable with the right hand variable via a boolean operator using a conditional move instruction.
1996 0 ▶ {my ($cmov, $op, $left, $right) = @_; # Conditional move instruction name, operator name, Left variable, right variable
Subroutine booleanC: not called CC=9 SCAR=45.0
1997  
1998 0 ▶ !ref($right) or ref($right) =~ m(Variable) or confess "Variable expected";
Branch: 1 branch
BranchTrueFalseTotal
not ref $right or ref($right) =~ /Variable/ or confess("Variable expected") 0 0 0
Condition0%0/3
not ref $right or ref($right) =~ /Variable/
l!l&&r!l&&!r
000
MC/DC0%0/2
not ref $right or ref($right) =~ /Variable/
not ref $right ref($right) =~ /Variable/
Truth table0%0/3
not(A) or B
A= not ref $rightB= ref($right) =~ /Variable/
ABresult
1X1
011
000
1999 0 ▶ my $r = ref($right) ? $right->address : $right; # Right can be either a variable reference or a constant
Branch: 1 branch
BranchTrueFalseTotal
ref $right ? : 0 0 0
2000  
2001 0 PushR r15;
2002 0 Mov r15, $left ->address;
2003 0 ▶ if ($left->reference) # Dereference left if necessary
Branch: 1 branch
BranchTrueFalseTotal
if ($left->reference) 0 0 0
2004 0 {Mov r15, "[r15]";
2005 }
2006 0 ▶ if (ref($right) and $right->reference) # Dereference on right if necessary
Branch: 2 branches
BranchTrueFalseTotal
if (ref $right and $right->reference) { } 0 0 0
elsif (ref $right) { } 0 0 0
Condition0%0/3
ref $right and $right->reference
!ll&&!rl&&r
000
MC/DC0%0/2
ref $right and $right->reference
ref $right $right->reference
Truth table0%0/3
A and B
A= ref $rightB= $right->reference
ABresult
0X0
100
111
2007 0 {PushR r14;
2008 0 Mov r14, $right ->address;
2009 0 Mov r14, "[r14]";
2010 0 Cmp r15, r14;
2011 0 PopR r14;
2012 }
2013 elsif (ref($right)) # Variable but not a reference on the right
2014 0 {Cmp r15, $right->address;
2015 }
2016 else # Constant on the right
2017 0 {Cmp r15, $right;
2018 }
2019  
2020 0 Mov r15, 1; # Place a one below the stack
2021 0 my $w = RegisterSize r15;
2022 0 Mov "[rsp-$w]", r15;
2023 0 Mov r15, 0; # Assume the result was false
2024 0 &$cmov(r15, "[rsp-$w]"); # Indicate true result
2025 0 ▶ my $v = V(join(' ', '('.$left->name, $op, (ref($right) ? $right->name : '').')'), r15);
Branch: 1 branch
BranchTrueFalseTotal
ref $right ? : 0 0 0
2026 0 PopR r15;
2027  
2028 0 $v
2029 }
2030  
2031 sub Nasm::X86::Variable::eq($$) # Check whether the left hand variable is equal to the right hand variable.
2032 0 ▶ {my ($left, $right) = @_; # Left variable, right variable
Subroutine eq: not called CC=1 SCAR=6.9
2033 0 Nasm::X86::Variable::booleanZF(\&IfEq, q(eq), $left, $right);
2034 }
2035  
2036 sub Nasm::X86::Variable::ne($$) # Check whether the left hand variable is not equal to the right hand variable.
2037 0 ▶ {my ($left, $right) = @_; # Left variable, right variable
Subroutine ne: not called CC=1 SCAR=6.9
2038 0 Nasm::X86::Variable::booleanZF(\&IfNe, q(ne), $left, $right);
2039 }
2040  
2041 sub Nasm::X86::Variable::ge($$) # Check whether the left hand variable is greater than or equal to the right hand variable.
2042 0 ▶ {my ($left, $right) = @_; # Left variable, right variable
Subroutine ge: not called CC=1 SCAR=6.9
2043 0 Nasm::X86::Variable::booleanZF(\&IfGe, q(ge), $left, $right);
2044 }
2045  
2046 sub Nasm::X86::Variable::gt($$) # Check whether the left hand variable is greater than the right hand variable.
2047 0 ▶ {my ($left, $right) = @_; # Left variable, right variable
Subroutine gt: not called CC=1 SCAR=6.9
2048 0 Nasm::X86::Variable::booleanZF(\&IfGt, q(gt), $left, $right);
2049 }
2050  
2051 sub Nasm::X86::Variable::le($$) # Check whether the left hand variable is less than or equal to the right hand variable.
2052 0 ▶ {my ($left, $right) = @_; # Left variable, right variable
Subroutine le: not called CC=1 SCAR=6.9
2053 0 Nasm::X86::Variable::booleanZF(\&IfLe, q(le), $left, $right);
2054 }
2055  
2056 sub Nasm::X86::Variable::lt($$) # Check whether the left hand variable is less than the right hand variable.
2057 0 ▶ {my ($left, $right) = @_; # Left variable, right variable
Subroutine lt: not called CC=1 SCAR=6.9
2058 0 Nasm::X86::Variable::booleanZF(\&IfLt, q(lt), $left, $right);
2059 }
2060  
2061 sub Nasm::X86::Variable::isRef($) # Check whether the specified variable is a reference to another variable.
2062 0 ▶ {my ($variable) = @_; # Variable
Subroutine isRef: not called CC=1 SCAR=6.9
2063 0 my $n = $variable->name; # Variable name
2064 0 $variable->reference
2065 }
2066  
2067 sub Nasm::X86::Variable::setReg($$) # Set the named registers from the content of the variable.
2068 0 ▶ {my ($variable, $register) = @_; # Variable, register to load
Subroutine setReg: not called CC=2 SCAR=17.9
2069  
2070 0 ▶ if ($variable->isRef)
Branch: 1 branch
BranchTrueFalseTotal
if ($variable->isRef) { } 0 0 0
2071 0 {Mov $register, $variable->address;
2072 0 Mov $register, "[$register]";
2073 }
2074 else
2075 0 {Mov $register, $variable->address;
2076 }
2077  
2078 0 $register
2079 }
2080  
2081 sub Nasm::X86::Variable::getReg($$@) # Load the variable from the named registers.
2082 0 ▶ {my ($variable, $register, @registers) = @_; # Variable, register to load, optional further registers to load from
Subroutine getReg: not called CC=4 SCAR=30.0
2083 0 ▶ if ($variable->isRef) # Move to the location referred to by this variable
Branch: 1 branch
BranchTrueFalseTotal
if ($variable->isRef) { } 0 0 0
2084 0 ▶ {$Registers{$register} or confess "No such register: $register"; # Check we have been given a register
Branch: 1 branch
BranchTrueFalseTotal
$Registers{$register} or confess("No such register: $register") 0 0 0
2085 0 Comment "Get variable value from register $register";
2086 0 ▶ my $r = $register eq r15 ? r14 : r15;
Branch: 1 branch
BranchTrueFalseTotal
$register eq r15() ? : 0 0 0
2087 0 PushR $r;
2088 0 Mov $r, $variable->address;
2089 0 Mov "[$r]", $register;
2090 0 PopR $r;
2091 }
2092 else # Move to this variable
2093 0 {Mov $variable->address, $register;
2094 }
2095 0 $variable # Chain
2096 }
2097  
2098 sub Nasm::X86::Variable::getConst($$;$) # Load the variable from a constant in effect setting a variable to a specified value.
2099 0 ▶ {my ($variable, $constant, $transfer) = @_; # Variable, constant to load, optional transfer register
Subroutine getConst: not called CC=2 SCAR=17.9
2100 0 ▶ if ($transfer)
Branch: 1 branch
BranchTrueFalseTotal
if ($transfer) { } 0 0 0
2101 0 {Mov $transfer, $constant;
2102 0 $variable->getReg($transfer);
2103 }
2104 else
2105 0 {PushR r15;
2106 0 Mov r15, $constant;
2107 0 $variable->getReg(r15);
2108 0 PopR;
2109 }
2110 }
2111  
2112 sub Nasm::X86::Variable::getConst22($$) # Load the variable from a constant in effect setting a variable to a specified value.
2113 0 ▶ {my ($variable, $constant) = @_; # Variable, constant to load
Subroutine getConst22: not called CC=1 SCAR=6.9
2114 0 PushR (r14, r15);
2115 0 Comment "Load constant $constant into variable: ".$variable->name;
2116 0 Mov r15, $constant;
2117 0 Lea r14, $variable->address;
2118 0 Mov "[r14]", r15;
2119 0 PopR;
2120 }
2121  
2122 sub Nasm::X86::Variable::incDec($$) # Increment or decrement a variable.
2123 0 ▶ {my ($left, $op) = @_; # Left variable operator, address of operator to perform inc or dec
Subroutine incDec: not called CC=3 SCAR=24.8
2124 0 ▶ $left->constant and confess "Cannot increment or decrement a constant";
Branch: 1 branch
BranchTrueFalseTotal
$left->constant and confess("Cannot increment or decrement a constant") 0 0 0
2125 0 my $l = $left->address;
2126 0 ▶ if ($left->reference)
Branch: 1 branch
BranchTrueFalseTotal
if ($left->reference) { } 0 0 0
2127 0 {PushR (r14, r15);
2128 0 Mov r15, $l;
2129 0 Mov r14, "[r15]";
2130 0 &$op(r14);
2131 0 Mov "[r15]", r14;
2132 0 PopR;
2133 0 return $left;
2134 }
2135 else
2136 0 {PushR r15;
2137 0 Mov r15, $l;
2138 0 &$op(r15);
2139 0 Mov $l, r15;
2140 0 PopR r15;
2141 0 return $left;
2142 }
2143 }
2144  
2145 sub Nasm::X86::Variable::inc($) # Increment a variable.
2146 0 ▶ {my ($left) = @_; # Variable
Subroutine inc: not called CC=1 SCAR=6.9
2147 0 $left->incDec(\&Inc);
2148 }
2149  
2150 sub Nasm::X86::Variable::dec($) # Decrement a variable.
2151 0 ▶ {my ($left) = @_; # Variable
Subroutine dec: not called CC=1 SCAR=6.9
2152 0 $left->incDec(\&Dec);
2153 }
2154  
2155 sub Nasm::X86::Variable::str($) # The name of the variable.
2156 0 ▶ {my ($left) = @_; # Variable
Subroutine str: not called CC=1 SCAR=6.9
2157 0 $left->name;
2158 }
2159  
2160 sub Nasm::X86::Variable::min($$) # Minimum of two variables.
2161 0 ▶ {my ($left, $right) = @_; # Left variable, right variable or constant
Subroutine min: not called CC=2 SCAR=17.9
2162 0 PushR (r12, r14, r15);
2163 0 $left->setReg(r14);
2164  
2165 0 ▶ if (ref($right)) # Right hand side is a variable
Branch: 1 branch
BranchTrueFalseTotal
if (ref $right) { } 0 0 0
2166 0 {$right->setReg(r15);
2167 }
2168 else # Right hand side is a constant
2169 0 {Mov r15, $right;
2170 }
2171  
2172 0 Cmp r14, r15;
2173 0 Cmovg r12, r15;
2174 0 Cmovle r12, r14;
2175 0 my $r = V("min", r12);
2176 0 PopR;
2177 0 $r
2178 }
2179  
2180 sub Nasm::X86::Variable::max($$) # Maximum of two variables.
2181 0 ▶ {my ($left, $right) = @_; # Left variable, right variable or constant
Subroutine max: not called CC=2 SCAR=17.9
2182 0 PushR (r12, r14, r15);
2183 0 $left->setReg(r14);
2184  
2185 0 ▶ if (ref($right)) # Right hand side is a variable
Branch: 1 branch
BranchTrueFalseTotal
if (ref $right) { } 0 0 0
2186 0 {$right->setReg(r15);
2187 }
2188 else # Right hand side is a constant
2189 0 {Mov r15, $right;
2190 }
2191  
2192 0 Cmp r14, r15;
2193 0 Cmovg r12, r14;
2194 0 Cmovle r12, r15;
2195  
2196 0 my $r = V("max", r12);
2197 0 PopR;
2198 0 $r
2199 }
2200  
2201 sub Nasm::X86::Variable::and($$) # And two variables.
2202 0 ▶ {my ($left, $right) = @_; # Left variable, right variable
Subroutine and: not called CC=1 SCAR=6.9
2203 0 PushR (r14, r15);
2204 0 Mov r14, 0;
2205 0 $left->setReg(r15);
2206 0 Cmp r15, 0;
2207 &IfNe (
2208 sub
2209 0 ▶ {$right->setReg(r15);
Subroutine __ANON__: not called CC=1 SCAR=6.9
2210 0 Cmp r15, 0;
2211 0 ▶ &IfNe(sub {Add r14, 1});
Subroutine __ANON__: not called CC=1 SCAR=6.9
2212 }
2213 0 );
2214 0 my $r = V("And(".$left->name.", ".$right->name.")", r14);
2215 0 PopR;
2216 0 $r
2217 }
2218  
2219 sub Nasm::X86::Variable::or($$) # Or two variables.
2220 0 ▶ {my ($left, $right) = @_; # Left variable, right variable
Subroutine or: not called CC=1 SCAR=6.9
2221 0 PushR (r14, r15);
2222 0 Mov r14, 1;
2223 0 $left->setReg(r15);
2224 0 Cmp r15, 0;
2225 &IfEq (
2226 sub
2227 0 ▶ {$right->setReg(r15);
Subroutine __ANON__: not called CC=1 SCAR=6.9
2228 0 Cmp r15, 0;
2229 0 ▶ &IfEq(sub {Mov r14, 0});
Subroutine __ANON__: not called CC=1 SCAR=6.9
2230 }
2231 0 );
2232 0 my $r = V("Or(".$left->name.", ".$right->name.")", r14);
2233 0 PopR;
2234 0 $r
2235 }
2236  
2237 sub Nasm::X86::Variable::setMask($$$) # Set the mask register to ones starting at the specified position for the specified length and zeroes elsewhere.
2238 0 ▶ {my ($start, $length, $mask) = @_; # Variable containing start of mask, variable containing length of mask, mask register
Subroutine setMask: not called CC=4 SCAR=30.0
2239 0 ▶ @_ == 3 or confess "Three parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess("Three parameters") 0 0 0
2240  
2241 0 PushR (r13, r14, r15);
2242 0 Mov r15, -1;
2243 0 ▶ if ($start) # Non zero start
Branch: 1 branch
BranchTrueFalseTotal
if ($start) { } 0 0 0
2244 0 {$start->setReg(r14);
2245 0 Bzhi r15, r15, r14;
2246 0 Not r15;
2247 0 ▶ ref($length) or confess "Not a variable";
Branch: 1 branch
BranchTrueFalseTotal
ref $length or confess("Not a variable") 0 0 0
2248 0 $length->setReg(r13);
2249 0 Add r14, r13;
2250 }
2251 else # Starting at zero
2252 0 {confess "Deprecated: use setMaskFirst instead";
2253 0 $length->setReg(r13);
2254 0 Mov r14, $length;
2255 }
2256 0 Bzhi r15, r15, r14;
2257 0 Kmovq $mask, r15;
2258 0 PopR;
2259 }
2260  
2261 sub Nasm::X86::Variable::setMaskFirst($$) # Set the first bits in the specified mask register.
2262 0 ▶ {my ($length, $mask) = @_; # Variable containing length to set, mask register
Subroutine setMaskFirst: not called CC=4 SCAR=30.0
2263 0 ▶ @_ == 2 or confess "Two parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess("Two parameters") 0 0 0
2264  
2265 0 PushR my @save = my ($l, $b) = ChooseRegisters(2, $mask); # Choose two registers not the mask register
2266 0 Mov $b, -1;
2267 0 $length->setReg($l);
2268 0 Bzhi $b, $b, $l;
2269 0 ▶ Kmovq $mask, $b if $mask =~ m(\Ak)i; # Set mask register if provided
Branch: 1 branch
BranchTrueFalseTotal
if $mask =~ /\Ak/i 0 0 0
2270 0 ▶ Mov $mask, $b if $mask =~ m(\Ar)i; # Set general purpose register if provided
Branch: 1 branch
BranchTrueFalseTotal
if $mask =~ /\Ar/i 0 0 0
2271 0 PopR;
2272 }
2273  
2274 sub Nasm::X86::Variable::setMaskBit($$) # Set a bit in the specified mask register retaining the other bits.
2275 0 ▶ {my ($index, $mask) = @_; # Variable containing bit position to set, mask register
Subroutine setMaskBit: not called CC=3 SCAR=24.8
2276 0 ▶ @_ == 2 or confess "Two parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess("Two parameters") 0 0 0
2277 0 ▶ $mask =~ m(\Ak)i or confess "Mask register required";
Branch: 1 branch
BranchTrueFalseTotal
$mask =~ /\Ak/i or confess("Mask register required") 0 0 0
2278 0 PushR my @save = my ($l, $b) = (r14, r15);
2279 0 Kmovq $b, $mask;
2280 0 $index->setReg($l);
2281 0 Bts $b, $l;
2282 0 Kmovq $mask, $b; # Set mask register if provided
2283 0 PopR;
2284 }
2285  
2286 sub Nasm::X86::Variable::clearMaskBit($$) # Clear a bit in the specified mask register retaining the other bits.
2287 0 ▶ {my ($index, $mask) = @_; # Variable containing bit position to clear, mask register
Subroutine clearMaskBit: not called CC=3 SCAR=24.8
2288 0 ▶ @_ == 2 or confess "Two parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess("Two parameters") 0 0 0
2289 0 ▶ $mask =~ m(\Ak)i or confess "Mask register required";
Branch: 1 branch
BranchTrueFalseTotal
$mask =~ /\Ak/i or confess("Mask register required") 0 0 0
2290  
2291 0 PushR my @save = my ($l, $b) = (r14, r15);
2292 0 Kmovq $b, $mask;
2293 0 $index->setReg($l);
2294 0 Btc $b, $l;
2295 0 Kmovq $mask, $b; # Set mask register if provided
2296 0 PopR;
2297 }
2298  
2299 sub Nasm::X86::Variable::setBit($$) # Set a bit in the specified register retaining the other bits.
2300 0 ▶ {my ($index, $mask) = @_; # Variable containing bit position to set, mask register
Subroutine setBit: not called CC=2 SCAR=17.9
2301 0 ▶ @_ == 2 or confess "Two parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess("Two parameters") 0 0 0
2302  
2303 0 PushR my @save = my ($l) = ChooseRegisters(1, $mask); # Choose a register
2304 0 $index->setReg($l);
2305 0 Bts $mask, $l;
2306 0 PopR;
2307 }
2308  
2309 sub Nasm::X86::Variable::clearBit($$) # Clear a bit in the specified mask register retaining the other bits.
2310 0 ▶ {my ($index, $mask) = @_; # Variable containing bit position to clear, mask register
Subroutine clearBit: not called CC=2 SCAR=17.9
2311 0 ▶ @_ == 2 or confess "Two parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess("Two parameters") 0 0 0
2312  
2313 0 PushR my @save = my ($l) = ChooseRegisters(1, $mask); # Choose a register
2314 0 $index->setReg($l);
2315 0 Btc $mask, $l;
2316 0 PopR;
2317 }
2318  
2319 sub Nasm::X86::Variable::setZmm($$$$) # Load bytes from the memory addressed by specified source variable into the numbered zmm register at the offset in the specified offset moving the number of bytes in the specified variable.
2320 0 ▶ {my ($source, $zmm, $offset, $length) = @_; # Variable containing the address of the source, number of zmm to load, variable containing offset in zmm to move to, variable containing length of move
Subroutine setZmm: not called CC=4 SCAR=30.0
2321 0 ▶ @_ == 4 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 4 or confess() 0 0 0
2322 0 ▶ ref($offset) && ref($length) or confess "Missing variable"; # Need variables of offset and length
Branch: 1 branch
BranchTrueFalseTotal
ref $offset and ref $length or confess("Missing variable") 0 0 0
Condition0%0/3
ref $offset and ref $length
!ll&&!rl&&r
000
MC/DC0%0/2
ref $offset and ref $length
ref $offset ref $length
Truth table0%0/3
A and B
A= ref $offsetB= ref $length
ABresult
0X0
100
111
2323 0 Comment "Set Zmm $zmm from Memory";
2324 0 PushR (k7, r14, r15);
2325 0 $offset->setMask($length, k7); # Set mask for target
2326 0 $source->setReg(r15);
2327 0 $offset->setReg(r14); # Position memory for target
2328 0 Sub r15, r14; # Position memory for target
2329 0 Vmovdqu8 "zmm${zmm}{k7}", "[r15]"; # Read from memory
2330 0 PopR;
2331 }
2332  
2333 sub Nasm::X86::Variable::loadZmm($$) # Load bytes from the memory addressed by the specified source variable into the numbered zmm register.
2334 0 ▶ {my ($source, $zmm) = @_; # Variable containing the address of the source, number of zmm to get
Subroutine loadZmm: not called CC=4 SCAR=30.0
2335 0 ▶ @_ == 2 or confess "Two parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess("Two parameters") 0 0 0
2336 0 ▶ if ($source->size == 3) # Load through memory addressed by a Vq
Branch: 2 branches
BranchTrueFalseTotal
if ($source->size == 3) { } 0 0 0
elsif ($source->size == 6) { } 0 0 0
2337 0 {Comment "Load zmm$zmm from memory addressed by ".$source->name;
2338 0 PushR r15;
2339 0 $source->setReg(r15);
2340 0 Vmovdqu8 "zmm$zmm", "[r15]";
2341 0 PopR r15;
2342 }
2343 elsif ($source->size == 6) # Load from Vz
2344 0 {Comment "Load zmm$zmm from ".$source->name;
2345 0 Vmovdqu8 "zmm$zmm", $source->address;
2346 }
2347 }
2348  
2349 sub loadFromZmm($*$$) # Load the specified register from the offset located in the numbered zmm.
2350 0 ▶ {my ($register, $size, $zmm, $offset) = @_; # Register to load, "b|w|d|q" for size, numbered zmm register to load from, constant offset in bytes
Subroutine loadFromZmm: not called CC=9 SCAR=45.0
Pod documented
2351 0 ▶ @_ == 4 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 4 or confess() 0 0 0
2352 0 ▶ $offset >= 0 && $offset <= RegisterSize zmm0 or confess "Out of range";
Branch: 1 branch
BranchTrueFalseTotal
$offset >= 0 and $offset <= &RegisterSize(scalar zmm0()) or confess("Out of range") 0 0 0
Condition0%0/3
$offset >= 0 and $offset <= &RegisterSize(scalar zmm0())
!ll&&!rl&&r
000
MC/DC0%0/2
$offset >= 0 and $offset <= &RegisterSize(scalar zmm0())
$offset >= 0 $offset <= &RegisterSize(scalar zmm0())
Truth table0%0/3
A and B
A= $offset >= 0B= $offset <= &RegisterSize(scalar zmm0())
ABresult
0X0
100
111
2353  
2354 0 ▶ $register =~ m(\Ar\d+) or confess "Choose r8..r15 not $register";
Branch: 1 branch
BranchTrueFalseTotal
$register =~ /\Ar\d+/ or confess("Choose r8..r15 not $register") 0 0 0
2355  
2356 0 PushRR "zmm$zmm"; # Push source register
2357  
2358 0 ClearRegisters $register;
2359  
2360 0 ▶ Mov $register."b", "[rsp+$offset]" if $size =~ m(b); # Load byte register from offset
Branch: 1 branch
BranchTrueFalseTotal
if $size =~ /b/ 0 0 0
2361 0 ▶ Mov $register."w", "[rsp+$offset]" if $size =~ m(w); # Load word register from offset
Branch: 1 branch
BranchTrueFalseTotal
if $size =~ /w/ 0 0 0
2362 0 ▶ Mov $register."d", "[rsp+$offset]" if $size =~ m(d); # Load double word register from offset
Branch: 1 branch
BranchTrueFalseTotal
if $size =~ /d/ 0 0 0
2363 0 ▶ Mov $register, "[rsp+$offset]" if $size =~ m(q); # Load register from offset
Branch: 1 branch
BranchTrueFalseTotal
if $size =~ /q/ 0 0 0
2364 0 Add rsp, RegisterSize "zmm$zmm"; # Pop source register
2365 }
2366  
2367 sub putIntoZmm($*$$) # Put the specified register into the numbered zmm at the specified offset in the zmm.
2368 0 ▶ {my ($register, $size, $zmm, $offset) = @_; # Register to load, bwdq for size, numbered zmm register to load from, constant offset in bytes
Subroutine putIntoZmm: not called CC=8 SCAR=42.8
Pod documented
2369 0 ▶ @_ == 4 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 4 or confess() 0 0 0
2370 0 ▶ $offset >= 0 && $offset <= RegisterSize zmm0 or confess "Out of range";
Branch: 1 branch
BranchTrueFalseTotal
$offset >= 0 and $offset <= &RegisterSize(scalar zmm0()) or confess("Out of range") 0 0 0
Condition0%0/3
$offset >= 0 and $offset <= &RegisterSize(scalar zmm0())
!ll&&!rl&&r
000
MC/DC0%0/2
$offset >= 0 and $offset <= &RegisterSize(scalar zmm0())
$offset >= 0 $offset <= &RegisterSize(scalar zmm0())
Truth table0%0/3
A and B
A= $offset >= 0B= $offset <= &RegisterSize(scalar zmm0())
ABresult
0X0
100
111
2371  
2372 0 PushR "zmm$zmm"; # Push source register
2373  
2374 0 ▶ Mov "[rsp+$offset]", $register."b" if $size =~ m(b); # Load byte register from offset
Branch: 1 branch
BranchTrueFalseTotal
if $size =~ /b/ 0 0 0
2375 0 ▶ Mov "[rsp+$offset]", $register."w" if $size =~ m(w); # Load word register from offset
Branch: 1 branch
BranchTrueFalseTotal
if $size =~ /w/ 0 0 0
2376 0 ▶ Mov "[rsp+$offset]", $register."d" if $size =~ m(d); # Load double word register from offset
Branch: 1 branch
BranchTrueFalseTotal
if $size =~ /d/ 0 0 0
2377 0 ▶ Mov "[rsp+$offset]", $register, if $size =~ m(q); # Load register from offset
Branch: 1 branch
BranchTrueFalseTotal
if $size =~ /q/ 0 0 0
2378 0 PopR "zmm$zmm"; # Reload zmm
2379 }
2380  
2381 sub LoadRegFromMm($$$) # Load the specified register from the numbered zmm at the quad offset specified as a constant number.
2382 0 ▶ {my ($mm, $offset, $reg) = @_; # Mm register, offset in quads, general purpose register to load
Subroutine LoadRegFromMm: not called CC=2 SCAR=17.9
Pod documented
2383 0 ▶ @_ == 3 or confess "Three parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess("Three parameters") 0 0 0
2384 0 my $w = RegisterSize $mm; # Size of mm register
2385 0 Vmovdqu64 "[rsp-$w]", $mm; # Write below the stack
2386 0 Mov $reg, "[rsp+8*$offset-$w]"; # Load register from offset
2387 }
2388  
2389 sub SaveRegIntoMm($$$) # Save the specified register into the numbered zmm at the quad offset specified as a constant number.
2390 0 ▶ {my ($mm, $offset, $reg) = @_; # Mm register, offset in quads, general purpose register to load
Subroutine SaveRegIntoMm: not called CC=2 SCAR=17.9
Pod documented
2391 0 ▶ @_ == 3 or confess "Three parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess("Three parameters") 0 0 0
2392 0 my $w = RegisterSize $mm; # Size of mm register
2393 0 Vmovdqu64 "[rsp-$w]", $mm; # Write below the stack
2394 0 Mov "[rsp+8*$offset-$w]", $reg; # Save register into offset
2395 0 Vmovdqu64 $mm, "[rsp-$w]"; # Reload from the stack
2396 }
2397  
2398 sub getBwdqFromMm($$$;$$) # Get the numbered byte|word|double word|quad word from the numbered zmm register and return it in a variable.
2399 0 ▶ {my ($size, $mm, $offset, $Transfer, $target) = @_; # Size of get, mm register, offset in bytes either as a constant or as a variable, optional transfer register, optional target variable - if none supplied we create a variable
Subroutine getBwdqFromMm: not called CC=22 SCAR=62.3
Pod documented
2400 0 ▶ @_ == 3 or @_ == 4 or @_ == 5 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or @_ == 4 or @_ == 5 or confess() 0 0 0
Condition0%0/6
@_ == 3 or @_ == 4 or @_ == 5
l!l&&r!l&&!r
000
@_ == 3 or @_ == 4
l!l&&r!l&&!r
000
MC/DC0%0/3
@_ == 3 or @_ == 4 or @_ == 5
@_ == 3 @_ == 4 @_ == 5
Truth table0%0/4
A or B or C
A= @_ == 3B= @_ == 4C= @_ == 5
ABCresult
1XX1
01X1
0011
0000
2401 0 my $w = RegisterSize $mm; # Size of mm register
2402 0 ▶ CheckNumberedGeneralPurposeRegister $Transfer if $Transfer; # Check that we have a numbered register
Branch: 1 branch
BranchTrueFalseTotal
if $Transfer 0 0 0
2403 0 ▶ my $transfer = $Transfer // r15; # Register to use to transfer value to variable
Condition0%0/3
$Transfer // r15()
l!l&&r!l&&!r
000
MC/DC0%0/2
$Transfer // r15()
$Transfer r15()
Truth table0%0/3
A // B
A= $TransferB= r15()
ABresult
1X1
011
000
2404  
2405 0 my $o; # The offset into the mm register
2406 0 ▶ if (ref($offset)) # The offset is being passed in a variable
Branch: 1 branch
BranchTrueFalseTotal
if (ref $offset) { } 0 0 0
2407 0 {my $name = $offset->name;
2408 0 PushR ($o = r14);
2409 0 $offset->setReg($o);
2410 }
2411 else # The offset is being passed as a register expression
2412 0 {$o = $offset;
2413 0 ▶ $offset >= 0 && $offset <= RegisterSize $mm or
Branch: 1 branch
BranchTrueFalseTotal
if $offset =~ /\A\d+\Z/ 0 0 0
Condition0%0/9
$offset =~ /\A\d+\Z/ && ($offset >= 0 && $offset <= &RegisterSize($mm) || confess('Out of range'))
!ll&&!rl&&r
000
$offset >= 0 and $offset <= &RegisterSize($mm) or confess("Out of range")
l!l&&r!l&&!r
000
$offset >= 0 and $offset <= &RegisterSize($mm)
!ll&&!rl&&r
000
MC/DC0%0/4
$offset =~ /\A\d+\Z/ && ($offset >= 0 && $offset <= &RegisterSize($mm) || confess('Out of range'))
$offset =~ /\A\d+\Z/ $offset >= 0 $offset <= &RegisterSize($mm) confess("Out of range")
Truth table0%0/6
A && B and C or D
A= $offset =~ /\A\d+\Z/B= $offset >= 0C= $offset <= &RegisterSize($mm)D= confess("Out of range")
ABCDresult
0XXX0
10X00
11000
111X1
10X11
11011
2414 confess "Out of range" if $offset =~ m(\A\d+\Z); # Check the offset if it is a number
2415 0 ▶ $offset =~ m(r15) and
Branch: 1 branch
BranchTrueFalseTotal
$offset =~ /r15/ and confess("Cannot pass offset: '${offset}', in r15, choose another register") 0 0 0
2416 confess "Cannot pass offset: '$offset', in r15, choose another register";
2417 }
2418  
2419 0 ▶ PushR $transfer unless $Transfer;
Branch: 1 branch
BranchTrueFalseTotal
unless $Transfer 0 0 0
2420 0 Vmovdqu32 "[rsp-$w]", $mm; # Write below the stack
2421  
2422 0 ▶ if ($size !~ m(q|d)) # Clear the register if necessary
Branch: 1 branch
BranchTrueFalseTotal
unless ($size =~ /q|d/) 0 0 0
2423 0 {ClearRegisters r15;
2424 }
2425  
2426 0 ▶ Mov $transfer."b", "[rsp+$o-$w]" if $size =~ m(b); # Load byte register from offset
Branch: 1 branch
BranchTrueFalseTotal
if $size =~ /b/ 0 0 0
2427 0 ▶ Mov $transfer."w", "[rsp+$o-$w]" if $size =~ m(w); # Load word register from offset
Branch: 1 branch
BranchTrueFalseTotal
if $size =~ /w/ 0 0 0
2428 0 ▶ Mov $transfer."d", "[rsp+$o-$w]" if $size =~ m(d); # Load double word register from offset
Branch: 1 branch
BranchTrueFalseTotal
if $size =~ /d/ 0 0 0
2429 0 ▶ Mov $transfer, "[rsp+$o-$w]" if $size =~ m(q); # Load register from offset
Branch: 1 branch
BranchTrueFalseTotal
if $size =~ /q/ 0 0 0
2430  
2431 0 ▶ if ($Transfer and $target) # Optimized load
Branch: 1 branch
BranchTrueFalseTotal
if ($Transfer and $target) { } 0 0 0
Condition0%0/3
$Transfer and $target
!ll&&!rl&&r
000
MC/DC0%0/2
$Transfer and $target
$Transfer $target
Truth table0%0/3
A and B
A= $TransferB= $target
ABresult
0X0
100
111
2432 0 {$target->getReg($transfer); # Load variable directly
2433 0 ▶ PopR $o if ref($offset); # The offset is being passed in a variable
Branch: 1 branch
BranchTrueFalseTotal
if ref $offset 0 0 0
2434 0 return $target; # Return variable
2435 }
2436 else # Unable to optimize load
2437 0 {my $v = V("$size at offset $offset in $mm", $transfer); # Create variable
2438 0 ▶ PopR $transfer unless $Transfer;
Branch: 1 branch
BranchTrueFalseTotal
unless $Transfer 0 0 0
2439 0 ▶ PopR $o if ref($offset); # The offset is being passed in a variable
Branch: 1 branch
BranchTrueFalseTotal
if ref $offset 0 0 0
2440 0 return $v # Return variable
2441 }
2442 }
2443  
2444 sub getBFromXmm($$) # Get the byte from the numbered xmm register and return it in a variable.
2445 0 ▶ {my ($xmm, $offset) = @_; # Numbered xmm, offset in bytes
Subroutine getBFromXmm: not called CC=1 SCAR=6.9
Pod documented
2446 0 getBwdqFromMm('b', "xmm$xmm", $offset) # Get the numbered byte|word|double word|quad word from the numbered xmm register and return it in a variable
2447 }
2448  
2449 sub getWFromXmm($$) # Get the word from the numbered xmm register and return it in a variable.
2450 0 ▶ {my ($xmm, $offset) = @_; # Numbered xmm, offset in bytes
Subroutine getWFromXmm: not called CC=1 SCAR=6.9
Pod documented
2451 0 getBwdqFromMm('w', "xmm$xmm", $offset) # Get the numbered byte|word|double word|quad word from the numbered xmm register and return it in a variable
2452 }
2453  
2454 sub getDFromXmm($$) # Get the double word from the numbered xmm register and return it in a variable.
2455 0 ▶ {my ($xmm, $offset) = @_; # Numbered xmm, offset in bytes
Subroutine getDFromXmm: not called CC=1 SCAR=6.9
Pod documented
2456 0 getBwdqFromMm('d', "xmm$xmm", $offset) # Get the numbered byte|word|double word|quad word from the numbered xmm register and return it in a variable
2457 }
2458  
2459 sub getQFromXmm($$) # Get the quad word from the numbered xmm register and return it in a variable.
2460 0 ▶ {my ($xmm, $offset) = @_; # Numbered xmm, offset in bytes
Subroutine getQFromXmm: not called CC=1 SCAR=6.9
Pod documented
2461 0 getBwdqFromMm('q', "xmm$xmm", $offset) # Get the numbered byte|word|double word|quad word from the numbered xmm register and return it in a variable
2462 }
2463  
2464 sub getBFromZmm($$) # Get the byte from the numbered zmm register and return it in a variable.
2465 0 ▶ {my ($zmm, $offset) = @_; # Numbered zmm, offset in bytes
Subroutine getBFromZmm: not called CC=1 SCAR=6.9
Pod documented
2466 0 getBwdqFromMm('b', "zmm$zmm", $offset) # Get the numbered byte|word|double word|quad word from the numbered zmm register and return it in a variable
2467 }
2468  
2469 sub getWFromZmm($$) # Get the word from the numbered zmm register and return it in a variable.
2470 0 ▶ {my ($zmm, $offset) = @_; # Numbered zmm, offset in bytes
Subroutine getWFromZmm: not called CC=1 SCAR=6.9
Pod documented
2471 0 getBwdqFromMm('w', "zmm$zmm", $offset) # Get the numbered byte|word|double word|quad word from the numbered zmm register and return it in a variable
2472 }
2473  
2474 sub getDFromZmm($$$) # Get the double word from the numbered zmm register and return it in a variable.
2475 0 ▶ {my ($zmm, $offset, $transfer) = @_; # Numbered zmm, offset in bytes, optional transfer register
Subroutine getDFromZmm: not called CC=1 SCAR=6.9
Pod documented
2476 0 getBwdqFromMm('d', "zmm$zmm", $offset, $transfer) # Get the numbered byte|word|double word|quad word from the numbered zmm register and return it in a variable
2477 }
2478  
2479 sub getQFromZmm($$) # Get the quad word from the numbered zmm register and return it in a variable.
2480 0 ▶ {my ($zmm, $offset) = @_; # Numbered zmm, offset in bytes
Subroutine getQFromZmm: not called CC=1 SCAR=6.9
Pod documented
2481 0 getBwdqFromMm('q', "zmm$zmm", $offset) # Get the numbered byte|word|double word|quad word from the numbered zmm register and return it in a variable
2482 }
2483  
2484 sub Nasm::X86::Variable::getBFromZmm($$$) # Get the byte from the numbered zmm register and put it in a variable.
2485 0 ▶ {my ($variable, $zmm, $offset) = @_; # Variable, numbered zmm, offset in bytes
Subroutine getBFromZmm: not called CC=1 SCAR=6.9
2486 0 $variable->copy(getBwdqFromMm('b', "zmm$zmm", $offset)) # Get the numbered byte|word|double word|quad word from the numbered zmm register and put it in a variable
2487 }
2488  
2489 sub Nasm::X86::Variable::getWFromZmm($$$) # Get the word from the numbered zmm register and put it in a variable.
2490 0 ▶ {my ($variable, $zmm, $offset) = @_; # Variable, numbered zmm, offset in bytes
Subroutine getWFromZmm: not called CC=1 SCAR=6.9
2491 0 $variable->copy(getBwdqFromMm('w', "zmm$zmm", $offset)) # Get the numbered byte|word|double word|quad word from the numbered zmm register and put it in a variable
2492 }
2493  
2494 sub Nasm::X86::Variable::getDFromZmm($$$;$) # Get the double word from the numbered zmm register and put it in a variable.
2495 0 ▶ {my ($variable, $zmm, $offset, $transfer) = @_; # Variable, numbered zmm, offset in bytes, transfer register
Subroutine getDFromZmm: not called CC=1 SCAR=6.9
2496 0 getBwdqFromMm 'd', "zmm$zmm", $offset, $transfer, $variable; # Get the numbered byte|word|double word|quad word from the numbered zmm register and put it in a variable
2497 0 $variable # Return input variable so we can assign or chain
2498 }
2499  
2500 sub Nasm::X86::Variable::getQFromZmm($$$) # Get the quad word from the numbered zmm register and put it in a variable.
2501 0 ▶ {my ($variable, $zmm, $offset) = @_; # Variable, numbered zmm, offset in bytes
Subroutine getQFromZmm: not called CC=1 SCAR=6.9
2502 0 $variable->copy(getBwdqFromMm('q', "zmm$zmm", $offset)) # Get the numbered byte|word|double word|quad word from the numbered zmm register and put it in a variable
2503 }
2504  
2505 sub Nasm::X86::Variable::putBwdqIntoMm($$$$;$) # Place the value of the content variable at the byte|word|double word|quad word in the numbered zmm register.
2506 0 ▶ {my ($content, $size, $mm, $offset, $Transfer) = @_; # Variable with content, size of put, numbered zmm, offset in bytes, optional transfer register
Subroutine putBwdqIntoMm: not called CC=16 SCAR=56.1
2507 0 ▶ @_ == 4 or @_ == 5 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 4 or @_ == 5 or confess() 0 0 0
Condition0%0/3
@_ == 4 or @_ == 5
l!l&&r!l&&!r
000
MC/DC0%0/2
@_ == 4 or @_ == 5
@_ == 4 @_ == 5
Truth table0%0/3
A or B
A= @_ == 4B= @_ == 5
ABresult
1X1
011
000
2508 0 ▶ CheckNumberedGeneralPurposeRegister $Transfer if $Transfer;
Branch: 1 branch
BranchTrueFalseTotal
if $Transfer 0 0 0
2509 0 my $w = RegisterSize $mm; # Size of mm register
2510 0 my ($temp) = ChooseRegisters(1, r14);
2511 0 ▶ my $transfer = $Transfer // $temp;
Condition0%0/3
$Transfer // $temp
l!l&&r!l&&!r
000
MC/DC0%0/2
$Transfer // $temp
$Transfer $temp
Truth table0%0/3
A // B
A= $TransferB= $temp
ABresult
1X1
011
000
2512 0 my $o; # The offset into the mm register
2513  
2514 0 ▶ if (ref($offset)) # The offset is being passed in a variable
Branch: 1 branch
BranchTrueFalseTotal
if (ref $offset) { } 0 0 0
2515 0 {my $name = $offset->name;
2516 0 Comment "Put $size at $name in $mm";
2517 0 PushR ($o = r14);
2518 0 $offset->setReg($o);
2519 }
2520 else # The offset is being passed as a register expression
2521 0 {$o = $offset;
2522 0 Comment "Put $size at $offset in $mm";
2523 0 ▶ $offset >= 0 && $offset <= RegisterSize $mm or
Branch: 1 branch
BranchTrueFalseTotal
if $offset =~ /\A\d+\Z/ 0 0 0
Condition0%0/9
$offset =~ /\A\d+\Z/ && ($offset >= 0 && $offset <= &RegisterSize($mm) || confess('Out of range'))
!ll&&!rl&&r
000
$offset >= 0 and $offset <= &RegisterSize($mm) or confess("Out of range")
l!l&&r!l&&!r
000
$offset >= 0 and $offset <= &RegisterSize($mm)
!ll&&!rl&&r
000
MC/DC0%0/4
$offset =~ /\A\d+\Z/ && ($offset >= 0 && $offset <= &RegisterSize($mm) || confess('Out of range'))
$offset =~ /\A\d+\Z/ $offset >= 0 $offset <= &RegisterSize($mm) confess("Out of range")
Truth table0%0/6
A && B and C or D
A= $offset =~ /\A\d+\Z/B= $offset >= 0C= $offset <= &RegisterSize($mm)D= confess("Out of range")
ABCDresult
0XXX0
10X00
11000
111X1
10X11
11011
2524 confess "Out of range" if $offset =~ m(\A\d+\Z); # Check the offset if it is a number
2525 }
2526  
2527 0 my @save = ($transfer);
2528 0 ▶ PushR @save unless $Transfer; # Push target register
Branch: 1 branch
BranchTrueFalseTotal
unless $Transfer 0 0 0
2529 0 $content->setReg($transfer);
2530 0 Vmovdqu32 "[rsp-$w]", $mm; # Write below the stack
2531 0 ▶ Mov "[rsp+$o-$w]", $transfer."b" if $size =~ m(b); # Write byte register
Branch: 1 branch
BranchTrueFalseTotal
if $size =~ /b/ 0 0 0
2532 0 ▶ Mov "[rsp+$o-$w]", $transfer."w" if $size =~ m(w); # Write word register
Branch: 1 branch
BranchTrueFalseTotal
if $size =~ /w/ 0 0 0
2533 0 ▶ Mov "[rsp+$o-$w]", $transfer."d" if $size =~ m(d); # Write double word register
Branch: 1 branch
BranchTrueFalseTotal
if $size =~ /d/ 0 0 0
2534 0 ▶ Mov "[rsp+$o-$w]", $transfer if $size =~ m(q); # Write register
Branch: 1 branch
BranchTrueFalseTotal
if $size =~ /q/ 0 0 0
2535 0 Vmovdqu32 $mm, "[rsp-$w]"; # Read below the stack
2536 0 ▶ PopR @save unless $Transfer;
Branch: 1 branch
BranchTrueFalseTotal
unless $Transfer 0 0 0
2537  
2538 0 ▶ PopR $o if ref($offset); # The offset is being passed in a variable
Branch: 1 branch
BranchTrueFalseTotal
if ref $offset 0 0 0
2539 }
2540  
2541 sub Nasm::X86::Variable::putBIntoXmm($$$) # Place the value of the content variable at the byte in the numbered xmm register.
2542 0 ▶ {my ($content, $xmm, $offset) = @_; # Variable with content, numbered xmm, offset in bytes
Subroutine putBIntoXmm: not called CC=1 SCAR=6.9
2543 0 $content->putBwdqIntoMm('b', "xmm$xmm", $offset) # Place the value of the content variable at the word in the numbered xmm register
2544 }
2545  
2546 sub Nasm::X86::Variable::putWIntoXmm($$$) # Place the value of the content variable at the word in the numbered xmm register.
2547 0 ▶ {my ($content, $xmm, $offset) = @_; # Variable with content, numbered xmm, offset in bytes
Subroutine putWIntoXmm: not called CC=1 SCAR=6.9
2548 0 $content->putBwdqIntoMm('w', "xmm$xmm", $offset) # Place the value of the content variable at the byte|word|double word|quad word in the numbered xmm register
2549 }
2550  
2551 sub Nasm::X86::Variable::putDIntoXmm($$$) # Place the value of the content variable at the double word in the numbered xmm register.
2552 0 ▶ {my ($content, $xmm, $offset) = @_; # Variable with content, numbered xmm, offset in bytes
Subroutine putDIntoXmm: not called CC=1 SCAR=6.9
2553 0 $content->putBwdqIntoMm('d', "xmm$xmm", $offset) # Place the value of the content variable at the byte|word|double word|quad word in the numbered xmm register
2554 }
2555  
2556 sub Nasm::X86::Variable::putQIntoXmm($$$) # Place the value of the content variable at the quad word in the numbered xmm register.
2557 0 ▶ {my ($content, $xmm, $offset) = @_; # Variable with content, numbered xmm, offset in bytes
Subroutine putQIntoXmm: not called CC=1 SCAR=6.9
2558 0 $content->putBwdqIntoMm('q', "xmm$xmm", $offset) # Place the value of the content variable at the byte|word|double word|quad word in the numbered xmm register
2559 }
2560  
2561 sub Nasm::X86::Variable::putBIntoZmm($$$) # Place the value of the content variable at the byte in the numbered zmm register.
2562 0 ▶ {my ($content, $zmm, $offset) = @_; # Variable with content, numbered zmm, offset in bytes
Subroutine putBIntoZmm: not called CC=2 SCAR=17.9
2563 0 ▶ $zmm =~ m(\A(0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31)\Z) or confess;
Branch: 1 branch
BranchTrueFalseTotal
$zmm =~ /\A(0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31)\Z/ or confess() 0 0 0
2564 0 $content->putBwdqIntoMm('b', "zmm$zmm", $offset) # Place the value of the content variable at the word in the numbered zmm register
2565 }
2566  
2567 sub Nasm::X86::Variable::putWIntoZmm($$$) # Place the value of the content variable at the word in the numbered zmm register.
2568 0 ▶ {my ($content, $zmm, $offset) = @_; # Variable with content, numbered zmm, offset in bytes
Subroutine putWIntoZmm: not called CC=2 SCAR=17.9
2569 0 ▶ $zmm =~ m(\A(0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31)\Z) or confess;
Branch: 1 branch
BranchTrueFalseTotal
$zmm =~ /\A(0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31)\Z/ or confess() 0 0 0
2570 0 $content->putBwdqIntoMm('w', "zmm$zmm", $offset) # Place the value of the content variable at the byte|word|double word|quad word in the numbered zmm register
2571 }
2572  
2573 sub Nasm::X86::Variable::putDIntoZmm($$$;$) # Place the value of the content variable at the double word in the numbered zmm register.
2574 0 ▶ {my ($content, $zmm, $offset, $transfer) = @_; # Variable with content, numbered zmm, offset in bytes, optional transfer register
Subroutine putDIntoZmm: not called CC=2 SCAR=17.9
2575 0 ▶ $zmm =~ m(\A(0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31)\Z) or confess;
Branch: 1 branch
BranchTrueFalseTotal
$zmm =~ /\A(0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31)\Z/ or confess() 0 0 0
2576 0 $content->putBwdqIntoMm('d', "zmm$zmm", $offset, $transfer) # Place the value of the content variable at the byte|word|double word|quad word in the numbered zmm register
2577 }
2578  
2579 sub Nasm::X86::Variable::putQIntoZmm($$$;$) # Place the value of the content variable at the quad word in the numbered zmm register.
2580 0 ▶ {my ($content, $zmm, $offset, $transfer) = @_; # Variable with content, numbered zmm, offset in bytes, optional transfer register
Subroutine putQIntoZmm: not called CC=2 SCAR=17.9
2581 0 ▶ $zmm =~ m(\A(0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31)\Z) or confess;
Branch: 1 branch
BranchTrueFalseTotal
$zmm =~ /\A(0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31)\Z/ or confess() 0 0 0
2582 0 $content->putBwdqIntoMm('q', "zmm$zmm", $offset, $transfer) # Place the value of the content variable at the byte|word|double word|quad word in the numbered zmm register
2583 }
2584  
2585 #D2 Broadcast # Broadcast from a variable into a zmm
2586  
2587 sub Nasm::X86::Variable::zBroadCastD($$) # Broadcast a double word in a variable into the numbered zmm.
2588 0 ▶ {my ($variable, $zmm) = @_; # Variable containing value to broadcast, numbered zmm to broadcast to
Subroutine zBroadCastD: not called CC=1 SCAR=6.9
2589 0 PushR (r15);
2590 0 $variable->setReg(r15); # Value of variable
2591 0 Vpbroadcastd "zmm".$zmm, r15d; # Broadcast
2592 0 PopR;
2593 }
2594  
2595 #D2 Stack # Push and pop variables to and from the stack
2596  
2597 sub Nasm::X86::Variable::push($) # Push a variable onto the stack.
2598 0 ▶ {my ($variable) = @_; # Variable
Subroutine push: not called CC=1 SCAR=6.9
2599 0 PushR rax; Push rax; # Make a slot on the stack and save rax
2600 0 $variable->setReg(rax); # Variable to rax
2601 0 my $s = RegisterSize rax; # Size of rax
2602 0 Mov "[rsp+$s]", rax; # Move variable to slot
2603 0 PopR rax; # Remove rax to leave variable on top of the stack
2604 }
2605  
2606 sub Nasm::X86::Variable::pop($) # Pop a variable from the stack.
2607 0 ▶ {my ($variable) = @_; # Variable
Subroutine pop: not called CC=1 SCAR=6.9
2608 0 PushR rax; # Liberate a register
2609 0 my $s = RegisterSize rax; # Size of rax
2610 0 Mov rax, "[rsp+$s]"; # Load from stack
2611 0 $variable->getReg(rax); # Variable to rax
2612 0 PopR rax; # Remove rax to leave variable on top of the stack
2613 0 Add rsp, $s; # Remove variable from stack
2614 }
2615  
2616 #D2 Memory # Actions on memory described by variables
2617  
2618 sub Nasm::X86::Variable::clearMemory($$) # Clear the memory described in this variable.
2619 0 ▶ {my ($address, $size) = @_; # Address of memory to clear, size of the memory to clear
Subroutine clearMemory: not called CC=1 SCAR=6.9
2620 0 &ClearMemory(size=>$size, address=>$address); # Free the memory
2621 }
2622  
2623 sub Nasm::X86::Variable::copyMemory($$$) # Copy from one block of memory to another.
2624 0 ▶ {my ($target, $source, $size) = @_; # Address of target, address of source, length to copy
Subroutine copyMemory: not called CC=2 SCAR=17.9
2625 0 ▶ @_ == 3 or confess "Three parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess("Three parameters") 0 0 0
2626 # $target->name eq q(target) or confess "Need target";
2627 # $source->name eq q(source) or confess "Need source";
2628 # $size ->name eq q(size) or confess "Need size";
2629 0 &CopyMemory(target => $target, source => $source, size => $size); # Copy the memory
2630 }
2631  
2632 sub Nasm::X86::Variable::printMemoryInHexNL($$$) # Write, in hexadecimal, the memory addressed by a variable to stdout or stderr.
2633 0 ▶ {my ($address, $channel, $size) = @_; # Address of memory, channel to print on, number of bytes to print
Subroutine printMemoryInHexNL: not called CC=2 SCAR=17.9
2634 0 ▶ @_ == 3 or confess "Three parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess("Three parameters") 0 0 0
2635 # $address->name eq q(address) or confess "Need address";
2636 # $size ->name eq q(size) or confess "Need size";
2637 0 PushR (rax, rdi);
2638 0 $address->setReg(rax);
2639 0 $size->setReg(rdi);
2640 0 &PrintMemoryInHex($channel);
2641 0 &PrintNL($channel);
2642 0 PopR;
2643 }
2644  
2645 sub Nasm::X86::Variable::printErrMemoryInHexNL($$) # Write the memory addressed by a variable to stderr.
2646 0 ▶ {my ($address, $size) = @_; # Address of memory, number of bytes to print
Subroutine printErrMemoryInHexNL: not called CC=1 SCAR=6.9
2647 0 $address->printMemoryInHexNL($stderr, $size);
2648 }
2649  
2650 sub Nasm::X86::Variable::printOutMemoryInHexNL($$) # Write the memory addressed by a variable to stdout.
2651 0 ▶ {my ($address, $size) = @_; # Address of memory, number of bytes to print
Subroutine printOutMemoryInHexNL: not called CC=1 SCAR=6.9
2652 0 $address->printMemoryInHexNL($stdout, $size);
2653 }
2654  
2655 sub Nasm::X86::Variable::freeMemory($$) # Free the memory addressed by this variable for the specified length.
2656 0 ▶ {my ($address, $size) = @_; # Address of memory to free, size of the memory to free
Subroutine freeMemory: not called CC=3 SCAR=24.8
2657 0 ▶ $address->name eq q(address) or confess "Need address";
Branch: 1 branch
BranchTrueFalseTotal
$address->name eq "address" or confess("Need address") 0 0 0
2658 0 ▶ $size ->name eq q(size) or confess "Need size";
Branch: 1 branch
BranchTrueFalseTotal
$size->name eq "size" or confess("Need size") 0 0 0
2659 0 &FreeMemory(size=>$size, address=>$address); # Free the memory
2660 }
2661  
2662 sub Nasm::X86::Variable::allocateMemory(@) # Allocate the specified amount of memory via mmap and return its address.
2663 0 ▶ {my ($size) = @_; # Size
Subroutine allocateMemory: not called CC=3 SCAR=24.8
2664 0 ▶ @_ >= 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 1 or confess() 0 0 0
2665 0 ▶ $size->name eq q(size) or confess "Need size";
Branch: 1 branch
BranchTrueFalseTotal
$size->name eq "size" or confess("Need size") 0 0 0
2666 0 &AllocateMemory(size => $size, my $a = V(address));
2667 0 $a
2668 }
2669  
2670 #D2 Structured Programming with variables # Structured programming operations driven off variables.
2671  
2672 sub Nasm::X86::Variable::for($&) # Iterate the block limit times.
2673 0 ▶ {my ($limit, $block) = @_; # Limit, Block
Subroutine for: not called CC=2 SCAR=17.9
2674 0 ▶ @_ == 2 or confess "Two parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess("Two parameters") 0 0 0
2675 0 Comment "Variable::For $limit";
2676 0 my $index = V(q(index), 0); # The index that will be incremented
2677 0 my $start = Label;
2678 0 my $next = Label;
2679 0 my $end = Label;
2680 0 SetLabel $start; # Start of loop
2681  
2682 0 ▶ If $index >= $limit, sub {Jge $end}; # Condition
Subroutine __ANON__: not called CC=1 SCAR=6.9
2683  
2684 0 &$block($index, $start, $next, $end); # Execute block
2685  
2686 0 SetLabel $next; # Next iteration
2687 0 $index++; # Increment
2688 0 Jmp $start;
2689 0 SetLabel $end;
2690 }
2691  
2692 #D1 Stack # Manage data on the stack
2693  
2694 #D2 Push, Pop, Peek # Generic versions of push, pop, peek
2695  
2696 sub PushRR(@) #P Push registers onto the stack without tracking.
2697 0 ▶ {my (@r) = @_; # Register
Subroutine PushRR: not called CC=5 SCAR=34.0
Pod documented
2698 0 for my $r(@r)
2699 0 {my $size = RegisterSize $r;
2700 0 ▶ $size or confess "No such register: $r";
Branch: 1 branch
BranchTrueFalseTotal
$size or confess("No such register: $r") 0 0 0
2701 0 ▶ if ($size > 8) # Wide registers
Branch: 2 branches
BranchTrueFalseTotal
if ($size > 8) { } 0 0 0
elsif ($r =~ /\Ak/) { } 0 0 0
2702 0 {Sub rsp, $size;
2703 0 Vmovdqu32 "[rsp]", $r;
2704 }
2705 elsif ($r =~ m(\Ak)) # Mask as they do not respond to push
2706 0 {Sub rsp, $size;
2707 0 Kmovq "[rsp]", $r;
2708 }
2709 else # Normal register
2710 0 {Push $r;
2711 }
2712 }
2713 }
2714  
2715 1 my @PushR; # Track pushes
2716  
2717 sub PushR(@) #P Push registers onto the stack.
2718 0 ▶ {my (@r) = @_; # Register
Subroutine PushR: not called CC=1 SCAR=6.9
Pod documented
2719 0 push @PushR, [@r];
2720 # CommentWithTraceBack;
2721 0 PushRR @r; # Push
2722 }
2723  
2724 sub PopRR(@) #P Pop registers from the stack without tracking.
2725 0 ▶ {my (@r) = @_; # Register
Subroutine PopRR: not called CC=4 SCAR=30.0
Pod documented
2726 0 for my $r(reverse @r) # Pop registers in reverse order
2727 0 {my $size = RegisterSize $r;
2728 0 ▶ if ($size > 8)
Branch: 2 branches
BranchTrueFalseTotal
if ($size > 8) { } 0 0 0
elsif ($r =~ /\Ak/) { } 0 0 0
2729 0 {Vmovdqu32 $r, "[rsp]";
2730 0 Add rsp, $size;
2731 }
2732 elsif ($r =~ m(\Ak))
2733 0 {Kmovq $r, "[rsp]";
2734 0 Add rsp, $size;
2735 }
2736 else
2737 0 {Pop $r;
2738 }
2739 }
2740 }
2741  
2742 sub PopR(@) # Pop registers from the stack. Use the last stored set if none explicitly supplied. Pops are done in reverse order to match the original pushing order.
2743 0 ▶ {my (@r) = @_; # Register
Subroutine PopR: not called CC=4 SCAR=30.0
Pod documented
2744 0 ▶ @PushR or confess "No stacked registers";
Branch: 1 branch
BranchTrueFalseTotal
@PushR or confess("No stacked registers") 0 0 0
2745 0 my $r = pop @PushR;
2746 0 ▶ dump(\@r) eq dump($r) or confess "Mismatched registers:\n".dump($r, \@r) if @r;
Branch: 1 branch
BranchTrueFalseTotal
if @r 0 0 0
Condition0%0/6
@r && (Nasm::X86::dump(\@r) eq Nasm::X86::dump($r) || confess("Mismatched registers:\n" . Nasm::X86::dump($r, \@r)))
!ll&&!rl&&r
000
Nasm::X86::dump(\@r) eq Nasm::X86::dump($r) or confess("Mismatched registers:\n" . Nasm::X86::dump($r, \@r))
l!l&&r!l&&!r
000
MC/DC0%0/3
@r && (Nasm::X86::dump(\@r) eq Nasm::X86::dump($r) || confess("Mismatched registers:\n" . Nasm::X86::dump($r, \@r)))
@r Nasm::X86::dump(\@r) eq Nasm::X86::dump($r) confess("Mismatched registers:\n" . Nasm::X86::dump($r, \@r))
Truth table0%0/4
A && B or C
A= @rB= Nasm::X86::dump(\@r) eq Nasm::X86::dump($r)C= confess("Mismatched registers:\n" . Nasm::X86::dump($r, \@r))
ABCresult
0XX0
1000
11X1
1011
2747 0 PopRR @$r; # Pop registers from the stack without tracking
2748 # CommentWithTraceBack;
2749 }
2750  
2751 sub PopEax() # We cannot pop a double word from the stack in 64 bit long mode using pop so we improvise.
2752 0 ▶ {my $l = RegisterSize eax; # Eax is half rax
Subroutine PopEax: not called CC=1 SCAR=6.9
Pod documented
2753 0 Mov eax, "[rsp]";
2754 0 Add rsp, RegisterSize eax;
2755 }
2756  
2757 sub PeekR($) # Peek at register on stack.
2758 0 ▶ {my ($r) = @_; # Register
Subroutine PeekR: not called CC=2 SCAR=17.9
Pod documented
2759 0 my $size = RegisterSize $r;
2760 0 ▶ if ($size > 8) # X|y|zmm*
Branch: 1 branch
BranchTrueFalseTotal
if ($size > 8) { } 0 0 0
2761 0 {Vmovdqu32 $r, "[rsp]";
2762 }
2763 else # General purpose 8 byte register
2764 0 {Mov $r, "[rsp]";
2765 }
2766 }
2767  
2768 my @PushZmm; # Zmm pushes
2769  
2770 sub PushZmm(@) # Push several zmm registers.
2771 0 ▶ {my (@Z) = @_; # Zmm register numbers
Subroutine PushZmm: not called CC=3 SCAR=24.8
Pod documented
2772 0 ▶ if (@Z)
Branch: 1 branch
BranchTrueFalseTotal
if (@Z) 0 0 0
2773 0 {my @z = zmm @Z;
2774 0 my $w = RegisterSize zmm0;
2775 0 Sub rsp, @z * $w;
2776 0 for my $i(keys @z)
2777 0 {Vmovdqu64 "[rsp+$w*$i]", $z[$i];
2778 }
2779 0 push @PushZmm, [@Z];
2780 }
2781 }
2782  
2783 sub PopZmm # Pop zmm registers.
2784 0 ▶ {@PushZmm or confess "No Zmm registers saved";
Subroutine PopZmm: not called CC=3 SCAR=24.8
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@PushZmm or confess("No Zmm registers saved") 0 0 0
2785 0 my $z = pop @PushZmm;
2786 0 my @z = zmm @$z;
2787 0 my $w = RegisterSize zmm0;
2788 0 for my $i(keys @z)
2789 0 {Vmovdqu64 $z[$i], "[rsp+$w*$i]";
2790 }
2791 0 Add rsp, @z * $w;
2792 }
2793  
2794 1 my @PushMask; # Mask pushes
2795  
2796 sub PushMask(@) # Push several Mask registers.
2797 0 ▶ {my (@M) = @_; # Mask register numbers
Subroutine PushMask: not called CC=3 SCAR=24.8
Pod documented
2798 0 ▶ if (@M)
Branch: 1 branch
BranchTrueFalseTotal
if (@M) 0 0 0
2799 0 {my @m = map {"k$_"} @M;
2800 0 my $w = RegisterSize k0;
2801 0 Sub rsp, @m * $w;
2802 0 for my $i(keys @m)
2803 0 {Kmovq "[rsp+$w*$i]", $m[$i];
2804 }
2805 0 push @PushMask, [@M];
2806 }
2807 }
2808  
2809 sub PopMask # Pop Mask registers.
2810 0 ▶ {@PushMask or confess "No Mask registers saved";
Subroutine PopMask: not called CC=3 SCAR=24.8
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@PushMask or confess("No Mask registers saved") 0 0 0
2811 0 my $m = pop @PushMask;
2812 0 my @m = map {"k$_"} @$m;
2813 0 my $w = RegisterSize k0;
2814 0 for my $i(keys @m)
2815 0 {Kmovq $m[$i], "[rsp+$w*$i]";
2816 }
2817 0 Add rsp, @m * $w;
2818 }
2819  
2820 #D2 Declarations # Declare variables and structures
2821  
2822 #D3 Structures # Declare a structure
2823  
2824 sub Structure() # Create a structure addressed by a register.
2825 0 ▶ {@_ == 0 or confess;
Subroutine Structure: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 0 or confess() 0 0 0
2826 0 my $local = genHash(__PACKAGE__."::Structure",
2827 size => 0,
2828 variables => [],
2829 );
2830 }
2831  
2832 sub Nasm::X86::Structure::field($$;$) # Add a field of the specified length with an optional comment.
2833 0 ▶ {my ($structure, $length, $comment) = @_; # Structure data descriptor, length of data, optional comment
Subroutine field: not called CC=2 SCAR=17.9
2834 0 ▶ @_ >= 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 or confess() 0 0 0
2835 0 my $variable = genHash(__PACKAGE__."::StructureField",
2836 structure => $structure, # Structure containing the field
2837 loc => $structure->size, # Offset of the field
2838 size => $length, # Size of the field
2839 comment => $comment # Comment describing the purpose of the field
2840 );
2841 0 $structure->size += $length; # Update size of local data
2842 0 push $structure->variables->@*, $variable; # Save variable
2843 0 $variable
2844 }
2845  
2846 sub Nasm::X86::StructureField::addr($;$) # Address a field in a structure by either the default register or the named register.
2847 0 ▶ {my ($field, $register) = @_; # Field, optional address register else rax
Subroutine addr: not called CC=3 SCAR=24.8
2848 0 ▶ @_ <= 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ <= 2 or confess() 0 0 0
2849 0 my $loc = $field->loc; # Offset of field in structure
2850 0 ▶ my $reg = $register || 'rax'; # Register locating the structure
Condition0%0/2
$register || 'rax'
l!l
00
MC/DC0%0/1
$register || 'rax'
$register
Truth table0%0/2
A
A= $register
Aresult
11
00
2851 0 "[$loc+$reg]" # Address field
2852 }
2853  
2854 sub All8Structure($) # Create a structure consisting of 8 byte fields.
2855 0 ▶ {my ($N) = @_; # Number of variables required
Subroutine All8Structure: not called CC=3 SCAR=24.8
Pod documented
2856 0 ▶ @_ == 1 or confess "One parameter";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess("One parameter") 0 0 0
2857 0 my $s = Structure; # Structure of specified size based on specified register
2858 0 my @f;
2859 0 my $z = RegisterSize rax;
2860 0 for(1..$N) # Create the variables
2861 0 {push @f, $s->field($z);
2862 }
2863 0 ($s, @f) # Structure, fields
2864 }
2865  
2866 #D3 Stack Frame # Declare local variables in a frame on the stack
2867  
2868 sub LocalData() # Map local data.
2869 0 ▶ {@_ == 0 or confess;
Subroutine LocalData: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 0 or confess() 0 0 0
2870 0 my $local = genHash(__PACKAGE__."::LocalData",
2871 size => 0,
2872 variables => [],
2873 );
2874 }
2875  
2876 sub Nasm::X86::LocalData::start($) # Start a local data area on the stack.
2877 0 ▶ {my ($local) = @_; # Local data descriptor
Subroutine start: not called CC=2 SCAR=17.9
2878 0 ▶ @_ == 1 or confess "One parameter";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess("One parameter") 0 0 0
2879 0 my $size = $local->size; # Size of local data
2880 0 Push rbp;
2881 0 Mov rbp,rsp;
2882 0 Sub rsp, $size;
2883 }
2884  
2885 sub Nasm::X86::LocalData::free($) # Free a local data area on the stack.
2886 0 ▶ {my ($local) = @_; # Local data descriptor
Subroutine free: not called CC=2 SCAR=17.9
2887 0 ▶ @_ == 1 or confess "One parameter";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess("One parameter") 0 0 0
2888 0 Mov rsp, rbp;
2889 0 Pop rbp;
2890 }
2891  
2892 sub Nasm::X86::LocalData::variable($$;$) # Add a local variable.
2893 0 ▶ {my ($local, $length, $comment) = @_; # Local data descriptor, length of data, optional comment
Subroutine variable: not called CC=2 SCAR=17.9
2894 0 ▶ @_ >= 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 or confess() 0 0 0
2895 0 my $variable = genHash(__PACKAGE__."::LocalVariable",
2896 loc => $local->size,
2897 size => $length,
2898 comment => $comment
2899 );
2900 0 $local->size += $length; # Update size of local data
2901 0 $variable
2902 }
2903  
2904 sub Nasm::X86::LocalVariable::stack($) # Address a local variable on the stack.
2905 0 ▶ {my ($variable) = @_; # Variable
Subroutine stack: not called CC=5 SCAR=34.0
2906 0 ▶ @_ == 1 or confess "One parameter";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess("One parameter") 0 0 0
2907 0 my $l = $variable->loc; # Location of variable on stack
2908 0 my $S = $variable->size;
2909 0 ▶ my $s = $S == 8 ? 'qword' : $S == 4 ? 'dword' : $S == 2 ? 'word' : 'byte'; # Variable size
Branch: 3 branches
BranchTrueFalseTotal
$S == 8 ? : 0 0 0
$S == 4 ? : 0 0 0
$S == 2 ? : 0 0 0
2910 0 "${s}[rbp-$l]" # Address variable - offsets are negative per Tino
2911 }
2912  
2913 sub Nasm::X86::LocalData::allocate8($@) # Add some 8 byte local variables and return an array of variable definitions.
2914 0 ▶ {my ($local, @comments) = @_; # Local data descriptor, optional comment
Subroutine allocate8: not called CC=3 SCAR=24.8
2915 0 my @v;
2916 0 for my $c(@comments)
2917 0 {push @v, Nasm::X86::LocalData::variable($local, 8, $c);
2918 }
2919 0 ▶ wantarray ? @v : $v[-1]; # Avoid returning the number of elements accidently
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
2920 }
2921  
2922 sub AllocateAll8OnStack($) # Create a local data descriptor consisting of the specified number of 8 byte local variables and return an array: (local data descriptor, variable definitions...).
2923 0 ▶ {my ($N) = @_; # Number of variables required
Subroutine AllocateAll8OnStack: not called CC=2 SCAR=17.9
Pod documented
2924 0 my $local = LocalData; # Create local data descriptor
2925 0 my @v;
2926 0 for(1..$N) # Create the variables
2927 0 {my $v = $local->variable(RegisterSize(rax));
2928 0 push @v, $v->stack;
2929 }
2930 0 $local->start; # Create the local data area on the stack
2931 0 ($local, @v)
2932 }
2933  
2934 #D1 Operating system # Interacting with the operating system.
2935  
2936 #D2 Processes # Create and manage processes
2937  
2938 sub Fork() # Fork.
2939 0 ▶ {@_ == 0 or confess;
Subroutine Fork: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 0 or confess() 0 0 0
2940 0 Comment "Fork";
2941 0 Mov rax, 57;
2942 0 Syscall
2943 }
2944  
2945 sub GetPid() # Get process identifier.
2946 0 ▶ {@_ == 0 or confess;
Subroutine GetPid: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 0 or confess() 0 0 0
2947 0 Comment "Get Pid";
2948  
2949 0 Mov rax, 39;
2950 0 Syscall
2951 }
2952  
2953 sub GetPidInHex() # Get process identifier in hex as 8 zero terminated bytes in rax.
2954 0 ▶ {@_ == 0 or confess;
Subroutine GetPidInHex: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 0 or confess() 0 0 0
2955 0 Comment "Get Pid";
2956 0 my $hexTranslateTable = hexTranslateTable;
2957  
2958 my $sub = Macro
2959 0 ▶ {SaveFirstFour;
Subroutine __ANON__: not called CC=2 SCAR=17.9
2960 0 Mov rax, 39; # Get pid
2961 0 Syscall;
2962 0 Mov rdx, rax; # Content to be printed
2963  
2964 0 ClearRegisters rax; # Save a trailing 00 on the stack
2965 0 Push ax;
2966 0 for my $i(reverse 5..7)
2967 0 {my $s = 8*$i;
2968 0 Mov rdi,rdx;
2969 0 Shl rdi,$s; # Push selected byte high
2970 0 Shr rdi,56; # Push select byte low
2971 0 Shl rdi,1; # Multiply by two because each entry in the translation table is two bytes long
2972 0 Mov ax, "[$hexTranslateTable+rdi]";
2973 0 Push ax;
2974 }
2975 0 Pop rax; # Get result from stack
2976 0 RestoreFirstFourExceptRax;
2977 0 } name => "GetPidInHex";
2978  
2979 0 Call $sub;
2980 }
2981  
2982 sub GetPPid() # Get parent process identifier.
2983 0 ▶ {@_ == 0 or confess;
Subroutine GetPPid: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 0 or confess() 0 0 0
2984 0 Comment "Get Parent Pid";
2985  
2986 0 Mov rax, 110;
2987 0 Syscall
2988 }
2989  
2990 sub GetUid() # Get userid of current process.
2991 0 ▶ {@_ == 0 or confess;
Subroutine GetUid: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 0 or confess() 0 0 0
2992 0 Comment "Get User id";
2993  
2994 0 Mov rax, 102;
2995 0 Syscall
2996 }
2997  
2998 sub WaitPid() # Wait for the pid in rax to complete.
2999 0 ▶ {@_ == 0 or confess;
Subroutine WaitPid: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 0 or confess() 0 0 0
3000 0 Comment "WaitPid - wait for the pid in rax";
3001  
3002 my $sub = Macro
3003 0 ▶ {SaveFirstSeven;
Subroutine __ANON__: not called CC=1 SCAR=6.9
3004 0 Mov rdi,rax;
3005 0 Mov rax, 61;
3006 0 Mov rsi, 0;
3007 0 Mov rdx, 0;
3008 0 Mov r10, 0;
3009 0 Syscall;
3010 0 RestoreFirstSevenExceptRax;
3011 0 } name => "WaitPid";
3012  
3013 0 Call $sub;
3014 }
3015  
3016 sub ReadTimeStampCounter() # Read the time stamp counter and return the time in nanoseconds in rax.
3017 0 ▶ {@_ == 0 or confess;
Subroutine ReadTimeStampCounter: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 0 or confess() 0 0 0
3018  
3019 my $sub = Macro
3020 0 ▶ {Comment "Read Time-Stamp Counter";
Subroutine __ANON__: not called CC=1 SCAR=6.9
3021 0 PushR rdx;
3022 0 ClearRegisters rax;
3023 0 Cpuid;
3024 0 Rdtsc;
3025 0 Shl rdx,32;
3026 0 Or rax,rdx;
3027 0 PopR;
3028 0 } name => "ReadTimeStampCounter";
3029  
3030 0 Call $sub;
3031 }
3032  
3033 #D2 Memory # Allocate and print memory
3034  
3035 sub PrintMemoryInHex($) # Dump memory from the address in rax for the length in rdi on the specified channel. As this method prints in blocks of 8 up to 7 bytes will be missing from the end unless the length is a multiple of 8 .
3036 0 ▶ {my ($channel) = @_; # Channel
Subroutine PrintMemoryInHex: not called CC=2 SCAR=17.9
Pod documented
3037 0 ▶ @_ == 1 or confess "One parameter";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess("One parameter") 0 0 0
3038 0 Comment "Print out memory in hex on channel: $channel";
3039  
3040 Call Macro
3041 0 ▶ {my $size = RegisterSize rax;
Subroutine __ANON__: not called CC=1 SCAR=6.9
3042 0 SaveFirstFour;
3043  
3044 0 Test rdi, 0x7; # Round the number of bytes to be printed
3045 IfNz
3046 Then # Round up
3047 0 ▶ {Add rdi, 8;
Subroutine __ANON__: not called CC=1 SCAR=6.9
3048 0 };
3049 0 And rdi, 0x3f8; # Limit the number of bytes to be printed to 1024
3050  
3051 0 Mov rsi, rax; # Position in memory
3052 0 Lea rdi,"[rax+rdi-$size+1]"; # Upper limit of printing with an 8 byte register
3053 For # Print string in blocks
3054 0 ▶ {Mov rax, "[rsi]";
Subroutine __ANON__: not called CC=1 SCAR=6.9
3055 0 Bswap rax;
3056 0 PrintRaxInHex($channel);
3057 0 } rsi, rdi, $size;
3058 0 RestoreFirstFour;
3059 0 } name=> "PrintOutMemoryInHexOnChannel$channel";
3060 }
3061  
3062 sub PrintErrMemoryInHex # Dump memory from the address in rax for the length in rdi on stderr.
3063 0 ▶ {@_ == 0 or confess;
Subroutine PrintErrMemoryInHex: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 0 or confess() 0 0 0
3064 0 PrintMemoryInHex($stderr);
3065 }
3066  
3067 sub PrintOutMemoryInHex # Dump memory from the address in rax for the length in rdi on stdout.
3068 0 ▶ {@_ == 0 or confess;
Subroutine PrintOutMemoryInHex: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 0 or confess() 0 0 0
3069 0 PrintMemoryInHex($stdout);
3070 }
3071  
3072 sub PrintErrMemoryInHexNL # Dump memory from the address in rax for the length in rdi and then print a new line.
3073 0 ▶ {@_ == 0 or confess;
Subroutine PrintErrMemoryInHexNL: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 0 or confess() 0 0 0
3074 0 PrintMemoryInHex($stderr);
3075 0 PrintNL($stderr);
3076 }
3077  
3078 sub PrintOutMemoryInHexNL # Dump memory from the address in rax for the length in rdi and then print a new line.
3079 0 ▶ {@_ == 0 or confess;
Subroutine PrintOutMemoryInHexNL: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 0 or confess() 0 0 0
3080 0 PrintMemoryInHex($stdout);
3081 0 PrintNL($stdout);
3082 }
3083  
3084 sub PrintMemory($) # Print the memory addressed by rax for a length of rdi on the specified channel.
3085 0 ▶ {my ($channel) = @_; # Channel
Subroutine PrintMemory: not called CC=2 SCAR=17.9
Pod documented
3086 0 ▶ @_ == 1 or confess "One parameter";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess("One parameter") 0 0 0
3087  
3088 Call Macro
3089 0 ▶ {Comment "Print memory on channel: $channel";
Subroutine __ANON__: not called CC=1 SCAR=6.9
3090 0 SaveFirstFour rax, rdi;
3091 0 Mov rsi, rax;
3092 0 Mov rdx, rdi;
3093 0 Mov rax, 1;
3094 0 Mov rdi, $channel;
3095 0 Syscall;
3096 0 RestoreFirstFour();
3097 0 } name => "PrintOutMemoryOnChannel$channel";
3098 }
3099  
3100 sub PrintMemoryNL # Print the memory addressed by rax for a length of rdi on the specified channel followed by a new line.
3101 0 ▶ {my ($channel) = @_; # Channel
Subroutine PrintMemoryNL: not called CC=2 SCAR=17.9
Pod documented
3102 0 ▶ @_ == 1 or confess "One parameter";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess("One parameter") 0 0 0
3103 0 PrintMemory($channel);
3104 0 PrintNL($channel);
3105 }
3106  
3107 sub PrintErrMemory # Print the memory addressed by rax for a length of rdi on stderr.
3108 0 ▶ {@_ == 0 or confess;
Subroutine PrintErrMemory: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 0 or confess() 0 0 0
3109 0 PrintMemory($stdout);
3110 }
3111  
3112 sub PrintOutMemory # Print the memory addressed by rax for a length of rdi on stdout.
3113 0 ▶ {@_ == 0 or confess;
Subroutine PrintOutMemory: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 0 or confess() 0 0 0
3114 0 PrintMemory($stdout);
3115 }
3116  
3117 sub PrintErrMemoryNL # Print the memory addressed by rax for a length of rdi followed by a new line on stderr.
3118 0 ▶ {@_ == 0 or confess;
Subroutine PrintErrMemoryNL: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 0 or confess() 0 0 0
3119 0 PrintErrMemory;
3120 0 PrintErrNL;
3121 }
3122  
3123 sub PrintOutMemoryNL # Print the memory addressed by rax for a length of rdi followed by a new line on stdout.
3124 0 ▶ {@_ == 0 or confess;
Subroutine PrintOutMemoryNL: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 0 or confess() 0 0 0
3125 0 PrintOutMemory;
3126 0 PrintOutNL;
3127 }
3128  
3129 sub AllocateMemory(@) # Allocate the specified amount of memory via mmap and return its address.
3130 0 ▶ {my (@variables) = @_; # Parameters
Subroutine AllocateMemory: not called CC=2 SCAR=17.9
Pod documented
3131 0 ▶ @_ >= 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 or confess() 0 0 0
3132  
3133 my $s = Subroutine
3134 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
3135 0 Comment "Allocate memory";
3136 0 SaveFirstSeven;
3137 0 my $d = extractMacroDefinitionsFromCHeaderFile "linux/mman.h"; # Memory map constants
3138 0 my $pa = $$d{MAP_PRIVATE} | $$d{MAP_ANONYMOUS};
3139 0 my $wr = $$d{PROT_WRITE} | $$d{PROT_READ};
3140  
3141 0 Mov rax, 9; # Memory map
3142 0 $$p{size}->setReg(rsi); # Amount of memory
3143 0 Xor rdi, rdi; # Anywhere
3144 0 Mov rdx, $wr; # Read write protections
3145 0 Mov r10, $pa; # Private and anonymous map
3146 0 Mov r8, -1; # File descriptor for file backing memory if any
3147 0 Mov r9, 0; # Offset into file
3148 0 Syscall;
3149 0 Cmp rax, -1; # Check return code
3150 IfEq(sub
3151 0 ▶ {PrintErrString "Cannot allocate memory, return code -1";
Subroutine __ANON__: not called CC=1 SCAR=6.9
3152 0 $$p{size}->errNL;
3153 0 Exit(1);
3154 0 });
3155 0 Cmp eax, 0xffffffea; # Check return code
3156 IfEq(sub
3157 0 ▶ {PrintErrString "Cannot allocate memory, return code 0xffffffea";
Subroutine __ANON__: not called CC=1 SCAR=6.9
3158 0 $$p{size}->errNL;
3159 0 Exit(1);
3160 0 });
3161 0 Cmp rax, -12; # Check return code
3162 IfEq(sub
3163 0 ▶ {PrintErrString "Cannot allocate memory, return code -12";
Subroutine __ANON__: not called CC=1 SCAR=6.9
3164 0 $$p{size}->errNL;
3165 0 Exit(1);
3166 0 });
3167 0 $$p{address}->getReg(rax); # Amount of memory
3168  
3169 0 RestoreFirstSeven;
3170 0 } [qw(address size)], name => 'AllocateMemory';
3171  
3172 0 $s->call(@variables);
3173 }
3174  
3175 sub FreeMemory(@) # Free memory.
3176 0 ▶ {my (@variables) = @_; # Variables
Subroutine FreeMemory: not called CC=2 SCAR=17.9
Pod documented
3177 0 ▶ @_ >= 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 or confess() 0 0 0
3178 0 Comment "Free memory";
3179  
3180 my $s = Subroutine
3181 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
3182 0 SaveFirstFour;
3183 0 Mov rax, 11; # Munmap
3184 0 $$p{address}->setReg(rdi); # Address
3185 0 $$p{size} ->setReg(rsi); # Length
3186 0 Syscall;
3187 0 RestoreFirstFour;
3188 0 } [qw(size address)], name=> 'FreeMemory';
3189  
3190 0 $s->call(@variables);
3191 }
3192  
3193 sub ClearMemory(@) # Clear memory.
3194 0 ▶ {my (@variables) = @_; # Variables
Subroutine ClearMemory: not called CC=2 SCAR=17.9
Pod documented
3195 0 ▶ @_ >= 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 or confess() 0 0 0
3196 0 Comment "Clear memory";
3197  
3198 my $s = Subroutine
3199 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
3200 0 PushR (zmm0, rax, rdi, rsi, rdx);
3201 0 $$p{address}->setReg(rax);
3202 0 $$p{size} ->setReg(rdi);
3203 0 Lea rdx, "[rax+rdi]"; # Address of upper limit of buffer
3204  
3205 0 ClearRegisters zmm0; # Clear the register that will be written into memory
3206  
3207 0 Mov rsi, rdi; # Modulus the size of zmm
3208 0 And rsi, 0x3f; # Remainder modulo 64
3209 0 Cmp rsi, 0; # Test remainder
3210 IfNz sub # Need to align so that the rest of the clear can be done in full zmm blocks
3211 0 ▶ {PushR k7;
Subroutine __ANON__: not called CC=1 SCAR=6.9
3212 0 V(align, rsi)->setMaskFirst(k7); # Set mask bits
3213 0 Vmovdqu8 "[rax]{k7}", zmm0; # Masked move to memory
3214 0 PopR;
3215 0 Add rax, rsi; # Update point to clear from
3216 0 Sub rdi, rsi; # Reduce clear length
3217 0 };
3218  
3219 For # Clear remaining memory in full zmm blocks
3220 0 ▶ {Vmovdqu64 "[rax]", zmm0;
Subroutine __ANON__: not called CC=1 SCAR=6.9
3221 0 } rax, rdx, RegisterSize zmm0;
3222  
3223 0 PopR;
3224 0 } [qw(size address)], name => 'ClearMemory';
3225  
3226 0 $s->call(@variables);
3227 }
3228  
3229 sub MaskMemory22(@) # Write the specified byte into locations in the target mask that correspond to the locations in the source that contain the specified byte.
3230 0 ▶ {my (@variables) = @_; # Variables
Subroutine MaskMemory22: not called CC=2 SCAR=17.9
Pod documented
3231 0 ▶ @_ >= 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 or confess() 0 0 0
3232 0 Comment "Clear memory";
3233  
3234 0 my $size = RegisterSize zmm0;
3235  
3236 my $s = Subroutine
3237 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
3238 0 PushR (k6, k7, rax, rdi, rsi, rdx, r8, r9, r10, zmm0, zmm1, zmm2);
3239 0 $$p{source}->setReg(rax);
3240 0 $$p{mask} ->setReg(rdx);
3241 0 $$p{match} ->setReg(rsi);
3242 0 $$p{set} ->setReg(rdi);
3243 0 $$p{size} ->setReg(r8);
3244 0 Lea r9, "[rax+r8]"; # Address of upper limit of source
3245  
3246 0 Vpbroadcastb zmm1, rsi; # Character to match
3247 0 Vpbroadcastb zmm2, rdi; # Character to write into mask
3248  
3249 0 Mov r10, r8; # Modulus the size of zmm
3250 0 And r10, 0x3f;
3251 0 Test r10, r10;
3252 IfNz sub # Need to align so that the rest of the clear can be done in full zmm blocks
3253 0 ▶ {V(align, r10)->setMaskFirst(k7); # Set mask bits
Subroutine __ANON__: not called CC=1 SCAR=6.9
3254 0 Vmovdqu8 "zmm0\{k7}", "[rax]"; # Load first incomplete block of source
3255 0 Vpcmpub "k6{k7}", zmm0, zmm1, 0; # Characters in source that match
3256 0 Vmovdqu8 "[rdx]{k6}", zmm2; # Write set byte into mask at match points
3257 0 Add rax, r10; # Update point to mask from
3258 0 Add rdx, r10; # Update point to mask to
3259 0 Sub r8, r10; # Reduce mask length
3260 0 };
3261  
3262 For # Clear remaining memory in full zmm blocks
3263 0 ▶ {Vmovdqu8 zmm0, "[rax]"; # Load complete block of source
Subroutine __ANON__: not called CC=1 SCAR=6.9
3264 0 Vpcmpub "k7", zmm0, zmm1, 0; # Characters in source that match
3265 0 Vmovdqu8 "[rdx]{k7}", zmm2; # Write set byte into mask at match points
3266 0 Add rdx, $size; # Update point to mask to
3267 0 } rax, r9, $size;
3268  
3269 0 PopR;
3270 0 } [qw(size source mask match set)]; # Match is the character to match on in the source, set is the character to write into the mask at the corresponding position.
3271  
3272 0 $s->call(@variables);
3273 }
3274  
3275 sub MaskMemoryInRange4_22(@) # Write the specified byte into locations in the target mask that correspond to the locations in the source that contain 4 bytes in the specified range.
3276 0 ▶ {my (@variables) = @_; # Variables
Subroutine MaskMemoryInRange4_22: not called CC=2 SCAR=17.9
Pod documented
3277 0 ▶ @_ >= 6 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 6 or confess() 0 0 0
3278 0 Comment "Clear memory";
3279  
3280 0 my $size = RegisterSize zmm0;
3281  
3282 my $s = Subroutine
3283 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
3284 0 PushR (k4, k5, k6, k7, zmm(0..9), map{"r$_"} qw(ax di si dx), 8..15);
3285 0 $$p{source}->setReg(rax);
3286 0 $$p{mask} ->setReg(rdx);
3287 0 $$p{low} ->setReg(r10);
3288 0 $$p{high} ->setReg(r11);
3289 0 $$p{set} ->setReg(rdi);
3290 0 $$p{size} ->setReg(rsi);
3291  
3292 0 Vpbroadcastb zmm1, rdi; # Character to write into mask
3293 0 Vpbroadcastb zmm2, r10; # Character 1 low
3294 0 Shr r10, 8; Vpbroadcastb zmm3, r10; # Character 2 low
3295 0 Shr r10, 8; Vpbroadcastb zmm4, r10; # Character 3 low
3296 0 Shr r10, 8; Vpbroadcastb zmm5, r10; # Character 4 low
3297 0 Vpbroadcastb zmm6, r11; # Character 1 high
3298 0 Shr r11, 8; Vpbroadcastb zmm7, r11; # Character 2 high
3299 0 Shr r11, 8; Vpbroadcastb zmm8, r11; # Character 3 high
3300 0 Shr r11, 8; Vpbroadcastb zmm9, r11; # Character 4 high
3301 0 Lea r8, "[rax+rsi]"; # Address of upper limit of source
3302  
3303 my sub check($$) # Check a character
3304 0 ▶ {my ($z, $f) = @_; # First zmm, finished label
Subroutine check: not called CC=1 SCAR=6.9
3305 0 my $Z = $z + 4;
3306 0 Vpcmpub "k6{k7}", zmm0, "zmm$z", 5; # Greater than or equal
3307 0 Vpcmpub "k7{k6}", zmm0, "zmm$Z", 2; # Less than or equal
3308 0 Ktestq k7, k7;
3309 0 Jz $f; # No match
3310 0 Kshiftlq k7, k7, 1; # Match - move up to next character
3311 };
3312  
3313 my sub last4() # Expand each set bit four times
3314 0 ▶ {Kshiftlq k6, k7, 1; Kandq k7, k6, k7; # We have found a character in the specified range
Subroutine last4: not called CC=1 SCAR=6.9
3315 0 Kshiftlq k6, k7, 2; Kandq k7, k6, k7; # Last four
3316 };
3317  
3318 For # Mask remaining memory in full zmm blocks
3319 0 ▶ {my $finished = Label; # Point where we have finished the initial comparisons
Subroutine __ANON__: not called CC=2 SCAR=17.9
3320 0 Vmovdqu8 zmm0, "[rax]"; # Load complete block of source
3321 0 Kxnorq k7, k7, k7; # Complete block - sets register to all ones
3322 0 check($_, $finished) for 2..5; last4; # Check a range
3323  
3324 0 Vmovdqu8 "[rdx]{k7}", zmm1; # Write set byte into mask at match points
3325 0 Add rdx, $size; # Update point to mask to
3326 0 SetLabel $finished;
3327 0 } rax, r8, $size;
3328  
3329  
3330 0 Mov r10, rsi; And r10, 0x3f; # Modulus the size of zmm
3331 0 Test r10, r10;
3332 IfNz sub # Need to align so that the rest of the mask can be done in full zmm blocks
3333 0 ▶ {my $finished = Label; # Point where we have finished the initial comparisons
Subroutine __ANON__: not called CC=2 SCAR=17.9
3334 0 V(align, r10)->setMaskFirst(k7); # Set mask bits
3335 0 Vmovdqu8 "zmm0\{k7}", "[rax]"; # Load first incomplete block of source
3336 0 check($_, $finished) for 2..5; last4; # Check a range
3337 0 Vmovdqu8 "[rdx]{k7}", zmm1; # Write set byte into mask at match points
3338 0 Add rax, r10; # Update point to mask from
3339 0 Add rdx, r10; # Update point to mask to
3340 0 Sub r8, r10; # Reduce mask length
3341 0 SetLabel $finished;
3342 0 };
3343  
3344 0 PopR;
3345 0 } [qw(size source mask set low high)];
3346  
3347 0 $s->call(@variables);
3348 } # MaskMemoryInRange4
3349  
3350 sub CopyMemory(@) # Copy memory, the target is addressed by rax, the length is in rdi, the source is addressed by rsi.
3351 0 ▶ {my (@variables) = @_; # Variables
Subroutine CopyMemory: not called CC=2 SCAR=17.9
Pod documented
3352 0 ▶ @_ >= 3 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 3 or confess() 0 0 0
3353  
3354 my $s = Subroutine
3355 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
3356 0 Comment "Copy memory";
3357 0 SaveFirstSeven;
3358 0 $$p{source}->setReg(rsi);
3359 0 $$p{target}->setReg(rax);
3360 0 $$p{size} ->setReg(rdi);
3361 0 ClearRegisters rdx;
3362 For # Clear memory
3363 0 ▶ {Mov "r8b", "[rsi+rdx]";
Subroutine __ANON__: not called CC=1 SCAR=6.9
3364 0 Mov "[rax+rdx]", "r8b";
3365 0 } rdx, rdi, 1;
3366 0 RestoreFirstSeven;
3367 0 } [qw(source target size)], name => 'CopyMemory';
3368  
3369 0 $s->call(@variables);
3370 }
3371  
3372 #D2 Files # Interact with the operating system via files.
3373  
3374 sub OpenRead() # Open a file, whose name is addressed by rax, for read and return the file descriptor in rax.
3375 0 ▶ {@_ == 0 or confess;
Subroutine OpenRead: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 0 or confess() 0 0 0
3376 0 Comment "Open a file for read";
3377  
3378 my $sub = Macro
3379 0 ▶ {my $S = extractMacroDefinitionsFromCHeaderFile "asm-generic/fcntl.h"; # Constants for reading a file
Subroutine __ANON__: not called CC=1 SCAR=6.9
3380 0 my $O_RDONLY = $$S{O_RDONLY};
3381 0 SaveFirstFour;
3382 0 Mov rdi,rax;
3383 0 Mov rax,2;
3384 0 Mov rsi,$O_RDONLY;
3385 0 Xor rdx,rdx;
3386 0 Syscall;
3387 0 RestoreFirstFourExceptRax;
3388 0 } name=> "OpenRead";
3389  
3390 0 Call $sub;
3391 }
3392  
3393 sub OpenWrite() # Create the file named by the terminated string addressed by rax for write.
3394 0 ▶ {@_ == 0 or confess;
Subroutine OpenWrite: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 0 or confess() 0 0 0
3395 0 Comment "Open a file for write";
3396  
3397 my $sub = Macro
3398 0 ▶ {my $S = extractMacroDefinitionsFromCHeaderFile "fcntl.h"; # Constants for creating a file
Subroutine __ANON__: not called CC=1 SCAR=6.9
3399 # my $T = extractMacroDefinitionsFromCHeaderFile "sys/stat.h";
3400 0 my $O_WRONLY = $$S{O_WRONLY};
3401 0 my $O_CREAT = $$S{O_CREAT};
3402 0 my $O_RDWR = $$S{O_RDWR};
3403 # my $S_IRUSR = $$T{__S_IREAD};
3404 # my $S_IWUSR = $$T{__S_IWRITE};
3405 0 my $write = $O_WRONLY+0 | $O_CREAT+0;
3406  
3407 0 SaveFirstFour;
3408 # Mov rdi,16;
3409 0 Mov rdi, rax;
3410 0 Mov rax, 2;
3411 0 Mov rsi, $write;
3412 # ClearRegisters rdx;
3413 0 Mov rdx, 0x1c0; # Permissions: u=rwx 1o=x 4o=r 8g=x 10g=w 20g=r 40u=x 80u=r 100u=r 200=T 400g=S 800u=S #0,2,1000, nothing
3414 0 Syscall;
3415  
3416 0 RestoreFirstFourExceptRax;
3417 0 } name=> "OpenWrite";
3418  
3419 0 Call $sub;
3420 }
3421  
3422 sub CloseFile() # Close the file whose descriptor is in rax.
3423 0 ▶ {@_ == 0 or confess;
Subroutine CloseFile: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 0 or confess() 0 0 0
3424  
3425 my $sub = Macro
3426 0 ▶ {Comment "Close a file";
Subroutine __ANON__: not called CC=1 SCAR=6.9
3427 0 SaveFirstFour;
3428 0 Mov rdi, rax;
3429 0 Mov rax, 3;
3430 0 Syscall;
3431 0 RestoreFirstFourExceptRax;
3432 0 } name=> "CloseFile";
3433  
3434 0 Call $sub;
3435 }
3436  
3437 sub StatSize() # Stat a file whose name is addressed by rax to get its size in rax.
3438 0 ▶ {@_ == 0 or confess;
Subroutine StatSize: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 0 or confess() 0 0 0
3439  
3440 0 my $S = extractCStructure "#include <sys/stat.h>"; # Get location of size field
3441 0 my $Size = $$S{stat}{size};
3442 0 my $off = $$S{stat}{fields}{st_size}{loc};
3443  
3444 my $sub = Macro
3445 0 ▶ {Comment "Stat a file for size";
Subroutine __ANON__: not called CC=1 SCAR=6.9
3446 0 SaveFirstFour rax;
3447 0 Mov rdi, rax; # File name
3448 0 Mov rax,4;
3449 0 Lea rsi, "[rsp-$Size]";
3450 0 Syscall;
3451 0 Mov rax, "[$off+rsp-$Size]"; # Place size in rax
3452 0 RestoreFirstFourExceptRax;
3453 0 } name=> "StatSize";
3454  
3455 0 Call $sub;
3456 }
3457  
3458 sub ReadFile(@) # Read a file whose name is addressed by rax into memory. The address of the mapped memory and its length are returned in registers rax,rdi.
3459 0 ▶ {my (@variables) = @_; # Variables
Subroutine ReadFile: not called CC=2 SCAR=17.9
Pod documented
3460 0 ▶ @_ >= 3 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 3 or confess() 0 0 0
3461  
3462 my $s = Subroutine
3463 0 ▶ {my ($p) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
3464 0 Comment "Read a file into memory";
3465 0 SaveFirstSeven; # Generated code
3466 0 my $size = V(size);
3467 0 my $fdes = V(fdes);
3468  
3469 0 $$p{file}->setReg(rax); # File name
3470  
3471 0 StatSize; # File size
3472 0 $size->getReg(rax); # Save file size
3473  
3474 0 $$p{file}->setReg(rax); # File name
3475 0 OpenRead; # Open file for read
3476 0 $fdes->getReg(rax); # Save file descriptor
3477  
3478 0 my $d = extractMacroDefinitionsFromCHeaderFile "linux/mman.h"; # Memory map constants
3479 0 my $pa = $$d{MAP_PRIVATE};
3480 0 my $ro = $$d{PROT_READ};
3481  
3482 0 Mov rax, 9; # Memory map
3483 0 $size->setReg(rsi); # Amount of memory
3484 0 Xor rdi, rdi; # Anywhere
3485 0 Mov rdx, $ro; # Read write protections
3486 0 Mov r10, $pa; # Private and anonymous map
3487 0 $fdes->setReg(r8); # File descriptor for file backing memory
3488 0 Mov r9, 0; # Offset into file
3489 0 Syscall;
3490 0 $size ->setReg(rdi);
3491 0 $$p{address}->getReg(rax);
3492 0 $$p{size} ->getReg(rdi);
3493 0 RestoreFirstSeven;
3494 0 } [qw(file address size)], name => 'ReadFile';
3495  
3496 0 $s->call(@variables);
3497 }
3498  
3499 sub executeFileViaBash(@) # Execute the file named in the arena addressed by rax with bash.
3500 0 ▶ {my (@variables) = @_; # Variables
Subroutine executeFileViaBash: not called CC=2 SCAR=17.9
Pod documented
3501 0 ▶ @_ >= 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 1 or confess() 0 0 0
3502  
3503 my $s = Subroutine
3504 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
3505 0 Comment "Execute a file via bash";
3506 0 SaveFirstFour;
3507 0 Fork; # Fork
3508  
3509 0 Test rax, rax;
3510  
3511 IfNz # Parent
3512 Then
3513 0 ▶ {WaitPid;
Subroutine __ANON__: not called CC=1 SCAR=6.9
3514 },
3515 Else # Child
3516 0 ▶ {$$p{file}->setReg(rdi);
Subroutine __ANON__: not called CC=1 SCAR=6.9
3517 0 Mov rsi, 0;
3518 0 Mov rdx, 0;
3519 0 Mov rax, 59;
3520 0 Syscall;
3521 0 };
3522 0 RestoreFirstFour;
3523 0 } [qw(file)], name => 'executeFileViaBash';
3524  
3525 0 $s->call(@variables);
3526 }
3527  
3528 sub unlinkFile(@) # Unlink the named file.
3529 0 ▶ {my (@variables) = @_; # Variables
Subroutine unlinkFile: not called CC=2 SCAR=17.9
Pod documented
3530 0 ▶ @_ >= 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 1 or confess() 0 0 0
3531  
3532 my $s = Subroutine
3533 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
3534 0 Comment "Unlink a file";
3535 0 SaveFirstFour;
3536 0 $$p{file}->setReg(rdi);
3537 0 Mov rax, 87;
3538 0 Syscall;
3539 0 RestoreFirstFour;
3540 0 } [qw(file)], name => 'unlinkFile';
3541  
3542 0 $s->call(@variables);
3543 }
3544  
3545 #D1 Hash functions # Hash functions
3546  
3547 sub Hash() # Hash a string addressed by rax with length held in rdi and return the hash code in r15.
3548 0 ▶ {@_ == 0 or confess;
Subroutine Hash: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 0 or confess() 0 0 0
3549  
3550 my $sub = Macro # Read file
3551 0 ▶ {Comment "Hash";
Subroutine __ANON__: not called CC=1 SCAR=6.9
3552  
3553 0 PushR my @regs = (rax, rdi, k1, zmm0, zmm1); # Save registers
3554 0 PushR r15;
3555 0 Vpbroadcastq zmm0, rdi; # Broadcast length through ymm0
3556 0 Vcvtuqq2pd zmm0, zmm0; # Convert to lengths to float
3557 0 Vgetmantps zmm0, zmm0, 4; # Normalize to 1 to 2, see: https://hjlebbink.github.io/x86doc/html/VGETMANTPD.html
3558  
3559 0 Add rdi, rax; # Upper limit of string
3560  
3561 ForIn # Hash in ymm0 sized blocks
3562 0 ▶ {Vmovdqu ymm1, "[rax]"; # Load data to hash
Subroutine __ANON__: not called CC=1 SCAR=6.9
3563 0 Vcvtudq2pd zmm1, ymm1; # Convert to float
3564 0 Vgetmantps zmm0, zmm0, 4; # Normalize to 1 to 2, see: https://hjlebbink.github.io/x86doc/html/VGETMANTPD.html
3565  
3566 0 Vmulpd zmm0, zmm1, zmm0; # Multiply current hash by data
3567 }
3568 sub # Remainder in partial block
3569 0 ▶ {Mov r15, -1;
Subroutine __ANON__: not called CC=1 SCAR=6.9
3570 0 Bzhi r15, r15, rdi; # Clear bits that we do not wish to load
3571 0 Kmovq k1, r15; # Take up mask
3572 0 Vmovdqu8 "ymm1{k1}", "[rax]"; # Load data to hash
3573  
3574 0 Vcvtudq2pd zmm1, ymm1; # Convert to float
3575 0 Vgetmantps zmm0, zmm0, 4; # Normalize to 1 to 2, see: https://hjlebbink.github.io/x86doc/html/VGETMANTPD.html
3576  
3577 0 Vmulpd zmm0, zmm1, zmm0; # Multiply current hash by data
3578 0 }, rax, rdi, RegisterSize ymm0;
3579  
3580 0 Vgetmantps zmm0, zmm0, 4; # Normalize to 1 to 2, see: https://hjlebbink.github.io/x86doc/html/VGETMANTPD.html
3581  
3582 0 Mov r15, 0b11110000; # Top 4 to bottom 4
3583 0 Kmovq k1, r15;
3584 0 Vpcompressq "zmm1{k1}", zmm0;
3585 0 Vaddpd ymm0, ymm0, ymm1; # Top 4 plus bottom 4
3586  
3587 0 Mov r15, 0b1100; # Top 2 to bottom 2
3588 0 Kmovq k1, r15;
3589 0 Vpcompressq "ymm1{k1}", ymm0;
3590 0 Vaddpd xmm0, xmm0, xmm1; # Top 2 plus bottom 2
3591  
3592 0 Pslldq xmm0, 2; # Move centers into double words
3593 0 Psrldq xmm0, 4;
3594 0 Mov r15, 0b0101; # Centers to lower quad
3595 0 Kmovq k1, r15;
3596 0 Vpcompressd "xmm0{k1}", xmm0; # Compress to lower quad
3597 0 PopR r15;
3598  
3599 0 Vmovq r15, xmm0; # Result in r15
3600  
3601 0 PopR @regs;
3602 0 } name=> "Hash";
3603  
3604 0 Call $sub;
3605 }
3606  
3607 #D1 Unicode # Convert utf8 to utf32
3608  
3609 sub GetNextUtf8CharAsUtf32(@) # Get the next utf8 encoded character from the addressed memory and return it as a utf32 char.
3610 0 ▶ {my (@parameters) = @_; # Parameters
Subroutine GetNextUtf8CharAsUtf32: not called CC=2 SCAR=17.9
Pod documented
3611 0 ▶ @_ >= 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 1 or confess() 0 0 0
3612  
3613 my $s = Subroutine
3614 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
3615 0 Comment "Get next Utf8 char";
3616  
3617 0 PushR (r11, r12, r13, r14, r15);
3618 0 $$p{fail}->getConst(0); # Clear failure indicator
3619 0 $$p{in}->setReg(r15); # Character to convert
3620 0 ClearRegisters r14; # Move to byte register below does not clear the entire register
3621 0 Mov r14b, "[r15]";
3622 0 my $success = Label; # As shown at: https://en.wikipedia.org/wiki/UTF-8
3623  
3624 0 Cmp r14, 0x7f; # Ascii
3625 IfLe
3626 Then
3627 0 ▶ {$$p{out}->getReg(r14);
Subroutine __ANON__: not called CC=1 SCAR=6.9
3628 0 $$p{size}->copy(1);
3629 0 Jmp $success;
3630 0 };
3631  
3632 0 Cmp r14, 0xdf; # Char size is: 2 bytes
3633 IfLe
3634 Then
3635 0 ▶ {Mov r13b, "[r15+1]";
Subroutine __ANON__: not called CC=1 SCAR=6.9
3636 0 And r13, 0x3f;
3637 0 And r14, 0x1f;
3638 0 Shl r14, 6;
3639 0 Or r14, r13;
3640 0 $$p{out}->getReg(r14);
3641 0 $$p{size}->copy(2);
3642 0 Jmp $success;
3643 0 };
3644  
3645 0 Cmp r14, 0xef; # Char size is: 3 bytes
3646 IfLe
3647 Then
3648 0 ▶ {Mov r12b, "[r15+2]";
Subroutine __ANON__: not called CC=1 SCAR=6.9
3649 0 And r12, 0x3f;
3650 0 Mov r13b, "[r15+1]";
3651 0 And r13, 0x3f;
3652 0 And r14, 0x0f;
3653 0 Shl r13, 6;
3654 0 Shl r14, 12;
3655 0 Or r14, r13;
3656 0 Or r14, r12;
3657 0 $$p{out}->getReg(r14);
3658 0 $$p{size}->copy(3);
3659 0 Jmp $success;
3660 0 };
3661  
3662 0 Cmp r14, 0xf7; # Char size is: 4 bytes
3663 IfLe
3664 Then
3665 0 ▶ {Mov r11b, "[r15+3]";
Subroutine __ANON__: not called CC=1 SCAR=6.9
3666 0 And r11, 0x3f;
3667 0 Mov r12b, "[r15+2]";
3668 0 And r12, 0x3f;
3669 0 Mov r13b, "[r15+1]";
3670 0 And r13, 0x3f;
3671 0 And r14, 0x07;
3672 0 Shl r12, 6;
3673 0 Shl r13, 12;
3674 0 Shl r14, 18;
3675 0 Or r14, r13;
3676 0 Or r14, r12;
3677 0 Or r14, r11;
3678 0 $$p{out}->getReg(r14);
3679 0 $$p{size}->copy(4);
3680 0 Jmp $success;
3681 0 };
3682  
3683 0 $$p{fail}->getConst(1); # Conversion failed
3684  
3685 0 SetLabel $success;
3686  
3687 0 PopR;
3688 0 } [qw(in out size fail)], name => 'GetNextUtf8CharAsUtf32';
3689  
3690 0 $s->call(@parameters);
3691 } # GetNextUtf8CharAsUtf32
3692  
3693 sub ConvertUtf8ToUtf32(@) # Convert a string of utf8 to an allocated block of utf32 and return its address and length.
3694 0 ▶ {my (@parameters) = @_; # Parameters
Subroutine ConvertUtf8ToUtf32: not called CC=2 SCAR=17.9
Pod documented
3695 0 ▶ @_ >= 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 1 or confess() 0 0 0
3696  
3697 my $s = Subroutine
3698 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
3699 0 Comment "Convert utf8 to utf32";
3700  
3701 0 PushR (r10, r11, r12, r13, r14, r15);
3702  
3703 0 my $size = $$p{size8} * 4; # Estimated length for utf32
3704 0 AllocateMemory size => $size, my $address = V(address);
3705  
3706 0 $$p{u8} ->setReg(r14); # Current position in input string
3707 0 ($$p{u8}+$$p{size8})->setReg(r15); # Upper limit of input string
3708 0 $address->setReg(r13); # Current position in output string
3709 0 ClearRegisters r12; # Number of characters in output string
3710  
3711 ForEver sub # Loop through input string converting each utf8 sequence to utf32
3712 0 ▶ {my ($start, $end) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
3713 0 my @p = my ($out, $size, $fail) = (V(out), V(size), V('fail'));
3714 0 GetNextUtf8CharAsUtf32 V(in, r14), @p; # Get next utf 8 character and convert it to utf32
3715 If $fail > 0,
3716 Then
3717 0 ▶ {PrintErrStringNL "Invalid utf8 character at index:";
Subroutine __ANON__: not called CC=1 SCAR=6.9
3718 0 PrintErrRegisterInHex r12;
3719 0 Exit(1);
3720 0 };
3721  
3722 0 Inc r12; # Count characters converted
3723 0 $out->setReg(r11); # Output character
3724  
3725 0 Mov "[r13]", r11d;
3726 0 Add r13, RegisterSize eax; # Move up 32 bits output string
3727 0 $size->setReg(r10); # Decoded this many bytes
3728 0 Add r14, r10; # Move up in input string
3729 0 Cmp r14, r15;
3730 0 Jge $end; # Exhausted input string
3731 0 };
3732  
3733 0 $$p{u32} ->copy($address); # Address of allocation
3734 0 $$p{size32}->copy($size); # Size of allocation
3735 0 $$p{count} ->getReg(r12); # Number of unicode points converted from utf8 to utf32
3736 0 PopR;
3737 0 } [qw(u8 size8 u32 size32 count)], name => 'ConvertUtf8ToUtf32';
3738  
3739 0 $s->call(@parameters);
3740 } # ConvertUtf8ToUtf32
3741  
3742 sub ClassifyRange($@) #P Implementation of ClassifyInRange and ClassifyWithinRange.
3743 0 ▶ {my ($recordOffsetInRange, @parameters) = @_; # Record offset in classification in high byte if 1 else in classification if 2, parameters
Subroutine ClassifyRange: not called CC=2 SCAR=17.9
Pod documented
3744 0 ▶ @_ >= 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 1 or confess() 0 0 0
3745  
3746 my $s = Subroutine
3747 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=2 SCAR=17.9
3748 0 Comment "Classify characters in utf32 format";
3749 0 my $finish = Label;
3750  
3751 0 ▶ PushR my @save = (($recordOffsetInRange ? (r12, r13) : ()), # More registers required if we are recording position in range
Branch: 1 branch
BranchTrueFalseTotal
$recordOffsetInRange ? : 0 0 0
3752 r14, r15, k6, k7, zmm 29..31);
3753  
3754 0 Mov r15, 0x88888888; # Create a mask for the classification bytes
3755 0 Kmovq k7, r15;
3756 0 Kshiftlq k6, k7, 32; # Move mask into upper half of register
3757 0 Korq k7, k6, k7; # Classification bytes masked by k7
3758  
3759 0 Knotq k7, k7; # Utf32 characters mask
3760 0 Vmovdqu8 "zmm31\{k7}{z}", zmm1; # Utf32 characters at upper end of each range
3761 0 Vmovdqu8 "zmm30\{k7}{z}", zmm0; # Utf32 characters at lower end of each range
3762  
3763 0 $$p{address}->setReg(r15); # Address of first utf32 character
3764 $$p{size}->for(sub # Process each utf32 character in the block of memory
3765 0 ▶ {my ($index, $start, $next, $end) = @_;
Subroutine __ANON__: not called CC=3 SCAR=24.8
3766  
3767 0 Mov r14d, "[r15]"; # Load utf32 character
3768 0 Add r15, RegisterSize r14d; # Move up to next utf32 character
3769 0 Vpbroadcastd zmm29, r14d; # Process 16 copies of the utf32 character
3770 0 Vpcmpud k7, zmm29, zmm30, 5; # Look for start of range
3771 0 Vpcmpud "k6\{k7}", zmm29, zmm31, 2; # Look for end of range
3772 0 Ktestw k6, k6; # Was there a match ?
3773 0 Jz $next; # No character was matched
3774 # Process matched character
3775 0 ▶ if ($recordOffsetInRange == 1) # Record offset in classification range in high byte as used for bracket matching
Branch: 2 branches
BranchTrueFalseTotal
if ($recordOffsetInRange == 1) { } 0 0 0
elsif ($recordOffsetInRange == 2) { } 0 0 0
3776 0 {Vpcompressd "zmm29\{k6}", zmm0; # Place classification byte at start of xmm29
3777 0 Vpextrd r13d, xmm29, 4; # Extract start of range
3778 0 Mov r12, r13; # Copy start of range
3779 0 Shr r12, 24; # Classification start
3780 0 And r13, 0x00ffffff; # Range start
3781 0 Sub r14, r13; # Offset in range
3782 0 Add r12, r14; # Offset in classification
3783 0 Mov "[r15-1]", r12b; # Save classification
3784 }
3785 elsif ($recordOffsetInRange == 2) # Record classification in high byte and offset in classification range in low byte as used for alphabets
3786 0 {Vpcompressd "zmm29\{k6}", zmm0; # Place classification byte and start of range at start of xmm29
3787 0 Vpextrd r13d, xmm29, 4; # Extract start of range specification
3788 0 Mov r12, r13; # Range classification code and start of range
3789 0 Shr r12, 24; # Range classification code
3790 0 Mov "[r15-1]", r12b; # Save classification
3791 0 And r13, 0x00ffffff; # Range start
3792  
3793 0 Vpcompressd "zmm29\{k6}", zmm1; # Place start of alphabet at start of xmm29
3794 0 Vpextrd r12d, xmm29, 4; # Extract offset of alphabet in range
3795 0 Shr r12, 24; # Alphabet offset
3796 0 Add r12, r14; # Range start plus utf32
3797 0 Sub r12, r13; # Offset of utf32 in alphabet range
3798 0 Mov "[r15-4]", r12b; # Save offset of utf32 in alphabet range
3799 0 ClearRegisters r12; # Zero r12
3800 0 Mov "[r15-3]", r12w; # Clear middle of utf32
3801 }
3802 else # Record classification in high byte
3803 0 {Vpcompressd "zmm29\{k6}", zmm0; # Place classification byte at start of xmm29
3804 0 Vpextrb "[r15-1]", xmm29, 3; # Extract and save classification
3805 }
3806 0 });
3807  
3808 0 SetLabel $finish;
3809 0 PopR;
3810 0 } [qw(address size)], name => "ClassifyRange_$recordOffsetInRange";
3811  
3812 0 $s->call(@parameters);
3813 } # ClassifyRange
3814  
3815 sub ClassifyInRange(@) # Character classification: classify the utf32 characters in a block of memory of specified length using a range specification held in zmm0, zmm1 formatted in double words with each word in zmm1 having the classification in the highest 8 bits and with zmm0 and zmm1 having the utf32 character at the start (zmm0) and end (zmm1) of each range in the lower 21 bits. The classification bits from the first matching range are copied into the high (unused) byte of each utf32 character in the block of memory.
3816 0 ▶ {my (@parameters) = @_; # Parameters
Subroutine ClassifyInRange: not called CC=1 SCAR=6.9
Pod documented
3817 0 ClassifyRange(0, @_);
3818 }
3819  
3820 sub ClassifyWithInRange(@) # Bracket classification: Classify the utf32 characters in a block of memory of specified length using a range specification held in zmm0, zmm1 formatted in double words with the classification range in the highest 8 bits of zmm0 and zmm1 and the utf32 character at the start (zmm0) and end (zmm1) of each range in the lower 21 bits. The classification bits from the position within the first matching range are copied into the high (unused) byte of each utf32 character in the block of memory.
3821 0 ▶ {my (@parameters) = @_; # Parameters
Subroutine ClassifyWithInRange: not called CC=1 SCAR=6.9
Pod documented
3822 0 ClassifyRange(1, @_);
3823 }
3824  
3825 sub ClassifyWithInRangeAndSaveOffset(@) # Alphabetic classification: classify the utf32 characters in a block of memory of specified length using a range specification held in zmm0, zmm1 formatted in double words with the classification code in the high byte of zmm1 and the offset of the first element in the range in the high byte of zmm0. The lowest 21 bits of each double word in zmm0 and zmm1 contain the utf32 characters marking the start and end of each range. The classification bits from zmm1 for the first matching range are copied into the high byte of each utf32 character in the block of memory. The offset in the range is copied into the lowest byte of each utf32 character in the block of memory. The middle two bytes are cleared. The net effect is to reduce 21 bits of utf32 to 16 bits.
3826 0 ▶ {my (@parameters) = @_; # Parameters
Subroutine ClassifyWithInRangeAndSaveOffset: not called CC=1 SCAR=6.9
Pod documented
3827 0 ClassifyRange(2, @_);
3828 }
3829  
3830 #D1 Short Strings # Operations on Short Strings
3831  
3832 sub CreateShortString($) # Create a description of a short string.
3833 0 ▶ {my ($zmm) = @_; # Numbered zmm containing the string
Subroutine CreateShortString: not called CC=5 SCAR=34.0
Pod documented
3834 0 ▶ @_ == 1 or confess "One parameter";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess("One parameter") 0 0 0
3835 0 ▶ $zmm =~ m(\A\d+\Z) && $zmm >=0 && $zmm < 32 or
Branch: 1 branch
BranchTrueFalseTotal
$zmm =~ /\A\d+\Z/ and $zmm >= 0 and $zmm < 32 or confess("Zmm register number required") 0 0 0
Condition0%0/6
$zmm =~ /\A\d+\Z/ and $zmm >= 0 and $zmm < 32
!ll&&!rl&&r
000
$zmm =~ /\A\d+\Z/ and $zmm >= 0
!ll&&!rl&&r
000
MC/DC0%0/3
$zmm =~ /\A\d+\Z/ and $zmm >= 0 and $zmm < 32
$zmm =~ /\A\d+\Z/ $zmm >= 0 $zmm < 32
Truth table0%0/4
A and B and C
A= $zmm =~ /\A\d+\Z/B= $zmm >= 0C= $zmm < 32
ABCresult
0XX0
10X0
1100
1111
3836 confess "Zmm register number required";
3837  
3838 0 genHash(__PACKAGE__."::ShortString", # A short string up to 63 bytes long held in a zmm register.
3839 maximumLength => RegisterSize(zmm0) - 1, # The maximum length of a short string
3840 zmm => $zmm, # The number of the zmm register containing the string
3841 x => "xmm$zmm", # The associated xmm register
3842 z => "zmm$zmm", # The full name of the zmm register
3843 );
3844 }
3845  
3846 sub Nasm::X86::ShortString::clear($) # Clear a short string.
3847 0 ▶ {my ($string) = @_; # String
Subroutine clear: not called CC=2 SCAR=17.9
3848 0 ▶ @_ == 1 or confess "One parameter";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess("One parameter") 0 0 0
3849 0 my $z = $string->z; # Zmm register to use
3850 0 ClearRegisters $z; # Clear the register we are going to use as a short string
3851 }
3852  
3853 sub Nasm::X86::ShortString::load($$$) # Load the variable addressed data with the variable length into the short string.
3854 0 ▶ {my ($string, $address, $length) = @_; # String, address, length
Subroutine load: not called CC=2 SCAR=17.9
3855 0 ▶ @_ == 3 or confess '3 parameters';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess("3 parameters") 0 0 0
3856 0 my $z = $string->z; # Zmm register to use
3857 0 my $x = $string->x; # Corresponding xmm
3858  
3859 0 $string->clear; # Clear the register we are going to use as a short string
3860  
3861 0 PushR r14, r15, k7;
3862 0 $length->setReg(r15); # Length of string
3863 0 Mov r14, -1; # Clear bits that we do not wish to load
3864 0 Bzhi r14, r14, r15;
3865 0 Shl r14, 1; # Move over length byte
3866 0 Kmovq k7, r14; # Load mask
3867  
3868 0 $address->setReg(r14); # Address of data to load
3869 0 Vmovdqu8 "${z}{k7}", "[r14-1]"; # Load string skipping length byte
3870 0 Pinsrb $x, r15b, 0; # Set length in zmm
3871 0 PopR;
3872 }
3873  
3874 sub Nasm::X86::ShortString::loadConstantString($$) # Load the a short string with a constant string.
3875 0 ▶ {my ($string, $data) = @_; # Short string, string to load
Subroutine loadConstantString: not called CC=2 SCAR=17.9
3876 0 ▶ @_ == 2 or confess '2 parameters';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess("2 parameters") 0 0 0
3877 0 my $z = $string->z; # Zmm register to use
3878 0 my $x = $string->x; # Corresponding xmm
3879  
3880 0 $string->clear; # Clear the register we are going to use as a short string
3881  
3882 0 PushR r14, r15, k7;
3883 0 Mov r15, length $data; # Length of string
3884 0 Mov r14, -1; # Clear bits that we do not wish to load
3885 0 Bzhi r14, r14, r15;
3886 0 Shl r14, 1; # Move over length byte
3887 0 Kmovq k7, r14; # Load mask
3888  
3889 0 Mov r14, Rs($data); # Address of data to load
3890 0 Vmovdqu8 "${z}{k7}", "[r14-1]"; # Load string skipping length byte
3891 0 Pinsrb $x, r15b, 0; # Set length in zmm
3892 0 PopR;
3893 0 $string
3894 }
3895  
3896 sub Nasm::X86::ShortString::loadDwordBytes($$$$;$) # Load the specified byte of each dword in the variable addressed data with the variable length into the short string.
3897 0 ▶ {my ($string, $byte, $address, $length, $Offset) = @_; # String, byte offset 0-3, variable address, variable length, variable offset in short string at which to start
Subroutine loadDwordBytes: not called CC=7 SCAR=40.3
3898 0 ▶ @_ == 4 or @_ == 5 or confess "4 or 5 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 4 or @_ == 5 or confess("4 or 5 parameters") 0 0 0
Condition0%0/3
@_ == 4 or @_ == 5
l!l&&r!l&&!r
000
MC/DC0%0/2
@_ == 4 or @_ == 5
@_ == 4 @_ == 5
Truth table0%0/3
A or B
A= @_ == 4B= @_ == 5
ABresult
1X1
011
000
3899 0 ▶ my $offset = $Offset // 0; # Offset in short string at which to start the load
Condition0%0/2
$Offset // 0
l!l
00
MC/DC0%0/1
$Offset // 0
$Offset
Truth table0%0/2
A
A= $Offset
Aresult
11
00
3900 0 ▶ $byte >= 0 and $byte < 4 or confess "Invalid offset in dword";
Branch: 1 branch
BranchTrueFalseTotal
$byte >= 0 and $byte < 4 or confess("Invalid offset in dword") 0 0 0
Condition0%0/3
$byte >= 0 and $byte < 4
!ll&&!rl&&r
000
MC/DC0%0/2
$byte >= 0 and $byte < 4
$byte >= 0 $byte < 4
Truth table0%0/3
A and B
A= $byte >= 0B= $byte < 4
ABresult
0X0
100
111
3901 0 my $z = $string->z; # Zmm register to use
3902 0 my $x = $string->x; # Corresponding xmm
3903  
3904 0 $string->clear; # Clear the register we are going to use as a short string
3905  
3906 0 PushR r13, r14, r15, $z; # Build an image of the short string on the stack and then pop it into the short string zmm
3907  
3908 0 my $m = $length->min($string->maximumLength); # Length to load
3909 0 $m->setReg(r15);
3910 0 ▶ Add r15, $offset if $Offset; # Include the offset in the length of the string if an offset has been supplied
Branch: 1 branch
BranchTrueFalseTotal
if $Offset 0 0 0
3911 0 Mov "[rsp]", r15b; # Save length on stack image of short string
3912  
3913 0 $address->setReg(r15); # Source dwords
3914 $m->for(sub # Load each byte while there is room in the short string
3915 0 ▶ {my ($index, $start, $next, $end) = @_; # Execute block
Subroutine __ANON__: not called CC=1 SCAR=6.9
3916 0 $index->setReg(r14); # Index source and target
3917 0 Mov r13b, "[r15+4*r14+$byte]"; # Load next byte from specified position in the source dword
3918 0 Mov "[rsp+r14+1+$offset]", r13b; # Save next byte skipping length
3919 0 });
3920  
3921 0 PopR;
3922 }
3923  
3924 sub Nasm::X86::ShortString::len($) # Return the length of a short string in a variable.
3925 0 ▶ {my ($string) = @_; # String
Subroutine len: not called CC=2 SCAR=17.9
3926 0 ▶ @_ == 1 or confess "One parameter";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess("One parameter") 0 0 0
3927 0 my $z = $string->z; # Zmm register to use
3928 0 my $x = $string->x; # Corresponding xmm
3929 0 PushR r15;
3930 0 Pextrb r15, $x, 0; # Length
3931 0 my $l = V(size, r15); # Length as a variable
3932 0 PopR;
3933 0 $l
3934 }
3935  
3936 sub Nasm::X86::ShortString::setLength($$) # Set the length of the short string.
3937 0 ▶ {my ($string, $length) = @_; # String, variable size
Subroutine setLength: not called CC=2 SCAR=17.9
3938 0 ▶ @_ == 2 or confess "Two parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess("Two parameters") 0 0 0
3939 0 my $x = $string->x; # Corresponding xmm
3940  
3941 0 PushR (r15);
3942 0 $length->setReg(r15); # Length of string
3943 0 Pinsrb $x, r15b, 0; # Set length in zmm
3944 0 PopR;
3945 }
3946  
3947 sub Nasm::X86::ShortString::appendByte($$) # Append the lowest variable byte to the specified string.
3948 0 ▶ {my ($string, $char) = @_; # String, variable byte
Subroutine appendByte: not called CC=2 SCAR=17.9
3949 0 ▶ @_ == 2 or confess "Two parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess("Two parameters") 0 0 0
3950 0 my $z = $string->z; # Zmm register to use
3951 0 my $x = $string->x; # Corresponding xmm
3952  
3953 my $s = Subroutine # Append byte to short string
3954 0 ▶ {PushR r14, r15;
Subroutine __ANON__: not called CC=1 SCAR=6.9
3955 0 Pextrb r15, $x, 0; # Length of string
3956 0 Cmp r15, $string->maximumLength; # Check current length against maximum length for a short string
3957 IfLt
3958 Then # Room for an additional character
3959 0 ▶ {PushR $z; # Stack string
Subroutine __ANON__: not called CC=1 SCAR=6.9
3960 0 $char->setReg(r14); # Byte to append
3961 0 Mov "[rsp+r15+1]", r14b; # Place byte
3962 0 PopR; # Reload string with additional byte
3963 0 Inc r15; # New length
3964 0 Pinsrb $x, r15b, 0; # Set length in zmm
3965 0 };
3966 0 PopR;
3967 0 } [], name=> "Nasm::X86::ShortString::appendByte_$z";
3968  
3969 0 $s->call;
3970 }
3971  
3972 sub Nasm::X86::ShortString::append($$) # Append the right hand short string to the left hand short string.
3973 0 ▶ {my ($left, $right) = @_; # Target zmm, source zmm
Subroutine append: not called CC=2 SCAR=17.9
3974 0 ▶ @_ == 2 or confess "Two parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess("Two parameters") 0 0 0
3975 0 my $lz = $left ->z; # Zmm register for left string
3976 0 my $lx = $left ->x; # Corresponding xmm
3977 0 my $rz = $right->z; # Zmm register for left string
3978 0 my $rx = $right->x; # Corresponding xmm
3979  
3980 my $s = Subroutine # Append two short strings
3981 0 ▶ {PushR (k7, rcx, r14, r15);
Subroutine __ANON__: not called CC=1 SCAR=6.9
3982 0 Pextrb r15, $rx, 0; # Length of right hand string
3983 0 Mov r14, -1; # Expand mask
3984 0 Bzhi r14, r14, r15; # Skip bits for left
3985 0 Pextrb rcx, $lx, 0; # Length of left hand string
3986 0 Inc rcx; # Skip length
3987 0 Shl r14, cl; # Skip length
3988 0 Kmovq k7, r14; # Unload mask
3989 0 PushRR $rz; # Stack right
3990 0 Sub rsp, rcx; # Position for masked read
3991 0 Vmovdqu8 $lz."{k7}", "[rsp+1]"; # Load right string
3992 0 Add rsp, rcx; # Restore stack
3993 0 Add rsp, RegisterSize zmm0;
3994 0 Dec rcx; # Length of left
3995 0 Add rcx, r15; # Length of combined string = length of left plus length of right
3996 0 Pinsrb $lx, cl, 0; # Save new length in left hand result
3997 0 PopR;
3998 0 } [], name=> "Nasm::X86::ShortString::append_${lz}_${rz}";
3999  
4000 0 $s->call;
4001 }
4002  
4003 #D1 Arenas # An arena is single extensible block of memory which contains other data structures such as strings, arrays, trees within it.
4004  
4005 sub Cstrlen() #P Length of the C style string addressed by rax returning the length in r15.
4006 0 ▶ {@_ == 0 or confess "No parameters";
Subroutine Cstrlen: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 0 or confess("No parameters") 0 0 0
4007  
4008 my $sub = Macro # Create arena
4009 0 ▶ {Comment "C strlen";
Subroutine __ANON__: not called CC=1 SCAR=6.9
4010 0 PushR my @regs = (rax, rdi, rcx);
4011 0 Mov rdi, rax;
4012 0 Mov rcx, -1;
4013 0 ClearRegisters rax;
4014 0 push @text, <<END;
4015 repne scasb
4016 END
4017 0 Mov r15, rcx;
4018 0 Not r15;
4019 0 Dec r15;
4020 0 PopR @regs;
4021 0 } name => "Cstrlen";
4022  
4023 0 Call $sub;
4024 }
4025  
4026 sub StringLength(@) # Length of a zero terminated string.
4027 0 ▶ {my (@parameters) = @_; # Parameters
Subroutine StringLength: not called CC=1 SCAR=6.9
Pod documented
4028 0 Comment "Length of zero terminated string";
4029  
4030 my $s = Subroutine
4031 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
4032 0 SaveFirstFour;
4033 0 $$p{string}->setReg(rax); # Address string
4034 0 Cstrlen; # Length now in r15
4035 0 $$p{size}->getReg(r15); # Save length
4036 0 RestoreFirstFour;
4037 0 } [qw(string size)], name => 'StringLength';
4038  
4039 0 $s->call(@parameters, my $z = V(size)); # Variable that holds the length of the string
4040 0 $z
4041 }
4042  
4043 sub DescribeArena(;$) # Describe a relocatable arena.
4044 0 ▶ {my ($bs) = @_; # Optional variable addressing the start of the arena
Subroutine DescribeArena: not called CC=1 SCAR=6.9
Pod documented
4045 0 my $N = 4096; # Initial size of arena
4046  
4047 0 my $quad = RegisterSize rax; # Field offsets
4048 0 my $size = 0;
4049 0 my $used = $size + $quad;
4050 0 my $free = $used + $quad;
4051 0 my $data = $free + $quad;
4052  
4053 0 genHash(__PACKAGE__."::Arena", # Definition of arena
4054 N => $N, # Initial allocation
4055 size => $size, # Size field offset
4056 used => $used, # Used field offset
4057 free => $free, # Free chain offset
4058 data => $data, # The start of the data
4059 bs => $bs, # Variable that addresses the arena
4060 );
4061 }
4062  
4063 sub CreateArena(%) # Create an relocatable arena and returns its address in rax. We add a chain header so that 64 byte blocks of memory can be freed and reused within the arena.
4064 0 ▶ {my (%options) = @_; # Free=>1 adds a free chain.
Subroutine CreateArena: not called CC=1 SCAR=6.9
Pod documented
4065 0 my $arena = DescribeArena; # Describe an arena
4066 0 my $N = $arena->N;
4067 0 my $used = $arena->used;
4068 0 my $free = $arena->free;
4069 0 my $data = $arena->data;
4070 0 my $size = $arena->size;
4071  
4072 my $s = Subroutine # Allocate arena
4073 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
4074 0 SaveFirstFour;
4075  
4076 0 AllocateMemory(K(size, $N), address=>$$p{bs}); # Allocate memory and save its location in a variable
4077  
4078 0 $$p{bs}->setReg(rax);
4079 0 Mov "dword[rax+$used]", $data; # Initially used space
4080 0 Mov "dword[rax+$size]", $N; # Size
4081  
4082 0 RestoreFirstFour;
4083 0 } [qw(bs)], name => 'CreateArena';
4084  
4085 0 $s->call(my $bs = G(bs)); # Variable that holds the reference to the arena which is updated when the arena is reallocated
4086  
4087 0 DescribeArena($bs); # Describe the arena with its address
4088 }
4089  
4090 sub Nasm::X86::Arena::chain($$$@) #P Return a variable with the end point of a chain of double words in the arena starting at the specified variable.
4091 0 ▶ {my ($arena, $bs, $variable, @offsets) = @_; # Arena descriptor, arena locator, start variable, offsets chain
Subroutine chain: not called CC=3 SCAR=24.8
4092 0 ▶ @_ >= 3 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 3 or confess() 0 0 0
4093  
4094 0 PushR (r14, r15); # Register 14 is the arena address, 15 the current offset in the arena
4095 0 $bs->setReg(r14);
4096 0 $variable->setReg(r15);
4097 0 for my $o(@offsets) # Each offset
4098 0 {Mov r15d, "dword[r14+r15+$o]"; # Step through each offset
4099 }
4100 0 my $r = V(join (' ', @offsets), r15); # Create a variable with the result
4101 0 PopR;
4102 0 $r
4103 }
4104  
4105 sub Nasm::X86::Arena::putChain($$$$@) #P Write the double word in the specified variable to the double word location at the the specified offset in the specified arena.
4106 0 ▶ {my ($arena, $bs, $start, $value, @offsets) = @_; # Arena descriptor, arena locator variable, start variable, value to put as a variable, offsets chain
Subroutine putChain: not called CC=4 SCAR=30.0
4107 0 ▶ @_ >= 5 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 5 or confess() 0 0 0
4108  
4109 0 PushR (r14, r15); # Register 14 is the arena address, 15 the current offset in the arena
4110 0 $bs->setReg(r14);
4111 0 $start->setReg(r15);
4112 0 for my $i(keys @offsets) # Each offset
4113 0 {my $o = $offsets[$i];
4114 0 ▶ if ($i < $#offsets) # Step through each offset
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $#offsets) { } 0 0 0
4115 0 {Mov r15d, "dword[r14+r15+$o]";
4116 }
4117 else # Address last location
4118 0 {Lea r15, "[r14+r15+$o]";
4119 }
4120 }
4121 0 $value->setReg(r14);
4122 0 Mov "[r15]", r14d;
4123 0 PopR;
4124 }
4125  
4126 sub Nasm::X86::Arena::length($@) # Get the length of an arena.
4127 0 ▶ {my ($arena, @variables) = @_; # Arena descriptor, variables
Subroutine length: not called CC=2 SCAR=17.9
4128 0 ▶ @_ >= 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 or confess() 0 0 0
4129  
4130 my $s = Subroutine # Allocate more space if required
4131 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
4132 0 SaveFirstFour;
4133 0 $$p{bs}->setReg(rax); # Address arena
4134 0 Mov rdx, "[rax+$$arena{used}]"; # Used
4135 0 Sub rdx, $arena->data; # Offset of size field
4136 0 $$p{size}->getReg(rdx);
4137 0 RestoreFirstFour;
4138 0 } [qw(bs size)], name => 'Nasm::X86::Arena::length';
4139  
4140 0 $s->call($arena->bs, @variables);
4141 }
4142  
4143 sub Nasm::X86::Arena::arenaSize($@) # Get the size of an arena.
4144 0 ▶ {my ($arena, @variables) = @_; # Arena descriptor, variables
Subroutine arenaSize: not called CC=2 SCAR=17.9
4145 0 ▶ @_ >= 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 or confess() 0 0 0
4146  
4147 my $s = Subroutine # Allocate more space if required
4148 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
4149 0 PushR (rax);
4150 0 $$p{bs}->setReg(rax); # Address arena
4151 0 Mov rax, "[rax+$$arena{size}]";
4152 0 $$p{size}->getReg(rax);
4153 0 PopR;
4154 0 } [qw(bs size)], name => 'Nasm::X86::Arena::size';
4155  
4156 0 $s->call($arena->bs, @variables);
4157 }
4158  
4159 sub Nasm::X86::Arena::updateSpace($@) #P Make sure that the arena addressed by rax has enough space to accommodate content of length rdi.
4160 0 ▶ {my ($arena, @variables) = @_; # Arena descriptor, variables
Subroutine updateSpace: not called CC=2 SCAR=17.9
4161  
4162 0 ▶ @_ >= 3 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 3 or confess() 0 0 0
4163  
4164 my $s = Subroutine
4165 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
4166 0 PushR (rax, r11, r12, r13, r14, r15);
4167 0 my $base = rax; # Base of arena
4168 0 my $size = r15; # Current size
4169 0 my $used = r14; # Currently used space
4170 0 my $request = r13; # Requested space
4171 0 my $newSize = r12; # New size needed
4172 0 my $proposed = r11; # Proposed size
4173  
4174 0 $$p{bs} ->setReg($base); # Address arena
4175 0 $$p{size}->setReg($request); # Requested space
4176  
4177 0 Mov $size, "[$base+$$arena{size}]";
4178 0 Mov $used, "[$base+$$arena{used}]";
4179 0 Mov $newSize, $used;
4180 0 Add $newSize, $request;
4181  
4182 0 Cmp $newSize,$size; # New size needed
4183 IfGt # New size is bigger than current size
4184 Then # More space needed
4185 0 ▶ {Mov $proposed, 4096; # Minimum proposed arena size
Subroutine __ANON__: not called CC=1 SCAR=6.9
4186 K(loop, 36)->for(sub # Maximum number of shifts
4187 0 ▶ {my ($index, $start, $next, $end) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
4188 0 Shl $proposed, 1; # New proposed size
4189 0 Cmp $proposed, $newSize; # Big enough?
4190 0 Jge $end; # Big enough!
4191 0 });
4192 0 my $oldSize = V(size, $size); # The old size of the arena
4193 0 my $newSize = V(size, $proposed); # The old size of the arena
4194 0 AllocateMemory(size => $newSize, my $address = V(address)); # Create new arena
4195 0 CopyMemory(target => $address, source => $$p{bs}, $oldSize); # Copy old arena into new arena
4196 0 FreeMemory(address => $$p{bs}, size => $oldSize); # Free previous memory previously occupied arena
4197 0 $$p{bs}->copy($address); # Save new arena address
4198  
4199 0 $$p{bs}->setReg($base); # Address arena
4200 0 Mov "[$base+$$arena{size}]", $proposed; # Save the new size in the arena
4201 0 };
4202  
4203 0 PopR;
4204 0 } [qw(bs size)] , name => 'Nasm::X86::Arena::updateSpace';
4205  
4206 0 $s->call(@variables);
4207 } # updateSpace
4208  
4209 sub Nasm::X86::Arena::makeReadOnly($) # Make an arena read only.
4210 0 ▶ {my ($arena) = @_; # Arena descriptor
Subroutine makeReadOnly: not called CC=2 SCAR=17.9
4211 0 ▶ @_ == 1 or confess "One parameter";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess("One parameter") 0 0 0
4212  
4213 my $s = Subroutine
4214 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
4215 0 Comment "Make an arena readable";
4216 0 SaveFirstFour;
4217 0 $$p{bs}->setReg(rax);
4218 0 Mov rdi, rax; # Address of arena
4219 0 Mov rsi, "[rax+$$arena{size}]"; # Size of arena
4220  
4221 0 Mov rdx, 1; # Read only access
4222 0 Mov rax, 10;
4223 0 Syscall;
4224 0 RestoreFirstFour; # Return the possibly expanded arena
4225 0 } [qw(bs)], name => 'Nasm::X86::Arena::makeReadOnly';
4226  
4227 0 $s->call(bs => $arena->bs);
4228 }
4229  
4230 sub Nasm::X86::Arena::makeWriteable($) # Make an arena writable.
4231 0 ▶ {my ($arena) = @_; # Arena descriptor
Subroutine makeWriteable: not called CC=2 SCAR=17.9
4232 0 ▶ @_ == 1 or confess "One parameter";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess("One parameter") 0 0 0
4233  
4234 my $s = Subroutine
4235 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
4236 0 Comment "Make an arena writable";
4237 0 SaveFirstFour;
4238 0 $$p{bs}->setReg(rax);
4239 0 Mov rdi, rax; # Address of arena
4240 0 Mov rsi, "[rax+$$arena{size}]"; # Size of arena
4241 0 Mov rdx, 3; # Read only access
4242 0 Mov rax, 10;
4243 0 Syscall;
4244 0 RestoreFirstFour; # Return the possibly expanded arena
4245 0 } [qw(bs)], name => 'Nasm::X86::Arena::makeWriteable';
4246  
4247 0 $s->call(bs => $arena->bs);
4248 }
4249  
4250 sub Nasm::X86::Arena::allocate($@) # Allocate the amount of space indicated in rdi in the arena addressed by rax and return the offset of the allocation in the arena in rdi.
4251 0 ▶ {my ($arena, @variables) = @_; # Arena descriptor, variables
Subroutine allocate: not called CC=2 SCAR=17.9
4252 0 ▶ @_ >= 3 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 3 or confess() 0 0 0
4253  
4254 my $s = Subroutine
4255 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
4256 0 Comment "Allocate space in an arena";
4257 0 SaveFirstFour;
4258  
4259 0 $arena->updateSpace($$p{bs}, $$p{size}); # Update space if needed
4260 0 $$p{bs} ->setReg(rax);
4261 0 Mov rsi, "[rax+$$arena{used}]"; # Currently used
4262 0 $$p{offset}->getReg(rsi);
4263 0 $$p{size} ->setReg(rdi);
4264 0 Add rsi, rdi;
4265 0 Mov "[rax+$$arena{used}]", rsi; # Currently used
4266  
4267 0 RestoreFirstFour;
4268 0 } [qw(bs size offset)], name => 'Nasm::X86::Arena::allocate';
4269  
4270 0 $s->call($arena->bs, @variables);
4271 }
4272  
4273 sub Nasm::X86::Arena::blockSize($) #P Size of a block.
4274 0 ▶ {my ($arena) = @_; # Arena
Subroutine blockSize: not called CC=1 SCAR=6.9
4275 0 RegisterSize(zmm0)
4276 }
4277  
4278 sub Nasm::X86::Arena::allocZmmBlock($@) # Allocate a block to hold a zmm register in the specified arena and return the offset of the block in a variable.
4279 0 ▶ {my ($arena, @variables) = @_; # Arena, variables
Subroutine allocZmmBlock: not called CC=2 SCAR=17.9
4280 0 ▶ @_ >= 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 or confess() 0 0 0
4281 0 my $ffb = $arena->firstFreeBlock; # Check for a free block
4282 If $ffb > 0,
4283 Then # Free block available
4284 0 ▶ {PushR (r8, r9, zmm31);
Subroutine __ANON__: not called CC=4 SCAR=30.0
4285 0 $arena->getBlock($arena->bs, $ffb, 31, r8, r9); # Load the first block on the free chain
4286 0 my $second = getDFromZmm(31, 60, r8); # The location of the next pointer is forced upon us by string which got there first.
4287 0 $arena->setFirstFreeBlock($second); # Set the first free block field to point to the second block
4288 0 for my $v(@variables)
4289 0 ▶ {if (ref($v) and $v->name eq "offset")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $v and $v->name eq "offset") 0 0 0
Condition0%0/3
ref $v and $v->name eq "offset"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $v and $v->name eq "offset"
ref $v $v->name eq "offset"
Truth table0%0/3
A and B
A= ref $vB= $v->name eq "offset"
ABresult
0X0
100
111
4290 0 {$v->copy($ffb);
4291 0 last;
4292 }
4293 }
4294 0 PopR;
4295 },
4296 Else # Cannot reuse a free block so use unassigned memory
4297 0 ▶ {$arena->allocate(V(size, RegisterSize(zmm0)), @variables);
Subroutine __ANON__: not called CC=1 SCAR=6.9
4298 0 };
4299 }
4300  
4301 sub Nasm::X86::Arena::allocBlock($$) # Allocate a block to hold a zmm register in the specified arena and return the offset of the block in a variable.
4302 0 ▶ {my ($arena, $bs) = @_; # Arena, address of arena
Subroutine allocBlock: not called CC=3 SCAR=24.8
4303 0 ▶ @_ == 1 or @_ == 2 or confess "One or two parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or @_ == 2 or confess("One or two parameters") 0 0 0
Condition0%0/3
@_ == 1 or @_ == 2
l!l&&r!l&&!r
000
MC/DC0%0/2
@_ == 1 or @_ == 2
@_ == 1 @_ == 2
Truth table0%0/3
A or B
A= @_ == 1B= @_ == 2
ABresult
1X1
011
000
4304 0 $arena->allocZmmBlock # Allocate a zmm block
4305 (bs=>$bs, V(size, RegisterSize(zmm0)), my $o = V(offset));
4306 0 $o # Offset as a variable
4307 }
4308  
4309 sub Nasm::X86::Arena::firstFreeBlock($) #P Create and load a variable with the first free block on the free block chain or zero if no such block in the given arena.
4310 0 ▶ {my ($arena) = @_; # Arena address as a variable
Subroutine firstFreeBlock: not called CC=2 SCAR=17.9
4311 0 ▶ @_ == 1 or confess "One parameter";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess("One parameter") 0 0 0
4312 0 PushR rax;
4313 0 $arena->bs->setReg(rax); #P Address underlying arena
4314 0 Mov rax, "[rax+$$arena{free}]"; # Content of free chain pointer
4315 0 my $v = V('free', rax); # Remainder of the free chain
4316 0 PopR rax;
4317 0 $v
4318 }
4319  
4320 sub Nasm::X86::Arena::setFirstFreeBlock($$) #P Set the first free block field from a variable.
4321 0 ▶ {my ($arena, $offset) = @_; # Arena descriptor, first free block offset as a variable
Subroutine setFirstFreeBlock: not called CC=2 SCAR=17.9
4322 0 ▶ @_ == 2 or confess "Two parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess("Two parameters") 0 0 0
4323  
4324 0 PushR (rax, rsi, rdx);
4325 0 $arena->bs->setReg(rax); # Address underlying arena
4326 0 Lea rdx, "[rax+$$arena{free}]"; # Address of address of free chain
4327 0 $offset->setReg(rsi); # Offset of block being freed
4328 0 Mov "[rdx]", rsi; # Set head of free chain to point to block just freed
4329 0 PopR;
4330 }
4331  
4332 sub Nasm::X86::Arena::freeBlock($@) #P Free a block in an arena by placing it on the free chain.
4333 0 ▶ {my ($arena, @variables) = @_; # Arena descriptor, variables
Subroutine freeBlock: not called CC=2 SCAR=17.9
4334 0 ▶ @_ >= 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 or confess() 0 0 0
4335  
4336 my $s = Subroutine
4337 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
4338 0 PushR my @save = (r8, zmm31);
4339 0 my $rfc = $arena->firstFreeBlock; # Get first free block
4340 0 ClearRegisters @save; # Second block
4341 0 $rfc->putDIntoZmm(31, 60, r8); # The position of the next pointer was dictated by strings.
4342 0 $arena->putBlock($$p{bs}, $$p{offset}, 31); # Link the freed block to the rest of the free chain
4343 0 $arena->setFirstFreeBlock($$p{offset}); # Set free chain field to point to latest free chain element
4344 0 PopR;
4345 0 } [qw(offset bs)], name => 'Nasm::X86::Arena::freeBlock';
4346  
4347 0 $s->call($arena->bs, @variables);
4348 }
4349  
4350 sub Nasm::X86::Arena::getBlock($$$$;$$) #P Get the block with the specified offset in the specified string and return it in the numbered zmm.
4351 0 ▶ {my ($arena, $address, $block, $zmm, $work1, $work2) = @_; # Arena descriptor, arena address variable, offset of the block as a variable, number of zmm register to contain block, first optional work register, second optional work register
Subroutine getBlock: not called CC=10 SCAR=47.0
4352 0 ▶ @_ == 4 or @_ == 6 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 4 or @_ == 6 or confess() 0 0 0
Condition0%0/3
@_ == 4 or @_ == 6
l!l&&r!l&&!r
000
MC/DC0%0/2
@_ == 4 or @_ == 6
@_ == 4 @_ == 6
Truth table0%0/3
A or B
A= @_ == 4B= @_ == 6
ABresult
1X1
011
000
4353 0 ▶ defined($address) or confess;
Branch: 1 branch
BranchTrueFalseTotal
defined $address or confess() 0 0 0
4354 0 ▶ defined($block) or confess;
Branch: 1 branch
BranchTrueFalseTotal
defined $block or confess() 0 0 0
4355 0 ▶ ref($block) =~ m(variable)i or confess;
Branch: 1 branch
BranchTrueFalseTotal
ref($block) =~ /variable/i or confess() 0 0 0
4356  
4357 0 ▶ my $a = $work1 // r14; # Work registers
Condition0%0/3
$work1 // r14()
l!l&&r!l&&!r
000
MC/DC0%0/2
$work1 // r14()
$work1 r14()
Truth table0%0/3
A // B
A= $work1B= r14()
ABresult
1X1
011
000
4358 0 ▶ my $o = $work2 // r15;
Condition0%0/3
$work2 // r15()
l!l&&r!l&&!r
000
MC/DC0%0/2
$work2 // r15()
$work2 r15()
Truth table0%0/3
A // B
A= $work2B= r15()
ABresult
1X1
011
000
4359 0 ▶ PushR my @save = ($a, $o) unless @_ == 6;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 6 0 0 0
4360  
4361 0 $address->setReg($a); # Arena address
4362 0 $block ->setReg($o); # Offset of block in arena
4363  
4364 0 Cmp $o, $arena->data;
4365 IfLt # We could have done this using variable arithmetic, but such arithmetic is expensive and so it is better to use register arithmetic if we can.
4366 Then
4367 0 ▶ {PrintErrStringNL "Attempt to get block before start of arena";
Subroutine __ANON__: not called CC=1 SCAR=6.9
4368 0 $block->errNL("Attempt to get block: ");
4369 0 PrintErrTraceBack;
4370 0 Exit(1);
4371 0 };
4372  
4373 0 Vmovdqu64 "zmm$zmm", "[$a+$o]"; # Read from memory
4374 0 ▶ PopR unless @_ == 6; # Restore registers
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 6 0 0 0
4375 }
4376  
4377 sub Nasm::X86::Arena::putBlock($$$$;$$) #P Write the numbered zmm to the block at the specified offset in the specified arena.
4378 0 ▶ {my ($arena, $address, $block, $zmm, $work1, $work2) = @_; # Arena descriptor, arena address variable, offset of the block as a variable, number of zmm register to contain block, first optional work register, second optional work register
Subroutine putBlock: not called CC=9 SCAR=45.0
4379 0 ▶ @_ >= 4 or @_ >= 6 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 4 or @_ >= 6 or confess() 0 0 0
Condition0%0/3
@_ >= 4 or @_ >= 6
l!l&&r!l&&!r
000
MC/DC0%0/2
@_ >= 4 or @_ >= 6
@_ >= 4 @_ >= 6
Truth table0%0/3
A or B
A= @_ >= 4B= @_ >= 6
ABresult
1X1
011
000
4380 0 ▶ defined($address) or confess "Arena not set";
Branch: 1 branch
BranchTrueFalseTotal
defined $address or confess("Arena not set") 0 0 0
4381 0 ▶ defined($block) or confess;
Branch: 1 branch
BranchTrueFalseTotal
defined $block or confess() 0 0 0
4382  
4383 0 ▶ my $a = $work1 // r14; # Work registers
Condition0%0/3
$work1 // r14()
l!l&&r!l&&!r
000
MC/DC0%0/2
$work1 // r14()
$work1 r14()
Truth table0%0/3
A // B
A= $work1B= r14()
ABresult
1X1
011
000
4384 0 ▶ my $o = $work2 // r15;
Condition0%0/3
$work2 // r15()
l!l&&r!l&&!r
000
MC/DC0%0/2
$work2 // r15()
$work2 r15()
Truth table0%0/3
A // B
A= $work2B= r15()
ABresult
1X1
011
000
4385 0 ▶ PushR my @save = ($a, $o) unless @_ == 6;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 6 0 0 0
4386  
4387 0 $address->setReg($a); # Arena address
4388 0 $block ->setReg($o); # Offset of block in arena
4389  
4390 0 Cmp $o, $arena->data;
4391 IfLt # We could have done this using variable arithmetic, but such arithmetic is expensive and so it is better to use register arithmetic if we can.
4392 Then
4393 0 ▶ {PrintErrStringNL "Attempt to put block before start of arena";
Subroutine __ANON__: not called CC=1 SCAR=6.9
4394 0 $block->errNL("Attempt to put block: ");
4395 0 PrintErrTraceBack;
4396 0 Exit(1);
4397 0 };
4398  
4399 0 Vmovdqu64 "[$a+$o]", "zmm$zmm"; # Read from memory
4400 0 ▶ PopR unless @_ == 6; # Restore registers
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 6 0 0 0
4401 }
4402  
4403 sub Nasm::X86::Arena::m($@) # Append the content with length rdi addressed by rsi to the arena addressed by rax.
4404 0 ▶ {my ($arena, @variables) = @_; # Arena descriptor, variables
Subroutine m: not called CC=2 SCAR=17.9
4405 0 ▶ @_ >= 4 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 4 or confess() 0 0 0
4406 0 my $used = "[rax+$$arena{used}]";
4407  
4408 my $s = Subroutine
4409 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
4410 0 Comment "Append memory to an arena";
4411 0 SaveFirstFour;
4412 0 $$p{bs}->setReg(rax);
4413 0 my $oldUsed = V("used", $used);
4414 0 $arena->updateSpace($$p{bs}, $$p{size}); # Update space if needed
4415  
4416 0 my $target = $oldUsed + $$p{bs};
4417 0 CopyMemory(source => $$p{address}, $$p{size}, target => $target); # Move data in
4418  
4419 0 my $newUsed = $oldUsed + $$p{size};
4420  
4421 0 $$p{bs} ->setReg(rax); # Update used field
4422 0 $newUsed->setReg(rdi);
4423 0 Mov $used, rdi;
4424  
4425 0 RestoreFirstFour;
4426 0 } [qw(bs address size)], name => 'Nasm::X86::Arena::m';
4427  
4428 0 $s->call(@variables);
4429 }
4430  
4431 sub Nasm::X86::Arena::q($$) # Append a constant string to the arena.
4432 0 ▶ {my ($arena, $string) = @_; # Arena descriptor, string
Subroutine q: not called CC=2 SCAR=17.9
4433 0 ▶ @_ == 2 or confess "Two parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess("Two parameters") 0 0 0
4434  
4435 0 my $s = Rs($string);
4436  
4437 0 my $bs = $arena->bs; # Move data
4438 0 my $ad = V(address, $s);
4439 0 my $sz = V(size, length($string));
4440 0 $arena->m($bs, $ad, $sz);
4441 }
4442  
4443 sub Nasm::X86::Arena::ql($$) # Append a quoted string containing new line characters to the arena addressed by rax.
4444 0 ▶ {my ($arena, $const) = @_; # Arena, constant
Subroutine ql: not called CC=3 SCAR=24.8
4445 0 ▶ @_ == 2 or confess "Two parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess("Two parameters") 0 0 0
4446 0 for my $l(split /\s*\n/, $const)
4447 0 {$arena->q($l);
4448 0 $arena->nl;
4449 }
4450 }
4451  
4452 sub Nasm::X86::Arena::char($$) # Append a character expressed as a decimal number to the arena addressed by rax.
4453 0 ▶ {my ($arena, $char) = @_; # Arena descriptor, number of character to be appended
Subroutine char: not called CC=2 SCAR=17.9
4454 0 ▶ @_ == 2 or confess "Two parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess("Two parameters") 0 0 0
4455 0 my $s = Rb(ord($char));
4456 0 $arena->m($arena->bs, V(address, $s), V(size, 1)); # Move data
4457 }
4458  
4459 sub Nasm::X86::Arena::nl($) # Append a new line to the arena addressed by rax.
4460 0 ▶ {my ($arena) = @_; # Arena descriptor
Subroutine nl: not called CC=2 SCAR=17.9
4461 0 ▶ @_ == 1 or confess "One parameter";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess("One parameter") 0 0 0
4462 0 $arena->char("\n");
4463 }
4464  
4465 sub Nasm::X86::Arena::z($) # Append a trailing zero to the arena addressed by rax.
4466 0 ▶ {my ($arena) = @_; # Arena descriptor
Subroutine z: not called CC=2 SCAR=17.9
4467 0 ▶ @_ == 1 or confess "One parameter";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess("One parameter") 0 0 0
4468 0 $arena->char("\0");
4469 }
4470  
4471 sub Nasm::X86::Arena::append($@) # Append one arena to another.
4472 0 ▶ {my ($arena, @variables) = @_; # Arena descriptor, variables
Subroutine append: not called CC=2 SCAR=17.9
4473 0 ▶ @_ >= 3 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 3 or confess() 0 0 0
4474  
4475 my $s = Subroutine
4476 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
4477 0 Comment "Concatenate arenas";
4478 0 SaveFirstFour;
4479 0 $$p{source}->setReg(rax);
4480 0 Mov rdi, "[rax+$$arena{used}]";
4481 0 Sub rdi, $arena->data;
4482 0 Lea rsi, "[rax+$$arena{data}]";
4483 0 $arena->m(bs=>$$p{target}, V(address, rsi), V(size, rdi));
4484 0 RestoreFirstFour;
4485 0 } [qw(target source)], name => 'Nasm::X86::Arena::append';
4486  
4487 0 $s->call(target=>$arena->bs, @variables);
4488 }
4489  
4490 sub Nasm::X86::Arena::clear($) # Clear the arena addressed by rax.
4491 0 ▶ {my ($arena) = @_; # Arena descriptor
Subroutine clear: not called CC=2 SCAR=17.9
4492 0 ▶ @_ == 1 or confess "One parameter";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess("One parameter") 0 0 0
4493  
4494 my $s = Subroutine
4495 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
4496 0 Comment "Clear arena";
4497 0 PushR (rax, rdi);
4498 0 $$p{bs}->setReg(rax);
4499 0 Mov rdi, $arena->data;
4500 0 Mov "[rax+$$arena{used}]", rdi;
4501 0 PopR;
4502 0 } [qw(bs)], name => 'Nasm::X86::Arena::clear';
4503  
4504 0 $s->call(bs => $arena->bs);
4505 }
4506  
4507 sub Nasm::X86::Arena::write($@) # Write the content in an arena addressed by rax to a temporary file and replace the arena content with the name of the temporary file.
4508 0 ▶ {my ($arena, @variables) = @_; # Arena descriptor, variables
Subroutine write: not called CC=2 SCAR=17.9
4509 0 ▶ @_ >= 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 or confess() 0 0 0
4510  
4511 my $s = Subroutine
4512 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
4513 0 Comment "Write an arena to a file";
4514 0 SaveFirstFour;
4515  
4516 0 $$p{file}->setReg(rax);
4517 0 OpenWrite; # Open file
4518 0 my $file = V('fd', rax); # File descriptor
4519  
4520 0 $$p{bs}->setReg(rax); # Write file
4521 0 Lea rsi, "[rax+$$arena{data}]";
4522 0 Mov rdx, "[rax+$$arena{used}]";
4523 0 Sub rdx, $arena->data;
4524  
4525 0 Mov rax, 1; # Write content to file
4526 0 $file->setReg(rdi);
4527 0 Syscall;
4528  
4529 0 $file->setReg(rax);
4530 0 CloseFile;
4531 0 RestoreFirstFour;
4532 0 } [qw(file bs)], name => 'Nasm::X86::Arena::write';
4533  
4534 0 $s->call(bs => $arena->bs, @variables);
4535 }
4536  
4537 sub Nasm::X86::Arena::read($@) # Read the named file (terminated with a zero byte) and place it into the named arena.
4538 0 ▶ {my ($arena, @variables) = @_; # Arena descriptor, variables
Subroutine read: not called CC=2 SCAR=17.9
4539 0 ▶ @_ >= 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 or confess() 0 0 0
4540  
4541 my $s = Subroutine
4542 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
4543 0 Comment "Read an arena";
4544 0 ReadFile($$p{file}, (my $size = V(size)), my $address = V(address));
4545 0 $arena->m($$p{bs}, $size, $address); # Move data into arena
4546 0 FreeMemory($size, $address); # Free memory allocated by read
4547 0 } [qw(bs file)], name => 'Nasm::X86::Arena::read';
4548  
4549 0 $s->call(bs => $arena->bs, @variables);
4550 }
4551  
4552 sub Nasm::X86::Arena::out($) # Print the specified arena addressed by rax on sysout.
4553 0 ▶ {my ($arena) = @_; # Arena descriptor
Subroutine out: not called CC=2 SCAR=17.9
4554 0 ▶ @_ == 1 or confess "One parameter";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess("One parameter") 0 0 0
4555  
4556 my $s = Subroutine
4557 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
4558 0 Comment "Write an arena";
4559 0 SaveFirstFour;
4560 0 $$p{bs}->setReg(rax);
4561  
4562 0 Mov rdi, "[rax+$$arena{used}]"; # Length to print
4563 0 Sub rdi, $arena->data; # Length to print
4564 0 Lea rax, "[rax+$$arena{data}]"; # Address of data field
4565 0 PrintOutMemory;
4566 0 RestoreFirstFour;
4567 0 } [qw(bs)], name => 'Nasm::X86::Arena::out';
4568  
4569 0 $s->call($arena->bs);
4570 }
4571  
4572 sub Nasm::X86::Arena::dump($;$) # Dump details of an arena.
4573 0 ▶ {my ($arena, $depth) = @_; # Arena descriptor, optional amount of memory to dump as the number of 64 byte blocks
Subroutine dump: not called CC=4 SCAR=30.0
4574 0 ▶ @_ == 1 or @_ == 2 or confess "One or two parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or @_ == 2 or confess("One or two parameters") 0 0 0
Condition0%0/3
@_ == 1 or @_ == 2
l!l&&r!l&&!r
000
MC/DC0%0/2
@_ == 1 or @_ == 2
@_ == 1 @_ == 2
Truth table0%0/3
A or B
A= @_ == 1B= @_ == 2
ABresult
1X1
011
000
4575 0 ▶ $depth //= 4; # Default depth
Condition0%0/2
$depth //= 4
l!l
00
MC/DC0%0/1
$depth //= 4
$depth
Truth table0%0/2
A
A= $depth
Aresult
11
00
4576  
4577 0 PushR (rax, r15); # Get address of arena
4578 0 $arena->bs->setReg(rax);
4579  
4580 Call Macro # Bash string
4581 0 ▶ {Comment "Print details of an arena";
Subroutine __ANON__: not called CC=2 SCAR=17.9
4582 0 SaveFirstFour;
4583 0 PrintOutStringNL("Arena");
4584  
4585 0 PushR rax; # Print size
4586 0 Mov rax, "[rax+$$arena{size}]";
4587 0 PrintOutString(" Size: ");
4588 0 PrintOutRaxInHex;
4589 0 PrintOutNL;
4590 0 PopR rax;
4591  
4592 0 PushR rax; # Print used
4593 0 Mov rax, "[rax+$$arena{used}]";
4594 0 PrintOutString(" Used: ");
4595 0 PrintOutRaxInHex;
4596 0 PrintOutNL;
4597 0 PopR rax;
4598  
4599 0 Mov rdi, 64;
4600 0 for my $b(0..$depth-1) # Print the requested number of blocks
4601 0 {my $o = sprintf("%04X: ", 64 * $b);
4602 0 PrintOutString($o);
4603 0 PrintOutMemoryInHexNL;
4604 0 Add rax, 64;
4605 }
4606  
4607 0 RestoreFirstFour;
4608 0 } name => "Nasm::X86::Arena::dump$depth";
4609  
4610 0 PopR;
4611 }
4612  
4613 #D1 String # Strings made from zmm sized blocks of text
4614  
4615 sub DescribeString(%) # Describe a string.
4616 0 ▶ {my (%options) = @_; # String options
Subroutine DescribeString: not called CC=3 SCAR=24.8
Pod documented
4617 0 ▶ @_ >= 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 1 or confess() 0 0 0
4618 0 my $b = RegisterSize zmm0; # Size of a block == size of a zmm register
4619 0 my $o = RegisterSize eax; # Size of a double word
4620  
4621 genHash(__PACKAGE__."::String", # String definition
4622 bs => DescribeArena($options{arena}), # Arena
4623 links => $b - 2 * $o, # Location of links in bytes in zmm
4624 next => $b - 1 * $o, # Location of next offset in block in bytes
4625 prev => $b - 2 * $o, # Location of prev offset in block in bytes
4626 length => $b - 2 * $o - 1, # Maximum length in a block
4627 0 ▶ first => ($options{first}//G('first')), # Variable addressing first block in string if one has not been supplied
Condition0%0/3
$options{"first"} // &G("first")
l!l&&r!l&&!r
000
MC/DC0%0/2
$options{"first"} // &G("first")
$options{"first"} &G("first")
Truth table0%0/3
A // B
A= $options{"first"}B= &G("first")
ABresult
1X1
011
000
4628 );
4629 }
4630  
4631 sub Nasm::X86::Arena::DescribeString22($%) # Describe a string and optionally set its first block.
4632 0 ▶ {my ($arena, %options) = @_; # Arena description, {first=> offset of first block}
Subroutine DescribeString22: not called CC=3 SCAR=24.8
4633 0 ▶ @_ >= 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 1 or confess() 0 0 0
4634 0 my $b = RegisterSize zmm0; # Size of a block == size of a zmm register
4635 0 my $o = RegisterSize eax; # Size of a double word
4636  
4637 genHash(__PACKAGE__."::String", # String definition
4638 bs => $arena, # Bytes string definition
4639 links => $b - 2 * $o, # Location of links in bytes in zmm
4640 next => $b - 1 * $o, # Location of next offset in block in bytes
4641 prev => $b - 2 * $o, # Location of prev offset in block in bytes
4642 length => $b - 2 * $o - 1, # Maximum length in a block
4643 0 ▶ first => ($options{first}//G('first')), # Variable addressing first block in string if one has not been supplied
Condition0%0/3
$options{"first"} // &G("first")
l!l&&r!l&&!r
000
MC/DC0%0/2
$options{"first"} // &G("first")
$options{"first"} &G("first")
Truth table0%0/3
A // B
A= $options{"first"}B= &G("first")
ABresult
1X1
011
000
4644 );
4645 }
4646  
4647 sub Nasm::X86::Arena::DescribeString($%) # Describe a string and optionally set its first block .
4648 0 ▶ {my ($arena, %options) = @_; # Arena description, arena options
Subroutine DescribeString: not called CC=1 SCAR=6.9
4649 0 DescribeString(arena=>$arena->bs, %options);
4650 }
4651  
4652 sub Nasm::X86::Arena::CreateString($) # Create a string from a doubly link linked list of 64 byte blocks linked via 4 byte offsets in an arena and return its descriptor.
4653 0 ▶ {my ($arena) = @_; # Arena description
Subroutine CreateString: not called CC=2 SCAR=17.9
4654 0 ▶ @_ == 1 or confess "One parameter";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess("One parameter") 0 0 0
4655  
4656 0 my $s = $arena->DescribeString; # String descriptor
4657 0 my $first = $s->allocBlock($arena->bs); # Allocate first block
4658 0 $s->first->copy($first); # Record offset of first block
4659  
4660 0 if (1) # Initialize circular list - really it would be better to allow the first block not to have pointers until it actually needed them for compatibility with short strings.
4661 0 {my $nn = $s->next;
4662 0 my $pp = $s->prev;
4663 0 PushR (r14, r15);
4664 0 $arena->bs->setReg(r15);
4665 0 $first ->setReg(r14);
4666 0 Mov "[r15+r14+$nn]", r14d;
4667 0 Mov "[r15+r14+$pp]", r14d;
4668 0 PopR;
4669 }
4670 $s # Description of string
4671 0 }
4672  
4673 sub Nasm::X86::String::address($) #P Address of a string.
4674 0 ▶ {my ($String) = @_; # String descriptor
Subroutine address: not called CC=2 SCAR=17.9
4675 0 ▶ @_ == 1 or confess "One parameter";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess("One parameter") 0 0 0
4676 0 $String->bs->bs;
4677 }
4678  
4679 sub Nasm::X86::String::allocBlock($$) #P Allocate a block to hold a zmm register in the specified arena and return the offset of the block in a variable.
4680 0 ▶ {my ($String, $arena) = @_; # String descriptor, arena address
Subroutine allocBlock: not called CC=2 SCAR=17.9
4681 0 ▶ @_ == 2 or confess "Two parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess("Two parameters") 0 0 0
4682  
4683 0 $String->bs->allocBlock($arena); # Allocate block and return its offset as a variable
4684 }
4685  
4686 sub Nasm::X86::String::getBlockLength($$) #P Get the block length of the numbered zmm and return it in a variable.
4687 0 ▶ {my ($String, $zmm) = @_; # String descriptor, number of zmm register
Subroutine getBlockLength: not called CC=2 SCAR=17.9
4688 0 ▶ @_ == 2 or confess "Two parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess("Two parameters") 0 0 0
4689 0 getBFromZmm $zmm, 0; # Block length
4690 }
4691  
4692 sub Nasm::X86::String::setBlockLengthInZmm($$$) #P Set the block length of the numbered zmm to the specified length.
4693 0 ▶ {my ($String, $length, $zmm) = @_; # String descriptor, length as a variable, number of zmm register
Subroutine setBlockLengthInZmm: not called CC=2 SCAR=17.9
4694 0 ▶ @_ == 3 or confess "Three parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess("Three parameters") 0 0 0
4695 0 PushR (r15); # Save work register
4696 0 $length->setReg(r15); # New length
4697 0 $length->putBIntoZmm($zmm, 0); # Insert block length
4698 0 PopR; # Length of block is a byte
4699 }
4700  
4701 sub Nasm::X86::String::getBlock($$$$) #P Get the block with the specified offset in the specified string and return it in the numbered zmm.
4702 0 ▶ {my ($String, $bsa, $block, $zmm) = @_; # String descriptor, arena variable, offset of the block as a variable, number of zmm register to contain block
Subroutine getBlock: not called CC=2 SCAR=17.9
4703 0 ▶ @_ >= 4 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 4 or confess() 0 0 0
4704 0 $String->bs->getBlock($bsa, $block, $zmm);
4705 }
4706  
4707 sub Nasm::X86::String::putBlock($$$$) #P Write the numbered zmm to the block at the specified offset in the specified arena.
4708 0 ▶ {my ($String, $bsa, $block, $zmm) = @_; # String descriptor, arena variable, block in arena, content variable
Subroutine putBlock: not called CC=2 SCAR=17.9
4709 0 ▶ @_ >= 4 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 4 or confess() 0 0 0
4710 0 $String->bs->putBlock($bsa, $block, $zmm);
4711 }
4712  
4713 sub Nasm::X86::String::getNextAndPrevBlockOffsetFromZmm($$) #P Get the offsets of the next and previous blocks as variables from the specified zmm.
4714 0 ▶ {my ($String, $zmm) = @_; # String descriptor, zmm containing block
Subroutine getNextAndPrevBlockOffsetFromZmm: not called CC=2 SCAR=17.9
4715 0 ▶ @_ == 2 or confess "Two parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess("Two parameters") 0 0 0
4716 0 my $l = $String->links; # Location of links
4717 0 PushR my @regs = (r14, r15); # Work registers
4718 0 my $L = getQFromZmm($zmm, $String->links); # Links in one register
4719 0 $L->setReg(r15); # Links
4720 0 Mov r14d, r15d; # Next
4721 0 Shr r15, RegisterSize(r14d) * 8; # Prev
4722 0 my @r = (V("Next block offset", r15), V("Prev block offset", r14)); # Result
4723 0 PopR @regs; # Free work registers
4724 0 @r; # Return (next, prev)
4725 }
4726  
4727 sub Nasm::X86::String::putNextandPrevBlockOffsetIntoZmm($$$$) #P Save next and prev offsets into a zmm representing a block.
4728 0 ▶ {my ($String, $zmm, $next, $prev) = @_; # String descriptor, zmm containing block, next offset as a variable, prev offset as a variable
Subroutine putNextandPrevBlockOffsetIntoZmm: not called CC=6 SCAR=37.4
4729 0 ▶ @_ == 4 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 4 or confess() 0 0 0
4730 0 ▶ if ($next and $prev) # Set both previous and next
Branch: 3 branches
BranchTrueFalseTotal
if ($next and $prev) { } 0 0 0
elsif ($next) { } 0 0 0
elsif ($prev) { } 0 0 0
Condition0%0/3
$next and $prev
!ll&&!rl&&r
000
MC/DC0%0/2
$next and $prev
$next $prev
Truth table0%0/3
A and B
A= $nextB= $prev
ABresult
0X0
100
111
4731 0 {PushR my @regs = (r14, r15); # Work registers
4732 0 $next->setReg(r14); # Next offset
4733 0 $prev->setReg(r15); # Prev offset
4734 0 Shl r14, RegisterSize(r14d) * 8; # Prev high
4735 0 Or r15, r14; # Links in one register
4736 0 my $l = V("Links", r15); # Links as variable
4737 0 $l->putQIntoZmm($zmm, $String->links); # Load links into zmm
4738 0 PopR @regs; # Free work registers
4739 }
4740 elsif ($next) # Set just next
4741 0 {PushR my @regs = (r8, r15); # Work registers
4742 0 $next->setReg(r15); # Next offset
4743 0 my $l = V("Links", r15); # Links as variable
4744 0 $l->putDIntoZmm($zmm, $String->next, r8); # Load links into zmm
4745 0 PopR @regs; # Free work registers
4746 }
4747 elsif ($prev) # Set just prev
4748 0 {PushR my @regs = (r8, r15); # Work registers
4749 0 $prev->setReg(r15); # Next offset
4750 0 my $l = V("Links", r15); # Links as variable
4751 0 $l->putDIntoZmm($zmm, $String->prev, r8); # Load links into zmm
4752 0 PopR @regs; # Free work registers
4753 }
4754 }
4755  
4756 sub Nasm::X86::String::dump($) # Dump a string to sysout.
4757 0 ▶ {my ($String) = @_; # String descriptor
Subroutine dump: not called CC=2 SCAR=17.9
4758 0 ▶ @_ == 1 or confess "One parameter";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess("One parameter") 0 0 0
4759  
4760 my $s = Subroutine
4761 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
4762 0 Comment "Dump a block in a string";
4763 0 PushR (zmm31);
4764 0 my $block = $$p{first}; # The first block
4765 0 $String->getBlock($$p{bs}, $block, 31); # The first block in zmm31
4766 0 my $length = $String->getBlockLength(31); # Length of block
4767 0 PrintOutStringNL "string Dump";
4768 0 $block ->out("Offset: ");
4769 0 PrintOutString " ";
4770 0 $length->outNL("Length: "); PrintOutRegisterInHex zmm31; # Print block
4771  
4772 ForEver # Each block in string
4773 0 ▶ {my ($start, $end) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
4774 0 my ($next, $prev) = $String->getNextAndPrevBlockOffsetFromZmm(31); # Get links from current block
4775 0 ▶ If $next == $block, sub{Jmp $end}; # Next block is the first block so we have printed the string
Subroutine __ANON__: not called CC=1 SCAR=6.9
4776 0 $String->getBlock($$p{bs}, $next, 31); # Next block in zmm
4777 0 my $length = $String->getBlockLength(31); # Length of block
4778 0 $next ->out("Offset: "); # Print block
4779 0 PrintOutString " ";
4780 0 $length->outNL("Length: "); PrintOutRegisterInHex zmm31;
4781 0 };
4782 0 PrintOutNL;
4783  
4784 0 PopR;
4785 0 } [qw(first bs)], name => 'Nasm::X86::String::dump';
4786  
4787 0 $s->call($String->address, $String->first);
4788 }
4789  
4790 sub Nasm::X86::String::len($;$$) # Find the length of a string.
4791 0 ▶ {my ($String, $bs, $first) = @_; # String descriptor, optional arena address, offset of first block
Subroutine len: not called CC=5 SCAR=34.0
4792 0 ▶ @_ == 1 or @_ == 3 or confess "1 or 3 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or @_ == 3 or confess("1 or 3 parameters") 0 0 0
Condition0%0/3
@_ == 1 or @_ == 3
l!l&&r!l&&!r
000
MC/DC0%0/2
@_ == 1 or @_ == 3
@_ == 1 @_ == 3
Truth table0%0/3
A or B
A= @_ == 1B= @_ == 3
ABresult
1X1
011
000
4793  
4794 my $s = Subroutine
4795 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
4796 0 Comment "Length of a string";
4797 0 PushR (zmm31);
4798 0 my $block = $$p{first}; # The first block
4799 0 $String->getBlock($$p{bs}, $block, 31); # The first block in zmm31
4800 0 my $length = $String->getBlockLength(31); # Length of block
4801  
4802 ForEver # Each block in string
4803 0 ▶ {my ($start, $end) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
4804 0 my ($next, $prev) = $String->getNextAndPrevBlockOffsetFromZmm(31); # Get links from current block
4805 0 ▶ If $next == $block, sub{Jmp $end}; # Next block is the first block so we have traversed the entire string
Subroutine __ANON__: not called CC=1 SCAR=6.9
4806 0 $String->getBlock($$p{bs}, $next, 31); # Next block in zmm
4807 0 $length += $String->getBlockLength(31); # Add length of block
4808 0 };
4809 0 $$p{size}->copy($length);
4810 0 PopR;
4811 0 } [qw(first bs size)], name => 'Nasm::X86::String::len';
4812  
4813 0 ▶ $s->call(($bs//$String->address), ($first//$String->first),
Condition0%0/6
$bs // $String->address
l!l&&r!l&&!r
000
$first // $String->first
l!l&&r!l&&!r
000
MC/DC0%0/2
$bs // $String->address
$bs $String->address
MC/DC0%0/2
$first // $String->first
$first $String->first
Truth table0%0/3
A // B
A= $bsB= $String->address
ABresult
1X1
011
000
Truth table0%0/3
A // B
A= $firstB= $String->first
ABresult
1X1
011
000
4814 my $size = V(size));
4815  
4816 0 $size
4817 }
4818  
4819 sub Nasm::X86::String::concatenate($$) # Concatenate two strings by appending a copy of the source to the target string.
4820 0 ▶ {my ($target, $source) = @_; # Target string, source string
Subroutine concatenate: not called CC=2 SCAR=17.9
4821 0 ▶ @_ == 2 or confess "Two parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess("Two parameters") 0 0 0
4822  
4823 my $s = Subroutine
4824 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
4825 0 Comment "Concatenate strings";
4826 0 PushZmm 29..31;
4827 0 my $sb = $$p{sBs}; # The arena underlying the source
4828 0 my $sf = $$p{sFirst}; # The first block in the source
4829 0 my $tb = $$p{tBs}; # The arena underlying the target
4830 0 my $tf = $$p{tFirst}; # The first block in the target
4831 0 $source->getBlock($sb, $sf, 31); # The first source block
4832 0 $target->getBlock($tb, $tf, 30); # The first target block
4833 0 my ($ts, $tl) = $target->getNextAndPrevBlockOffsetFromZmm(30); # Target second and last
4834 0 $target->getBlock($tb, $tl, 30); # The last target block to which we will append
4835  
4836 ForEver # Each block in source string
4837 0 ▶ {my ($start, $end) = @_; # Start and end labels
Subroutine __ANON__: not called CC=1 SCAR=6.9
4838  
4839 0 my $new = $target->allocBlock($$p{tBs}); # Allocate new block
4840 0 Vmovdqu8 zmm29, zmm31; # Load new target block from source
4841 0 my ($next, $prev) = $target->getNextAndPrevBlockOffsetFromZmm(30); # Linkage from last target block
4842  
4843 0 $target->putNextandPrevBlockOffsetIntoZmm(30, $new, $prev); # From last block
4844 0 $target->putNextandPrevBlockOffsetIntoZmm(29, $tf, $tl); # From new block
4845 0 $target->putBlock($tb, $tl, 30); # Put the modified last target block
4846 0 $tl->copy($new); # New last target block
4847 0 $target->putBlock($tb, $tl, 29); # Put the modified new last target block
4848 0 Vmovdqu8 zmm30, zmm29; # Last target block
4849  
4850 0 my ($sn, $sp) = $source->getNextAndPrevBlockOffsetFromZmm(31); # Get links from current source block
4851 If $sn == $sf,
4852 Then # Last source block
4853 0 ▶ {$source->getBlock($tb, $tf, 30); # The first target block
Subroutine __ANON__: not called CC=1 SCAR=6.9
4854 0 $source->putNextandPrevBlockOffsetIntoZmm(30, undef, $new); # Update end of block chain
4855 0 $source->putBlock($tb, $tf, 30); # Save modified first target block
4856  
4857 0 Jmp $end
4858 0 };
4859  
4860 0 $source->getBlock($sb, $sn, 31); # Next source block
4861 0 };
4862  
4863 0 PopZmm;
4864 0 } [qw(sBs sFirst tBs tFirst)], name => 'Nasm::X86::String::concatenate';
4865  
4866 0 $s->call(sBs => $source->address, sFirst => $source->first,
4867 tBs => $target->address, tFirst => $target->first);
4868 }
4869  
4870 sub Nasm::X86::String::insertChar($@) # Insert a character into a string.
4871 0 ▶ {my ($String, @variables) = @_; # String, variables
Subroutine insertChar: not called CC=2 SCAR=17.9
4872 0 ▶ @_ >= 3 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 3 or confess() 0 0 0
4873  
4874 my $s = Subroutine
4875 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
4876 0 PushR (k7, r14, r15, zmm30, zmm31);
4877 0 my $B = $$p{bs}; # The arena underlying the string
4878 0 my $F = $$p{first}; # The first block in string
4879 0 my $c = $$p{character}; # The character to insert
4880 0 my $P = $$p{position}; # The position in the string at which we want to insert the character
4881 0 $String->getBlock($B, $F, 31); # The first source block
4882  
4883 0 my $C = V('Current character position', 0); # Current character position
4884 0 my $L = $String->getBlockLength(31); # Length of last block
4885 0 my $M = V('Block length', $String->length); # Maximum length of a block
4886 0 my $One = V('One', 1); # Literal one
4887 0 my $current = V(current)->copy($F); # Current position in scan of block chain
4888  
4889 ForEver # Each block in source string
4890 0 ▶ {my ($start, $end) = @_; # Start and end labels
Subroutine __ANON__: not called CC=1 SCAR=6.9
4891  
4892 If $P >= $C,
4893 Then # Position is in current block
4894 {If $P <= $C + $L,
4895 Then # Position is in current block
4896 0 ▶ {my $O = $P - $C; # Offset in current block
Subroutine __ANON__: not called CC=1 SCAR=6.9
4897  
4898 0 PushR zmm31; # Stack block
4899 0 $O->setReg(r14); # Offset of character in block
4900 0 $c->setReg(r15); # Character to insert
4901 0 Mov "[rsp+r14]", r15b; # Place character after skipping length field
4902  
4903 If $L < $M,
4904 Then # Current block has space
4905 0 ▶ {($P+1-$C)->setMask($C + $L - $P + 1, k7); # Set mask for reload
Subroutine __ANON__: not called CC=1 SCAR=6.9
4906 0 Vmovdqu8 "zmm31{k7}", "[rsp-1]"; # Reload
4907 0 $String->setBlockLengthInZmm($L + 1, 31); # Length of block
4908 },
4909 Else # In the current block but no space so split the block
4910 0 ▶ {$One->setMask($C + $L - $P + 2, k7); # Set mask for reload
Subroutine __ANON__: not called CC=1 SCAR=6.9
4911 0 Vmovdqu8 "zmm30{k7}", "[rsp+r14-1]"; # Reload
4912 0 $String->setBlockLengthInZmm($O, 31); # New shorter length of original block
4913 0 $String->setBlockLengthInZmm($L - $O + 1, 30); # Set length of remainder plus inserted char in the new block
4914  
4915 0 my $new = $String->allocBlock($$p{bs}); # Allocate new block
4916 0 my ($next, $prev) = $String->getNextAndPrevBlockOffsetFromZmm(31); # Linkage from last block
4917  
4918 If $next == $prev,
4919 Then # The existing string has one block, add new as the second block
4920 0 ▶ {$String->putNextandPrevBlockOffsetIntoZmm(31, $new, $new);
Subroutine __ANON__: not called CC=1 SCAR=6.9
4921 0 $String->putNextandPrevBlockOffsetIntoZmm(30, $next, $prev);
4922 },
4923 Else # The existing string has two or more blocks
4924 0 ▶ {$String->putNextandPrevBlockOffsetIntoZmm(31, $new, $prev); # From last block
Subroutine __ANON__: not called CC=1 SCAR=6.9
4925 0 $String->putNextandPrevBlockOffsetIntoZmm(30, $next, $current); # From new block
4926 0 };
4927  
4928 0 $String->putBlock($B, $new, 30); # Save the modified block
4929 0 };
4930  
4931 0 $String->putBlock($B, $current, 31); # Save the modified block
4932 0 PopR zmm31; # Restore stack
4933 0 Jmp $end; # Character successfully inserted
4934 0 ▶ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
4935 0 };
4936  
4937 0 my ($next, $prev) = $String->getNextAndPrevBlockOffsetFromZmm(31); # Get links from current source block
4938  
4939 If $next == $F,
4940 Then # Last source block
4941 0 ▶ {$c->setReg(r15); # Character to insert
Subroutine __ANON__: not called CC=1 SCAR=6.9
4942 0 Push r15;
4943 0 Mov r15, rsp; # Address content on the stack
4944 0 $String->append($B, $F, V(size, 1), V(source, r15)); # Append character if we go beyond limit
4945 0 Pop r15;
4946 0 Jmp $end;
4947 0 };
4948  
4949 0 $C += $L; # Current character position at the start of the next block
4950 0 $current->copy($next); # Address next block
4951 0 $String->getBlock($B, $current, 31); # Next block
4952 0 $L->copy($String->getBlockLength(31)); # Length of block
4953 0 };
4954  
4955 0 PopR;
4956 0 } [qw(bs first character position)], name => 'Nasm::X86::String::insertChar';
4957  
4958 0 $s->call($String->address, first => $String->first, @variables)
4959 } #insertChar
4960  
4961 sub Nasm::X86::String::deleteChar($@) # Delete a character in a string.
4962 0 ▶ {my ($String, @variables) = @_; # String, variables
Subroutine deleteChar: not called CC=2 SCAR=17.9
4963 0 ▶ @_ >= 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 or confess() 0 0 0
4964  
4965 my $s = Subroutine
4966 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
4967 0 Comment "Delete a character in a string";
4968 0 PushR (k7, zmm31);
4969 0 my $B = $$p{bs}; # The arena underlying the string
4970 0 my $F = $$p{first}; # The first block in string
4971 0 my $P = $$p{position}; # The position in the string at which we want to insert the character
4972 0 $String->getBlock($B, $F, 31); # The first source block
4973 0 my $C = V('Current character position', 0); # Current character position
4974 0 my $L = $String->getBlockLength(31); # Length of last block
4975 0 my $current = V(currwn)->copy($F); # Current position in scan of block chain
4976  
4977 ForEver # Each block in source string
4978 0 ▶ {my ($start, $end) = @_; # Start and end labels
Subroutine __ANON__: not called CC=1 SCAR=6.9
4979  
4980 If $P >= $C,
4981 Then # Position is in current block
4982 {If $P <= $C + $L,
4983 Then # Position is in current block
4984 0 ▶ {my $O = $P - $C; # Offset in current block
Subroutine __ANON__: not called CC=1 SCAR=6.9
4985 0 PushR zmm31; # Stack block
4986 0 ($O+1)->setMask($L - $O, k7); # Set mask for reload
4987 0 Vmovdqu8 "zmm31{k7}", "[rsp+1]"; # Reload
4988 0 $String->setBlockLengthInZmm($L-1, 31); # Length of block
4989 0 $String->putBlock($B, $current, 31); # Save the modified block
4990 0 PopR zmm31; # Stack block
4991 0 Jmp $end; # Character successfully inserted
4992 0 ▶ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
4993 0 };
4994  
4995 0 my ($next, $prev) = $String->getNextAndPrevBlockOffsetFromZmm(31); # Get links from current source block
4996 0 $String->getBlock($B, $next, 31); # Next block
4997 0 $current->copy($next);
4998 0 $L->copy($String->getBlockLength(31)); # Length of block
4999 0 $C += $L; # Current character position at the start of this block
5000 0 };
5001  
5002 0 PopR;
5003 0 } [qw(first position bs)], name => 'Nasm::X86::String::deleteChar';
5004  
5005 0 $s->call($String->address, first => $String->first, @variables)
5006 }
5007  
5008 sub Nasm::X86::String::getCharacter($@) # Get a character from a string.
5009 0 ▶ {my ($String, @variables) = @_; # String, variables
Subroutine getCharacter: not called CC=2 SCAR=17.9
5010 0 ▶ @_ >= 3 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 3 or confess() 0 0 0
5011  
5012 my $s = Subroutine
5013 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
5014 0 Comment "Get a character from a string";
5015 0 PushR (r15, zmm31);
5016 0 my $B = $$p{bs}; # The arena underlying the string
5017 0 my $F = $$p{first}; # The first block in string
5018 0 my $P = $$p{position}; # The position in the string at which we want to insert the character
5019 0 $String->getBlock($B, $F, 31); # The first source block
5020 0 my $C = V('Current character position', 0); # Current character position
5021 0 my $L = $String->getBlockLength(31); # Length of last block
5022  
5023 ForEver # Each block in source string
5024 0 ▶ {my ($start, $end) = @_; # Start and end labels
Subroutine __ANON__: not called CC=1 SCAR=6.9
5025  
5026 If $P >= $C,
5027 Then # Position is in current block
5028 {If $P <= $C + $L,
5029 Then # Position is in current block
5030 0 ▶ {my $O = $P - $C; # Offset in current block
Subroutine __ANON__: not called CC=1 SCAR=6.9
5031 0 PushR zmm31; # Stack block
5032 0 ($O+1) ->setReg(r15); # Character to get
5033 0 Mov r15b, "[rsp+r15]"; # Reload
5034 0 $$p{out}->getReg(r15); # Save character
5035 0 PopR zmm31; # Stack block
5036 0 Jmp $end; # Character successfully inserted
5037 0 ▶ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
5038 0 };
5039  
5040 0 my ($next, $prev) = $String->getNextAndPrevBlockOffsetFromZmm(31); # Get links from current source block
5041 0 $String->getBlock($B, $next, 31); # Next block
5042 0 $L = $String->getBlockLength(31); # Length of block
5043 0 $C += $L; # Current character position at the start of this block
5044 0 };
5045  
5046 0 PopR;
5047 0 } [qw(first position bs out)], name => 'Nasm::X86::String::getCharacter';
5048  
5049 0 $s->call($String->address, first => $String->first, @variables)
5050 }
5051  
5052 sub Nasm::X86::String::append($@) # Append the specified content in memory to the specified string.
5053 0 ▶ {my ($String, @variables) = @_; # String descriptor, variables
Subroutine append: not called CC=2 SCAR=17.9
5054 0 ▶ @_ >= 3 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 3 or confess() 0 0 0
5055  
5056 my $s = Subroutine
5057 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
5058  
5059 0 my $Z = K(zero, 0); # Zero
5060 0 my $O = K(one, 1); # One
5061 0 my $L = V(size, $String->length); # Length of a full block
5062 0 my $B = $$p{bs}; # Underlying string
5063 0 my $source = V(source)->copy($$p{source}); # Address of content to be appended
5064 0 my $size = V(size) ->copy($$p{size}); # Size of content
5065 0 my $first = $$p{first}; # First (preallocated) block in string
5066  
5067 0 PushZmm 29..31;
5068 ForEver # Append content until source exhausted
5069 0 ▶ {my ($start, $end) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
5070  
5071 0 $String->getBlock($B, $first, 29); # Get the first block
5072 0 my ($second, $last) = $String->getNextAndPrevBlockOffsetFromZmm(29); # Get the offsets of the second and last blocks
5073 0 $String->getBlock($B, $last, 31); # Get the last block
5074 0 my $lengthLast = $String->getBlockLength(31); # Length of last block
5075 0 my $spaceLast = $L - $lengthLast; # Space in last block
5076 0 my $toCopy = $spaceLast->min($size); # Amount of data required to fill first block
5077 0 my $startPos = $O + $lengthLast; # Start position in zmm
5078  
5079 0 $source->setZmm(31, $startPos, $toCopy); # Append bytes
5080 0 $String->setBlockLengthInZmm($lengthLast + $toCopy, 31); # Set the length
5081 0 $String->putBlock($B, $last, 31); # Put the block
5082 0 ▶ If $size <= $spaceLast, sub {Jmp $end}; # We are finished because the last block had enough space
Subroutine __ANON__: not called CC=1 SCAR=6.9
5083  
5084 0 $source += $toCopy; # Remaining source
5085 0 $size -= $toCopy; # Remaining source length
5086  
5087 0 my $new = $String->allocBlock($$p{bs}); # Allocate new block
5088 0 $String->getBlock ($B, $new, 30); # Load the new block
5089 0 my ($next, $prev) = $String->getNextAndPrevBlockOffsetFromZmm(31); # Linkage from last block
5090  
5091 If $first == $last,
5092 Then # The existing string has one block, add new as the second block
5093 0 ▶ {$String->putNextandPrevBlockOffsetIntoZmm(31, $new, $new);
Subroutine __ANON__: not called CC=1 SCAR=6.9
5094 0 $String->putNextandPrevBlockOffsetIntoZmm(30, $last, $last);
5095 },
5096 Else # The existing string has two or more blocks
5097 0 ▶ {$String->putNextandPrevBlockOffsetIntoZmm(31, $new, $prev); # From last block
Subroutine __ANON__: not called CC=1 SCAR=6.9
5098 0 $String->putNextandPrevBlockOffsetIntoZmm(30, $next, $last); # From new block
5099 0 $String->putNextandPrevBlockOffsetIntoZmm(29, undef, $new); # From first block
5100 0 $String->putBlock($B, $first, 29); # Put the modified last block
5101 0 };
5102  
5103 0 $String->putBlock($B, $last, 31); # Put the modified last block
5104 0 $String->putBlock($B, $new, 30); # Put the modified new block
5105 0 };
5106 0 PopZmm;
5107 0 } [qw(bs first source size)], name => 'Nasm::X86::String::append';
5108  
5109 0 $s->call($String->address, $String->first, @variables);
5110 }
5111  
5112 sub Nasm::X86::String::appendShortString($$) # Append the content of the specified short string.
5113 0 ▶ {my ($string, $short) = @_; # String descriptor, short string
Subroutine appendShortString: not called CC=2 SCAR=17.9
5114 0 ▶ @_ == 2 or confess "Two parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess("Two parameters") 0 0 0
5115 0 my $z = $short->z; # Zmm register containing short string
5116 0 PushR r15, $z;
5117 0 my $L = $short->len;
5118 0 Mov r15, rsp;
5119 0 Inc r15;
5120 0 my $S = V(source, r15);
5121 0 $string->append($S, $L);
5122 0 PopR;
5123 }
5124  
5125 sub Nasm::X86::String::saveToShortString($$;$) # Place as much as possible of the specified string into the specified short string.
5126 0 ▶ {my ($string, $short, $first) = @_; # String descriptor, short string descriptor, optional offset to first block of string
Subroutine saveToShortString: not called CC=4 SCAR=30.0
5127 0 ▶ @_ == 2 or confess "Two parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess("Two parameters") 0 0 0
5128 0 ▶ my $z = $short->z; $z eq zmm31 and confess "Cannot use zmm31"; # Zmm register in short string to load must not be zmm31
Branch: 1 branch
BranchTrueFalseTotal
$z eq zmm31() and confess("Cannot use zmm31") 0 0 0
5129  
5130 my $s = Subroutine ### At the moment we only read the first block - we need to read more data out of the string if necessary
5131 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
5132 0 PushR k7, zmm31, r14, r15;
5133 0 $string->getBlock($$p{bs}, $$p{first}, 31); # The first block in zmm31
5134  
5135 0 Mov r15, -1; Shr r15, 1; Shl r15, 9; Shr r15, 8; Kmovq k7, r15; # Mask for the most we can get out of a block of the string
5136 0 $short->clear;
5137 0 Vmovdqu8 "${z}{k7}", zmm31; # Move all the data in the first block
5138  
5139 0 my $b = $string->getBlockLength(31); # Length of block
5140 0 $short->setLength($b); # Set length of short string
5141  
5142 0 PopR;
5143 0 } [qw(bs first)], name => "Nasm::X86::String::saveToShortString_$z"; # Separate by zmm register being loaded
5144  
5145 0 ▶ $s->call(bs => $string->address, first => ($first//$string->first));
Condition0%0/3
$first // $string->first
l!l&&r!l&&!r
000
MC/DC0%0/2
$first // $string->first
$first $string->first
Truth table0%0/3
A // B
A= $firstB= $string->first
ABresult
1X1
011
000
5146  
5147 0 $short # Chain
5148 }
5149  
5150 sub Nasm::X86::String::clear($) # Clear the block by freeing all but the first block.
5151 0 ▶ {my ($String) = @_; # String descriptor
Subroutine clear: not called CC=2 SCAR=17.9
5152 0 ▶ @_ == 1 or confess "One parameter";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess("One parameter") 0 0 0
5153  
5154 my $s = Subroutine
5155 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
5156  
5157 0 PushR rax, r14, r15; PushZmm 29..31;
5158  
5159 0 my $first = $$p{first}; # First block
5160 0 $String->getBlock($$p{bs}, $$p{first}, 29); # Get the first block
5161 0 my ($second, $last) = $String->getNextAndPrevBlockOffsetFromZmm(29); # Get the offsets of the second and last blocks
5162 0 ClearRegisters zmm29; # Clear first block
5163 0 $String->putNextandPrevBlockOffsetIntoZmm(29, $first, $first); # Initialize block chain
5164 0 $String->putBlock($$p{bs}, $first, 29); # Put the first block
5165  
5166 If $last != $first,
5167 Then # Two or more blocks on the chain
5168 0 ▶ {$$p{bs}->setReg(rax); # Address underlying arena
Subroutine __ANON__: not called CC=1 SCAR=6.9
5169 0 my $free = $String->bs->free;
5170 0 Lea r14, "[rax+$free]"; # Address of address of free chain
5171 0 Mov r15, "[r14]"; # Address of free chain
5172 0 my $rfc = V('next', r15); # Remainder of the free chain
5173  
5174 If $second == $last,
5175 Then # Two blocks on the chain
5176 0 ▶ {ClearRegisters zmm30; # Second block
Subroutine __ANON__: not called CC=1 SCAR=6.9
5177 0 $String->putNextandPrevBlockOffsetIntoZmm(30, $rfc, undef); # Put second block on head of the list
5178 0 $String->putBlock($$p{bs}, $second, 30); # Put the second block
5179 },
5180 Else # Three or more blocks on the chain
5181 0 ▶ {my $z = V(zero, 0); # A variable with zero in it
Subroutine __ANON__: not called CC=1 SCAR=6.9
5182 0 $String->getBlock($$p{bs}, $second, 30); # Get the second block
5183 0 $String->getBlock($$p{bs}, $last, 31); # Get the last block
5184 0 $String->putNextandPrevBlockOffsetIntoZmm(30, undef, $z); # Reset prev pointer in second block
5185 0 $String->putNextandPrevBlockOffsetIntoZmm(31, $rfc, undef); # Reset next pointer in last block to remainder of free chain
5186 0 $String->putBlock($$p{bs}, $second, 30); # Put the second block
5187 0 $String->putBlock($$p{bs}, $last, 31); # Put the last block
5188 0 };
5189  
5190 0 $second->setReg(r15);
5191 0 Mov "[r14]", r15;
5192 0 };
5193  
5194 0 PushZmm; PopR;
5195 0 } [qw(first bs)], name => 'Nasm::X86::String::clear';
5196  
5197 0 $s->call($String->address, $String->first);
5198 }
5199  
5200 #D1 Array # Array constructed as a set of blocks in an arena
5201  
5202 sub DescribeArray(%) # Describe a dynamic array held in an arena.
5203 0 ▶ {my (%options) = @_; # Array description
Subroutine DescribeArray: not called CC=3 SCAR=24.8
Pod documented
5204 0 my $b = RegisterSize zmm0; # Size of a block == size of a zmm register
5205 0 my $o = RegisterSize eax; # Size of a double word
5206  
5207 my $a = genHash(__PACKAGE__."::Array", # Array definition
5208 bs => $options{arena}, # Variable address of arena for array
5209 width => $o, # Width of each element
5210 0 ▶ first => ($options{first} // G('first')), # Variable addressing first block in array
Condition0%0/3
$options{"first"} // &G("first")
l!l&&r!l&&!r
000
MC/DC0%0/2
$options{"first"} // &G("first")
$options{"first"} &G("first")
Truth table0%0/3
A // B
A= $options{"first"}B= &G("first")
ABresult
1X1
011
000
5211 slots1 => $b / $o - 1, # Number of slots in first block
5212 slots2 => $b / $o, # Number of slots in second and subsequent blocks
5213 );
5214  
5215 0 ▶ $a->slots2 == 16 or confess "Number of slots per block not 16"; # Slots per block check
Branch: 1 branch
BranchTrueFalseTotal
$a->slots2 == 16 or confess("Number of slots per block not 16") 0 0 0
5216  
5217 0 $a # Description of array
5218 }
5219  
5220 sub Nasm::X86::Arena::DescribeArray($) # Describe a dynamic array held in an arena.
5221 0 ▶ {my ($arena) = @_; # Arena description
Subroutine DescribeArray: not called CC=2 SCAR=17.9
5222 0 ▶ @_ == 1 or confess "One parameter";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess("One parameter") 0 0 0
5223 0 DescribeArray(arena => $arena)
5224 }
5225  
5226 sub Nasm::X86::Arena::CreateArray($) # Create a dynamic array held in an arena.
5227 0 ▶ {my ($arena) = @_; # Arena description
Subroutine CreateArray: not called CC=2 SCAR=17.9
5228 0 ▶ @_ == 1 or confess "One parameter";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess("One parameter") 0 0 0
5229  
5230 0 my $a = $arena->DescribeArray; # Describe array
5231  
5232 0 $a->reload(first => $a->allocBlock($arena->bs)); # Allocate first block and return created array descriptor
5233 }
5234  
5235 sub Nasm::X86::Array::reload($%) # Reload the specified array description.
5236 0 ▶ {my ($array, %options) = @_; # Array descriptor, {first=>first block of array if not the existing first node; arena=>arena used by array if not the existing arena}
Subroutine reload: not called CC=4 SCAR=30.0
5237 0 ▶ @_ >= 1 or confess "At least one parameter";
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 1 or confess("At least one parameter") 0 0 0
5238  
5239 0 my $a = $array->bs->DescribeArray; # Return a descriptor for an array
5240 0 ▶ $a->bs = $options{arena} if $options{arena};
Branch: 1 branch
BranchTrueFalseTotal
if $options{"arena"} 0 0 0
5241 0 ▶ $a->first->copy($options{first}//$array->first); # Set the first block
Condition0%0/3
$options{"first"} // $array->first
l!l&&r!l&&!r
000
MC/DC0%0/2
$options{"first"} // $array->first
$options{"first"} $array->first
Truth table0%0/3
A // B
A= $options{"first"}B= $array->first
ABresult
1X1
011
000
5242 0 $a
5243 }
5244  
5245 sub Nasm::X86::Array::address($) #P Address of a string.
5246 0 ▶ {my ($Array) = @_; # Array descriptor
Subroutine address: not called CC=2 SCAR=17.9
5247 0 ▶ @_ == 1 or confess "One parameter";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess("One parameter") 0 0 0
5248 0 $Array->bs->bs;
5249 }
5250  
5251 sub Nasm::X86::Array::allocBlock($$) #P Allocate a block to hold a zmm register in the specified arena and return the offset of the block in a variable.
5252 0 ▶ {my ($Array, $bs) = @_; # Array descriptor, arena address
Subroutine allocBlock: not called CC=2 SCAR=17.9
5253 0 ▶ @_ == 2 or confess "2 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess("2 parameters") 0 0 0
5254  
5255 0 $Array->bs->allocBlock($bs);
5256 }
5257  
5258 sub Nasm::X86::Array::dump($@) # Dump a array.
5259 0 ▶ {my ($Array, @variables) = @_; # Array descriptor, variables
Subroutine dump: not called CC=2 SCAR=17.9
5260 0 ▶ @_ >= 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 1 or confess() 0 0 0
5261 0 my $b = $Array->bs; # Underlying arena
5262 0 my $W = RegisterSize zmm0; # The size of a block
5263 0 my $w = $Array->width; # The size of an entry in a block
5264 0 my $n = $Array->slots1; # The number of slots per block
5265 0 my $N = $Array->slots2; # The number of slots per block
5266  
5267 my $s = Subroutine
5268 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
5269  
5270 0 my $B = $$p{bs}; # Arena
5271 0 my $F = $$p{first}; # First block
5272  
5273 0 PushR (r8, zmm30, zmm31);
5274 0 $b->getBlock($B, $F, 31); # Get the first block
5275 0 my $size = getDFromZmm(31, 0, r8); # Size of array
5276 0 PrintOutStringNL("array");
5277 0 $size->out("Size: ", " ");
5278 0 PrintOutRegisterInHex zmm31;
5279  
5280 If $size > $n,
5281 Then # Array has secondary blocks
5282 0 ▶ {my $T = $size / $N; # Number of full blocks
Subroutine __ANON__: not called CC=1 SCAR=6.9
5283  
5284 $T->for(sub # Print out each block
5285 0 ▶ {my ($index, $start, $next, $end) = @_; # Execute block
Subroutine __ANON__: not called CC=1 SCAR=6.9
5286 0 my $S = getDFromZmm(31, ($index + 1) * $w, r8); # Address secondary block from first block
5287 0 $b->getBlock($B, $S, 30); # Get the secondary block
5288 0 $S->out("Full: ", " ");
5289 0 PrintOutRegisterInHex zmm30;
5290 0 });
5291  
5292 0 my $lastBlockCount = $size % $N; # Number of elements in the last block
5293 If $lastBlockCount > 0, sub # Print non empty last block
5294 0 ▶ {my $S = getDFromZmm(31, ($T + 1) * $w, r8); # Address secondary block from first block
Subroutine __ANON__: not called CC=1 SCAR=6.9
5295 0 $b->getBlock($B, $S, 30); # Get the secondary block
5296 0 $S->out("Last: ", " ");
5297 0 PrintOutRegisterInHex zmm30;
5298 0 };
5299 0 };
5300  
5301 0 PopR;
5302 0 } [qw(bs first)], name => q(Nasm::X86::Array::dump);
5303  
5304 0 $s->call($Array->address, $Array->first, @variables);
5305 }
5306  
5307 sub Nasm::X86::Array::push($@) # Push an element onto the array.
5308 0 ▶ {my ($Array, @variables) = @_; # Array descriptor, variables
Subroutine push: not called CC=2 SCAR=17.9
5309 0 ▶ @_ >= 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 or confess() 0 0 0
5310 0 my $b = $Array->bs; # Underlying arena
5311 0 my $W = RegisterSize zmm0; # The size of a block
5312 0 my $w = $Array->width; # The size of an entry in a block
5313 0 my $n = $Array->slots1; # The number of slots per block
5314 0 my $N = $Array->slots2; # The number of slots per block
5315  
5316 my $s = Subroutine
5317 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
5318 0 my $success = Label; # Short circuit if ladders by jumping directly to the end after a successful push
5319  
5320 0 my $B = $$p{bs}; # Arena
5321 0 my $F = $$p{first}; # First block
5322 0 my $E = $$p{element}; # The element to be inserted
5323  
5324 0 PushR (r8, zmm31);
5325 0 my $transfer = r8; # Transfer data from zmm to variable via this register
5326  
5327 0 $b->getBlock($B, $F, 31); # Get the first block
5328 0 my $size = getDFromZmm(31, 0, $transfer); # Size of array
5329  
5330 If $size < $n,
5331 Then # Room in the first block
5332 0 ▶ {$E ->putDIntoZmm(31, ($size + 1) * $w, $transfer); # Place element
Subroutine __ANON__: not called CC=1 SCAR=6.9
5333 0 ($size+1)->putDIntoZmm(31, 0, $transfer); # Update size
5334 0 $b ->putBlock($B, $F, 31); # Put the first block back into memory
5335 0 Jmp $success; # Element successfully inserted in first block
5336 0 };
5337  
5338 If $size == $n,
5339 Then # Migrate the first block to the second block and fill in the last slot
5340 0 ▶ {PushR (rax, k7, zmm30);
Subroutine __ANON__: not called CC=1 SCAR=6.9
5341 0 Mov rax, -2; # Load compression mask
5342 0 Kmovq k7, rax; # Set compression mask
5343 0 Vpcompressd "zmm30{k7}{z}", zmm31; # Compress first block into second block
5344 0 ClearRegisters zmm31; # Clear first block
5345 0 ($size+1)->putDIntoZmm(31, 0, $transfer); # Save new size in first block
5346 0 my $new = $b->allocBlock($$p{bs}); # Allocate new block
5347 0 $new->putDIntoZmm(31, $w, $transfer); # Save offset of second block in first block
5348 0 $E ->putDIntoZmm(30, $W - 1 * $w, $transfer); # Place new element
5349 0 $b ->putBlock($B, $new, 30); # Put the second block back into memory
5350 0 $b ->putBlock($B, $F, 31); # Put the first block back into memory
5351 0 PopR;
5352 0 Jmp $success; # Element successfully inserted in second block
5353 0 };
5354  
5355 If $size <= $N * ($N - 1),
5356 Then # Still within two levels
5357 {If $size % $N == 0,
5358 Then # New secondary block needed
5359 0 ▶ {PushR (rax, zmm30);
Subroutine __ANON__: not called CC=1 SCAR=6.9
5360 0 my $new = $b->allocBlock($$p{bs}); # Allocate new block
5361 0 $E ->putDIntoZmm(30, 0, $transfer); # Place new element last in new second block
5362 0 ($size+1)->putDIntoZmm(31, 0, $transfer); # Save new size in first block
5363 0 $new ->putDIntoZmm(31, ($size / $N + 1) * $w, $transfer); # Address new second block from first block
5364 0 $b ->putBlock($B, $new, 30); # Put the second block back into memory
5365 0 $b ->putBlock($B, $F, 31); # Put the first block back into memory
5366 0 PopR;
5367 0 Jmp $success; # Element successfully inserted in second block
5368 0 ▶ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
5369  
5370 0 if (1) # Continue with existing secondary block
5371 0 {PushR (rax, r14, zmm30);
5372 0 my $S = getDFromZmm(31, ($size / $N + 1) * $w, $transfer); # Offset of second block in first block
5373 0 $b ->getBlock($B, $S, 30); # Get the second block
5374 0 $E ->putDIntoZmm(30, ($size % $N) * $w, $transfer); # Place new element last in new second block
5375 0 ($size+1)->putDIntoZmm(31, 0, $transfer); # Save new size in first block
5376 0 $b ->putBlock($B, $S, 30); # Put the second block back into memory
5377 0 $b ->putBlock($B, $F, 31); # Put the first block back into memory
5378 0 PopR;
5379 0 Jmp $success; # Element successfully inserted in second block
5380 }
5381 0 };
5382  
5383 0 SetLabel $success;
5384 0 PopR;
5385 0 } [qw(bs first element)], name => 'Nasm::X86::Array::push';
5386  
5387 0 $s->call($Array->address, $Array->first, @variables);
5388 }
5389  
5390 sub Nasm::X86::Array::pop($@) # Pop an element from an array.
5391 0 ▶ {my ($Array, @variables) = @_; # Array descriptor, variables
Subroutine pop: not called CC=2 SCAR=17.9
5392 0 ▶ @_ >= 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 or confess() 0 0 0
5393 0 my $b = $Array->bs; # Underlying arena
5394 0 my $W = RegisterSize zmm0; # The size of a block
5395 0 my $w = $Array->width; # The size of an entry in a block
5396 0 my $n = $Array->slots1; # The number of slots per block
5397 0 my $N = $Array->slots2; # The number of slots per block
5398  
5399 my $s = Subroutine
5400 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
5401 0 my $success = Label; # Short circuit if ladders by jumping directly to the end after a successful push
5402  
5403 0 my $B = $$p{bs}; # Arena
5404 0 my $F = $$p{first}; # First block
5405 0 my $E = $$p{element}; # The element being popped
5406  
5407 0 PushR (r8, zmm31);
5408 0 my $transfer = r8; # Transfer data from zmm to variable via this register
5409 0 $b->getBlock($B, $F, 31); # Get the first block
5410 0 my $size = getDFromZmm(31, 0, $transfer); # Size of array
5411  
5412 If $size > 0,
5413 Then # Array has elements
5414 {If $size <= $n,
5415 Then # In the first block
5416 0 ▶ {$E ->getDFromZmm(31, $size * $w, $transfer); # Get element
Subroutine __ANON__: not called CC=1 SCAR=6.9
5417 0 ($size-1)->putDIntoZmm(31, 0, $transfer); # Update size
5418 0 $b ->putBlock($B, $F, 31); # Put the first block back into memory
5419 0 Jmp $success; # Element successfully retrieved from secondary block
5420 0 ▶ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
5421  
5422 If $size == $N,
5423 Then # Migrate the second block to the first block now that the last slot is empty
5424 0 ▶ {PushR (rax, k7, zmm30);
Subroutine __ANON__: not called CC=1 SCAR=6.9
5425 0 my $S = getDFromZmm(31, $w, $transfer); # Offset of second block in first block
5426 0 $b->getBlock($B, $S, 30); # Get the second block
5427 0 $E->getDFromZmm(30, $n * $w, $transfer); # Get element from second block
5428 0 Mov rax, -2; # Load expansion mask
5429 0 Kmovq k7, rax; # Set expansion mask
5430 0 Vpexpandd "zmm31{k7}{z}", zmm30; # Expand second block into first block
5431 0 ($size-1)->putDIntoZmm(31, 0, $transfer); # Save new size in first block
5432 0 $b -> putBlock($B, $F, 31); # Save the first block
5433 0 $b ->freeBlock($B, offset=>$S); # Free the now redundant second block
5434 0 PopR;
5435 0 Jmp $success; # Element successfully retrieved from secondary block
5436 0 };
5437  
5438 If $size <= $N * ($N - 1),
5439 Then # Still within two levels
5440 {If $size % $N == 1,
5441 Then # Secondary block can be freed
5442 0 ▶ {PushR (rax, zmm30);
Subroutine __ANON__: not called CC=1 SCAR=6.9
5443 0 my $S = getDFromZmm(31, ($size / $N + 1) * $w, $transfer); # Address secondary block from first block
5444 0 $b ->getBlock($B, $S, 30); # Load secondary block
5445 0 $E->getDFromZmm(30, 0, $transfer); # Get first element from secondary block
5446 0 V(zero, 0)->putDIntoZmm(31, ($size / $N + 1) * $w, $transfer); # Zero at offset of secondary block in first block
5447 0 ($size-1)->putDIntoZmm(31, 0, $transfer); # Save new size in first block
5448 0 $b ->freeBlock($B, offset=>$S); # Free the secondary block
5449 0 $b ->putBlock ($B, $F, 31); # Put the first block back into memory
5450 0 PopR;
5451 0 Jmp $success; # Element successfully retrieved from secondary block
5452 0 ▶ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
5453  
5454 0 if (1) # Continue with existing secondary block
5455 0 {PushR (rax, r14, zmm30);
5456 0 my $S = getDFromZmm(31, (($size-1) / $N + 1) * $w, $transfer); # Offset of secondary block in first block
5457 0 $b ->getBlock($B, $S, 30); # Get the secondary block
5458 0 $E ->getDFromZmm(30, (($size - 1) % $N) * $w, $transfer); # Get element from secondary block
5459 0 ($size-1)->putDIntoZmm(31, 0, $transfer); # Save new size in first block
5460 0 $b ->putBlock($B, $S, 30); # Put the secondary block back into memory
5461 0 $b ->putBlock($B, $F, 31); # Put the first block back into memory
5462 0 PopR;
5463 0 Jmp $success; # Element successfully retrieved from secondary block
5464 }
5465 0 };
5466 0 };
5467  
5468 0 SetLabel $success;
5469 0 PopR;
5470 0 } [qw(bs first element)], name => 'Nasm::X86::Array::pop';
5471  
5472 0 $s->call($Array->address, $Array->first, @variables);
5473 }
5474  
5475 sub Nasm::X86::Array::size($;$$) # Return the size of an array as a variable.
5476 0 ▶ {my ($Array, $bs, $first) = @_; # Array descriptor, optional arena address, optional first block
Subroutine size: not called CC=5 SCAR=34.0
5477 0 ▶ @_ == 1 or @_ == 3 or confess "1 or 3 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or @_ == 3 or confess("1 or 3 parameters") 0 0 0
Condition0%0/3
@_ == 1 or @_ == 3
l!l&&r!l&&!r
000
MC/DC0%0/2
@_ == 1 or @_ == 3
@_ == 1 @_ == 3
Truth table0%0/3
A or B
A= @_ == 1B= @_ == 3
ABresult
1X1
011
000
5478  
5479 my $s = Subroutine
5480 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
5481 0 my $success = Label; # Short circuit if ladders by jumping directly to the end after a successful push
5482  
5483 0 my $B = $$p{bs}; # Arena
5484 0 my $F = $$p{first}; # First block
5485  
5486 0 PushR (r8, zmm31);
5487 0 my $transfer = r8; # Transfer data from zmm to variable via this register
5488 0 $Array->bs->getBlock($B, $F, 31); # Get the first block
5489 0 $$p{size}->copy(getDFromZmm(31, 0, $transfer)); # Size of array
5490  
5491 0 SetLabel $success;
5492 0 PopR;
5493 0 } [qw(bs first size)], name => 'Nasm::X86::Array::size';
5494  
5495 0 ▶ $s->call(bs => ($bs//$Array->address), # Get the size of the array
Condition0%0/6
$bs // $Array->address
l!l&&r!l&&!r
000
$first // $Array->first
l!l&&r!l&&!r
000
MC/DC0%0/2
$bs // $Array->address
$bs $Array->address
MC/DC0%0/2
$first // $Array->first
$first $Array->first
Truth table0%0/3
A // B
A= $bsB= $Array->address
ABresult
1X1
011
000
Truth table0%0/3
A // B
A= $firstB= $Array->first
ABresult
1X1
011
000
5496 first => ($first//$Array->first), my $size = V(size));
5497  
5498 0 $size # Return size as a variable
5499 }
5500  
5501 sub Nasm::X86::Array::get($@) # Get an element from the array.
5502 0 ▶ {my ($Array, @variables) = @_; # Array descriptor, variables
Subroutine get: not called CC=2 SCAR=17.9
5503 0 ▶ @_ >= 3 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 3 or confess() 0 0 0
5504 0 my $b = $Array->bs; # Underlying arena
5505 0 my $W = RegisterSize zmm0; # The size of a block
5506 0 my $w = $Array->width; # The size of an entry in a block
5507 0 my $n = $Array->slots1; # The number of slots in the first block
5508 0 my $N = $Array->slots2; # The number of slots in the secondary blocks
5509  
5510 my $s = Subroutine
5511 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
5512 0 my $success = Label; # Short circuit if ladders by jumping directly to the end after a successful push
5513  
5514 0 my $B = $$p{bs}; # Arena
5515 0 my $F = $$p{first}; # First block
5516 0 my $E = $$p{element}; # The element to be returned
5517 0 my $I = $$p{index}; # Index of the element to be returned
5518  
5519 0 PushR (r8, zmm31);
5520 0 my $transfer = r8; # Transfer data from zmm to variable via this register
5521 0 $b->getBlock($B, $F, 31); # Get the first block
5522 0 my $size = getDFromZmm(31, 0, $transfer); # Size of array
5523 If $I < $size,
5524 Then # Index is in array
5525 {If $size <= $n,
5526 Then # Element is in the first block
5527 0 ▶ {$E->getDFromZmm(31, ($I + 1) * $w, $transfer); # Get element
Subroutine __ANON__: not called CC=1 SCAR=6.9
5528 0 Jmp $success; # Element successfully inserted in first block
5529 0 ▶ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
5530  
5531 If $size <= $N * ($N - 1),
5532 Then # Still within two levels
5533 0 ▶ {my $S = getDFromZmm(31, ($I / $N + 1) * $w, $transfer); # Offset of second block in first block
Subroutine __ANON__: not called CC=1 SCAR=6.9
5534 0 $b->getBlock($B, $S, 31); # Get the second block
5535 0 $E->getDFromZmm(31, ($I % $N) * $w, $transfer); # Offset of element in second block
5536 0 Jmp $success; # Element successfully inserted in second block
5537 0 };
5538 0 };
5539  
5540 0 PrintErrString "Index out of bounds on get from array, "; # Array index out of bounds
5541 0 $I->err("Index: "); PrintErrString " "; $size->errNL("Size: ");
5542 0 Exit(1);
5543  
5544 0 SetLabel $success;
5545 0 PopR;
5546 0 } [qw(bs first index element)], name => 'Nasm::X86::Array::get';
5547  
5548 0 $s->call($Array->address, $Array->first, @variables);
5549 }
5550  
5551 sub Nasm::X86::Array::put($@) # Put an element into an array as long as it is with in its limits established by pushing.
5552 0 ▶ {my ($Array, @variables) = @_; # Array descriptor, variables
Subroutine put: not called CC=2 SCAR=17.9
5553 0 ▶ @_ >= 3 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 3 or confess() 0 0 0
5554 0 my $b = $Array->bs; # Underlying arena
5555 0 my $W = RegisterSize zmm0; # The size of a block
5556 0 my $w = $Array->width; # The size of an entry in a block
5557 0 my $n = $Array->slots1; # The number of slots in the first block
5558 0 my $N = $Array->slots2; # The number of slots in the secondary blocks
5559  
5560 my $s = Subroutine
5561 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
5562 0 my $success = Label; # Short circuit if ladders by jumping directly to the end after a successful push
5563  
5564 0 my $B = $$p{bs}; # Arena
5565 0 my $F = $$p{first}; # First block
5566 0 my $E = $$p{element}; # The element to be added
5567 0 my $I = $$p{index}; # Index of the element to be inserted
5568  
5569 0 PushR (r8, zmm31);
5570 0 my $transfer = r8; # Transfer data from zmm to variable via this register
5571 0 $b->getBlock($B, $F, 31); # Get the first block
5572 0 my $size = getDFromZmm(31, 0, $transfer); # Size of array
5573 If $I < $size,
5574 Then # Index is in array
5575 {If $size <= $n,
5576 Then # Element is in the first block
5577 0 ▶ {$E->putDIntoZmm(31, ($I + 1) * $w, $transfer); # Put element
Subroutine __ANON__: not called CC=1 SCAR=6.9
5578 0 $b->putBlock($B, $F, 31); # Get the first block
5579 0 Jmp $success; # Element successfully inserted in first block
5580 0 ▶ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
5581  
5582 If $size <= $N * ($N - 1),
5583 Then # Still within two levels
5584 0 ▶ {my $S = getDFromZmm(31, ($I / $N + 1) * $w, $transfer); # Offset of second block in first block
Subroutine __ANON__: not called CC=1 SCAR=6.9
5585 0 $b->getBlock($B, $S, 31); # Get the second block
5586 0 $E->putDIntoZmm(31, ($I % $N) * $w, $transfer); # Put the element into the second block in first block
5587 0 $b->putBlock($B, $S, 31); # Get the first block
5588 0 Jmp $success; # Element successfully inserted in second block
5589 0 };
5590 0 };
5591  
5592 0 PrintErrString "Index out of bounds on put to array, "; # Array index out of bounds
5593 0 $I->err("Index: "); PrintErrString " "; $size->errNL("Size: ");
5594 0 Exit(1);
5595  
5596 0 SetLabel $success;
5597 0 PopR;
5598 0 } [qw(first index element bs)], name => 'Nasm::X86::Array::put';
5599  
5600 0 $s->call($Array->address, $Array->first, @variables);
5601 }
5602  
5603 #D1 Tree # Tree constructed as sets of blocks in an arena.
5604  
5605 sub DescribeTree(%) # Return a descriptor for a tree with the specified options.
5606 0 ▶ {my (%options) = @_; # Tree description options
Subroutine DescribeTree: not called CC=4 SCAR=30.0
Pod documented
5607  
5608 0 my $b = RegisterSize zmm0; # Size of a block == size of a zmm register
5609 0 my $o = RegisterSize eax; # Size of a double word
5610  
5611 0 my $length = $b / $o - 2; # Length of block to split
5612 0 my $split = $length / 2 * $o; # Offset of splitting key
5613  
5614 0 ▶ confess "Maximum keys must be 14" unless $length == 14; # Maximum number of keys is expected to be 14
Branch: 1 branch
BranchTrueFalseTotal
unless $length == 14 0 0 0
5615 0 ▶ confess "Splitting key offset must be 28" unless $split == 28; # Splitting key offset
Branch: 1 branch
BranchTrueFalseTotal
unless $split == 28 0 0 0
5616  
5617 genHash(__PACKAGE__."::Tree", # Tree.
5618 bs => DescribeArena($options{arena}), # Arena definition.
5619 data => G(data), # Variable containing the last data found
5620 0 ▶ first => ($options{first} // G(first)), # Variable addressing offset to first block of keys.
Condition0%0/3
$options{"first"} // &G("first")
l!l&&r!l&&!r
000
MC/DC0%0/2
$options{"first"} // &G("first")
$options{"first"} &G("first")
Truth table0%0/3
A // B
A= $options{"first"}B= &G("first")
ABresult
1X1
011
000
5621 found => G(found), # Variable indicating whether the last find was successful or not
5622 leftLength => $length / 2, # Left split length
5623 lengthOffset => $b - $o * 2, # Offset of length in keys block. The length field is a word - see: "MultiWayTree.svg"
5624 loop => $b - $o, # Offset of keys, data, node loop.
5625 maxKeys => $length, # Maximum number of keys.
5626 splittingKey => $split, # POint at which to split a full block
5627 rightLength => $length - 1 - $length / 2, # Right split length
5628 subTree => G(subTree), # Variable indicating whether the last find found a sub tree
5629 treeBits => $b - $o * 2 + 2, # Offset of tree bits in keys block. The tree bits field is a word, each bit of which tells us whether the corresponding data element is the offset (or not) to a sub tree of this tree .
5630 treeBitsMask => 0x3fff, # Total of 14 tree bits
5631 up => $b - $o * 2, # Offset of up in data block.
5632 width => $o, # Width of a key or data slot.
5633 );
5634 }
5635  
5636 sub Nasm::X86::Arena::DescribeTree($%) # Return a descriptor for a tree in the specified arena with the specified options.
5637 0 ▶ {my ($arena, %options) = @_; # Arena descriptor, options for tree
Subroutine DescribeTree: not called CC=2 SCAR=17.9
5638 0 ▶ @_ >= 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 1 or confess() 0 0 0
5639  
5640 0 DescribeTree(arena=>$arena->bs, %options)
5641 }
5642  
5643 sub Nasm::X86::Arena::CreateTree($;$) # Create a tree in an arena.
5644 0 ▶ {my ($arena, $bs) = @_; # Arena description, optional arena address
Subroutine CreateTree: not called CC=4 SCAR=30.0
5645 0 ▶ @_ == 1 or @_ == 2 or confess "1 or 2 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or @_ == 2 or confess("1 or 2 parameters") 0 0 0
Condition0%0/3
@_ == 1 or @_ == 2
l!l&&r!l&&!r
000
MC/DC0%0/2
@_ == 1 or @_ == 2
@_ == 1 @_ == 2
Truth table0%0/3
A or B
A= @_ == 1B= @_ == 2
ABresult
1X1
011
000
5646  
5647 0 my $t = $arena->DescribeTree; # Return a descriptor for a tree at the specified offset in the specified arena
5648  
5649 my $s = Subroutine
5650 0 ▶ {my ($p) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
5651 0 Comment "Create a block multiway Tree start";
5652 0 my $keys = $t->allocBlock($$p{bs}); # Allocate first keys block
5653 0 $$p{first}->copy($keys); # Save address of first block used to contain the root of the tree
5654 0 PushR my @save = (r8, r9, zmm31);
5655 0 ClearRegisters zmm31;
5656 0 $t->putLoop($t->allocBlock($$p{bs}), 31, r8); # Keys loops to data - for the first 7 keys we should store the corresponding data further up in the block rather than creating a new block.
5657 0 $arena->putBlock($$p{bs}, $keys, 31, r8, r9); # Write first keys
5658 0 PopR;
5659 0 } [qw(bs first)], name => 'Nasm::X86::Arena::CreateTree';
5660  
5661 0 ▶ $s->call(bs => ($bs//$t->address), first => $t->first);
Condition0%0/3
$bs // $t->address
l!l&&r!l&&!r
000
MC/DC0%0/2
$bs // $t->address
$bs $t->address
Truth table0%0/3
A // B
A= $bsB= $t->address
ABresult
1X1
011
000
5662  
5663 0 $t # Description of array
5664 }
5665  
5666 sub Nasm::X86::Tree::reload($%) # Reload the specified tree description.
5667 0 ▶ {my ($tree, %options) = @_; # Tree descriptor, {first=>first node of tree if not the existing first node; arena=>arena used by tree if not the existing arena}
Subroutine reload: not called CC=4 SCAR=30.0
5668 0 ▶ @_ >= 1 or confess "At least one parameter";
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 1 or confess("At least one parameter") 0 0 0
5669  
5670 0 my $t = $tree->bs->DescribeTree; # Return a descriptor for a tree
5671 0 ▶ $t->bs = $options{arena} if $options{arena}; # Set the arena if requested
Branch: 1 branch
BranchTrueFalseTotal
if $options{"arena"} 0 0 0
5672 0 ▶ $t->first->copy($options{first}//$tree->first); # Set the first block
Condition0%0/3
$options{"first"} // $tree->first
l!l&&r!l&&!r
000
MC/DC0%0/2
$options{"first"} // $tree->first
$options{"first"} $tree->first
Truth table0%0/3
A // B
A= $options{"first"}B= $tree->first
ABresult
1X1
011
000
5673 0 $t
5674 }
5675  
5676 sub Nasm::X86::Tree::allocKeysDataNode($$$$$) #P Allocate a keys/data/node block and place it in the numbered zmm registers.
5677 0 ▶ {my ($t, $bs, $K, $D, $N) = @_; # Tree descriptor, arena address, numbered zmm for keys, numbered zmm for data, numbered zmm for children
Subroutine allocKeysDataNode: not called CC=2 SCAR=17.9
5678 0 ▶ @_ == 5 or confess "5 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 5 or confess("5 parameters") 0 0 0
5679  
5680 my $s = Subroutine
5681 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
5682  
5683 0 my $B = $$p{bs}; # Arena
5684 0 $t->bs->allocZmmBlock($B, my $k = V(offset)); # Keys
5685 0 $t->bs->allocZmmBlock($B, my $d = V(offset)); # Data
5686 0 $t->bs->allocZmmBlock($B, my $n = V(offset)); # Children
5687  
5688 0 PushR r8;
5689 0 $t->putLoop($d, $K, r8); # Set the link from key to data
5690 0 $t->putLoop($n, $D, r8); # Set the link from data to node
5691 0 $t->putLoop($k, $N, r8); # Set the link from node to key
5692 0 PopR r8;
5693 0 } [qw(bs)], name => qq(Nasm::X86::Tree::allocKeysDataNode::${K}::${D}::${N});# Create a subroutine for each combination of registers encountered
5694  
5695 0 $s->call($bs);
5696 } # allocKeysDataNode
5697  
5698 sub Nasm::X86::Tree::splitNode($$$$@) #P Split a non root node given its offset in an arena retaining the key being inserted in the node being split while putting the remainder to the left or right.
5699 0 ▶ {my ($t, $bs, $node, $key, @variables) = @_; # Tree descriptor, backing arena, offset of node, key, variables
Subroutine splitNode: not called CC=2 SCAR=17.9
5700 0 ▶ @_ >= 4 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 4 or confess() 0 0 0
5701  
5702 0 my $K = 31; my $D = 30; my $N = 29; # Key, data, node blocks
5703  
5704 my $s = Subroutine
5705 0 ▶ {my ($parameters) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
5706 0 my $success = Label; # Short circuit if ladders by jumping directly to the end after a successful push
5707  
5708 0 my $B = $$parameters{bs}; # Arena
5709 0 my $k = $$parameters{key}; # Key we are looking for
5710 0 my $n = $$parameters{node}; # Node to split
5711  
5712 0 PushR (r8, r9); PushZmm 22...31;
5713  
5714 0 my $transfer = r8; # Use this register to transfer data between zmm blocks and variables
5715 0 my $work = r9; # Work register
5716  
5717 0 $t->getKeysDataNode($B, $n, $K, $D, $N, $transfer, $work); # Load node
5718  
5719 If $t->getLengthInKeys($K) != $t->maxKeys,
5720 Then # Only split full blocks
5721 0 ▶ {Jmp $success;
Subroutine __ANON__: not called CC=1 SCAR=6.9
5722 0 };
5723  
5724 0 my $p = $t->getUpFromData($D, $transfer); # Parent
5725 If $p > 0,
5726 Then # Not the root
5727 0 ▶ {my $s = getDFromZmm $K, $t->splittingKey, $transfer; # Splitting key
Subroutine __ANON__: not called CC=1 SCAR=6.9
5728 If $k < $s,
5729 Then # Split left node pushing remainder right so that we keep the key we are looking for in the left node
5730 0 ▶ {Vmovdqu64 zmm28, zmm31; # Load left node
Subroutine __ANON__: not called CC=1 SCAR=6.9
5731 0 Vmovdqu64 zmm27, zmm30;
5732 0 Vmovdqu64 zmm26, zmm29;
5733 0 $t->allocKeysDataNode($B, 25, 24, 23); # Create new right node
5734  
5735 0 $t->getKeysDataNode($B, $p, $K, $D, $N, $transfer, $work); # Load parent
5736 0 $t->splitFullLeftNode;
5737 0 $t->putKeysDataNode($B, $p, $K, $D, $N, $transfer, $work); # Save parent
5738 0 $t->putKeysDataNode($B, $n, 28, 27, 26, $transfer, $work); # Save left
5739 0 my $r = $t->getLoop (23, $transfer); # Offset of right keys
5740 0 $t->putUpIntoData ($p, 24, $transfer); # Reparent new block
5741 0 $t->putKeysDataNode($B, $r, 25, 24, 23, $transfer, $work) # Save right back into node we just split
5742 },
5743 Else # Split right node pushing remainder left so that we keep the key we are looking for in the right node
5744 0 ▶ {Vmovdqu64 zmm25, zmm31; # Load right node
Subroutine __ANON__: not called CC=1 SCAR=6.9
5745 0 Vmovdqu64 zmm24, zmm30;
5746 0 Vmovdqu64 zmm23, zmm29;
5747 0 $t->allocKeysDataNode($B, 28, 27, 26); # Create new left node
5748  
5749 0 $t->getKeysDataNode($B, $p, $K, $D, $N, $transfer, $work); # Load parent
5750 0 $t->splitFullRightNode;
5751 0 $t->putKeysDataNode($B, $p, $K, $D, $N, $transfer, $work); # Save parent
5752 0 my $l = $t->getLoop (26, $transfer); # Offset of left keys
5753 0 $t->putUpIntoData ($p, 27, $transfer); # Reparent new block
5754 0 $t->putKeysDataNode($B, $l, 28, 27, 26, $transfer, $work); # Save left
5755 0 $t->putKeysDataNode($B, $n, 25, 24, 23, $transfer, $work); # Save right back into node we just split
5756 0 };
5757 },
5758 Else
5759 0 ▶ {$t->splitFullRoot($B); # Root
Subroutine __ANON__: not called CC=1 SCAR=6.9
5760 0 my $l = getDFromZmm $N, 0, $transfer;
5761 0 my $r = getDFromZmm $N, $t->width, $transfer;
5762 0 $t->putKeysDataNode($B, $n, $K, $D, $N, $transfer, $work); # Save root
5763 0 $t->putKeysDataNode($B, $l, 28, 27, 26, $transfer, $work); # Save left
5764 0 $t->putKeysDataNode($B, $r, 25, 24, 23, $transfer, $work); # Save right
5765 0 };
5766  
5767 0 SetLabel $success; # Insert completed successfully
5768 0 PopZmm;
5769 0 PopR;
5770 0 } [qw(bs node key)], name => 'Nasm::X86::Tree::splitNode';
5771  
5772 0 $s->call(bs=>$bs, node=>$node, key=>$key, @variables);
5773  
5774 } # splitNode
5775  
5776 sub Nasm::X86::Tree::reParent($$$$$@) #P Reparent the children of a node held in registers. The children are in the backing arena not registers.
5777 0 ▶ {my ($t, $bs, $PK, $PD, $PN, @variables) = @_; # Tree descriptor, backing arena, numbered zmm key node, numbered zmm data node, numbered zmm child node, variables
Subroutine reParent: not called CC=2 SCAR=17.9
5778 0 ▶ @_ >= 5 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 5 or confess() 0 0 0
5779  
5780 my $s = Subroutine
5781 0 ▶ {my ($parameters) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
5782 0 PushR (r8);
5783  
5784 0 my $B = $$parameters{bs}; # Arena
5785 0 my $L = $t->getLengthInKeys($PK) + 1; # Number of children
5786 0 my $p = $t->getUpFromDataNM($PD, r8); # Parent node offset in compressed format as a variable
5787  
5788 If $t->getLoop($PD, r8) > 0, sub # Not a leaf
5789 0 ▶ {PushR (rax, rdi);
Subroutine __ANON__: not called CC=1 SCAR=6.9
5790 0 Mov rdi, rsp; # Save stack base
5791 0 PushRR "zmm$PN"; # Child nodes on stack
5792 0 my $w = $t->width; my $l = $t->loop; my $u = $t->up; # Steps we will make along the chain
5793 0 my $s = V(start);
5794 $L->for(sub # Each child
5795 0 ▶ {my ($index, $start, $next, $end) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
5796 0 &PopEax; # The nodes are double words but we cannot pop a double word from the stack in 64 bit long mode using pop
5797 0 $s->getReg(rax);
5798 0 $t->bs->putChain($B, $s, $p, $l, $u);
5799 0 });
5800  
5801 0 Mov rsp, rdi; # Level stack
5802 0 PopR;
5803 0 };
5804 0 PopR;
5805 0 } [qw(bs)], name => 'Nasm::X86::Tree::reParent';
5806  
5807 0 $s->call($t->address, @variables);
5808 } # reParent
5809  
5810 sub Nasm::X86::Tree::transferTreeBitsFromParent($$$$) #P Transfer tree bits when splitting a full node.
5811 0 ▶ {my ($t, $parent, $left, $right) = @_; # Tree descriptor, numbered parent zmm, numbered left zmm, numbered right zmm
Subroutine transferTreeBitsFromParent: not called CC=1 SCAR=6.9
5812  
5813 0 PushR my @save = my ($whole, $half) = (r15, r14);
5814 0 $t->getTreeBits($parent, $whole); # Transfer Tree bits
5815 0 Cmp $whole, 0;
5816 IfNz # Action required iff there are some tree bits
5817 Then
5818 0 ▶ {Mov $half, $whole; # Left tree bits
Subroutine __ANON__: not called CC=1 SCAR=6.9
5819 0 And $half, ((1 << $t->leftLength) - 1); # Isolate left bits
5820 0 $t->putTreeBits($left, $half); # Save left tree bits
5821  
5822 0 Mov $half, $whole; # Right tree bits
5823 0 Shr $half, $t->leftLength + 1; # Isolate right bits
5824 0 And $half, ((1 << $t->rightLength) - 1); # Remove any bits above
5825 0 $t->putTreeBits($right, $half); # Save right tree bits
5826  
5827 0 Mov $half, $whole; # Right tree bits
5828 0 Shr $half, $t->leftLength; # Parent bit
5829 0 And $half, 1; # Only one bit
5830 0 $t->putTreeBits($parent, $half); # Save parent tree bits
5831 0 };
5832 0 PopR;
5833 }
5834  
5835 sub Nasm::X86::Tree::transferTreeBitsFromLeftOrRight($$$$$$) #P Transfer tree bits when splitting a full left or right node.
5836 0 ▶ {my ($t, $rnl, $point, $parent, $left, $right) = @_; # Tree descriptor, 0 - left 1 - right, register indicating point of left in parent, numbered parent zmm, numbered left zmm, numbered right zmm
Subroutine transferTreeBitsFromLeftOrRight: not called CC=2 SCAR=17.9
5837  
5838 0 PushR my @save = my ($whole, $half, $bits) = ChooseRegisters(3, $point);
5839 0 ▶ $t->getTreeBits($rnl ? $right : $left, $whole); # Tree bits
Branch: 1 branch
BranchTrueFalseTotal
$rnl ? : 0 0 0
5840  
5841 0 Mov $half, $whole; # Right bits
5842 0 Shr $half, $t->leftLength + 1; # Isolate right bits
5843 0 $t->putTreeBits($right, $half); # Save right bits
5844  
5845 0 $t->getTreeBits($parent, $bits); # Parent bits
5846 0 InsertZeroIntoRegisterAtPoint($point, $bits);
5847 0 Mov $half, $whole; # Tree bit of key being moved into parent from left
5848 0 Shr $half, $t->leftLength+1; # Tree bit to move into parent is now in carry flag
5849 0 ▶ IfC Then {Or $bits, $point}; # One parent bit
Subroutine __ANON__: not called CC=1 SCAR=6.9
5850 0 $t->putTreeBits($parent, $bits); # Put parent tree bits
5851  
5852 0 Mov $half, $whole; # Left bits
5853 0 And $half, ((1 << $t->leftLength) - 1); # Remove any bits above
5854 0 $t->putTreeBits($left, $half); # Save left bits
5855 0 PopR;
5856 }
5857  
5858 sub Nasm::X86::Tree::transferTreeBitsFromLeft($$$$$) #P Transfer tree bits when splitting a full left node.
5859 0 ▶ {my ($t, $point, $parent, $left, $right) = @_; # Tree descriptor, register indicating point of left in parent, numbered parent zmm, numbered left zmm, numbered right zmm
Subroutine transferTreeBitsFromLeft: not called CC=1 SCAR=6.9
5860 0 $t->transferTreeBitsFromLeftOrRight(0, $point, $parent, $left, $right);
5861 }
5862  
5863 sub Nasm::X86::Tree::transferTreeBitsFromRight($$$$$) #P Transfer tree bits when splitting a full right node.
5864 0 ▶ {my ($t, $point, $parent, $left, $right) = @_; # Tree descriptor, register indicating point of right in parent, numbered parent zmm, numbered left zmm, numbered right zmm
Subroutine transferTreeBitsFromRight: not called CC=1 SCAR=6.9
5865 0 $t->transferTreeBitsFromLeftOrRight(1, $point, $parent, $left, $right);
5866 }
5867  
5868 sub Nasm::X86::Tree::splitFullRoot($$) #P Split a full root block held in 31..29 and place the left block in 28..26 and the right block in 25..23. The left and right blocks should have their loop offsets set so they can be inserted into the root.
5869 0 ▶ {my ($t, $bs) = @_; # Tree descriptor, arena address
Subroutine splitFullRoot: not called CC=2 SCAR=17.9
5870 0 ▶ @_ == 2 or confess "2 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess("2 parameters") 0 0 0
5871  
5872 0 my $length = $t->maxKeys; # Length of block to split
5873 0 my $ll = $t->leftLength; # Left split point
5874 0 my $rl = $t->rightLength; # Right split point
5875  
5876 0 my $TK = 31; my $TD = 30; my $TN = 29; # Root key, data, node
5877 0 my $LK = 28; my $LD = 27; my $LN = 26; # Key, data, node blocks in left child
5878 0 my $RK = 25; my $RD = 24; my $RN = 23; # Key, data, node blocks in right child
5879 0 my $Test = 22; # Zmm used to hold test values via broadcast
5880  
5881 my $s = Subroutine
5882 0 ▶ {my ($parameters) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
5883 0 my $success = Label; # Short circuit if ladders by jumping directly to the end after a successful push
5884 0 my $B = $$parameters{bs};
5885  
5886 0 PushR (k6, k7, r8, zmm22);
5887 0 my $transfer = r8; # Use this register to transfer data between zmm blocks and variables
5888 0 my $work = r9; # Work register
5889  
5890 0 ▶ If $t->getLengthInKeys($TK) != $t->maxKeys, sub {Jmp $success}; # Only split full blocks
Subroutine __ANON__: not called CC=1 SCAR=6.9
5891  
5892 0 $t->allocKeysDataNode($B, 28, 27, 26); # Allocate immediate children of the root
5893 0 my $l = $t->getLoop( 26, $transfer);
5894 0 $t->putKeysDataNode ($B, $l, 28, 27, 26, $transfer, $work);
5895 0 $t->allocKeysDataNode($B, 25, 24, 23);
5896 0 my $r = $t->getLoop (23, $transfer);
5897 0 $t->putKeysDataNode ($B, $l, 25, 24, 23, $transfer, $work);
5898 0 $t->reParent ($B, 28, 27, 26); # Reparent grandchildren
5899 0 $t->reParent ($B, 25, 24, 23);
5900  
5901 0 my $n = $t->getLoop($TD, $transfer); # Offset of node block or zero if there is no node block
5902 0 my $to = $t->getLoop($TN, $transfer); # Offset of root block
5903 0 my $lo = $t->getLoop($LN, $transfer); # Offset of left block
5904 0 my $ro = $t->getLoop($RN, $transfer); # Offset of right block
5905  
5906 0 LoadBitsIntoMaskRegister(k7, $transfer, "11", -$length); # Area to clear preserving loop and up/length
5907 0 &Vmovdqu32 (zmm $LK."{k7}{z}", $LK); # Clear left
5908 0 &Vmovdqu32 (zmm $LD."{k7}{z}", $LD);
5909 0 &Vmovdqu32 (zmm $RK."{k7}{z}", $RK); # Clear right
5910 0 &Vmovdqu32 (zmm $RD."{k7}{z}", $RD);
5911  
5912 0 LoadBitsIntoMaskRegister(k7, $transfer, "10", -$length); # Area to clear preserving loop
5913 0 &Vmovdqu32 (zmm $LN."{k7}{z}", $LN); # Clear left
5914 0 &Vmovdqu32 (zmm $RK."{k7}{z}", $RK); # Clear right
5915  
5916 0 LoadBitsIntoMaskRegister(k7, $transfer, "", +$ll); # Constant mask up to the split point
5917 0 &Vmovdqu32 (zmm $LK."{k7}", $TK); # Split keys left
5918 0 &Vmovdqu32 (zmm $LD."{k7}", $TD); # Split data left
5919 0 ▶ If $n > 0, sub {&Vmovdqu32 (zmm $LN."{k7}", $TN)}; # Split nodes left
Subroutine __ANON__: not called CC=1 SCAR=6.9
5920  
5921 0 LoadBitsIntoMaskRegister(k6, $transfer, '', +$rl, -($ll+1)); # Constant mask from one beyond split point to end of keys
5922 0 Kshiftrq k7, k6, $ll+1; # Constant mask for compressed right keys
5923  
5924 0 &Vmovdqu32 (zmm $Test."{k6}{z}", $TK); # Split right keys
5925 0 &Vpcompressd (zmm $Test."{k6}", $Test); # Compress right keys
5926 0 &Vmovdqu32 (zmm $RK. "{k7}", $Test); # Save right keys
5927  
5928 0 &Vmovdqu32 (zmm $Test."{k6}{z}", $TD); # Split right data
5929 0 &Vpcompressd (zmm $Test."{k6}", $Test); # Compress right data
5930 0 &Vmovdqu32 (zmm $RD. "{k7}", $Test); # Save right data
5931  
5932 If $n > 0,
5933 Then # Split nodes right
5934 0 ▶ {&Vmovdqu32 (zmm $Test."{k6}{z}", $TN); # Split right nodes
Subroutine __ANON__: not called CC=1 SCAR=6.9
5935 0 &Vpcompressd (zmm $Test."{k6}", $Test); # Compress right node
5936 0 &Vmovdqu32 (zmm $RN. "{k7}", $Test); # Save right node
5937 0 };
5938  
5939 0 my $k = getDFromZmm $TK, $ll * (my $w = $t->width), $transfer; # Splitting key
5940 0 my $d = getDFromZmm $TD, $ll * $w, $transfer; # Splitting data
5941  
5942 0 LoadConstantIntoMaskRegister(k7, $transfer, 1); # Position of key, data in root node
5943 0 $k->zBroadCastD($Test); # Broadcast keys
5944 0 &Vmovdqu32 (zmm $TK."{k7}", $Test); # Insert key in root
5945 0 $d->zBroadCastD($Test); # Broadcast keys
5946 0 &Vmovdqu32 (zmm $TD."{k7}", $Test); # Insert data in root
5947 0 LoadBitsIntoMaskRegister(k7, $transfer, "11", -($length-1), 1); # Unused fields
5948 0 &Vmovdqu32 (zmm $TK."{k7}{z}", $TK); # Clear unused keys in root
5949 0 &Vmovdqu32 (zmm $TD."{k7}{z}", $TD); # Clear unused data in root
5950  
5951 If $n > 0,
5952 Then
5953 0 ▶ {LoadBitsIntoMaskRegister(k7, $transfer, "1", -$length, 1); # Unused fields
Subroutine __ANON__: not called CC=1 SCAR=6.9
5954 0 &Vmovdqu32 (zmm $TN."{k7}{z}", $TN); # Clear unused node in root
5955 0 };
5956  
5957 0 $t->putLengthInKeys($TK, K(one, 1)); # Set length of root keys
5958 0 $t->putLengthInKeys($LK, K(leftLength, $ll)); # Length of left node
5959 0 $t->putLengthInKeys($RK, K(rightLength, $rl)); # Length of right node
5960  
5961 0 $t->putUpIntoData($to, $LD, $transfer); # Set parent of left node
5962 0 $t->putUpIntoData($to, $RD, $transfer); # Set parent of right node
5963  
5964 0 $lo->putDIntoZmm($TN, 0, $transfer); # Insert offset of left node in root nodes
5965 0 $ro->putDIntoZmm($TN, $w, $transfer); # Insert offset of right node in root nodes
5966  
5967 0 $t->transferTreeBitsFromParent($TK, $LK, $RK); # Transfer any tree bits present
5968  
5969 0 SetLabel $success; # Insert completed successfully
5970 0 PopR;
5971 0 } [qw(bs)], name => 'Nasm::X86::Tree::splitFullRoot';
5972  
5973 0 $s->call (bs => $bs);
5974 } # splitFullRoot
5975  
5976 sub Nasm::X86::Tree::splitFullLeftOrRightNode($$) #P Split a full a full left node (held in 28..26) or a full right node (held in 25..23) whose parent is in 31..29.
5977 0 ▶ {my ($t, $right) = @_; # Tree descriptor, 0 left or 1 right
Subroutine splitFullLeftOrRightNode: not called CC=2 SCAR=17.9
5978 0 ▶ @_ == 2 or confess "Two parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess("Two parameters") 0 0 0
5979  
5980 0 my $length = $t->maxKeys; # Length of block to split
5981 0 my $ll = $t->leftLength; # Left split point
5982 0 my $rl = $t->rightLength; # Right split point
5983  
5984 0 my $PK = 31; my $PD = 30; my $PN = 29; # Root key, data, node. These registers are saved in L<splitNode>
5985 0 my $LK = 28; my $LD = 27; my $LN = 26; # Key, data, node blocks in left child
5986 0 my $RK = 25; my $RD = 24; my $RN = 23; # Key, data, node blocks in right child
5987 0 my $Test = 22; # Zmm used to hold test values via broadcast
5988  
5989 my $s = Subroutine
5990 0 ▶ {my ($parameters) = @_; # Parameters
Subroutine __ANON__: not called CC=6 SCAR=37.4
5991 0 my $success = Label; # Short circuit if ladders by jumping directly to the end after a successful push
5992  
5993 0 PushR (r8);
5994 0 my $transfer = r8; # Use this register to transfer data between zmm blocks and variables
5995  
5996 If $t->getLengthInKeys($right ? $RK : $LK) != $t->maxKeys, # Only split full blocks
5997 0 ▶ Then {Jmp $success};
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$right ? : 0 0 0
5998  
5999 0 ▶ my $n = $t->getLoop($right ? $RD : $LD, $transfer); # Offset of node block or zero if there is no node block for the right node
Branch: 1 branch
BranchTrueFalseTotal
$right ? : 0 0 0
6000 0 my $lo = $t->getLoop($LN, $transfer); # Offset of left block
6001 0 my $ro = $t->getLoop($RN, $transfer); # Offset of right block
6002  
6003 0 ▶ if ($right)
Branch: 1 branch
BranchTrueFalseTotal
if ($right) 0 0 0
6004 0 {LoadBitsIntoMaskRegister(k7, $transfer, "00", +$length); # Left mask for keys and data
6005 0 &Vmovdqu32(zmm $LK."{k7}", $RK); # Copy right keys to left node
6006 0 &Vmovdqu32(zmm $LD."{k7}", $RD); # Copy right data to left node
6007 0 LoadBitsIntoMaskRegister(k7, $transfer, "01", +$length); # Left mask for child nodes
6008 0 &Vmovdqu32(zmm $LN."{k7}", $RN); # Copy right nodes to left node
6009 }
6010  
6011 0 my $k = getDFromZmm $LK, $ll * (my $w = $t->width), $transfer; # Splitting key
6012 0 my $d = getDFromZmm $LD, $ll * $w, $transfer; # Splitting data
6013  
6014 0 LoadBitsIntoMaskRegister(k6, $transfer, '', +$rl, -($ll+1)); # Constant mask from one beyond split point to end of keys
6015 0 Kshiftrq k7, k6, $ll+1; # Constant mask for compressed right keys
6016  
6017 0 &Vmovdqu32 (zmm $Test."{k6}{z}", $LK); # Split out right keys
6018 0 &Vpcompressd (zmm $Test."{k6}", $Test); # Compress right keys
6019 0 &Vmovdqu32 (zmm $RK. "{k7}", $Test); # Save right keys
6020  
6021 0 &Vmovdqu32 (zmm $Test."{k6}{z}", $LD); # Split out right data
6022 0 &Vpcompressd (zmm $Test."{k6}", $Test); # Compress right data
6023 0 &Vmovdqu32 (zmm $RD. "{k7}", $Test); # Save right data
6024  
6025 If $n > 0,
6026 Then # Split nodes right
6027 0 ▶ {&Vmovdqu32 (zmm $Test."{k6}{z}", $LN); # Split right nodes
Subroutine __ANON__: not called CC=1 SCAR=6.9
6028 0 &Vpcompressd (zmm $Test."{k6}", $Test); # Compress right node
6029 0 &Vmovdqu32 (zmm $RN. "{k7}", $Test); # Save right node
6030 0 };
6031  
6032 0 ▶ if ($right)
Branch: 1 branch
BranchTrueFalseTotal
if ($right) { } 0 0 0
6033 0 {LoadBitsIntoMaskRegister(k7, $transfer, '11', -($rl+2), +($ll-1)); # Areas to retain
6034 0 LoadBitsIntoMaskRegister(k6, $transfer, '11', -($rl+1), +$ll);
6035  
6036 0 &Vmovdqu32 (zmm $RK."{k7}{z}", $RK); # Remove unused keys on right
6037 0 &Vmovdqu32 (zmm $RD."{k7}{z}", $RD); # Remove unused data on right
6038  
6039 If $n > 0,
6040 Then # Split nodes left
6041 0 ▶ {LoadBitsIntoMaskRegister(k7, $transfer, '10', -($rl+2), +($ll-1));
Subroutine __ANON__: not called CC=1 SCAR=6.9
6042 0 &Vmovdqu32 (zmm $RN."{k7}{z}", $RN);
6043 0 };
6044  
6045 0 &Vmovdqu32 (zmm $LK."{k6}{z}", $LK); # Remove unused keys on left
6046 0 &Vmovdqu32 (zmm $LD."{k6}{z}", $LD); # Remove unused data on left
6047  
6048 If $n > 0,
6049 Then # Split nodes left
6050 0 ▶ {LoadBitsIntoMaskRegister(k6, $transfer, '10', -($rl+1), +$ll);
Subroutine __ANON__: not called CC=1 SCAR=6.9
6051 0 &Vmovdqu32 (zmm $LN."{k6}{z}", $LN);
6052 0 };
6053 }
6054 else
6055 0 {LoadBitsIntoMaskRegister(k7, $transfer, "11", -($rl+1), +$ll); # Mask to reset moved keys
6056  
6057 0 &Vmovdqu32 (zmm $LK."{k7}{z}", $LK); # Remove unused keys
6058 0 &Vmovdqu32 (zmm $LD."{k7}{z}", $LD); # Split data left
6059 If $n > 0,
6060 Then # Split nodes left
6061 0 ▶ {LoadBitsIntoMaskRegister(k7, $transfer, '10', -($rl+1), +$ll);
Subroutine __ANON__: not called CC=1 SCAR=6.9
6062 0 &Vmovdqu32 (zmm $LN."{k7}{z}", $LN);
6063 0 };
6064 }
6065 0 ▶ ($right ? $ro : $lo)->zBroadCastD($Test); # Find index in parent of left node - broadcast offset of left node so we can locate it in the parent
Branch: 1 branch
BranchTrueFalseTotal
$right ? : 0 0 0
6066 0 LoadBitsIntoMaskRegister(k7, $transfer, '', +$length); # Nodes
6067 0 &Vpcmpud("k6{k7}", zmm($PN, $Test), 0); # Check for equal offset - one of them will match to create the single insertion point in k6
6068  
6069 0 Kandnq k5, k6, k7; # Expansion mask
6070 0 &Vpexpandd (zmm $PK."{k5}", $PK); # Shift up keys
6071 0 &Vpexpandd (zmm $PD."{k5}", $PD); # Shift up keys
6072 0 $k->zBroadCastD($Test); # Broadcast new key
6073 0 &Vmovdqu32 (zmm $PK."{k6}", $Test); # Insert new key
6074 0 $d->zBroadCastD($Test); # Broadcast new data
6075 0 &Vmovdqu32 (zmm $PD."{k6}", $Test); # Insert new data
6076  
6077 0 Kmovq r15, k6; # Point at which to insert in parent
6078 0 $t->transferTreeBitsFromLeftOrRight($right, r15, $PK, $LK, $RK);
6079  
6080 If $n > 0,
6081 Then # Insert new left node offset into parent nodes
6082 0 ▶ {Kshiftlq k6, k6, 1 unless $right; # Node insertion point
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
unless $right 0 0 0
6083 0 Kandnq k5, k6, k7; # Expansion mask
6084 0 &Vpexpandd (zmm $PN."{k5}", $PN); # Shift up nodes
6085 0 ▶ ($right ? $lo : $ro)->zBroadCastD($Test); # Broadcast left node offset
Branch: 1 branch
BranchTrueFalseTotal
$right ? : 0 0 0
6086 0 &Vmovdqu32 (zmm $PN."{k6}", $Test); # Insert right node offset
6087 0 };
6088  
6089 0 my $l = $t->getLengthInKeys($PK); # Length of parent
6090 0 $t->putLengthInKeys($PK, $l + 1); # New length of parent
6091 0 $t->putLengthInKeys($LK, K(leftLength, $ll)); # Length of left node
6092 0 $t->putLengthInKeys($RK, K(rightLength, $rl)); # Length of right node
6093  
6094 0 SetLabel $success; # Insert completed successfully
6095 0 PopR;
6096 0 } [], name => "splitFullLeftOrRightNode_$right";
6097  
6098 0 $s->call;
6099 } # splitFullLeftOrRightNode
6100  
6101 sub Nasm::X86::Tree::splitFullLeftNode($) #P Split a full left node block held in 28..26 whose parent is in 31..29 and place the new right block in 25..23. The parent is assumed to be not full. The loop and length fields are assumed to be authoritative and hence are preserved.
6102 0 ▶ {my ($t) = @_; # Tree descriptor
Subroutine splitFullLeftNode: not called CC=2 SCAR=17.9
6103 0 ▶ @_ == 1 or confess "One parameter";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess("One parameter") 0 0 0
6104 0 $t->splitFullLeftOrRightNode(0);
6105 }
6106  
6107 sub Nasm::X86::Tree::splitFullRightNode($) #P Split a full right node block held in 25..23 whose parent is in 31..29 and place the new left block in 28..26. The loop and length fields are assumed to be authoritative and hence are preserved.
6108 0 ▶ {my ($t) = @_; # Tree descriptor
Subroutine splitFullRightNode: not called CC=2 SCAR=17.9
6109 0 ▶ @_ == 1 or confess "One parameter";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess("One parameter") 0 0 0
6110 0 $t->splitFullLeftOrRightNode(1);
6111 }
6112  
6113 sub Nasm::X86::Tree::findAndSplit($$$$$$$) #P Find a key in a tree which is known to contain at least one key splitting full nodes along the path to the key.
6114 0 ▶ {my ($t, $bs, $first, $key, $compare, $offset, $index) = @_; # Tree descriptor, arena address, start node, key to find, last comparison result variable, offset of last node found, index within last node found
Subroutine findAndSplit: not called CC=2 SCAR=17.9
6115 0 ▶ @_ == 7 or confess "7 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 7 or confess("7 parameters") 0 0 0
6116 0 my $W = $t->width; # Width of keys and data
6117  
6118 my $s = Subroutine
6119 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
6120 0 my $success = Label; # Short circuit if ladders by jumping directly to the end after a successful push
6121  
6122 0 my $B = $$p{bs}; # Arena
6123 0 my $F = $$p{first}; # First keys block
6124 0 my $K = $$p{key}; # Key to find
6125  
6126 0 my $tree = V(tree)->copy($F); # Start at the first key block
6127 0 PushR k6, k7, r8, r9, r14, r15; PushZmm 28..31;
6128 0 my $zmmKeys = 31; my $zmmData = 30; my $zmmNode = 29; my $zmmTest = 28;
6129 0 my $lengthMask = k6; my $testMask = k7;
6130 0 my $transfer = r8; # Use this register to transfer data between zmm blocks and variables
6131 0 my $work = r9; # Work register
6132  
6133 0 $K->setReg(r15); # Load key into test register
6134 0 Vpbroadcastd "zmm$zmmTest", r15d;
6135  
6136 0 $t->splitNode($B, $F, $K); # Split the root
6137  
6138 ForEver # Step down through tree
6139 0 ▶ {my ($start, $end) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
6140 0 $t->getKeysDataNode($B, $tree, $zmmKeys, $zmmData, $zmmNode, # Get the keys/data/nodes block
6141 $transfer, $work);
6142 0 my $node = getDFromZmm $zmmNode, 0, $transfer; # First element of node block, which will be zero if we are on a leaf
6143  
6144 0 my $l = $t->getLengthInKeys($zmmKeys); # Length of the block
6145 0 $l->setMaskFirst($lengthMask); # Set the length mask
6146 0 Vpcmpud "$testMask\{$lengthMask}", "zmm$zmmKeys", "zmm$zmmTest", 0; # Check for equal elements
6147  
6148 0 Ktestw $testMask, $testMask;
6149 IfNz # Result mask is non zero so we must have found the key
6150 Then
6151 0 ▶ {Kmovq r15, $testMask;
Subroutine __ANON__: not called CC=1 SCAR=6.9
6152 0 Tzcnt r14, r15; # Trailing zeros gives index
6153 0 $$p{compare}->copy(0); # Key found
6154 0 $$p{index} ->getReg(r14); # Index from trailing zeros
6155 0 $$p{offset} ->copy($tree); # Offset of matching block
6156 0 Jmp $success; # Return
6157 0 };
6158  
6159 0 Vpcmpud "$testMask\{$lengthMask}", "zmm$zmmTest", "zmm$zmmKeys", 1; # Check for greater elements
6160 0 Ktestw $testMask, $testMask;
6161 IfNz # Non zero implies that the key is less than some of the keys in the block
6162 Then
6163 0 ▶ {Kmovq r15, $testMask;
Subroutine __ANON__: not called CC=1 SCAR=6.9
6164 0 Tzcnt r14, r15; # Trailing zeros
6165 If $node == 0,
6166 Then # We are on a leaf
6167 0 ▶ {$$p{compare}->copy(-1); # Key less than
Subroutine __ANON__: not called CC=1 SCAR=6.9
6168 0 $$p{index} ->getReg(r14); # Index from trailing zeros
6169 0 $$p{offset} ->copy($tree); # Offset of matching block
6170 0 Jmp $success; # Return
6171 0 };
6172 0 $tree->copy(getDFromZmm $zmmNode, "r14*$W", $transfer); # Corresponding node
6173 0 Jmp $start; # Loop
6174 0 };
6175  
6176 0 if (1) # Key greater than all keys in block
6177 {If $node == 0,
6178 Then # We have reached a leaf
6179 0 ▶ {$$p{compare}->copy(+1); # Key greater than last key
Subroutine __ANON__: not called CC=1 SCAR=6.9
6180 0 $$p{index} ->copy($l-1); # Index of last key which we are greater than
6181 0 $$p{offset} ->copy($tree); # Offset of matching block
6182 0 Jmp $success
6183 0 };
6184 };
6185 0 my $next = getDFromZmm $zmmNode, $l * $t->width, $transfer; # Greater than all keys so step through last child node
6186 0 $tree->copy($next);
6187 0 };
6188  
6189 0 SetLabel $success; # Insert completed successfully
6190 0 PopZmm; PopR;
6191 0 } [qw(bs first key compare offset index)],
6192 name => 'Nasm::X86::Tree::findAndSplit';
6193  
6194 0 $s->call($bs, first => $first, key => $key, compare => $compare,
6195 offset => $offset, index => $index);
6196 } # findAndSplit
6197  
6198 sub Nasm::X86::Tree::find($$;$$) # Find a key in a tree and test whether the found data is a sub tree. The results are held in the variables "found", "data", "subTree" addressed by the tree descriptor.
6199 0 ▶ {my ($t, $key, $bs, $first) = @_; # Tree descriptor, key field to search for, optional arena address, optional start node
Subroutine find: not called CC=5 SCAR=34.0
6200 0 ▶ @_ == 2 or @_ == 4 or confess "2 or 4 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or @_ == 4 or confess("2 or 4 parameters") 0 0 0
Condition0%0/3
@_ == 2 or @_ == 4
l!l&&r!l&&!r
000
MC/DC0%0/2
@_ == 2 or @_ == 4
@_ == 2 @_ == 4
Truth table0%0/3
A or B
A= @_ == 2B= @_ == 4
ABresult
1X1
011
000
6201 0 my $W = $t->width; # Width of keys and data
6202  
6203 my $s = Subroutine
6204 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
6205 0 my $success = Label; # Short circuit if ladders by jumping directly to the end after a successful push
6206  
6207 0 my $B = $$p{bs}; # First keys block
6208 0 my $F = $$p{first}; # First keys block
6209 0 my $K = $$p{key}; # Key to find
6210  
6211 0 PushR k6, k7, r8, r9, r14, r15; PushZmm 28..31;
6212 0 my $zmmKeys = 31; my $zmmData = 30; my $zmmNode = 29; my $zmmTest = 28;
6213 0 my $lengthMask = k6; my $testMask = k7;
6214 0 my $transfer = r8; # Use this register to transfer data between zmm blocks and variables
6215 0 my $work = r9; # Work register
6216  
6217 0 $$p{found} ->copy(0, $transfer); # Key not found
6218 0 $$p{data} ->copy(0, $transfer); # Data not yet found
6219 0 $$p{subTree}->copy(0, $transfer); # Not yet a sub tree
6220  
6221 0 my $tree = V(tree)->copy($F, $transfer); # Start at the first key block
6222  
6223 0 $K->setReg(r15); # Load key into test register
6224 0 Vpbroadcastd "zmm$zmmTest", r15d;
6225  
6226 K(loop, 99)->for(sub # Step down through tree
6227 0 ▶ {my ($index, $start, $next, $end) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
6228  
6229 0 $t->getKeysDataNode($B, $tree, $zmmKeys, $zmmData, $zmmNode, # Get the keys block
6230 $transfer, $work);
6231  
6232 0 my $l = $t->getLengthInKeys($zmmKeys); # Length of the block
6233 If $l == 0,
6234 Then # Empty tree so we have not found the key
6235 0 ▶ {Jmp $success; # Return
Subroutine __ANON__: not called CC=1 SCAR=6.9
6236 0 };
6237  
6238 0 $l->setMaskFirst($lengthMask); # Set the length mask
6239 0 Vpcmpud "$testMask\{$lengthMask}", "zmm$zmmKeys", "zmm$zmmTest", 0; # Check for equal elements
6240 0 Ktestw $testMask, $testMask;
6241 IfNz # Result mask is non zero so we must have found the key
6242 Then
6243 0 ▶ {Kmovq r15, $testMask;
Subroutine __ANON__: not called CC=1 SCAR=6.9
6244 0 Tzcnt r14, r15; # Trailing zeros
6245 0 $$p{found}->copy(1, $transfer); # Key found
6246 0 $$p{data} ->copy(getDFromZmm $zmmData, "r14*$W", $transfer); # Data associated with the key
6247 0 $t->isTree(r15, $zmmKeys); # Check whether the data so found is a sub tree
6248 0 $$p{subTree}->copyZFInverted; # Copy zero flag which opposes the notion that this element is a sub tree
6249 0 Jmp $success; # Return
6250 0 };
6251  
6252 0 my $n = getDFromZmm $zmmNode, 0, $transfer; # First child empty implies we are on a leaf
6253 If $n == 0,
6254 Then # Zero implies that this is a leaf node
6255 0 ▶ {Jmp $success; # Return
Subroutine __ANON__: not called CC=1 SCAR=6.9
6256 0 };
6257  
6258 0 Vpcmpud "$testMask\{$lengthMask}", "zmm$zmmTest", "zmm$zmmKeys", 1; # Check for greater elements
6259 0 Ktestw $testMask, $testMask;
6260  
6261 IfNz # Non zero implies that the key is less than some of the keys
6262 Then
6263 0 ▶ {Kmovq r15, $testMask;
Subroutine __ANON__: not called CC=1 SCAR=6.9
6264 0 Tzcnt r14, r15; # Trailing zeros
6265 0 $tree->copy(getDFromZmm $zmmNode, "r14*$W", $transfer); # Corresponding node
6266 0 Jmp $next; # Loop
6267 0 };
6268 0 $tree->copy(getDFromZmm $zmmNode, $l * $W, $transfer); # Greater than all keys
6269 0 });
6270 0 PrintErrStringNL "Stuck in find"; # We seem to be looping endlessly
6271 0 Exit(1);
6272  
6273 0 SetLabel $success; # Insert completed successfully
6274 0 PopZmm; PopR;
6275 0 } [qw(bs first key data found data subTree)], name => 'Nasm::X86::Tree::find';
6276  
6277 0 ▶ $s->call(bs => ($bs // $t->address), first => ($first // $t->first),
Condition0%0/6
$bs // $t->address
l!l&&r!l&&!r
000
$first // $t->first
l!l&&r!l&&!r
000
MC/DC0%0/2
$bs // $t->address
$bs $t->address
MC/DC0%0/2
$first // $t->first
$first $t->first
Truth table0%0/3
A // B
A= $bsB= $t->address
ABresult
1X1
011
000
Truth table0%0/3
A // B
A= $firstB= $t->first
ABresult
1X1
011
000
6278 key => $key, data => $t->data,
6279 found => $t->found, subTree => $t->subTree);
6280 } # find
6281  
6282 sub Nasm::X86::Tree::findAndReload($$) # Find a key in the specified tree and clone it is it is a sub tree.
6283 0 ▶ {my ($t, $key) = @_; # Tree descriptor, key as a dword
Subroutine findAndReload: not called CC=2 SCAR=17.9
6284 0 ▶ @_ == 2 or confess "Two parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess("Two parameters") 0 0 0
6285 0 Comment "Nasm::X86::Tree::findAndReload";
6286 0 $t->find($key);
6287 If $t->found > 0,
6288 Then
6289 0 ▶ {$t->first->copy($t->data); # Copy the data variable to the first variable without checking whether it is valid
Subroutine __ANON__: not called CC=1 SCAR=6.9
6290 0 };
6291 }
6292  
6293 sub Nasm::X86::Tree::findShortString($$) # Find the data at the end of a key chain held in a short string. Return a tree descriptor referencing the data located or marked as failed to find.
6294 0 ▶ {my ($tree, $string) = @_; # Tree descriptor, short string
Subroutine findShortString: not called CC=2 SCAR=17.9
6295 0 ▶ @_ == 2 or confess "2 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess("2 parameters") 0 0 0
6296 0 my $t = $tree->reload; # Reload the input tree so we can walk down the chain
6297 0 my $w = $tree->width; # Size of a key on the tree
6298 0 my $z = $string->z; # The zmm containing the short string
6299  
6300 my $s = Subroutine
6301 0 ▶ {my ($p) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
6302 0 my $L = $string->len; # Length of the short string
6303 0 $t->first->copy($$p{first}); # Reload the input tree so we can walk down the chain
6304 0 $$p{found}->copy(0); # Not yet found
6305  
6306 0 PushR rax, r14, r15;
6307 0 ClearRegisters r15;
6308 0 PushR r15, $z; # Put the zmm holding the short string onto the stack with a register block full of zeroes above it
6309 0 Lea rax, "[rsp+1]"; # Address first data byte of short string
6310 0 $L->setReg(r15); # Length of key remaining to write into key chain
6311  
6312 AndBlock
6313 0 ▶ {my ($fail, $end, $start) = @_; # Fail block, end of fail block, start of test block
Subroutine __ANON__: not called CC=1 SCAR=6.9
6314 0 Cmp r15, $w; # Can we write a full key block ?
6315 IfGt
6316 Then # Full dwords from key still to load
6317 0 ▶ {Mov r14d, "[rax]"; # Load dword from string
Subroutine __ANON__: not called CC=1 SCAR=6.9
6318 0 $t->findAndReload(V(key, r14)); # Find dword of key
6319 If $t->found == 0, # Failed to find dword
6320 Then
6321 0 ▶ {Jmp $end;
Subroutine __ANON__: not called CC=1 SCAR=6.9
6322 0 };
6323 0 Add rax, $w; # Move up over found key
6324 0 Sub r15, $w; # Reduce amount of key still to find
6325 0 Jmp $start; # Restart
6326 0 };
6327 0 Mov r14d, "[rax]"; # Load possibly partial dword from string which might have some trailing zeroes in it from the register block above
6328 0 $t->find(V(key, r14)); # Find remaining key and data
6329 0 $$p{data} ->copy($t->data);
6330 0 $$p{found}->copy($t->found);
6331 0 };
6332 0 PopR; PopR;
6333 0 } [qw(bs first data found)], name => "Nasm::X86::Tree::findShortString_$z";
6334  
6335 0 $s->call($tree->address, first => $tree->first, $tree->data, $tree->found); # Find the data at the end of the short string key
6336  
6337 0 $t # Return the cloned tree descriptor as it shows the data and the find status
6338 } # findShortString
6339  
6340 sub Nasm::X86::Tree::size($) # Return a variable containing the number of keys in the specified tree.
6341 0 ▶ {my ($t) = @_; # Tree descriptor
Subroutine size: not called CC=2 SCAR=17.9
6342 0 ▶ @_ == 1 or confess "One parameter";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess("One parameter") 0 0 0
6343  
6344 my $s = Subroutine
6345 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
6346  
6347 0 PushR r8, r9;
6348 0 my $transfer = r8; # Use this register to transfer data between zmm blocks and variables
6349 0 my $work = r9; # Work register
6350  
6351 0 $t->getKeysData($$p{bs}, $$p{first}, 31, 30, $transfer, $work); # Get the first block so we can update the key count
6352 0 my $size = $t->getCountFromData(30, $transfer); # Get key count
6353 0 $$p{size}->copy($size); # Set result
6354 0 PopR;
6355 0 } [qw(bs first size)], name => "Nasm::X86::Tree::size";
6356  
6357 0 $s->call(bs => $t->address, first => $t->first, my $size = V(size));
6358  
6359 0 $size;
6360 } # size
6361  
6362 sub Nasm::X86::Tree::insertDataOrTree($$$$) # Insert either a key, data pair into the tree or create a sub tree at the specified key (if it does not already exist) and return the offset of the first block of the sub tree in the data variable.
6363 0 ▶ {my ($t, $tnd, $key, $data) = @_; # Tree descriptor, 0 - data or 1 - tree, key as a dword, data as a dword
Subroutine insertDataOrTree: not called CC=3 SCAR=24.8
6364 0 ▶ @_ >= 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 or confess() 0 0 0
6365 0 my $W = RegisterSize zmm0; # The size of a block
6366  
6367 my $s = Subroutine
6368 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
6369 0 my $success = Label; # Short circuit if ladders by jumping directly to the end after a successful push
6370  
6371 0 my $B = $$p{bs}; # Arena
6372 0 my $F = $$p{first}; # First keys block
6373 0 my $K = $$p{key}; # Key to be inserted
6374 0 my $D = $$p{data}; # Data to be inserted
6375  
6376 0 PushMask 4..7; PushR r8, r9, r13, r14, r15; PushZmm 22..31;
6377 0 my $transfer = r8; # Use this register to transfer data between zmm blocks and variables
6378 0 my $work = r9; # Work register
6379 0 my $point = r13; # Insertion indicator
6380 0 $t->getKeysDataNode($B, $F, 31, 30, 29, $transfer, $work); # Get the first block
6381  
6382 0 my $l = $t->getLengthInKeys(31); # Length of the block
6383 If $l == 0, # Check for empty tree.
6384 Then # Empty tree
6385 0 ▶ {$K->putDIntoZmm (31, 0, $transfer); # Write key
Subroutine __ANON__: not called CC=3 SCAR=24.8
6386 0 $t->putLengthInKeys(31, K(one, 1)); # Set the length of the block
6387 0 ▶ if ($tnd) # Create and mark key as addressing a sub tree
Branch: 1 branch
BranchTrueFalseTotal
if ($tnd) 0 0 0
6388 0 ▶ {$D->copy($t->bs->CreateTree($B)->first) if $tnd == 1; # Create sub tree
Branch: 1 branch
BranchTrueFalseTotal
if $tnd == 1 0 0 0
6389 0 Mov r15, 1; # Indicate first position
6390 0 $t->setTree(r15, 31); # Mark this key as addressing a sub tree from the existing tree
6391 }
6392 0 $D->putDIntoZmm (30, 0, $transfer); # Write data
6393 0 $t->incCountInData (30, $transfer); # Update count
6394 0 $t->putKeysData($B, $F, 31, 30, $transfer, $work); # Write the data block back into the underlying arena
6395 0 Jmp $success; # Insert completed successfully
6396 0 };
6397  
6398 0 my $n = $t->getLoop(30, $transfer); # Get the offset of the node block
6399 If $n == 0,
6400 Then # Node is root with no children and space for more keys
6401 {If $l < $t->maxKeys,
6402 Then # Node is root with no children and space for more keys
6403 0 ▶ {$l->setMaskFirst(k7); # Set the compare bits
Subroutine __ANON__: not called CC=3 SCAR=24.8
6404 0 $K->setReg(r15); # Key to search for
6405 0 Vpbroadcastd zmm22, r15d; # Load key
6406 0 Vpcmpud "k6{k7}", zmm22, zmm31, 0; # Check for equal key
6407 0 Ktestd k6, k6; # Check whether a matching key was found - the operation clears the zero flag if the register is not zero
6408 IfNz # Found the key so we just update the data field
6409 Then
6410 0 ▶ {if ($tnd) # Insert sub tree if requested
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
if ($tnd) 0 0 0
6411 0 {Kmovq r15, k6; # Position of key just found
6412 0 $t->isTree(r15, 31); # Set the zero flag to indicate whether the existing data element is in fact a tree
6413 IfNz # If the data element is already a tree then get its value and return it in the data variable
6414 Then
6415 0 ▶ {Tzcnt r14, r15; # Trailing zeros
Subroutine __ANON__: not called CC=1 SCAR=6.9
6416 0 $D->copy(getDFromZmm 30, "r14*$$t{width}", $transfer); # Data associated with the key
6417 0 Jmp $success; # Return offset of sub tree
6418 },
6419 Else # The existing element is not a tree so we mark it as such using the single bit in r15/k6
6420 0 ▶ {$t->setTree(r15, 31);
Subroutine __ANON__: not called CC=1 SCAR=6.9
6421 0 };
6422 0 ▶ $D->copy($t->bs->CreateTree->first) if $tnd == 1; # Create tree and copy offset of first block
Branch: 1 branch
BranchTrueFalseTotal
if $tnd == 1 0 0 0
6423 }
6424 0 $D->setReg(r14); # Key to search for
6425 0 Vpbroadcastd "zmm30{k6}", r14d; # Load data
6426 0 $t->putKeysData($B, $F, 31, 30, $transfer, $work); # Write the data block back into the underlying arena
6427 0 Jmp $success; # Insert completed successfully
6428 0 };
6429  
6430 0 Vpcmpud "k6{k7}", zmm22, zmm31, 1; # Check for elements that are greater than an existing element
6431 0 Ktestw k6, k6;
6432 IfEq (sub # K6 zero implies the latest key goes at the end
6433 0 ▶ {Kshiftlw k6, k7, 1; # Reach next empty field
Subroutine __ANON__: not called CC=1 SCAR=6.9
6434 0 Kandnw k6, k7, k6; # Remove back fill to leave a single bit at the next empty field
6435 },
6436 sub
6437 0 ▶ {Kandw k5, k6, k7; # Tested at: # Insert key for Tree but we could simplify by using a mask for the valid area
Subroutine __ANON__: not called CC=1 SCAR=6.9
6438 0 Kandnw k4, k5, k7;
6439 0 Kshiftlw k5, k5, 1;
6440 0 Korw k5, k4, k5; # Broadcast mask
6441 0 Kandnw k6, k5, k7; # Expand mask
6442 0 Vpexpandd "zmm31{k5}", zmm31; # Shift up keys
6443 0 Vpexpandd "zmm30{k5}", zmm30; # Shift up data
6444 0 });
6445  
6446 0 Vpbroadcastd "zmm31{k6}", r15d; # Load key
6447  
6448 0 ▶ if ($tnd) # Insert new sub tree
Branch: 1 branch
BranchTrueFalseTotal
if ($tnd) 0 0 0
6449 0 ▶ {$D->copy($t->bs->CreateTree->first) if $tnd == 1; # Create tree and copy offset of first block
Branch: 1 branch
BranchTrueFalseTotal
if $tnd == 1 0 0 0
6450 }
6451 0 if (1) # Expand tree bits to match
6452 0 {Kmovq $point, k6; # Position of key just found
6453 0 $t->expandTreeBitsWithZeroOrOne($tnd, 31, $point); # Mark new entry as a sub tree
6454 }
6455  
6456 0 $D->setReg(r14); # Corresponding data
6457 0 Vpbroadcastd "zmm30{k6}", r14d; # Load data
6458 0 $t->putLengthInKeys( 31, $l + 1); # Set the length of the block
6459 0 $t->incCountInData ( 30, $transfer); # Update count
6460  
6461 If $l + 1 == $t->maxKeys,
6462 Then # Root is now full: allocate the node block for it and chain it in
6463 0 ▶ {$t->bs->allocZmmBlock($B, my $n = V(offset)); # Children
Subroutine __ANON__: not called CC=1 SCAR=6.9
6464 0 $t->putLoop($n, 30, $transfer); # Set the link from data to node
6465 0 $t->putLoop($F, 29, $transfer); # Set the link from node to key
6466 0 };
6467  
6468 0 $t->putKeysDataNode($B, $F, 31, 30, 29, $transfer, $work); # Write the data block back into the underlying arena
6469 0 $t->splitNode($B, $F, $K); # Split if the leaf has got too big
6470 0 Jmp $success; # Insert completed successfully
6471 0 ▶ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
6472 0 };
6473  
6474 0 my $compare = V(compare); # Comparison result
6475 0 my $offset = V(offset); # Offset of result
6476 0 my $index = V('index'); # Index of result
6477  
6478 0 $t->findAndSplit($B, $F, $K, $compare, $offset, $index); # Find block that should contain key
6479  
6480 0 $t->getKeysDataNode($B, $offset, 31, 30, 29, $transfer, $work);
6481 0 Mov $point, 0;
6482 0 $index->setBit($point); # Set point at the index
6483  
6484 If $compare == 0, # Duplicate key
6485 Then # Found an equal key so update the data
6486 0 ▶ {$D->putDIntoZmm(30, $index * $t->width, $transfer); # Update data at key
Subroutine __ANON__: not called CC=1 SCAR=6.9
6487 0 $t->putKeysDataNode($B, $offset, 31, 30, 29, $transfer, $work); # Rewrite data and keys
6488 0 $t->setOrClearTree($tnd, $point, 31); # Set or clear tree bit as necessary
6489 },
6490 Else # We have room for the insert because each block has been split to make it non full
6491 {If $compare > 0,
6492 Then # Position at which to insert new key if it is greater than the indexed key
6493 0 ▶ {++$index;
Subroutine __ANON__: not called CC=1 SCAR=6.9
6494 0 Shl $point, 1; # Move point up as well
6495 0 ▶ };
Subroutine __ANON__: not called CC=2 SCAR=17.9
6496  
6497 0 my $length = $t->getLengthInKeys(31); # Number of keys
6498 If $index < $length,
6499 Then # Need to expand as we cannot push
6500 0 ▶ {$length->setMaskFirst(k7); # Length as bits
Subroutine __ANON__: not called CC=1 SCAR=6.9
6501 0 Kshiftlw k6, k7, 1; # Length plus one as bits with a trailing zero
6502 0 Korw k6, k6, k7; # Length plus one as bits with no trailing zero
6503 0 $index->clearMaskBit(k6); # Zero at the index
6504 0 Vpexpandd "zmm31{k6}", zmm31; # Shift up keys
6505 0 Vpexpandd "zmm30{k6}", zmm30; # Shift up data
6506 0 };
6507  
6508 0 $t->expandTreeBitsWithZeroOrOne($tnd, 31, $point); # Mark inserted key as referring to a tree or not
6509  
6510 0 ▶ $D->copy($t->bs->CreateTree->first) if $tnd == 1; # Create tree and place its offset into data field
Branch: 1 branch
BranchTrueFalseTotal
if $tnd == 1 0 0 0
6511  
6512 0 ClearRegisters k7;
6513 0 $index->setMaskBit(k7); # Set bit at insertion point
6514 0 $K->setReg(r15); # Corresponding data
6515 0 Vpbroadcastd "zmm31{k7}", r15d; # Load key
6516 0 $D->setReg(r14); # Corresponding data
6517 0 Vpbroadcastd "zmm30{k7}", r14d; # Load data
6518 0 $t->putLengthInKeys(31, $length + 1); # Set the new length of the block
6519 0 $t->putKeysDataNode($B, $offset, 31, 30, 29, $transfer, $work); # Rewrite data and keys
6520 0 $t->splitNode($B, $offset, $K); # Split if the leaf has got too big
6521  
6522 0 $t->getKeysData($B, $F, 31, 30, $transfer, $work); # Get the first block so we can update the key count
6523 0 $t->incCountInData (30, $transfer); # Update key count
6524 0 $t->putKeysData($B, $F, 31, 30, $transfer, $work); # Write the first block with the updated key count
6525 0 };
6526  
6527 0 SetLabel $success; # Insert completed successfully
6528 0 PopZmm;
6529 0 PopR;
6530 0 PopMask;
6531 0 } [qw(bs first key data)], name => "Nasm::X86::Tree::insertDataOrTree_$tnd"; # Data either supplies the data or returns the offset of the sub tree
6532  
6533 0 ▶ $s->call($t->address, first => $t->first, key => $key,
Branch: 1 branch
BranchTrueFalseTotal
$tnd == 1 ? : 0 0 0
6534 data => $tnd == 1 ? $t->data : $data);
6535 } # insert
6536  
6537 sub Nasm::X86::Tree::insert($$$) # Insert a dword into into the specified tree at the specified key.
6538 0 ▶ {my ($t, $key, $data) = @_; # Tree descriptor, key as a dword, data as a dword
Subroutine insert: not called CC=2 SCAR=17.9
6539 0 ▶ @_ == 3 or confess "Three parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess("Three parameters") 0 0 0
6540 0 $t->insertDataOrTree(0, $key, $data); # Insert data
6541 }
6542  
6543 sub Nasm::X86::Tree::insertTree($$;$) # Insert a sub tree into the specified tree tree under the specified key. If no sub tree is supplied an empty one is provided gratis.
6544 0 ▶ {my ($t, $key, $subTree) = @_; # Tree descriptor, key as a dword, sub tree to insert else an empty one will be added
Subroutine insertTree: not called CC=6 SCAR=37.4
6545 0 ▶ @_ == 2 or @_ == 3 or confess "Two or three parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or @_ == 3 or confess("Two or three parameters") 0 0 0
Condition0%0/3
@_ == 2 or @_ == 3
l!l&&r!l&&!r
000
MC/DC0%0/2
@_ == 2 or @_ == 3
@_ == 2 @_ == 3
Truth table0%0/3
A or B
A= @_ == 2B= @_ == 3
ABresult
1X1
011
000
6546 0 ▶ if (my $r = ref($subTree))
Branch: 1 branch
BranchTrueFalseTotal
if (my $r = ref $subTree) { } 0 0 0
6547 0 ▶ {if ($r =~ m(Tree))
Branch: 2 branches
BranchTrueFalseTotal
if ($r =~ /Tree/) { } 0 0 0
elsif ($r =~ /Variable/) { } 0 0 0
6548 0 {$t->insertDataOrTree(2, $key, $subTree->first); # Insert a sub tree from a tree descriptor
6549 }
6550 elsif ($r =~ m(Variable))
6551 0 {$t->insertDataOrTree(2, $key, $subTree); # Insert a sub tree from a variable containing an offset to the first node of the tree
6552 }
6553 else
6554 0 {confess "Reference to a variable or a tree required";
6555 }
6556 }
6557 else # Create a sub tree
6558 0 {$t->insertDataOrTree(1, $key); # Request a sub tree be created if one has not been supplied
6559 }
6560 }
6561  
6562 sub Nasm::X86::Tree::insertTreeAndReload($$) # Insert a new sub tree into the specified tree tree under the specified key and return a descriptor for it. If the tree already exists, return a descriptor for it.
6563 0 ▶ {my ($t, $key) = @_; # Tree descriptor, key as a dword
Subroutine insertTreeAndReload: not called CC=2 SCAR=17.9
6564 0 ▶ @_ == 2 or confess "Two parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess("Two parameters") 0 0 0
6565 0 $t->insertTree($key);
6566 0 $t->first->copy($t->data); # Copy the data variable to the first variable without checking whether it is valid
6567 }
6568  
6569 sub Nasm::X86::Tree::insertShortString($$$) # Insert some data at the end of a chain of sub trees keyed by the contents of a short string.
6570 0 ▶ {my ($tree, $string, $data) = @_; # Tree descriptor, short string, data as a dword
Subroutine insertShortString: not called CC=2 SCAR=17.9
6571 0 ▶ @_ == 3 or confess "Three parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess("Three parameters") 0 0 0
6572 0 my $w = $tree->width; # Size of a key on the tree
6573 0 my $z = $string->z; # The zmm containing the short string
6574  
6575 my $s = Subroutine
6576 0 ▶ {my ($p) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
6577 0 my $L = $string->len; # Length of the short string
6578  
6579 0 PushR rax, r14, r15;
6580 0 ClearRegisters r15;
6581 0 PushR r15, $z; # Put the zmm holding the short string onto the stack with a register block full of zeroes above it
6582 0 Lea rax, "[rsp+1]"; # Address first data byte of short string
6583 0 $L->setReg(r15); # Length of key remaining to write into key chain
6584  
6585 0 my $t = $tree->reload(first=>$$p{first}); # Reload the input tree so we can walk down the chain from it.
6586  
6587 AndBlock
6588 0 ▶ {my ($fail, $end, $start) = @_; # Fail block, end of fail block, start of test block
Subroutine __ANON__: not called CC=1 SCAR=6.9
6589 0 Cmp r15, $w; # Can we write a full key block ?
6590 IfGt
6591 Then # Full dwords from key still to load
6592 0 ▶ {Mov r14d, "[rax]"; # Load dword from string
Subroutine __ANON__: not called CC=1 SCAR=6.9
6593 0 $t->insertTreeAndReload(V(key, r14)); # Create sub tree
6594 0 Add rax, $w; # Move up over inserted key
6595 0 Sub r15, $w; # Reduce amount of key still to write
6596 0 Jmp $start; # Restart
6597 0 };
6598 0 Mov r14d, "[rax]"; # Load possibly partial dword from string which might have some trailing zeroes in it from the register block above
6599 0 $t->insert(V(key, r14), $$p{data}); # Insert remaining key and data
6600 0 };
6601 0 PopR; PopR;
6602 0 } [qw(bs first data)],
6603 name => "Nasm::X86::Tree::insertinsertShortString_$z";
6604  
6605 0 $s->call($tree->address, first => $tree->first, data => $data); # Insert the data at the end of the short string key
6606 } # insertShortString
6607  
6608 sub Nasm::X86::Tree::getKeysData($$$$$;$$) #P Load the keys and data blocks for a node.
6609 0 ▶ {my ($t, $bs, $offset, $zmmKeys, $zmmData, $work1, $work2) = @_; # Tree descriptor, arena address, offset as a variable, numbered zmm for keys, numbered data for keys, optional first work register, optional second work register
Subroutine getKeysData: not called CC=3 SCAR=24.8
6610 0 ▶ @_ == 5 or @_ == 7 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 5 or @_ == 7 or confess() 0 0 0
Condition0%0/3
@_ == 5 or @_ == 7
l!l&&r!l&&!r
000
MC/DC0%0/2
@_ == 5 or @_ == 7
@_ == 5 @_ == 7
Truth table0%0/3
A or B
A= @_ == 5B= @_ == 7
ABresult
1X1
011
000
6611 0 $t->bs->getBlock($bs, $offset, $zmmKeys, $work1, $work2); # Get the keys block
6612 0 my $data = $t->getLoop($zmmKeys, $work1); # Get the offset of the corresponding data block
6613 0 $t->bs->getBlock($bs, $data, $zmmData, $work1, $work2); # Get the data block
6614 }
6615  
6616 sub Nasm::X86::Tree::putKeysData($$$$$;$$) #P Save the key and data blocks for a node.
6617 0 ▶ {my ($t, $bs, $offset, $zmmKeys, $zmmData, $work1, $work2) = @_; # Tree descriptor, arena address, offset as a variable, numbered zmm for keys, numbered data for keys, optional first work register, optional second work register
Subroutine putKeysData: not called CC=3 SCAR=24.8
6618 0 ▶ @_ == 4 or @_ == 7 or confess "5 or 7 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 4 or @_ == 7 or confess("5 or 7 parameters") 0 0 0
Condition0%0/3
@_ == 4 or @_ == 7
l!l&&r!l&&!r
000
MC/DC0%0/2
@_ == 4 or @_ == 7
@_ == 4 @_ == 7
Truth table0%0/3
A or B
A= @_ == 4B= @_ == 7
ABresult
1X1
011
000
6619 0 $t->bs->putBlock($bs, $offset, $zmmKeys, $work1, $work2); # Put the keys block
6620 0 my $data = $t->getLoop($zmmKeys, $work1); # Get the offset of the corresponding data block
6621 0 $t->bs->putBlock($bs, $data, $zmmData, $work1, $work2); # Put the data block
6622 }
6623  
6624 sub Nasm::X86::Tree::getKeysDataNode($$$$$$;$$) #P Load the keys, data and child nodes for a node.
6625 0 ▶ {my ($t, $bs, $offset, $zmmKeys, $zmmData, $zmmNode, $work1, $work2) = @_; # Tree descriptor, arena address, offset as a variable, numbered zmm for keys, numbered data for keys, numbered numbered for keys, optional first work register, optional second work register
Subroutine getKeysDataNode: not called CC=5 SCAR=34.0
6626 0 ▶ @_ == 6 or @_ == 8 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 6 or @_ == 8 or confess() 0 0 0
Condition0%0/3
@_ == 6 or @_ == 8
l!l&&r!l&&!r
000
MC/DC0%0/2
@_ == 6 or @_ == 8
@_ == 6 @_ == 8
Truth table0%0/3
A or B
A= @_ == 6B= @_ == 8
ABresult
1X1
011
000
6627 0 ▶ ref($offset) && ref($offset) =~ m(variable)i or
Branch: 1 branch
BranchTrueFalseTotal
ref $offset and ref($offset) =~ /variable/i or confess("Variable required for offset") 0 0 0
Condition0%0/3
ref $offset and ref($offset) =~ /variable/i
!ll&&!rl&&r
000
MC/DC0%0/2
ref $offset and ref($offset) =~ /variable/i
ref $offset ref($offset) =~ /variable/i
Truth table0%0/3
A and B
A= ref $offsetB= ref($offset) =~ /variable/i
ABresult
0X0
100
111
6628 confess "Variable required for offset";
6629 0 my $b = $t->bs; # Underlying arena
6630  
6631 0 $b->getBlock($bs, $offset, $zmmKeys, $work1, $work2); # Get the keys block
6632 0 my $data = $t->getLoop ($zmmKeys, $work1, $work2); # Get the offset of the corresponding data block
6633 0 $b->getBlock($bs, $data, $zmmData, $work1, $work2); # Get the data block
6634  
6635 0 my $node = $t->getLoop ($zmmData, $work1, $work2); # Get the offset of the corresponding node block
6636 If $node > 0,
6637 Then # Check for optional node block
6638 0 ▶ {$b->getBlock($bs, $node, $zmmNode, $work1, $work2); # Get the node block
Subroutine __ANON__: not called CC=1 SCAR=6.9
6639 },
6640 Else # No children
6641 0 ▶ {ClearRegisters zmm $zmmNode; # Clear the child block to signal that there was not one - if there were it would have child nodes in it which would be none zero
Subroutine __ANON__: not called CC=1 SCAR=6.9
6642 0 };
6643 }
6644  
6645 sub Nasm::X86::Tree::putKeysDataNode($$$$$$;$$) #P Save the keys, data and child nodes for a node.
6646 0 ▶ {my ($t, $bs, $offset, $zmmKeys, $zmmData, $zmmNode, $work1, $work2) = @_; # Tree descriptor, arena address, offset as a variable, numbered zmm for keys, numbered data for keys, numbered numbered for keys, optional first work register, optional second work register
Subroutine putKeysDataNode: not called CC=3 SCAR=24.8
6647 0 ▶ @_ == 6 or @_ == 8 or confess " 6 or 8 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 6 or @_ == 8 or confess(" 6 or 8 parameters") 0 0 0
Condition0%0/3
@_ == 6 or @_ == 8
l!l&&r!l&&!r
000
MC/DC0%0/2
@_ == 6 or @_ == 8
@_ == 6 @_ == 8
Truth table0%0/3
A or B
A= @_ == 6B= @_ == 8
ABresult
1X1
011
000
6648 0 $t->putKeysData($bs, $offset, $zmmKeys, $zmmData, $work1, $work2); # Put keys and data
6649 0 my $node = $t->getLoop($zmmData, $work1); # Get the offset of the corresponding node block
6650 If $node > 0,
6651 Then # Check for optional node block
6652 0 ▶ {$t->bs->putBlock($bs, $node, $zmmNode, $work1, $work2); # Put the node block
Subroutine __ANON__: not called CC=1 SCAR=6.9
6653 0 };
6654 }
6655  
6656 sub Nasm::X86::Tree::getLengthInKeys($$) #P Get the length of the keys block in the numbered zmm and return it as a variable.
6657 0 ▶ {my ($t, $zmm) = @_; # Tree descriptor, zmm number
Subroutine getLengthInKeys: not called CC=2 SCAR=17.9
6658 0 ▶ @_ == 2 or confess "2 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess("2 parameters") 0 0 0
6659  
6660 0 getBFromZmm($zmm, $t->lengthOffset); # The length field as a variable
6661 }
6662  
6663 sub Nasm::X86::Tree::putLengthInKeys($$$) #P Get the length of the block in the numbered zmm from the specified variable.
6664 0 ▶ {my ($t, $zmm, $length) = @_; # Tree, zmm number, length variable
Subroutine putLengthInKeys: not called CC=3 SCAR=24.8
6665 0 ▶ @_ == 3 or confess "3 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess("3 parameters") 0 0 0
6666 0 ▶ ref($length) or confess dump($length);
Branch: 1 branch
BranchTrueFalseTotal
ref $length or confess(Nasm::X86::dump($length)) 0 0 0
6667 0 $length->putBIntoZmm($zmm, $t->lengthOffset) # Set the length field
6668 }
6669  
6670 sub Nasm::X86::Tree::getUpFromData11($$$) #P Get the up offset from the data block in the numbered zmm and return it as a variable.
6671 0 ▶ {my ($t, $zmm, $transfer) = @_; # Tree descriptor, zmm number, transfer register
Subroutine getUpFromData11: not called CC=2 SCAR=17.9
6672 0 ▶ @_ == 3 or confess "3 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess("3 parameters") 0 0 0
6673 0 getDFromZmm($zmm, $t->up, $transfer); # The length field as a variable
6674 }
6675  
6676 sub Nasm::X86::Tree::putUpIntoData11($$$;$) #P Put the offset of the parent keys block expressed as a variable into the numbered zmm.
6677 0 ▶ {my ($t, $offset, $zmm, $transfer) = @_; # Tree descriptor, variable containing up offset, zmm number, optional transfer register
Subroutine putUpIntoData11: not called CC=4 SCAR=30.0
6678 0 ▶ @_ == 3 or @_ == 4 or confess "3 or 4 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or @_ == 4 or confess("3 or 4 parameters") 0 0 0
Condition0%0/3
@_ == 3 or @_ == 4
l!l&&r!l&&!r
000
MC/DC0%0/2
@_ == 3 or @_ == 4
@_ == 3 @_ == 4
Truth table0%0/3
A or B
A= @_ == 3B= @_ == 4
ABresult
1X1
011
000
6679 0 ▶ defined($offset) or confess;
Branch: 1 branch
BranchTrueFalseTotal
defined $offset or confess() 0 0 0
6680 0 $offset->putDIntoZmm($zmm, $t->up, $transfer); # Save the up offset into the data block
6681 }
6682  
6683 sub Nasm::X86::Tree::getUpFromData($$$) #P Get the decompressed up offset from the data block in the numbered zmm and return it as a variable. The lowest 6 bits of an offset are always 0b011000. The up field becomes the count field for the root node which has no node above it. To differentiate between up and count, the lowest bit of the up field is set for offsets, and cleared for the count of the number of nodes in the tree held in the root node. Thus if this dword is set to zero it means that this is the count field for an empty tree.
6684 0 ▶ {my ($t, $zmm, $transfer) = @_; # Tree descriptor, zmm number, transfer register
Subroutine getUpFromData: not called CC=2 SCAR=17.9
6685 0 ▶ @_ == 3 or confess "3 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess("3 parameters") 0 0 0
6686 0 my $z = "zmm$zmm";
6687 0 my $w = RegisterSize $z; # Size of zmm register
6688 0 my $o = $t->up; # Offset into register in bytes
6689 0 Vmovdqu32 "[rsp-$w]", $z; # Write below the stack
6690 0 Mov $transfer."d", "[rsp+$o-$w]"; # Load double word register from offset
6691 0 Shr $transfer."d", 1; # Shift out the lowest bit which tells us whether this is an offset(1) or a count (0) and set the flags accordingly
6692 IfC
6693 Then # Low bit set so it is an offset
6694 0 ▶ {Shl $transfer, 6; # Divide the offset by 64 being the minimum size of a block
Subroutine __ANON__: not called CC=1 SCAR=6.9
6695 0 Add $transfer, 0x18; # Blocks are always offset by this amount which represents the header overhead for an arena. If anything other than 64 byte allocations have been made in the arena this formula becomes inaccurate.
6696 },
6697 Else # Low bit clear so it is a count in the root node and so the up offset is zero.
6698 0 ▶ {ClearRegisters $transfer;
Subroutine __ANON__: not called CC=1 SCAR=6.9
6699 0 };
6700 0 V(up, $transfer);
6701 }
6702  
6703 sub Nasm::X86::Tree::getUpFromDataNM($$$) #P Get the compressed up offset//count from the data block in the numbered zmm and return it as a variable.
6704 0 ▶ {my ($t, $zmm, $transfer) = @_; # Tree descriptor, zmm number, transfer register
Subroutine getUpFromDataNM: not called CC=2 SCAR=17.9
6705 0 ▶ @_ == 3 or confess "3 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess("3 parameters") 0 0 0
6706 0 my $z = "zmm$zmm";
6707 0 my $w = RegisterSize $z; # Size of zmm register
6708 0 my $o = $t->up; # Offset into register in bytes
6709 0 Vmovdqu32 "[rsp-$w]", $z; # Write below the stack
6710 0 Mov $transfer."d", "[rsp+$o-$w]"; # Load double word register from offset
6711 0 V(up, $transfer);
6712 }
6713  
6714 sub Nasm::X86::Tree::putUpIntoData($$$$) #P Put the offset of the parent keys block expressed as a variable into the numbered zmm. Offsets always end in 0b01100 as long as only 64 byte allocations have been made in the arena. Offsets are indicated by setting the lowest bit in the dword containing the offset to 1.
6715 0 ▶ {my ($t, $offset, $zmm, $transfer) = @_; # Tree descriptor, variable containing up offset, zmm number, transfer register
Subroutine putUpIntoData: not called CC=2 SCAR=17.9
6716 0 ▶ @_ == 4 or confess "4 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 4 or confess("4 parameters") 0 0 0
6717  
6718 0 $offset->setReg($transfer);
6719 0 Shr $transfer."d", 5; # The lowest 6 bits of an offset are always 0b011000 so we shift them off to save space but we need one bit to indicate whether this is an offset(1) or a count(0)
6720 0 Or $transfer, 1; # Set highest lowest bit to show that it is an offset
6721 0 my $z = "zmm$zmm";
6722 0 my $w = RegisterSize $z; # Size of zmm register
6723 0 my $o = $t->up; # Offset into zmm register in bytes of count/up field
6724 0 Vmovdqu64 "[rsp-$w]", $z; # Write zmm below the stack
6725 0 Mov "[rsp+$o-$w]", $transfer."d"; # Save offset
6726 0 Vmovdqu64 $z, "[rsp-$w]"; # Reload zmm
6727 }
6728  
6729 sub Nasm::X86::Tree::getCountFromData($$$) #P Get the number of keys in the tree. The number of keys in the tree is stored in the up field of the data block associated with the root. If the lowest bit in this field is set then the field is an offset, if it is clear then it is a count.
6730 0 ▶ {my ($t, $zmm, $transfer) = @_; # Tree descriptor, zmm number, transfer register
Subroutine getCountFromData: not called CC=2 SCAR=17.9
6731 0 ▶ @_ == 3 or confess "3 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess("3 parameters") 0 0 0
6732  
6733 0 my $z = "zmm$zmm";
6734 0 my $w = RegisterSize $z; # Size of zmm register
6735 0 my $o = $t->up; # Offset into register in bytes
6736 0 Vmovdqu32 "[rsp-$w]", $z; # Write below the stack
6737 0 Mov $transfer."d", "[rsp+$o-$w]"; # Load double word register from offset
6738 0 my $size = V(size, 0);
6739 0 Shr $transfer, 1; # Remove and test the lowest bit
6740 IfNc
6741 Then # Highest bit is zero so the field is a count
6742 0 ▶ {$size->getReg($transfer); # Load count
Subroutine __ANON__: not called CC=1 SCAR=6.9
6743 },
6744 Else # Complain because we are being asked for an invalid field
6745 0 ▶ {PrintErrTraceBack;
Subroutine __ANON__: not called CC=1 SCAR=6.9
6746 0 PrintErrStringNL "Cannot get count field from non root node data block";
6747 0 Exit(1);
6748 0 };
6749  
6750 0 $size; # Return variable containing size of tree
6751 }
6752  
6753 sub Nasm::X86::Tree::incCountInData($$$) #P Increment the count field in the up field of the data block associate with the root node.
6754 0 ▶ {my ($t, $zmm, $transfer) = @_; # Tree descriptor, zmm number, transfer register
Subroutine incCountInData: not called CC=2 SCAR=17.9
6755 0 ▶ @_ == 3 or confess "3 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess("3 parameters") 0 0 0
6756  
6757 0 my $z = "zmm$zmm";
6758 0 my $w = RegisterSize $z; # Size of zmm register
6759 0 my $o = $t->up; # Offset into zmm register in bytes of count/up field
6760 0 Vmovdqu64 "[rsp-$w]", $z; # Write zmm below the stack
6761 0 Mov $transfer."d", "[rsp+$o-$w]"; # Load current count
6762 0 Shr $transfer, 1; # Remove and test the lowest bit - if it is set then this is an offset, else if clear it is a count
6763 IfC
6764 Then # We are trying to manipulate an offset not a count
6765 0 ▶ {PrintErrTraceBack; # Complain because we are being asked for an invalid field
Subroutine __ANON__: not called CC=1 SCAR=6.9
6766 0 PrintErrStringNL "Not a root node";
6767 0 Exit(1);
6768 0 };
6769 0 Inc $transfer; # Increment
6770 0 Shl $transfer, 1; # Space for indicator bit cleared.
6771 0 Mov "[rsp+$o-$w]", $transfer."d"; # Save count
6772 0 Vmovdqu64 "zmm$zmm", "[rsp-$w]"; # Reload zmm
6773 }
6774  
6775 sub Nasm::X86::Tree::decCountInData($$$) #P Decrement the count field in the up field of the data block associate with the root node.
6776 0 ▶ {my ($t, $zmm, $transfer) = @_; # Tree descriptor, zmm number, transfer register
Subroutine decCountInData: not called CC=2 SCAR=17.9
6777 0 ▶ @_ == 3 or confess "3 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess("3 parameters") 0 0 0
6778  
6779 0 my $z = "zmm$zmm";
6780 0 my $w = RegisterSize $z; # Size of zmm register
6781 0 my $o = $t->up; # Offset into zmm register in bytes of count/up field
6782 0 Vmovdqu64 "[rsp-$w]", $z; # Write zmm below the stack
6783 0 Mov $transfer."d", "[rsp+$o-$w]"; # Load current count
6784 0 Shr $transfer, 1; # Remove and test the lowest bit - if it is set then this is an offset, else if clear it is a count
6785 IfC
6786 Then # We are trying to manipulate an offset not a count
6787 0 ▶ {PrintErrTraceBack; # Complain because we are being asked for an invalid field
Subroutine __ANON__: not called CC=1 SCAR=6.9
6788 0 PrintErrStringNL "Not a root node";
6789 0 Exit(1);
6790 0 };
6791 0 Cmp $transfer, 0; # Check that we are able to reduce the count
6792 IfEq
6793 Then # We are trying to manipulate an offset not a count
6794 0 ▶ {PrintErrTraceBack; # Complain because we are being asked for an invalid field
Subroutine __ANON__: not called CC=1 SCAR=6.9
6795 0 PrintErrStringNL "Cannot reduce node count below zero";
6796 0 Exit(1);
6797 0 };
6798 0 Dec $transfer; # Increment
6799 0 Shl $transfer, 1; # Space for indicator bit cleared.
6800 0 Mov "[rsp+$o-$w]", $transfer."d"; # Save count
6801 0 Vmovdqu64 "zmm$zmm", "[rsp-$w]"; # Reload zmm
6802 }
6803  
6804 sub Nasm::X86::Tree::getLoop($$;$) #P Return the value of the loop field as a variable.
6805 0 ▶ {my ($t, $zmm, $transfer) = @_; # Tree descriptor, numbered zmm, optional transfer register
Subroutine getLoop: not called CC=2 SCAR=17.9
6806 0 ▶ @_ >= 1 or confess "1 parameter";
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 1 or confess("1 parameter") 0 0 0
6807 0 getDFromZmm($zmm, $t->loop, $transfer); # Get loop field as a variable
6808 }
6809  
6810 sub Nasm::X86::Tree::putLoop($$$;$) #P Set the value of the loop field from a variable.
6811 0 ▶ {my ($t, $value, $zmm, $transfer) = @_; # Tree descriptor, variable containing offset of next loop entry, numbered zmm, optional transfer register
Subroutine putLoop: not called CC=2 SCAR=17.9
6812 0 ▶ @_ >= 1 or confess "1 parameter";
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 1 or confess("1 parameter") 0 0 0
6813 0 $value->putDIntoZmm($zmm, $t->loop, $transfer); # Put loop field as a variable
6814 }
6815  
6816 sub Nasm::X86::Tree::leftOrRightMost($$$$$) # Return the offset of the left most or right most node.
6817 0 ▶ {my ($t, $dir, $bs, $node, $offset) = @_; # Tree descriptor, direction: left = 0 or right = 1, arena address, start node, offset of located node
Subroutine leftOrRightMost: not called CC=3 SCAR=24.8
6818 0 ▶ @_ == 5 or confess "5 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 5 or confess("5 parameters") 0 0 0
6819  
6820 my $s = Subroutine
6821 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
6822 0 my $success = Label; # Short circuit if ladders by jumping directly to the end after a successful push
6823  
6824 0 my $B = $$p{bs}; # Arena address
6825 0 my $F = $$p{node}; # First block
6826 0 PushR rax, r8, r9; PushZmm 29..31;
6827  
6828 K(loopLimit, 9)->for(sub # Loop a reasonable number of times
6829 0 ▶ {my ($index, $start, $next, $end) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
6830 0 $t->getKeysDataNode($B, $F, 31, 30, 29, r8, r9); # Get the first keys block
6831 0 my $n = getDFromZmm 29, 0, r8; # Get the node block offset from the data block loop
6832 If $n == 0,
6833 Then # Reached the end so return the containing block
6834 0 ▶ {$$p{offset}->copy($F);
Subroutine __ANON__: not called CC=1 SCAR=6.9
6835 0 Jmp $success;
6836 0 };
6837 0 ▶ if ($dir == 0) # Left most
Branch: 1 branch
BranchTrueFalseTotal
if ($dir == 0) { } 0 0 0
6838 0 {my $l = getDFromZmm 29, 0, r8; # Get the left most node
6839 0 $F->copy($l); # Continue with the next level
6840 }
6841 else # Right most
6842 0 {my $l = $t->getLengthInKeys(31); # Length of the node
6843 0 my $r = getDFromZmm(31, $l, r8); # Get the right most child
6844 0 $F->copy($r); # Continue with the next level
6845 }
6846 0 });
6847 0 PrintErrStringNL "Stuck in LeftOrRightMost";
6848 0 Exit(1);
6849  
6850 0 SetLabel $success; # Insert completed successfully
6851 0 PushZmm; PopR;
6852 0 ▶ } [qw(bs node offset )],
Branch: 1 branch
BranchTrueFalseTotal
$dir == 0 ? : 0 0 0
6853 name => $dir==0 ? "Nasm::X86::Tree::leftMost" : "Nasm::X86::Tree::rightMost";
6854  
6855 0 $s->call($bs, node => $node, offset=>$offset);
6856 }
6857  
6858 sub Nasm::X86::Tree::leftMost($$$$) # Return the offset of the left most node from the specified node.
6859 0 ▶ {my ($t, $bs, $node, $offset) = @_; # Tree descriptor, arena address, start node, returned offset
Subroutine leftMost: not called CC=2 SCAR=17.9
6860 0 ▶ @_ == 4 or confess "4 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 4 or confess("4 parameters") 0 0 0
6861 0 $t->leftOrRightMost(0, $bs, $node, $offset) # Return the left most node
6862 }
6863  
6864 sub Nasm::X86::Tree::rightMost($$$$) # Return the offset of the left most node from the specified node.
6865 0 ▶ {my ($t, $bs, $node, $offset) = @_; # Tree descriptor, arena address, start node, returned offset
Subroutine rightMost: not called CC=2 SCAR=17.9
6866 0 ▶ @_ == 4 or confess "4 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 4 or confess("4 parameters") 0 0 0
6867 0 $t->leftOrRightMost(1, $bs, $node, $offset) # Return the right most node
6868 }
6869  
6870 sub Nasm::X86::Tree::nodeFromData($$$) #P Load the the node block into the numbered zmm corresponding to the data block held in the numbered zmm.
6871 0 ▶ {my ($t, $data, $node) = @_; # Tree descriptor, numbered zmm containing data, numbered zmm to hold node block
Subroutine nodeFromData: not called CC=2 SCAR=17.9
6872 0 confess "Not needed";
6873 0 ▶ @_ == 3 or confess "Three parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess("Three parameters") 0 0 0
6874 0 my $loop = $t->getLoop($data); # Get loop offset from data
6875 0 $t->getBlock($t->address, $loop, $node); # Node
6876 }
6877  
6878 sub Nasm::X86::Tree::address($) #P Address of the arena containing a tree.
6879 0 ▶ {my ($t) = @_; # Tree descriptor
Subroutine address: not called CC=2 SCAR=17.9
6880 0 ▶ @_ == 1 or confess "4 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess("4 parameters") 0 0 0
6881 0 $t->bs->bs;
6882 }
6883  
6884 sub Nasm::X86::Tree::allocBlock($$) #P Allocate a block to hold a zmm register in the specified arena and return the offset of the block in a variable.
6885 0 ▶ {my ($t, $bs) = @_; # Tree descriptor, variables
Subroutine allocBlock: not called CC=2 SCAR=17.9
6886 0 ▶ @_ == 2 or confess "2 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess("2 parameters") 0 0 0
6887 0 $t->bs->allocBlock($bs); # Allocate a block and return its offset as a variable
6888 }
6889  
6890 sub Nasm::X86::Tree::depth($$$$) # Return the depth of a node within a tree.
6891 0 ▶ {my ($t, $bs, $node, $depth) = @_; # Tree descriptor, arena address, node, return depth
Subroutine depth: not called CC=2 SCAR=17.9
6892 0 ▶ @_ == 4 or confess "4 parameters required";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 4 or confess("4 parameters required") 0 0 0
6893  
6894 my $s = Subroutine
6895 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
6896 0 my $success = Label; # Short circuit if ladders by jumping directly to the end after a successful push
6897  
6898 0 my $B = $$p{bs}; # Arena address
6899 0 my $N = $$p{node}; # Starting node
6900  
6901 0 PushR r8, r9, r14, r15, zmm30, zmm31;
6902 0 my $tree = V(tree)->copy($N); # Start at the specified node
6903  
6904 K(loop, 9)->for(sub # Step up through tree
6905 0 ▶ {my ($index, $start, $next, $end) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
6906 0 $t->getKeysData($B, $tree, 31, 30, r8, r9); # Get the keys block
6907 0 my $P = $t->getUpFromData(30, r8); # Parent
6908 If $P == 0,
6909 Then # Empty tree so we have not found the key
6910 0 ▶ {$$p{depth}->copy($index+1); # Key not found
Subroutine __ANON__: not called CC=1 SCAR=6.9
6911 0 Jmp $success; # Return
6912 0 };
6913 0 $tree->copy($P); # Up to next level
6914 0 });
6915 0 PrintErrStringNL "Stuck in depth"; # We seem to be looping endlessly
6916 0 Exit(1);
6917  
6918 0 SetLabel $success; # Insert completed successfully
6919 0 PopR;
6920 0 } [qw(bs node depth)], name => 'Nasm::X86::Tree::allocBlock';
6921  
6922 0 $s->call($t->address, node => $node, depth => $depth);
6923 } # depth
6924  
6925 #D2 Sub trees # Construct trees of trees.
6926  
6927 sub Nasm::X86::Tree::testTree($$$) #P Set the Zero Flag to oppose the tree bit indexed by the specified variable in the numbered zmm register holding the keys of a node to indicate whether the data element indicated by the specified register is an offset to a sub tree in the containing arena or not.
6928 0 ▶{my ($t, $position, $zmm) = @_; # Tree descriptor, variable holding index of position to test, numbered zmm register holding the keys for a node in the tree
Subroutine testTree: not called CC=2 SCAR=17.9
6929 0 ▶ @_ == 3 or confess "3 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess("3 parameters") 0 0 0
6930 0 PushR rax, rcx;
6931 0 Mov rax, 1; # Place a single 1 at the position to test
6932 0 $position->setReg(rcx); # Position
6933 0 Shl rax, cl; # Move into position
6934 0 $t->isTree(rax, $zmm); # Test position
6935 0 PopR;
6936 } # isTree
6937  
6938 sub Nasm::X86::Tree::isTree($$$) #P Set the Zero Flag to oppose the tree bit in the numbered zmm register holding the keys of a node to indicate whether the data element indicated by the specified register is an offset to a sub tree in the containing arena or not.
6939 0 ▶{my ($t, $register, $zmm) = @_; # Tree descriptor, word register holding a bit shifted into the position to test, numbered zmm register holding the keys for a node in the tree
Subroutine isTree: not called CC=2 SCAR=17.9
6940 0 ▶ @_ == 3 or confess "3 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess("3 parameters") 0 0 0
6941  
6942 0 my $z = "zmm$zmm"; # Full name of zmm register
6943 0 my $o = $$t{treeBits}; # Bytes from tree bits to end of zmm
6944 0 my $w = RegisterSize $z; # Size of zmm register
6945 0 Vmovdqu64 "[rsp-$w]", $z; # Write beyond stack
6946 0 Test $register, "[rsp-$w+$o]"; # Test the tree bits
6947 } # isTree
6948  
6949 sub Nasm::X86::Tree::setOrClearTree($$$$) #P Set or clear the tree bit in the numbered zmm register holding the keys of a node to indicate that the data element indicated by the specified register is an offset to a sub tree in the containing arena.
6950 0 ▶ {my ($t, $set, $register, $zmm) = @_; # Tree descriptor, set if true else clear, register holding a single one in the lowest 14 bits at the insertion point, numbered zmm register holding the keys for a node in the tree
Subroutine setOrClearTree: not called CC=4 SCAR=30.0
6951 0 ▶ @_ == 4 or confess "4 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 4 or confess("4 parameters") 0 0 0
6952 0 ▶ $register =~ m(\Ar) or # Check register type
Branch: 1 branch
BranchTrueFalseTotal
$register =~ /\Ar/ or confess("General purpose register required, not $register") 0 0 0
6953 confess "General purpose register required, not $register";
6954  
6955 0 my $z = "zmm$zmm"; # Full name of zmm register
6956 0 my $o = $$t{treeBits}; # Tree bits to end of zmm
6957 0 PushR ($register, $z);
6958 0 ▶ if ($set) # Set the indexed bit
Branch: 1 branch
BranchTrueFalseTotal
if ($set) { } 0 0 0
6959 0 {And $register, $t->treeBitsMask; # Mask tree bits to prevent operations outside the permitted area
6960 0 Or "[rsp+$o]", $register; # Set tree bit in zmm
6961 }
6962 else # Clear the indexed bit
6963 0 {And $register, $t->treeBitsMask; # Mask tree bits to prevent operations outside the permitted area
6964 0 Not $register;
6965 0 And "[rsp+$o]", $register;
6966 }
6967 0 PopR;
6968 } # setOrClearTree
6969  
6970 sub Nasm::X86::Tree::setTree($$$) #P Set the tree bit in the numbered zmm register holding the keys of a node to indicate that the data element indexed by the specified register is an offset to a sub tree in the containing arena.
6971 0 ▶ {my ($t, $register, $zmm) = @_; # Tree descriptor, register holding data element index 0..13, numbered zmm register holding the keys for a node in the tree
Subroutine setTree: not called CC=2 SCAR=17.9
6972 0 ▶ @_ == 3 or confess "3 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess("3 parameters") 0 0 0
6973 0 $t->setOrClearTree(1, $register, $zmm);
6974 } # setTree
6975  
6976 sub Nasm::X86::Tree::clearTree($$$) #P Clear the tree bit in the numbered zmm register holding the keys of a node to indicate that the data element indexed by the specified register is an offset to a sub tree in the containing arena.
6977 0 ▶{my ($t, $register, $zmm) = @_; # Tree descriptor, register holding data element index 0..13, numbered zmm register holding the keys for a node in the tree
Subroutine clearTree: not called CC=2 SCAR=17.9
6978 0 ▶ @_ == 3 or confess "3 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess("3 parameters") 0 0 0
6979 0 $t->setOrClearTree(0, $register, $zmm);
6980 } # clearTree
6981  
6982 sub Nasm::X86::Tree::getTreeBits($$$) #P Load the tree bits from the numbered zmm into the specified register.
6983 0 ▶ {my ($t, $zmm, $register) = @_; # Tree descriptor, numbered zmm, target register
Subroutine getTreeBits: not called CC=2 SCAR=17.9
6984 0 ▶ @_ == 3 or confess "3 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess("3 parameters") 0 0 0
6985 0 loadFromZmm $register, w, $zmm, $t->treeBits;
6986 0 And $register, $t->treeBitsMask;
6987 }
6988  
6989 sub Nasm::X86::Tree::putTreeBits($$$) #P Put the tree bits in the specified register into the numbered zmm.
6990 0 ▶ {my ($t, $zmm, $register) = @_; # Tree descriptor, numbered zmm, target register
Subroutine putTreeBits: not called CC=2 SCAR=17.9
6991 0 ▶ @_ == 3 or confess "3 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess("3 parameters") 0 0 0
6992 0 putIntoZmm $register, w, $zmm, $t->treeBits;
6993 0 And $register, $t->treeBitsMask;
6994 }
6995  
6996 sub Nasm::X86::Tree::expandTreeBitsWithZeroOrOne($$$$) #P Insert a zero or one into the tree bits field in the numbered zmm at the specified point.
6997 0 ▶ {my ($t, $onz, $zmm, $point) = @_; # Tree descriptor, 0 - zero or 1 - one, numbered zmm, register indicating point
Subroutine expandTreeBitsWithZeroOrOne: not called CC=3 SCAR=24.8
6998 0 ▶ @_ == 4 or confess "4 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 4 or confess("4 parameters") 0 0 0
6999 0 PushR my @save = my ($bits) = ChooseRegisters(1, $point); # Tree bits register
7000 0 $t->getTreeBits($zmm, $bits); # Get tree bits
7001 0 ▶ if ($onz)
Branch: 1 branch
BranchTrueFalseTotal
if ($onz) { } 0 0 0
7002 0 {InsertOneIntoRegisterAtPoint($point, $bits); # Insert a one into the tree bits at the indicated location
7003 }
7004 else
7005 0 {InsertZeroIntoRegisterAtPoint($point, $bits); # Insert a zero into the tree bits at the indicated location
7006 }
7007 0 $t->putTreeBits($zmm, $bits); # Put tree bits
7008 0 PopR;
7009 }
7010  
7011 sub Nasm::X86::Tree::expandTreeBitsWithZero($$$) #P Insert a zero into the tree bits field in the numbered zmm at the specified point.
7012 0 ▶ {my ($t, $zmm, $point) = @_; # Tree descriptor, numbered zmm, register indicating point
Subroutine expandTreeBitsWithZero: not called CC=2 SCAR=17.9
7013 0 ▶ @_ == 3 or confess "3 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess("3 parameters") 0 0 0
7014 0 $t->expandTreeBitsWithZeroOrOne(0, $zmm, $point); # Insert a zero into the tree bits field in the numbered zmm at the specified point
7015 }
7016  
7017 sub Nasm::X86::Tree::expandTreeBitsWithOne($$$) #P Insert a one into the tree bits field in the numbered zmm at the specified point.
7018 0 ▶ {my ($t, $zmm, $point) = @_; # Tree descriptor, numbered zmm, register indicating point
Subroutine expandTreeBitsWithOne: not called CC=2 SCAR=17.9
7019 0 ▶ @_ == 3 or confess "3 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess("3 parameters") 0 0 0
7020 0 $t->expandTreeBitsWithZeroOrOne(1, $zmm, $point); # Insert a one into the tree bits field in the numbered zmm at the specified point
7021 }
7022  
7023 #D2 Print # Print a tree
7024  
7025 sub Nasm::X86::Tree::print($) # Print a tree.
7026 0 ▶ {my ($t) = @_; # Tree
Subroutine print: not called CC=2 SCAR=17.9
7027 0 ▶ @_ == 1 or confess "One parameter";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess("One parameter") 0 0 0
7028  
7029 my $s = Subroutine # Print a tree
7030 0 ▶ {my ($p, $s) = @_; # Parameters, sub definition
Subroutine __ANON__: not called CC=1 SCAR=6.9
7031  
7032 0 PrintOutString "Tree at: "; $$p{first}->outNL(' ');
7033  
7034 $t->by(sub # Iterate through the tree
7035 0 ▶ {my ($iter, $end) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
7036 0 $iter->tree->depth($$p{bs}, $iter->node, my $D = V(depth));
7037 0 $iter->key ->out('key: ');
7038 0 $iter->data->out(' data: ');
7039 0 $D ->outNL (' depth: ');
7040 0 $t->find($iter->key); # Slow way to find out if this is a subtree
7041 If $t->subTree > 0,
7042 Then
7043 0 ▶ {$s->call($$p{bs}, first => $t->data);
Subroutine __ANON__: not called CC=1 SCAR=6.9
7044 0 };
7045 0 }, $$p{bs}, $$p{first}+0);
7046 0 } [qw(bs first)], name => "Nasm::X86::Tree::print";
7047  
7048 0 $s->call($t->address, $t->first);
7049 }
7050  
7051 sub Nasm::X86::Tree::dump($;$$) # Dump a tree and all its sub trees.
7052 0 ▶ {my ($t, $first, $bs) = @_; # Tree, optional offset to first node, optional arena address
Subroutine dump: not called CC=5 SCAR=34.0
7053 0 ▶ @_ >= 1 && @_ <= 3 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 1 and @_ <= 3 or confess() 0 0 0
Condition0%0/3
@_ >= 1 and @_ <= 3
!ll&&!rl&&r
000
MC/DC0%0/2
@_ >= 1 and @_ <= 3
@_ >= 1 @_ <= 3
Truth table0%0/3
A and B
A= @_ >= 1B= @_ <= 3
ABresult
0X0
100
111
7054  
7055 0 PushR my ($depthR) = (r12);
7056  
7057 my $b = Subroutine # Print the spacing blanks to offset sub trees
7058 {V(loop, $depthR)->for(sub
7059 0 ▶ {PrintOutString " ";
Subroutine __ANON__: not called CC=1 SCAR=6.9
7060 0 ▶ });
Subroutine __ANON__: not called CC=1 SCAR=6.9
7061 0 } [], name => "Nasm::X86::Tree::dump::spaces";
7062  
7063 my $s = Subroutine # Print a tree
7064 0 ▶ {my ($p, $s) = @_; # Parameters, sub definition
Subroutine __ANON__: not called CC=2 SCAR=17.9
7065  
7066 0 my $B = $$p{bs};
7067 0 my $F = $$p{first};
7068  
7069 0 PushZmm 29..31; PushR r8, r9, r10;
7070 0 my ($treeBitsR, $treeBitsIndexR, $transfer) = (r8, r9, r10);
7071  
7072 0 $t->getKeysDataNode($B, $F, 31, 30, 29, $treeBitsR, $treeBitsIndexR); # Load node
7073 0 $t->getTreeBits(31, $treeBitsR); # Tree bits for this node
7074 0 my $l = $t->getLengthInKeys(31); # Number of nodes
7075  
7076 0 $b->call;
7077 0 PrintOutString "Tree at: "; $$p{first}->out(' '); $l->outNL(' length: '); # Position and length
7078  
7079 0 Inc $depthR; # Indent sub tree
7080  
7081 0 for my $i(0..2) # Tree node description
7082 0 {my ($z) = zmm 29+$i; # Zmm returns an array
7083 0 $b->call; PrintOneRegisterInHex $stdout, $z; PrintOutNL;
7084 }
7085  
7086 0 Mov $treeBitsIndexR, 1; # Check each tree bit position
7087 $l->for(sub # Print keys and data
7088 0 ▶ {my ($index, $start, $next, $end) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
7089 0 my $i = $index * $t->width; # Key/Data offset
7090 0 my $k = getDFromZmm(31, $i, $transfer); # Key
7091 0 my $d = getDFromZmm(30, $i, $transfer); # Data
7092 0 $b->call;
7093 0 $index->out(' index: ');
7094 0 $k->out(' key: ');
7095 0 $d->out(' data: ');
7096 0 Test $treeBitsR, $treeBitsIndexR; # Check for a tree bit
7097 IfNz
7098 Then # This key indexes a sub tree
7099 0 ▶ {PrintOutStringNL(" subTree");
Subroutine __ANON__: not called CC=1 SCAR=6.9
7100 },
7101 Else
7102 0 ▶ {PrintOutNL;
Subroutine __ANON__: not called CC=1 SCAR=6.9
7103 0 };
7104 0 Shl $treeBitsIndexR, 1; # Next tree bit position
7105 0 });
7106  
7107 0 Cmp $treeBitsR, 0; # Any tree bit sets?
7108 IfNe
7109 Then # Tree bits present
7110 0 ▶ {Mov $treeBitsIndexR, 1; # Check each tree bit position
Subroutine __ANON__: not called CC=1 SCAR=6.9
7111 K(loop, $t->maxKeys)->for(sub
7112 0 ▶ {my ($index, $start, $next, $end) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
7113 0 Test $treeBitsR, $treeBitsIndexR; # Check for a tree bit
7114 IfNz
7115 Then # This key indexes a sub tree
7116 0 ▶ {my $i = $index * $t->width; # Key/data offset
Subroutine __ANON__: not called CC=1 SCAR=6.9
7117 0 my $d = getDFromZmm(30, $i, $transfer); # Data
7118 0 $s->call($B, first => $d); # Print sub tree referenced by data field
7119 0 };
7120 0 Shl $treeBitsIndexR, 1; # Next tree bit position
7121 0 });
7122 0 };
7123  
7124 ($l+1)->for(sub # Print sub nodes
7125 0 ▶ {my ($index, $start, $next, $end) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
7126 0 my $i = $index * $t->width; # Key/Data offset
7127 0 my $d = getDFromZmm(29, $i, $transfer); # Data
7128 If $d > 0, # Print any sub nodes
7129 Then
7130 0 ▶ {$s->call($B, first => $d);
Subroutine __ANON__: not called CC=1 SCAR=6.9
7131 0 };
7132 0 });
7133  
7134 0 Dec $depthR; # Reset indent
7135  
7136 0 $b->call; PrintOutStringNL "end"; # Separate sub tree dumps
7137 0 PopR; PopZmm;
7138 0 } [qw(bs first)], name => "Nasm::X86::Tree::dump";
7139  
7140 0 PushR $depthR;
7141 0 ClearRegisters $depthR; # Depth starts at zero
7142  
7143 0 ▶ $s->call(bs => ($bs//$t->address), first => ($first//$t->first));
Condition0%0/6
$bs // $t->address
l!l&&r!l&&!r
000
$first // $t->first
l!l&&r!l&&!r
000
MC/DC0%0/2
$bs // $t->address
$bs $t->address
MC/DC0%0/2
$first // $t->first
$first $t->first
Truth table0%0/3
A // B
A= $bsB= $t->address
ABresult
1X1
011
000
Truth table0%0/3
A // B
A= $firstB= $t->first
ABresult
1X1
011
000
7144  
7145 0 PopR;
7146 }
7147  
7148 #D2 Iteration # Iterate through a tree non recursively
7149  
7150 sub Nasm::X86::Tree::iterator($;$$) # Iterate through a multi way tree starting either at the specified node or the first node of the specified tree.
7151 0 ▶ {my ($t, $bs, $first) = @_; # Tree, optional arena else the arena associated with the tree, optionally the node to start at else the first node of the supplied tree will be used
Subroutine iterator: not called CC=5 SCAR=34.0
7152 0 ▶ @_ == 1 or @_ == 3 or confess "1 or 3 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or @_ == 3 or confess("1 or 3 parameters") 0 0 0
Condition0%0/3
@_ == 1 or @_ == 3
l!l&&r!l&&!r
000
MC/DC0%0/2
@_ == 1 or @_ == 3
@_ == 1 @_ == 3
Truth table0%0/3
A or B
A= @_ == 1B= @_ == 3
ABresult
1X1
011
000
7153 0 Comment "Nasm::X86::Tree::iterator";
7154  
7155 0 my $i = genHash(__PACKAGE__.'::Tree::Iterator', # Iterator
7156 tree => $t, # Tree we are iterating over
7157 bs => V(bs), # Arena containing tree
7158 node => V(node), # Current node within tree
7159 pos => V('pos'), # Current position within node
7160 key => V(key), # Key at this position
7161 data => V(data), # Data at this position
7162 count => V(count), # Counter - number of node
7163 more => V(more), # Iteration not yet finished
7164 );
7165  
7166 0 ▶ $i->bs ->copy($bs // $t->address); # Arena containing nodes of tree
Condition0%0/3
$bs // $t->address
l!l&&r!l&&!r
000
MC/DC0%0/2
$bs // $t->address
$bs $t->address
Truth table0%0/3
A // B
A= $bsB= $t->address
ABresult
1X1
011
000
7167 0 ▶ $i->node ->copy($first // $t->first); # Start at the specified node or else the first node in the tree
Condition0%0/3
$first // $t->first
l!l&&r!l&&!r
000
MC/DC0%0/2
$first // $t->first
$first $t->first
Truth table0%0/3
A // B
A= $firstB= $t->first
ABresult
1X1
011
000
7168 0 $i->pos ->copy(-1); # Initialize iterator
7169 0 $i->count->copy( 0);
7170 0 $i->more ->copy(+1);
7171  
7172 0 $i->next; # First element if any
7173 }
7174  
7175 sub Nasm::X86::Tree::Iterator::next($) # Next element in the tree.
7176 0 ▶ {my ($iter) = @_; # Iterator
Subroutine next: not called CC=2 SCAR=17.9
7177 0 ▶ @_ == 1 or confess "One parameter";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess("One parameter") 0 0 0
7178  
7179 my $s = Subroutine
7180 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
7181 0 my $success = Label; # Short circuit if ladders by jumping directly to the end after a successful push
7182  
7183 0 my $B = $$p{bs}; # Arena address
7184 0 my $C = $$p{node}; # Current node required
7185 0 $$p{count} = $$p{count} + 1; # Count the calls to the iterator
7186  
7187 my $new = sub # Load iterator with latest position
7188 0 ▶ {my ($node, $pos) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
7189 0 PushR r8, r9; PushZmm 29..31;
7190 0 $$p{node}->copy($node); # Set current node
7191 0 $$p{pos} ->copy($pos); # Set current position in node
7192 0 $iter->tree->getKeysData($B, $node, 31, 30, r8, r9); # Load keys and data
7193  
7194 0 my $offset = $pos * $iter->tree->width; # Load key and data
7195 0 $$p{key} ->copy(getDFromZmm 31, $offset, r8);
7196 0 $$p{data}->copy(getDFromZmm 30, $offset, r8);
7197 0 PopZmm; PopR;
7198 0 };
7199  
7200 my $done = sub # The tree has been completely traversed
7201 0 ▶ {PushR rax;
Subroutine __ANON__: not called CC=1 SCAR=6.9
7202 0 Mov rax, 0;
7203 0 $$p{more}->getReg(rax);
7204 0 PopR rax;
7205 0 };
7206  
7207 If $$p{pos} == -1,
7208 Then # Initial descent
7209 0 ▶ {my $t = $iter->tree;
Subroutine __ANON__: not called CC=1 SCAR=6.9
7210 0 my $end = Label;
7211  
7212 0 PushR r8, r9; PushZmm 29..31;
7213 0 $t->getKeysDataNode($B, $C, 31, 30, 29, r8, r9); # Load keys and data
7214  
7215 0 my $l = $t->getLengthInKeys(31); # Length of the block
7216 If $l == 0, # Check for empty tree.
7217 Then # Empty tree
7218 0 ▶ {&$done;
Subroutine __ANON__: not called CC=1 SCAR=6.9
7219 0 Jmp $end;
7220 0 };
7221  
7222 0 my $nodes = $t->getLoop(30, r8); # Nodes
7223  
7224 If $nodes > 0,
7225 Then # Go left if there are child nodes
7226 0 ▶ {$t->leftMost($B, $C, my $l = V(offset));
Subroutine __ANON__: not called CC=1 SCAR=6.9
7227 0 &$new($l, K(zero, 0));
7228 },
7229 Else
7230 0 ▶ {my $l = $t->getLengthInKeys(31); # Number of keys
Subroutine __ANON__: not called CC=1 SCAR=6.9
7231 If $l > 0,
7232 Then # Start with the current node as it is a leaf
7233 0 ▶ {&$new($C, K(zero, 0));
Subroutine __ANON__: not called CC=1 SCAR=6.9
7234 },
7235 Else
7236 0 ▶ {&$done;
Subroutine __ANON__: not called CC=1 SCAR=6.9
7237 0 };
7238 0 };
7239  
7240 0 SetLabel $end;
7241 0 PopZmm; PopR;
7242 0 Jmp $success; # Return with iterator loaded
7243 0 };
7244  
7245 my $up = sub # Iterate up to next node that has not been visited
7246 0 ▶ {my $top = Label; # Reached the top of the tree
Subroutine __ANON__: not called CC=1 SCAR=6.9
7247 0 my $n = V(first)->copy($C);
7248 0 my $zmmNK = 31; my $zmmPK = 28; my $zmmTest = 25;
7249 0 my $zmmND = 30; my $zmmPD = 27;
7250 0 my $zmmNN = 29; my $zmmPN = 26;
7251 0 PushR k7, r8, r9, r14, r15; PushZmm 25..31;
7252 0 my $t = $iter->tree;
7253  
7254 ForEver # Up through the tree
7255 0 ▶ {my ($start, $end) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
7256 0 $t->getKeysData($B, $n, $zmmNK, $zmmND, r8, r9); # Load keys and data for current node
7257 0 my $p = $t->getUpFromData($zmmND, r8);
7258 0 ▶ If $p == 0, sub{Jmp $end}; # Jump to the end if we have reached the top of the tree
Subroutine __ANON__: not called CC=1 SCAR=6.9
7259 0 $t->getKeysDataNode($B, $p, $zmmPK, $zmmPD, $zmmPN, r8, r9); # Load keys, data and children nodes for parent which must have children
7260 0 $n->setReg(r15); # Offset of child
7261 0 Vpbroadcastd "zmm".$zmmTest, r15d; # Current node broadcasted
7262 0 Vpcmpud k7, "zmm".$zmmPN, "zmm".$zmmTest, 0; # Check for equal offset - one of them will match to create the single insertion point in k6
7263 0 Kmovw r14d, k7; # Bit mask ready for count
7264 0 Tzcnt r14, r14; # Number of leading zeros gives us the position of the child in the parent
7265 0 my $i = V(indexInParent, r14); # Index in parent
7266 0 my $l = $t->getLengthInKeys($zmmPK); # Length of parent
7267  
7268 If $i < $l,
7269 Then # Continue with this node if all the keys have yet to be finished
7270 0 ▶ {&$new($p, $i);
Subroutine __ANON__: not called CC=1 SCAR=6.9
7271 0 Jmp $top;
7272 0 };
7273 0 $n->copy($p); # Continue with parent
7274 0 };
7275 0 &$done; # No nodes not visited
7276 0 SetLabel $top;
7277 0 PopZmm;
7278 0 PopR;
7279 0 };
7280  
7281 0 $$p{pos}->copy(my $i = $$p{pos} + 1); # Next position in block being scanned
7282 0 PushR r8, r9; PushZmm 29..31;
7283 0 my $t = $iter->tree;
7284 0 $t->getKeysDataNode($B, $C, 31, 30, 29, r8, r9); # Load keys and data
7285 0 my $l = $t->getLengthInKeys(31); # Length of keys
7286 0 my $n = getDFromZmm 29, 0, r8; # First node will ne zero if on a leaf
7287 If $n == 0,
7288 Then # Leaf
7289 {If $i < $l,
7290 Then
7291 0 ▶ {&$new($C, $i);
Subroutine __ANON__: not called CC=1 SCAR=6.9
7292 },
7293 Else
7294 0 ▶ {&$up;
Subroutine __ANON__: not called CC=1 SCAR=6.9
7295 0 ▶ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
7296 },
7297 Then # Node
7298 0 ▶ {my $offsetAtI = getDFromZmm 29, $i * $iter->tree->width, r8;
Subroutine __ANON__: not called CC=1 SCAR=6.9
7299 0 $iter->tree->leftMost($B, $offsetAtI, my $l = V(offset));
7300 0 &$new($l, K(zero, 0));
7301 0 };
7302  
7303 0 PopZmm; PopR;
7304 0 SetLabel $success;
7305 0 } [qw(bs node pos key data count more)],
7306 name => 'Nasm::X86::Tree::Iterator::next ';
7307  
7308 0 $s->call($iter->bs,
7309 $iter->node, $iter->pos, $iter->key, # Call with iterator variables
7310 $iter->data, $iter->count, $iter->more);
7311 0 $iter # Return the iterator
7312 }
7313  
7314 sub Nasm::X86::Tree::by($&;$$) # Call the specified block with each (key, data) from the specified tree in order.
7315 0 ▶ {my ($t, $block, $bs, $first) = @_; # Tree descriptor, block to execute, arena address if not the one associated with the tree descriptor, first node offset if not the root of the tree provided
Subroutine by: not called CC=3 SCAR=24.8
7316 0 ▶ @_ == 2 or @_ == 4 or confess "2 or 4 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or @_ == 4 or confess("2 or 4 parameters") 0 0 0
Condition0%0/3
@_ == 2 or @_ == 4
l!l&&r!l&&!r
000
MC/DC0%0/2
@_ == 2 or @_ == 4
@_ == 2 @_ == 4
Truth table0%0/3
A or B
A= @_ == 2B= @_ == 4
ABresult
1X1
011
000
7317  
7318 0 my $iter = $t->iterator($bs, $first); # Create an iterator
7319 0 my $start = SetLabel Label; my $end = Label; # Start and end of loop
7320 0 ▶ If $iter->more == 0, sub {Jmp $end}; # Jump to end if there are no more elements to process
Subroutine __ANON__: not called CC=1 SCAR=6.9
7321 0 &$block($iter, $end); # Perform the block parameterized by the iterator and the end label
7322 0 $iter->next; # Next element
7323 0 Jmp $start; # Process next element
7324 0 SetLabel $end; # End of the loop
7325 }
7326  
7327 #D1 Quarks # Quarks allow us to replace unique strings with unique numbers. We can translate either from a string to its associated number or from a number to its associated string or from a quark in one set of quarks to the corresponding quark with the same string in another set of quarks.
7328  
7329 sub DescribeQuarks(%) # Return a descriptor for a set of quarks.
7330 0 ▶ {my (%options) = @_; # Options
Subroutine DescribeQuarks: not called CC=1 SCAR=6.9
Pod documented
7331  
7332 genHash(__PACKAGE__."::Quarks", # Quarks
7333 0 arena => DescribeArena($options{arena}), # The arena containing the quarks
7334 stringsToNumbers => undef, # A tree mapping strings to numbers
7335 numbersToStrings => undef, # Array mapping numbers to strings
7336 );
7337 }
7338  
7339 sub Nasm::X86::Arena::DescribeQuarks($) # Return a descriptor for a tree in the specified arena.
7340 0 ▶ {my ($arena) = @_; # Arena descriptor
Subroutine DescribeQuarks: not called CC=1 SCAR=6.9
7341 0 DescribeQuarks(arena=>$arena->bs)
7342 }
7343  
7344 sub Nasm::X86::Arena::CreateQuarks($) # Create quarks in a specified arena.
7345 0 ▶ {my ($arena) = @_; # Arena description optional arena address
Subroutine CreateQuarks: not called CC=2 SCAR=17.9
7346 0 ▶ @_ == 1 or confess "1 parameter";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess("1 parameter") 0 0 0
7347  
7348 0 my $q = $arena->DescribeQuarks; # Return a descriptor for a tree at the specified offset in the specified arena
7349 0 $q->stringsToNumbers = $arena->CreateTree;
7350 0 $q->numbersToStrings = $arena->CreateArray;
7351  
7352 0 $q # Description of array
7353 }
7354  
7355 sub Nasm::X86::Quarks::reload($%) # Reload the description of a set of quarks.
7356 0 ▶ {my ($q, %options) = @_; # Quarks, {arena=>arena to use; tree => first tree block; array => first array block}
Subroutine reload: not called CC=2 SCAR=17.9
7357 0 ▶ @_ >= 1 or confess "One or more parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 1 or confess("One or more parameters") 0 0 0
7358  
7359 0 $q->stringsToNumbers->reload(arena=>$options{arena}, first=>$options{tree});
7360 0 $q->numbersToStrings->reload(arena=>$options{arena}, first=>$options{array});
7361  
7362 0 $q # Return upgraded quarks descriptor
7363 }
7364  
7365 sub Nasm::X86::Quarks::quarkFromShortString($$) # Create a quark from a short string.
7366 0 ▶ {my ($q, $string) = @_; # Quarks, short string
Subroutine quarkFromShortString: not called CC=2 SCAR=17.9
7367 0 ▶ @_ == 2 or confess "2 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess("2 parameters") 0 0 0
7368  
7369 0 my $l = $string->len;
7370 0 my $Q = V(quark); # The variable that will hold the quark number
7371  
7372 AndBlock
7373 0 ▶ {my ($fail, $end, $start) = @_; # Fail block, end of fail block, start of test block
Subroutine __ANON__: not called CC=1 SCAR=6.9
7374  
7375 0 my $t = $q->stringsToNumbers->reload; # Reload strings to numbers
7376 0 $t->findAndReload($l); # Separate by length
7377 0 ▶ If $t->found == 0, Then {Jmp $fail}; # Length not found
Subroutine __ANON__: not called CC=1 SCAR=6.9
7378 0 $t->findShortString($string); # Find the specified short string
7379 0 ▶ If $t->found == 0, Then {Jmp $fail}; # Length not found
Subroutine __ANON__: not called CC=1 SCAR=6.9
7380 0 $Q->copy($t->data); # Load found quark number
7381 }
7382 Fail
7383 0 ▶ {my $N = $q->numbersToStrings->size; # Get the number of quarks
Subroutine __ANON__: not called CC=1 SCAR=6.9
7384 0 my $S = $q->arena->CreateString;
7385 0 $S->appendShortString($string);
7386 0 my $T = $q->stringsToNumbers->reload; # Reload strings to numbers tree descriptor
7387 0 $T->insertTreeAndReload($l); # Classify strings by length
7388 0 $T->insertShortString($string, $N); # Insert the string with the quark number as data
7389 0 $q->numbersToStrings->push(element => $S->first); # Append the quark number with a reference to the string
7390 0 $Q->copy($N);
7391 0 };
7392  
7393 0 $Q # Quark number for short string in a variable
7394 }
7395  
7396 sub Nasm::X86::Quarks::locateQuarkFromShortString($$) # Locate (if possible) but do not create a quark from a short string. A quark of -1 is returned if there is no matching quark otherwise the number of the matching quark is returned in a variable.
7397 0 ▶ {my ($q, $string) = @_; # Quarks, short string
Subroutine locateQuarkFromShortString: not called CC=2 SCAR=17.9
7398 0 ▶ @_ == 2 or confess "2 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess("2 parameters") 0 0 0
7399  
7400 0 my $l = $string->len;
7401 0 my $Q = V(quark); # The variable that will hold the quark number
7402  
7403 AndBlock
7404 0 ▶ {my ($fail, $end, $start) = @_; # Fail block, end of fail block, start of test block
Subroutine __ANON__: not called CC=1 SCAR=6.9
7405  
7406 0 my $t = $q->stringsToNumbers->reload; # Reload strings to numbers
7407 0 $t->findAndReload($l); # Separate by length
7408 0 ▶ If $t->found == 0, Then {Jmp $fail}; # Length not found
Subroutine __ANON__: not called CC=1 SCAR=6.9
7409 0 $t->findShortString($string); # Find the specified short string
7410 0 ▶ If $t->found == 0, Then {Jmp $fail}; # Length not found
Subroutine __ANON__: not called CC=1 SCAR=6.9
7411 0 $Q->copy($t->data); # Load found quark number
7412 }
7413 Fail
7414 0 ▶ {$Q->copy(-1);
Subroutine __ANON__: not called CC=1 SCAR=6.9
7415 0 };
7416  
7417 0 $Q # Quark number for short string in a variable
7418 }
7419  
7420 sub Nasm::X86::Quarks::shortStringFromQuark($$$) # Load a short string from the quark with the specified number. Returns a variable that is set to one if the quark was found else zero.
7421 0 ▶ {my ($q, $number, $string) = @_; # Quarks, variable quark number, short string to load
Subroutine shortStringFromQuark: not called CC=2 SCAR=17.9
7422 0 ▶ @_ == 3 or confess "3 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess("3 parameters") 0 0 0
7423  
7424 0 my $f = V(found); # Whether the quark was found
7425  
7426 AndBlock
7427 0 ▶ {my ($fail, $end, $start) = @_; # Fail block, end of fail block, start of test block
Subroutine __ANON__: not called CC=1 SCAR=6.9
7428 0 my $N = $q->numbersToStrings->size; # Get the number of quarks
7429 0 ▶ If $number >= $N, Then {Jmp $fail}; # Quark number too big to be valid
Subroutine __ANON__: not called CC=1 SCAR=6.9
7430 0 $q->numbersToStrings->get(index => $number, my $e = V(element)); # Get long string indexed by quark
7431  
7432 0 my $S = $q->numbersToStrings->bs->DescribeString(first=>$e); # Long string descriptor
7433 0 $S->saveToShortString($string); # Load long string into short string
7434 0 $f->copy(1); # Show short string is valid
7435 }
7436 Fail # Quark too big
7437 0 ▶ {$f->copy(0); # Show failure code
Subroutine __ANON__: not called CC=1 SCAR=6.9
7438 0 };
7439  
7440 0 $f
7441 }
7442  
7443 sub Nasm::X86::Quarks::quarkToQuark($$$) # Given a variable quark number in one set of quarks find the corresponding quark in another set of quarks and return it in a variable. No new quarks are created in this process. If the quark cannot be found in the first set we return -1, if it cannot be found in the second set we return -2 else the number of the matching quark.
7444 0 ▶ {my ($Q, $number, $q) = @_; # First set of quarks, variable quark number in first set, second set of quarks
Subroutine quarkToQuark: not called CC=4 SCAR=30.0
7445 0 ▶ @_ == 3 or confess "3 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess("3 parameters") 0 0 0
7446 0 ▶ ref($q) && ref($q) =~ m(Nasm::X86::Quarks) or
Branch: 1 branch
BranchTrueFalseTotal
ref $q and ref($q) =~ /Nasm::X86::Quarks/ or confess("Quarks required") 0 0 0
Condition0%0/3
ref $q and ref($q) =~ /Nasm::X86::Quarks/
!ll&&!rl&&r
000
MC/DC0%0/2
ref $q and ref($q) =~ /Nasm::X86::Quarks/
ref $q ref($q) =~ /Nasm::X86::Quarks/
Truth table0%0/3
A and B
A= ref $qB= ref($q) =~ /Nasm::X86::Quarks/
ABresult
0X0
100
111
7447 confess "Quarks required";
7448  
7449 0 my $N = V(found); # Whether the quark was found
7450  
7451 0 PushR zmm31;
7452  
7453 0 my $s = CreateShortString 0;
7454 If $Q->shortStringFromQuark($number, $s) == 0, # Quark not found in the first set
7455 Then
7456 0 ▶ {$N->copy(-1); # Not found in first set
Subroutine __ANON__: not called CC=1 SCAR=6.9
7457 },
7458 0 ▶ Ef {$q->locateQuarkFromShortString($s) >= 0} # Found the matching quark in the second set
Subroutine __ANON__: not called CC=1 SCAR=6.9
7459 Then
7460 0 ▶ {$N->copy($q->locateQuarkFromShortString($s)); # Load string from quark in second set
Subroutine __ANON__: not called CC=1 SCAR=6.9
7461 },
7462 Else
7463 0 ▶ {$N->copy(-2); # Not found in second set
Subroutine __ANON__: not called CC=1 SCAR=6.9
7464 0 };
7465  
7466 0 PopR;
7467  
7468 0 $N # Return the variable containing the matching quark or -1 if no such quark
7469 }
7470  
7471 sub Nasm::X86::Quarks::quarkFromSub($$;$) # Create a quark from a subroutine definition.
7472 0 ▶ {my ($q, $sub, $String) = @_; # Quarks, subroutine definition, optional overriding name as a short string
Subroutine quarkFromSub: not called CC=7 SCAR=40.3
7473 0 ▶ @_ == 2 or @_ == 3 or confess "2 or 3 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or @_ == 3 or confess("2 or 3 parameters") 0 0 0
Condition0%0/3
@_ == 2 or @_ == 3
l!l&&r!l&&!r
000
MC/DC0%0/2
@_ == 2 or @_ == 3
@_ == 2 @_ == 3
Truth table0%0/3
A or B
A= @_ == 2B= @_ == 3
ABresult
1X1
011
000
7474 0 ▶ ref($sub) && ref($sub) =~ m(Nasm::X86::Sub) or
Branch: 1 branch
BranchTrueFalseTotal
ref $sub and ref($sub) =~ /Nasm::X86::Sub/ or confess("Subroutine definition needed") 0 0 0
Condition0%0/3
ref $sub and ref($sub) =~ /Nasm::X86::Sub/
!ll&&!rl&&r
000
MC/DC0%0/2
ref $sub and ref($sub) =~ /Nasm::X86::Sub/
ref $sub ref($sub) =~ /Nasm::X86::Sub/
Truth table0%0/3
A and B
A= ref $subB= ref($sub) =~ /Nasm::X86::Sub/
ABresult
0X0
100
111
7475 confess "Subroutine definition needed";
7476  
7477 0 my $string = $String;
7478 0 ▶ if (!defined $String) # Create a short string from the subroutine name
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $String) 0 0 0
7479 0 {PushR zmm0;
7480 0 $string = CreateShortString(0); # Short string to hold the subroutine name
7481 0 my $name = K('address', Rs($sub->name));
7482 0 $string->load($name, K(size, length($sub->name))); # Load the short string with the subroutine name
7483 }
7484  
7485 0 my $N = $q->quarkFromShortString($string); # Create quark
7486 0 $q->numbersToStrings->put(index => $N, element => $sub->V); # Reuse the array component to point to the sub
7487 0 ▶ PopR if !defined $String; # Free short string if we created one
Branch: 1 branch
BranchTrueFalseTotal
unless defined $String 0 0 0
7488 0 $N # Quark number gives rapid access to the sub
7489 }
7490  
7491 sub Nasm::X86::Quarks::subFromQuark($$) # Get the offset of a subroutine as a variable from a set of quarks.
7492 0 ▶ {my ($q, $number) = @_; # Quarks, variable subroutine number
Subroutine subFromQuark: not called CC=2 SCAR=17.9
7493 0 ▶ @_ == 2 or confess "2 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess("2 parameters") 0 0 0
7494  
7495 0 my $s = V('sub'); # The offset of the subroutine or -1 if the subroutine cannot be found
7496  
7497 AndBlock
7498 0 ▶ {my ($fail, $end, $start) = @_; # Fail block, end of fail block, start of test block
Subroutine __ANON__: not called CC=1 SCAR=6.9
7499 0 my $N = $q->numbersToStrings->size; # Get the number of quarks
7500 0 ▶ If $number >= $N, Then {Jmp $fail}; # Quark number too big to be valid
Subroutine __ANON__: not called CC=1 SCAR=6.9
7501 0 $q->numbersToStrings->get(index => $number, my $e = V(element)); # Get subroutine indexed by quark
7502 0 $s->copy($e); # Subroutine address
7503 }
7504 Fail # Quark too big
7505 0 ▶ {$s->copy(-1); # Show failure
Subroutine __ANON__: not called CC=1 SCAR=6.9
7506 0 };
7507  
7508 0 $s # Return subroutine offset or -1
7509 }
7510  
7511 sub Nasm::X86::Quarks::call($$) # Call a subroutine via its quark number. Return one in a variable if the subroutine was found and called else zero.
7512 0 ▶ {my ($q, $number) = @_; # Quarks, variable subroutine number
Subroutine call: not called CC=2 SCAR=17.9
7513 0 ▶ @_ == 2 or confess "2 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess("2 parameters") 0 0 0
7514  
7515 0 my $s = V(found); # Whether the quark was found
7516  
7517 AndBlock
7518 0 ▶ {my ($fail, $end, $start) = @_; # Fail block, end of fail block, start of test block
Subroutine __ANON__: not called CC=1 SCAR=6.9
7519 0 my $N = $q->numbersToStrings->size; # Get the number of quarks
7520 0 ▶ If $number >= $N, Then {Jmp $fail}; # Quark number too big to be valid
Subroutine __ANON__: not called CC=1 SCAR=6.9
7521 0 $q->numbersToStrings->get(index => $number, my $e = V(element)); # Get subroutine indexed by quark
7522  
7523 0 PushR r15;
7524 0 $e->setReg(r15); # Offset to subroutine
7525 0 Call r15; # Call sub routine
7526 0 PopR r15;
7527 0 $s->copy(1); # Show subroutine was found and called
7528 }
7529 Fail # Quark too big
7530 0 ▶ {$s->copy(0); # Show failure
Subroutine __ANON__: not called CC=1 SCAR=6.9
7531 0 };
7532  
7533 0 $s # Return subroutine offset or -1
7534 }
7535  
7536 sub Nasm::X86::Quarks::dumpSubs($) # Dump a set of quarks identifying subroutines.
7537 0 ▶ {my ($q) = @_; # Quarks
Subroutine dumpSubs: not called CC=2 SCAR=17.9
7538 0 ▶ @_ == 1 or confess "1 parameter";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess("1 parameter") 0 0 0
7539  
7540 0 my $l = $q->numbersToStrings->size; # Number of subs
7541  
7542 $l->for(sub
7543 0 ▶ {my ($index, $start, $next, $end) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
7544 0 $q->numbersToStrings->get(index => $index, my $e = V(element)); # Get long string indexed by quark
7545 0 $index->out("Quark : "); $e->outNL(" = ");
7546 0 });
7547 }
7548  
7549 #D1 Assemble # Assemble generated code
7550  
7551 sub CallC($@) # Call a C subroutine.
7552 0 ▶ {my ($sub, @parameters) = @_; # Name of the sub to call, parameters
Subroutine CallC: not called CC=3 SCAR=24.8
Pod documented
7553 0 my @order = (rdi, rsi, rdx, rcx, r8, r9, r15);
7554 0 PushR @order;
7555  
7556 0 for my $i(keys @parameters) # Load parameters into designated registers
7557 0 {Mov $order[$i], $parameters[$i];
7558 }
7559  
7560 0 Push rax; # Align stack on 16 bytes
7561 0 Mov rax, rsp; # Move stack pointer
7562 0 Shl rax, 60; # Get lowest nibble
7563 0 Shr rax, 60;
7564 IfEq # If we are 16 byte aligned push two twos
7565 Then
7566 0 ▶ {Mov rax, 2; Push rax; Push rax;
Subroutine __ANON__: not called CC=1 SCAR=6.9
7567 },
7568 Else # If we are not 16 byte aligned push one one.
7569 0 ▶ {Mov rax, 1; Push rax;
Subroutine __ANON__: not called CC=1 SCAR=6.9
7570 0 };
7571  
7572 0 ▶ if (ref($sub)) # Where do we use this option?
Branch: 1 branch
BranchTrueFalseTotal
if (ref $sub) { } 0 0 0
7573 0 {Call $sub->start;
7574 }
7575 else # Call named subroutine
7576 0 {Call $sub;
7577 }
7578  
7579 0 Pop r15; # Decode and reset stack after 16 byte alignment
7580 0 Cmp r15, 2; # Check for double push
7581 0 Pop r15; # Single or double push
7582 0 ▶ IfEq Then {Pop r15}; # Double push
Subroutine __ANON__: not called CC=1 SCAR=6.9
7583 0 PopR @order;
7584 }
7585  
7586 sub Extern(@) # Name external references.
7587 0 ▶ {my (@externalReferences) = @_; # External references
Subroutine Extern: not called CC=1 SCAR=6.9
Pod documented
7588 0 push @extern, @_;
7589 }
7590  
7591 sub Link(@) # Libraries to link with.
7592 0 ▶ {my (@libraries) = @_; # External references
Subroutine Link: not called CC=1 SCAR=6.9
Pod documented
7593 0 push @link, @_;
7594 }
7595  
7596 sub Start() # Initialize the assembler.
7597 0 ▶ {@bss = @data = @rodata = %rodata = %rodatas = %subroutines = @text =
Subroutine Start: not called CC=1 SCAR=6.9
Pod documented
7598 @PushR = @PushZmm = @PushMask = @extern = @link = @VariableStack = ();
7599 0 @RegistersAvailable = ({map {$_=>1} @GeneralPurposeRegisters}); # A stack of hashes of registers that are currently free and this can be used without pushing and popping them.
7600 0 SubroutineStartStack; # Number of variables at each lexical level
7601 0 $Labels = 0;
7602 }
7603  
7604 sub Exit(;$) # Exit with the specified return code or zero if no return code supplied. Assemble() automatically adds a call to Exit(0) if the last operation in the program is not a call to Exit.
7605 0 ▶ {my ($c) = @_; # Return code
Subroutine Exit: not called CC=2 SCAR=17.9
Pod documented
7606 0 ▶ $c //= 0;
Condition0%0/2
$c //= 0
l!l
00
MC/DC0%0/1
$c //= 0
$c
Truth table0%0/2
A
A= $c
Aresult
11
00
7607 my $s = Subroutine
7608 0 ▶ {Comment "Exit code: $c";
Subroutine __ANON__: not called CC=1 SCAR=6.9
7609 0 PushR (rax, rdi);
7610 0 Mov rdi, $c;
7611 0 Mov rax, 60;
7612 0 Syscall;
7613 0 PopR;
7614 0 } [], name => "Exit_$c";
7615  
7616 0 $s->call;
7617 }
7618  
7619 1 my $LocateIntelEmulator; # Location of Intel Software Development Emulator
7620  
7621 sub LocateIntelEmulator() #P Locate the Intel Software Development Emulator.
7622 0 ▶ {my @locations = qw(/var/isde/sde64 sde/sde64 ./sde64); # Locations at which we might find the emulator
Subroutine LocateIntelEmulator: not called CC=8 SCAR=42.8
Pod documented
7623 0 my $downloads = q(/home/phil/Downloads); # Downloads folder
7624  
7625 0 ▶ return $LocateIntelEmulator if defined $LocateIntelEmulator; # Location has already been discovered
Branch: 1 branch
BranchTrueFalseTotal
if defined $LocateIntelEmulator 0 0 0
7626  
7627 0 for my $l(@locations) # Try each locations
7628 0 ▶ {return $LocateIntelEmulator = $l if -e $l; # Found it - cache and return
Branch: 1 branch
BranchTrueFalseTotal
if -e $l 0 0 0
7629 }
7630  
7631 0 ▶ if (qx(sde64 -version) =~ m(Intel.R. Software Development Emulator)) # Try path
Branch: 1 branch
BranchTrueFalseTotal
if (`sde64 -version` =~ /Intel.R. Software Development Emulator/) 0 0 0
7632 0 {return $LocateIntelEmulator = "sde64";
7633 }
7634  
7635 0 ▶ return undef unless -e $downloads; # Skip local install if not developing
Branch: 1 branch
BranchTrueFalseTotal
unless -e $downloads 0 0 0
7636 0 my $install = <<END =~ s(\n) ( && )gsr =~ s(&&\s*\Z) ()sr; # Install sde
7637 cd $downloads
7638 curl https://software.intel.com/content/dam/develop/external/us/en/documents/downloads/sde-external-8.63.0-2021-01-18-lin.tar.bz2 > sde.tar.bz2
7639 tar -xf sde.tar.bz2
7640 sudo mkdir -p /var/isde/
7641 sudo cp -r * /var/isde/
7642 ls -ls /var/isde/
7643 END
7644  
7645 0 say STDERR qx($install); # Execute install
7646  
7647 0 for my $l(@locations) # Retry install locations after install
7648 0 ▶ {return $LocateIntelEmulator = $l if -e $l; # Found it - cache and return
Branch: 1 branch
BranchTrueFalseTotal
if -e $l 0 0 0
7649 }
7650 undef # Still not found - give up
7651 0 }
7652  
7653 sub getInstructionCount() #P Get the number of instructions executed from the emulator mix file.
7654 0 ▶ {return 0 unless -e $sdeMixOut;
Subroutine getInstructionCount: not called CC=3 SCAR=24.8
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless -e $sdeMixOut 0 0 0
7655 0 my $s = readFile $sdeMixOut;
7656 0 ▶ if ($s =~ m(\*total\s*(\d+))) {return $1}
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /\*total\s*(\d+)/) 0 0 0
7657 0 confess;
7658 }
7659  
7660 sub Optimize(%) #P Perform code optimizations.
7661 0 ▶ {my (%options) = @_; # Options
Subroutine Optimize: not called CC=7 SCAR=40.3
Pod documented
7662 0 my %o = map {$_=>1} $options{optimize}->@*;
7663 0 if (1 or $o{if}) # Optimize if statements by looking for the unnecessary reload of the just stored result
7664 0 {for my $i(1..@text-2) # Each line
7665 0 {my $t = $text[$i];
7666 0 ▶ if ($t =~ m(\A\s+push\s+(r\d+)\s*\Z)i) # Push
Branch: 1 branch
BranchTrueFalseTotal
if ($t =~ /\A\s+push\s+(r\d+)\s*\Z/i) 0 0 0
7667 0 {my $R = $1; # Register being pushed
7668 0 my $s = $text[$i-1]; # Previous line
7669 0 ▶ if ($s =~ m(\A\s+pop\s+$R\s*\Z)i) # Matching push
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /\A\s+pop\s+$R\s*\Z/i) 0 0 0
7670 0 {my $r = $text[$i-2];
7671 0 ▶ if ($r =~ m(\A\s+mov\s+\[rbp-8\*\((\d+)\)],\s*$R\s*\Z)i) # Save to variable
Branch: 1 branch
BranchTrueFalseTotal
if ($r =~ /\A\s+mov\s+\[rbp-8\*\((\d+)\)],\s*$R\s*\Z/i) 0 0 0
7672 0 {my $n = $1; # Variable number
7673 0 my $u = $text[$i+1];
7674 0 ▶ if ($u =~ m(\A\s+mov\s+$R,\s*\[rbp-8\*\($n\)]\s*\Z)i) # Reload register
Branch: 1 branch
BranchTrueFalseTotal
if ($u =~ /\A\s+mov\s+$R,\s*\[rbp-8\*\($n\)]\s*\Z/i) 0 0 0
7675 0 {for my $j($i-1..$i+1)
7676 0 {$text[$j] = '; out '. $text[$j];
7677 }
7678 }
7679 }
7680 }
7681 }
7682 }
7683 }
7684 }
7685  
7686 1 our $assembliesPerformed = 0; # Number of assemblies performed
7687 1 our $instructionsExecuted = 0; # Total number of instructions executed
7688 1 our $totalBytesAssembled = 0; # Total size of the output programs
7689  
7690 sub Assemble(%) # Assemble the generated code.
7691 0 ▶ {my (%options) = @_; # Options
Subroutine Assemble: not called CC=47 SCAR=77.2
Pod documented
7692 0 ▶ Exit 0 unless @text > 4 and $text[-4] =~ m(Exit code:); # Exit with code 0 if an exit was not the last thing coded.
Branch: 1 branch
BranchTrueFalseTotal
unless @text > 4 and $text[-4] =~ /Exit code:/ 0 0 0
Condition0%0/3
@text > 4 and $text[-4] =~ /Exit code:/
!ll&&!rl&&r
000
MC/DC0%0/2
@text > 4 and $text[-4] =~ /Exit code:/
@text > 4 $text[-4] =~ /Exit code:/
Truth table0%0/3
A and B
A= @text > 4B= $text[-4] =~ /Exit code:/
ABresult
0X0
100
111
7693 0 ▶ my $debug = $options{debug}//0; # Debug: 0 - none (minimal output), 1 - normal (debug output and confess of failure), 2 - failures (debug output and no confess on failure) .
Condition0%0/2
$options{"debug"} // 0
l!l
00
MC/DC0%0/1
$options{"debug"} // 0
$options{"debug"}
Truth table0%0/2
A
A= $options{"debug"}
Aresult
11
00
7694 0 ▶ my $debugTrace = $options{trace}//0; # Trace: 0 - none (minimal output), 1 - trace with sde64
Condition0%0/2
$options{"trace"} // 0
l!l
00
MC/DC0%0/1
$options{"trace"} // 0
$options{"trace"}
Truth table0%0/2
A
A= $options{"trace"}
Aresult
11
00
7695  
7696 # Optimize(%options); # Perform any optimizations requested
7697  
7698 0 my $k = $options{keep}; # Keep the executable
7699 0 my $r = join "\n", map {s/\s+\Z//sr} @rodata;
7700 0 my $d = join "\n", map {s/\s+\Z//sr} @data;
7701 0 my $B = join "\n", map {s/\s+\Z//sr} @bss;
7702 0 my $t = join "\n", map {s/\s+\Z//sr} @text;
7703 0 my $x = join "\n", map {qq(extern $_)} @extern;
7704 0 my $L = join " ", map {qq(-l$_)} @link;
7705 0 my $N = $VariableStack[0]; # Number of variables needed on the stack
7706  
7707 0 my $A = <<END;
7708 section .rodata
7709 $r
7710 section .data
7711 $d
7712 section .bss
7713 $B
7714 section .text
7715 $x
7716 global _start, main
7717 _start:
7718 main:
7719 Enter $N*8, 0
7720 $t
7721 Leave
7722 END
7723  
7724 0 my $c = owf(q(z.asm), $A); # Source file
7725 0 ▶ my $e = $k // q(z); # Executable file
Condition0%0/2
$k // "z"
l!l
00
MC/DC0%0/1
$k // "z"
$k
Truth table0%0/2
A
A= $k
Aresult
11
00
7726 0 my $l = q(z.txt); # Assembler listing
7727 0 my $o = q(z.o); # Object file
7728  
7729 0 ▶ if (!confirmHasCommandLineCommand(q(nasm))) # Check for network assembler
Branch: 1 branch
BranchTrueFalseTotal
unless (&confirmHasCommandLineCommand("nasm")) 0 0 0
7730 0 {my $L = fpf(currentDirectory, $l);
7731 0 say STDERR <<END;
7732 Assember code written to the following file:
7733  
7734 $L
7735  
7736 I cannot compile this file because you do not have Nasm installed, see:
7737  
7738 https://www.nasm.us/
7739 END
7740 0 return;
7741 }
7742  
7743 0 ▶ my $emulator = exists $options{emulator} ? $options{emulator} : 1; # Emulate by default unless told otherwise
Branch: 1 branch
BranchTrueFalseTotal
exists $options{'emulator'} ? : 0 0 0
7744 0 my $sde = LocateIntelEmulator; # Locate the emulator
7745  
7746 0 ▶ if (!$k and $emulator and !$sde) # Complain about the emulator if we are going to run and we have not suppressed the emulator and the emulator is not present
Branch: 1 branch
BranchTrueFalseTotal
if (not $k and $emulator and not $sde) 0 0 0
Condition0%0/6
not $k and $emulator and not $sde
!ll&&!rl&&r
000
not $k and $emulator
!ll&&!rl&&r
000
MC/DC0%0/3
not $k and $emulator and not $sde
not $k $emulator not $sde
Truth table0%0/4
not(A) and B and not(C)
A= not $kB= $emulatorC= not $sde
ABCresult
0XX0
10X0
1100
1111
7747 0 {my $E = fpf(currentDirectory, $e);
7748 0 say STDERR <<END;
7749 Executable written to the following file:
7750  
7751 $E
7752  
7753 I am going to run this without using the Intel emulator. Your program will
7754 crash if it contains instructions not implemented on your computer.
7755  
7756 You can get the Intel emulator from:
7757  
7758 https://software.intel.com/content/dam/develop/external/us/en/documents/downloads/sde-external-8.63.0-2021-01-18-lin.tar.bz2
7759  
7760 To avoid this message, use option(1) below to produce just an executable
7761 without running it, or use the option(2) to run without the emulator:
7762  
7763 (1) Assemble(keep=>"executable file name")
7764  
7765 (2) Assemble(emulator=>0)
7766 END
7767 0 $emulator = 0;
7768 }
7769  
7770 0 ▶ if (my @emulatorFiles = searchDirectoryTreesForMatchingFiles(qw(. .txt))) # Remove prior emulator output files
Branch: 1 branch
BranchTrueFalseTotal
if (my(@emulatorFiles) = &searchDirectoryTreesForMatchingFiles((".", ".txt"))) 0 0 0
7771 0 {for my $f(@emulatorFiles)
7772 0 ▶ {unlink $f if $f =~ m(sde-mix-out);
Branch: 1 branch
BranchTrueFalseTotal
if $f =~ /sde-mix-out/ 0 0 0
7773 }
7774 }
7775 0 unlink qw(sde-ptr-check.out.txt sde-mix-out.txt sde-debugtrace-out.txt);
7776  
7777 0 ▶ my $I = @link ? $interpreter : ''; # Interpreter only required if calling C
Branch: 1 branch
BranchTrueFalseTotal
@link ? : 0 0 0
7778 0 my $cmd = trim(<<END);
7779 nasm -f elf64 -g -l $l -o $o $c && ld $I $L -o $e $o && chmod 744 $e
7780 END
7781 0 my $o1 = 'zzzOut.txt';
7782 0 my $o2 = 'zzzErr.txt';
7783 0 unlink $o1, $o2; # Remove output files
7784 0 ▶ my $out = $k ? '' : "1>$o1";
Branch: 1 branch
BranchTrueFalseTotal
$k ? : 0 0 0
7785 0 ▶ my $err = $k ? '' : "2>$o2";
Branch: 1 branch
BranchTrueFalseTotal
$k ? : 0 0 0
7786 0 my $opt = qq($sde -mix -ptr-check); # Emulator options
7787 0 ▶ $opt = qq($sde -mix -ptr-check -debugtrace -footprint) if $debugTrace; # Emulator options
Branch: 1 branch
BranchTrueFalseTotal
if $debugTrace 0 0 0
7788 0 ▶ my $exec = $emulator ? qq($opt -- ./$e $err $out) : qq(./$e $err $out); # Execute with or without the emulator
Branch: 1 branch
BranchTrueFalseTotal
$emulator ? : 0 0 0
7789  
7790 0 ▶ $cmd .= qq( && $exec) unless $k; # Execute automatically unless suppressed by user
Branch: 1 branch
BranchTrueFalseTotal
unless $k 0 0 0
7791  
7792 0 qx($cmd); # Assemble and perhaps run
7793  
7794 0 if (1) # Execution details
7795 0 {my $instructions = getInstructionCount; # Instructions executed under emulator
7796 0 $instructionsExecuted += $instructions; # Count instructions executed
7797 0 my $p = $assembliesPerformed++; # Count assemblies
7798 0 my $n = $options{number};
7799 0 ▶ !$n or $n == $p or warn "Assembly $p versus number => $n";
Branch: 1 branch
BranchTrueFalseTotal
not $n or $n == $p or warn "Assembly $p versus number => $n" 0 0 0
Condition0%0/3
not $n or $n == $p
l!l&&r!l&&!r
000
MC/DC0%0/2
not $n or $n == $p
not $n $n == $p
Truth table0%0/3
not(A) or B
A= not $nB= $n == $p
ABresult
1X1
011
000
7800  
7801 0 my $bytes = fileSize($e) - 9512 + 64; # Estimate the size of the output program
7802 0 $totalBytesAssembled += $bytes; # Estimate total of all programs assembled
7803  
7804 0 my (undef, $file, $line) = caller(); # Line in caller
7805  
7806 0 ▶ say STDERR sprintf(" %-12s %-12s %-12s %-12s", # Header if necessary
Branch: 1 branch
BranchTrueFalseTotal
if $Nasm::X86::assembliesPerformed % 100 == 1 0 0 0
7807 "Clocks", "Bytes", "Total Clocks", "Total Bytes")
7808 if $assembliesPerformed % 100 == 1;
7809  
7810 say STDERR # Rows
7811 sprintf("%4d %12s %12s %12s %12s at $file line $line",
7812 $assembliesPerformed,
7813 0 map {numberWithCommas $_} $instructions, $bytes,
7814 $instructionsExecuted, $totalBytesAssembled);
7815 }
7816  
7817 0 ▶ if (!$k and $debug == 0) # Print errors if not debugging
Branch: 1 branch
BranchTrueFalseTotal
if (not $k and $debug == 0) 0 0 0
Condition0%0/3
not $k and $debug == 0
!ll&&!rl&&r
000
MC/DC0%0/2
not $k and $debug == 0
not $k $debug == 0
Truth table0%0/3
not(A) and B
A= not $kB= $debug == 0
ABresult
0X0
100
111
7818 0 {say STDERR readBinaryFile($o2);
7819 }
7820  
7821 0 ▶ if (!$k and $debug == 1) # Print files if soft debugging
Branch: 1 branch
BranchTrueFalseTotal
if (not $k and $debug == 1) 0 0 0
Condition0%0/3
not $k and $debug == 1
!ll&&!rl&&r
000
MC/DC0%0/2
not $k and $debug == 1
not $k $debug == 1
Truth table0%0/3
not(A) and B
A= not $kB= $debug == 1
ABresult
0X0
100
111
7822 0 {say STDERR readFile($o1) =~ s(0) ( )gsr;
7823 0 say STDERR readFile($o2);
7824 }
7825  
7826 0 ▶ confess "Failed $?" if $debug < 2 and $?; # Check that the assembly succeeded
Branch: 1 branch
BranchTrueFalseTotal
if $debug < 2 and $? 0 0 0
Condition0%0/3
$debug < 2 and $?
!ll&&!rl&&r
000
MC/DC0%0/2
$debug < 2 and $?
$debug < 2 $?
Truth table0%0/3
A and B
A= $debug < 2B= $?
ABresult
0X0
100
111
7827  
7828 0 ▶ if (!$k and $debug < 2 and -e $o2 and readFile($o2) =~ m(SDE ERROR:)s) # Emulator detected an error
Branch: 1 branch
BranchTrueFalseTotal
if (not $k and $debug < 2 and -e $o2 and &readFile($o2) =~ /SDE ERROR:/s) 0 0 0
Condition0%0/9
not $k and $debug < 2 and -e $o2 and &readFile($o2) =~ /SDE ERROR:/s
!ll&&!rl&&r
000
not $k and $debug < 2 and -e $o2
!ll&&!rl&&r
000
not $k and $debug < 2
!ll&&!rl&&r
000
MC/DC0%0/4
not $k and $debug < 2 and -e $o2 and &readFile($o2) =~ /SDE ERROR:/s
not $k $debug < 2 -e $o2 &readFile($o2) =~ /SDE ERROR:/s
Truth table0%0/5
not(A) and B and C and D
A= not $kB= $debug < 2C= -e $o2D= &readFile($o2) =~ /SDE ERROR:/s
ABCDresult
0XXX0
10XX0
110X0
11100
11111
7829 0 {confess "SDE ERROR\n".readFile($o2);
7830 }
7831  
7832 0 unlink $o; # Delete files
7833 0 ▶ unlink $e unless $k; # Delete executable unless asked to keep it
Branch: 1 branch
BranchTrueFalseTotal
unless $k 0 0 0
7834  
7835 0 ▶ if (my $N = $options{countComments}) # Count the comments so we can see what code to put into subroutines
Branch: 1 branch
BranchTrueFalseTotal
if (my $N = $options{"countComments"}) 0 0 0
7836 0 {my %c; my %b; # The number of lines between the comments, the number of blocks
7837 0 my $s;
7838 0 for my $c(split /\n/, $A)
7839 0 ▶ {if (!$s)
Branch: 2 branches
BranchTrueFalseTotal
if (not $s) { } 0 0 0
elsif ($c eq $s) { } 0 0 0
7840 0 ▶ {if ($c =~ m(;\s+CommentWithTraceBack\s+PushR))
Branch: 1 branch
BranchTrueFalseTotal
if ($c =~ /;\s+CommentWithTraceBack\s+PushR/) 0 0 0
7841 0 {$s = $c =~ s(Push) (Pop)r;
7842 0 $b{$s}++;
7843 }
7844 }
7845 0 elsif ($c eq $s) {$s = undef}
7846 0 else {$c{$s}++}
7847 }
7848  
7849 0 my @c;
7850 0 for my $c(keys %c) # Remove comments that do not appear often
7851 0 ▶ {push @c, [$c{$c}, $b{$c}, $c] if $c{$c} >= $N;
Branch: 1 branch
BranchTrueFalseTotal
if $c{$c} >= $N 0 0 0
7852 }
7853 0 my @d = sort {$$b[0] <=> $$a[0]} @c;
7854 0 say STDERR formatTable(\@d, [qw(Lines Blocks Comment)]); # Print frequently appearing comments
7855 }
7856  
7857 0 Start; # Clear work areas for next assembly
7858 0 ▶ return $exec if $k; # Executable wanted
Branch: 1 branch
BranchTrueFalseTotal
if $k 0 0 0
7859  
7860 0 ▶ if (defined(my $e = $options{eq})) # Diff against expected
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $e = $options{"eq"})) 0 0 0
7861 0 ▶ {my $g = readFile($debug < 2 ? $o1 : $o2);
Branch: 1 branch
BranchTrueFalseTotal
$debug < 2 ? : 0 0 0
7862 0 $e =~ s(\s+#.*?\n) (\n)gs; # Remove comments so we can annotate listings
7863 0 ▶ if ($g ne $e)
Branch: 1 branch
BranchTrueFalseTotal
if ($g ne $e) 0 0 0
7864 0 {my ($s, $G, $E) = stringsAreNotEqual($g, $e);
7865 0 ▶ if (length($s))
Branch: 1 branch
BranchTrueFalseTotal
if (length $s) 0 0 0
7866 0 {my $line = 1 + length($s =~ s([^\n]) ()gsr);
7867 0 my $char = 1 + length($s =~ s(\A.*\n) ()sr);
7868 0 say STDERR "Comparing wanted with got failed at line: $line, character: $char";
7869 0 say STDERR "Start:\n$s";
7870 }
7871 0 my $b1 = '+' x 80;
7872 0 my $b2 = '_' x 80;
7873 0 say STDERR "Want $b1\n", firstNChars($E, 80);
7874 0 say STDERR "Got $b2\n", firstNChars($G, 80);
7875 0 say STDERR "Want: ", dump($e);
7876 0 say STDERR "Got : ", dump($g);
7877 0 confess "Test failed"; # Test failed unless we are debugging test failures
7878 }
7879 0 return 1; # Test passed
7880 }
7881  
7882 0 ▶ scalar(readFile($debug < 2 ? $o1 : $o2)); # Show stdout results unless stderr results requested
Branch: 1 branch
BranchTrueFalseTotal
$debug < 2 ? : 0 0 0
7883 }
7884  
7885 sub removeNonAsciiChars($) #P Return a copy of the specified string with all the non ascii characters removed.
7886 0 ▶ {my ($string) = @_; # String
Subroutine removeNonAsciiChars: not called CC=1 SCAR=6.9
Pod documented
7887 0 $string =~ s([^a-z0..9]) ()igsr; # Remove non ascii characters
7888 }
7889  
7890 sub totalBytesAssembled #P Total size in bytes of all files assembled during testing.
7891 0 ▶ {$totalBytesAssembled
Subroutine totalBytesAssembled: not called CC=1 SCAR=6.9
Pod documented
7892 }
7893  
7894 #d
7895 #-------------------------------------------------------------------------------
7896 # Export - eeee
7897 #-------------------------------------------------------------------------------
7898  
7899 1 if (0) # Print exports
7900 {my @e;
7901 for my $a(sort keys %Nasm::X86::)
7902 {next if $a =~ m(BAIL_OUT|BEGIN|DATA|confirmHasCommandLineCommand|currentDirectory|fff|fileMd5Sum|fileSize|findFiles|firstNChars|formatTable|fpe|fpf|genHash|lll|owf|pad|readFile|stringsAreNotEqual|stringMd5Sum|temporaryFile);
7903 next if $a =~ m(\AEXPORT);
7904 next if $a !~ m(\A[A-Z]) and !$Registers{$a};
7905 next if $a =~ m(::\Z);
7906 push @e, $a if $Nasm::X86::{$a} =~ m(\*Nasm::X86::);
7907 }
7908 say STDERR q/@EXPORT_OK = qw(/.join(' ', @e).q/);/;
7909 exit;
7910 }
7911  
7912 1 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
7913  
7914 1 ▶use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
Subroutine BEGIN: called CC=1 SCAR=0.0
7915  
7916 1 @ISA = qw(Exporter);
7917 1 @EXPORT = qw();
7918 1 @EXPORT_OK = qw(Add All8Structure AllocateAll8OnStack AllocateMemory And AndBlock Andn Assemble Bswap Bt Btc Btr Bts Bzhi Call CallC CheckGeneralPurposeRegister CheckMaskRegister CheckNumberedGeneralPurposeRegister ChooseRegisters ClassifyInRange ClassifyRange ClassifyWithInRange ClassifyWithInRangeAndSaveOffset ClearMemory ClearRegisters ClearZF CloseFile Cmova Cmovae Cmovb Cmovbe Cmovc Cmove Cmovg Cmovge Cmovl Cmovle Cmovna Cmovnae Cmovnb Cmp Comment CommentWithTraceBack ConvertUtf8ToUtf32 CopyMemory Cpuid CreateArena CreateShortString Cstrlen DComment Db Dbwdq Dd Dec DescribeArena Dq Ds Dw Ef Else Enter Exit Extern Fail For ForEver ForIn Fork FreeMemory G GetNextUtf8CharAsUtf32 GetPPid GetPid GetPidInHex GetUid Hash ISA Idiv If IfC IfEq IfGe IfGt IfLe IfLt IfNc IfNe IfNz IfZ Imul Inc InsertOneIntoRegisterAtPoint InsertZeroIntoRegisterAtPoint Ja Jae Jb Jbe Jc Jcxz Je Jecxz Jg Jge Jl Jle Jmp Jna Jnae Jnb Jnbe Jnc Jne Jng Jnge Jnl Jnle Jno Jnp Jns Jnz Jo Jp Jpe Jpo Jrcxz Js Jz K Kaddb Kaddd Kaddq Kaddw Kandb Kandd Kandnb Kandnd Kandnq Kandnw Kandq Kandw Kmovb Kmovd Kmovq Kmovw Knotb Knotd Knotq Knotw Korb Kord Korq Kortestb Kortestd Kortestq Kortestw Korw Kshiftlb Kshiftld Kshiftlq Kshiftlw Kshiftrb Kshiftrd Kshiftrq Kshiftrw Ktestb Ktestd Ktestq Ktestw Kunpckb Kunpckd Kunpckq Kunpckw Kxnorb Kxnord Kxnorq Kxnorw Kxorb Kxord Kxorq Kxorw Label Lahf Lea Leave Link LoadBitsIntoMaskRegister LoadConstantIntoMaskRegister LoadRegFromMm LoadZmm LocalData LocateIntelEmulator Loop Lzcnt Macro MaskMemory22 MaskMemoryInRange4_22 Mov Movdqa Mulpd Neg Not OnSegv OpenRead OpenWrite Optimize Or OrBlock Pass PeekR Pextrb Pextrd Pextrq Pextrw Pi32 Pi64 Pinsrb Pinsrd Pinsrq Pinsrw Pop PopEax PopMask PopR PopRR PopZmm Popcnt Popfq PrintErrMemory PrintErrMemoryInHex PrintErrMemoryInHexNL PrintErrMemoryNL PrintErrNL PrintErrRaxInHex PrintErrRegisterInHex PrintErrSpace PrintErrString PrintErrStringNL PrintErrTraceBack PrintErrUtf32 PrintErrUtf8Char PrintErrZF PrintMemory PrintMemoryInHex PrintMemoryNL PrintNL PrintOneRegisterInHex PrintOutMemory PrintOutMemoryInHex PrintOutMemoryInHexNL PrintOutMemoryNL PrintOutNL PrintOutRaxInHex PrintOutRaxInReverseInHex PrintOutRegisterInHex PrintOutRegistersInHex PrintOutRflagsInHex PrintOutRipInHex PrintOutSpace PrintOutString PrintOutStringNL PrintOutTraceBack PrintOutUtf32 PrintOutUtf8Char PrintOutZF PrintRaxInHex PrintRegisterInHex PrintSpace PrintString PrintStringNL PrintTraceBack PrintUtf32 PrintUtf8Char Pslldq Psrldq Push PushMask PushR PushRR PushZmm Pushfq R RComment Rb Rbwdq Rd Rdtsc ReadFile ReadTimeStampCounter RegisterSize RegistersAvailable RegistersFree ReorderSyscallRegisters RestoreFirstFour RestoreFirstFourExceptRax RestoreFirstFourExceptRaxAndRdi RestoreFirstSeven RestoreFirstSevenExceptRax RestoreFirstSevenExceptRaxAndRdi Ret Rq Rs Rutf8 Rw SaveFirstFour SaveFirstSeven SaveRegIntoMm SetLabel SetMaskRegister SetZF Seta Setae Setb Setbe Setc Sete Setg Setge Setl Setle Setna Setnae Setnb Setnbe Setnc Setne Setng Setnge Setnl Setno Setnp Setns Setnz Seto Setp Setpe Setpo Sets Setz Shl Shr Start StatSize StringLength Structure Sub Subroutine SubroutineStartStack Syscall Test Then Tzcnt UnReorderSyscallRegisters V VERSION Vaddd Vaddpd Variable Vcvtudq2pd Vcvtudq2ps Vcvtuqq2pd Vdpps Vgetmantps Vmovd Vmovdqa32 Vmovdqa64 Vmovdqu Vmovdqu32 Vmovdqu64 Vmovdqu8 Vmovq Vmulpd Vpandb Vpandd Vpandnb Vpandnd Vpandnq Vpandnw Vpandq Vpandw Vpbroadcastb Vpbroadcastd Vpbroadcastq Vpbroadcastw Vpcmpeqb Vpcmpeqd Vpcmpeqq Vpcmpeqw Vpcmpub Vpcmpud Vpcmpuq Vpcmpuw Vpcompressd Vpcompressq Vpexpandd Vpexpandq Vpextrb Vpextrd Vpextrq Vpextrw Vpinsrb Vpinsrd Vpinsrq Vpinsrw Vpmullb Vpmulld Vpmullq Vpmullw Vporb Vpord Vporq Vporvpcmpeqb Vporvpcmpeqd Vporvpcmpeqq Vporvpcmpeqw Vporw Vprolq Vpsubb Vpsubd Vpsubq Vpsubw Vptestb Vptestd Vptestq Vptestw Vpxorb Vpxord Vpxorq Vpxorw Vsqrtpd WaitPid Xchg Xor ah al ax bh bl bp bpl bx ch cl cs cx dh di dil dl ds dx eax ebp ebx ecx edi edx es esi esp fs gs k0 k1 k2 k3 k4 k5 k6 k7 mm0 mm1 mm2 mm3 mm4 mm5 mm6 mm7 r10 r10b r10d r10l r10w r11 r11b r11d r11l r11w r12 r12b r12d r12l r12w r13 r13b r13d r13l r13w r14 r14b r14d r14l r14w r15 r15b r15d r15l r15w r8 r8b r8d r8l r8w r9 r9b r9d r9l r9w rax rbp rbx rcx rdi rdx rflags rip rsi rsp si sil sp spl ss st0 st1 st2 st3 st4 st5 st6 st7 xmm0 xmm1 xmm10 xmm11 xmm12 xmm13 xmm14 xmm15 xmm16 xmm17 xmm18 xmm19 xmm2 xmm20 xmm21 xmm22 xmm23 xmm24 xmm25 xmm26 xmm27 xmm28 xmm29 xmm3 xmm30 xmm31 xmm4 xmm5 xmm6 xmm7 xmm8 xmm9 ymm0 ymm1 ymm10 ymm11 ymm12 ymm13 ymm14 ymm15 ymm16 ymm17 ymm18 ymm19 ymm2 ymm20 ymm21 ymm22 ymm23 ymm24 ymm25 ymm26 ymm27 ymm28 ymm29 ymm3 ymm30 ymm31 ymm4 ymm5 ymm6 ymm7 ymm8 ymm9 zmm0 zmm1 zmm10 zmm11 zmm12 zmm13 zmm14 zmm15 zmm16 zmm17 zmm18 zmm19 zmm2 zmm20 zmm21 zmm22 zmm23 zmm24 zmm25 zmm26 zmm27 zmm28 zmm29 zmm3 zmm30 zmm31 zmm4 zmm5 zmm6 zmm7 zmm8 zmm9);
7919 1 %EXPORT_TAGS = (all => [@EXPORT, @EXPORT_OK]);
7920  
7921 # podDocumentation
7922 =pod
7923  
7924 =encoding utf-8
7925  
7926 =head1 Name
7927  
7928 Nasm::X86 - Generate X86 assembler code using Perl as a macro pre-processor.
7929  
7930 =head1 Synopsis
7931  
7932 Write and execute B<x64> B<Avx512> assembler code from L<perl> using L<perl> as a
7933 macro assembler. The generated code can be run under the Intel emulator to
7934 obtain execution trace and instruction counts.
7935  
7936 =head2 Examples
7937  
7938 =head3 Avx512 instructions
7939  
7940 Use B<Avx512> instructions to perform B<64> comparisons in parallel.
7941  
7942 my $P = "2F"; # Value to test for
7943 my $l = Rb 0; Rb $_ for 1..RegisterSize zmm0; # 0..63
7944 Vmovdqu8 zmm0, "[$l]"; # Load data to test
7945 PrintOutRegisterInHex zmm0;
7946  
7947 Mov rax, "0x$P"; # Broadcast the value to be tested
7948 Vpbroadcastb zmm1, rax;
7949 PrintOutRegisterInHex zmm1;
7950  
7951 for my $c(0..7) # Each possible test
7952 {my $m = "k$c";
7953 Vpcmpub $m, zmm1, zmm0, $c;
7954 PrintOutRegisterInHex $m;
7955 }
7956  
7957 Kmovq rax, k0; # Count the number of trailing zeros in k0
7958 Tzcnt rax, rax;
7959 PrintOutRegisterInHex rax;
7960  
7961 is_deeply Assemble, <<END; # Assemble and test
7962 zmm0: 3F3E 3D3C 3B3A 3938 3736 3534 3332 3130 2F2E 2D2C 2B2A 2928 2726 2524 2322 2120 1F1E 1D1C 1B1A 1918 1716 1514 1312 1110 0F0E 0D0C 0B0A 0908 0706 0504 0302 0100
7963 zmm1: 2F2F 2F2F 2F2F 2F2F 2F2F 2F2F 2F2F 2F2F 2F2F 2F2F 2F2F 2F2F 2F2F 2F2F 2F2F 2F2F 2F2F 2F2F 2F2F 2F2F 2F2F 2F2F 2F2F 2F2F 2F2F 2F2F 2F2F 2F2F 2F2F 2F2F 2F2F 2F2F
7964 k0: 0000 8000 0000 0000
7965 k1: FFFF 0000 0000 0000
7966 k2: FFFF 8000 0000 0000
7967 k3: 0000 0000 0000 0000
7968 k4: FFFF 7FFF FFFF FFFF
7969 k5: 0000 FFFF FFFF FFFF
7970 k6: 0000 7FFF FFFF FFFF
7971 k7: FFFF FFFF FFFF FFFF
7972 rax: 0000 0000 0000 002F
7973 END
7974  
7975 With the print statements removed, the Intel Emulator indicates that 26
7976 instructions were executed:
7977  
7978 CALL_NEAR 1
7979 ENTER 2
7980 JMP 1
7981 KMOVQ 1
7982 MOV 5
7983 POP 1
7984 PUSH 3
7985 SYSCALL 1
7986 TZCNT 1
7987 VMOVDQU8 1
7988 VPBROADCASTB 1
7989 VPCMPUB 8
7990  
7991 *total 26
7992  
7993 =head3 Process management
7994  
7995 Start a child process and wait for it, printing out the process identifiers of
7996 each process involved:
7997  
7998 Fork; # Fork
7999  
8000 Test rax,rax;
8001 IfNz # Parent
8002 Then
8003 {Mov rbx, rax;
8004 WaitPid;
8005 GetPid; # Pid of parent as seen in parent
8006 Mov rcx,rax;
8007 PrintOutRegisterInHex rax, rbx, rcx;
8008 },
8009 Else # Child
8010 {Mov r8,rax;
8011 GetPid; # Child pid as seen in child
8012 Mov r9,rax;
8013 GetPPid; # Parent pid as seen in child
8014 Mov r10,rax;
8015 PrintOutRegisterInHex r8, r9, r10;
8016 };
8017  
8018 my $r = Assemble;
8019  
8020 # r8: 0000 0000 0000 0000 #1 Return from fork as seen by child
8021 # r9: 0000 0000 0003 0C63 #2 Pid of child
8022 # r10: 0000 0000 0003 0C60 #3 Pid of parent from child
8023 # rax: 0000 0000 0003 0C63 #4 Return from fork as seen by parent
8024 # rbx: 0000 0000 0003 0C63 #5 Wait for child pid result
8025 # rcx: 0000 0000 0003 0C60 #6 Pid of parent
8026  
8027 =head3 Read a file
8028  
8029 Read this file:
8030  
8031 ReadFile(V(file, Rs($0)), (my $s = V(size)), my $a = V(address)); # Read file
8032 $a->setReg(rax); # Address of file in memory
8033 $s->setReg(rdi); # Length of file in memory
8034 PrintOutMemory; # Print contents of memory to stdout
8035  
8036 my $r = Assemble(1 => (my $f = temporaryFile)); # Assemble and execute
8037 ok fileMd5Sum($f) eq fileMd5Sum($0); # Output contains this file
8038  
8039  
8040 =head3 Call functions in Libc
8041  
8042 Call B<C> functions by naming them as external and including their library:
8043  
8044 my $format = Rs "Hello %s\n";
8045 my $data = Rs "World";
8046  
8047 Extern qw(printf exit malloc strcpy); Link 'c';
8048  
8049 CallC 'malloc', length($format)+1;
8050 Mov r15, rax;
8051 CallC 'strcpy', r15, $format;
8052 CallC 'printf', r15, $data;
8053 CallC 'exit', 0;
8054  
8055 ok Assemble(eq => <<END);
8056 Hello World
8057 END
8058  
8059 =head3 Dynamic arena
8060  
8061 Arenas are resizeable, relocatable blocks of memory that hold other dynamic
8062 data structures. Arenas can be transferred between processes and relocated as
8063 needed as all addressing is relative to the start of the block of memory
8064 containing each arena.
8065  
8066 Create two dynamic arenas, add some content to them, write each arena to
8067 stdout:
8068  
8069 my $a = CreateArena;
8070  
8071 my $b = CreateArena;
8072 $a->q('aa');
8073 $b->q('bb');
8074 $a->q('AA');
8075 $b->q('BB');
8076 $a->q('aa');
8077 $b->q('bb');
8078  
8079 $a->out;
8080 $b->out;
8081  
8082 PrintOutNL;
8083  
8084 is_deeply Assemble, <<END;
8085 aaAAaabbBBbb
8086 END
8087  
8088 =head4 Dynamic string held in an arena
8089  
8090 Create a dynamic string within an arena and add some content to it:
8091  
8092 my $s = Rb(0..255);
8093 my $A = CreateArena;
8094 my $S = $A->CreateString;
8095  
8096 $S->append(V(source, $s), K(size, 256));
8097 $S->len->outNL;
8098 $S->clear;
8099  
8100 $S->append(V(source, $s), K(size, 16));
8101 $S->len->outNL;
8102 $S->dump;
8103  
8104 ok Assemble(debug => 0, eq => <<END);
8105 size: 0000 0000 0000 0100
8106 size: 0000 0000 0000 0010
8107 string Dump
8108 Offset: 0000 0000 0000 0018 Length: 0000 0000 0000 0010
8109 zmm31: 0000 0018 0000 0018 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 000F 0E0D 0C0B 0A09 0807 0605 0403 0201 0010
8110  
8111 END
8112  
8113 =head4 Dynamic array held in an arena
8114  
8115 Create a dynamic array within an arena, push some content on to it then pop it
8116 off again:
8117  
8118 my $N = 15;
8119 my $A = CreateArena;
8120 my $a = $A->CreateArray;
8121  
8122 $a->push(V(element, $_)) for 1..$N;
8123  
8124 K(loop, $N)->for(sub
8125 {my ($start, $end, $next) = @_;
8126 my $l = $a->size;
8127 If $l == 0, Then {Jmp $end};
8128 $a->pop(my $e = V(element));
8129 $e->outNL;
8130 });
8131  
8132 ok Assemble(debug => 0, eq => <<END);
8133 element: 0000 0000 0000 000F
8134 element: 0000 0000 0000 000E
8135 element: 0000 0000 0000 000D
8136 element: 0000 0000 0000 000C
8137 element: 0000 0000 0000 000B
8138 element: 0000 0000 0000 000A
8139 element: 0000 0000 0000 0009
8140 element: 0000 0000 0000 0008
8141 element: 0000 0000 0000 0007
8142 element: 0000 0000 0000 0006
8143 element: 0000 0000 0000 0005
8144 element: 0000 0000 0000 0004
8145 element: 0000 0000 0000 0003
8146 element: 0000 0000 0000 0002
8147 element: 0000 0000 0000 0001
8148 END
8149  
8150 =head4 Create a multi way tree in an arena using SIMD instructions
8151  
8152 Create a multiway tree as in L<Tree::Multi> using B<Avx512> instructions and
8153 iterate through it:
8154  
8155 my $N = 12;
8156 my $b = CreateArena; # Resizable memory block
8157 my $t = $b->CreateTree; # Multi way tree in memory block
8158  
8159 K(count, $N)->for(sub # Add some entries to the tree
8160 {my ($index, $start, $next, $end) = @_;
8161 my $k = $index + 1;
8162 $t->insert($k, $k + 0x100);
8163 $t->insert($k + $N, $k + 0x200);
8164 });
8165  
8166 $t->by(sub # Iterate through the tree
8167 {my ($iter, $end) = @_;
8168 $iter->key ->out('key: ');
8169 $iter->data->out(' data: ');
8170 $iter->tree->depth($iter->node, my $D = V(depth));
8171  
8172 $t->find($iter->key);
8173 $t->found->out(' found: '); $t->data->out(' data: '); $D->outNL(' depth: ');
8174 });
8175  
8176 $t->find(K(key, 0xffff)); $t->found->outNL('Found: '); # Find some entries
8177 $t->find(K(key, 0xd)); $t->found->outNL('Found: ');
8178  
8179 If ($t->found,
8180 Then
8181 {$t->data->outNL("Data : ");
8182 });
8183  
8184 ok Assemble(debug => 0, eq => <<END);
8185 key: 0000 0000 0000 0001 data: 0000 0000 0000 0101 found: 0000 0000 0000 0001 data: 0000 0000 0000 0101 depth: 0000 0000 0000 0002
8186 key: 0000 0000 0000 0002 data: 0000 0000 0000 0102 found: 0000 0000 0000 0001 data: 0000 0000 0000 0102 depth: 0000 0000 0000 0002
8187 key: 0000 0000 0000 0003 data: 0000 0000 0000 0103 found: 0000 0000 0000 0001 data: 0000 0000 0000 0103 depth: 0000 0000 0000 0002
8188 key: 0000 0000 0000 0004 data: 0000 0000 0000 0104 found: 0000 0000 0000 0001 data: 0000 0000 0000 0104 depth: 0000 0000 0000 0002
8189 key: 0000 0000 0000 0005 data: 0000 0000 0000 0105 found: 0000 0000 0000 0001 data: 0000 0000 0000 0105 depth: 0000 0000 0000 0002
8190 key: 0000 0000 0000 0006 data: 0000 0000 0000 0106 found: 0000 0000 0000 0001 data: 0000 0000 0000 0106 depth: 0000 0000 0000 0002
8191 key: 0000 0000 0000 0007 data: 0000 0000 0000 0107 found: 0000 0000 0000 0001 data: 0000 0000 0000 0107 depth: 0000 0000 0000 0002
8192 key: 0000 0000 0000 0008 data: 0000 0000 0000 0108 found: 0000 0000 0000 0001 data: 0000 0000 0000 0108 depth: 0000 0000 0000 0002
8193 key: 0000 0000 0000 0009 data: 0000 0000 0000 0109 found: 0000 0000 0000 0001 data: 0000 0000 0000 0109 depth: 0000 0000 0000 0002
8194 key: 0000 0000 0000 000A data: 0000 0000 0000 010A found: 0000 0000 0000 0001 data: 0000 0000 0000 010A depth: 0000 0000 0000 0002
8195 key: 0000 0000 0000 000B data: 0000 0000 0000 010B found: 0000 0000 0000 0001 data: 0000 0000 0000 010B depth: 0000 0000 0000 0002
8196 key: 0000 0000 0000 000C data: 0000 0000 0000 010C found: 0000 0000 0000 0001 data: 0000 0000 0000 010C depth: 0000 0000 0000 0002
8197 key: 0000 0000 0000 000D data: 0000 0000 0000 0201 found: 0000 0000 0000 0001 data: 0000 0000 0000 0201 depth: 0000 0000 0000 0001
8198 key: 0000 0000 0000 000E data: 0000 0000 0000 0202 found: 0000 0000 0000 0001 data: 0000 0000 0000 0202 depth: 0000 0000 0000 0002
8199 key: 0000 0000 0000 000F data: 0000 0000 0000 0203 found: 0000 0000 0000 0001 data: 0000 0000 0000 0203 depth: 0000 0000 0000 0002
8200 key: 0000 0000 0000 0010 data: 0000 0000 0000 0204 found: 0000 0000 0000 0001 data: 0000 0000 0000 0204 depth: 0000 0000 0000 0002
8201 key: 0000 0000 0000 0011 data: 0000 0000 0000 0205 found: 0000 0000 0000 0001 data: 0000 0000 0000 0205 depth: 0000 0000 0000 0002
8202 key: 0000 0000 0000 0012 data: 0000 0000 0000 0206 found: 0000 0000 0000 0001 data: 0000 0000 0000 0206 depth: 0000 0000 0000 0002
8203 key: 0000 0000 0000 0013 data: 0000 0000 0000 0207 found: 0000 0000 0000 0001 data: 0000 0000 0000 0207 depth: 0000 0000 0000 0002
8204 key: 0000 0000 0000 0014 data: 0000 0000 0000 0208 found: 0000 0000 0000 0001 data: 0000 0000 0000 0208 depth: 0000 0000 0000 0002
8205 key: 0000 0000 0000 0015 data: 0000 0000 0000 0209 found: 0000 0000 0000 0001 data: 0000 0000 0000 0209 depth: 0000 0000 0000 0002
8206 key: 0000 0000 0000 0016 data: 0000 0000 0000 020A found: 0000 0000 0000 0001 data: 0000 0000 0000 020A depth: 0000 0000 0000 0002
8207 key: 0000 0000 0000 0017 data: 0000 0000 0000 020B found: 0000 0000 0000 0001 data: 0000 0000 0000 020B depth: 0000 0000 0000 0002
8208 key: 0000 0000 0000 0018 data: 0000 0000 0000 020C found: 0000 0000 0000 0001 data: 0000 0000 0000 020C depth: 0000 0000 0000 0002
8209 Found: 0000 0000 0000 0000
8210 Found: 0000 0000 0000 0001
8211 Data : 0000 0000 0000 0201
8212 END
8213  
8214 =head3 Recursion with stack and parameter tracing
8215  
8216 Call a subroutine recursively and get a trace back showing the procedure calls
8217 and parameters passed to each call. Parameters are passed by reference not
8218 value.
8219  
8220 my $d = V depth, 3; # Create a variable on the stack
8221  
8222 my $s = Subroutine
8223 {my ($p, $s) = @_; # Parameters, subroutine descriptor
8224 PrintOutTraceBack;
8225  
8226 my $d = $$p{depth}->copy($$p{depth} - 1); # Modify the variable referenced by the parameter
8227  
8228 If ($d > 0,
8229 Then
8230 {$s->call($d); # Recurse
8231 });
8232  
8233 PrintOutTraceBack;
8234 } [qw(depth)], name => 'ref';
8235  
8236 $s->call($d); # Call the subroutine
8237  
8238 ok Assemble(debug => 0, eq => <<END);
8239  
8240 Subroutine trace back, depth: 0000 0000 0000 0001
8241 0000 0000 0000 0003 ref
8242  
8243  
8244 Subroutine trace back, depth: 0000 0000 0000 0002
8245 0000 0000 0000 0002 ref
8246 0000 0000 0000 0002 ref
8247  
8248  
8249 Subroutine trace back, depth: 0000 0000 0000 0003
8250 0000 0000 0000 0001 ref
8251 0000 0000 0000 0001 ref
8252 0000 0000 0000 0001 ref
8253  
8254  
8255 Subroutine trace back, depth: 0000 0000 0000 0003
8256 0000 0000 0000 0000 ref
8257 0000 0000 0000 0000 ref
8258 0000 0000 0000 0000 ref
8259  
8260  
8261 Subroutine trace back, depth: 0000 0000 0000 0002
8262 0000 0000 0000 0000 ref
8263 0000 0000 0000 0000 ref
8264  
8265  
8266 Subroutine trace back, depth: 0000 0000 0000 0001
8267 0000 0000 0000 0000 ref
8268  
8269 END
8270  
8271 =head3 Quarks
8272  
8273 Quarks replace unique strings with unique numbers and in doing so unite all
8274 that is best and brightest in dynamic trees, arrays, strings and short
8275 strings, all written in X86 assembler, all generated by Perl:
8276  
8277 my $N = 5;
8278 my $a = CreateArena; # Arena containing quarks
8279 my $Q = $a->CreateQuarks; # Quarks
8280  
8281 my $s = CreateShortString(0); # Short string used to load and unload quarks
8282 my $d = Rb(1..63);
8283  
8284 for my $i(1..$N) # Load a set of quarks
8285 {my $j = $i - 1;
8286 $s->load(K(address, $d), K(size, 4+$i));
8287 my $q = $Q->quarkFromShortString($s);
8288 $q->outNL("New quark $j: "); # New quark, new number
8289 }
8290 PrintOutNL;
8291  
8292 for my $i(reverse 1..$N) # Reload a set of quarks
8293 {my $j = $i - 1;
8294 $s->load(K(address, $d), K(size, 4+$i));
8295 my $q = $Q->quarkFromShortString($s);
8296 $q->outNL("Old quark $j: "); # Old quark, old number
8297 }
8298 PrintOutNL;
8299  
8300 for my $i(1..$N) # Dump quarks
8301 {my $j = $i - 1;
8302 $s->clear;
8303 $Q->shortStringFromQuark(K(quark, $j), $s);
8304 PrintOutString "Quark string $j: ";
8305 PrintOutRegisterInHex xmm0;
8306 }
8307  
8308 ok Assemble(debug => 0, trace => 0, eq => <<END);
8309 New quark 0: 0000 0000 0000 0000
8310 New quark 1: 0000 0000 0000 0001
8311 New quark 2: 0000 0000 0000 0002
8312 New quark 3: 0000 0000 0000 0003
8313 New quark 4: 0000 0000 0000 0004
8314  
8315 Old quark 4: 0000 0000 0000 0004
8316 Old quark 3: 0000 0000 0000 0003
8317 Old quark 2: 0000 0000 0000 0002
8318 Old quark 1: 0000 0000 0000 0001
8319 Old quark 0: 0000 0000 0000 0000
8320  
8321 Quark string 0: xmm0: 0000 0000 0000 0000 0000 0504 0302 0105
8322 Quark string 1: xmm0: 0000 0000 0000 0000 0006 0504 0302 0106
8323 Quark string 2: xmm0: 0000 0000 0000 0000 0706 0504 0302 0107
8324 Quark string 3: xmm0: 0000 0000 0000 0008 0706 0504 0302 0108
8325 Quark string 4: xmm0: 0000 0000 0000 0908 0706 0504 0302 0109
8326 END
8327  
8328  
8329  
8330 =head2 Installation
8331  
8332 The Intel Software Development Emulator will be required if you do not have a
8333 computer with the avx512 instruction set and wish to execute code containing
8334 these instructions. For details see:
8335  
8336 L<https://software.intel.com/content/dam/develop/external/us/en/documents/downloads/sde-external-8.63.0-2021-01-18-lin.tar.bz2>
8337  
8338  
8339 The Networkwide Assembler is required to assemble the code produced For full
8340 details see:
8341  
8342 L<https://github.com/philiprbrenan/NasmX86/blob/main/.github/workflows/main.yml>
8343  
8344 =head2 Execution Options
8345  
8346 The L</Assemble(%)> function takes the keywords described below to
8347 control assembly and execution of the assembled code:
8348  
8349 L</Assemble(%)> runs the generated program after a successful assembly
8350 unless the B<keep> option is specified. The output on B<stdout> is captured in
8351 file B<zzzOut.txt> and that on B<stderr> is captured in file B<zzzErr.txt>.
8352  
8353 The amount of output displayed is controlled by the B<debug> keyword.
8354  
8355 The B<eq> keyword can be used to test that the output by the run.
8356  
8357 The output produced by the program execution is returned as the result of the
8358 L</Assemble(%)> function.
8359  
8360 =head3 Keep
8361  
8362 To produce a named executable without running it, specify:
8363  
8364 keep=>"executable file name"
8365  
8366 =head3 Emulator
8367  
8368 To run the executable produced by L</Assemble(%)> without the Intel
8369 emulator, which is used by default if it is present, specify:
8370  
8371 emulator=>0
8372  
8373 =head3 eq
8374  
8375 The B<eq> keyword supplies the expected output from the execution of the
8376 assembled program. If the expected output is not obtained on B<stdout> then we
8377 confess and stop further testing. Output on B<stderr> is ignored for test
8378 purposes.
8379  
8380 The point at which the wanted output diverges from the output actually got is
8381 displayed to assist debugging as in:
8382  
8383 Comparing wanted with got failed at line: 4, character: 22
8384 Start:
8385 k7: 0000 0000 0000 0001
8386 k6: 0000 0000 0000 0003
8387 k5: 0000 0000 0000 0007
8388 k4: 0000 0000 000
8389 Want ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8390 1 0002
8391 k3: 0000 0000 0000 0006
8392 k2: 0000 0000 0000 000E
8393 k1: 0000 0000
8394 Got ________________________________________________________________________________
8395 0 0002
8396 k3: 0000 0000 0000 0006
8397 k2: 0000 0000 0000 000E
8398 k1: 0000 0000
8399  
8400  
8401 =head3 Debug
8402  
8403 The debug keyword controls how much output is printed after each assemble and
8404 run.
8405  
8406 debug => 0
8407  
8408 produces no output unless the B<eq> keyword was specified and the actual output
8409 fails to match the expected output. If such a test fails we L<Carp::confess>.
8410  
8411 debug => 1
8412  
8413 shows all the output produces and conducts the test specified by the B<eq> is
8414 present. If the test fails we L<Carp::confess>.
8415  
8416 debug => 2
8417  
8418 shows all the output produces and conducts the test specified by the B<eq> is
8419 present. If the test fails we continue rather than calling L<Carp::confess>.
8420  
8421 =head1 Description
8422  
8423 Generate X86 assembler code using Perl as a macro pre-processor.
8424  
8425  
8426 Version "20210918".
8427  
8428  
8429 The following sections describe the methods in each functional area of this
8430 module. For an alphabetic listing of all methods by name see L<Index|/Index>.
8431  
8432  
8433  
8434 =head1 Data
8435  
8436 Layout data
8437  
8438 =head2 SetLabel($l)
8439  
8440 Create (if necessary) and set a label in the code section returning the label so set.
8441  
8442 Parameter Description
8443 1 $l Label
8444  
8445 B<Example:>
8446  
8447  
8448 Mov rax, 1;
8449 Mov rdi, 1;
8450 SaveFirstFour;
8451 Mov rax, 2;
8452 Mov rdi, 2;
8453 SaveFirstSeven;
8454 Mov rax, 3;
8455 Mov rdi, 4;
8456 PrintOutRegisterInHex rax, rdi;
8457 RestoreFirstSeven;
8458 PrintOutRegisterInHex rax, rdi;
8459 RestoreFirstFour;
8460 PrintOutRegisterInHex rax, rdi;
8461
8462 SaveFirstFour;
8463 Mov rax, 2;
8464 Mov rdi, 2;
8465 SaveFirstSeven;
8466 Mov rax, 3;
8467 Mov rdi, 4;
8468 PrintOutRegisterInHex rax, rdi;
8469 RestoreFirstSevenExceptRax;
8470 PrintOutRegisterInHex rax, rdi;
8471 RestoreFirstFourExceptRax;
8472 PrintOutRegisterInHex rax, rdi;
8473
8474 SaveFirstFour;
8475 Mov rax, 2;
8476 Mov rdi, 2;
8477 SaveFirstSeven;
8478 Mov rax, 3;
8479 Mov rdi, 4;
8480 PrintOutRegisterInHex rax, rdi;
8481 RestoreFirstSevenExceptRaxAndRdi;
8482 PrintOutRegisterInHex rax, rdi;
8483 RestoreFirstFourExceptRaxAndRdi;
8484 PrintOutRegisterInHex rax, rdi;
8485
8486 Bswap rax;
8487 PrintOutRegisterInHex rax;
8488
8489 my $l = Label;
8490 Jmp $l;
8491
8492 SetLabel $l; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
8493  
8494
8495 ok Assemble(debug => 0, eq => <<END);
8496 rax: 0000 0000 0000 0003
8497 rdi: 0000 0000 0000 0004
8498 rax: 0000 0000 0000 0002
8499 rdi: 0000 0000 0000 0002
8500 rax: 0000 0000 0000 0001
8501 rdi: 0000 0000 0000 0001
8502 rax: 0000 0000 0000 0003
8503 rdi: 0000 0000 0000 0004
8504 rax: 0000 0000 0000 0003
8505 rdi: 0000 0000 0000 0002
8506 rax: 0000 0000 0000 0003
8507 rdi: 0000 0000 0000 0001
8508 rax: 0000 0000 0000 0003
8509 rdi: 0000 0000 0000 0004
8510 rax: 0000 0000 0000 0003
8511 rdi: 0000 0000 0000 0004
8512 rax: 0000 0000 0000 0003
8513 rdi: 0000 0000 0000 0004
8514 rax: 0300 0000 0000 0000
8515 END
8516
8517 ok 8 == RegisterSize rax;
8518
8519  
8520 =head2 Ds(@d)
8521  
8522 Layout bytes in memory and return their label.
8523  
8524 Parameter Description
8525 1 @d Data to be laid out
8526  
8527 B<Example:>
8528  
8529  
8530 my $q = Rs('a'..'z');
8531
8532 Mov rax, Ds('0'x64); # Output area # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
8533  
8534 Vmovdqu32(xmm0, "[$q]"); # Load
8535 Vprolq (xmm0, xmm0, 32); # Rotate double words in quad words
8536 Vmovdqu32("[rax]", xmm0); # Save
8537 Mov rdi, 16;
8538 PrintOutMemory;
8539
8540 ok Assemble =~ m(efghabcdmnopijkl)s;
8541
8542  
8543 =head2 Rs(@d)
8544  
8545 Layout bytes in read only memory and return their label.
8546  
8547 Parameter Description
8548 1 @d Data to be laid out
8549  
8550 B<Example:>
8551  
8552  
8553 Comment "Print a string from memory";
8554 my $s = "Hello World";
8555
8556 Mov rax, Rs($s); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
8557  
8558 Mov rdi, length $s;
8559 PrintOutMemory;
8560 Exit(0);
8561
8562 ok Assemble =~ m(Hello World);
8563
8564
8565 my $q = Rs('abababab'); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
8566  
8567 Mov(rax, 1);
8568 Mov(rbx, 2);
8569 Mov(rcx, 3);
8570 Mov(rdx, 4);
8571 Mov(r8, 5);
8572 Lea r9, "[rax+rbx]";
8573 PrintOutRegistersInHex;
8574
8575 my $r = Assemble;
8576 ok $r =~ m( r8: 0000 0000 0000 0005.* r9: 0000 0000 0000 0003.*rax: 0000 0000 0000 0001)s;
8577 ok $r =~ m(rbx: 0000 0000 0000 0002.*rcx: 0000 0000 0000 0003.*rdx: 0000 0000 0000 0004)s;
8578
8579  
8580 =head2 Rutf8(@d)
8581  
8582 Layout a utf8 encoded string as bytes in read only memory and return their label.
8583  
8584 Parameter Description
8585 1 @d Data to be laid out
8586  
8587 =head2 Db(@bytes)
8588  
8589 Layout bytes in the data segment and return their label.
8590  
8591 Parameter Description
8592 1 @bytes Bytes to layout
8593  
8594 B<Example:>
8595  
8596  
8597 my $s = Rb 0; Rb 1; Rw 2; Rd 3; Rq 4;
8598
8599 my $t = Db 0; Db 1; Dw 2; Dd 3; Dq 4; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
8600  
8601
8602 Vmovdqu8 xmm0, "[$s]";
8603 Vmovdqu8 xmm1, "[$t]";
8604 PrintOutRegisterInHex xmm0;
8605 PrintOutRegisterInHex xmm1;
8606 Sub rsp, 16;
8607
8608 Mov rax, rsp; # Copy memory, the target is addressed by rax, the length is in rdi, the source is addressed by rsi
8609 Mov rdi, 16;
8610 Mov rsi, $s;
8611 CopyMemory(V(source, rsi), V(target, rax), V(size, rdi));
8612 PrintOutMemoryInHex;
8613
8614 my $r = Assemble;
8615 ok $r =~ m(xmm0: 0000 0000 0000 0004 0000 0003 0002 0100);
8616 ok $r =~ m(xmm1: 0000 0000 0000 0004 0000 0003 0002 0100);
8617 ok $r =~ m(0001 0200 0300 00000400 0000 0000 0000);
8618
8619  
8620 =head2 Dw(@words)
8621  
8622 Layout words in the data segment and return their label.
8623  
8624 Parameter Description
8625 1 @words Words to layout
8626  
8627 B<Example:>
8628  
8629  
8630 my $s = Rb 0; Rb 1; Rw 2; Rd 3; Rq 4;
8631
8632 my $t = Db 0; Db 1; Dw 2; Dd 3; Dq 4; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
8633  
8634
8635 Vmovdqu8 xmm0, "[$s]";
8636 Vmovdqu8 xmm1, "[$t]";
8637 PrintOutRegisterInHex xmm0;
8638 PrintOutRegisterInHex xmm1;
8639 Sub rsp, 16;
8640
8641 Mov rax, rsp; # Copy memory, the target is addressed by rax, the length is in rdi, the source is addressed by rsi
8642 Mov rdi, 16;
8643 Mov rsi, $s;
8644 CopyMemory(V(source, rsi), V(target, rax), V(size, rdi));
8645 PrintOutMemoryInHex;
8646
8647 my $r = Assemble;
8648 ok $r =~ m(xmm0: 0000 0000 0000 0004 0000 0003 0002 0100);
8649 ok $r =~ m(xmm1: 0000 0000 0000 0004 0000 0003 0002 0100);
8650 ok $r =~ m(0001 0200 0300 00000400 0000 0000 0000);
8651
8652  
8653 =head2 Dd(@dwords)
8654  
8655 Layout double words in the data segment and return their label.
8656  
8657 Parameter Description
8658 1 @dwords Double words to layout
8659  
8660 B<Example:>
8661  
8662  
8663 my $s = Rb 0; Rb 1; Rw 2; Rd 3; Rq 4;
8664
8665 my $t = Db 0; Db 1; Dw 2; Dd 3; Dq 4; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
8666  
8667
8668 Vmovdqu8 xmm0, "[$s]";
8669 Vmovdqu8 xmm1, "[$t]";
8670 PrintOutRegisterInHex xmm0;
8671 PrintOutRegisterInHex xmm1;
8672 Sub rsp, 16;
8673
8674 Mov rax, rsp; # Copy memory, the target is addressed by rax, the length is in rdi, the source is addressed by rsi
8675 Mov rdi, 16;
8676 Mov rsi, $s;
8677 CopyMemory(V(source, rsi), V(target, rax), V(size, rdi));
8678 PrintOutMemoryInHex;
8679
8680 my $r = Assemble;
8681 ok $r =~ m(xmm0: 0000 0000 0000 0004 0000 0003 0002 0100);
8682 ok $r =~ m(xmm1: 0000 0000 0000 0004 0000 0003 0002 0100);
8683 ok $r =~ m(0001 0200 0300 00000400 0000 0000 0000);
8684
8685  
8686 =head2 Dq(@qwords)
8687  
8688 Layout quad words in the data segment and return their label.
8689  
8690 Parameter Description
8691 1 @qwords Quad words to layout
8692  
8693 B<Example:>
8694  
8695  
8696 my $s = Rb 0; Rb 1; Rw 2; Rd 3; Rq 4;
8697
8698 my $t = Db 0; Db 1; Dw 2; Dd 3; Dq 4; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
8699  
8700
8701 Vmovdqu8 xmm0, "[$s]";
8702 Vmovdqu8 xmm1, "[$t]";
8703 PrintOutRegisterInHex xmm0;
8704 PrintOutRegisterInHex xmm1;
8705 Sub rsp, 16;
8706
8707 Mov rax, rsp; # Copy memory, the target is addressed by rax, the length is in rdi, the source is addressed by rsi
8708 Mov rdi, 16;
8709 Mov rsi, $s;
8710 CopyMemory(V(source, rsi), V(target, rax), V(size, rdi));
8711 PrintOutMemoryInHex;
8712
8713 my $r = Assemble;
8714 ok $r =~ m(xmm0: 0000 0000 0000 0004 0000 0003 0002 0100);
8715 ok $r =~ m(xmm1: 0000 0000 0000 0004 0000 0003 0002 0100);
8716 ok $r =~ m(0001 0200 0300 00000400 0000 0000 0000);
8717
8718  
8719 =head2 Rb(@bytes)
8720  
8721 Layout bytes in the data segment and return their label.
8722  
8723 Parameter Description
8724 1 @bytes Bytes to layout
8725  
8726 B<Example:>
8727  
8728  
8729
8730 my $s = Rb 0; Rb 1; Rw 2; Rd 3; Rq 4; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
8731  
8732 my $t = Db 0; Db 1; Dw 2; Dd 3; Dq 4;
8733
8734 Vmovdqu8 xmm0, "[$s]";
8735 Vmovdqu8 xmm1, "[$t]";
8736 PrintOutRegisterInHex xmm0;
8737 PrintOutRegisterInHex xmm1;
8738 Sub rsp, 16;
8739
8740 Mov rax, rsp; # Copy memory, the target is addressed by rax, the length is in rdi, the source is addressed by rsi
8741 Mov rdi, 16;
8742 Mov rsi, $s;
8743 CopyMemory(V(source, rsi), V(target, rax), V(size, rdi));
8744 PrintOutMemoryInHex;
8745
8746 my $r = Assemble;
8747 ok $r =~ m(xmm0: 0000 0000 0000 0004 0000 0003 0002 0100);
8748 ok $r =~ m(xmm1: 0000 0000 0000 0004 0000 0003 0002 0100);
8749 ok $r =~ m(0001 0200 0300 00000400 0000 0000 0000);
8750
8751  
8752 =head2 Rw(@words)
8753  
8754 Layout words in the data segment and return their label.
8755  
8756 Parameter Description
8757 1 @words Words to layout
8758  
8759 B<Example:>
8760  
8761  
8762
8763 my $s = Rb 0; Rb 1; Rw 2; Rd 3; Rq 4; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
8764  
8765 my $t = Db 0; Db 1; Dw 2; Dd 3; Dq 4;
8766
8767 Vmovdqu8 xmm0, "[$s]";
8768 Vmovdqu8 xmm1, "[$t]";
8769 PrintOutRegisterInHex xmm0;
8770 PrintOutRegisterInHex xmm1;
8771 Sub rsp, 16;
8772
8773 Mov rax, rsp; # Copy memory, the target is addressed by rax, the length is in rdi, the source is addressed by rsi
8774 Mov rdi, 16;
8775 Mov rsi, $s;
8776 CopyMemory(V(source, rsi), V(target, rax), V(size, rdi));
8777 PrintOutMemoryInHex;
8778
8779 my $r = Assemble;
8780 ok $r =~ m(xmm0: 0000 0000 0000 0004 0000 0003 0002 0100);
8781 ok $r =~ m(xmm1: 0000 0000 0000 0004 0000 0003 0002 0100);
8782 ok $r =~ m(0001 0200 0300 00000400 0000 0000 0000);
8783
8784  
8785 =head2 Rd(@dwords)
8786  
8787 Layout double words in the data segment and return their label.
8788  
8789 Parameter Description
8790 1 @dwords Double words to layout
8791  
8792 B<Example:>
8793  
8794  
8795
8796 my $s = Rb 0; Rb 1; Rw 2; Rd 3; Rq 4; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
8797  
8798 my $t = Db 0; Db 1; Dw 2; Dd 3; Dq 4;
8799
8800 Vmovdqu8 xmm0, "[$s]";
8801 Vmovdqu8 xmm1, "[$t]";
8802 PrintOutRegisterInHex xmm0;
8803 PrintOutRegisterInHex xmm1;
8804 Sub rsp, 16;
8805
8806 Mov rax, rsp; # Copy memory, the target is addressed by rax, the length is in rdi, the source is addressed by rsi
8807 Mov rdi, 16;
8808 Mov rsi, $s;
8809 CopyMemory(V(source, rsi), V(target, rax), V(size, rdi));
8810 PrintOutMemoryInHex;
8811
8812 my $r = Assemble;
8813 ok $r =~ m(xmm0: 0000 0000 0000 0004 0000 0003 0002 0100);
8814 ok $r =~ m(xmm1: 0000 0000 0000 0004 0000 0003 0002 0100);
8815 ok $r =~ m(0001 0200 0300 00000400 0000 0000 0000);
8816
8817  
8818 =head2 Rq(@qwords)
8819  
8820 Layout quad words in the data segment and return their label.
8821  
8822 Parameter Description
8823 1 @qwords Quad words to layout
8824  
8825 B<Example:>
8826  
8827  
8828
8829 my $s = Rb 0; Rb 1; Rw 2; Rd 3; Rq 4; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
8830  
8831 my $t = Db 0; Db 1; Dw 2; Dd 3; Dq 4;
8832
8833 Vmovdqu8 xmm0, "[$s]";
8834 Vmovdqu8 xmm1, "[$t]";
8835 PrintOutRegisterInHex xmm0;
8836 PrintOutRegisterInHex xmm1;
8837 Sub rsp, 16;
8838
8839 Mov rax, rsp; # Copy memory, the target is addressed by rax, the length is in rdi, the source is addressed by rsi
8840 Mov rdi, 16;
8841 Mov rsi, $s;
8842 CopyMemory(V(source, rsi), V(target, rax), V(size, rdi));
8843 PrintOutMemoryInHex;
8844
8845 my $r = Assemble;
8846 ok $r =~ m(xmm0: 0000 0000 0000 0004 0000 0003 0002 0100);
8847 ok $r =~ m(xmm1: 0000 0000 0000 0004 0000 0003 0002 0100);
8848 ok $r =~ m(0001 0200 0300 00000400 0000 0000 0000);
8849
8850  
8851 =head1 Registers
8852  
8853 Operations on registers
8854  
8855 =head2 xmm(@r)
8856  
8857 Add xmm to the front of a list of register expressions.
8858  
8859 Parameter Description
8860 1 @r Register numbers
8861  
8862 =head2 ymm(@r)
8863  
8864 Add ymm to the front of a list of register expressions.
8865  
8866 Parameter Description
8867 1 @r Register numbers
8868  
8869 =head2 zmm(@r)
8870  
8871 Add zmm to the front of a list of register expressions.
8872  
8873 Parameter Description
8874 1 @r Register numbers
8875  
8876 B<Example:>
8877  
8878  
8879 LoadZmm 0, 0..63;
8880
8881 PrintOutRegisterInHex zmm 0; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
8882  
8883
8884 ok Assemble(debug => 0, eq => <<END);
8885 zmm0: 3F3E 3D3C 3B3A 3938 3736 3534 3332 3130 2F2E 2D2C 2B2A 2928 2726 2524 2322 2120 1F1E 1D1C 1B1A 1918 1716 1514 1312 1110 0F0E 0D0C 0B0A 0908 0706 0504 0302 0100
8886 END
8887
8888  
8889 =head2 ChooseRegisters($number, @registers)
8890  
8891 Choose the specified numbers of registers excluding those on the specified list.
8892  
8893 Parameter Description
8894 1 $number Number of registers needed
8895 2 @registers Registers not to choose
8896  
8897 =head2 RegistersAvailable(@reg)
8898  
8899 Add a new set of registers that are available.
8900  
8901 Parameter Description
8902 1 @reg Registers known to be available at the moment
8903  
8904 =head2 RegistersFree()
8905  
8906 Remove the current set of registers known to be free.
8907  
8908  
8909 =head2 CheckGeneralPurposeRegister($reg)
8910  
8911 Check that a register is in fact a general purpose register.
8912  
8913 Parameter Description
8914 1 $reg Mask register to check
8915  
8916 =head2 CheckNumberedGeneralPurposeRegister($reg)
8917  
8918 Check that a register is in fact a numbered general purpose register.
8919  
8920 Parameter Description
8921 1 $reg Mask register to check
8922  
8923 =head2 InsertZeroIntoRegisterAtPoint($point, $in)
8924  
8925 Insert a zero into the specified register at the point indicated by another register.
8926  
8927 Parameter Description
8928 1 $point Register with a single 1 at the insertion point
8929 2 $in Register to be inserted into.
8930  
8931 B<Example:>
8932  
8933  
8934 Mov r15, 0x100; # Given a register with a single one in it indicating the desired position,
8935 Mov r14, 0xFFDC; # Insert a zero into the register at that position shifting the bits above that position up left one to make space for the new zero.
8936 Mov r13, 0xF03F;
8937 PrintOutRegisterInHex r14, r15;
8938
8939 InsertZeroIntoRegisterAtPoint r15, r14; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
8940  
8941 PrintOutRegisterInHex r14;
8942 Or r14, r15; # Replace the inserted zero with a one
8943 PrintOutRegisterInHex r14;
8944 InsertOneIntoRegisterAtPoint r15, r13;
8945 PrintOutRegisterInHex r13;
8946 ok Assemble(debug => 0, eq => <<END);
8947 r14: 0000 0000 0000 FFDC
8948 r15: 0000 0000 0000 0100
8949 r14: 0000 0000 0001 FEDC
8950 r14: 0000 0000 0001 FFDC
8951 r13: 0000 0000 0001 E13F
8952 END
8953
8954  
8955 =head2 InsertOneIntoRegisterAtPoint($point, $in)
8956  
8957 Insert a one into the specified register at the point indicated by another register.
8958  
8959 Parameter Description
8960 1 $point Register with a single 1 at the insertion point
8961 2 $in Register to be inserted into.
8962  
8963 B<Example:>
8964  
8965  
8966 Mov r15, 0x100; # Given a register with a single one in it indicating the desired position,
8967 Mov r14, 0xFFDC; # Insert a zero into the register at that position shifting the bits above that position up left one to make space for the new zero.
8968 Mov r13, 0xF03F;
8969 PrintOutRegisterInHex r14, r15;
8970 InsertZeroIntoRegisterAtPoint r15, r14;
8971 PrintOutRegisterInHex r14;
8972 Or r14, r15; # Replace the inserted zero with a one
8973 PrintOutRegisterInHex r14;
8974
8975 InsertOneIntoRegisterAtPoint r15, r13; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
8976  
8977 PrintOutRegisterInHex r13;
8978 ok Assemble(debug => 0, eq => <<END);
8979 r14: 0000 0000 0000 FFDC
8980 r15: 0000 0000 0000 0100
8981 r14: 0000 0000 0001 FEDC
8982 r14: 0000 0000 0001 FFDC
8983 r13: 0000 0000 0001 E13F
8984 END
8985
8986  
8987 =head2 LoadZmm($zmm, @bytes)
8988  
8989 Load a numbered zmm with the specified bytes.
8990  
8991 Parameter Description
8992 1 $zmm Numbered zmm
8993 2 @bytes Bytes
8994  
8995 B<Example:>
8996  
8997  
8998
8999 LoadZmm 0, 0..63; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9000  
9001 PrintOutRegisterInHex zmm 0;
9002
9003 ok Assemble(debug => 0, eq => <<END);
9004 zmm0: 3F3E 3D3C 3B3A 3938 3736 3534 3332 3130 2F2E 2D2C 2B2A 2928 2726 2524 2322 2120 1F1E 1D1C 1B1A 1918 1716 1514 1312 1110 0F0E 0D0C 0B0A 0908 0706 0504 0302 0100
9005 END
9006
9007  
9008 =head2 Save and Restore
9009  
9010 Saving and restoring registers via the stack
9011  
9012 =head3 SaveFirstFour(@keep)
9013  
9014 Save the first 4 parameter registers making any parameter registers read only.
9015  
9016 Parameter Description
9017 1 @keep Registers to mark as read only
9018  
9019 B<Example:>
9020  
9021  
9022 Mov rax, 1;
9023 Mov rdi, 1;
9024
9025 SaveFirstFour; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9026  
9027 Mov rax, 2;
9028 Mov rdi, 2;
9029 SaveFirstSeven;
9030 Mov rax, 3;
9031 Mov rdi, 4;
9032 PrintOutRegisterInHex rax, rdi;
9033 RestoreFirstSeven;
9034 PrintOutRegisterInHex rax, rdi;
9035 RestoreFirstFour;
9036 PrintOutRegisterInHex rax, rdi;
9037
9038
9039 SaveFirstFour; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9040  
9041 Mov rax, 2;
9042 Mov rdi, 2;
9043 SaveFirstSeven;
9044 Mov rax, 3;
9045 Mov rdi, 4;
9046 PrintOutRegisterInHex rax, rdi;
9047 RestoreFirstSevenExceptRax;
9048 PrintOutRegisterInHex rax, rdi;
9049 RestoreFirstFourExceptRax;
9050 PrintOutRegisterInHex rax, rdi;
9051
9052
9053 SaveFirstFour; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9054  
9055 Mov rax, 2;
9056 Mov rdi, 2;
9057 SaveFirstSeven;
9058 Mov rax, 3;
9059 Mov rdi, 4;
9060 PrintOutRegisterInHex rax, rdi;
9061 RestoreFirstSevenExceptRaxAndRdi;
9062 PrintOutRegisterInHex rax, rdi;
9063 RestoreFirstFourExceptRaxAndRdi;
9064 PrintOutRegisterInHex rax, rdi;
9065
9066 Bswap rax;
9067 PrintOutRegisterInHex rax;
9068
9069 my $l = Label;
9070 Jmp $l;
9071 SetLabel $l;
9072
9073 ok Assemble(debug => 0, eq => <<END);
9074 rax: 0000 0000 0000 0003
9075 rdi: 0000 0000 0000 0004
9076 rax: 0000 0000 0000 0002
9077 rdi: 0000 0000 0000 0002
9078 rax: 0000 0000 0000 0001
9079 rdi: 0000 0000 0000 0001
9080 rax: 0000 0000 0000 0003
9081 rdi: 0000 0000 0000 0004
9082 rax: 0000 0000 0000 0003
9083 rdi: 0000 0000 0000 0002
9084 rax: 0000 0000 0000 0003
9085 rdi: 0000 0000 0000 0001
9086 rax: 0000 0000 0000 0003
9087 rdi: 0000 0000 0000 0004
9088 rax: 0000 0000 0000 0003
9089 rdi: 0000 0000 0000 0004
9090 rax: 0000 0000 0000 0003
9091 rdi: 0000 0000 0000 0004
9092 rax: 0300 0000 0000 0000
9093 END
9094
9095 ok 8 == RegisterSize rax;
9096
9097  
9098 =head3 RestoreFirstFour()
9099  
9100 Restore the first 4 parameter registers.
9101  
9102  
9103 B<Example:>
9104  
9105  
9106 Mov rax, 1;
9107 Mov rdi, 1;
9108 SaveFirstFour;
9109 Mov rax, 2;
9110 Mov rdi, 2;
9111 SaveFirstSeven;
9112 Mov rax, 3;
9113 Mov rdi, 4;
9114 PrintOutRegisterInHex rax, rdi;
9115 RestoreFirstSeven;
9116 PrintOutRegisterInHex rax, rdi;
9117
9118 RestoreFirstFour; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9119  
9120 PrintOutRegisterInHex rax, rdi;
9121
9122 SaveFirstFour;
9123 Mov rax, 2;
9124 Mov rdi, 2;
9125 SaveFirstSeven;
9126 Mov rax, 3;
9127 Mov rdi, 4;
9128 PrintOutRegisterInHex rax, rdi;
9129 RestoreFirstSevenExceptRax;
9130 PrintOutRegisterInHex rax, rdi;
9131 RestoreFirstFourExceptRax;
9132 PrintOutRegisterInHex rax, rdi;
9133
9134 SaveFirstFour;
9135 Mov rax, 2;
9136 Mov rdi, 2;
9137 SaveFirstSeven;
9138 Mov rax, 3;
9139 Mov rdi, 4;
9140 PrintOutRegisterInHex rax, rdi;
9141 RestoreFirstSevenExceptRaxAndRdi;
9142 PrintOutRegisterInHex rax, rdi;
9143 RestoreFirstFourExceptRaxAndRdi;
9144 PrintOutRegisterInHex rax, rdi;
9145
9146 Bswap rax;
9147 PrintOutRegisterInHex rax;
9148
9149 my $l = Label;
9150 Jmp $l;
9151 SetLabel $l;
9152
9153 ok Assemble(debug => 0, eq => <<END);
9154 rax: 0000 0000 0000 0003
9155 rdi: 0000 0000 0000 0004
9156 rax: 0000 0000 0000 0002
9157 rdi: 0000 0000 0000 0002
9158 rax: 0000 0000 0000 0001
9159 rdi: 0000 0000 0000 0001
9160 rax: 0000 0000 0000 0003
9161 rdi: 0000 0000 0000 0004
9162 rax: 0000 0000 0000 0003
9163 rdi: 0000 0000 0000 0002
9164 rax: 0000 0000 0000 0003
9165 rdi: 0000 0000 0000 0001
9166 rax: 0000 0000 0000 0003
9167 rdi: 0000 0000 0000 0004
9168 rax: 0000 0000 0000 0003
9169 rdi: 0000 0000 0000 0004
9170 rax: 0000 0000 0000 0003
9171 rdi: 0000 0000 0000 0004
9172 rax: 0300 0000 0000 0000
9173 END
9174
9175 ok 8 == RegisterSize rax;
9176
9177  
9178 =head3 RestoreFirstFourExceptRax()
9179  
9180 Restore the first 4 parameter registers except rax so it can return its value.
9181  
9182  
9183 B<Example:>
9184  
9185  
9186 Mov rax, 1;
9187 Mov rdi, 1;
9188 SaveFirstFour;
9189 Mov rax, 2;
9190 Mov rdi, 2;
9191 SaveFirstSeven;
9192 Mov rax, 3;
9193 Mov rdi, 4;
9194 PrintOutRegisterInHex rax, rdi;
9195 RestoreFirstSeven;
9196 PrintOutRegisterInHex rax, rdi;
9197 RestoreFirstFour;
9198 PrintOutRegisterInHex rax, rdi;
9199
9200 SaveFirstFour;
9201 Mov rax, 2;
9202 Mov rdi, 2;
9203 SaveFirstSeven;
9204 Mov rax, 3;
9205 Mov rdi, 4;
9206 PrintOutRegisterInHex rax, rdi;
9207 RestoreFirstSevenExceptRax;
9208 PrintOutRegisterInHex rax, rdi;
9209
9210 RestoreFirstFourExceptRax; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9211  
9212 PrintOutRegisterInHex rax, rdi;
9213
9214 SaveFirstFour;
9215 Mov rax, 2;
9216 Mov rdi, 2;
9217 SaveFirstSeven;
9218 Mov rax, 3;
9219 Mov rdi, 4;
9220 PrintOutRegisterInHex rax, rdi;
9221 RestoreFirstSevenExceptRaxAndRdi;
9222 PrintOutRegisterInHex rax, rdi;
9223 RestoreFirstFourExceptRaxAndRdi;
9224 PrintOutRegisterInHex rax, rdi;
9225
9226 Bswap rax;
9227 PrintOutRegisterInHex rax;
9228
9229 my $l = Label;
9230 Jmp $l;
9231 SetLabel $l;
9232
9233 ok Assemble(debug => 0, eq => <<END);
9234 rax: 0000 0000 0000 0003
9235 rdi: 0000 0000 0000 0004
9236 rax: 0000 0000 0000 0002
9237 rdi: 0000 0000 0000 0002
9238 rax: 0000 0000 0000 0001
9239 rdi: 0000 0000 0000 0001
9240 rax: 0000 0000 0000 0003
9241 rdi: 0000 0000 0000 0004
9242 rax: 0000 0000 0000 0003
9243 rdi: 0000 0000 0000 0002
9244 rax: 0000 0000 0000 0003
9245 rdi: 0000 0000 0000 0001
9246 rax: 0000 0000 0000 0003
9247 rdi: 0000 0000 0000 0004
9248 rax: 0000 0000 0000 0003
9249 rdi: 0000 0000 0000 0004
9250 rax: 0000 0000 0000 0003
9251 rdi: 0000 0000 0000 0004
9252 rax: 0300 0000 0000 0000
9253 END
9254
9255 ok 8 == RegisterSize rax;
9256
9257  
9258 =head3 RestoreFirstFourExceptRaxAndRdi()
9259  
9260 Restore the first 4 parameter registers except rax and rdi so we can return a pair of values.
9261  
9262  
9263 B<Example:>
9264  
9265  
9266 Mov rax, 1;
9267 Mov rdi, 1;
9268 SaveFirstFour;
9269 Mov rax, 2;
9270 Mov rdi, 2;
9271 SaveFirstSeven;
9272 Mov rax, 3;
9273 Mov rdi, 4;
9274 PrintOutRegisterInHex rax, rdi;
9275 RestoreFirstSeven;
9276 PrintOutRegisterInHex rax, rdi;
9277 RestoreFirstFour;
9278 PrintOutRegisterInHex rax, rdi;
9279
9280 SaveFirstFour;
9281 Mov rax, 2;
9282 Mov rdi, 2;
9283 SaveFirstSeven;
9284 Mov rax, 3;
9285 Mov rdi, 4;
9286 PrintOutRegisterInHex rax, rdi;
9287 RestoreFirstSevenExceptRax;
9288 PrintOutRegisterInHex rax, rdi;
9289 RestoreFirstFourExceptRax;
9290 PrintOutRegisterInHex rax, rdi;
9291
9292 SaveFirstFour;
9293 Mov rax, 2;
9294 Mov rdi, 2;
9295 SaveFirstSeven;
9296 Mov rax, 3;
9297 Mov rdi, 4;
9298 PrintOutRegisterInHex rax, rdi;
9299 RestoreFirstSevenExceptRaxAndRdi;
9300 PrintOutRegisterInHex rax, rdi;
9301
9302 RestoreFirstFourExceptRaxAndRdi; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9303  
9304 PrintOutRegisterInHex rax, rdi;
9305
9306 Bswap rax;
9307 PrintOutRegisterInHex rax;
9308
9309 my $l = Label;
9310 Jmp $l;
9311 SetLabel $l;
9312
9313 ok Assemble(debug => 0, eq => <<END);
9314 rax: 0000 0000 0000 0003
9315 rdi: 0000 0000 0000 0004
9316 rax: 0000 0000 0000 0002
9317 rdi: 0000 0000 0000 0002
9318 rax: 0000 0000 0000 0001
9319 rdi: 0000 0000 0000 0001
9320 rax: 0000 0000 0000 0003
9321 rdi: 0000 0000 0000 0004
9322 rax: 0000 0000 0000 0003
9323 rdi: 0000 0000 0000 0002
9324 rax: 0000 0000 0000 0003
9325 rdi: 0000 0000 0000 0001
9326 rax: 0000 0000 0000 0003
9327 rdi: 0000 0000 0000 0004
9328 rax: 0000 0000 0000 0003
9329 rdi: 0000 0000 0000 0004
9330 rax: 0000 0000 0000 0003
9331 rdi: 0000 0000 0000 0004
9332 rax: 0300 0000 0000 0000
9333 END
9334
9335 ok 8 == RegisterSize rax;
9336
9337  
9338 =head3 SaveFirstSeven()
9339  
9340 Save the first 7 parameter registers.
9341  
9342  
9343 B<Example:>
9344  
9345  
9346 Mov rax, 1;
9347 Mov rdi, 1;
9348 SaveFirstFour;
9349 Mov rax, 2;
9350 Mov rdi, 2;
9351
9352 SaveFirstSeven; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9353  
9354 Mov rax, 3;
9355 Mov rdi, 4;
9356 PrintOutRegisterInHex rax, rdi;
9357 RestoreFirstSeven;
9358 PrintOutRegisterInHex rax, rdi;
9359 RestoreFirstFour;
9360 PrintOutRegisterInHex rax, rdi;
9361
9362 SaveFirstFour;
9363 Mov rax, 2;
9364 Mov rdi, 2;
9365
9366 SaveFirstSeven; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9367  
9368 Mov rax, 3;
9369 Mov rdi, 4;
9370 PrintOutRegisterInHex rax, rdi;
9371 RestoreFirstSevenExceptRax;
9372 PrintOutRegisterInHex rax, rdi;
9373 RestoreFirstFourExceptRax;
9374 PrintOutRegisterInHex rax, rdi;
9375
9376 SaveFirstFour;
9377 Mov rax, 2;
9378 Mov rdi, 2;
9379
9380 SaveFirstSeven; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9381  
9382 Mov rax, 3;
9383 Mov rdi, 4;
9384 PrintOutRegisterInHex rax, rdi;
9385 RestoreFirstSevenExceptRaxAndRdi;
9386 PrintOutRegisterInHex rax, rdi;
9387 RestoreFirstFourExceptRaxAndRdi;
9388 PrintOutRegisterInHex rax, rdi;
9389
9390 Bswap rax;
9391 PrintOutRegisterInHex rax;
9392
9393 my $l = Label;
9394 Jmp $l;
9395 SetLabel $l;
9396
9397 ok Assemble(debug => 0, eq => <<END);
9398 rax: 0000 0000 0000 0003
9399 rdi: 0000 0000 0000 0004
9400 rax: 0000 0000 0000 0002
9401 rdi: 0000 0000 0000 0002
9402 rax: 0000 0000 0000 0001
9403 rdi: 0000 0000 0000 0001
9404 rax: 0000 0000 0000 0003
9405 rdi: 0000 0000 0000 0004
9406 rax: 0000 0000 0000 0003
9407 rdi: 0000 0000 0000 0002
9408 rax: 0000 0000 0000 0003
9409 rdi: 0000 0000 0000 0001
9410 rax: 0000 0000 0000 0003
9411 rdi: 0000 0000 0000 0004
9412 rax: 0000 0000 0000 0003
9413 rdi: 0000 0000 0000 0004
9414 rax: 0000 0000 0000 0003
9415 rdi: 0000 0000 0000 0004
9416 rax: 0300 0000 0000 0000
9417 END
9418
9419 ok 8 == RegisterSize rax;
9420
9421  
9422 =head3 RestoreFirstSeven()
9423  
9424 Restore the first 7 parameter registers.
9425  
9426  
9427 B<Example:>
9428  
9429  
9430 Mov rax, 1;
9431 Mov rdi, 1;
9432 SaveFirstFour;
9433 Mov rax, 2;
9434 Mov rdi, 2;
9435 SaveFirstSeven;
9436 Mov rax, 3;
9437 Mov rdi, 4;
9438 PrintOutRegisterInHex rax, rdi;
9439
9440 RestoreFirstSeven; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9441  
9442 PrintOutRegisterInHex rax, rdi;
9443 RestoreFirstFour;
9444 PrintOutRegisterInHex rax, rdi;
9445
9446 SaveFirstFour;
9447 Mov rax, 2;
9448 Mov rdi, 2;
9449 SaveFirstSeven;
9450 Mov rax, 3;
9451 Mov rdi, 4;
9452 PrintOutRegisterInHex rax, rdi;
9453 RestoreFirstSevenExceptRax;
9454 PrintOutRegisterInHex rax, rdi;
9455 RestoreFirstFourExceptRax;
9456 PrintOutRegisterInHex rax, rdi;
9457
9458 SaveFirstFour;
9459 Mov rax, 2;
9460 Mov rdi, 2;
9461 SaveFirstSeven;
9462 Mov rax, 3;
9463 Mov rdi, 4;
9464 PrintOutRegisterInHex rax, rdi;
9465 RestoreFirstSevenExceptRaxAndRdi;
9466 PrintOutRegisterInHex rax, rdi;
9467 RestoreFirstFourExceptRaxAndRdi;
9468 PrintOutRegisterInHex rax, rdi;
9469
9470 Bswap rax;
9471 PrintOutRegisterInHex rax;
9472
9473 my $l = Label;
9474 Jmp $l;
9475 SetLabel $l;
9476
9477 ok Assemble(debug => 0, eq => <<END);
9478 rax: 0000 0000 0000 0003
9479 rdi: 0000 0000 0000 0004
9480 rax: 0000 0000 0000 0002
9481 rdi: 0000 0000 0000 0002
9482 rax: 0000 0000 0000 0001
9483 rdi: 0000 0000 0000 0001
9484 rax: 0000 0000 0000 0003
9485 rdi: 0000 0000 0000 0004
9486 rax: 0000 0000 0000 0003
9487 rdi: 0000 0000 0000 0002
9488 rax: 0000 0000 0000 0003
9489 rdi: 0000 0000 0000 0001
9490 rax: 0000 0000 0000 0003
9491 rdi: 0000 0000 0000 0004
9492 rax: 0000 0000 0000 0003
9493 rdi: 0000 0000 0000 0004
9494 rax: 0000 0000 0000 0003
9495 rdi: 0000 0000 0000 0004
9496 rax: 0300 0000 0000 0000
9497 END
9498
9499 ok 8 == RegisterSize rax;
9500
9501  
9502 =head3 RestoreFirstSevenExceptRax()
9503  
9504 Restore the first 7 parameter registers except rax which is being used to return the result.
9505  
9506  
9507 B<Example:>
9508  
9509  
9510 Mov rax, 1;
9511 Mov rdi, 1;
9512 SaveFirstFour;
9513 Mov rax, 2;
9514 Mov rdi, 2;
9515 SaveFirstSeven;
9516 Mov rax, 3;
9517 Mov rdi, 4;
9518 PrintOutRegisterInHex rax, rdi;
9519 RestoreFirstSeven;
9520 PrintOutRegisterInHex rax, rdi;
9521 RestoreFirstFour;
9522 PrintOutRegisterInHex rax, rdi;
9523
9524 SaveFirstFour;
9525 Mov rax, 2;
9526 Mov rdi, 2;
9527 SaveFirstSeven;
9528 Mov rax, 3;
9529 Mov rdi, 4;
9530 PrintOutRegisterInHex rax, rdi;
9531
9532 RestoreFirstSevenExceptRax; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9533  
9534 PrintOutRegisterInHex rax, rdi;
9535 RestoreFirstFourExceptRax;
9536 PrintOutRegisterInHex rax, rdi;
9537
9538 SaveFirstFour;
9539 Mov rax, 2;
9540 Mov rdi, 2;
9541 SaveFirstSeven;
9542 Mov rax, 3;
9543 Mov rdi, 4;
9544 PrintOutRegisterInHex rax, rdi;
9545 RestoreFirstSevenExceptRaxAndRdi;
9546 PrintOutRegisterInHex rax, rdi;
9547 RestoreFirstFourExceptRaxAndRdi;
9548 PrintOutRegisterInHex rax, rdi;
9549
9550 Bswap rax;
9551 PrintOutRegisterInHex rax;
9552
9553 my $l = Label;
9554 Jmp $l;
9555 SetLabel $l;
9556
9557 ok Assemble(debug => 0, eq => <<END);
9558 rax: 0000 0000 0000 0003
9559 rdi: 0000 0000 0000 0004
9560 rax: 0000 0000 0000 0002
9561 rdi: 0000 0000 0000 0002
9562 rax: 0000 0000 0000 0001
9563 rdi: 0000 0000 0000 0001
9564 rax: 0000 0000 0000 0003
9565 rdi: 0000 0000 0000 0004
9566 rax: 0000 0000 0000 0003
9567 rdi: 0000 0000 0000 0002
9568 rax: 0000 0000 0000 0003
9569 rdi: 0000 0000 0000 0001
9570 rax: 0000 0000 0000 0003
9571 rdi: 0000 0000 0000 0004
9572 rax: 0000 0000 0000 0003
9573 rdi: 0000 0000 0000 0004
9574 rax: 0000 0000 0000 0003
9575 rdi: 0000 0000 0000 0004
9576 rax: 0300 0000 0000 0000
9577 END
9578
9579 ok 8 == RegisterSize rax;
9580
9581  
9582 =head3 RestoreFirstSevenExceptRaxAndRdi()
9583  
9584 Restore the first 7 parameter registers except rax and rdi which are being used to return the results.
9585  
9586  
9587 B<Example:>
9588  
9589  
9590 Mov rax, 1;
9591 Mov rdi, 1;
9592 SaveFirstFour;
9593 Mov rax, 2;
9594 Mov rdi, 2;
9595 SaveFirstSeven;
9596 Mov rax, 3;
9597 Mov rdi, 4;
9598 PrintOutRegisterInHex rax, rdi;
9599 RestoreFirstSeven;
9600 PrintOutRegisterInHex rax, rdi;
9601 RestoreFirstFour;
9602 PrintOutRegisterInHex rax, rdi;
9603
9604 SaveFirstFour;
9605 Mov rax, 2;
9606 Mov rdi, 2;
9607 SaveFirstSeven;
9608 Mov rax, 3;
9609 Mov rdi, 4;
9610 PrintOutRegisterInHex rax, rdi;
9611 RestoreFirstSevenExceptRax;
9612 PrintOutRegisterInHex rax, rdi;
9613 RestoreFirstFourExceptRax;
9614 PrintOutRegisterInHex rax, rdi;
9615
9616 SaveFirstFour;
9617 Mov rax, 2;
9618 Mov rdi, 2;
9619 SaveFirstSeven;
9620 Mov rax, 3;
9621 Mov rdi, 4;
9622 PrintOutRegisterInHex rax, rdi;
9623
9624 RestoreFirstSevenExceptRaxAndRdi; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9625  
9626 PrintOutRegisterInHex rax, rdi;
9627 RestoreFirstFourExceptRaxAndRdi;
9628 PrintOutRegisterInHex rax, rdi;
9629
9630 Bswap rax;
9631 PrintOutRegisterInHex rax;
9632
9633 my $l = Label;
9634 Jmp $l;
9635 SetLabel $l;
9636
9637 ok Assemble(debug => 0, eq => <<END);
9638 rax: 0000 0000 0000 0003
9639 rdi: 0000 0000 0000 0004
9640 rax: 0000 0000 0000 0002
9641 rdi: 0000 0000 0000 0002
9642 rax: 0000 0000 0000 0001
9643 rdi: 0000 0000 0000 0001
9644 rax: 0000 0000 0000 0003
9645 rdi: 0000 0000 0000 0004
9646 rax: 0000 0000 0000 0003
9647 rdi: 0000 0000 0000 0002
9648 rax: 0000 0000 0000 0003
9649 rdi: 0000 0000 0000 0001
9650 rax: 0000 0000 0000 0003
9651 rdi: 0000 0000 0000 0004
9652 rax: 0000 0000 0000 0003
9653 rdi: 0000 0000 0000 0004
9654 rax: 0000 0000 0000 0003
9655 rdi: 0000 0000 0000 0004
9656 rax: 0300 0000 0000 0000
9657 END
9658
9659 ok 8 == RegisterSize rax;
9660
9661  
9662 =head3 ReorderSyscallRegisters(@registers)
9663  
9664 Map the list of registers provided to the 64 bit system call sequence.
9665  
9666 Parameter Description
9667 1 @registers Registers
9668  
9669 B<Example:>
9670  
9671  
9672 Mov rax, 1; Mov rdi, 2; Mov rsi, 3; Mov rdx, 4;
9673 Mov r8, 8; Mov r9, 9; Mov r10, 10; Mov r11, 11;
9674
9675
9676 ReorderSyscallRegisters r8,r9; # Reorder the registers for syscall # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9677  
9678 PrintOutRegisterInHex rax;
9679 PrintOutRegisterInHex rdi;
9680
9681 UnReorderSyscallRegisters r8,r9; # Unreorder the registers to recover their original values
9682 PrintOutRegisterInHex rax;
9683 PrintOutRegisterInHex rdi;
9684
9685 ok Assemble =~ m(rax:.*08.*rdi:.*9.*rax:.*1.*rdi:.*2.*)s;
9686
9687  
9688 =head3 UnReorderSyscallRegisters(@registers)
9689  
9690 Recover the initial values in registers that were reordered.
9691  
9692 Parameter Description
9693 1 @registers Registers
9694  
9695 B<Example:>
9696  
9697  
9698 Mov rax, 1; Mov rdi, 2; Mov rsi, 3; Mov rdx, 4;
9699 Mov r8, 8; Mov r9, 9; Mov r10, 10; Mov r11, 11;
9700
9701 ReorderSyscallRegisters r8,r9; # Reorder the registers for syscall
9702 PrintOutRegisterInHex rax;
9703 PrintOutRegisterInHex rdi;
9704
9705
9706 UnReorderSyscallRegisters r8,r9; # Unreorder the registers to recover their original values # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9707  
9708 PrintOutRegisterInHex rax;
9709 PrintOutRegisterInHex rdi;
9710
9711 ok Assemble =~ m(rax:.*08.*rdi:.*9.*rax:.*1.*rdi:.*2.*)s;
9712
9713  
9714 =head3 RegisterSize($r)
9715  
9716 Return the size of a register.
9717  
9718 Parameter Description
9719 1 $r Register
9720  
9721 B<Example:>
9722  
9723  
9724 Mov rax, 1;
9725 Mov rdi, 1;
9726 SaveFirstFour;
9727 Mov rax, 2;
9728 Mov rdi, 2;
9729 SaveFirstSeven;
9730 Mov rax, 3;
9731 Mov rdi, 4;
9732 PrintOutRegisterInHex rax, rdi;
9733 RestoreFirstSeven;
9734 PrintOutRegisterInHex rax, rdi;
9735 RestoreFirstFour;
9736 PrintOutRegisterInHex rax, rdi;
9737
9738 SaveFirstFour;
9739 Mov rax, 2;
9740 Mov rdi, 2;
9741 SaveFirstSeven;
9742 Mov rax, 3;
9743 Mov rdi, 4;
9744 PrintOutRegisterInHex rax, rdi;
9745 RestoreFirstSevenExceptRax;
9746 PrintOutRegisterInHex rax, rdi;
9747 RestoreFirstFourExceptRax;
9748 PrintOutRegisterInHex rax, rdi;
9749
9750 SaveFirstFour;
9751 Mov rax, 2;
9752 Mov rdi, 2;
9753 SaveFirstSeven;
9754 Mov rax, 3;
9755 Mov rdi, 4;
9756 PrintOutRegisterInHex rax, rdi;
9757 RestoreFirstSevenExceptRaxAndRdi;
9758 PrintOutRegisterInHex rax, rdi;
9759 RestoreFirstFourExceptRaxAndRdi;
9760 PrintOutRegisterInHex rax, rdi;
9761
9762 Bswap rax;
9763 PrintOutRegisterInHex rax;
9764
9765 my $l = Label;
9766 Jmp $l;
9767 SetLabel $l;
9768
9769 ok Assemble(debug => 0, eq => <<END);
9770 rax: 0000 0000 0000 0003
9771 rdi: 0000 0000 0000 0004
9772 rax: 0000 0000 0000 0002
9773 rdi: 0000 0000 0000 0002
9774 rax: 0000 0000 0000 0001
9775 rdi: 0000 0000 0000 0001
9776 rax: 0000 0000 0000 0003
9777 rdi: 0000 0000 0000 0004
9778 rax: 0000 0000 0000 0003
9779 rdi: 0000 0000 0000 0002
9780 rax: 0000 0000 0000 0003
9781 rdi: 0000 0000 0000 0001
9782 rax: 0000 0000 0000 0003
9783 rdi: 0000 0000 0000 0004
9784 rax: 0000 0000 0000 0003
9785 rdi: 0000 0000 0000 0004
9786 rax: 0000 0000 0000 0003
9787 rdi: 0000 0000 0000 0004
9788 rax: 0300 0000 0000 0000
9789 END
9790
9791
9792 ok 8 == RegisterSize rax; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9793  
9794
9795  
9796 =head3 ClearRegisters(@registers)
9797  
9798 Clear registers by setting them to zero.
9799  
9800 Parameter Description
9801 1 @registers Registers
9802  
9803 B<Example:>
9804  
9805  
9806 Mov rax,1;
9807 Kmovq k0, rax;
9808 Kaddb k0, k0, k0;
9809 Kaddb k0, k0, k0;
9810 Kaddb k0, k0, k0;
9811 Kmovq rax, k0;
9812 PushR k0;
9813
9814 ClearRegisters k0; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9815  
9816 Kmovq k1, k0;
9817 PopR k0;
9818 PrintOutRegisterInHex k0;
9819 PrintOutRegisterInHex k1;
9820
9821 ok Assemble =~ m(k0: 0000 0000 0000 0008.*k1: 0000 0000 0000 0000)s;
9822
9823  
9824 =head3 SetMaskRegister($mask, $start, $length)
9825  
9826 Set the mask register to ones starting at the specified position for the specified length and zeroes elsewhere.
9827  
9828 Parameter Description
9829 1 $mask Mask register to set
9830 2 $start Register containing start position or 0 for position 0
9831 3 $length Register containing end position
9832  
9833 B<Example:>
9834  
9835  
9836 Mov rax, 8;
9837 Mov rsi, -1;
9838
9839 Inc rsi; SetMaskRegister(k0, rax, rsi); PrintOutRegisterInHex k0; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9840  
9841
9842 Inc rsi; SetMaskRegister(k1, rax, rsi); PrintOutRegisterInHex k1; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9843  
9844
9845 Inc rsi; SetMaskRegister(k2, rax, rsi); PrintOutRegisterInHex k2; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9846  
9847
9848 Inc rsi; SetMaskRegister(k3, rax, rsi); PrintOutRegisterInHex k3; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9849  
9850
9851 Inc rsi; SetMaskRegister(k4, rax, rsi); PrintOutRegisterInHex k4; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9852  
9853
9854 Inc rsi; SetMaskRegister(k5, rax, rsi); PrintOutRegisterInHex k5; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9855  
9856
9857 Inc rsi; SetMaskRegister(k6, rax, rsi); PrintOutRegisterInHex k6; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9858  
9859
9860 Inc rsi; SetMaskRegister(k7, rax, rsi); PrintOutRegisterInHex k7; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9861  
9862
9863 ok Assemble(debug => 0, eq => <<END);
9864 k0: 0000 0000 0000 0000
9865 k1: 0000 0000 0000 0100
9866 k2: 0000 0000 0000 0300
9867 k3: 0000 0000 0000 0700
9868 k4: 0000 0000 0000 0F00
9869 k5: 0000 0000 0000 1F00
9870 k6: 0000 0000 0000 3F00
9871 k7: 0000 0000 0000 7F00
9872 END
9873
9874  
9875 =head3 SetZF()
9876  
9877 Set the zero flag.
9878  
9879  
9880 B<Example:>
9881  
9882  
9883
9884 SetZF; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9885  
9886 PrintOutZF;
9887 ClearZF;
9888 PrintOutZF;
9889
9890 SetZF; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9891  
9892 PrintOutZF;
9893
9894 SetZF; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9895  
9896 PrintOutZF;
9897 ClearZF;
9898 PrintOutZF;
9899
9900
9901 SetZF; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9902  
9903 IfZ Then {PrintOutStringNL "Zero"}, Else {PrintOutStringNL "NOT zero"};
9904 ClearZF;
9905 IfNz Then {PrintOutStringNL "NOT zero"}, Else {PrintOutStringNL "Zero"};
9906
9907 Mov r15, 5;
9908 Shr r15, 1; IfC Then {PrintOutStringNL "Carry"} , Else {PrintOutStringNL "NO carry"};
9909 Shr r15, 1; IfC Then {PrintOutStringNL "Carry"} , Else {PrintOutStringNL "NO carry"};
9910 Shr r15, 1; IfNc Then {PrintOutStringNL "NO carry"}, Else {PrintOutStringNL "Carry"};
9911 Shr r15, 1; IfNc Then {PrintOutStringNL "NO carry"}, Else {PrintOutStringNL "Carry"};
9912
9913 ok Assemble(debug => 0, eq => <<END);
9914 ZF=1
9915 ZF=0
9916 ZF=1
9917 ZF=1
9918 ZF=0
9919 Zero
9920 NOT zero
9921 Carry
9922 NO carry
9923 Carry
9924 NO carry
9925 END
9926
9927  
9928 =head3 ClearZF()
9929  
9930 Clear the zero flag.
9931  
9932  
9933 B<Example:>
9934  
9935  
9936 SetZF;
9937 PrintOutZF;
9938
9939 ClearZF; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9940  
9941 PrintOutZF;
9942 SetZF;
9943 PrintOutZF;
9944 SetZF;
9945 PrintOutZF;
9946
9947 ClearZF; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9948  
9949 PrintOutZF;
9950
9951 SetZF;
9952 IfZ Then {PrintOutStringNL "Zero"}, Else {PrintOutStringNL "NOT zero"};
9953
9954 ClearZF; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9955  
9956 IfNz Then {PrintOutStringNL "NOT zero"}, Else {PrintOutStringNL "Zero"};
9957
9958 Mov r15, 5;
9959 Shr r15, 1; IfC Then {PrintOutStringNL "Carry"} , Else {PrintOutStringNL "NO carry"};
9960 Shr r15, 1; IfC Then {PrintOutStringNL "Carry"} , Else {PrintOutStringNL "NO carry"};
9961 Shr r15, 1; IfNc Then {PrintOutStringNL "NO carry"}, Else {PrintOutStringNL "Carry"};
9962 Shr r15, 1; IfNc Then {PrintOutStringNL "NO carry"}, Else {PrintOutStringNL "Carry"};
9963
9964 ok Assemble(debug => 0, eq => <<END);
9965 ZF=1
9966 ZF=0
9967 ZF=1
9968 ZF=1
9969 ZF=0
9970 Zero
9971 NOT zero
9972 Carry
9973 NO carry
9974 Carry
9975 NO carry
9976 END
9977
9978  
9979 =head2 Mask
9980  
9981 Operations on mask registers
9982  
9983 =head3 CheckMaskRegister($mask)
9984  
9985 Check that a register is in fact a mask register.
9986  
9987 Parameter Description
9988 1 $mask Mask register to check
9989  
9990 =head3 LoadConstantIntoMaskRegister($mask, $transfer, $value)
9991  
9992 Set a mask register equal to a constant.
9993  
9994 Parameter Description
9995 1 $mask Mask register to load
9996 2 $transfer Transfer register
9997 3 $value Constant to load
9998  
9999 B<Example:>
10000  
10001  
10002 Mov r14, 0;
10003 Kmovq k0, r14;
10004 Ktestq k0, k0;
10005 IfZ Then {PrintOutStringNL "0 & 0 == 0"};
10006 PrintOutZF;
10007
10008
10009 LoadConstantIntoMaskRegister k1, r13, 1; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10010  
10011 Ktestq k1, k1;
10012 IfNz Then {PrintOutStringNL "1 & 1 != 0"};
10013 PrintOutZF;
10014
10015
10016 LoadConstantIntoMaskRegister k2, r13, eval "0b".(('1'x4).('0'x4))x2; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10017  
10018
10019 PrintOutRegisterInHex k0, k1, k2;
10020
10021 Mov r15, 0x89abcdef;
10022 Mov r14, 0x01234567;
10023 Shl r14, 32;
10024 Or r15, r14;
10025 Push r15;
10026 Push r15;
10027 PopEax; PrintRaxInHex($stdout, 3); PrintOutNL;
10028
10029 my $a = V('aaaa');
10030 $a->pop;
10031 $a->push;
10032 $a->outNL;
10033
10034 PopEax; PrintRaxInHex($stdout, 3); PrintOutNL;
10035
10036 ok Assemble(debug => 0, eq => <<END);
10037 0 & 0 == 0
10038 ZF=1
10039 1 & 1 != 0
10040 ZF=0
10041 k0: 0000 0000 0000 0000
10042 k1: 0000 0000 0000 0001
10043 k2: 0000 0000 0000 F0F0
10044 89AB CDEF
10045 aaaa: 89AB CDEF 0123 4567
10046 0123 4567
10047 END
10048
10049  
10050 =head3 LoadBitsIntoMaskRegister($mask, $transfer, $prefix, @values)
10051  
10052 Load a bit string specification into a mask register.
10053  
10054 Parameter Description
10055 1 $mask Mask register to load
10056 2 $transfer Transfer register
10057 3 $prefix Prefix bits
10058 4 @values +n 1 bits -n 0 bits
10059  
10060 B<Example:>
10061  
10062  
10063 for (0..7)
10064 {ClearRegisters "k$_";
10065 K($_,$_)->setMaskBit("k$_");
10066 PrintOutRegisterInHex "k$_";
10067 }
10068
10069 ClearRegisters k7;
10070
10071 LoadBitsIntoMaskRegister(k7, r15, '1010', -4, +4, -2, +2, -1, +1, -1, +1); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10072  
10073 PrintOutRegisterInHex "k7";
10074
10075 ok Assemble(debug => 0, eq => <<END);
10076 k0: 0000 0000 0000 0001
10077 k1: 0000 0000 0000 0002
10078 k2: 0000 0000 0000 0004
10079 k3: 0000 0000 0000 0008
10080 k4: 0000 0000 0000 0010
10081 k5: 0000 0000 0000 0020
10082 k6: 0000 0000 0000 0040
10083 k7: 0000 0000 0000 0080
10084 k7: 0000 0000 000A 0F35
10085 END
10086
10087  
10088 =head1 Structured Programming
10089  
10090 Structured programming constructs
10091  
10092 =head2 If($jump, $then, $else)
10093  
10094 If.
10095  
10096 Parameter Description
10097 1 $jump Jump op code of variable
10098 2 $then Then - required
10099 3 $else Else - optional
10100  
10101 B<Example:>
10102  
10103  
10104 my $c = K(one,1);
10105
10106 If ($c == 0, # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10107  
10108 Then
10109 {PrintOutStringNL "1 == 0";
10110 },
10111 Else
10112 {PrintOutStringNL "1 != 0";
10113 });
10114
10115 ok Assemble(debug => 0, eq => <<END);
10116 1 != 0
10117 END
10118
10119  
10120 =head2 Then($block)
10121  
10122 Then block for an If statement.
10123  
10124 Parameter Description
10125 1 $block Then block
10126  
10127 B<Example:>
10128  
10129  
10130 my $a = V(a, 3); $a->outNL;
10131 my $b = K(b, 2); $b->outNL;
10132 my $c = $a + $b; $c->outNL;
10133 my $d = $c - $a; $d->outNL;
10134 my $g = $a * $b; $g->outNL;
10135 my $h = $g / $b; $h->outNL;
10136 my $i = $a % $b; $i->outNL;
10137
10138 If ($a == 3,
10139
10140 Then # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10141  
10142 {PrintOutStringNL "a == 3"
10143 },
10144 Else
10145 {PrintOutStringNL "a != 3"
10146 });
10147
10148 ++$a; $a->outNL;
10149 --$a; $a->outNL;
10150
10151 ok Assemble(debug => 0, eq => <<END);
10152 a: 0000 0000 0000 0003
10153 b: 0000 0000 0000 0002
10154 (a add b): 0000 0000 0000 0005
10155 ((a add b) sub a): 0000 0000 0000 0002
10156 (a times b): 0000 0000 0000 0006
10157 ((a times b) / b): 0000 0000 0000 0003
10158 (a % b): 0000 0000 0000 0001
10159 a == 3
10160 a: 0000 0000 0000 0004
10161 a: 0000 0000 0000 0003
10162 END
10163
10164  
10165 =head2 Else($block)
10166  
10167 Else block for an If statement.
10168  
10169 Parameter Description
10170 1 $block Else block
10171  
10172 B<Example:>
10173  
10174  
10175 my $a = V(a, 3); $a->outNL;
10176 my $b = K(b, 2); $b->outNL;
10177 my $c = $a + $b; $c->outNL;
10178 my $d = $c - $a; $d->outNL;
10179 my $g = $a * $b; $g->outNL;
10180 my $h = $g / $b; $h->outNL;
10181 my $i = $a % $b; $i->outNL;
10182
10183 If ($a == 3,
10184 Then
10185 {PrintOutStringNL "a == 3"
10186 },
10187
10188 Else # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10189  
10190 {PrintOutStringNL "a != 3"
10191 });
10192
10193 ++$a; $a->outNL;
10194 --$a; $a->outNL;
10195
10196 ok Assemble(debug => 0, eq => <<END);
10197 a: 0000 0000 0000 0003
10198 b: 0000 0000 0000 0002
10199 (a add b): 0000 0000 0000 0005
10200 ((a add b) sub a): 0000 0000 0000 0002
10201 (a times b): 0000 0000 0000 0006
10202 ((a times b) / b): 0000 0000 0000 0003
10203 (a % b): 0000 0000 0000 0001
10204 a == 3
10205 a: 0000 0000 0000 0004
10206 a: 0000 0000 0000 0003
10207 END
10208
10209  
10210 =head2 Ef($condition, $then, $else)
10211  
10212 Else if block for an If statement.
10213  
10214 Parameter Description
10215 1 $condition Condition
10216 2 $then Then block
10217 3 $else Else block
10218  
10219 =head2 IfEq($then, $else)
10220  
10221 If equal execute the then block else the else block.
10222  
10223 Parameter Description
10224 1 $then Then - required
10225 2 $else Else - optional
10226  
10227 B<Example:>
10228  
10229  
10230 my $cmp = sub
10231 {my ($a, $b) = @_;
10232
10233 for my $op(qw(eq ne lt le gt ge))
10234 {Mov rax, $a;
10235 Cmp rax, $b;
10236 my $Op = ucfirst $op;
10237 eval qq(If$Op Then {PrintOutStringNL("$a $op $b")}, Else {PrintOutStringNL("$a NOT $op $b")});
10238 $@ and confess $@;
10239 }
10240 };
10241 &$cmp(1,1);
10242 &$cmp(1,2);
10243 &$cmp(3,2);
10244 Assemble(debug => 0, eq => <<END);
10245 1 eq 1
10246 1 NOT ne 1
10247 1 NOT lt 1
10248 1 le 1
10249 1 NOT gt 1
10250 1 ge 1
10251 1 NOT eq 2
10252 1 ne 2
10253 1 lt 2
10254 1 le 2
10255 1 NOT gt 2
10256 1 NOT ge 2
10257 3 NOT eq 2
10258 3 ne 2
10259 3 NOT lt 2
10260 3 NOT le 2
10261 3 gt 2
10262 3 ge 2
10263 END
10264
10265  
10266 =head2 IfNe($then, $else)
10267  
10268 If not equal execute the then block else the else block.
10269  
10270 Parameter Description
10271 1 $then Then - required
10272 2 $else Else - optional
10273  
10274 B<Example:>
10275  
10276  
10277 my $cmp = sub
10278 {my ($a, $b) = @_;
10279
10280 for my $op(qw(eq ne lt le gt ge))
10281 {Mov rax, $a;
10282 Cmp rax, $b;
10283 my $Op = ucfirst $op;
10284 eval qq(If$Op Then {PrintOutStringNL("$a $op $b")}, Else {PrintOutStringNL("$a NOT $op $b")});
10285 $@ and confess $@;
10286 }
10287 };
10288 &$cmp(1,1);
10289 &$cmp(1,2);
10290 &$cmp(3,2);
10291 Assemble(debug => 0, eq => <<END);
10292 1 eq 1
10293 1 NOT ne 1
10294 1 NOT lt 1
10295 1 le 1
10296 1 NOT gt 1
10297 1 ge 1
10298 1 NOT eq 2
10299 1 ne 2
10300 1 lt 2
10301 1 le 2
10302 1 NOT gt 2
10303 1 NOT ge 2
10304 3 NOT eq 2
10305 3 ne 2
10306 3 NOT lt 2
10307 3 NOT le 2
10308 3 gt 2
10309 3 ge 2
10310 END
10311
10312  
10313 =head2 IfNz($then, $else)
10314  
10315 If the zero flag is not set then execute the then block else the else block.
10316  
10317 Parameter Description
10318 1 $then Then - required
10319 2 $else Else - optional
10320  
10321 B<Example:>
10322  
10323  
10324 Mov rax, 0;
10325 Test rax,rax;
10326
10327 IfNz # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10328  
10329 Then
10330 {PrintOutRegisterInHex rax;
10331 },
10332 Else
10333 {PrintOutRegisterInHex rbx;
10334 };
10335 Mov rax, 1;
10336 Test rax,rax;
10337
10338 IfNz # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10339  
10340 Then
10341 {PrintOutRegisterInHex rcx;
10342 },
10343 Else
10344 {PrintOutRegisterInHex rdx;
10345 };
10346
10347 ok Assemble =~ m(rbx.*rcx)s;
10348
10349  
10350 =head2 IfZ($then, $else)
10351  
10352 If the zero flag is set then execute the then block else the else block.
10353  
10354 Parameter Description
10355 1 $then Then - required
10356 2 $else Else - optional
10357  
10358 B<Example:>
10359  
10360  
10361 SetZF;
10362 PrintOutZF;
10363 ClearZF;
10364 PrintOutZF;
10365 SetZF;
10366 PrintOutZF;
10367 SetZF;
10368 PrintOutZF;
10369 ClearZF;
10370 PrintOutZF;
10371
10372 SetZF;
10373
10374 IfZ Then {PrintOutStringNL "Zero"}, Else {PrintOutStringNL "NOT zero"}; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10375  
10376 ClearZF;
10377 IfNz Then {PrintOutStringNL "NOT zero"}, Else {PrintOutStringNL "Zero"};
10378
10379 Mov r15, 5;
10380 Shr r15, 1; IfC Then {PrintOutStringNL "Carry"} , Else {PrintOutStringNL "NO carry"};
10381 Shr r15, 1; IfC Then {PrintOutStringNL "Carry"} , Else {PrintOutStringNL "NO carry"};
10382 Shr r15, 1; IfNc Then {PrintOutStringNL "NO carry"}, Else {PrintOutStringNL "Carry"};
10383 Shr r15, 1; IfNc Then {PrintOutStringNL "NO carry"}, Else {PrintOutStringNL "Carry"};
10384
10385 ok Assemble(debug => 0, eq => <<END);
10386 ZF=1
10387 ZF=0
10388 ZF=1
10389 ZF=1
10390 ZF=0
10391 Zero
10392 NOT zero
10393 Carry
10394 NO carry
10395 Carry
10396 NO carry
10397 END
10398
10399  
10400 =head2 IfC($then, $else)
10401  
10402 If the carry flag is set then execute the then block else the else block.
10403  
10404 Parameter Description
10405 1 $then Then - required
10406 2 $else Else - optional
10407  
10408 B<Example:>
10409  
10410  
10411 SetZF;
10412 PrintOutZF;
10413 ClearZF;
10414 PrintOutZF;
10415 SetZF;
10416 PrintOutZF;
10417 SetZF;
10418 PrintOutZF;
10419 ClearZF;
10420 PrintOutZF;
10421
10422 SetZF;
10423 IfZ Then {PrintOutStringNL "Zero"}, Else {PrintOutStringNL "NOT zero"};
10424 ClearZF;
10425 IfNz Then {PrintOutStringNL "NOT zero"}, Else {PrintOutStringNL "Zero"};
10426
10427 Mov r15, 5;
10428
10429 Shr r15, 1; IfC Then {PrintOutStringNL "Carry"} , Else {PrintOutStringNL "NO carry"}; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10430  
10431
10432 Shr r15, 1; IfC Then {PrintOutStringNL "Carry"} , Else {PrintOutStringNL "NO carry"}; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10433  
10434 Shr r15, 1; IfNc Then {PrintOutStringNL "NO carry"}, Else {PrintOutStringNL "Carry"};
10435 Shr r15, 1; IfNc Then {PrintOutStringNL "NO carry"}, Else {PrintOutStringNL "Carry"};
10436
10437 ok Assemble(debug => 0, eq => <<END);
10438 ZF=1
10439 ZF=0
10440 ZF=1
10441 ZF=1
10442 ZF=0
10443 Zero
10444 NOT zero
10445 Carry
10446 NO carry
10447 Carry
10448 NO carry
10449 END
10450
10451  
10452 =head2 IfNc($then, $else)
10453  
10454 If the carry flag is not set then execute the then block else the else block.
10455  
10456 Parameter Description
10457 1 $then Then - required
10458 2 $else Else - optional
10459  
10460 B<Example:>
10461  
10462  
10463 SetZF;
10464 PrintOutZF;
10465 ClearZF;
10466 PrintOutZF;
10467 SetZF;
10468 PrintOutZF;
10469 SetZF;
10470 PrintOutZF;
10471 ClearZF;
10472 PrintOutZF;
10473
10474 SetZF;
10475 IfZ Then {PrintOutStringNL "Zero"}, Else {PrintOutStringNL "NOT zero"};
10476 ClearZF;
10477 IfNz Then {PrintOutStringNL "NOT zero"}, Else {PrintOutStringNL "Zero"};
10478
10479 Mov r15, 5;
10480 Shr r15, 1; IfC Then {PrintOutStringNL "Carry"} , Else {PrintOutStringNL "NO carry"};
10481 Shr r15, 1; IfC Then {PrintOutStringNL "Carry"} , Else {PrintOutStringNL "NO carry"};
10482
10483 Shr r15, 1; IfNc Then {PrintOutStringNL "NO carry"}, Else {PrintOutStringNL "Carry"}; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10484  
10485
10486 Shr r15, 1; IfNc Then {PrintOutStringNL "NO carry"}, Else {PrintOutStringNL "Carry"}; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10487  
10488
10489 ok Assemble(debug => 0, eq => <<END);
10490 ZF=1
10491 ZF=0
10492 ZF=1
10493 ZF=1
10494 ZF=0
10495 Zero
10496 NOT zero
10497 Carry
10498 NO carry
10499 Carry
10500 NO carry
10501 END
10502
10503  
10504 =head2 IfLt($then, $else)
10505  
10506 If less than execute the then block else the else block.
10507  
10508 Parameter Description
10509 1 $then Then - required
10510 2 $else Else - optional
10511  
10512 B<Example:>
10513  
10514  
10515 my $cmp = sub
10516 {my ($a, $b) = @_;
10517
10518 for my $op(qw(eq ne lt le gt ge))
10519 {Mov rax, $a;
10520 Cmp rax, $b;
10521 my $Op = ucfirst $op;
10522 eval qq(If$Op Then {PrintOutStringNL("$a $op $b")}, Else {PrintOutStringNL("$a NOT $op $b")});
10523 $@ and confess $@;
10524 }
10525 };
10526 &$cmp(1,1);
10527 &$cmp(1,2);
10528 &$cmp(3,2);
10529 Assemble(debug => 0, eq => <<END);
10530 1 eq 1
10531 1 NOT ne 1
10532 1 NOT lt 1
10533 1 le 1
10534 1 NOT gt 1
10535 1 ge 1
10536 1 NOT eq 2
10537 1 ne 2
10538 1 lt 2
10539 1 le 2
10540 1 NOT gt 2
10541 1 NOT ge 2
10542 3 NOT eq 2
10543 3 ne 2
10544 3 NOT lt 2
10545 3 NOT le 2
10546 3 gt 2
10547 3 ge 2
10548 END
10549
10550  
10551 =head2 IfLe($then, $else)
10552  
10553 If less than or equal execute the then block else the else block.
10554  
10555 Parameter Description
10556 1 $then Then - required
10557 2 $else Else - optional
10558  
10559 B<Example:>
10560  
10561  
10562 my $cmp = sub
10563 {my ($a, $b) = @_;
10564
10565 for my $op(qw(eq ne lt le gt ge))
10566 {Mov rax, $a;
10567 Cmp rax, $b;
10568 my $Op = ucfirst $op;
10569 eval qq(If$Op Then {PrintOutStringNL("$a $op $b")}, Else {PrintOutStringNL("$a NOT $op $b")});
10570 $@ and confess $@;
10571 }
10572 };
10573 &$cmp(1,1);
10574 &$cmp(1,2);
10575 &$cmp(3,2);
10576 Assemble(debug => 0, eq => <<END);
10577 1 eq 1
10578 1 NOT ne 1
10579 1 NOT lt 1
10580 1 le 1
10581 1 NOT gt 1
10582 1 ge 1
10583 1 NOT eq 2
10584 1 ne 2
10585 1 lt 2
10586 1 le 2
10587 1 NOT gt 2
10588 1 NOT ge 2
10589 3 NOT eq 2
10590 3 ne 2
10591 3 NOT lt 2
10592 3 NOT le 2
10593 3 gt 2
10594 3 ge 2
10595 END
10596
10597  
10598 =head2 IfGt($then, $else)
10599  
10600 If greater than execute the then block else the else block.
10601  
10602 Parameter Description
10603 1 $then Then - required
10604 2 $else Else - optional
10605  
10606 B<Example:>
10607  
10608  
10609 my $cmp = sub
10610 {my ($a, $b) = @_;
10611
10612 for my $op(qw(eq ne lt le gt ge))
10613 {Mov rax, $a;
10614 Cmp rax, $b;
10615 my $Op = ucfirst $op;
10616 eval qq(If$Op Then {PrintOutStringNL("$a $op $b")}, Else {PrintOutStringNL("$a NOT $op $b")});
10617 $@ and confess $@;
10618 }
10619 };
10620 &$cmp(1,1);
10621 &$cmp(1,2);
10622 &$cmp(3,2);
10623 Assemble(debug => 0, eq => <<END);
10624 1 eq 1
10625 1 NOT ne 1
10626 1 NOT lt 1
10627 1 le 1
10628 1 NOT gt 1
10629 1 ge 1
10630 1 NOT eq 2
10631 1 ne 2
10632 1 lt 2
10633 1 le 2
10634 1 NOT gt 2
10635 1 NOT ge 2
10636 3 NOT eq 2
10637 3 ne 2
10638 3 NOT lt 2
10639 3 NOT le 2
10640 3 gt 2
10641 3 ge 2
10642 END
10643
10644  
10645 =head2 IfGe($then, $else)
10646  
10647 If greater than or equal execute the then block else the else block.
10648  
10649 Parameter Description
10650 1 $then Then - required
10651 2 $else Else - optional
10652  
10653 B<Example:>
10654  
10655  
10656 my $cmp = sub
10657 {my ($a, $b) = @_;
10658
10659 for my $op(qw(eq ne lt le gt ge))
10660 {Mov rax, $a;
10661 Cmp rax, $b;
10662 my $Op = ucfirst $op;
10663 eval qq(If$Op Then {PrintOutStringNL("$a $op $b")}, Else {PrintOutStringNL("$a NOT $op $b")});
10664 $@ and confess $@;
10665 }
10666 };
10667 &$cmp(1,1);
10668 &$cmp(1,2);
10669 &$cmp(3,2);
10670 Assemble(debug => 0, eq => <<END);
10671 1 eq 1
10672 1 NOT ne 1
10673 1 NOT lt 1
10674 1 le 1
10675 1 NOT gt 1
10676 1 ge 1
10677 1 NOT eq 2
10678 1 ne 2
10679 1 lt 2
10680 1 le 2
10681 1 NOT gt 2
10682 1 NOT ge 2
10683 3 NOT eq 2
10684 3 ne 2
10685 3 NOT lt 2
10686 3 NOT le 2
10687 3 gt 2
10688 3 ge 2
10689 END
10690
10691  
10692 =head2 Pass($block)
10693  
10694 Pass block for an L<OrBlock>.
10695  
10696 Parameter Description
10697 1 $block Block
10698  
10699 B<Example:>
10700  
10701  
10702 Mov rax, 1;
10703 OrBlock
10704 {my ($pass, $end, $start) = @_;
10705 Cmp rax, 1;
10706 Je $pass;
10707 Cmp rax, 2;
10708 Je $pass;
10709 PrintOutStringNL "Fail";
10710 }
10711
10712 Pass # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10713  
10714 {my ($end, $pass, $start) = @_;
10715
10716 PrintOutStringNL "Pass"; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10717  
10718 };
10719
10720 ok Assemble(debug => 0, eq => <<END);
10721
10722 Pass # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10723  
10724 END
10725
10726  
10727 =head2 Fail($block)
10728  
10729 Fail block for an L<AndBlock>.
10730  
10731 Parameter Description
10732 1 $block Block
10733  
10734 B<Example:>
10735  
10736  
10737 Mov rax, 1; Mov rdx, 2;
10738 AndBlock
10739 {my ($fail, $end, $start) = @_;
10740 Cmp rax, 1;
10741 Jne $fail;
10742 Cmp rdx, 2;
10743 Jne $fail;
10744 PrintOutStringNL "Pass";
10745 }
10746
10747 Fail # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10748  
10749 {my ($end, $fail, $start) = @_;
10750
10751 PrintOutStringNL "Fail"; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10752  
10753 };
10754
10755 ok Assemble(debug => 0, eq => <<END);
10756 Pass
10757 END
10758
10759  
10760 =head2 AndBlock($test, $fail)
10761  
10762 Short circuit B<and>: execute a block of code to test conditions which, if all of them pass, allows the first block to continue successfully else if one of the conditions fails we execute the optional fail block.
10763  
10764 Parameter Description
10765 1 $test Block
10766 2 $fail Optional failure block
10767  
10768 B<Example:>
10769  
10770  
10771 Mov rax, 1; Mov rdx, 2;
10772
10773 AndBlock # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10774  
10775 {my ($fail, $end, $start) = @_;
10776 Cmp rax, 1;
10777 Jne $fail;
10778 Cmp rdx, 2;
10779 Jne $fail;
10780 PrintOutStringNL "Pass";
10781 }
10782 Fail
10783 {my ($end, $fail, $start) = @_;
10784 PrintOutStringNL "Fail";
10785 };
10786
10787 ok Assemble(debug => 0, eq => <<END);
10788 Pass
10789 END
10790
10791  
10792 =head2 OrBlock($test, $pass)
10793  
10794 Short circuit B<or>: execute a block of code to test conditions which, if one of them is met, leads on to the execution of the pass block, if all of the tests fail we continue withe the test block.
10795  
10796 Parameter Description
10797 1 $test Tests
10798 2 $pass Optional block to execute on success
10799  
10800 B<Example:>
10801  
10802  
10803 Mov rax, 1;
10804
10805 OrBlock # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10806  
10807 {my ($pass, $end, $start) = @_;
10808 Cmp rax, 1;
10809 Je $pass;
10810 Cmp rax, 2;
10811 Je $pass;
10812 PrintOutStringNL "Fail";
10813 }
10814 Pass
10815 {my ($end, $pass, $start) = @_;
10816 PrintOutStringNL "Pass";
10817 };
10818
10819 ok Assemble(debug => 0, eq => <<END);
10820 Pass
10821 END
10822
10823  
10824 =head2 For($block, $register, $limit, $increment)
10825  
10826 For - iterate the block as long as register is less than limit incrementing by increment each time. Nota Bene: The register is not explicitly set to zero as you might want to start at some other number.
10827  
10828 Parameter Description
10829 1 $block Block
10830 2 $register Register
10831 3 $limit Limit on loop
10832 4 $increment Increment on each iteration
10833  
10834 B<Example:>
10835  
10836  
10837
10838 For # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10839  
10840 {my ($start, $end, $next) = @_;
10841 Cmp rax, 3;
10842 Jge $end;
10843 PrintOutRegisterInHex rax;
10844 } rax, 16, 1;
10845
10846 ok Assemble(debug => 0, eq => <<END);
10847 rax: 0000 0000 0000 0000
10848 rax: 0000 0000 0000 0001
10849 rax: 0000 0000 0000 0002
10850 END
10851
10852  
10853 =head2 ForIn($full, $last, $register, $limitRegister, $increment)
10854  
10855 For - iterate the full block as long as register plus increment is less than than limit incrementing by increment each time then increment the last block for the last non full block.
10856  
10857 Parameter Description
10858 1 $full Block for full block
10859 2 $last Block for last block
10860 3 $register Register
10861 4 $limitRegister Register containing upper limit of loop
10862 5 $increment Increment on each iteration
10863  
10864 =head2 ForEver($block)
10865  
10866 Iterate for ever.
10867  
10868 Parameter Description
10869 1 $block Block to iterate
10870  
10871 =head2 Macro($block, %options)
10872  
10873 Create a sub with optional parameters name=> the name of the subroutine so it can be reused rather than regenerated, comment=> a comment describing the sub.
10874  
10875 Parameter Description
10876 1 $block Block
10877 2 %options Options.
10878  
10879 =head2 Call
10880  
10881 Call a subroutine
10882  
10883 =head3 SubroutineStartStack()
10884  
10885 Initialize a new stack frame. The first quad of each frame has the address of the name of the sub in the low dword, and the parameter count in the upper byte of the quad. This field is all zeroes in the initial frame.
10886  
10887  
10888 =head3 Subroutine($block, $parameters, %options)
10889  
10890 Create a subroutine that can be called in assembler code.
10891  
10892 Parameter Description
10893 1 $block Block
10894 2 $parameters [parameters names]
10895 3 %options Options.
10896  
10897 B<Example:>
10898  
10899  
10900 my $g = G g, 3;
10901
10902 my $s = Subroutine # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10903  
10904 {my ($p, $s) = @_;
10905 $g->copy($g - 1);
10906 $g->outNL;
10907 If ($g > 0,
10908 Then
10909 {$s->call;
10910 });
10911 } [], name => 'ref';
10912
10913 $s->call;
10914
10915 ok Assemble(debug => 0, eq => <<END);
10916 g: 0000 0000 0000 0002
10917 g: 0000 0000 0000 0001
10918 g: 0000 0000 0000 0000
10919 END
10920
10921 my $g = G g, 2;
10922
10923 my $u = Subroutine # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10924  
10925 {my ($p, $s) = @_;
10926 PrintOutTraceBack;
10927 $$p{g}->copy(K gg, 1);
10928 PrintOutTraceBack;
10929 } [qw(g)], name => 'uuuu';
10930
10931 my $t = Subroutine # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10932  
10933 {my ($p, $s) = @_;
10934 $u->call($$p{g});
10935 } [qw(g)], name => 'tttt';
10936
10937 my $s = Subroutine # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10938  
10939 {my ($p, $s) = @_;
10940 $t->call($$p{g});
10941 } [qw(g)], name => 'ssss';
10942
10943 $g->outNL;
10944 $s->call($g);
10945 $g->outNL;
10946
10947 ok Assemble(debug => 0, eq => <<END);
10948 g: 0000 0000 0000 0002
10949
10950
10951 Subroutine trace back, depth: 0000 0000 0000 0003 # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10952  
10953 0000 0000 0000 0002 uuuu
10954 0000 0000 0000 0002 tttt
10955 0000 0000 0000 0002 ssss
10956
10957
10958
10959 Subroutine trace back, depth: 0000 0000 0000 0003 # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10960  
10961 0000 0000 0000 0001 uuuu
10962 0000 0000 0000 0001 tttt
10963 0000 0000 0000 0001 ssss
10964
10965 g: 0000 0000 0000 0001
10966 END
10967
10968 my $r = G r, 2;
10969
10970
10971 my $u = Subroutine # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10972  
10973 {my ($p, $s) = @_;
10974 PrintOutTraceBack;
10975 $$p{u}->copy(K gg, 1);
10976 PrintOutTraceBack;
10977 } [qw(u)], name => 'uuuu';
10978
10979
10980 my $t = Subroutine # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10981  
10982 {my ($p, $s) = @_;
10983 $u->call(u => $$p{t});
10984 } [qw(t)], name => 'tttt';
10985
10986
10987 my $s = Subroutine # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10988  
10989 {my ($p, $s) = @_;
10990 $t->call(t => $$p{s});
10991 } [qw(s)], name => 'ssss';
10992
10993 $r->outNL;
10994 $s->call(s=>$r);
10995 $r->outNL;
10996
10997 ok Assemble(debug => 0, eq => <<END);
10998 r: 0000 0000 0000 0002
10999
11000
11001 Subroutine trace back, depth: 0000 0000 0000 0003 # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11002  
11003 0000 0000 0000 0002 uuuu
11004 0000 0000 0000 0002 tttt
11005 0000 0000 0000 0002 ssss
11006
11007
11008
11009 Subroutine trace back, depth: 0000 0000 0000 0003 # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11010  
11011 0000 0000 0000 0001 uuuu
11012 0000 0000 0000 0001 tttt
11013 0000 0000 0000 0001 ssss
11014
11015 r: 0000 0000 0000 0001
11016 END
11017
11018  
11019 =head3 Nasm::X86::Sub::call($sub, @parameters)
11020  
11021 Call a sub passing it some parameters.
11022  
11023 Parameter Description
11024 1 $sub Subroutine descriptor
11025 2 @parameters Parameter variables
11026  
11027 B<Example:>
11028  
11029  
11030 my $s = Subroutine
11031 {my ($p) = @_;
11032 $$p{in}->outNL;
11033 } [qw(in)], name => 'sss';
11034
11035 my $t = Subroutine
11036 {my ($p) = @_;
11037 $s->call($$p{in});
11038 } [qw(in)], name => 'ttt';
11039
11040 my $c = Subroutine
11041 {my ($p) = @_;
11042 $t->via($$p{call}, $$p{in});
11043 } [qw(call in)], name => 'ccc';
11044
11045 $c->call($t->V, V(in, 42));
11046
11047 ok Assemble(debug => 0, eq => <<END);
11048 in: 0000 0000 0000 002A
11049 END
11050
11051  
11052 =head3 Nasm::X86::Sub::via($sub, $ref, @parameters)
11053  
11054 Call a sub by reference passing it some parameters.
11055  
11056 Parameter Description
11057 1 $sub Subroutine descriptor
11058 2 $ref Variable containing a reference to the sub
11059 3 @parameters Parameter variables
11060  
11061 B<Example:>
11062  
11063  
11064 my $s = Subroutine
11065 {my ($p) = @_;
11066 $$p{in}->outNL;
11067 } [qw(in)], name => 'sss';
11068
11069 my $t = Subroutine
11070 {my ($p) = @_;
11071 $s->call($$p{in});
11072 } [qw(in)], name => 'ttt';
11073
11074 my $c = Subroutine
11075 {my ($p) = @_;
11076 $t->via($$p{call}, $$p{in});
11077 } [qw(call in)], name => 'ccc';
11078
11079 $c->call($t->V, V(in, 42));
11080
11081 ok Assemble(debug => 0, eq => <<END);
11082 in: 0000 0000 0000 002A
11083 END
11084
11085  
11086 =head3 Nasm::X86::Sub::V($sub)
11087  
11088 Put the address of a subroutine into a stack variable so that it can be passed as a parameter.
11089  
11090 Parameter Description
11091 1 $sub Subroutine descriptor
11092  
11093 =head3 PrintTraceBack($channel)
11094  
11095 Trace the call stack.
11096  
11097 Parameter Description
11098 1 $channel Channel to write on
11099  
11100 =head3 PrintErrTraceBack()
11101  
11102 Print sub routine track back on stderr.
11103  
11104  
11105 =head3 PrintOutTraceBack()
11106  
11107 Print sub routine track back on stdout.
11108  
11109  
11110 B<Example:>
11111  
11112  
11113 my $d = V depth, 3; # Create a variable on the stack
11114
11115 my $s = Subroutine
11116 {my ($p, $s) = @_; # Parameters, subroutine descriptor
11117
11118 PrintOutTraceBack; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11119  
11120
11121 my $d = $$p{depth}->copy($$p{depth} - 1); # Modify the variable referenced by the parameter
11122
11123 If ($d > 0,
11124 Then
11125 {$s->call($d); # Recurse
11126 });
11127
11128
11129 PrintOutTraceBack; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11130  
11131 } [qw(depth)], name => 'ref';
11132
11133 $s->call($d); # Call the subroutine
11134
11135 ok Assemble(debug => 0, eq => <<END);
11136
11137 Subroutine trace back, depth: 0000 0000 0000 0001
11138 0000 0000 0000 0003 ref
11139
11140
11141 Subroutine trace back, depth: 0000 0000 0000 0002
11142 0000 0000 0000 0002 ref
11143 0000 0000 0000 0002 ref
11144
11145
11146 Subroutine trace back, depth: 0000 0000 0000 0003
11147 0000 0000 0000 0001 ref
11148 0000 0000 0000 0001 ref
11149 0000 0000 0000 0001 ref
11150
11151
11152 Subroutine trace back, depth: 0000 0000 0000 0003
11153 0000 0000 0000 0000 ref
11154 0000 0000 0000 0000 ref
11155 0000 0000 0000 0000 ref
11156
11157
11158 Subroutine trace back, depth: 0000 0000 0000 0002
11159 0000 0000 0000 0000 ref
11160 0000 0000 0000 0000 ref
11161
11162
11163 Subroutine trace back, depth: 0000 0000 0000 0001
11164 0000 0000 0000 0000 ref
11165
11166 END
11167
11168  
11169 =head3 OnSegv()
11170  
11171 Request a trace back followed by exit on a B<segv> signal.
11172  
11173  
11174 B<Example:>
11175  
11176  
11177
11178 OnSegv(); # Request a trace back followed by exit on a segv signal. # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11179  
11180
11181 my $t = Subroutine # Subroutine that will cause an error to occur to force a trace back to be printed
11182 {Mov r15, 0;
11183 Mov r15, "[r15]"; # Try to read an unmapped memory location
11184 } [qw(in)], name => 'sub that causes a segv'; # The name that will appear in the trace back
11185
11186 $t->call(K(in, 42));
11187
11188 ok Assemble(debug => 0, keep2 => 'signal', emulator=>0, eq => <<END); # Cannot use the emulator because it does not understand signals
11189
11190 Subroutine trace back, depth: 0000 0000 0000 0001
11191 0000 0000 0000 002A sub that causes a segv
11192
11193 END
11194
11195  
11196 =head3 cr($block, @registers)
11197  
11198 Call a subroutine with a reordering of the registers.
11199  
11200 Parameter Description
11201 1 $block Code to execute with reordered registers
11202 2 @registers Registers to reorder
11203  
11204 =head1 Comments
11205  
11206 Inserts comments into the generated assember code.
11207  
11208 =head2 CommentWithTraceBack(@comment)
11209  
11210 Insert a comment into the assembly code with a traceback showing how it was generated.
11211  
11212 Parameter Description
11213 1 @comment Text of comment
11214  
11215 =head2 Comment(@comment)
11216  
11217 Insert a comment into the assembly code.
11218  
11219 Parameter Description
11220 1 @comment Text of comment
11221  
11222 B<Example:>
11223  
11224  
11225
11226 Comment "Print a string from memory"; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11227  
11228 my $s = "Hello World";
11229 Mov rax, Rs($s);
11230 Mov rdi, length $s;
11231 PrintOutMemory;
11232 Exit(0);
11233
11234 ok Assemble =~ m(Hello World);
11235
11236  
11237 =head2 DComment(@comment)
11238  
11239 Insert a comment into the data segment.
11240  
11241 Parameter Description
11242 1 @comment Text of comment
11243  
11244 =head2 RComment(@comment)
11245  
11246 Insert a comment into the read only data segment.
11247  
11248 Parameter Description
11249 1 @comment Text of comment
11250  
11251 =head1 Print
11252  
11253 Print
11254  
11255 =head2 PrintNL($channel)
11256  
11257 Print a new line to stdout or stderr.
11258  
11259 Parameter Description
11260 1 $channel Channel to write on
11261  
11262 =head2 PrintErrNL()
11263  
11264 Print a new line to stderr.
11265  
11266  
11267 =head2 PrintOutNL()
11268  
11269 Print a new line to stderr.
11270  
11271  
11272 B<Example:>
11273  
11274  
11275 my $q = Rs('abababab');
11276 Mov(rax, "[$q]");
11277 PrintOutString "rax: ";
11278 PrintOutRaxInHex;
11279
11280 PrintOutNL; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11281  
11282 Xor rax, rax;
11283 PrintOutString "rax: ";
11284 PrintOutRaxInHex;
11285
11286 PrintOutNL; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11287  
11288
11289 ok Assemble =~ m(rax: 6261 6261 6261 6261.*rax: 0000 0000 0000 0000)s;
11290
11291  
11292 =head2 PrintString($channel, @string)
11293  
11294 Print a constant string to the specified channel.
11295  
11296 Parameter Description
11297 1 $channel Channel
11298 2 @string Strings
11299  
11300 =head2 PrintStringNL($channel, @string)
11301  
11302 Print a constant string to the specified channel followed by a new line.
11303  
11304 Parameter Description
11305 1 $channel Channel
11306 2 @string Strings
11307  
11308 =head2 PrintErrString(@string)
11309  
11310 Print a constant string to stderr.
11311  
11312 Parameter Description
11313 1 @string String
11314  
11315 =head2 PrintOutString(@string)
11316  
11317 Print a constant string to stdout.
11318  
11319 Parameter Description
11320 1 @string String
11321  
11322 B<Example:>
11323  
11324  
11325 my $q = Rs('abababab');
11326 Mov(rax, "[$q]");
11327
11328 PrintOutString "rax: "; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11329  
11330 PrintOutRaxInHex;
11331 PrintOutNL;
11332 Xor rax, rax;
11333
11334 PrintOutString "rax: "; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11335  
11336 PrintOutRaxInHex;
11337 PrintOutNL;
11338
11339 ok Assemble =~ m(rax: 6261 6261 6261 6261.*rax: 0000 0000 0000 0000)s;
11340
11341  
11342 =head2 PrintSpace($channel, $spaces)
11343  
11344 Print one or more spaces to the specified channel.
11345  
11346 Parameter Description
11347 1 $channel Channel
11348 2 $spaces Number of spaces if not one.
11349  
11350 =head2 PrintErrSpace($spaces)
11351  
11352 Print one or more spaces to stderr.
11353  
11354 Parameter Description
11355 1 $spaces Number of spaces if not one.
11356  
11357 =head2 PrintOutSpace($spaces)
11358  
11359 Print one or more spaces to stdout.
11360  
11361 Parameter Description
11362 1 $spaces Number of spaces if not one.
11363  
11364 =head2 PrintErrStringNL(@string)
11365  
11366 Print a constant string followed by a new line to stderr.
11367  
11368 Parameter Description
11369 1 @string Strings
11370  
11371 B<Example:>
11372  
11373  
11374 PrintOutStringNL "Hello World";
11375 PrintOutStringNL "Hello
11376 World";
11377
11378 PrintErrStringNL "Hello World"; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11379  
11380
11381 ok Assemble(debug => 0, eq => <<END);
11382 Hello World
11383 Hello
11384 World
11385 END
11386
11387  
11388 =head2 PrintOutStringNL(@string)
11389  
11390 Print a constant string followed by a new line to stdout.
11391  
11392 Parameter Description
11393 1 @string Strings
11394  
11395 B<Example:>
11396  
11397  
11398
11399 PrintOutStringNL "Hello World"; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11400  
11401
11402 PrintOutStringNL "Hello
11403 World"; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11404  
11405 PrintErrStringNL "Hello World";
11406
11407 ok Assemble(debug => 0, eq => <<END);
11408 Hello World
11409 Hello
11410 World
11411 END
11412
11413  
11414 =head2 PrintRaxInHex($channel, $end)
11415  
11416 Write the content of register rax in hexadecimal in big endian notation to the specified channel.
11417  
11418 Parameter Description
11419 1 $channel Channel
11420 2 $end Optional end byte
11421  
11422 =head2 PrintErrRaxInHex()
11423  
11424 Write the content of register rax in hexadecimal in big endian notation to stderr.
11425  
11426  
11427 =head2 PrintOutRaxInHex()
11428  
11429 Write the content of register rax in hexadecimal in big endian notation to stderr.
11430  
11431  
11432 B<Example:>
11433  
11434  
11435 my $q = Rs('abababab');
11436 Mov(rax, "[$q]");
11437 PrintOutString "rax: ";
11438
11439 PrintOutRaxInHex; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11440  
11441 PrintOutNL;
11442 Xor rax, rax;
11443 PrintOutString "rax: ";
11444
11445 PrintOutRaxInHex; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11446  
11447 PrintOutNL;
11448
11449 ok Assemble =~ m(rax: 6261 6261 6261 6261.*rax: 0000 0000 0000 0000)s;
11450
11451  
11452 =head2 PrintOutRaxInReverseInHex()
11453  
11454 Write the content of register rax to stderr in hexadecimal in little endian notation.
11455  
11456  
11457 B<Example:>
11458  
11459  
11460 Mov rax, 0x07654321;
11461 Shl rax, 32;
11462 Or rax, 0x07654321;
11463 PushR rax;
11464
11465 PrintOutRaxInHex;
11466 PrintOutNL;
11467
11468 PrintOutRaxInReverseInHex; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11469  
11470 PrintOutNL;
11471
11472 Mov rax, rsp;
11473 Mov rdi, 8;
11474 PrintOutMemoryInHex;
11475 PrintOutNL;
11476 PopR rax;
11477
11478 Mov rax, 4096;
11479 PushR rax;
11480 Mov rax, rsp;
11481 Mov rdi, 8;
11482 PrintOutMemoryInHex;
11483 PrintOutNL;
11484 PopR rax;
11485
11486 ok Assemble(debug => 0, eq => <<END);
11487 0765 4321 0765 4321
11488 2143 6507 2143 6507
11489 2143 6507 2143 6507
11490 0010 0000 0000 0000
11491 END
11492
11493  
11494 =head2 PrintOneRegisterInHex($channel, $r)
11495  
11496 Print the named register as a hex strings.
11497  
11498 Parameter Description
11499 1 $channel Channel to print on
11500 2 $r Register to print
11501  
11502 =head2 PrintRegisterInHex($channel, @r)
11503  
11504 Print the named registers as hex strings.
11505  
11506 Parameter Description
11507 1 $channel Channel to print on
11508 2 @r Names of the registers to print
11509  
11510 =head2 PrintErrRegisterInHex(@r)
11511  
11512 Print the named registers as hex strings on stderr.
11513  
11514 Parameter Description
11515 1 @r Names of the registers to print
11516  
11517 =head2 PrintOutRegisterInHex(@r)
11518  
11519 Print the named registers as hex strings on stdout.
11520  
11521 Parameter Description
11522 1 @r Names of the registers to print
11523  
11524 B<Example:>
11525  
11526  
11527 my $q = Rs(('a'..'p')x4);
11528 Mov r8,"[$q]";
11529
11530 PrintOutRegisterInHex r8; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11531  
11532
11533 ok Assemble(debug => 0, eq => <<END);
11534 r8: 6867 6665 6463 6261
11535 END
11536
11537  
11538 =head2 PrintOutRegistersInHex()
11539  
11540 Print the general purpose registers in hex.
11541  
11542  
11543 B<Example:>
11544  
11545  
11546 my $q = Rs('abababab');
11547 Mov(rax, 1);
11548 Mov(rbx, 2);
11549 Mov(rcx, 3);
11550 Mov(rdx, 4);
11551 Mov(r8, 5);
11552 Lea r9, "[rax+rbx]";
11553
11554 PrintOutRegistersInHex; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11555  
11556
11557 my $r = Assemble;
11558 ok $r =~ m( r8: 0000 0000 0000 0005.* r9: 0000 0000 0000 0003.*rax: 0000 0000 0000 0001)s;
11559 ok $r =~ m(rbx: 0000 0000 0000 0002.*rcx: 0000 0000 0000 0003.*rdx: 0000 0000 0000 0004)s;
11560
11561  
11562 =head2 PrintErrZF()
11563  
11564 Print the zero flag without disturbing it on stderr.
11565  
11566  
11567 =head2 PrintOutZF()
11568  
11569 Print the zero flag without disturbing it on stdout.
11570  
11571  
11572 B<Example:>
11573  
11574  
11575 SetZF;
11576
11577 PrintOutZF; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11578  
11579 ClearZF;
11580
11581 PrintOutZF; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11582  
11583 SetZF;
11584
11585 PrintOutZF; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11586  
11587 SetZF;
11588
11589 PrintOutZF; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11590  
11591 ClearZF;
11592
11593 PrintOutZF; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11594  
11595
11596 SetZF;
11597 IfZ Then {PrintOutStringNL "Zero"}, Else {PrintOutStringNL "NOT zero"};
11598 ClearZF;
11599 IfNz Then {PrintOutStringNL "NOT zero"}, Else {PrintOutStringNL "Zero"};
11600
11601 Mov r15, 5;
11602 Shr r15, 1; IfC Then {PrintOutStringNL "Carry"} , Else {PrintOutStringNL "NO carry"};
11603 Shr r15, 1; IfC Then {PrintOutStringNL "Carry"} , Else {PrintOutStringNL "NO carry"};
11604 Shr r15, 1; IfNc Then {PrintOutStringNL "NO carry"}, Else {PrintOutStringNL "Carry"};
11605 Shr r15, 1; IfNc Then {PrintOutStringNL "NO carry"}, Else {PrintOutStringNL "Carry"};
11606
11607 ok Assemble(debug => 0, eq => <<END);
11608 ZF=1
11609 ZF=0
11610 ZF=1
11611 ZF=1
11612 ZF=0
11613 Zero
11614 NOT zero
11615 Carry
11616 NO carry
11617 Carry
11618 NO carry
11619 END
11620
11621  
11622 =head2 PrintUtf8Char($channel)
11623  
11624 Print the utf 8 character addressed by rax to the specified channel. The character must be in little endian form.
11625  
11626 Parameter Description
11627 1 $channel Channel
11628  
11629 =head2 PrintErrUtf8Char()
11630  
11631 Print the utf 8 character addressed by rax to stderr.
11632  
11633  
11634 =head2 PrintOutUtf8Char()
11635  
11636 Print the utf 8 character addressed by rax to stdout.
11637  
11638  
11639 B<Example:>
11640  
11641  
11642 my $u = Rd(convertUtf32ToUtf8LE(ord('α')));
11643 Mov rax, $u;
11644
11645 PrintOutUtf8Char; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11646  
11647 PrintOutNL;
11648
11649 ok Assemble(debug => 0, trace => 0, eq => <<END);
11650 α
11651 END
11652
11653  
11654 =head2 PrintErrUtf32($size, $address)
11655  
11656 Print the utf 8 character addressed by rax to stderr.
11657  
11658 Parameter Description
11659 1 $size Variable: number of characters to print
11660 2 $address Variable: address of memory
11661  
11662 =head2 PrintOutUtf32($size, $address)
11663  
11664 Print the utf 8 character addressed by rax to stdout.
11665  
11666 Parameter Description
11667 1 $size Variable: number of characters to print
11668 2 $address Variable: address of memory
11669  
11670 =head1 Variables
11671  
11672 Variable definitions and operations
11673  
11674 =head2 Definitions
11675  
11676 Variable definitions
11677  
11678 =head3 Variable($name, $expr, %options)
11679  
11680 Create a new variable with the specified name initialized via an optional expression.
11681  
11682 Parameter Description
11683 1 $name Name of variable
11684 2 $expr Optional expression initializing variable
11685 3 %options Options
11686  
11687 =head3 G($name, $expr, %options)
11688  
11689 Define a global variable.
11690  
11691 Parameter Description
11692 1 $name Name of variable
11693 2 $expr Initializing expression
11694 3 %options Options
11695  
11696 B<Example:>
11697  
11698  
11699 my $s = Subroutine
11700 {my ($p) = @_;
11701 $$p{v}->copy($$p{v} + $$p{k} + $$p{g} + 1);
11702 } [qw(v k g)], name => 'add';
11703
11704 my $v = V(v, 1);
11705 my $k = K(k, 2);
11706
11707 my $g = G(g, 3); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11708  
11709 $s->call($v, $k, $g);
11710 $v->outNL;
11711
11712 ok Assemble(debug => 0, eq => <<END);
11713 v: 0000 0000 0000 0007
11714 END
11715
11716
11717 my $g = G g, 0; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11718  
11719 my $s = Subroutine
11720 {my ($p) = @_;
11721 $$p{g}->copy(K value, 1);
11722 } [qw(g)], name => 'ref2';
11723
11724 my $t = Subroutine
11725 {my ($p) = @_;
11726 $s->call($$p{g});
11727 } [qw(g)], name => 'ref';
11728
11729 $t->call($g);
11730 $g->outNL;
11731
11732 ok Assemble(debug => 0, eq => <<END);
11733 g: 0000 0000 0000 0001
11734 END
11735
11736  
11737 =head3 K($name, $expr, %options)
11738  
11739 Define a constant variable.
11740  
11741 Parameter Description
11742 1 $name Name of variable
11743 2 $expr Initializing expression
11744 3 %options Options
11745  
11746 B<Example:>
11747  
11748  
11749 my $s = Subroutine
11750 {my ($p) = @_;
11751 $$p{v}->copy($$p{v} + $$p{k} + $$p{g} + 1);
11752 } [qw(v k g)], name => 'add';
11753
11754 my $v = V(v, 1);
11755
11756 my $k = K(k, 2); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11757  
11758 my $g = G(g, 3);
11759 $s->call($v, $k, $g);
11760 $v->outNL;
11761
11762 ok Assemble(debug => 0, eq => <<END);
11763 v: 0000 0000 0000 0007
11764 END
11765
11766 my $g = G g, 0;
11767 my $s = Subroutine
11768 {my ($p) = @_;
11769
11770 $$p{g}->copy(K value, 1); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11771  
11772 } [qw(g)], name => 'ref2';
11773
11774 my $t = Subroutine
11775 {my ($p) = @_;
11776 $s->call($$p{g});
11777 } [qw(g)], name => 'ref';
11778
11779 $t->call($g);
11780 $g->outNL;
11781
11782 ok Assemble(debug => 0, eq => <<END);
11783 g: 0000 0000 0000 0001
11784 END
11785
11786 my $a = V(a, 3); $a->outNL;
11787
11788 my $b = K(b, 2); $b->outNL; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11789  
11790 my $c = $a + $b; $c->outNL;
11791 my $d = $c - $a; $d->outNL;
11792 my $g = $a * $b; $g->outNL;
11793 my $h = $g / $b; $h->outNL;
11794 my $i = $a % $b; $i->outNL;
11795
11796 If ($a == 3,
11797 Then
11798 {PrintOutStringNL "a == 3"
11799 },
11800 Else
11801 {PrintOutStringNL "a != 3"
11802 });
11803
11804 ++$a; $a->outNL;
11805 --$a; $a->outNL;
11806
11807 ok Assemble(debug => 0, eq => <<END);
11808 a: 0000 0000 0000 0003
11809 b: 0000 0000 0000 0002
11810 (a add b): 0000 0000 0000 0005
11811 ((a add b) sub a): 0000 0000 0000 0002
11812 (a times b): 0000 0000 0000 0006
11813 ((a times b) / b): 0000 0000 0000 0003
11814 (a % b): 0000 0000 0000 0001
11815 a == 3
11816 a: 0000 0000 0000 0004
11817 a: 0000 0000 0000 0003
11818 END
11819
11820  
11821 =head3 R($name)
11822  
11823 Define a reference variable.
11824  
11825 Parameter Description
11826 1 $name Name of variable
11827  
11828 =head3 V($name, $expr, %options)
11829  
11830 Define a variable.
11831  
11832 Parameter Description
11833 1 $name Name of variable
11834 2 $expr Initializing expression
11835 3 %options Options
11836  
11837 B<Example:>
11838  
11839  
11840 my $s = Subroutine
11841 {my ($p) = @_;
11842 $$p{v}->copy($$p{v} + $$p{k} + $$p{g} + 1);
11843 } [qw(v k g)], name => 'add';
11844
11845
11846 my $v = V(v, 1); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11847  
11848 my $k = K(k, 2);
11849 my $g = G(g, 3);
11850 $s->call($v, $k, $g);
11851 $v->outNL;
11852
11853 ok Assemble(debug => 0, eq => <<END);
11854 v: 0000 0000 0000 0007
11855 END
11856
11857 my $g = G g, 0;
11858 my $s = Subroutine
11859 {my ($p) = @_;
11860 $$p{g}->copy(K value, 1);
11861 } [qw(g)], name => 'ref2';
11862
11863 my $t = Subroutine
11864 {my ($p) = @_;
11865 $s->call($$p{g});
11866 } [qw(g)], name => 'ref';
11867
11868 $t->call($g);
11869 $g->outNL;
11870
11871 ok Assemble(debug => 0, eq => <<END);
11872 g: 0000 0000 0000 0001
11873 END
11874
11875
11876 my $a = V(a, 3); $a->outNL; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11877  
11878 my $b = K(b, 2); $b->outNL;
11879 my $c = $a + $b; $c->outNL;
11880 my $d = $c - $a; $d->outNL;
11881 my $g = $a * $b; $g->outNL;
11882 my $h = $g / $b; $h->outNL;
11883 my $i = $a % $b; $i->outNL;
11884
11885 If ($a == 3,
11886 Then
11887 {PrintOutStringNL "a == 3"
11888 },
11889 Else
11890 {PrintOutStringNL "a != 3"
11891 });
11892
11893 ++$a; $a->outNL;
11894 --$a; $a->outNL;
11895
11896 ok Assemble(debug => 0, eq => <<END);
11897 a: 0000 0000 0000 0003
11898 b: 0000 0000 0000 0002
11899 (a add b): 0000 0000 0000 0005
11900 ((a add b) sub a): 0000 0000 0000 0002
11901 (a times b): 0000 0000 0000 0006
11902 ((a times b) / b): 0000 0000 0000 0003
11903 (a % b): 0000 0000 0000 0001
11904 a == 3
11905 a: 0000 0000 0000 0004
11906 a: 0000 0000 0000 0003
11907 END
11908
11909  
11910 =head2 Print variables
11911  
11912 Print the values of variables or the memory addressed by them
11913  
11914 =head3 Nasm::X86::Variable::err($left, $title1, $title2)
11915  
11916 Dump the value of a variable on stderr.
11917  
11918 Parameter Description
11919 1 $left Left variable
11920 2 $title1 Optional leading title
11921 3 $title2 Optional trailing title
11922  
11923 =head3 Nasm::X86::Variable::out($left, $title1, $title2)
11924  
11925 Dump the value of a variable on stdout.
11926  
11927 Parameter Description
11928 1 $left Left variable
11929 2 $title1 Optional leading title
11930 3 $title2 Optional trailing title
11931  
11932 =head3 Nasm::X86::Variable::errNL($left, $title1, $title2)
11933  
11934 Dump the value of a variable on stderr and append a new line.
11935  
11936 Parameter Description
11937 1 $left Left variable
11938 2 $title1 Optional leading title
11939 3 $title2 Optional trailing title
11940  
11941 =head3 Nasm::X86::Variable::d($left, $title1, $title2)
11942  
11943 Dump the value of a variable on stderr and append a new line.
11944  
11945 Parameter Description
11946 1 $left Left variable
11947 2 $title1 Optional leading title
11948 3 $title2 Optional trailing title
11949  
11950 =head3 Nasm::X86::Variable::outNL($left, $title1, $title2)
11951  
11952 Dump the value of a variable on stdout and append a new line.
11953  
11954 Parameter Description
11955 1 $left Left variable
11956 2 $title1 Optional leading title
11957 3 $title2 Optional trailing title
11958  
11959 =head3 Nasm::X86::Variable::debug($left)
11960  
11961 Dump the value of a variable on stdout with an indication of where the dump came from.
11962  
11963 Parameter Description
11964 1 $left Left variable
11965  
11966 =head3 Nasm::X86::Variable::printOutZeroString($address)
11967  
11968 Print the variable addressed zero terminated string on stdout.
11969  
11970 Parameter Description
11971 1 $address Variable string address
11972  
11973 B<Example:>
11974  
11975  
11976 my $s = Rutf8 '𝝰𝝱𝝲𝝳';
11977 V(address, $s)->printOutZeroString;
11978
11979 ok Assemble(debug => 0, trace => 0, eq => <<END);
11980 𝝰𝝱𝝲𝝳
11981 END
11982
11983  
11984 =head2 Operations
11985  
11986 Variable operations
11987  
11988 =head3 Nasm::X86::Variable::address($left, $offset)
11989  
11990 Get the address of a variable with an optional offset.
11991  
11992 Parameter Description
11993 1 $left Left variable
11994 2 $offset Optional offset
11995  
11996 =head3 Nasm::X86::Variable::copy($left, $right, $Transfer)
11997  
11998 Copy one variable into another.
11999  
12000 Parameter Description
12001 1 $left Left variable
12002 2 $right Right variable
12003 3 $Transfer Optional transfer register
12004  
12005 B<Example:>
12006  
12007  
12008 my $s = Subroutine
12009 {my ($p) = @_;
12010 $$p{v}->copy($$p{v} + $$p{k} + $$p{g} + 1);
12011 } [qw(v k g)], name => 'add';
12012
12013 my $v = V(v, 1);
12014 my $k = K(k, 2);
12015 my $g = G(g, 3);
12016 $s->call($v, $k, $g);
12017 $v->outNL;
12018
12019 ok Assemble(debug => 0, eq => <<END);
12020 v: 0000 0000 0000 0007
12021 END
12022
12023 my $g = G g, 0;
12024 my $s = Subroutine
12025 {my ($p) = @_;
12026 $$p{g}->copy(K value, 1);
12027 } [qw(g)], name => 'ref2';
12028
12029 my $t = Subroutine
12030 {my ($p) = @_;
12031 $s->call($$p{g});
12032 } [qw(g)], name => 'ref';
12033
12034 $t->call($g);
12035 $g->outNL;
12036
12037 ok Assemble(debug => 0, eq => <<END);
12038 g: 0000 0000 0000 0001
12039 END
12040
12041  
12042 =head3 Nasm::X86::Variable::copyRef($left, $right, $Transfer)
12043  
12044 Copy a reference to a variable.
12045  
12046 Parameter Description
12047 1 $left Left variable
12048 2 $right Right variable
12049 3 $Transfer Optional transfer register
12050  
12051 =head3 Nasm::X86::Variable::copyZF($var)
12052  
12053 Copy the current state of the zero flag into a variable.
12054  
12055 Parameter Description
12056 1 $var Variable
12057  
12058 B<Example:>
12059  
12060  
12061 Mov r15, 1;
12062 my $z = V(zf);
12063 Cmp r15, 1; $z->copyZF; $z->outNL;
12064 Cmp r15, 2; $z->copyZF; $z->outNL;
12065 Cmp r15, 1; $z->copyZFInverted; $z->outNL;
12066 Cmp r15, 2; $z->copyZFInverted; $z->outNL;
12067
12068 ok Assemble(debug => 0, eq => <<END);
12069 zf: 0000 0000 0000 0001
12070 zf: 0000 0000 0000 0000
12071 zf: 0000 0000 0000 0000
12072 zf: 0000 0000 0000 0001
12073 END
12074
12075  
12076 =head3 Nasm::X86::Variable::copyZFInverted($var)
12077  
12078 Copy the opposite of the current state of the zero flag into a variable.
12079  
12080 Parameter Description
12081 1 $var Variable
12082  
12083 B<Example:>
12084  
12085  
12086 Mov r15, 1;
12087 my $z = V(zf);
12088 Cmp r15, 1; $z->copyZF; $z->outNL;
12089 Cmp r15, 2; $z->copyZF; $z->outNL;
12090 Cmp r15, 1; $z->copyZFInverted; $z->outNL;
12091 Cmp r15, 2; $z->copyZFInverted; $z->outNL;
12092
12093 ok Assemble(debug => 0, eq => <<END);
12094 zf: 0000 0000 0000 0001
12095 zf: 0000 0000 0000 0000
12096 zf: 0000 0000 0000 0000
12097 zf: 0000 0000 0000 0001
12098 END
12099
12100  
12101 =head3 Nasm::X86::Variable::equals($op, $left, $right)
12102  
12103 Equals operator.
12104  
12105 Parameter Description
12106 1 $op Operator
12107 2 $left Left variable
12108 3 $right Right variable
12109  
12110 =head3 Nasm::X86::Variable::assign($left, $op, $right)
12111  
12112 Assign to the left hand side the value of the right hand side.
12113  
12114 Parameter Description
12115 1 $left Left variable
12116 2 $op Operator
12117 3 $right Right variable
12118  
12119 =head3 Nasm::X86::Variable::plusAssign($left, $right)
12120  
12121 Implement plus and assign.
12122  
12123 Parameter Description
12124 1 $left Left variable
12125 2 $right Right variable
12126  
12127 =head3 Nasm::X86::Variable::minusAssign($left, $right)
12128  
12129 Implement minus and assign.
12130  
12131 Parameter Description
12132 1 $left Left variable
12133 2 $right Right variable
12134  
12135 =head3 Nasm::X86::Variable::arithmetic($op, $name, $left, $right)
12136  
12137 Return a variable containing the result of an arithmetic operation on the left hand and right hand side variables.
12138  
12139 Parameter Description
12140 1 $op Operator
12141 2 $name Operator name
12142 3 $left Left variable
12143 4 $right Right variable
12144  
12145 =head3 Nasm::X86::Variable::add($left, $right)
12146  
12147 Add the right hand variable to the left hand variable and return the result as a new variable.
12148  
12149 Parameter Description
12150 1 $left Left variable
12151 2 $right Right variable
12152  
12153 =head3 Nasm::X86::Variable::sub($left, $right)
12154  
12155 Subtract the right hand variable from the left hand variable and return the result as a new variable.
12156  
12157 Parameter Description
12158 1 $left Left variable
12159 2 $right Right variable
12160  
12161 =head3 Nasm::X86::Variable::times($left, $right)
12162  
12163 Multiply the left hand variable by the right hand variable and return the result as a new variable.
12164  
12165 Parameter Description
12166 1 $left Left variable
12167 2 $right Right variable
12168  
12169 =head3 Nasm::X86::Variable::division($op, $left, $right)
12170  
12171 Return a variable containing the result or the remainder that occurs when the left hand side is divided by the right hand side.
12172  
12173 Parameter Description
12174 1 $op Operator
12175 2 $left Left variable
12176 3 $right Right variable
12177  
12178 =head3 Nasm::X86::Variable::divide($left, $right)
12179  
12180 Divide the left hand variable by the right hand variable and return the result as a new variable.
12181  
12182 Parameter Description
12183 1 $left Left variable
12184 2 $right Right variable
12185  
12186 =head3 Nasm::X86::Variable::mod($left, $right)
12187  
12188 Divide the left hand variable by the right hand variable and return the remainder as a new variable.
12189  
12190 Parameter Description
12191 1 $left Left variable
12192 2 $right Right variable
12193  
12194 =head3 Nasm::X86::Variable::boolean($sub, $op, $left, $right)
12195  
12196 Combine the left hand variable with the right hand variable via a boolean operator.
12197  
12198 Parameter Description
12199 1 $sub Operator
12200 2 $op Operator name
12201 3 $left Left variable
12202 4 $right Right variable
12203  
12204 =head3 Nasm::X86::Variable::booleanZF($sub, $op, $left, $right)
12205  
12206 Combine the left hand variable with the right hand variable via a boolean operator and indicate the result by setting the zero flag if the result is true.
12207  
12208 Parameter Description
12209 1 $sub Operator
12210 2 $op Operator name
12211 3 $left Left variable
12212 4 $right Right variable
12213  
12214 =head3 Nasm::X86::Variable::booleanC($cmov, $op, $left, $right)
12215  
12216 Combine the left hand variable with the right hand variable via a boolean operator using a conditional move instruction.
12217  
12218 Parameter Description
12219 1 $cmov Conditional move instruction name
12220 2 $op Operator name
12221 3 $left Left variable
12222 4 $right Right variable
12223  
12224 =head3 Nasm::X86::Variable::eq($left, $right)
12225  
12226 Check whether the left hand variable is equal to the right hand variable.
12227  
12228 Parameter Description
12229 1 $left Left variable
12230 2 $right Right variable
12231  
12232 =head3 Nasm::X86::Variable::ne($left, $right)
12233  
12234 Check whether the left hand variable is not equal to the right hand variable.
12235  
12236 Parameter Description
12237 1 $left Left variable
12238 2 $right Right variable
12239  
12240 =head3 Nasm::X86::Variable::ge($left, $right)
12241  
12242 Check whether the left hand variable is greater than or equal to the right hand variable.
12243  
12244 Parameter Description
12245 1 $left Left variable
12246 2 $right Right variable
12247  
12248 =head3 Nasm::X86::Variable::gt($left, $right)
12249  
12250 Check whether the left hand variable is greater than the right hand variable.
12251  
12252 Parameter Description
12253 1 $left Left variable
12254 2 $right Right variable
12255  
12256 =head3 Nasm::X86::Variable::le($left, $right)
12257  
12258 Check whether the left hand variable is less than or equal to the right hand variable.
12259  
12260 Parameter Description
12261 1 $left Left variable
12262 2 $right Right variable
12263  
12264 =head3 Nasm::X86::Variable::lt($left, $right)
12265  
12266 Check whether the left hand variable is less than the right hand variable.
12267  
12268 Parameter Description
12269 1 $left Left variable
12270 2 $right Right variable
12271  
12272 =head3 Nasm::X86::Variable::isRef($variable)
12273  
12274 Check whether the specified variable is a reference to another variable.
12275  
12276 Parameter Description
12277 1 $variable Variable
12278  
12279 =head3 Nasm::X86::Variable::setReg($variable, $register)
12280  
12281 Set the named registers from the content of the variable.
12282  
12283 Parameter Description
12284 1 $variable Variable
12285 2 $register Register to load
12286  
12287 =head3 Nasm::X86::Variable::getReg($variable, $register, @registers)
12288  
12289 Load the variable from the named registers.
12290  
12291 Parameter Description
12292 1 $variable Variable
12293 2 $register Register to load
12294 3 @registers Optional further registers to load from
12295  
12296 =head3 Nasm::X86::Variable::getConst($variable, $constant, $transfer)
12297  
12298 Load the variable from a constant in effect setting a variable to a specified value.
12299  
12300 Parameter Description
12301 1 $variable Variable
12302 2 $constant Constant to load
12303 3 $transfer Optional transfer register
12304  
12305 =head3 Nasm::X86::Variable::getConst22($variable, $constant)
12306  
12307 Load the variable from a constant in effect setting a variable to a specified value.
12308  
12309 Parameter Description
12310 1 $variable Variable
12311 2 $constant Constant to load
12312  
12313 =head3 Nasm::X86::Variable::incDec($left, $op)
12314  
12315 Increment or decrement a variable.
12316  
12317 Parameter Description
12318 1 $left Left variable operator
12319 2 $op Address of operator to perform inc or dec
12320  
12321 =head3 Nasm::X86::Variable::inc($left)
12322  
12323 Increment a variable.
12324  
12325 Parameter Description
12326 1 $left Variable
12327  
12328 =head3 Nasm::X86::Variable::dec($left)
12329  
12330 Decrement a variable.
12331  
12332 Parameter Description
12333 1 $left Variable
12334  
12335 =head3 Nasm::X86::Variable::str($left)
12336  
12337 The name of the variable.
12338  
12339 Parameter Description
12340 1 $left Variable
12341  
12342 =head3 Nasm::X86::Variable::min($left, $right)
12343  
12344 Minimum of two variables.
12345  
12346 Parameter Description
12347 1 $left Left variable
12348 2 $right Right variable or constant
12349  
12350 B<Example:>
12351  
12352  
12353 my $a = V("a", 1);
12354 my $b = V("b", 2);
12355 my $c = $a->min($b);
12356 my $d = $a->max($b);
12357 $a->outNL;
12358 $b->outNL;
12359 $c->outNL;
12360 $d->outNL;
12361
12362 ok Assemble(debug => 0, eq => <<END);
12363 a: 0000 0000 0000 0001
12364 b: 0000 0000 0000 0002
12365 min: 0000 0000 0000 0001
12366 max: 0000 0000 0000 0002
12367 END
12368
12369  
12370 =head3 Nasm::X86::Variable::max($left, $right)
12371  
12372 Maximum of two variables.
12373  
12374 Parameter Description
12375 1 $left Left variable
12376 2 $right Right variable or constant
12377  
12378 B<Example:>
12379  
12380  
12381 my $a = V("a", 1);
12382 my $b = V("b", 2);
12383 my $c = $a->min($b);
12384 my $d = $a->max($b);
12385 $a->outNL;
12386 $b->outNL;
12387 $c->outNL;
12388 $d->outNL;
12389
12390 ok Assemble(debug => 0, eq => <<END);
12391 a: 0000 0000 0000 0001
12392 b: 0000 0000 0000 0002
12393 min: 0000 0000 0000 0001
12394 max: 0000 0000 0000 0002
12395 END
12396
12397  
12398 =head3 Nasm::X86::Variable::and($left, $right)
12399  
12400 And two variables.
12401  
12402 Parameter Description
12403 1 $left Left variable
12404 2 $right Right variable
12405  
12406 =head3 Nasm::X86::Variable::or($left, $right)
12407  
12408 Or two variables.
12409  
12410 Parameter Description
12411 1 $left Left variable
12412 2 $right Right variable
12413  
12414 =head3 Nasm::X86::Variable::setMask($start, $length, $mask)
12415  
12416 Set the mask register to ones starting at the specified position for the specified length and zeroes elsewhere.
12417  
12418 Parameter Description
12419 1 $start Variable containing start of mask
12420 2 $length Variable containing length of mask
12421 3 $mask Mask register
12422  
12423 B<Example:>
12424  
12425  
12426 my $start = V("Start", 7);
12427 my $length = V("Length", 3);
12428 $start->setMask($length, k7);
12429 PrintOutRegisterInHex k7;
12430
12431 ok Assemble(debug => 0, eq => <<END);
12432 k7: 0000 0000 0000 0380
12433 END
12434
12435 my $z = V('zero', 0);
12436 my $o = V('one', 1);
12437 my $t = V('two', 2);
12438 $z->setMask($o, k7); PrintOutRegisterInHex k7;
12439 $z->setMask($t, k6); PrintOutRegisterInHex k6;
12440 $z->setMask($o+$t, k5); PrintOutRegisterInHex k5;
12441 $o->setMask($o, k4); PrintOutRegisterInHex k4;
12442 $o->setMask($t, k3); PrintOutRegisterInHex k3;
12443 $o->setMask($o+$t, k2); PrintOutRegisterInHex k2;
12444
12445 $t->setMask($o, k1); PrintOutRegisterInHex k1;
12446 $t->setMask($t, k0); PrintOutRegisterInHex k0;
12447
12448
12449 ok Assemble(debug => 0, eq => <<END);
12450 k7: 0000 0000 0000 0001
12451 k6: 0000 0000 0000 0003
12452 k5: 0000 0000 0000 0007
12453 k4: 0000 0000 0000 0002
12454 k3: 0000 0000 0000 0006
12455 k2: 0000 0000 0000 000E
12456 k1: 0000 0000 0000 0004
12457 k0: 0000 0000 0000 000C
12458 END
12459
12460  
12461 =head3 Nasm::X86::Variable::setMaskFirst($length, $mask)
12462  
12463 Set the first bits in the specified mask register.
12464  
12465 Parameter Description
12466 1 $length Variable containing length to set
12467 2 $mask Mask register
12468  
12469 =head3 Nasm::X86::Variable::setMaskBit($index, $mask)
12470  
12471 Set a bit in the specified mask register retaining the other bits.
12472  
12473 Parameter Description
12474 1 $index Variable containing bit position to set
12475 2 $mask Mask register
12476  
12477 =head3 Nasm::X86::Variable::clearMaskBit($index, $mask)
12478  
12479 Clear a bit in the specified mask register retaining the other bits.
12480  
12481 Parameter Description
12482 1 $index Variable containing bit position to clear
12483 2 $mask Mask register
12484  
12485 =head3 Nasm::X86::Variable::setBit($index, $mask)
12486  
12487 Set a bit in the specified register retaining the other bits.
12488  
12489 Parameter Description
12490 1 $index Variable containing bit position to set
12491 2 $mask Mask register
12492  
12493 =head3 Nasm::X86::Variable::clearBit($index, $mask)
12494  
12495 Clear a bit in the specified mask register retaining the other bits.
12496  
12497 Parameter Description
12498 1 $index Variable containing bit position to clear
12499 2 $mask Mask register
12500  
12501 =head3 Nasm::X86::Variable::setZmm($source, $zmm, $offset, $length)
12502  
12503 Load bytes from the memory addressed by specified source variable into the numbered zmm register at the offset in the specified offset moving the number of bytes in the specified variable.
12504  
12505 Parameter Description
12506 1 $source Variable containing the address of the source
12507 2 $zmm Number of zmm to load
12508 3 $offset Variable containing offset in zmm to move to
12509 4 $length Variable containing length of move
12510  
12511 B<Example:>
12512  
12513  
12514 my $s = Rb(0..128);
12515 my $source = V(Source, $s);
12516
12517 if (1) # First block
12518 {my $offset = V(Offset, 7);
12519 my $length = V(Length, 3);
12520 $source->setZmm(0, $offset, $length);
12521 }
12522
12523 if (1) # Second block
12524 {my $offset = V(Offset, 33);
12525 my $length = V(Length, 12);
12526 $source->setZmm(0, $offset, $length);
12527 }
12528
12529 PrintOutRegisterInHex zmm0;
12530
12531 ok Assemble(debug => 0, eq => <<END);
12532 zmm0: 0000 0000 0000 0000 0000 0000 0000 0000 0000 000B 0A09 0807 0605 0403 0201 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0201 0000 0000 0000 0000
12533 END
12534
12535  
12536 =head3 Nasm::X86::Variable::loadZmm($source, $zmm)
12537  
12538 Load bytes from the memory addressed by the specified source variable into the numbered zmm register.
12539  
12540 Parameter Description
12541 1 $source Variable containing the address of the source
12542 2 $zmm Number of zmm to get
12543  
12544 =head3 loadFromZmm($register, $size, $zmm, $offset)
12545  
12546 Load the specified register from the offset located in the numbered zmm.
12547  
12548 Parameter Description
12549 1 $register Register to load
12550 2 $size "b|w|d|q" for size
12551 3 $zmm Numbered zmm register to load from
12552 4 $offset Constant offset in bytes
12553  
12554 =head3 putIntoZmm($register, $size, $zmm, $offset)
12555  
12556 Put the specified register into the numbered zmm at the specified offset in the zmm.
12557  
12558 Parameter Description
12559 1 $register Register to load
12560 2 $size Bwdq for size
12561 3 $zmm Numbered zmm register to load from
12562 4 $offset Constant offset in bytes
12563  
12564 =head3 LoadRegFromMm($mm, $offset, $reg)
12565  
12566 Load the specified register from the numbered zmm at the quad offset specified as a constant number.
12567  
12568 Parameter Description
12569 1 $mm Mm register
12570 2 $offset Offset in quads
12571 3 $reg General purpose register to load
12572  
12573 =head3 SaveRegIntoMm($mm, $offset, $reg)
12574  
12575 Save the specified register into the numbered zmm at the quad offset specified as a constant number.
12576  
12577 Parameter Description
12578 1 $mm Mm register
12579 2 $offset Offset in quads
12580 3 $reg General purpose register to load
12581  
12582 =head3 getBwdqFromMm($size, $mm, $offset, $Transfer, $target)
12583  
12584 Get the numbered byte|word|double word|quad word from the numbered zmm register and return it in a variable.
12585  
12586 Parameter Description
12587 1 $size Size of get
12588 2 $mm Mm register
12589 3 $offset Offset in bytes either as a constant or as a variable
12590 4 $Transfer Optional transfer register
12591 5 $target Optional target variable - if none supplied we create a variable
12592  
12593 =head3 getBFromXmm($xmm, $offset)
12594  
12595 Get the byte from the numbered xmm register and return it in a variable.
12596  
12597 Parameter Description
12598 1 $xmm Numbered xmm
12599 2 $offset Offset in bytes
12600  
12601 =head3 getWFromXmm($xmm, $offset)
12602  
12603 Get the word from the numbered xmm register and return it in a variable.
12604  
12605 Parameter Description
12606 1 $xmm Numbered xmm
12607 2 $offset Offset in bytes
12608  
12609 =head3 getDFromXmm($xmm, $offset)
12610  
12611 Get the double word from the numbered xmm register and return it in a variable.
12612  
12613 Parameter Description
12614 1 $xmm Numbered xmm
12615 2 $offset Offset in bytes
12616  
12617 =head3 getQFromXmm($xmm, $offset)
12618  
12619 Get the quad word from the numbered xmm register and return it in a variable.
12620  
12621 Parameter Description
12622 1 $xmm Numbered xmm
12623 2 $offset Offset in bytes
12624  
12625 =head3 getBFromZmm($zmm, $offset)
12626  
12627 Get the byte from the numbered zmm register and return it in a variable.
12628  
12629 Parameter Description
12630 1 $zmm Numbered zmm
12631 2 $offset Offset in bytes
12632  
12633 =head3 getWFromZmm($zmm, $offset)
12634  
12635 Get the word from the numbered zmm register and return it in a variable.
12636  
12637 Parameter Description
12638 1 $zmm Numbered zmm
12639 2 $offset Offset in bytes
12640  
12641 =head3 getDFromZmm($zmm, $offset, $transfer)
12642  
12643 Get the double word from the numbered zmm register and return it in a variable.
12644  
12645 Parameter Description
12646 1 $zmm Numbered zmm
12647 2 $offset Offset in bytes
12648 3 $transfer Optional transfer register
12649  
12650 B<Example:>
12651  
12652  
12653 my $s = Rb(0..8);
12654 my $c = V("Content", "[$s]");
12655 $c->putBIntoZmm(0, 4);
12656 $c->putWIntoZmm(0, 6);
12657 $c->putDIntoZmm(0, 10);
12658 $c->putQIntoZmm(0, 16);
12659 PrintOutRegisterInHex zmm0;
12660 getBFromZmm(0, 12)->outNL;
12661 getWFromZmm(0, 12)->outNL;
12662
12663 getDFromZmm(0, 12, r15)->outNL; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
12664  
12665 getQFromZmm(0, 12)->outNL;
12666
12667 ok Assemble(debug => 0, eq => <<END);
12668 zmm0: 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0706 0504 0302 0100 0000 0302 0100 0000 0100 0000 0000 0000
12669 b at offset 12 in zmm0: 0000 0000 0000 0002
12670 w at offset 12 in zmm0: 0000 0000 0000 0302
12671 d at offset 12 in zmm0: 0000 0000 0000 0302
12672 q at offset 12 in zmm0: 0302 0100 0000 0302
12673 END
12674
12675  
12676 =head3 getQFromZmm($zmm, $offset)
12677  
12678 Get the quad word from the numbered zmm register and return it in a variable.
12679  
12680 Parameter Description
12681 1 $zmm Numbered zmm
12682 2 $offset Offset in bytes
12683  
12684 =head3 Nasm::X86::Variable::getBFromZmm($variable, $zmm, $offset)
12685  
12686 Get the byte from the numbered zmm register and put it in a variable.
12687  
12688 Parameter Description
12689 1 $variable Variable
12690 2 $zmm Numbered zmm
12691 3 $offset Offset in bytes
12692  
12693 =head3 Nasm::X86::Variable::getWFromZmm($variable, $zmm, $offset)
12694  
12695 Get the word from the numbered zmm register and put it in a variable.
12696  
12697 Parameter Description
12698 1 $variable Variable
12699 2 $zmm Numbered zmm
12700 3 $offset Offset in bytes
12701  
12702 =head3 Nasm::X86::Variable::getDFromZmm($variable, $zmm, $offset, $transfer)
12703  
12704 Get the double word from the numbered zmm register and put it in a variable.
12705  
12706 Parameter Description
12707 1 $variable Variable
12708 2 $zmm Numbered zmm
12709 3 $offset Offset in bytes
12710 4 $transfer Transfer register
12711  
12712 =head3 Nasm::X86::Variable::getQFromZmm($variable, $zmm, $offset)
12713  
12714 Get the quad word from the numbered zmm register and put it in a variable.
12715  
12716 Parameter Description
12717 1 $variable Variable
12718 2 $zmm Numbered zmm
12719 3 $offset Offset in bytes
12720  
12721 =head3 Nasm::X86::Variable::putBwdqIntoMm($content, $size, $mm, $offset, $Transfer)
12722  
12723 Place the value of the content variable at the byte|word|double word|quad word in the numbered zmm register.
12724  
12725 Parameter Description
12726 1 $content Variable with content
12727 2 $size Size of put
12728 3 $mm Numbered zmm
12729 4 $offset Offset in bytes
12730 5 $Transfer Optional transfer register
12731  
12732 =head3 Nasm::X86::Variable::putBIntoXmm($content, $xmm, $offset)
12733  
12734 Place the value of the content variable at the byte in the numbered xmm register.
12735  
12736 Parameter Description
12737 1 $content Variable with content
12738 2 $xmm Numbered xmm
12739 3 $offset Offset in bytes
12740  
12741 =head3 Nasm::X86::Variable::putWIntoXmm($content, $xmm, $offset)
12742  
12743 Place the value of the content variable at the word in the numbered xmm register.
12744  
12745 Parameter Description
12746 1 $content Variable with content
12747 2 $xmm Numbered xmm
12748 3 $offset Offset in bytes
12749  
12750 =head3 Nasm::X86::Variable::putDIntoXmm($content, $xmm, $offset)
12751  
12752 Place the value of the content variable at the double word in the numbered xmm register.
12753  
12754 Parameter Description
12755 1 $content Variable with content
12756 2 $xmm Numbered xmm
12757 3 $offset Offset in bytes
12758  
12759 =head3 Nasm::X86::Variable::putQIntoXmm($content, $xmm, $offset)
12760  
12761 Place the value of the content variable at the quad word in the numbered xmm register.
12762  
12763 Parameter Description
12764 1 $content Variable with content
12765 2 $xmm Numbered xmm
12766 3 $offset Offset in bytes
12767  
12768 =head3 Nasm::X86::Variable::putBIntoZmm($content, $zmm, $offset)
12769  
12770 Place the value of the content variable at the byte in the numbered zmm register.
12771  
12772 Parameter Description
12773 1 $content Variable with content
12774 2 $zmm Numbered zmm
12775 3 $offset Offset in bytes
12776  
12777 =head3 Nasm::X86::Variable::putWIntoZmm($content, $zmm, $offset)
12778  
12779 Place the value of the content variable at the word in the numbered zmm register.
12780  
12781 Parameter Description
12782 1 $content Variable with content
12783 2 $zmm Numbered zmm
12784 3 $offset Offset in bytes
12785  
12786 =head3 Nasm::X86::Variable::putDIntoZmm($content, $zmm, $offset, $transfer)
12787  
12788 Place the value of the content variable at the double word in the numbered zmm register.
12789  
12790 Parameter Description
12791 1 $content Variable with content
12792 2 $zmm Numbered zmm
12793 3 $offset Offset in bytes
12794 4 $transfer Optional transfer register
12795  
12796 B<Example:>
12797  
12798  
12799 my $s = Rb(0..8);
12800 my $c = V("Content", "[$s]");
12801 $c->putBIntoZmm(0, 4);
12802 $c->putWIntoZmm(0, 6);
12803 $c->putDIntoZmm(0, 10);
12804 $c->putQIntoZmm(0, 16);
12805 PrintOutRegisterInHex zmm0;
12806 getBFromZmm(0, 12)->outNL;
12807 getWFromZmm(0, 12)->outNL;
12808 getDFromZmm(0, 12, r15)->outNL;
12809 getQFromZmm(0, 12)->outNL;
12810
12811 ok Assemble(debug => 0, eq => <<END);
12812 zmm0: 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0706 0504 0302 0100 0000 0302 0100 0000 0100 0000 0000 0000
12813 b at offset 12 in zmm0: 0000 0000 0000 0002
12814 w at offset 12 in zmm0: 0000 0000 0000 0302
12815 d at offset 12 in zmm0: 0000 0000 0000 0302
12816 q at offset 12 in zmm0: 0302 0100 0000 0302
12817 END
12818
12819  
12820 =head3 Nasm::X86::Variable::putQIntoZmm($content, $zmm, $offset, $transfer)
12821  
12822 Place the value of the content variable at the quad word in the numbered zmm register.
12823  
12824 Parameter Description
12825 1 $content Variable with content
12826 2 $zmm Numbered zmm
12827 3 $offset Offset in bytes
12828 4 $transfer Optional transfer register
12829  
12830 =head2 Broadcast
12831  
12832 Broadcast from a variable into a zmm
12833  
12834 =head3 Nasm::X86::Variable::zBroadCastD($variable, $zmm)
12835  
12836 Broadcast a double word in a variable into the numbered zmm.
12837  
12838 Parameter Description
12839 1 $variable Variable containing value to broadcast
12840 2 $zmm Numbered zmm to broadcast to
12841  
12842 =head2 Stack
12843  
12844 Push and pop variables to and from the stack
12845  
12846 =head3 Nasm::X86::Variable::push($variable)
12847  
12848 Push a variable onto the stack.
12849  
12850 Parameter Description
12851 1 $variable Variable
12852  
12853 =head3 Nasm::X86::Variable::pop($variable)
12854  
12855 Pop a variable from the stack.
12856  
12857 Parameter Description
12858 1 $variable Variable
12859  
12860 =head2 Memory
12861  
12862 Actions on memory described by variables
12863  
12864 =head3 Nasm::X86::Variable::clearMemory($address, $size)
12865  
12866 Clear the memory described in this variable.
12867  
12868 Parameter Description
12869 1 $address Address of memory to clear
12870 2 $size Size of the memory to clear
12871  
12872 =head3 Nasm::X86::Variable::copyMemory($target, $source, $size)
12873  
12874 Copy from one block of memory to another.
12875  
12876 Parameter Description
12877 1 $target Address of target
12878 2 $source Address of source
12879 3 $size Length to copy
12880  
12881 =head3 Nasm::X86::Variable::printMemoryInHexNL($address, $channel, $size)
12882  
12883 Write, in hexadecimal, the memory addressed by a variable to stdout or stderr.
12884  
12885 Parameter Description
12886 1 $address Address of memory
12887 2 $channel Channel to print on
12888 3 $size Number of bytes to print
12889  
12890 =head3 Nasm::X86::Variable::printErrMemoryInHexNL($address, $size)
12891  
12892 Write the memory addressed by a variable to stderr.
12893  
12894 Parameter Description
12895 1 $address Address of memory
12896 2 $size Number of bytes to print
12897  
12898 =head3 Nasm::X86::Variable::printOutMemoryInHexNL($address, $size)
12899  
12900 Write the memory addressed by a variable to stdout.
12901  
12902 Parameter Description
12903 1 $address Address of memory
12904 2 $size Number of bytes to print
12905  
12906 B<Example:>
12907  
12908  
12909 my $u = Rd(ord('𝝰'), ord('𝝱'), ord('𝝲'), ord('𝝳'));
12910 Mov rax, $u;
12911 my $address = V(address)->getReg(rax);
12912 $address->printOutMemoryInHexNL(K(size, 16));
12913
12914 ok Assemble(debug => 0, trace => 0, eq => <<END);
12915 70D7 0100 71D7 010072D7 0100 73D7 0100
12916 END
12917
12918 my $v = V(var, 2);
12919
12920 If $v == 0, Then {Mov rax, 0},
12921 Ef {$v == 1} Then {Mov rax, 1},
12922 Ef {$v == 2} Then {Mov rax, 2},
12923 Else {Mov rax, 3};
12924 PrintOutRegisterInHex rax;
12925 ok Assemble(debug => 0, trace => 0, eq => <<END);
12926 rax: 0000 0000 0000 0002
12927 END
12928
12929  
12930 =head3 Nasm::X86::Variable::freeMemory($address, $size)
12931  
12932 Free the memory addressed by this variable for the specified length.
12933  
12934 Parameter Description
12935 1 $address Address of memory to free
12936 2 $size Size of the memory to free
12937  
12938 B<Example:>
12939  
12940  
12941 my $N = V(size, 2048);
12942 my $q = Rs('a'..'p');
12943 AllocateMemory($N, my $address = V(address));
12944
12945 Vmovdqu8 xmm0, "[$q]";
12946 $address->setReg(rax);
12947 Vmovdqu8 "[rax]", xmm0;
12948 Mov rdi, 16;
12949 PrintOutMemory;
12950 PrintOutNL;
12951
12952 FreeMemory(address => $address, size=> $N);
12953
12954 ok Assemble(debug => 0, eq => <<END);
12955 abcdefghijklmnop
12956 END
12957
12958  
12959 =head3 Nasm::X86::Variable::allocateMemory($size)
12960  
12961 Allocate the specified amount of memory via mmap and return its address.
12962  
12963 Parameter Description
12964 1 $size Size
12965  
12966 =head2 Structured Programming with variables
12967  
12968 Structured programming operations driven off variables.
12969  
12970 =head3 Nasm::X86::Variable::for($limit, $block)
12971  
12972 Iterate the block limit times.
12973  
12974 Parameter Description
12975 1 $limit Limit
12976 2 $block Block
12977  
12978 B<Example:>
12979  
12980  
12981 V(limit,10)->for(sub
12982 {my ($i, $start, $next, $end) = @_;
12983 $i->outNL;
12984 });
12985
12986 ok Assemble(debug => 0, eq => <<END);
12987 index: 0000 0000 0000 0000
12988 index: 0000 0000 0000 0001
12989 index: 0000 0000 0000 0002
12990 index: 0000 0000 0000 0003
12991 index: 0000 0000 0000 0004
12992 index: 0000 0000 0000 0005
12993 index: 0000 0000 0000 0006
12994 index: 0000 0000 0000 0007
12995 index: 0000 0000 0000 0008
12996 index: 0000 0000 0000 0009
12997 END
12998
12999  
13000 =head1 Stack
13001  
13002 Manage data on the stack
13003  
13004 =head2 Push, Pop, Peek
13005  
13006 Generic versions of push, pop, peek
13007  
13008 =head3 PopR(@r)
13009  
13010 Pop registers from the stack. Use the last stored set if none explicitly supplied. Pops are done in reverse order to match the original pushing order.
13011  
13012 Parameter Description
13013 1 @r Register
13014  
13015 B<Example:>
13016  
13017  
13018 Mov rax, 0x11111111;
13019 Mov rbx, 0x22222222;
13020 PushR my @save = (rax, rbx);
13021 Mov rax, 0x33333333;
13022
13023 PopR; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13024  
13025 PrintOutRegisterInHex rax;
13026 PrintOutRegisterInHex rbx;
13027
13028 ok Assemble(debug => 0, eq => <<END);
13029 rax: 0000 0000 1111 1111
13030 rbx: 0000 0000 2222 2222
13031 END
13032
13033  
13034 =head3 PopEax()
13035  
13036 We cannot pop a double word from the stack in 64 bit long mode using pop so we improvise.
13037  
13038  
13039 B<Example:>
13040  
13041  
13042 Mov r14, 0;
13043 Kmovq k0, r14;
13044 Ktestq k0, k0;
13045 IfZ Then {PrintOutStringNL "0 & 0 == 0"};
13046 PrintOutZF;
13047
13048 LoadConstantIntoMaskRegister k1, r13, 1;
13049 Ktestq k1, k1;
13050 IfNz Then {PrintOutStringNL "1 & 1 != 0"};
13051 PrintOutZF;
13052
13053 LoadConstantIntoMaskRegister k2, r13, eval "0b".(('1'x4).('0'x4))x2;
13054
13055 PrintOutRegisterInHex k0, k1, k2;
13056
13057 Mov r15, 0x89abcdef;
13058 Mov r14, 0x01234567;
13059 Shl r14, 32;
13060 Or r15, r14;
13061 Push r15;
13062 Push r15;
13063
13064 PopEax; PrintRaxInHex($stdout, 3); PrintOutNL; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13065  
13066
13067 my $a = V('aaaa');
13068 $a->pop;
13069 $a->push;
13070 $a->outNL;
13071
13072
13073 PopEax; PrintRaxInHex($stdout, 3); PrintOutNL; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13074  
13075
13076 ok Assemble(debug => 0, eq => <<END);
13077 0 & 0 == 0
13078 ZF=1
13079 1 & 1 != 0
13080 ZF=0
13081 k0: 0000 0000 0000 0000
13082 k1: 0000 0000 0000 0001
13083 k2: 0000 0000 0000 F0F0
13084 89AB CDEF
13085 aaaa: 89AB CDEF 0123 4567
13086 0123 4567
13087 END
13088
13089  
13090 =head3 PeekR($r)
13091  
13092 Peek at register on stack.
13093  
13094 Parameter Description
13095 1 $r Register
13096  
13097 =head3 PushZmm(@Z)
13098  
13099 Push several zmm registers.
13100  
13101 Parameter Description
13102 1 @Z Zmm register numbers
13103  
13104 =head3 PopZmm()
13105  
13106 Pop zmm registers.
13107  
13108  
13109 =head3 PushMask(@M)
13110  
13111 Push several Mask registers.
13112  
13113 Parameter Description
13114 1 @M Mask register numbers
13115  
13116 =head3 PopMask()
13117  
13118 Pop Mask registers.
13119  
13120  
13121 =head2 Declarations
13122  
13123 Declare variables and structures
13124  
13125 =head3 Structures
13126  
13127 Declare a structure
13128  
13129 =head4 Structure()
13130  
13131 Create a structure addressed by a register.
13132  
13133  
13134 =head4 Nasm::X86::Structure::field($structure, $length, $comment)
13135  
13136 Add a field of the specified length with an optional comment.
13137  
13138 Parameter Description
13139 1 $structure Structure data descriptor
13140 2 $length Length of data
13141 3 $comment Optional comment
13142  
13143 =head4 Nasm::X86::StructureField::addr($field, $register)
13144  
13145 Address a field in a structure by either the default register or the named register.
13146  
13147 Parameter Description
13148 1 $field Field
13149 2 $register Optional address register else rax
13150  
13151 =head4 All8Structure($N)
13152  
13153 Create a structure consisting of 8 byte fields.
13154  
13155 Parameter Description
13156 1 $N Number of variables required
13157  
13158 =head3 Stack Frame
13159  
13160 Declare local variables in a frame on the stack
13161  
13162 =head4 LocalData()
13163  
13164 Map local data.
13165  
13166  
13167 =head4 Nasm::X86::LocalData::start($local)
13168  
13169 Start a local data area on the stack.
13170  
13171 Parameter Description
13172 1 $local Local data descriptor
13173  
13174 =head4 Nasm::X86::LocalData::free($local)
13175  
13176 Free a local data area on the stack.
13177  
13178 Parameter Description
13179 1 $local Local data descriptor
13180  
13181 =head4 Nasm::X86::LocalData::variable($local, $length, $comment)
13182  
13183 Add a local variable.
13184  
13185 Parameter Description
13186 1 $local Local data descriptor
13187 2 $length Length of data
13188 3 $comment Optional comment
13189  
13190 =head4 Nasm::X86::LocalVariable::stack($variable)
13191  
13192 Address a local variable on the stack.
13193  
13194 Parameter Description
13195 1 $variable Variable
13196  
13197 =head4 Nasm::X86::LocalData::allocate8($local, @comments)
13198  
13199 Add some 8 byte local variables and return an array of variable definitions.
13200  
13201 Parameter Description
13202 1 $local Local data descriptor
13203 2 @comments Optional comment
13204  
13205 =head4 AllocateAll8OnStack($N)
13206  
13207 Create a local data descriptor consisting of the specified number of 8 byte local variables and return an array: (local data descriptor, variable definitions...).
13208  
13209 Parameter Description
13210 1 $N Number of variables required
13211  
13212 =head1 Operating system
13213  
13214 Interacting with the operating system.
13215  
13216 =head2 Processes
13217  
13218 Create and manage processes
13219  
13220 =head3 Fork()
13221  
13222 Fork.
13223  
13224  
13225 B<Example:>
13226  
13227  
13228
13229 Fork; # Fork # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13230  
13231
13232 Test rax,rax;
13233 IfNz # Parent
13234 Then
13235 {Mov rbx, rax;
13236 WaitPid;
13237 GetPid; # Pid of parent as seen in parent
13238 Mov rcx,rax;
13239 PrintOutRegisterInHex rax, rbx, rcx;
13240 },
13241 Else # Child
13242 {Mov r8,rax;
13243 GetPid; # Child pid as seen in child
13244 Mov r9,rax;
13245 GetPPid; # Parent pid as seen in child
13246 Mov r10,rax;
13247 PrintOutRegisterInHex r8, r9, r10;
13248 };
13249
13250 my $r = Assemble;
13251
13252 # r8: 0000 0000 0000 0000 #1 Return from fork as seen by child
13253 # r9: 0000 0000 0003 0C63 #2 Pid of child
13254 # r10: 0000 0000 0003 0C60 #3 Pid of parent from child
13255 # rax: 0000 0000 0003 0C63 #4 Return from fork as seen by parent
13256 # rbx: 0000 0000 0003 0C63 #5 Wait for child pid result
13257 # rcx: 0000 0000 0003 0C60 #6 Pid of parent
13258
13259 if ($r =~ m(r8:( 0000){4}.*r9:(.*)\s{5,}r10:(.*)\s{5,}rax:(.*)\s{5,}rbx:(.*)\s{5,}rcx:(.*)\s{2,})s)
13260 {ok $2 eq $4;
13261 ok $2 eq $5;
13262 ok $3 eq $6;
13263 ok $2 gt $6;
13264 }
13265
13266  
13267 =head3 GetPid()
13268  
13269 Get process identifier.
13270  
13271  
13272 B<Example:>
13273  
13274  
13275 Fork; # Fork
13276
13277 Test rax,rax;
13278 IfNz # Parent
13279 Then
13280 {Mov rbx, rax;
13281 WaitPid;
13282
13283 GetPid; # Pid of parent as seen in parent # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13284  
13285 Mov rcx,rax;
13286 PrintOutRegisterInHex rax, rbx, rcx;
13287 },
13288 Else # Child
13289 {Mov r8,rax;
13290
13291 GetPid; # Child pid as seen in child # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13292  
13293 Mov r9,rax;
13294 GetPPid; # Parent pid as seen in child
13295 Mov r10,rax;
13296 PrintOutRegisterInHex r8, r9, r10;
13297 };
13298
13299 my $r = Assemble;
13300
13301 # r8: 0000 0000 0000 0000 #1 Return from fork as seen by child
13302 # r9: 0000 0000 0003 0C63 #2 Pid of child
13303 # r10: 0000 0000 0003 0C60 #3 Pid of parent from child
13304 # rax: 0000 0000 0003 0C63 #4 Return from fork as seen by parent
13305 # rbx: 0000 0000 0003 0C63 #5 Wait for child pid result
13306 # rcx: 0000 0000 0003 0C60 #6 Pid of parent
13307
13308 if ($r =~ m(r8:( 0000){4}.*r9:(.*)\s{5,}r10:(.*)\s{5,}rax:(.*)\s{5,}rbx:(.*)\s{5,}rcx:(.*)\s{2,})s)
13309 {ok $2 eq $4;
13310 ok $2 eq $5;
13311 ok $3 eq $6;
13312 ok $2 gt $6;
13313 }
13314
13315  
13316 =head3 GetPidInHex()
13317  
13318 Get process identifier in hex as 8 zero terminated bytes in rax.
13319  
13320  
13321 B<Example:>
13322  
13323  
13324
13325 GetPidInHex; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13326  
13327 PrintOutRegisterInHex rax;
13328
13329 ok Assemble =~ m(rax: 00);
13330
13331  
13332 =head3 GetPPid()
13333  
13334 Get parent process identifier.
13335  
13336  
13337 B<Example:>
13338  
13339  
13340 Fork; # Fork
13341
13342 Test rax,rax;
13343 IfNz # Parent
13344 Then
13345 {Mov rbx, rax;
13346 WaitPid;
13347 GetPid; # Pid of parent as seen in parent
13348 Mov rcx,rax;
13349 PrintOutRegisterInHex rax, rbx, rcx;
13350 },
13351 Else # Child
13352 {Mov r8,rax;
13353 GetPid; # Child pid as seen in child
13354 Mov r9,rax;
13355
13356 GetPPid; # Parent pid as seen in child # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13357  
13358 Mov r10,rax;
13359 PrintOutRegisterInHex r8, r9, r10;
13360 };
13361
13362 my $r = Assemble;
13363
13364 # r8: 0000 0000 0000 0000 #1 Return from fork as seen by child
13365 # r9: 0000 0000 0003 0C63 #2 Pid of child
13366 # r10: 0000 0000 0003 0C60 #3 Pid of parent from child
13367 # rax: 0000 0000 0003 0C63 #4 Return from fork as seen by parent
13368 # rbx: 0000 0000 0003 0C63 #5 Wait for child pid result
13369 # rcx: 0000 0000 0003 0C60 #6 Pid of parent
13370
13371 if ($r =~ m(r8:( 0000){4}.*r9:(.*)\s{5,}r10:(.*)\s{5,}rax:(.*)\s{5,}rbx:(.*)\s{5,}rcx:(.*)\s{2,})s)
13372 {ok $2 eq $4;
13373 ok $2 eq $5;
13374 ok $3 eq $6;
13375 ok $2 gt $6;
13376 }
13377
13378  
13379 =head3 GetUid()
13380  
13381 Get userid of current process.
13382  
13383  
13384 B<Example:>
13385  
13386  
13387
13388 GetUid; # Userid # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13389  
13390 PrintOutRegisterInHex rax;
13391
13392 my $r = Assemble;
13393 ok $r =~ m(rax:( 0000){3});
13394
13395  
13396 =head3 WaitPid()
13397  
13398 Wait for the pid in rax to complete.
13399  
13400  
13401 B<Example:>
13402  
13403  
13404 Fork; # Fork
13405
13406 Test rax,rax;
13407 IfNz # Parent
13408 Then
13409 {Mov rbx, rax;
13410
13411 WaitPid; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13412  
13413 GetPid; # Pid of parent as seen in parent
13414 Mov rcx,rax;
13415 PrintOutRegisterInHex rax, rbx, rcx;
13416 },
13417 Else # Child
13418 {Mov r8,rax;
13419 GetPid; # Child pid as seen in child
13420 Mov r9,rax;
13421 GetPPid; # Parent pid as seen in child
13422 Mov r10,rax;
13423 PrintOutRegisterInHex r8, r9, r10;
13424 };
13425
13426 my $r = Assemble;
13427
13428 # r8: 0000 0000 0000 0000 #1 Return from fork as seen by child
13429 # r9: 0000 0000 0003 0C63 #2 Pid of child
13430 # r10: 0000 0000 0003 0C60 #3 Pid of parent from child
13431 # rax: 0000 0000 0003 0C63 #4 Return from fork as seen by parent
13432 # rbx: 0000 0000 0003 0C63 #5 Wait for child pid result
13433 # rcx: 0000 0000 0003 0C60 #6 Pid of parent
13434
13435 if ($r =~ m(r8:( 0000){4}.*r9:(.*)\s{5,}r10:(.*)\s{5,}rax:(.*)\s{5,}rbx:(.*)\s{5,}rcx:(.*)\s{2,})s)
13436 {ok $2 eq $4;
13437 ok $2 eq $5;
13438 ok $3 eq $6;
13439 ok $2 gt $6;
13440 }
13441
13442  
13443 =head3 ReadTimeStampCounter()
13444  
13445 Read the time stamp counter and return the time in nanoseconds in rax.
13446  
13447  
13448 B<Example:>
13449  
13450  
13451 for(1..10)
13452
13453 {ReadTimeStampCounter; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13454  
13455 PrintOutRegisterInHex rax;
13456 }
13457
13458 my @s = split /
13459 /, Assemble;
13460 my @S = sort @s;
13461 is_deeply \@s, \@S;
13462
13463  
13464 =head2 Memory
13465  
13466 Allocate and print memory
13467  
13468 =head3 PrintMemoryInHex($channel)
13469  
13470 Dump memory from the address in rax for the length in rdi on the specified channel. As this method prints in blocks of 8 up to 7 bytes will be missing from the end unless the length is a multiple of 8 .
13471  
13472 Parameter Description
13473 1 $channel Channel
13474  
13475 =head3 PrintErrMemoryInHex()
13476  
13477 Dump memory from the address in rax for the length in rdi on stderr.
13478  
13479  
13480 =head3 PrintOutMemoryInHex()
13481  
13482 Dump memory from the address in rax for the length in rdi on stdout.
13483  
13484  
13485 B<Example:>
13486  
13487  
13488 Mov rax, 0x07654321;
13489 Shl rax, 32;
13490 Or rax, 0x07654321;
13491 PushR rax;
13492
13493 PrintOutRaxInHex;
13494 PrintOutNL;
13495 PrintOutRaxInReverseInHex;
13496 PrintOutNL;
13497
13498 Mov rax, rsp;
13499 Mov rdi, 8;
13500
13501 PrintOutMemoryInHex; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13502  
13503 PrintOutNL;
13504 PopR rax;
13505
13506 Mov rax, 4096;
13507 PushR rax;
13508 Mov rax, rsp;
13509 Mov rdi, 8;
13510
13511 PrintOutMemoryInHex; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13512  
13513 PrintOutNL;
13514 PopR rax;
13515
13516 ok Assemble(debug => 0, eq => <<END);
13517 0765 4321 0765 4321
13518 2143 6507 2143 6507
13519 2143 6507 2143 6507
13520 0010 0000 0000 0000
13521 END
13522
13523  
13524 =head3 PrintErrMemoryInHexNL()
13525  
13526 Dump memory from the address in rax for the length in rdi and then print a new line.
13527  
13528  
13529 =head3 PrintOutMemoryInHexNL()
13530  
13531 Dump memory from the address in rax for the length in rdi and then print a new line.
13532  
13533  
13534 B<Example:>
13535  
13536  
13537 my $N = 256;
13538 my $s = Rb 0..$N-1;
13539 AllocateMemory(K(size, $N), my $a = V(address));
13540 CopyMemory(V(source, $s), V(size, $N), target => $a);
13541
13542 AllocateMemory(K(size, $N), my $b = V(address));
13543 CopyMemory(source => $a, target => $b, K(size, $N));
13544
13545 $b->setReg(rax);
13546 Mov rdi, $N;
13547
13548 PrintOutMemoryInHexNL; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13549  
13550
13551 ok Assemble(debug=>0, eq => <<END);
13552 0001 0203 0405 06070809 0A0B 0C0D 0E0F1011 1213 1415 16171819 1A1B 1C1D 1E1F2021 2223 2425 26272829 2A2B 2C2D 2E2F3031 3233 3435 36373839 3A3B 3C3D 3E3F4041 4243 4445 46474849 4A4B 4C4D 4E4F5051 5253 5455 56575859 5A5B 5C5D 5E5F6061 6263 6465 66676869 6A6B 6C6D 6E6F7071 7273 7475 76777879 7A7B 7C7D 7E7F8081 8283 8485 86878889 8A8B 8C8D 8E8F9091 9293 9495 96979899 9A9B 9C9D 9E9FA0A1 A2A3 A4A5 A6A7A8A9 AAAB ACAD AEAFB0B1 B2B3 B4B5 B6B7B8B9 BABB BCBD BEBFC0C1 C2C3 C4C5 C6C7C8C9 CACB CCCD CECFD0D1 D2D3 D4D5 D6D7D8D9 DADB DCDD DEDFE0E1 E2E3 E4E5 E6E7E8E9 EAEB ECED EEEFF0F1 F2F3 F4F5 F6F7F8F9 FAFB FCFD FEFF
13553 END
13554
13555  
13556 =head3 PrintMemory($channel)
13557  
13558 Print the memory addressed by rax for a length of rdi on the specified channel.
13559  
13560 Parameter Description
13561 1 $channel Channel
13562  
13563 B<Example:>
13564  
13565  
13566 my $file = G(file, Rs($0));
13567 my $size = G(size);
13568 my $address = G(address);
13569 ReadFile $file, $size, $address; # Read file
13570 $address->setReg(rax); # Address of file in memory
13571 $size ->setReg(rdi); # Length of file in memory
13572 PrintOutMemory; # Print contents of memory to stdout
13573
13574 my $r = Assemble; # Assemble and execute
13575 ok stringMd5Sum($r) eq fileMd5Sum($0); # Output contains this file
13576
13577  
13578 =head3 PrintMemoryNL()
13579  
13580 Print the memory addressed by rax for a length of rdi on the specified channel followed by a new line.
13581  
13582  
13583 =head3 PrintErrMemory()
13584  
13585 Print the memory addressed by rax for a length of rdi on stderr.
13586  
13587  
13588 =head3 PrintOutMemory()
13589  
13590 Print the memory addressed by rax for a length of rdi on stdout.
13591  
13592  
13593 B<Example:>
13594  
13595  
13596 Comment "Print a string from memory";
13597 my $s = "Hello World";
13598 Mov rax, Rs($s);
13599 Mov rdi, length $s;
13600
13601 PrintOutMemory; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13602  
13603 Exit(0);
13604
13605 ok Assemble =~ m(Hello World);
13606
13607  
13608 =head3 PrintErrMemoryNL()
13609  
13610 Print the memory addressed by rax for a length of rdi followed by a new line on stderr.
13611  
13612  
13613 =head3 PrintOutMemoryNL()
13614  
13615 Print the memory addressed by rax for a length of rdi followed by a new line on stdout.
13616  
13617  
13618 B<Example:>
13619  
13620  
13621 my $s = Rs("Hello World
13622  
13623 Hello Skye");
13624 Mov rax, $s;
13625 Cstrlen;
13626 Mov rdi, r15;
13627
13628 PrintOutMemoryNL; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13629  
13630
13631 ok Assemble(debug => 0, eq => <<END);
13632 Hello World
13633
13634 Hello Skye
13635 END
13636
13637  
13638 =head3 AllocateMemory(@variables)
13639  
13640 Allocate the specified amount of memory via mmap and return its address.
13641  
13642 Parameter Description
13643 1 @variables Parameters
13644  
13645 B<Example:>
13646  
13647  
13648 my $N = V(size, 2048);
13649 my $q = Rs('a'..'p');
13650
13651 AllocateMemory($N, my $address = V(address)); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13652  
13653
13654 Vmovdqu8 xmm0, "[$q]";
13655 $address->setReg(rax);
13656 Vmovdqu8 "[rax]", xmm0;
13657 Mov rdi, 16;
13658 PrintOutMemory;
13659 PrintOutNL;
13660
13661 FreeMemory(address => $address, size=> $N);
13662
13663 ok Assemble(debug => 0, eq => <<END);
13664 abcdefghijklmnop
13665 END
13666
13667 my $N = V(size, 4096); # Size of the initial allocation which should be one or more pages
13668
13669
13670 AllocateMemory($N, my $A = V(address)); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13671  
13672
13673 ClearMemory($N, $A);
13674
13675 $A->setReg(rax);
13676 Mov rdi, 128;
13677 PrintOutMemoryInHexNL;
13678
13679 FreeMemory($N, $A);
13680
13681 ok Assemble(debug => 1, eq => <<END);
13682 0000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
13683 END
13684
13685 my $N = 256;
13686 my $s = Rb 0..$N-1;
13687
13688 AllocateMemory(K(size, $N), my $a = V(address)); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13689  
13690 CopyMemory(V(source, $s), V(size, $N), target => $a);
13691
13692
13693 AllocateMemory(K(size, $N), my $b = V(address)); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13694  
13695 CopyMemory(source => $a, target => $b, K(size, $N));
13696
13697 $b->setReg(rax);
13698 Mov rdi, $N;
13699 PrintOutMemoryInHexNL;
13700
13701 ok Assemble(debug=>0, eq => <<END);
13702 0001 0203 0405 06070809 0A0B 0C0D 0E0F1011 1213 1415 16171819 1A1B 1C1D 1E1F2021 2223 2425 26272829 2A2B 2C2D 2E2F3031 3233 3435 36373839 3A3B 3C3D 3E3F4041 4243 4445 46474849 4A4B 4C4D 4E4F5051 5253 5455 56575859 5A5B 5C5D 5E5F6061 6263 6465 66676869 6A6B 6C6D 6E6F7071 7273 7475 76777879 7A7B 7C7D 7E7F8081 8283 8485 86878889 8A8B 8C8D 8E8F9091 9293 9495 96979899 9A9B 9C9D 9E9FA0A1 A2A3 A4A5 A6A7A8A9 AAAB ACAD AEAFB0B1 B2B3 B4B5 B6B7B8B9 BABB BCBD BEBFC0C1 C2C3 C4C5 C6C7C8C9 CACB CCCD CECFD0D1 D2D3 D4D5 D6D7D8D9 DADB DCDD DEDFE0E1 E2E3 E4E5 E6E7E8E9 EAEB ECED EEEFF0F1 F2F3 F4F5 F6F7F8F9 FAFB FCFD FEFF
13703 END
13704
13705  
13706 =head3 FreeMemory(@variables)
13707  
13708 Free memory.
13709  
13710 Parameter Description
13711 1 @variables Variables
13712  
13713 B<Example:>
13714  
13715  
13716 my $N = V(size, 4096); # Size of the initial allocation which should be one or more pages
13717
13718 AllocateMemory($N, my $A = V(address));
13719
13720 ClearMemory($N, $A);
13721
13722 $A->setReg(rax);
13723 Mov rdi, 128;
13724 PrintOutMemoryInHexNL;
13725
13726
13727 FreeMemory($N, $A); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13728  
13729
13730 ok Assemble(debug => 1, eq => <<END);
13731 0000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
13732 END
13733
13734  
13735 =head3 ClearMemory(@variables)
13736  
13737 Clear memory.
13738  
13739 Parameter Description
13740 1 @variables Variables
13741  
13742 B<Example:>
13743  
13744  
13745 K(loop, 8+1)->for(sub
13746 {my ($index, $start, $next, $end) = @_;
13747 $index->setReg(r15);
13748 Push r15;
13749 });
13750
13751 Mov rax, rsp;
13752 Mov rdi, 8*9;
13753 PrintOutMemoryInHexNL;
13754
13755 ClearMemory(K(size, 8*9), V(address, rax)); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13756  
13757 PrintOutMemoryInHexNL;
13758
13759 ok Assemble(debug => 0, eq => <<END);
13760 0800 0000 0000 00000700 0000 0000 00000600 0000 0000 00000500 0000 0000 00000400 0000 0000 00000300 0000 0000 00000200 0000 0000 00000100 0000 0000 00000000 0000 0000 0000
13761 0000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
13762 END
13763
13764 my $N = V(size, 4096); # Size of the initial allocation which should be one or more pages
13765
13766 AllocateMemory($N, my $A = V(address));
13767
13768
13769 ClearMemory($N, $A); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13770  
13771
13772 $A->setReg(rax);
13773 Mov rdi, 128;
13774 PrintOutMemoryInHexNL;
13775
13776 FreeMemory($N, $A);
13777
13778 ok Assemble(debug => 1, eq => <<END);
13779 0000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
13780 END
13781
13782  
13783 =head3 MaskMemory22(@variables)
13784  
13785 Write the specified byte into locations in the target mask that correspond to the locations in the source that contain the specified byte.
13786  
13787 Parameter Description
13788 1 @variables Variables
13789  
13790 =head3 MaskMemoryInRange4_22(@variables)
13791  
13792 Write the specified byte into locations in the target mask that correspond to the locations in the source that contain 4 bytes in the specified range.
13793  
13794 Parameter Description
13795 1 @variables Variables
13796  
13797 =head3 CopyMemory(@variables)
13798  
13799 Copy memory, the target is addressed by rax, the length is in rdi, the source is addressed by rsi.
13800  
13801 Parameter Description
13802 1 @variables Variables
13803  
13804 B<Example:>
13805  
13806  
13807 my $s = Rb 0; Rb 1; Rw 2; Rd 3; Rq 4;
13808 my $t = Db 0; Db 1; Dw 2; Dd 3; Dq 4;
13809
13810 Vmovdqu8 xmm0, "[$s]";
13811 Vmovdqu8 xmm1, "[$t]";
13812 PrintOutRegisterInHex xmm0;
13813 PrintOutRegisterInHex xmm1;
13814 Sub rsp, 16;
13815
13816 Mov rax, rsp; # Copy memory, the target is addressed by rax, the length is in rdi, the source is addressed by rsi
13817 Mov rdi, 16;
13818 Mov rsi, $s;
13819
13820 CopyMemory(V(source, rsi), V(target, rax), V(size, rdi)); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13821  
13822 PrintOutMemoryInHex;
13823
13824 my $r = Assemble;
13825 ok $r =~ m(xmm0: 0000 0000 0000 0004 0000 0003 0002 0100);
13826 ok $r =~ m(xmm1: 0000 0000 0000 0004 0000 0003 0002 0100);
13827 ok $r =~ m(0001 0200 0300 00000400 0000 0000 0000);
13828
13829 my $N = 256;
13830 my $s = Rb 0..$N-1;
13831 AllocateMemory(K(size, $N), my $a = V(address));
13832
13833 CopyMemory(V(source, $s), V(size, $N), target => $a); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13834  
13835
13836 AllocateMemory(K(size, $N), my $b = V(address));
13837
13838 CopyMemory(source => $a, target => $b, K(size, $N)); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13839  
13840
13841 $b->setReg(rax);
13842 Mov rdi, $N;
13843 PrintOutMemoryInHexNL;
13844
13845 ok Assemble(debug=>0, eq => <<END);
13846 0001 0203 0405 06070809 0A0B 0C0D 0E0F1011 1213 1415 16171819 1A1B 1C1D 1E1F2021 2223 2425 26272829 2A2B 2C2D 2E2F3031 3233 3435 36373839 3A3B 3C3D 3E3F4041 4243 4445 46474849 4A4B 4C4D 4E4F5051 5253 5455 56575859 5A5B 5C5D 5E5F6061 6263 6465 66676869 6A6B 6C6D 6E6F7071 7273 7475 76777879 7A7B 7C7D 7E7F8081 8283 8485 86878889 8A8B 8C8D 8E8F9091 9293 9495 96979899 9A9B 9C9D 9E9FA0A1 A2A3 A4A5 A6A7A8A9 AAAB ACAD AEAFB0B1 B2B3 B4B5 B6B7B8B9 BABB BCBD BEBFC0C1 C2C3 C4C5 C6C7C8C9 CACB CCCD CECFD0D1 D2D3 D4D5 D6D7D8D9 DADB DCDD DEDFE0E1 E2E3 E4E5 E6E7E8E9 EAEB ECED EEEFF0F1 F2F3 F4F5 F6F7F8F9 FAFB FCFD FEFF
13847 END
13848
13849  
13850 =head2 Files
13851  
13852 Interact with the operating system via files.
13853  
13854 =head3 OpenRead()
13855  
13856 Open a file, whose name is addressed by rax, for read and return the file descriptor in rax.
13857  
13858  
13859 B<Example:>
13860  
13861  
13862 Mov rax, Rs($0); # File to read
13863
13864 OpenRead; # Open file # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13865  
13866 PrintOutRegisterInHex rax;
13867 CloseFile; # Close file
13868 PrintOutRegisterInHex rax;
13869
13870 Mov rax, Rs(my $f = "zzzTemporaryFile.txt"); # File to write
13871 OpenWrite; # Open file
13872 CloseFile; # Close file
13873
13874 ok Assemble(debug => 0, eq => <<END);
13875 rax: 0000 0000 0000 0003
13876 rax: 0000 0000 0000 0000
13877 END
13878 ok -e $f; # Created file
13879 unlink $f;
13880
13881  
13882 =head3 OpenWrite()
13883  
13884 Create the file named by the terminated string addressed by rax for write.
13885  
13886  
13887 B<Example:>
13888  
13889  
13890 Mov rax, Rs($0); # File to read
13891 OpenRead; # Open file
13892 PrintOutRegisterInHex rax;
13893 CloseFile; # Close file
13894 PrintOutRegisterInHex rax;
13895
13896 Mov rax, Rs(my $f = "zzzTemporaryFile.txt"); # File to write
13897
13898 OpenWrite; # Open file # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13899  
13900 CloseFile; # Close file
13901
13902 ok Assemble(debug => 0, eq => <<END);
13903 rax: 0000 0000 0000 0003
13904 rax: 0000 0000 0000 0000
13905 END
13906 ok -e $f; # Created file
13907 unlink $f;
13908
13909  
13910 =head3 CloseFile()
13911  
13912 Close the file whose descriptor is in rax.
13913  
13914  
13915 B<Example:>
13916  
13917  
13918 Mov rax, Rs($0); # File to read
13919 OpenRead; # Open file
13920 PrintOutRegisterInHex rax;
13921
13922 CloseFile; # Close file # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13923  
13924 PrintOutRegisterInHex rax;
13925
13926 Mov rax, Rs(my $f = "zzzTemporaryFile.txt"); # File to write
13927 OpenWrite; # Open file
13928
13929 CloseFile; # Close file # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13930  
13931
13932 ok Assemble(debug => 0, eq => <<END);
13933 rax: 0000 0000 0000 0003
13934 rax: 0000 0000 0000 0000
13935 END
13936 ok -e $f; # Created file
13937 unlink $f;
13938
13939  
13940 =head3 StatSize()
13941  
13942 Stat a file whose name is addressed by rax to get its size in rax.
13943  
13944  
13945 B<Example:>
13946  
13947  
13948 Mov rax, Rs($0); # File to stat
13949
13950 StatSize; # Stat the file # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13951  
13952 PrintOutRegisterInHex rax;
13953
13954 my $r = Assemble =~ s( ) ()gsr;
13955 if ($r =~ m(rax:([0-9a-f]{16}))is) # Compare file size obtained with that from fileSize()
13956 {is_deeply $1, sprintf("%016X", fileSize($0));
13957 }
13958
13959  
13960 =head3 ReadFile(@variables)
13961  
13962 Read a file whose name is addressed by rax into memory. The address of the mapped memory and its length are returned in registers rax,rdi.
13963  
13964 Parameter Description
13965 1 @variables Variables
13966  
13967 B<Example:>
13968  
13969  
13970 my $file = G(file, Rs($0));
13971 my $size = G(size);
13972 my $address = G(address);
13973
13974 ReadFile $file, $size, $address; # Read file # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13975  
13976 $address->setReg(rax); # Address of file in memory
13977 $size ->setReg(rdi); # Length of file in memory
13978 PrintOutMemory; # Print contents of memory to stdout
13979
13980 my $r = Assemble; # Assemble and execute
13981 ok stringMd5Sum($r) eq fileMd5Sum($0); # Output contains this file
13982
13983  
13984 =head3 executeFileViaBash(@variables)
13985  
13986 Execute the file named in the arena addressed by rax with bash.
13987  
13988 Parameter Description
13989 1 @variables Variables
13990  
13991 B<Example:>
13992  
13993  
13994 my $s = CreateArena; # Create a string
13995 $s->ql(<<END); # Write code to execute
13996 #!/usr/bin/bash
13997 whoami
13998 ls -la
13999 pwd
14000 END
14001 $s->write (my $f = V('file', Rs("zzz.sh"))); # Write code to a file
14002
14003 executeFileViaBash($f); # Execute the file # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
14004  
14005 unlinkFile ($f); # Delete the file
14006
14007 my $u = qx(whoami); chomp($u);
14008 ok Assemble(emulator => 0) =~ m($u); # The Intel Software Development Emulator is way too slow on these operations.
14009
14010  
14011 =head3 unlinkFile(@variables)
14012  
14013 Unlink the named file.
14014  
14015 Parameter Description
14016 1 @variables Variables
14017  
14018 B<Example:>
14019  
14020  
14021 my $s = CreateArena; # Create a string
14022 $s->ql(<<END); # Write code to execute
14023 #!/usr/bin/bash
14024 whoami
14025 ls -la
14026 pwd
14027 END
14028 $s->write (my $f = V('file', Rs("zzz.sh"))); # Write code to a file
14029 executeFileViaBash($f); # Execute the file
14030
14031 unlinkFile ($f); # Delete the file # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
14032  
14033
14034 my $u = qx(whoami); chomp($u);
14035 ok Assemble(emulator => 0) =~ m($u); # The Intel Software Development Emulator is way too slow on these operations.
14036
14037  
14038 =head1 Hash functions
14039  
14040 Hash functions
14041  
14042 =head2 Hash()
14043  
14044 Hash a string addressed by rax with length held in rdi and return the hash code in r15.
14045  
14046  
14047 B<Example:>
14048  
14049  
14050 Mov rax, "[rbp+24]";
14051 Cstrlen; # Length of string to hash
14052 Mov rdi, r15;
14053
14054 Hash(); # Hash string # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
14055  
14056
14057 PrintOutRegisterInHex r15;
14058
14059 my $e = Assemble keep=>'hash'; # Assemble to the specified file name
14060 ok qx($e "") =~ m(r15: 0000 3F80 0000 3F80); # Test well known hashes
14061 ok qx($e "a") =~ m(r15: 0000 3F80 C000 45B2);
14062
14063
14064 if (0) # Hash various strings # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
14065  
14066 {my %r; my %f; my $count = 0;
14067 my $N = RegisterSize zmm0;
14068
14069 if (1) # Fixed blocks
14070 {for my $l(qw(a ab abc abcd), 'a a', 'a a')
14071 {for my $i(1..$N)
14072 {my $t = $l x $i;
14073 last if $N < length $t;
14074 my $s = substr($t.(' ' x $N), 0, $N);
14075 next if $f{$s}++;
14076 my $r = qx($e "$s");
14077 say STDERR "$count $r";
14078 if ($r =~ m(^.*r15:\s*(.*)$)m)
14079 {push $r{$1}->@*, $s;
14080 ++$count;
14081 }
14082 }
14083 }
14084 }
14085
14086 if (1) # Variable blocks
14087 {for my $l(qw(a ab abc abcd), '', 'a a', 'a a')
14088 {for my $i(1..$N)
14089 {my $t = $l x $i;
14090 next if $f{$t}++;
14091 my $r = qx($e "$t");
14092 say STDERR "$count $r";
14093 if ($r =~ m(^.*r15:\s*(.*)$)m)
14094 {push $r{$1}->@*, $t;
14095 ++$count;
14096 }
14097 }
14098 }
14099 }
14100 for my $r(keys %r)
14101 {delete $r{$r} if $r{$r}->@* < 2;
14102 }
14103
14104 say STDERR dump(\%r);
14105 say STDERR "Keys hashed: ", $count;
14106 confess "Duplicates : ", scalar keys(%r);
14107 }
14108
14109  
14110 =head1 Unicode
14111  
14112 Convert utf8 to utf32
14113  
14114 =head2 GetNextUtf8CharAsUtf32(@parameters)
14115  
14116 Get the next utf8 encoded character from the addressed memory and return it as a utf32 char.
14117  
14118 Parameter Description
14119 1 @parameters Parameters
14120  
14121 =head2 ConvertUtf8ToUtf32(@parameters)
14122  
14123 Convert a string of utf8 to an allocated block of utf32 and return its address and length.
14124  
14125 Parameter Description
14126 1 @parameters Parameters
14127  
14128 B<Example:>
14129  
14130  
14131 my @p = my ($out, $size, $fail) = (V(out), V(size), V('fail'));
14132
14133 my $Chars = Rb(0x24, 0xc2, 0xa2, 0xc9, 0x91, 0xE2, 0x82, 0xAC, 0xF0, 0x90, 0x8D, 0x88);
14134 my $chars = V(chars, $Chars);
14135
14136 GetNextUtf8CharAsUtf32 in=>$chars, @p; # Dollar UTF-8 Encoding: 0x24 UTF-32 Encoding: 0x00000024
14137 $out->out('out1 : '); $size->outNL(' size : ');
14138
14139 GetNextUtf8CharAsUtf32 in=>$chars+1, @p; # Cents UTF-8 Encoding: 0xC2 0xA2 UTF-32 Encoding: 0x000000a2
14140 $out->out('out2 : '); $size->outNL(' size : ');
14141
14142 GetNextUtf8CharAsUtf32 in=>$chars+3, @p; # Alpha UTF-8 Encoding: 0xC9 0x91 UTF-32 Encoding: 0x00000251
14143 $out->out('out3 : '); $size->outNL(' size : ');
14144
14145 GetNextUtf8CharAsUtf32 in=>$chars+5, @p; # Euro UTF-8 Encoding: 0xE2 0x82 0xAC UTF-32 Encoding: 0x000020AC
14146 $out->out('out4 : '); $size->outNL(' size : ');
14147
14148 GetNextUtf8CharAsUtf32 in=>$chars+8, @p; # Gothic Letter Hwair UTF-8 Encoding 0xF0 0x90 0x8D 0x88 UTF-32 Encoding: 0x00010348
14149 $out->out('out5 : '); $size->outNL(' size : ');
14150
14151 my $statement = qq(𝖺
14152 𝑎𝑠𝑠𝑖𝑔𝑛 【【𝖻 𝐩𝐥𝐮𝐬 𝖼】】
14153 AAAAAAAA); # A sample sentence to parse
14154
14155 my $s = K(statement, Rutf8($statement));
14156 my $l = StringLength string => $s;
14157
14158 AllocateMemory($l, my $address = V(address)); # Allocate enough memory for a copy of the string
14159 CopyMemory(source => $s, target => $address, $l);
14160
14161 GetNextUtf8CharAsUtf32 in=>$address, @p;
14162 $out->out('outA : '); $size->outNL(' size : ');
14163
14164 GetNextUtf8CharAsUtf32 in=>$address+4, @p;
14165 $out->out('outB : '); $size->outNL(' size : ');
14166
14167 GetNextUtf8CharAsUtf32 in=>$address+5, @p;
14168 $out->out('outC : '); $size->outNL(' size : ');
14169
14170 GetNextUtf8CharAsUtf32 in=>$address+30, @p;
14171 $out->out('outD : '); $size->outNL(' size : ');
14172
14173 GetNextUtf8CharAsUtf32 in=>$address+35, @p;
14174 $out->out('outE : '); $size->outNL(' size : ');
14175
14176 $address->printOutMemoryInHexNL($l);
14177
14178 ok Assemble(debug => 0, eq => <<END);
14179 out1 : 0000 0000 0000 0024 size : 0000 0000 0000 0001
14180 out2 : 0000 0000 0000 00A2 size : 0000 0000 0000 0002
14181 out3 : 0000 0000 0000 0251 size : 0000 0000 0000 0002
14182 out4 : 0000 0000 0000 20AC size : 0000 0000 0000 0003
14183 out5 : 0000 0000 0001 0348 size : 0000 0000 0000 0004
14184 outA : 0000 0000 0001 D5BA size : 0000 0000 0000 0004
14185 outB : 0000 0000 0000 000A size : 0000 0000 0000 0001
14186 outC : 0000 0000 0000 0020 size : 0000 0000 0000 0001
14187 outD : 0000 0000 0000 0020 size : 0000 0000 0000 0001
14188 outE : 0000 0000 0000 0010 size : 0000 0000 0000 0002
14189 F09D 96BA 0A20 F09D918E F09D 91A0 F09D91A0 F09D 9196 F09D9194 F09D 919B 20E38090 E380 90F0 9D96BB20 F09D 90A9 F09D90A5 F09D 90AE F09D90AC 20F0 9D96 BCE38091 E380 910A 41414141 4141 4141 0000
14190 END
14191
14192  
14193 =head2 ClassifyInRange(@parameters)
14194  
14195 Character classification: classify the utf32 characters in a block of memory of specified length using a range specification held in zmm0, zmm1 formatted in double words with each word in zmm1 having the classification in the highest 8 bits and with zmm0 and zmm1 having the utf32 character at the start (zmm0) and end (zmm1) of each range in the lower 21 bits. The classification bits from the first matching range are copied into the high (unused) byte of each utf32 character in the block of memory.
14196  
14197 Parameter Description
14198 1 @parameters Parameters
14199  
14200 =head2 ClassifyWithInRange(@parameters)
14201  
14202 Bracket classification: Classify the utf32 characters in a block of memory of specified length using a range specification held in zmm0, zmm1 formatted in double words with the classification range in the highest 8 bits of zmm0 and zmm1 and the utf32 character at the start (zmm0) and end (zmm1) of each range in the lower 21 bits. The classification bits from the position within the first matching range are copied into the high (unused) byte of each utf32 character in the block of memory.
14203  
14204 Parameter Description
14205 1 @parameters Parameters
14206  
14207 =head2 ClassifyWithInRangeAndSaveOffset(@parameters)
14208  
14209 Alphabetic classification: classify the utf32 characters in a block of memory of specified length using a range specification held in zmm0, zmm1 formatted in double words with the classification code in the high byte of zmm1 and the offset of the first element in the range in the high byte of zmm0. The lowest 21 bits of each double word in zmm0 and zmm1 contain the utf32 characters marking the start and end of each range. The classification bits from zmm1 for the first matching range are copied into the high byte of each utf32 character in the block of memory. The offset in the range is copied into the lowest byte of each utf32 character in the block of memory. The middle two bytes are cleared. The net effect is to reduce 21 bits of utf32 to 16 bits.
14210  
14211 Parameter Description
14212 1 @parameters Parameters
14213  
14214 =head1 Short Strings
14215  
14216 Operations on Short Strings
14217  
14218 =head2 CreateShortString($zmm)
14219  
14220 Create a description of a short string.
14221  
14222 Parameter Description
14223 1 $zmm Numbered zmm containing the string
14224  
14225 B<Example:>
14226  
14227  
14228
14229 my $s = CreateShortString(0); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
14230  
14231 my $d = Rb(1..63);
14232 $s->load(K(address, $d), K(size, 9));
14233 PrintOutRegisterInHex xmm0;
14234
14235 $s->len->outNL;
14236
14237 $s->setLength(K(size, 7));
14238 PrintOutRegisterInHex xmm0;
14239
14240 $s->append($s);
14241 PrintOutRegisterInHex ymm0;
14242
14243 $s->appendByte(K(append,0xFF));
14244 PrintOutRegisterInHex ymm0;
14245
14246 ok Assemble(debug => 0, trace => 0, eq => <<END);
14247 xmm0: 0000 0000 0000 0908 0706 0504 0302 0109
14248 size: 0000 0000 0000 0009
14249 xmm0: 0000 0000 0000 0908 0706 0504 0302 0107
14250 ymm0: 0000 0000 0000 0000 0000 0000 0000 0000 0007 0605 0403 0201 0706 0504 0302 010E
14251 ymm0: 0000 0000 0000 0000 0000 0000 0000 0000 FF07 0605 0403 0201 0706 0504 0302 010F
14252 END
14253
14254  
14255 =head2 Nasm::X86::ShortString::clear($string)
14256  
14257 Clear a short string.
14258  
14259 Parameter Description
14260 1 $string String
14261  
14262 =head2 Nasm::X86::ShortString::load($string, $address, $length)
14263  
14264 Load the variable addressed data with the variable length into the short string.
14265  
14266 Parameter Description
14267 1 $string String
14268 2 $address Address
14269 3 $length Length
14270  
14271 B<Example:>
14272  
14273  
14274 my $s = CreateShortString(0);
14275 my $d = Rb(1..63);
14276 $s->load(K(address, $d), K(size, 9));
14277 PrintOutRegisterInHex xmm0;
14278
14279 $s->len->outNL;
14280
14281 $s->setLength(K(size, 7));
14282 PrintOutRegisterInHex xmm0;
14283
14284 $s->append($s);
14285 PrintOutRegisterInHex ymm0;
14286
14287 $s->appendByte(K(append,0xFF));
14288 PrintOutRegisterInHex ymm0;
14289
14290 ok Assemble(debug => 0, trace => 0, eq => <<END);
14291 xmm0: 0000 0000 0000 0908 0706 0504 0302 0109
14292 size: 0000 0000 0000 0009
14293 xmm0: 0000 0000 0000 0908 0706 0504 0302 0107
14294 ymm0: 0000 0000 0000 0000 0000 0000 0000 0000 0007 0605 0403 0201 0706 0504 0302 010E
14295 ymm0: 0000 0000 0000 0000 0000 0000 0000 0000 FF07 0605 0403 0201 0706 0504 0302 010F
14296 END
14297
14298  
14299 =head2 Nasm::X86::ShortString::loadConstantString($string, $data)
14300  
14301 Load the a short string with a constant string.
14302  
14303 Parameter Description
14304 1 $string Short string
14305 2 $data String to load
14306  
14307 =head2 Nasm::X86::ShortString::loadDwordBytes($string, $byte, $address, $length, $Offset)
14308  
14309 Load the specified byte of each dword in the variable addressed data with the variable length into the short string.
14310  
14311 Parameter Description
14312 1 $string String
14313 2 $byte Byte offset 0-3
14314 3 $address Variable address
14315 4 $length Variable length
14316 5 $Offset Variable offset in short string at which to start
14317  
14318 =head2 Nasm::X86::ShortString::len($string)
14319  
14320 Return the length of a short string in a variable.
14321  
14322 Parameter Description
14323 1 $string String
14324  
14325 =head2 Nasm::X86::ShortString::setLength($string, $length)
14326  
14327 Set the length of the short string.
14328  
14329 Parameter Description
14330 1 $string String
14331 2 $length Variable size
14332  
14333 B<Example:>
14334  
14335  
14336 my $s = CreateShortString(0);
14337 my $d = Rb(1..63);
14338 $s->load(K(address, $d), K(size, 9));
14339 PrintOutRegisterInHex xmm0;
14340
14341 $s->len->outNL;
14342
14343 $s->setLength(K(size, 7));
14344 PrintOutRegisterInHex xmm0;
14345
14346 $s->append($s);
14347 PrintOutRegisterInHex ymm0;
14348
14349 $s->appendByte(K(append,0xFF));
14350 PrintOutRegisterInHex ymm0;
14351
14352 ok Assemble(debug => 0, trace => 0, eq => <<END);
14353 xmm0: 0000 0000 0000 0908 0706 0504 0302 0109
14354 size: 0000 0000 0000 0009
14355 xmm0: 0000 0000 0000 0908 0706 0504 0302 0107
14356 ymm0: 0000 0000 0000 0000 0000 0000 0000 0000 0007 0605 0403 0201 0706 0504 0302 010E
14357 ymm0: 0000 0000 0000 0000 0000 0000 0000 0000 FF07 0605 0403 0201 0706 0504 0302 010F
14358 END
14359
14360  
14361 =head2 Nasm::X86::ShortString::appendByte($string, $char)
14362  
14363 Append the lowest variable byte to the specified string.
14364  
14365 Parameter Description
14366 1 $string String
14367 2 $char Variable byte
14368  
14369 =head2 Nasm::X86::ShortString::append($left, $right)
14370  
14371 Append the right hand short string to the left hand short string.
14372  
14373 Parameter Description
14374 1 $left Target zmm
14375 2 $right Source zmm
14376  
14377 B<Example:>
14378  
14379  
14380 my $s = CreateShortString(0);
14381 my $d = Rb(1..63);
14382 $s->load(K(address, $d), K(size, 9));
14383 PrintOutRegisterInHex xmm0;
14384
14385 $s->len->outNL;
14386
14387 $s->setLength(K(size, 7));
14388 PrintOutRegisterInHex xmm0;
14389
14390 $s->append($s);
14391 PrintOutRegisterInHex ymm0;
14392
14393 $s->appendByte(K(append,0xFF));
14394 PrintOutRegisterInHex ymm0;
14395
14396 ok Assemble(debug => 0, trace => 0, eq => <<END);
14397 xmm0: 0000 0000 0000 0908 0706 0504 0302 0109
14398 size: 0000 0000 0000 0009
14399 xmm0: 0000 0000 0000 0908 0706 0504 0302 0107
14400 ymm0: 0000 0000 0000 0000 0000 0000 0000 0000 0007 0605 0403 0201 0706 0504 0302 010E
14401 ymm0: 0000 0000 0000 0000 0000 0000 0000 0000 FF07 0605 0403 0201 0706 0504 0302 010F
14402 END
14403
14404  
14405 =head1 Arenas
14406  
14407 An arena is single extensible block of memory which contains other data structures such as strings, arrays, trees within it.
14408  
14409 =head2 StringLength(@parameters)
14410  
14411 Length of a zero terminated string.
14412  
14413 Parameter Description
14414 1 @parameters Parameters
14415  
14416 B<Example:>
14417  
14418  
14419
14420 StringLength(V(string, Rs("abcd")))->outNL; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
14421  
14422 Assemble(debug => 0, eq => <<END);
14423 size: 0000 0000 0000 0004
14424 END
14425
14426  
14427 =head2 DescribeArena($bs)
14428  
14429 Describe a relocatable arena.
14430  
14431 Parameter Description
14432 1 $bs Optional variable addressing the start of the arena
14433  
14434 =head2 CreateArena(%options)
14435  
14436 Create an relocatable arena and returns its address in rax. We add a chain header so that 64 byte blocks of memory can be freed and reused within the arena.
14437  
14438 Parameter Description
14439 1 %options Free=>1 adds a free chain.
14440  
14441 B<Example:>
14442  
14443  
14444
14445 my $a = CreateArena; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
14446  
14447 $a->q('aa');
14448 $a->out;
14449 PrintOutNL;
14450 ok Assemble(debug => 0, eq => <<END);
14451 aa
14452 END
14453
14454
14455 my $a = CreateArena; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
14456  
14457
14458 my $b = CreateArena; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
14459  
14460 $a->q('aa');
14461 $b->q('bb');
14462 $a->out;
14463 PrintOutNL;
14464 $b->out;
14465 PrintOutNL;
14466 ok Assemble(debug => 0, eq => <<END);
14467 aa
14468 bb
14469 END
14470
14471
14472 my $a = CreateArena; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
14473  
14474
14475 my $b = CreateArena; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
14476  
14477 $a->q('aa');
14478 $a->q('AA');
14479 $a->out;
14480 PrintOutNL;
14481 ok Assemble(debug => 0, eq => <<END);
14482 aaAA
14483 END
14484
14485
14486 my $a = CreateArena; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
14487  
14488
14489 my $b = CreateArena; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
14490  
14491 $a->q('aa');
14492 $b->q('bb');
14493 $a->q('AA');
14494 $b->q('BB');
14495 $a->q('aa');
14496 $b->q('bb');
14497 $a->out;
14498 $b->out;
14499 PrintOutNL;
14500 ok Assemble(debug => 0, eq => <<END);
14501 aaAAaabbBBbb
14502 END
14503
14504
14505 my $a = CreateArena; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
14506  
14507 $a->q('ab');
14508
14509 my $b = CreateArena; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
14510  
14511 $b->append(source=>$a->bs);
14512 $b->append(source=>$a->bs);
14513 $a->append(source=>$b->bs);
14514 $b->append(source=>$a->bs);
14515 $a->append(source=>$b->bs);
14516 $b->append(source=>$a->bs);
14517 $b->append(source=>$a->bs);
14518 $b->append(source=>$a->bs);
14519 $b->append(source=>$a->bs);
14520
14521
14522 $a->out; PrintOutNL; # Print arena
14523 $b->out; PrintOutNL; # Print arena
14524 $a->length(my $sa = V(size)); $sa->outNL;
14525 $b->length(my $sb = V(size)); $sb->outNL;
14526 $a->clear;
14527 $a->length(my $sA = V(size)); $sA->outNL;
14528 $b->length(my $sB = V(size)); $sB->outNL;
14529
14530 ok Assemble(debug => 0, eq => <<END);
14531 abababababababab
14532 ababababababababababababababababababababababababababababababababababababab
14533 size: 0000 0000 0000 0010
14534 size: 0000 0000 0000 004A
14535 size: 0000 0000 0000 0000
14536 size: 0000 0000 0000 004A
14537 END
14538
14539  
14540 =head2 Nasm::X86::Arena::length($arena, @variables)
14541  
14542 Get the length of an arena.
14543  
14544 Parameter Description
14545 1 $arena Arena descriptor
14546 2 @variables Variables
14547  
14548 =head2 Nasm::X86::Arena::arenaSize($arena, @variables)
14549  
14550 Get the size of an arena.
14551  
14552 Parameter Description
14553 1 $arena Arena descriptor
14554 2 @variables Variables
14555  
14556 =head2 Nasm::X86::Arena::makeReadOnly($arena)
14557  
14558 Make an arena read only.
14559  
14560 Parameter Description
14561 1 $arena Arena descriptor
14562  
14563 =head2 Nasm::X86::Arena::makeWriteable($arena)
14564  
14565 Make an arena writable.
14566  
14567 Parameter Description
14568 1 $arena Arena descriptor
14569  
14570 =head2 Nasm::X86::Arena::allocate($arena, @variables)
14571  
14572 Allocate the amount of space indicated in rdi in the arena addressed by rax and return the offset of the allocation in the arena in rdi.
14573  
14574 Parameter Description
14575 1 $arena Arena descriptor
14576 2 @variables Variables
14577  
14578 =head2 Nasm::X86::Arena::allocZmmBlock($arena, @variables)
14579  
14580 Allocate a block to hold a zmm register in the specified arena and return the offset of the block in a variable.
14581  
14582 Parameter Description
14583 1 $arena Arena
14584 2 @variables Variables
14585  
14586 =head2 Nasm::X86::Arena::allocBlock($arena, $bs)
14587  
14588 Allocate a block to hold a zmm register in the specified arena and return the offset of the block in a variable.
14589  
14590 Parameter Description
14591 1 $arena Arena
14592 2 $bs Address of arena
14593  
14594 B<Example:>
14595  
14596  
14597 my $a = CreateArena; $a->dump;
14598 my $b1 = $a->allocBlock($a->bs); $a->dump;
14599 my $b2 = $a->allocBlock($a->bs); $a->dump;
14600 $a->freeBlock($b2); $a->dump;
14601 $a->freeBlock($b1); $a->dump;
14602
14603 ok Assemble(debug => 0, eq => <<END);
14604 Arena
14605 Size: 0000 0000 0000 1000
14606 Used: 0000 0000 0000 0018
14607 0000: 0010 0000 0000 00001800 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
14608 0040: 0000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
14609 0080: 0000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
14610 00C0: 0000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
14611 Arena
14612 Size: 0000 0000 0000 1000
14613 Used: 0000 0000 0000 0058
14614 0000: 0010 0000 0000 00005800 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
14615 0040: 0000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
14616 0080: 0000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
14617 00C0: 0000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
14618 Arena
14619 Size: 0000 0000 0000 1000
14620 Used: 0000 0000 0000 0098
14621 0000: 0010 0000 0000 00009800 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
14622 0040: 0000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
14623 0080: 0000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
14624 00C0: 0000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
14625 Arena
14626 Size: 0000 0000 0000 1000
14627 Used: 0000 0000 0000 0098
14628 0000: 0010 0000 0000 00009800 0000 0000 00005800 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
14629 0040: 0000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
14630 0080: 0000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
14631 00C0: 0000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
14632 Arena
14633 Size: 0000 0000 0000 1000
14634 Used: 0000 0000 0000 0098
14635 0000: 0010 0000 0000 00009800 0000 0000 00001800 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
14636 0040: 0000 0000 0000 00000000 0000 0000 00000000 0000 5800 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
14637 0080: 0000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
14638 00C0: 0000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
14639 END
14640
14641  
14642 =head2 Nasm::X86::Arena::m($arena, @variables)
14643  
14644 Append the content with length rdi addressed by rsi to the arena addressed by rax.
14645  
14646 Parameter Description
14647 1 $arena Arena descriptor
14648 2 @variables Variables
14649  
14650 =head2 Nasm::X86::Arena::q($arena, $string)
14651  
14652 Append a constant string to the arena.
14653  
14654 Parameter Description
14655 1 $arena Arena descriptor
14656 2 $string String
14657  
14658 =head2 Nasm::X86::Arena::ql($arena, $const)
14659  
14660 Append a quoted string containing new line characters to the arena addressed by rax.
14661  
14662 Parameter Description
14663 1 $arena Arena
14664 2 $const Constant
14665  
14666 =head2 Nasm::X86::Arena::char($arena, $char)
14667  
14668 Append a character expressed as a decimal number to the arena addressed by rax.
14669  
14670 Parameter Description
14671 1 $arena Arena descriptor
14672 2 $char Number of character to be appended
14673  
14674 =head2 Nasm::X86::Arena::nl($arena)
14675  
14676 Append a new line to the arena addressed by rax.
14677  
14678 Parameter Description
14679 1 $arena Arena descriptor
14680  
14681 =head2 Nasm::X86::Arena::z($arena)
14682  
14683 Append a trailing zero to the arena addressed by rax.
14684  
14685 Parameter Description
14686 1 $arena Arena descriptor
14687  
14688 =head2 Nasm::X86::Arena::append($arena, @variables)
14689  
14690 Append one arena to another.
14691  
14692 Parameter Description
14693 1 $arena Arena descriptor
14694 2 @variables Variables
14695  
14696 =head2 Nasm::X86::Arena::clear($arena)
14697  
14698 Clear the arena addressed by rax.
14699  
14700 Parameter Description
14701 1 $arena Arena descriptor
14702  
14703 =head2 Nasm::X86::Arena::write($arena, @variables)
14704  
14705 Write the content in an arena addressed by rax to a temporary file and replace the arena content with the name of the temporary file.
14706  
14707 Parameter Description
14708 1 $arena Arena descriptor
14709 2 @variables Variables
14710  
14711 =head2 Nasm::X86::Arena::read($arena, @variables)
14712  
14713 Read the named file (terminated with a zero byte) and place it into the named arena.
14714  
14715 Parameter Description
14716 1 $arena Arena descriptor
14717 2 @variables Variables
14718  
14719 =head2 Nasm::X86::Arena::out($arena)
14720  
14721 Print the specified arena addressed by rax on sysout.
14722  
14723 Parameter Description
14724 1 $arena Arena descriptor
14725  
14726 =head2 Nasm::X86::Arena::dump($arena, $depth)
14727  
14728 Dump details of an arena.
14729  
14730 Parameter Description
14731 1 $arena Arena descriptor
14732 2 $depth Optional amount of memory to dump as the number of 64 byte blocks
14733  
14734 =head1 String
14735  
14736 Strings made from zmm sized blocks of text
14737  
14738 =head2 DescribeString(%options)
14739  
14740 Describe a string.
14741  
14742 Parameter Description
14743 1 %options String options
14744  
14745 =head2 Nasm::X86::Arena::DescribeString22($arena, %options)
14746  
14747 Describe a string and optionally set its first block.
14748  
14749 Parameter Description
14750 1 $arena Arena description
14751 2 %options {first=> offset of first block}
14752  
14753 =head2 Nasm::X86::Arena::DescribeString($arena, %options)
14754  
14755 Describe a string and optionally set its first block .
14756  
14757 Parameter Description
14758 1 $arena Arena description
14759 2 %options Arena options
14760  
14761 =head2 Nasm::X86::Arena::CreateString($arena)
14762  
14763 Create a string from a doubly link linked list of 64 byte blocks linked via 4 byte offsets in an arena and return its descriptor.
14764  
14765 Parameter Description
14766 1 $arena Arena description
14767  
14768 =head2 Nasm::X86::String::dump($String)
14769  
14770 Dump a string to sysout.
14771  
14772 Parameter Description
14773 1 $String String descriptor
14774  
14775 =head2 Nasm::X86::String::len($String, $bs, $first)
14776  
14777 Find the length of a string.
14778  
14779 Parameter Description
14780 1 $String String descriptor
14781 2 $bs Optional arena address
14782 3 $first Offset of first block
14783  
14784 B<Example:>
14785  
14786  
14787 my $c = Rb(0..255);
14788 my $S = CreateArena; my $s = $S->CreateString;
14789
14790 $s->append(source=>V(source, $c), V(size, 165)); $s->dump;
14791 $s->deleteChar(V(position, 0x44)); $s->dump;
14792 $s->len->outNL;
14793
14794 ok Assemble(debug => 0, eq => <<END);
14795 string Dump
14796 Offset: 0000 0000 0000 0018 Length: 0000 0000 0000 0037
14797 zmm31: 0000 0058 0000 0098 3635 3433 3231 302F 2E2D 2C2B 2A29 2827 2625 2423 2221 201F 1E1D 1C1B 1A19 1817 1615 1413 1211 100F 0E0D 0C0B 0A09 0807 0605 0403 0201 0037
14798 Offset: 0000 0000 0000 0058 Length: 0000 0000 0000 0037
14799 zmm31: 0000 0098 0000 0018 6D6C 6B6A 6968 6766 6564 6362 6160 5F5E 5D5C 5B5A 5958 5756 5554 5352 5150 4F4E 4D4C 4B4A 4948 4746 4544 4342 4140 3F3E 3D3C 3B3A 3938 3737
14800 Offset: 0000 0000 0000 0098 Length: 0000 0000 0000 0037
14801 zmm31: 0000 0018 0000 0058 A4A3 A2A1 A09F 9E9D 9C9B 9A99 9897 9695 9493 9291 908F 8E8D 8C8B 8A89 8887 8685 8483 8281 807F 7E7D 7C7B 7A79 7877 7675 7473 7271 706F 6E37
14802
14803 string Dump
14804 Offset: 0000 0000 0000 0018 Length: 0000 0000 0000 0037
14805 zmm31: 0000 0058 0000 0098 3635 3433 3231 302F 2E2D 2C2B 2A29 2827 2625 2423 2221 201F 1E1D 1C1B 1A19 1817 1615 1413 1211 100F 0E0D 0C0B 0A09 0807 0605 0403 0201 0037
14806 Offset: 0000 0000 0000 0058 Length: 0000 0000 0000 0036
14807 zmm31: 0000 0098 0000 0018 186D 6C6B 6A69 6867 6665 6463 6261 605F 5E5D 5C5B 5A59 5857 5655 5453 5251 504F 4E4D 4C4B 4A49 4847 4645 4342 4140 3F3E 3D3C 3B3A 3938 3736
14808 Offset: 0000 0000 0000 0098 Length: 0000 0000 0000 0037
14809 zmm31: 0000 0018 0000 0058 A4A3 A2A1 A09F 9E9D 9C9B 9A99 9897 9695 9493 9291 908F 8E8D 8C8B 8A89 8887 8685 8483 8281 807F 7E7D 7C7B 7A79 7877 7675 7473 7271 706F 6E37
14810
14811 size: 0000 0000 0000 00A4
14812 END
14813
14814  
14815 =head2 Nasm::X86::String::concatenate($target, $source)
14816  
14817 Concatenate two strings by appending a copy of the source to the target string.
14818  
14819 Parameter Description
14820 1 $target Target string
14821 2 $source Source string
14822  
14823 =head2 Nasm::X86::String::insertChar($String, @variables)
14824  
14825 Insert a character into a string.
14826  
14827 Parameter Description
14828 1 $String String
14829 2 @variables Variables
14830  
14831 B<Example:>
14832  
14833  
14834 my $c = Rb(0..255);
14835 my $S = CreateArena;
14836 my $s = $S->CreateString;
14837
14838 $s->append(source=>V(source, $c), K(size, 54)); $s->dump;
14839
14840 $s->insertChar(V(character, 0x77), K(position, 4)); $s->dump;
14841 $s->insertChar(V(character, 0x88), K(position, 5)); $s->dump;
14842 $s->insertChar(V(character, 0x99), K(position, 6)); $s->dump;
14843 $s->insertChar(V(character, 0xAA), K(position, 7)); $s->dump;
14844 $s->insertChar(V(character, 0xBB), K(position, 8)); $s->dump;
14845 $s->insertChar(V(character, 0xCC), K(position, 9)); $s->dump;
14846 $s->insertChar(V(character, 0xDD), K(position, 10)); $s->dump;
14847 $s->insertChar(V(character, 0xEE), K(position, 11)); $s->dump;
14848 $s->insertChar(V(character, 0xFF), K(position, 12)); $s->dump;
14849
14850 ok Assemble(debug => 0, eq => <<END);
14851 string Dump
14852 Offset: 0000 0000 0000 0018 Length: 0000 0000 0000 0036
14853 zmm31: 0000 0018 0000 0018 0035 3433 3231 302F 2E2D 2C2B 2A29 2827 2625 2423 2221 201F 1E1D 1C1B 1A19 1817 1615 1413 1211 100F 0E0D 0C0B 0A09 0807 0605 0403 0201 0036
14854
14855 string Dump
14856 Offset: 0000 0000 0000 0018 Length: 0000 0000 0000 0037
14857 zmm31: 0000 0018 0000 0018 3534 3332 3130 2F2E 2D2C 2B2A 2928 2726 2524 2322 2120 1F1E 1D1C 1B1A 1918 1716 1514 1312 1110 0F0E 0D0C 0B0A 0908 0706 0504 7703 0201 0037
14858
14859 string Dump
14860 Offset: 0000 0000 0000 0018 Length: 0000 0000 0000 0005
14861 zmm31: 0000 0058 0000 0058 3534 3332 3130 2F2E 2D2C 2B2A 2928 2726 2524 2322 2120 1F1E 1D1C 1B1A 1918 1716 1514 1312 1110 0F0E 0D0C 0B0A 0908 0706 0504 7703 0201 0005
14862 Offset: 0000 0000 0000 0058 Length: 0000 0000 0000 0033
14863 zmm31: 0000 0018 0000 0018 0000 0018 3534 3332 3130 2F2E 2D2C 2B2A 2928 2726 2524 2322 2120 1F1E 1D1C 1B1A 1918 1716 1514 1312 1110 0F0E 0D0C 0B0A 0908 0706 0504 8833
14864
14865 string Dump
14866 Offset: 0000 0000 0000 0018 Length: 0000 0000 0000 0005
14867 zmm31: 0000 0058 0000 0058 3534 3332 3130 2F2E 2D2C 2B2A 2928 2726 2524 2322 2120 1F1E 1D1C 1B1A 1918 1716 1514 1312 1110 0F0E 0D0C 0B0A 0908 0706 0504 7703 0201 0005
14868 Offset: 0000 0000 0000 0058 Length: 0000 0000 0000 0034
14869 zmm31: 0000 0018 0000 0018 0000 0035 3433 3231 302F 2E2D 2C2B 2A29 2827 2625 2423 2221 201F 1E1D 1C1B 1A19 1817 1615 1413 1211 100F 0E0D 0C0B 0A09 0807 0605 0499 8834
14870
14871 string Dump
14872 Offset: 0000 0000 0000 0018 Length: 0000 0000 0000 0005
14873 zmm31: 0000 0058 0000 0058 3534 3332 3130 2F2E 2D2C 2B2A 2928 2726 2524 2322 2120 1F1E 1D1C 1B1A 1918 1716 1514 1312 1110 0F0E 0D0C 0B0A 0908 0706 0504 7703 0201 0005
14874 Offset: 0000 0000 0000 0058 Length: 0000 0000 0000 0035
14875 zmm31: 0000 0018 0000 0018 0000 3534 3332 3130 2F2E 2D2C 2B2A 2928 2726 2524 2322 2120 1F1E 1D1C 1B1A 1918 1716 1514 1312 1110 0F0E 0D0C 0B0A 0908 0706 0504 AA99 8835
14876
14877 string Dump
14878 Offset: 0000 0000 0000 0018 Length: 0000 0000 0000 0005
14879 zmm31: 0000 0058 0000 0058 3534 3332 3130 2F2E 2D2C 2B2A 2928 2726 2524 2322 2120 1F1E 1D1C 1B1A 1918 1716 1514 1312 1110 0F0E 0D0C 0B0A 0908 0706 0504 7703 0201 0005
14880 Offset: 0000 0000 0000 0058 Length: 0000 0000 0000 0036
14881 zmm31: 0000 0018 0000 0018 0035 3433 3231 302F 2E2D 2C2B 2A29 2827 2625 2423 2221 201F 1E1D 1C1B 1A19 1817 1615 1413 1211 100F 0E0D 0C0B 0A09 0807 0605 04BB AA99 8836
14882
14883 string Dump
14884 Offset: 0000 0000 0000 0018 Length: 0000 0000 0000 0005
14885 zmm31: 0000 0058 0000 0058 3534 3332 3130 2F2E 2D2C 2B2A 2928 2726 2524 2322 2120 1F1E 1D1C 1B1A 1918 1716 1514 1312 1110 0F0E 0D0C 0B0A 0908 0706 0504 7703 0201 0005
14886 Offset: 0000 0000 0000 0058 Length: 0000 0000 0000 0037
14887 zmm31: 0000 0018 0000 0018 3534 3332 3130 2F2E 2D2C 2B2A 2928 2726 2524 2322 2120 1F1E 1D1C 1B1A 1918 1716 1514 1312 1110 0F0E 0D0C 0B0A 0908 0706 0504 CCBB AA99 8837
14888
14889 string Dump
14890 Offset: 0000 0000 0000 0018 Length: 0000 0000 0000 0005
14891 zmm31: 0000 0058 0000 0058 3534 3332 3130 2F2E 2D2C 2B2A 2928 2726 2524 2322 2120 1F1E 1D1C 1B1A 1918 1716 1514 1312 1110 0F0E 0D0C 0B0A 0908 0706 0504 7703 0201 0005
14892 Offset: 0000 0000 0000 0058 Length: 0000 0000 0000 0005
14893 zmm31: 0000 0098 0000 0098 3534 3332 3130 2F2E 2D2C 2B2A 2928 2726 2524 2322 2120 1F1E 1D1C 1B1A 1918 1716 1514 1312 1110 0F0E 0D0C 0B0A 0908 0706 0504 CCBB AA99 8805
14894 Offset: 0000 0000 0000 0098 Length: 0000 0000 0000 0033
14895 zmm31: 0000 0018 0000 0018 0000 0018 3534 3332 3130 2F2E 2D2C 2B2A 2928 2726 2524 2322 2120 1F1E 1D1C 1B1A 1918 1716 1514 1312 1110 0F0E 0D0C 0B0A 0908 0706 0504 DD33
14896
14897 string Dump
14898 Offset: 0000 0000 0000 0018 Length: 0000 0000 0000 0005
14899 zmm31: 0000 0058 0000 0058 3534 3332 3130 2F2E 2D2C 2B2A 2928 2726 2524 2322 2120 1F1E 1D1C 1B1A 1918 1716 1514 1312 1110 0F0E 0D0C 0B0A 0908 0706 0504 7703 0201 0005
14900 Offset: 0000 0000 0000 0058 Length: 0000 0000 0000 0005
14901 zmm31: 0000 0098 0000 0098 3534 3332 3130 2F2E 2D2C 2B2A 2928 2726 2524 2322 2120 1F1E 1D1C 1B1A 1918 1716 1514 1312 1110 0F0E 0D0C 0B0A 0908 0706 0504 CCBB AA99 8805
14902 Offset: 0000 0000 0000 0098 Length: 0000 0000 0000 0034
14903 zmm31: 0000 0018 0000 0018 0000 0035 3433 3231 302F 2E2D 2C2B 2A29 2827 2625 2423 2221 201F 1E1D 1C1B 1A19 1817 1615 1413 1211 100F 0E0D 0C0B 0A09 0807 0605 04EE DD34
14904
14905 string Dump
14906 Offset: 0000 0000 0000 0018 Length: 0000 0000 0000 0005
14907 zmm31: 0000 0058 0000 0058 3534 3332 3130 2F2E 2D2C 2B2A 2928 2726 2524 2322 2120 1F1E 1D1C 1B1A 1918 1716 1514 1312 1110 0F0E 0D0C 0B0A 0908 0706 0504 7703 0201 0005
14908 Offset: 0000 0000 0000 0058 Length: 0000 0000 0000 0005
14909 zmm31: 0000 0098 0000 0098 3534 3332 3130 2F2E 2D2C 2B2A 2928 2726 2524 2322 2120 1F1E 1D1C 1B1A 1918 1716 1514 1312 1110 0F0E 0D0C 0B0A 0908 0706 0504 CCBB AA99 8805
14910 Offset: 0000 0000 0000 0098 Length: 0000 0000 0000 0035
14911 zmm31: 0000 0018 0000 0018 0000 3534 3332 3130 2F2E 2D2C 2B2A 2928 2726 2524 2322 2120 1F1E 1D1C 1B1A 1918 1716 1514 1312 1110 0F0E 0D0C 0B0A 0908 0706 0504 FFEE DD35
14912
14913 END
14914
14915  
14916 =head2 Nasm::X86::String::deleteChar($String, @variables)
14917  
14918 Delete a character in a string.
14919  
14920 Parameter Description
14921 1 $String String
14922 2 @variables Variables
14923  
14924 B<Example:>
14925  
14926  
14927 my $c = Rb(0..255);
14928 my $S = CreateArena; my $s = $S->CreateString;
14929
14930 $s->append(source=>V(source, $c), V(size, 165)); $s->dump;
14931 $s->deleteChar(V(position, 0x44)); $s->dump;
14932 $s->len->outNL;
14933
14934 ok Assemble(debug => 0, eq => <<END);
14935 string Dump
14936 Offset: 0000 0000 0000 0018 Length: 0000 0000 0000 0037
14937 zmm31: 0000 0058 0000 0098 3635 3433 3231 302F 2E2D 2C2B 2A29 2827 2625 2423 2221 201F 1E1D 1C1B 1A19 1817 1615 1413 1211 100F 0E0D 0C0B 0A09 0807 0605 0403 0201 0037
14938 Offset: 0000 0000 0000 0058 Length: 0000 0000 0000 0037
14939 zmm31: 0000 0098 0000 0018 6D6C 6B6A 6968 6766 6564 6362 6160 5F5E 5D5C 5B5A 5958 5756 5554 5352 5150 4F4E 4D4C 4B4A 4948 4746 4544 4342 4140 3F3E 3D3C 3B3A 3938 3737
14940 Offset: 0000 0000 0000 0098 Length: 0000 0000 0000 0037
14941 zmm31: 0000 0018 0000 0058 A4A3 A2A1 A09F 9E9D 9C9B 9A99 9897 9695 9493 9291 908F 8E8D 8C8B 8A89 8887 8685 8483 8281 807F 7E7D 7C7B 7A79 7877 7675 7473 7271 706F 6E37
14942
14943 string Dump
14944 Offset: 0000 0000 0000 0018 Length: 0000 0000 0000 0037
14945 zmm31: 0000 0058 0000 0098 3635 3433 3231 302F 2E2D 2C2B 2A29 2827 2625 2423 2221 201F 1E1D 1C1B 1A19 1817 1615 1413 1211 100F 0E0D 0C0B 0A09 0807 0605 0403 0201 0037
14946 Offset: 0000 0000 0000 0058 Length: 0000 0000 0000 0036
14947 zmm31: 0000 0098 0000 0018 186D 6C6B 6A69 6867 6665 6463 6261 605F 5E5D 5C5B 5A59 5857 5655 5453 5251 504F 4E4D 4C4B 4A49 4847 4645 4342 4140 3F3E 3D3C 3B3A 3938 3736
14948 Offset: 0000 0000 0000 0098 Length: 0000 0000 0000 0037
14949 zmm31: 0000 0018 0000 0058 A4A3 A2A1 A09F 9E9D 9C9B 9A99 9897 9695 9493 9291 908F 8E8D 8C8B 8A89 8887 8685 8483 8281 807F 7E7D 7C7B 7A79 7877 7675 7473 7271 706F 6E37
14950
14951 size: 0000 0000 0000 00A4
14952 END
14953
14954  
14955 =head2 Nasm::X86::String::getCharacter($String, @variables)
14956  
14957 Get a character from a string.
14958  
14959 Parameter Description
14960 1 $String String
14961 2 @variables Variables
14962  
14963 =head2 Nasm::X86::String::append($String, @variables)
14964  
14965 Append the specified content in memory to the specified string.
14966  
14967 Parameter Description
14968 1 $String String descriptor
14969 2 @variables Variables
14970  
14971 =head2 Nasm::X86::String::appendShortString($string, $short)
14972  
14973 Append the content of the specified short string.
14974  
14975 Parameter Description
14976 1 $string String descriptor
14977 2 $short Short string
14978  
14979 B<Example:>
14980  
14981  
14982 my $a = CreateArena;
14983 my $S = $a->CreateString;
14984
14985 my $s = CreateShortString(0);
14986 my $d = Rb(1..63);
14987 $s->load(K(address, $d), K(size, 9));
14988 $s->append($s);
14989
14990 $S->appendShortString($s);
14991
14992 $S->dump;
14993
14994 ok Assemble(debug => 0, trace => 0, eq => <<END);
14995 string Dump
14996 Offset: 0000 0000 0000 0018 Length: 0000 0000 0000 0012
14997 zmm31: 0000 0018 0000 0018 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0009 0807 0605 0403 0201 0908 0706 0504 0302 0112
14998
14999 END
15000
15001 my $a = CreateArena;
15002 my $t = $a->CreateTree;
15003
15004 my $s = CreateShortString(0);
15005 my $d = Rb(1..63);
15006 $s->load(K(address, $d), K(size, 9));
15007
15008 $t->insertShortString($s, K(data,42));
15009
15010 $t->dump;
15011
15012 ok Assemble(debug => 0, trace => 0, eq => <<END);
15013 Tree at: 0000 0000 0000 0018 length: 0000 0000 0000 0001
15014 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
15015 0000 0000 0000 0002 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0098
15016 0000 0058 0001 0001 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0403 0201
15017 index: 0000 0000 0000 0000 key: 0000 0000 0403 0201 data: 0000 0000 0000 0098 subTree
15018 Tree at: 0000 0000 0000 0098 length: 0000 0000 0000 0001
15019 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
15020 0000 0000 0000 0002 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0118
15021 0000 00D8 0001 0001 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0807 0605
15022 index: 0000 0000 0000 0000 key: 0000 0000 0807 0605 data: 0000 0000 0000 0118 subTree
15023 Tree at: 0000 0000 0000 0118 length: 0000 0000 0000 0001
15024 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
15025 0000 0000 0000 0002 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 002A
15026 0000 0158 0000 0001 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0009
15027 index: 0000 0000 0000 0000 key: 0000 0000 0000 0009 data: 0000 0000 0000 002A
15028 end
15029 end
15030 end
15031 END
15032
15033  
15034 =head2 Nasm::X86::String::saveToShortString($string, $short, $first)
15035  
15036 Place as much as possible of the specified string into the specified short string.
15037  
15038 Parameter Description
15039 1 $string String descriptor
15040 2 $short Short string descriptor
15041 3 $first Optional offset to first block of string
15042  
15043 =head2 Nasm::X86::String::clear($String)
15044  
15045 Clear the block by freeing all but the first block.
15046  
15047 Parameter Description
15048 1 $String String descriptor
15049  
15050 =head1 Array
15051  
15052 Array constructed as a set of blocks in an arena
15053  
15054 =head2 DescribeArray(%options)
15055  
15056 Describe a dynamic array held in an arena.
15057  
15058 Parameter Description
15059 1 %options Array description
15060  
15061 =head2 Nasm::X86::Arena::DescribeArray($arena)
15062  
15063 Describe a dynamic array held in an arena.
15064  
15065 Parameter Description
15066 1 $arena Arena description
15067  
15068 =head2 Nasm::X86::Arena::CreateArray($arena)
15069  
15070 Create a dynamic array held in an arena.
15071  
15072 Parameter Description
15073 1 $arena Arena description
15074  
15075 =head2 Nasm::X86::Array::reload($array, %options)
15076  
15077 Reload the specified array description.
15078  
15079 Parameter Description
15080 1 $array Array descriptor
15081 2 %options {first=>first block of array if not the existing first node; arena=>arena used by array if not the existing arena}
15082  
15083 =head2 Nasm::X86::Array::dump($Array, @variables)
15084  
15085 Dump a array.
15086  
15087 Parameter Description
15088 1 $Array Array descriptor
15089 2 @variables Variables
15090  
15091 =head2 Nasm::X86::Array::push($Array, @variables)
15092  
15093 Push an element onto the array.
15094  
15095 Parameter Description
15096 1 $Array Array descriptor
15097 2 @variables Variables
15098  
15099 B<Example:>
15100  
15101  
15102 my $c = Rb(0..255);
15103 my $A = CreateArena; my $a = $A->CreateArray;
15104 my $l = V(limit, 15);
15105 my $L = $l + 5;
15106
15107 my sub put # Put a constant or a variable
15108 {my ($e) = @_;
15109 $a->push(element => (ref($e) ? $e : V($e, $e)));
15110 };
15111
15112 my sub get # Get a constant or a variable
15113 {my ($i) = @_;
15114 $a->get(index=>(my $v = ref($i) ? $i : K('index', $i)), my $e = V(element));
15115 $v->out("index: ", " "); $e->outNL;
15116 };
15117
15118 $l->for(sub # Loop to the limit pushing
15119 {my ($index, $start, $next, $end) = @_;
15120 put($index+1);
15121 });
15122
15123 $l->for(sub # Loop to the limit getting
15124 {my ($index, $start, $next, $end) = @_;
15125 get($index);
15126 });
15127
15128 put(16);
15129 get(15);
15130
15131 $L->for(sub
15132 {my ($index, $start, $next, $end) = @_;
15133 put($index+$l+2);
15134 });
15135
15136 $L->for(sub
15137 {my ($index, $start, $next, $end) = @_;
15138 get($index + $l + 1);
15139 });
15140
15141 if (1)
15142 {$a->put(my $i = V('index', 9), my $e = V(element, 0xFFF9));
15143 get(9);
15144 }
15145
15146 if (1)
15147 {$a->put(my $i = V('index', 19), my $e = V(element, 0xEEE9));
15148 get(19);
15149 }
15150
15151 ($l+$L+1)->for(sub
15152 {my ($i, $start, $next, $end) = @_;
15153 $a->pop(my $e = V(element));
15154 $e->outNL;
15155 });
15156
15157 V(limit, 38)->for(sub # Push using a loop and reusing the freed space
15158 {my ($index, $start, $next, $end) = @_;
15159 $a->push(element=>$index*2);
15160 });
15161
15162 V(limit, 38)->for(sub # Push using a loop and reusing the freed space
15163 {my ($index, $start, $next, $end) = @_;
15164 $a->pop(my $e = V(element));
15165 $e->outNL;
15166 });
15167
15168 $a->dump;
15169
15170 ok Assemble(debug => 0, eq => <<END);
15171 index: 0000 0000 0000 0000 element: 0000 0000 0000 0001
15172 index: 0000 0000 0000 0001 element: 0000 0000 0000 0002
15173 index: 0000 0000 0000 0002 element: 0000 0000 0000 0003
15174 index: 0000 0000 0000 0003 element: 0000 0000 0000 0004
15175 index: 0000 0000 0000 0004 element: 0000 0000 0000 0005
15176 index: 0000 0000 0000 0005 element: 0000 0000 0000 0006
15177 index: 0000 0000 0000 0006 element: 0000 0000 0000 0007
15178 index: 0000 0000 0000 0007 element: 0000 0000 0000 0008
15179 index: 0000 0000 0000 0008 element: 0000 0000 0000 0009
15180 index: 0000 0000 0000 0009 element: 0000 0000 0000 000A
15181 index: 0000 0000 0000 000A element: 0000 0000 0000 000B
15182 index: 0000 0000 0000 000B element: 0000 0000 0000 000C
15183 index: 0000 0000 0000 000C element: 0000 0000 0000 000D
15184 index: 0000 0000 0000 000D element: 0000 0000 0000 000E
15185 index: 0000 0000 0000 000E element: 0000 0000 0000 000F
15186 index: 0000 0000 0000 000F element: 0000 0000 0000 0010
15187 index: 0000 0000 0000 0010 element: 0000 0000 0000 0011
15188 index: 0000 0000 0000 0011 element: 0000 0000 0000 0012
15189 index: 0000 0000 0000 0012 element: 0000 0000 0000 0013
15190 index: 0000 0000 0000 0013 element: 0000 0000 0000 0014
15191 index: 0000 0000 0000 0014 element: 0000 0000 0000 0015
15192 index: 0000 0000 0000 0015 element: 0000 0000 0000 0016
15193 index: 0000 0000 0000 0016 element: 0000 0000 0000 0017
15194 index: 0000 0000 0000 0017 element: 0000 0000 0000 0018
15195 index: 0000 0000 0000 0018 element: 0000 0000 0000 0019
15196 index: 0000 0000 0000 0019 element: 0000 0000 0000 001A
15197 index: 0000 0000 0000 001A element: 0000 0000 0000 001B
15198 index: 0000 0000 0000 001B element: 0000 0000 0000 001C
15199 index: 0000 0000 0000 001C element: 0000 0000 0000 001D
15200 index: 0000 0000 0000 001D element: 0000 0000 0000 001E
15201 index: 0000 0000 0000 001E element: 0000 0000 0000 001F
15202 index: 0000 0000 0000 001F element: 0000 0000 0000 0020
15203 index: 0000 0000 0000 0020 element: 0000 0000 0000 0021
15204 index: 0000 0000 0000 0021 element: 0000 0000 0000 0022
15205 index: 0000 0000 0000 0022 element: 0000 0000 0000 0023
15206 index: 0000 0000 0000 0023 element: 0000 0000 0000 0024
15207 index: 0000 0000 0000 0009 element: 0000 0000 0000 FFF9
15208 index: 0000 0000 0000 0013 element: 0000 0000 0000 EEE9
15209 element: 0000 0000 0000 0024
15210 element: 0000 0000 0000 0023
15211 element: 0000 0000 0000 0022
15212 element: 0000 0000 0000 0021
15213 element: 0000 0000 0000 0020
15214 element: 0000 0000 0000 001F
15215 element: 0000 0000 0000 001E
15216 element: 0000 0000 0000 001D
15217 element: 0000 0000 0000 001C
15218 element: 0000 0000 0000 001B
15219 element: 0000 0000 0000 001A
15220 element: 0000 0000 0000 0019
15221 element: 0000 0000 0000 0018
15222 element: 0000 0000 0000 0017
15223 element: 0000 0000 0000 0016
15224 element: 0000 0000 0000 0015
15225 element: 0000 0000 0000 EEE9
15226 element: 0000 0000 0000 0013
15227 element: 0000 0000 0000 0012
15228 element: 0000 0000 0000 0011
15229 element: 0000 0000 0000 0010
15230 element: 0000 0000 0000 000F
15231 element: 0000 0000 0000 000E
15232 element: 0000 0000 0000 000D
15233 element: 0000 0000 0000 000C
15234 element: 0000 0000 0000 000B
15235 element: 0000 0000 0000 FFF9
15236 element: 0000 0000 0000 0009
15237 element: 0000 0000 0000 0008
15238 element: 0000 0000 0000 0007
15239 element: 0000 0000 0000 0006
15240 element: 0000 0000 0000 0005
15241 element: 0000 0000 0000 0004
15242 element: 0000 0000 0000 0003
15243 element: 0000 0000 0000 0002
15244 element: 0000 0000 0000 0001
15245 element: 0000 0000 0000 004A
15246 element: 0000 0000 0000 0048
15247 element: 0000 0000 0000 0046
15248 element: 0000 0000 0000 0044
15249 element: 0000 0000 0000 0042
15250 element: 0000 0000 0000 0040
15251 element: 0000 0000 0000 003E
15252 element: 0000 0000 0000 003C
15253 element: 0000 0000 0000 003A
15254 element: 0000 0000 0000 0038
15255 element: 0000 0000 0000 0036
15256 element: 0000 0000 0000 0034
15257 element: 0000 0000 0000 0032
15258 element: 0000 0000 0000 0030
15259 element: 0000 0000 0000 002E
15260 element: 0000 0000 0000 002C
15261 element: 0000 0000 0000 002A
15262 element: 0000 0000 0000 0028
15263 element: 0000 0000 0000 0026
15264 element: 0000 0000 0000 0024
15265 element: 0000 0000 0000 0022
15266 element: 0000 0000 0000 0020
15267 element: 0000 0000 0000 001E
15268 element: 0000 0000 0000 001C
15269 element: 0000 0000 0000 001A
15270 element: 0000 0000 0000 0018
15271 element: 0000 0000 0000 0016
15272 element: 0000 0000 0000 0014
15273 element: 0000 0000 0000 0012
15274 element: 0000 0000 0000 0010
15275 element: 0000 0000 0000 000E
15276 element: 0000 0000 0000 000C
15277 element: 0000 0000 0000 000A
15278 element: 0000 0000 0000 0008
15279 element: 0000 0000 0000 0006
15280 element: 0000 0000 0000 0004
15281 element: 0000 0000 0000 0002
15282 element: 0000 0000 0000 0000
15283 array
15284 Size: 0000 0000 0000 0000 zmm31: 0000 001C 0000 001A 0000 0018 0000 0016 0000 0014 0000 0012 0000 0010 0000 000E 0000 000C 0000 000A 0000 0008 0000 0006 0000 0004 0000 0002 0000 0000 0000 0000
15285 END
15286
15287 my $c = Rb(0..255);
15288 my $A = CreateArena; my $a = $A->CreateArray;
15289
15290 my sub put
15291 {my ($e) = @_;
15292 $a->push(element => V($e, $e));
15293 };
15294
15295 my sub get
15296 {my ($i) = @_; # Parameters
15297 $a->get(my $v = V('index', $i), my $e = V(element));
15298 $v->out; PrintOutString " "; $e->outNL;
15299 };
15300
15301 put($_) for 1..15; get(15);
15302
15303 ok Assemble(debug => 2, eq => <<END);
15304 Index out of bounds on get from array, Index: 0000 0000 0000 000F Size: 0000 0000 0000 000F
15305 END
15306
15307  
15308 =head2 Nasm::X86::Array::pop($Array, @variables)
15309  
15310 Pop an element from an array.
15311  
15312 Parameter Description
15313 1 $Array Array descriptor
15314 2 @variables Variables
15315  
15316 B<Example:>
15317  
15318  
15319 my $c = Rb(0..255);
15320 my $A = CreateArena; my $a = $A->CreateArray;
15321 my $l = V(limit, 15);
15322 my $L = $l + 5;
15323
15324 my sub put # Put a constant or a variable
15325 {my ($e) = @_;
15326 $a->push(element => (ref($e) ? $e : V($e, $e)));
15327 };
15328
15329 my sub get # Get a constant or a variable
15330 {my ($i) = @_;
15331 $a->get(index=>(my $v = ref($i) ? $i : K('index', $i)), my $e = V(element));
15332 $v->out("index: ", " "); $e->outNL;
15333 };
15334
15335 $l->for(sub # Loop to the limit pushing
15336 {my ($index, $start, $next, $end) = @_;
15337 put($index+1);
15338 });
15339
15340 $l->for(sub # Loop to the limit getting
15341 {my ($index, $start, $next, $end) = @_;
15342 get($index);
15343 });
15344
15345 put(16);
15346 get(15);
15347
15348 $L->for(sub
15349 {my ($index, $start, $next, $end) = @_;
15350 put($index+$l+2);
15351 });
15352
15353 $L->for(sub
15354 {my ($index, $start, $next, $end) = @_;
15355 get($index + $l + 1);
15356 });
15357
15358 if (1)
15359 {$a->put(my $i = V('index', 9), my $e = V(element, 0xFFF9));
15360 get(9);
15361 }
15362
15363 if (1)
15364 {$a->put(my $i = V('index', 19), my $e = V(element, 0xEEE9));
15365 get(19);
15366 }
15367
15368 ($l+$L+1)->for(sub
15369 {my ($i, $start, $next, $end) = @_;
15370 $a->pop(my $e = V(element));
15371 $e->outNL;
15372 });
15373
15374 V(limit, 38)->for(sub # Push using a loop and reusing the freed space
15375 {my ($index, $start, $next, $end) = @_;
15376 $a->push(element=>$index*2);
15377 });
15378
15379 V(limit, 38)->for(sub # Push using a loop and reusing the freed space
15380 {my ($index, $start, $next, $end) = @_;
15381 $a->pop(my $e = V(element));
15382 $e->outNL;
15383 });
15384
15385 $a->dump;
15386
15387 ok Assemble(debug => 0, eq => <<END);
15388 index: 0000 0000 0000 0000 element: 0000 0000 0000 0001
15389 index: 0000 0000 0000 0001 element: 0000 0000 0000 0002
15390 index: 0000 0000 0000 0002 element: 0000 0000 0000 0003
15391 index: 0000 0000 0000 0003 element: 0000 0000 0000 0004
15392 index: 0000 0000 0000 0004 element: 0000 0000 0000 0005
15393 index: 0000 0000 0000 0005 element: 0000 0000 0000 0006
15394 index: 0000 0000 0000 0006 element: 0000 0000 0000 0007
15395 index: 0000 0000 0000 0007 element: 0000 0000 0000 0008
15396 index: 0000 0000 0000 0008 element: 0000 0000 0000 0009
15397 index: 0000 0000 0000 0009 element: 0000 0000 0000 000A
15398 index: 0000 0000 0000 000A element: 0000 0000 0000 000B
15399 index: 0000 0000 0000 000B element: 0000 0000 0000 000C
15400 index: 0000 0000 0000 000C element: 0000 0000 0000 000D
15401 index: 0000 0000 0000 000D element: 0000 0000 0000 000E
15402 index: 0000 0000 0000 000E element: 0000 0000 0000 000F
15403 index: 0000 0000 0000 000F element: 0000 0000 0000 0010
15404 index: 0000 0000 0000 0010 element: 0000 0000 0000 0011
15405 index: 0000 0000 0000 0011 element: 0000 0000 0000 0012
15406 index: 0000 0000 0000 0012 element: 0000 0000 0000 0013
15407 index: 0000 0000 0000 0013 element: 0000 0000 0000 0014
15408 index: 0000 0000 0000 0014 element: 0000 0000 0000 0015
15409 index: 0000 0000 0000 0015 element: 0000 0000 0000 0016
15410 index: 0000 0000 0000 0016 element: 0000 0000 0000 0017
15411 index: 0000 0000 0000 0017 element: 0000 0000 0000 0018
15412 index: 0000 0000 0000 0018 element: 0000 0000 0000 0019
15413 index: 0000 0000 0000 0019 element: 0000 0000 0000 001A
15414 index: 0000 0000 0000 001A element: 0000 0000 0000 001B
15415 index: 0000 0000 0000 001B element: 0000 0000 0000 001C
15416 index: 0000 0000 0000 001C element: 0000 0000 0000 001D
15417 index: 0000 0000 0000 001D element: 0000 0000 0000 001E
15418 index: 0000 0000 0000 001E element: 0000 0000 0000 001F
15419 index: 0000 0000 0000 001F element: 0000 0000 0000 0020
15420 index: 0000 0000 0000 0020 element: 0000 0000 0000 0021
15421 index: 0000 0000 0000 0021 element: 0000 0000 0000 0022
15422 index: 0000 0000 0000 0022 element: 0000 0000 0000 0023
15423 index: 0000 0000 0000 0023 element: 0000 0000 0000 0024
15424 index: 0000 0000 0000 0009 element: 0000 0000 0000 FFF9
15425 index: 0000 0000 0000 0013 element: 0000 0000 0000 EEE9
15426 element: 0000 0000 0000 0024
15427 element: 0000 0000 0000 0023
15428 element: 0000 0000 0000 0022
15429 element: 0000 0000 0000 0021
15430 element: 0000 0000 0000 0020
15431 element: 0000 0000 0000 001F
15432 element: 0000 0000 0000 001E
15433 element: 0000 0000 0000 001D
15434 element: 0000 0000 0000 001C
15435 element: 0000 0000 0000 001B
15436 element: 0000 0000 0000 001A
15437 element: 0000 0000 0000 0019
15438 element: 0000 0000 0000 0018
15439 element: 0000 0000 0000 0017
15440 element: 0000 0000 0000 0016
15441 element: 0000 0000 0000 0015
15442 element: 0000 0000 0000 EEE9
15443 element: 0000 0000 0000 0013
15444 element: 0000 0000 0000 0012
15445 element: 0000 0000 0000 0011
15446 element: 0000 0000 0000 0010
15447 element: 0000 0000 0000 000F
15448 element: 0000 0000 0000 000E
15449 element: 0000 0000 0000 000D
15450 element: 0000 0000 0000 000C
15451 element: 0000 0000 0000 000B
15452 element: 0000 0000 0000 FFF9
15453 element: 0000 0000 0000 0009
15454 element: 0000 0000 0000 0008
15455 element: 0000 0000 0000 0007
15456 element: 0000 0000 0000 0006
15457 element: 0000 0000 0000 0005
15458 element: 0000 0000 0000 0004
15459 element: 0000 0000 0000 0003
15460 element: 0000 0000 0000 0002
15461 element: 0000 0000 0000 0001
15462 element: 0000 0000 0000 004A
15463 element: 0000 0000 0000 0048
15464 element: 0000 0000 0000 0046
15465 element: 0000 0000 0000 0044
15466 element: 0000 0000 0000 0042
15467 element: 0000 0000 0000 0040
15468 element: 0000 0000 0000 003E
15469 element: 0000 0000 0000 003C
15470 element: 0000 0000 0000 003A
15471 element: 0000 0000 0000 0038
15472 element: 0000 0000 0000 0036
15473 element: 0000 0000 0000 0034
15474 element: 0000 0000 0000 0032
15475 element: 0000 0000 0000 0030
15476 element: 0000 0000 0000 002E
15477 element: 0000 0000 0000 002C
15478 element: 0000 0000 0000 002A
15479 element: 0000 0000 0000 0028
15480 element: 0000 0000 0000 0026
15481 element: 0000 0000 0000 0024
15482 element: 0000 0000 0000 0022
15483 element: 0000 0000 0000 0020
15484 element: 0000 0000 0000 001E
15485 element: 0000 0000 0000 001C
15486 element: 0000 0000 0000 001A
15487 element: 0000 0000 0000 0018
15488 element: 0000 0000 0000 0016
15489 element: 0000 0000 0000 0014
15490 element: 0000 0000 0000 0012
15491 element: 0000 0000 0000 0010
15492 element: 0000 0000 0000 000E
15493 element: 0000 0000 0000 000C
15494 element: 0000 0000 0000 000A
15495 element: 0000 0000 0000 0008
15496 element: 0000 0000 0000 0006
15497 element: 0000 0000 0000 0004
15498 element: 0000 0000 0000 0002
15499 element: 0000 0000 0000 0000
15500 array
15501 Size: 0000 0000 0000 0000 zmm31: 0000 001C 0000 001A 0000 0018 0000 0016 0000 0014 0000 0012 0000 0010 0000 000E 0000 000C 0000 000A 0000 0008 0000 0006 0000 0004 0000 0002 0000 0000 0000 0000
15502 END
15503
15504  
15505 =head2 Nasm::X86::Array::size($Array, $bs, $first)
15506  
15507 Return the size of an array as a variable.
15508  
15509 Parameter Description
15510 1 $Array Array descriptor
15511 2 $bs Optional arena address
15512 3 $first Optional first block
15513  
15514 B<Example:>
15515  
15516  
15517 my $N = 15;
15518 my $A = CreateArena;
15519 my $a = $A->CreateArray;
15520
15521 $a->push(V(element, $_)) for 1..$N;
15522
15523 K(loop, $N)->for(sub
15524 {my ($start, $end, $next) = @_;
15525 my $l = $a->size;
15526 If $l == 0, Then {Jmp $end};
15527 $a->pop(my $e = V(element));
15528 $e->outNL;
15529 });
15530
15531 ok Assemble(debug => 0, eq => <<END);
15532 element: 0000 0000 0000 000F
15533 element: 0000 0000 0000 000E
15534 element: 0000 0000 0000 000D
15535 element: 0000 0000 0000 000C
15536 element: 0000 0000 0000 000B
15537 element: 0000 0000 0000 000A
15538 element: 0000 0000 0000 0009
15539 element: 0000 0000 0000 0008
15540 element: 0000 0000 0000 0007
15541 element: 0000 0000 0000 0006
15542 element: 0000 0000 0000 0005
15543 element: 0000 0000 0000 0004
15544 element: 0000 0000 0000 0003
15545 element: 0000 0000 0000 0002
15546 element: 0000 0000 0000 0001
15547 END
15548
15549  
15550 =head2 Nasm::X86::Array::get($Array, @variables)
15551  
15552 Get an element from the array.
15553  
15554 Parameter Description
15555 1 $Array Array descriptor
15556 2 @variables Variables
15557  
15558 B<Example:>
15559  
15560  
15561 my $c = Rb(0..255);
15562 my $A = CreateArena; my $a = $A->CreateArray;
15563 my $l = V(limit, 15);
15564 my $L = $l + 5;
15565
15566 my sub put # Put a constant or a variable
15567 {my ($e) = @_;
15568 $a->push(element => (ref($e) ? $e : V($e, $e)));
15569 };
15570
15571 my sub get # Get a constant or a variable
15572 {my ($i) = @_;
15573 $a->get(index=>(my $v = ref($i) ? $i : K('index', $i)), my $e = V(element));
15574 $v->out("index: ", " "); $e->outNL;
15575 };
15576
15577 $l->for(sub # Loop to the limit pushing
15578 {my ($index, $start, $next, $end) = @_;
15579 put($index+1);
15580 });
15581
15582 $l->for(sub # Loop to the limit getting
15583 {my ($index, $start, $next, $end) = @_;
15584 get($index);
15585 });
15586
15587 put(16);
15588 get(15);
15589
15590 $L->for(sub
15591 {my ($index, $start, $next, $end) = @_;
15592 put($index+$l+2);
15593 });
15594
15595 $L->for(sub
15596 {my ($index, $start, $next, $end) = @_;
15597 get($index + $l + 1);
15598 });
15599
15600 if (1)
15601 {$a->put(my $i = V('index', 9), my $e = V(element, 0xFFF9));
15602 get(9);
15603 }
15604
15605 if (1)
15606 {$a->put(my $i = V('index', 19), my $e = V(element, 0xEEE9));
15607 get(19);
15608 }
15609
15610 ($l+$L+1)->for(sub
15611 {my ($i, $start, $next, $end) = @_;
15612 $a->pop(my $e = V(element));
15613 $e->outNL;
15614 });
15615
15616 V(limit, 38)->for(sub # Push using a loop and reusing the freed space
15617 {my ($index, $start, $next, $end) = @_;
15618 $a->push(element=>$index*2);
15619 });
15620
15621 V(limit, 38)->for(sub # Push using a loop and reusing the freed space
15622 {my ($index, $start, $next, $end) = @_;
15623 $a->pop(my $e = V(element));
15624 $e->outNL;
15625 });
15626
15627 $a->dump;
15628
15629 ok Assemble(debug => 0, eq => <<END);
15630 index: 0000 0000 0000 0000 element: 0000 0000 0000 0001
15631 index: 0000 0000 0000 0001 element: 0000 0000 0000 0002
15632 index: 0000 0000 0000 0002 element: 0000 0000 0000 0003
15633 index: 0000 0000 0000 0003 element: 0000 0000 0000 0004
15634 index: 0000 0000 0000 0004 element: 0000 0000 0000 0005
15635 index: 0000 0000 0000 0005 element: 0000 0000 0000 0006
15636 index: 0000 0000 0000 0006 element: 0000 0000 0000 0007
15637 index: 0000 0000 0000 0007 element: 0000 0000 0000 0008
15638 index: 0000 0000 0000 0008 element: 0000 0000 0000 0009
15639 index: 0000 0000 0000 0009 element: 0000 0000 0000 000A
15640 index: 0000 0000 0000 000A element: 0000 0000 0000 000B
15641 index: 0000 0000 0000 000B element: 0000 0000 0000 000C
15642 index: 0000 0000 0000 000C element: 0000 0000 0000 000D
15643 index: 0000 0000 0000 000D element: 0000 0000 0000 000E
15644 index: 0000 0000 0000 000E element: 0000 0000 0000 000F
15645 index: 0000 0000 0000 000F element: 0000 0000 0000 0010
15646 index: 0000 0000 0000 0010 element: 0000 0000 0000 0011
15647 index: 0000 0000 0000 0011 element: 0000 0000 0000 0012
15648 index: 0000 0000 0000 0012 element: 0000 0000 0000 0013
15649 index: 0000 0000 0000 0013 element: 0000 0000 0000 0014
15650 index: 0000 0000 0000 0014 element: 0000 0000 0000 0015
15651 index: 0000 0000 0000 0015 element: 0000 0000 0000 0016
15652 index: 0000 0000 0000 0016 element: 0000 0000 0000 0017
15653 index: 0000 0000 0000 0017 element: 0000 0000 0000 0018
15654 index: 0000 0000 0000 0018 element: 0000 0000 0000 0019
15655 index: 0000 0000 0000 0019 element: 0000 0000 0000 001A
15656 index: 0000 0000 0000 001A element: 0000 0000 0000 001B
15657 index: 0000 0000 0000 001B element: 0000 0000 0000 001C
15658 index: 0000 0000 0000 001C element: 0000 0000 0000 001D
15659 index: 0000 0000 0000 001D element: 0000 0000 0000 001E
15660 index: 0000 0000 0000 001E element: 0000 0000 0000 001F
15661 index: 0000 0000 0000 001F element: 0000 0000 0000 0020
15662 index: 0000 0000 0000 0020 element: 0000 0000 0000 0021
15663 index: 0000 0000 0000 0021 element: 0000 0000 0000 0022
15664 index: 0000 0000 0000 0022 element: 0000 0000 0000 0023
15665 index: 0000 0000 0000 0023 element: 0000 0000 0000 0024
15666 index: 0000 0000 0000 0009 element: 0000 0000 0000 FFF9
15667 index: 0000 0000 0000 0013 element: 0000 0000 0000 EEE9
15668 element: 0000 0000 0000 0024
15669 element: 0000 0000 0000 0023
15670 element: 0000 0000 0000 0022
15671 element: 0000 0000 0000 0021
15672 element: 0000 0000 0000 0020
15673 element: 0000 0000 0000 001F
15674 element: 0000 0000 0000 001E
15675 element: 0000 0000 0000 001D
15676 element: 0000 0000 0000 001C
15677 element: 0000 0000 0000 001B
15678 element: 0000 0000 0000 001A
15679 element: 0000 0000 0000 0019
15680 element: 0000 0000 0000 0018
15681 element: 0000 0000 0000 0017
15682 element: 0000 0000 0000 0016
15683 element: 0000 0000 0000 0015
15684 element: 0000 0000 0000 EEE9
15685 element: 0000 0000 0000 0013
15686 element: 0000 0000 0000 0012
15687 element: 0000 0000 0000 0011
15688 element: 0000 0000 0000 0010
15689 element: 0000 0000 0000 000F
15690 element: 0000 0000 0000 000E
15691 element: 0000 0000 0000 000D
15692 element: 0000 0000 0000 000C
15693 element: 0000 0000 0000 000B
15694 element: 0000 0000 0000 FFF9
15695 element: 0000 0000 0000 0009
15696 element: 0000 0000 0000 0008
15697 element: 0000 0000 0000 0007
15698 element: 0000 0000 0000 0006
15699 element: 0000 0000 0000 0005
15700 element: 0000 0000 0000 0004
15701 element: 0000 0000 0000 0003
15702 element: 0000 0000 0000 0002
15703 element: 0000 0000 0000 0001
15704 element: 0000 0000 0000 004A
15705 element: 0000 0000 0000 0048
15706 element: 0000 0000 0000 0046
15707 element: 0000 0000 0000 0044
15708 element: 0000 0000 0000 0042
15709 element: 0000 0000 0000 0040
15710 element: 0000 0000 0000 003E
15711 element: 0000 0000 0000 003C
15712 element: 0000 0000 0000 003A
15713 element: 0000 0000 0000 0038
15714 element: 0000 0000 0000 0036
15715 element: 0000 0000 0000 0034
15716 element: 0000 0000 0000 0032
15717 element: 0000 0000 0000 0030
15718 element: 0000 0000 0000 002E
15719 element: 0000 0000 0000 002C
15720 element: 0000 0000 0000 002A
15721 element: 0000 0000 0000 0028
15722 element: 0000 0000 0000 0026
15723 element: 0000 0000 0000 0024
15724 element: 0000 0000 0000 0022
15725 element: 0000 0000 0000 0020
15726 element: 0000 0000 0000 001E
15727 element: 0000 0000 0000 001C
15728 element: 0000 0000 0000 001A
15729 element: 0000 0000 0000 0018
15730 element: 0000 0000 0000 0016
15731 element: 0000 0000 0000 0014
15732 element: 0000 0000 0000 0012
15733 element: 0000 0000 0000 0010
15734 element: 0000 0000 0000 000E
15735 element: 0000 0000 0000 000C
15736 element: 0000 0000 0000 000A
15737 element: 0000 0000 0000 0008
15738 element: 0000 0000 0000 0006
15739 element: 0000 0000 0000 0004
15740 element: 0000 0000 0000 0002
15741 element: 0000 0000 0000 0000
15742 array
15743 Size: 0000 0000 0000 0000 zmm31: 0000 001C 0000 001A 0000 0018 0000 0016 0000 0014 0000 0012 0000 0010 0000 000E 0000 000C 0000 000A 0000 0008 0000 0006 0000 0004 0000 0002 0000 0000 0000 0000
15744 END
15745
15746  
15747 =head2 Nasm::X86::Array::put($Array, @variables)
15748  
15749 Put an element into an array as long as it is with in its limits established by pushing.
15750  
15751 Parameter Description
15752 1 $Array Array descriptor
15753 2 @variables Variables
15754  
15755 B<Example:>
15756  
15757  
15758 my $c = Rb(0..255);
15759 my $A = CreateArena; my $a = $A->CreateArray;
15760 my $l = V(limit, 15);
15761 my $L = $l + 5;
15762
15763 my sub put # Put a constant or a variable
15764 {my ($e) = @_;
15765 $a->push(element => (ref($e) ? $e : V($e, $e)));
15766 };
15767
15768 my sub get # Get a constant or a variable
15769 {my ($i) = @_;
15770 $a->get(index=>(my $v = ref($i) ? $i : K('index', $i)), my $e = V(element));
15771 $v->out("index: ", " "); $e->outNL;
15772 };
15773
15774 $l->for(sub # Loop to the limit pushing
15775 {my ($index, $start, $next, $end) = @_;
15776 put($index+1);
15777 });
15778
15779 $l->for(sub # Loop to the limit getting
15780 {my ($index, $start, $next, $end) = @_;
15781 get($index);
15782 });
15783
15784 put(16);
15785 get(15);
15786
15787 $L->for(sub
15788 {my ($index, $start, $next, $end) = @_;
15789 put($index+$l+2);
15790 });
15791
15792 $L->for(sub
15793 {my ($index, $start, $next, $end) = @_;
15794 get($index + $l + 1);
15795 });
15796
15797 if (1)
15798 {$a->put(my $i = V('index', 9), my $e = V(element, 0xFFF9));
15799 get(9);
15800 }
15801
15802 if (1)
15803 {$a->put(my $i = V('index', 19), my $e = V(element, 0xEEE9));
15804 get(19);
15805 }
15806
15807 ($l+$L+1)->for(sub
15808 {my ($i, $start, $next, $end) = @_;
15809 $a->pop(my $e = V(element));
15810 $e->outNL;
15811 });
15812
15813 V(limit, 38)->for(sub # Push using a loop and reusing the freed space
15814 {my ($index, $start, $next, $end) = @_;
15815 $a->push(element=>$index*2);
15816 });
15817
15818 V(limit, 38)->for(sub # Push using a loop and reusing the freed space
15819 {my ($index, $start, $next, $end) = @_;
15820 $a->pop(my $e = V(element));
15821 $e->outNL;
15822 });
15823
15824 $a->dump;
15825
15826 ok Assemble(debug => 0, eq => <<END);
15827 index: 0000 0000 0000 0000 element: 0000 0000 0000 0001
15828 index: 0000 0000 0000 0001 element: 0000 0000 0000 0002
15829 index: 0000 0000 0000 0002 element: 0000 0000 0000 0003
15830 index: 0000 0000 0000 0003 element: 0000 0000 0000 0004
15831 index: 0000 0000 0000 0004 element: 0000 0000 0000 0005
15832 index: 0000 0000 0000 0005 element: 0000 0000 0000 0006
15833 index: 0000 0000 0000 0006 element: 0000 0000 0000 0007
15834 index: 0000 0000 0000 0007 element: 0000 0000 0000 0008
15835 index: 0000 0000 0000 0008 element: 0000 0000 0000 0009
15836 index: 0000 0000 0000 0009 element: 0000 0000 0000 000A
15837 index: 0000 0000 0000 000A element: 0000 0000 0000 000B
15838 index: 0000 0000 0000 000B element: 0000 0000 0000 000C
15839 index: 0000 0000 0000 000C element: 0000 0000 0000 000D
15840 index: 0000 0000 0000 000D element: 0000 0000 0000 000E
15841 index: 0000 0000 0000 000E element: 0000 0000 0000 000F
15842 index: 0000 0000 0000 000F element: 0000 0000 0000 0010
15843 index: 0000 0000 0000 0010 element: 0000 0000 0000 0011
15844 index: 0000 0000 0000 0011 element: 0000 0000 0000 0012
15845 index: 0000 0000 0000 0012 element: 0000 0000 0000 0013
15846 index: 0000 0000 0000 0013 element: 0000 0000 0000 0014
15847 index: 0000 0000 0000 0014 element: 0000 0000 0000 0015
15848 index: 0000 0000 0000 0015 element: 0000 0000 0000 0016
15849 index: 0000 0000 0000 0016 element: 0000 0000 0000 0017
15850 index: 0000 0000 0000 0017 element: 0000 0000 0000 0018
15851 index: 0000 0000 0000 0018 element: 0000 0000 0000 0019
15852 index: 0000 0000 0000 0019 element: 0000 0000 0000 001A
15853 index: 0000 0000 0000 001A element: 0000 0000 0000 001B
15854 index: 0000 0000 0000 001B element: 0000 0000 0000 001C
15855 index: 0000 0000 0000 001C element: 0000 0000 0000 001D
15856 index: 0000 0000 0000 001D element: 0000 0000 0000 001E
15857 index: 0000 0000 0000 001E element: 0000 0000 0000 001F
15858 index: 0000 0000 0000 001F element: 0000 0000 0000 0020
15859 index: 0000 0000 0000 0020 element: 0000 0000 0000 0021
15860 index: 0000 0000 0000 0021 element: 0000 0000 0000 0022
15861 index: 0000 0000 0000 0022 element: 0000 0000 0000 0023
15862 index: 0000 0000 0000 0023 element: 0000 0000 0000 0024
15863 index: 0000 0000 0000 0009 element: 0000 0000 0000 FFF9
15864 index: 0000 0000 0000 0013 element: 0000 0000 0000 EEE9
15865 element: 0000 0000 0000 0024
15866 element: 0000 0000 0000 0023
15867 element: 0000 0000 0000 0022
15868 element: 0000 0000 0000 0021
15869 element: 0000 0000 0000 0020
15870 element: 0000 0000 0000 001F
15871 element: 0000 0000 0000 001E
15872 element: 0000 0000 0000 001D
15873 element: 0000 0000 0000 001C
15874 element: 0000 0000 0000 001B
15875 element: 0000 0000 0000 001A
15876 element: 0000 0000 0000 0019
15877 element: 0000 0000 0000 0018
15878 element: 0000 0000 0000 0017
15879 element: 0000 0000 0000 0016
15880 element: 0000 0000 0000 0015
15881 element: 0000 0000 0000 EEE9
15882 element: 0000 0000 0000 0013
15883 element: 0000 0000 0000 0012
15884 element: 0000 0000 0000 0011
15885 element: 0000 0000 0000 0010
15886 element: 0000 0000 0000 000F
15887 element: 0000 0000 0000 000E
15888 element: 0000 0000 0000 000D
15889 element: 0000 0000 0000 000C
15890 element: 0000 0000 0000 000B
15891 element: 0000 0000 0000 FFF9
15892 element: 0000 0000 0000 0009
15893 element: 0000 0000 0000 0008
15894 element: 0000 0000 0000 0007
15895 element: 0000 0000 0000 0006
15896 element: 0000 0000 0000 0005
15897 element: 0000 0000 0000 0004
15898 element: 0000 0000 0000 0003
15899 element: 0000 0000 0000 0002
15900 element: 0000 0000 0000 0001
15901 element: 0000 0000 0000 004A
15902 element: 0000 0000 0000 0048
15903 element: 0000 0000 0000 0046
15904 element: 0000 0000 0000 0044
15905 element: 0000 0000 0000 0042
15906 element: 0000 0000 0000 0040
15907 element: 0000 0000 0000 003E
15908 element: 0000 0000 0000 003C
15909 element: 0000 0000 0000 003A
15910 element: 0000 0000 0000 0038
15911 element: 0000 0000 0000 0036
15912 element: 0000 0000 0000 0034
15913 element: 0000 0000 0000 0032
15914 element: 0000 0000 0000 0030
15915 element: 0000 0000 0000 002E
15916 element: 0000 0000 0000 002C
15917 element: 0000 0000 0000 002A
15918 element: 0000 0000 0000 0028
15919 element: 0000 0000 0000 0026
15920 element: 0000 0000 0000 0024
15921 element: 0000 0000 0000 0022
15922 element: 0000 0000 0000 0020
15923 element: 0000 0000 0000 001E
15924 element: 0000 0000 0000 001C
15925 element: 0000 0000 0000 001A
15926 element: 0000 0000 0000 0018
15927 element: 0000 0000 0000 0016
15928 element: 0000 0000 0000 0014
15929 element: 0000 0000 0000 0012
15930 element: 0000 0000 0000 0010
15931 element: 0000 0000 0000 000E
15932 element: 0000 0000 0000 000C
15933 element: 0000 0000 0000 000A
15934 element: 0000 0000 0000 0008
15935 element: 0000 0000 0000 0006
15936 element: 0000 0000 0000 0004
15937 element: 0000 0000 0000 0002
15938 element: 0000 0000 0000 0000
15939 array
15940 Size: 0000 0000 0000 0000 zmm31: 0000 001C 0000 001A 0000 0018 0000 0016 0000 0014 0000 0012 0000 0010 0000 000E 0000 000C 0000 000A 0000 0008 0000 0006 0000 0004 0000 0002 0000 0000 0000 0000
15941 END
15942
15943  
15944 =head1 Tree
15945  
15946 Tree constructed as sets of blocks in an arena.
15947  
15948 =head2 DescribeTree(%options)
15949  
15950 Return a descriptor for a tree with the specified options.
15951  
15952 Parameter Description
15953 1 %options Tree description options
15954  
15955 =head2 Nasm::X86::Arena::DescribeTree($arena, %options)
15956  
15957 Return a descriptor for a tree in the specified arena with the specified options.
15958  
15959 Parameter Description
15960 1 $arena Arena descriptor
15961 2 %options Options for tree
15962  
15963 =head2 Nasm::X86::Arena::CreateTree($arena, $bs)
15964  
15965 Create a tree in an arena.
15966  
15967 Parameter Description
15968 1 $arena Arena description
15969 2 $bs Optional arena address
15970  
15971 B<Example:>
15972  
15973  
15974 my $N = 12;
15975 my $b = CreateArena;
15976 my $t = $b->CreateTree;
15977
15978 K(count, $N)->for(sub # Add some entries to the tree
15979 {my ($index, $start, $next, $end) = @_;
15980 my $k = $index + 1;
15981 $t->insert($k, $k + 0x100);
15982 $t->insert($k + $N, $k + 0x200);
15983 });
15984
15985 $t->by(sub # Iterate through the tree
15986 {my ($iter, $end) = @_;
15987 $iter->key ->out('key: ');
15988 $iter->data->out(' data: ');
15989 my $D = V(depth);
15990 $iter->tree->depth($t->address, $iter->node, $D);
15991
15992 $t->find($iter->key);
15993 $t->found->out(' found: '); $t->data->out(' data: '); $D->outNL(' depth: ');
15994 });
15995
15996 $t->find(K(key, 0xffff)); $t->found->outNL('Found: '); # Find some entries
15997 $t->find(K(key, 0xd)); $t->found->outNL('Found: ');
15998 If ($t->found > 0,
15999 Then
16000 {$t->data->outNL("Data : ");
16001 });
16002
16003 ok Assemble(debug => 0, eq => <<END);
16004 key: 0000 0000 0000 0001 data: 0000 0000 0000 0101 found: 0000 0000 0000 0001 data: 0000 0000 0000 0101 depth: 0000 0000 0000 0002
16005 key: 0000 0000 0000 0002 data: 0000 0000 0000 0102 found: 0000 0000 0000 0001 data: 0000 0000 0000 0102 depth: 0000 0000 0000 0002
16006 key: 0000 0000 0000 0003 data: 0000 0000 0000 0103 found: 0000 0000 0000 0001 data: 0000 0000 0000 0103 depth: 0000 0000 0000 0002
16007 key: 0000 0000 0000 0004 data: 0000 0000 0000 0104 found: 0000 0000 0000 0001 data: 0000 0000 0000 0104 depth: 0000 0000 0000 0002
16008 key: 0000 0000 0000 0005 data: 0000 0000 0000 0105 found: 0000 0000 0000 0001 data: 0000 0000 0000 0105 depth: 0000 0000 0000 0002
16009 key: 0000 0000 0000 0006 data: 0000 0000 0000 0106 found: 0000 0000 0000 0001 data: 0000 0000 0000 0106 depth: 0000 0000 0000 0002
16010 key: 0000 0000 0000 0007 data: 0000 0000 0000 0107 found: 0000 0000 0000 0001 data: 0000 0000 0000 0107 depth: 0000 0000 0000 0002
16011 key: 0000 0000 0000 0008 data: 0000 0000 0000 0108 found: 0000 0000 0000 0001 data: 0000 0000 0000 0108 depth: 0000 0000 0000 0002
16012 key: 0000 0000 0000 0009 data: 0000 0000 0000 0109 found: 0000 0000 0000 0001 data: 0000 0000 0000 0109 depth: 0000 0000 0000 0002
16013 key: 0000 0000 0000 000A data: 0000 0000 0000 010A found: 0000 0000 0000 0001 data: 0000 0000 0000 010A depth: 0000 0000 0000 0002
16014 key: 0000 0000 0000 000B data: 0000 0000 0000 010B found: 0000 0000 0000 0001 data: 0000 0000 0000 010B depth: 0000 0000 0000 0002
16015 key: 0000 0000 0000 000C data: 0000 0000 0000 010C found: 0000 0000 0000 0001 data: 0000 0000 0000 010C depth: 0000 0000 0000 0002
16016 key: 0000 0000 0000 000D data: 0000 0000 0000 0201 found: 0000 0000 0000 0001 data: 0000 0000 0000 0201 depth: 0000 0000 0000 0001
16017 key: 0000 0000 0000 000E data: 0000 0000 0000 0202 found: 0000 0000 0000 0001 data: 0000 0000 0000 0202 depth: 0000 0000 0000 0002
16018 key: 0000 0000 0000 000F data: 0000 0000 0000 0203 found: 0000 0000 0000 0001 data: 0000 0000 0000 0203 depth: 0000 0000 0000 0002
16019 key: 0000 0000 0000 0010 data: 0000 0000 0000 0204 found: 0000 0000 0000 0001 data: 0000 0000 0000 0204 depth: 0000 0000 0000 0002
16020 key: 0000 0000 0000 0011 data: 0000 0000 0000 0205 found: 0000 0000 0000 0001 data: 0000 0000 0000 0205 depth: 0000 0000 0000 0002
16021 key: 0000 0000 0000 0012 data: 0000 0000 0000 0206 found: 0000 0000 0000 0001 data: 0000 0000 0000 0206 depth: 0000 0000 0000 0002
16022 key: 0000 0000 0000 0013 data: 0000 0000 0000 0207 found: 0000 0000 0000 0001 data: 0000 0000 0000 0207 depth: 0000 0000 0000 0002
16023 key: 0000 0000 0000 0014 data: 0000 0000 0000 0208 found: 0000 0000 0000 0001 data: 0000 0000 0000 0208 depth: 0000 0000 0000 0002
16024 key: 0000 0000 0000 0015 data: 0000 0000 0000 0209 found: 0000 0000 0000 0001 data: 0000 0000 0000 0209 depth: 0000 0000 0000 0002
16025 key: 0000 0000 0000 0016 data: 0000 0000 0000 020A found: 0000 0000 0000 0001 data: 0000 0000 0000 020A depth: 0000 0000 0000 0002
16026 key: 0000 0000 0000 0017 data: 0000 0000 0000 020B found: 0000 0000 0000 0001 data: 0000 0000 0000 020B depth: 0000 0000 0000 0002
16027 key: 0000 0000 0000 0018 data: 0000 0000 0000 020C found: 0000 0000 0000 0001 data: 0000 0000 0000 020C depth: 0000 0000 0000 0002
16028 Found: 0000 0000 0000 0000
16029 Found: 0000 0000 0000 0001
16030 Data : 0000 0000 0000 0201
16031 END
16032
16033  
16034 =head2 Nasm::X86::Tree::reload($tree, %options)
16035  
16036 Reload the specified tree description.
16037  
16038 Parameter Description
16039 1 $tree Tree descriptor
16040 2 %options {first=>first node of tree if not the existing first node; arena=>arena used by tree if not the existing arena}
16041  
16042 =head2 Nasm::X86::Tree::find($t, $key, $bs, $first)
16043  
16044 Find a key in a tree and test whether the found data is a sub tree. The results are held in the variables "found", "data", "subTree" addressed by the tree descriptor.
16045  
16046 Parameter Description
16047 1 $t Tree descriptor
16048 2 $key Key field to search for
16049 3 $bs Optional arena address
16050 4 $first Optional start node
16051  
16052 =head2 Nasm::X86::Tree::findAndReload($t, $key)
16053  
16054 Find a key in the specified tree and clone it is it is a sub tree.
16055  
16056 Parameter Description
16057 1 $t Tree descriptor
16058 2 $key Key as a dword
16059  
16060 B<Example:>
16061  
16062  
16063 my $L = K(loop, 4);
16064 my $b = CreateArena;
16065 my $T = $b->CreateTree;
16066 my $t = $T->reload;
16067
16068 $L->for(sub
16069 {my ($i, $start, $next, $end) = @_;
16070 $t->insertTreeAndReload($i);
16071 $t->first->outNL;
16072 });
16073
16074 $t->insert($L, $L*2);
16075
16076 my $f = $T->reload;
16077 $L->for(sub
16078 {my ($i, $start, $next, $end) = @_;
16079 $f->findAndReload($i);
16080 $i->out('i: '); $f->found->out(' f: '); $f->data->out(' d: '); $f->subTree->outNL(' s: ');
16081 });
16082 $f->find($L);
16083 $L->out('N: '); $f->found->out(' f: '); $f->data->out(' d: '); $f->subTree->outNL(' s: ');
16084
16085 ok Assemble(debug => 0, eq => <<END);
16086 first: 0000 0000 0000 0098
16087 first: 0000 0000 0000 0118
16088 first: 0000 0000 0000 0198
16089 first: 0000 0000 0000 0218
16090 i: 0000 0000 0000 0000 f: 0000 0000 0000 0001 d: 0000 0000 0000 0098 s: 0000 0000 0000 0001
16091 i: 0000 0000 0000 0001 f: 0000 0000 0000 0001 d: 0000 0000 0000 0118 s: 0000 0000 0000 0001
16092 i: 0000 0000 0000 0002 f: 0000 0000 0000 0001 d: 0000 0000 0000 0198 s: 0000 0000 0000 0001
16093 i: 0000 0000 0000 0003 f: 0000 0000 0000 0001 d: 0000 0000 0000 0218 s: 0000 0000 0000 0001
16094 N: 0000 0000 0000 0004 f: 0000 0000 0000 0001 d: 0000 0000 0000 0008 s: 0000 0000 0000 0000
16095 END
16096
16097  
16098 =head2 Nasm::X86::Tree::findShortString($tree, $string)
16099  
16100 Find the data at the end of a key chain held in a short string. Return a tree descriptor referencing the data located or marked as failed to find.
16101  
16102 Parameter Description
16103 1 $tree Tree descriptor
16104 2 $string Short string
16105  
16106 =head2 Nasm::X86::Tree::size($t)
16107  
16108 Return a variable containing the number of keys in the specified tree.
16109  
16110 Parameter Description
16111 1 $t Tree descriptor
16112  
16113 B<Example:>
16114  
16115  
16116 my $b = CreateArena;
16117 my $t = $b->CreateTree;
16118 my $s = $t->size;
16119 $s->outNL;
16120
16121 V(count, 24)->for(sub
16122 {my ($index, $start, $next, $end) = @_;
16123 my $k = $index + 1; my $d = $k + 0x100;
16124 $t->insert($k, $d);
16125 my $s = $t->size;
16126 $s->outNL;
16127 });
16128
16129 $t->getKeysDataNode($b->bs, $t->first, 31, 30, 29);
16130 PrintOutStringNL "Root"; $t->first->outNL('First: ');
16131 PrintOutRegisterInHex zmm31, zmm30, zmm29;
16132
16133 $t->getKeysDataNode($b->bs, V(offset, 0xd8), 28,27,26);
16134 PrintOutStringNL "Left";
16135 PrintOutRegisterInHex zmm28, zmm27, zmm26;
16136
16137 $t->getKeysDataNode($b->bs, V(offset, 0x258), 28,27,26);
16138 PrintOutStringNL "Left";
16139 PrintOutRegisterInHex zmm28, zmm27, zmm26;
16140
16141 $t->getKeysDataNode($b->bs, V(offset, 0x198), 28,27,26);
16142 PrintOutStringNL "Left";
16143 PrintOutRegisterInHex zmm28, zmm27, zmm26;
16144
16145 ok Assemble(debug => 0, eq => <<END);
16146 size: 0000 0000 0000 0000
16147 size: 0000 0000 0000 0001
16148 size: 0000 0000 0000 0002
16149 size: 0000 0000 0000 0003
16150 size: 0000 0000 0000 0004
16151 size: 0000 0000 0000 0005
16152 size: 0000 0000 0000 0006
16153 size: 0000 0000 0000 0007
16154 size: 0000 0000 0000 0008
16155 size: 0000 0000 0000 0009
16156 size: 0000 0000 0000 000A
16157 size: 0000 0000 0000 000B
16158 size: 0000 0000 0000 000C
16159 size: 0000 0000 0000 000D
16160 size: 0000 0000 0000 000E
16161 size: 0000 0000 0000 000F
16162 size: 0000 0000 0000 0010
16163 size: 0000 0000 0000 0011
16164 size: 0000 0000 0000 0012
16165 size: 0000 0000 0000 0013
16166 size: 0000 0000 0000 0014
16167 size: 0000 0000 0000 0015
16168 size: 0000 0000 0000 0016
16169 size: 0000 0000 0000 0017
16170 size: 0000 0000 0000 0018
16171 Root
16172 First: 0000 0000 0000 0018
16173 zmm31: 0000 0058 0000 0002 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0010 0000 0008
16174 zmm30: 0000 0098 0000 0030 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0110 0000 0108
16175 zmm29: 0000 0018 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0198 0000 0258 0000 00D8
16176 Left
16177 zmm28: 0000 0118 0000 0007 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0007 0000 0006 0000 0005 0000 0004 0000 0003 0000 0002 0000 0001
16178 zmm27: 0000 0158 0000 0001 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0107 0000 0106 0000 0105 0000 0104 0000 0103 0000 0102 0000 0101
16179 zmm26: 0000 00D8 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
16180 Left
16181 zmm28: 0000 0298 0000 0007 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 000F 0000 000E 0000 000D 0000 000C 0000 000B 0000 000A 0000 0009
16182 zmm27: 0000 02D8 0000 0001 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 010F 0000 010E 0000 010D 0000 010C 0000 010B 0000 010A 0000 0109
16183 zmm26: 0000 0258 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
16184 Left
16185 zmm28: 0000 01D8 0000 0008 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0018 0000 0017 0000 0016 0000 0015 0000 0014 0000 0013 0000 0012 0000 0011
16186 zmm27: 0000 0218 0000 0001 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0118 0000 0117 0000 0116 0000 0115 0000 0114 0000 0113 0000 0112 0000 0111
16187 zmm26: 0000 0198 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
16188 END
16189
16190  
16191 =head2 Nasm::X86::Tree::insertDataOrTree($t, $tnd, $key, $data)
16192  
16193 Insert either a key, data pair into the tree or create a sub tree at the specified key (if it does not already exist) and return the offset of the first block of the sub tree in the data variable.
16194  
16195 Parameter Description
16196 1 $t Tree descriptor
16197 2 $tnd 0 - data or 1 - tree
16198 3 $key Key as a dword
16199 4 $data Data as a dword
16200  
16201 =head2 Nasm::X86::Tree::insert($t, $key, $data)
16202  
16203 Insert a dword into into the specified tree at the specified key.
16204  
16205 Parameter Description
16206 1 $t Tree descriptor
16207 2 $key Key as a dword
16208 3 $data Data as a dword
16209  
16210 =head2 Nasm::X86::Tree::insertTree($t, $key, $subTree)
16211  
16212 Insert a sub tree into the specified tree tree under the specified key. If no sub tree is supplied an empty one is provided gratis.
16213  
16214 Parameter Description
16215 1 $t Tree descriptor
16216 2 $key Key as a dword
16217 3 $subTree Sub tree to insert else an empty one will be added
16218  
16219 B<Example:>
16220  
16221  
16222 my $b = CreateArena;
16223 my $t = $b->CreateTree;
16224 my $T = $b->CreateTree;
16225
16226 $T->insert (K(key, 2), K(data, 4));
16227 $t->insertTree(K(key, 1), $T);
16228
16229 $t->print;
16230
16231 ok Assemble(debug => 0, eq => <<END);
16232 Tree at: 0000 0000 0000 0018
16233 key: 0000 0000 0000 0001 data: 0000 0000 0000 0098 depth: 0000 0000 0000 0001
16234 Tree at: 0000 0000 0000 0098
16235 key: 0000 0000 0000 0002 data: 0000 0000 0000 0004 depth: 0000 0000 0000 0001
16236 END
16237
16238 my $L = K(loop, 11);
16239 my $b = CreateArena;
16240 my $B = CreateArena;
16241 my $t = $b->CreateTree;
16242 my $T = $B->CreateTree;
16243
16244 $L->for(sub
16245 {my ($i, $start, $next, $end) = @_;
16246 $t->insert($i+0x11, K(data, 0xFF));
16247 $T->insert($i+0x22, K(data, 0xDD));
16248 });
16249
16250 $b->dump;
16251 $B->dump;
16252
16253 $t->print;
16254 $T->print;
16255
16256 ok Assemble(debug => 0, eq => <<END);
16257 Arena
16258 Size: 0000 0000 0000 1000
16259 Used: 0000 0000 0000 0098
16260 0000: 0010 0000 0000 00009800 0000 0000 00000000 0000 0000 00001100 0000 1200 00001300 0000 1400 00001500 0000 1600 00001700 0000 1800 00001900 0000 1A00 0000
16261 0040: 1B00 0000 0000 00000000 0000 0000 00000B00 0000 5800 0000FF00 0000 FF00 0000FF00 0000 FF00 0000FF00 0000 FF00 0000FF00 0000 FF00 0000FF00 0000 FF00 0000
16262 0080: FF00 0000 0000 00000000 0000 0000 00001600 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
16263 00C0: 0000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
16264 Arena
16265 Size: 0000 0000 0000 1000
16266 Used: 0000 0000 0000 0098
16267 0000: 0010 0000 0000 00009800 0000 0000 00000000 0000 0000 00002200 0000 2300 00002400 0000 2500 00002600 0000 2700 00002800 0000 2900 00002A00 0000 2B00 0000
16268 0040: 2C00 0000 0000 00000000 0000 0000 00000B00 0000 5800 0000DD00 0000 DD00 0000DD00 0000 DD00 0000DD00 0000 DD00 0000DD00 0000 DD00 0000DD00 0000 DD00 0000
16269 0080: DD00 0000 0000 00000000 0000 0000 00001600 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
16270 00C0: 0000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
16271 Tree at: 0000 0000 0000 0018
16272 key: 0000 0000 0000 0011 data: 0000 0000 0000 00FF depth: 0000 0000 0000 0001
16273 key: 0000 0000 0000 0012 data: 0000 0000 0000 00FF depth: 0000 0000 0000 0001
16274 key: 0000 0000 0000 0013 data: 0000 0000 0000 00FF depth: 0000 0000 0000 0001
16275 key: 0000 0000 0000 0014 data: 0000 0000 0000 00FF depth: 0000 0000 0000 0001
16276 key: 0000 0000 0000 0015 data: 0000 0000 0000 00FF depth: 0000 0000 0000 0001
16277 key: 0000 0000 0000 0016 data: 0000 0000 0000 00FF depth: 0000 0000 0000 0001
16278 key: 0000 0000 0000 0017 data: 0000 0000 0000 00FF depth: 0000 0000 0000 0001
16279 key: 0000 0000 0000 0018 data: 0000 0000 0000 00FF depth: 0000 0000 0000 0001
16280 key: 0000 0000 0000 0019 data: 0000 0000 0000 00FF depth: 0000 0000 0000 0001
16281 key: 0000 0000 0000 001A data: 0000 0000 0000 00FF depth: 0000 0000 0000 0001
16282 key: 0000 0000 0000 001B data: 0000 0000 0000 00FF depth: 0000 0000 0000 0001
16283 Tree at: 0000 0000 0000 0018
16284 key: 0000 0000 0000 0022 data: 0000 0000 0000 00DD depth: 0000 0000 0000 0001
16285 key: 0000 0000 0000 0023 data: 0000 0000 0000 00DD depth: 0000 0000 0000 0001
16286 key: 0000 0000 0000 0024 data: 0000 0000 0000 00DD depth: 0000 0000 0000 0001
16287 key: 0000 0000 0000 0025 data: 0000 0000 0000 00DD depth: 0000 0000 0000 0001
16288 key: 0000 0000 0000 0026 data: 0000 0000 0000 00DD depth: 0000 0000 0000 0001
16289 key: 0000 0000 0000 0027 data: 0000 0000 0000 00DD depth: 0000 0000 0000 0001
16290 key: 0000 0000 0000 0028 data: 0000 0000 0000 00DD depth: 0000 0000 0000 0001
16291 key: 0000 0000 0000 0029 data: 0000 0000 0000 00DD depth: 0000 0000 0000 0001
16292 key: 0000 0000 0000 002A data: 0000 0000 0000 00DD depth: 0000 0000 0000 0001
16293 key: 0000 0000 0000 002B data: 0000 0000 0000 00DD depth: 0000 0000 0000 0001
16294 key: 0000 0000 0000 002C data: 0000 0000 0000 00DD depth: 0000 0000 0000 0001
16295 END
16296
16297  
16298 =head2 Nasm::X86::Tree::insertTreeAndReload($t, $key)
16299  
16300 Insert a new sub tree into the specified tree tree under the specified key and return a descriptor for it. If the tree already exists, return a descriptor for it.
16301  
16302 Parameter Description
16303 1 $t Tree descriptor
16304 2 $key Key as a dword
16305  
16306 B<Example:>
16307  
16308  
16309 my $L = K(loop, 4);
16310 my $b = CreateArena;
16311 my $T = $b->CreateTree;
16312 my $t = $T->reload;
16313
16314 $L->for(sub
16315 {my ($i, $start, $next, $end) = @_;
16316 $t->insertTreeAndReload($i);
16317 $t->first->outNL;
16318 });
16319
16320 $t->insert($L, $L*2);
16321
16322 my $f = $T->reload;
16323 $L->for(sub
16324 {my ($i, $start, $next, $end) = @_;
16325 $f->findAndReload($i);
16326 $i->out('i: '); $f->found->out(' f: '); $f->data->out(' d: '); $f->subTree->outNL(' s: ');
16327 });
16328 $f->find($L);
16329 $L->out('N: '); $f->found->out(' f: '); $f->data->out(' d: '); $f->subTree->outNL(' s: ');
16330
16331 ok Assemble(debug => 0, eq => <<END);
16332 first: 0000 0000 0000 0098
16333 first: 0000 0000 0000 0118
16334 first: 0000 0000 0000 0198
16335 first: 0000 0000 0000 0218
16336 i: 0000 0000 0000 0000 f: 0000 0000 0000 0001 d: 0000 0000 0000 0098 s: 0000 0000 0000 0001
16337 i: 0000 0000 0000 0001 f: 0000 0000 0000 0001 d: 0000 0000 0000 0118 s: 0000 0000 0000 0001
16338 i: 0000 0000 0000 0002 f: 0000 0000 0000 0001 d: 0000 0000 0000 0198 s: 0000 0000 0000 0001
16339 i: 0000 0000 0000 0003 f: 0000 0000 0000 0001 d: 0000 0000 0000 0218 s: 0000 0000 0000 0001
16340 N: 0000 0000 0000 0004 f: 0000 0000 0000 0001 d: 0000 0000 0000 0008 s: 0000 0000 0000 0000
16341 END
16342
16343  
16344 =head2 Nasm::X86::Tree::insertShortString($tree, $string, $data)
16345  
16346 Insert some data at the end of a chain of sub trees keyed by the contents of a short string.
16347  
16348 Parameter Description
16349 1 $tree Tree descriptor
16350 2 $string Short string
16351 3 $data Data as a dword
16352  
16353 =head2 Nasm::X86::Tree::leftOrRightMost($t, $dir, $bs, $node, $offset)
16354  
16355 Return the offset of the left most or right most node.
16356  
16357 Parameter Description
16358 1 $t Tree descriptor
16359 2 $dir Direction: left = 0 or right = 1
16360 3 $bs Arena address
16361 4 $node Start node
16362 5 $offset Offset of located node
16363  
16364 =head2 Nasm::X86::Tree::leftMost($t, $bs, $node, $offset)
16365  
16366 Return the offset of the left most node from the specified node.
16367  
16368 Parameter Description
16369 1 $t Tree descriptor
16370 2 $bs Arena address
16371 3 $node Start node
16372 4 $offset Returned offset
16373  
16374 =head2 Nasm::X86::Tree::rightMost($t, $bs, $node, $offset)
16375  
16376 Return the offset of the left most node from the specified node.
16377  
16378 Parameter Description
16379 1 $t Tree descriptor
16380 2 $bs Arena address
16381 3 $node Start node
16382 4 $offset Returned offset
16383  
16384 =head2 Nasm::X86::Tree::depth($t, $bs, $node, $depth)
16385  
16386 Return the depth of a node within a tree.
16387  
16388 Parameter Description
16389 1 $t Tree descriptor
16390 2 $bs Arena address
16391 3 $node Node
16392 4 $depth Return depth
16393  
16394 =head2 Sub trees
16395  
16396 Construct trees of trees.
16397  
16398 =head2 Print
16399  
16400 Print a tree
16401  
16402 =head3 Nasm::X86::Tree::print($t)
16403  
16404 Print a tree.
16405  
16406 Parameter Description
16407 1 $t Tree
16408  
16409 B<Example:>
16410  
16411  
16412 my $L = V(loop, 45);
16413
16414 my $b = CreateArena;
16415 my $t = $b->CreateTree;
16416
16417 $L->for(sub
16418 {my ($i, $start, $next, $end) = @_;
16419 my $l = $L - $i;
16420 If ($i % 2 == 0, sub
16421 {$t->insert($i, $l);
16422 $t->insertTree($l);
16423 });
16424 });
16425
16426 $t->print;
16427
16428 ok Assemble(debug => 0, eq => <<END);
16429 Tree at: 0000 0000 0000 0018
16430 key: 0000 0000 0000 0000 data: 0000 0000 0000 002D depth: 0000 0000 0000 0002
16431 key: 0000 0000 0000 0001 data: 0000 0000 0000 0ED8 depth: 0000 0000 0000 0002
16432 Tree at: 0000 0000 0000 0ED8
16433 key: 0000 0000 0000 0002 data: 0000 0000 0000 002B depth: 0000 0000 0000 0002
16434 key: 0000 0000 0000 0003 data: 0000 0000 0000 0E58 depth: 0000 0000 0000 0002
16435 Tree at: 0000 0000 0000 0E58
16436 key: 0000 0000 0000 0004 data: 0000 0000 0000 0029 depth: 0000 0000 0000 0002
16437 key: 0000 0000 0000 0005 data: 0000 0000 0000 0DD8 depth: 0000 0000 0000 0002
16438 Tree at: 0000 0000 0000 0DD8
16439 key: 0000 0000 0000 0006 data: 0000 0000 0000 0027 depth: 0000 0000 0000 0002
16440 key: 0000 0000 0000 0007 data: 0000 0000 0000 0D58 depth: 0000 0000 0000 0001
16441 Tree at: 0000 0000 0000 0D58
16442 key: 0000 0000 0000 0008 data: 0000 0000 0000 0025 depth: 0000 0000 0000 0002
16443 key: 0000 0000 0000 0009 data: 0000 0000 0000 0CD8 depth: 0000 0000 0000 0002
16444 Tree at: 0000 0000 0000 0CD8
16445 key: 0000 0000 0000 000A data: 0000 0000 0000 0023 depth: 0000 0000 0000 0002
16446 key: 0000 0000 0000 000B data: 0000 0000 0000 0C58 depth: 0000 0000 0000 0002
16447 Tree at: 0000 0000 0000 0C58
16448 key: 0000 0000 0000 000C data: 0000 0000 0000 0021 depth: 0000 0000 0000 0002
16449 key: 0000 0000 0000 000D data: 0000 0000 0000 0BD8 depth: 0000 0000 0000 0002
16450 Tree at: 0000 0000 0000 0BD8
16451 key: 0000 0000 0000 000E data: 0000 0000 0000 001F depth: 0000 0000 0000 0001
16452 key: 0000 0000 0000 000F data: 0000 0000 0000 0B58 depth: 0000 0000 0000 0002
16453 Tree at: 0000 0000 0000 0B58
16454 key: 0000 0000 0000 0010 data: 0000 0000 0000 001D depth: 0000 0000 0000 0002
16455 key: 0000 0000 0000 0011 data: 0000 0000 0000 0AD8 depth: 0000 0000 0000 0002
16456 Tree at: 0000 0000 0000 0AD8
16457 key: 0000 0000 0000 0012 data: 0000 0000 0000 001B depth: 0000 0000 0000 0002
16458 key: 0000 0000 0000 0013 data: 0000 0000 0000 0998 depth: 0000 0000 0000 0002
16459 Tree at: 0000 0000 0000 0998
16460 key: 0000 0000 0000 0014 data: 0000 0000 0000 0019 depth: 0000 0000 0000 0002
16461 key: 0000 0000 0000 0015 data: 0000 0000 0000 0918 depth: 0000 0000 0000 0002
16462 Tree at: 0000 0000 0000 0918
16463 key: 0000 0000 0000 0016 data: 0000 0000 0000 0017 depth: 0000 0000 0000 0002
16464 key: 0000 0000 0000 0017 data: 0000 0000 0000 0898 depth: 0000 0000 0000 0002
16465 Tree at: 0000 0000 0000 0898
16466 key: 0000 0000 0000 0018 data: 0000 0000 0000 0015 depth: 0000 0000 0000 0001
16467 key: 0000 0000 0000 0019 data: 0000 0000 0000 0818 depth: 0000 0000 0000 0002
16468 Tree at: 0000 0000 0000 0818
16469 key: 0000 0000 0000 001A data: 0000 0000 0000 0013 depth: 0000 0000 0000 0002
16470 key: 0000 0000 0000 001B data: 0000 0000 0000 06D8 depth: 0000 0000 0000 0002
16471 Tree at: 0000 0000 0000 06D8
16472 key: 0000 0000 0000 001C data: 0000 0000 0000 0011 depth: 0000 0000 0000 0002
16473 key: 0000 0000 0000 001D data: 0000 0000 0000 0658 depth: 0000 0000 0000 0002
16474 Tree at: 0000 0000 0000 0658
16475 key: 0000 0000 0000 001E data: 0000 0000 0000 000F depth: 0000 0000 0000 0002
16476 key: 0000 0000 0000 001F data: 0000 0000 0000 05D8 depth: 0000 0000 0000 0002
16477 Tree at: 0000 0000 0000 05D8
16478 key: 0000 0000 0000 0020 data: 0000 0000 0000 000D depth: 0000 0000 0000 0002
16479 key: 0000 0000 0000 0021 data: 0000 0000 0000 0398 depth: 0000 0000 0000 0001
16480 Tree at: 0000 0000 0000 0398
16481 key: 0000 0000 0000 0022 data: 0000 0000 0000 000B depth: 0000 0000 0000 0002
16482 key: 0000 0000 0000 0023 data: 0000 0000 0000 0318 depth: 0000 0000 0000 0002
16483 Tree at: 0000 0000 0000 0318
16484 key: 0000 0000 0000 0024 data: 0000 0000 0000 0009 depth: 0000 0000 0000 0002
16485 key: 0000 0000 0000 0025 data: 0000 0000 0000 0298 depth: 0000 0000 0000 0002
16486 Tree at: 0000 0000 0000 0298
16487 key: 0000 0000 0000 0026 data: 0000 0000 0000 0007 depth: 0000 0000 0000 0002
16488 key: 0000 0000 0000 0027 data: 0000 0000 0000 0218 depth: 0000 0000 0000 0002
16489 Tree at: 0000 0000 0000 0218
16490 key: 0000 0000 0000 0028 data: 0000 0000 0000 0005 depth: 0000 0000 0000 0002
16491 key: 0000 0000 0000 0029 data: 0000 0000 0000 0198 depth: 0000 0000 0000 0002
16492 Tree at: 0000 0000 0000 0198
16493 key: 0000 0000 0000 002A data: 0000 0000 0000 0003 depth: 0000 0000 0000 0002
16494 key: 0000 0000 0000 002B data: 0000 0000 0000 0118 depth: 0000 0000 0000 0002
16495 Tree at: 0000 0000 0000 0118
16496 key: 0000 0000 0000 002C data: 0000 0000 0000 0001 depth: 0000 0000 0000 0002
16497 key: 0000 0000 0000 002D data: 0000 0000 0000 0098 depth: 0000 0000 0000 0002
16498 Tree at: 0000 0000 0000 0098
16499 END
16500
16501  
16502 =head3 Nasm::X86::Tree::dump($t, $first, $bs)
16503  
16504 Dump a tree and all its sub trees.
16505  
16506 Parameter Description
16507 1 $t Tree
16508 2 $first Optional offset to first node
16509 3 $bs Optional arena address
16510  
16511 B<Example:>
16512  
16513  
16514 my $L = V(loop, 15);
16515
16516 my $b = CreateArena;
16517 my $t = $b->CreateTree;
16518
16519 $L->for(sub
16520 {my ($i, $start, $next, $end) = @_;
16521 If ($i % 2 == 0,
16522 Then
16523 {$t->insert ($i, $i);
16524 },
16525 Else
16526 {$t->insertTree($i);
16527 });
16528 });
16529
16530 $t->dump();
16531
16532 ok Assemble(debug => 0, eq => <<END);
16533 Tree at: 0000 0000 0000 0018 length: 0000 0000 0000 0001
16534 0000 0018 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0518 0000 0458
16535 0000 0418 0000 001E 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0218
16536 0000 0058 0001 0001 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0007
16537 index: 0000 0000 0000 0000 key: 0000 0000 0000 0007 data: 0000 0000 0000 0218 subTree
16538 Tree at: 0000 0000 0000 0218 length: 0000 0000 0000 0000
16539 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
16540 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
16541 0000 0258 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
16542 end
16543 Tree at: 0000 0000 0000 0458 length: 0000 0000 0000 0007
16544 0000 0458 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
16545 0000 04D8 0000 0001 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0006 0000 0198 0000 0004 0000 0118 0000 0002 0000 0098 0000 0000
16546 0000 0498 002A 0007 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0006 0000 0005 0000 0004 0000 0003 0000 0002 0000 0001 0000 0000
16547 index: 0000 0000 0000 0000 key: 0000 0000 0000 0000 data: 0000 0000 0000 0000
16548 index: 0000 0000 0000 0001 key: 0000 0000 0000 0001 data: 0000 0000 0000 0098 subTree
16549 index: 0000 0000 0000 0002 key: 0000 0000 0000 0002 data: 0000 0000 0000 0002
16550 index: 0000 0000 0000 0003 key: 0000 0000 0000 0003 data: 0000 0000 0000 0118 subTree
16551 index: 0000 0000 0000 0004 key: 0000 0000 0000 0004 data: 0000 0000 0000 0004
16552 index: 0000 0000 0000 0005 key: 0000 0000 0000 0005 data: 0000 0000 0000 0198 subTree
16553 index: 0000 0000 0000 0006 key: 0000 0000 0000 0006 data: 0000 0000 0000 0006
16554 Tree at: 0000 0000 0000 0098 length: 0000 0000 0000 0000
16555 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
16556 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
16557 0000 00D8 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
16558 end
16559 Tree at: 0000 0000 0000 0118 length: 0000 0000 0000 0000
16560 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
16561 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
16562 0000 0158 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
16563 end
16564 Tree at: 0000 0000 0000 0198 length: 0000 0000 0000 0000
16565 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
16566 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
16567 0000 01D8 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
16568 end
16569 end
16570 Tree at: 0000 0000 0000 0518 length: 0000 0000 0000 0007
16571 0000 0518 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
16572 0000 0598 0000 0001 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 000E 0000 0398 0000 000C 0000 0318 0000 000A 0000 0298 0000 0008
16573 0000 0558 002A 0007 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 000E 0000 000D 0000 000C 0000 000B 0000 000A 0000 0009 0000 0008
16574 index: 0000 0000 0000 0000 key: 0000 0000 0000 0008 data: 0000 0000 0000 0008
16575 index: 0000 0000 0000 0001 key: 0000 0000 0000 0009 data: 0000 0000 0000 0298 subTree
16576 index: 0000 0000 0000 0002 key: 0000 0000 0000 000A data: 0000 0000 0000 000A
16577 index: 0000 0000 0000 0003 key: 0000 0000 0000 000B data: 0000 0000 0000 0318 subTree
16578 index: 0000 0000 0000 0004 key: 0000 0000 0000 000C data: 0000 0000 0000 000C
16579 index: 0000 0000 0000 0005 key: 0000 0000 0000 000D data: 0000 0000 0000 0398 subTree
16580 index: 0000 0000 0000 0006 key: 0000 0000 0000 000E data: 0000 0000 0000 000E
16581 Tree at: 0000 0000 0000 0298 length: 0000 0000 0000 0000
16582 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
16583 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
16584 0000 02D8 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
16585 end
16586 Tree at: 0000 0000 0000 0318 length: 0000 0000 0000 0000
16587 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
16588 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
16589 0000 0358 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
16590 end
16591 Tree at: 0000 0000 0000 0398 length: 0000 0000 0000 0000
16592 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
16593 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
16594 0000 03D8 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
16595 end
16596 end
16597 end
16598 END
16599
16600  
16601 =head2 Iteration
16602  
16603 Iterate through a tree non recursively
16604  
16605 =head3 Nasm::X86::Tree::iterator($t, $bs, $first)
16606  
16607 Iterate through a multi way tree starting either at the specified node or the first node of the specified tree.
16608  
16609 Parameter Description
16610 1 $t Tree
16611 2 $bs Optional arena else the arena associated with the tree
16612 3 $first Optionally the node to start at else the first node of the supplied tree will be used
16613  
16614 =head3 Nasm::X86::Tree::Iterator::next($iter)
16615  
16616 Next element in the tree.
16617  
16618 Parameter Description
16619 1 $iter Iterator
16620  
16621 =head3 Nasm::X86::Tree::by($t, $block, $bs, $first)
16622  
16623 Call the specified block with each (key, data) from the specified tree in order.
16624  
16625 Parameter Description
16626 1 $t Tree descriptor
16627 2 $block Block to execute
16628 3 $bs Arena address if not the one associated with the tree descriptor
16629 4 $first First node offset if not the root of the tree provided
16630  
16631 =head1 Quarks
16632  
16633 Quarks allow us to replace unique strings with unique numbers. We can translate either from a string to its associated number or from a number to its associated string or from a quark in one set of quarks to the corresponding quark with the same string in another set of quarks.
16634  
16635 =head2 DescribeQuarks(%options)
16636  
16637 Return a descriptor for a set of quarks.
16638  
16639 Parameter Description
16640 1 %options Options
16641  
16642 =head2 Nasm::X86::Arena::DescribeQuarks($arena)
16643  
16644 Return a descriptor for a tree in the specified arena.
16645  
16646 Parameter Description
16647 1 $arena Arena descriptor
16648  
16649 =head2 Nasm::X86::Arena::CreateQuarks($arena)
16650  
16651 Create quarks in a specified arena.
16652  
16653 Parameter Description
16654 1 $arena Arena description optional arena address
16655  
16656 B<Example:>
16657  
16658  
16659 my $N = 5;
16660 my $a = CreateArena; # Arena containing quarks
16661 my $Q = $a->CreateQuarks; # Quarks
16662
16663 my $s = CreateShortString(0); # Short string used to load and unload quarks
16664 my $d = Rb(1..63);
16665
16666 for my $i(1..$N) # Load a set of quarks
16667 {my $j = $i - 1;
16668 $s->load(K(address, $d), K(size, 4+$i));
16669 my $q = $Q->quarkFromShortString($s);
16670 $q->outNL("New quark $j: "); # New quark, new number
16671 }
16672 PrintOutNL;
16673
16674 for my $i(reverse 1..$N) # Reload a set of quarks
16675 {my $j = $i - 1;
16676 $s->load(K(address, $d), K(size, 4+$i));
16677 my $q = $Q->quarkFromShortString($s);
16678 $q->outNL("Old quark $j: "); # Old quark, old number
16679 }
16680 PrintOutNL;
16681
16682 for my $i(1..$N) # Dump quarks
16683 {my $j = $i - 1;
16684 $s->clear;
16685 $Q->shortStringFromQuark(K(quark, $j), $s);
16686 PrintOutString "Quark string $j: ";
16687 PrintOutRegisterInHex xmm0;
16688 }
16689
16690 ok Assemble(debug => 0, trace => 0, eq => <<END);
16691 New quark 0: 0000 0000 0000 0000
16692 New quark 1: 0000 0000 0000 0001
16693 New quark 2: 0000 0000 0000 0002
16694 New quark 3: 0000 0000 0000 0003
16695 New quark 4: 0000 0000 0000 0004
16696
16697 Old quark 4: 0000 0000 0000 0004
16698 Old quark 3: 0000 0000 0000 0003
16699 Old quark 2: 0000 0000 0000 0002
16700 Old quark 1: 0000 0000 0000 0001
16701 Old quark 0: 0000 0000 0000 0000
16702
16703 Quark string 0: xmm0: 0000 0000 0000 0000 0000 0504 0302 0105
16704 Quark string 1: xmm0: 0000 0000 0000 0000 0006 0504 0302 0106
16705 Quark string 2: xmm0: 0000 0000 0000 0000 0706 0504 0302 0107
16706 Quark string 3: xmm0: 0000 0000 0000 0008 0706 0504 0302 0108
16707 Quark string 4: xmm0: 0000 0000 0000 0908 0706 0504 0302 0109
16708 END
16709
16710 my $N = 5;
16711 my $a = CreateArena; # Arena containing quarks
16712 my $Q1 = $a->CreateQuarks; # Quarks
16713 my $Q2 = $a->CreateQuarks; # Quarks
16714
16715 my $s = CreateShortString(0); # Short string used to load and unload quarks
16716 my $d = Rb(1..63);
16717
16718 for my $i(1..$N) # Load first set of quarks
16719 {my $j = $i - 1;
16720 $s->load(K(address, $d), K(size, 4+$i));
16721 my $q = $Q1->quarkFromShortString($s);
16722 $q->outNL("Q1 $j: ");
16723 }
16724 PrintOutNL;
16725
16726 for my $i(1..$N) # Load second set of quarks
16727 {my $j = $i - 1;
16728 $s->load(K(address, $d), K(size, 5+$i));
16729 my $q = $Q2->quarkFromShortString($s);
16730 $q->outNL("Q2 $j: ");
16731 }
16732 PrintOutNL;
16733
16734 $Q1->quarkToQuark(K(three,3), $Q1)->outNL;
16735 $Q1->quarkToQuark(K(three,3), $Q2)->outNL;
16736 $Q2->quarkToQuark(K(two, 2), $Q1)->outNL;
16737 $Q2->quarkToQuark(K(two, 2), $Q2)->outNL;
16738
16739 ok Assemble(debug => 0, trace => 0, eq => <<END);
16740 Q1 0: 0000 0000 0000 0000
16741 Q1 1: 0000 0000 0000 0001
16742 Q1 2: 0000 0000 0000 0002
16743 Q1 3: 0000 0000 0000 0003
16744 Q1 4: 0000 0000 0000 0004
16745
16746 Q2 0: 0000 0000 0000 0000
16747 Q2 1: 0000 0000 0000 0001
16748 Q2 2: 0000 0000 0000 0002
16749 Q2 3: 0000 0000 0000 0003
16750 Q2 4: 0000 0000 0000 0004
16751
16752 found: 0000 0000 0000 0003
16753 found: 0000 0000 0000 0002
16754 found: 0000 0000 0000 0003
16755 found: 0000 0000 0000 0002
16756 END
16757
16758 my $s = CreateShortString(0); # Short string used to load and unload quarks
16759 my $d = Rb(1..63);
16760 $s->loadDwordBytes(0, K(address, $d), K(size, 9));
16761 PrintOutRegisterInHex xmm0;
16762
16763 ok Assemble(debug => 0, trace => 0, eq => <<END);
16764 xmm0: 0000 0000 0000 211D 1915 110D 0905 0109
16765 END
16766
16767  
16768 =head2 Nasm::X86::Quarks::reload($q, %options)
16769  
16770 Reload the description of a set of quarks.
16771  
16772 Parameter Description
16773 1 $q Quarks
16774 2 %options {arena=>arena to use; tree => first tree block; array => first array block}
16775  
16776 =head2 Nasm::X86::Quarks::quarkFromShortString($q, $string)
16777  
16778 Create a quark from a short string.
16779  
16780 Parameter Description
16781 1 $q Quarks
16782 2 $string Short string
16783  
16784 B<Example:>
16785  
16786  
16787 my $N = 5;
16788 my $a = CreateArena; # Arena containing quarks
16789 my $Q = $a->CreateQuarks; # Quarks
16790
16791 my $s = CreateShortString(0); # Short string used to load and unload quarks
16792 my $d = Rb(1..63);
16793
16794 for my $i(1..$N) # Load a set of quarks
16795 {my $j = $i - 1;
16796 $s->load(K(address, $d), K(size, 4+$i));
16797 my $q = $Q->quarkFromShortString($s);
16798 $q->outNL("New quark $j: "); # New quark, new number
16799 }
16800 PrintOutNL;
16801
16802 for my $i(reverse 1..$N) # Reload a set of quarks
16803 {my $j = $i - 1;
16804 $s->load(K(address, $d), K(size, 4+$i));
16805 my $q = $Q->quarkFromShortString($s);
16806 $q->outNL("Old quark $j: "); # Old quark, old number
16807 }
16808 PrintOutNL;
16809
16810 for my $i(1..$N) # Dump quarks
16811 {my $j = $i - 1;
16812 $s->clear;
16813 $Q->shortStringFromQuark(K(quark, $j), $s);
16814 PrintOutString "Quark string $j: ";
16815 PrintOutRegisterInHex xmm0;
16816 }
16817
16818 ok Assemble(debug => 0, trace => 0, eq => <<END);
16819 New quark 0: 0000 0000 0000 0000
16820 New quark 1: 0000 0000 0000 0001
16821 New quark 2: 0000 0000 0000 0002
16822 New quark 3: 0000 0000 0000 0003
16823 New quark 4: 0000 0000 0000 0004
16824
16825 Old quark 4: 0000 0000 0000 0004
16826 Old quark 3: 0000 0000 0000 0003
16827 Old quark 2: 0000 0000 0000 0002
16828 Old quark 1: 0000 0000 0000 0001
16829 Old quark 0: 0000 0000 0000 0000
16830
16831 Quark string 0: xmm0: 0000 0000 0000 0000 0000 0504 0302 0105
16832 Quark string 1: xmm0: 0000 0000 0000 0000 0006 0504 0302 0106
16833 Quark string 2: xmm0: 0000 0000 0000 0000 0706 0504 0302 0107
16834 Quark string 3: xmm0: 0000 0000 0000 0008 0706 0504 0302 0108
16835 Quark string 4: xmm0: 0000 0000 0000 0908 0706 0504 0302 0109
16836 END
16837
16838 my $N = 5;
16839 my $a = CreateArena; # Arena containing quarks
16840 my $Q1 = $a->CreateQuarks; # Quarks
16841 my $Q2 = $a->CreateQuarks; # Quarks
16842
16843 my $s = CreateShortString(0); # Short string used to load and unload quarks
16844 my $d = Rb(1..63);
16845
16846 for my $i(1..$N) # Load first set of quarks
16847 {my $j = $i - 1;
16848 $s->load(K(address, $d), K(size, 4+$i));
16849 my $q = $Q1->quarkFromShortString($s);
16850 $q->outNL("Q1 $j: ");
16851 }
16852 PrintOutNL;
16853
16854 for my $i(1..$N) # Load second set of quarks
16855 {my $j = $i - 1;
16856 $s->load(K(address, $d), K(size, 5+$i));
16857 my $q = $Q2->quarkFromShortString($s);
16858 $q->outNL("Q2 $j: ");
16859 }
16860 PrintOutNL;
16861
16862 $Q1->quarkToQuark(K(three,3), $Q1)->outNL;
16863 $Q1->quarkToQuark(K(three,3), $Q2)->outNL;
16864 $Q2->quarkToQuark(K(two, 2), $Q1)->outNL;
16865 $Q2->quarkToQuark(K(two, 2), $Q2)->outNL;
16866
16867 ok Assemble(debug => 0, trace => 0, eq => <<END);
16868 Q1 0: 0000 0000 0000 0000
16869 Q1 1: 0000 0000 0000 0001
16870 Q1 2: 0000 0000 0000 0002
16871 Q1 3: 0000 0000 0000 0003
16872 Q1 4: 0000 0000 0000 0004
16873
16874 Q2 0: 0000 0000 0000 0000
16875 Q2 1: 0000 0000 0000 0001
16876 Q2 2: 0000 0000 0000 0002
16877 Q2 3: 0000 0000 0000 0003
16878 Q2 4: 0000 0000 0000 0004
16879
16880 found: 0000 0000 0000 0003
16881 found: 0000 0000 0000 0002
16882 found: 0000 0000 0000 0003
16883 found: 0000 0000 0000 0002
16884 END
16885
16886 my $s = CreateShortString(0); # Short string used to load and unload quarks
16887 my $d = Rb(1..63);
16888 $s->loadDwordBytes(0, K(address, $d), K(size, 9));
16889 PrintOutRegisterInHex xmm0;
16890
16891 ok Assemble(debug => 0, trace => 0, eq => <<END);
16892 xmm0: 0000 0000 0000 211D 1915 110D 0905 0109
16893 END
16894
16895  
16896 =head2 Nasm::X86::Quarks::locateQuarkFromShortString($q, $string)
16897  
16898 Locate (if possible) but do not create a quark from a short string. A quark of -1 is returned if there is no matching quark otherwise the number of the matching quark is returned in a variable.
16899  
16900 Parameter Description
16901 1 $q Quarks
16902 2 $string Short string
16903  
16904 =head2 Nasm::X86::Quarks::shortStringFromQuark($q, $number, $string)
16905  
16906 Load a short string from the quark with the specified number. Returns a variable that is set to one if the quark was found else zero.
16907  
16908 Parameter Description
16909 1 $q Quarks
16910 2 $number Variable quark number
16911 3 $string Short string to load
16912  
16913 B<Example:>
16914  
16915  
16916 my $N = 5;
16917 my $a = CreateArena; # Arena containing quarks
16918 my $Q = $a->CreateQuarks; # Quarks
16919
16920 my $s = CreateShortString(0); # Short string used to load and unload quarks
16921 my $d = Rb(1..63);
16922
16923 for my $i(1..$N) # Load a set of quarks
16924 {my $j = $i - 1;
16925 $s->load(K(address, $d), K(size, 4+$i));
16926 my $q = $Q->quarkFromShortString($s);
16927 $q->outNL("New quark $j: "); # New quark, new number
16928 }
16929 PrintOutNL;
16930
16931 for my $i(reverse 1..$N) # Reload a set of quarks
16932 {my $j = $i - 1;
16933 $s->load(K(address, $d), K(size, 4+$i));
16934 my $q = $Q->quarkFromShortString($s);
16935 $q->outNL("Old quark $j: "); # Old quark, old number
16936 }
16937 PrintOutNL;
16938
16939 for my $i(1..$N) # Dump quarks
16940 {my $j = $i - 1;
16941 $s->clear;
16942 $Q->shortStringFromQuark(K(quark, $j), $s);
16943 PrintOutString "Quark string $j: ";
16944 PrintOutRegisterInHex xmm0;
16945 }
16946
16947 ok Assemble(debug => 0, trace => 0, eq => <<END);
16948 New quark 0: 0000 0000 0000 0000
16949 New quark 1: 0000 0000 0000 0001
16950 New quark 2: 0000 0000 0000 0002
16951 New quark 3: 0000 0000 0000 0003
16952 New quark 4: 0000 0000 0000 0004
16953
16954 Old quark 4: 0000 0000 0000 0004
16955 Old quark 3: 0000 0000 0000 0003
16956 Old quark 2: 0000 0000 0000 0002
16957 Old quark 1: 0000 0000 0000 0001
16958 Old quark 0: 0000 0000 0000 0000
16959
16960 Quark string 0: xmm0: 0000 0000 0000 0000 0000 0504 0302 0105
16961 Quark string 1: xmm0: 0000 0000 0000 0000 0006 0504 0302 0106
16962 Quark string 2: xmm0: 0000 0000 0000 0000 0706 0504 0302 0107
16963 Quark string 3: xmm0: 0000 0000 0000 0008 0706 0504 0302 0108
16964 Quark string 4: xmm0: 0000 0000 0000 0908 0706 0504 0302 0109
16965 END
16966
16967 my $N = 5;
16968 my $a = CreateArena; # Arena containing quarks
16969 my $Q1 = $a->CreateQuarks; # Quarks
16970 my $Q2 = $a->CreateQuarks; # Quarks
16971
16972 my $s = CreateShortString(0); # Short string used to load and unload quarks
16973 my $d = Rb(1..63);
16974
16975 for my $i(1..$N) # Load first set of quarks
16976 {my $j = $i - 1;
16977 $s->load(K(address, $d), K(size, 4+$i));
16978 my $q = $Q1->quarkFromShortString($s);
16979 $q->outNL("Q1 $j: ");
16980 }
16981 PrintOutNL;
16982
16983 for my $i(1..$N) # Load second set of quarks
16984 {my $j = $i - 1;
16985 $s->load(K(address, $d), K(size, 5+$i));
16986 my $q = $Q2->quarkFromShortString($s);
16987 $q->outNL("Q2 $j: ");
16988 }
16989 PrintOutNL;
16990
16991 $Q1->quarkToQuark(K(three,3), $Q1)->outNL;
16992 $Q1->quarkToQuark(K(three,3), $Q2)->outNL;
16993 $Q2->quarkToQuark(K(two, 2), $Q1)->outNL;
16994 $Q2->quarkToQuark(K(two, 2), $Q2)->outNL;
16995
16996 ok Assemble(debug => 0, trace => 0, eq => <<END);
16997 Q1 0: 0000 0000 0000 0000
16998 Q1 1: 0000 0000 0000 0001
16999 Q1 2: 0000 0000 0000 0002
17000 Q1 3: 0000 0000 0000 0003
17001 Q1 4: 0000 0000 0000 0004
17002
17003 Q2 0: 0000 0000 0000 0000
17004 Q2 1: 0000 0000 0000 0001
17005 Q2 2: 0000 0000 0000 0002
17006 Q2 3: 0000 0000 0000 0003
17007 Q2 4: 0000 0000 0000 0004
17008
17009 found: 0000 0000 0000 0003
17010 found: 0000 0000 0000 0002
17011 found: 0000 0000 0000 0003
17012 found: 0000 0000 0000 0002
17013 END
17014
17015 my $s = CreateShortString(0); # Short string used to load and unload quarks
17016 my $d = Rb(1..63);
17017 $s->loadDwordBytes(0, K(address, $d), K(size, 9));
17018 PrintOutRegisterInHex xmm0;
17019
17020 ok Assemble(debug => 0, trace => 0, eq => <<END);
17021 xmm0: 0000 0000 0000 211D 1915 110D 0905 0109
17022 END
17023
17024  
17025 =head2 Nasm::X86::Quarks::quarkToQuark($Q, $number, $q)
17026  
17027 Given a variable quark number in one set of quarks find the corresponding quark in another set of quarks and return it in a variable. No new quarks are created in this process. If the quark cannot be found in the first set we return -1, if it cannot be found in the second set we return -2 else the number of the matching quark.
17028  
17029 Parameter Description
17030 1 $Q First set of quarks
17031 2 $number Variable quark number in first set
17032 3 $q Second set of quarks
17033  
17034 =head2 Nasm::X86::Quarks::quarkFromSub($q, $sub, $String)
17035  
17036 Create a quark from a subroutine definition.
17037  
17038 Parameter Description
17039 1 $q Quarks
17040 2 $sub Subroutine definition
17041 3 $String Optional overriding name as a short string
17042  
17043 B<Example:>
17044  
17045  
17046 my $s1 = Subroutine
17047 {PrintOutStringNL "11111";
17048 } [], name => 'test1';
17049
17050 my $s2 = Subroutine
17051 {PrintOutStringNL "22222";
17052 } [], name => 'test2';
17053
17054 my $a = CreateArena;
17055 my $q = $a->CreateQuarks;
17056 my $n1 = $q->quarkFromSub($s1);
17057
17058 my $s = CreateShortString(0);
17059 $s->loadConstantString("assign");
17060 my $n2 = $q->quarkFromSub($s2, $s);
17061
17062 my $S1 = $q->subFromQuark($n1);
17063 $s1->V->outNL;
17064 $S1 ->outNL(" sub: ");
17065
17066 my $S2 = $q->subFromQuark($n2);
17067 $s2->V->outNL;
17068 $S2 ->outNL(" sub: ");
17069
17070 $q->call($n1);
17071 $q->call($n2);
17072
17073 ok Assemble(debug => 0, trace => 0, eq => <<END);
17074 call: 0000 0000 0040 1006
17075 sub: 0000 0000 0040 1006
17076 call: 0000 0000 0040 107A
17077 sub: 0000 0000 0040 107A
17078 11111
17079 22222
17080 END
17081
17082  
17083 =head2 Nasm::X86::Quarks::subFromQuark($q, $number)
17084  
17085 Get the offset of a subroutine as a variable from a set of quarks.
17086  
17087 Parameter Description
17088 1 $q Quarks
17089 2 $number Variable subroutine number
17090  
17091 B<Example:>
17092  
17093  
17094 my $s1 = Subroutine
17095 {PrintOutStringNL "11111";
17096 } [], name => 'test1';
17097
17098 my $s2 = Subroutine
17099 {PrintOutStringNL "22222";
17100 } [], name => 'test2';
17101
17102 my $a = CreateArena;
17103 my $q = $a->CreateQuarks;
17104 my $n1 = $q->quarkFromSub($s1);
17105
17106 my $s = CreateShortString(0);
17107 $s->loadConstantString("assign");
17108 my $n2 = $q->quarkFromSub($s2, $s);
17109
17110 my $S1 = $q->subFromQuark($n1);
17111 $s1->V->outNL;
17112 $S1 ->outNL(" sub: ");
17113
17114 my $S2 = $q->subFromQuark($n2);
17115 $s2->V->outNL;
17116 $S2 ->outNL(" sub: ");
17117
17118 $q->call($n1);
17119 $q->call($n2);
17120
17121 ok Assemble(debug => 0, trace => 0, eq => <<END);
17122 call: 0000 0000 0040 1006
17123 sub: 0000 0000 0040 1006
17124 call: 0000 0000 0040 107A
17125 sub: 0000 0000 0040 107A
17126 11111
17127 22222
17128 END
17129
17130  
17131 =head2 Nasm::X86::Quarks::call($q, $number)
17132  
17133 Call a subroutine via its quark number. Return one in a variable if the subroutine was found and called else zero.
17134  
17135 Parameter Description
17136 1 $q Quarks
17137 2 $number Variable subroutine number
17138  
17139 =head2 Nasm::X86::Quarks::dumpSubs($q)
17140  
17141 Dump a set of quarks identifying subroutines.
17142  
17143 Parameter Description
17144 1 $q Quarks
17145  
17146 =head1 Assemble
17147  
17148 Assemble generated code
17149  
17150 =head2 CallC($sub, @parameters)
17151  
17152 Call a C subroutine.
17153  
17154 Parameter Description
17155 1 $sub Name of the sub to call
17156 2 @parameters Parameters
17157  
17158 B<Example:>
17159  
17160  
17161 my $format = Rs "Hello %s
17162 ";
17163 my $data = Rs "World";
17164
17165 Extern qw(printf exit malloc strcpy); Link 'c';
17166
17167
17168 CallC 'malloc', length($format)+1; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
17169  
17170 Mov r15, rax;
17171
17172 CallC 'strcpy', r15, $format; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
17173  
17174
17175 CallC 'printf', r15, $data; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
17176  
17177
17178 CallC 'exit', 0; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
17179  
17180
17181 ok Assemble(eq => <<END);
17182 Hello World
17183 END
17184
17185  
17186 =head2 Extern(@externalReferences)
17187  
17188 Name external references.
17189  
17190 Parameter Description
17191 1 @externalReferences External references
17192  
17193 B<Example:>
17194  
17195  
17196 my $format = Rs "Hello %s
17197 ";
17198 my $data = Rs "World";
17199
17200
17201 Extern qw(printf exit malloc strcpy); Link 'c'; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
17202  
17203
17204 CallC 'malloc', length($format)+1;
17205 Mov r15, rax;
17206 CallC 'strcpy', r15, $format;
17207 CallC 'printf', r15, $data;
17208 CallC 'exit', 0;
17209
17210 ok Assemble(eq => <<END);
17211 Hello World
17212 END
17213
17214  
17215 =head2 Link(@libraries)
17216  
17217 Libraries to link with.
17218  
17219 Parameter Description
17220 1 @libraries External references
17221  
17222 B<Example:>
17223  
17224  
17225 my $format = Rs "Hello %s
17226 ";
17227 my $data = Rs "World";
17228
17229
17230 Extern qw(printf exit malloc strcpy); Link 'c'; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
17231  
17232
17233 CallC 'malloc', length($format)+1;
17234 Mov r15, rax;
17235 CallC 'strcpy', r15, $format;
17236 CallC 'printf', r15, $data;
17237 CallC 'exit', 0;
17238
17239 ok Assemble(eq => <<END);
17240 Hello World
17241 END
17242
17243  
17244 =head2 Start()
17245  
17246 Initialize the assembler.
17247  
17248  
17249 =head2 Exit($c)
17250  
17251 Exit with the specified return code or zero if no return code supplied. Assemble() automatically adds a call to Exit(0) if the last operation in the program is not a call to Exit.
17252  
17253 Parameter Description
17254 1 $c Return code
17255  
17256 B<Example:>
17257  
17258  
17259 Comment "Print a string from memory";
17260 my $s = "Hello World";
17261 Mov rax, Rs($s);
17262 Mov rdi, length $s;
17263 PrintOutMemory;
17264
17265 Exit(0); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
17266  
17267
17268 ok Assemble =~ m(Hello World);
17269
17270  
17271 =head2 Assemble(%options)
17272  
17273 Assemble the generated code.
17274  
17275 Parameter Description
17276 1 %options Options
17277  
17278 B<Example:>
17279  
17280  
17281 PrintOutStringNL "Hello World";
17282 PrintOutStringNL "Hello
17283 World";
17284 PrintErrStringNL "Hello World";
17285
17286
17287 ok Assemble(debug => 0, eq => <<END); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
17288  
17289 Hello World
17290 Hello
17291 World
17292 END
17293
17294  
17295  
17296 =head1 Hash Definitions
17297  
17298  
17299  
17300  
17301 =head2 Nasm::X86 Definition
17302  
17303  
17304 Quarks
17305  
17306  
17307  
17308  
17309 =head3 Output fields
17310  
17311  
17312 =head4 N
17313  
17314 Initial allocation
17315  
17316 =head4 arena
17317  
17318 The arena containing the quarks
17319  
17320 =head4 args
17321  
17322 Hash of {argument name, argument variable}
17323  
17324 =head4 bs
17325  
17326 Arena containing tree
17327  
17328 =head4 constant
17329  
17330 Constant if true
17331  
17332 =head4 count
17333  
17334 Counter - number of node
17335  
17336 =head4 data
17337  
17338 Data at this position
17339  
17340 =head4 depth
17341  
17342 Lexical depth
17343  
17344 =head4 end
17345  
17346 End label for this subroutine
17347  
17348 =head4 expr
17349  
17350 Expression that initializes the variable
17351  
17352 =head4 first
17353  
17354 Variable addressing offset to first block of keys.
17355  
17356 =head4 found
17357  
17358 Variable indicating whether the last find was successful or not
17359  
17360 =head4 free
17361  
17362 Free chain offset
17363  
17364 =head4 global
17365  
17366 Global if true
17367  
17368 =head4 key
17369  
17370 Key at this position
17371  
17372 =head4 label
17373  
17374 Address in memory
17375  
17376 =head4 leftLength
17377  
17378 Left split length
17379  
17380 =head4 length
17381  
17382 Maximum length in a block
17383  
17384 =head4 lengthOffset
17385  
17386 Offset of length in keys block. The length field is a word - see: "MultiWayTree.svg"
17387  
17388 =head4 level
17389  
17390 Lexical level
17391  
17392 =head4 links
17393  
17394 Location of links in bytes in zmm
17395  
17396 =head4 loop
17397  
17398 Offset of keys, data, node loop.
17399  
17400 =head4 maxKeys
17401  
17402 Maximum number of keys.
17403  
17404 =head4 maximumLength
17405  
17406 The maximum length of a short string
17407  
17408 =head4 more
17409  
17410 Iteration not yet finished
17411  
17412 =head4 name
17413  
17414 Name of the variable
17415  
17416 =head4 nameString
17417  
17418 Name of the sub as a string constant
17419  
17420 =head4 next
17421  
17422 Location of next offset in block in bytes
17423  
17424 =head4 node
17425  
17426 Current node within tree
17427  
17428 =head4 numbersToStrings
17429  
17430 Array mapping numbers to strings
17431  
17432 =head4 options
17433  
17434 Options
17435  
17436 =head4 parameters
17437  
17438 Parameters
17439  
17440 =head4 pos
17441  
17442 Current position within node
17443  
17444 =head4 prev
17445  
17446 Location of prev offset in block in bytes
17447  
17448 =head4 reference
17449  
17450 Reference to another variable
17451  
17452 =head4 rightLength
17453  
17454 Right split length
17455  
17456 =head4 size
17457  
17458 Size field offset
17459  
17460 =head4 slots1
17461  
17462 Number of slots in first block
17463  
17464 =head4 slots2
17465  
17466 Number of slots in second and subsequent blocks
17467  
17468 =head4 splittingKey
17469  
17470 POint at which to split a full block
17471  
17472 =head4 start
17473  
17474 Start label for this subroutine
17475  
17476 =head4 stringsToNumbers
17477  
17478 A tree mapping strings to numbers
17479  
17480 =head4 subTree
17481  
17482 Variable indicating whether the last find found a sub tree
17483  
17484 =head4 tree
17485  
17486 Tree we are iterating over
17487  
17488 =head4 treeBits
17489  
17490 Offset of tree bits in keys block. The tree bits field is a word, each bit of which tells us whether the corresponding data element is the offset (or not) to a sub tree of this tree .
17491  
17492 =head4 treeBitsMask
17493  
17494 Total of 14 tree bits
17495  
17496 =head4 up
17497  
17498 Offset of up in data block.
17499  
17500 =head4 used
17501  
17502 Used field offset
17503  
17504 =head4 variables
17505  
17506 Argument variables
17507  
17508 =head4 vars
17509  
17510 Number of variables in subroutine
17511  
17512 =head4 width
17513  
17514 Width of a key or data slot.
17515  
17516 =head4 x
17517  
17518 The associated xmm register
17519  
17520 =head4 z
17521  
17522 The full name of the zmm register
17523  
17524 =head4 zmm
17525  
17526 The number of the zmm register containing the string
17527  
17528  
17529  
17530 =head1 Attributes
17531  
17532  
17533 The following is a list of all the attributes in this package. A method coded
17534 with the same name in your package will over ride the method of the same name
17535 in this package and thus provide your value for the attribute in place of the
17536 default value supplied for this attribute by this package.
17537  
17538 =head2 Replaceable Attribute List
17539  
17540  
17541 Pi32 Pi64
17542  
17543  
17544 =head2 Pi32
17545  
17546 Pi as a 32 bit float.
17547  
17548  
17549 =head2 Pi64
17550  
17551 Pi as a 64 bit float.
17552  
17553  
17554  
17555  
17556 =head1 Private Methods
17557  
17558 =head2 Label({return "l".++$Labels unless @_;)
17559  
17560 Create a unique label or reuse the one supplied.
17561  
17562 Parameter Description
17563 1 {return "l".++$Labels unless @_; Generate a label
17564  
17565 =head2 Dbwdq($s, @d)
17566  
17567 Layout data.
17568  
17569 Parameter Description
17570 1 $s Element size
17571 2 @d Data to be laid out
17572  
17573 =head2 Rbwdq($s, @d)
17574  
17575 Layout data.
17576  
17577 Parameter Description
17578 1 $s Element size
17579 2 @d Data to be laid out
17580  
17581 =head2 Nasm::X86::Sub::callTo($sub, $mode, $label, @parameters)
17582  
17583 Call a sub passing it some parameters.
17584  
17585 Parameter Description
17586 1 $sub Subroutine descriptor
17587 2 $mode Mode 0 - direct call or 1 - indirect call
17588 3 $label Label of sub
17589 4 @parameters Parameter variables
17590  
17591 =head2 hexTranslateTable()
17592  
17593 Create/address a hex translate table and return its label.
17594  
17595  
17596 =head2 PrintOutRipInHex()
17597  
17598 Print the instruction pointer in hex.
17599  
17600  
17601 =head2 PrintOutRflagsInHex()
17602  
17603 Print the flags register in hex.
17604  
17605  
17606 =head2 PrintUtf32($channel, $size, $address)
17607  
17608 Print the specified number of utf32 characters at the specified address to the specified channel.
17609  
17610 Parameter Description
17611 1 $channel Channel
17612 2 $size Variable: number of characters to print
17613 3 $address Variable: address of memory
17614  
17615 =head2 Nasm::X86::Variable::dump($left, $channel, $newLine, $title1, $title2)
17616  
17617 Dump the value of a variable to the specified channel adding an optional title and new line if requested.
17618  
17619 Parameter Description
17620 1 $left Left variable
17621 2 $channel Channel
17622 3 $newLine New line required
17623 4 $title1 Optional leading title
17624 5 $title2 Optional trailing title
17625  
17626 B<Example:>
17627  
17628  
17629 my $a = V(a, 3); $a->outNL;
17630 my $b = K(b, 2); $b->outNL;
17631 my $c = $a + $b; $c->outNL;
17632 my $d = $c - $a; $d->outNL;
17633 my $g = $a * $b; $g->outNL;
17634 my $h = $g / $b; $h->outNL;
17635 my $i = $a % $b; $i->outNL;
17636
17637 If ($a == 3,
17638 Then
17639 {PrintOutStringNL "a == 3"
17640 },
17641 Else
17642 {PrintOutStringNL "a != 3"
17643 });
17644
17645 ++$a; $a->outNL;
17646 --$a; $a->outNL;
17647
17648 ok Assemble(debug => 0, eq => <<END);
17649 a: 0000 0000 0000 0003
17650 b: 0000 0000 0000 0002
17651 (a add b): 0000 0000 0000 0005
17652 ((a add b) sub a): 0000 0000 0000 0002
17653 (a times b): 0000 0000 0000 0006
17654 ((a times b) / b): 0000 0000 0000 0003
17655 (a % b): 0000 0000 0000 0001
17656 a == 3
17657 a: 0000 0000 0000 0004
17658 a: 0000 0000 0000 0003
17659 END
17660
17661  
17662 =head2 PushRR(@r)
17663  
17664 Push registers onto the stack without tracking.
17665  
17666 Parameter Description
17667 1 @r Register
17668  
17669 =head2 PushR(@r)
17670  
17671 Push registers onto the stack.
17672  
17673 Parameter Description
17674 1 @r Register
17675  
17676 B<Example:>
17677  
17678  
17679 Mov rax, 0x11111111;
17680 Mov rbx, 0x22222222;
17681
17682 PushR my @save = (rax, rbx); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
17683  
17684 Mov rax, 0x33333333;
17685 PopR;
17686 PrintOutRegisterInHex rax;
17687 PrintOutRegisterInHex rbx;
17688
17689 ok Assemble(debug => 0, eq => <<END);
17690 rax: 0000 0000 1111 1111
17691 rbx: 0000 0000 2222 2222
17692 END
17693
17694  
17695 =head2 PopRR(@r)
17696  
17697 Pop registers from the stack without tracking.
17698  
17699 Parameter Description
17700 1 @r Register
17701  
17702 =head2 ClassifyRange($recordOffsetInRange, @parameters)
17703  
17704 Implementation of ClassifyInRange and ClassifyWithinRange.
17705  
17706 Parameter Description
17707 1 $recordOffsetInRange Record offset in classification in high byte if 1 else in classification if 2
17708 2 @parameters Parameters
17709  
17710 =head2 Cstrlen()
17711  
17712 Length of the C style string addressed by rax returning the length in r15.
17713  
17714  
17715 B<Example:>
17716  
17717  
17718 my $s = Rs("Hello World
17719  
17720 Hello Skye");
17721 Mov rax, $s;
17722
17723 Cstrlen; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
17724  
17725 Mov rdi, r15;
17726 PrintOutMemoryNL;
17727
17728 ok Assemble(debug => 0, eq => <<END);
17729 Hello World
17730
17731 Hello Skye
17732 END
17733
17734  
17735 =head2 Nasm::X86::Arena::chain($arena, $bs, $variable, @offsets)
17736  
17737 Return a variable with the end point of a chain of double words in the arena starting at the specified variable.
17738  
17739 Parameter Description
17740 1 $arena Arena descriptor
17741 2 $bs Arena locator
17742 3 $variable Start variable
17743 4 @offsets Offsets chain
17744  
17745 B<Example:>
17746  
17747  
17748 my $format = Rd(map{4*$_+24} 0..64);
17749
17750 my $b = CreateArena;
17751 my $a = $b->allocBlock($b->bs);
17752 Vmovdqu8 zmm31, "[$format]";
17753 $b->putBlock($b->bs, $a, 31);
17754 my $r = $b->chain($b->bs, V(start, 0x18), 4); $r->outNL("chain1: ");
17755 my $s = $b->chain($b->bs, $r, 4); $s->outNL("chain2: ");
17756 my $t = $b->chain($b->bs, $s, 4); $t->outNL("chain3: ");
17757 my $A = $b->chain($b->bs, V(start, 0x18), 4, 4, 4); $A->outNL("chain4: "); # Get a long chain
17758
17759 $b->putChain($b->bs, V(start, 0x18), V(end, 0xff), 4, 4, 4); # Put at the end of a long chain
17760
17761 $b->dump;
17762
17763 my $sub = Subroutine
17764 {my ($p) = @_; # Parameters
17765 If ($$p{c} == -1,
17766 sub {PrintOutStringNL "C is minus one"},
17767 sub {PrintOutStringNL "C is NOT minus one"},
17768 );
17769 If ($$p{d} == -1,
17770 sub {PrintOutStringNL "D is minus one"},
17771 sub {PrintOutStringNL "D is NOT minus one"},
17772 );
17773
17774 $$p{c}->outNL;
17775
17776 $$p{e} += 1;
17777 $$p{e}->outNL('E: ');
17778
17779 $$p{f}->outNL('F1: ');
17780 $$p{f}++;
17781 $$p{f}->outNL('F2: ');
17782 } [qw(c d e f)], name=> 'aaa';
17783
17784 my $c = K(c, -1);
17785 my $d = K(d, -1);
17786 my $e = V(e, 1);
17787 my $f = V(f, 2);
17788
17789 $sub->call($c, $d, $e, $f);
17790 $f->outNL('F3: ');
17791
17792 ok Assemble(debug => 0, eq => <<END);
17793 chain1: 0000 0000 0000 001C
17794 chain2: 0000 0000 0000 0020
17795 chain3: 0000 0000 0000 0024
17796 chain4: 0000 0000 0000 0024
17797 Arena
17798 Size: 0000 0000 0000 1000
17799 Used: 0000 0000 0000 0058
17800 0000: 0010 0000 0000 00005800 0000 0000 00000000 0000 0000 00001800 0000 1C00 00002000 0000 FF00 00002800 0000 2C00 00003000 0000 3400 00003800 0000 3C00 0000
17801 0040: 4000 0000 4400 00004800 0000 4C00 00005000 0000 5400 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
17802 0080: 0000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
17803 00C0: 0000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
17804 C is minus one
17805 D is minus one
17806 c: FFFF FFFF FFFF FFFF
17807 E: 0000 0000 0000 0002
17808 F1: 0000 0000 0000 0002
17809 F2: 0000 0000 0000 0003
17810 F3: 0000 0000 0000 0003
17811 END
17812
17813  
17814 =head2 Nasm::X86::Arena::putChain($arena, $bs, $start, $value, @offsets)
17815  
17816 Write the double word in the specified variable to the double word location at the the specified offset in the specified arena.
17817  
17818 Parameter Description
17819 1 $arena Arena descriptor
17820 2 $bs Arena locator variable
17821 3 $start Start variable
17822 4 $value Value to put as a variable
17823 5 @offsets Offsets chain
17824  
17825 =head2 Nasm::X86::Arena::updateSpace($arena, @variables)
17826  
17827 Make sure that the arena addressed by rax has enough space to accommodate content of length rdi.
17828  
17829 Parameter Description
17830 1 $arena Arena descriptor
17831 2 @variables Variables
17832  
17833 =head2 Nasm::X86::Arena::blockSize($arena)
17834  
17835 Size of a block.
17836  
17837 Parameter Description
17838 1 $arena Arena
17839  
17840 =head2 Nasm::X86::Arena::firstFreeBlock($arena)
17841  
17842 Create and load a variable with the first free block on the free block chain or zero if no such block in the given arena.
17843  
17844 Parameter Description
17845 1 $arena Arena address as a variable
17846  
17847 =head2 Nasm::X86::Arena::setFirstFreeBlock($arena, $offset)
17848  
17849 Set the first free block field from a variable.
17850  
17851 Parameter Description
17852 1 $arena Arena descriptor
17853 2 $offset First free block offset as a variable
17854  
17855 =head2 Nasm::X86::Arena::freeBlock($arena, @variables)
17856  
17857 Free a block in an arena by placing it on the free chain.
17858  
17859 Parameter Description
17860 1 $arena Arena descriptor
17861 2 @variables Variables
17862  
17863 B<Example:>
17864  
17865  
17866 my $a = CreateArena; $a->dump;
17867 my $b1 = $a->allocBlock($a->bs); $a->dump;
17868 my $b2 = $a->allocBlock($a->bs); $a->dump;
17869 $a->freeBlock($b2); $a->dump;
17870 $a->freeBlock($b1); $a->dump;
17871
17872 ok Assemble(debug => 0, eq => <<END);
17873 Arena
17874 Size: 0000 0000 0000 1000
17875 Used: 0000 0000 0000 0018
17876 0000: 0010 0000 0000 00001800 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
17877 0040: 0000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
17878 0080: 0000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
17879 00C0: 0000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
17880 Arena
17881 Size: 0000 0000 0000 1000
17882 Used: 0000 0000 0000 0058
17883 0000: 0010 0000 0000 00005800 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
17884 0040: 0000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
17885 0080: 0000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
17886 00C0: 0000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
17887 Arena
17888 Size: 0000 0000 0000 1000
17889 Used: 0000 0000 0000 0098
17890 0000: 0010 0000 0000 00009800 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
17891 0040: 0000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
17892 0080: 0000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
17893 00C0: 0000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
17894 Arena
17895 Size: 0000 0000 0000 1000
17896 Used: 0000 0000 0000 0098
17897 0000: 0010 0000 0000 00009800 0000 0000 00005800 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
17898 0040: 0000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
17899 0080: 0000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
17900 00C0: 0000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
17901 Arena
17902 Size: 0000 0000 0000 1000
17903 Used: 0000 0000 0000 0098
17904 0000: 0010 0000 0000 00009800 0000 0000 00001800 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
17905 0040: 0000 0000 0000 00000000 0000 0000 00000000 0000 5800 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
17906 0080: 0000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
17907 00C0: 0000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 00000000 0000 0000 0000
17908 END
17909
17910  
17911 =head2 Nasm::X86::Arena::getBlock($arena, $address, $block, $zmm, $work1, $work2)
17912  
17913 Get the block with the specified offset in the specified string and return it in the numbered zmm.
17914  
17915 Parameter Description
17916 1 $arena Arena descriptor
17917 2 $address Arena address variable
17918 3 $block Offset of the block as a variable
17919 4 $zmm Number of zmm register to contain block
17920 5 $work1 First optional work register
17921 6 $work2 Second optional work register
17922  
17923 =head2 Nasm::X86::Arena::putBlock($arena, $address, $block, $zmm, $work1, $work2)
17924  
17925 Write the numbered zmm to the block at the specified offset in the specified arena.
17926  
17927 Parameter Description
17928 1 $arena Arena descriptor
17929 2 $address Arena address variable
17930 3 $block Offset of the block as a variable
17931 4 $zmm Number of zmm register to contain block
17932 5 $work1 First optional work register
17933 6 $work2 Second optional work register
17934  
17935 =head2 Nasm::X86::String::address($String)
17936  
17937 Address of a string.
17938  
17939 Parameter Description
17940 1 $String String descriptor
17941  
17942 =head2 Nasm::X86::String::allocBlock($String, $arena)
17943  
17944 Allocate a block to hold a zmm register in the specified arena and return the offset of the block in a variable.
17945  
17946 Parameter Description
17947 1 $String String descriptor
17948 2 $arena Arena address
17949  
17950 =head2 Nasm::X86::String::getBlockLength($String, $zmm)
17951  
17952 Get the block length of the numbered zmm and return it in a variable.
17953  
17954 Parameter Description
17955 1 $String String descriptor
17956 2 $zmm Number of zmm register
17957  
17958 =head2 Nasm::X86::String::setBlockLengthInZmm($String, $length, $zmm)
17959  
17960 Set the block length of the numbered zmm to the specified length.
17961  
17962 Parameter Description
17963 1 $String String descriptor
17964 2 $length Length as a variable
17965 3 $zmm Number of zmm register
17966  
17967 =head2 Nasm::X86::String::getBlock($String, $bsa, $block, $zmm)
17968  
17969 Get the block with the specified offset in the specified string and return it in the numbered zmm.
17970  
17971 Parameter Description
17972 1 $String String descriptor
17973 2 $bsa Arena variable
17974 3 $block Offset of the block as a variable
17975 4 $zmm Number of zmm register to contain block
17976  
17977 =head2 Nasm::X86::String::putBlock($String, $bsa, $block, $zmm)
17978  
17979 Write the numbered zmm to the block at the specified offset in the specified arena.
17980  
17981 Parameter Description
17982 1 $String String descriptor
17983 2 $bsa Arena variable
17984 3 $block Block in arena
17985 4 $zmm Content variable
17986  
17987 =head2 Nasm::X86::String::getNextAndPrevBlockOffsetFromZmm($String, $zmm)
17988  
17989 Get the offsets of the next and previous blocks as variables from the specified zmm.
17990  
17991 Parameter Description
17992 1 $String String descriptor
17993 2 $zmm Zmm containing block
17994  
17995 =head2 Nasm::X86::String::putNextandPrevBlockOffsetIntoZmm($String, $zmm, $next, $prev)
17996  
17997 Save next and prev offsets into a zmm representing a block.
17998  
17999 Parameter Description
18000 1 $String String descriptor
18001 2 $zmm Zmm containing block
18002 3 $next Next offset as a variable
18003 4 $prev Prev offset as a variable
18004  
18005 =head2 Nasm::X86::Array::address($Array)
18006  
18007 Address of a string.
18008  
18009 Parameter Description
18010 1 $Array Array descriptor
18011  
18012 =head2 Nasm::X86::Array::allocBlock($Array, $bs)
18013  
18014 Allocate a block to hold a zmm register in the specified arena and return the offset of the block in a variable.
18015  
18016 Parameter Description
18017 1 $Array Array descriptor
18018 2 $bs Arena address
18019  
18020 =head2 Nasm::X86::Tree::allocKeysDataNode($t, $bs, $K, $D, $N)
18021  
18022 Allocate a keys/data/node block and place it in the numbered zmm registers.
18023  
18024 Parameter Description
18025 1 $t Tree descriptor
18026 2 $bs Arena address
18027 3 $K Numbered zmm for keys
18028 4 $D Numbered zmm for data
18029 5 $N Numbered zmm for children
18030  
18031 =head2 Nasm::X86::Tree::splitNode($t, $bs, $node, $key, @variables)
18032  
18033 Split a non root node given its offset in an arena retaining the key being inserted in the node being split while putting the remainder to the left or right.
18034  
18035 Parameter Description
18036 1 $t Tree descriptor
18037 2 $bs Backing arena
18038 3 $node Offset of node
18039 4 $key Key
18040 5 @variables Variables
18041  
18042 =head2 Nasm::X86::Tree::reParent($t, $bs, $PK, $PD, $PN, @variables)
18043  
18044 Reparent the children of a node held in registers. The children are in the backing arena not registers.
18045  
18046 Parameter Description
18047 1 $t Tree descriptor
18048 2 $bs Backing arena
18049 3 $PK Numbered zmm key node
18050 4 $PD Numbered zmm data node
18051 5 $PN Numbered zmm child node
18052 6 @variables Variables
18053  
18054 =head2 Nasm::X86::Tree::transferTreeBitsFromParent($t, $parent, $left, $right)
18055  
18056 Transfer tree bits when splitting a full node.
18057  
18058 Parameter Description
18059 1 $t Tree descriptor
18060 2 $parent Numbered parent zmm
18061 3 $left Numbered left zmm
18062 4 $right Numbered right zmm
18063  
18064 B<Example:>
18065  
18066  
18067 my $B = Rb(0..63);
18068 Vmovdqu8 zmm0, "[$B]";
18069 loadFromZmm r15, w, zmm, 14;
18070
18071 my $b = CreateArena;
18072 my $t = $b->CreateTree;
18073 $t->getTreeBits(0, r14);
18074
18075 PrintOutRegisterInHex zmm0, r15, r14;
18076
18077 Mov r14, my $treeBits = 0xDCBA;
18078 $t->putTreeBits(1, r14);
18079 PrintOutRegisterInHex zmm1;
18080
18081 $t->transferTreeBitsFromParent(1, 2, 3);
18082 PrintOutStringNL "Split:";
18083 PrintOutRegisterInHex zmm1, zmm2, zmm3;
18084
18085 my $left = $treeBits & ((1<<$t->leftLength) - 1);
18086 my $right = ($treeBits >> ($t->leftLength + 1)) & ((1<<$t->rightLength) - 1);
18087
18088 my $l = sprintf("%02X", $left);
18089 my $r = sprintf("%02X", $right);
18090
18091 ok Assemble(debug => 0, eq => <<END);
18092 zmm0: 3F3E 3D3C 3B3A 3938 3736 3534 3332 3130 2F2E 2D2C 2B2A 2928 2726 2524 2322 2120 1F1E 1D1C 1B1A 1918 1716 1514 1312 1110 0F0E 0D0C 0B0A 0908 0706 0504 0302 0100
18093 r15: 0000 0000 0000 0F0E
18094 r14: 0000 0000 0000 3B3A
18095 zmm1: 0000 0000 DCBA 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
18096 Split:
18097 zmm1: 0000 0000 0001 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
18098 zmm2: 0000 0000 00$l 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
18099 zmm3: 0000 0000 00$r 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
18100 END
18101
18102  
18103 =head2 Nasm::X86::Tree::transferTreeBitsFromLeftOrRight($t, $rnl, $point, $parent, $left, $right)
18104  
18105 Transfer tree bits when splitting a full left or right node.
18106  
18107 Parameter Description
18108 1 $t Tree descriptor
18109 2 $rnl 0 - left 1 - right
18110 3 $point Register indicating point of left in parent
18111 4 $parent Numbered parent zmm
18112 5 $left Numbered left zmm
18113 6 $right Numbered right zmm
18114  
18115 =head2 Nasm::X86::Tree::transferTreeBitsFromLeft($t, $point, $parent, $left, $right)
18116  
18117 Transfer tree bits when splitting a full left node.
18118  
18119 Parameter Description
18120 1 $t Tree descriptor
18121 2 $point Register indicating point of left in parent
18122 3 $parent Numbered parent zmm
18123 4 $left Numbered left zmm
18124 5 $right Numbered right zmm
18125  
18126 B<Example:>
18127  
18128  
18129 my $b = CreateArena;
18130 my $t = $b->CreateTree;
18131 my $lR = "110110";
18132 my $lP = "1";
18133 my $lL = "1110111";
18134
18135 my $p1 = "01010_110010";
18136 my $p2 = "1";
18137
18138 my $epe = sprintf("%04X", eval "0b$p1$lP$p2");
18139 my $ele = sprintf("%04X", eval "0b$lL" );
18140 my $ere = sprintf("%04X", eval "0b$lR" );
18141
18142 my @expected;
18143 for my $i(0..1)
18144 {Mov r15, eval "0b$lR$lP$lL"; $t->putTreeBits(1+$i, r15);
18145 Mov r15, eval "0b$p1$p2"; $t->putTreeBits(0, r15);
18146
18147 PrintOutRegisterInHex zmm 0, 1+$i;
18148
18149 Mov r15, 0b10;
18150 $t->transferTreeBitsFromLeft (r15, 0, 1, 2) unless $i;
18151 $t->transferTreeBitsFromRight(r15, 0, 1, 2) if $i;
18152 PrintOutRegisterInHex zmm 0..2;
18153
18154 my $zzz = $i ? "zmm2" : "zmm1";
18155 push @expected, <<END;
18156 zmm0: 0000 0000 0565 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
18157 $zzz: 0000 0000 36F7 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
18158 zmm0: 0000 0000 $epe 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
18159 zmm1: 0000 0000 $ele 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
18160 zmm2: 0000 0000 $ere 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
18161 END
18162 }
18163
18164 ok Assemble(debug => 0, eq => join "", @expected);
18165
18166  
18167 =head2 Nasm::X86::Tree::transferTreeBitsFromRight($t, $point, $parent, $left, $right)
18168  
18169 Transfer tree bits when splitting a full right node.
18170  
18171 Parameter Description
18172 1 $t Tree descriptor
18173 2 $point Register indicating point of right in parent
18174 3 $parent Numbered parent zmm
18175 4 $left Numbered left zmm
18176 5 $right Numbered right zmm
18177  
18178 B<Example:>
18179  
18180  
18181 my $b = CreateArena;
18182 my $t = $b->CreateTree;
18183 my $lR = "110110";
18184 my $lP = "1";
18185 my $lL = "1110111";
18186
18187 my $p1 = "01010_110010";
18188 my $p2 = "1";
18189
18190 my $epe = sprintf("%04X", eval "0b$p1$lP$p2");
18191 my $ele = sprintf("%04X", eval "0b$lL" );
18192 my $ere = sprintf("%04X", eval "0b$lR" );
18193
18194 my @expected;
18195 for my $i(0..1)
18196 {Mov r15, eval "0b$lR$lP$lL"; $t->putTreeBits(1+$i, r15);
18197 Mov r15, eval "0b$p1$p2"; $t->putTreeBits(0, r15);
18198
18199 PrintOutRegisterInHex zmm 0, 1+$i;
18200
18201 Mov r15, 0b10;
18202 $t->transferTreeBitsFromLeft (r15, 0, 1, 2) unless $i;
18203 $t->transferTreeBitsFromRight(r15, 0, 1, 2) if $i;
18204 PrintOutRegisterInHex zmm 0..2;
18205
18206 my $zzz = $i ? "zmm2" : "zmm1";
18207 push @expected, <<END;
18208 zmm0: 0000 0000 0565 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
18209 $zzz: 0000 0000 36F7 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
18210 zmm0: 0000 0000 $epe 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
18211 zmm1: 0000 0000 $ele 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
18212 zmm2: 0000 0000 $ere 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
18213 END
18214 }
18215
18216 ok Assemble(debug => 0, eq => join "", @expected);
18217
18218  
18219 =head2 Nasm::X86::Tree::splitFullRoot($t, $bs)
18220  
18221 Split a full root block held in 31..29 and place the left block in 28..26 and the right block in 25..23. The left and right blocks should have their loop offsets set so they can be inserted into the root.
18222  
18223 Parameter Description
18224 1 $t Tree descriptor
18225 2 $bs Arena address
18226  
18227 =head2 Nasm::X86::Tree::splitFullLeftOrRightNode($t, $right)
18228  
18229 Split a full a full left node (held in 28..26) or a full right node (held in 25..23) whose parent is in 31..29.
18230  
18231 Parameter Description
18232 1 $t Tree descriptor
18233 2 $right 0 left or 1 right
18234  
18235 =head2 Nasm::X86::Tree::splitFullLeftNode($t)
18236  
18237 Split a full left node block held in 28..26 whose parent is in 31..29 and place the new right block in 25..23. The parent is assumed to be not full. The loop and length fields are assumed to be authoritative and hence are preserved.
18238  
18239 Parameter Description
18240 1 $t Tree descriptor
18241  
18242 B<Example:>
18243  
18244  
18245 my $Sk = Rd(17..28, 0, 0, 12, 0xFF);
18246 my $Sd = Rd(17..28, 0, 0, 0xDD, 0xEE);
18247 my $Sn = Rd(1..13, 0, 0, 0xCC);
18248
18249 my $sk = Rd(1..14, 14, 0xA1);
18250 my $sd = Rd(1..14, 0xCC, 0xA2);
18251 my $sn = Rd(1..15, 0xA3);
18252
18253 my $rk = Rd((0)x14, 14, 0xB1);
18254 my $rd = Rd((0)x14, 0xCC, 0xB2);
18255 my $rn = Rd((0)x15, 0xB3);
18256
18257 my $b = CreateArena;
18258 my $t = $b->CreateTree;
18259
18260 Vmovdqu8 zmm31, "[$Sk]";
18261 Vmovdqu8 zmm30, "[$Sd]";
18262 Vmovdqu8 zmm29, "[$Sn]";
18263
18264 Vmovdqu8 zmm28, "[$sk]";
18265 Vmovdqu8 zmm27, "[$sd]";
18266 Vmovdqu8 zmm26, "[$sn]";
18267
18268 Vmovdqu8 zmm25, "[$rk]";
18269 Vmovdqu8 zmm24, "[$rd]";
18270 Vmovdqu8 zmm23, "[$rn]";
18271
18272 $t->splitFullLeftNode;
18273
18274 PrintOutRegisterInHex reverse zmm(23..31);
18275
18276 ok Assemble(debug => 0, eq => <<END);
18277 zmm31: 0000 00FF 0000 000D 0000 0000 0000 0000 0000 001C 0000 001B 0000 001A 0000 0019 0000 0018 0000 0017 0000 0016 0000 0015 0000 0014 0000 0013 0000 0012 0000 0011
18278 zmm30: 0000 00EE 0000 00DD 0000 0000 0000 0000 0000 001C 0000 001B 0000 001A 0000 0019 0000 0018 0000 0017 0000 0016 0000 0015 0000 0014 0000 0013 0000 0012 0000 0011
18279 zmm29: 0000 00CC 0000 0000 0000 0000 0000 000D 0000 000C 0000 000B 0000 000A 0000 0009 0000 0008 0000 0007 0000 0006 0000 0005 0000 0004 0000 0003 0000 0002 0000 0001
18280 zmm28: 0000 00A1 0000 0007 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0007 0000 0006 0000 0005 0000 0004 0000 0003 0000 0002 0000 0001
18281 zmm27: 0000 00A2 0000 00CC 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0007 0000 0006 0000 0005 0000 0004 0000 0003 0000 0002 0000 0001
18282 zmm26: 0000 00A3 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0007 0000 0006 0000 0005 0000 0004 0000 0003 0000 0002 0000 0001
18283 zmm25: 0000 00B1 0000 0006 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 000E 0000 000D 0000 000C 0000 000B 0000 000A 0000 0009
18284 zmm24: 0000 00B2 0000 00CC 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 000E 0000 000D 0000 000C 0000 000B 0000 000A 0000 0009
18285 zmm23: 0000 00B3 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 000E 0000 000D 0000 000C 0000 000B 0000 000A 0000 0009
18286 END
18287
18288 my $tk = Rd(1, (0) x 13, 1, 0xC1);
18289 my $td = Rd(1, (0) x 14, 0xC2);
18290 my $tn = Rd(1, 0xAA, (0) x 13, 0xCC);
18291
18292 my $lk = Rd(1..14, 14, 0xA1);
18293 my $ld = Rd(1..14, 0xCC, 0xA2);
18294 my $ln = Rd(1..15, 0xAA);
18295
18296 my $rk = Rd((0)x14, 14, 0xB1);
18297 my $rd = Rd((0)x14, 0xCC, 0xB2);
18298 my $rn = Rd((0)x15, 0xBB);
18299
18300 my $b = CreateArena;
18301 my $t = $b->CreateTree;
18302
18303 Vmovdqu8 zmm31, "[$tk]";
18304 Vmovdqu8 zmm30, "[$td]";
18305 Vmovdqu8 zmm29, "[$tn]";
18306
18307 Vmovdqu8 zmm28, "[$lk]";
18308 Vmovdqu8 zmm27, "[$ld]";
18309 Vmovdqu8 zmm26, "[$ln]";
18310
18311 Vmovdqu8 zmm25, "[$rk]";
18312 Vmovdqu8 zmm24, "[$rd]";
18313 Vmovdqu8 zmm23, "[$rn]";
18314
18315 $t->splitFullLeftNode;
18316
18317 PrintOutRegisterInHex reverse zmm(23..31);
18318
18319 ok Assemble(debug => 0, eq => <<END);
18320 zmm31: 0000 00C1 0000 0002 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0008 0000 0001
18321 zmm30: 0000 00C2 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0008 0000 0001
18322 zmm29: 0000 00CC 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 00BB 0000 00AA 0000 0001
18323 zmm28: 0000 00A1 0000 0007 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0007 0000 0006 0000 0005 0000 0004 0000 0003 0000 0002 0000 0001
18324 zmm27: 0000 00A2 0000 00CC 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0007 0000 0006 0000 0005 0000 0004 0000 0003 0000 0002 0000 0001
18325 zmm26: 0000 00AA 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0007 0000 0006 0000 0005 0000 0004 0000 0003 0000 0002 0000 0001
18326 zmm25: 0000 00B1 0000 0006 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 000E 0000 000D 0000 000C 0000 000B 0000 000A 0000 0009
18327 zmm24: 0000 00B2 0000 00CC 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 000E 0000 000D 0000 000C 0000 000B 0000 000A 0000 0009
18328 zmm23: 0000 00BB 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 000E 0000 000D 0000 000C 0000 000B 0000 000A 0000 0009
18329 END
18330
18331  
18332 =head2 Nasm::X86::Tree::splitFullRightNode($t)
18333  
18334 Split a full right node block held in 25..23 whose parent is in 31..29 and place the new left block in 28..26. The loop and length fields are assumed to be authoritative and hence are preserved.
18335  
18336 Parameter Description
18337 1 $t Tree descriptor
18338  
18339 B<Example:>
18340  
18341  
18342 my $tk = Rd(1..12, 0, 0, 12, 0xC1);
18343 my $td = Rd(1..12, 0, 0, 0, 0xC2);
18344 my $tn = Rd(1, 0xBB, 3..13, 0, 0, 0xCC);
18345
18346 my $lk = Rd(17..30, 14, 0xA1);
18347 my $ld = Rd(17..30, 0xCC, 0xA2);
18348 my $ln = Rd(17..31, 0xAA);
18349
18350 my $rk = Rd(17..30, 14, 0xB1);
18351 my $rd = Rd(17..30, 0xCC, 0xB2);
18352 my $rn = Rd(17..31, 0xBB);
18353
18354 my $b = CreateArena;
18355 my $t = $b->CreateTree;
18356
18357 Vmovdqu8 zmm31, "[$tk]";
18358 Vmovdqu8 zmm30, "[$td]";
18359 Vmovdqu8 zmm29, "[$tn]";
18360
18361 Vmovdqu8 zmm28, "[$lk]";
18362 Vmovdqu8 zmm27, "[$ld]";
18363 Vmovdqu8 zmm26, "[$ln]";
18364
18365 Vmovdqu8 zmm25, "[$rk]";
18366 Vmovdqu8 zmm24, "[$rd]";
18367 Vmovdqu8 zmm23, "[$rn]";
18368
18369 $t->splitFullRightNode;
18370
18371 PrintOutRegisterInHex reverse zmm(23..31);
18372
18373 ok Assemble(debug => 0, eq => <<END);
18374 zmm31: 0000 00C1 0000 000D 0000 0000 0000 000C 0000 000B 0000 000A 0000 0009 0000 0008 0000 0007 0000 0006 0000 0005 0000 0004 0000 0003 0000 0002 0000 0018 0000 0001
18375 zmm30: 0000 00C2 0000 0000 0000 0000 0000 000C 0000 000B 0000 000A 0000 0009 0000 0008 0000 0007 0000 0006 0000 0005 0000 0004 0000 0003 0000 0002 0000 0018 0000 0001
18376 zmm29: 0000 00CC 0000 0000 0000 000D 0000 000C 0000 000B 0000 000A 0000 0009 0000 0008 0000 0007 0000 0006 0000 0005 0000 0004 0000 0003 0000 00BB 0000 00AA 0000 0001
18377 zmm28: 0000 00A1 0000 0007 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0017 0000 0016 0000 0015 0000 0014 0000 0013 0000 0012 0000 0011
18378 zmm27: 0000 00A2 0000 00CC 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0017 0000 0016 0000 0015 0000 0014 0000 0013 0000 0012 0000 0011
18379 zmm26: 0000 00AA 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0017 0000 0016 0000 0015 0000 0014 0000 0013 0000 0012 0000 0011
18380 zmm25: 0000 00B1 0000 0006 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 001E 0000 001D 0000 001C 0000 001B 0000 001A 0000 0019
18381 zmm24: 0000 00B2 0000 00CC 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 001E 0000 001D 0000 001C 0000 001B 0000 001A 0000 0019
18382 zmm23: 0000 00BB 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 001E 0000 001D 0000 001C 0000 001B 0000 001A 0000 0019
18383 END
18384
18385  
18386 =head2 Nasm::X86::Tree::findAndSplit($t, $bs, $first, $key, $compare, $offset, $index)
18387  
18388 Find a key in a tree which is known to contain at least one key splitting full nodes along the path to the key.
18389  
18390 Parameter Description
18391 1 $t Tree descriptor
18392 2 $bs Arena address
18393 3 $first Start node
18394 4 $key Key to find
18395 5 $compare Last comparison result variable
18396 6 $offset Offset of last node found
18397 7 $index Index within last node found
18398  
18399 =head2 Nasm::X86::Tree::getKeysData($t, $bs, $offset, $zmmKeys, $zmmData, $work1, $work2)
18400  
18401 Load the keys and data blocks for a node.
18402  
18403 Parameter Description
18404 1 $t Tree descriptor
18405 2 $bs Arena address
18406 3 $offset Offset as a variable
18407 4 $zmmKeys Numbered zmm for keys
18408 5 $zmmData Numbered data for keys
18409 6 $work1 Optional first work register
18410 7 $work2 Optional second work register
18411  
18412 =head2 Nasm::X86::Tree::putKeysData($t, $bs, $offset, $zmmKeys, $zmmData, $work1, $work2)
18413  
18414 Save the key and data blocks for a node.
18415  
18416 Parameter Description
18417 1 $t Tree descriptor
18418 2 $bs Arena address
18419 3 $offset Offset as a variable
18420 4 $zmmKeys Numbered zmm for keys
18421 5 $zmmData Numbered data for keys
18422 6 $work1 Optional first work register
18423 7 $work2 Optional second work register
18424  
18425 =head2 Nasm::X86::Tree::getKeysDataNode($t, $bs, $offset, $zmmKeys, $zmmData, $zmmNode, $work1, $work2)
18426  
18427 Load the keys, data and child nodes for a node.
18428  
18429 Parameter Description
18430 1 $t Tree descriptor
18431 2 $bs Arena address
18432 3 $offset Offset as a variable
18433 4 $zmmKeys Numbered zmm for keys
18434 5 $zmmData Numbered data for keys
18435 6 $zmmNode Numbered numbered for keys
18436 7 $work1 Optional first work register
18437 8 $work2 Optional second work register
18438  
18439 =head2 Nasm::X86::Tree::putKeysDataNode($t, $bs, $offset, $zmmKeys, $zmmData, $zmmNode, $work1, $work2)
18440  
18441 Save the keys, data and child nodes for a node.
18442  
18443 Parameter Description
18444 1 $t Tree descriptor
18445 2 $bs Arena address
18446 3 $offset Offset as a variable
18447 4 $zmmKeys Numbered zmm for keys
18448 5 $zmmData Numbered data for keys
18449 6 $zmmNode Numbered numbered for keys
18450 7 $work1 Optional first work register
18451 8 $work2 Optional second work register
18452  
18453 =head2 Nasm::X86::Tree::getLengthInKeys($t, $zmm)
18454  
18455 Get the length of the keys block in the numbered zmm and return it as a variable.
18456  
18457 Parameter Description
18458 1 $t Tree descriptor
18459 2 $zmm Zmm number
18460  
18461 =head2 Nasm::X86::Tree::putLengthInKeys($t, $zmm, $length)
18462  
18463 Get the length of the block in the numbered zmm from the specified variable.
18464  
18465 Parameter Description
18466 1 $t Tree
18467 2 $zmm Zmm number
18468 3 $length Length variable
18469  
18470 =head2 Nasm::X86::Tree::getUpFromData11($t, $zmm, $transfer)
18471  
18472 Get the up offset from the data block in the numbered zmm and return it as a variable.
18473  
18474 Parameter Description
18475 1 $t Tree descriptor
18476 2 $zmm Zmm number
18477 3 $transfer Transfer register
18478  
18479 =head2 Nasm::X86::Tree::putUpIntoData11($t, $offset, $zmm, $transfer)
18480  
18481 Put the offset of the parent keys block expressed as a variable into the numbered zmm.
18482  
18483 Parameter Description
18484 1 $t Tree descriptor
18485 2 $offset Variable containing up offset
18486 3 $zmm Zmm number
18487 4 $transfer Optional transfer register
18488  
18489 =head2 Nasm::X86::Tree::getUpFromData($t, $zmm, $transfer)
18490  
18491 Get the decompressed up offset from the data block in the numbered zmm and return it as a variable. The lowest 6 bits of an offset are always 0b011000. The up field becomes the count field for the root node which has no node above it. To differentiate between up and count, the lowest bit of the up field is set for offsets, and cleared for the count of the number of nodes in the tree held in the root node. Thus if this dword is set to zero it means that this is the count field for an empty tree.
18492  
18493 Parameter Description
18494 1 $t Tree descriptor
18495 2 $zmm Zmm number
18496 3 $transfer Transfer register
18497  
18498 =head2 Nasm::X86::Tree::getUpFromDataNM($t, $zmm, $transfer)
18499  
18500 Get the compressed up offset//count from the data block in the numbered zmm and return it as a variable.
18501  
18502 Parameter Description
18503 1 $t Tree descriptor
18504 2 $zmm Zmm number
18505 3 $transfer Transfer register
18506  
18507 =head2 Nasm::X86::Tree::putUpIntoData($t, $offset, $zmm, $transfer)
18508  
18509 Put the offset of the parent keys block expressed as a variable into the numbered zmm. Offsets always end in 0b01100 as long as only 64 byte allocations have been made in the arena. Offsets are indicated by setting the lowest bit in the dword containing the offset to 1.
18510  
18511 Parameter Description
18512 1 $t Tree descriptor
18513 2 $offset Variable containing up offset
18514 3 $zmm Zmm number
18515 4 $transfer Transfer register
18516  
18517 =head2 Nasm::X86::Tree::getCountFromData($t, $zmm, $transfer)
18518  
18519 Get the number of keys in the tree. The number of keys in the tree is stored in the up field of the data block associated with the root. If the lowest bit in this field is set then the field is an offset, if it is clear then it is a count.
18520  
18521 Parameter Description
18522 1 $t Tree descriptor
18523 2 $zmm Zmm number
18524 3 $transfer Transfer register
18525  
18526 =head2 Nasm::X86::Tree::incCountInData($t, $zmm, $transfer)
18527  
18528 Increment the count field in the up field of the data block associate with the root node.
18529  
18530 Parameter Description
18531 1 $t Tree descriptor
18532 2 $zmm Zmm number
18533 3 $transfer Transfer register
18534  
18535 =head2 Nasm::X86::Tree::decCountInData($t, $zmm, $transfer)
18536  
18537 Decrement the count field in the up field of the data block associate with the root node.
18538  
18539 Parameter Description
18540 1 $t Tree descriptor
18541 2 $zmm Zmm number
18542 3 $transfer Transfer register
18543  
18544 =head2 Nasm::X86::Tree::getLoop($t, $zmm, $transfer)
18545  
18546 Return the value of the loop field as a variable.
18547  
18548 Parameter Description
18549 1 $t Tree descriptor
18550 2 $zmm Numbered zmm
18551 3 $transfer Optional transfer register
18552  
18553 =head2 Nasm::X86::Tree::putLoop($t, $value, $zmm, $transfer)
18554  
18555 Set the value of the loop field from a variable.
18556  
18557 Parameter Description
18558 1 $t Tree descriptor
18559 2 $value Variable containing offset of next loop entry
18560 3 $zmm Numbered zmm
18561 4 $transfer Optional transfer register
18562  
18563 =head2 Nasm::X86::Tree::nodeFromData($t, $data, $node)
18564  
18565 Load the the node block into the numbered zmm corresponding to the data block held in the numbered zmm.
18566  
18567 Parameter Description
18568 1 $t Tree descriptor
18569 2 $data Numbered zmm containing data
18570 3 $node Numbered zmm to hold node block
18571  
18572 =head2 Nasm::X86::Tree::address($t)
18573  
18574 Address of the arena containing a tree.
18575  
18576 Parameter Description
18577 1 $t Tree descriptor
18578  
18579 =head2 Nasm::X86::Tree::allocBlock($t, $bs)
18580  
18581 Allocate a block to hold a zmm register in the specified arena and return the offset of the block in a variable.
18582  
18583 Parameter Description
18584 1 $t Tree descriptor
18585 2 $bs Variables
18586  
18587 =head2 Nasm::X86::Tree::testTree($t, $position, $zmm)
18588  
18589 Set the Zero Flag to oppose the tree bit indexed by the specified variable in the numbered zmm register holding the keys of a node to indicate whether the data element indicated by the specified register is an offset to a sub tree in the containing arena or not.
18590  
18591 Parameter Description
18592 1 $t Tree descriptor
18593 2 $position Variable holding index of position to test
18594 3 $zmm Numbered zmm register holding the keys for a node in the tree
18595  
18596 =head2 Nasm::X86::Tree::isTree($t, $register, $zmm)
18597  
18598 Set the Zero Flag to oppose the tree bit in the numbered zmm register holding the keys of a node to indicate whether the data element indicated by the specified register is an offset to a sub tree in the containing arena or not.
18599  
18600 Parameter Description
18601 1 $t Tree descriptor
18602 2 $register Word register holding a bit shifted into the position to test
18603 3 $zmm Numbered zmm register holding the keys for a node in the tree
18604  
18605 =head2 Nasm::X86::Tree::setOrClearTree($t, $set, $register, $zmm)
18606  
18607 Set or clear the tree bit in the numbered zmm register holding the keys of a node to indicate that the data element indicated by the specified register is an offset to a sub tree in the containing arena.
18608  
18609 Parameter Description
18610 1 $t Tree descriptor
18611 2 $set Set if true else clear
18612 3 $register Register holding a single one in the lowest 14 bits at the insertion point
18613 4 $zmm Numbered zmm register holding the keys for a node in the tree
18614  
18615 =head2 Nasm::X86::Tree::setTree($t, $register, $zmm)
18616  
18617 Set the tree bit in the numbered zmm register holding the keys of a node to indicate that the data element indexed by the specified register is an offset to a sub tree in the containing arena.
18618  
18619 Parameter Description
18620 1 $t Tree descriptor
18621 2 $register Register holding data element index 0..13
18622 3 $zmm Numbered zmm register holding the keys for a node in the tree
18623  
18624 =head2 Nasm::X86::Tree::clearTree($t, $register, $zmm)
18625  
18626 Clear the tree bit in the numbered zmm register holding the keys of a node to indicate that the data element indexed by the specified register is an offset to a sub tree in the containing arena.
18627  
18628 Parameter Description
18629 1 $t Tree descriptor
18630 2 $register Register holding data element index 0..13
18631 3 $zmm Numbered zmm register holding the keys for a node in the tree
18632  
18633 =head2 Nasm::X86::Tree::getTreeBits($t, $zmm, $register)
18634  
18635 Load the tree bits from the numbered zmm into the specified register.
18636  
18637 Parameter Description
18638 1 $t Tree descriptor
18639 2 $zmm Numbered zmm
18640 3 $register Target register
18641  
18642 =head2 Nasm::X86::Tree::putTreeBits($t, $zmm, $register)
18643  
18644 Put the tree bits in the specified register into the numbered zmm.
18645  
18646 Parameter Description
18647 1 $t Tree descriptor
18648 2 $zmm Numbered zmm
18649 3 $register Target register
18650  
18651 =head2 Nasm::X86::Tree::expandTreeBitsWithZeroOrOne($t, $onz, $zmm, $point)
18652  
18653 Insert a zero or one into the tree bits field in the numbered zmm at the specified point.
18654  
18655 Parameter Description
18656 1 $t Tree descriptor
18657 2 $onz 0 - zero or 1 - one
18658 3 $zmm Numbered zmm
18659 4 $point Register indicating point
18660  
18661 =head2 Nasm::X86::Tree::expandTreeBitsWithZero($t, $zmm, $point)
18662  
18663 Insert a zero into the tree bits field in the numbered zmm at the specified point.
18664  
18665 Parameter Description
18666 1 $t Tree descriptor
18667 2 $zmm Numbered zmm
18668 3 $point Register indicating point
18669  
18670 =head2 Nasm::X86::Tree::expandTreeBitsWithOne($t, $zmm, $point)
18671  
18672 Insert a one into the tree bits field in the numbered zmm at the specified point.
18673  
18674 Parameter Description
18675 1 $t Tree descriptor
18676 2 $zmm Numbered zmm
18677 3 $point Register indicating point
18678  
18679 =head2 LocateIntelEmulator()
18680  
18681 Locate the Intel Software Development Emulator.
18682  
18683  
18684 =head2 getInstructionCount()
18685  
18686 Get the number of instructions executed from the emulator mix file.
18687  
18688  
18689 =head2 Optimize(%options)
18690  
18691 Perform code optimizations.
18692  
18693 Parameter Description
18694 1 %options Options
18695  
18696 =head2 removeNonAsciiChars($string)
18697  
18698 Return a copy of the specified string with all the non ascii characters removed.
18699  
18700 Parameter Description
18701 1 $string String
18702  
18703 =head2 totalBytesAssembled()
18704  
18705 Total size in bytes of all files assembled during testing.
18706  
18707  
18708  
18709 =head1 Index
18710  
18711  
18712 1 L<All8Structure|/All8Structure> - Create a structure consisting of 8 byte fields.
18713  
18714 2 L<AllocateAll8OnStack|/AllocateAll8OnStack> - Create a local data descriptor consisting of the specified number of 8 byte local variables and return an array: (local data descriptor, variable definitions.
18715  
18716 3 L<AllocateMemory|/AllocateMemory> - Allocate the specified amount of memory via mmap and return its address.
18717  
18718 4 L<AndBlock|/AndBlock> - Short circuit B<and>: execute a block of code to test conditions which, if all of them pass, allows the first block to continue successfully else if one of the conditions fails we execute the optional fail block.
18719  
18720 5 L<Assemble|/Assemble> - Assemble the generated code.
18721  
18722 6 L<CallC|/CallC> - Call a C subroutine.
18723  
18724 7 L<CheckGeneralPurposeRegister|/CheckGeneralPurposeRegister> - Check that a register is in fact a general purpose register.
18725  
18726 8 L<CheckMaskRegister|/CheckMaskRegister> - Check that a register is in fact a mask register.
18727  
18728 9 L<CheckNumberedGeneralPurposeRegister|/CheckNumberedGeneralPurposeRegister> - Check that a register is in fact a numbered general purpose register.
18729  
18730 10 L<ChooseRegisters|/ChooseRegisters> - Choose the specified numbers of registers excluding those on the specified list.
18731  
18732 11 L<ClassifyInRange|/ClassifyInRange> - Character classification: classify the utf32 characters in a block of memory of specified length using a range specification held in zmm0, zmm1 formatted in double words with each word in zmm1 having the classification in the highest 8 bits and with zmm0 and zmm1 having the utf32 character at the start (zmm0) and end (zmm1) of each range in the lower 21 bits.
18733  
18734 12 L<ClassifyRange|/ClassifyRange> - Implementation of ClassifyInRange and ClassifyWithinRange.
18735  
18736 13 L<ClassifyWithInRange|/ClassifyWithInRange> - Bracket classification: Classify the utf32 characters in a block of memory of specified length using a range specification held in zmm0, zmm1 formatted in double words with the classification range in the highest 8 bits of zmm0 and zmm1 and the utf32 character at the start (zmm0) and end (zmm1) of each range in the lower 21 bits.
18737  
18738 14 L<ClassifyWithInRangeAndSaveOffset|/ClassifyWithInRangeAndSaveOffset> - Alphabetic classification: classify the utf32 characters in a block of memory of specified length using a range specification held in zmm0, zmm1 formatted in double words with the classification code in the high byte of zmm1 and the offset of the first element in the range in the high byte of zmm0.
18739  
18740 15 L<ClearMemory|/ClearMemory> - Clear memory.
18741  
18742 16 L<ClearRegisters|/ClearRegisters> - Clear registers by setting them to zero.
18743  
18744 17 L<ClearZF|/ClearZF> - Clear the zero flag.
18745  
18746 18 L<CloseFile|/CloseFile> - Close the file whose descriptor is in rax.
18747  
18748 19 L<Comment|/Comment> - Insert a comment into the assembly code.
18749  
18750 20 L<CommentWithTraceBack|/CommentWithTraceBack> - Insert a comment into the assembly code with a traceback showing how it was generated.
18751  
18752 21 L<ConvertUtf8ToUtf32|/ConvertUtf8ToUtf32> - Convert a string of utf8 to an allocated block of utf32 and return its address and length.
18753  
18754 22 L<CopyMemory|/CopyMemory> - Copy memory, the target is addressed by rax, the length is in rdi, the source is addressed by rsi.
18755  
18756 23 L<cr|/cr> - Call a subroutine with a reordering of the registers.
18757  
18758 24 L<CreateArena|/CreateArena> - Create an relocatable arena and returns its address in rax.
18759  
18760 25 L<CreateShortString|/CreateShortString> - Create a description of a short string.
18761  
18762 26 L<Cstrlen|/Cstrlen> - Length of the C style string addressed by rax returning the length in r15.
18763  
18764 27 L<Db|/Db> - Layout bytes in the data segment and return their label.
18765  
18766 28 L<Dbwdq|/Dbwdq> - Layout data.
18767  
18768 29 L<DComment|/DComment> - Insert a comment into the data segment.
18769  
18770 30 L<Dd|/Dd> - Layout double words in the data segment and return their label.
18771  
18772 31 L<DescribeArena|/DescribeArena> - Describe a relocatable arena.
18773  
18774 32 L<DescribeArray|/DescribeArray> - Describe a dynamic array held in an arena.
18775  
18776 33 L<DescribeQuarks|/DescribeQuarks> - Return a descriptor for a set of quarks.
18777  
18778 34 L<DescribeString|/DescribeString> - Describe a string.
18779  
18780 35 L<DescribeTree|/DescribeTree> - Return a descriptor for a tree with the specified options.
18781  
18782 36 L<Dq|/Dq> - Layout quad words in the data segment and return their label.
18783  
18784 37 L<Ds|/Ds> - Layout bytes in memory and return their label.
18785  
18786 38 L<Dw|/Dw> - Layout words in the data segment and return their label.
18787  
18788 39 L<Ef|/Ef> - Else if block for an If statement.
18789  
18790 40 L<Else|/Else> - Else block for an If statement.
18791  
18792 41 L<executeFileViaBash|/executeFileViaBash> - Execute the file named in the arena addressed by rax with bash.
18793  
18794 42 L<Exit|/Exit> - Exit with the specified return code or zero if no return code supplied.
18795  
18796 43 L<Extern|/Extern> - Name external references.
18797  
18798 44 L<Fail|/Fail> - Fail block for an L<AndBlock>.
18799  
18800 45 L<For|/For> - For - iterate the block as long as register is less than limit incrementing by increment each time.
18801  
18802 46 L<ForEver|/ForEver> - Iterate for ever.
18803  
18804 47 L<ForIn|/ForIn> - For - iterate the full block as long as register plus increment is less than than limit incrementing by increment each time then increment the last block for the last non full block.
18805  
18806 48 L<Fork|/Fork> - Fork.
18807  
18808 49 L<FreeMemory|/FreeMemory> - Free memory.
18809  
18810 50 L<G|/G> - Define a global variable.
18811  
18812 51 L<getBFromXmm|/getBFromXmm> - Get the byte from the numbered xmm register and return it in a variable.
18813  
18814 52 L<getBFromZmm|/getBFromZmm> - Get the byte from the numbered zmm register and return it in a variable.
18815  
18816 53 L<getBwdqFromMm|/getBwdqFromMm> - Get the numbered byte|word|double word|quad word from the numbered zmm register and return it in a variable.
18817  
18818 54 L<getDFromXmm|/getDFromXmm> - Get the double word from the numbered xmm register and return it in a variable.
18819  
18820 55 L<getDFromZmm|/getDFromZmm> - Get the double word from the numbered zmm register and return it in a variable.
18821  
18822 56 L<getInstructionCount|/getInstructionCount> - Get the number of instructions executed from the emulator mix file.
18823  
18824 57 L<GetNextUtf8CharAsUtf32|/GetNextUtf8CharAsUtf32> - Get the next utf8 encoded character from the addressed memory and return it as a utf32 char.
18825  
18826 58 L<GetPid|/GetPid> - Get process identifier.
18827  
18828 59 L<GetPidInHex|/GetPidInHex> - Get process identifier in hex as 8 zero terminated bytes in rax.
18829  
18830 60 L<GetPPid|/GetPPid> - Get parent process identifier.
18831  
18832 61 L<getQFromXmm|/getQFromXmm> - Get the quad word from the numbered xmm register and return it in a variable.
18833  
18834 62 L<getQFromZmm|/getQFromZmm> - Get the quad word from the numbered zmm register and return it in a variable.
18835  
18836 63 L<GetUid|/GetUid> - Get userid of current process.
18837  
18838 64 L<getWFromXmm|/getWFromXmm> - Get the word from the numbered xmm register and return it in a variable.
18839  
18840 65 L<getWFromZmm|/getWFromZmm> - Get the word from the numbered zmm register and return it in a variable.
18841  
18842 66 L<Hash|/Hash> - Hash a string addressed by rax with length held in rdi and return the hash code in r15.
18843  
18844 67 L<hexTranslateTable|/hexTranslateTable> - Create/address a hex translate table and return its label.
18845  
18846 68 L<If|/If> - If.
18847  
18848 69 L<IfC|/IfC> - If the carry flag is set then execute the then block else the else block.
18849  
18850 70 L<IfEq|/IfEq> - If equal execute the then block else the else block.
18851  
18852 71 L<IfGe|/IfGe> - If greater than or equal execute the then block else the else block.
18853  
18854 72 L<IfGt|/IfGt> - If greater than execute the then block else the else block.
18855  
18856 73 L<IfLe|/IfLe> - If less than or equal execute the then block else the else block.
18857  
18858 74 L<IfLt|/IfLt> - If less than execute the then block else the else block.
18859  
18860 75 L<IfNc|/IfNc> - If the carry flag is not set then execute the then block else the else block.
18861  
18862 76 L<IfNe|/IfNe> - If not equal execute the then block else the else block.
18863  
18864 77 L<IfNz|/IfNz> - If the zero flag is not set then execute the then block else the else block.
18865  
18866 78 L<IfZ|/IfZ> - If the zero flag is set then execute the then block else the else block.
18867  
18868 79 L<InsertOneIntoRegisterAtPoint|/InsertOneIntoRegisterAtPoint> - Insert a one into the specified register at the point indicated by another register.
18869  
18870 80 L<InsertZeroIntoRegisterAtPoint|/InsertZeroIntoRegisterAtPoint> - Insert a zero into the specified register at the point indicated by another register.
18871  
18872 81 L<K|/K> - Define a constant variable.
18873  
18874 82 L<Label|/Label> - Create a unique label or reuse the one supplied.
18875  
18876 83 L<Link|/Link> - Libraries to link with.
18877  
18878 84 L<LoadBitsIntoMaskRegister|/LoadBitsIntoMaskRegister> - Load a bit string specification into a mask register.
18879  
18880 85 L<LoadConstantIntoMaskRegister|/LoadConstantIntoMaskRegister> - Set a mask register equal to a constant.
18881  
18882 86 L<loadFromZmm|/loadFromZmm> - Load the specified register from the offset located in the numbered zmm.
18883  
18884 87 L<LoadRegFromMm|/LoadRegFromMm> - Load the specified register from the numbered zmm at the quad offset specified as a constant number.
18885  
18886 88 L<LoadZmm|/LoadZmm> - Load a numbered zmm with the specified bytes.
18887  
18888 89 L<LocalData|/LocalData> - Map local data.
18889  
18890 90 L<LocateIntelEmulator|/LocateIntelEmulator> - Locate the Intel Software Development Emulator.
18891  
18892 91 L<Macro|/Macro> - Create a sub with optional parameters name=> the name of the subroutine so it can be reused rather than regenerated, comment=> a comment describing the sub.
18893  
18894 92 L<MaskMemory22|/MaskMemory22> - Write the specified byte into locations in the target mask that correspond to the locations in the source that contain the specified byte.
18895  
18896 93 L<MaskMemoryInRange4_22|/MaskMemoryInRange4_22> - Write the specified byte into locations in the target mask that correspond to the locations in the source that contain 4 bytes in the specified range.
18897  
18898 94 L<Nasm::X86::Arena::allocate|/Nasm::X86::Arena::allocate> - Allocate the amount of space indicated in rdi in the arena addressed by rax and return the offset of the allocation in the arena in rdi.
18899  
18900 95 L<Nasm::X86::Arena::allocBlock|/Nasm::X86::Arena::allocBlock> - Allocate a block to hold a zmm register in the specified arena and return the offset of the block in a variable.
18901  
18902 96 L<Nasm::X86::Arena::allocZmmBlock|/Nasm::X86::Arena::allocZmmBlock> - Allocate a block to hold a zmm register in the specified arena and return the offset of the block in a variable.
18903  
18904 97 L<Nasm::X86::Arena::append|/Nasm::X86::Arena::append> - Append one arena to another.
18905  
18906 98 L<Nasm::X86::Arena::arenaSize|/Nasm::X86::Arena::arenaSize> - Get the size of an arena.
18907  
18908 99 L<Nasm::X86::Arena::blockSize|/Nasm::X86::Arena::blockSize> - Size of a block.
18909  
18910 100 L<Nasm::X86::Arena::chain|/Nasm::X86::Arena::chain> - Return a variable with the end point of a chain of double words in the arena starting at the specified variable.
18911  
18912 101 L<Nasm::X86::Arena::char|/Nasm::X86::Arena::char> - Append a character expressed as a decimal number to the arena addressed by rax.
18913  
18914 102 L<Nasm::X86::Arena::clear|/Nasm::X86::Arena::clear> - Clear the arena addressed by rax.
18915  
18916 103 L<Nasm::X86::Arena::CreateArray|/Nasm::X86::Arena::CreateArray> - Create a dynamic array held in an arena.
18917  
18918 104 L<Nasm::X86::Arena::CreateQuarks|/Nasm::X86::Arena::CreateQuarks> - Create quarks in a specified arena.
18919  
18920 105 L<Nasm::X86::Arena::CreateString|/Nasm::X86::Arena::CreateString> - Create a string from a doubly link linked list of 64 byte blocks linked via 4 byte offsets in an arena and return its descriptor.
18921  
18922 106 L<Nasm::X86::Arena::CreateTree|/Nasm::X86::Arena::CreateTree> - Create a tree in an arena.
18923  
18924 107 L<Nasm::X86::Arena::DescribeArray|/Nasm::X86::Arena::DescribeArray> - Describe a dynamic array held in an arena.
18925  
18926 108 L<Nasm::X86::Arena::DescribeQuarks|/Nasm::X86::Arena::DescribeQuarks> - Return a descriptor for a tree in the specified arena.
18927  
18928 109 L<Nasm::X86::Arena::DescribeString|/Nasm::X86::Arena::DescribeString> - Describe a string and optionally set its first block .
18929  
18930 110 L<Nasm::X86::Arena::DescribeString22|/Nasm::X86::Arena::DescribeString22> - Describe a string and optionally set its first block.
18931  
18932 111 L<Nasm::X86::Arena::DescribeTree|/Nasm::X86::Arena::DescribeTree> - Return a descriptor for a tree in the specified arena with the specified options.
18933  
18934 112 L<Nasm::X86::Arena::dump|/Nasm::X86::Arena::dump> - Dump details of an arena.
18935  
18936 113 L<Nasm::X86::Arena::firstFreeBlock|/Nasm::X86::Arena::firstFreeBlock> - Create and load a variable with the first free block on the free block chain or zero if no such block in the given arena.
18937  
18938 114 L<Nasm::X86::Arena::freeBlock|/Nasm::X86::Arena::freeBlock> - Free a block in an arena by placing it on the free chain.
18939  
18940 115 L<Nasm::X86::Arena::getBlock|/Nasm::X86::Arena::getBlock> - Get the block with the specified offset in the specified string and return it in the numbered zmm.
18941  
18942 116 L<Nasm::X86::Arena::length|/Nasm::X86::Arena::length> - Get the length of an arena.
18943  
18944 117 L<Nasm::X86::Arena::m|/Nasm::X86::Arena::m> - Append the content with length rdi addressed by rsi to the arena addressed by rax.
18945  
18946 118 L<Nasm::X86::Arena::makeReadOnly|/Nasm::X86::Arena::makeReadOnly> - Make an arena read only.
18947  
18948 119 L<Nasm::X86::Arena::makeWriteable|/Nasm::X86::Arena::makeWriteable> - Make an arena writable.
18949  
18950 120 L<Nasm::X86::Arena::nl|/Nasm::X86::Arena::nl> - Append a new line to the arena addressed by rax.
18951  
18952 121 L<Nasm::X86::Arena::out|/Nasm::X86::Arena::out> - Print the specified arena addressed by rax on sysout.
18953  
18954 122 L<Nasm::X86::Arena::putBlock|/Nasm::X86::Arena::putBlock> - Write the numbered zmm to the block at the specified offset in the specified arena.
18955  
18956 123 L<Nasm::X86::Arena::putChain|/Nasm::X86::Arena::putChain> - Write the double word in the specified variable to the double word location at the the specified offset in the specified arena.
18957  
18958 124 L<Nasm::X86::Arena::q|/Nasm::X86::Arena::q> - Append a constant string to the arena.
18959  
18960 125 L<Nasm::X86::Arena::ql|/Nasm::X86::Arena::ql> - Append a quoted string containing new line characters to the arena addressed by rax.
18961  
18962 126 L<Nasm::X86::Arena::read|/Nasm::X86::Arena::read> - Read the named file (terminated with a zero byte) and place it into the named arena.
18963  
18964 127 L<Nasm::X86::Arena::setFirstFreeBlock|/Nasm::X86::Arena::setFirstFreeBlock> - Set the first free block field from a variable.
18965  
18966 128 L<Nasm::X86::Arena::updateSpace|/Nasm::X86::Arena::updateSpace> - Make sure that the arena addressed by rax has enough space to accommodate content of length rdi.
18967  
18968 129 L<Nasm::X86::Arena::write|/Nasm::X86::Arena::write> - Write the content in an arena addressed by rax to a temporary file and replace the arena content with the name of the temporary file.
18969  
18970 130 L<Nasm::X86::Arena::z|/Nasm::X86::Arena::z> - Append a trailing zero to the arena addressed by rax.
18971  
18972 131 L<Nasm::X86::Array::address|/Nasm::X86::Array::address> - Address of a string.
18973  
18974 132 L<Nasm::X86::Array::allocBlock|/Nasm::X86::Array::allocBlock> - Allocate a block to hold a zmm register in the specified arena and return the offset of the block in a variable.
18975  
18976 133 L<Nasm::X86::Array::dump|/Nasm::X86::Array::dump> - Dump a array.
18977  
18978 134 L<Nasm::X86::Array::get|/Nasm::X86::Array::get> - Get an element from the array.
18979  
18980 135 L<Nasm::X86::Array::pop|/Nasm::X86::Array::pop> - Pop an element from an array.
18981  
18982 136 L<Nasm::X86::Array::push|/Nasm::X86::Array::push> - Push an element onto the array.
18983  
18984 137 L<Nasm::X86::Array::put|/Nasm::X86::Array::put> - Put an element into an array as long as it is with in its limits established by pushing.
18985  
18986 138 L<Nasm::X86::Array::reload|/Nasm::X86::Array::reload> - Reload the specified array description.
18987  
18988 139 L<Nasm::X86::Array::size|/Nasm::X86::Array::size> - Return the size of an array as a variable.
18989  
18990 140 L<Nasm::X86::LocalData::allocate8|/Nasm::X86::LocalData::allocate8> - Add some 8 byte local variables and return an array of variable definitions.
18991  
18992 141 L<Nasm::X86::LocalData::free|/Nasm::X86::LocalData::free> - Free a local data area on the stack.
18993  
18994 142 L<Nasm::X86::LocalData::start|/Nasm::X86::LocalData::start> - Start a local data area on the stack.
18995  
18996 143 L<Nasm::X86::LocalData::variable|/Nasm::X86::LocalData::variable> - Add a local variable.
18997  
18998 144 L<Nasm::X86::LocalVariable::stack|/Nasm::X86::LocalVariable::stack> - Address a local variable on the stack.
18999  
19000 145 L<Nasm::X86::Quarks::call|/Nasm::X86::Quarks::call> - Call a subroutine via its quark number.
19001  
19002 146 L<Nasm::X86::Quarks::dumpSubs|/Nasm::X86::Quarks::dumpSubs> - Dump a set of quarks identifying subroutines.
19003  
19004 147 L<Nasm::X86::Quarks::locateQuarkFromShortString|/Nasm::X86::Quarks::locateQuarkFromShortString> - Locate (if possible) but do not create a quark from a short string.
19005  
19006 148 L<Nasm::X86::Quarks::quarkFromShortString|/Nasm::X86::Quarks::quarkFromShortString> - Create a quark from a short string.
19007  
19008 149 L<Nasm::X86::Quarks::quarkFromSub|/Nasm::X86::Quarks::quarkFromSub> - Create a quark from a subroutine definition.
19009  
19010 150 L<Nasm::X86::Quarks::quarkToQuark|/Nasm::X86::Quarks::quarkToQuark> - Given a variable quark number in one set of quarks find the corresponding quark in another set of quarks and return it in a variable.
19011  
19012 151 L<Nasm::X86::Quarks::reload|/Nasm::X86::Quarks::reload> - Reload the description of a set of quarks.
19013  
19014 152 L<Nasm::X86::Quarks::shortStringFromQuark|/Nasm::X86::Quarks::shortStringFromQuark> - Load a short string from the quark with the specified number.
19015  
19016 153 L<Nasm::X86::Quarks::subFromQuark|/Nasm::X86::Quarks::subFromQuark> - Get the offset of a subroutine as a variable from a set of quarks.
19017  
19018 154 L<Nasm::X86::ShortString::append|/Nasm::X86::ShortString::append> - Append the right hand short string to the left hand short string.
19019  
19020 155 L<Nasm::X86::ShortString::appendByte|/Nasm::X86::ShortString::appendByte> - Append the lowest variable byte to the specified string.
19021  
19022 156 L<Nasm::X86::ShortString::clear|/Nasm::X86::ShortString::clear> - Clear a short string.
19023  
19024 157 L<Nasm::X86::ShortString::len|/Nasm::X86::ShortString::len> - Return the length of a short string in a variable.
19025  
19026 158 L<Nasm::X86::ShortString::load|/Nasm::X86::ShortString::load> - Load the variable addressed data with the variable length into the short string.
19027  
19028 159 L<Nasm::X86::ShortString::loadConstantString|/Nasm::X86::ShortString::loadConstantString> - Load the a short string with a constant string.
19029  
19030 160 L<Nasm::X86::ShortString::loadDwordBytes|/Nasm::X86::ShortString::loadDwordBytes> - Load the specified byte of each dword in the variable addressed data with the variable length into the short string.
19031  
19032 161 L<Nasm::X86::ShortString::setLength|/Nasm::X86::ShortString::setLength> - Set the length of the short string.
19033  
19034 162 L<Nasm::X86::String::address|/Nasm::X86::String::address> - Address of a string.
19035  
19036 163 L<Nasm::X86::String::allocBlock|/Nasm::X86::String::allocBlock> - Allocate a block to hold a zmm register in the specified arena and return the offset of the block in a variable.
19037  
19038 164 L<Nasm::X86::String::append|/Nasm::X86::String::append> - Append the specified content in memory to the specified string.
19039  
19040 165 L<Nasm::X86::String::appendShortString|/Nasm::X86::String::appendShortString> - Append the content of the specified short string.
19041  
19042 166 L<Nasm::X86::String::clear|/Nasm::X86::String::clear> - Clear the block by freeing all but the first block.
19043  
19044 167 L<Nasm::X86::String::concatenate|/Nasm::X86::String::concatenate> - Concatenate two strings by appending a copy of the source to the target string.
19045  
19046 168 L<Nasm::X86::String::deleteChar|/Nasm::X86::String::deleteChar> - Delete a character in a string.
19047  
19048 169 L<Nasm::X86::String::dump|/Nasm::X86::String::dump> - Dump a string to sysout.
19049  
19050 170 L<Nasm::X86::String::getBlock|/Nasm::X86::String::getBlock> - Get the block with the specified offset in the specified string and return it in the numbered zmm.
19051  
19052 171 L<Nasm::X86::String::getBlockLength|/Nasm::X86::String::getBlockLength> - Get the block length of the numbered zmm and return it in a variable.
19053  
19054 172 L<Nasm::X86::String::getCharacter|/Nasm::X86::String::getCharacter> - Get a character from a string.
19055  
19056 173 L<Nasm::X86::String::getNextAndPrevBlockOffsetFromZmm|/Nasm::X86::String::getNextAndPrevBlockOffsetFromZmm> - Get the offsets of the next and previous blocks as variables from the specified zmm.
19057  
19058 174 L<Nasm::X86::String::insertChar|/Nasm::X86::String::insertChar> - Insert a character into a string.
19059  
19060 175 L<Nasm::X86::String::len|/Nasm::X86::String::len> - Find the length of a string.
19061  
19062 176 L<Nasm::X86::String::putBlock|/Nasm::X86::String::putBlock> - Write the numbered zmm to the block at the specified offset in the specified arena.
19063  
19064 177 L<Nasm::X86::String::putNextandPrevBlockOffsetIntoZmm|/Nasm::X86::String::putNextandPrevBlockOffsetIntoZmm> - Save next and prev offsets into a zmm representing a block.
19065  
19066 178 L<Nasm::X86::String::saveToShortString|/Nasm::X86::String::saveToShortString> - Place as much as possible of the specified string into the specified short string.
19067  
19068 179 L<Nasm::X86::String::setBlockLengthInZmm|/Nasm::X86::String::setBlockLengthInZmm> - Set the block length of the numbered zmm to the specified length.
19069  
19070 180 L<Nasm::X86::Structure::field|/Nasm::X86::Structure::field> - Add a field of the specified length with an optional comment.
19071  
19072 181 L<Nasm::X86::StructureField::addr|/Nasm::X86::StructureField::addr> - Address a field in a structure by either the default register or the named register.
19073  
19074 182 L<Nasm::X86::Sub::call|/Nasm::X86::Sub::call> - Call a sub passing it some parameters.
19075  
19076 183 L<Nasm::X86::Sub::callTo|/Nasm::X86::Sub::callTo> - Call a sub passing it some parameters.
19077  
19078 184 L<Nasm::X86::Sub::V|/Nasm::X86::Sub::V> - Put the address of a subroutine into a stack variable so that it can be passed as a parameter.
19079  
19080 185 L<Nasm::X86::Sub::via|/Nasm::X86::Sub::via> - Call a sub by reference passing it some parameters.
19081  
19082 186 L<Nasm::X86::Tree::address|/Nasm::X86::Tree::address> - Address of the arena containing a tree.
19083  
19084 187 L<Nasm::X86::Tree::allocBlock|/Nasm::X86::Tree::allocBlock> - Allocate a block to hold a zmm register in the specified arena and return the offset of the block in a variable.
19085  
19086 188 L<Nasm::X86::Tree::allocKeysDataNode|/Nasm::X86::Tree::allocKeysDataNode> - Allocate a keys/data/node block and place it in the numbered zmm registers.
19087  
19088 189 L<Nasm::X86::Tree::by|/Nasm::X86::Tree::by> - Call the specified block with each (key, data) from the specified tree in order.
19089  
19090 190 L<Nasm::X86::Tree::clearTree|/Nasm::X86::Tree::clearTree> - Clear the tree bit in the numbered zmm register holding the keys of a node to indicate that the data element indexed by the specified register is an offset to a sub tree in the containing arena.
19091  
19092 191 L<Nasm::X86::Tree::decCountInData|/Nasm::X86::Tree::decCountInData> - Decrement the count field in the up field of the data block associate with the root node.
19093  
19094 192 L<Nasm::X86::Tree::depth|/Nasm::X86::Tree::depth> - Return the depth of a node within a tree.
19095  
19096 193 L<Nasm::X86::Tree::dump|/Nasm::X86::Tree::dump> - Dump a tree and all its sub trees.
19097  
19098 194 L<Nasm::X86::Tree::expandTreeBitsWithOne|/Nasm::X86::Tree::expandTreeBitsWithOne> - Insert a one into the tree bits field in the numbered zmm at the specified point.
19099  
19100 195 L<Nasm::X86::Tree::expandTreeBitsWithZero|/Nasm::X86::Tree::expandTreeBitsWithZero> - Insert a zero into the tree bits field in the numbered zmm at the specified point.
19101  
19102 196 L<Nasm::X86::Tree::expandTreeBitsWithZeroOrOne|/Nasm::X86::Tree::expandTreeBitsWithZeroOrOne> - Insert a zero or one into the tree bits field in the numbered zmm at the specified point.
19103  
19104 197 L<Nasm::X86::Tree::find|/Nasm::X86::Tree::find> - Find a key in a tree and test whether the found data is a sub tree.
19105  
19106 198 L<Nasm::X86::Tree::findAndReload|/Nasm::X86::Tree::findAndReload> - Find a key in the specified tree and clone it is it is a sub tree.
19107  
19108 199 L<Nasm::X86::Tree::findAndSplit|/Nasm::X86::Tree::findAndSplit> - Find a key in a tree which is known to contain at least one key splitting full nodes along the path to the key.
19109  
19110 200 L<Nasm::X86::Tree::findShortString|/Nasm::X86::Tree::findShortString> - Find the data at the end of a key chain held in a short string.
19111  
19112 201 L<Nasm::X86::Tree::getCountFromData|/Nasm::X86::Tree::getCountFromData> - Get the number of keys in the tree.
19113  
19114 202 L<Nasm::X86::Tree::getKeysData|/Nasm::X86::Tree::getKeysData> - Load the keys and data blocks for a node.
19115  
19116 203 L<Nasm::X86::Tree::getKeysDataNode|/Nasm::X86::Tree::getKeysDataNode> - Load the keys, data and child nodes for a node.
19117  
19118 204 L<Nasm::X86::Tree::getLengthInKeys|/Nasm::X86::Tree::getLengthInKeys> - Get the length of the keys block in the numbered zmm and return it as a variable.
19119  
19120 205 L<Nasm::X86::Tree::getLoop|/Nasm::X86::Tree::getLoop> - Return the value of the loop field as a variable.
19121  
19122 206 L<Nasm::X86::Tree::getTreeBits|/Nasm::X86::Tree::getTreeBits> - Load the tree bits from the numbered zmm into the specified register.
19123  
19124 207 L<Nasm::X86::Tree::getUpFromData|/Nasm::X86::Tree::getUpFromData> - Get the decompressed up offset from the data block in the numbered zmm and return it as a variable.
19125  
19126 208 L<Nasm::X86::Tree::getUpFromData11|/Nasm::X86::Tree::getUpFromData11> - Get the up offset from the data block in the numbered zmm and return it as a variable.
19127  
19128 209 L<Nasm::X86::Tree::getUpFromDataNM|/Nasm::X86::Tree::getUpFromDataNM> - Get the compressed up offset//count from the data block in the numbered zmm and return it as a variable.
19129  
19130 210 L<Nasm::X86::Tree::incCountInData|/Nasm::X86::Tree::incCountInData> - Increment the count field in the up field of the data block associate with the root node.
19131  
19132 211 L<Nasm::X86::Tree::insert|/Nasm::X86::Tree::insert> - Insert a dword into into the specified tree at the specified key.
19133  
19134 212 L<Nasm::X86::Tree::insertDataOrTree|/Nasm::X86::Tree::insertDataOrTree> - Insert either a key, data pair into the tree or create a sub tree at the specified key (if it does not already exist) and return the offset of the first block of the sub tree in the data variable.
19135  
19136 213 L<Nasm::X86::Tree::insertShortString|/Nasm::X86::Tree::insertShortString> - Insert some data at the end of a chain of sub trees keyed by the contents of a short string.
19137  
19138 214 L<Nasm::X86::Tree::insertTree|/Nasm::X86::Tree::insertTree> - Insert a sub tree into the specified tree tree under the specified key.
19139  
19140 215 L<Nasm::X86::Tree::insertTreeAndReload|/Nasm::X86::Tree::insertTreeAndReload> - Insert a new sub tree into the specified tree tree under the specified key and return a descriptor for it.
19141  
19142 216 L<Nasm::X86::Tree::isTree|/Nasm::X86::Tree::isTree> - Set the Zero Flag to oppose the tree bit in the numbered zmm register holding the keys of a node to indicate whether the data element indicated by the specified register is an offset to a sub tree in the containing arena or not.
19143  
19144 217 L<Nasm::X86::Tree::iterator|/Nasm::X86::Tree::iterator> - Iterate through a multi way tree starting either at the specified node or the first node of the specified tree.
19145  
19146 218 L<Nasm::X86::Tree::Iterator::next|/Nasm::X86::Tree::Iterator::next> - Next element in the tree.
19147  
19148 219 L<Nasm::X86::Tree::leftMost|/Nasm::X86::Tree::leftMost> - Return the offset of the left most node from the specified node.
19149  
19150 220 L<Nasm::X86::Tree::leftOrRightMost|/Nasm::X86::Tree::leftOrRightMost> - Return the offset of the left most or right most node.
19151  
19152 221 L<Nasm::X86::Tree::nodeFromData|/Nasm::X86::Tree::nodeFromData> - Load the the node block into the numbered zmm corresponding to the data block held in the numbered zmm.
19153  
19154 222 L<Nasm::X86::Tree::print|/Nasm::X86::Tree::print> - Print a tree.
19155  
19156 223 L<Nasm::X86::Tree::putKeysData|/Nasm::X86::Tree::putKeysData> - Save the key and data blocks for a node.
19157  
19158 224 L<Nasm::X86::Tree::putKeysDataNode|/Nasm::X86::Tree::putKeysDataNode> - Save the keys, data and child nodes for a node.
19159  
19160 225 L<Nasm::X86::Tree::putLengthInKeys|/Nasm::X86::Tree::putLengthInKeys> - Get the length of the block in the numbered zmm from the specified variable.
19161  
19162 226 L<Nasm::X86::Tree::putLoop|/Nasm::X86::Tree::putLoop> - Set the value of the loop field from a variable.
19163  
19164 227 L<Nasm::X86::Tree::putTreeBits|/Nasm::X86::Tree::putTreeBits> - Put the tree bits in the specified register into the numbered zmm.
19165  
19166 228 L<Nasm::X86::Tree::putUpIntoData|/Nasm::X86::Tree::putUpIntoData> - Put the offset of the parent keys block expressed as a variable into the numbered zmm.
19167  
19168 229 L<Nasm::X86::Tree::putUpIntoData11|/Nasm::X86::Tree::putUpIntoData11> - Put the offset of the parent keys block expressed as a variable into the numbered zmm.
19169  
19170 230 L<Nasm::X86::Tree::reload|/Nasm::X86::Tree::reload> - Reload the specified tree description.
19171  
19172 231 L<Nasm::X86::Tree::reParent|/Nasm::X86::Tree::reParent> - Reparent the children of a node held in registers.
19173  
19174 232 L<Nasm::X86::Tree::rightMost|/Nasm::X86::Tree::rightMost> - Return the offset of the left most node from the specified node.
19175  
19176 233 L<Nasm::X86::Tree::setOrClearTree|/Nasm::X86::Tree::setOrClearTree> - Set or clear the tree bit in the numbered zmm register holding the keys of a node to indicate that the data element indicated by the specified register is an offset to a sub tree in the containing arena.
19177  
19178 234 L<Nasm::X86::Tree::setTree|/Nasm::X86::Tree::setTree> - Set the tree bit in the numbered zmm register holding the keys of a node to indicate that the data element indexed by the specified register is an offset to a sub tree in the containing arena.
19179  
19180 235 L<Nasm::X86::Tree::size|/Nasm::X86::Tree::size> - Return a variable containing the number of keys in the specified tree.
19181  
19182 236 L<Nasm::X86::Tree::splitFullLeftNode|/Nasm::X86::Tree::splitFullLeftNode> - Split a full left node block held in 28.
19183  
19184 237 L<Nasm::X86::Tree::splitFullLeftOrRightNode|/Nasm::X86::Tree::splitFullLeftOrRightNode> - Split a full a full left node (held in 28.
19185  
19186 238 L<Nasm::X86::Tree::splitFullRightNode|/Nasm::X86::Tree::splitFullRightNode> - Split a full right node block held in 25.
19187  
19188 239 L<Nasm::X86::Tree::splitFullRoot|/Nasm::X86::Tree::splitFullRoot> - Split a full root block held in 31.
19189  
19190 240 L<Nasm::X86::Tree::splitNode|/Nasm::X86::Tree::splitNode> - Split a non root node given its offset in an arena retaining the key being inserted in the node being split while putting the remainder to the left or right.
19191  
19192 241 L<Nasm::X86::Tree::testTree|/Nasm::X86::Tree::testTree> - Set the Zero Flag to oppose the tree bit indexed by the specified variable in the numbered zmm register holding the keys of a node to indicate whether the data element indicated by the specified register is an offset to a sub tree in the containing arena or not.
19193  
19194 242 L<Nasm::X86::Tree::transferTreeBitsFromLeft|/Nasm::X86::Tree::transferTreeBitsFromLeft> - Transfer tree bits when splitting a full left node.
19195  
19196 243 L<Nasm::X86::Tree::transferTreeBitsFromLeftOrRight|/Nasm::X86::Tree::transferTreeBitsFromLeftOrRight> - Transfer tree bits when splitting a full left or right node.
19197  
19198 244 L<Nasm::X86::Tree::transferTreeBitsFromParent|/Nasm::X86::Tree::transferTreeBitsFromParent> - Transfer tree bits when splitting a full node.
19199  
19200 245 L<Nasm::X86::Tree::transferTreeBitsFromRight|/Nasm::X86::Tree::transferTreeBitsFromRight> - Transfer tree bits when splitting a full right node.
19201  
19202 246 L<Nasm::X86::Variable::add|/Nasm::X86::Variable::add> - Add the right hand variable to the left hand variable and return the result as a new variable.
19203  
19204 247 L<Nasm::X86::Variable::address|/Nasm::X86::Variable::address> - Get the address of a variable with an optional offset.
19205  
19206 248 L<Nasm::X86::Variable::allocateMemory|/Nasm::X86::Variable::allocateMemory> - Allocate the specified amount of memory via mmap and return its address.
19207  
19208 249 L<Nasm::X86::Variable::and|/Nasm::X86::Variable::and> - And two variables.
19209  
19210 250 L<Nasm::X86::Variable::arithmetic|/Nasm::X86::Variable::arithmetic> - Return a variable containing the result of an arithmetic operation on the left hand and right hand side variables.
19211  
19212 251 L<Nasm::X86::Variable::assign|/Nasm::X86::Variable::assign> - Assign to the left hand side the value of the right hand side.
19213  
19214 252 L<Nasm::X86::Variable::boolean|/Nasm::X86::Variable::boolean> - Combine the left hand variable with the right hand variable via a boolean operator.
19215  
19216 253 L<Nasm::X86::Variable::booleanC|/Nasm::X86::Variable::booleanC> - Combine the left hand variable with the right hand variable via a boolean operator using a conditional move instruction.
19217  
19218 254 L<Nasm::X86::Variable::booleanZF|/Nasm::X86::Variable::booleanZF> - Combine the left hand variable with the right hand variable via a boolean operator and indicate the result by setting the zero flag if the result is true.
19219  
19220 255 L<Nasm::X86::Variable::clearBit|/Nasm::X86::Variable::clearBit> - Clear a bit in the specified mask register retaining the other bits.
19221  
19222 256 L<Nasm::X86::Variable::clearMaskBit|/Nasm::X86::Variable::clearMaskBit> - Clear a bit in the specified mask register retaining the other bits.
19223  
19224 257 L<Nasm::X86::Variable::clearMemory|/Nasm::X86::Variable::clearMemory> - Clear the memory described in this variable.
19225  
19226 258 L<Nasm::X86::Variable::copy|/Nasm::X86::Variable::copy> - Copy one variable into another.
19227  
19228 259 L<Nasm::X86::Variable::copyMemory|/Nasm::X86::Variable::copyMemory> - Copy from one block of memory to another.
19229  
19230 260 L<Nasm::X86::Variable::copyRef|/Nasm::X86::Variable::copyRef> - Copy a reference to a variable.
19231  
19232 261 L<Nasm::X86::Variable::copyZF|/Nasm::X86::Variable::copyZF> - Copy the current state of the zero flag into a variable.
19233  
19234 262 L<Nasm::X86::Variable::copyZFInverted|/Nasm::X86::Variable::copyZFInverted> - Copy the opposite of the current state of the zero flag into a variable.
19235  
19236 263 L<Nasm::X86::Variable::d|/Nasm::X86::Variable::d> - Dump the value of a variable on stderr and append a new line.
19237  
19238 264 L<Nasm::X86::Variable::debug|/Nasm::X86::Variable::debug> - Dump the value of a variable on stdout with an indication of where the dump came from.
19239  
19240 265 L<Nasm::X86::Variable::dec|/Nasm::X86::Variable::dec> - Decrement a variable.
19241  
19242 266 L<Nasm::X86::Variable::divide|/Nasm::X86::Variable::divide> - Divide the left hand variable by the right hand variable and return the result as a new variable.
19243  
19244 267 L<Nasm::X86::Variable::division|/Nasm::X86::Variable::division> - Return a variable containing the result or the remainder that occurs when the left hand side is divided by the right hand side.
19245  
19246 268 L<Nasm::X86::Variable::dump|/Nasm::X86::Variable::dump> - Dump the value of a variable to the specified channel adding an optional title and new line if requested.
19247  
19248 269 L<Nasm::X86::Variable::eq|/Nasm::X86::Variable::eq> - Check whether the left hand variable is equal to the right hand variable.
19249  
19250 270 L<Nasm::X86::Variable::equals|/Nasm::X86::Variable::equals> - Equals operator.
19251  
19252 271 L<Nasm::X86::Variable::err|/Nasm::X86::Variable::err> - Dump the value of a variable on stderr.
19253  
19254 272 L<Nasm::X86::Variable::errNL|/Nasm::X86::Variable::errNL> - Dump the value of a variable on stderr and append a new line.
19255  
19256 273 L<Nasm::X86::Variable::for|/Nasm::X86::Variable::for> - Iterate the block limit times.
19257  
19258 274 L<Nasm::X86::Variable::freeMemory|/Nasm::X86::Variable::freeMemory> - Free the memory addressed by this variable for the specified length.
19259  
19260 275 L<Nasm::X86::Variable::ge|/Nasm::X86::Variable::ge> - Check whether the left hand variable is greater than or equal to the right hand variable.
19261  
19262 276 L<Nasm::X86::Variable::getBFromZmm|/Nasm::X86::Variable::getBFromZmm> - Get the byte from the numbered zmm register and put it in a variable.
19263  
19264 277 L<Nasm::X86::Variable::getConst|/Nasm::X86::Variable::getConst> - Load the variable from a constant in effect setting a variable to a specified value.
19265  
19266 278 L<Nasm::X86::Variable::getConst22|/Nasm::X86::Variable::getConst22> - Load the variable from a constant in effect setting a variable to a specified value.
19267  
19268 279 L<Nasm::X86::Variable::getDFromZmm|/Nasm::X86::Variable::getDFromZmm> - Get the double word from the numbered zmm register and put it in a variable.
19269  
19270 280 L<Nasm::X86::Variable::getQFromZmm|/Nasm::X86::Variable::getQFromZmm> - Get the quad word from the numbered zmm register and put it in a variable.
19271  
19272 281 L<Nasm::X86::Variable::getReg|/Nasm::X86::Variable::getReg> - Load the variable from the named registers.
19273  
19274 282 L<Nasm::X86::Variable::getWFromZmm|/Nasm::X86::Variable::getWFromZmm> - Get the word from the numbered zmm register and put it in a variable.
19275  
19276 283 L<Nasm::X86::Variable::gt|/Nasm::X86::Variable::gt> - Check whether the left hand variable is greater than the right hand variable.
19277  
19278 284 L<Nasm::X86::Variable::inc|/Nasm::X86::Variable::inc> - Increment a variable.
19279  
19280 285 L<Nasm::X86::Variable::incDec|/Nasm::X86::Variable::incDec> - Increment or decrement a variable.
19281  
19282 286 L<Nasm::X86::Variable::isRef|/Nasm::X86::Variable::isRef> - Check whether the specified variable is a reference to another variable.
19283  
19284 287 L<Nasm::X86::Variable::le|/Nasm::X86::Variable::le> - Check whether the left hand variable is less than or equal to the right hand variable.
19285  
19286 288 L<Nasm::X86::Variable::loadZmm|/Nasm::X86::Variable::loadZmm> - Load bytes from the memory addressed by the specified source variable into the numbered zmm register.
19287  
19288 289 L<Nasm::X86::Variable::lt|/Nasm::X86::Variable::lt> - Check whether the left hand variable is less than the right hand variable.
19289  
19290 290 L<Nasm::X86::Variable::max|/Nasm::X86::Variable::max> - Maximum of two variables.
19291  
19292 291 L<Nasm::X86::Variable::min|/Nasm::X86::Variable::min> - Minimum of two variables.
19293  
19294 292 L<Nasm::X86::Variable::minusAssign|/Nasm::X86::Variable::minusAssign> - Implement minus and assign.
19295  
19296 293 L<Nasm::X86::Variable::mod|/Nasm::X86::Variable::mod> - Divide the left hand variable by the right hand variable and return the remainder as a new variable.
19297  
19298 294 L<Nasm::X86::Variable::ne|/Nasm::X86::Variable::ne> - Check whether the left hand variable is not equal to the right hand variable.
19299  
19300 295 L<Nasm::X86::Variable::or|/Nasm::X86::Variable::or> - Or two variables.
19301  
19302 296 L<Nasm::X86::Variable::out|/Nasm::X86::Variable::out> - Dump the value of a variable on stdout.
19303  
19304 297 L<Nasm::X86::Variable::outNL|/Nasm::X86::Variable::outNL> - Dump the value of a variable on stdout and append a new line.
19305  
19306 298 L<Nasm::X86::Variable::plusAssign|/Nasm::X86::Variable::plusAssign> - Implement plus and assign.
19307  
19308 299 L<Nasm::X86::Variable::pop|/Nasm::X86::Variable::pop> - Pop a variable from the stack.
19309  
19310 300 L<Nasm::X86::Variable::printErrMemoryInHexNL|/Nasm::X86::Variable::printErrMemoryInHexNL> - Write the memory addressed by a variable to stderr.
19311  
19312 301 L<Nasm::X86::Variable::printMemoryInHexNL|/Nasm::X86::Variable::printMemoryInHexNL> - Write, in hexadecimal, the memory addressed by a variable to stdout or stderr.
19313  
19314 302 L<Nasm::X86::Variable::printOutMemoryInHexNL|/Nasm::X86::Variable::printOutMemoryInHexNL> - Write the memory addressed by a variable to stdout.
19315  
19316 303 L<Nasm::X86::Variable::printOutZeroString|/Nasm::X86::Variable::printOutZeroString> - Print the variable addressed zero terminated string on stdout.
19317  
19318 304 L<Nasm::X86::Variable::push|/Nasm::X86::Variable::push> - Push a variable onto the stack.
19319  
19320 305 L<Nasm::X86::Variable::putBIntoXmm|/Nasm::X86::Variable::putBIntoXmm> - Place the value of the content variable at the byte in the numbered xmm register.
19321  
19322 306 L<Nasm::X86::Variable::putBIntoZmm|/Nasm::X86::Variable::putBIntoZmm> - Place the value of the content variable at the byte in the numbered zmm register.
19323  
19324 307 L<Nasm::X86::Variable::putBwdqIntoMm|/Nasm::X86::Variable::putBwdqIntoMm> - Place the value of the content variable at the byte|word|double word|quad word in the numbered zmm register.
19325  
19326 308 L<Nasm::X86::Variable::putDIntoXmm|/Nasm::X86::Variable::putDIntoXmm> - Place the value of the content variable at the double word in the numbered xmm register.
19327  
19328 309 L<Nasm::X86::Variable::putDIntoZmm|/Nasm::X86::Variable::putDIntoZmm> - Place the value of the content variable at the double word in the numbered zmm register.
19329  
19330 310 L<Nasm::X86::Variable::putQIntoXmm|/Nasm::X86::Variable::putQIntoXmm> - Place the value of the content variable at the quad word in the numbered xmm register.
19331  
19332 311 L<Nasm::X86::Variable::putQIntoZmm|/Nasm::X86::Variable::putQIntoZmm> - Place the value of the content variable at the quad word in the numbered zmm register.
19333  
19334 312 L<Nasm::X86::Variable::putWIntoXmm|/Nasm::X86::Variable::putWIntoXmm> - Place the value of the content variable at the word in the numbered xmm register.
19335  
19336 313 L<Nasm::X86::Variable::putWIntoZmm|/Nasm::X86::Variable::putWIntoZmm> - Place the value of the content variable at the word in the numbered zmm register.
19337  
19338 314 L<Nasm::X86::Variable::setBit|/Nasm::X86::Variable::setBit> - Set a bit in the specified register retaining the other bits.
19339  
19340 315 L<Nasm::X86::Variable::setMask|/Nasm::X86::Variable::setMask> - Set the mask register to ones starting at the specified position for the specified length and zeroes elsewhere.
19341  
19342 316 L<Nasm::X86::Variable::setMaskBit|/Nasm::X86::Variable::setMaskBit> - Set a bit in the specified mask register retaining the other bits.
19343  
19344 317 L<Nasm::X86::Variable::setMaskFirst|/Nasm::X86::Variable::setMaskFirst> - Set the first bits in the specified mask register.
19345  
19346 318 L<Nasm::X86::Variable::setReg|/Nasm::X86::Variable::setReg> - Set the named registers from the content of the variable.
19347  
19348 319 L<Nasm::X86::Variable::setZmm|/Nasm::X86::Variable::setZmm> - Load bytes from the memory addressed by specified source variable into the numbered zmm register at the offset in the specified offset moving the number of bytes in the specified variable.
19349  
19350 320 L<Nasm::X86::Variable::str|/Nasm::X86::Variable::str> - The name of the variable.
19351  
19352 321 L<Nasm::X86::Variable::sub|/Nasm::X86::Variable::sub> - Subtract the right hand variable from the left hand variable and return the result as a new variable.
19353  
19354 322 L<Nasm::X86::Variable::times|/Nasm::X86::Variable::times> - Multiply the left hand variable by the right hand variable and return the result as a new variable.
19355  
19356 323 L<Nasm::X86::Variable::zBroadCastD|/Nasm::X86::Variable::zBroadCastD> - Broadcast a double word in a variable into the numbered zmm.
19357  
19358 324 L<OnSegv|/OnSegv> - Request a trace back followed by exit on a B<segv> signal.
19359  
19360 325 L<OpenRead|/OpenRead> - Open a file, whose name is addressed by rax, for read and return the file descriptor in rax.
19361  
19362 326 L<OpenWrite|/OpenWrite> - Create the file named by the terminated string addressed by rax for write.
19363  
19364 327 L<Optimize|/Optimize> - Perform code optimizations.
19365  
19366 328 L<OrBlock|/OrBlock> - Short circuit B<or>: execute a block of code to test conditions which, if one of them is met, leads on to the execution of the pass block, if all of the tests fail we continue withe the test block.
19367  
19368 329 L<Pass|/Pass> - Pass block for an L<OrBlock>.
19369  
19370 330 L<PeekR|/PeekR> - Peek at register on stack.
19371  
19372 331 L<PopEax|/PopEax> - We cannot pop a double word from the stack in 64 bit long mode using pop so we improvise.
19373  
19374 332 L<PopMask|/PopMask> - Pop Mask registers.
19375  
19376 333 L<PopR|/PopR> - Pop registers from the stack.
19377  
19378 334 L<PopRR|/PopRR> - Pop registers from the stack without tracking.
19379  
19380 335 L<PopZmm|/PopZmm> - Pop zmm registers.
19381  
19382 336 L<PrintErrMemory|/PrintErrMemory> - Print the memory addressed by rax for a length of rdi on stderr.
19383  
19384 337 L<PrintErrMemoryInHex|/PrintErrMemoryInHex> - Dump memory from the address in rax for the length in rdi on stderr.
19385  
19386 338 L<PrintErrMemoryInHexNL|/PrintErrMemoryInHexNL> - Dump memory from the address in rax for the length in rdi and then print a new line.
19387  
19388 339 L<PrintErrMemoryNL|/PrintErrMemoryNL> - Print the memory addressed by rax for a length of rdi followed by a new line on stderr.
19389  
19390 340 L<PrintErrNL|/PrintErrNL> - Print a new line to stderr.
19391  
19392 341 L<PrintErrRaxInHex|/PrintErrRaxInHex> - Write the content of register rax in hexadecimal in big endian notation to stderr.
19393  
19394 342 L<PrintErrRegisterInHex|/PrintErrRegisterInHex> - Print the named registers as hex strings on stderr.
19395  
19396 343 L<PrintErrSpace|/PrintErrSpace> - Print one or more spaces to stderr.
19397  
19398 344 L<PrintErrString|/PrintErrString> - Print a constant string to stderr.
19399  
19400 345 L<PrintErrStringNL|/PrintErrStringNL> - Print a constant string followed by a new line to stderr.
19401  
19402 346 L<PrintErrTraceBack|/PrintErrTraceBack> - Print sub routine track back on stderr.
19403  
19404 347 L<PrintErrUtf32|/PrintErrUtf32> - Print the utf 8 character addressed by rax to stderr.
19405  
19406 348 L<PrintErrUtf8Char|/PrintErrUtf8Char> - Print the utf 8 character addressed by rax to stderr.
19407  
19408 349 L<PrintErrZF|/PrintErrZF> - Print the zero flag without disturbing it on stderr.
19409  
19410 350 L<PrintMemory|/PrintMemory> - Print the memory addressed by rax for a length of rdi on the specified channel.
19411  
19412 351 L<PrintMemoryInHex|/PrintMemoryInHex> - Dump memory from the address in rax for the length in rdi on the specified channel.
19413  
19414 352 L<PrintMemoryNL|/PrintMemoryNL> - Print the memory addressed by rax for a length of rdi on the specified channel followed by a new line.
19415  
19416 353 L<PrintNL|/PrintNL> - Print a new line to stdout or stderr.
19417  
19418 354 L<PrintOneRegisterInHex|/PrintOneRegisterInHex> - Print the named register as a hex strings.
19419  
19420 355 L<PrintOutMemory|/PrintOutMemory> - Print the memory addressed by rax for a length of rdi on stdout.
19421  
19422 356 L<PrintOutMemoryInHex|/PrintOutMemoryInHex> - Dump memory from the address in rax for the length in rdi on stdout.
19423  
19424 357 L<PrintOutMemoryInHexNL|/PrintOutMemoryInHexNL> - Dump memory from the address in rax for the length in rdi and then print a new line.
19425  
19426 358 L<PrintOutMemoryNL|/PrintOutMemoryNL> - Print the memory addressed by rax for a length of rdi followed by a new line on stdout.
19427  
19428 359 L<PrintOutNL|/PrintOutNL> - Print a new line to stderr.
19429  
19430 360 L<PrintOutRaxInHex|/PrintOutRaxInHex> - Write the content of register rax in hexadecimal in big endian notation to stderr.
19431  
19432 361 L<PrintOutRaxInReverseInHex|/PrintOutRaxInReverseInHex> - Write the content of register rax to stderr in hexadecimal in little endian notation.
19433  
19434 362 L<PrintOutRegisterInHex|/PrintOutRegisterInHex> - Print the named registers as hex strings on stdout.
19435  
19436 363 L<PrintOutRegistersInHex|/PrintOutRegistersInHex> - Print the general purpose registers in hex.
19437  
19438 364 L<PrintOutRflagsInHex|/PrintOutRflagsInHex> - Print the flags register in hex.
19439  
19440 365 L<PrintOutRipInHex|/PrintOutRipInHex> - Print the instruction pointer in hex.
19441  
19442 366 L<PrintOutSpace|/PrintOutSpace> - Print one or more spaces to stdout.
19443  
19444 367 L<PrintOutString|/PrintOutString> - Print a constant string to stdout.
19445  
19446 368 L<PrintOutStringNL|/PrintOutStringNL> - Print a constant string followed by a new line to stdout.
19447  
19448 369 L<PrintOutTraceBack|/PrintOutTraceBack> - Print sub routine track back on stdout.
19449  
19450 370 L<PrintOutUtf32|/PrintOutUtf32> - Print the utf 8 character addressed by rax to stdout.
19451  
19452 371 L<PrintOutUtf8Char|/PrintOutUtf8Char> - Print the utf 8 character addressed by rax to stdout.
19453  
19454 372 L<PrintOutZF|/PrintOutZF> - Print the zero flag without disturbing it on stdout.
19455  
19456 373 L<PrintRaxInHex|/PrintRaxInHex> - Write the content of register rax in hexadecimal in big endian notation to the specified channel.
19457  
19458 374 L<PrintRegisterInHex|/PrintRegisterInHex> - Print the named registers as hex strings.
19459  
19460 375 L<PrintSpace|/PrintSpace> - Print one or more spaces to the specified channel.
19461  
19462 376 L<PrintString|/PrintString> - Print a constant string to the specified channel.
19463  
19464 377 L<PrintStringNL|/PrintStringNL> - Print a constant string to the specified channel followed by a new line.
19465  
19466 378 L<PrintTraceBack|/PrintTraceBack> - Trace the call stack.
19467  
19468 379 L<PrintUtf32|/PrintUtf32> - Print the specified number of utf32 characters at the specified address to the specified channel.
19469  
19470 380 L<PrintUtf8Char|/PrintUtf8Char> - Print the utf 8 character addressed by rax to the specified channel.
19471  
19472 381 L<PushMask|/PushMask> - Push several Mask registers.
19473  
19474 382 L<PushR|/PushR> - Push registers onto the stack.
19475  
19476 383 L<PushRR|/PushRR> - Push registers onto the stack without tracking.
19477  
19478 384 L<PushZmm|/PushZmm> - Push several zmm registers.
19479  
19480 385 L<putIntoZmm|/putIntoZmm> - Put the specified register into the numbered zmm at the specified offset in the zmm.
19481  
19482 386 L<R|/R> - Define a reference variable.
19483  
19484 387 L<Rb|/Rb> - Layout bytes in the data segment and return their label.
19485  
19486 388 L<Rbwdq|/Rbwdq> - Layout data.
19487  
19488 389 L<RComment|/RComment> - Insert a comment into the read only data segment.
19489  
19490 390 L<Rd|/Rd> - Layout double words in the data segment and return their label.
19491  
19492 391 L<ReadFile|/ReadFile> - Read a file whose name is addressed by rax into memory.
19493  
19494 392 L<ReadTimeStampCounter|/ReadTimeStampCounter> - Read the time stamp counter and return the time in nanoseconds in rax.
19495  
19496 393 L<RegistersAvailable|/RegistersAvailable> - Add a new set of registers that are available.
19497  
19498 394 L<RegistersFree|/RegistersFree> - Remove the current set of registers known to be free.
19499  
19500 395 L<RegisterSize|/RegisterSize> - Return the size of a register.
19501  
19502 396 L<removeNonAsciiChars|/removeNonAsciiChars> - Return a copy of the specified string with all the non ascii characters removed.
19503  
19504 397 L<ReorderSyscallRegisters|/ReorderSyscallRegisters> - Map the list of registers provided to the 64 bit system call sequence.
19505  
19506 398 L<RestoreFirstFour|/RestoreFirstFour> - Restore the first 4 parameter registers.
19507  
19508 399 L<RestoreFirstFourExceptRax|/RestoreFirstFourExceptRax> - Restore the first 4 parameter registers except rax so it can return its value.
19509  
19510 400 L<RestoreFirstFourExceptRaxAndRdi|/RestoreFirstFourExceptRaxAndRdi> - Restore the first 4 parameter registers except rax and rdi so we can return a pair of values.
19511  
19512 401 L<RestoreFirstSeven|/RestoreFirstSeven> - Restore the first 7 parameter registers.
19513  
19514 402 L<RestoreFirstSevenExceptRax|/RestoreFirstSevenExceptRax> - Restore the first 7 parameter registers except rax which is being used to return the result.
19515  
19516 403 L<RestoreFirstSevenExceptRaxAndRdi|/RestoreFirstSevenExceptRaxAndRdi> - Restore the first 7 parameter registers except rax and rdi which are being used to return the results.
19517  
19518 404 L<Rq|/Rq> - Layout quad words in the data segment and return their label.
19519  
19520 405 L<Rs|/Rs> - Layout bytes in read only memory and return their label.
19521  
19522 406 L<Rutf8|/Rutf8> - Layout a utf8 encoded string as bytes in read only memory and return their label.
19523  
19524 407 L<Rw|/Rw> - Layout words in the data segment and return their label.
19525  
19526 408 L<SaveFirstFour|/SaveFirstFour> - Save the first 4 parameter registers making any parameter registers read only.
19527  
19528 409 L<SaveFirstSeven|/SaveFirstSeven> - Save the first 7 parameter registers.
19529  
19530 410 L<SaveRegIntoMm|/SaveRegIntoMm> - Save the specified register into the numbered zmm at the quad offset specified as a constant number.
19531  
19532 411 L<SetLabel|/SetLabel> - Create (if necessary) and set a label in the code section returning the label so set.
19533  
19534 412 L<SetMaskRegister|/SetMaskRegister> - Set the mask register to ones starting at the specified position for the specified length and zeroes elsewhere.
19535  
19536 413 L<SetZF|/SetZF> - Set the zero flag.
19537  
19538 414 L<Start|/Start> - Initialize the assembler.
19539  
19540 415 L<StatSize|/StatSize> - Stat a file whose name is addressed by rax to get its size in rax.
19541  
19542 416 L<StringLength|/StringLength> - Length of a zero terminated string.
19543  
19544 417 L<Structure|/Structure> - Create a structure addressed by a register.
19545  
19546 418 L<Subroutine|/Subroutine> - Create a subroutine that can be called in assembler code.
19547  
19548 419 L<SubroutineStartStack|/SubroutineStartStack> - Initialize a new stack frame.
19549  
19550 420 L<Then|/Then> - Then block for an If statement.
19551  
19552 421 L<totalBytesAssembled|/totalBytesAssembled> - Total size in bytes of all files assembled during testing.
19553  
19554 422 L<unlinkFile|/unlinkFile> - Unlink the named file.
19555  
19556 423 L<UnReorderSyscallRegisters|/UnReorderSyscallRegisters> - Recover the initial values in registers that were reordered.
19557  
19558 424 L<V|/V> - Define a variable.
19559  
19560 425 L<Variable|/Variable> - Create a new variable with the specified name initialized via an optional expression.
19561  
19562 426 L<WaitPid|/WaitPid> - Wait for the pid in rax to complete.
19563  
19564 427 L<xmm|/xmm> - Add xmm to the front of a list of register expressions.
19565  
19566 428 L<ymm|/ymm> - Add ymm to the front of a list of register expressions.
19567  
19568 429 L<zmm|/zmm> - Add zmm to the front of a list of register expressions.
19569  
19570 =head1 Installation
19571  
19572 This module is written in 100% Pure Perl and, thus, it is easy to read,
19573 comprehend, use, modify and install via B<cpan>:
19574  
19575 sudo cpan install Nasm::X86
19576  
19577 =head1 Author
19578  
19579 L<philiprbrenan@gmail.com|mailto:philiprbrenan@gmail.com>
19580  
19581 L<http://www.appaapps.com|http://www.appaapps.com>
19582  
19583 =head1 Copyright
19584  
19585 Copyright (c) 2016-2021 Philip R Brenan.
19586  
19587 This module is free software. It may be used, redistributed and/or modified
19588 under the same terms as Perl itself.
19589  
19590 =cut
19591  
19592  
19593  
19594 # Tests and documentation
19595  
19596 sub test
19597 1 ▶ {my $p = __PACKAGE__;
Subroutine test: called CC=5 SCAR=17.4
Pod undocumented
19598 1 binmode($_, ":utf8") for *STDOUT, *STDERR;
19599 1 ▶ return if eval "eof(${p}::DATA)";
Branch: 1 branch
BranchTrueFalseTotal
if eval "eof(${p}::DATA)" 0 1 1
19600 1 my $s = eval "join('', <${p}::DATA>)";
19601 1 ▶ $@ and die $@;
Branch: 1 branch
BranchTrueFalseTotal
$@ and die $@ 0 1 1
19602 1 ▶ eval $s;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
19603 0 ▶ $@ and die $@;
Branch: 1 branch
BranchTrueFalseTotal
$@ and die $@ 0 0 0
19604 0 1
19605 }
19606  
19607 1 ▶test unless caller;
Branch: 1 branch
BranchTrueFalseTotal
unless caller 0 1 1
19608  
19609 1 1;
19610 # podDocumentation
19611 __DATA__
↑ Summary Build »