blib/lib/Nasm/X86.pm

filter: Statementstmt 3.1% 201 / 6339 Branchbran 0.7% 11 / 1572 Conditioncond 0.0% 0 / 340 MC/DCmcdc 0.0% 0 / 211 Subroutinesub 1.1% 16 / 1417 Podpod 23.0% 202 / 877 totaltotal 4.0% 430 / 10756 CC 975 SCAR 42.1
CC
975
Cov
3%
Assemble
1980.0
BEGIN
831.5
getBwdqFromMm
506.0
CRAP 67.3
↑ 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? elif ? switch statement? confess? Number of parameters test? Remove macro? Extend short strings.
11 # M: v->copy now allows constant numbers so remove K(xxx, number)
12 package Nasm::X86;
13 1 our $VERSION = "20210910";
14 1 ▶use warnings FATAL => qw(all);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Carp qw(confess cluck);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Data::Dump qw(dump);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use Data::Table::Text qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use Asm::C qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use feature qw(say current_sub);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 1 makeDieConfess;
24  
25 1 my %rodata; # Read only data already written
26 my %rodatas; # Read only string already written
27 1 my %subroutines; # Subroutines generated
28 1 my @rodata; # Read only data
29 1 my @data; # Data
30 1 my @bss; # Block started by symbol
31 1 my @text; # Code
32 1 my @extern; # External symbols imports for linking with C libraries
33 1 my @link; # Specify libraries which to link against in the final assembly stage
34 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.
35 1 my $develop = -e q(/home/phil/); # Developing
36 1 my $sdeMixOut = q(sde-mix-out.txt); # Emulator output file
37  
38 1 our $stdin = 0; # File descriptor for standard input
39 1 our $stdout = 1; # File descriptor for standard output
40 1 our $stderr = 2; # File descriptor for standard error
41  
42 1 my %Registers; # The names of all the registers
43 my %RegisterContaining; # The largest register containing a register
44 1 my @GeneralPurposeRegisters = (qw(rax rbx rcx rdx rsi rdi), map {"r$_"} 8..15); # General purpose registers
45 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.
46  
47 BEGIN{
48 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
49 1 %r = (%r, map {$_=>[16, 's' ]} qw(cs ds es fs gs ss));
50 1 %r = (%r, map {$_=>[16, '16' ]} qw(ax bx cx dx r8w r9w r10w r11w r12w r13w r14w r15w si di sp bp));
51 1 %r = (%r, map {$_=>[32, '32a']} qw(eax ebx ecx edx esi edi esp ebp));
52 1 %r = (%r, map {$_=>[32, '32b']} qw(r8d r9d r10d r11d r12d r13d r14d r15d));
53 1 %r = (%r, map {$_=>[80, 'f' ]} qw(st0 st1 st2 st3 st4 st5 st6 st7));
54 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));
55 1 %r = (%r, map {$_=>[64, '64m']} qw(mm0 mm1 mm2 mm3 mm4 mm5 mm6 mm7));
56 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));
57 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));
58 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));
59 1 %r = (%r, map {$_=>[64, 'm' ]} qw(k0 k1 k2 k3 k4 k5 k6 k7));
60  
61 1 %Registers = %r; # Register names
62  
63 my sub registerContaining($@)
64 56 ▶ {my ($r, @r) = @_; # Register, contents
Subroutine registerContaining: called CC=2 SCAR=6.9
65 56 $RegisterContaining{$r} = $r; # A register contains itself
66 56 $RegisterContaining{$_} = $r for @r; # Registers contained by a register
67 }
68  
69 1 registerContaining("k$_") for 0..7;
70 1 registerContaining("zmm$_", "ymm$_", "xmm$_") for 0..31;
71 1 registerContaining("r${_}x", "e${_}x", "${_}x", "${_}l", "${_}h") for qw(a b c d);
72 1 registerContaining("r${_}", "r${_}l", "r${_}w", "r${_}b", "r${_}d") for 8..15;
73 1 registerContaining("r${_}p", "e${_}p", "${_}p", "${_}pl") for qw(s b);
74 1 registerContaining("r${_}i", "e${_}i", "${_}i", "${_}il") for qw(s d);
75 1 my @i0 = qw(cpuid lahf leave popfq pushfq rdtsc ret syscall); # Zero operand instructions
76  
77 1 my @i1 = split /\s+/, <<END; # Single operand instructions
78 bswap call dec idiv inc jmp ja jae jb jbe jc jcxz je jecxz jg jge jl jle
79 jna jnae jnb jnbe jnc jne jng jnge jnl jnle jno jnp jns jnz jo jp jpe jpo jrcxz
80 js jz loop neg not seta setae setb setbe setc sete setg setge setl setle setna setnae
81 setnb setnbe setnc setne setng setnge setnl setno setnp setns setnz seto setp
82 setpe setpo sets setz pop push
83 END
84  
85 1 my @i2 = split /\s+/, <<END; # Double operand instructions
86 add and bt btc btr bts
87 cmova cmovae cmovb cmovbe cmovc cmove cmovg cmovge cmovl cmovle
88 cmovna cmovnae cmovnb cmp
89 enter
90 imul
91 kmov knot kortest ktest lea lzcnt mov movdqa
92 or popcnt shl shr sub test tzcnt
93 vcvtudq2pd vcvtuqq2pd vcvtudq2ps vmovdqu vmovdqu32 vmovdqu64 vmovdqu8
94 vpcompressd vpcompressq vpexpandd vpexpandq xchg xor
95 vmovd vmovq
96 mulpd
97 pslldq psrldq
98 vsqrtpd
99 vmovdqa32 vmovdqa64
100 END
101 # print STDERR join ' ', sort @i2; exit;
102  
103 1 my @i2qdwb = split /\s+/, <<END; # Double operand instructions which have qdwb versions
104 vpbroadcast
105 END
106  
107 1 my @i3 = split /\s+/, <<END; # Triple operand instructions
108 andn
109 bzhi
110 kadd kand kandn kor kshiftl kshiftr kunpck kxnor kxor
111  
112 vdpps
113 vprolq
114 vgetmantps
115 vaddd
116 vmulpd vaddpd
117 END
118  
119 1 my @i3qdwb = split /\s+/, <<END; # Triple operand instructions which have qdwb versions
120 pinsr pextr vpand vpandn vpcmpeq vpor vpxor vptest vporvpcmpeq vpinsr vpextr vpadd vpsub vpmull
121 END
122  
123 1 my @i4 = split /\s+/, <<END; # Quadruple operand instructions
124 END
125  
126 1 my @i4qdwb = split /\s+/, <<END; # Quadruple operand instructions which have qdwb versions
127 vpcmpu
128 END
129  
130 1 if (1) # Add variants to mask instructions
131 1 {my @k2 = grep {m/\Ak/} @i2; @i2 = grep {!m/\Ak/} @i2;
132 1 my @k3 = grep {m/\Ak/} @i3; @i3 = grep {!m/\Ak/} @i3;
133 1 for my $s(qw(b w d q))
134 4 {push @i2, $_.$s for grep {m/\Ak/} @k2;
135 4 push @i3, $_.$s for grep {m/\Ak/} @k3;
136 }
137 }
138  
139 1 if (1) # Add qdwb versions of instructions
140 1 {for my $o(@i2qdwb)
141 1 {push @i2, $o.$_ for qw(b w d q);
142 }
143 1 for my $o(@i3qdwb)
144 14 {push @i3, $o.$_ for qw(b w d q);
145 }
146 1 for my $o(@i4qdwb)
147 1 {push @i4, $o.$_ for qw(b w d q);
148 }
149 }
150  
151 1 for my $r(sort keys %r) # Create register definitions
152 204 {if (1)
153 204 {my $s = "sub $r\{q($r)\}";
154 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
155 204 ▶ confess "$s$@ "if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 204 204
156 }
157 204 if (1)
158 204 {my $b = $r{$r}[0] / 8;
159 204 my $s = "sub ${r}Size\{$b}";
160 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
161 204 ▶ confess "$s$@ "if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 204 204
162 }
163 }
164  
165 1 my %v = map {$$_[1]=>1} values %r;
166 1 for my $v(sort keys %v) # Types of register
167 12 {my @r = grep {$r{$_}[1] eq $v} sort keys %r;
168 12 my $s = "sub registers_$v\{".dump(\@r)."}";
169 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
170 12 ▶ confess "$s$@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 12 12
171 }
172  
173 1 if (1) # Instructions that take zero operands
174 1 {my $s = '';
175 1 for my $i(@i0)
176 8 {my $I = ucfirst $i;
177 8 $s .= <<END;
178 sub $I()
179 {\@_ == 0 or confess "No arguments allowed";
180 my \$s = ' ' x scalar(my \@d = caller);
181 push \@text, qq(\${s}$i\\n);
182 }
183 END
184 }
185 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
186 1 ▶ confess "$s$@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 1 1
187 }
188  
189 1 if (1) # Instructions that take one operand
190 1 {my $s = '';
191 1 for my $i(@i1)
192 73 {my $I = ucfirst $i;
193 73 $s .= <<END;
194 sub $I(\$)
195 {my (\$target) = \@_;
196 \@_ == 1 or confess "One argument required";
197 my \$s = ' ' x scalar(my \@d = caller);
198 push \@text, qq(\${s}$i \$target\\n);
199 }
200 END
201 }
202 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
203 1 ▶ confess "$s$@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 1 1
204 }
205  
206 1 if (1) # Instructions that take two operands
207 1 {my $s = '';
208 1 for my $i(@i2)
209 74 {my $I = ucfirst $i;
210 74 $s .= <<END;
211 sub $I(\$\$)
212 {my (\$target, \$source) = \@_;
213 \@_ == 2 or confess "Two arguments required";
214 #TEST Keep(\$target) if "$i" =~ m(\\Amov\\Z) and \$Registers{\$target};
215 #TEST KeepSet(\$source) if "$i" =~ m(\\Amov\\Z) and \$Registers{\$source};
216 my \$s = ' ' x scalar(my \@d = caller);
217 push \@text, qq(\${s}$i \$target, \$source\\n);
218 }
219 END
220 }
221 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
222 1 ▶ confess "$s$@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 1 1
223 }
224  
225 1 if (1) # Instructions that take three operands
226 1 {my $s = '';
227 1 for my $i(@i3)
228 100 {my $I = ucfirst $i;
229 100 $s .= <<END;
230 sub $I(\$\$\$)
231 {my (\$target, \$source, \$bits) = \@_;
232 \@_ == 3 or confess "Three arguments required";
233 my \$s = ' ' x scalar(my \@d = caller);
234 push \@text, qq(\${s}$i \$target, \$source, \$bits\\n);
235 }
236 END
237 }
238 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
239 1 ▶ confess $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 1 1
240 }
241  
242 1 if (1) # Instructions that take four operands
243 1 {my $s = '';
244 1 for my $i(@i4)
245 4 {my $I = ucfirst $i;
246 4 $s .= <<END;
247 sub $I(\$\$\$\$)
248 {my (\$target, \$source, \$bits, \$zero) = \@_;
249 \@_ == 4 or confess "Four arguments required";
250 my \$s = ' ' x scalar(my \@d = caller);
251 push \@text, qq(\${s}$i \$target, \$source, \$bits, \$zero\\n);
252 }
253 END
254 }
255 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
256 1 ▶ confess $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 1 1
257 }
258 }
259  
260 sub ClearRegisters(@); # Clear registers by setting them to zero.
261 sub Comment(@); # Insert a comment into the assembly code.
262 sub DComment(@); # Insert a comment into the data section.
263 sub RComment(@); # Insert a comment into the read only data section.
264 sub PeekR($); # Peek at the register on top of the stack.
265 sub PopR(@); # Pop a list of registers off the stack.
266 sub PopRR(@); # Pop a list of registers off the stack without tracking.
267 sub PrintErrStringNL(@); # Print a constant string followed by a new line to stderr.
268 sub PrintOutMemory; # Print the memory addressed by rax for a length of rdi.
269 sub PrintOutRegisterInHex(@); # Print any register as a hex string.
270 sub PrintOutStringNL(@); # Print a constant string to stdout followed by new line.
271 sub PrintString($@); # Print a constant string to the specified channel.
272 sub PushR(@); # Push a list of registers onto the stack.
273 sub PushRR(@); # Push a list of registers onto the stack without tracking.
274 sub Syscall(); # System call in linux 64 format.
275  
276 #D1 Data # Layout data
277  
278 1 my $Labels = 0;
279  
280 sub Label(;$) #P Create a unique label or reuse the one supplied.
281 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
282 0 $_[0]; # Use supplied label
283 }
284  
285 sub SetLabel(;$) # Create (if necessary) and set a label in the code section returning the label so set.
286 0 ▶ {my ($l) = @_; # Label
Subroutine SetLabel: not called CC=2 SCAR=17.9
Pod documented
287 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
288 0 push @text, <<END; # Define bytes
289 $l:
290 END
291 0 $l # Return label name
292 }
293  
294 sub Ds(@) # Layout bytes in memory and return their label.
295 0 ▶ {my (@d) = @_; # Data to be laid out
Subroutine Ds: not called CC=1 SCAR=6.9
Pod documented
296 0 my $d = join '', @_;
297 0 $d =~ s(') (\')gs;
298 0 my $l = Label;
299 0 push @data, <<END; # Define bytes
300 $l: db '$d';
301 END
302 0 $l # Return label
303 }
304  
305 sub Rs(@) # Layout bytes in read only memory and return their label.
306 0 ▶ {my (@d) = @_; # Data to be laid out
Subroutine Rs: not called CC=4 SCAR=30.0
Pod documented
307 0 my $d = join '', @_;
308 0 my @e;
309 0 for my $e(split //, $d)
310 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
311 }
312 0 my $e = join ', ', @e;
313 0 my $L = $rodatas{$e};
314 0 ▶ return $L if defined $L; # Data already exists so return it
Branch: 1 branch
BranchTrueFalseTotal
if defined $L 0 0 0
315 0 my $l = Label; # New label for new data
316 0 $rodatas{$e} = $l; # Record label
317 0 push @rodata, <<END; # Define bytes
318 $l: db $e, 0;
319 END
320 0 $l # Return label
321 }
322  
323 sub Rutf8(@) # Layout a utf8 encoded string as bytes in read only memory and return their label.
324 0 ▶ {my (@d) = @_; # Data to be laid out
Subroutine Rutf8: not called CC=7 SCAR=40.3
Pod documented
325 0 ▶ confess unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
326 0 my $d = join '', @_;
327 0 my @e;
328 0 for my $e(split //, $d)
329 0 {my $o = ord $e; # Effectively the utf32 encoding of each character
330 0 my $u = convertUtf32ToUtf8($o);
331 0 my $x = sprintf("%08x", $u);
332 0 my $o1 = substr($x, 0, 2);
333 0 my $o2 = substr($x, 2, 2);
334 0 my $o3 = substr($x, 4, 2);
335 0 my $o4 = substr($x, 6, 2);
336 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
337 0 elsif ($o <= (1 << 11)) {push @e, $o3, $o4}
338 0 elsif ($o <= (1 << 16)) {push @e, $o2, $o3, $o4}
339 0 else {push @e, $o1, $o2, $o3, $o4}
340 }
341  
342 0 my $e = join ', ',map {"0x$_"} @e;
343 0 my $L = $rodatas{$e};
344 0 ▶ return $L if defined $L; # Data already exists so return it
Branch: 1 branch
BranchTrueFalseTotal
if defined $L 0 0 0
345 0 my $l = Label; # New label for new data
346 0 $rodatas{$e} = $l; # Record label
347 0 push @rodata, <<END; # Define bytes
348 $l: db $e, 0;
349 END
350 0 $l # Return label
351 }
352  
353 sub Dbwdq($@) #P Layout data.
354 0 ▶ {my ($s, @d) = @_; # Element size, data to be laid out
Subroutine Dbwdq: not called CC=1 SCAR=6.9
Pod documented
355 0 my $d = join ', ', @d;
356 0 my $l = Label;
357 0 push @data, <<END;
358 $l: d$s $d
359 END
360 0 $l # Return label
361 }
362  
363 sub Db(@) # Layout bytes in the data segment and return their label.
364 0 ▶ {my (@bytes) = @_; # Bytes to layout
Subroutine Db: not called CC=1 SCAR=6.9
Pod documented
365 0 Dbwdq 'b', @_;
366 }
367 sub Dw(@) # Layout words in the data segment and return their label.
368 0 ▶ {my (@words) = @_; # Words to layout
Subroutine Dw: not called CC=1 SCAR=6.9
Pod documented
369 0 Dbwdq 'w', @_;
370 }
371 sub Dd(@) # Layout double words in the data segment and return their label.
372 0 ▶ {my (@dwords) = @_; # Double words to layout
Subroutine Dd: not called CC=1 SCAR=6.9
Pod documented
373 0 Dbwdq 'd', @_;
374 }
375 sub Dq(@) # Layout quad words in the data segment and return their label.
376 0 ▶ {my (@qwords) = @_; # Quad words to layout
Subroutine Dq: not called CC=1 SCAR=6.9
Pod documented
377 0 Dbwdq 'q', @_;
378 }
379  
380 sub Rbwdq($@) #P Layout data.
381 0 ▶ {my ($s, @d) = @_; # Element size, data to be laid out
Subroutine Rbwdq: not called CC=3 SCAR=24.8
Pod documented
382 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
383 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
384 0 {return $c
385 }
386 0 my $l = Label; # New data - create a label
387 0 push @rodata, <<END; # Save in read only data
388 $l: d$s $d
389 END
390 0 $rodata{$s}{$d} = $l; # Record label
391 0 $l # Return label
392 }
393  
394 sub Rb(@) # Layout bytes in the data segment and return their label.
395 0 ▶ {my (@bytes) = @_; # Bytes to layout
Subroutine Rb: not called CC=1 SCAR=6.9
Pod documented
396 0 Rbwdq 'b', @_;
397 }
398 sub Rw(@) # Layout words in the data segment and return their label.
399 0 ▶ {my (@words) = @_; # Words to layout
Subroutine Rw: not called CC=1 SCAR=6.9
Pod documented
400 0 Rbwdq 'w', @_;
401 }
402 sub Rd(@) # Layout double words in the data segment and return their label.
403 0 ▶ {my (@dwords) = @_; # Double words to layout
Subroutine Rd: not called CC=1 SCAR=6.9
Pod documented
404 0 Rbwdq 'd', @_;
405 }
406 sub Rq(@) # Layout quad words in the data segment and return their label.
407 0 ▶ {my (@qwords) = @_; # Quad words to layout
Subroutine Rq: not called CC=1 SCAR=6.9
Pod documented
408 0 Rbwdq 'q', @_;
409 }
410  
411 1 my $Pi = "3.141592653589793238462";
412  
413 0 ▶sub Pi32 {Rd("__float32__($Pi)")} #P Pi as a 32 bit float.
Subroutine Pi32: not called CC=1 SCAR=6.9
Pod documented
414 0 ▶sub Pi64 {Rq("__float32__($Pi)")} #P Pi as a 64 bit float.
Subroutine Pi64: not called CC=1 SCAR=6.9
Pod documented
415  
416 #D1 Registers # Operations on registers
417  
418 sub xmm(@) # Add xmm to the front of a list of register expressions.
419 0 ▶ {my (@r) = @_; # Register numbers
Subroutine xmm: not called CC=1 SCAR=6.9
Pod documented
420 0 map {"xmm$_"} @_;
421 }
422  
423 sub ymm(@) # Add ymm to the front of a list of register expressions.
424 0 ▶ {my (@r) = @_; # Register numbers
Subroutine ymm: not called CC=1 SCAR=6.9
Pod documented
425 0 map {"ymm$_"} @_;
426 }
427  
428 sub zmm(@) # Add zmm to the front of a list of register expressions.
429 0 ▶ {my (@r) = @_; # Register numbers
Subroutine zmm: not called CC=1 SCAR=6.9
Pod documented
430 0 map {"zmm$_"} @_;
431 }
432  
433 sub ChooseRegisters($@) # Choose the specified numbers of registers excluding those on the specified list.
434 0 ▶ {my ($number, @registers) = @_; # Number of registers needed, Registers not to choose
Subroutine ChooseRegisters: not called CC=3 SCAR=24.8
Pod documented
435 0 my %r = (map {$_=>1} map {"r$_"} 8..15);
436 0 delete $r{$_} for @registers;
437 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
438 0 sort keys %r
439 }
440  
441 sub RegistersAvailable(@) # Add a new set of registers that are available.
442 0 ▶ {my (@reg) = @_; # Registers known to be available at the moment
Subroutine RegistersAvailable: not called CC=1 SCAR=6.9
Pod documented
443 0 my %r = map {$_=>1} @reg;
444 0 push @RegistersAvailable, \%r;
445 }
446  
447 sub RegistersFree # Remove the current set of registers known to be free.
448 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
449 0 pop @RegistersAvailable;
450 }
451  
452 sub CheckGeneralPurposeRegister($) # Check that a register is in fact a general purpose register.
453 0 ▶ {my ($reg) = @_; # Mask register to check
Subroutine CheckGeneralPurposeRegister: not called CC=4 SCAR=30.0
Pod documented
454 0 ▶ @_ == 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess() 0 0 0
455 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
456 confess "Not a general purpose register: $reg";
457 }
458  
459 sub CheckNumberedGeneralPurposeRegister($) # Check that a register is in fact a numbered general purpose register.
460 0 ▶ {my ($reg) = @_; # Mask register to check
Subroutine CheckNumberedGeneralPurposeRegister: not called CC=4 SCAR=30.0
Pod documented
461 0 ▶ @_ == 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess() 0 0 0
462 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
463 confess "Not a numbered general purpose register: $reg";
464 }
465  
466 sub InsertZeroIntoRegisterAtPoint($$) # Insert a zero into the specified register at the point indicated by another register.
467 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
468  
469 0 PushR my @s = my ($mask, $low, $high) = ChooseRegisters(3, $in, $point); # Choose three work registers and push them
470 0 Mov $mask, $point;
471 0 Sub $mask, 1;
472 0 Andn $high, $mask, $in;
473 0 Shl $high, 1;
474 0 Mov $low, $in;
475 0 And $low, $mask;
476 0 Or $low, $high;
477 0 Mov $in, $low;
478 0 PopR @s; # Restore stack
479 }
480  
481 sub InsertOneIntoRegisterAtPoint($$) # Insert a one into the specified register at the point indicated by another register.
482 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
483 0 InsertZeroIntoRegisterAtPoint($point, $in); # Insert a zero
484 0 Or $in, $point; # Make the zero a one
485 }
486  
487 sub LoadZmm($@) # Load a numbered zmm with the specified bytes.
488 0 ▶ {my ($zmm, @bytes) = @_; # Numbered zmm, bytes
Subroutine LoadZmm: not called CC=1 SCAR=6.9
Pod documented
489 0 my $b = Rb(@bytes);
490 0 Vmovdqu8 "zmm$zmm", "[$b]";
491 }
492  
493 #D2 Save and Restore # Saving and restoring registers via the stack
494  
495 1 my @syscallSequence = qw(rax rdi rsi rdx r10 r8 r9); # The parameter list sequence for system calls
496  
497 sub SaveFirstFour(@) # Save the first 4 parameter registers making any parameter registers read only.
498 0 ▶ {my (@keep) = @_; # Registers to mark as read only
Subroutine SaveFirstFour: not called CC=2 SCAR=17.9
Pod documented
499 0 my $N = 4;
500 0 PushRR $_ for @syscallSequence[0..$N-1];
501 0 $N * &RegisterSize(rax); # Space occupied by push
502 }
503  
504 sub RestoreFirstFour() # Restore the first 4 parameter registers.
505 0 ▶ {my $N = 4;
Subroutine RestoreFirstFour: not called CC=2 SCAR=17.9
Pod documented
506 0 PopRR $_ for reverse @syscallSequence[0..$N-1];
507 }
508  
509 sub RestoreFirstFourExceptRax() # Restore the first 4 parameter registers except rax so it can return its value.
510 0 ▶ {my $N = 4;
Subroutine RestoreFirstFourExceptRax: not called CC=2 SCAR=17.9
Pod documented
511 0 PopRR $_ for reverse @syscallSequence[1..$N-1];
512 0 Add rsp, 1*RegisterSize(rax);
513 }
514  
515 sub RestoreFirstFourExceptRaxAndRdi() # Restore the first 4 parameter registers except rax and rdi so we can return a pair of values.
516 0 ▶ {my $N = 4;
Subroutine RestoreFirstFourExceptRaxAndRdi: not called CC=2 SCAR=17.9
Pod documented
517 0 PopRR $_ for reverse @syscallSequence[2..$N-1];
518 0 Add rsp, 2*RegisterSize(rax);
519 }
520  
521 sub SaveFirstSeven() # Save the first 7 parameter registers.
522 0 ▶ {my $N = 7;
Subroutine SaveFirstSeven: not called CC=2 SCAR=17.9
Pod documented
523 0 PushRR $_ for @syscallSequence[0..$N-1];
524 0 $N * 1*RegisterSize(rax); # Space occupied by push
525 }
526  
527 sub RestoreFirstSeven() # Restore the first 7 parameter registers.
528 0 ▶ {my $N = 7;
Subroutine RestoreFirstSeven: not called CC=2 SCAR=17.9
Pod documented
529 0 PopRR $_ for reverse @syscallSequence[0..$N-1];
530 }
531  
532 sub RestoreFirstSevenExceptRax() # Restore the first 7 parameter registers except rax which is being used to return the result.
533 0 ▶ {my $N = 7;
Subroutine RestoreFirstSevenExceptRax: not called CC=2 SCAR=17.9
Pod documented
534 0 PopRR $_ for reverse @syscallSequence[1..$N-1];
535 0 Add rsp, 1*RegisterSize(rax);
536 }
537  
538 sub RestoreFirstSevenExceptRaxAndRdi() # Restore the first 7 parameter registers except rax and rdi which are being used to return the results.
539 0 ▶ {my $N = 7;
Subroutine RestoreFirstSevenExceptRaxAndRdi: not called CC=2 SCAR=17.9
Pod documented
540 0 PopRR $_ for reverse @syscallSequence[2..$N-1];
541 0 Add rsp, 2*RegisterSize(rax); # Skip rdi and rax
542 }
543  
544 sub ReorderSyscallRegisters(@) # Map the list of registers provided to the 64 bit system call sequence.
545 0 ▶ {my (@registers) = @_; # Registers
Subroutine ReorderSyscallRegisters: not called CC=1 SCAR=6.9
Pod documented
546 0 PushRR @syscallSequence[0..$#registers];
547 0 PushRR @registers;
548 0 PopRR @syscallSequence[0..$#registers];
549 }
550  
551 sub UnReorderSyscallRegisters(@) # Recover the initial values in registers that were reordered.
552 0 ▶ {my (@registers) = @_; # Registers
Subroutine UnReorderSyscallRegisters: not called CC=1 SCAR=6.9
Pod documented
553 0 PopRR @syscallSequence[0..$#registers];
554 }
555  
556 sub RegisterSize($) # Return the size of a register.
557 0 ▶ {my ($r) = @_; # Register
Subroutine RegisterSize: not called CC=3 SCAR=24.8
Pod documented
558 0 ▶ defined($r) or confess;
Branch: 1 branch
BranchTrueFalseTotal
defined $r or confess() 0 0 0
559 0 ▶ defined($Registers{$r}) or confess;
Branch: 1 branch
BranchTrueFalseTotal
defined $Registers{$r} or confess() 0 0 0
560 0 eval "${r}Size()";
561 }
562  
563 sub ClearRegisters(@) # Clear registers by setting them to zero.
564 0 ▶ {my (@registers) = @_; # Registers
Subroutine ClearRegisters: not called CC=7 SCAR=40.3
Pod documented
565 0 for my $r(@registers) # Each register
566 0 {my $size = RegisterSize $r;
567 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
568 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
569 0 ▶ Vpxorq $r, $r, $r if $size > 8;
Branch: 1 branch
BranchTrueFalseTotal
if $size > 8 0 0 0
570 }
571 }
572  
573 sub SetMaskRegister($$$) # Set the mask register to ones starting at the specified position for the specified length and zeroes elsewhere.
574 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
575 0 ▶ @_ == 3 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess() 0 0 0
576  
577 0 PushR (r15, r14);
578 0 Mov r15, -1;
579 0 ▶ if ($start) # Non zero start
Branch: 1 branch
BranchTrueFalseTotal
if ($start) { } 0 0 0
580 0 {Mov r14, $start;
581 0 Bzhi r15, r15, r14;
582 0 Not r15;
583 0 Add r14, $length;
584 }
585 else # Starting at zero
586 0 {Mov r14, $length;
587 }
588 0 Bzhi r15, r15, r14;
589 0 Kmovq $mask, r15;
590 0 PopR;
591 }
592  
593 sub SetZF() # Set the zero flag.
594 0 ▶ {Cmp rax, rax;
Subroutine SetZF: not called CC=1 SCAR=6.9
Pod documented
595 }
596  
597 sub ClearZF() # Clear the zero flag.
598 0 ▶ {PushR rax;
Subroutine ClearZF: not called CC=1 SCAR=6.9
Pod documented
599 0 Mov rax, 1;
600 0 Cmp rax, 0;
601 0 PopR rax;
602 }
603  
604 #D2 Mask # Operations on mask registers
605  
606 sub CheckMaskRegister($) # Check that a register is in fact a mask register.
607 0 ▶ {my ($mask) = @_; # Mask register to check
Subroutine CheckMaskRegister: not called CC=4 SCAR=30.0
Pod documented
608 0 ▶ @_ == 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess() 0 0 0
609 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
610 confess "Not a mask register: $mask";
611 }
612  
613 sub LoadConstantIntoMaskRegister($$$) # Set a mask register equal to a constant.
614 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
615 0 ▶ @_ == 3 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess() 0 0 0
616 0 CheckMaskRegister $mask;
617 0 CheckGeneralPurposeRegister $transfer;
618 0 Mov $transfer, $value; # Load mask into a general purpose register
619 0 Kmovq $mask, $transfer; # Load mask register from general purpose register
620 }
621  
622 sub LoadBitsIntoMaskRegister($$$@) # Load a bit string specification into a mask register.
623 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
624 0 ▶ @_ > 3 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ > 3 or confess() 0 0 0
625 0 CheckMaskRegister $mask;
626 0 CheckGeneralPurposeRegister $transfer;
627 0 my $b = "0b$prefix";
628 0 for my $v(@values) # String representation of bit string
629 0 ▶ {$b .= '1' x +$v if $v > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $v > 0 0 0 0
630 0 ▶ $b .= '0' x -$v if $v < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $v < 0 0 0 0
631 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
632 }
633 0 LoadConstantIntoMaskRegister($mask, $transfer, eval $b)
634 }
635  
636 1 my $Vpcmp = genHash("NasmX86::CompareCodes", # Compare codes for "Vpcmp"
637 eq=>0, # Equal
638 lt=>1, # Less than
639 le=>2, # Less than or equals
640 ne=>4, # Not equals
641 ge=>5, # Greater than or equal
642 gt=>6, # Greater than
643 );
644  
645 #D1 Structured Programming # Structured programming constructs
646  
647 sub If($$;$) # If.
648 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
649 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
650  
651 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
652 or confess "Invalid jump: $jump";
653  
654 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
655 0 { __SUB__->(q(Jnz), $then, $else);
656 }
657 elsif (!$else) # No else
658 0 {my $end = Label;
659 0 push @text, <<END;
660 $jump $end;
661 END
662 0 &$then;
663 0 SetLabel $end;
664 }
665 else # With else
666 0 {my $endIf = Label;
667 0 my $startElse = Label;
668 0 push @text, <<END;
669 $jump $startElse
670 END
671 0 &$then;
672 0 Jmp $endIf;
673 0 SetLabel $startElse;
674 0 &$else;
675 0 SetLabel $endIf;
676 }
677 }
678  
679 sub Then(&) # Then block for an If statement.
680 0 ▶ {my ($block) = @_; # Then block
Subroutine Then: not called CC=1 SCAR=6.9
Pod documented
681 0 $block;
682 }
683  
684 sub Else(&) # Else block for an If statement.
685 0 ▶ {my ($block) = @_; # Else block
Subroutine Else: not called CC=1 SCAR=6.9
Pod documented
686 0 $block;
687 }
688  
689 sub Ef(&$;$) # Else if block for an If statement.
690 0 ▶ {my ($condition, $then, $else) = @_; # Condition, then block, else block
Subroutine Ef: not called CC=1 SCAR=6.9
Pod documented
691 sub
692 0 ▶ {If (&$condition, $then, $else);
Subroutine __ANON__: not called CC=1 SCAR=6.9
693 }
694 0 }
695  
696 sub IfEq($;$) # If equal execute the then block else the else block.
697 0 ▶ {my ($then, $else) = @_; # Then - required , else - optional
Subroutine IfEq: not called CC=1 SCAR=6.9
Pod documented
698 0 If(q(Jne), $then, $else); # Opposite code
699 }
700  
701 sub IfNe($;$) # If not equal execute the then block else the else block.
702 0 ▶ {my ($then, $else) = @_; # Then - required , else - optional
Subroutine IfNe: not called CC=1 SCAR=6.9
Pod documented
703 0 If(q(Je), $then, $else); # Opposite code
704 }
705  
706 sub IfNz($;$) # If the zero flag is not set then execute the then block else the else block.
707 0 ▶ {my ($then, $else) = @_; # Then - required , else - optional
Subroutine IfNz: not called CC=1 SCAR=6.9
Pod documented
708 0 If(q(Jz), $then, $else); # Opposite code
709 }
710  
711 sub IfZ($;$) # If the zero flag is set then execute the then block else the else block.
712 0 ▶ {my ($then, $else) = @_; # Then - required , else - optional
Subroutine IfZ: not called CC=1 SCAR=6.9
Pod documented
713 0 If(q(Jnz), $then, $else); # Opposite code
714 }
715  
716 sub IfC($;$) # If the carry flag is set then execute the then block else the else block.
717 0 ▶ {my ($then, $else) = @_; # Then - required , else - optional
Subroutine IfC: not called CC=1 SCAR=6.9
Pod documented
718 0 If(q(Jnc), $then, $else); # Opposite code
719 }
720  
721 sub IfNc($;$) # If the carry flag is not set then execute the then block else the else block.
722 0 ▶ {my ($then, $else) = @_; # Then - required , else - optional
Subroutine IfNc: not called CC=1 SCAR=6.9
Pod documented
723 0 If(q(Jc), $then, $else); # Opposite code
724 }
725  
726 sub IfLt($;$) # If less than execute the then block else the else block.
727 0 ▶ {my ($then, $else) = @_; # Then - required , else - optional
Subroutine IfLt: not called CC=1 SCAR=6.9
Pod documented
728 0 If(q(Jge), $then, $else); # Opposite code
729 }
730  
731 sub IfLe($;$) # If less than or equal execute the then block else the else block.
732 0 ▶ {my ($then, $else) = @_; # Then - required , else - optional
Subroutine IfLe: not called CC=1 SCAR=6.9
Pod documented
733 0 If(q(Jg), $then, $else); # Opposite code
734 }
735  
736 sub IfGt($;$) # If greater than execute the then block else the else block.
737 0 ▶ {my ($then, $else) = @_; # Then - required , else - optional
Subroutine IfGt: not called CC=1 SCAR=6.9
Pod documented
738 0 If(q(Jle), $then, $else); # Opposite code
739 }
740  
741 sub IfGe($;$) # If greater than or equal execute the then block else the else block.
742 0 ▶ {my ($then, $else) = @_; # Then - required , else - optional
Subroutine IfGe: not called CC=1 SCAR=6.9
Pod documented
743 0 If(q(Jl), $then, $else); # Opposite code
744 }
745  
746 sub Pass(&) # Pass block for an L<OrBlock>.
747 0 ▶ {my ($block) = @_; # Block
Subroutine Pass: not called CC=1 SCAR=6.9
Pod documented
748 0 $block;
749 }
750  
751 sub Fail(&) # Fail block for an L<AndBlock>.
752 0 ▶ {my ($block) = @_; # Block
Subroutine Fail: not called CC=1 SCAR=6.9
Pod documented
753 0 $block;
754 }
755  
756 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.
757 0 ▶ {my ($test, $fail) = @_; # Block, optional failure block
Subroutine AndBlock: not called CC=6 SCAR=37.4
Pod documented
758 0 ▶ @_ == 1 or @_ == 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or @_ == 2 or confess() 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
759 0 SetLabel(my $start = Label); # Start of test block
760 0 ▶ my $Fail = @_ == 2 ? Label : undef; # Start of fail block
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 ? : 0 0 0
761 0 my $end = Label; # End of both blocks
762 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
763 0 ▶ if ($fail)
Branch: 1 branch
BranchTrueFalseTotal
if ($fail) 0 0 0
764 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>.
765 0 SetLabel $Fail;
766 0 &$fail($end, $Fail, $start); # Execute when true
767 }
768 0 SetLabel $end; # Exit block
769 }
770  
771 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.
772 0 ▶ {my ($test, $pass) = @_; # Tests, optional block to execute on success
Subroutine OrBlock: not called CC=6 SCAR=37.4
Pod documented
773 0 ▶ @_ == 1 or @_ == 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or @_ == 2 or confess() 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
774 0 SetLabel(my $start = Label); # Start of test block
775 0 ▶ my $Pass = @_ == 2 ? Label : undef; # Start of pass block
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 ? : 0 0 0
776 0 my $end = Label; # End of both blocks
777 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
778 0 ▶ if ($pass)
Branch: 1 branch
BranchTrueFalseTotal
if ($pass) 0 0 0
779 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>.
780 0 SetLabel $Pass;
781 0 &$pass($end, $Pass, $start); # Execute when true
782 }
783 0 SetLabel $end; # Exit block
784 }
785  
786 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.
787 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
788 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
789 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
790 0 my $next = Label; # Next iteration
791 0 Comment "For $register $limit";
792 0 my $start = Label;
793 0 my $end = Label;
794 0 SetLabel $start;
795 0 Cmp $register, $limit;
796 0 Jge $end;
797  
798 0 &$block($start, $end, $next); # Start, end and next labels
799  
800 0 SetLabel $next; # Next iteration starting with after incrementing
801 0 ▶ if ($increment == 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($increment == 1) { } 0 0 0
802 0 {Inc $register;
803 }
804 else
805 0 {Add $register, $increment;
806 }
807 0 Jmp $start; # Restart loop
808 0 SetLabel $end; # Exit loop
809 }
810  
811 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.
812 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
813 0 ▶ @_ == 5 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 5 or confess() 0 0 0
814 0 my $start = Label;
815 0 my $end = Label;
816  
817 0 SetLabel $start; # Start of loop
818 0 PushR $register; # Save the register so we can test that there is still room
819 0 Add $register, $increment; # Add increment
820 0 Cmp $register, $limitRegister; # Test that we have room for increment
821 0 PopR $register; # Remove increment
822 0 Jge $end;
823  
824 0 &$full;
825  
826 0 Add $register, $increment; # Increment for real
827 0 Jmp $start;
828 0 SetLabel $end;
829  
830 0 Sub $limitRegister, $register; # Size of remainder
831 IfNz # Non remainder
832 Then
833 0 ▶ {&$last; # Process remainder
Subroutine __ANON__: not called CC=1 SCAR=6.9
834 }
835 0 }
836  
837 sub ForEver(&) # Iterate for ever.
838 0 ▶ {my ($block) = @_; # Block to iterate
Subroutine ForEver: not called CC=2 SCAR=17.9
Pod documented
839 0 ▶ @_ == 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess() 0 0 0
840 0 Comment "ForEver";
841 0 my $start = Label; # Start label
842 0 my $end = Label; # End label
843  
844 0 SetLabel $start; # Start of loop
845  
846 0 &$block($start, $end); # End of loop
847  
848 0 Jmp $start; # Restart loop
849 0 SetLabel $end; # End of loop
850 }
851  
852 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.
853 0 ▶ {my ($block, %options) = @_; # Block, options.
Subroutine Macro: not called CC=7 SCAR=40.3
Pod documented
854  
855 0 ▶ @_ >= 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 1 or confess() 0 0 0
856 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
857 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
858  
859 0 my $start = Label;
860 0 my $end = Label;
861 0 Jmp $end;
862 0 SetLabel $start;
863 0 &$block;
864 0 Ret;
865 0 SetLabel $end;
866 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
867  
868 0 $start
869 }
870  
871 #D2 Call # Call a subroutine
872  
873 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.
874  
875 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.
876 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
877 }
878  
879 sub Subroutine(&$%) # Create a subroutine that can be called in assembler code.
880 0 ▶ {my ($block, $parameters, %options) = @_; # Block, [parameters names], options.
Subroutine Subroutine: not called CC=10 SCAR=47.0
Pod documented
881 0 ▶ @_ >= 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 or confess() 0 0 0
882 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
883 confess "Reference to array of parameter names required";
884  
885 0 my $name = $options{name}; # Subroutine name
886 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
887  
888 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
889  
890 0 SubroutineStartStack; # Open new stack layout with references to parameters
891 0 my %p; $p{$_} = R($_) for @$parameters; # Reference each parameter
892  
893 0 my $end = Label; Jmp $end; # End label
894 0 my $start = SetLabel; # Start label
895  
896 my $s = $subroutines{$name} = genHash(__PACKAGE__."::Sub", # Subroutine definition
897 start => $start, # Start label for this subroutine
898 end => $start, # End label for this subroutine
899 name => $name, # Name of the subroutine from which the entry label is located
900 0 args => {map {$_=>1} @$parameters}, # Hash of {argument name, argument variable}
901 variables => {%p}, # Argument variables
902 options => \%options, # Options
903 parameters=> $parameters, # Parameters
904 vars => $VariableStack[-1], # Number of variables in subroutine
905 depth => scalar @VariableStack, # Lexical depth
906 nameString=> Rs($name), # Name of the sub as a string constant
907 );
908  
909 0 my $E = @text; # Code entry that will contain the Enter instruction
910 0 Enter 0, 0;
911 0 &$block({%p}, $s); # Code with parameters
912  
913 0 my $V = pop @VariableStack; # Number of variables
914 0 my $P = @$parameters; # Number of parameters supplied
915 0 my $N = $P + $V; # Size of stack frame
916  
917 0 ▶ Leave if $N; # Remove frame if there was one
Branch: 1 branch
BranchTrueFalseTotal
if $N 0 0 0
918  
919 0 Ret;
920 0 SetLabel $end;
921 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
922 Enter $N*8, 0
923 END
924  
925 0 $s # Subroutine definition
926 }
927  
928 sub Nasm::X86::Sub::callTo($$$@) #P Call a sub passing it some parameters.
929 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
930  
931 0 my %p;
932 0 ▶ while(@parameters) # Copy parameters supplied by the caller
Branch: 1 branch
BranchTrueFalseTotal
if (@parameters) 0 0 0
933 0 {my $p = shift @parameters; # Check parameters provided by caller
934 0 ▶ my $n = ref($p) ? $p->name : $p;
Branch: 1 branch
BranchTrueFalseTotal
ref $p ? : 0 0 0
935 0 ▶ defined($n) or confess "No name or variable";
Branch: 1 branch
BranchTrueFalseTotal
defined $n or confess("No name or variable") 0 0 0
936 0 ▶ my $v = ref($p) ? $p : shift @parameters;
Branch: 1 branch
BranchTrueFalseTotal
ref $p ? : 0 0 0
937 0 ▶ unless ($sub->args->{$n}) # Describe valid parameters using a table
Branch: 1 branch
BranchTrueFalseTotal
unless ($sub->args->{$n}) 0 0 0
938 0 {my @t;
939 0 push @t, map {[$_]} keys $sub->args->%*;
940 0 my $t = formatTable([@t], [qw(Name)]);
941 0 confess "Invalid parameter: '$n'\n$t";
942 }
943 0 $p{$n} = $v;
944 }
945  
946 0 if (1) # Check for missing arguments
947 0 {my %m = map {$_=>1} keys $sub->args->%*; # Formal arguments
948 0 delete $m{$_} for sort keys %p; # Remove actual arguments
949 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
950 }
951  
952 0 if (1) # Check for misnamed arguments
953 0 {my %m = map {$_=>1} keys %p; # Actual arguments
954 0 delete $m{$_} for sort keys $sub->args->%*; # Remove formal arguments
955 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
956 }
957  
958 0 my $w = RegisterSize r15;
959 0 PushR r15; # Use this register to transfer between the current frame and the next frame
960 0 Mov "dword[rsp -$w*3]", $sub->nameString; # Point to name
961 0 Mov "byte [rsp-1-$w*2]", scalar $sub->parameters->@*; # Number of parameters to enable traceback with parameters
962  
963 0 for my $p(sort keys %p) # Transfer parameters from current frame to next frame
964 {!ref($p{$p}) or ref($p{$p}) =~ m(variable)i or
965 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
966 0 my $P = $p{$p}->label; # Source in current frame
967 0 ▶ if (my $q = $sub->variables->{$p}) # Target in new frame
Branch: 1 branch
BranchTrueFalseTotal
if (my $q = $sub->variables->{$p}) 0 0 0
968 0 ▶ {if ($p{$p}->reference) # Source is a reference
Branch: 1 branch
BranchTrueFalseTotal
if ($p{$p}->reference) { } 0 0 0
969 0 {Mov r15, "[$P]";
970 }
971 else # Source is not a reference
972 0 {Lea r15, "[$P]";
973 }
974 0 my $Q = $q->label;
975 0 $Q =~ s(rbp) (rsp);
976 0 Mov "[$Q-$w*2]", r15;
977 }
978 }
979  
980 0 ▶ if ($mode) # Dereference and call
Branch: 1 branch
BranchTrueFalseTotal
if ($mode) { } 0 0 0
981 0 {Mov r15, $label;
982 0 Mov r15, "[r15]";
983 0 Call r15;
984 }
985 else # Call via label
986 0 {Call $label;
987 }
988 0 PopR;
989 }
990  
991 sub Nasm::X86::Sub::call($@) # Call a sub passing it some parameters.
992 0 ▶ {my ($sub, @parameters) = @_; # Subroutine descriptor, parameter variables
Subroutine call: not called CC=1 SCAR=6.9
993 0 $sub->callTo(0, $sub->start, @parameters); # Call the subroutine
994 }
995  
996 sub Nasm::X86::Sub::via($$@) # Call a sub by reference passing it some parameters.
997 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
998 0 PushR r15;
999 0 $sub->callTo(1, "[$$ref{label}]", @parameters); # Call the subroutine
1000 0 PopR;
1001 }
1002  
1003 sub Nasm::X86::Sub::V($) # Put the address of a subroutine into a stack variable so that it can be passed as a parameter.
1004 0 ▶ {my ($sub) = @_; # Subroutine descriptor
Subroutine V: not called CC=1 SCAR=6.9
1005 0 V('call', $sub->start); # Address subroutine via a stack variable
1006 }
1007  
1008 sub PrintTraceBack($) # Trace the call stack.
1009 0 ▶ {my ($channel) = @_; # Channel to write on
Subroutine PrintTraceBack: not called CC=1 SCAR=6.9
Pod documented
1010 my $s = Subroutine
1011 0 ▶ {PushR my @save = (rax, rdi, r9, r10, r8, r12, r13, r14, r15);
Subroutine __ANON__: not called CC=1 SCAR=6.9
1012 0 my $stack = r15;
1013 0 my $count = r14;
1014 0 my $index = r13;
1015 0 my $parameter = r12; # Number of parameters
1016 0 my $maxCount = r8; # Maximum number of parameters - should be r11 when we have found out why r11 does not print correctly.
1017 0 my $depth = r10; # Depth of trace back
1018 0 ClearRegisters @save;
1019  
1020 0 Mov $stack, rbp; # Current stack frame
1021 AndBlock # Each level
1022 0 ▶ {my ($fail, $end, $start) = @_; # Fail block, end of fail block, start of test block
Subroutine __ANON__: not called CC=1 SCAR=6.9
1023 0 Mov $stack, "[$stack]"; # Up one level
1024 0 Mov rax, "[$stack-8]";
1025 0 Mov $count, rax;
1026 0 Shr $count, 56; # Top byte contains the parameter count
1027 0 Cmp $count, $maxCount; # Compare this count with maximum so far
1028 0 Cmovg $maxCount, $count; # Update count if greater
1029 0 Shl rax, 8; Shr rax, 8; # Remove parameter count
1030 0 Je $end; # Reached top of stack if rax is zero
1031 0 Inc $depth; # Depth of trace back
1032 0 Jmp $start; # Next level
1033 0 };
1034  
1035 0 Mov $stack, rbp; # Current stack frame
1036 0 &PrintNL($channel); # Print title
1037 0 &PrintString($channel, "Subroutine trace back, depth: ");
1038 0 PushR rax;
1039 0 Mov rax, $depth;
1040 0 &PrintRaxInHex($channel);
1041 0 PopR rax;
1042 0 &PrintNL($channel);
1043  
1044 AndBlock # Each level
1045 0 ▶ {my ($fail, $end, $start) = @_; # Fail block, end of fail block, start of test block
Subroutine __ANON__: not called CC=1 SCAR=6.9
1046 0 Mov $stack, "[$stack]"; # Up one level
1047 0 Mov rax, "[$stack-8]";
1048 0 Mov $count, rax;
1049 0 Shr $count, 56; # Top byte contains the parameter count
1050 0 Shl rax, 8; Shr rax, 8; # Remove parameter count
1051 0 Je $end; # Reached top of stack
1052 0 Cmp $count, 0; # Check for parameters
1053 IfGt
1054 Then # One or more parameters
1055 0 ▶ {Mov $index, 0;
Subroutine __ANON__: not called CC=1 SCAR=6.9
1056 For
1057 0 ▶ {my ($start, $end, $next) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
1058 0 Mov $parameter, $index;
1059 0 Add $parameter, 2; # Skip traceback
1060 0 Shl $parameter, 3; # Each parameter is a quad
1061 0 Neg $parameter; # Offset from stack
1062 0 Add $parameter, $stack; # Position on stack
1063 0 Mov $parameter, "[$parameter]"; # Parameter reference to variable
1064 0 Push rax;
1065 0 Mov rax, "[$parameter]"; # Variable content
1066 0 &PrintRaxInHex($channel);
1067 0 Pop rax;
1068 0 &PrintSpace($channel, 4);
1069 0 } $index, $count;
1070 For # Vertically align subroutine names
1071 0 ▶ {my ($start, $end, $next) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
1072 0 &PrintSpace($channel, 23);
1073 0 } $index, $maxCount;
1074 0 };
1075  
1076 0 Push $stack; # Print the name of the subroutine
1077 0 &Cstrlen(); # Length of name
1078 0 Mov rdi, $stack;
1079 0 Pop $stack;
1080 0 &PrintMemoryNL($channel); # Print name
1081 0 Jmp $start; # Next level
1082 0 };
1083 0 &PrintNL($channel);
1084 0 PopR;
1085 0 } [], name => 'SubroutineTraceBack';
1086  
1087 0 $s->call;
1088 }
1089  
1090 sub PrintErrTraceBack() # Print sub routine track back on stderr.
1091 0 ▶ {PrintTraceBack($stderr);
Subroutine PrintErrTraceBack: not called CC=1 SCAR=6.9
Pod documented
1092 }
1093  
1094 sub PrintOutTraceBack() # Print sub routine track back on stdout.
1095 0 ▶ {PrintTraceBack($stdout);
Subroutine PrintOutTraceBack: not called CC=1 SCAR=6.9
Pod documented
1096 }
1097  
1098 sub OnSegv() # Request a trace back followed by exit on a B<segv> signal.
1099 {my $s = Subroutine # Subroutine that will cause an error to occur to force a trace back to be printed
1100 0 ▶ {my $end = Label;
Subroutine __ANON__: not called CC=2 SCAR=17.9
1101 0 Jmp $end; # Jump over subroutine definition
1102 0 my $start = SetLabel;
1103 0 Enter 0, 0; # Inline code of signal handler
1104 0 Mov r15, rbp; # Preserve the new stack frame
1105 0 Mov rbp, "[rbp]"; # Restore our last stack frame
1106 0 PrintOutTraceBack; # Print our trace back
1107 0 Mov rbp, r15; # Restore supplied stack frame
1108 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.
1109 0 Leave;
1110 0 Ret;
1111 0 SetLabel $end;
1112  
1113 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
1114 0 Push r15 for 1..16;
1115  
1116 0 Mov r15, $start; # Actual signal handler
1117 0 Mov "[rsp]", r15; # Show as signal handler
1118 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
1119 0 Mov r15, 0x4000000; # Mask to show we have a trampoline which is, apparently, required on x86
1120 0 Mov "[rsp+0x8]", r15; # Confirm we have a trampoline
1121  
1122 0 Mov rax, 13; # B<Sigaction> from B<kill -l>
1123 0 Mov rdi, 11; # Confirmed B<SIGSEGV = 11> from B<kill -l> and tracing with B<sde64>
1124 0 Mov rsi, rsp; # Structure B<sigaction> structure on stack
1125 0 Mov rdx, 0; # Confirmed by trace
1126 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.
1127 0 Syscall;
1128 0 Add rsp, 128;
1129 0 ▶ } [], name=>"on segv";
Subroutine OnSegv: not called CC=1 SCAR=6.9
Pod documented
1130  
1131 0 $s->call;
1132 }
1133  
1134 sub cr(&@) # Call a subroutine with a reordering of the registers.
1135 0 ▶ {my ($block, @registers) = @_; # Code to execute with reordered registers, registers to reorder
Subroutine cr: not called CC=1 SCAR=6.9
Pod documented
1136 0 ReorderSyscallRegisters @registers;
1137 0 &$block;
1138 0 UnReorderSyscallRegisters @registers;
1139 }
1140  
1141 #D1 Comments # Inserts comments into the generated assember code.
1142  
1143 sub CommentWithTraceBack(@) # Insert a comment into the assembly code with a traceback showing how it was generated.
1144 0 ▶ {my (@comment) = @_; # Text of comment
Subroutine CommentWithTraceBack: not called CC=1 SCAR=6.9
Pod documented
1145 0 my $c = join "", @comment;
1146 0 eval {confess};
1147 0 my $p = dump($@);
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;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess() 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;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or @_ == 2 or confess() 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;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess() 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;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess() 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;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess() 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;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess() 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 #D2 Operations # Variable operations
1676  
1677 1 if (1) # Define operator overloading for Variables
1678 {package Nasm::X86::Variable;
1679 use overload
1680 1 '+' => \&add,
1681 '-' => \&sub,
1682 '*' => \&times,
1683 '/' => \&divide,
1684 '%' => \&mod,
1685 '==' => \&eq,
1686 '!=' => \&ne,
1687 '>=' => \&ge,
1688 '>' => \&gt,
1689 '<=' => \&le,
1690 '<' => \&lt,
1691 '++' => \&inc,
1692 '--' => \&dec,
1693 '""' => \&str,
1694 # '&' => \&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.
1695 # '|' => \&or,
1696 '+=' => \&plusAssign,
1697 '-=' => \&minusAssign,
1698 '=' => \&equals,
1699 1 ▶ }
Subroutine BEGIN: called CC=1 SCAR=0.0
1700  
1701 sub Nasm::X86::Variable::address($;$) # Get the address of a variable with an optional offset.
1702 0 ▶ {my ($left, $offset) = @_; # Left variable, optional offset
Subroutine address: not called CC=2 SCAR=17.9
1703 0 ▶ my $o = $offset ? "+$offset" : "";
Branch: 1 branch
BranchTrueFalseTotal
$offset ? : 0 0 0
1704 0 "[".$left-> label."$o]"
1705 }
1706  
1707 sub Nasm::X86::Variable::copy($$;$) # Copy one variable into another.
1708 0 ▶ {my ($left, $right, $Transfer) = @_; # Left variable, right variable, optional transfer register
Subroutine copy: not called CC=11 SCAR=48.8
1709 0 ▶ @_ == 2 or @_ == 3 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or @_ == 3 or confess() 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
1710 0 ▶ CheckGeneralPurposeRegister $Transfer if $Transfer;
Branch: 1 branch
BranchTrueFalseTotal
if $Transfer 0 0 0
1711  
1712 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
1713  
1714 # ref($right) =~ m(Variable) or confess "Variable required";
1715 0 my $l = $left ->address;
1716 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
1717  
1718 0 ▶ PushR $transfer unless $Transfer;
Branch: 1 branch
BranchTrueFalseTotal
unless $Transfer 0 0 0
1719 0 Mov $transfer, $r; # Load right hand side
1720  
1721 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
1722 0 {Mov $transfer, "[$transfer]";
1723 }
1724  
1725 0 ▶ if ($left ->reference) # Copy a reference
Branch: 1 branch
BranchTrueFalseTotal
if ($left->reference) { } 0 0 0
1726 0 {my ($ref) = ChooseRegisters(1, $transfer);
1727 0 PushR $ref;
1728 0 Mov $ref, $l;
1729 0 Mov "[$ref]", $transfer;
1730 0 PopR $ref;
1731 }
1732 else # Copy a non reference
1733 0 {Mov $l, $transfer;
1734 }
1735 0 ▶ PopR $transfer unless $Transfer;
Branch: 1 branch
BranchTrueFalseTotal
unless $Transfer 0 0 0
1736 0 $left # Return the variable on the left now that it has had the right hand side copied into it.
1737 }
1738  
1739 sub Nasm::X86::Variable::copyRef($$;$) # Copy a reference to a variable.
1740 0 ▶ {my ($left, $right, $Transfer) = @_; # Left variable, right variable, optional transfer register
Subroutine copyRef: not called CC=7 SCAR=40.3
1741 0 ▶ CheckGeneralPurposeRegister $Transfer if $Transfer;
Branch: 1 branch
BranchTrueFalseTotal
if $Transfer 0 0 0
1742  
1743 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
1744  
1745 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
1746  
1747 0 my $l = $left ->address;
1748 0 my $r = $right->address;
1749  
1750 0 ▶ PushR $transfer unless $Transfer;
Branch: 1 branch
BranchTrueFalseTotal
unless $Transfer 0 0 0
1751 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
1752 0 {Mov $transfer, $r;
1753 }
1754 else # Right is not a reference so we copy its address to make a reference to the data
1755 0 {Lea $transfer, $r;
1756 }
1757 0 Mov $l, $transfer; # Save value of address in left
1758 0 ▶ PopR $transfer unless $Transfer;
Branch: 1 branch
BranchTrueFalseTotal
unless $Transfer 0 0 0
1759  
1760 0 $left; # Chain
1761 }
1762  
1763 sub Nasm::X86::Variable::copyZF($) # Copy the current state of the zero flag into a variable.
1764 0 ▶ {my ($var) = @_; # Variable
Subroutine copyZF: not called CC=2 SCAR=17.9
1765 0 ▶ @_ == 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess() 0 0 0
1766  
1767 0 my $a = $var->address; # Address of the variable
1768  
1769 0 PushR (rax);
1770 0 Lahf; # Save flags to ah: (SF:ZF:0:AF:0:PF:1:CF)
1771 0 Shr ah, 6; # Put zero flag in bit zero
1772 0 And ah, 1; # Isolate zero flag
1773 0 Mov $a, ah; # Save zero flag
1774 0 PopR;
1775 }
1776  
1777 sub Nasm::X86::Variable::copyZFInverted($) # Copy the opposite of the current state of the zero flag into a variable.
1778 0 ▶ {my ($var) = @_; # Variable
Subroutine copyZFInverted: not called CC=3 SCAR=24.8
1779 0 ▶ @_ == 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess() 0 0 0
1780  
1781 0 my $a = $var->address; # Address of the variable
1782  
1783 0 PushR (rax, r15);
1784 0 Lahf; # Save flags to ah: (SF:ZF:0:AF:0:PF:1:CF)
1785 0 Shr ah, 6; # Put zero flag in bit zero
1786 0 Not ah; # Invert zero flag
1787 0 And ah, 1; # Isolate zero flag
1788 0 ▶ if ($var->reference) # Dereference and save
Branch: 1 branch
BranchTrueFalseTotal
if ($var->reference) { } 0 0 0
1789 0 {PushR rdx;
1790 0 Mov rdx, $a;
1791 0 Mov "[rdx]", ah; # Save zero flag
1792 0 PopR rdx;
1793 }
1794 else # Save without dereferencing
1795 0 {Mov $a, ah; # Save zero flag
1796 }
1797 0 PopR;
1798 }
1799  
1800 sub Nasm::X86::Variable::equals($$$) # Equals operator.
1801 0 ▶ {my ($op, $left, $right) = @_; # Operator, left variable, right variable
Subroutine equals: not called CC=1 SCAR=6.9
1802 0 $op
1803 }
1804  
1805 sub Nasm::X86::Variable::assign($$$) # Assign to the left hand side the value of the right hand side.
1806 0 ▶ {my ($left, $op, $right) = @_; # Left variable, operator, right variable
Subroutine assign: not called CC=6 SCAR=37.4
1807 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
1808  
1809 0 Comment "Variable assign";
1810 0 PushR (r14, r15);
1811 0 Mov r14, $left ->address;
1812 0 ▶ if ($left->reference) # Dereference left if necessary
Branch: 1 branch
BranchTrueFalseTotal
if ($left->reference) 0 0 0
1813 0 {Mov r14, "[r14]";
1814 }
1815 0 ▶ if (!ref($right)) # Load right constant
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $right) { } 0 0 0
1816 0 {Mov r15, $right;
1817 }
1818 else # Load right variable
1819 0 {Mov r15, $right->address;
1820 0 ▶ if ($right->reference) # Dereference right if necessary
Branch: 1 branch
BranchTrueFalseTotal
if ($right->reference) 0 0 0
1821 0 {Mov r15, "[r15]";
1822 }
1823 }
1824 0 &$op(r14, r15);
1825 0 ▶ if ($left->reference) # Store in reference on left if necessary
Branch: 1 branch
BranchTrueFalseTotal
if ($left->reference) { } 0 0 0
1826 0 {PushR r13;
1827 0 Mov r13, $left->address;
1828 0 Mov "[r13]", r14;
1829 0 PopR r13;
1830 }
1831 else # Store in variable
1832 0 {Mov $left ->address, r14;
1833 }
1834 0 PopR;
1835  
1836 0 $left;
1837 }
1838  
1839 sub Nasm::X86::Variable::plusAssign($$) # Implement plus and assign.
1840 0 ▶ {my ($left, $right) = @_; # Left variable, right variable
Subroutine plusAssign: not called CC=1 SCAR=6.9
1841 0 $left->assign(\&Add, $right);
1842 }
1843  
1844 sub Nasm::X86::Variable::minusAssign($$) # Implement minus and assign.
1845 0 ▶ {my ($left, $right) = @_; # Left variable, right variable
Subroutine minusAssign: not called CC=1 SCAR=6.9
1846 0 $left->assign(\&Sub, $right);
1847 }
1848  
1849 sub Nasm::X86::Variable::arithmetic($$$$) # Return a variable containing the result of an arithmetic operation on the left hand and right hand side variables.
1850 0 ▶ {my ($op, $name, $left, $right) = @_; # Operator, operator name, Left variable, right variable
Subroutine arithmetic: not called CC=6 SCAR=37.4
1851  
1852 0 my $l = $left ->address;
1853 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
1854  
1855 0 Comment "Arithmetic Start";
1856 0 PushR (r14, r15);
1857 0 Mov r15, $l;
1858 0 ▶ if ($left->reference) # Dereference left if necessary
Branch: 1 branch
BranchTrueFalseTotal
if ($left->reference) 0 0 0
1859 0 {Mov r15, "[r15]";
1860 }
1861 0 Mov r14, $r;
1862 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
1863 0 {Mov r14, "[r14]";
1864 }
1865 0 &$op(r15, r14);
1866 0 ▶ my $v = V(join(' ', '('.$left->name, $name, (ref($right) ? $right->name : $right).')'), r15);
Branch: 1 branch
BranchTrueFalseTotal
ref $right ? : 0 0 0
1867 0 PopR;
1868 0 Comment "Arithmetic End";
1869  
1870 0 return $v;
1871 }
1872  
1873 sub Nasm::X86::Variable::add($$) # Add the right hand variable to the left hand variable and return the result as a new variable.
1874 0 ▶ {my ($left, $right) = @_; # Left variable, right variable
Subroutine add: not called CC=1 SCAR=6.9
1875 0 Nasm::X86::Variable::arithmetic(\&Add, q(add), $left, $right);
1876 }
1877  
1878 sub Nasm::X86::Variable::sub($$) # Subtract the right hand variable from the left hand variable and return the result as a new variable.
1879 0 ▶ {my ($left, $right) = @_; # Left variable, right variable
Subroutine sub: not called CC=1 SCAR=6.9
1880 0 Nasm::X86::Variable::arithmetic(\&Sub, q(sub), $left, $right);
1881 }
1882  
1883 sub Nasm::X86::Variable::times($$) # Multiply the left hand variable by the right hand variable and return the result as a new variable.
1884 0 ▶ {my ($left, $right) = @_; # Left variable, right variable
Subroutine times: not called CC=1 SCAR=6.9
1885 0 Nasm::X86::Variable::arithmetic(\&Imul, q(times), $left, $right);
1886 }
1887  
1888 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.
1889 0 ▶ {my ($op, $left, $right) = @_; # Operator, Left variable, right variable
Subroutine division: not called CC=7 SCAR=40.3
1890  
1891 0 my $l = $left ->address;
1892 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
1893 0 PushR my @regs = (rax, rdx, r15);
1894 0 Mov rax, $l;
1895 0 ▶ Mov rax, "[rax]" if $left->reference;
Branch: 1 branch
BranchTrueFalseTotal
if $left->reference 0 0 0
1896 0 Mov r15, $r;
1897 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
1898 0 Idiv r15;
1899 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
1900 0 PopR @regs;
1901 0 $v;
1902 }
1903  
1904 sub Nasm::X86::Variable::divide($$) # Divide the left hand variable by the right hand variable and return the result as a new variable.
1905 0 ▶ {my ($left, $right) = @_; # Left variable, right variable
Subroutine divide: not called CC=1 SCAR=6.9
1906 0 Nasm::X86::Variable::division("/", $left, $right);
1907 }
1908  
1909 sub Nasm::X86::Variable::mod($$) # Divide the left hand variable by the right hand variable and return the remainder as a new variable.
1910 0 ▶ {my ($left, $right) = @_; # Left variable, right variable
Subroutine mod: not called CC=1 SCAR=6.9
1911 0 Nasm::X86::Variable::division("%", $left, $right);
1912 }
1913  
1914 sub Nasm::X86::Variable::boolean($$$$) # Combine the left hand variable with the right hand variable via a boolean operator.
1915 0 ▶ {my ($sub, $op, $left, $right) = @_; # Operator, operator name, Left variable, right variable
Subroutine boolean: not called CC=9 SCAR=45.0
1916  
1917 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
1918 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
1919  
1920 0 Comment "Boolean Arithmetic Start";
1921 0 PushR r15;
1922  
1923 0 Mov r15, $left ->address;
1924 0 ▶ if ($left->reference) # Dereference left if necessary
Branch: 1 branch
BranchTrueFalseTotal
if ($left->reference) 0 0 0
1925 0 {Mov r15, "[r15]";
1926 }
1927 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
1928 0 {PushR r14;
1929 0 Mov r14, $right ->address;
1930 0 Mov r14, "[r14]";
1931 0 Cmp r15, r14;
1932 0 PopR r14;
1933 }
1934 elsif (ref($right)) # Variable but not a reference on the right
1935 0 {Cmp r15, $right->address;
1936 }
1937 else # Constant on the right
1938 0 {Cmp r15, $right;
1939 }
1940  
1941 0 ▶ &$sub(sub {Mov r15, 1}, sub {Mov r15, 0});
Subroutine __ANON__: not called CC=1 SCAR=6.9
1942 0 ▶ my $v = V(join(' ', '('.$left->name, $op, (ref($right) ? $right->name : '').')'), r15);
Branch: 1 branch
BranchTrueFalseTotal
ref $right ? : 0 0 0
1943  
1944 0 PopR r15;
1945 0 Comment "Boolean Arithmetic end";
1946  
1947 0 $v
1948 }
1949  
1950 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.
1951 0 ▶ {my ($sub, $op, $left, $right) = @_; # Operator, operator name, Left variable, right variable
Subroutine booleanZF: not called CC=8 SCAR=42.8
1952  
1953 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
1954 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
1955  
1956 0 Comment "Boolean ZF Arithmetic Start";
1957 0 PushR r15;
1958  
1959 0 Mov r15, $left ->address;
1960 0 ▶ if ($left->reference) # Dereference left if necessary
Branch: 1 branch
BranchTrueFalseTotal
if ($left->reference) 0 0 0
1961 0 {Mov r15, "[r15]";
1962 }
1963 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
1964 0 {PushR r14;
1965 0 Mov r14, $right ->address;
1966 0 Mov r14, "[r14]";
1967 0 Cmp r15, r14;
1968 0 PopR r14;
1969 }
1970 elsif (ref($right)) # Variable but not a reference on the right
1971 0 {Cmp r15, $right->address;
1972 }
1973 else # Constant on the right
1974 0 {Cmp r15, $right;
1975 }
1976  
1977 0 ▶ &$sub(sub {Cmp rsp, rsp}, sub {Test rsp, rsp});
Subroutine __ANON__: not called CC=1 SCAR=6.9
1978  
1979 0 PopR r15;
1980 0 Comment "Boolean ZF Arithmetic end";
1981  
1982 0 V(empty); # Return an empty variable so that If regenerates the follow on code
1983 }
1984  
1985 sub Nasm::X86::Variable::booleanC($$$$) # Combine the left hand variable with the right hand variable via a boolean operator using a conditional move instruction.
1986 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
1987  
1988 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
1989 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
1990  
1991 0 PushR r15;
1992 0 Mov r15, $left ->address;
1993 0 ▶ if ($left->reference) # Dereference left if necessary
Branch: 1 branch
BranchTrueFalseTotal
if ($left->reference) 0 0 0
1994 0 {Mov r15, "[r15]";
1995 }
1996 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
1997 0 {PushR r14;
1998 0 Mov r14, $right ->address;
1999 0 Mov r14, "[r14]";
2000 0 Cmp r15, r14;
2001 0 PopR r14;
2002 }
2003 elsif (ref($right)) # Variable but not a reference on the right
2004 0 {Cmp r15, $right->address;
2005 }
2006 else # Constant on the right
2007 0 {Cmp r15, $right;
2008 }
2009  
2010 0 Mov r15, 1; # Place a one below the stack
2011 0 my $w = RegisterSize r15;
2012 0 Mov "[rsp-$w]", r15;
2013 0 Mov r15, 0; # Assume the result was false
2014 0 &$cmov(r15, "[rsp-$w]"); # Indicate true result
2015 0 ▶ my $v = V(join(' ', '('.$left->name, $op, (ref($right) ? $right->name : '').')'), r15);
Branch: 1 branch
BranchTrueFalseTotal
ref $right ? : 0 0 0
2016 0 PopR r15;
2017  
2018 0 $v
2019 }
2020  
2021 sub Nasm::X86::Variable::eq($$) # Check whether the left hand variable is equal to the right hand variable.
2022 0 ▶ {my ($left, $right) = @_; # Left variable, right variable
Subroutine eq: not called CC=1 SCAR=6.9
2023 0 Nasm::X86::Variable::booleanZF(\&IfEq, q(eq), $left, $right);
2024 }
2025  
2026 sub Nasm::X86::Variable::ne($$) # Check whether the left hand variable is not equal to the right hand variable.
2027 0 ▶ {my ($left, $right) = @_; # Left variable, right variable
Subroutine ne: not called CC=1 SCAR=6.9
2028 0 Nasm::X86::Variable::booleanZF(\&IfNe, q(ne), $left, $right);
2029 }
2030  
2031 sub Nasm::X86::Variable::ge($$) # Check whether the left hand variable is greater than or equal to the right hand variable.
2032 0 ▶ {my ($left, $right) = @_; # Left variable, right variable
Subroutine ge: not called CC=1 SCAR=6.9
2033 0 Nasm::X86::Variable::booleanZF(\&IfGe, q(ge), $left, $right);
2034 }
2035  
2036 sub Nasm::X86::Variable::gt($$) # Check whether the left hand variable is greater than the right hand variable.
2037 0 ▶ {my ($left, $right) = @_; # Left variable, right variable
Subroutine gt: not called CC=1 SCAR=6.9
2038 0 Nasm::X86::Variable::booleanZF(\&IfGt, q(gt), $left, $right);
2039 }
2040  
2041 sub Nasm::X86::Variable::le($$) # Check whether the left hand variable is less than or equal to the right hand variable.
2042 0 ▶ {my ($left, $right) = @_; # Left variable, right variable
Subroutine le: not called CC=1 SCAR=6.9
2043 0 Nasm::X86::Variable::booleanZF(\&IfLe, q(le), $left, $right);
2044 }
2045  
2046 sub Nasm::X86::Variable::lt($$) # Check whether the left hand variable is less than the right hand variable.
2047 0 ▶ {my ($left, $right) = @_; # Left variable, right variable
Subroutine lt: not called CC=1 SCAR=6.9
2048 0 Nasm::X86::Variable::booleanZF(\&IfLt, q(lt), $left, $right);
2049 }
2050  
2051 sub Nasm::X86::Variable::isRef($) # Check whether the specified variable is a reference to another variable.
2052 0 ▶ {my ($variable) = @_; # Variable
Subroutine isRef: not called CC=1 SCAR=6.9
2053 0 my $n = $variable->name; # Variable name
2054 0 $variable->reference
2055 }
2056  
2057 sub Nasm::X86::Variable::setReg($$) # Set the named registers from the content of the variable.
2058 0 ▶ {my ($variable, $register) = @_; # Variable, register to load
Subroutine setReg: not called CC=2 SCAR=17.9
2059  
2060 0 ▶ if ($variable->isRef)
Branch: 1 branch
BranchTrueFalseTotal
if ($variable->isRef) { } 0 0 0
2061 0 {Mov $register, $variable->address;
2062 0 Mov $register, "[$register]";
2063 }
2064 else
2065 0 {Mov $register, $variable->address;
2066 }
2067  
2068 0 $register
2069 }
2070  
2071 sub Nasm::X86::Variable::getReg($$@) # Load the variable from the named registers.
2072 0 ▶ {my ($variable, $register, @registers) = @_; # Variable, register to load, optional further registers to load from
Subroutine getReg: not called CC=4 SCAR=30.0
2073 0 ▶ if ($variable->isRef) # Move to the location referred to by this variable
Branch: 1 branch
BranchTrueFalseTotal
if ($variable->isRef) { } 0 0 0
2074 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
2075 0 Comment "Get variable value from register $register";
2076 0 ▶ my $r = $register eq r15 ? r14 : r15;
Branch: 1 branch
BranchTrueFalseTotal
$register eq r15() ? : 0 0 0
2077 0 PushR $r;
2078 0 Mov $r, $variable->address;
2079 0 Mov "[$r]", $register;
2080 0 PopR $r;
2081 }
2082 else # Move to this variable
2083 0 {Mov $variable->address, $register;
2084 }
2085 0 $variable # Chain
2086 }
2087  
2088 sub Nasm::X86::Variable::getConst($$;$) # Load the variable from a constant in effect setting a variable to a specified value.
2089 0 ▶ {my ($variable, $constant, $transfer) = @_; # Variable, constant to load, optional transfer register
Subroutine getConst: not called CC=2 SCAR=17.9
2090 0 ▶ if ($transfer)
Branch: 1 branch
BranchTrueFalseTotal
if ($transfer) { } 0 0 0
2091 0 {Mov $transfer, $constant;
2092 0 $variable->getReg($transfer);
2093 }
2094 else
2095 0 {PushR r15;
2096 0 Mov r15, $constant;
2097 0 $variable->getReg(r15);
2098 0 PopR;
2099 }
2100 }
2101  
2102 sub Nasm::X86::Variable::getConst22($$) # Load the variable from a constant in effect setting a variable to a specified value.
2103 0 ▶ {my ($variable, $constant) = @_; # Variable, constant to load
Subroutine getConst22: not called CC=1 SCAR=6.9
2104 0 PushR (r14, r15);
2105 0 Comment "Load constant $constant into variable: ".$variable->name;
2106 0 Mov r15, $constant;
2107 0 Lea r14, $variable->address;
2108 0 Mov "[r14]", r15;
2109 0 PopR;
2110 }
2111  
2112 sub Nasm::X86::Variable::incDec($$) # Increment or decrement a variable.
2113 0 ▶ {my ($left, $op) = @_; # Left variable operator, address of operator to perform inc or dec
Subroutine incDec: not called CC=3 SCAR=24.8
2114 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
2115 0 my $l = $left->address;
2116 0 ▶ if ($left->reference)
Branch: 1 branch
BranchTrueFalseTotal
if ($left->reference) { } 0 0 0
2117 0 {PushR (r14, r15);
2118 0 Mov r15, $l;
2119 0 Mov r14, "[r15]";
2120 0 &$op(r14);
2121 0 Mov "[r15]", r14;
2122 0 PopR;
2123 0 return $left;
2124 }
2125 else
2126 0 {PushR r15;
2127 0 Mov r15, $l;
2128 0 &$op(r15);
2129 0 Mov $l, r15;
2130 0 PopR r15;
2131 0 return $left;
2132 }
2133 }
2134  
2135 sub Nasm::X86::Variable::inc($) # Increment a variable.
2136 0 ▶ {my ($left) = @_; # Variable
Subroutine inc: not called CC=1 SCAR=6.9
2137 0 $left->incDec(\&Inc);
2138 }
2139  
2140 sub Nasm::X86::Variable::dec($) # Decrement a variable.
2141 0 ▶ {my ($left) = @_; # Variable
Subroutine dec: not called CC=1 SCAR=6.9
2142 0 $left->incDec(\&Dec);
2143 }
2144  
2145 sub Nasm::X86::Variable::str($) # The name of the variable.
2146 0 ▶ {my ($left) = @_; # Variable
Subroutine str: not called CC=1 SCAR=6.9
2147 0 $left->name;
2148 }
2149  
2150 sub Nasm::X86::Variable::min($$) # Minimum of two variables.
2151 0 ▶ {my ($left, $right) = @_; # Left variable, right variable or constant
Subroutine min: not called CC=2 SCAR=17.9
2152 0 PushR (r12, r14, r15);
2153 0 $left->setReg(r14);
2154  
2155 0 ▶ if (ref($right)) # Right hand side is a variable
Branch: 1 branch
BranchTrueFalseTotal
if (ref $right) { } 0 0 0
2156 0 {$right->setReg(r15);
2157 }
2158 else # Right hand side is a constant
2159 0 {Mov r15, $right;
2160 }
2161  
2162 0 Cmp r14, r15;
2163 0 Cmovg r12, r15;
2164 0 Cmovle r12, r14;
2165 0 my $r = V("min", r12);
2166 0 PopR;
2167 0 $r
2168 }
2169  
2170 sub Nasm::X86::Variable::max($$) # Maximum of two variables.
2171 0 ▶ {my ($left, $right) = @_; # Left variable, right variable or constant
Subroutine max: not called CC=2 SCAR=17.9
2172 0 PushR (r12, r14, r15);
2173 0 $left->setReg(r14);
2174  
2175 0 ▶ if (ref($right)) # Right hand side is a variable
Branch: 1 branch
BranchTrueFalseTotal
if (ref $right) { } 0 0 0
2176 0 {$right->setReg(r15);
2177 }
2178 else # Right hand side is a constant
2179 0 {Mov r15, $right;
2180 }
2181  
2182 0 Cmp r14, r15;
2183 0 Cmovg r12, r14;
2184 0 Cmovle r12, r15;
2185  
2186 0 my $r = V("max", r12);
2187 0 PopR;
2188 0 $r
2189 }
2190  
2191 sub Nasm::X86::Variable::and($$) # And two variables.
2192 0 ▶ {my ($left, $right) = @_; # Left variable, right variable
Subroutine and: not called CC=1 SCAR=6.9
2193 0 PushR (r14, r15);
2194 0 Mov r14, 0;
2195 0 $left->setReg(r15);
2196 0 Cmp r15, 0;
2197 &IfNe (
2198 sub
2199 0 ▶ {$right->setReg(r15);
Subroutine __ANON__: not called CC=1 SCAR=6.9
2200 0 Cmp r15, 0;
2201 0 ▶ &IfNe(sub {Add r14, 1});
Subroutine __ANON__: not called CC=1 SCAR=6.9
2202 }
2203 0 );
2204 0 my $r = V("And(".$left->name.", ".$right->name.")", r14);
2205 0 PopR;
2206 0 $r
2207 }
2208  
2209 sub Nasm::X86::Variable::or($$) # Or two variables.
2210 0 ▶ {my ($left, $right) = @_; # Left variable, right variable
Subroutine or: not called CC=1 SCAR=6.9
2211 0 PushR (r14, r15);
2212 0 Mov r14, 1;
2213 0 $left->setReg(r15);
2214 0 Cmp r15, 0;
2215 &IfEq (
2216 sub
2217 0 ▶ {$right->setReg(r15);
Subroutine __ANON__: not called CC=1 SCAR=6.9
2218 0 Cmp r15, 0;
2219 0 ▶ &IfEq(sub {Mov r14, 0});
Subroutine __ANON__: not called CC=1 SCAR=6.9
2220 }
2221 0 );
2222 0 my $r = V("Or(".$left->name.", ".$right->name.")", r14);
2223 0 PopR;
2224 0 $r
2225 }
2226  
2227 sub Nasm::X86::Variable::setMask($$$) # Set the mask register to ones starting at the specified position for the specified length and zeroes elsewhere.
2228 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
2229 0 ▶ @_ == 3 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess() 0 0 0
2230  
2231 0 PushR (r13, r14, r15);
2232 0 Mov r15, -1;
2233 0 ▶ if ($start) # Non zero start
Branch: 1 branch
BranchTrueFalseTotal
if ($start) { } 0 0 0
2234 0 {$start->setReg(r14);
2235 0 Bzhi r15, r15, r14;
2236 0 Not r15;
2237 0 ▶ ref($length) or confess "Not a variable";
Branch: 1 branch
BranchTrueFalseTotal
ref $length or confess("Not a variable") 0 0 0
2238 0 $length->setReg(r13);
2239 0 Add r14, r13;
2240 }
2241 else # Starting at zero
2242 0 {confess "Deprecated: use setMaskFirst instead";
2243 0 $length->setReg(r13);
2244 0 Mov r14, $length;
2245 }
2246 0 Bzhi r15, r15, r14;
2247 0 Kmovq $mask, r15;
2248 0 PopR;
2249 }
2250  
2251 sub Nasm::X86::Variable::setMaskFirst($$) # Set the first bits in the specified mask register.
2252 0 ▶ {my ($length, $mask) = @_; # Variable containing length to set, mask register
Subroutine setMaskFirst: not called CC=4 SCAR=30.0
2253 0 ▶ @_ == 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess() 0 0 0
2254  
2255 0 PushR my @save = my ($l, $b) = ChooseRegisters(2, $mask); # Choose two registers not the mask register
2256 0 Mov $b, -1;
2257 0 $length->setReg($l);
2258 0 Bzhi $b, $b, $l;
2259 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
2260 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
2261 0 PopR;
2262 }
2263  
2264 sub Nasm::X86::Variable::setMaskBit($$) # Set a bit in the specified mask register retaining the other bits.
2265 0 ▶ {my ($index, $mask) = @_; # Variable containing bit position to set, mask register
Subroutine setMaskBit: not called CC=3 SCAR=24.8
2266 0 ▶ @_ == 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess() 0 0 0
2267 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
2268 0 PushR my @save = my ($l, $b) = (r14, r15);
2269 0 Kmovq $b, $mask;
2270 0 $index->setReg($l);
2271 0 Bts $b, $l;
2272 0 Kmovq $mask, $b; # Set mask register if provided
2273 0 PopR;
2274 }
2275  
2276 sub Nasm::X86::Variable::clearMaskBit($$) # Clear a bit in the specified mask register retaining the other bits.
2277 0 ▶ {my ($index, $mask) = @_; # Variable containing bit position to clear, mask register
Subroutine clearMaskBit: not called CC=3 SCAR=24.8
2278 0 ▶ @_ == 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess() 0 0 0
2279 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
2280  
2281 0 PushR my @save = my ($l, $b) = (r14, r15);
2282 0 Kmovq $b, $mask;
2283 0 $index->setReg($l);
2284 0 Btc $b, $l;
2285 0 Kmovq $mask, $b; # Set mask register if provided
2286 0 PopR;
2287 }
2288  
2289 sub Nasm::X86::Variable::setBit($$) # Set a bit in the specified register retaining the other bits.
2290 0 ▶ {my ($index, $mask) = @_; # Variable containing bit position to set, mask register
Subroutine setBit: not called CC=2 SCAR=17.9
2291 0 ▶ @_ == 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess() 0 0 0
2292  
2293 0 PushR my @save = my ($l) = ChooseRegisters(1, $mask); # Choose a register
2294 0 $index->setReg($l);
2295 0 Bts $mask, $l;
2296 0 PopR;
2297 }
2298  
2299 sub Nasm::X86::Variable::clearBit($$) # Clear a bit in the specified mask register retaining the other bits.
2300 0 ▶ {my ($index, $mask) = @_; # Variable containing bit position to clear, mask register
Subroutine clearBit: not called CC=2 SCAR=17.9
2301 0 ▶ @_ == 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess() 0 0 0
2302  
2303 0 PushR my @save = my ($l) = ChooseRegisters(1, $mask); # Choose a register
2304 0 $index->setReg($l);
2305 0 Btc $mask, $l;
2306 0 PopR;
2307 }
2308  
2309 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.
2310 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
2311 0 ▶ @_ == 4 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 4 or confess() 0 0 0
2312 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
2313 0 Comment "Set Zmm $zmm from Memory";
2314 0 PushR (k7, r14, r15);
2315 0 $offset->setMask($length, k7); # Set mask for target
2316 0 $source->setReg(r15);
2317 0 $offset->setReg(r14); # Position memory for target
2318 0 Sub r15, r14; # Position memory for target
2319 0 Vmovdqu8 "zmm${zmm}{k7}", "[r15]"; # Read from memory
2320 0 PopR;
2321 }
2322  
2323 sub Nasm::X86::Variable::loadZmm($$) # Load bytes from the memory addressed by the specified source variable into the numbered zmm register.
2324 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
2325 0 ▶ @_ == 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess() 0 0 0
2326 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
2327 0 {Comment "Load zmm$zmm from memory addressed by ".$source->name;
2328 0 PushR r15;
2329 0 $source->setReg(r15);
2330 0 Vmovdqu8 "zmm$zmm", "[r15]";
2331 0 PopR r15;
2332 }
2333 elsif ($source->size == 6) # Load from Vz
2334 0 {Comment "Load zmm$zmm from ".$source->name;
2335 0 Vmovdqu8 "zmm$zmm", $source->address;
2336 }
2337 }
2338  
2339 sub loadFromZmm($*$$) # Load the specified register from the offset located in the numbered zmm.
2340 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
2341 0 ▶ @_ == 4 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 4 or confess() 0 0 0
2342 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
2343  
2344 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
2345  
2346 0 PushRR "zmm$zmm"; # Push source register
2347  
2348 0 ClearRegisters $register;
2349  
2350 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
2351 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
2352 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
2353 0 ▶ Mov $register, "[rsp+$offset]" if $size =~ m(q); # Load register from offset
Branch: 1 branch
BranchTrueFalseTotal
if $size =~ /q/ 0 0 0
2354 0 Add rsp, RegisterSize "zmm$zmm"; # Pop source register
2355 }
2356  
2357 sub putIntoZmm($*$$) # Put the specified register into the numbered zmm at the specified offset in the zmm.
2358 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
2359 0 ▶ @_ == 4 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 4 or confess() 0 0 0
2360 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
2361  
2362 0 PushR "zmm$zmm"; # Push source register
2363  
2364 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
2365 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
2366 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
2367 0 ▶ Mov "[rsp+$offset]", $register, if $size =~ m(q); # Load register from offset
Branch: 1 branch
BranchTrueFalseTotal
if $size =~ /q/ 0 0 0
2368 0 PopR "zmm$zmm"; # Reload zmm
2369 }
2370  
2371 sub LoadRegFromMm($$$) # Load the specified register from the numbered zmm at the quad offset specified as a constant number.
2372 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
2373 0 ▶ @_ == 3 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess() 0 0 0
2374 0 my $w = RegisterSize $mm; # Size of mm register
2375 0 Vmovdqu64 "[rsp-$w]", $mm; # Write below the stack
2376 0 Mov $reg, "[rsp+8*$offset-$w]"; # Load register from offset
2377 }
2378  
2379 sub SaveRegIntoMm($$$) # Save the specified register into the numbered zmm at the quad offset specified as a constant number.
2380 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
2381 0 ▶ @_ == 3 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess() 0 0 0
2382 0 my $w = RegisterSize $mm; # Size of mm register
2383 0 Vmovdqu64 "[rsp-$w]", $mm; # Write below the stack
2384 0 Mov "[rsp+8*$offset-$w]", $reg; # Save register into offset
2385 0 Vmovdqu64 $mm, "[rsp-$w]"; # Reload from the stack
2386 }
2387  
2388 sub getBwdqFromMm($$$;$$) # Get the numbered byte|word|double word|quad word from the numbered zmm register and return it in a variable.
2389 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
2390 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
2391 0 my $w = RegisterSize $mm; # Size of mm register
2392 0 ▶ CheckNumberedGeneralPurposeRegister $Transfer if $Transfer; # Check that we have a numbered register
Branch: 1 branch
BranchTrueFalseTotal
if $Transfer 0 0 0
2393 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
2394  
2395 0 my $o; # The offset into the mm register
2396 0 ▶ if (ref($offset)) # The offset is being passed in a variable
Branch: 1 branch
BranchTrueFalseTotal
if (ref $offset) { } 0 0 0
2397 0 {my $name = $offset->name;
2398 0 PushR ($o = r14);
2399 0 $offset->setReg($o);
2400 }
2401 else # The offset is being passed as a register expression
2402 0 {$o = $offset;
2403 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
2404 confess "Out of range" if $offset =~ m(\A\d+\Z); # Check the offset if it is a number
2405 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
2406 confess "Cannot pass offset: '$offset', in r15, choose another register";
2407 }
2408  
2409 0 ▶ PushR $transfer unless $Transfer;
Branch: 1 branch
BranchTrueFalseTotal
unless $Transfer 0 0 0
2410 0 Vmovdqu32 "[rsp-$w]", $mm; # Write below the stack
2411  
2412 0 ▶ if ($size !~ m(q|d)) # Clear the register if necessary
Branch: 1 branch
BranchTrueFalseTotal
unless ($size =~ /q|d/) 0 0 0
2413 0 {ClearRegisters r15;
2414 }
2415  
2416 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
2417 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
2418 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
2419 0 ▶ Mov $transfer, "[rsp+$o-$w]" if $size =~ m(q); # Load register from offset
Branch: 1 branch
BranchTrueFalseTotal
if $size =~ /q/ 0 0 0
2420  
2421 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
2422 0 {$target->getReg($transfer); # Load variable directly
2423 0 ▶ PopR $o if ref($offset); # The offset is being passed in a variable
Branch: 1 branch
BranchTrueFalseTotal
if ref $offset 0 0 0
2424 0 return $target; # Return variable
2425 }
2426 else # Unable to optimize load
2427 0 {my $v = V("$size at offset $offset in $mm", $transfer); # Create variable
2428 0 ▶ PopR $transfer unless $Transfer;
Branch: 1 branch
BranchTrueFalseTotal
unless $Transfer 0 0 0
2429 0 ▶ PopR $o if ref($offset); # The offset is being passed in a variable
Branch: 1 branch
BranchTrueFalseTotal
if ref $offset 0 0 0
2430 0 return $v # Return variable
2431 }
2432 }
2433  
2434 sub getBFromXmm($$) # Get the byte from the numbered xmm register and return it in a variable.
2435 0 ▶ {my ($xmm, $offset) = @_; # Numbered xmm, offset in bytes
Subroutine getBFromXmm: not called CC=1 SCAR=6.9
Pod documented
2436 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
2437 }
2438  
2439 sub getWFromXmm($$) # Get the word from the numbered xmm register and return it in a variable.
2440 0 ▶ {my ($xmm, $offset) = @_; # Numbered xmm, offset in bytes
Subroutine getWFromXmm: not called CC=1 SCAR=6.9
Pod documented
2441 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
2442 }
2443  
2444 sub getDFromXmm($$) # Get the double word from the numbered xmm register and return it in a variable.
2445 0 ▶ {my ($xmm, $offset) = @_; # Numbered xmm, offset in bytes
Subroutine getDFromXmm: not called CC=1 SCAR=6.9
Pod documented
2446 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
2447 }
2448  
2449 sub getQFromXmm($$) # Get the quad word from the numbered xmm register and return it in a variable.
2450 0 ▶ {my ($xmm, $offset) = @_; # Numbered xmm, offset in bytes
Subroutine getQFromXmm: not called CC=1 SCAR=6.9
Pod documented
2451 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
2452 }
2453  
2454 sub getBFromZmm($$) # Get the byte from the numbered zmm register and return it in a variable.
2455 0 ▶ {my ($zmm, $offset) = @_; # Numbered zmm, offset in bytes
Subroutine getBFromZmm: not called CC=1 SCAR=6.9
Pod documented
2456 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
2457 }
2458  
2459 sub getWFromZmm($$) # Get the word from the numbered zmm register and return it in a variable.
2460 0 ▶ {my ($zmm, $offset) = @_; # Numbered zmm, offset in bytes
Subroutine getWFromZmm: not called CC=1 SCAR=6.9
Pod documented
2461 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
2462 }
2463  
2464 sub getDFromZmm($$$) # Get the double word from the numbered zmm register and return it in a variable.
2465 0 ▶ {my ($zmm, $offset, $transfer) = @_; # Numbered zmm, offset in bytes, optional transfer register
Subroutine getDFromZmm: not called CC=1 SCAR=6.9
Pod documented
2466 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
2467 }
2468  
2469 sub getQFromZmm($$) # Get the quad word from the numbered zmm register and return it in a variable.
2470 0 ▶ {my ($zmm, $offset) = @_; # Numbered zmm, offset in bytes
Subroutine getQFromZmm: not called CC=1 SCAR=6.9
Pod documented
2471 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
2472 }
2473  
2474 sub Nasm::X86::Variable::getBFromZmm($$$) # Get the byte from the numbered zmm register and put it in a variable.
2475 0 ▶ {my ($variable, $zmm, $offset) = @_; # Variable, numbered zmm, offset in bytes
Subroutine getBFromZmm: not called CC=1 SCAR=6.9
2476 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
2477 }
2478  
2479 sub Nasm::X86::Variable::getWFromZmm($$$) # Get the word from the numbered zmm register and put it in a variable.
2480 0 ▶ {my ($variable, $zmm, $offset) = @_; # Variable, numbered zmm, offset in bytes
Subroutine getWFromZmm: not called CC=1 SCAR=6.9
2481 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
2482 }
2483  
2484 sub Nasm::X86::Variable::getDFromZmm($$$;$) # Get the double word from the numbered zmm register and put it in a variable.
2485 0 ▶ {my ($variable, $zmm, $offset, $transfer) = @_; # Variable, numbered zmm, offset in bytes, transfer register
Subroutine getDFromZmm: not called CC=1 SCAR=6.9
2486 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
2487 0 $variable # Return input variable so we can assign or chain
2488 }
2489  
2490 sub Nasm::X86::Variable::getQFromZmm($$$) # Get the quad word from the numbered zmm register and put it in a variable.
2491 0 ▶ {my ($variable, $zmm, $offset) = @_; # Variable, numbered zmm, offset in bytes
Subroutine getQFromZmm: not called CC=1 SCAR=6.9
2492 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
2493 }
2494  
2495 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.
2496 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
2497 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
2498 0 ▶ CheckNumberedGeneralPurposeRegister $Transfer if $Transfer;
Branch: 1 branch
BranchTrueFalseTotal
if $Transfer 0 0 0
2499 0 my $w = RegisterSize $mm; # Size of mm register
2500 0 my ($temp) = ChooseRegisters(1, r14);
2501 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
2502 0 my $o; # The offset into the mm register
2503  
2504 0 ▶ if (ref($offset)) # The offset is being passed in a variable
Branch: 1 branch
BranchTrueFalseTotal
if (ref $offset) { } 0 0 0
2505 0 {my $name = $offset->name;
2506 0 Comment "Put $size at $name in $mm";
2507 0 PushR ($o = r14);
2508 0 $offset->setReg($o);
2509 }
2510 else # The offset is being passed as a register expression
2511 0 {$o = $offset;
2512 0 Comment "Put $size at $offset in $mm";
2513 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
2514 confess "Out of range" if $offset =~ m(\A\d+\Z); # Check the offset if it is a number
2515 }
2516  
2517 0 my @save = ($transfer);
2518 0 ▶ PushR @save unless $Transfer; # Push target register
Branch: 1 branch
BranchTrueFalseTotal
unless $Transfer 0 0 0
2519 0 $content->setReg($transfer);
2520 0 Vmovdqu32 "[rsp-$w]", $mm; # Write below the stack
2521 0 ▶ Mov "[rsp+$o-$w]", $transfer."b" if $size =~ m(b); # Write byte register
Branch: 1 branch
BranchTrueFalseTotal
if $size =~ /b/ 0 0 0
2522 0 ▶ Mov "[rsp+$o-$w]", $transfer."w" if $size =~ m(w); # Write word register
Branch: 1 branch
BranchTrueFalseTotal
if $size =~ /w/ 0 0 0
2523 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
2524 0 ▶ Mov "[rsp+$o-$w]", $transfer if $size =~ m(q); # Write register
Branch: 1 branch
BranchTrueFalseTotal
if $size =~ /q/ 0 0 0
2525 0 Vmovdqu32 $mm, "[rsp-$w]"; # Read below the stack
2526 0 ▶ PopR @save unless $Transfer;
Branch: 1 branch
BranchTrueFalseTotal
unless $Transfer 0 0 0
2527  
2528 0 ▶ PopR $o if ref($offset); # The offset is being passed in a variable
Branch: 1 branch
BranchTrueFalseTotal
if ref $offset 0 0 0
2529 }
2530  
2531 sub Nasm::X86::Variable::putBIntoXmm($$$) # Place the value of the content variable at the byte in the numbered xmm register.
2532 0 ▶ {my ($content, $xmm, $offset) = @_; # Variable with content, numbered xmm, offset in bytes
Subroutine putBIntoXmm: not called CC=1 SCAR=6.9
2533 0 $content->putBwdqIntoMm('b', "xmm$xmm", $offset) # Place the value of the content variable at the word in the numbered xmm register
2534 }
2535  
2536 sub Nasm::X86::Variable::putWIntoXmm($$$) # Place the value of the content variable at the word in the numbered xmm register.
2537 0 ▶ {my ($content, $xmm, $offset) = @_; # Variable with content, numbered xmm, offset in bytes
Subroutine putWIntoXmm: not called CC=1 SCAR=6.9
2538 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
2539 }
2540  
2541 sub Nasm::X86::Variable::putDIntoXmm($$$) # Place the value of the content variable at the double word in the numbered xmm register.
2542 0 ▶ {my ($content, $xmm, $offset) = @_; # Variable with content, numbered xmm, offset in bytes
Subroutine putDIntoXmm: not called CC=1 SCAR=6.9
2543 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
2544 }
2545  
2546 sub Nasm::X86::Variable::putQIntoXmm($$$) # Place the value of the content variable at the quad word in the numbered xmm register.
2547 0 ▶ {my ($content, $xmm, $offset) = @_; # Variable with content, numbered xmm, offset in bytes
Subroutine putQIntoXmm: not called CC=1 SCAR=6.9
2548 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
2549 }
2550  
2551 sub Nasm::X86::Variable::putBIntoZmm($$$) # Place the value of the content variable at the byte in the numbered zmm register.
2552 0 ▶ {my ($content, $zmm, $offset) = @_; # Variable with content, numbered zmm, offset in bytes
Subroutine putBIntoZmm: not called CC=2 SCAR=17.9
2553 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
2554 0 $content->putBwdqIntoMm('b', "zmm$zmm", $offset) # Place the value of the content variable at the word in the numbered zmm register
2555 }
2556  
2557 sub Nasm::X86::Variable::putWIntoZmm($$$) # Place the value of the content variable at the word in the numbered zmm register.
2558 0 ▶ {my ($content, $zmm, $offset) = @_; # Variable with content, numbered zmm, offset in bytes
Subroutine putWIntoZmm: not called CC=2 SCAR=17.9
2559 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
2560 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
2561 }
2562  
2563 sub Nasm::X86::Variable::putDIntoZmm($$$;$) # Place the value of the content variable at the double word in the numbered zmm register.
2564 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
2565 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
2566 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
2567 }
2568  
2569 sub Nasm::X86::Variable::putQIntoZmm($$$;$) # Place the value of the content variable at the quad word in the numbered zmm register.
2570 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
2571 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
2572 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
2573 }
2574  
2575 #D2 Broadcast # Broadcast from a variable into a zmm
2576  
2577 sub Nasm::X86::Variable::zBroadCastD($$) # Broadcast a double word in a variable into the numbered zmm.
2578 0 ▶ {my ($variable, $zmm) = @_; # Variable containing value to broadcast, numbered zmm to broadcast to
Subroutine zBroadCastD: not called CC=1 SCAR=6.9
2579 0 PushR (r15);
2580 0 $variable->setReg(r15); # Value of variable
2581 0 Vpbroadcastd "zmm".$zmm, r15d; # Broadcast
2582 0 PopR;
2583 }
2584  
2585 #D2 Stack # Push and pop variables to and from the stack
2586  
2587 sub Nasm::X86::Variable::push($) # Push a variable onto the stack.
2588 0 ▶ {my ($variable) = @_; # Variable
Subroutine push: not called CC=1 SCAR=6.9
2589 0 PushR rax; Push rax; # Make a slot on the stack and save rax
2590 0 $variable->setReg(rax); # Variable to rax
2591 0 my $s = RegisterSize rax; # Size of rax
2592 0 Mov "[rsp+$s]", rax; # Move variable to slot
2593 0 PopR rax; # Remove rax to leave variable on top of the stack
2594 }
2595  
2596 sub Nasm::X86::Variable::pop($) # Pop a variable from the stack.
2597 0 ▶ {my ($variable) = @_; # Variable
Subroutine pop: not called CC=1 SCAR=6.9
2598 0 PushR rax; # Liberate a register
2599 0 my $s = RegisterSize rax; # Size of rax
2600 0 Mov rax, "[rsp+$s]"; # Load from stack
2601 0 $variable->getReg(rax); # Variable to rax
2602 0 PopR rax; # Remove rax to leave variable on top of the stack
2603 0 Add rsp, $s; # Remove variable from stack
2604 }
2605  
2606 #D2 Memory # Actions on memory described by variables
2607  
2608 sub Nasm::X86::Variable::clearMemory($$) # Clear the memory described in this variable.
2609 0 ▶ {my ($address, $size) = @_; # Address of memory to clear, size of the memory to clear
Subroutine clearMemory: not called CC=1 SCAR=6.9
2610 0 &ClearMemory(size=>$size, address=>$address); # Free the memory
2611 }
2612  
2613 sub Nasm::X86::Variable::copyMemory($$$) # Copy from one block of memory to another.
2614 0 ▶ {my ($target, $source, $size) = @_; # Address of target, address of source, length to copy
Subroutine copyMemory: not called CC=2 SCAR=17.9
2615 0 ▶ @_ == 3 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess() 0 0 0
2616 # $target->name eq q(target) or confess "Need target";
2617 # $source->name eq q(source) or confess "Need source";
2618 # $size ->name eq q(size) or confess "Need size";
2619 0 &CopyMemory(target => $target, source => $source, size => $size); # Copy the memory
2620 }
2621  
2622 sub Nasm::X86::Variable::printMemoryInHexNL($$$) # Write, in hexadecimal, the memory addressed by a variable to stdout or stderr.
2623 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
2624 0 ▶ @_ == 3 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess() 0 0 0
2625 # $address->name eq q(address) or confess "Need address";
2626 # $size ->name eq q(size) or confess "Need size";
2627 0 PushR (rax, rdi);
2628 0 $address->setReg(rax);
2629 0 $size->setReg(rdi);
2630 0 &PrintMemoryInHex($channel);
2631 0 &PrintNL($channel);
2632 0 PopR;
2633 }
2634  
2635 sub Nasm::X86::Variable::printErrMemoryInHexNL($$) # Write the memory addressed by a variable to stderr.
2636 0 ▶ {my ($address, $size) = @_; # Address of memory, number of bytes to print
Subroutine printErrMemoryInHexNL: not called CC=1 SCAR=6.9
2637 0 $address->printMemoryInHexNL($stderr, $size);
2638 }
2639  
2640 sub Nasm::X86::Variable::printOutMemoryInHexNL($$) # Write the memory addressed by a variable to stdout.
2641 0 ▶ {my ($address, $size) = @_; # Address of memory, number of bytes to print
Subroutine printOutMemoryInHexNL: not called CC=1 SCAR=6.9
2642 0 $address->printMemoryInHexNL($stdout, $size);
2643 }
2644  
2645 sub Nasm::X86::Variable::freeMemory($$) # Free the memory addressed by this variable for the specified length.
2646 0 ▶ {my ($address, $size) = @_; # Address of memory to free, size of the memory to free
Subroutine freeMemory: not called CC=3 SCAR=24.8
2647 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
2648 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
2649 0 &FreeMemory(size=>$size, address=>$address); # Free the memory
2650 }
2651  
2652 sub Nasm::X86::Variable::allocateMemory(@) # Allocate the specified amount of memory via mmap and return its address.
2653 0 ▶ {my ($size) = @_; # Size
Subroutine allocateMemory: not called CC=3 SCAR=24.8
2654 0 ▶ @_ >= 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 1 or confess() 0 0 0
2655 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
2656 0 &AllocateMemory(size => $size, my $a = V(address));
2657 0 $a
2658 }
2659  
2660 #D2 Structured Programming with variables # Structured programming operations driven off variables.
2661  
2662 sub Nasm::X86::Variable::for($&) # Iterate the block limit times.
2663 0 ▶ {my ($limit, $block) = @_; # Limit, Block
Subroutine for: not called CC=2 SCAR=17.9
2664 0 ▶ @_ == 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess() 0 0 0
2665 0 Comment "Variable::For $limit";
2666 0 my $index = V(q(index), 0); # The index that will be incremented
2667 0 my $start = Label;
2668 0 my $next = Label;
2669 0 my $end = Label;
2670 0 SetLabel $start; # Start of loop
2671  
2672 0 ▶ If $index >= $limit, sub {Jge $end}; # Condition
Subroutine __ANON__: not called CC=1 SCAR=6.9
2673  
2674 0 &$block($index, $start, $next, $end); # Execute block
2675  
2676 0 SetLabel $next; # Next iteration
2677 0 $index++; # Increment
2678 0 Jmp $start;
2679 0 SetLabel $end;
2680 }
2681  
2682 #D1 Stack # Manage data on the stack
2683  
2684 #D2 Push, Pop, Peek # Generic versions of push, pop, peek
2685  
2686 sub PushRR(@) #P Push registers onto the stack without tracking.
2687 0 ▶ {my (@r) = @_; # Register
Subroutine PushRR: not called CC=5 SCAR=34.0
Pod documented
2688 0 for my $r(@r)
2689 0 {my $size = RegisterSize $r;
2690 0 ▶ $size or confess "No such register: $r";
Branch: 1 branch
BranchTrueFalseTotal
$size or confess("No such register: $r") 0 0 0
2691 0 ▶ if ($size > 8) # Wide registers
Branch: 2 branches
BranchTrueFalseTotal
if ($size > 8) { } 0 0 0
elsif ($r =~ /\Ak/) { } 0 0 0
2692 0 {Sub rsp, $size;
2693 0 Vmovdqu32 "[rsp]", $r;
2694 }
2695 elsif ($r =~ m(\Ak)) # Mask as they do not respond to push
2696 0 {Sub rsp, $size;
2697 0 Kmovq "[rsp]", $r;
2698 }
2699 else # Normal register
2700 0 {Push $r;
2701 }
2702 }
2703 }
2704  
2705 1 my @PushR; # Track pushes
2706  
2707 sub PushR(@) #P Push registers onto the stack.
2708 0 ▶ {my (@r) = @_; # Register
Subroutine PushR: not called CC=1 SCAR=6.9
Pod documented
2709 0 push @PushR, [@r];
2710 0 PushRR @r; # Push
2711 }
2712  
2713 sub PopRR(@) #P Pop registers from the stack without tracking.
2714 0 ▶ {my (@r) = @_; # Register
Subroutine PopRR: not called CC=4 SCAR=30.0
Pod documented
2715 0 for my $r(reverse @r) # Pop registers in reverse order
2716 0 {my $size = RegisterSize $r;
2717 0 ▶ if ($size > 8)
Branch: 2 branches
BranchTrueFalseTotal
if ($size > 8) { } 0 0 0
elsif ($r =~ /\Ak/) { } 0 0 0
2718 0 {Vmovdqu32 $r, "[rsp]";
2719 0 Add rsp, $size;
2720 }
2721 elsif ($r =~ m(\Ak))
2722 0 {Kmovq $r, "[rsp]";
2723 0 Add rsp, $size;
2724 }
2725 else
2726 0 {Pop $r;
2727 }
2728 }
2729 }
2730  
2731 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.
2732 0 ▶ {my (@r) = @_; # Register
Subroutine PopR: not called CC=4 SCAR=30.0
Pod documented
2733 0 ▶ @PushR or confess "No stacked registers";
Branch: 1 branch
BranchTrueFalseTotal
@PushR or confess("No stacked registers") 0 0 0
2734 0 my $r = pop @PushR;
2735 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
2736 0 PopRR @$r; # Pop registers from the stack without tracking
2737 }
2738  
2739 sub PopEax() # We cannot pop a double word from the stack in 64 bit long mode using pop so we improvise.
2740 0 ▶ {my $l = RegisterSize eax; # Eax is half rax
Subroutine PopEax: not called CC=1 SCAR=6.9
Pod documented
2741 0 Mov eax, "[rsp]";
2742 0 Add rsp, RegisterSize eax;
2743 }
2744  
2745 sub PeekR($) # Peek at register on stack.
2746 0 ▶ {my ($r) = @_; # Register
Subroutine PeekR: not called CC=2 SCAR=17.9
Pod documented
2747 0 my $size = RegisterSize $r;
2748 0 ▶ if ($size > 8) # X|y|zmm*
Branch: 1 branch
BranchTrueFalseTotal
if ($size > 8) { } 0 0 0
2749 0 {Vmovdqu32 $r, "[rsp]";
2750 }
2751 else # General purpose 8 byte register
2752 0 {Mov $r, "[rsp]";
2753 }
2754 }
2755  
2756 my @PushZmm; # Zmm pushes
2757  
2758 sub PushZmm(@) # Push several zmm registers.
2759 0 ▶ {my (@Z) = @_; # Zmm register numbers
Subroutine PushZmm: not called CC=3 SCAR=24.8
Pod documented
2760 0 ▶ if (@Z)
Branch: 1 branch
BranchTrueFalseTotal
if (@Z) 0 0 0
2761 0 {my @z = zmm @Z;
2762 0 my $w = RegisterSize zmm0;
2763 0 Sub rsp, @z * $w;
2764 0 for my $i(keys @z)
2765 0 {Vmovdqu64 "[rsp+$w*$i]", $z[$i];
2766 }
2767 0 push @PushZmm, [@Z];
2768 }
2769 }
2770  
2771 sub PopZmm # Pop zmm registers.
2772 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
2773 0 my $z = pop @PushZmm;
2774 0 my @z = zmm @$z;
2775 0 my $w = RegisterSize zmm0;
2776 0 for my $i(keys @z)
2777 0 {Vmovdqu64 $z[$i], "[rsp+$w*$i]";
2778 }
2779 0 Add rsp, @z * $w;
2780 }
2781  
2782 1 my @PushMask; # Mask pushes
2783  
2784 sub PushMask(@) # Push several Mask registers.
2785 0 ▶ {my (@M) = @_; # Mask register numbers
Subroutine PushMask: not called CC=3 SCAR=24.8
Pod documented
2786 0 ▶ if (@M)
Branch: 1 branch
BranchTrueFalseTotal
if (@M) 0 0 0
2787 0 {my @m = map {"k$_"} @M;
2788 0 my $w = RegisterSize k0;
2789 0 Sub rsp, @m * $w;
2790 0 for my $i(keys @m)
2791 0 {Kmovq "[rsp+$w*$i]", $m[$i];
2792 }
2793 0 push @PushMask, [@M];
2794 }
2795 }
2796  
2797 sub PopMask # Pop Mask registers.
2798 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
2799 0 my $m = pop @PushMask;
2800 0 my @m = map {"k$_"} @$m;
2801 0 my $w = RegisterSize k0;
2802 0 for my $i(keys @m)
2803 0 {Kmovq $m[$i], "[rsp+$w*$i]";
2804 }
2805 0 Add rsp, @m * $w;
2806 }
2807  
2808 #D2 Declarations # Declare variables and structures
2809  
2810 #D3 Structures # Declare a structure
2811  
2812 sub Structure() # Create a structure addressed by a register.
2813 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
2814 0 my $local = genHash(__PACKAGE__."::Structure",
2815 size => 0,
2816 variables => [],
2817 );
2818 }
2819  
2820 sub Nasm::X86::Structure::field($$;$) # Add a field of the specified length with an optional comment.
2821 0 ▶ {my ($structure, $length, $comment) = @_; # Structure data descriptor, length of data, optional comment
Subroutine field: not called CC=2 SCAR=17.9
2822 0 ▶ @_ >= 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 or confess() 0 0 0
2823 0 my $variable = genHash(__PACKAGE__."::StructureField",
2824 structure => $structure, # Structure containing the field
2825 loc => $structure->size, # Offset of the field
2826 size => $length, # Size of the field
2827 comment => $comment # Comment describing the purpose of the field
2828 );
2829 0 $structure->size += $length; # Update size of local data
2830 0 push $structure->variables->@*, $variable; # Save variable
2831 0 $variable
2832 }
2833  
2834 sub Nasm::X86::StructureField::addr($;$) # Address a field in a structure by either the default register or the named register.
2835 0 ▶ {my ($field, $register) = @_; # Field, optional address register else rax
Subroutine addr: not called CC=3 SCAR=24.8
2836 0 ▶ @_ <= 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ <= 2 or confess() 0 0 0
2837 0 my $loc = $field->loc; # Offset of field in structure
2838 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
2839 0 "[$loc+$reg]" # Address field
2840 }
2841  
2842 sub All8Structure($) # Create a structure consisting of 8 byte fields.
2843 0 ▶ {my ($N) = @_; # Number of variables required
Subroutine All8Structure: not called CC=3 SCAR=24.8
Pod documented
2844 0 ▶ @_ == 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess() 0 0 0
2845 0 my $s = Structure; # Structure of specified size based on specified register
2846 0 my @f;
2847 0 my $z = RegisterSize rax;
2848 0 for(1..$N) # Create the variables
2849 0 {push @f, $s->field($z);
2850 }
2851 0 ($s, @f) # Structure, fields
2852 }
2853  
2854 #D3 Stack Frame # Declare local variables in a frame on the stack
2855  
2856 sub LocalData() # Map local data.
2857 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
2858 0 my $local = genHash(__PACKAGE__."::LocalData",
2859 size => 0,
2860 variables => [],
2861 );
2862 }
2863  
2864 sub Nasm::X86::LocalData::start($) # Start a local data area on the stack.
2865 0 ▶ {my ($local) = @_; # Local data descriptor
Subroutine start: not called CC=2 SCAR=17.9
2866 0 ▶ @_ == 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess() 0 0 0
2867 0 my $size = $local->size; # Size of local data
2868 0 Push rbp;
2869 0 Mov rbp,rsp;
2870 0 Sub rsp, $size;
2871 }
2872  
2873 sub Nasm::X86::LocalData::free($) # Free a local data area on the stack.
2874 0 ▶ {my ($local) = @_; # Local data descriptor
Subroutine free: not called CC=2 SCAR=17.9
2875 0 ▶ @_ == 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess() 0 0 0
2876 0 Mov rsp, rbp;
2877 0 Pop rbp;
2878 }
2879  
2880 sub Nasm::X86::LocalData::variable($$;$) # Add a local variable.
2881 0 ▶ {my ($local, $length, $comment) = @_; # Local data descriptor, length of data, optional comment
Subroutine variable: not called CC=2 SCAR=17.9
2882 0 ▶ @_ >= 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 or confess() 0 0 0
2883 0 my $variable = genHash(__PACKAGE__."::LocalVariable",
2884 loc => $local->size,
2885 size => $length,
2886 comment => $comment
2887 );
2888 0 $local->size += $length; # Update size of local data
2889 0 $variable
2890 }
2891  
2892 sub Nasm::X86::LocalVariable::stack($) # Address a local variable on the stack.
2893 0 ▶ {my ($variable) = @_; # Variable
Subroutine stack: not called CC=5 SCAR=34.0
2894 0 ▶ @_ == 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess() 0 0 0
2895 0 my $l = $variable->loc; # Location of variable on stack
2896 0 my $S = $variable->size;
2897 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
2898 0 "${s}[rbp-$l]" # Address variable - offsets are negative per Tino
2899 }
2900  
2901 sub Nasm::X86::LocalData::allocate8($@) # Add some 8 byte local variables and return an array of variable definitions.
2902 0 ▶ {my ($local, @comments) = @_; # Local data descriptor, optional comment
Subroutine allocate8: not called CC=3 SCAR=24.8
2903 0 my @v;
2904 0 for my $c(@comments)
2905 0 {push @v, Nasm::X86::LocalData::variable($local, 8, $c);
2906 }
2907 0 ▶ wantarray ? @v : $v[-1]; # Avoid returning the number of elements accidently
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
2908 }
2909  
2910 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...).
2911 0 ▶ {my ($N) = @_; # Number of variables required
Subroutine AllocateAll8OnStack: not called CC=2 SCAR=17.9
Pod documented
2912 0 my $local = LocalData; # Create local data descriptor
2913 0 my @v;
2914 0 for(1..$N) # Create the variables
2915 0 {my $v = $local->variable(RegisterSize(rax));
2916 0 push @v, $v->stack;
2917 }
2918 0 $local->start; # Create the local data area on the stack
2919 0 ($local, @v)
2920 }
2921  
2922 #D1 Operating system # Interacting with the operating system.
2923  
2924 #D2 Processes # Create and manage processes
2925  
2926 sub Fork() # Fork.
2927 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
2928 0 Comment "Fork";
2929 0 Mov rax, 57;
2930 0 Syscall
2931 }
2932  
2933 sub GetPid() # Get process identifier.
2934 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
2935 0 Comment "Get Pid";
2936  
2937 0 Mov rax, 39;
2938 0 Syscall
2939 }
2940  
2941 sub GetPidInHex() # Get process identifier in hex as 8 zero terminated bytes in rax.
2942 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
2943 0 Comment "Get Pid";
2944 0 my $hexTranslateTable = hexTranslateTable;
2945  
2946 my $sub = Macro
2947 0 ▶ {SaveFirstFour;
Subroutine __ANON__: not called CC=2 SCAR=17.9
2948 0 Mov rax, 39; # Get pid
2949 0 Syscall;
2950 0 Mov rdx, rax; # Content to be printed
2951  
2952 0 ClearRegisters rax; # Save a trailing 00 on the stack
2953 0 Push ax;
2954 0 for my $i(reverse 5..7)
2955 0 {my $s = 8*$i;
2956 0 Mov rdi,rdx;
2957 0 Shl rdi,$s; # Push selected byte high
2958 0 Shr rdi,56; # Push select byte low
2959 0 Shl rdi,1; # Multiply by two because each entry in the translation table is two bytes long
2960 0 Mov ax, "[$hexTranslateTable+rdi]";
2961 0 Push ax;
2962 }
2963 0 Pop rax; # Get result from stack
2964 0 RestoreFirstFourExceptRax;
2965 0 } name => "GetPidInHex";
2966  
2967 0 Call $sub;
2968 }
2969  
2970 sub GetPPid() # Get parent process identifier.
2971 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
2972 0 Comment "Get Parent Pid";
2973  
2974 0 Mov rax, 110;
2975 0 Syscall
2976 }
2977  
2978 sub GetUid() # Get userid of current process.
2979 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
2980 0 Comment "Get User id";
2981  
2982 0 Mov rax, 102;
2983 0 Syscall
2984 }
2985  
2986 sub WaitPid() # Wait for the pid in rax to complete.
2987 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
2988 0 Comment "WaitPid - wait for the pid in rax";
2989  
2990 my $sub = Macro
2991 0 ▶ {SaveFirstSeven;
Subroutine __ANON__: not called CC=1 SCAR=6.9
2992 0 Mov rdi,rax;
2993 0 Mov rax, 61;
2994 0 Mov rsi, 0;
2995 0 Mov rdx, 0;
2996 0 Mov r10, 0;
2997 0 Syscall;
2998 0 RestoreFirstSevenExceptRax;
2999 0 } name => "WaitPid";
3000  
3001 0 Call $sub;
3002 }
3003  
3004 sub ReadTimeStampCounter() # Read the time stamp counter and return the time in nanoseconds in rax.
3005 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
3006  
3007 my $sub = Macro
3008 0 ▶ {Comment "Read Time-Stamp Counter";
Subroutine __ANON__: not called CC=1 SCAR=6.9
3009 0 PushR rdx;
3010 0 ClearRegisters rax;
3011 0 Cpuid;
3012 0 Rdtsc;
3013 0 Shl rdx,32;
3014 0 Or rax,rdx;
3015 0 PopR;
3016 0 } name => "ReadTimeStampCounter";
3017  
3018 0 Call $sub;
3019 }
3020  
3021 #D2 Memory # Allocate and print memory
3022  
3023 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 .
3024 0 ▶ {my ($channel) = @_; # Channel
Subroutine PrintMemoryInHex: not called CC=2 SCAR=17.9
Pod documented
3025 0 ▶ @_ == 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess() 0 0 0
3026 0 Comment "Print out memory in hex on channel: $channel";
3027  
3028 Call Macro
3029 0 ▶ {my $size = RegisterSize rax;
Subroutine __ANON__: not called CC=1 SCAR=6.9
3030 0 SaveFirstFour;
3031  
3032 0 Test rdi, 0x7; # Round the number of bytes to be printed
3033 IfNz
3034 Then # Round up
3035 0 ▶ {Add rdi, 8;
Subroutine __ANON__: not called CC=1 SCAR=6.9
3036 0 };
3037 0 And rdi, 0x3f8; # Limit the number of bytes to be printed to 1024
3038  
3039 0 Mov rsi, rax; # Position in memory
3040 0 Lea rdi,"[rax+rdi-$size+1]"; # Upper limit of printing with an 8 byte register
3041 For # Print string in blocks
3042 0 ▶ {Mov rax, "[rsi]";
Subroutine __ANON__: not called CC=1 SCAR=6.9
3043 0 Bswap rax;
3044 0 PrintRaxInHex($channel);
3045 0 } rsi, rdi, $size;
3046 0 RestoreFirstFour;
3047 0 } name=> "PrintOutMemoryInHexOnChannel$channel";
3048 }
3049  
3050 sub PrintErrMemoryInHex # Dump memory from the address in rax for the length in rdi on stderr.
3051 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
3052 0 PrintMemoryInHex($stderr);
3053 }
3054  
3055 sub PrintOutMemoryInHex # Dump memory from the address in rax for the length in rdi on stdout.
3056 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
3057 0 PrintMemoryInHex($stdout);
3058 }
3059  
3060 sub PrintErrMemoryInHexNL # Dump memory from the address in rax for the length in rdi and then print a new line.
3061 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
3062 0 PrintMemoryInHex($stderr);
3063 0 PrintNL($stderr);
3064 }
3065  
3066 sub PrintOutMemoryInHexNL # Dump memory from the address in rax for the length in rdi and then print a new line.
3067 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
3068 0 PrintMemoryInHex($stdout);
3069 0 PrintNL($stdout);
3070 }
3071  
3072 sub PrintMemory($) # Print the memory addressed by rax for a length of rdi on the specified channel.
3073 0 ▶ {my ($channel) = @_; # Channel
Subroutine PrintMemory: not called CC=2 SCAR=17.9
Pod documented
3074 0 ▶ @_ == 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess() 0 0 0
3075  
3076 Call Macro
3077 0 ▶ {Comment "Print memory on channel: $channel";
Subroutine __ANON__: not called CC=1 SCAR=6.9
3078 0 SaveFirstFour rax, rdi;
3079 0 Mov rsi, rax;
3080 0 Mov rdx, rdi;
3081 0 Mov rax, 1;
3082 0 Mov rdi, $channel;
3083 0 Syscall;
3084 0 RestoreFirstFour();
3085 0 } name => "PrintOutMemoryOnChannel$channel";
3086 }
3087  
3088 sub PrintMemoryNL # Print the memory addressed by rax for a length of rdi on the specified channel followed by a new line.
3089 0 ▶ {my ($channel) = @_; # Channel
Subroutine PrintMemoryNL: not called CC=2 SCAR=17.9
Pod documented
3090 0 ▶ @_ == 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess() 0 0 0
3091 0 PrintMemory($channel);
3092 0 PrintNL($channel);
3093 }
3094  
3095 sub PrintErrMemory # Print the memory addressed by rax for a length of rdi on stderr.
3096 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
3097 0 PrintMemory($stdout);
3098 }
3099  
3100 sub PrintOutMemory # Print the memory addressed by rax for a length of rdi on stdout.
3101 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
3102 0 PrintMemory($stdout);
3103 }
3104  
3105 sub PrintErrMemoryNL # Print the memory addressed by rax for a length of rdi followed by a new line on stderr.
3106 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
3107 0 PrintErrMemory;
3108 0 PrintErrNL;
3109 }
3110  
3111 sub PrintOutMemoryNL # Print the memory addressed by rax for a length of rdi followed by a new line on stdout.
3112 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
3113 0 PrintOutMemory;
3114 0 PrintOutNL;
3115 }
3116  
3117 sub AllocateMemory(@) # Allocate the specified amount of memory via mmap and return its address.
3118 0 ▶ {my (@variables) = @_; # Parameters
Subroutine AllocateMemory: not called CC=2 SCAR=17.9
Pod documented
3119 0 ▶ @_ >= 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 or confess() 0 0 0
3120  
3121 my $s = Subroutine
3122 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
3123 0 Comment "Allocate memory";
3124 0 SaveFirstSeven;
3125 0 my $d = extractMacroDefinitionsFromCHeaderFile "linux/mman.h"; # Memory map constants
3126 0 my $pa = $$d{MAP_PRIVATE} | $$d{MAP_ANONYMOUS};
3127 0 my $wr = $$d{PROT_WRITE} | $$d{PROT_READ};
3128  
3129 0 Mov rax, 9; # Memory map
3130 0 $$p{size}->setReg(rsi); # Amount of memory
3131 0 Xor rdi, rdi; # Anywhere
3132 0 Mov rdx, $wr; # Read write protections
3133 0 Mov r10, $pa; # Private and anonymous map
3134 0 Mov r8, -1; # File descriptor for file backing memory if any
3135 0 Mov r9, 0; # Offset into file
3136 0 Syscall;
3137 0 Cmp rax, -1; # Check return code
3138 IfEq(sub
3139 0 ▶ {PrintErrString "Cannot allocate memory, return code -1";
Subroutine __ANON__: not called CC=1 SCAR=6.9
3140 0 $$p{size}->errNL;
3141 0 Exit(1);
3142 0 });
3143 0 Cmp eax, 0xffffffea; # Check return code
3144 IfEq(sub
3145 0 ▶ {PrintErrString "Cannot allocate memory, return code 0xffffffea";
Subroutine __ANON__: not called CC=1 SCAR=6.9
3146 0 $$p{size}->errNL;
3147 0 Exit(1);
3148 0 });
3149 0 Cmp rax, -12; # Check return code
3150 IfEq(sub
3151 0 ▶ {PrintErrString "Cannot allocate memory, return code -12";
Subroutine __ANON__: not called CC=1 SCAR=6.9
3152 0 $$p{size}->errNL;
3153 0 Exit(1);
3154 0 });
3155 0 $$p{address}->getReg(rax); # Amount of memory
3156  
3157 0 RestoreFirstSeven;
3158 0 } [qw(address size)], name => 'AllocateMemory';
3159  
3160 0 $s->call(@variables);
3161 }
3162  
3163 sub FreeMemory(@) # Free memory.
3164 0 ▶ {my (@variables) = @_; # Variables
Subroutine FreeMemory: not called CC=2 SCAR=17.9
Pod documented
3165 0 ▶ @_ >= 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 or confess() 0 0 0
3166 0 Comment "Free memory";
3167  
3168 my $s = Subroutine
3169 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
3170 0 SaveFirstFour;
3171 0 Mov rax, 11; # Munmap
3172 0 $$p{address}->setReg(rdi); # Address
3173 0 $$p{size} ->setReg(rsi); # Length
3174 0 Syscall;
3175 0 RestoreFirstFour;
3176 0 } [qw(size address)], name=> 'FreeMemory';
3177  
3178 0 $s->call(@variables);
3179 }
3180  
3181 sub ClearMemory(@) # Clear memory.
3182 0 ▶ {my (@variables) = @_; # Variables
Subroutine ClearMemory: not called CC=2 SCAR=17.9
Pod documented
3183 0 ▶ @_ >= 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 or confess() 0 0 0
3184 0 Comment "Clear memory";
3185  
3186 my $s = Subroutine
3187 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
3188 0 PushR (zmm0, rax, rdi, rsi, rdx);
3189 0 $$p{address}->setReg(rax);
3190 0 $$p{size} ->setReg(rdi);
3191 0 Lea rdx, "[rax+rdi]"; # Address of upper limit of buffer
3192  
3193 0 ClearRegisters zmm0; # Clear the register that will be written into memory
3194  
3195 0 Mov rsi, rdi; # Modulus the size of zmm
3196 0 And rsi, 0x3f; # Remainder modulo 64
3197 0 Cmp rsi, 0; # Test remainder
3198 IfNz sub # Need to align so that the rest of the clear can be done in full zmm blocks
3199 0 ▶ {PushR k7;
Subroutine __ANON__: not called CC=1 SCAR=6.9
3200 0 V(align, rsi)->setMaskFirst(k7); # Set mask bits
3201 0 Vmovdqu8 "[rax]{k7}", zmm0; # Masked move to memory
3202 0 PopR;
3203 0 Add rax, rsi; # Update point to clear from
3204 0 Sub rdi, rsi; # Reduce clear length
3205 0 };
3206  
3207 For # Clear remaining memory in full zmm blocks
3208 0 ▶ {Vmovdqu64 "[rax]", zmm0;
Subroutine __ANON__: not called CC=1 SCAR=6.9
3209 0 } rax, rdx, RegisterSize zmm0;
3210  
3211 0 PopR;
3212 0 } [qw(size address)], name => 'ClearMemory';
3213  
3214 0 $s->call(@variables);
3215 }
3216  
3217 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.
3218 0 ▶ {my (@variables) = @_; # Variables
Subroutine MaskMemory22: not called CC=2 SCAR=17.9
Pod documented
3219 0 ▶ @_ >= 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 or confess() 0 0 0
3220 0 Comment "Clear memory";
3221  
3222 0 my $size = RegisterSize zmm0;
3223  
3224 my $s = Subroutine
3225 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
3226 0 PushR (k6, k7, rax, rdi, rsi, rdx, r8, r9, r10, zmm0, zmm1, zmm2);
3227 0 $$p{source}->setReg(rax);
3228 0 $$p{mask} ->setReg(rdx);
3229 0 $$p{match} ->setReg(rsi);
3230 0 $$p{set} ->setReg(rdi);
3231 0 $$p{size} ->setReg(r8);
3232 0 Lea r9, "[rax+r8]"; # Address of upper limit of source
3233  
3234 0 Vpbroadcastb zmm1, rsi; # Character to match
3235 0 Vpbroadcastb zmm2, rdi; # Character to write into mask
3236  
3237 0 Mov r10, r8; # Modulus the size of zmm
3238 0 And r10, 0x3f;
3239 0 Test r10, r10;
3240 IfNz sub # Need to align so that the rest of the clear can be done in full zmm blocks
3241 0 ▶ {V(align, r10)->setMaskFirst(k7); # Set mask bits
Subroutine __ANON__: not called CC=1 SCAR=6.9
3242 0 Vmovdqu8 "zmm0\{k7}", "[rax]"; # Load first incomplete block of source
3243 0 Vpcmpub "k6{k7}", zmm0, zmm1, 0; # Characters in source that match
3244 0 Vmovdqu8 "[rdx]{k6}", zmm2; # Write set byte into mask at match points
3245 0 Add rax, r10; # Update point to mask from
3246 0 Add rdx, r10; # Update point to mask to
3247 0 Sub r8, r10; # Reduce mask length
3248 0 };
3249  
3250 For # Clear remaining memory in full zmm blocks
3251 0 ▶ {Vmovdqu8 zmm0, "[rax]"; # Load complete block of source
Subroutine __ANON__: not called CC=1 SCAR=6.9
3252 0 Vpcmpub "k7", zmm0, zmm1, 0; # Characters in source that match
3253 0 Vmovdqu8 "[rdx]{k7}", zmm2; # Write set byte into mask at match points
3254 0 Add rdx, $size; # Update point to mask to
3255 0 } rax, r9, $size;
3256  
3257 0 PopR;
3258 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.
3259  
3260 0 $s->call(@variables);
3261 }
3262  
3263 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.
3264 0 ▶ {my (@variables) = @_; # Variables
Subroutine MaskMemoryInRange4_22: not called CC=2 SCAR=17.9
Pod documented
3265 0 ▶ @_ >= 6 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 6 or confess() 0 0 0
3266 0 Comment "Clear memory";
3267  
3268 0 my $size = RegisterSize zmm0;
3269  
3270 my $s = Subroutine
3271 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
3272 0 PushR (k4, k5, k6, k7, zmm(0..9), map{"r$_"} qw(ax di si dx), 8..15);
3273 0 $$p{source}->setReg(rax);
3274 0 $$p{mask} ->setReg(rdx);
3275 0 $$p{low} ->setReg(r10);
3276 0 $$p{high} ->setReg(r11);
3277 0 $$p{set} ->setReg(rdi);
3278 0 $$p{size} ->setReg(rsi);
3279  
3280 0 Vpbroadcastb zmm1, rdi; # Character to write into mask
3281 0 Vpbroadcastb zmm2, r10; # Character 1 low
3282 0 Shr r10, 8; Vpbroadcastb zmm3, r10; # Character 2 low
3283 0 Shr r10, 8; Vpbroadcastb zmm4, r10; # Character 3 low
3284 0 Shr r10, 8; Vpbroadcastb zmm5, r10; # Character 4 low
3285 0 Vpbroadcastb zmm6, r11; # Character 1 high
3286 0 Shr r11, 8; Vpbroadcastb zmm7, r11; # Character 2 high
3287 0 Shr r11, 8; Vpbroadcastb zmm8, r11; # Character 3 high
3288 0 Shr r11, 8; Vpbroadcastb zmm9, r11; # Character 4 high
3289 0 Lea r8, "[rax+rsi]"; # Address of upper limit of source
3290  
3291 my sub check($$) # Check a character
3292 0 ▶ {my ($z, $f) = @_; # First zmm, finished label
Subroutine check: not called CC=1 SCAR=6.9
3293 0 my $Z = $z + 4;
3294 0 Vpcmpub "k6{k7}", zmm0, "zmm$z", 5; # Greater than or equal
3295 0 Vpcmpub "k7{k6}", zmm0, "zmm$Z", 2; # Less than or equal
3296 0 Ktestq k7, k7;
3297 0 Jz $f; # No match
3298 0 Kshiftlq k7, k7, 1; # Match - move up to next character
3299 };
3300  
3301 my sub last4() # Expand each set bit four times
3302 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
3303 0 Kshiftlq k6, k7, 2; Kandq k7, k6, k7; # Last four
3304 };
3305  
3306 For # Mask remaining memory in full zmm blocks
3307 0 ▶ {my $finished = Label; # Point where we have finished the initial comparisons
Subroutine __ANON__: not called CC=2 SCAR=17.9
3308 0 Vmovdqu8 zmm0, "[rax]"; # Load complete block of source
3309 0 Kxnorq k7, k7, k7; # Complete block - sets register to all ones
3310 0 check($_, $finished) for 2..5; last4; # Check a range
3311  
3312 0 Vmovdqu8 "[rdx]{k7}", zmm1; # Write set byte into mask at match points
3313 0 Add rdx, $size; # Update point to mask to
3314 0 SetLabel $finished;
3315 0 } rax, r8, $size;
3316  
3317  
3318 0 Mov r10, rsi; And r10, 0x3f; # Modulus the size of zmm
3319 0 Test r10, r10;
3320 IfNz sub # Need to align so that the rest of the mask can be done in full zmm blocks
3321 0 ▶ {my $finished = Label; # Point where we have finished the initial comparisons
Subroutine __ANON__: not called CC=2 SCAR=17.9
3322 0 V(align, r10)->setMaskFirst(k7); # Set mask bits
3323 0 Vmovdqu8 "zmm0\{k7}", "[rax]"; # Load first incomplete block of source
3324 0 check($_, $finished) for 2..5; last4; # Check a range
3325 0 Vmovdqu8 "[rdx]{k7}", zmm1; # Write set byte into mask at match points
3326 0 Add rax, r10; # Update point to mask from
3327 0 Add rdx, r10; # Update point to mask to
3328 0 Sub r8, r10; # Reduce mask length
3329 0 SetLabel $finished;
3330 0 };
3331  
3332 0 PopR;
3333 0 } [qw(size source mask set low high)];
3334  
3335 0 $s->call(@variables);
3336 } # MaskMemoryInRange4
3337  
3338 sub CopyMemory(@) # Copy memory, the target is addressed by rax, the length is in rdi, the source is addressed by rsi.
3339 0 ▶ {my (@variables) = @_; # Variables
Subroutine CopyMemory: not called CC=2 SCAR=17.9
Pod documented
3340 0 ▶ @_ >= 3 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 3 or confess() 0 0 0
3341  
3342 my $s = Subroutine
3343 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
3344 0 Comment "Copy memory";
3345 0 SaveFirstSeven;
3346 0 $$p{source}->setReg(rsi);
3347 0 $$p{target}->setReg(rax);
3348 0 $$p{size} ->setReg(rdi);
3349 0 ClearRegisters rdx;
3350 For # Clear memory
3351 0 ▶ {Mov "r8b", "[rsi+rdx]";
Subroutine __ANON__: not called CC=1 SCAR=6.9
3352 0 Mov "[rax+rdx]", "r8b";
3353 0 } rdx, rdi, 1;
3354 0 RestoreFirstSeven;
3355 0 } [qw(source target size)], name => 'CopyMemory';
3356  
3357 0 $s->call(@variables);
3358 }
3359  
3360 #D2 Files # Interact with the operating system via files.
3361  
3362 sub OpenRead() # Open a file, whose name is addressed by rax, for read and return the file descriptor in rax.
3363 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
3364 0 Comment "Open a file for read";
3365  
3366 my $sub = Macro
3367 0 ▶ {my $S = extractMacroDefinitionsFromCHeaderFile "asm-generic/fcntl.h"; # Constants for reading a file
Subroutine __ANON__: not called CC=1 SCAR=6.9
3368 0 my $O_RDONLY = $$S{O_RDONLY};
3369 0 SaveFirstFour;
3370 0 Mov rdi,rax;
3371 0 Mov rax,2;
3372 0 Mov rsi,$O_RDONLY;
3373 0 Xor rdx,rdx;
3374 0 Syscall;
3375 0 RestoreFirstFourExceptRax;
3376 0 } name=> "OpenRead";
3377  
3378 0 Call $sub;
3379 }
3380  
3381 sub OpenWrite() # Create the file named by the terminated string addressed by rax for write.
3382 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
3383 0 Comment "Open a file for write";
3384  
3385 my $sub = Macro
3386 0 ▶ {my $S = extractMacroDefinitionsFromCHeaderFile "fcntl.h"; # Constants for creating a file
Subroutine __ANON__: not called CC=1 SCAR=6.9
3387 # my $T = extractMacroDefinitionsFromCHeaderFile "sys/stat.h";
3388 0 my $O_WRONLY = $$S{O_WRONLY};
3389 0 my $O_CREAT = $$S{O_CREAT};
3390 0 my $O_RDWR = $$S{O_RDWR};
3391 # my $S_IRUSR = $$T{__S_IREAD};
3392 # my $S_IWUSR = $$T{__S_IWRITE};
3393 0 my $write = $O_WRONLY+0 | $O_CREAT+0;
3394  
3395 0 SaveFirstFour;
3396 # Mov rdi,16;
3397 0 Mov rdi, rax;
3398 0 Mov rax, 2;
3399 0 Mov rsi, $write;
3400 # ClearRegisters rdx;
3401 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
3402 0 Syscall;
3403  
3404 0 RestoreFirstFourExceptRax;
3405 0 } name=> "OpenWrite";
3406  
3407 0 Call $sub;
3408 }
3409  
3410 sub CloseFile() # Close the file whose descriptor is in rax.
3411 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
3412  
3413 my $sub = Macro
3414 0 ▶ {Comment "Close a file";
Subroutine __ANON__: not called CC=1 SCAR=6.9
3415 0 SaveFirstFour;
3416 0 Mov rdi, rax;
3417 0 Mov rax, 3;
3418 0 Syscall;
3419 0 RestoreFirstFourExceptRax;
3420 0 } name=> "CloseFile";
3421  
3422 0 Call $sub;
3423 }
3424  
3425 sub StatSize() # Stat a file whose name is addressed by rax to get its size in rax.
3426 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
3427  
3428 0 my $S = extractCStructure "#include <sys/stat.h>"; # Get location of size field
3429 0 my $Size = $$S{stat}{size};
3430 0 my $off = $$S{stat}{fields}{st_size}{loc};
3431  
3432 my $sub = Macro
3433 0 ▶ {Comment "Stat a file for size";
Subroutine __ANON__: not called CC=1 SCAR=6.9
3434 0 SaveFirstFour rax;
3435 0 Mov rdi, rax; # File name
3436 0 Mov rax,4;
3437 0 Lea rsi, "[rsp-$Size]";
3438 0 Syscall;
3439 0 Mov rax, "[$off+rsp-$Size]"; # Place size in rax
3440 0 RestoreFirstFourExceptRax;
3441 0 } name=> "StatSize";
3442  
3443 0 Call $sub;
3444 }
3445  
3446 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.
3447 0 ▶ {my (@variables) = @_; # Variables
Subroutine ReadFile: not called CC=2 SCAR=17.9
Pod documented
3448 0 ▶ @_ >= 3 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 3 or confess() 0 0 0
3449  
3450 my $s = Subroutine
3451 0 ▶ {my ($p) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
3452 0 Comment "Read a file into memory";
3453 0 SaveFirstSeven; # Generated code
3454 0 my $size = V(size);
3455 0 my $fdes = V(fdes);
3456  
3457 0 $$p{file}->setReg(rax); # File name
3458  
3459 0 StatSize; # File size
3460 0 $size->getReg(rax); # Save file size
3461  
3462 0 $$p{file}->setReg(rax); # File name
3463 0 OpenRead; # Open file for read
3464 0 $fdes->getReg(rax); # Save file descriptor
3465  
3466 0 my $d = extractMacroDefinitionsFromCHeaderFile "linux/mman.h"; # Memory map constants
3467 0 my $pa = $$d{MAP_PRIVATE};
3468 0 my $ro = $$d{PROT_READ};
3469  
3470 0 Mov rax, 9; # Memory map
3471 0 $size->setReg(rsi); # Amount of memory
3472 0 Xor rdi, rdi; # Anywhere
3473 0 Mov rdx, $ro; # Read write protections
3474 0 Mov r10, $pa; # Private and anonymous map
3475 0 $fdes->setReg(r8); # File descriptor for file backing memory
3476 0 Mov r9, 0; # Offset into file
3477 0 Syscall;
3478 0 $size ->setReg(rdi);
3479 0 $$p{address}->getReg(rax);
3480 0 $$p{size} ->getReg(rdi);
3481 0 RestoreFirstSeven;
3482 0 } [qw(file address size)], name => 'ReadFile';
3483  
3484 0 $s->call(@variables);
3485 }
3486  
3487 sub executeFileViaBash(@) # Execute the file named in the arena addressed by rax with bash.
3488 0 ▶ {my (@variables) = @_; # Variables
Subroutine executeFileViaBash: not called CC=2 SCAR=17.9
Pod documented
3489 0 ▶ @_ >= 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 1 or confess() 0 0 0
3490  
3491 my $s = Subroutine
3492 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
3493 0 Comment "Execute a file via bash";
3494 0 SaveFirstFour;
3495 0 Fork; # Fork
3496  
3497 0 Test rax, rax;
3498  
3499 IfNz # Parent
3500 Then
3501 0 ▶ {WaitPid;
Subroutine __ANON__: not called CC=1 SCAR=6.9
3502 },
3503 Else # Child
3504 0 ▶ {$$p{file}->setReg(rdi);
Subroutine __ANON__: not called CC=1 SCAR=6.9
3505 0 Mov rsi, 0;
3506 0 Mov rdx, 0;
3507 0 Mov rax, 59;
3508 0 Syscall;
3509 0 };
3510 0 RestoreFirstFour;
3511 0 } [qw(file)], name => 'executeFileViaBash';
3512  
3513 0 $s->call(@variables);
3514 }
3515  
3516 sub unlinkFile(@) # Unlink the named file.
3517 0 ▶ {my (@variables) = @_; # Variables
Subroutine unlinkFile: not called CC=2 SCAR=17.9
Pod documented
3518 0 ▶ @_ >= 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 1 or confess() 0 0 0
3519  
3520 my $s = Subroutine
3521 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
3522 0 Comment "Unlink a file";
3523 0 SaveFirstFour;
3524 0 $$p{file}->setReg(rdi);
3525 0 Mov rax, 87;
3526 0 Syscall;
3527 0 RestoreFirstFour;
3528 0 } [qw(file)], name => 'unlinkFile';
3529  
3530 0 $s->call(@variables);
3531 }
3532  
3533 #D1 Hash functions # Hash functions
3534  
3535 sub Hash() # Hash a string addressed by rax with length held in rdi and return the hash code in r15.
3536 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
3537  
3538 my $sub = Macro # Read file
3539 0 ▶ {Comment "Hash";
Subroutine __ANON__: not called CC=1 SCAR=6.9
3540  
3541 0 PushR my @regs = (rax, rdi, k1, zmm0, zmm1); # Save registers
3542 0 PushR r15;
3543 0 Vpbroadcastq zmm0, rdi; # Broadcast length through ymm0
3544 0 Vcvtuqq2pd zmm0, zmm0; # Convert to lengths to float
3545 0 Vgetmantps zmm0, zmm0, 4; # Normalize to 1 to 2, see: https://hjlebbink.github.io/x86doc/html/VGETMANTPD.html
3546  
3547 0 Add rdi, rax; # Upper limit of string
3548  
3549 ForIn # Hash in ymm0 sized blocks
3550 0 ▶ {Vmovdqu ymm1, "[rax]"; # Load data to hash
Subroutine __ANON__: not called CC=1 SCAR=6.9
3551 0 Vcvtudq2pd zmm1, ymm1; # Convert to float
3552 0 Vgetmantps zmm0, zmm0, 4; # Normalize to 1 to 2, see: https://hjlebbink.github.io/x86doc/html/VGETMANTPD.html
3553  
3554 0 Vmulpd zmm0, zmm1, zmm0; # Multiply current hash by data
3555 }
3556 sub # Remainder in partial block
3557 0 ▶ {Mov r15, -1;
Subroutine __ANON__: not called CC=1 SCAR=6.9
3558 0 Bzhi r15, r15, rdi; # Clear bits that we do not wish to load
3559 0 Kmovq k1, r15; # Take up mask
3560 0 Vmovdqu8 "ymm1{k1}", "[rax]"; # Load data to hash
3561  
3562 0 Vcvtudq2pd zmm1, ymm1; # Convert to float
3563 0 Vgetmantps zmm0, zmm0, 4; # Normalize to 1 to 2, see: https://hjlebbink.github.io/x86doc/html/VGETMANTPD.html
3564  
3565 0 Vmulpd zmm0, zmm1, zmm0; # Multiply current hash by data
3566 0 }, rax, rdi, RegisterSize ymm0;
3567  
3568 0 Vgetmantps zmm0, zmm0, 4; # Normalize to 1 to 2, see: https://hjlebbink.github.io/x86doc/html/VGETMANTPD.html
3569  
3570 0 Mov r15, 0b11110000; # Top 4 to bottom 4
3571 0 Kmovq k1, r15;
3572 0 Vpcompressq "zmm1{k1}", zmm0;
3573 0 Vaddpd ymm0, ymm0, ymm1; # Top 4 plus bottom 4
3574  
3575 0 Mov r15, 0b1100; # Top 2 to bottom 2
3576 0 Kmovq k1, r15;
3577 0 Vpcompressq "ymm1{k1}", ymm0;
3578 0 Vaddpd xmm0, xmm0, xmm1; # Top 2 plus bottom 2
3579  
3580 0 Pslldq xmm0, 2; # Move centers into double words
3581 0 Psrldq xmm0, 4;
3582 0 Mov r15, 0b0101; # Centers to lower quad
3583 0 Kmovq k1, r15;
3584 0 Vpcompressd "xmm0{k1}", xmm0; # Compress to lower quad
3585 0 PopR r15;
3586  
3587 0 Vmovq r15, xmm0; # Result in r15
3588  
3589 0 PopR @regs;
3590 0 } name=> "Hash";
3591  
3592 0 Call $sub;
3593 }
3594  
3595 #D1 Unicode # Convert utf8 to utf32
3596  
3597 sub GetNextUtf8CharAsUtf32(@) # Get the next utf8 encoded character from the addressed memory and return it as a utf32 char.
3598 0 ▶ {my (@parameters) = @_; # Parameters
Subroutine GetNextUtf8CharAsUtf32: not called CC=2 SCAR=17.9
Pod documented
3599 0 ▶ @_ >= 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 1 or confess() 0 0 0
3600  
3601 my $s = Subroutine
3602 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
3603 0 Comment "Get next Utf8 char";
3604  
3605 0 PushR (r11, r12, r13, r14, r15);
3606 0 $$p{fail}->getConst(0); # Clear failure indicator
3607 0 $$p{in}->setReg(r15); # Character to convert
3608 0 ClearRegisters r14; # Move to byte register below does not clear the entire register
3609 0 Mov r14b, "[r15]";
3610 0 my $success = Label; # As shown at: https://en.wikipedia.org/wiki/UTF-8
3611  
3612 0 Cmp r14, 0x7f; # Ascii
3613 IfLe
3614 Then
3615 0 ▶ {$$p{out}->getReg(r14);
Subroutine __ANON__: not called CC=1 SCAR=6.9
3616 0 $$p{size}->copy(1);
3617 0 Jmp $success;
3618 0 };
3619  
3620 0 Cmp r14, 0xdf; # Char size is: 2 bytes
3621 IfLe
3622 Then
3623 0 ▶ {Mov r13b, "[r15+1]";
Subroutine __ANON__: not called CC=1 SCAR=6.9
3624 0 And r13, 0x3f;
3625 0 And r14, 0x1f;
3626 0 Shl r14, 6;
3627 0 Or r14, r13;
3628 0 $$p{out}->getReg(r14);
3629 0 $$p{size}->copy(2);
3630 0 Jmp $success;
3631 0 };
3632  
3633 0 Cmp r14, 0xef; # Char size is: 3 bytes
3634 IfLe
3635 Then
3636 0 ▶ {Mov r12b, "[r15+2]";
Subroutine __ANON__: not called CC=1 SCAR=6.9
3637 0 And r12, 0x3f;
3638 0 Mov r13b, "[r15+1]";
3639 0 And r13, 0x3f;
3640 0 And r14, 0x0f;
3641 0 Shl r13, 6;
3642 0 Shl r14, 12;
3643 0 Or r14, r13;
3644 0 Or r14, r12;
3645 0 $$p{out}->getReg(r14);
3646 0 $$p{size}->copy(3);
3647 0 Jmp $success;
3648 0 };
3649  
3650 0 Cmp r14, 0xf7; # Char size is: 4 bytes
3651 IfLe
3652 Then
3653 0 ▶ {Mov r11b, "[r15+3]";
Subroutine __ANON__: not called CC=1 SCAR=6.9
3654 0 And r11, 0x3f;
3655 0 Mov r12b, "[r15+2]";
3656 0 And r12, 0x3f;
3657 0 Mov r13b, "[r15+1]";
3658 0 And r13, 0x3f;
3659 0 And r14, 0x07;
3660 0 Shl r12, 6;
3661 0 Shl r13, 12;
3662 0 Shl r14, 18;
3663 0 Or r14, r13;
3664 0 Or r14, r12;
3665 0 Or r14, r11;
3666 0 $$p{out}->getReg(r14);
3667 0 $$p{size}->copy(4);
3668 0 Jmp $success;
3669 0 };
3670  
3671 0 $$p{fail}->getConst(1); # Conversion failed
3672  
3673 0 SetLabel $success;
3674  
3675 0 PopR;
3676 0 } [qw(in out size fail)], name => 'GetNextUtf8CharAsUtf32';
3677  
3678 0 $s->call(@parameters);
3679 } # GetNextUtf8CharAsUtf32
3680  
3681 sub ConvertUtf8ToUtf32(@) # Convert a string of utf8 to an allocated block of utf32 and return its address and length.
3682 0 ▶ {my (@parameters) = @_; # Parameters
Subroutine ConvertUtf8ToUtf32: not called CC=2 SCAR=17.9
Pod documented
3683 0 ▶ @_ >= 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 1 or confess() 0 0 0
3684  
3685 my $s = Subroutine
3686 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
3687 0 Comment "Convert utf8 to utf32";
3688  
3689 0 PushR (r10, r11, r12, r13, r14, r15);
3690  
3691 0 my $size = $$p{size8} * 4; # Estimated length for utf32
3692 0 AllocateMemory size => $size, my $address = V(address);
3693  
3694 0 $$p{u8} ->setReg(r14); # Current position in input string
3695 0 ($$p{u8}+$$p{size8})->setReg(r15); # Upper limit of input string
3696 0 $address->setReg(r13); # Current position in output string
3697 0 ClearRegisters r12; # Number of characters in output string
3698  
3699 ForEver sub # Loop through input string converting each utf8 sequence to utf32
3700 0 ▶ {my ($start, $end) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
3701 0 my @p = my ($out, $size, $fail) = (V(out), V(size), V('fail'));
3702 0 GetNextUtf8CharAsUtf32 V(in, r14), @p; # Get next utf 8 character and convert it to utf32
3703 If $fail > 0,
3704 Then
3705 0 ▶ {PrintErrStringNL "Invalid utf8 character at index:";
Subroutine __ANON__: not called CC=1 SCAR=6.9
3706 0 PrintErrRegisterInHex r12;
3707 0 Exit(1);
3708 0 };
3709  
3710 0 Inc r12; # Count characters converted
3711 0 $out->setReg(r11); # Output character
3712  
3713 0 Mov "[r13]", r11d;
3714 0 Add r13, RegisterSize eax; # Move up 32 bits output string
3715 0 $size->setReg(r10); # Decoded this many bytes
3716 0 Add r14, r10; # Move up in input string
3717 0 Cmp r14, r15;
3718 0 Jge $end; # Exhausted input string
3719 0 };
3720  
3721 0 $$p{u32} ->copy($address); # Address of allocation
3722 0 $$p{size32}->copy($size); # Size of allocation
3723 0 $$p{count} ->getReg(r12); # Number of unicode points converted from utf8 to utf32
3724 0 PopR;
3725 0 } [qw(u8 size8 u32 size32 count)], name => 'ConvertUtf8ToUtf32';
3726  
3727 0 $s->call(@parameters);
3728 } # ConvertUtf8ToUtf32
3729  
3730 sub ClassifyRange($@) #P Implementation of ClassifyInRange and ClassifyWithinRange.
3731 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
3732 0 ▶ @_ >= 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 1 or confess() 0 0 0
3733  
3734 my $s = Subroutine
3735 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=2 SCAR=17.9
3736 0 Comment "Classify characters in utf32 format";
3737 0 my $finish = Label;
3738  
3739 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
3740 r14, r15, k6, k7, zmm 29..31);
3741  
3742 0 Mov r15, 0x88888888; # Create a mask for the classification bytes
3743 0 Kmovq k7, r15;
3744 0 Kshiftlq k6, k7, 32; # Move mask into upper half of register
3745 0 Korq k7, k6, k7; # Classification bytes masked by k7
3746  
3747 0 Knotq k7, k7; # Utf32 characters mask
3748 0 Vmovdqu8 "zmm31\{k7}{z}", zmm1; # Utf32 characters at upper end of each range
3749 0 Vmovdqu8 "zmm30\{k7}{z}", zmm0; # Utf32 characters at lower end of each range
3750  
3751 0 $$p{address}->setReg(r15); # Address of first utf32 character
3752 $$p{size}->for(sub # Process each utf32 character in the block of memory
3753 0 ▶ {my ($index, $start, $next, $end) = @_;
Subroutine __ANON__: not called CC=3 SCAR=24.8
3754  
3755 0 Mov r14d, "[r15]"; # Load utf32 character
3756 0 Add r15, RegisterSize r14d; # Move up to next utf32 character
3757 0 Vpbroadcastd zmm29, r14d; # Process 16 copies of the utf32 character
3758 0 Vpcmpud k7, zmm29, zmm30, 5; # Look for start of range
3759 0 Vpcmpud "k6\{k7}", zmm29, zmm31, 2; # Look for end of range
3760 0 Ktestw k6, k6; # Was there a match ?
3761 0 Jz $next; # No character was matched
3762 # Process matched character
3763 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
3764 0 {Vpcompressd "zmm29\{k6}", zmm0; # Place classification byte at start of xmm29
3765 0 Vpextrd r13d, xmm29, 4; # Extract start of range
3766 0 Mov r12, r13; # Copy start of range
3767 0 Shr r12, 24; # Classification start
3768 0 And r13, 0x00ffffff; # Range start
3769 0 Sub r14, r13; # Offset in range
3770 0 Add r12, r14; # Offset in classification
3771 0 Mov "[r15-1]", r12b; # Save classification
3772 }
3773 elsif ($recordOffsetInRange == 2) # Record classification in high byte and offset in classification range in low byte as used for alphabets
3774 0 {Vpcompressd "zmm29\{k6}", zmm0; # Place classification byte and start of range at start of xmm29
3775 0 Vpextrd r13d, xmm29, 4; # Extract start of range specification
3776 0 Mov r12, r13; # Range classification code and start of range
3777 0 Shr r12, 24; # Range classification code
3778 0 Mov "[r15-1]", r12b; # Save classification
3779 0 And r13, 0x00ffffff; # Range start
3780  
3781 0 Vpcompressd "zmm29\{k6}", zmm1; # Place start of alphabet at start of xmm29
3782 0 Vpextrd r12d, xmm29, 4; # Extract offset of alphabet in range
3783 0 Shr r12, 24; # Alphabet offset
3784 0 Add r12, r14; # Range start plus utf32
3785 0 Sub r12, r13; # Offset of utf32 in alphabet range
3786 0 Mov "[r15-4]", r12b; # Save offset of utf32 in alphabet range
3787 0 ClearRegisters r12; # Zero r12
3788 0 Mov "[r15-3]", r12w; # Clear middle of utf32
3789 }
3790 else # Record classification in high byte
3791 0 {Vpcompressd "zmm29\{k6}", zmm0; # Place classification byte at start of xmm29
3792 0 Vpextrb "[r15-1]", xmm29, 3; # Extract and save classification
3793 }
3794 0 });
3795  
3796 0 SetLabel $finish;
3797 0 PopR;
3798 0 } [qw(address size)], name => "ClassifyRange_$recordOffsetInRange";
3799  
3800 0 $s->call(@parameters);
3801 } # ClassifyRange
3802  
3803 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.
3804 0 ▶ {my (@parameters) = @_; # Parameters
Subroutine ClassifyInRange: not called CC=1 SCAR=6.9
Pod documented
3805 0 ClassifyRange(0, @_);
3806 }
3807  
3808 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.
3809 0 ▶ {my (@parameters) = @_; # Parameters
Subroutine ClassifyWithInRange: not called CC=1 SCAR=6.9
Pod documented
3810 0 ClassifyRange(1, @_);
3811 }
3812  
3813 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.
3814 0 ▶ {my (@parameters) = @_; # Parameters
Subroutine ClassifyWithInRangeAndSaveOffset: not called CC=1 SCAR=6.9
Pod documented
3815 0 ClassifyRange(2, @_);
3816 }
3817  
3818 #D1 Short Strings # Operations on Short Strings
3819  
3820 sub CreateShortString($) # Create a description of a short string.
3821 0 ▶ {my ($zmm) = @_; # Numbered zmm containing the string
Subroutine CreateShortString: not called CC=5 SCAR=34.0
Pod documented
3822 0 ▶ @_ == 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess() 0 0 0
3823 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
3824 confess "Zmm register number required";
3825  
3826 0 genHash(__PACKAGE__."::ShortString", # A short string up to 63 bytes long held in a zmm register.
3827 maximumLength => RegisterSize(zmm0) - 1, # The maximum length of a short string
3828 zmm => $zmm, # The number of the zmm register containing the string
3829 x => "xmm$zmm", # The associated xmm register
3830 z => "zmm$zmm", # The full name of the zmm register
3831 );
3832 }
3833  
3834 sub Nasm::X86::ShortString::clear($) # Clear a short string.
3835 0 ▶ {my ($string) = @_; # String
Subroutine clear: not called CC=2 SCAR=17.9
3836 0 ▶ @_ == 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess() 0 0 0
3837 0 my $z = $string->z; # Zmm register to use
3838 0 ClearRegisters $z; # Clear the register we are going to use as a short string
3839 }
3840  
3841 sub Nasm::X86::ShortString::load($$$) # Load the variable addressed data with the variable length into the short string.
3842 0 ▶ {my ($string, $address, $length) = @_; # String, address, length
Subroutine load: not called CC=2 SCAR=17.9
3843 0 ▶ @_ == 3 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess() 0 0 0
3844 0 my $z = $string->z; # Zmm register to use
3845 0 my $x = $string->x; # Corresponding xmm
3846  
3847 0 $string->clear; # Clear the register we are going to use as a short string
3848  
3849 0 PushR r14, r15, k7;
3850 0 $length->setReg(r15); # Length of string
3851 0 Mov r14, -1; # Clear bits that we do not wish to load
3852 0 Bzhi r14, r14, r15;
3853 0 Shl r14, 1; # Move over length byte
3854 0 Kmovq k7, r14; # Load mask
3855  
3856 0 $address->setReg(r14); # Address of data to load
3857 0 Vmovdqu8 "${z}{k7}", "[r14-1]"; # Load string skipping length byte
3858 0 Pinsrb $x, r15b, 0; # Set length in zmm
3859 0 PopR;
3860 }
3861  
3862 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.
3863 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
3864 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
3865 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
3866 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
3867 0 my $z = $string->z; # Zmm register to use
3868 0 my $x = $string->x; # Corresponding xmm
3869  
3870 0 $string->clear; # Clear the register we are going to use as a short string
3871  
3872 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
3873  
3874 0 my $m = $length->min($string->maximumLength); # Length to load
3875 0 $m->setReg(r15);
3876 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
3877 0 Mov "[rsp]", r15b; # Save length on stack image of short string
3878  
3879 0 $address->setReg(r15); # Source dwords
3880 $m->for(sub # Load each byte while there is room in the short string
3881 0 ▶ {my ($index, $start, $next, $end) = @_; # Execute block
Subroutine __ANON__: not called CC=1 SCAR=6.9
3882 0 $index->setReg(r14); # Index source and target
3883 0 Mov r13b, "[r15+4*r14+$byte]"; # Load next byte from specified position in the source dword
3884 0 Mov "[rsp+r14+1+$offset]", r13b; # Save next byte skipping length
3885 0 });
3886  
3887 0 PopR;
3888 }
3889  
3890 sub Nasm::X86::ShortString::len($) # Return the length of a short string in a variable.
3891 0 ▶ {my ($string) = @_; # String
Subroutine len: not called CC=2 SCAR=17.9
3892 0 ▶ @_ == 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess() 0 0 0
3893 0 my $z = $string->z; # Zmm register to use
3894 0 my $x = $string->x; # Corresponding xmm
3895 0 PushR r15;
3896 0 Pextrb r15, $x, 0; # Length
3897 0 my $l = V(size, r15); # Length as a variable
3898 0 PopR;
3899 0 $l
3900 }
3901  
3902 sub Nasm::X86::ShortString::setLength($$) # Set the length of the short string.
3903 0 ▶ {my ($string, $length) = @_; # String, variable size
Subroutine setLength: not called CC=2 SCAR=17.9
3904 0 ▶ @_ == 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess() 0 0 0
3905 0 my $x = $string->x; # Corresponding xmm
3906  
3907 0 PushR (r15);
3908 0 $length->setReg(r15); # Length of string
3909 0 Pinsrb $x, r15b, 0; # Set length in zmm
3910 0 PopR;
3911 }
3912  
3913 sub Nasm::X86::ShortString::appendByte($$) # Append the lowest variable byte to the specified string.
3914 0 ▶ {my ($string, $char) = @_; # String, variable byte
Subroutine appendByte: not called CC=2 SCAR=17.9
3915 0 ▶ @_ == 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess() 0 0 0
3916 0 my $z = $string->z; # Zmm register to use
3917 0 my $x = $string->x; # Corresponding xmm
3918  
3919 my $s = Subroutine # Append byte to short string
3920 0 ▶ {PushR r14, r15;
Subroutine __ANON__: not called CC=1 SCAR=6.9
3921 0 Pextrb r15, $x, 0; # Length of string
3922 0 Cmp r15, $string->maximumLength; # Check current length against maximum length for a short string
3923 IfLt
3924 Then # Room for an additional character
3925 0 ▶ {PushR $z; # Stack string
Subroutine __ANON__: not called CC=1 SCAR=6.9
3926 0 $char->setReg(r14); # Byte to append
3927 0 Mov "[rsp+r15+1]", r14b; # Place byte
3928 0 PopR; # Reload string with additional byte
3929 0 Inc r15; # New length
3930 0 Pinsrb $x, r15b, 0; # Set length in zmm
3931 0 };
3932 0 PopR;
3933 0 } [], name=> "Nasm::X86::ShortString::appendByte_$z";
3934  
3935 0 $s->call;
3936 }
3937  
3938 sub Nasm::X86::ShortString::append($$) # Append the right hand short string to the left hand short string.
3939 0 ▶ {my ($left, $right) = @_; # Target zmm, source zmm
Subroutine append: not called CC=2 SCAR=17.9
3940 0 ▶ @_ == 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess() 0 0 0
3941 0 my $lz = $left ->z; # Zmm register for left string
3942 0 my $lx = $left ->x; # Corresponding xmm
3943 0 my $rz = $right->z; # Zmm register for left string
3944 0 my $rx = $right->x; # Corresponding xmm
3945  
3946 my $s = Subroutine # Append two short strings
3947 0 ▶ {PushR (k7, rcx, r14, r15);
Subroutine __ANON__: not called CC=1 SCAR=6.9
3948 0 Pextrb r15, $rx, 0; # Length of right hand string
3949 0 Mov r14, -1; # Expand mask
3950 0 Bzhi r14, r14, r15; # Skip bits for left
3951 0 Pextrb rcx, $lx, 0; # Length of left hand string
3952 0 Inc rcx; # Skip length
3953 0 Shl r14, cl; # Skip length
3954 0 Kmovq k7, r14; # Unload mask
3955 0 PushRR $rz; # Stack right
3956 0 Sub rsp, rcx; # Position for masked read
3957 0 Vmovdqu8 $lz."{k7}", "[rsp+1]"; # Load right string
3958 0 Add rsp, rcx; # Restore stack
3959 0 Add rsp, RegisterSize zmm0;
3960 0 Dec rcx; # Length of left
3961 0 Add rcx, r15; # Length of combined string = length of left plus length of right
3962 0 Pinsrb $lx, cl, 0; # Save new length in left hand result
3963 0 PopR;
3964 0 } [], name=> "Nasm::X86::ShortString::append_${lz}_${rz}";
3965  
3966 0 $s->call;
3967 }
3968  
3969 #D1 Arenas # An arena is single extensible block of memory which contains other data structures such as strings, arrays, trees within it.
3970  
3971 sub Cstrlen() #P Length of the C style string addressed by rax returning the length in r15.
3972 0 ▶ {@_ == 0 or confess;
Subroutine Cstrlen: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 0 or confess() 0 0 0
3973  
3974 my $sub = Macro # Create arena
3975 0 ▶ {Comment "C strlen";
Subroutine __ANON__: not called CC=1 SCAR=6.9
3976 0 PushR my @regs = (rax, rdi, rcx);
3977 0 Mov rdi, rax;
3978 0 Mov rcx, -1;
3979 0 ClearRegisters rax;
3980 0 push @text, <<END;
3981 repne scasb
3982 END
3983 0 Mov r15, rcx;
3984 0 Not r15;
3985 0 Dec r15;
3986 0 PopR @regs;
3987 0 } name => "Cstrlen";
3988  
3989 0 Call $sub;
3990 }
3991  
3992 sub StringLength(@) # Length of a zero terminated string.
3993 0 ▶ {my (@parameters) = @_; # Parameters
Subroutine StringLength: not called CC=1 SCAR=6.9
Pod documented
3994 0 Comment "Length of zero terminated string";
3995  
3996 my $s = Subroutine
3997 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
3998 0 SaveFirstFour;
3999 0 $$p{string}->setReg(rax); # Address string
4000 0 Cstrlen; # Length now in r15
4001 0 $$p{size}->getReg(r15); # Save length
4002 0 RestoreFirstFour;
4003 0 } [qw(string size)], name => 'StringLength';
4004  
4005 0 $s->call(@parameters, my $z = V(size)); # Variable that holds the length of the string
4006 0 $z
4007 }
4008  
4009 sub DescribeArena(;$) # Describe a relocatable arena.
4010 0 ▶ {my ($bs) = @_; # Optional variable addressing the start of the arena
Subroutine DescribeArena: not called CC=1 SCAR=6.9
Pod documented
4011 0 my $N = 4096; # Initial size of arena
4012  
4013 0 my $quad = RegisterSize rax; # Field offsets
4014 0 my $size = 0;
4015 0 my $used = $size + $quad;
4016 0 my $free = $used + $quad;
4017 0 my $data = $free + $quad;
4018  
4019 0 genHash(__PACKAGE__."::Arena", # Definition of arena
4020 N => $N, # Initial allocation
4021 size => $size, # Size field offset
4022 used => $used, # Used field offset
4023 free => $free, # Free chain offset
4024 data => $data, # The start of the data
4025 bs => $bs, # Variable that addresses the arena
4026 );
4027 }
4028  
4029 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.
4030 0 ▶ {my (%options) = @_; # Free=>1 adds a free chain.
Subroutine CreateArena: not called CC=1 SCAR=6.9
Pod documented
4031 0 my $arena = DescribeArena; # Describe an arena
4032 0 my $N = $arena->N;
4033 0 my $used = $arena->used;
4034 0 my $free = $arena->free;
4035 0 my $data = $arena->data;
4036 0 my $size = $arena->size;
4037  
4038 my $s = Subroutine # Allocate arena
4039 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
4040 0 SaveFirstFour;
4041  
4042 0 AllocateMemory(K(size, $N), address=>$$p{bs}); # Allocate memory and save its location in a variable
4043  
4044 0 $$p{bs}->setReg(rax);
4045 0 Mov "dword[rax+$used]", $data; # Initially used space
4046 0 Mov "dword[rax+$size]", $N; # Size
4047  
4048 0 RestoreFirstFour;
4049 0 } [qw(bs)], name => 'CreateArena';
4050  
4051 0 $s->call(my $bs = G(bs)); # Variable that holds the reference to the arena which is updated when the arena is reallocated
4052  
4053 0 DescribeArena($bs); # Describe the arena with its address
4054 }
4055  
4056 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.
4057 0 ▶ {my ($arena, $bs, $variable, @offsets) = @_; # Arena descriptor, arena locator, start variable, offsets chain
Subroutine chain: not called CC=3 SCAR=24.8
4058 0 ▶ @_ >= 3 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 3 or confess() 0 0 0
4059  
4060 0 PushR (r14, r15); # Register 14 is the arena address, 15 the current offset in the arena
4061 0 $bs->setReg(r14);
4062 0 $variable->setReg(r15);
4063 0 for my $o(@offsets) # Each offset
4064 0 {Mov r15d, "dword[r14+r15+$o]"; # Step through each offset
4065 }
4066 0 my $r = V(join (' ', @offsets), r15); # Create a variable with the result
4067 0 PopR;
4068 0 $r
4069 }
4070  
4071 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.
4072 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
4073 0 ▶ @_ >= 5 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 5 or confess() 0 0 0
4074  
4075 0 PushR (r14, r15); # Register 14 is the arena address, 15 the current offset in the arena
4076 0 $bs->setReg(r14);
4077 0 $start->setReg(r15);
4078 0 for my $i(keys @offsets) # Each offset
4079 0 {my $o = $offsets[$i];
4080 0 ▶ if ($i < $#offsets) # Step through each offset
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $#offsets) { } 0 0 0
4081 0 {Mov r15d, "dword[r14+r15+$o]";
4082 }
4083 else # Address last location
4084 0 {Lea r15, "[r14+r15+$o]";
4085 }
4086 }
4087 0 $value->setReg(r14);
4088 0 Mov "[r15]", r14d;
4089 0 PopR;
4090 }
4091  
4092 sub Nasm::X86::Arena::length($@) # Get the length of an arena.
4093 0 ▶ {my ($arena, @variables) = @_; # Arena descriptor, variables
Subroutine length: not called CC=2 SCAR=17.9
4094 0 ▶ @_ >= 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 or confess() 0 0 0
4095  
4096 my $s = Subroutine # Allocate more space if required
4097 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
4098 0 SaveFirstFour;
4099 0 $$p{bs}->setReg(rax); # Address arena
4100 0 Mov rdx, "[rax+$$arena{used}]"; # Used
4101 0 Sub rdx, $arena->data; # Offset of size field
4102 0 $$p{size}->getReg(rdx);
4103 0 RestoreFirstFour;
4104 0 } [qw(bs size)], name => 'Nasm::X86::Arena::length';
4105  
4106 0 $s->call($arena->bs, @variables);
4107 }
4108  
4109 sub Nasm::X86::Arena::arenaSize($@) # Get the size of an arena.
4110 0 ▶ {my ($arena, @variables) = @_; # Arena descriptor, variables
Subroutine arenaSize: not called CC=2 SCAR=17.9
4111 0 ▶ @_ >= 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 or confess() 0 0 0
4112  
4113 my $s = Subroutine # Allocate more space if required
4114 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
4115 0 PushR (rax);
4116 0 $$p{bs}->setReg(rax); # Address arena
4117 0 Mov rax, "[rax+$$arena{size}]";
4118 0 $$p{size}->getReg(rax);
4119 0 PopR;
4120 0 } [qw(bs size)], name => 'Nasm::X86::Arena::size';
4121  
4122 0 $s->call($arena->bs, @variables);
4123 }
4124  
4125 sub Nasm::X86::Arena::updateSpace($@) #P Make sure that the arena addressed by rax has enough space to accommodate content of length rdi.
4126 0 ▶ {my ($arena, @variables) = @_; # Arena descriptor, variables
Subroutine updateSpace: not called CC=2 SCAR=17.9
4127  
4128 0 ▶ @_ >= 3 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 3 or confess() 0 0 0
4129  
4130 my $s = Subroutine
4131 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
4132 0 PushR (rax, r11, r12, r13, r14, r15);
4133 0 my $base = rax; # Base of arena
4134 0 my $size = r15; # Current size
4135 0 my $used = r14; # Currently used space
4136 0 my $request = r13; # Requested space
4137 0 my $newSize = r12; # New size needed
4138 0 my $proposed = r11; # Proposed size
4139  
4140 0 $$p{bs} ->setReg($base); # Address arena
4141 0 $$p{size}->setReg($request); # Requested space
4142  
4143 0 Mov $size, "[$base+$$arena{size}]";
4144 0 Mov $used, "[$base+$$arena{used}]";
4145 0 Mov $newSize, $used;
4146 0 Add $newSize, $request;
4147  
4148 0 Cmp $newSize,$size; # New size needed
4149 IfGt # New size is bigger than current size
4150 Then # More space needed
4151 0 ▶ {Mov $proposed, 4096; # Minimum proposed arena size
Subroutine __ANON__: not called CC=1 SCAR=6.9
4152 K(loop, 36)->for(sub # Maximum number of shifts
4153 0 ▶ {my ($index, $start, $next, $end) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
4154 0 Shl $proposed, 1; # New proposed size
4155 0 Cmp $proposed, $newSize; # Big enough?
4156 0 Jge $end; # Big enough!
4157 0 });
4158 0 my $oldSize = V(size, $size); # The old size of the arena
4159 0 my $newSize = V(size, $proposed); # The old size of the arena
4160 0 AllocateMemory(size => $newSize, my $address = V(address)); # Create new arena
4161 0 CopyMemory(target => $address, source => $$p{bs}, $oldSize); # Copy old arena into new arena
4162 0 FreeMemory(address => $$p{bs}, size => $oldSize); # Free previous memory previously occupied arena
4163 0 $$p{bs}->copy($address); # Save new arena address
4164  
4165 0 $$p{bs}->setReg($base); # Address arena
4166 0 Mov "[$base+$$arena{size}]", $proposed; # Save the new size in the arena
4167 0 };
4168  
4169 0 PopR;
4170 0 } [qw(bs size)] , name => 'Nasm::X86::Arena::updateSpace';
4171  
4172 0 $s->call(@variables);
4173 } # updateSpace
4174  
4175 sub Nasm::X86::Arena::makeReadOnly($) # Make an arena read only.
4176 0 ▶ {my ($arena) = @_; # Arena descriptor
Subroutine makeReadOnly: not called CC=2 SCAR=17.9
4177 0 ▶ @_ == 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess() 0 0 0
4178  
4179 my $s = Subroutine
4180 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
4181 0 Comment "Make an arena readable";
4182 0 SaveFirstFour;
4183 0 $$p{bs}->setReg(rax);
4184 0 Mov rdi, rax; # Address of arena
4185 0 Mov rsi, "[rax+$$arena{size}]"; # Size of arena
4186  
4187 0 Mov rdx, 1; # Read only access
4188 0 Mov rax, 10;
4189 0 Syscall;
4190 0 RestoreFirstFour; # Return the possibly expanded arena
4191 0 } [qw(bs)], name => 'Nasm::X86::Arena::makeReadOnly';
4192  
4193 0 $s->call(bs => $arena->bs);
4194 }
4195  
4196 sub Nasm::X86::Arena::makeWriteable($) # Make an arena writable.
4197 0 ▶ {my ($arena) = @_; # Arena descriptor
Subroutine makeWriteable: not called CC=2 SCAR=17.9
4198 0 ▶ @_ == 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess() 0 0 0
4199  
4200 my $s = Subroutine
4201 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
4202 0 Comment "Make an arena writable";
4203 0 SaveFirstFour;
4204 0 $$p{bs}->setReg(rax);
4205 0 Mov rdi, rax; # Address of arena
4206 0 Mov rsi, "[rax+$$arena{size}]"; # Size of arena
4207 0 Mov rdx, 3; # Read only access
4208 0 Mov rax, 10;
4209 0 Syscall;
4210 0 RestoreFirstFour; # Return the possibly expanded arena
4211 0 } [qw(bs)], name => 'Nasm::X86::Arena::makeWriteable';
4212  
4213 0 $s->call(bs => $arena->bs);
4214 }
4215  
4216 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.
4217 0 ▶ {my ($arena, @variables) = @_; # Arena descriptor, variables
Subroutine allocate: not called CC=2 SCAR=17.9
4218 0 ▶ @_ >= 3 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 3 or confess() 0 0 0
4219  
4220 my $s = Subroutine
4221 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
4222 0 Comment "Allocate space in an arena";
4223 0 SaveFirstFour;
4224  
4225 0 $arena->updateSpace($$p{bs}, $$p{size}); # Update space if needed
4226 0 $$p{bs} ->setReg(rax);
4227 0 Mov rsi, "[rax+$$arena{used}]"; # Currently used
4228 0 $$p{offset}->getReg(rsi);
4229 0 $$p{size} ->setReg(rdi);
4230 0 Add rsi, rdi;
4231 0 Mov "[rax+$$arena{used}]", rsi; # Currently used
4232  
4233 0 RestoreFirstFour;
4234 0 } [qw(bs size offset)], name => 'Nasm::X86::Arena::allocate';
4235  
4236 0 $s->call($arena->bs, @variables);
4237 }
4238  
4239 sub Nasm::X86::Arena::blockSize($) #P Size of a block.
4240 0 ▶ {my ($arena) = @_; # Arena
Subroutine blockSize: not called CC=1 SCAR=6.9
4241 0 RegisterSize(zmm0)
4242 }
4243  
4244 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.
4245 0 ▶ {my ($arena, @variables) = @_; # Arena, variables
Subroutine allocZmmBlock: not called CC=2 SCAR=17.9
4246 0 ▶ @_ >= 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 or confess() 0 0 0
4247 0 my $ffb = $arena->firstFreeBlock; # Check for a free block
4248 If $ffb > 0,
4249 Then # Free block available
4250 0 ▶ {PushR (r8, r9, zmm31);
Subroutine __ANON__: not called CC=4 SCAR=30.0
4251 0 $arena->getBlock($arena->bs, $ffb, 31, r8, r9); # Load the first block on the free chain
4252 0 my $second = getDFromZmm(31, 60, r8); # The location of the next pointer is forced upon us by string which got there first.
4253 0 $arena->setFirstFreeBlock($second); # Set the first free block field to point to the second block
4254 0 for my $v(@variables)
4255 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
4256 0 {$v->copy($ffb);
4257 0 last;
4258 }
4259 }
4260 0 PopR;
4261 },
4262 Else # Cannot reuse a free block so use unassigned memory
4263 0 ▶ {$arena->allocate(V(size, RegisterSize(zmm0)), @variables);
Subroutine __ANON__: not called CC=1 SCAR=6.9
4264 0 };
4265 }
4266  
4267 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.
4268 0 ▶ {my ($arena, $bs) = @_; # Arena, address of arena
Subroutine allocBlock: not called CC=3 SCAR=24.8
4269 0 ▶ @_ == 1 or @_ == 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or @_ == 2 or confess() 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
4270 0 $arena->allocZmmBlock # Allocate a zmm block
4271 (bs=>$bs, V(size, RegisterSize(zmm0)), my $o = V(offset));
4272 0 $o # Offset as a variable
4273 }
4274  
4275 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.
4276 0 ▶ {my ($arena) = @_; # Arena address as a variable
Subroutine firstFreeBlock: not called CC=2 SCAR=17.9
4277 0 ▶ @_ == 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess() 0 0 0
4278 0 PushR rax;
4279 0 $arena->bs->setReg(rax); #P Address underlying arena
4280 0 Mov rax, "[rax+$$arena{free}]"; # Content of free chain pointer
4281 0 my $v = V('free', rax); # Remainder of the free chain
4282 0 PopR rax;
4283 0 $v
4284 }
4285  
4286 sub Nasm::X86::Arena::setFirstFreeBlock($$) #P Set the first free block field from a variable.
4287 0 ▶ {my ($arena, $offset) = @_; # Arena descriptor, first free block offset as a variable
Subroutine setFirstFreeBlock: not called CC=2 SCAR=17.9
4288 0 ▶ @_ == 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess() 0 0 0
4289  
4290 0 PushR (rax, rsi, rdx);
4291 0 $arena->bs->setReg(rax); # Address underlying arena
4292 0 Lea rdx, "[rax+$$arena{free}]"; # Address of address of free chain
4293 0 $offset->setReg(rsi); # Offset of block being freed
4294 0 Mov "[rdx]", rsi; # Set head of free chain to point to block just freed
4295 0 PopR;
4296 }
4297  
4298 sub Nasm::X86::Arena::freeBlock($@) #P Free a block in an arena by placing it on the free chain.
4299 0 ▶ {my ($arena, @variables) = @_; # Arena descriptor, variables
Subroutine freeBlock: not called CC=2 SCAR=17.9
4300 0 ▶ @_ >= 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 or confess() 0 0 0
4301  
4302 my $s = Subroutine
4303 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
4304 0 PushR my @save = (r8, zmm31);
4305 0 my $rfc = $arena->firstFreeBlock; # Get first free block
4306 0 ClearRegisters @save; # Second block
4307 0 $rfc->putDIntoZmm(31, 60, r8); # The position of the next pointer was dictated by strings.
4308 0 $arena->putBlock($$p{bs}, $$p{offset}, 31); # Link the freed block to the rest of the free chain
4309 0 $arena->setFirstFreeBlock($$p{offset}); # Set free chain field to point to latest free chain element
4310 0 PopR;
4311 0 } [qw(offset bs)], name => 'Nasm::X86::Arena::freeBlock';
4312  
4313 0 $s->call($arena->bs, @variables);
4314 }
4315  
4316 sub Nasm::X86::Arena::getBlock($$$$;$$) #P Get the block with the specified offset in the specified string and return it in the numbered zmm.
4317 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
4318 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
4319 0 ▶ defined($address) or confess;
Branch: 1 branch
BranchTrueFalseTotal
defined $address or confess() 0 0 0
4320 0 ▶ defined($block) or confess;
Branch: 1 branch
BranchTrueFalseTotal
defined $block or confess() 0 0 0
4321 0 ▶ ref($block) =~ m(variable)i or confess;
Branch: 1 branch
BranchTrueFalseTotal
ref($block) =~ /variable/i or confess() 0 0 0
4322  
4323 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
4324 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
4325 0 ▶ PushR my @save = ($a, $o) unless @_ == 6;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 6 0 0 0
4326  
4327 0 $address->setReg($a); # Arena address
4328 0 $block ->setReg($o); # Offset of block in arena
4329  
4330 0 Cmp $o, $arena->data;
4331 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.
4332 Then
4333 0 ▶ {PrintErrStringNL "Attempt to get block before start of arena";
Subroutine __ANON__: not called CC=1 SCAR=6.9
4334 0 $block->errNL("Attempt to get block: ");
4335 0 PrintErrTraceBack;
4336 0 Exit(1);
4337 0 };
4338  
4339 0 Vmovdqu64 "zmm$zmm", "[$a+$o]"; # Read from memory
4340 0 ▶ PopR unless @_ == 6; # Restore registers
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 6 0 0 0
4341 }
4342  
4343 sub Nasm::X86::Arena::putBlock($$$$;$$) #P Write the numbered zmm to the block at the specified offset in the specified arena.
4344 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
4345 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
4346 0 ▶ defined($address) or confess "Arena not set";
Branch: 1 branch
BranchTrueFalseTotal
defined $address or confess("Arena not set") 0 0 0
4347 0 ▶ defined($block) or confess;
Branch: 1 branch
BranchTrueFalseTotal
defined $block or confess() 0 0 0
4348  
4349 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
4350 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
4351 0 ▶ PushR my @save = ($a, $o) unless @_ == 6;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 6 0 0 0
4352  
4353 0 $address->setReg($a); # Arena address
4354 0 $block ->setReg($o); # Offset of block in arena
4355  
4356 0 Cmp $o, $arena->data;
4357 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.
4358 Then
4359 0 ▶ {PrintErrStringNL "Attempt to put block before start of arena";
Subroutine __ANON__: not called CC=1 SCAR=6.9
4360 0 $block->errNL("Attempt to put block: ");
4361 0 PrintErrTraceBack;
4362 0 Exit(1);
4363 0 };
4364  
4365 0 Vmovdqu64 "[$a+$o]", "zmm$zmm"; # Read from memory
4366 0 ▶ PopR unless @_ == 6; # Restore registers
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 6 0 0 0
4367 }
4368  
4369 sub Nasm::X86::Arena::m($@) # Append the content with length rdi addressed by rsi to the arena addressed by rax.
4370 0 ▶ {my ($arena, @variables) = @_; # Arena descriptor, variables
Subroutine m: not called CC=2 SCAR=17.9
4371 0 ▶ @_ >= 4 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 4 or confess() 0 0 0
4372 0 my $used = "[rax+$$arena{used}]";
4373  
4374 my $s = Subroutine
4375 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
4376 0 Comment "Append memory to an arena";
4377 0 SaveFirstFour;
4378 0 $$p{bs}->setReg(rax);
4379 0 my $oldUsed = V("used", $used);
4380 0 $arena->updateSpace($$p{bs}, $$p{size}); # Update space if needed
4381  
4382 0 my $target = $oldUsed + $$p{bs};
4383 0 CopyMemory(source => $$p{address}, $$p{size}, target => $target); # Move data in
4384  
4385 0 my $newUsed = $oldUsed + $$p{size};
4386  
4387 0 $$p{bs} ->setReg(rax); # Update used field
4388 0 $newUsed->setReg(rdi);
4389 0 Mov $used, rdi;
4390  
4391 0 RestoreFirstFour;
4392 0 } [qw(bs address size)], name => 'Nasm::X86::Arena::m';
4393  
4394 0 $s->call(@variables);
4395 }
4396  
4397 sub Nasm::X86::Arena::q($$) # Append a constant string to the arena.
4398 0 ▶ {my ($arena, $string) = @_; # Arena descriptor, string
Subroutine q: not called CC=2 SCAR=17.9
4399 0 ▶ @_ == 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess() 0 0 0
4400  
4401 0 my $s = Rs($string);
4402  
4403 0 my $bs = $arena->bs; # Move data
4404 0 my $ad = V(address, $s);
4405 0 my $sz = V(size, length($string));
4406 0 $arena->m($bs, $ad, $sz);
4407 }
4408  
4409 sub Nasm::X86::Arena::ql($$) # Append a quoted string containing new line characters to the arena addressed by rax.
4410 0 ▶ {my ($arena, $const) = @_; # Arena, constant
Subroutine ql: not called CC=3 SCAR=24.8
4411 0 ▶ @_ == 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess() 0 0 0
4412 0 for my $l(split /\s*\n/, $const)
4413 0 {$arena->q($l);
4414 0 $arena->nl;
4415 }
4416 }
4417  
4418 sub Nasm::X86::Arena::char($$) # Append a character expressed as a decimal number to the arena addressed by rax.
4419 0 ▶ {my ($arena, $char) = @_; # Arena descriptor, number of character to be appended
Subroutine char: not called CC=2 SCAR=17.9
4420 0 ▶ @_ == 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess() 0 0 0
4421 0 my $s = Rb(ord($char));
4422 0 $arena->m($arena->bs, V(address, $s), V(size, 1)); # Move data
4423 }
4424  
4425 sub Nasm::X86::Arena::nl($) # Append a new line to the arena addressed by rax.
4426 0 ▶ {my ($arena) = @_; # Arena descriptor
Subroutine nl: not called CC=2 SCAR=17.9
4427 0 ▶ @_ == 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess() 0 0 0
4428 0 $arena->char("\n");
4429 }
4430  
4431 sub Nasm::X86::Arena::z($) # Append a trailing zero to the arena addressed by rax.
4432 0 ▶ {my ($arena) = @_; # Arena descriptor
Subroutine z: not called CC=2 SCAR=17.9
4433 0 ▶ @_ == 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess() 0 0 0
4434 0 $arena->char("\0");
4435 }
4436  
4437 sub Nasm::X86::Arena::append($@) # Append one arena to another.
4438 0 ▶ {my ($arena, @variables) = @_; # Arena descriptor, variables
Subroutine append: not called CC=2 SCAR=17.9
4439 0 ▶ @_ >= 3 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 3 or confess() 0 0 0
4440  
4441 my $s = Subroutine
4442 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
4443 0 Comment "Concatenate arenas";
4444 0 SaveFirstFour;
4445 0 $$p{source}->setReg(rax);
4446 0 Mov rdi, "[rax+$$arena{used}]";
4447 0 Sub rdi, $arena->data;
4448 0 Lea rsi, "[rax+$$arena{data}]";
4449 0 $arena->m(bs=>$$p{target}, V(address, rsi), V(size, rdi));
4450 0 RestoreFirstFour;
4451 0 } [qw(target source)], name => 'Nasm::X86::Arena::append';
4452  
4453 0 $s->call(target=>$arena->bs, @variables);
4454 }
4455  
4456 sub Nasm::X86::Arena::clear($) # Clear the arena addressed by rax.
4457 0 ▶ {my ($arena) = @_; # Arena descriptor
Subroutine clear: not called CC=2 SCAR=17.9
4458 0 ▶ @_ == 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess() 0 0 0
4459  
4460 my $s = Subroutine
4461 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
4462 0 Comment "Clear arena";
4463 0 PushR (rax, rdi);
4464 0 $$p{bs}->setReg(rax);
4465 0 Mov rdi, $arena->data;
4466 0 Mov "[rax+$$arena{used}]", rdi;
4467 0 PopR;
4468 0 } [qw(bs)], name => 'Nasm::X86::Arena::clear';
4469  
4470 0 $s->call(bs => $arena->bs);
4471 }
4472  
4473 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.
4474 0 ▶ {my ($arena, @variables) = @_; # Arena descriptor, variables
Subroutine write: not called CC=2 SCAR=17.9
4475 0 ▶ @_ >= 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 or confess() 0 0 0
4476  
4477 my $s = Subroutine
4478 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
4479 0 Comment "Write an arena to a file";
4480 0 SaveFirstFour;
4481  
4482 0 $$p{file}->setReg(rax);
4483 0 OpenWrite; # Open file
4484 0 my $file = V('fd', rax); # File descriptor
4485  
4486 0 $$p{bs}->setReg(rax); # Write file
4487 0 Lea rsi, "[rax+$$arena{data}]";
4488 0 Mov rdx, "[rax+$$arena{used}]";
4489 0 Sub rdx, $arena->data;
4490  
4491 0 Mov rax, 1; # Write content to file
4492 0 $file->setReg(rdi);
4493 0 Syscall;
4494  
4495 0 $file->setReg(rax);
4496 0 CloseFile;
4497 0 RestoreFirstFour;
4498 0 } [qw(file bs)], name => 'Nasm::X86::Arena::write';
4499  
4500 0 $s->call(bs => $arena->bs, @variables);
4501 }
4502  
4503 sub Nasm::X86::Arena::read($@) # Read the named file (terminated with a zero byte) and place it into the named arena.
4504 0 ▶ {my ($arena, @variables) = @_; # Arena descriptor, variables
Subroutine read: not called CC=2 SCAR=17.9
4505 0 ▶ @_ >= 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 or confess() 0 0 0
4506  
4507 my $s = Subroutine
4508 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
4509 0 Comment "Read an arena";
4510 0 ReadFile($$p{file}, (my $size = V(size)), my $address = V(address));
4511 0 $arena->m($$p{bs}, $size, $address); # Move data into arena
4512 0 FreeMemory($size, $address); # Free memory allocated by read
4513 0 } [qw(bs file)], name => 'Nasm::X86::Arena::read';
4514  
4515 0 $s->call(bs => $arena->bs, @variables);
4516 }
4517  
4518 sub Nasm::X86::Arena::out($) # Print the specified arena addressed by rax on sysout.
4519 0 ▶ {my ($arena) = @_; # Arena descriptor
Subroutine out: not called CC=2 SCAR=17.9
4520 0 ▶ @_ == 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess() 0 0 0
4521  
4522 my $s = Subroutine
4523 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
4524 0 Comment "Write an arena";
4525 0 SaveFirstFour;
4526 0 $$p{bs}->setReg(rax);
4527  
4528 0 Mov rdi, "[rax+$$arena{used}]"; # Length to print
4529 0 Sub rdi, $arena->data; # Length to print
4530 0 Lea rax, "[rax+$$arena{data}]"; # Address of data field
4531 0 PrintOutMemory;
4532 0 RestoreFirstFour;
4533 0 } [qw(bs)], name => 'Nasm::X86::Arena::out';
4534  
4535 0 $s->call($arena->bs);
4536 }
4537  
4538 sub Nasm::X86::Arena::dump($;$) # Dump details of an arena.
4539 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
4540 0 ▶ @_ == 1 or @_ == 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or @_ == 2 or confess() 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
4541 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
4542  
4543 0 PushR (rax, r15); # Get address of arena
4544 0 $arena->bs->setReg(rax);
4545  
4546 Call Macro # Bash string
4547 0 ▶ {Comment "Print details of an arena";
Subroutine __ANON__: not called CC=2 SCAR=17.9
4548 0 SaveFirstFour;
4549 0 PrintOutStringNL("Arena");
4550  
4551 0 PushR rax; # Print size
4552 0 Mov rax, "[rax+$$arena{size}]";
4553 0 PrintOutString(" Size: ");
4554 0 PrintOutRaxInHex;
4555 0 PrintOutNL;
4556 0 PopR rax;
4557  
4558 0 PushR rax; # Print used
4559 0 Mov rax, "[rax+$$arena{used}]";
4560 0 PrintOutString(" Used: ");
4561 0 PrintOutRaxInHex;
4562 0 PrintOutNL;
4563 0 PopR rax;
4564  
4565 0 Mov rdi, 64;
4566 0 for my $b(0..$depth-1) # Print the requested number of blocks
4567 0 {my $o = sprintf("%04X: ", 64 * $b);
4568 0 PrintOutString($o);
4569 0 PrintOutMemoryInHexNL;
4570 0 Add rax, 64;
4571 }
4572  
4573 0 RestoreFirstFour;
4574 0 } name => "Nasm::X86::Arena::dump$depth";
4575  
4576 0 PopR;
4577 }
4578  
4579 #D1 String # Strings made from zmm sized blocks of text
4580  
4581 sub Nasm::X86::Arena::DescribeString($%) # Describe a string and optionally set its first block .
4582 0 ▶ {my ($arena, %options) = @_; # Arena description, {first=> offset of first block}
Subroutine DescribeString: not called CC=3 SCAR=24.8
4583 0 ▶ @_ >= 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 1 or confess() 0 0 0
4584 0 my $b = RegisterSize zmm0; # Size of a block == size of a zmm register
4585 0 my $o = RegisterSize eax; # Size of a double word
4586  
4587 genHash(__PACKAGE__."::String", # String definition
4588 bs => $arena, # Bytes string definition
4589 links => $b - 2 * $o, # Location of links in bytes in zmm
4590 next => $b - 1 * $o, # Location of next offset in block in bytes
4591 prev => $b - 2 * $o, # Location of prev offset in block in bytes
4592 length => $b - 2 * $o - 1, # Maximum length in a block
4593 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
4594 );
4595 }
4596  
4597 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.
4598 0 ▶ {my ($arena) = @_; # Arena description
Subroutine CreateString: not called CC=2 SCAR=17.9
4599 0 ▶ @_ == 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess() 0 0 0
4600  
4601 0 my $s = $arena->DescribeString; # String descriptor
4602 0 my $first = $s->allocBlock($arena->bs); # Allocate first block
4603 0 $s->first->copy($first); # Record offset of first block
4604  
4605 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.
4606 0 {my $nn = $s->next;
4607 0 my $pp = $s->prev;
4608 0 PushR (r14, r15);
4609 0 $arena->bs->setReg(r15);
4610 0 $first ->setReg(r14);
4611 0 Mov "[r15+r14+$nn]", r14d;
4612 0 Mov "[r15+r14+$pp]", r14d;
4613 0 PopR;
4614 }
4615 $s # Description of string
4616 0 }
4617  
4618 sub Nasm::X86::String::address($) #P Address of a string.
4619 0 ▶ {my ($String) = @_; # String descriptor
Subroutine address: not called CC=2 SCAR=17.9
4620 0 ▶ @_ == 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess() 0 0 0
4621 0 $String->bs->bs;
4622 }
4623  
4624 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.
4625 0 ▶ {my ($String, $arena) = @_; # String descriptor, arena address
Subroutine allocBlock: not called CC=2 SCAR=17.9
4626 0 ▶ @_ == 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess() 0 0 0
4627  
4628 0 $String->bs->allocBlock($arena); # Allocate block and return its offset as a variable
4629 }
4630  
4631 sub Nasm::X86::String::getBlockLength($$) #P Get the block length of the numbered zmm and return it in a variable.
4632 0 ▶ {my ($String, $zmm) = @_; # String descriptor, number of zmm register
Subroutine getBlockLength: not called CC=2 SCAR=17.9
4633 0 ▶ @_ == 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess() 0 0 0
4634 0 getBFromZmm $zmm, 0; # Block length
4635 }
4636  
4637 sub Nasm::X86::String::setBlockLengthInZmm($$$) #P Set the block length of the numbered zmm to the specified length.
4638 0 ▶ {my ($String, $length, $zmm) = @_; # String descriptor, length as a variable, number of zmm register
Subroutine setBlockLengthInZmm: not called CC=2 SCAR=17.9
4639 0 ▶ @_ == 3 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess() 0 0 0
4640 0 PushR (r15); # Save work register
4641 0 $length->setReg(r15); # New length
4642 0 $length->putBIntoZmm($zmm, 0); # Insert block length
4643 0 PopR; # Length of block is a byte
4644 }
4645  
4646 sub Nasm::X86::String::getBlock($$$$) #P Get the block with the specified offset in the specified string and return it in the numbered zmm.
4647 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
4648 0 ▶ @_ >= 4 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 4 or confess() 0 0 0
4649 0 $String->bs->getBlock($bsa, $block, $zmm);
4650 }
4651  
4652 sub Nasm::X86::String::putBlock($$$$) #P Write the numbered zmm to the block at the specified offset in the specified arena.
4653 0 ▶ {my ($String, $bsa, $block, $zmm) = @_; # String descriptor, arena variable, block in arena, content variable
Subroutine putBlock: not called CC=2 SCAR=17.9
4654 0 ▶ @_ >= 4 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 4 or confess() 0 0 0
4655 0 $String->bs->putBlock($bsa, $block, $zmm);
4656 }
4657  
4658 sub Nasm::X86::String::getNextAndPrevBlockOffsetFromZmm($$) #P Get the offsets of the next and previous blocks as variables from the specified zmm.
4659 0 ▶ {my ($String, $zmm) = @_; # String descriptor, zmm containing block
Subroutine getNextAndPrevBlockOffsetFromZmm: not called CC=2 SCAR=17.9
4660 0 ▶ @_ == 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess() 0 0 0
4661 0 my $l = $String->links; # Location of links
4662 0 PushR my @regs = (r14, r15); # Work registers
4663 0 my $L = getQFromZmm($zmm, $String->links); # Links in one register
4664 0 $L->setReg(r15); # Links
4665 0 Mov r14d, r15d; # Next
4666 0 Shr r15, RegisterSize(r14d) * 8; # Prev
4667 0 my @r = (V("Next block offset", r15), V("Prev block offset", r14)); # Result
4668 0 PopR @regs; # Free work registers
4669 0 @r; # Return (next, prev)
4670 }
4671  
4672 sub Nasm::X86::String::putNextandPrevBlockOffsetIntoZmm($$$$) #P Save next and prev offsets into a zmm representing a block.
4673 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
4674 0 ▶ @_ == 4 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 4 or confess() 0 0 0
4675 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
4676 0 {PushR my @regs = (r14, r15); # Work registers
4677 0 $next->setReg(r14); # Next offset
4678 0 $prev->setReg(r15); # Prev offset
4679 0 Shl r14, RegisterSize(r14d) * 8; # Prev high
4680 0 Or r15, r14; # Links in one register
4681 0 my $l = V("Links", r15); # Links as variable
4682 0 $l->putQIntoZmm($zmm, $String->links); # Load links into zmm
4683 0 PopR @regs; # Free work registers
4684 }
4685 elsif ($next) # Set just next
4686 0 {PushR my @regs = (r8, r15); # Work registers
4687 0 $next->setReg(r15); # Next offset
4688 0 my $l = V("Links", r15); # Links as variable
4689 0 $l->putDIntoZmm($zmm, $String->next, r8); # Load links into zmm
4690 0 PopR @regs; # Free work registers
4691 }
4692 elsif ($prev) # Set just prev
4693 0 {PushR my @regs = (r8, r15); # Work registers
4694 0 $prev->setReg(r15); # Next offset
4695 0 my $l = V("Links", r15); # Links as variable
4696 0 $l->putDIntoZmm($zmm, $String->prev, r8); # Load links into zmm
4697 0 PopR @regs; # Free work registers
4698 }
4699 }
4700  
4701 sub Nasm::X86::String::dump($) # Dump a string to sysout.
4702 0 ▶ {my ($String) = @_; # String descriptor
Subroutine dump: not called CC=2 SCAR=17.9
4703 0 ▶ @_ == 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess() 0 0 0
4704  
4705 my $s = Subroutine
4706 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
4707 0 Comment "Dump a block in a string";
4708 0 PushR (zmm31);
4709 0 my $block = $$p{first}; # The first block
4710 0 $String->getBlock($$p{bs}, $block, 31); # The first block in zmm31
4711 0 my $length = $String->getBlockLength(31); # Length of block
4712 0 PrintOutStringNL "string Dump";
4713 0 $block ->out("Offset: ");
4714 0 PrintOutString " ";
4715 0 $length->outNL("Length: "); PrintOutRegisterInHex zmm31; # Print block
4716  
4717 ForEver # Each block in string
4718 0 ▶ {my ($start, $end) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
4719 0 my ($next, $prev) = $String->getNextAndPrevBlockOffsetFromZmm(31); # Get links from current block
4720 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
4721 0 $String->getBlock($$p{bs}, $next, 31); # Next block in zmm
4722 0 my $length = $String->getBlockLength(31); # Length of block
4723 0 $next ->out("Offset: "); # Print block
4724 0 PrintOutString " ";
4725 0 $length->outNL("Length: "); PrintOutRegisterInHex zmm31;
4726 0 };
4727 0 PrintOutNL;
4728  
4729 0 PopR;
4730 0 } [qw(first bs)], name => 'Nasm::X86::String::dump';
4731  
4732 0 $s->call($String->address, $String->first);
4733 }
4734  
4735 sub Nasm::X86::String::len($;$$) # Find the length of a string.
4736 0 ▶ {my ($String, $bs, $first) = @_; # String descriptor, optional arena address, offset of first block
Subroutine len: not called CC=5 SCAR=34.0
4737 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
4738  
4739 my $s = Subroutine
4740 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
4741 0 Comment "Length of a string";
4742 0 PushR (zmm31);
4743 0 my $block = $$p{first}; # The first block
4744 0 $String->getBlock($$p{bs}, $block, 31); # The first block in zmm31
4745 0 my $length = $String->getBlockLength(31); # Length of block
4746  
4747 ForEver # Each block in string
4748 0 ▶ {my ($start, $end) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
4749 0 my ($next, $prev) = $String->getNextAndPrevBlockOffsetFromZmm(31); # Get links from current block
4750 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
4751 0 $String->getBlock($$p{bs}, $next, 31); # Next block in zmm
4752 0 $length += $String->getBlockLength(31); # Add length of block
4753 0 };
4754 0 $$p{size}->copy($length);
4755 0 PopR;
4756 0 } [qw(first bs size)], name => 'Nasm::X86::String::len';
4757  
4758 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
4759 my $size = V(size));
4760  
4761 0 $size
4762 }
4763  
4764 sub Nasm::X86::String::concatenate($$) # Concatenate two strings by appending a copy of the source to the target string.
4765 0 ▶ {my ($target, $source) = @_; # Target string, source string
Subroutine concatenate: not called CC=2 SCAR=17.9
4766 0 ▶ @_ == 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess() 0 0 0
4767  
4768 my $s = Subroutine
4769 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
4770 0 Comment "Concatenate strings";
4771 0 PushZmm 29..31;
4772 0 my $sb = $$p{sBs}; # The arena underlying the source
4773 0 my $sf = $$p{sFirst}; # The first block in the source
4774 0 my $tb = $$p{tBs}; # The arena underlying the target
4775 0 my $tf = $$p{tFirst}; # The first block in the target
4776 0 $source->getBlock($sb, $sf, 31); # The first source block
4777 0 $target->getBlock($tb, $tf, 30); # The first target block
4778 0 my ($ts, $tl) = $target->getNextAndPrevBlockOffsetFromZmm(30); # Target second and last
4779 0 $target->getBlock($tb, $tl, 30); # The last target block to which we will append
4780  
4781 ForEver # Each block in source string
4782 0 ▶ {my ($start, $end) = @_; # Start and end labels
Subroutine __ANON__: not called CC=1 SCAR=6.9
4783  
4784 0 my $new = $target->allocBlock($$p{tBs}); # Allocate new block
4785 0 Vmovdqu8 zmm29, zmm31; # Load new target block from source
4786 0 my ($next, $prev) = $target->getNextAndPrevBlockOffsetFromZmm(30); # Linkage from last target block
4787  
4788 0 $target->putNextandPrevBlockOffsetIntoZmm(30, $new, $prev); # From last block
4789 0 $target->putNextandPrevBlockOffsetIntoZmm(29, $tf, $tl); # From new block
4790 0 $target->putBlock($tb, $tl, 30); # Put the modified last target block
4791 0 $tl->copy($new); # New last target block
4792 0 $target->putBlock($tb, $tl, 29); # Put the modified new last target block
4793 0 Vmovdqu8 zmm30, zmm29; # Last target block
4794  
4795 0 my ($sn, $sp) = $source->getNextAndPrevBlockOffsetFromZmm(31); # Get links from current source block
4796 If $sn == $sf,
4797 Then # Last source block
4798 0 ▶ {$source->getBlock($tb, $tf, 30); # The first target block
Subroutine __ANON__: not called CC=1 SCAR=6.9
4799 0 $source->putNextandPrevBlockOffsetIntoZmm(30, undef, $new); # Update end of block chain
4800 0 $source->putBlock($tb, $tf, 30); # Save modified first target block
4801  
4802 0 Jmp $end
4803 0 };
4804  
4805 0 $source->getBlock($sb, $sn, 31); # Next source block
4806 0 };
4807  
4808 0 PopZmm;
4809 0 } [qw(sBs sFirst tBs tFirst)], name => 'Nasm::X86::String::concatenate';
4810  
4811 0 $s->call(sBs => $source->address, sFirst => $source->first,
4812 tBs => $target->address, tFirst => $target->first);
4813 }
4814  
4815 sub Nasm::X86::String::insertChar($@) # Insert a character into a string.
4816 0 ▶ {my ($String, @variables) = @_; # String, variables
Subroutine insertChar: not called CC=2 SCAR=17.9
4817 0 ▶ @_ >= 3 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 3 or confess() 0 0 0
4818  
4819 my $s = Subroutine
4820 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
4821 0 PushR (k7, r14, r15, zmm30, zmm31);
4822 0 my $B = $$p{bs}; # The arena underlying the string
4823 0 my $F = $$p{first}; # The first block in string
4824 0 my $c = $$p{character}; # The character to insert
4825 0 my $P = $$p{position}; # The position in the string at which we want to insert the character
4826 0 $String->getBlock($B, $F, 31); # The first source block
4827  
4828 0 my $C = V('Current character position', 0); # Current character position
4829 0 my $L = $String->getBlockLength(31); # Length of last block
4830 0 my $M = V('Block length', $String->length); # Maximum length of a block
4831 0 my $One = V('One', 1); # Literal one
4832 0 my $current = V(current)->copy($F); # Current position in scan of block chain
4833  
4834 ForEver # Each block in source string
4835 0 ▶ {my ($start, $end) = @_; # Start and end labels
Subroutine __ANON__: not called CC=1 SCAR=6.9
4836  
4837 If $P >= $C,
4838 Then # Position is in current block
4839 {If $P <= $C + $L,
4840 Then # Position is in current block
4841 0 ▶ {my $O = $P - $C; # Offset in current block
Subroutine __ANON__: not called CC=1 SCAR=6.9
4842  
4843 0 PushR zmm31; # Stack block
4844 0 $O->setReg(r14); # Offset of character in block
4845 0 $c->setReg(r15); # Character to insert
4846 0 Mov "[rsp+r14]", r15b; # Place character after skipping length field
4847  
4848 If $L < $M,
4849 Then # Current block has space
4850 0 ▶ {($P+1-$C)->setMask($C + $L - $P + 1, k7); # Set mask for reload
Subroutine __ANON__: not called CC=1 SCAR=6.9
4851 0 Vmovdqu8 "zmm31{k7}", "[rsp-1]"; # Reload
4852 0 $String->setBlockLengthInZmm($L + 1, 31); # Length of block
4853 },
4854 Else # In the current block but no space so split the block
4855 0 ▶ {$One->setMask($C + $L - $P + 2, k7); # Set mask for reload
Subroutine __ANON__: not called CC=1 SCAR=6.9
4856 0 Vmovdqu8 "zmm30{k7}", "[rsp+r14-1]"; # Reload
4857 0 $String->setBlockLengthInZmm($O, 31); # New shorter length of original block
4858 0 $String->setBlockLengthInZmm($L - $O + 1, 30); # Set length of remainder plus inserted char in the new block
4859  
4860 0 my $new = $String->allocBlock($$p{bs}); # Allocate new block
4861 0 my ($next, $prev) = $String->getNextAndPrevBlockOffsetFromZmm(31); # Linkage from last block
4862  
4863 If $next == $prev,
4864 Then # The existing string has one block, add new as the second block
4865 0 ▶ {$String->putNextandPrevBlockOffsetIntoZmm(31, $new, $new);
Subroutine __ANON__: not called CC=1 SCAR=6.9
4866 0 $String->putNextandPrevBlockOffsetIntoZmm(30, $next, $prev);
4867 },
4868 Else # The existing string has two or more blocks
4869 0 ▶ {$String->putNextandPrevBlockOffsetIntoZmm(31, $new, $prev); # From last block
Subroutine __ANON__: not called CC=1 SCAR=6.9
4870 0 $String->putNextandPrevBlockOffsetIntoZmm(30, $next, $current); # From new block
4871 0 };
4872  
4873 0 $String->putBlock($B, $new, 30); # Save the modified block
4874 0 };
4875  
4876 0 $String->putBlock($B, $current, 31); # Save the modified block
4877 0 PopR zmm31; # Restore stack
4878 0 Jmp $end; # Character successfully inserted
4879 0 ▶ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
4880 0 };
4881  
4882 0 my ($next, $prev) = $String->getNextAndPrevBlockOffsetFromZmm(31); # Get links from current source block
4883  
4884 If $next == $F,
4885 Then # Last source block
4886 0 ▶ {$c->setReg(r15); # Character to insert
Subroutine __ANON__: not called CC=1 SCAR=6.9
4887 0 Push r15;
4888 0 Mov r15, rsp; # Address content on the stack
4889 0 $String->append($B, $F, V(size, 1), V(source, r15)); # Append character if we go beyond limit
4890 0 Pop r15;
4891 0 Jmp $end;
4892 0 };
4893  
4894 0 $C += $L; # Current character position at the start of the next block
4895 0 $current->copy($next); # Address next block
4896 0 $String->getBlock($B, $current, 31); # Next block
4897 0 $L->copy($String->getBlockLength(31)); # Length of block
4898 0 };
4899  
4900 0 PopR;
4901 0 } [qw(bs first character position)], name => 'Nasm::X86::String::insertChar';
4902  
4903 0 $s->call($String->address, first => $String->first, @variables)
4904 } #insertChar
4905  
4906 sub Nasm::X86::String::deleteChar($@) # Delete a character in a string.
4907 0 ▶ {my ($String, @variables) = @_; # String, variables
Subroutine deleteChar: not called CC=2 SCAR=17.9
4908 0 ▶ @_ >= 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 or confess() 0 0 0
4909  
4910 my $s = Subroutine
4911 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
4912 0 Comment "Delete a character in a string";
4913 0 PushR (k7, zmm31);
4914 0 my $B = $$p{bs}; # The arena underlying the string
4915 0 my $F = $$p{first}; # The first block in string
4916 0 my $P = $$p{position}; # The position in the string at which we want to insert the character
4917 0 $String->getBlock($B, $F, 31); # The first source block
4918 0 my $C = V('Current character position', 0); # Current character position
4919 0 my $L = $String->getBlockLength(31); # Length of last block
4920 0 my $current = V(currwn)->copy($F); # Current position in scan of block chain
4921  
4922 ForEver # Each block in source string
4923 0 ▶ {my ($start, $end) = @_; # Start and end labels
Subroutine __ANON__: not called CC=1 SCAR=6.9
4924  
4925 If $P >= $C,
4926 Then # Position is in current block
4927 {If $P <= $C + $L,
4928 Then # Position is in current block
4929 0 ▶ {my $O = $P - $C; # Offset in current block
Subroutine __ANON__: not called CC=1 SCAR=6.9
4930 0 PushR zmm31; # Stack block
4931 0 ($O+1)->setMask($L - $O, k7); # Set mask for reload
4932 0 Vmovdqu8 "zmm31{k7}", "[rsp+1]"; # Reload
4933 0 $String->setBlockLengthInZmm($L-1, 31); # Length of block
4934 0 $String->putBlock($B, $current, 31); # Save the modified block
4935 0 PopR zmm31; # Stack block
4936 0 Jmp $end; # Character successfully inserted
4937 0 ▶ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
4938 0 };
4939  
4940 0 my ($next, $prev) = $String->getNextAndPrevBlockOffsetFromZmm(31); # Get links from current source block
4941 0 $String->getBlock($B, $next, 31); # Next block
4942 0 $current->copy($next);
4943 0 $L->copy($String->getBlockLength(31)); # Length of block
4944 0 $C += $L; # Current character position at the start of this block
4945 0 };
4946  
4947 0 PopR;
4948 0 } [qw(first position bs)], name => 'Nasm::X86::String::deleteChar';
4949  
4950 0 $s->call($String->address, first => $String->first, @variables)
4951 }
4952  
4953 sub Nasm::X86::String::getCharacter($@) # Get a character from a string.
4954 0 ▶ {my ($String, @variables) = @_; # String, variables
Subroutine getCharacter: not called CC=2 SCAR=17.9
4955 0 ▶ @_ >= 3 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 3 or confess() 0 0 0
4956  
4957 my $s = Subroutine
4958 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
4959 0 Comment "Get a character from a string";
4960 0 PushR (r15, zmm31);
4961 0 my $B = $$p{bs}; # The arena underlying the string
4962 0 my $F = $$p{first}; # The first block in string
4963 0 my $P = $$p{position}; # The position in the string at which we want to insert the character
4964 0 $String->getBlock($B, $F, 31); # The first source block
4965 0 my $C = V('Current character position', 0); # Current character position
4966 0 my $L = $String->getBlockLength(31); # Length of last block
4967  
4968 ForEver # Each block in source string
4969 0 ▶ {my ($start, $end) = @_; # Start and end labels
Subroutine __ANON__: not called CC=1 SCAR=6.9
4970  
4971 If $P >= $C,
4972 Then # Position is in current block
4973 {If $P <= $C + $L,
4974 Then # Position is in current block
4975 0 ▶ {my $O = $P - $C; # Offset in current block
Subroutine __ANON__: not called CC=1 SCAR=6.9
4976 0 PushR zmm31; # Stack block
4977 0 ($O+1) ->setReg(r15); # Character to get
4978 0 Mov r15b, "[rsp+r15]"; # Reload
4979 0 $$p{out}->getReg(r15); # Save character
4980 0 PopR zmm31; # Stack block
4981 0 Jmp $end; # Character successfully inserted
4982 0 ▶ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
4983 0 };
4984  
4985 0 my ($next, $prev) = $String->getNextAndPrevBlockOffsetFromZmm(31); # Get links from current source block
4986 0 $String->getBlock($B, $next, 31); # Next block
4987 0 $L = $String->getBlockLength(31); # Length of block
4988 0 $C += $L; # Current character position at the start of this block
4989 0 };
4990  
4991 0 PopR;
4992 0 } [qw(first position bs out)], name => 'Nasm::X86::String::getCharacter';
4993  
4994 0 $s->call($String->address, first => $String->first, @variables)
4995 }
4996  
4997 sub Nasm::X86::String::append($@) # Append the specified content in memory to the specified string.
4998 0 ▶ {my ($String, @variables) = @_; # String descriptor, variables
Subroutine append: not called CC=2 SCAR=17.9
4999 0 ▶ @_ >= 3 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 3 or confess() 0 0 0
5000  
5001 my $s = Subroutine
5002 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
5003  
5004 0 my $Z = K(zero, 0); # Zero
5005 0 my $O = K(one, 1); # One
5006 0 my $L = V(size, $String->length); # Length of a full block
5007 0 my $B = $$p{bs}; # Underlying string
5008 0 my $source = V(source)->copy($$p{source}); # Address of content to be appended
5009 0 my $size = V(size) ->copy($$p{size}); # Size of content
5010 0 my $first = $$p{first}; # First (preallocated) block in string
5011  
5012 0 PushZmm 29..31;
5013 ForEver # Append content until source exhausted
5014 0 ▶ {my ($start, $end) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
5015  
5016 0 $String->getBlock($B, $first, 29); # Get the first block
5017 0 my ($second, $last) = $String->getNextAndPrevBlockOffsetFromZmm(29); # Get the offsets of the second and last blocks
5018 0 $String->getBlock($B, $last, 31); # Get the last block
5019 0 my $lengthLast = $String->getBlockLength(31); # Length of last block
5020 0 my $spaceLast = $L - $lengthLast; # Space in last block
5021 0 my $toCopy = $spaceLast->min($size); # Amount of data required to fill first block
5022 0 my $startPos = $O + $lengthLast; # Start position in zmm
5023  
5024 0 $source->setZmm(31, $startPos, $toCopy); # Append bytes
5025 0 $String->setBlockLengthInZmm($lengthLast + $toCopy, 31); # Set the length
5026 0 $String->putBlock($B, $last, 31); # Put the block
5027 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
5028  
5029 0 $source += $toCopy; # Remaining source
5030 0 $size -= $toCopy; # Remaining source length
5031  
5032 0 my $new = $String->allocBlock($$p{bs}); # Allocate new block
5033 0 $String->getBlock ($B, $new, 30); # Load the new block
5034 0 my ($next, $prev) = $String->getNextAndPrevBlockOffsetFromZmm(31); # Linkage from last block
5035  
5036 If $first == $last,
5037 Then # The existing string has one block, add new as the second block
5038 0 ▶ {$String->putNextandPrevBlockOffsetIntoZmm(31, $new, $new);
Subroutine __ANON__: not called CC=1 SCAR=6.9
5039 0 $String->putNextandPrevBlockOffsetIntoZmm(30, $last, $last);
5040 },
5041 Else # The existing string has two or more blocks
5042 0 ▶ {$String->putNextandPrevBlockOffsetIntoZmm(31, $new, $prev); # From last block
Subroutine __ANON__: not called CC=1 SCAR=6.9
5043 0 $String->putNextandPrevBlockOffsetIntoZmm(30, $next, $last); # From new block
5044 0 $String->putNextandPrevBlockOffsetIntoZmm(29, undef, $new); # From first block
5045 0 $String->putBlock($B, $first, 29); # Put the modified last block
5046 0 };
5047  
5048 0 $String->putBlock($B, $last, 31); # Put the modified last block
5049 0 $String->putBlock($B, $new, 30); # Put the modified new block
5050 0 };
5051 0 PopZmm;
5052 0 } [qw(bs first source size)], name => 'Nasm::X86::String::append';
5053  
5054 0 $s->call($String->address, $String->first, @variables);
5055 }
5056  
5057 sub Nasm::X86::String::appendShortString($$) # Append the content of the specified short string.
5058 0 ▶ {my ($string, $short) = @_; # String descriptor, short string
Subroutine appendShortString: not called CC=2 SCAR=17.9
5059 0 ▶ @_ == 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess() 0 0 0
5060 0 my $z = $short->z; # Zmm register containing short string
5061 0 PushR r15, $z;
5062 0 my $L = $short->len;
5063 0 Mov r15, rsp;
5064 0 Inc r15;
5065 0 my $S = V(source, r15);
5066 0 $string->append($S, $L);
5067 0 PopR;
5068 }
5069  
5070 sub Nasm::X86::String::saveToShortString($$;$) # Place as much as possible of the specified string into the specified short string.
5071 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
5072 0 ▶ @_ == 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess() 0 0 0
5073 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
5074  
5075 my $s = Subroutine ### At the moment we only read the first block - we need to read more data out of the string if necessary
5076 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
5077 0 PushR k7, zmm31, r14, r15;
5078 0 $string->getBlock($$p{bs}, $$p{first}, 31); # The first block in zmm31
5079  
5080 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
5081 0 $short->clear;
5082 0 Vmovdqu8 "${z}{k7}", zmm31; # Move all the data in the first block
5083  
5084 0 my $b = $string->getBlockLength(31); # Length of block
5085 0 $short->setLength($b); # Set length of short string
5086  
5087 0 PopR;
5088 0 } [qw(bs first)], name => "Nasm::X86::String::saveToShortString_$z"; # Separate by zmm register being loaded
5089  
5090 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
5091  
5092 0 $short # Chain
5093 }
5094  
5095 sub Nasm::X86::String::clear($) # Clear the block by freeing all but the first block.
5096 0 ▶ {my ($String) = @_; # String descriptor
Subroutine clear: not called CC=2 SCAR=17.9
5097 0 ▶ @_ == 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess() 0 0 0
5098  
5099 my $s = Subroutine
5100 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
5101  
5102 0 PushR rax, r14, r15; PushZmm 29..31;
5103  
5104 0 my $first = $$p{first}; # First block
5105 0 $String->getBlock($$p{bs}, $$p{first}, 29); # Get the first block
5106 0 my ($second, $last) = $String->getNextAndPrevBlockOffsetFromZmm(29); # Get the offsets of the second and last blocks
5107 0 ClearRegisters zmm29; # Clear first block
5108 0 $String->putNextandPrevBlockOffsetIntoZmm(29, $first, $first); # Initialize block chain
5109 0 $String->putBlock($$p{bs}, $first, 29); # Put the first block
5110  
5111 If $last != $first,
5112 Then # Two or more blocks on the chain
5113 0 ▶ {$$p{bs}->setReg(rax); # Address underlying arena
Subroutine __ANON__: not called CC=1 SCAR=6.9
5114 0 my $free = $String->bs->free;
5115 0 Lea r14, "[rax+$free]"; # Address of address of free chain
5116 0 Mov r15, "[r14]"; # Address of free chain
5117 0 my $rfc = V('next', r15); # Remainder of the free chain
5118  
5119 If $second == $last,
5120 Then # Two blocks on the chain
5121 0 ▶ {ClearRegisters zmm30; # Second block
Subroutine __ANON__: not called CC=1 SCAR=6.9
5122 0 $String->putNextandPrevBlockOffsetIntoZmm(30, $rfc, undef); # Put second block on head of the list
5123 0 $String->putBlock($$p{bs}, $second, 30); # Put the second block
5124 },
5125 Else # Three or more blocks on the chain
5126 0 ▶ {my $z = V(zero, 0); # A variable with zero in it
Subroutine __ANON__: not called CC=1 SCAR=6.9
5127 0 $String->getBlock($$p{bs}, $second, 30); # Get the second block
5128 0 $String->getBlock($$p{bs}, $last, 31); # Get the last block
5129 0 $String->putNextandPrevBlockOffsetIntoZmm(30, undef, $z); # Reset prev pointer in second block
5130 0 $String->putNextandPrevBlockOffsetIntoZmm(31, $rfc, undef); # Reset next pointer in last block to remainder of free chain
5131 0 $String->putBlock($$p{bs}, $second, 30); # Put the second block
5132 0 $String->putBlock($$p{bs}, $last, 31); # Put the last block
5133 0 };
5134  
5135 0 $second->setReg(r15);
5136 0 Mov "[r14]", r15;
5137 0 };
5138  
5139 0 PushZmm; PopR;
5140 0 } [qw(first bs)], name => 'Nasm::X86::String::clear';
5141  
5142 0 $s->call($String->address, $String->first);
5143 }
5144  
5145 #D1 Array # Array constructed as a set of blocks in an arena
5146  
5147 sub Nasm::X86::Arena::DescribeArray($) # Describe a dynamic array held in an arena.
5148 0 ▶ {my ($arena) = @_; # Arena description
Subroutine DescribeArray: not called CC=3 SCAR=24.8
5149 0 ▶ @_ == 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess() 0 0 0
5150 0 my $b = RegisterSize zmm0; # Size of a block == size of a zmm register
5151 0 my $o = RegisterSize eax; # Size of a double word
5152  
5153 # my $p = 0; # Position in block
5154 0 my $s = genHash(__PACKAGE__."::Array", # String definition
5155 bs => $arena, # Bytes string definition
5156 width => $o, # Width of each element
5157 first => G('first'), # Variable addressing first block in string
5158 slots1 => $b / $o - 1, # Number of slots in first block
5159 slots2 => $b / $o, # Number of slots in second and subsequent blocks
5160 );
5161 0 ▶ $s->slots2 == 16 or confess "Number of slots per block not 16"; # Slots per block
Branch: 1 branch
BranchTrueFalseTotal
$s->slots2 == 16 or confess("Number of slots per block not 16") 0 0 0
5162  
5163 0 $s # Description of array
5164 }
5165  
5166 sub Nasm::X86::Arena::CreateArray($) # Create a dynamic array held in an arena.
5167 0 ▶ {my ($arena) = @_; # Arena description
Subroutine CreateArray: not called CC=2 SCAR=17.9
5168 0 ▶ @_ == 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess() 0 0 0
5169  
5170 0 my $a = $arena->DescribeArray; # Describe array
5171  
5172 0 $a->reload(first => $a->allocBlock($arena->bs)); # Allocate first block and return created array descriptor
5173 }
5174  
5175 sub Nasm::X86::Array::reload($%) # Reload the specified array description.
5176 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
5177 0 ▶ @_ >= 1 or confess "At least one parameter";
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 1 or confess("At least one parameter") 0 0 0
5178  
5179 0 my $a = $array->bs->DescribeArray; # Return a descriptor for an array
5180 0 ▶ $a->bs = $options{arena} if $options{arena};
Branch: 1 branch
BranchTrueFalseTotal
if $options{"arena"} 0 0 0
5181 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
5182 0 $a
5183 }
5184  
5185 sub Nasm::X86::Array::address($) #P Address of a string.
5186 0 ▶ {my ($Array) = @_; # Array descriptor
Subroutine address: not called CC=2 SCAR=17.9
5187 0 ▶ @_ == 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess() 0 0 0
5188 0 $Array->bs->bs;
5189 }
5190  
5191 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.
5192 0 ▶ {my ($Array, $bs) = @_; # Array descriptor, arena address
Subroutine allocBlock: not called CC=2 SCAR=17.9
5193 0 ▶ @_ == 2 or confess "2 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess("2 parameters") 0 0 0
5194  
5195 0 $Array->bs->allocBlock($bs);
5196 }
5197  
5198 sub Nasm::X86::Array::dump($@) # Dump a array.
5199 0 ▶ {my ($Array, @variables) = @_; # Array descriptor, variables
Subroutine dump: not called CC=2 SCAR=17.9
5200 0 ▶ @_ >= 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 1 or confess() 0 0 0
5201 0 my $b = $Array->bs; # Underlying arena
5202 0 my $W = RegisterSize zmm0; # The size of a block
5203 0 my $w = $Array->width; # The size of an entry in a block
5204 0 my $n = $Array->slots1; # The number of slots per block
5205 0 my $N = $Array->slots2; # The number of slots per block
5206  
5207 my $s = Subroutine
5208 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
5209  
5210 0 my $B = $$p{bs}; # Arena
5211 0 my $F = $$p{first}; # First block
5212  
5213 0 PushR (r8, zmm30, zmm31);
5214 0 $b->getBlock($B, $F, 31); # Get the first block
5215 0 my $size = getDFromZmm(31, 0, r8); # Size of array
5216 0 PrintOutStringNL("array");
5217 0 $size->out("Size: ", " ");
5218 0 PrintOutRegisterInHex zmm31;
5219  
5220 If $size > $n,
5221 Then # Array has secondary blocks
5222 0 ▶ {my $T = $size / $N; # Number of full blocks
Subroutine __ANON__: not called CC=1 SCAR=6.9
5223  
5224 $T->for(sub # Print out each block
5225 0 ▶ {my ($index, $start, $next, $end) = @_; # Execute block
Subroutine __ANON__: not called CC=1 SCAR=6.9
5226 0 my $S = getDFromZmm(31, ($index + 1) * $w, r8); # Address secondary block from first block
5227 0 $b->getBlock($B, $S, 30); # Get the secondary block
5228 0 $S->out("Full: ", " ");
5229 0 PrintOutRegisterInHex zmm30;
5230 0 });
5231  
5232 0 my $lastBlockCount = $size % $N; # Number of elements in the last block
5233 If $lastBlockCount > 0, sub # Print non empty last block
5234 0 ▶ {my $S = getDFromZmm(31, ($T + 1) * $w, r8); # Address secondary block from first block
Subroutine __ANON__: not called CC=1 SCAR=6.9
5235 0 $b->getBlock($B, $S, 30); # Get the secondary block
5236 0 $S->out("Last: ", " ");
5237 0 PrintOutRegisterInHex zmm30;
5238 0 };
5239 0 };
5240  
5241 0 PopR;
5242 0 } [qw(bs first)], name => q(Nasm::X86::Array::dump);
5243  
5244 0 $s->call($Array->address, $Array->first, @variables);
5245 }
5246  
5247 sub Nasm::X86::Array::push($@) # Push an element onto the array.
5248 0 ▶ {my ($Array, @variables) = @_; # Array descriptor, variables
Subroutine push: not called CC=2 SCAR=17.9
5249 0 ▶ @_ >= 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 or confess() 0 0 0
5250 0 my $b = $Array->bs; # Underlying arena
5251 0 my $W = RegisterSize zmm0; # The size of a block
5252 0 my $w = $Array->width; # The size of an entry in a block
5253 0 my $n = $Array->slots1; # The number of slots per block
5254 0 my $N = $Array->slots2; # The number of slots per block
5255  
5256 my $s = Subroutine
5257 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
5258 0 my $success = Label; # Short circuit if ladders by jumping directly to the end after a successful push
5259  
5260 0 my $B = $$p{bs}; # Arena
5261 0 my $F = $$p{first}; # First block
5262 0 my $E = $$p{element}; # The element to be inserted
5263  
5264 0 PushR (r8, zmm31);
5265 0 my $transfer = r8; # Transfer data from zmm to variable via this register
5266  
5267 0 $b->getBlock($B, $F, 31); # Get the first block
5268 0 my $size = getDFromZmm(31, 0, $transfer); # Size of array
5269  
5270 If $size < $n,
5271 Then # Room in the first block
5272 0 ▶ {$E ->putDIntoZmm(31, ($size + 1) * $w, $transfer); # Place element
Subroutine __ANON__: not called CC=1 SCAR=6.9
5273 0 ($size+1)->putDIntoZmm(31, 0, $transfer); # Update size
5274 0 $b ->putBlock($B, $F, 31); # Put the first block back into memory
5275 0 Jmp $success; # Element successfully inserted in first block
5276 0 };
5277  
5278 If $size == $n,
5279 Then # Migrate the first block to the second block and fill in the last slot
5280 0 ▶ {PushR (rax, k7, zmm30);
Subroutine __ANON__: not called CC=1 SCAR=6.9
5281 0 Mov rax, -2; # Load compression mask
5282 0 Kmovq k7, rax; # Set compression mask
5283 0 Vpcompressd "zmm30{k7}{z}", zmm31; # Compress first block into second block
5284 0 ClearRegisters zmm31; # Clear first block
5285 0 ($size+1)->putDIntoZmm(31, 0, $transfer); # Save new size in first block
5286 0 my $new = $b->allocBlock($$p{bs}); # Allocate new block
5287 0 $new->putDIntoZmm(31, $w, $transfer); # Save offset of second block in first block
5288 0 $E ->putDIntoZmm(30, $W - 1 * $w, $transfer); # Place new element
5289 0 $b ->putBlock($B, $new, 30); # Put the second block back into memory
5290 0 $b ->putBlock($B, $F, 31); # Put the first block back into memory
5291 0 PopR;
5292 0 Jmp $success; # Element successfully inserted in second block
5293 0 };
5294  
5295 If $size <= $N * ($N - 1),
5296 Then # Still within two levels
5297 {If $size % $N == 0,
5298 Then # New secondary block needed
5299 0 ▶ {PushR (rax, zmm30);
Subroutine __ANON__: not called CC=1 SCAR=6.9
5300 0 my $new = $b->allocBlock($$p{bs}); # Allocate new block
5301 0 $E ->putDIntoZmm(30, 0, $transfer); # Place new element last in new second block
5302 0 ($size+1)->putDIntoZmm(31, 0, $transfer); # Save new size in first block
5303 0 $new ->putDIntoZmm(31, ($size / $N + 1) * $w, $transfer); # Address new second block from first block
5304 0 $b ->putBlock($B, $new, 30); # Put the second block back into memory
5305 0 $b ->putBlock($B, $F, 31); # Put the first block back into memory
5306 0 PopR;
5307 0 Jmp $success; # Element successfully inserted in second block
5308 0 ▶ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
5309  
5310 0 if (1) # Continue with existing secondary block
5311 0 {PushR (rax, r14, zmm30);
5312 0 my $S = getDFromZmm(31, ($size / $N + 1) * $w, $transfer); # Offset of second block in first block
5313 0 $b ->getBlock($B, $S, 30); # Get the second block
5314 0 $E ->putDIntoZmm(30, ($size % $N) * $w, $transfer); # Place new element last in new second block
5315 0 ($size+1)->putDIntoZmm(31, 0, $transfer); # Save new size in first block
5316 0 $b ->putBlock($B, $S, 30); # Put the second block back into memory
5317 0 $b ->putBlock($B, $F, 31); # Put the first block back into memory
5318 0 PopR;
5319 0 Jmp $success; # Element successfully inserted in second block
5320 }
5321 0 };
5322  
5323 0 SetLabel $success;
5324 0 PopR;
5325 0 } [qw(bs first element)], name => 'Nasm::X86::Array::push';
5326  
5327 0 $s->call($Array->address, $Array->first, @variables);
5328 }
5329  
5330 sub Nasm::X86::Array::pop($@) # Pop an element from an array.
5331 0 ▶ {my ($Array, @variables) = @_; # Array descriptor, variables
Subroutine pop: not called CC=2 SCAR=17.9
5332 0 ▶ @_ >= 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 or confess() 0 0 0
5333 0 my $b = $Array->bs; # Underlying arena
5334 0 my $W = RegisterSize zmm0; # The size of a block
5335 0 my $w = $Array->width; # The size of an entry in a block
5336 0 my $n = $Array->slots1; # The number of slots per block
5337 0 my $N = $Array->slots2; # The number of slots per block
5338  
5339 my $s = Subroutine
5340 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
5341 0 my $success = Label; # Short circuit if ladders by jumping directly to the end after a successful push
5342  
5343 0 my $B = $$p{bs}; # Arena
5344 0 my $F = $$p{first}; # First block
5345 0 my $E = $$p{element}; # The element being popped
5346  
5347 0 PushR (r8, zmm31);
5348 0 my $transfer = r8; # Transfer data from zmm to variable via this register
5349 0 $b->getBlock($B, $F, 31); # Get the first block
5350 0 my $size = getDFromZmm(31, 0, $transfer); # Size of array
5351  
5352 If $size > 0,
5353 Then # Array has elements
5354 {If $size <= $n,
5355 Then # In the first block
5356 0 ▶ {$E ->getDFromZmm(31, $size * $w, $transfer); # Get element
Subroutine __ANON__: not called CC=1 SCAR=6.9
5357 0 ($size-1)->putDIntoZmm(31, 0, $transfer); # Update size
5358 0 $b ->putBlock($B, $F, 31); # Put the first block back into memory
5359 0 Jmp $success; # Element successfully retrieved from secondary block
5360 0 ▶ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
5361  
5362 If $size == $N,
5363 Then # Migrate the second block to the first block now that the last slot is empty
5364 0 ▶ {PushR (rax, k7, zmm30);
Subroutine __ANON__: not called CC=1 SCAR=6.9
5365 0 my $S = getDFromZmm(31, $w, $transfer); # Offset of second block in first block
5366 0 $b->getBlock($B, $S, 30); # Get the second block
5367 0 $E->getDFromZmm(30, $n * $w, $transfer); # Get element from second block
5368 0 Mov rax, -2; # Load expansion mask
5369 0 Kmovq k7, rax; # Set expansion mask
5370 0 Vpexpandd "zmm31{k7}{z}", zmm30; # Expand second block into first block
5371 0 ($size-1)->putDIntoZmm(31, 0, $transfer); # Save new size in first block
5372 0 $b -> putBlock($B, $F, 31); # Save the first block
5373 0 $b ->freeBlock($B, offset=>$S); # Free the now redundant second block
5374 0 PopR;
5375 0 Jmp $success; # Element successfully retrieved from secondary block
5376 0 };
5377  
5378 If $size <= $N * ($N - 1),
5379 Then # Still within two levels
5380 {If $size % $N == 1,
5381 Then # Secondary block can be freed
5382 0 ▶ {PushR (rax, zmm30);
Subroutine __ANON__: not called CC=1 SCAR=6.9
5383 0 my $S = getDFromZmm(31, ($size / $N + 1) * $w, $transfer); # Address secondary block from first block
5384 0 $b ->getBlock($B, $S, 30); # Load secondary block
5385 0 $E->getDFromZmm(30, 0, $transfer); # Get first element from secondary block
5386 0 V(zero, 0)->putDIntoZmm(31, ($size / $N + 1) * $w, $transfer); # Zero at offset of secondary block in first block
5387 0 ($size-1)->putDIntoZmm(31, 0, $transfer); # Save new size in first block
5388 0 $b ->freeBlock($B, offset=>$S); # Free the secondary block
5389 0 $b ->putBlock ($B, $F, 31); # Put the first block back into memory
5390 0 PopR;
5391 0 Jmp $success; # Element successfully retrieved from secondary block
5392 0 ▶ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
5393  
5394 0 if (1) # Continue with existing secondary block
5395 0 {PushR (rax, r14, zmm30);
5396 0 my $S = getDFromZmm(31, (($size-1) / $N + 1) * $w, $transfer); # Offset of secondary block in first block
5397 0 $b ->getBlock($B, $S, 30); # Get the secondary block
5398 0 $E ->getDFromZmm(30, (($size - 1) % $N) * $w, $transfer); # Get element from secondary block
5399 0 ($size-1)->putDIntoZmm(31, 0, $transfer); # Save new size in first block
5400 0 $b ->putBlock($B, $S, 30); # Put the secondary block back into memory
5401 0 $b ->putBlock($B, $F, 31); # Put the first block back into memory
5402 0 PopR;
5403 0 Jmp $success; # Element successfully retrieved from secondary block
5404 }
5405 0 };
5406 0 };
5407  
5408 0 SetLabel $success;
5409 0 PopR;
5410 0 } [qw(bs first element)], name => 'Nasm::X86::Array::pop';
5411  
5412 0 $s->call($Array->address, $Array->first, @variables);
5413 }
5414  
5415 sub Nasm::X86::Array::size($;$$) # Return the size of an array as a variable.
5416 0 ▶ {my ($Array, $bs, $first) = @_; # Array descriptor, optional arena address, optional first block
Subroutine size: not called CC=5 SCAR=34.0
5417 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
5418  
5419 my $s = Subroutine
5420 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
5421 0 my $success = Label; # Short circuit if ladders by jumping directly to the end after a successful push
5422  
5423 0 my $B = $$p{bs}; # Arena
5424 0 my $F = $$p{first}; # First block
5425  
5426 0 PushR (r8, zmm31);
5427 0 my $transfer = r8; # Transfer data from zmm to variable via this register
5428 0 $Array->bs->getBlock($B, $F, 31); # Get the first block
5429 0 $$p{size}->copy(getDFromZmm(31, 0, $transfer)); # Size of array
5430  
5431 0 SetLabel $success;
5432 0 PopR;
5433 0 } [qw(bs first size)], name => 'Nasm::X86::Array::size';
5434  
5435 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
5436 first => ($first//$Array->first), my $size = V(size));
5437  
5438 0 $size # Return size as a variable
5439 }
5440  
5441 sub Nasm::X86::Array::get($@) # Get an element from the array.
5442 0 ▶ {my ($Array, @variables) = @_; # Array descriptor, variables
Subroutine get: not called CC=2 SCAR=17.9
5443 0 ▶ @_ >= 3 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 3 or confess() 0 0 0
5444 0 my $b = $Array->bs; # Underlying arena
5445 0 my $W = RegisterSize zmm0; # The size of a block
5446 0 my $w = $Array->width; # The size of an entry in a block
5447 0 my $n = $Array->slots1; # The number of slots in the first block
5448 0 my $N = $Array->slots2; # The number of slots in the secondary blocks
5449  
5450 my $s = Subroutine
5451 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
5452 0 my $success = Label; # Short circuit if ladders by jumping directly to the end after a successful push
5453  
5454 0 my $B = $$p{bs}; # Arena
5455 0 my $F = $$p{first}; # First block
5456 0 my $E = $$p{element}; # The element to be returned
5457 0 my $I = $$p{index}; # Index of the element to be returned
5458  
5459 0 PushR (r8, zmm31);
5460 0 my $transfer = r8; # Transfer data from zmm to variable via this register
5461 0 $b->getBlock($B, $F, 31); # Get the first block
5462 0 my $size = getDFromZmm(31, 0, $transfer); # Size of array
5463 If $I < $size,
5464 Then # Index is in array
5465 {If $size <= $n,
5466 Then # Element is in the first block
5467 0 ▶ {$E->getDFromZmm(31, ($I + 1) * $w, $transfer); # Get element
Subroutine __ANON__: not called CC=1 SCAR=6.9
5468 0 Jmp $success; # Element successfully inserted in first block
5469 0 ▶ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
5470  
5471 If $size <= $N * ($N - 1),
5472 Then # Still within two levels
5473 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
5474 0 $b->getBlock($B, $S, 31); # Get the second block
5475 0 $E->getDFromZmm(31, ($I % $N) * $w, $transfer); # Offset of element in second block
5476 0 Jmp $success; # Element successfully inserted in second block
5477 0 };
5478 0 };
5479  
5480 0 PrintErrString "Index out of bounds on get from array, "; # Array index out of bounds
5481 0 $I->err("Index: "); PrintErrString " "; $size->errNL("Size: ");
5482 0 Exit(1);
5483  
5484 0 SetLabel $success;
5485 0 PopR;
5486 0 } [qw(bs first index element)], name => 'Nasm::X86::Array::get';
5487  
5488 0 $s->call($Array->address, $Array->first, @variables);
5489 }
5490  
5491 sub Nasm::X86::Array::put($@) # Put an element into an array as long as it is with in its limits established by pushing.
5492 0 ▶ {my ($Array, @variables) = @_; # Array descriptor, variables
Subroutine put: not called CC=2 SCAR=17.9
5493 0 ▶ @_ >= 3 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 3 or confess() 0 0 0
5494 0 my $b = $Array->bs; # Underlying arena
5495 0 my $W = RegisterSize zmm0; # The size of a block
5496 0 my $w = $Array->width; # The size of an entry in a block
5497 0 my $n = $Array->slots1; # The number of slots in the first block
5498 0 my $N = $Array->slots2; # The number of slots in the secondary blocks
5499  
5500 my $s = Subroutine
5501 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
5502 0 my $success = Label; # Short circuit if ladders by jumping directly to the end after a successful push
5503  
5504 0 my $B = $$p{bs}; # Arena
5505 0 my $F = $$p{first}; # First block
5506 0 my $E = $$p{element}; # The element to be added
5507 0 my $I = $$p{index}; # Index of the element to be inserted
5508  
5509 0 PushR (r8, zmm31);
5510 0 my $transfer = r8; # Transfer data from zmm to variable via this register
5511 0 $b->getBlock($B, $F, 31); # Get the first block
5512 0 my $size = getDFromZmm(31, 0, $transfer); # Size of array
5513 If $I < $size,
5514 Then # Index is in array
5515 {If $size <= $n,
5516 Then # Element is in the first block
5517 0 ▶ {$E->putDIntoZmm(31, ($I + 1) * $w, $transfer); # Put element
Subroutine __ANON__: not called CC=1 SCAR=6.9
5518 0 $b->putBlock($B, $F, 31); # Get the first block
5519 0 Jmp $success; # Element successfully inserted in first block
5520 0 ▶ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
5521  
5522 If $size <= $N * ($N - 1),
5523 Then # Still within two levels
5524 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
5525 0 $b->getBlock($B, $S, 31); # Get the second block
5526 0 $E->putDIntoZmm(31, ($I % $N) * $w, $transfer); # Put the element into the second block in first block
5527 0 $b->putBlock($B, $S, 31); # Get the first block
5528 0 Jmp $success; # Element successfully inserted in second block
5529 0 };
5530 0 };
5531  
5532 0 PrintErrString "Index out of bounds on put to array, "; # Array index out of bounds
5533 0 $I->err("Index: "); PrintErrString " "; $size->errNL("Size: ");
5534 0 Exit(1);
5535  
5536 0 SetLabel $success;
5537 0 PopR;
5538 0 } [qw(first index element bs)], name => 'Nasm::X86::Array::put';
5539  
5540 0 $s->call($Array->address, $Array->first, @variables);
5541 }
5542  
5543 #D1 Tree # Tree constructed as sets of blocks in an arena.
5544  
5545 sub Nasm::X86::Arena::DescribeTree($) # Return a descriptor for a tree in the specified arena.
5546 0 ▶ {my ($arena) = @_; # Arena descriptor
Subroutine DescribeTree: not called CC=4 SCAR=30.0
5547 0 ▶ @_ == 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess() 0 0 0
5548  
5549 0 my $b = RegisterSize zmm0; # Size of a block == size of a zmm register
5550 0 my $o = RegisterSize eax; # Size of a double word
5551  
5552 0 my $length = $b / $o - 2; # Length of block to split
5553 0 my $split = $length / 2 * $o; # Offset of splitting key
5554  
5555 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
5556 0 ▶ confess "Splitting key offset must be 28" unless $split == 28; # Splitting key offset
Branch: 1 branch
BranchTrueFalseTotal
unless $split == 28 0 0 0
5557  
5558 0 genHash(__PACKAGE__."::Tree", # Tree.
5559 bs => $arena, # Arena definition.
5560 data => G(data), # Variable containing the last data found
5561 first => G(first), # Variable addressing offset to first block of keys.
5562 found => G(found), # Variable indicating whether the last find was successful or not
5563 leftLength => $length / 2, # Left split length
5564 lengthOffset => $b - $o * 2, # Offset of length in keys block. The length field is a word - see: "MultiWayTree.svg"
5565 loop => $b - $o, # Offset of keys, data, node loop.
5566 maxKeys => $length, # Maximum number of keys.
5567 splittingKey => $split, # POint at which to split a full block
5568 rightLength => $length - 1 - $length / 2, # Right split length
5569 subTree => G(subTree), # Variable indicating whether the last find found a sub tree
5570 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 .
5571 treeBitsMask => 0x3fff, # Total of 14 tree bits
5572 up => $b - $o * 2, # Offset of up in data block.
5573 width => $o, # Width of a key or data slot.
5574 );
5575 }
5576  
5577 sub Nasm::X86::Arena::CreateTree($;$) # Create a tree in an arena.
5578 0 ▶ {my ($arena, $bs) = @_; # Arena description, optional arena address
Subroutine CreateTree: not called CC=4 SCAR=30.0
5579 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
5580  
5581 0 my $t = $arena->DescribeTree; # Return a descriptor for a tree at the specified offset in the specified arena
5582  
5583 my $s = Subroutine
5584 0 ▶ {my ($p) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
5585 0 Comment "Create a block multiway Tree start";
5586 0 my $keys = $t->allocBlock($$p{bs}); # Allocate first keys block
5587 0 $$p{first}->copy($keys); # Save address of first block used to contain the root of the tree
5588 0 PushR my @save = (r8, r9, zmm31);
5589 0 ClearRegisters zmm31;
5590 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.
5591 0 $arena->putBlock($$p{bs}, $keys, 31, r8, r9); # Write first keys
5592 0 PopR;
5593 0 } [qw(bs first)], name => 'Nasm::X86::Arena::CreateTree';
5594  
5595 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
5596  
5597 0 $t # Description of array
5598 }
5599  
5600 sub Nasm::X86::Tree::reload($%) # Reload the specified tree description.
5601 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
5602 0 ▶ @_ >= 1 or confess "At least one parameter";
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 1 or confess("At least one parameter") 0 0 0
5603  
5604 0 my $t = $tree->bs->DescribeTree; # Return a descriptor for a tree
5605 0 ▶ $t->bs = $options{arena} if $options{arena}; # Set the arena if requested
Branch: 1 branch
BranchTrueFalseTotal
if $options{"arena"} 0 0 0
5606 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
5607 0 $t
5608 }
5609  
5610 sub Nasm::X86::Tree::allocKeysDataNode($$$$$) #P Allocate a keys/data/node block and place it in the numbered zmm registers.
5611 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
5612 0 ▶ @_ == 5 or confess "5 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 5 or confess("5 parameters") 0 0 0
5613  
5614 my $s = Subroutine
5615 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
5616  
5617 0 my $B = $$p{bs}; # Arena
5618 0 $t->bs->allocZmmBlock($B, my $k = V(offset)); # Keys
5619 0 $t->bs->allocZmmBlock($B, my $d = V(offset)); # Data
5620 0 $t->bs->allocZmmBlock($B, my $n = V(offset)); # Children
5621  
5622 0 PushR r8;
5623 0 $t->putLoop($d, $K, r8); # Set the link from key to data
5624 0 $t->putLoop($n, $D, r8); # Set the link from data to node
5625 0 $t->putLoop($k, $N, r8); # Set the link from node to key
5626 0 PopR r8;
5627 0 } [qw(bs)], name => qq(Nasm::X86::Tree::allocKeysDataNode::${K}::${D}::${N});# Create a subroutine for each combination of registers encountered
5628  
5629 0 $s->call($bs);
5630 } # allocKeysDataNode
5631  
5632 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.
5633 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
5634 0 ▶ @_ >= 4 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 4 or confess() 0 0 0
5635  
5636 0 my $K = 31; my $D = 30; my $N = 29; # Key, data, node blocks
5637  
5638 my $s = Subroutine
5639 0 ▶ {my ($parameters) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
5640 0 my $success = Label; # Short circuit if ladders by jumping directly to the end after a successful push
5641  
5642 0 my $B = $$parameters{bs}; # Arena
5643 0 my $k = $$parameters{key}; # Key we are looking for
5644 0 my $n = $$parameters{node}; # Node to split
5645  
5646 0 PushR (r8, r9); PushZmm 22...31;
5647  
5648 0 my $transfer = r8; # Use this register to transfer data between zmm blocks and variables
5649 0 my $work = r9; # Work register
5650  
5651 0 $t->getKeysDataNode($B, $n, $K, $D, $N, $transfer, $work); # Load node
5652  
5653 If $t->getLengthInKeys($K) != $t->maxKeys,
5654 Then # Only split full blocks
5655 0 ▶ {Jmp $success;
Subroutine __ANON__: not called CC=1 SCAR=6.9
5656 0 };
5657  
5658 0 my $p = $t->getUpFromData($D, $transfer); # Parent
5659 If $p > 0,
5660 Then # Not the root
5661 0 ▶ {my $s = getDFromZmm $K, $t->splittingKey, $transfer; # Splitting key
Subroutine __ANON__: not called CC=1 SCAR=6.9
5662 If $k < $s,
5663 Then # Split left node pushing remainder right so that we keep the key we are looking for in the left node
5664 0 ▶ {Vmovdqu64 zmm28, zmm31; # Load left node
Subroutine __ANON__: not called CC=1 SCAR=6.9
5665 0 Vmovdqu64 zmm27, zmm30;
5666 0 Vmovdqu64 zmm26, zmm29;
5667 0 $t->allocKeysDataNode($B, 25, 24, 23); # Create new right node
5668  
5669 0 $t->getKeysDataNode($B, $p, $K, $D, $N, $transfer, $work); # Load parent
5670 0 $t->splitFullLeftNode;
5671 0 $t->putKeysDataNode($B, $p, $K, $D, $N, $transfer, $work); # Save parent
5672 0 $t->putKeysDataNode($B, $n, 28, 27, 26, $transfer, $work); # Save left
5673 0 my $r = $t->getLoop (23, $transfer); # Offset of right keys
5674 0 $t->putUpIntoData ($p, 24, $transfer); # Reparent new block
5675 0 $t->putKeysDataNode($B, $r, 25, 24, 23, $transfer, $work) # Save right back into node we just split
5676 },
5677 Else # Split right node pushing remainder left so that we keep the key we are looking for in the right node
5678 0 ▶ {Vmovdqu64 zmm25, zmm31; # Load right node
Subroutine __ANON__: not called CC=1 SCAR=6.9
5679 0 Vmovdqu64 zmm24, zmm30;
5680 0 Vmovdqu64 zmm23, zmm29;
5681 0 $t->allocKeysDataNode($B, 28, 27, 26); # Create new left node
5682  
5683 0 $t->getKeysDataNode($B, $p, $K, $D, $N, $transfer, $work); # Load parent
5684 0 $t->splitFullRightNode;
5685 0 $t->putKeysDataNode($B, $p, $K, $D, $N, $transfer, $work); # Save parent
5686 0 my $l = $t->getLoop (26, $transfer); # Offset of left keys
5687 0 $t->putUpIntoData ($p, 27, $transfer); # Reparent new block
5688 0 $t->putKeysDataNode($B, $l, 28, 27, 26, $transfer, $work); # Save left
5689 0 $t->putKeysDataNode($B, $n, 25, 24, 23, $transfer, $work); # Save right back into node we just split
5690 0 };
5691 },
5692 Else
5693 0 ▶ {$t->splitFullRoot($B); # Root
Subroutine __ANON__: not called CC=1 SCAR=6.9
5694 0 my $l = getDFromZmm $N, 0, $transfer;
5695 0 my $r = getDFromZmm $N, $t->width, $transfer;
5696 0 $t->putKeysDataNode($B, $n, $K, $D, $N, $transfer, $work); # Save root
5697 0 $t->putKeysDataNode($B, $l, 28, 27, 26, $transfer, $work); # Save left
5698 0 $t->putKeysDataNode($B, $r, 25, 24, 23, $transfer, $work); # Save right
5699 0 };
5700  
5701 0 SetLabel $success; # Insert completed successfully
5702 0 PopZmm;
5703 0 PopR;
5704 0 } [qw(bs node key)], name => 'Nasm::X86::Tree::splitNode';
5705  
5706 0 $s->call(bs=>$bs, node=>$node, key=>$key, @variables);
5707  
5708 } # splitNode
5709  
5710 sub Nasm::X86::Tree::reParent($$$$$@) #P Reparent the children of a node held in registers. The children are in the backing arena not registers.
5711 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
5712 0 ▶ @_ >= 5 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 5 or confess() 0 0 0
5713  
5714 my $s = Subroutine
5715 0 ▶ {my ($parameters) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
5716 0 PushR (r8);
5717  
5718 0 my $B = $$parameters{bs}; # Arena
5719 0 my $L = $t->getLengthInKeys($PK) + 1; # Number of children
5720 0 my $p = $t->getUpFromDataNM($PD, r8); # Parent node offset in compressed format as a variable
5721  
5722 If $t->getLoop($PD, r8) > 0, sub # Not a leaf
5723 0 ▶ {PushR (rax, rdi);
Subroutine __ANON__: not called CC=1 SCAR=6.9
5724 0 Mov rdi, rsp; # Save stack base
5725 0 PushRR "zmm$PN"; # Child nodes on stack
5726 0 my $w = $t->width; my $l = $t->loop; my $u = $t->up; # Steps we will make along the chain
5727 0 my $s = V(start);
5728 $L->for(sub # Each child
5729 0 ▶ {my ($index, $start, $next, $end) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
5730 0 &PopEax; # The nodes are double words but we cannot pop a double word from the stack in 64 bit long mode using pop
5731 0 $s->getReg(rax);
5732 0 $t->bs->putChain($B, $s, $p, $l, $u);
5733 0 });
5734  
5735 0 Mov rsp, rdi; # Level stack
5736 0 PopR;
5737 0 };
5738 0 PopR;
5739 0 } [qw(bs)], name => 'Nasm::X86::Tree::reParent';
5740  
5741 0 $s->call($t->address, @variables);
5742 } # reParent
5743  
5744 sub Nasm::X86::Tree::transferTreeBitsFromParent($$$$) #P Transfer tree bits when splitting a full node.
5745 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
5746  
5747 0 PushR my @save = my ($whole, $half) = (r15, r14);
5748 0 $t->getTreeBits($parent, $whole); # Transfer Tree bits
5749 0 Cmp $whole, 0;
5750 IfNz # Action required iff there are some tree bits
5751 Then
5752 0 ▶ {Mov $half, $whole; # Left tree bits
Subroutine __ANON__: not called CC=1 SCAR=6.9
5753 0 And $half, ((1 << $t->leftLength) - 1); # Isolate left bits
5754 0 $t->putTreeBits($left, $half); # Save left tree bits
5755  
5756 0 Mov $half, $whole; # Right tree bits
5757 0 Shr $half, $t->leftLength + 1; # Isolate right bits
5758 0 And $half, ((1 << $t->rightLength) - 1); # Remove any bits above
5759 0 $t->putTreeBits($right, $half); # Save right tree bits
5760  
5761 0 Mov $half, $whole; # Right tree bits
5762 0 Shr $half, $t->leftLength; # Parent bit
5763 0 And $half, 1; # Only one bit
5764 0 $t->putTreeBits($parent, $half); # Save parent tree bits
5765 0 };
5766 0 PopR;
5767 }
5768  
5769 sub Nasm::X86::Tree::transferTreeBitsFromLeftOrRight($$$$$$) #P Transfer tree bits when splitting a full left or right node.
5770 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
5771  
5772 0 PushR my @save = my ($whole, $half, $bits) = ChooseRegisters(3, $point);
5773 0 ▶ $t->getTreeBits($rnl ? $right : $left, $whole); # Tree bits
Branch: 1 branch
BranchTrueFalseTotal
$rnl ? : 0 0 0
5774  
5775 0 Mov $half, $whole; # Right bits
5776 0 Shr $half, $t->leftLength + 1; # Isolate right bits
5777 0 $t->putTreeBits($right, $half); # Save right bits
5778  
5779 0 $t->getTreeBits($parent, $bits); # Parent bits
5780 0 InsertZeroIntoRegisterAtPoint($point, $bits);
5781 0 Mov $half, $whole; # Tree bit of key being moved into parent from left
5782 0 Shr $half, $t->leftLength+1; # Tree bit to move into parent is now in carry flag
5783 0 ▶ IfC Then {Or $bits, $point}; # One parent bit
Subroutine __ANON__: not called CC=1 SCAR=6.9
5784 0 $t->putTreeBits($parent, $bits); # Put parent tree bits
5785  
5786 0 Mov $half, $whole; # Left bits
5787 0 And $half, ((1 << $t->leftLength) - 1); # Remove any bits above
5788 0 $t->putTreeBits($left, $half); # Save left bits
5789 0 PopR;
5790 }
5791  
5792 sub Nasm::X86::Tree::transferTreeBitsFromLeft($$$$$) #P Transfer tree bits when splitting a full left node.
5793 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
5794 0 $t->transferTreeBitsFromLeftOrRight(0, $point, $parent, $left, $right);
5795 }
5796  
5797 sub Nasm::X86::Tree::transferTreeBitsFromRight($$$$$) #P Transfer tree bits when splitting a full right node.
5798 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
5799 0 $t->transferTreeBitsFromLeftOrRight(1, $point, $parent, $left, $right);
5800 }
5801  
5802 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.
5803 0 ▶ {my ($t, $bs) = @_; # Tree descriptor, arena address
Subroutine splitFullRoot: not called CC=2 SCAR=17.9
5804 0 ▶ @_ == 2 or confess "2 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess("2 parameters") 0 0 0
5805  
5806 0 my $length = $t->maxKeys; # Length of block to split
5807 0 my $ll = $t->leftLength; # Left split point
5808 0 my $rl = $t->rightLength; # Right split point
5809  
5810 0 my $TK = 31; my $TD = 30; my $TN = 29; # Root key, data, node
5811 0 my $LK = 28; my $LD = 27; my $LN = 26; # Key, data, node blocks in left child
5812 0 my $RK = 25; my $RD = 24; my $RN = 23; # Key, data, node blocks in right child
5813 0 my $Test = 22; # Zmm used to hold test values via broadcast
5814  
5815 my $s = Subroutine
5816 0 ▶ {my ($parameters) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
5817 0 my $success = Label; # Short circuit if ladders by jumping directly to the end after a successful push
5818 0 my $B = $$parameters{bs};
5819  
5820 0 PushR (k6, k7, r8, zmm22);
5821 0 my $transfer = r8; # Use this register to transfer data between zmm blocks and variables
5822 0 my $work = r9; # Work register
5823  
5824 0 ▶ If $t->getLengthInKeys($TK) != $t->maxKeys, sub {Jmp $success}; # Only split full blocks
Subroutine __ANON__: not called CC=1 SCAR=6.9
5825  
5826 0 $t->allocKeysDataNode($B, 28, 27, 26); # Allocate immediate children of the root
5827 0 my $l = $t->getLoop( 26, $transfer);
5828 0 $t->putKeysDataNode ($B, $l, 28, 27, 26, $transfer, $work);
5829 0 $t->allocKeysDataNode($B, 25, 24, 23);
5830 0 my $r = $t->getLoop (23, $transfer);
5831 0 $t->putKeysDataNode ($B, $l, 25, 24, 23, $transfer, $work);
5832 0 $t->reParent ($B, 28, 27, 26); # Reparent grandchildren
5833 0 $t->reParent ($B, 25, 24, 23);
5834  
5835 0 my $n = $t->getLoop($TD, $transfer); # Offset of node block or zero if there is no node block
5836 0 my $to = $t->getLoop($TN, $transfer); # Offset of root block
5837 0 my $lo = $t->getLoop($LN, $transfer); # Offset of left block
5838 0 my $ro = $t->getLoop($RN, $transfer); # Offset of right block
5839  
5840 0 LoadBitsIntoMaskRegister(k7, $transfer, "11", -$length); # Area to clear preserving loop and up/length
5841 0 &Vmovdqu32 (zmm $LK."{k7}{z}", $LK); # Clear left
5842 0 &Vmovdqu32 (zmm $LD."{k7}{z}", $LD);
5843 0 &Vmovdqu32 (zmm $RK."{k7}{z}", $RK); # Clear right
5844 0 &Vmovdqu32 (zmm $RD."{k7}{z}", $RD);
5845  
5846 0 LoadBitsIntoMaskRegister(k7, $transfer, "10", -$length); # Area to clear preserving loop
5847 0 &Vmovdqu32 (zmm $LN."{k7}{z}", $LN); # Clear left
5848 0 &Vmovdqu32 (zmm $RK."{k7}{z}", $RK); # Clear right
5849  
5850 0 LoadBitsIntoMaskRegister(k7, $transfer, "", +$ll); # Constant mask up to the split point
5851 0 &Vmovdqu32 (zmm $LK."{k7}", $TK); # Split keys left
5852 0 &Vmovdqu32 (zmm $LD."{k7}", $TD); # Split data left
5853 0 ▶ If $n > 0, sub {&Vmovdqu32 (zmm $LN."{k7}", $TN)}; # Split nodes left
Subroutine __ANON__: not called CC=1 SCAR=6.9
5854  
5855 0 LoadBitsIntoMaskRegister(k6, $transfer, '', +$rl, -($ll+1)); # Constant mask from one beyond split point to end of keys
5856 0 Kshiftrq k7, k6, $ll+1; # Constant mask for compressed right keys
5857  
5858 0 &Vmovdqu32 (zmm $Test."{k6}{z}", $TK); # Split right keys
5859 0 &Vpcompressd (zmm $Test."{k6}", $Test); # Compress right keys
5860 0 &Vmovdqu32 (zmm $RK. "{k7}", $Test); # Save right keys
5861  
5862 0 &Vmovdqu32 (zmm $Test."{k6}{z}", $TD); # Split right data
5863 0 &Vpcompressd (zmm $Test."{k6}", $Test); # Compress right data
5864 0 &Vmovdqu32 (zmm $RD. "{k7}", $Test); # Save right data
5865  
5866 If $n > 0,
5867 Then # Split nodes right
5868 0 ▶ {&Vmovdqu32 (zmm $Test."{k6}{z}", $TN); # Split right nodes
Subroutine __ANON__: not called CC=1 SCAR=6.9
5869 0 &Vpcompressd (zmm $Test."{k6}", $Test); # Compress right node
5870 0 &Vmovdqu32 (zmm $RN. "{k7}", $Test); # Save right node
5871 0 };
5872  
5873 0 my $k = getDFromZmm $TK, $ll * (my $w = $t->width), $transfer; # Splitting key
5874 0 my $d = getDFromZmm $TD, $ll * $w, $transfer; # Splitting data
5875  
5876 0 LoadConstantIntoMaskRegister(k7, $transfer, 1); # Position of key, data in root node
5877 0 $k->zBroadCastD($Test); # Broadcast keys
5878 0 &Vmovdqu32 (zmm $TK."{k7}", $Test); # Insert key in root
5879 0 $d->zBroadCastD($Test); # Broadcast keys
5880 0 &Vmovdqu32 (zmm $TD."{k7}", $Test); # Insert data in root
5881 0 LoadBitsIntoMaskRegister(k7, $transfer, "11", -($length-1), 1); # Unused fields
5882 0 &Vmovdqu32 (zmm $TK."{k7}{z}", $TK); # Clear unused keys in root
5883 0 &Vmovdqu32 (zmm $TD."{k7}{z}", $TD); # Clear unused data in root
5884  
5885 If $n > 0,
5886 Then
5887 0 ▶ {LoadBitsIntoMaskRegister(k7, $transfer, "1", -$length, 1); # Unused fields
Subroutine __ANON__: not called CC=1 SCAR=6.9
5888 0 &Vmovdqu32 (zmm $TN."{k7}{z}", $TN); # Clear unused node in root
5889 0 };
5890  
5891 0 $t->putLengthInKeys($TK, K(one, 1)); # Set length of root keys
5892 0 $t->putLengthInKeys($LK, K(leftLength, $ll)); # Length of left node
5893 0 $t->putLengthInKeys($RK, K(rightLength, $rl)); # Length of right node
5894  
5895 0 $t->putUpIntoData($to, $LD, $transfer); # Set parent of left node
5896 0 $t->putUpIntoData($to, $RD, $transfer); # Set parent of right node
5897  
5898 0 $lo->putDIntoZmm($TN, 0, $transfer); # Insert offset of left node in root nodes
5899 0 $ro->putDIntoZmm($TN, $w, $transfer); # Insert offset of right node in root nodes
5900  
5901 0 $t->transferTreeBitsFromParent($TK, $LK, $RK); # Transfer any tree bits present
5902  
5903 0 SetLabel $success; # Insert completed successfully
5904 0 PopR;
5905 0 } [qw(bs)], name => 'Nasm::X86::Tree::splitFullRoot';
5906  
5907 0 $s->call (bs => $bs);
5908 } # splitFullRoot
5909  
5910 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.
5911 0 ▶ {my ($t, $right) = @_; # Tree descriptor, 0 left or 1 right
Subroutine splitFullLeftOrRightNode: not called CC=2 SCAR=17.9
5912 0 ▶ @_ == 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess() 0 0 0
5913  
5914 0 my $length = $t->maxKeys; # Length of block to split
5915 0 my $ll = $t->leftLength; # Left split point
5916 0 my $rl = $t->rightLength; # Right split point
5917  
5918 0 my $PK = 31; my $PD = 30; my $PN = 29; # Root key, data, node. These registers are saved in L<splitNode>
5919 0 my $LK = 28; my $LD = 27; my $LN = 26; # Key, data, node blocks in left child
5920 0 my $RK = 25; my $RD = 24; my $RN = 23; # Key, data, node blocks in right child
5921 0 my $Test = 22; # Zmm used to hold test values via broadcast
5922  
5923 my $s = Subroutine
5924 0 ▶ {my ($parameters) = @_; # Parameters
Subroutine __ANON__: not called CC=6 SCAR=37.4
5925 0 my $success = Label; # Short circuit if ladders by jumping directly to the end after a successful push
5926  
5927 0 PushR (r8);
5928 0 my $transfer = r8; # Use this register to transfer data between zmm blocks and variables
5929  
5930 If $t->getLengthInKeys($right ? $RK : $LK) != $t->maxKeys, # Only split full blocks
5931 0 ▶ Then {Jmp $success};
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$right ? : 0 0 0
5932  
5933 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
5934 0 my $lo = $t->getLoop($LN, $transfer); # Offset of left block
5935 0 my $ro = $t->getLoop($RN, $transfer); # Offset of right block
5936  
5937 0 ▶ if ($right)
Branch: 1 branch
BranchTrueFalseTotal
if ($right) 0 0 0
5938 0 {LoadBitsIntoMaskRegister(k7, $transfer, "00", +$length); # Left mask for keys and data
5939 0 &Vmovdqu32(zmm $LK."{k7}", $RK); # Copy right keys to left node
5940 0 &Vmovdqu32(zmm $LD."{k7}", $RD); # Copy right data to left node
5941 0 LoadBitsIntoMaskRegister(k7, $transfer, "01", +$length); # Left mask for child nodes
5942 0 &Vmovdqu32(zmm $LN."{k7}", $RN); # Copy right nodes to left node
5943 }
5944  
5945 0 my $k = getDFromZmm $LK, $ll * (my $w = $t->width), $transfer; # Splitting key
5946 0 my $d = getDFromZmm $LD, $ll * $w, $transfer; # Splitting data
5947  
5948 0 LoadBitsIntoMaskRegister(k6, $transfer, '', +$rl, -($ll+1)); # Constant mask from one beyond split point to end of keys
5949 0 Kshiftrq k7, k6, $ll+1; # Constant mask for compressed right keys
5950  
5951 0 &Vmovdqu32 (zmm $Test."{k6}{z}", $LK); # Split out right keys
5952 0 &Vpcompressd (zmm $Test."{k6}", $Test); # Compress right keys
5953 0 &Vmovdqu32 (zmm $RK. "{k7}", $Test); # Save right keys
5954  
5955 0 &Vmovdqu32 (zmm $Test."{k6}{z}", $LD); # Split out right data
5956 0 &Vpcompressd (zmm $Test."{k6}", $Test); # Compress right data
5957 0 &Vmovdqu32 (zmm $RD. "{k7}", $Test); # Save right data
5958  
5959 If $n > 0,
5960 Then # Split nodes right
5961 0 ▶ {&Vmovdqu32 (zmm $Test."{k6}{z}", $LN); # Split right nodes
Subroutine __ANON__: not called CC=1 SCAR=6.9
5962 0 &Vpcompressd (zmm $Test."{k6}", $Test); # Compress right node
5963 0 &Vmovdqu32 (zmm $RN. "{k7}", $Test); # Save right node
5964 0 };
5965  
5966 0 ▶ if ($right)
Branch: 1 branch
BranchTrueFalseTotal
if ($right) { } 0 0 0
5967 0 {LoadBitsIntoMaskRegister(k7, $transfer, '11', -($rl+2), +($ll-1)); # Areas to retain
5968 0 LoadBitsIntoMaskRegister(k6, $transfer, '11', -($rl+1), +$ll);
5969  
5970 0 &Vmovdqu32 (zmm $RK."{k7}{z}", $RK); # Remove unused keys on right
5971 0 &Vmovdqu32 (zmm $RD."{k7}{z}", $RD); # Remove unused data on right
5972  
5973 If $n > 0,
5974 Then # Split nodes left
5975 0 ▶ {LoadBitsIntoMaskRegister(k7, $transfer, '10', -($rl+2), +($ll-1));
Subroutine __ANON__: not called CC=1 SCAR=6.9
5976 0 &Vmovdqu32 (zmm $RN."{k7}{z}", $RN);
5977 0 };
5978  
5979 0 &Vmovdqu32 (zmm $LK."{k6}{z}", $LK); # Remove unused keys on left
5980 0 &Vmovdqu32 (zmm $LD."{k6}{z}", $LD); # Remove unused data on left
5981  
5982 If $n > 0,
5983 Then # Split nodes left
5984 0 ▶ {LoadBitsIntoMaskRegister(k6, $transfer, '10', -($rl+1), +$ll);
Subroutine __ANON__: not called CC=1 SCAR=6.9
5985 0 &Vmovdqu32 (zmm $LN."{k6}{z}", $LN);
5986 0 };
5987 }
5988 else
5989 0 {LoadBitsIntoMaskRegister(k7, $transfer, "11", -($rl+1), +$ll); # Mask to reset moved keys
5990  
5991 0 &Vmovdqu32 (zmm $LK."{k7}{z}", $LK); # Remove unused keys
5992 0 &Vmovdqu32 (zmm $LD."{k7}{z}", $LD); # Split data left
5993 If $n > 0,
5994 Then # Split nodes left
5995 0 ▶ {LoadBitsIntoMaskRegister(k7, $transfer, '10', -($rl+1), +$ll);
Subroutine __ANON__: not called CC=1 SCAR=6.9
5996 0 &Vmovdqu32 (zmm $LN."{k7}{z}", $LN);
5997 0 };
5998 }
5999 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
6000 0 LoadBitsIntoMaskRegister(k7, $transfer, '', +$length); # Nodes
6001 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
6002  
6003 0 Kandnq k5, k6, k7; # Expansion mask
6004 0 &Vpexpandd (zmm $PK."{k5}", $PK); # Shift up keys
6005 0 &Vpexpandd (zmm $PD."{k5}", $PD); # Shift up keys
6006 0 $k->zBroadCastD($Test); # Broadcast new key
6007 0 &Vmovdqu32 (zmm $PK."{k6}", $Test); # Insert new key
6008 0 $d->zBroadCastD($Test); # Broadcast new data
6009 0 &Vmovdqu32 (zmm $PD."{k6}", $Test); # Insert new data
6010  
6011 0 Kmovq r15, k6; # Point at which to insert in parent
6012 0 $t->transferTreeBitsFromLeftOrRight($right, r15, $PK, $LK, $RK);
6013  
6014 If $n > 0,
6015 Then # Insert new left node offset into parent nodes
6016 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
6017 0 Kandnq k5, k6, k7; # Expansion mask
6018 0 &Vpexpandd (zmm $PN."{k5}", $PN); # Shift up nodes
6019 0 ▶ ($right ? $lo : $ro)->zBroadCastD($Test); # Broadcast left node offset
Branch: 1 branch
BranchTrueFalseTotal
$right ? : 0 0 0
6020 0 &Vmovdqu32 (zmm $PN."{k6}", $Test); # Insert right node offset
6021 0 };
6022  
6023 0 my $l = $t->getLengthInKeys($PK); # Length of parent
6024 0 $t->putLengthInKeys($PK, $l + 1); # New length of parent
6025 0 $t->putLengthInKeys($LK, K(leftLength, $ll)); # Length of left node
6026 0 $t->putLengthInKeys($RK, K(rightLength, $rl)); # Length of right node
6027  
6028 0 SetLabel $success; # Insert completed successfully
6029 0 PopR;
6030 0 } [], name => "splitFullLeftOrRightNode_$right";
6031  
6032 0 $s->call;
6033 } # splitFullLeftOrRightNode
6034  
6035 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.
6036 0 ▶ {my ($t) = @_; # Tree descriptor
Subroutine splitFullLeftNode: not called CC=2 SCAR=17.9
6037 0 ▶ @_ == 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess() 0 0 0
6038 0 $t->splitFullLeftOrRightNode(0);
6039 }
6040  
6041 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.
6042 0 ▶ {my ($t) = @_; # Tree descriptor
Subroutine splitFullRightNode: not called CC=2 SCAR=17.9
6043 0 ▶ @_ == 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess() 0 0 0
6044 0 $t->splitFullLeftOrRightNode(1);
6045 }
6046  
6047 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.
6048 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
6049 0 ▶ @_ == 7 or confess "7 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 7 or confess("7 parameters") 0 0 0
6050 0 my $W = $t->width; # Width of keys and data
6051  
6052 my $s = Subroutine
6053 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
6054 0 my $success = Label; # Short circuit if ladders by jumping directly to the end after a successful push
6055  
6056 0 my $B = $$p{bs}; # Arena
6057 0 my $F = $$p{first}; # First keys block
6058 0 my $K = $$p{key}; # Key to find
6059  
6060 0 my $tree = V(tree)->copy($F); # Start at the first key block
6061 0 PushR k6, k7, r8, r9, r14, r15; PushZmm 28..31;
6062 0 my $zmmKeys = 31; my $zmmData = 30; my $zmmNode = 29; my $zmmTest = 28;
6063 0 my $lengthMask = k6; my $testMask = k7;
6064 0 my $transfer = r8; # Use this register to transfer data between zmm blocks and variables
6065 0 my $work = r9; # Work register
6066  
6067 0 $K->setReg(r15); # Load key into test register
6068 0 Vpbroadcastd "zmm$zmmTest", r15d;
6069  
6070 0 $t->splitNode($B, $F, $K); # Split the root
6071  
6072 ForEver # Step down through tree
6073 0 ▶ {my ($start, $end) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
6074 0 $t->getKeysDataNode($B, $tree, $zmmKeys, $zmmData, $zmmNode, # Get the keys/data/nodes block
6075 $transfer, $work);
6076 0 my $node = getDFromZmm $zmmNode, 0, $transfer; # First element of node block, which will be zero if we are on a leaf
6077  
6078 0 my $l = $t->getLengthInKeys($zmmKeys); # Length of the block
6079 0 $l->setMaskFirst($lengthMask); # Set the length mask
6080 0 Vpcmpud "$testMask\{$lengthMask}", "zmm$zmmKeys", "zmm$zmmTest", 0; # Check for equal elements
6081  
6082 0 Ktestw $testMask, $testMask;
6083 IfNz # Result mask is non zero so we must have found the key
6084 Then
6085 0 ▶ {Kmovq r15, $testMask;
Subroutine __ANON__: not called CC=1 SCAR=6.9
6086 0 Tzcnt r14, r15; # Trailing zeros gives index
6087 0 $$p{compare}->copy(K(zero, 0)); # Key found
6088 0 $$p{index} ->getReg(r14); # Index from trailing zeros
6089 0 $$p{offset} ->copy($tree); # Offset of matching block
6090 0 Jmp $success; # Return
6091 0 };
6092  
6093 0 Vpcmpud "$testMask\{$lengthMask}", "zmm$zmmTest", "zmm$zmmKeys", 1; # Check for greater elements
6094 0 Ktestw $testMask, $testMask;
6095 IfNz # Non zero implies that the key is less than some of the keys in the block
6096 Then
6097 0 ▶ {Kmovq r15, $testMask;
Subroutine __ANON__: not called CC=1 SCAR=6.9
6098 0 Tzcnt r14, r15; # Trailing zeros
6099 If $node == 0,
6100 Then # We are on a leaf
6101 0 ▶ {$$p{compare}->copy(K(minusOne, -1)); # Key less than
Subroutine __ANON__: not called CC=1 SCAR=6.9
6102 0 $$p{index} ->getReg(r14); # Index from trailing zeros
6103 0 $$p{offset} ->copy($tree); # Offset of matching block
6104 0 Jmp $success; # Return
6105 0 };
6106 0 $tree->copy(getDFromZmm $zmmNode, "r14*$W", $transfer); # Corresponding node
6107 0 Jmp $start; # Loop
6108 0 };
6109  
6110 0 if (1) # Key greater than all keys in block
6111 {If $node == 0,
6112 Then # We have reached a leaf
6113 0 ▶ {$$p{compare}->copy(K(plusOne, +1)); # Key greater than last key
Subroutine __ANON__: not called CC=1 SCAR=6.9
6114 0 $$p{index} ->copy($l-1); # Index of last key which we are greater than
6115 0 $$p{offset} ->copy($tree); # Offset of matching block
6116 0 Jmp $success
6117 0 };
6118 };
6119 0 my $next = getDFromZmm $zmmNode, $l * $t->width, $transfer; # Greater than all keys so step through last child node
6120 0 $tree->copy($next);
6121 0 };
6122  
6123 0 SetLabel $success; # Insert completed successfully
6124 0 PopZmm; PopR;
6125 0 } [qw(bs first key compare offset index)],
6126 name => 'Nasm::X86::Tree::findAndSplit';
6127  
6128 0 $s->call($bs, first => $first, key => $key, compare => $compare,
6129 offset => $offset, index => $index);
6130 } # findAndSplit
6131  
6132 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.
6133 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
6134 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
6135 0 my $W = $t->width; # Width of keys and data
6136  
6137 my $s = Subroutine
6138 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
6139 0 my $success = Label; # Short circuit if ladders by jumping directly to the end after a successful push
6140  
6141 0 my $B = $$p{bs}; # First keys block
6142 0 my $F = $$p{first}; # First keys block
6143 0 my $K = $$p{key}; # Key to find
6144  
6145 0 $$p{found} ->copy(K(zero, 0)); # Key not found
6146 0 $$p{data} ->copy(K(zero, 0)); # Data not yet found
6147 0 $$p{subTree}->copy(K(zero, 0)); # Not yet a sub tree
6148  
6149 0 my $tree = V(tree)->copy($F); # Start at the first key block
6150 0 PushR k6, k7, r8, r9, r14, r15; PushZmm 28..31;
6151 0 my $zmmKeys = 31; my $zmmData = 30; my $zmmNode = 29; my $zmmTest = 28;
6152 0 my $lengthMask = k6; my $testMask = k7;
6153 0 my $transfer = r8; # Use this register to transfer data between zmm blocks and variables
6154 0 my $work = r9; # Work register
6155  
6156 0 $K->setReg(r15); # Load key into test register
6157 0 Vpbroadcastd "zmm$zmmTest", r15d;
6158  
6159 K(loop, 99)->for(sub # Step down through tree
6160 0 ▶ {my ($index, $start, $next, $end) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
6161  
6162 0 $t->getKeysDataNode($B, $tree, $zmmKeys, $zmmData, $zmmNode, # Get the keys block
6163 $transfer, $work);
6164  
6165 0 my $l = $t->getLengthInKeys($zmmKeys); # Length of the block
6166 If $l == 0,
6167 Then # Empty tree so we have not found the key
6168 0 ▶ {Jmp $success; # Return
Subroutine __ANON__: not called CC=1 SCAR=6.9
6169 0 };
6170  
6171 0 $l->setMaskFirst($lengthMask); # Set the length mask
6172 0 Vpcmpud "$testMask\{$lengthMask}", "zmm$zmmKeys", "zmm$zmmTest", 0; # Check for equal elements
6173 0 Ktestw $testMask, $testMask;
6174 IfNz # Result mask is non zero so we must have found the key
6175 Then
6176 0 ▶ {Kmovq r15, $testMask;
Subroutine __ANON__: not called CC=1 SCAR=6.9
6177 0 Tzcnt r14, r15; # Trailing zeros
6178 0 $$p{found}->copy(K(one, 1)); # Key found
6179 0 $$p{data} ->copy(getDFromZmm $zmmData, "r14*$W", $transfer); # Data associated with the key
6180 0 $t->isTree(r15, $zmmKeys); # Check whether the data so found is a sub tree
6181 0 $$p{subTree}->copyZFInverted; # Copy zero flag which opposes the notion that this element is a sub tree
6182 0 Jmp $success; # Return
6183 0 };
6184  
6185 0 my $n = getDFromZmm $zmmNode, 0, $transfer; # First child empty implies we are on a leaf
6186 If $n == 0,
6187 Then # Zero implies that this is a leaf node
6188 0 ▶ {Jmp $success; # Return
Subroutine __ANON__: not called CC=1 SCAR=6.9
6189 0 };
6190  
6191 0 Vpcmpud "$testMask\{$lengthMask}", "zmm$zmmTest", "zmm$zmmKeys", 1; # Check for greater elements
6192 0 Ktestw $testMask, $testMask;
6193  
6194 IfNz # Non zero implies that the key is less than some of the keys
6195 Then
6196 0 ▶ {Kmovq r15, $testMask;
Subroutine __ANON__: not called CC=1 SCAR=6.9
6197 0 Tzcnt r14, r15; # Trailing zeros
6198 0 $tree->copy(getDFromZmm $zmmNode, "r14*$W", $transfer); # Corresponding node
6199 0 Jmp $next; # Loop
6200 0 };
6201 0 $tree->copy(getDFromZmm $zmmNode, $l * $W, $transfer); # Greater than all keys
6202 0 });
6203 0 PrintErrStringNL "Stuck in find"; # We seem to be looping endlessly
6204 0 Exit(1);
6205  
6206 0 SetLabel $success; # Insert completed successfully
6207 0 PopZmm; PopR;
6208 0 } [qw(bs first key data found data subTree)], name => 'Nasm::X86::Tree::find';
6209  
6210 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
6211 key => $key, data => $t->data,
6212 found => $t->found, subTree => $t->subTree);
6213 } # find
6214  
6215 sub Nasm::X86::Tree::findAndReload($$) # Find a key in the specified tree and clone it is it is a sub tree.
6216 0 ▶ {my ($t, $key) = @_; # Tree descriptor, key as a dword
Subroutine findAndReload: not called CC=2 SCAR=17.9
6217 0 ▶ @_ == 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess() 0 0 0
6218 0 Comment "Nasm::X86::Tree::findAndReload";
6219 0 $t->find($key);
6220 If $t->found > 0,
6221 Then
6222 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
6223 0 };
6224 }
6225  
6226 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.
6227 0 ▶ {my ($tree, $string) = @_; # Tree descriptor, short string
Subroutine findShortString: not called CC=2 SCAR=17.9
6228 0 ▶ @_ == 2 or confess "2 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess("2 parameters") 0 0 0
6229 0 my $t = $tree->reload; # Reload the input tree so we can walk down the chain
6230 0 my $w = $tree->width; # Size of a key on the tree
6231 0 my $z = $string->z; # The zmm containing the short string
6232  
6233 my $s = Subroutine
6234 0 ▶ {my ($p) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
6235 0 my $L = $string->len; # Length of the short string
6236 0 $t->first->copy($$p{first}); # Reload the input tree so we can walk down the chain
6237 0 $$p{found}->copy(K(zero, 0)); # Not yet found
6238  
6239 0 PushR rax, r14, r15;
6240 0 ClearRegisters r15;
6241 0 PushR r15, $z; # Put the zmm holding the short string onto the stack with a register block full of zeroes above it
6242 0 Lea rax, "[rsp+1]"; # Address first data byte of short string
6243 0 $L->setReg(r15); # Length of key remaining to write into key chain
6244  
6245 AndBlock
6246 0 ▶ {my ($fail, $end, $start) = @_; # Fail block, end of fail block, start of test block
Subroutine __ANON__: not called CC=1 SCAR=6.9
6247 0 Cmp r15, $w; # Can we write a full key block ?
6248 IfGt
6249 Then # Full dwords from key still to load
6250 0 ▶ {Mov r14d, "[rax]"; # Load dword from string
Subroutine __ANON__: not called CC=1 SCAR=6.9
6251 0 $t->findAndReload(V(key, r14)); # Find dword of key
6252 If $t->found == 0, # Failed to find dword
6253 Then
6254 0 ▶ {Jmp $end;
Subroutine __ANON__: not called CC=1 SCAR=6.9
6255 0 };
6256 0 Add rax, $w; # Move up over found key
6257 0 Sub r15, $w; # Reduce amount of key still to find
6258 0 Jmp $start; # Restart
6259 0 };
6260 0 Mov r14d, "[rax]"; # Load possibly partial dword from string which might have some trailing zeroes in it from the register block above
6261 0 $t->find(V(key, r14)); # Find remaining key and data
6262 0 $$p{data} ->copy($t->data);
6263 0 $$p{found}->copy($t->found);
6264 0 };
6265 0 PopR; PopR;
6266 0 } [qw(bs first data found)], name => "Nasm::X86::Tree::findShortString_$z";
6267  
6268 0 $s->call($tree->address, first => $tree->first, $tree->data, $tree->found); # Find the data at the end of the short string key
6269  
6270 0 $t # Return the cloned tree descriptor as it shows the data and the find status
6271 } # findShortString
6272  
6273 sub Nasm::X86::Tree::size($) # Return a variable containing the number of keys in the specified tree.
6274 0 ▶ {my ($t) = @_; # Tree descriptor
Subroutine size: not called CC=2 SCAR=17.9
6275 0 ▶ @_ == 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess() 0 0 0
6276  
6277 my $s = Subroutine
6278 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
6279  
6280 0 PushR r8, r9;
6281 0 my $transfer = r8; # Use this register to transfer data between zmm blocks and variables
6282 0 my $work = r9; # Work register
6283  
6284 0 $t->getKeysData($$p{bs}, $$p{first}, 31, 30, $transfer, $work); # Get the first block so we can update the key count
6285 0 my $size = $t->getCountFromData(30, $transfer); # Get key count
6286 0 $$p{size}->copy($size); # Set result
6287 0 PopR;
6288 0 } [qw(bs first size)], name => "Nasm::X86::Tree::size";
6289  
6290 0 $s->call(bs => $t->address, first => $t->first, my $size = V(size));
6291  
6292 0 $size;
6293 } # size
6294  
6295 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.
6296 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
6297 0 ▶ @_ >= 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 or confess() 0 0 0
6298 0 my $W = RegisterSize zmm0; # The size of a block
6299  
6300 my $s = Subroutine
6301 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
6302 0 my $success = Label; # Short circuit if ladders by jumping directly to the end after a successful push
6303  
6304 0 my $B = $$p{bs}; # Arena
6305 0 my $F = $$p{first}; # First keys block
6306 0 my $K = $$p{key}; # Key to be inserted
6307 0 my $D = $$p{data}; # Data to be inserted
6308  
6309 0 PushMask 4..7; PushR r8, r9, r13, r14, r15; PushZmm 22..31;
6310 0 my $transfer = r8; # Use this register to transfer data between zmm blocks and variables
6311 0 my $work = r9; # Work register
6312 0 my $point = r13; # Insertion indicator
6313 0 $t->getKeysDataNode($B, $F, 31, 30, 29, $transfer, $work); # Get the first block
6314  
6315 0 my $l = $t->getLengthInKeys(31); # Length of the block
6316 If $l == 0, # Check for empty tree.
6317 Then # Empty tree
6318 0 ▶ {$K->putDIntoZmm (31, 0, $transfer); # Write key
Subroutine __ANON__: not called CC=3 SCAR=24.8
6319 0 $t->putLengthInKeys(31, K(one, 1)); # Set the length of the block
6320 0 ▶ if ($tnd) # Create and mark key as addressing a sub tree
Branch: 1 branch
BranchTrueFalseTotal
if ($tnd) 0 0 0
6321 0 ▶ {$D->copy($t->bs->CreateTree($B)->first) if $tnd == 1; # Create sub tree
Branch: 1 branch
BranchTrueFalseTotal
if $tnd == 1 0 0 0
6322 0 Mov r15, 1; # Indicate first position
6323 0 $t->setTree(r15, 31); # Mark this key as addressing a sub tree from the existing tree
6324 }
6325 0 $D->putDIntoZmm (30, 0, $transfer); # Write data
6326 0 $t->incCountInData (30, $transfer); # Update count
6327 0 $t->putKeysData($B, $F, 31, 30, $transfer, $work); # Write the data block back into the underlying arena
6328 0 Jmp $success; # Insert completed successfully
6329 0 };
6330  
6331 0 my $n = $t->getLoop(30, $transfer); # Get the offset of the node block
6332 If $n == 0,
6333 Then # Node is root with no children and space for more keys
6334 {If $l < $t->maxKeys,
6335 Then # Node is root with no children and space for more keys
6336 0 ▶ {$l->setMaskFirst(k7); # Set the compare bits
Subroutine __ANON__: not called CC=3 SCAR=24.8
6337 0 $K->setReg(r15); # Key to search for
6338 0 Vpbroadcastd zmm22, r15d; # Load key
6339 0 Vpcmpud "k6{k7}", zmm22, zmm31, 0; # Check for equal key
6340 0 Ktestd k6, k6; # Check whether a matching key was found - the operation clears the zero flag if the register is not zero
6341 IfNz # Found the key so we just update the data field
6342 Then
6343 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
6344 0 {Kmovq r15, k6; # Position of key just found
6345 0 $t->isTree(r15, 31); # Set the zero flag to indicate whether the existing data element is in fact a tree
6346 IfNz # If the data element is already a tree then get its value and return it in the data variable
6347 Then
6348 0 ▶ {Tzcnt r14, r15; # Trailing zeros
Subroutine __ANON__: not called CC=1 SCAR=6.9
6349 0 $D->copy(getDFromZmm 30, "r14*$$t{width}", $transfer); # Data associated with the key
6350 0 Jmp $success; # Return offset of sub tree
6351 },
6352 Else # The existing element is not a tree so we mark it as such using the single bit in r15/k6
6353 0 ▶ {$t->setTree(r15, 31);
Subroutine __ANON__: not called CC=1 SCAR=6.9
6354 0 };
6355 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
6356 }
6357 0 $D->setReg(r14); # Key to search for
6358 0 Vpbroadcastd "zmm30{k6}", r14d; # Load data
6359 0 $t->putKeysData($B, $F, 31, 30, $transfer, $work); # Write the data block back into the underlying arena
6360 0 Jmp $success; # Insert completed successfully
6361 0 };
6362  
6363 0 Vpcmpud "k6{k7}", zmm22, zmm31, 1; # Check for elements that are greater than an existing element
6364 0 Ktestw k6, k6;
6365 IfEq (sub # K6 zero implies the latest key goes at the end
6366 0 ▶ {Kshiftlw k6, k7, 1; # Reach next empty field
Subroutine __ANON__: not called CC=1 SCAR=6.9
6367 0 Kandnw k6, k7, k6; # Remove back fill to leave a single bit at the next empty field
6368 },
6369 sub
6370 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
6371 0 Kandnw k4, k5, k7;
6372 0 Kshiftlw k5, k5, 1;
6373 0 Korw k5, k4, k5; # Broadcast mask
6374 0 Kandnw k6, k5, k7; # Expand mask
6375 0 Vpexpandd "zmm31{k5}", zmm31; # Shift up keys
6376 0 Vpexpandd "zmm30{k5}", zmm30; # Shift up data
6377 0 });
6378  
6379 0 Vpbroadcastd "zmm31{k6}", r15d; # Load key
6380  
6381 0 ▶ if ($tnd) # Insert new sub tree
Branch: 1 branch
BranchTrueFalseTotal
if ($tnd) 0 0 0
6382 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
6383 }
6384 0 if (1) # Expand tree bits to match
6385 0 {Kmovq $point, k6; # Position of key just found
6386 0 $t->expandTreeBitsWithZeroOrOne($tnd, 31, $point); # Mark new entry as a sub tree
6387 }
6388  
6389 0 $D->setReg(r14); # Corresponding data
6390 0 Vpbroadcastd "zmm30{k6}", r14d; # Load data
6391 0 $t->putLengthInKeys( 31, $l + 1); # Set the length of the block
6392 0 $t->incCountInData ( 30, $transfer); # Update count
6393  
6394 If $l + 1 == $t->maxKeys,
6395 Then # Root is now full: allocate the node block for it and chain it in
6396 0 ▶ {$t->bs->allocZmmBlock($B, my $n = V(offset)); # Children
Subroutine __ANON__: not called CC=1 SCAR=6.9
6397 0 $t->putLoop($n, 30, $transfer); # Set the link from data to node
6398 0 $t->putLoop($F, 29, $transfer); # Set the link from node to key
6399 0 };
6400  
6401 0 $t->putKeysDataNode($B, $F, 31, 30, 29, $transfer, $work); # Write the data block back into the underlying arena
6402 0 $t->splitNode($B, $F, $K); # Split if the leaf has got too big
6403 0 Jmp $success; # Insert completed successfully
6404 0 ▶ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
6405 0 };
6406  
6407 0 my $compare = V(compare); # Comparison result
6408 0 my $offset = V(offset); # Offset of result
6409 0 my $index = V('index'); # Index of result
6410  
6411 0 $t->findAndSplit($B, $F, $K, $compare, $offset, $index); # Find block that should contain key
6412  
6413 0 $t->getKeysDataNode($B, $offset, 31, 30, 29, $transfer, $work);
6414 0 Mov $point, 0;
6415 0 $index->setBit($point); # Set point at the index
6416  
6417 If $compare == 0, # Duplicate key
6418 Then # Found an equal key so update the data
6419 0 ▶ {$D->putDIntoZmm(30, $index * $t->width, $transfer); # Update data at key
Subroutine __ANON__: not called CC=1 SCAR=6.9
6420 0 $t->putKeysDataNode($B, $offset, 31, 30, 29, $transfer, $work); # Rewrite data and keys
6421 0 $t->setOrClearTree($tnd, $point, 31); # Set or clear tree bit as necessary
6422 },
6423 Else # We have room for the insert because each block has been split to make it non full
6424 {If $compare > 0,
6425 Then # Position at which to insert new key if it is greater than the indexed key
6426 0 ▶ {++$index;
Subroutine __ANON__: not called CC=1 SCAR=6.9
6427 0 Shl $point, 1; # Move point up as well
6428 0 ▶ };
Subroutine __ANON__: not called CC=2 SCAR=17.9
6429  
6430 0 my $length = $t->getLengthInKeys(31); # Number of keys
6431 If $index < $length,
6432 Then # Need to expand as we cannot push
6433 0 ▶ {$length->setMaskFirst(k7); # Length as bits
Subroutine __ANON__: not called CC=1 SCAR=6.9
6434 0 Kshiftlw k6, k7, 1; # Length plus one as bits with a trailing zero
6435 0 Korw k6, k6, k7; # Length plus one as bits with no trailing zero
6436 0 $index->clearMaskBit(k6); # Zero at the index
6437 0 Vpexpandd "zmm31{k6}", zmm31; # Shift up keys
6438 0 Vpexpandd "zmm30{k6}", zmm30; # Shift up data
6439 0 };
6440  
6441 0 $t->expandTreeBitsWithZeroOrOne($tnd, 31, $point); # Mark inserted key as referring to a tree or not
6442  
6443 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
6444  
6445 0 ClearRegisters k7;
6446 0 $index->setMaskBit(k7); # Set bit at insertion point
6447 0 $K->setReg(r15); # Corresponding data
6448 0 Vpbroadcastd "zmm31{k7}", r15d; # Load key
6449 0 $D->setReg(r14); # Corresponding data
6450 0 Vpbroadcastd "zmm30{k7}", r14d; # Load data
6451 0 $t->putLengthInKeys(31, $length + 1); # Set the new length of the block
6452 0 $t->putKeysDataNode($B, $offset, 31, 30, 29, $transfer, $work); # Rewrite data and keys
6453 0 $t->splitNode($B, $offset, $K); # Split if the leaf has got too big
6454  
6455 0 $t->getKeysData($B, $F, 31, 30, $transfer, $work); # Get the first block so we can update the key count
6456 0 $t->incCountInData (30, $transfer); # Update key count
6457 0 $t->putKeysData($B, $F, 31, 30, $transfer, $work); # Write the first block with the updated key count
6458 0 };
6459  
6460 0 SetLabel $success; # Insert completed successfully
6461 0 PopZmm;
6462 0 PopR;
6463 0 PopMask;
6464 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
6465  
6466 0 ▶ $s->call($t->address, first => $t->first, key => $key,
Branch: 1 branch
BranchTrueFalseTotal
$tnd == 1 ? : 0 0 0
6467 data => $tnd == 1 ? $t->data : $data);
6468 } # insert
6469  
6470 sub Nasm::X86::Tree::insert($$$) # Insert a dword into into the specified tree at the specified key.
6471 0 ▶ {my ($t, $key, $data) = @_; # Tree descriptor, key as a dword, data as a dword
Subroutine insert: not called CC=2 SCAR=17.9
6472 0 ▶ @_ == 3 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess() 0 0 0
6473 0 $t->insertDataOrTree(0, $key, $data); # Insert data
6474 }
6475  
6476 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.
6477 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
6478 0 ▶ @_ == 2 or @_ == 3 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or @_ == 3 or confess() 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
6479 0 ▶ if (my $r = ref($subTree))
Branch: 1 branch
BranchTrueFalseTotal
if (my $r = ref $subTree) { } 0 0 0
6480 0 ▶ {if ($r =~ m(Tree))
Branch: 2 branches
BranchTrueFalseTotal
if ($r =~ /Tree/) { } 0 0 0
elsif ($r =~ /Variable/) { } 0 0 0
6481 0 {$t->insertDataOrTree(2, $key, $subTree->first); # Insert a sub tree from a tree descriptor
6482 }
6483 elsif ($r =~ m(Variable))
6484 0 {$t->insertDataOrTree(2, $key, $subTree); # Insert a sub tree from a variable containing an offset to the first node of the tree
6485 }
6486 else
6487 0 {confess "Reference to a variable or a tree required";
6488 }
6489 }
6490 else # Create a sub tree
6491 0 {$t->insertDataOrTree(1, $key); # Request a sub tree be created if one has not been supplied
6492 }
6493 }
6494  
6495 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.
6496 0 ▶ {my ($t, $key) = @_; # Tree descriptor, key as a dword
Subroutine insertTreeAndReload: not called CC=2 SCAR=17.9
6497 0 ▶ @_ == 2 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess() 0 0 0
6498 0 $t->insertTree($key);
6499 0 $t->first->copy($t->data); # Copy the data variable to the first variable without checking whether it is valid
6500 }
6501  
6502 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.
6503 0 ▶ {my ($tree, $string, $data) = @_; # Tree descriptor, short string, data as a dword
Subroutine insertShortString: not called CC=2 SCAR=17.9
6504 0 ▶ @_ == 3 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess() 0 0 0
6505 0 my $w = $tree->width; # Size of a key on the tree
6506 0 my $z = $string->z; # The zmm containing the short string
6507  
6508 my $s = Subroutine
6509 0 ▶ {my ($p) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
6510 0 my $L = $string->len; # Length of the short string
6511  
6512 0 PushR rax, r14, r15;
6513 0 ClearRegisters r15;
6514 0 PushR r15, $z; # Put the zmm holding the short string onto the stack with a register block full of zeroes above it
6515 0 Lea rax, "[rsp+1]"; # Address first data byte of short string
6516 0 $L->setReg(r15); # Length of key remaining to write into key chain
6517  
6518 0 my $t = $tree->reload(first=>$$p{first}); # Reload the input tree so we can walk down the chain from it.
6519  
6520 AndBlock
6521 0 ▶ {my ($fail, $end, $start) = @_; # Fail block, end of fail block, start of test block
Subroutine __ANON__: not called CC=1 SCAR=6.9
6522 0 Cmp r15, $w; # Can we write a full key block ?
6523 IfGt
6524 Then # Full dwords from key still to load
6525 0 ▶ {Mov r14d, "[rax]"; # Load dword from string
Subroutine __ANON__: not called CC=1 SCAR=6.9
6526 0 $t->insertTreeAndReload(V(key, r14)); # Create sub tree
6527 0 Add rax, $w; # Move up over inserted key
6528 0 Sub r15, $w; # Reduce amount of key still to write
6529 0 Jmp $start; # Restart
6530 0 };
6531 0 Mov r14d, "[rax]"; # Load possibly partial dword from string which might have some trailing zeroes in it from the register block above
6532 0 $t->insert(V(key, r14), $$p{data}); # Insert remaining key and data
6533 0 };
6534 0 PopR; PopR;
6535 0 } [qw(bs first data)],
6536 name => "Nasm::X86::Tree::insertinsertShortString_$z";
6537  
6538 0 $s->call($tree->address, first => $tree->first, data => $data); # Insert the data at the end of the short string key
6539 } # insertShortString
6540  
6541 sub Nasm::X86::Tree::getKeysData($$$$$;$$) #P Load the keys and data blocks for a node.
6542 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
6543 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
6544 0 $t->bs->getBlock($bs, $offset, $zmmKeys, $work1, $work2); # Get the keys block
6545 0 my $data = $t->getLoop($zmmKeys, $work1); # Get the offset of the corresponding data block
6546 0 $t->bs->getBlock($bs, $data, $zmmData, $work1, $work2); # Get the data block
6547 }
6548  
6549 sub Nasm::X86::Tree::putKeysData($$$$$;$$) #P Save the key and data blocks for a node.
6550 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
6551 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
6552 0 $t->bs->putBlock($bs, $offset, $zmmKeys, $work1, $work2); # Put the keys block
6553 0 my $data = $t->getLoop($zmmKeys, $work1); # Get the offset of the corresponding data block
6554 0 $t->bs->putBlock($bs, $data, $zmmData, $work1, $work2); # Put the data block
6555 }
6556  
6557 sub Nasm::X86::Tree::getKeysDataNode($$$$$$;$$) #P Load the keys, data and child nodes for a node.
6558 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
6559 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
6560 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
6561 confess "Variable required for offset";
6562 0 my $b = $t->bs; # Underlying arena
6563  
6564 0 $b->getBlock($bs, $offset, $zmmKeys, $work1, $work2); # Get the keys block
6565 0 my $data = $t->getLoop ($zmmKeys, $work1, $work2); # Get the offset of the corresponding data block
6566 0 $b->getBlock($bs, $data, $zmmData, $work1, $work2); # Get the data block
6567  
6568 0 my $node = $t->getLoop ($zmmData, $work1, $work2); # Get the offset of the corresponding node block
6569 If $node > 0,
6570 Then # Check for optional node block
6571 0 ▶ {$b->getBlock($bs, $node, $zmmNode, $work1, $work2); # Get the node block
Subroutine __ANON__: not called CC=1 SCAR=6.9
6572 },
6573 Else # No children
6574 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
6575 0 };
6576 }
6577  
6578 sub Nasm::X86::Tree::putKeysDataNode($$$$$$;$$) #P Save the keys, data and child nodes for a node.
6579 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
6580 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
6581 0 $t->putKeysData($bs, $offset, $zmmKeys, $zmmData, $work1, $work2); # Put keys and data
6582 0 my $node = $t->getLoop($zmmData, $work1); # Get the offset of the corresponding node block
6583 If $node > 0,
6584 Then # Check for optional node block
6585 0 ▶ {$t->bs->putBlock($bs, $node, $zmmNode, $work1, $work2); # Put the node block
Subroutine __ANON__: not called CC=1 SCAR=6.9
6586 0 };
6587 }
6588  
6589 sub Nasm::X86::Tree::getLengthInKeys($$) #P Get the length of the keys block in the numbered zmm and return it as a variable.
6590 0 ▶ {my ($t, $zmm) = @_; # Tree descriptor, zmm number
Subroutine getLengthInKeys: not called CC=2 SCAR=17.9
6591 0 ▶ @_ == 2 or confess "2 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess("2 parameters") 0 0 0
6592  
6593 0 getBFromZmm($zmm, $t->lengthOffset); # The length field as a variable
6594 }
6595  
6596 sub Nasm::X86::Tree::putLengthInKeys($$$) #P Get the length of the block in the numbered zmm from the specified variable.
6597 0 ▶ {my ($t, $zmm, $length) = @_; # Tree, zmm number, length variable
Subroutine putLengthInKeys: not called CC=3 SCAR=24.8
6598 0 ▶ @_ == 3 or confess "3 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess("3 parameters") 0 0 0
6599 0 ▶ ref($length) or confess dump($length);
Branch: 1 branch
BranchTrueFalseTotal
ref $length or confess(Nasm::X86::dump($length)) 0 0 0
6600 0 $length->putBIntoZmm($zmm, $t->lengthOffset) # Set the length field
6601 }
6602  
6603 sub Nasm::X86::Tree::getUpFromData11($$$) #P Get the up offset from the data block in the numbered zmm and return it as a variable.
6604 0 ▶ {my ($t, $zmm, $transfer) = @_; # Tree descriptor, zmm number, transfer register
Subroutine getUpFromData11: not called CC=2 SCAR=17.9
6605 0 ▶ @_ == 3 or confess "3 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess("3 parameters") 0 0 0
6606 0 getDFromZmm($zmm, $t->up, $transfer); # The length field as a variable
6607 }
6608  
6609 sub Nasm::X86::Tree::putUpIntoData11($$$;$) #P Put the offset of the parent keys block expressed as a variable into the numbered zmm.
6610 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
6611 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
6612 0 ▶ defined($offset) or confess;
Branch: 1 branch
BranchTrueFalseTotal
defined $offset or confess() 0 0 0
6613 0 $offset->putDIntoZmm($zmm, $t->up, $transfer); # Save the up offset into the data block
6614 }
6615  
6616 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.
6617 0 ▶ {my ($t, $zmm, $transfer) = @_; # Tree descriptor, zmm number, transfer register
Subroutine getUpFromData: not called CC=2 SCAR=17.9
6618 0 ▶ @_ == 3 or confess "3 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess("3 parameters") 0 0 0
6619 0 my $z = "zmm$zmm";
6620 0 my $w = RegisterSize $z; # Size of zmm register
6621 0 my $o = $t->up; # Offset into register in bytes
6622 0 Vmovdqu32 "[rsp-$w]", $z; # Write below the stack
6623 0 Mov $transfer."d", "[rsp+$o-$w]"; # Load double word register from offset
6624 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
6625 IfC
6626 Then # Low bit set so it is an offset
6627 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
6628 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.
6629 },
6630 Else # Low bit clear so it is a count in the root node and so the up offset is zero.
6631 0 ▶ {ClearRegisters $transfer;
Subroutine __ANON__: not called CC=1 SCAR=6.9
6632 0 };
6633 0 V(up, $transfer);
6634 }
6635  
6636 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.
6637 0 ▶ {my ($t, $zmm, $transfer) = @_; # Tree descriptor, zmm number, transfer register
Subroutine getUpFromDataNM: not called CC=2 SCAR=17.9
6638 0 ▶ @_ == 3 or confess "3 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess("3 parameters") 0 0 0
6639 0 my $z = "zmm$zmm";
6640 0 my $w = RegisterSize $z; # Size of zmm register
6641 0 my $o = $t->up; # Offset into register in bytes
6642 0 Vmovdqu32 "[rsp-$w]", $z; # Write below the stack
6643 0 Mov $transfer."d", "[rsp+$o-$w]"; # Load double word register from offset
6644 0 V(up, $transfer);
6645 }
6646  
6647 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.
6648 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
6649 0 ▶ @_ == 4 or confess "4 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 4 or confess("4 parameters") 0 0 0
6650  
6651 0 $offset->setReg($transfer);
6652 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)
6653 0 Or $transfer, 1; # Set highest lowest bit to show that it is an offset
6654 0 my $z = "zmm$zmm";
6655 0 my $w = RegisterSize $z; # Size of zmm register
6656 0 my $o = $t->up; # Offset into zmm register in bytes of count/up field
6657 0 Vmovdqu64 "[rsp-$w]", $z; # Write zmm below the stack
6658 0 Mov "[rsp+$o-$w]", $transfer."d"; # Save offset
6659 0 Vmovdqu64 $z, "[rsp-$w]"; # Reload zmm
6660 }
6661  
6662 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.
6663 0 ▶ {my ($t, $zmm, $transfer) = @_; # Tree descriptor, zmm number, transfer register
Subroutine getCountFromData: not called CC=2 SCAR=17.9
6664 0 ▶ @_ == 3 or confess "3 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess("3 parameters") 0 0 0
6665  
6666 0 my $z = "zmm$zmm";
6667 0 my $w = RegisterSize $z; # Size of zmm register
6668 0 my $o = $t->up; # Offset into register in bytes
6669 0 Vmovdqu32 "[rsp-$w]", $z; # Write below the stack
6670 0 Mov $transfer."d", "[rsp+$o-$w]"; # Load double word register from offset
6671 0 my $size = V(size, 0);
6672 0 Shr $transfer, 1; # Remove and test the lowest bit
6673 IfNc
6674 Then # Highest bit is zero so the field is a count
6675 0 ▶ {$size->getReg($transfer); # Load count
Subroutine __ANON__: not called CC=1 SCAR=6.9
6676 },
6677 Else # Complain because we are being asked for an invalid field
6678 0 ▶ {PrintErrTraceBack;
Subroutine __ANON__: not called CC=1 SCAR=6.9
6679 0 PrintErrStringNL "Cannot get count field from non root node data block";
6680 0 Exit(1);
6681 0 };
6682  
6683 0 $size; # Return variable containing size of tree
6684 }
6685  
6686 sub Nasm::X86::Tree::incCountInData($$$) #P Increment the count field in the up field of the data block associate with the root node.
6687 0 ▶ {my ($t, $zmm, $transfer) = @_; # Tree descriptor, zmm number, transfer register
Subroutine incCountInData: not called CC=2 SCAR=17.9
6688 0 ▶ @_ == 3 or confess "3 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess("3 parameters") 0 0 0
6689  
6690 0 my $z = "zmm$zmm";
6691 0 my $w = RegisterSize $z; # Size of zmm register
6692 0 my $o = $t->up; # Offset into zmm register in bytes of count/up field
6693 0 Vmovdqu64 "[rsp-$w]", $z; # Write zmm below the stack
6694 0 Mov $transfer."d", "[rsp+$o-$w]"; # Load current count
6695 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
6696 IfC
6697 Then # We are trying to manipulate an offset not a count
6698 0 ▶ {PrintErrTraceBack; # Complain because we are being asked for an invalid field
Subroutine __ANON__: not called CC=1 SCAR=6.9
6699 0 PrintErrStringNL "Not a root node";
6700 0 Exit(1);
6701 0 };
6702 0 Inc $transfer; # Increment
6703 0 Shl $transfer, 1; # Space for indicator bit cleared.
6704 0 Mov "[rsp+$o-$w]", $transfer."d"; # Save count
6705 0 Vmovdqu64 "zmm$zmm", "[rsp-$w]"; # Reload zmm
6706 }
6707  
6708 sub Nasm::X86::Tree::decCountInData($$$) #P Decrement the count field in the up field of the data block associate with the root node.
6709 0 ▶ {my ($t, $zmm, $transfer) = @_; # Tree descriptor, zmm number, transfer register
Subroutine decCountInData: not called CC=2 SCAR=17.9
6710 0 ▶ @_ == 3 or confess "3 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess("3 parameters") 0 0 0
6711  
6712 0 my $z = "zmm$zmm";
6713 0 my $w = RegisterSize $z; # Size of zmm register
6714 0 my $o = $t->up; # Offset into zmm register in bytes of count/up field
6715 0 Vmovdqu64 "[rsp-$w]", $z; # Write zmm below the stack
6716 0 Mov $transfer."d", "[rsp+$o-$w]"; # Load current count
6717 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
6718 IfC
6719 Then # We are trying to manipulate an offset not a count
6720 0 ▶ {PrintErrTraceBack; # Complain because we are being asked for an invalid field
Subroutine __ANON__: not called CC=1 SCAR=6.9
6721 0 PrintErrStringNL "Not a root node";
6722 0 Exit(1);
6723 0 };
6724 0 Cmp $transfer, 0; # Check that we are able to reduce the count
6725 IfEq
6726 Then # We are trying to manipulate an offset not a count
6727 0 ▶ {PrintErrTraceBack; # Complain because we are being asked for an invalid field
Subroutine __ANON__: not called CC=1 SCAR=6.9
6728 0 PrintErrStringNL "Cannot reduce node count below zero";
6729 0 Exit(1);
6730 0 };
6731 0 Dec $transfer; # Increment
6732 0 Shl $transfer, 1; # Space for indicator bit cleared.
6733 0 Mov "[rsp+$o-$w]", $transfer."d"; # Save count
6734 0 Vmovdqu64 "zmm$zmm", "[rsp-$w]"; # Reload zmm
6735 }
6736  
6737 sub Nasm::X86::Tree::getLoop($$;$) #P Return the value of the loop field as a variable.
6738 0 ▶ {my ($t, $zmm, $transfer) = @_; # Tree descriptor, numbered zmm, optional transfer register
Subroutine getLoop: not called CC=2 SCAR=17.9
6739 0 ▶ @_ >= 1 or confess "1 parameter";
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 1 or confess("1 parameter") 0 0 0
6740 0 getDFromZmm($zmm, $t->loop, $transfer); # Get loop field as a variable
6741 }
6742  
6743 sub Nasm::X86::Tree::putLoop($$$;$) #P Set the value of the loop field from a variable.
6744 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
6745 0 ▶ @_ >= 1 or confess "1 parameter";
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 1 or confess("1 parameter") 0 0 0
6746 0 $value->putDIntoZmm($zmm, $t->loop, $transfer); # Put loop field as a variable
6747 }
6748  
6749 sub Nasm::X86::Tree::leftOrRightMost($$$$$) # Return the offset of the left most or right most node.
6750 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
6751 0 ▶ @_ == 5 or confess "5 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 5 or confess("5 parameters") 0 0 0
6752  
6753 my $s = Subroutine
6754 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
6755 0 my $success = Label; # Short circuit if ladders by jumping directly to the end after a successful push
6756  
6757 0 my $B = $$p{bs}; # Arena address
6758 0 my $F = $$p{node}; # First block
6759 0 PushR rax, r8, r9; PushZmm 29..31;
6760  
6761 K(loopLimit, 9)->for(sub # Loop a reasonable number of times
6762 0 ▶ {my ($index, $start, $next, $end) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
6763 0 $t->getKeysDataNode($B, $F, 31, 30, 29, r8, r9); # Get the first keys block
6764 0 my $n = getDFromZmm 29, 0, r8; # Get the node block offset from the data block loop
6765 If $n == 0,
6766 Then # Reached the end so return the containing block
6767 0 ▶ {$$p{offset}->copy($F);
Subroutine __ANON__: not called CC=1 SCAR=6.9
6768 0 Jmp $success;
6769 0 };
6770 0 ▶ if ($dir == 0) # Left most
Branch: 1 branch
BranchTrueFalseTotal
if ($dir == 0) { } 0 0 0
6771 0 {my $l = getDFromZmm 29, 0, r8; # Get the left most node
6772 0 $F->copy($l); # Continue with the next level
6773 }
6774 else # Right most
6775 0 {my $l = $t->getLengthInKeys(31); # Length of the node
6776 0 my $r = getDFromZmm(31, $l, r8); # Get the right most child
6777 0 $F->copy($r); # Continue with the next level
6778 }
6779 0 });
6780 0 PrintErrStringNL "Stuck in LeftOrRightMost";
6781 0 Exit(1);
6782  
6783 0 SetLabel $success; # Insert completed successfully
6784 0 PushZmm; PopR;
6785 0 ▶ } [qw(bs node offset )],
Branch: 1 branch
BranchTrueFalseTotal
$dir == 0 ? : 0 0 0
6786 name => $dir==0 ? "Nasm::X86::Tree::leftMost" : "Nasm::X86::Tree::rightMost";
6787  
6788 0 $s->call($bs, node => $node, offset=>$offset);
6789 }
6790  
6791 sub Nasm::X86::Tree::leftMost($$$$) # Return the offset of the left most node from the specified node.
6792 0 ▶ {my ($t, $bs, $node, $offset) = @_; # Tree descriptor, arena address, start node, returned offset
Subroutine leftMost: not called CC=2 SCAR=17.9
6793 0 ▶ @_ == 4 or confess "4 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 4 or confess("4 parameters") 0 0 0
6794 0 $t->leftOrRightMost(0, $bs, $node, $offset) # Return the left most node
6795 }
6796  
6797 sub Nasm::X86::Tree::rightMost($$$$) # Return the offset of the left most node from the specified node.
6798 0 ▶ {my ($t, $bs, $node, $offset) = @_; # Tree descriptor, arena address, start node, returned offset
Subroutine rightMost: not called CC=2 SCAR=17.9
6799 0 ▶ @_ == 4 or confess "4 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 4 or confess("4 parameters") 0 0 0
6800 0 $t->leftOrRightMost(1, $bs, $node, $offset) # Return the right most node
6801 }
6802  
6803 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.
6804 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
6805 0 confess "Not needed";
6806 0 ▶ @_ == 3 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess() 0 0 0
6807 0 my $loop = $t->getLoop($data); # Get loop offset from data
6808 0 $t->getBlock($t->address, $loop, $node); # Node
6809 }
6810  
6811 sub Nasm::X86::Tree::address($) #P Address of the arena containing a tree.
6812 0 ▶ {my ($t) = @_; # Tree descriptor
Subroutine address: not called CC=2 SCAR=17.9
6813 0 ▶ @_ == 1 or confess "4 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess("4 parameters") 0 0 0
6814 0 $t->bs->bs;
6815 }
6816  
6817 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.
6818 0 ▶ {my ($t, $bs) = @_; # Tree descriptor, variables
Subroutine allocBlock: not called CC=2 SCAR=17.9
6819 0 ▶ @_ == 2 or confess "2 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess("2 parameters") 0 0 0
6820 0 $t->bs->allocBlock($bs); # Allocate a block and return its offset as a variable
6821 }
6822  
6823 sub Nasm::X86::Tree::depth($$$$) # Return the depth of a node within a tree.
6824 0 ▶ {my ($t, $bs, $node, $depth) = @_; # Tree descriptor, arena address, node, return depth
Subroutine depth: not called CC=2 SCAR=17.9
6825 0 ▶ @_ == 4 or confess "4 parameters required";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 4 or confess("4 parameters required") 0 0 0
6826  
6827 my $s = Subroutine
6828 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
6829 0 my $success = Label; # Short circuit if ladders by jumping directly to the end after a successful push
6830  
6831 0 my $B = $$p{bs}; # Arena address
6832 0 my $N = $$p{node}; # Starting node
6833  
6834 0 PushR r8, r9, r14, r15, zmm30, zmm31;
6835 0 my $tree = V(tree)->copy($N); # Start at the specified node
6836  
6837 K(loop, 9)->for(sub # Step up through tree
6838 0 ▶ {my ($index, $start, $next, $end) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
6839 0 $t->getKeysData($B, $tree, 31, 30, r8, r9); # Get the keys block
6840 0 my $P = $t->getUpFromData(30, r8); # Parent
6841 If $P == 0,
6842 Then # Empty tree so we have not found the key
6843 0 ▶ {$$p{depth}->copy($index+1); # Key not found
Subroutine __ANON__: not called CC=1 SCAR=6.9
6844 0 Jmp $success; # Return
6845 0 };
6846 0 $tree->copy($P); # Up to next level
6847 0 });
6848 0 PrintErrStringNL "Stuck in depth"; # We seem to be looping endlessly
6849 0 Exit(1);
6850  
6851 0 SetLabel $success; # Insert completed successfully
6852 0 PopR;
6853 0 } [qw(bs node depth)], name => 'Nasm::X86::Tree::allocBlock';
6854  
6855 0 $s->call($t->address, node => $node, depth => $depth);
6856 } # depth
6857  
6858 #D2 Sub trees # Construct trees of trees.
6859  
6860 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.
6861 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
6862 0 ▶ @_ == 3 or confess "3 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess("3 parameters") 0 0 0
6863 0 PushR rax, rcx;
6864 0 Mov rax, 1; # Place a single 1 at the position to test
6865 0 $position->setReg(rcx); # Position
6866 0 Shl rax, cl; # Move into position
6867 0 $t->isTree(rax, $zmm); # Test position
6868 0 PopR;
6869 } # isTree
6870  
6871 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.
6872 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
6873 0 ▶ @_ == 3 or confess "3 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess("3 parameters") 0 0 0
6874  
6875 0 my $z = "zmm$zmm"; # Full name of zmm register
6876 0 my $o = $$t{treeBits}; # Bytes from tree bits to end of zmm
6877 0 my $w = RegisterSize $z; # Size of zmm register
6878 0 Vmovdqu64 "[rsp-$w]", $z; # Write beyond stack
6879 0 Test $register, "[rsp-$w+$o]"; # Test the tree bits
6880 } # isTree
6881  
6882 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.
6883 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
6884 0 ▶ @_ == 4 or confess "4 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 4 or confess("4 parameters") 0 0 0
6885 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
6886 confess "General purpose register required, not $register";
6887  
6888 0 my $z = "zmm$zmm"; # Full name of zmm register
6889 0 my $o = $$t{treeBits}; # Tree bits to end of zmm
6890 0 PushR ($register, $z);
6891 0 ▶ if ($set) # Set the indexed bit
Branch: 1 branch
BranchTrueFalseTotal
if ($set) { } 0 0 0
6892 0 {And $register, $t->treeBitsMask; # Mask tree bits to prevent operations outside the permitted area
6893 0 Or "[rsp+$o]", $register; # Set tree bit in zmm
6894 }
6895 else # Clear the indexed bit
6896 0 {And $register, $t->treeBitsMask; # Mask tree bits to prevent operations outside the permitted area
6897 0 Not $register;
6898 0 And "[rsp+$o]", $register;
6899 }
6900 0 PopR;
6901 } # setOrClearTree
6902  
6903 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.
6904 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
6905 0 ▶ @_ == 3 or confess "3 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess("3 parameters") 0 0 0
6906 0 $t->setOrClearTree(1, $register, $zmm);
6907 } # setTree
6908  
6909 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.
6910 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
6911 0 ▶ @_ == 3 or confess "3 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess("3 parameters") 0 0 0
6912 0 $t->setOrClearTree(0, $register, $zmm);
6913 } # clearTree
6914  
6915 sub Nasm::X86::Tree::getTreeBits($$$) #P Load the tree bits from the numbered zmm into the specified register.
6916 0 ▶ {my ($t, $zmm, $register) = @_; # Tree descriptor, numbered zmm, target register
Subroutine getTreeBits: not called CC=2 SCAR=17.9
6917 0 ▶ @_ == 3 or confess "3 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess("3 parameters") 0 0 0
6918 0 loadFromZmm $register, w, $zmm, $t->treeBits;
6919 0 And $register, $t->treeBitsMask;
6920 }
6921  
6922 sub Nasm::X86::Tree::putTreeBits($$$) #P Put the tree bits in the specified register into the numbered zmm.
6923 0 ▶ {my ($t, $zmm, $register) = @_; # Tree descriptor, numbered zmm, target register
Subroutine putTreeBits: not called CC=2 SCAR=17.9
6924 0 ▶ @_ == 3 or confess "3 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess("3 parameters") 0 0 0
6925 0 putIntoZmm $register, w, $zmm, $t->treeBits;
6926 0 And $register, $t->treeBitsMask;
6927 }
6928  
6929 sub Nasm::X86::Tree::expandTreeBitsWithZeroOrOne($$$$) #P Insert a zero or one into the tree bits field in the numbered zmm at the specified point.
6930 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
6931 0 ▶ @_ == 4 or confess "4 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 4 or confess("4 parameters") 0 0 0
6932 0 PushR my @save = my ($bits) = ChooseRegisters(1, $point); # Tree bits register
6933 0 $t->getTreeBits($zmm, $bits); # Get tree bits
6934 0 ▶ if ($onz)
Branch: 1 branch
BranchTrueFalseTotal
if ($onz) { } 0 0 0
6935 0 {InsertOneIntoRegisterAtPoint($point, $bits); # Insert a one into the tree bits at the indicated location
6936 }
6937 else
6938 0 {InsertZeroIntoRegisterAtPoint($point, $bits); # Insert a zero into the tree bits at the indicated location
6939 }
6940 0 $t->putTreeBits($zmm, $bits); # Put tree bits
6941 0 PopR;
6942 }
6943  
6944 sub Nasm::X86::Tree::expandTreeBitsWithZero($$$) #P Insert a zero into the tree bits field in the numbered zmm at the specified point.
6945 0 ▶ {my ($t, $zmm, $point) = @_; # Tree descriptor, numbered zmm, register indicating point
Subroutine expandTreeBitsWithZero: not called CC=2 SCAR=17.9
6946 0 ▶ @_ == 3 or confess "3 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess("3 parameters") 0 0 0
6947 0 $t->expandTreeBitsWithZeroOrOne(0, $zmm, $point); # Insert a zero into the tree bits field in the numbered zmm at the specified point
6948 }
6949  
6950 sub Nasm::X86::Tree::expandTreeBitsWithOne($$$) #P Insert a one into the tree bits field in the numbered zmm at the specified point.
6951 0 ▶ {my ($t, $zmm, $point) = @_; # Tree descriptor, numbered zmm, register indicating point
Subroutine expandTreeBitsWithOne: not called CC=2 SCAR=17.9
6952 0 ▶ @_ == 3 or confess "3 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess("3 parameters") 0 0 0
6953 0 $t->expandTreeBitsWithZeroOrOne(1, $zmm, $point); # Insert a one into the tree bits field in the numbered zmm at the specified point
6954 }
6955  
6956 #D2 Print # Print a tree
6957  
6958 sub Nasm::X86::Tree::print($) # Print a tree.
6959 0 ▶ {my ($t) = @_; # Tree
Subroutine print: not called CC=2 SCAR=17.9
6960 0 ▶ @_ == 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess() 0 0 0
6961  
6962 my $s = Subroutine # Print a tree
6963 0 ▶ {my ($p, $s) = @_; # Parameters, sub definition
Subroutine __ANON__: not called CC=1 SCAR=6.9
6964  
6965 0 PrintOutString "Tree at: "; $$p{first}->outNL(' ');
6966  
6967 $t->by(sub # Iterate through the tree
6968 0 ▶ {my ($iter, $end) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
6969 0 $iter->tree->depth($$p{bs}, $iter->node, my $D = V(depth));
6970 0 $iter->key ->out('key: ');
6971 0 $iter->data->out(' data: ');
6972 0 $D ->outNL (' depth: ');
6973 0 $t->find($iter->key); # Slow way to find out if this is a subtree
6974 If $t->subTree > 0,
6975 Then
6976 0 ▶ {$s->call($$p{bs}, first => $t->data);
Subroutine __ANON__: not called CC=1 SCAR=6.9
6977 0 };
6978 0 }, $$p{bs}, $$p{first}+0);
6979 0 } [qw(bs first)], name => "Nasm::X86::Tree::print";
6980  
6981 0 $s->call($t->address, $t->first);
6982 }
6983  
6984 sub Nasm::X86::Tree::dump($;$$) # Dump a tree and all its sub trees.
6985 0 ▶ {my ($t, $first, $bs) = @_; # Tree, optional offset to first node, optional arena address
Subroutine dump: not called CC=5 SCAR=34.0
6986 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
6987  
6988 0 PushR my ($depthR) = (r12);
6989  
6990 my $b = Subroutine # Print the spacing blanks to offset sub trees
6991 {V(loop, $depthR)->for(sub
6992 0 ▶ {PrintOutString " ";
Subroutine __ANON__: not called CC=1 SCAR=6.9
6993 0 ▶ });
Subroutine __ANON__: not called CC=1 SCAR=6.9
6994 0 } [], name => "Nasm::X86::Tree::dump::spaces";
6995  
6996 my $s = Subroutine # Print a tree
6997 0 ▶ {my ($p, $s) = @_; # Parameters, sub definition
Subroutine __ANON__: not called CC=2 SCAR=17.9
6998  
6999 0 my $B = $$p{bs};
7000 0 my $F = $$p{first};
7001  
7002 0 PushZmm 29..31; PushR r8, r9, r10;
7003 0 my ($treeBitsR, $treeBitsIndexR, $transfer) = (r8, r9, r10);
7004  
7005 0 $t->getKeysDataNode($B, $F, 31, 30, 29, $treeBitsR, $treeBitsIndexR); # Load node
7006 0 $t->getTreeBits(31, $treeBitsR); # Tree bits for this node
7007 0 my $l = $t->getLengthInKeys(31); # Number of nodes
7008  
7009 0 $b->call;
7010 0 PrintOutString "Tree at: "; $$p{first}->out(' '); $l->outNL(' length: '); # Position and length
7011  
7012 0 Inc $depthR; # Indent sub tree
7013  
7014 0 for my $i(0..2) # Tree node description
7015 0 {my ($z) = zmm 29+$i; # Zmm returns an array
7016 0 $b->call; PrintOneRegisterInHex $stdout, $z; PrintOutNL;
7017 }
7018  
7019 0 Mov $treeBitsIndexR, 1; # Check each tree bit position
7020 $l->for(sub # Print keys and data
7021 0 ▶ {my ($index, $start, $next, $end) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
7022 0 my $i = $index * $t->width; # Key/Data offset
7023 0 my $k = getDFromZmm(31, $i, $transfer); # Key
7024 0 my $d = getDFromZmm(30, $i, $transfer); # Data
7025 0 $b->call;
7026 0 $index->out(' index: ');
7027 0 $k->out(' key: ');
7028 0 $d->out(' data: ');
7029 0 Test $treeBitsR, $treeBitsIndexR; # Check for a tree bit
7030 IfNz
7031 Then # This key indexes a sub tree
7032 0 ▶ {PrintOutStringNL(" subTree");
Subroutine __ANON__: not called CC=1 SCAR=6.9
7033 },
7034 Else
7035 0 ▶ {PrintOutNL;
Subroutine __ANON__: not called CC=1 SCAR=6.9
7036 0 };
7037 0 Shl $treeBitsIndexR, 1; # Next tree bit position
7038 0 });
7039  
7040 0 Cmp $treeBitsR, 0; # Any tree bit sets?
7041 IfNe
7042 Then # Tree bits present
7043 0 ▶ {Mov $treeBitsIndexR, 1; # Check each tree bit position
Subroutine __ANON__: not called CC=1 SCAR=6.9
7044 K(loop, $t->maxKeys)->for(sub
7045 0 ▶ {my ($index, $start, $next, $end) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
7046 0 Test $treeBitsR, $treeBitsIndexR; # Check for a tree bit
7047 IfNz
7048 Then # This key indexes a sub tree
7049 0 ▶ {my $i = $index * $t->width; # Key/data offset
Subroutine __ANON__: not called CC=1 SCAR=6.9
7050 0 my $d = getDFromZmm(30, $i, $transfer); # Data
7051 0 $s->call($B, first => $d); # Print sub tree referenced by data field
7052 0 };
7053 0 Shl $treeBitsIndexR, 1; # Next tree bit position
7054 0 });
7055 0 };
7056  
7057 ($l+1)->for(sub # Print sub nodes
7058 0 ▶ {my ($index, $start, $next, $end) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
7059 0 my $i = $index * $t->width; # Key/Data offset
7060 0 my $d = getDFromZmm(29, $i, $transfer); # Data
7061 If $d > 0, # Print any sub nodes
7062 Then
7063 0 ▶ {$s->call($B, first => $d);
Subroutine __ANON__: not called CC=1 SCAR=6.9
7064 0 };
7065 0 });
7066  
7067 0 Dec $depthR; # Reset indent
7068  
7069 0 $b->call; PrintOutStringNL "end"; # Separate sub tree dumps
7070 0 PopR; PopZmm;
7071 0 } [qw(bs first)], name => "Nasm::X86::Tree::dump";
7072  
7073 0 PushR $depthR;
7074 0 ClearRegisters $depthR; # Depth starts at zero
7075  
7076 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
7077  
7078 0 PopR;
7079 }
7080  
7081 #D2 Iteration # Iterate through a tree non recursively
7082  
7083 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.
7084 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
7085 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
7086 0 Comment "Nasm::X86::Tree::iterator";
7087  
7088 0 my $i = genHash(__PACKAGE__.'::Tree::Iterator', # Iterator
7089 tree => $t, # Tree we are iterating over
7090 bs => V(bs), # Arena containing tree
7091 node => V(node), # Current node within tree
7092 pos => V('pos'), # Current position within node
7093 key => V(key), # Key at this position
7094 data => V(data), # Data at this position
7095 count => V(count), # Counter - number of node
7096 more => V(more), # Iteration not yet finished
7097 );
7098  
7099 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
7100 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
7101 0 $i->pos ->copy(K('pos', -1)); # Initialize iterator
7102 0 $i->count->copy(K(count, 0));
7103 0 $i->more ->copy(K(more, 1));
7104  
7105 0 $i->next; # First element if any
7106 }
7107  
7108 sub Nasm::X86::Tree::Iterator::next($) # Next element in the tree.
7109 0 ▶ {my ($iter) = @_; # Iterator
Subroutine next: not called CC=2 SCAR=17.9
7110 0 ▶ @_ == 1 or confess;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess() 0 0 0
7111  
7112 my $s = Subroutine
7113 0 ▶ {my ($p) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
7114 0 my $success = Label; # Short circuit if ladders by jumping directly to the end after a successful push
7115  
7116 0 my $B = $$p{bs}; # Arena address
7117 0 my $C = $$p{node}; # Current node required
7118 0 $$p{count} = $$p{count} + 1; # Count the calls to the iterator
7119  
7120 my $new = sub # Load iterator with latest position
7121 0 ▶ {my ($node, $pos) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
7122 0 PushR r8, r9; PushZmm 29..31;
7123 0 $$p{node}->copy($node); # Set current node
7124 0 $$p{pos} ->copy($pos); # Set current position in node
7125 0 $iter->tree->getKeysData($B, $node, 31, 30, r8, r9); # Load keys and data
7126  
7127 0 my $offset = $pos * $iter->tree->width; # Load key and data
7128 0 $$p{key} ->copy(getDFromZmm 31, $offset, r8);
7129 0 $$p{data}->copy(getDFromZmm 30, $offset, r8);
7130 0 PopZmm; PopR;
7131 0 };
7132  
7133 my $done = sub # The tree has been completely traversed
7134 0 ▶ {PushR rax;
Subroutine __ANON__: not called CC=1 SCAR=6.9
7135 0 Mov rax, 0;
7136 0 $$p{more}->getReg(rax);
7137 0 PopR rax;
7138 0 };
7139  
7140 If $$p{pos} == -1,
7141 Then # Initial descent
7142 0 ▶ {my $t = $iter->tree;
Subroutine __ANON__: not called CC=1 SCAR=6.9
7143 0 my $end = Label;
7144  
7145 0 PushR r8, r9; PushZmm 29..31;
7146 0 $t->getKeysDataNode($B, $C, 31, 30, 29, r8, r9); # Load keys and data
7147  
7148 0 my $l = $t->getLengthInKeys(31); # Length of the block
7149 If $l == 0, # Check for empty tree.
7150 Then # Empty tree
7151 0 ▶ {&$done;
Subroutine __ANON__: not called CC=1 SCAR=6.9
7152 0 Jmp $end;
7153 0 };
7154  
7155 0 my $nodes = $t->getLoop(30, r8); # Nodes
7156  
7157 If $nodes > 0,
7158 Then # Go left if there are child nodes
7159 0 ▶ {$t->leftMost($B, $C, my $l = V(offset));
Subroutine __ANON__: not called CC=1 SCAR=6.9
7160 0 &$new($l, K(zero, 0));
7161 },
7162 Else
7163 0 ▶ {my $l = $t->getLengthInKeys(31); # Number of keys
Subroutine __ANON__: not called CC=1 SCAR=6.9
7164 If $l > 0,
7165 Then # Start with the current node as it is a leaf
7166 0 ▶ {&$new($C, K(zero, 0));
Subroutine __ANON__: not called CC=1 SCAR=6.9
7167 },
7168 Else
7169 0 ▶ {&$done;
Subroutine __ANON__: not called CC=1 SCAR=6.9
7170 0 };
7171 0 };
7172  
7173 0 SetLabel $end;
7174 0 PopZmm; PopR;
7175 0 Jmp $success; # Return with iterator loaded
7176 0 };
7177  
7178 my $up = sub # Iterate up to next node that has not been visited
7179 0 ▶ {my $top = Label; # Reached the top of the tree
Subroutine __ANON__: not called CC=1 SCAR=6.9
7180 0 my $n = V(first)->copy($C);
7181 0 my $zmmNK = 31; my $zmmPK = 28; my $zmmTest = 25;
7182 0 my $zmmND = 30; my $zmmPD = 27;
7183 0 my $zmmNN = 29; my $zmmPN = 26;
7184 0 PushR k7, r8, r9, r14, r15; PushZmm 25..31;
7185 0 my $t = $iter->tree;
7186  
7187 ForEver # Up through the tree
7188 0 ▶ {my ($start, $end) = @_; # Parameters
Subroutine __ANON__: not called CC=1 SCAR=6.9
7189 0 $t->getKeysData($B, $n, $zmmNK, $zmmND, r8, r9); # Load keys and data for current node
7190 0 my $p = $t->getUpFromData($zmmND, r8);
7191 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
7192 0 $t->getKeysDataNode($B, $p, $zmmPK, $zmmPD, $zmmPN, r8, r9); # Load keys, data and children nodes for parent which must have children
7193 0 $n->setReg(r15); # Offset of child
7194 0 Vpbroadcastd "zmm".$zmmTest, r15d; # Current node broadcasted
7195 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
7196 0 Kmovw r14d, k7; # Bit mask ready for count
7197 0 Tzcnt r14, r14; # Number of leading zeros gives us the position of the child in the parent
7198 0 my $i = V(indexInParent, r14); # Index in parent
7199 0 my $l = $t->getLengthInKeys($zmmPK); # Length of parent
7200  
7201 If $i < $l,
7202 Then # Continue with this node if all the keys have yet to be finished
7203 0 ▶ {&$new($p, $i);
Subroutine __ANON__: not called CC=1 SCAR=6.9
7204 0 Jmp $top;
7205 0 };
7206 0 $n->copy($p); # Continue with parent
7207 0 };
7208 0 &$done; # No nodes not visited
7209 0 SetLabel $top;
7210 0 PopZmm;
7211 0 PopR;
7212 0 };
7213  
7214 0 $$p{pos}->copy(my $i = $$p{pos} + 1); # Next position in block being scanned
7215 0 PushR r8, r9; PushZmm 29..31;
7216 0 my $t = $iter->tree;
7217 0 $t->getKeysDataNode($B, $C, 31, 30, 29, r8, r9); # Load keys and data
7218 0 my $l = $t->getLengthInKeys(31); # Length of keys
7219 0 my $n = getDFromZmm 29, 0, r8; # First node will ne zero if on a leaf
7220 If $n == 0,
7221 Then # Leaf
7222 {If $i < $l,
7223 Then
7224 0 ▶ {&$new($C, $i);
Subroutine __ANON__: not called CC=1 SCAR=6.9
7225 },
7226 Else
7227 0 ▶ {&$up;
Subroutine __ANON__: not called CC=1 SCAR=6.9
7228 0 ▶ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
7229 },
7230 Then # Node
7231 0 ▶ {my $offsetAtI = getDFromZmm 29, $i * $iter->tree->width, r8;
Subroutine __ANON__: not called CC=1 SCAR=6.9
7232 0 $iter->tree->leftMost($B, $offsetAtI, my $l = V(offset));
7233 0 &$new($l, K(zero, 0));
7234 0 };
7235  
7236 0 PopZmm; PopR;
7237 0 SetLabel $success;
7238 0 } [qw(bs node pos key data count more)],
7239 name => 'Nasm::X86::Tree::Iterator::next ';
7240  
7241 0 $s->call($iter->bs,
7242 $iter->node, $iter->pos, $iter->key, # Call with iterator variables
7243 $iter->data, $iter->count, $iter->more);
7244 0 $iter # Return the iterator
7245 }
7246  
7247 sub Nasm::X86::Tree::by($&;$$) # Call the specified block with each (key, data) from the specified tree in order.
7248 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
7249 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
7250  
7251 0 my $iter = $t->iterator($bs, $first); # Create an iterator
7252 0 my $start = SetLabel Label; my $end = Label; # Start and end of loop
7253 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
7254 0 &$block($iter, $end); # Perform the block parameterized by the iterator and the end label
7255 0 $iter->next; # Next element
7256 0 Jmp $start; # Process next element
7257 0 SetLabel $end; # End of the loop
7258 }
7259  
7260 #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.
7261  
7262 sub Nasm::X86::Arena::DescribeQuarks($) # Return a descriptor for a tree in the specified arena.
7263 0 ▶ {my ($arena) = @_; # Arena descriptor
Subroutine DescribeQuarks: not called CC=1 SCAR=6.9
7264  
7265 0 genHash(__PACKAGE__."::Quarks", # Tree.
7266 arena => $arena, # The arena containing the quarks
7267 stringsToNumbers => undef, # A tree mapping strings to numbers
7268 numbersToStrings => undef, # Array mapping numbers to strings
7269 );
7270 }
7271  
7272 sub Nasm::X86::Arena::CreateQuarks($) # Create quarks in a specified arena.
7273 0 ▶ {my ($arena) = @_; # Arena description optional arena address
Subroutine CreateQuarks: not called CC=2 SCAR=17.9
7274 0 ▶ @_ == 1 or confess "1 parameter";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or confess("1 parameter") 0 0 0
7275  
7276 0 my $q = $arena->DescribeQuarks; # Return a descriptor for a tree at the specified offset in the specified arena
7277 0 $q->stringsToNumbers = $arena->CreateTree;
7278 0 $q->numbersToStrings = $arena->CreateArray;
7279  
7280 0 $q # Description of array
7281 }
7282  
7283 sub Nasm::X86::Quarks::reload($%) # Reload the description of a set of quarks.
7284 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
7285 0 ▶ @_ >= 1 or confess "One or more parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 1 or confess("One or more parameters") 0 0 0
7286  
7287 0 $q->stringsToNumbers->reload(arena=>$options{arena}, first=>$options{tree});
7288 0 $q->numbersToStrings->reload(arena=>$options{arena}, first=>$options{array});
7289  
7290 0 $q # Return upgraded quarks descriptor
7291 }
7292  
7293 sub Nasm::X86::Quarks::quarkFromShortString($$) # Create a quark from a short string.
7294 0 ▶ {my ($q, $string) = @_; # Quarks, short string
Subroutine quarkFromShortString: not called CC=2 SCAR=17.9
7295 0 ▶ @_ == 2 or confess "2 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess("2 parameters") 0 0 0
7296  
7297 0 my $l = $string->len;
7298 0 my $Q = V(quark); # The variable that will hold the quark number
7299  
7300 AndBlock
7301 0 ▶ {my ($fail, $end, $start) = @_; # Fail block, end of fail block, start of test block
Subroutine __ANON__: not called CC=1 SCAR=6.9
7302  
7303 0 my $t = $q->stringsToNumbers->reload; # Reload strings to numbers
7304 0 $t->findAndReload($l); # Separate by length
7305 0 ▶ If $t->found == 0, Then {Jmp $fail}; # Length not found
Subroutine __ANON__: not called CC=1 SCAR=6.9
7306 0 $t->findShortString($string); # Find the specified short string
7307 0 ▶ If $t->found == 0, Then {Jmp $fail}; # Length not found
Subroutine __ANON__: not called CC=1 SCAR=6.9
7308 0 $Q->copy($t->data); # Load found quark number
7309 }
7310 Fail
7311 0 ▶ {my $N = $q->numbersToStrings->size; # Get the number of quarks
Subroutine __ANON__: not called CC=1 SCAR=6.9
7312 0 my $S = $q->arena->CreateString;
7313 0 $S->appendShortString($string);
7314 0 my $T = $q->stringsToNumbers->reload; # Reload strings to numbers tree descriptor
7315 0 $T->insertTreeAndReload($l); # Classify strings by length
7316 0 $T->insertShortString($string, $N); # Insert the string with the quark number as data
7317 0 $q->numbersToStrings->push(element => $S->first); # Append the quark number with a reference to the string
7318 0 $Q->copy($N);
7319 0 };
7320  
7321 0 $Q # Quark number for short string in a variable
7322 }
7323  
7324 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.
7325 0 ▶ {my ($q, $string) = @_; # Quarks, short string
Subroutine locateQuarkFromShortString: not called CC=2 SCAR=17.9
7326 0 ▶ @_ == 2 or confess "2 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess("2 parameters") 0 0 0
7327  
7328 0 my $l = $string->len;
7329 0 my $Q = V(quark); # The variable that will hold the quark number
7330  
7331 AndBlock
7332 0 ▶ {my ($fail, $end, $start) = @_; # Fail block, end of fail block, start of test block
Subroutine __ANON__: not called CC=1 SCAR=6.9
7333  
7334 0 my $t = $q->stringsToNumbers->reload; # Reload strings to numbers
7335 0 $t->findAndReload($l); # Separate by length
7336 0 ▶ If $t->found == 0, Then {Jmp $fail}; # Length not found
Subroutine __ANON__: not called CC=1 SCAR=6.9
7337 0 $t->findShortString($string); # Find the specified short string
7338 0 ▶ If $t->found == 0, Then {Jmp $fail}; # Length not found
Subroutine __ANON__: not called CC=1 SCAR=6.9
7339 0 $Q->copy($t->data); # Load found quark number
7340 }
7341 Fail
7342 0 ▶ {$Q->copy(-1);
Subroutine __ANON__: not called CC=1 SCAR=6.9
7343 0 };
7344  
7345 0 $Q # Quark number for short string in a variable
7346 }
7347  
7348 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.
7349 0 ▶ {my ($q, $number, $string) = @_; # Quarks, variable quark number, short string to load
Subroutine shortStringFromQuark: not called CC=2 SCAR=17.9
7350 0 ▶ @_ == 3 or confess "3 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess("3 parameters") 0 0 0
7351  
7352 0 my $f = V(found); # Whether the quark was found
7353  
7354 AndBlock
7355 0 ▶ {my ($fail, $end, $start) = @_; # Fail block, end of fail block, start of test block
Subroutine __ANON__: not called CC=1 SCAR=6.9
7356 0 my $N = $q->numbersToStrings->size; # Get the number of quarks
7357 0 ▶ If $number >= $N, Then {Jmp $fail}; # Quark number too big to be valid
Subroutine __ANON__: not called CC=1 SCAR=6.9
7358 0 $q->numbersToStrings->get(index => $number, my $e = V(element)); # Get long string indexed by quark
7359  
7360 0 my $S = $q->numbersToStrings->bs->DescribeString(first=>$e); # Long string descriptor
7361 0 $S->saveToShortString($string); # Load long string into short string
7362 0 $f->copy(K(one, 1)); # Show short string is valid
7363 }
7364 Fail # Quark too big
7365 0 ▶ {$f->copy(K(zero, 0)); # Show failure code
Subroutine __ANON__: not called CC=1 SCAR=6.9
7366 0 };
7367  
7368 0 $f
7369 }
7370  
7371 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.
7372 0 ▶ {my ($Q, $number, $q) = @_; # First set of quarks, variable quark number in first set, second set of quarks
Subroutine quarkToQuark: not called CC=2 SCAR=17.9
7373 0 ▶ @_ == 3 or confess "3 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or confess("3 parameters") 0 0 0
7374  
7375 0 my $N = V(found); # Whether the quark was found
7376  
7377 0 PushR zmm31;
7378  
7379 0 my $s = CreateShortString 0;
7380 If $Q->shortStringFromQuark($number, $s) == 0, # Quark not found in the first set
7381 Then
7382 0 ▶ {$N->copy(-1); # Not found in first set
Subroutine __ANON__: not called CC=1 SCAR=6.9
7383 },
7384 0 ▶ Ef {$q->locateQuarkFromShortString($s) >= 0} # Found the matching quark in the second set
Subroutine __ANON__: not called CC=1 SCAR=6.9
7385 Then
7386 0 ▶ {$N->copy($q->locateQuarkFromShortString($s)); # Load string from quark in second set
Subroutine __ANON__: not called CC=1 SCAR=6.9
7387 },
7388 Else
7389 0 ▶ {$N->copy(-2); # Not found in second set
Subroutine __ANON__: not called CC=1 SCAR=6.9
7390 0 };
7391  
7392 0 PopR;
7393  
7394 0 $N # Return the variable containing the matching quark or -1 if no such quark
7395 }
7396  
7397 sub Nasm::X86::Quarks::quarkFromSub($$) # Create a quark from a subroutine definition.
7398 0 ▶ {my ($q, $sub) = @_; # Quarks, subroutine definition
Subroutine quarkFromSub: not called CC=2 SCAR=17.9
7399 0 ▶ @_ == 2 or confess "2 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess("2 parameters") 0 0 0
7400  
7401 0 PushR zmm0;
7402 0 my $string = CreateShortString(0); # Short string to hold the subroutine name
7403 0 my $name = K('address', Rs($sub->name));
7404 0 $string->load($name, K(size, length($sub->name))); # Load the short string with the subroutine name
7405  
7406 0 my $N = $q->quarkFromShortString($string); # Create quark
7407 0 $q->numbersToStrings->put(index => $N, element => $sub->V); # Reuse the array component to point to the sub
7408  
7409 0 PopR;
7410 0 $N # Quark number gives rapid access to the sub
7411 }
7412  
7413 sub Nasm::X86::Quarks::subFromQuark($$) # Create a quark from a subroutine definition.
7414 0 ▶ {my ($q, $number) = @_; # Quarks, variable subroutine number
Subroutine subFromQuark: not called CC=2 SCAR=17.9
7415 0 ▶ @_ == 2 or confess "2 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess("2 parameters") 0 0 0
7416  
7417 0 my $s = V('sub'); # Whether the quark was found
7418  
7419 AndBlock
7420 0 ▶ {my ($fail, $end, $start) = @_; # Fail block, end of fail block, start of test block
Subroutine __ANON__: not called CC=1 SCAR=6.9
7421 0 my $N = $q->numbersToStrings->size; # Get the number of quarks
7422 0 ▶ If $number >= $N, Then {Jmp $fail}; # Quark number too big to be valid
Subroutine __ANON__: not called CC=1 SCAR=6.9
7423 0 $q->numbersToStrings->get(index => $number, my $e = V(element)); # Get subroutine indexed by quark
7424 0 $s->copy($e); # Subroutine offset
7425 }
7426 Fail # Quark too big
7427 0 ▶ {$s->copy(K(minusOne, -1)); # Show failure
Subroutine __ANON__: not called CC=1 SCAR=6.9
7428 0 };
7429  
7430 0 $s # Return subroutine offset or -1
7431 }
7432  
7433 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.
7434 0 ▶ {my ($q, $number) = @_; # Quarks, variable subroutine number
Subroutine call: not called CC=2 SCAR=17.9
7435 0 ▶ @_ == 2 or confess "2 parameters";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or confess("2 parameters") 0 0 0
7436  
7437 0 my $s = V(found); # Whether the quark was found
7438  
7439 AndBlock
7440 0 ▶ {my ($fail, $end, $start) = @_; # Fail block, end of fail block, start of test block
Subroutine __ANON__: not called CC=1 SCAR=6.9
7441 0 my $N = $q->numbersToStrings->size; # Get the number of quarks
7442 0 ▶ If $number >= $N, Then {Jmp $fail}; # Quark number too big to be valid
Subroutine __ANON__: not called CC=1 SCAR=6.9
7443 0 $q->numbersToStrings->get(index => $number, my $e = V(element)); # Get subroutine indexed by quark
7444  
7445 0 PushR r15;
7446 0 $e->setReg(r15); # Offset to subroutine
7447 0 Call r15; # Call sub routine
7448 0 PopR r15;
7449 0 $s->copy(1); # Show subroutine was found and called
7450 }
7451 Fail # Quark too big
7452 0 ▶ {$s->copy(0); # Show failure
Subroutine __ANON__: not called CC=1 SCAR=6.9
7453 0 };
7454  
7455 0 $s # Return subroutine offset or -1
7456 }
7457  
7458 #D1 Assemble # Assemble generated code
7459  
7460 sub CallC($@) # Call a C subroutine.
7461 0 ▶ {my ($sub, @parameters) = @_; # Name of the sub to call, parameters
Subroutine CallC: not called CC=3 SCAR=24.8
Pod documented
7462 0 my @order = (rdi, rsi, rdx, rcx, r8, r9, r15);
7463 0 PushR @order;
7464  
7465 0 for my $i(keys @parameters) # Load parameters into designated registers
7466 0 {Mov $order[$i], $parameters[$i];
7467 }
7468  
7469 0 Push rax; # Align stack on 16 bytes
7470 0 Mov rax, rsp; # Move stack pointer
7471 0 Shl rax, 60; # Get lowest nibble
7472 0 Shr rax, 60;
7473 IfEq # If we are 16 byte aligned push two twos
7474 Then
7475 0 ▶ {Mov rax, 2; Push rax; Push rax;
Subroutine __ANON__: not called CC=1 SCAR=6.9
7476 },
7477 Else # If we are not 16 byte aligned push one one.
7478 0 ▶ {Mov rax, 1; Push rax;
Subroutine __ANON__: not called CC=1 SCAR=6.9
7479 0 };
7480  
7481 0 ▶ if (ref($sub)) # Where do we use this option?
Branch: 1 branch
BranchTrueFalseTotal
if (ref $sub) { } 0 0 0
7482 0 {Call $sub->start;
7483 }
7484 else # Call named subroutine
7485 0 {Call $sub;
7486 }
7487  
7488 0 Pop r15; # Decode and reset stack after 16 byte alignment
7489 0 Cmp r15, 2; # Check for double push
7490 0 Pop r15; # Single or double push
7491 0 ▶ IfEq Then {Pop r15}; # Double push
Subroutine __ANON__: not called CC=1 SCAR=6.9
7492 0 PopR @order;
7493 }
7494  
7495 sub Extern(@) # Name external references.
7496 0 ▶ {my (@externalReferences) = @_; # External references
Subroutine Extern: not called CC=1 SCAR=6.9
Pod documented
7497 0 push @extern, @_;
7498 }
7499  
7500 sub Link(@) # Libraries to link with.
7501 0 ▶ {my (@libraries) = @_; # External references
Subroutine Link: not called CC=1 SCAR=6.9
Pod documented
7502 0 push @link, @_;
7503 }
7504  
7505 sub Start() # Initialize the assembler.
7506 0 ▶ {@bss = @data = @rodata = %rodata = %rodatas = %subroutines = @text =
Subroutine Start: not called CC=1 SCAR=6.9
Pod documented
7507 @PushR = @PushZmm = @PushMask = @extern = @link = @VariableStack = ();
7508 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.
7509 0 SubroutineStartStack; # Number of variables at each lexical level
7510 0 $Labels = 0;
7511 }
7512  
7513 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.
7514 0 ▶ {my ($c) = @_; # Return code
Subroutine Exit: not called CC=2 SCAR=17.9
Pod documented
7515 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
7516 my $s = Subroutine
7517 0 ▶ {Comment "Exit code: $c";
Subroutine __ANON__: not called CC=1 SCAR=6.9
7518 0 PushR (rax, rdi);
7519 0 Mov rdi, $c;
7520 0 Mov rax, 60;
7521 0 Syscall;
7522 0 PopR;
7523 0 } [], name => "Exit_$c";
7524  
7525 0 $s->call;
7526 }
7527  
7528 1 my $LocateIntelEmulator; # Location of Intel Software Development Emulator
7529  
7530 sub LocateIntelEmulator() #P Locate the Intel Software Development Emulator.
7531 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
7532 0 my $downloads = q(/home/phil/Downloads); # Downloads folder
7533  
7534 0 ▶ return $LocateIntelEmulator if defined $LocateIntelEmulator; # Location has already been discovered
Branch: 1 branch
BranchTrueFalseTotal
if defined $LocateIntelEmulator 0 0 0
7535  
7536 0 for my $l(@locations) # Try each locations
7537 0 ▶ {return $LocateIntelEmulator = $l if -e $l; # Found it - cache and return
Branch: 1 branch
BranchTrueFalseTotal
if -e $l 0 0 0
7538 }
7539  
7540 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
7541 0 {return $LocateIntelEmulator = "sde64";
7542 }
7543  
7544 0 ▶ return undef unless -e $downloads; # Skip local install if not developing
Branch: 1 branch
BranchTrueFalseTotal
unless -e $downloads 0 0 0
7545 0 my $install = <<END =~ s(\n) ( && )gsr =~ s(&&\s*\Z) ()sr; # Install sde
7546 cd $downloads
7547 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
7548 tar -xf sde.tar.bz2
7549 sudo mkdir -p /var/isde/
7550 sudo cp -r * /var/isde/
7551 ls -ls /var/isde/
7552 END
7553  
7554 0 say STDERR qx($install); # Execute install
7555  
7556 0 for my $l(@locations) # Retry install locations after install
7557 0 ▶ {return $LocateIntelEmulator = $l if -e $l; # Found it - cache and return
Branch: 1 branch
BranchTrueFalseTotal
if -e $l 0 0 0
7558 }
7559 undef # Still not found - give up
7560 0 }
7561  
7562 sub getInstructionCount() #P Get the number of instructions executed from the emulator mix file.
7563 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
7564 0 my $s = readFile $sdeMixOut;
7565 0 ▶ if ($s =~ m(\*total\s*(\d+))) {return $1}
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /\*total\s*(\d+)/) 0 0 0
7566 0 confess;
7567 }
7568  
7569 sub Optimize(%) #P Perform code optimizations.
7570 0 ▶ {my (%options) = @_; # Options
Subroutine Optimize: not called CC=7 SCAR=40.3
Pod documented
7571 0 my %o = map {$_=>1} $options{optimize}->@*;
7572 0 if (1 or $o{if}) # Optimize if statements by looking for the unnecessary reload of the just stored result
7573 0 {for my $i(1..@text-2) # Each line
7574 0 {my $t = $text[$i];
7575 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
7576 0 {my $R = $1; # Register being pushed
7577 0 my $s = $text[$i-1]; # Previous line
7578 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
7579 0 {my $r = $text[$i-2];
7580 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
7581 0 {my $n = $1; # Variable number
7582 0 my $u = $text[$i+1];
7583 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
7584 0 {for my $j($i-1..$i+1)
7585 0 {$text[$j] = '; out '. $text[$j];
7586 }
7587 }
7588 }
7589 }
7590 }
7591 }
7592 }
7593 }
7594  
7595 1 our $assembliesPerformed = 0; # Number of assemblies performed
7596 1 our $instructionsExecuted = 0; # Total number of instructions executed
7597 1 our $totalBytesAssembled = 0; # Total size of the output programs
7598  
7599 sub Assemble(%) # Assemble the generated code.
7600 0 ▶ {my (%options) = @_; # Options
Subroutine Assemble: not called CC=44 SCAR=75.9
Pod documented
7601 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
7602 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
7603 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
7604  
7605 # Optimize(%options); # Perform any optimizations requested
7606  
7607 0 my $k = $options{keep}; # Keep the executable
7608 0 my $r = join "\n", map {s/\s+\Z//sr} @rodata;
7609 0 my $d = join "\n", map {s/\s+\Z//sr} @data;
7610 0 my $B = join "\n", map {s/\s+\Z//sr} @bss;
7611 0 my $t = join "\n", map {s/\s+\Z//sr} @text;
7612 0 my $x = join "\n", map {qq(extern $_)} @extern;
7613 0 my $L = join " ", map {qq(-l$_)} @link;
7614 0 my $N = $VariableStack[0]; # Number of variables needed on the stack
7615  
7616 0 my $A = <<END;
7617 section .rodata
7618 $r
7619 section .data
7620 $d
7621 section .bss
7622 $B
7623 section .text
7624 $x
7625 global _start, main
7626 _start:
7627 main:
7628 Enter $N*8, 0
7629 $t
7630 Leave
7631 END
7632  
7633 0 my $c = owf(q(z.asm), $A); # Source file
7634 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
7635 0 my $l = q(z.txt); # Assembler listing
7636 0 my $o = q(z.o); # Object file
7637  
7638 0 ▶ if (!confirmHasCommandLineCommand(q(nasm))) # Check for network assembler
Branch: 1 branch
BranchTrueFalseTotal
unless (&confirmHasCommandLineCommand("nasm")) 0 0 0
7639 0 {my $L = fpf(currentDirectory, $l);
7640 0 say STDERR <<END;
7641 Assember code written to the following file:
7642  
7643 $L
7644  
7645 I cannot compile this file because you do not have Nasm installed, see:
7646  
7647 https://www.nasm.us/
7648 END
7649 0 return;
7650 }
7651  
7652 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
7653 0 my $sde = LocateIntelEmulator; # Locate the emulator
7654  
7655 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
7656 0 {my $E = fpf(currentDirectory, $e);
7657 0 say STDERR <<END;
7658 Executable written to the following file:
7659  
7660 $E
7661  
7662 I am going to run this without using the Intel emulator. Your program will
7663 crash if it contains instructions not implemented on your computer.
7664  
7665 You can get the Intel emulator from:
7666  
7667 https://software.intel.com/content/dam/develop/external/us/en/documents/downloads/sde-external-8.63.0-2021-01-18-lin.tar.bz2
7668  
7669 To avoid this message, use option(1) below to produce just an executable
7670 without running it, or use the option(2) to run without the emulator:
7671  
7672 (1) Assemble(keep=>"executable file name")
7673  
7674 (2) Assemble(emulator=>0)
7675 END
7676 0 $emulator = 0;
7677 }
7678  
7679 0 ▶ if (my @emulatorFiles = searchDirectoryTreesForMatchingFiles(qw(. .txt))) # Remove prior emulator output files
Branch: 1 branch
BranchTrueFalseTotal
if (my(@emulatorFiles) = &searchDirectoryTreesForMatchingFiles((".", ".txt"))) 0 0 0
7680 0 {for my $f(@emulatorFiles)
7681 0 ▶ {unlink $f if $f =~ m(sde-mix-out);
Branch: 1 branch
BranchTrueFalseTotal
if $f =~ /sde-mix-out/ 0 0 0
7682 }
7683 }
7684 0 unlink qw(sde-ptr-check.out.txt sde-mix-out.txt sde-debugtrace-out.txt);
7685  
7686 0 ▶ my $I = @link ? $interpreter : ''; # Interpreter only required if calling C
Branch: 1 branch
BranchTrueFalseTotal
@link ? : 0 0 0
7687 0 my $cmd = trim(<<END);
7688 nasm -f elf64 -g -l $l -o $o $c && ld $I $L -o $e $o && chmod 744 $e
7689 END
7690 0 my $o1 = 'zzzOut.txt';
7691 0 my $o2 = 'zzzErr.txt';
7692 0 unlink $o1, $o2; # Remove output files
7693 0 ▶ my $out = $k ? '' : "1>$o1";
Branch: 1 branch
BranchTrueFalseTotal
$k ? : 0 0 0
7694 0 ▶ my $err = $k ? '' : "2>$o2";
Branch: 1 branch
BranchTrueFalseTotal
$k ? : 0 0 0
7695 0 my $opt = qq($sde -mix -ptr-check); # Emulator options
7696 0 ▶ $opt = qq($sde -mix -ptr-check -debugtrace -footprint) if $debugTrace; # Emulator options
Branch: 1 branch
BranchTrueFalseTotal
if $debugTrace 0 0 0
7697 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
7698  
7699 0 ▶ $cmd .= qq( && $exec) unless $k; # Execute automatically unless suppressed by user
Branch: 1 branch
BranchTrueFalseTotal
unless $k 0 0 0
7700  
7701 0 qx($cmd); # Assemble and perhaps run
7702  
7703 0 if (1) # Execution details
7704 0 {my $instructions = getInstructionCount; # Instructions executed under emulator
7705 0 $instructionsExecuted += $instructions; # Count instructions executed
7706 0 my $p = $assembliesPerformed++; # Count assemblies
7707 0 my $n = $options{number};
7708 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
7709  
7710 0 my $bytes = fileSize($e) - 9512 + 64; # Estimate the size of the output program
7711 0 $totalBytesAssembled += $bytes; # Estimate total of all programs assembled
7712  
7713 0 my (undef, $file, $line) = caller();
7714 # Line in caller
7715 say STDERR sprintf("%4d %12s %12s %12s %12s at $file line $line",
7716 $assembliesPerformed,
7717 0 map {numberWithCommas $_} $instructions, $bytes,
7718 $instructionsExecuted, $totalBytesAssembled);
7719 }
7720  
7721 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
7722 0 {say STDERR readBinaryFile($o2);
7723 }
7724  
7725 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
7726 0 {say STDERR readFile($o1) =~ s(0) ( )gsr;
7727 0 say STDERR readFile($o2);
7728 }
7729  
7730 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
7731  
7732 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
7733 0 {confess "SDE ERROR\n".readFile($o2);
7734 }
7735  
7736 0 unlink $o; # Delete files
7737 0 ▶ unlink $e unless $k; # Delete executable unless asked to keep it
Branch: 1 branch
BranchTrueFalseTotal
unless $k 0 0 0
7738  
7739 0 ▶ if (my $N = $options{countComments}) # Count the comments so we can see what code to put into sub routines
Branch: 1 branch
BranchTrueFalseTotal
if (my $N = $options{"countComments"}) 0 0 0
7740 0 {my %c;
7741  
7742 0 for my $c(grep {m/\A\;/} split /\n/, $A)
7743 0 ▶ {if ($c =~ m(line (\d+)))
Branch: 1 branch
BranchTrueFalseTotal
if ($c =~ /line (\d+)/) 0 0 0
7744 0 {$c{$1}++;
7745 }
7746 }
7747  
7748 0 my @c;
7749 0 for my $c(keys %c) # Remove comments that do not appear often
7750 0 ▶ {push @c, [$c{$c}, $c] if $c{$c} >= $N;
Branch: 1 branch
BranchTrueFalseTotal
if $c{$c} >= $N 0 0 0
7751 }
7752 0 my @d = sort {$$b[0] <=> $$a[0]} @c;
7753 0 say STDERR formatTable(\@d, [qw(Count Line)]); # Print frequently appearing comments
7754 }
7755  
7756 0 Start; # Clear work areas for next assembly
7757 0 ▶ return $exec if $k; # Executable wanted
Branch: 1 branch
BranchTrueFalseTotal
if $k 0 0 0
7758  
7759 0 ▶ if (defined(my $e = $options{eq})) # Diff against expected
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $e = $options{"eq"})) 0 0 0
7760 0 ▶ {my $g = readFile($debug < 2 ? $o1 : $o2);
Branch: 1 branch
BranchTrueFalseTotal
$debug < 2 ? : 0 0 0
7761 0 $e =~ s(\s+#.*?\n) (\n)gs; # Remove comments so we can annotate listings
7762 0 ▶ if ($g ne $e)
Branch: 1 branch
BranchTrueFalseTotal
if ($g ne $e) 0 0 0
7763 0 {my ($s, $G, $E) = stringsAreNotEqual($g, $e);
7764 0 ▶ if (length($s))
Branch: 1 branch
BranchTrueFalseTotal
if (length $s) 0 0 0
7765 0 {my $line = 1 + length($s =~ s([^\n]) ()gsr);
7766 0 my $char = 1 + length($s =~ s(\A.*\n) ()sr);
7767 0 say STDERR "Comparing wanted with got failed at line: $line, character: $char";
7768 0 say STDERR "Start:\n$s";
7769 }
7770 0 my $b1 = '+' x 80;
7771 0 my $b2 = '_' x 80;
7772 0 say STDERR "Want $b1\n", firstNChars($E, 80);
7773 0 say STDERR "Got $b2\n", firstNChars($G, 80);
7774 0 say STDERR "Want: ", dump($e);
7775 0 say STDERR "Got : ", dump($g);
7776 0 confess "Test failed"; # Test failed unless we are debugging test failures
7777 }
7778 0 return 1; # Test passed
7779 }
7780  
7781 0 ▶ scalar(readFile($debug < 2 ? $o1 : $o2)); # Show stdout results unless stderr results requested
Branch: 1 branch
BranchTrueFalseTotal
$debug < 2 ? : 0 0 0
7782 }
7783  
7784 sub removeNonAsciiChars($) #P Return a copy of the specified string with all the non ascii characters removed.
7785 0 ▶ {my ($string) = @_; # String
Subroutine removeNonAsciiChars: not called CC=1 SCAR=6.9
Pod documented
7786 0 $string =~ s([^a-z0..9]) ()igsr; # Remove non ascii characters
7787 }
7788  
7789 sub totalBytesAssembled #P Total size in bytes of all files assembled during testing.
7790 0 ▶ {$totalBytesAssembled
Subroutine totalBytesAssembled: not called CC=1 SCAR=6.9
Pod documented
7791 }
7792  
7793 #d
7794 #-------------------------------------------------------------------------------
7795 # Export - eeee
7796 #-------------------------------------------------------------------------------
7797  
7798 1 if (0) # Print exports
7799 {my @e;
7800 for my $a(sort keys %Nasm::X86::)
7801 {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);
7802 next if $a =~ m(\AEXPORT);
7803 next if $a !~ m(\A[A-Z]) and !$Registers{$a};
7804 next if $a =~ m(::\Z);
7805 push @e, $a if $Nasm::X86::{$a} =~ m(\*Nasm::X86::);
7806 }
7807 say STDERR q/@EXPORT_OK = qw(/.join(' ', @e).q/);/;
7808 exit;
7809 }
7810  
7811 1 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
7812  
7813 1 ▶use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
Subroutine BEGIN: called CC=1 SCAR=0.0
7814  
7815 1 @ISA = qw(Exporter);
7816 1 @EXPORT = qw();
7817 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);
7818 1 %EXPORT_TAGS = (all => [@EXPORT, @EXPORT_OK]);
7819  
7820 # podDocumentation
7821 =pod
7822  
7823 =encoding utf-8
7824  
7825 =head1 Name
7826  
7827 Nasm::X86 - Generate X86 assembler code using Perl as a macro pre-processor.
7828  
7829 =head1 Synopsis
7830  
7831 Write and execute B<x64> B<Avx512> assembler code from L<perl> using L<perl> as a
7832 macro assembler. The generated code can be run under the Intel emulator to
7833 obtain execution trace and instruction counts.
7834  
7835 =head2 Examples
7836  
7837 =head3 Avx512 instructions
7838  
7839 Use B<Avx512> instructions to perform B<64> comparisons in parallel.
7840  
7841 my $P = "2F"; # Value to test for
7842 my $l = Rb 0; Rb $_ for 1..RegisterSize zmm0; # 0..63
7843 Vmovdqu8 zmm0, "[$l]"; # Load data to test
7844 PrintOutRegisterInHex zmm0;
7845  
7846 Mov rax, "0x$P"; # Broadcast the value to be tested
7847 Vpbroadcastb zmm1, rax;
7848 PrintOutRegisterInHex zmm1;
7849  
7850 for my $c(0..7) # Each possible test
7851 {my $m = "k$c";
7852 Vpcmpub $m, zmm1, zmm0, $c;
7853 PrintOutRegisterInHex $m;
7854 }
7855  
7856 Kmovq rax, k0; # Count the number of trailing zeros in k0
7857 Tzcnt rax, rax;
7858 PrintOutRegisterInHex rax;
7859  
7860 is_deeply Assemble, <<END; # Assemble and test
7861 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
7862 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
7863 k0: 0000 8000 0000 0000
7864 k1: FFFF 0000 0000 0000
7865 k2: FFFF 8000 0000 0000
7866 k3: 0000 0000 0000 0000
7867 k4: FFFF 7FFF FFFF FFFF
7868 k5: 0000 FFFF FFFF FFFF
7869 k6: 0000 7FFF FFFF FFFF
7870 k7: FFFF FFFF FFFF FFFF
7871 rax: 0000 0000 0000 002F
7872 END
7873  
7874 With the print statements removed, the Intel Emulator indicates that 26
7875 instructions were executed:
7876  
7877 CALL_NEAR 1
7878 ENTER 2
7879 JMP 1
7880 KMOVQ 1
7881 MOV 5
7882 POP 1
7883 PUSH 3
7884 SYSCALL 1
7885 TZCNT 1
7886 VMOVDQU8 1
7887 VPBROADCASTB 1
7888 VPCMPUB 8
7889  
7890 *total 26
7891  
7892 =head3 Process management
7893  
7894 Start a child process and wait for it, printing out the process identifiers of
7895 each process involved:
7896  
7897 Fork; # Fork
7898  
7899 Test rax,rax;
7900 IfNz # Parent
7901 Then
7902 {Mov rbx, rax;
7903 WaitPid;
7904 GetPid; # Pid of parent as seen in parent
7905 Mov rcx,rax;
7906 PrintOutRegisterInHex rax, rbx, rcx;
7907 },
7908 Else # Child
7909 {Mov r8,rax;
7910 GetPid; # Child pid as seen in child
7911 Mov r9,rax;
7912 GetPPid; # Parent pid as seen in child
7913 Mov r10,rax;
7914 PrintOutRegisterInHex r8, r9, r10;
7915 };
7916  
7917 my $r = Assemble;
7918  
7919 # r8: 0000 0000 0000 0000 #1 Return from fork as seen by child
7920 # r9: 0000 0000 0003 0C63 #2 Pid of child
7921 # r10: 0000 0000 0003 0C60 #3 Pid of parent from child
7922 # rax: 0000 0000 0003 0C63 #4 Return from fork as seen by parent
7923 # rbx: 0000 0000 0003 0C63 #5 Wait for child pid result
7924 # rcx: 0000 0000 0003 0C60 #6 Pid of parent
7925  
7926 =head3 Read a file
7927  
7928 Read this file:
7929  
7930 ReadFile(V(file, Rs($0)), (my $s = V(size)), my $a = V(address)); # Read file
7931 $a->setReg(rax); # Address of file in memory
7932 $s->setReg(rdi); # Length of file in memory
7933 PrintOutMemory; # Print contents of memory to stdout
7934  
7935 my $r = Assemble(1 => (my $f = temporaryFile)); # Assemble and execute
7936 ok fileMd5Sum($f) eq fileMd5Sum($0); # Output contains this file
7937  
7938  
7939 =head3 Call functions in Libc
7940  
7941 Call B<C> functions by naming them as external and including their library:
7942  
7943 my $format = Rs "Hello %s\n";
7944 my $data = Rs "World";
7945  
7946 Extern qw(printf exit malloc strcpy); Link 'c';
7947  
7948 CallC 'malloc', length($format)+1;
7949 Mov r15, rax;
7950 CallC 'strcpy', r15, $format;
7951 CallC 'printf', r15, $data;
7952 CallC 'exit', 0;
7953  
7954 ok Assemble(eq => <<END);
7955 Hello World
7956 END
7957  
7958 =head3 Dynamic arena
7959  
7960 Arenas are resizeable, relocatable blocks of memory that hold other dynamic
7961 data structures. Arenas can be transferred between processes and relocated as
7962 needed as all addressing is relative to the start of the block of memory
7963 containing each arena.
7964  
7965 Create two dynamic arenas, add some content to them, write each arena to
7966 stdout:
7967  
7968 my $a = CreateArena;
7969  
7970 my $b = CreateArena;
7971 $a->q('aa');
7972 $b->q('bb');
7973 $a->q('AA');
7974 $b->q('BB');
7975 $a->q('aa');
7976 $b->q('bb');
7977  
7978 $a->out;
7979 $b->out;
7980  
7981 PrintOutNL;
7982  
7983 is_deeply Assemble, <<END;
7984 aaAAaabbBBbb
7985 END
7986  
7987 =head4 Dynamic string held in an arena
7988  
7989 Create a dynamic string within an arena and add some content to it:
7990  
7991 my $s = Rb(0..255);
7992 my $A = CreateArena;
7993 my $S = $A->CreateString;
7994  
7995 $S->append(V(source, $s), K(size, 256));
7996 $S->len->outNL;
7997 $S->clear;
7998  
7999 $S->append(V(source, $s), K(size, 16));
8000 $S->len->outNL;
8001 $S->dump;
8002  
8003 ok Assemble(debug => 0, eq => <<END);
8004 size: 0000 0000 0000 0100
8005 size: 0000 0000 0000 0010
8006 string Dump
8007 Offset: 0000 0000 0000 0018 Length: 0000 0000 0000 0010
8008 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
8009  
8010 END
8011  
8012 =head4 Dynamic array held in an arena
8013  
8014 Create a dynamic array within an arena, push some content on to it then pop it
8015 off again:
8016  
8017 my $N = 15;
8018 my $A = CreateArena;
8019 my $a = $A->CreateArray;
8020  
8021 $a->push(V(element, $_)) for 1..$N;
8022  
8023 K(loop, $N)->for(sub
8024 {my ($start, $end, $next) = @_;
8025 my $l = $a->size;
8026 If $l == 0, Then {Jmp $end};
8027 $a->pop(my $e = V(element));
8028 $e->outNL;
8029 });
8030  
8031 ok Assemble(debug => 0, eq => <<END);
8032 element: 0000 0000 0000 000F
8033 element: 0000 0000 0000 000E
8034 element: 0000 0000 0000 000D
8035 element: 0000 0000 0000 000C
8036 element: 0000 0000 0000 000B
8037 element: 0000 0000 0000 000A
8038 element: 0000 0000 0000 0009
8039 element: 0000 0000 0000 0008
8040 element: 0000 0000 0000 0007
8041 element: 0000 0000 0000 0006
8042 element: 0000 0000 0000 0005
8043 element: 0000 0000 0000 0004
8044 element: 0000 0000 0000 0003
8045 element: 0000 0000 0000 0002
8046 element: 0000 0000 0000 0001
8047 END
8048  
8049 =head4 Create a multi way tree in an arena using SIMD instructions
8050  
8051 Create a multiway tree as in L<Tree::Multi> using B<Avx512> instructions and
8052 iterate through it:
8053  
8054 my $N = 12;
8055 my $b = CreateArena; # Resizable memory block
8056 my $t = $b->CreateTree; # Multi way tree in memory block
8057  
8058 K(count, $N)->for(sub # Add some entries to the tree
8059 {my ($index, $start, $next, $end) = @_;
8060 my $k = $index + 1;
8061 $t->insert($k, $k + 0x100);
8062 $t->insert($k + $N, $k + 0x200);
8063 });
8064  
8065 $t->by(sub # Iterate through the tree
8066 {my ($iter, $end) = @_;
8067 $iter->key ->out('key: ');
8068 $iter->data->out(' data: ');
8069 $iter->tree->depth($iter->node, my $D = V(depth));
8070  
8071 $t->find($iter->key);
8072 $t->found->out(' found: '); $t->data->out(' data: '); $D->outNL(' depth: ');
8073 });
8074  
8075 $t->find(K(key, 0xffff)); $t->found->outNL('Found: '); # Find some entries
8076 $t->find(K(key, 0xd)); $t->found->outNL('Found: ');
8077  
8078 If ($t->found,
8079 Then
8080 {$t->data->outNL("Data : ");
8081 });
8082  
8083 ok Assemble(debug => 0, eq => <<END);
8084 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
8085 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
8086 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
8087 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
8088 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
8089 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
8090 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
8091 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
8092 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
8093 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
8094 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
8095 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
8096 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
8097 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
8098 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
8099 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
8100 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
8101 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
8102 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
8103 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
8104 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
8105 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
8106 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
8107 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
8108 Found: 0000 0000 0000 0000
8109 Found: 0000 0000 0000 0001
8110 Data : 0000 0000 0000 0201
8111 END
8112  
8113 =head3 Recursion with stack and parameter tracing
8114  
8115 Call a subroutine recursively and get a trace back showing the procedure calls
8116 and parameters passed to each call. Parameters are passed by reference not
8117 value.
8118  
8119 my $d = V depth, 3; # Create a variable on the stack
8120  
8121 my $s = Subroutine
8122 {my ($p, $s) = @_; # Parameters, subroutine descriptor
8123 PrintOutTraceBack;
8124  
8125 my $d = $$p{depth}->copy($$p{depth} - 1); # Modify the variable referenced by the parameter
8126  
8127 If ($d > 0,
8128 Then
8129 {$s->call($d); # Recurse
8130 });
8131  
8132 PrintOutTraceBack;
8133 } [qw(depth)], name => 'ref';
8134  
8135 $s->call($d); # Call the subroutine
8136  
8137 ok Assemble(debug => 0, eq => <<END);
8138  
8139 Subroutine trace back, depth: 0000 0000 0000 0001
8140 0000 0000 0000 0003 ref
8141  
8142  
8143 Subroutine trace back, depth: 0000 0000 0000 0002
8144 0000 0000 0000 0002 ref
8145 0000 0000 0000 0002 ref
8146  
8147  
8148 Subroutine trace back, depth: 0000 0000 0000 0003
8149 0000 0000 0000 0001 ref
8150 0000 0000 0000 0001 ref
8151 0000 0000 0000 0001 ref
8152  
8153  
8154 Subroutine trace back, depth: 0000 0000 0000 0003
8155 0000 0000 0000 0000 ref
8156 0000 0000 0000 0000 ref
8157 0000 0000 0000 0000 ref
8158  
8159  
8160 Subroutine trace back, depth: 0000 0000 0000 0002
8161 0000 0000 0000 0000 ref
8162 0000 0000 0000 0000 ref
8163  
8164  
8165 Subroutine trace back, depth: 0000 0000 0000 0001
8166 0000 0000 0000 0000 ref
8167  
8168 END
8169  
8170 =head3 Quarks
8171  
8172 Quarks replace unique strings with unique numbers and in doing so unite all
8173 that is best and brightest in dynamic trees, arrays, strings and short
8174 strings, all written in X86 assembler, all generated by Perl:
8175  
8176 my $N = 5;
8177 my $a = CreateArena; # Arena containing quarks
8178 my $Q = $a->CreateQuarks; # Quarks
8179  
8180 my $s = CreateShortString(0); # Short string used to load and unload quarks
8181 my $d = Rb(1..63);
8182  
8183 for my $i(1..$N) # Load a set of quarks
8184 {my $j = $i - 1;
8185 $s->load(K(address, $d), K(size, 4+$i));
8186 my $q = $Q->quarkFromShortString($s);
8187 $q->outNL("New quark $j: "); # New quark, new number
8188 }
8189 PrintOutNL;
8190  
8191 for my $i(reverse 1..$N) # Reload a set of quarks
8192 {my $j = $i - 1;
8193 $s->load(K(address, $d), K(size, 4+$i));
8194 my $q = $Q->quarkFromShortString($s);
8195 $q->outNL("Old quark $j: "); # Old quark, old number
8196 }
8197 PrintOutNL;
8198  
8199 for my $i(1..$N) # Dump quarks
8200 {my $j = $i - 1;
8201 $s->clear;
8202 $Q->shortStringFromQuark(K(quark, $j), $s);
8203 PrintOutString "Quark string $j: ";
8204 PrintOutRegisterInHex xmm0;
8205 }
8206  
8207 ok Assemble(debug => 0, trace => 0, eq => <<END);
8208 New quark 0: 0000 0000 0000 0000
8209 New quark 1: 0000 0000 0000 0001
8210 New quark 2: 0000 0000 0000 0002
8211 New quark 3: 0000 0000 0000 0003
8212 New quark 4: 0000 0000 0000 0004
8213  
8214 Old quark 4: 0000 0000 0000 0004
8215 Old quark 3: 0000 0000 0000 0003
8216 Old quark 2: 0000 0000 0000 0002
8217 Old quark 1: 0000 0000 0000 0001
8218 Old quark 0: 0000 0000 0000 0000
8219  
8220 Quark string 0: xmm0: 0000 0000 0000 0000 0000 0504 0302 0105
8221 Quark string 1: xmm0: 0000 0000 0000 0000 0006 0504 0302 0106
8222 Quark string 2: xmm0: 0000 0000 0000 0000 0706 0504 0302 0107
8223 Quark string 3: xmm0: 0000 0000 0000 0008 0706 0504 0302 0108
8224 Quark string 4: xmm0: 0000 0000 0000 0908 0706 0504 0302 0109
8225 END
8226  
8227  
8228  
8229 =head2 Installation
8230  
8231 The Intel Software Development Emulator will be required if you do not have a
8232 computer with the avx512 instruction set and wish to execute code containing
8233 these instructions. For details see:
8234  
8235 L<https://software.intel.com/content/dam/develop/external/us/en/documents/downloads/sde-external-8.63.0-2021-01-18-lin.tar.bz2>
8236  
8237  
8238 The Networkwide Assembler is required to assemble the code produced For full
8239 details see:
8240  
8241 L<https://github.com/philiprbrenan/NasmX86/blob/main/.github/workflows/main.yml>
8242  
8243 =head2 Execution Options
8244  
8245 The L</Assemble(%)> function takes the keywords described below to
8246 control assembly and execution of the assembled code:
8247  
8248 L</Assemble(%)> runs the generated program after a successful assembly
8249 unless the B<keep> option is specified. The output on B<stdout> is captured in
8250 file B<zzzOut.txt> and that on B<stderr> is captured in file B<zzzErr.txt>.
8251  
8252 The amount of output displayed is controlled by the B<debug> keyword.
8253  
8254 The B<eq> keyword can be used to test that the output by the run.
8255  
8256 The output produced by the program execution is returned as the result of the
8257 L</Assemble(%)> function.
8258  
8259 =head3 Keep
8260  
8261 To produce a named executable without running it, specify:
8262  
8263 keep=>"executable file name"
8264  
8265 =head3 Emulator
8266  
8267 To run the executable produced by L</Assemble(%)> without the Intel
8268 emulator, which is used by default if it is present, specify:
8269  
8270 emulator=>0
8271  
8272 =head3 eq
8273  
8274 The B<eq> keyword supplies the expected output from the execution of the
8275 assembled program. If the expected output is not obtained on B<stdout> then we
8276 confess and stop further testing. Output on B<stderr> is ignored for test
8277 purposes.
8278  
8279 The point at which the wanted output diverges from the output actually got is
8280 displayed to assist debugging as in:
8281  
8282 Comparing wanted with got failed at line: 4, character: 22
8283 Start:
8284 k7: 0000 0000 0000 0001
8285 k6: 0000 0000 0000 0003
8286 k5: 0000 0000 0000 0007
8287 k4: 0000 0000 000
8288 Want ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8289 1 0002
8290 k3: 0000 0000 0000 0006
8291 k2: 0000 0000 0000 000E
8292 k1: 0000 0000
8293 Got ________________________________________________________________________________
8294 0 0002
8295 k3: 0000 0000 0000 0006
8296 k2: 0000 0000 0000 000E
8297 k1: 0000 0000
8298  
8299  
8300 =head3 Debug
8301  
8302 The debug keyword controls how much output is printed after each assemble and
8303 run.
8304  
8305 debug => 0
8306  
8307 produces no output unless the B<eq> keyword was specified and the actual output
8308 fails to match the expected output. If such a test fails we L<Carp::confess>.
8309  
8310 debug => 1
8311  
8312 shows all the output produces and conducts the test specified by the B<eq> is
8313 present. If the test fails we L<Carp::confess>.
8314  
8315 debug => 2
8316  
8317 shows all the output produces and conducts the test specified by the B<eq> is
8318 present. If the test fails we continue rather than calling L<Carp::confess>.
8319  
8320 =head1 Description
8321  
8322 Generate X86 assembler code using Perl as a macro pre-processor.
8323  
8324  
8325 Version "20210910".
8326  
8327  
8328 The following sections describe the methods in each functional area of this
8329 module. For an alphabetic listing of all methods by name see L<Index|/Index>.
8330  
8331  
8332  
8333 =head1 Data
8334  
8335 Layout data
8336  
8337 =head2 SetLabel($l)
8338  
8339 Create (if necessary) and set a label in the code section returning the label so set.
8340  
8341 Parameter Description
8342 1 $l Label
8343  
8344 B<Example:>
8345  
8346  
8347 Mov rax, 1;
8348 Mov rdi, 1;
8349 SaveFirstFour;
8350 Mov rax, 2;
8351 Mov rdi, 2;
8352 SaveFirstSeven;
8353 Mov rax, 3;
8354 Mov rdi, 4;
8355 PrintOutRegisterInHex rax, rdi;
8356 RestoreFirstSeven;
8357 PrintOutRegisterInHex rax, rdi;
8358 RestoreFirstFour;
8359 PrintOutRegisterInHex rax, rdi;
8360  
8361 SaveFirstFour;
8362 Mov rax, 2;
8363 Mov rdi, 2;
8364 SaveFirstSeven;
8365 Mov rax, 3;
8366 Mov rdi, 4;
8367 PrintOutRegisterInHex rax, rdi;
8368 RestoreFirstSevenExceptRax;
8369 PrintOutRegisterInHex rax, rdi;
8370 RestoreFirstFourExceptRax;
8371 PrintOutRegisterInHex rax, rdi;
8372  
8373 SaveFirstFour;
8374 Mov rax, 2;
8375 Mov rdi, 2;
8376 SaveFirstSeven;
8377 Mov rax, 3;
8378 Mov rdi, 4;
8379 PrintOutRegisterInHex rax, rdi;
8380 RestoreFirstSevenExceptRaxAndRdi;
8381 PrintOutRegisterInHex rax, rdi;
8382 RestoreFirstFourExceptRaxAndRdi;
8383 PrintOutRegisterInHex rax, rdi;
8384  
8385 Bswap rax;
8386 PrintOutRegisterInHex rax;
8387  
8388 my $l = Label;
8389 Jmp $l;
8390  
8391 SetLabel $l; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
8392  
8393  
8394 ok Assemble(debug => 0, eq => <<END);
8395 rax: 0000 0000 0000 0003
8396 rdi: 0000 0000 0000 0004
8397 rax: 0000 0000 0000 0002
8398 rdi: 0000 0000 0000 0002
8399 rax: 0000 0000 0000 0001
8400 rdi: 0000 0000 0000 0001
8401 rax: 0000 0000 0000 0003
8402 rdi: 0000 0000 0000 0004
8403 rax: 0000 0000 0000 0003
8404 rdi: 0000 0000 0000 0002
8405 rax: 0000 0000 0000 0003
8406 rdi: 0000 0000 0000 0001
8407 rax: 0000 0000 0000 0003
8408 rdi: 0000 0000 0000 0004
8409 rax: 0000 0000 0000 0003
8410 rdi: 0000 0000 0000 0004
8411 rax: 0000 0000 0000 0003
8412 rdi: 0000 0000 0000 0004
8413 rax: 0300 0000 0000 0000
8414 END
8415  
8416 ok 8 == RegisterSize rax;
8417  
8418  
8419 =head2 Ds(@d)
8420  
8421 Layout bytes in memory and return their label.
8422  
8423 Parameter Description
8424 1 @d Data to be laid out
8425  
8426 B<Example:>
8427  
8428  
8429 my $q = Rs('a'..'z');
8430  
8431 Mov rax, Ds('0'x64); # Output area # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
8432  
8433 Vmovdqu32(xmm0, "[$q]"); # Load
8434 Vprolq (xmm0, xmm0, 32); # Rotate double words in quad words
8435 Vmovdqu32("[rax]", xmm0); # Save
8436 Mov rdi, 16;
8437 PrintOutMemory;
8438  
8439 ok Assemble =~ m(efghabcdmnopijkl)s;
8440  
8441  
8442 =head2 Rs(@d)
8443  
8444 Layout bytes in read only memory and return their label.
8445  
8446 Parameter Description
8447 1 @d Data to be laid out
8448  
8449 B<Example:>
8450  
8451  
8452 Comment "Print a string from memory";
8453 my $s = "Hello World";
8454  
8455 Mov rax, Rs($s); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
8456  
8457 Mov rdi, length $s;
8458 PrintOutMemory;
8459 Exit(0);
8460  
8461 ok Assemble =~ m(Hello World);
8462  
8463  
8464 my $q = Rs('abababab'); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
8465  
8466 Mov(rax, 1);
8467 Mov(rbx, 2);
8468 Mov(rcx, 3);
8469 Mov(rdx, 4);
8470 Mov(r8, 5);
8471 Lea r9, "[rax+rbx]";
8472 PrintOutRegistersInHex;
8473  
8474 my $r = Assemble;
8475 ok $r =~ m( r8: 0000 0000 0000 0005.* r9: 0000 0000 0000 0003.*rax: 0000 0000 0000 0001)s;
8476 ok $r =~ m(rbx: 0000 0000 0000 0002.*rcx: 0000 0000 0000 0003.*rdx: 0000 0000 0000 0004)s;
8477  
8478  
8479 =head2 Rutf8(@d)
8480  
8481 Layout a utf8 encoded string as bytes in read only memory and return their label.
8482  
8483 Parameter Description
8484 1 @d Data to be laid out
8485  
8486 =head2 Db(@bytes)
8487  
8488 Layout bytes in the data segment and return their label.
8489  
8490 Parameter Description
8491 1 @bytes Bytes to layout
8492  
8493 B<Example:>
8494  
8495  
8496 my $s = Rb 0; Rb 1; Rw 2; Rd 3; Rq 4;
8497  
8498 my $t = Db 0; Db 1; Dw 2; Dd 3; Dq 4; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
8499  
8500  
8501 Vmovdqu8 xmm0, "[$s]";
8502 Vmovdqu8 xmm1, "[$t]";
8503 PrintOutRegisterInHex xmm0;
8504 PrintOutRegisterInHex xmm1;
8505 Sub rsp, 16;
8506  
8507 Mov rax, rsp; # Copy memory, the target is addressed by rax, the length is in rdi, the source is addressed by rsi
8508 Mov rdi, 16;
8509 Mov rsi, $s;
8510 CopyMemory(V(source, rsi), V(target, rax), V(size, rdi));
8511 PrintOutMemoryInHex;
8512  
8513 my $r = Assemble;
8514 ok $r =~ m(xmm0: 0000 0000 0000 0004 0000 0003 0002 0100);
8515 ok $r =~ m(xmm1: 0000 0000 0000 0004 0000 0003 0002 0100);
8516 ok $r =~ m(0001 0200 0300 00000400 0000 0000 0000);
8517  
8518  
8519 =head2 Dw(@words)
8520  
8521 Layout words in the data segment and return their label.
8522  
8523 Parameter Description
8524 1 @words Words to layout
8525  
8526 B<Example:>
8527  
8528  
8529 my $s = Rb 0; Rb 1; Rw 2; Rd 3; Rq 4;
8530  
8531 my $t = Db 0; Db 1; Dw 2; Dd 3; Dq 4; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
8532  
8533  
8534 Vmovdqu8 xmm0, "[$s]";
8535 Vmovdqu8 xmm1, "[$t]";
8536 PrintOutRegisterInHex xmm0;
8537 PrintOutRegisterInHex xmm1;
8538 Sub rsp, 16;
8539  
8540 Mov rax, rsp; # Copy memory, the target is addressed by rax, the length is in rdi, the source is addressed by rsi
8541 Mov rdi, 16;
8542 Mov rsi, $s;
8543 CopyMemory(V(source, rsi), V(target, rax), V(size, rdi));
8544 PrintOutMemoryInHex;
8545  
8546 my $r = Assemble;
8547 ok $r =~ m(xmm0: 0000 0000 0000 0004 0000 0003 0002 0100);
8548 ok $r =~ m(xmm1: 0000 0000 0000 0004 0000 0003 0002 0100);
8549 ok $r =~ m(0001 0200 0300 00000400 0000 0000 0000);
8550  
8551  
8552 =head2 Dd(@dwords)
8553  
8554 Layout double words in the data segment and return their label.
8555  
8556 Parameter Description
8557 1 @dwords Double words to layout
8558  
8559 B<Example:>
8560  
8561  
8562 my $s = Rb 0; Rb 1; Rw 2; Rd 3; Rq 4;
8563  
8564 my $t = Db 0; Db 1; Dw 2; Dd 3; Dq 4; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
8565  
8566  
8567 Vmovdqu8 xmm0, "[$s]";
8568 Vmovdqu8 xmm1, "[$t]";
8569 PrintOutRegisterInHex xmm0;
8570 PrintOutRegisterInHex xmm1;
8571 Sub rsp, 16;
8572  
8573 Mov rax, rsp; # Copy memory, the target is addressed by rax, the length is in rdi, the source is addressed by rsi
8574 Mov rdi, 16;
8575 Mov rsi, $s;
8576 CopyMemory(V(source, rsi), V(target, rax), V(size, rdi));
8577 PrintOutMemoryInHex;
8578  
8579 my $r = Assemble;
8580 ok $r =~ m(xmm0: 0000 0000 0000 0004 0000 0003 0002 0100);
8581 ok $r =~ m(xmm1: 0000 0000 0000 0004 0000 0003 0002 0100);
8582 ok $r =~ m(0001 0200 0300 00000400 0000 0000 0000);
8583  
8584  
8585 =head2 Dq(@qwords)
8586  
8587 Layout quad words in the data segment and return their label.
8588  
8589 Parameter Description
8590 1 @qwords Quad words to layout
8591  
8592 B<Example:>
8593  
8594  
8595 my $s = Rb 0; Rb 1; Rw 2; Rd 3; Rq 4;
8596  
8597 my $t = Db 0; Db 1; Dw 2; Dd 3; Dq 4; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
8598  
8599  
8600 Vmovdqu8 xmm0, "[$s]";
8601 Vmovdqu8 xmm1, "[$t]";
8602 PrintOutRegisterInHex xmm0;
8603 PrintOutRegisterInHex xmm1;
8604 Sub rsp, 16;
8605  
8606 Mov rax, rsp; # Copy memory, the target is addressed by rax, the length is in rdi, the source is addressed by rsi
8607 Mov rdi, 16;
8608 Mov rsi, $s;
8609 CopyMemory(V(source, rsi), V(target, rax), V(size, rdi));
8610 PrintOutMemoryInHex;
8611  
8612 my $r = Assemble;
8613 ok $r =~ m(xmm0: 0000 0000 0000 0004 0000 0003 0002 0100);
8614 ok $r =~ m(xmm1: 0000 0000 0000 0004 0000 0003 0002 0100);
8615 ok $r =~ m(0001 0200 0300 00000400 0000 0000 0000);
8616  
8617  
8618 =head2 Rb(@bytes)
8619  
8620 Layout bytes in the data segment and return their label.
8621  
8622 Parameter Description
8623 1 @bytes Bytes to layout
8624  
8625 B<Example:>
8626  
8627  
8628  
8629 my $s = Rb 0; Rb 1; Rw 2; Rd 3; Rq 4; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
8630  
8631 my $t = Db 0; Db 1; Dw 2; Dd 3; Dq 4;
8632  
8633 Vmovdqu8 xmm0, "[$s]";
8634 Vmovdqu8 xmm1, "[$t]";
8635 PrintOutRegisterInHex xmm0;
8636 PrintOutRegisterInHex xmm1;
8637 Sub rsp, 16;
8638  
8639 Mov rax, rsp; # Copy memory, the target is addressed by rax, the length is in rdi, the source is addressed by rsi
8640 Mov rdi, 16;
8641 Mov rsi, $s;
8642 CopyMemory(V(source, rsi), V(target, rax), V(size, rdi));
8643 PrintOutMemoryInHex;
8644  
8645 my $r = Assemble;
8646 ok $r =~ m(xmm0: 0000 0000 0000 0004 0000 0003 0002 0100);
8647 ok $r =~ m(xmm1: 0000 0000 0000 0004 0000 0003 0002 0100);
8648 ok $r =~ m(0001 0200 0300 00000400 0000 0000 0000);
8649  
8650  
8651 =head2 Rw(@words)
8652  
8653 Layout words in the data segment and return their label.
8654  
8655 Parameter Description
8656 1 @words Words to layout
8657  
8658 B<Example:>
8659  
8660  
8661  
8662 my $s = Rb 0; Rb 1; Rw 2; Rd 3; Rq 4; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
8663  
8664 my $t = Db 0; Db 1; Dw 2; Dd 3; Dq 4;
8665  
8666 Vmovdqu8 xmm0, "[$s]";
8667 Vmovdqu8 xmm1, "[$t]";
8668 PrintOutRegisterInHex xmm0;
8669 PrintOutRegisterInHex xmm1;
8670 Sub rsp, 16;
8671  
8672 Mov rax, rsp; # Copy memory, the target is addressed by rax, the length is in rdi, the source is addressed by rsi
8673 Mov rdi, 16;
8674 Mov rsi, $s;
8675 CopyMemory(V(source, rsi), V(target, rax), V(size, rdi));
8676 PrintOutMemoryInHex;
8677  
8678 my $r = Assemble;
8679 ok $r =~ m(xmm0: 0000 0000 0000 0004 0000 0003 0002 0100);
8680 ok $r =~ m(xmm1: 0000 0000 0000 0004 0000 0003 0002 0100);
8681 ok $r =~ m(0001 0200 0300 00000400 0000 0000 0000);
8682  
8683  
8684 =head2 Rd(@dwords)
8685  
8686 Layout double words in the data segment and return their label.
8687  
8688 Parameter Description
8689 1 @dwords Double words to layout
8690  
8691 B<Example:>
8692  
8693  
8694  
8695 my $s = Rb 0; Rb 1; Rw 2; Rd 3; Rq 4; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
8696  
8697 my $t = Db 0; Db 1; Dw 2; Dd 3; Dq 4;
8698  
8699 Vmovdqu8 xmm0, "[$s]";
8700 Vmovdqu8 xmm1, "[$t]";
8701 PrintOutRegisterInHex xmm0;
8702 PrintOutRegisterInHex xmm1;
8703 Sub rsp, 16;
8704  
8705 Mov rax, rsp; # Copy memory, the target is addressed by rax, the length is in rdi, the source is addressed by rsi
8706 Mov rdi, 16;
8707 Mov rsi, $s;
8708 CopyMemory(V(source, rsi), V(target, rax), V(size, rdi));
8709 PrintOutMemoryInHex;
8710  
8711 my $r = Assemble;
8712 ok $r =~ m(xmm0: 0000 0000 0000 0004 0000 0003 0002 0100);
8713 ok $r =~ m(xmm1: 0000 0000 0000 0004 0000 0003 0002 0100);
8714 ok $r =~ m(0001 0200 0300 00000400 0000 0000 0000);
8715  
8716  
8717 =head2 Rq(@qwords)
8718  
8719 Layout quad words in the data segment and return their label.
8720  
8721 Parameter Description
8722 1 @qwords Quad words to layout
8723  
8724 B<Example:>
8725  
8726  
8727  
8728 my $s = Rb 0; Rb 1; Rw 2; Rd 3; Rq 4; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
8729  
8730 my $t = Db 0; Db 1; Dw 2; Dd 3; Dq 4;
8731  
8732 Vmovdqu8 xmm0, "[$s]";
8733 Vmovdqu8 xmm1, "[$t]";
8734 PrintOutRegisterInHex xmm0;
8735 PrintOutRegisterInHex xmm1;
8736 Sub rsp, 16;
8737  
8738 Mov rax, rsp; # Copy memory, the target is addressed by rax, the length is in rdi, the source is addressed by rsi
8739 Mov rdi, 16;
8740 Mov rsi, $s;
8741 CopyMemory(V(source, rsi), V(target, rax), V(size, rdi));
8742 PrintOutMemoryInHex;
8743  
8744 my $r = Assemble;
8745 ok $r =~ m(xmm0: 0000 0000 0000 0004 0000 0003 0002 0100);
8746 ok $r =~ m(xmm1: 0000 0000 0000 0004 0000 0003 0002 0100);
8747 ok $r =~ m(0001 0200 0300 00000400 0000 0000 0000);
8748  
8749  
8750 =head1 Registers
8751  
8752 Operations on registers
8753  
8754 =head2 xmm(@r)
8755  
8756 Add xmm to the front of a list of register expressions.
8757  
8758 Parameter Description
8759 1 @r Register numbers
8760  
8761 =head2 ymm(@r)
8762  
8763 Add ymm to the front of a list of register expressions.
8764  
8765 Parameter Description
8766 1 @r Register numbers
8767  
8768 =head2 zmm(@r)
8769  
8770 Add zmm to the front of a list of register expressions.
8771  
8772 Parameter Description
8773 1 @r Register numbers
8774  
8775 B<Example:>
8776  
8777  
8778 LoadZmm 0, 0..63;
8779  
8780 PrintOutRegisterInHex zmm 0; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
8781  
8782  
8783 ok Assemble(debug => 0, eq => <<END);
8784 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
8785 END
8786  
8787  
8788 =head2 ChooseRegisters($number, @registers)
8789  
8790 Choose the specified numbers of registers excluding those on the specified list.
8791  
8792 Parameter Description
8793 1 $number Number of registers needed
8794 2 @registers Registers not to choose
8795  
8796 =head2 RegistersAvailable(@reg)
8797  
8798 Add a new set of registers that are available.
8799  
8800 Parameter Description
8801 1 @reg Registers known to be available at the moment
8802  
8803 =head2 RegistersFree()
8804  
8805 Remove the current set of registers known to be free.
8806  
8807  
8808 =head2 CheckGeneralPurposeRegister($reg)
8809  
8810 Check that a register is in fact a general purpose register.
8811  
8812 Parameter Description
8813 1 $reg Mask register to check
8814  
8815 =head2 CheckNumberedGeneralPurposeRegister($reg)
8816  
8817 Check that a register is in fact a numbered general purpose register.
8818  
8819 Parameter Description
8820 1 $reg Mask register to check
8821  
8822 =head2 InsertZeroIntoRegisterAtPoint($point, $in)
8823  
8824 Insert a zero into the specified register at the point indicated by another register.
8825  
8826 Parameter Description
8827 1 $point Register with a single 1 at the insertion point
8828 2 $in Register to be inserted into.
8829  
8830 B<Example:>
8831  
8832  
8833 Mov r15, 0x100; # Given a register with a single one in it indicating the desired position,
8834 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.
8835 Mov r13, 0xF03F;
8836 PrintOutRegisterInHex r14, r15;
8837  
8838 InsertZeroIntoRegisterAtPoint r15, r14; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
8839  
8840 PrintOutRegisterInHex r14;
8841 Or r14, r15; # Replace the inserted zero with a one
8842 PrintOutRegisterInHex r14;
8843 InsertOneIntoRegisterAtPoint r15, r13;
8844 PrintOutRegisterInHex r13;
8845 ok Assemble(debug => 0, eq => <<END);
8846 r14: 0000 0000 0000 FFDC
8847 r15: 0000 0000 0000 0100
8848 r14: 0000 0000 0001 FEDC
8849 r14: 0000 0000 0001 FFDC
8850 r13: 0000 0000 0001 E13F
8851 END
8852  
8853  
8854 =head2 InsertOneIntoRegisterAtPoint($point, $in)
8855  
8856 Insert a one into the specified register at the point indicated by another register.
8857  
8858 Parameter Description
8859 1 $point Register with a single 1 at the insertion point
8860 2 $in Register to be inserted into.
8861  
8862 B<Example:>
8863  
8864  
8865 Mov r15, 0x100; # Given a register with a single one in it indicating the desired position,
8866 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.
8867 Mov r13, 0xF03F;
8868 PrintOutRegisterInHex r14, r15;
8869 InsertZeroIntoRegisterAtPoint r15, r14;
8870 PrintOutRegisterInHex r14;
8871 Or r14, r15; # Replace the inserted zero with a one
8872 PrintOutRegisterInHex r14;
8873  
8874 InsertOneIntoRegisterAtPoint r15, r13; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
8875  
8876 PrintOutRegisterInHex r13;
8877 ok Assemble(debug => 0, eq => <<END);
8878 r14: 0000 0000 0000 FFDC
8879 r15: 0000 0000 0000 0100
8880 r14: 0000 0000 0001 FEDC
8881 r14: 0000 0000 0001 FFDC
8882 r13: 0000 0000 0001 E13F
8883 END
8884  
8885  
8886 =head2 LoadZmm($zmm, @bytes)
8887  
8888 Load a numbered zmm with the specified bytes.
8889  
8890 Parameter Description
8891 1 $zmm Numbered zmm
8892 2 @bytes Bytes
8893  
8894 B<Example:>
8895  
8896  
8897  
8898 LoadZmm 0, 0..63; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
8899  
8900 PrintOutRegisterInHex zmm 0;
8901  
8902 ok Assemble(debug => 0, eq => <<END);
8903 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
8904 END
8905  
8906  
8907 =head2 Save and Restore
8908  
8909 Saving and restoring registers via the stack
8910  
8911 =head3 SaveFirstFour(@keep)
8912  
8913 Save the first 4 parameter registers making any parameter registers read only.
8914  
8915 Parameter Description
8916 1 @keep Registers to mark as read only
8917  
8918 B<Example:>
8919  
8920  
8921 Mov rax, 1;
8922 Mov rdi, 1;
8923  
8924 SaveFirstFour; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
8925  
8926 Mov rax, 2;
8927 Mov rdi, 2;
8928 SaveFirstSeven;
8929 Mov rax, 3;
8930 Mov rdi, 4;
8931 PrintOutRegisterInHex rax, rdi;
8932 RestoreFirstSeven;
8933 PrintOutRegisterInHex rax, rdi;
8934 RestoreFirstFour;
8935 PrintOutRegisterInHex rax, rdi;
8936  
8937  
8938 SaveFirstFour; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
8939  
8940 Mov rax, 2;
8941 Mov rdi, 2;
8942 SaveFirstSeven;
8943 Mov rax, 3;
8944 Mov rdi, 4;
8945 PrintOutRegisterInHex rax, rdi;
8946 RestoreFirstSevenExceptRax;
8947 PrintOutRegisterInHex rax, rdi;
8948 RestoreFirstFourExceptRax;
8949 PrintOutRegisterInHex rax, rdi;
8950  
8951  
8952 SaveFirstFour; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
8953  
8954 Mov rax, 2;
8955 Mov rdi, 2;
8956 SaveFirstSeven;
8957 Mov rax, 3;
8958 Mov rdi, 4;
8959 PrintOutRegisterInHex rax, rdi;
8960 RestoreFirstSevenExceptRaxAndRdi;
8961 PrintOutRegisterInHex rax, rdi;
8962 RestoreFirstFourExceptRaxAndRdi;
8963 PrintOutRegisterInHex rax, rdi;
8964  
8965 Bswap rax;
8966 PrintOutRegisterInHex rax;
8967  
8968 my $l = Label;
8969 Jmp $l;
8970 SetLabel $l;
8971  
8972 ok Assemble(debug => 0, eq => <<END);
8973 rax: 0000 0000 0000 0003
8974 rdi: 0000 0000 0000 0004
8975 rax: 0000 0000 0000 0002
8976 rdi: 0000 0000 0000 0002
8977 rax: 0000 0000 0000 0001
8978 rdi: 0000 0000 0000 0001
8979 rax: 0000 0000 0000 0003
8980 rdi: 0000 0000 0000 0004
8981 rax: 0000 0000 0000 0003
8982 rdi: 0000 0000 0000 0002
8983 rax: 0000 0000 0000 0003
8984 rdi: 0000 0000 0000 0001
8985 rax: 0000 0000 0000 0003
8986 rdi: 0000 0000 0000 0004
8987 rax: 0000 0000 0000 0003
8988 rdi: 0000 0000 0000 0004
8989 rax: 0000 0000 0000 0003
8990 rdi: 0000 0000 0000 0004
8991 rax: 0300 0000 0000 0000
8992 END
8993  
8994 ok 8 == RegisterSize rax;
8995  
8996  
8997 =head3 RestoreFirstFour()
8998  
8999 Restore the first 4 parameter registers.
9000  
9001  
9002 B<Example:>
9003  
9004  
9005 Mov rax, 1;
9006 Mov rdi, 1;
9007 SaveFirstFour;
9008 Mov rax, 2;
9009 Mov rdi, 2;
9010 SaveFirstSeven;
9011 Mov rax, 3;
9012 Mov rdi, 4;
9013 PrintOutRegisterInHex rax, rdi;
9014 RestoreFirstSeven;
9015 PrintOutRegisterInHex rax, rdi;
9016  
9017 RestoreFirstFour; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9018  
9019 PrintOutRegisterInHex rax, rdi;
9020  
9021 SaveFirstFour;
9022 Mov rax, 2;
9023 Mov rdi, 2;
9024 SaveFirstSeven;
9025 Mov rax, 3;
9026 Mov rdi, 4;
9027 PrintOutRegisterInHex rax, rdi;
9028 RestoreFirstSevenExceptRax;
9029 PrintOutRegisterInHex rax, rdi;
9030 RestoreFirstFourExceptRax;
9031 PrintOutRegisterInHex rax, rdi;
9032  
9033 SaveFirstFour;
9034 Mov rax, 2;
9035 Mov rdi, 2;
9036 SaveFirstSeven;
9037 Mov rax, 3;
9038 Mov rdi, 4;
9039 PrintOutRegisterInHex rax, rdi;
9040 RestoreFirstSevenExceptRaxAndRdi;
9041 PrintOutRegisterInHex rax, rdi;
9042 RestoreFirstFourExceptRaxAndRdi;
9043 PrintOutRegisterInHex rax, rdi;
9044  
9045 Bswap rax;
9046 PrintOutRegisterInHex rax;
9047  
9048 my $l = Label;
9049 Jmp $l;
9050 SetLabel $l;
9051  
9052 ok Assemble(debug => 0, eq => <<END);
9053 rax: 0000 0000 0000 0003
9054 rdi: 0000 0000 0000 0004
9055 rax: 0000 0000 0000 0002
9056 rdi: 0000 0000 0000 0002
9057 rax: 0000 0000 0000 0001
9058 rdi: 0000 0000 0000 0001
9059 rax: 0000 0000 0000 0003
9060 rdi: 0000 0000 0000 0004
9061 rax: 0000 0000 0000 0003
9062 rdi: 0000 0000 0000 0002
9063 rax: 0000 0000 0000 0003
9064 rdi: 0000 0000 0000 0001
9065 rax: 0000 0000 0000 0003
9066 rdi: 0000 0000 0000 0004
9067 rax: 0000 0000 0000 0003
9068 rdi: 0000 0000 0000 0004
9069 rax: 0000 0000 0000 0003
9070 rdi: 0000 0000 0000 0004
9071 rax: 0300 0000 0000 0000
9072 END
9073  
9074 ok 8 == RegisterSize rax;
9075  
9076  
9077 =head3 RestoreFirstFourExceptRax()
9078  
9079 Restore the first 4 parameter registers except rax so it can return its value.
9080  
9081  
9082 B<Example:>
9083  
9084  
9085 Mov rax, 1;
9086 Mov rdi, 1;
9087 SaveFirstFour;
9088 Mov rax, 2;
9089 Mov rdi, 2;
9090 SaveFirstSeven;
9091 Mov rax, 3;
9092 Mov rdi, 4;
9093 PrintOutRegisterInHex rax, rdi;
9094 RestoreFirstSeven;
9095 PrintOutRegisterInHex rax, rdi;
9096 RestoreFirstFour;
9097 PrintOutRegisterInHex rax, rdi;
9098  
9099 SaveFirstFour;
9100 Mov rax, 2;
9101 Mov rdi, 2;
9102 SaveFirstSeven;
9103 Mov rax, 3;
9104 Mov rdi, 4;
9105 PrintOutRegisterInHex rax, rdi;
9106 RestoreFirstSevenExceptRax;
9107 PrintOutRegisterInHex rax, rdi;
9108  
9109 RestoreFirstFourExceptRax; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9110  
9111 PrintOutRegisterInHex rax, rdi;
9112  
9113 SaveFirstFour;
9114 Mov rax, 2;
9115 Mov rdi, 2;
9116 SaveFirstSeven;
9117 Mov rax, 3;
9118 Mov rdi, 4;
9119 PrintOutRegisterInHex rax, rdi;
9120 RestoreFirstSevenExceptRaxAndRdi;
9121 PrintOutRegisterInHex rax, rdi;
9122 RestoreFirstFourExceptRaxAndRdi;
9123 PrintOutRegisterInHex rax, rdi;
9124  
9125 Bswap rax;
9126 PrintOutRegisterInHex rax;
9127  
9128 my $l = Label;
9129 Jmp $l;
9130 SetLabel $l;
9131  
9132 ok Assemble(debug => 0, eq => <<END);
9133 rax: 0000 0000 0000 0003
9134 rdi: 0000 0000 0000 0004
9135 rax: 0000 0000 0000 0002
9136 rdi: 0000 0000 0000 0002
9137 rax: 0000 0000 0000 0001
9138 rdi: 0000 0000 0000 0001
9139 rax: 0000 0000 0000 0003
9140 rdi: 0000 0000 0000 0004
9141 rax: 0000 0000 0000 0003
9142 rdi: 0000 0000 0000 0002
9143 rax: 0000 0000 0000 0003
9144 rdi: 0000 0000 0000 0001
9145 rax: 0000 0000 0000 0003
9146 rdi: 0000 0000 0000 0004
9147 rax: 0000 0000 0000 0003
9148 rdi: 0000 0000 0000 0004
9149 rax: 0000 0000 0000 0003
9150 rdi: 0000 0000 0000 0004
9151 rax: 0300 0000 0000 0000
9152 END
9153  
9154 ok 8 == RegisterSize rax;
9155  
9156  
9157 =head3 RestoreFirstFourExceptRaxAndRdi()
9158  
9159 Restore the first 4 parameter registers except rax and rdi so we can return a pair of values.
9160  
9161  
9162 B<Example:>
9163  
9164  
9165 Mov rax, 1;
9166 Mov rdi, 1;
9167 SaveFirstFour;
9168 Mov rax, 2;
9169 Mov rdi, 2;
9170 SaveFirstSeven;
9171 Mov rax, 3;
9172 Mov rdi, 4;
9173 PrintOutRegisterInHex rax, rdi;
9174 RestoreFirstSeven;
9175 PrintOutRegisterInHex rax, rdi;
9176 RestoreFirstFour;
9177 PrintOutRegisterInHex rax, rdi;
9178  
9179 SaveFirstFour;
9180 Mov rax, 2;
9181 Mov rdi, 2;
9182 SaveFirstSeven;
9183 Mov rax, 3;
9184 Mov rdi, 4;
9185 PrintOutRegisterInHex rax, rdi;
9186 RestoreFirstSevenExceptRax;
9187 PrintOutRegisterInHex rax, rdi;
9188 RestoreFirstFourExceptRax;
9189 PrintOutRegisterInHex rax, rdi;
9190  
9191 SaveFirstFour;
9192 Mov rax, 2;
9193 Mov rdi, 2;
9194 SaveFirstSeven;
9195 Mov rax, 3;
9196 Mov rdi, 4;
9197 PrintOutRegisterInHex rax, rdi;
9198 RestoreFirstSevenExceptRaxAndRdi;
9199 PrintOutRegisterInHex rax, rdi;
9200  
9201 RestoreFirstFourExceptRaxAndRdi; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9202  
9203 PrintOutRegisterInHex rax, rdi;
9204  
9205 Bswap rax;
9206 PrintOutRegisterInHex rax;
9207  
9208 my $l = Label;
9209 Jmp $l;
9210 SetLabel $l;
9211  
9212 ok Assemble(debug => 0, eq => <<END);
9213 rax: 0000 0000 0000 0003
9214 rdi: 0000 0000 0000 0004
9215 rax: 0000 0000 0000 0002
9216 rdi: 0000 0000 0000 0002
9217 rax: 0000 0000 0000 0001
9218 rdi: 0000 0000 0000 0001
9219 rax: 0000 0000 0000 0003
9220 rdi: 0000 0000 0000 0004
9221 rax: 0000 0000 0000 0003
9222 rdi: 0000 0000 0000 0002
9223 rax: 0000 0000 0000 0003
9224 rdi: 0000 0000 0000 0001
9225 rax: 0000 0000 0000 0003
9226 rdi: 0000 0000 0000 0004
9227 rax: 0000 0000 0000 0003
9228 rdi: 0000 0000 0000 0004
9229 rax: 0000 0000 0000 0003
9230 rdi: 0000 0000 0000 0004
9231 rax: 0300 0000 0000 0000
9232 END
9233  
9234 ok 8 == RegisterSize rax;
9235  
9236  
9237 =head3 SaveFirstSeven()
9238  
9239 Save the first 7 parameter registers.
9240  
9241  
9242 B<Example:>
9243  
9244  
9245 Mov rax, 1;
9246 Mov rdi, 1;
9247 SaveFirstFour;
9248 Mov rax, 2;
9249 Mov rdi, 2;
9250  
9251 SaveFirstSeven; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9252  
9253 Mov rax, 3;
9254 Mov rdi, 4;
9255 PrintOutRegisterInHex rax, rdi;
9256 RestoreFirstSeven;
9257 PrintOutRegisterInHex rax, rdi;
9258 RestoreFirstFour;
9259 PrintOutRegisterInHex rax, rdi;
9260  
9261 SaveFirstFour;
9262 Mov rax, 2;
9263 Mov rdi, 2;
9264  
9265 SaveFirstSeven; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9266  
9267 Mov rax, 3;
9268 Mov rdi, 4;
9269 PrintOutRegisterInHex rax, rdi;
9270 RestoreFirstSevenExceptRax;
9271 PrintOutRegisterInHex rax, rdi;
9272 RestoreFirstFourExceptRax;
9273 PrintOutRegisterInHex rax, rdi;
9274  
9275 SaveFirstFour;
9276 Mov rax, 2;
9277 Mov rdi, 2;
9278  
9279 SaveFirstSeven; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9280  
9281 Mov rax, 3;
9282 Mov rdi, 4;
9283 PrintOutRegisterInHex rax, rdi;
9284 RestoreFirstSevenExceptRaxAndRdi;
9285 PrintOutRegisterInHex rax, rdi;
9286 RestoreFirstFourExceptRaxAndRdi;
9287 PrintOutRegisterInHex rax, rdi;
9288  
9289 Bswap rax;
9290 PrintOutRegisterInHex rax;
9291  
9292 my $l = Label;
9293 Jmp $l;
9294 SetLabel $l;
9295  
9296 ok Assemble(debug => 0, eq => <<END);
9297 rax: 0000 0000 0000 0003
9298 rdi: 0000 0000 0000 0004
9299 rax: 0000 0000 0000 0002
9300 rdi: 0000 0000 0000 0002
9301 rax: 0000 0000 0000 0001
9302 rdi: 0000 0000 0000 0001
9303 rax: 0000 0000 0000 0003
9304 rdi: 0000 0000 0000 0004
9305 rax: 0000 0000 0000 0003
9306 rdi: 0000 0000 0000 0002
9307 rax: 0000 0000 0000 0003
9308 rdi: 0000 0000 0000 0001
9309 rax: 0000 0000 0000 0003
9310 rdi: 0000 0000 0000 0004
9311 rax: 0000 0000 0000 0003
9312 rdi: 0000 0000 0000 0004
9313 rax: 0000 0000 0000 0003
9314 rdi: 0000 0000 0000 0004
9315 rax: 0300 0000 0000 0000
9316 END
9317  
9318 ok 8 == RegisterSize rax;
9319  
9320  
9321 =head3 RestoreFirstSeven()
9322  
9323 Restore the first 7 parameter registers.
9324  
9325  
9326 B<Example:>
9327  
9328  
9329 Mov rax, 1;
9330 Mov rdi, 1;
9331 SaveFirstFour;
9332 Mov rax, 2;
9333 Mov rdi, 2;
9334 SaveFirstSeven;
9335 Mov rax, 3;
9336 Mov rdi, 4;
9337 PrintOutRegisterInHex rax, rdi;
9338  
9339 RestoreFirstSeven; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9340  
9341 PrintOutRegisterInHex rax, rdi;
9342 RestoreFirstFour;
9343 PrintOutRegisterInHex rax, rdi;
9344  
9345 SaveFirstFour;
9346 Mov rax, 2;
9347 Mov rdi, 2;
9348 SaveFirstSeven;
9349 Mov rax, 3;
9350 Mov rdi, 4;
9351 PrintOutRegisterInHex rax, rdi;
9352 RestoreFirstSevenExceptRax;
9353 PrintOutRegisterInHex rax, rdi;
9354 RestoreFirstFourExceptRax;
9355 PrintOutRegisterInHex rax, rdi;
9356  
9357 SaveFirstFour;
9358 Mov rax, 2;
9359 Mov rdi, 2;
9360 SaveFirstSeven;
9361 Mov rax, 3;
9362 Mov rdi, 4;
9363 PrintOutRegisterInHex rax, rdi;
9364 RestoreFirstSevenExceptRaxAndRdi;
9365 PrintOutRegisterInHex rax, rdi;
9366 RestoreFirstFourExceptRaxAndRdi;
9367 PrintOutRegisterInHex rax, rdi;
9368  
9369 Bswap rax;
9370 PrintOutRegisterInHex rax;
9371  
9372 my $l = Label;
9373 Jmp $l;
9374 SetLabel $l;
9375  
9376 ok Assemble(debug => 0, eq => <<END);
9377 rax: 0000 0000 0000 0003
9378 rdi: 0000 0000 0000 0004
9379 rax: 0000 0000 0000 0002
9380 rdi: 0000 0000 0000 0002
9381 rax: 0000 0000 0000 0001
9382 rdi: 0000 0000 0000 0001
9383 rax: 0000 0000 0000 0003
9384 rdi: 0000 0000 0000 0004
9385 rax: 0000 0000 0000 0003
9386 rdi: 0000 0000 0000 0002
9387 rax: 0000 0000 0000 0003
9388 rdi: 0000 0000 0000 0001
9389 rax: 0000 0000 0000 0003
9390 rdi: 0000 0000 0000 0004
9391 rax: 0000 0000 0000 0003
9392 rdi: 0000 0000 0000 0004
9393 rax: 0000 0000 0000 0003
9394 rdi: 0000 0000 0000 0004
9395 rax: 0300 0000 0000 0000
9396 END
9397  
9398 ok 8 == RegisterSize rax;
9399  
9400  
9401 =head3 RestoreFirstSevenExceptRax()
9402  
9403 Restore the first 7 parameter registers except rax which is being used to return the result.
9404  
9405  
9406 B<Example:>
9407  
9408  
9409 Mov rax, 1;
9410 Mov rdi, 1;
9411 SaveFirstFour;
9412 Mov rax, 2;
9413 Mov rdi, 2;
9414 SaveFirstSeven;
9415 Mov rax, 3;
9416 Mov rdi, 4;
9417 PrintOutRegisterInHex rax, rdi;
9418 RestoreFirstSeven;
9419 PrintOutRegisterInHex rax, rdi;
9420 RestoreFirstFour;
9421 PrintOutRegisterInHex rax, rdi;
9422  
9423 SaveFirstFour;
9424 Mov rax, 2;
9425 Mov rdi, 2;
9426 SaveFirstSeven;
9427 Mov rax, 3;
9428 Mov rdi, 4;
9429 PrintOutRegisterInHex rax, rdi;
9430  
9431 RestoreFirstSevenExceptRax; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9432  
9433 PrintOutRegisterInHex rax, rdi;
9434 RestoreFirstFourExceptRax;
9435 PrintOutRegisterInHex rax, rdi;
9436  
9437 SaveFirstFour;
9438 Mov rax, 2;
9439 Mov rdi, 2;
9440 SaveFirstSeven;
9441 Mov rax, 3;
9442 Mov rdi, 4;
9443 PrintOutRegisterInHex rax, rdi;
9444 RestoreFirstSevenExceptRaxAndRdi;
9445 PrintOutRegisterInHex rax, rdi;
9446 RestoreFirstFourExceptRaxAndRdi;
9447 PrintOutRegisterInHex rax, rdi;
9448  
9449 Bswap rax;
9450 PrintOutRegisterInHex rax;
9451  
9452 my $l = Label;
9453 Jmp $l;
9454 SetLabel $l;
9455  
9456 ok Assemble(debug => 0, eq => <<END);
9457 rax: 0000 0000 0000 0003
9458 rdi: 0000 0000 0000 0004
9459 rax: 0000 0000 0000 0002
9460 rdi: 0000 0000 0000 0002
9461 rax: 0000 0000 0000 0001
9462 rdi: 0000 0000 0000 0001
9463 rax: 0000 0000 0000 0003
9464 rdi: 0000 0000 0000 0004
9465 rax: 0000 0000 0000 0003
9466 rdi: 0000 0000 0000 0002
9467 rax: 0000 0000 0000 0003
9468 rdi: 0000 0000 0000 0001
9469 rax: 0000 0000 0000 0003
9470 rdi: 0000 0000 0000 0004
9471 rax: 0000 0000 0000 0003
9472 rdi: 0000 0000 0000 0004
9473 rax: 0000 0000 0000 0003
9474 rdi: 0000 0000 0000 0004
9475 rax: 0300 0000 0000 0000
9476 END
9477  
9478 ok 8 == RegisterSize rax;
9479  
9480  
9481 =head3 RestoreFirstSevenExceptRaxAndRdi()
9482  
9483 Restore the first 7 parameter registers except rax and rdi which are being used to return the results.
9484  
9485  
9486 B<Example:>
9487  
9488  
9489 Mov rax, 1;
9490 Mov rdi, 1;
9491 SaveFirstFour;
9492 Mov rax, 2;
9493 Mov rdi, 2;
9494 SaveFirstSeven;
9495 Mov rax, 3;
9496 Mov rdi, 4;
9497 PrintOutRegisterInHex rax, rdi;
9498 RestoreFirstSeven;
9499 PrintOutRegisterInHex rax, rdi;
9500 RestoreFirstFour;
9501 PrintOutRegisterInHex rax, rdi;
9502  
9503 SaveFirstFour;
9504 Mov rax, 2;
9505 Mov rdi, 2;
9506 SaveFirstSeven;
9507 Mov rax, 3;
9508 Mov rdi, 4;
9509 PrintOutRegisterInHex rax, rdi;
9510 RestoreFirstSevenExceptRax;
9511 PrintOutRegisterInHex rax, rdi;
9512 RestoreFirstFourExceptRax;
9513 PrintOutRegisterInHex rax, rdi;
9514  
9515 SaveFirstFour;
9516 Mov rax, 2;
9517 Mov rdi, 2;
9518 SaveFirstSeven;
9519 Mov rax, 3;
9520 Mov rdi, 4;
9521 PrintOutRegisterInHex rax, rdi;
9522  
9523 RestoreFirstSevenExceptRaxAndRdi; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9524  
9525 PrintOutRegisterInHex rax, rdi;
9526 RestoreFirstFourExceptRaxAndRdi;
9527 PrintOutRegisterInHex rax, rdi;
9528  
9529 Bswap rax;
9530 PrintOutRegisterInHex rax;
9531  
9532 my $l = Label;
9533 Jmp $l;
9534 SetLabel $l;
9535  
9536 ok Assemble(debug => 0, eq => <<END);
9537 rax: 0000 0000 0000 0003
9538 rdi: 0000 0000 0000 0004
9539 rax: 0000 0000 0000 0002
9540 rdi: 0000 0000 0000 0002
9541 rax: 0000 0000 0000 0001
9542 rdi: 0000 0000 0000 0001
9543 rax: 0000 0000 0000 0003
9544 rdi: 0000 0000 0000 0004
9545 rax: 0000 0000 0000 0003
9546 rdi: 0000 0000 0000 0002
9547 rax: 0000 0000 0000 0003
9548 rdi: 0000 0000 0000 0001
9549 rax: 0000 0000 0000 0003
9550 rdi: 0000 0000 0000 0004
9551 rax: 0000 0000 0000 0003
9552 rdi: 0000 0000 0000 0004
9553 rax: 0000 0000 0000 0003
9554 rdi: 0000 0000 0000 0004
9555 rax: 0300 0000 0000 0000
9556 END
9557  
9558 ok 8 == RegisterSize rax;
9559  
9560  
9561 =head3 ReorderSyscallRegisters(@registers)
9562  
9563 Map the list of registers provided to the 64 bit system call sequence.
9564  
9565 Parameter Description
9566 1 @registers Registers
9567  
9568 B<Example:>
9569  
9570  
9571 Mov rax, 1; Mov rdi, 2; Mov rsi, 3; Mov rdx, 4;
9572 Mov r8, 8; Mov r9, 9; Mov r10, 10; Mov r11, 11;
9573  
9574  
9575 ReorderSyscallRegisters r8,r9; # Reorder the registers for syscall # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9576  
9577 PrintOutRegisterInHex rax;
9578 PrintOutRegisterInHex rdi;
9579  
9580 UnReorderSyscallRegisters r8,r9; # Unreorder the registers to recover their original values
9581 PrintOutRegisterInHex rax;
9582 PrintOutRegisterInHex rdi;
9583  
9584 ok Assemble =~ m(rax:.*08.*rdi:.*9.*rax:.*1.*rdi:.*2.*)s;
9585  
9586  
9587 =head3 UnReorderSyscallRegisters(@registers)
9588  
9589 Recover the initial values in registers that were reordered.
9590  
9591 Parameter Description
9592 1 @registers Registers
9593  
9594 B<Example:>
9595  
9596  
9597 Mov rax, 1; Mov rdi, 2; Mov rsi, 3; Mov rdx, 4;
9598 Mov r8, 8; Mov r9, 9; Mov r10, 10; Mov r11, 11;
9599  
9600 ReorderSyscallRegisters r8,r9; # Reorder the registers for syscall
9601 PrintOutRegisterInHex rax;
9602 PrintOutRegisterInHex rdi;
9603  
9604  
9605 UnReorderSyscallRegisters r8,r9; # Unreorder the registers to recover their original values # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9606  
9607 PrintOutRegisterInHex rax;
9608 PrintOutRegisterInHex rdi;
9609  
9610 ok Assemble =~ m(rax:.*08.*rdi:.*9.*rax:.*1.*rdi:.*2.*)s;
9611  
9612  
9613 =head3 RegisterSize($r)
9614  
9615 Return the size of a register.
9616  
9617 Parameter Description
9618 1 $r Register
9619  
9620 B<Example:>
9621  
9622  
9623 Mov rax, 1;
9624 Mov rdi, 1;
9625 SaveFirstFour;
9626 Mov rax, 2;
9627 Mov rdi, 2;
9628 SaveFirstSeven;
9629 Mov rax, 3;
9630 Mov rdi, 4;
9631 PrintOutRegisterInHex rax, rdi;
9632 RestoreFirstSeven;
9633 PrintOutRegisterInHex rax, rdi;
9634 RestoreFirstFour;
9635 PrintOutRegisterInHex rax, rdi;
9636  
9637 SaveFirstFour;
9638 Mov rax, 2;
9639 Mov rdi, 2;
9640 SaveFirstSeven;
9641 Mov rax, 3;
9642 Mov rdi, 4;
9643 PrintOutRegisterInHex rax, rdi;
9644 RestoreFirstSevenExceptRax;
9645 PrintOutRegisterInHex rax, rdi;
9646 RestoreFirstFourExceptRax;
9647 PrintOutRegisterInHex rax, rdi;
9648  
9649 SaveFirstFour;
9650 Mov rax, 2;
9651 Mov rdi, 2;
9652 SaveFirstSeven;
9653 Mov rax, 3;
9654 Mov rdi, 4;
9655 PrintOutRegisterInHex rax, rdi;
9656 RestoreFirstSevenExceptRaxAndRdi;
9657 PrintOutRegisterInHex rax, rdi;
9658 RestoreFirstFourExceptRaxAndRdi;
9659 PrintOutRegisterInHex rax, rdi;
9660  
9661 Bswap rax;
9662 PrintOutRegisterInHex rax;
9663  
9664 my $l = Label;
9665 Jmp $l;
9666 SetLabel $l;
9667  
9668 ok Assemble(debug => 0, eq => <<END);
9669 rax: 0000 0000 0000 0003
9670 rdi: 0000 0000 0000 0004
9671 rax: 0000 0000 0000 0002
9672 rdi: 0000 0000 0000 0002
9673 rax: 0000 0000 0000 0001
9674 rdi: 0000 0000 0000 0001
9675 rax: 0000 0000 0000 0003
9676 rdi: 0000 0000 0000 0004
9677 rax: 0000 0000 0000 0003
9678 rdi: 0000 0000 0000 0002
9679 rax: 0000 0000 0000 0003
9680 rdi: 0000 0000 0000 0001
9681 rax: 0000 0000 0000 0003
9682 rdi: 0000 0000 0000 0004
9683 rax: 0000 0000 0000 0003
9684 rdi: 0000 0000 0000 0004
9685 rax: 0000 0000 0000 0003
9686 rdi: 0000 0000 0000 0004
9687 rax: 0300 0000 0000 0000
9688 END
9689  
9690  
9691 ok 8 == RegisterSize rax; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9692  
9693  
9694  
9695 =head3 ClearRegisters(@registers)
9696  
9697 Clear registers by setting them to zero.
9698  
9699 Parameter Description
9700 1 @registers Registers
9701  
9702 B<Example:>
9703  
9704  
9705 Mov rax,1;
9706 Kmovq k0, rax;
9707 Kaddb k0, k0, k0;
9708 Kaddb k0, k0, k0;
9709 Kaddb k0, k0, k0;
9710 Kmovq rax, k0;
9711 PushR k0;
9712  
9713 ClearRegisters k0; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9714  
9715 Kmovq k1, k0;
9716 PopR k0;
9717 PrintOutRegisterInHex k0;
9718 PrintOutRegisterInHex k1;
9719  
9720 ok Assemble =~ m(k0: 0000 0000 0000 0008.*k1: 0000 0000 0000 0000)s;
9721  
9722  
9723 =head3 SetMaskRegister($mask, $start, $length)
9724  
9725 Set the mask register to ones starting at the specified position for the specified length and zeroes elsewhere.
9726  
9727 Parameter Description
9728 1 $mask Mask register to set
9729 2 $start Register containing start position or 0 for position 0
9730 3 $length Register containing end position
9731  
9732 B<Example:>
9733  
9734  
9735 Mov rax, 8;
9736 Mov rsi, -1;
9737  
9738 Inc rsi; SetMaskRegister(k0, rax, rsi); PrintOutRegisterInHex k0; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9739  
9740  
9741 Inc rsi; SetMaskRegister(k1, rax, rsi); PrintOutRegisterInHex k1; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9742  
9743  
9744 Inc rsi; SetMaskRegister(k2, rax, rsi); PrintOutRegisterInHex k2; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9745  
9746  
9747 Inc rsi; SetMaskRegister(k3, rax, rsi); PrintOutRegisterInHex k3; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9748  
9749  
9750 Inc rsi; SetMaskRegister(k4, rax, rsi); PrintOutRegisterInHex k4; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9751  
9752  
9753 Inc rsi; SetMaskRegister(k5, rax, rsi); PrintOutRegisterInHex k5; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9754  
9755  
9756 Inc rsi; SetMaskRegister(k6, rax, rsi); PrintOutRegisterInHex k6; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9757  
9758  
9759 Inc rsi; SetMaskRegister(k7, rax, rsi); PrintOutRegisterInHex k7; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9760  
9761  
9762 ok Assemble(debug => 0, eq => <<END);
9763 k0: 0000 0000 0000 0000
9764 k1: 0000 0000 0000 0100
9765 k2: 0000 0000 0000 0300
9766 k3: 0000 0000 0000 0700
9767 k4: 0000 0000 0000 0F00
9768 k5: 0000 0000 0000 1F00
9769 k6: 0000 0000 0000 3F00
9770 k7: 0000 0000 0000 7F00
9771 END
9772  
9773  
9774 =head3 SetZF()
9775  
9776 Set the zero flag.
9777  
9778  
9779 B<Example:>
9780  
9781  
9782  
9783 SetZF; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9784  
9785 PrintOutZF;
9786 ClearZF;
9787 PrintOutZF;
9788  
9789 SetZF; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9790  
9791 PrintOutZF;
9792  
9793 SetZF; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9794  
9795 PrintOutZF;
9796 ClearZF;
9797 PrintOutZF;
9798  
9799  
9800 SetZF; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9801  
9802 IfZ Then {PrintOutStringNL "Zero"}, Else {PrintOutStringNL "NOT zero"};
9803 ClearZF;
9804 IfNz Then {PrintOutStringNL "NOT zero"}, Else {PrintOutStringNL "Zero"};
9805  
9806 Mov r15, 5;
9807 Shr r15, 1; IfC Then {PrintOutStringNL "Carry"} , Else {PrintOutStringNL "NO carry"};
9808 Shr r15, 1; IfC Then {PrintOutStringNL "Carry"} , Else {PrintOutStringNL "NO carry"};
9809 Shr r15, 1; IfNc Then {PrintOutStringNL "NO carry"}, Else {PrintOutStringNL "Carry"};
9810 Shr r15, 1; IfNc Then {PrintOutStringNL "NO carry"}, Else {PrintOutStringNL "Carry"};
9811  
9812 ok Assemble(debug => 0, eq => <<END);
9813 ZF=1
9814 ZF=0
9815 ZF=1
9816 ZF=1
9817 ZF=0
9818 Zero
9819 NOT zero
9820 Carry
9821 NO carry
9822 Carry
9823 NO carry
9824 END
9825  
9826  
9827 =head3 ClearZF()
9828  
9829 Clear the zero flag.
9830  
9831  
9832 B<Example:>
9833  
9834  
9835 SetZF;
9836 PrintOutZF;
9837  
9838 ClearZF; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9839  
9840 PrintOutZF;
9841 SetZF;
9842 PrintOutZF;
9843 SetZF;
9844 PrintOutZF;
9845  
9846 ClearZF; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9847  
9848 PrintOutZF;
9849  
9850 SetZF;
9851 IfZ Then {PrintOutStringNL "Zero"}, Else {PrintOutStringNL "NOT zero"};
9852  
9853 ClearZF; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9854  
9855 IfNz Then {PrintOutStringNL "NOT zero"}, Else {PrintOutStringNL "Zero"};
9856  
9857 Mov r15, 5;
9858 Shr r15, 1; IfC Then {PrintOutStringNL "Carry"} , Else {PrintOutStringNL "NO carry"};
9859 Shr r15, 1; IfC Then {PrintOutStringNL "Carry"} , Else {PrintOutStringNL "NO carry"};
9860 Shr r15, 1; IfNc Then {PrintOutStringNL "NO carry"}, Else {PrintOutStringNL "Carry"};
9861 Shr r15, 1; IfNc Then {PrintOutStringNL "NO carry"}, Else {PrintOutStringNL "Carry"};
9862  
9863 ok Assemble(debug => 0, eq => <<END);
9864 ZF=1
9865 ZF=0
9866 ZF=1
9867 ZF=1
9868 ZF=0
9869 Zero
9870 NOT zero
9871 Carry
9872 NO carry
9873 Carry
9874 NO carry
9875 END
9876  
9877  
9878 =head2 Mask
9879  
9880 Operations on mask registers
9881  
9882 =head3 CheckMaskRegister($mask)
9883  
9884 Check that a register is in fact a mask register.
9885  
9886 Parameter Description
9887 1 $mask Mask register to check
9888  
9889 =head3 LoadConstantIntoMaskRegister($mask, $transfer, $value)
9890  
9891 Set a mask register equal to a constant.
9892  
9893 Parameter Description
9894 1 $mask Mask register to load
9895 2 $transfer Transfer register
9896 3 $value Constant to load
9897  
9898 B<Example:>
9899  
9900  
9901 Mov r14, 0;
9902 Kmovq k0, r14;
9903 Ktestq k0, k0;
9904 IfZ Then {PrintOutStringNL "0 & 0 == 0"};
9905 PrintOutZF;
9906  
9907  
9908 LoadConstantIntoMaskRegister k1, r13, 1; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9909  
9910 Ktestq k1, k1;
9911 IfNz Then {PrintOutStringNL "1 & 1 != 0"};
9912 PrintOutZF;
9913  
9914  
9915 LoadConstantIntoMaskRegister k2, r13, eval "0b".(('1'x4).('0'x4))x2; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9916  
9917  
9918 PrintOutRegisterInHex k0, k1, k2;
9919  
9920 Mov r15, 0x89abcdef;
9921 Mov r14, 0x01234567;
9922 Shl r14, 32;
9923 Or r15, r14;
9924 Push r15;
9925 Push r15;
9926 PopEax; PrintRaxInHex($stdout, 3); PrintOutNL;
9927  
9928 my $a = V('aaaa');
9929 $a->pop;
9930 $a->push;
9931 $a->outNL;
9932  
9933 PopEax; PrintRaxInHex($stdout, 3); PrintOutNL;
9934  
9935 ok Assemble(debug => 0, eq => <<END);
9936 0 & 0 == 0
9937 ZF=1
9938 1 & 1 != 0
9939 ZF=0
9940 k0: 0000 0000 0000 0000
9941 k1: 0000 0000 0000 0001
9942 k2: 0000 0000 0000 F0F0
9943 89AB CDEF
9944 aaaa: 89AB CDEF 0123 4567
9945 0123 4567
9946 END
9947  
9948  
9949 =head3 LoadBitsIntoMaskRegister($mask, $transfer, $prefix, @values)
9950  
9951 Load a bit string specification into a mask register.
9952  
9953 Parameter Description
9954 1 $mask Mask register to load
9955 2 $transfer Transfer register
9956 3 $prefix Prefix bits
9957 4 @values +n 1 bits -n 0 bits
9958  
9959 B<Example:>
9960  
9961  
9962 for (0..7)
9963 {ClearRegisters "k$_";
9964 K($_,$_)->setMaskBit("k$_");
9965 PrintOutRegisterInHex "k$_";
9966 }
9967  
9968 ClearRegisters k7;
9969  
9970 LoadBitsIntoMaskRegister(k7, r15, '1010', -4, +4, -2, +2, -1, +1, -1, +1); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
9971  
9972 PrintOutRegisterInHex "k7";
9973  
9974 ok Assemble(debug => 0, eq => <<END);
9975 k0: 0000 0000 0000 0001
9976 k1: 0000 0000 0000 0002
9977 k2: 0000 0000 0000 0004
9978 k3: 0000 0000 0000 0008
9979 k4: 0000 0000 0000 0010
9980 k5: 0000 0000 0000 0020
9981 k6: 0000 0000 0000 0040
9982 k7: 0000 0000 0000 0080
9983 k7: 0000 0000 000A 0F35
9984 END
9985  
9986  
9987 =head1 Structured Programming
9988  
9989 Structured programming constructs
9990  
9991 =head2 If($jump, $then, $else)
9992  
9993 If.
9994  
9995 Parameter Description
9996 1 $jump Jump op code of variable
9997 2 $then Then - required
9998 3 $else Else - optional
9999  
10000 B<Example:>
10001  
10002  
10003 my $c = K(one,1);
10004  
10005 If ($c == 0, # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10006  
10007 Then
10008 {PrintOutStringNL "1 == 0";
10009 },
10010 Else
10011 {PrintOutStringNL "1 != 0";
10012 });
10013  
10014 ok Assemble(debug => 0, eq => <<END);
10015 1 != 0
10016 END
10017  
10018  
10019 =head2 Then($block)
10020  
10021 Then block for an If statement.
10022  
10023 Parameter Description
10024 1 $block Then block
10025  
10026 B<Example:>
10027  
10028  
10029 my $a = V(a, 3); $a->outNL;
10030 my $b = K(b, 2); $b->outNL;
10031 my $c = $a + $b; $c->outNL;
10032 my $d = $c - $a; $d->outNL;
10033 my $g = $a * $b; $g->outNL;
10034 my $h = $g / $b; $h->outNL;
10035 my $i = $a % $b; $i->outNL;
10036  
10037 If ($a == 3,
10038  
10039 Then # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10040  
10041 {PrintOutStringNL "a == 3"
10042 },
10043 Else
10044 {PrintOutStringNL "a != 3"
10045 });
10046  
10047 ++$a; $a->outNL;
10048 --$a; $a->outNL;
10049  
10050 ok Assemble(debug => 0, eq => <<END);
10051 a: 0000 0000 0000 0003
10052 b: 0000 0000 0000 0002
10053 (a add b): 0000 0000 0000 0005
10054 ((a add b) sub a): 0000 0000 0000 0002
10055 (a times b): 0000 0000 0000 0006
10056 ((a times b) / b): 0000 0000 0000 0003
10057 (a % b): 0000 0000 0000 0001
10058 a == 3
10059 a: 0000 0000 0000 0004
10060 a: 0000 0000 0000 0003
10061 END
10062  
10063  
10064 =head2 Else($block)
10065  
10066 Else block for an If statement.
10067  
10068 Parameter Description
10069 1 $block Else block
10070  
10071 B<Example:>
10072  
10073  
10074 my $a = V(a, 3); $a->outNL;
10075 my $b = K(b, 2); $b->outNL;
10076 my $c = $a + $b; $c->outNL;
10077 my $d = $c - $a; $d->outNL;
10078 my $g = $a * $b; $g->outNL;
10079 my $h = $g / $b; $h->outNL;
10080 my $i = $a % $b; $i->outNL;
10081  
10082 If ($a == 3,
10083 Then
10084 {PrintOutStringNL "a == 3"
10085 },
10086  
10087 Else # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10088  
10089 {PrintOutStringNL "a != 3"
10090 });
10091  
10092 ++$a; $a->outNL;
10093 --$a; $a->outNL;
10094  
10095 ok Assemble(debug => 0, eq => <<END);
10096 a: 0000 0000 0000 0003
10097 b: 0000 0000 0000 0002
10098 (a add b): 0000 0000 0000 0005
10099 ((a add b) sub a): 0000 0000 0000 0002
10100 (a times b): 0000 0000 0000 0006
10101 ((a times b) / b): 0000 0000 0000 0003
10102 (a % b): 0000 0000 0000 0001
10103 a == 3
10104 a: 0000 0000 0000 0004
10105 a: 0000 0000 0000 0003
10106 END
10107  
10108  
10109 =head2 Ef($condition, $then, $else)
10110  
10111 Else if block for an If statement.
10112  
10113 Parameter Description
10114 1 $condition Condition
10115 2 $then Then block
10116 3 $else Else block
10117  
10118 =head2 IfEq($then, $else)
10119  
10120 If equal execute the then block else the else block.
10121  
10122 Parameter Description
10123 1 $then Then - required
10124 2 $else Else - optional
10125  
10126 B<Example:>
10127  
10128  
10129 my $cmp = sub
10130 {my ($a, $b) = @_;
10131  
10132 for my $op(qw(eq ne lt le gt ge))
10133 {Mov rax, $a;
10134 Cmp rax, $b;
10135 my $Op = ucfirst $op;
10136 eval qq(If$Op Then {PrintOutStringNL("$a $op $b")}, Else {PrintOutStringNL("$a NOT $op $b")});
10137 $@ and confess $@;
10138 }
10139 };
10140 &$cmp(1,1);
10141 &$cmp(1,2);
10142 &$cmp(3,2);
10143 Assemble(debug => 0, eq => <<END);
10144 1 eq 1
10145 1 NOT ne 1
10146 1 NOT lt 1
10147 1 le 1
10148 1 NOT gt 1
10149 1 ge 1
10150 1 NOT eq 2
10151 1 ne 2
10152 1 lt 2
10153 1 le 2
10154 1 NOT gt 2
10155 1 NOT ge 2
10156 3 NOT eq 2
10157 3 ne 2
10158 3 NOT lt 2
10159 3 NOT le 2
10160 3 gt 2
10161 3 ge 2
10162 END
10163  
10164  
10165 =head2 IfNe($then, $else)
10166  
10167 If not equal execute the then block else the else block.
10168  
10169 Parameter Description
10170 1 $then Then - required
10171 2 $else Else - optional
10172  
10173 B<Example:>
10174  
10175  
10176 my $cmp = sub
10177 {my ($a, $b) = @_;
10178  
10179 for my $op(qw(eq ne lt le gt ge))
10180 {Mov rax, $a;
10181 Cmp rax, $b;
10182 my $Op = ucfirst $op;
10183 eval qq(If$Op Then {PrintOutStringNL("$a $op $b")}, Else {PrintOutStringNL("$a NOT $op $b")});
10184 $@ and confess $@;
10185 }
10186 };
10187 &$cmp(1,1);
10188 &$cmp(1,2);
10189 &$cmp(3,2);
10190 Assemble(debug => 0, eq => <<END);
10191 1 eq 1
10192 1 NOT ne 1
10193 1 NOT lt 1
10194 1 le 1
10195 1 NOT gt 1
10196 1 ge 1
10197 1 NOT eq 2
10198 1 ne 2
10199 1 lt 2
10200 1 le 2
10201 1 NOT gt 2
10202 1 NOT ge 2
10203 3 NOT eq 2
10204 3 ne 2
10205 3 NOT lt 2
10206 3 NOT le 2
10207 3 gt 2
10208 3 ge 2
10209 END
10210  
10211  
10212 =head2 IfNz($then, $else)
10213  
10214 If the zero flag is not set then execute the then block else the else block.
10215  
10216 Parameter Description
10217 1 $then Then - required
10218 2 $else Else - optional
10219  
10220 B<Example:>
10221  
10222  
10223 Mov rax, 0;
10224 Test rax,rax;
10225  
10226 IfNz # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10227  
10228 Then
10229 {PrintOutRegisterInHex rax;
10230 },
10231 Else
10232 {PrintOutRegisterInHex rbx;
10233 };
10234 Mov rax, 1;
10235 Test rax,rax;
10236  
10237 IfNz # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10238  
10239 Then
10240 {PrintOutRegisterInHex rcx;
10241 },
10242 Else
10243 {PrintOutRegisterInHex rdx;
10244 };
10245  
10246 ok Assemble =~ m(rbx.*rcx)s;
10247  
10248  
10249 =head2 IfZ($then, $else)
10250  
10251 If the zero flag is set then execute the then block else the else block.
10252  
10253 Parameter Description
10254 1 $then Then - required
10255 2 $else Else - optional
10256  
10257 B<Example:>
10258  
10259  
10260 SetZF;
10261 PrintOutZF;
10262 ClearZF;
10263 PrintOutZF;
10264 SetZF;
10265 PrintOutZF;
10266 SetZF;
10267 PrintOutZF;
10268 ClearZF;
10269 PrintOutZF;
10270  
10271 SetZF;
10272  
10273 IfZ Then {PrintOutStringNL "Zero"}, Else {PrintOutStringNL "NOT zero"}; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10274  
10275 ClearZF;
10276 IfNz Then {PrintOutStringNL "NOT zero"}, Else {PrintOutStringNL "Zero"};
10277  
10278 Mov r15, 5;
10279 Shr r15, 1; IfC Then {PrintOutStringNL "Carry"} , Else {PrintOutStringNL "NO carry"};
10280 Shr r15, 1; IfC Then {PrintOutStringNL "Carry"} , Else {PrintOutStringNL "NO carry"};
10281 Shr r15, 1; IfNc Then {PrintOutStringNL "NO carry"}, Else {PrintOutStringNL "Carry"};
10282 Shr r15, 1; IfNc Then {PrintOutStringNL "NO carry"}, Else {PrintOutStringNL "Carry"};
10283  
10284 ok Assemble(debug => 0, eq => <<END);
10285 ZF=1
10286 ZF=0
10287 ZF=1
10288 ZF=1
10289 ZF=0
10290 Zero
10291 NOT zero
10292 Carry
10293 NO carry
10294 Carry
10295 NO carry
10296 END
10297  
10298  
10299 =head2 IfC($then, $else)
10300  
10301 If the carry flag is set then execute the then block else the else block.
10302  
10303 Parameter Description
10304 1 $then Then - required
10305 2 $else Else - optional
10306  
10307 B<Example:>
10308  
10309  
10310 SetZF;
10311 PrintOutZF;
10312 ClearZF;
10313 PrintOutZF;
10314 SetZF;
10315 PrintOutZF;
10316 SetZF;
10317 PrintOutZF;
10318 ClearZF;
10319 PrintOutZF;
10320  
10321 SetZF;
10322 IfZ Then {PrintOutStringNL "Zero"}, Else {PrintOutStringNL "NOT zero"};
10323 ClearZF;
10324 IfNz Then {PrintOutStringNL "NOT zero"}, Else {PrintOutStringNL "Zero"};
10325  
10326 Mov r15, 5;
10327  
10328 Shr r15, 1; IfC Then {PrintOutStringNL "Carry"} , Else {PrintOutStringNL "NO carry"}; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10329  
10330  
10331 Shr r15, 1; IfC Then {PrintOutStringNL "Carry"} , Else {PrintOutStringNL "NO carry"}; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10332  
10333 Shr r15, 1; IfNc Then {PrintOutStringNL "NO carry"}, Else {PrintOutStringNL "Carry"};
10334 Shr r15, 1; IfNc Then {PrintOutStringNL "NO carry"}, Else {PrintOutStringNL "Carry"};
10335  
10336 ok Assemble(debug => 0, eq => <<END);
10337 ZF=1
10338 ZF=0
10339 ZF=1
10340 ZF=1
10341 ZF=0
10342 Zero
10343 NOT zero
10344 Carry
10345 NO carry
10346 Carry
10347 NO carry
10348 END
10349  
10350  
10351 =head2 IfNc($then, $else)
10352  
10353 If the carry flag is not set then execute the then block else the else block.
10354  
10355 Parameter Description
10356 1 $then Then - required
10357 2 $else Else - optional
10358  
10359 B<Example:>
10360  
10361  
10362 SetZF;
10363 PrintOutZF;
10364 ClearZF;
10365 PrintOutZF;
10366 SetZF;
10367 PrintOutZF;
10368 SetZF;
10369 PrintOutZF;
10370 ClearZF;
10371 PrintOutZF;
10372  
10373 SetZF;
10374 IfZ Then {PrintOutStringNL "Zero"}, Else {PrintOutStringNL "NOT zero"};
10375 ClearZF;
10376 IfNz Then {PrintOutStringNL "NOT zero"}, Else {PrintOutStringNL "Zero"};
10377  
10378 Mov r15, 5;
10379 Shr r15, 1; IfC Then {PrintOutStringNL "Carry"} , Else {PrintOutStringNL "NO carry"};
10380 Shr r15, 1; IfC Then {PrintOutStringNL "Carry"} , Else {PrintOutStringNL "NO carry"};
10381  
10382 Shr r15, 1; IfNc Then {PrintOutStringNL "NO carry"}, Else {PrintOutStringNL "Carry"}; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10383  
10384  
10385 Shr r15, 1; IfNc Then {PrintOutStringNL "NO carry"}, Else {PrintOutStringNL "Carry"}; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10386  
10387  
10388 ok Assemble(debug => 0, eq => <<END);
10389 ZF=1
10390 ZF=0
10391 ZF=1
10392 ZF=1
10393 ZF=0
10394 Zero
10395 NOT zero
10396 Carry
10397 NO carry
10398 Carry
10399 NO carry
10400 END
10401  
10402  
10403 =head2 IfLt($then, $else)
10404  
10405 If less than execute the then block else the else block.
10406  
10407 Parameter Description
10408 1 $then Then - required
10409 2 $else Else - optional
10410  
10411 B<Example:>
10412  
10413  
10414 my $cmp = sub
10415 {my ($a, $b) = @_;
10416  
10417 for my $op(qw(eq ne lt le gt ge))
10418 {Mov rax, $a;
10419 Cmp rax, $b;
10420 my $Op = ucfirst $op;
10421 eval qq(If$Op Then {PrintOutStringNL("$a $op $b")}, Else {PrintOutStringNL("$a NOT $op $b")});
10422 $@ and confess $@;
10423 }
10424 };
10425 &$cmp(1,1);
10426 &$cmp(1,2);
10427 &$cmp(3,2);
10428 Assemble(debug => 0, eq => <<END);
10429 1 eq 1
10430 1 NOT ne 1
10431 1 NOT lt 1
10432 1 le 1
10433 1 NOT gt 1
10434 1 ge 1
10435 1 NOT eq 2
10436 1 ne 2
10437 1 lt 2
10438 1 le 2
10439 1 NOT gt 2
10440 1 NOT ge 2
10441 3 NOT eq 2
10442 3 ne 2
10443 3 NOT lt 2
10444 3 NOT le 2
10445 3 gt 2
10446 3 ge 2
10447 END
10448  
10449  
10450 =head2 IfLe($then, $else)
10451  
10452 If less than or equal execute the then block else the else block.
10453  
10454 Parameter Description
10455 1 $then Then - required
10456 2 $else Else - optional
10457  
10458 B<Example:>
10459  
10460  
10461 my $cmp = sub
10462 {my ($a, $b) = @_;
10463  
10464 for my $op(qw(eq ne lt le gt ge))
10465 {Mov rax, $a;
10466 Cmp rax, $b;
10467 my $Op = ucfirst $op;
10468 eval qq(If$Op Then {PrintOutStringNL("$a $op $b")}, Else {PrintOutStringNL("$a NOT $op $b")});
10469 $@ and confess $@;
10470 }
10471 };
10472 &$cmp(1,1);
10473 &$cmp(1,2);
10474 &$cmp(3,2);
10475 Assemble(debug => 0, eq => <<END);
10476 1 eq 1
10477 1 NOT ne 1
10478 1 NOT lt 1
10479 1 le 1
10480 1 NOT gt 1
10481 1 ge 1
10482 1 NOT eq 2
10483 1 ne 2
10484 1 lt 2
10485 1 le 2
10486 1 NOT gt 2
10487 1 NOT ge 2
10488 3 NOT eq 2
10489 3 ne 2
10490 3 NOT lt 2
10491 3 NOT le 2
10492 3 gt 2
10493 3 ge 2
10494 END
10495  
10496  
10497 =head2 IfGt($then, $else)
10498  
10499 If greater than execute the then block else the else block.
10500  
10501 Parameter Description
10502 1 $then Then - required
10503 2 $else Else - optional
10504  
10505 B<Example:>
10506  
10507  
10508 my $cmp = sub
10509 {my ($a, $b) = @_;
10510  
10511 for my $op(qw(eq ne lt le gt ge))
10512 {Mov rax, $a;
10513 Cmp rax, $b;
10514 my $Op = ucfirst $op;
10515 eval qq(If$Op Then {PrintOutStringNL("$a $op $b")}, Else {PrintOutStringNL("$a NOT $op $b")});
10516 $@ and confess $@;
10517 }
10518 };
10519 &$cmp(1,1);
10520 &$cmp(1,2);
10521 &$cmp(3,2);
10522 Assemble(debug => 0, eq => <<END);
10523 1 eq 1
10524 1 NOT ne 1
10525 1 NOT lt 1
10526 1 le 1
10527 1 NOT gt 1
10528 1 ge 1
10529 1 NOT eq 2
10530 1 ne 2
10531 1 lt 2
10532 1 le 2
10533 1 NOT gt 2
10534 1 NOT ge 2
10535 3 NOT eq 2
10536 3 ne 2
10537 3 NOT lt 2
10538 3 NOT le 2
10539 3 gt 2
10540 3 ge 2
10541 END
10542  
10543  
10544 =head2 IfGe($then, $else)
10545  
10546 If greater than or equal execute the then block else the else block.
10547  
10548 Parameter Description
10549 1 $then Then - required
10550 2 $else Else - optional
10551  
10552 B<Example:>
10553  
10554  
10555 my $cmp = sub
10556 {my ($a, $b) = @_;
10557  
10558 for my $op(qw(eq ne lt le gt ge))
10559 {Mov rax, $a;
10560 Cmp rax, $b;
10561 my $Op = ucfirst $op;
10562 eval qq(If$Op Then {PrintOutStringNL("$a $op $b")}, Else {PrintOutStringNL("$a NOT $op $b")});
10563 $@ and confess $@;
10564 }
10565 };
10566 &$cmp(1,1);
10567 &$cmp(1,2);
10568 &$cmp(3,2);
10569 Assemble(debug => 0, eq => <<END);
10570 1 eq 1
10571 1 NOT ne 1
10572 1 NOT lt 1
10573 1 le 1
10574 1 NOT gt 1
10575 1 ge 1
10576 1 NOT eq 2
10577 1 ne 2
10578 1 lt 2
10579 1 le 2
10580 1 NOT gt 2
10581 1 NOT ge 2
10582 3 NOT eq 2
10583 3 ne 2
10584 3 NOT lt 2
10585 3 NOT le 2
10586 3 gt 2
10587 3 ge 2
10588 END
10589  
10590  
10591 =head2 Pass($block)
10592  
10593 Pass block for an L<OrBlock>.
10594  
10595 Parameter Description
10596 1 $block Block
10597  
10598 B<Example:>
10599  
10600  
10601 Mov rax, 1;
10602 OrBlock
10603 {my ($pass, $end, $start) = @_;
10604 Cmp rax, 1;
10605 Je $pass;
10606 Cmp rax, 2;
10607 Je $pass;
10608 PrintOutStringNL "Fail";
10609 }
10610  
10611 Pass # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10612  
10613 {my ($end, $pass, $start) = @_;
10614  
10615 PrintOutStringNL "Pass"; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10616  
10617 };
10618  
10619 ok Assemble(debug => 0, eq => <<END);
10620  
10621 Pass # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10622  
10623 END
10624  
10625  
10626 =head2 Fail($block)
10627  
10628 Fail block for an L<AndBlock>.
10629  
10630 Parameter Description
10631 1 $block Block
10632  
10633 B<Example:>
10634  
10635  
10636 Mov rax, 1; Mov rdx, 2;
10637 AndBlock
10638 {my ($fail, $end, $start) = @_;
10639 Cmp rax, 1;
10640 Jne $fail;
10641 Cmp rdx, 2;
10642 Jne $fail;
10643 PrintOutStringNL "Pass";
10644 }
10645  
10646 Fail # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10647  
10648 {my ($end, $fail, $start) = @_;
10649  
10650 PrintOutStringNL "Fail"; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10651  
10652 };
10653  
10654 ok Assemble(debug => 0, eq => <<END);
10655 Pass
10656 END
10657  
10658  
10659 =head2 AndBlock($test, $fail)
10660  
10661 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.
10662  
10663 Parameter Description
10664 1 $test Block
10665 2 $fail Optional failure block
10666  
10667 B<Example:>
10668  
10669  
10670 Mov rax, 1; Mov rdx, 2;
10671  
10672 AndBlock # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10673  
10674 {my ($fail, $end, $start) = @_;
10675 Cmp rax, 1;
10676 Jne $fail;
10677 Cmp rdx, 2;
10678 Jne $fail;
10679 PrintOutStringNL "Pass";
10680 }
10681 Fail
10682 {my ($end, $fail, $start) = @_;
10683 PrintOutStringNL "Fail";
10684 };
10685  
10686 ok Assemble(debug => 0, eq => <<END);
10687 Pass
10688 END
10689  
10690  
10691 =head2 OrBlock($test, $pass)
10692  
10693 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.
10694  
10695 Parameter Description
10696 1 $test Tests
10697 2 $pass Optional block to execute on success
10698  
10699 B<Example:>
10700  
10701  
10702 Mov rax, 1;
10703  
10704 OrBlock # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10705  
10706 {my ($pass, $end, $start) = @_;
10707 Cmp rax, 1;
10708 Je $pass;
10709 Cmp rax, 2;
10710 Je $pass;
10711 PrintOutStringNL "Fail";
10712 }
10713 Pass
10714 {my ($end, $pass, $start) = @_;
10715 PrintOutStringNL "Pass";
10716 };
10717  
10718 ok Assemble(debug => 0, eq => <<END);
10719 Pass
10720 END
10721  
10722  
10723 =head2 For($block, $register, $limit, $increment)
10724  
10725 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.
10726  
10727 Parameter Description
10728 1 $block Block
10729 2 $register Register
10730 3 $limit Limit on loop
10731 4 $increment Increment on each iteration
10732  
10733 B<Example:>
10734  
10735  
10736  
10737 For # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10738  
10739 {my ($start, $end, $next) = @_;
10740 Cmp rax, 3;
10741 Jge $end;
10742 PrintOutRegisterInHex rax;
10743 } rax, 16, 1;
10744  
10745 ok Assemble(debug => 0, eq => <<END);
10746 rax: 0000 0000 0000 0000
10747 rax: 0000 0000 0000 0001
10748 rax: 0000 0000 0000 0002
10749 END
10750  
10751  
10752 =head2 ForIn($full, $last, $register, $limitRegister, $increment)
10753  
10754 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.
10755  
10756 Parameter Description
10757 1 $full Block for full block
10758 2 $last Block for last block
10759 3 $register Register
10760 4 $limitRegister Register containing upper limit of loop
10761 5 $increment Increment on each iteration
10762  
10763 =head2 ForEver($block)
10764  
10765 Iterate for ever.
10766  
10767 Parameter Description
10768 1 $block Block to iterate
10769  
10770 =head2 Macro($block, %options)
10771  
10772 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.
10773  
10774 Parameter Description
10775 1 $block Block
10776 2 %options Options.
10777  
10778 =head2 Call
10779  
10780 Call a subroutine
10781  
10782 =head3 SubroutineStartStack()
10783  
10784 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.
10785  
10786  
10787 =head3 Subroutine($block, $parameters, %options)
10788  
10789 Create a subroutine that can be called in assembler code.
10790  
10791 Parameter Description
10792 1 $block Block
10793 2 $parameters [parameters names]
10794 3 %options Options.
10795  
10796 B<Example:>
10797  
10798  
10799 my $g = G g, 3;
10800  
10801 my $s = Subroutine # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10802  
10803 {my ($p, $s) = @_;
10804 $g->copy($g - 1);
10805 $g->outNL;
10806 If ($g > 0,
10807 Then
10808 {$s->call;
10809 });
10810 } [], name => 'ref';
10811  
10812 $s->call;
10813  
10814 ok Assemble(debug => 0, eq => <<END);
10815 g: 0000 0000 0000 0002
10816 g: 0000 0000 0000 0001
10817 g: 0000 0000 0000 0000
10818 END
10819  
10820 my $g = G g, 2;
10821  
10822 my $u = Subroutine # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10823  
10824 {my ($p, $s) = @_;
10825 PrintOutTraceBack;
10826 $$p{g}->copy(K gg, 1);
10827 PrintOutTraceBack;
10828 } [qw(g)], name => 'uuuu';
10829  
10830 my $t = Subroutine # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10831  
10832 {my ($p, $s) = @_;
10833 $u->call($$p{g});
10834 } [qw(g)], name => 'tttt';
10835  
10836 my $s = Subroutine # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10837  
10838 {my ($p, $s) = @_;
10839 $t->call($$p{g});
10840 } [qw(g)], name => 'ssss';
10841  
10842 $g->outNL;
10843 $s->call($g);
10844 $g->outNL;
10845  
10846 ok Assemble(debug => 0, eq => <<END);
10847 g: 0000 0000 0000 0002
10848  
10849  
10850 Subroutine trace back, depth: 0000 0000 0000 0003 # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10851  
10852 0000 0000 0000 0002 uuuu
10853 0000 0000 0000 0002 tttt
10854 0000 0000 0000 0002 ssss
10855  
10856  
10857  
10858 Subroutine trace back, depth: 0000 0000 0000 0003 # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10859  
10860 0000 0000 0000 0001 uuuu
10861 0000 0000 0000 0001 tttt
10862 0000 0000 0000 0001 ssss
10863  
10864 g: 0000 0000 0000 0001
10865 END
10866  
10867 my $r = G r, 2;
10868  
10869  
10870 my $u = Subroutine # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10871  
10872 {my ($p, $s) = @_;
10873 PrintOutTraceBack;
10874 $$p{u}->copy(K gg, 1);
10875 PrintOutTraceBack;
10876 } [qw(u)], name => 'uuuu';
10877  
10878  
10879 my $t = Subroutine # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10880  
10881 {my ($p, $s) = @_;
10882 $u->call(u => $$p{t});
10883 } [qw(t)], name => 'tttt';
10884  
10885  
10886 my $s = Subroutine # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10887  
10888 {my ($p, $s) = @_;
10889 $t->call(t => $$p{s});
10890 } [qw(s)], name => 'ssss';
10891  
10892 $r->outNL;
10893 $s->call(s=>$r);
10894 $r->outNL;
10895  
10896 ok Assemble(debug => 0, eq => <<END);
10897 r: 0000 0000 0000 0002
10898  
10899  
10900 Subroutine trace back, depth: 0000 0000 0000 0003 # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10901  
10902 0000 0000 0000 0002 uuuu
10903 0000 0000 0000 0002 tttt
10904 0000 0000 0000 0002 ssss
10905  
10906  
10907  
10908 Subroutine trace back, depth: 0000 0000 0000 0003 # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
10909  
10910 0000 0000 0000 0001 uuuu
10911 0000 0000 0000 0001 tttt
10912 0000 0000 0000 0001 ssss
10913  
10914 r: 0000 0000 0000 0001
10915 END
10916  
10917  
10918 =head3 Nasm::X86::Sub::call($sub, @parameters)
10919  
10920 Call a sub passing it some parameters.
10921  
10922 Parameter Description
10923 1 $sub Subroutine descriptor
10924 2 @parameters Parameter variables
10925  
10926 B<Example:>
10927  
10928  
10929 my $s = Subroutine
10930 {my ($p) = @_;
10931 $$p{in}->outNL;
10932 } [qw(in)], name => 'sss';
10933  
10934 my $t = Subroutine
10935 {my ($p) = @_;
10936 $s->call($$p{in});
10937 } [qw(in)], name => 'ttt';
10938  
10939 my $c = Subroutine
10940 {my ($p) = @_;
10941 $t->via($$p{call}, $$p{in});
10942 } [qw(call in)], name => 'ccc';
10943  
10944 $c->call($t->V, V(in, 42));
10945  
10946 ok Assemble(debug => 0, eq => <<END);
10947 in: 0000 0000 0000 002A
10948 END
10949  
10950  
10951 =head3 Nasm::X86::Sub::via($sub, $ref, @parameters)
10952  
10953 Call a sub by reference passing it some parameters.
10954  
10955 Parameter Description
10956 1 $sub Subroutine descriptor
10957 2 $ref Variable containing a reference to the sub
10958 3 @parameters Parameter variables
10959  
10960 B<Example:>
10961  
10962  
10963 my $s = Subroutine
10964 {my ($p) = @_;
10965 $$p{in}->outNL;
10966 } [qw(in)], name => 'sss';
10967  
10968 my $t = Subroutine
10969 {my ($p) = @_;
10970 $s->call($$p{in});
10971 } [qw(in)], name => 'ttt';
10972  
10973 my $c = Subroutine
10974 {my ($p) = @_;
10975 $t->via($$p{call}, $$p{in});
10976 } [qw(call in)], name => 'ccc';
10977  
10978 $c->call($t->V, V(in, 42));
10979  
10980 ok Assemble(debug => 0, eq => <<END);
10981 in: 0000 0000 0000 002A
10982 END
10983  
10984  
10985 =head3 Nasm::X86::Sub::V($sub)
10986  
10987 Put the address of a subroutine into a stack variable so that it can be passed as a parameter.
10988  
10989 Parameter Description
10990 1 $sub Subroutine descriptor
10991  
10992 =head3 PrintTraceBack($channel)
10993  
10994 Trace the call stack.
10995  
10996 Parameter Description
10997 1 $channel Channel to write on
10998  
10999 =head3 PrintErrTraceBack()
11000  
11001 Print sub routine track back on stderr.
11002  
11003  
11004 =head3 PrintOutTraceBack()
11005  
11006 Print sub routine track back on stdout.
11007  
11008  
11009 B<Example:>
11010  
11011  
11012 my $d = V depth, 3; # Create a variable on the stack
11013  
11014 my $s = Subroutine
11015 {my ($p, $s) = @_; # Parameters, subroutine descriptor
11016  
11017 PrintOutTraceBack; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11018  
11019  
11020 my $d = $$p{depth}->copy($$p{depth} - 1); # Modify the variable referenced by the parameter
11021  
11022 If ($d > 0,
11023 Then
11024 {$s->call($d); # Recurse
11025 });
11026  
11027  
11028 PrintOutTraceBack; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11029  
11030 } [qw(depth)], name => 'ref';
11031  
11032 $s->call($d); # Call the subroutine
11033  
11034 ok Assemble(debug => 0, eq => <<END);
11035  
11036 Subroutine trace back, depth: 0000 0000 0000 0001
11037 0000 0000 0000 0003 ref
11038  
11039  
11040 Subroutine trace back, depth: 0000 0000 0000 0002
11041 0000 0000 0000 0002 ref
11042 0000 0000 0000 0002 ref
11043  
11044  
11045 Subroutine trace back, depth: 0000 0000 0000 0003
11046 0000 0000 0000 0001 ref
11047 0000 0000 0000 0001 ref
11048 0000 0000 0000 0001 ref
11049  
11050  
11051 Subroutine trace back, depth: 0000 0000 0000 0003
11052 0000 0000 0000 0000 ref
11053 0000 0000 0000 0000 ref
11054 0000 0000 0000 0000 ref
11055  
11056  
11057 Subroutine trace back, depth: 0000 0000 0000 0002
11058 0000 0000 0000 0000 ref
11059 0000 0000 0000 0000 ref
11060  
11061  
11062 Subroutine trace back, depth: 0000 0000 0000 0001
11063 0000 0000 0000 0000 ref
11064  
11065 END
11066  
11067  
11068 =head3 OnSegv()
11069  
11070 Request a trace back followed by exit on a B<segv> signal.
11071  
11072  
11073 B<Example:>
11074  
11075  
11076  
11077 OnSegv(); # Request a trace back followed by exit on a segv signal. # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11078  
11079  
11080 my $t = Subroutine # Subroutine that will cause an error to occur to force a trace back to be printed
11081 {Mov r15, 0;
11082 Mov r15, "[r15]"; # Try to read an unmapped memory location
11083 } [qw(in)], name => 'sub that causes a segv'; # The name that will appear in the trace back
11084  
11085 $t->call(K(in, 42));
11086  
11087 ok Assemble(debug => 0, keep2 => 'signal', emulator=>0, eq => <<END); # Cannot use the emulator because it does not understand signals
11088  
11089 Subroutine trace back, depth: 0000 0000 0000 0001
11090 0000 0000 0000 002A sub that causes a segv
11091  
11092 END
11093  
11094  
11095 =head3 cr($block, @registers)
11096  
11097 Call a subroutine with a reordering of the registers.
11098  
11099 Parameter Description
11100 1 $block Code to execute with reordered registers
11101 2 @registers Registers to reorder
11102  
11103 =head1 Comments
11104  
11105 Inserts comments into the generated assember code.
11106  
11107 =head2 CommentWithTraceBack(@comment)
11108  
11109 Insert a comment into the assembly code with a traceback showing how it was generated.
11110  
11111 Parameter Description
11112 1 @comment Text of comment
11113  
11114 =head2 Comment(@comment)
11115  
11116 Insert a comment into the assembly code.
11117  
11118 Parameter Description
11119 1 @comment Text of comment
11120  
11121 B<Example:>
11122  
11123  
11124  
11125 Comment "Print a string from memory"; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11126  
11127 my $s = "Hello World";
11128 Mov rax, Rs($s);
11129 Mov rdi, length $s;
11130 PrintOutMemory;
11131 Exit(0);
11132  
11133 ok Assemble =~ m(Hello World);
11134  
11135  
11136 =head2 DComment(@comment)
11137  
11138 Insert a comment into the data segment.
11139  
11140 Parameter Description
11141 1 @comment Text of comment
11142  
11143 =head2 RComment(@comment)
11144  
11145 Insert a comment into the read only data segment.
11146  
11147 Parameter Description
11148 1 @comment Text of comment
11149  
11150 =head1 Print
11151  
11152 Print
11153  
11154 =head2 PrintNL($channel)
11155  
11156 Print a new line to stdout or stderr.
11157  
11158 Parameter Description
11159 1 $channel Channel to write on
11160  
11161 =head2 PrintErrNL()
11162  
11163 Print a new line to stderr.
11164  
11165  
11166 =head2 PrintOutNL()
11167  
11168 Print a new line to stderr.
11169  
11170  
11171 B<Example:>
11172  
11173  
11174 my $q = Rs('abababab');
11175 Mov(rax, "[$q]");
11176 PrintOutString "rax: ";
11177 PrintOutRaxInHex;
11178  
11179 PrintOutNL; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11180  
11181 Xor rax, rax;
11182 PrintOutString "rax: ";
11183 PrintOutRaxInHex;
11184  
11185 PrintOutNL; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11186  
11187  
11188 ok Assemble =~ m(rax: 6261 6261 6261 6261.*rax: 0000 0000 0000 0000)s;
11189  
11190  
11191 =head2 PrintString($channel, @string)
11192  
11193 Print a constant string to the specified channel.
11194  
11195 Parameter Description
11196 1 $channel Channel
11197 2 @string Strings
11198  
11199 =head2 PrintStringNL($channel, @string)
11200  
11201 Print a constant string to the specified channel followed by a new line.
11202  
11203 Parameter Description
11204 1 $channel Channel
11205 2 @string Strings
11206  
11207 =head2 PrintErrString(@string)
11208  
11209 Print a constant string to stderr.
11210  
11211 Parameter Description
11212 1 @string String
11213  
11214 =head2 PrintOutString(@string)
11215  
11216 Print a constant string to stdout.
11217  
11218 Parameter Description
11219 1 @string String
11220  
11221 B<Example:>
11222  
11223  
11224 my $q = Rs('abababab');
11225 Mov(rax, "[$q]");
11226  
11227 PrintOutString "rax: "; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11228  
11229 PrintOutRaxInHex;
11230 PrintOutNL;
11231 Xor rax, rax;
11232  
11233 PrintOutString "rax: "; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11234  
11235 PrintOutRaxInHex;
11236 PrintOutNL;
11237  
11238 ok Assemble =~ m(rax: 6261 6261 6261 6261.*rax: 0000 0000 0000 0000)s;
11239  
11240  
11241 =head2 PrintSpace($channel, $spaces)
11242  
11243 Print one or more spaces to the specified channel.
11244  
11245 Parameter Description
11246 1 $channel Channel
11247 2 $spaces Number of spaces if not one.
11248  
11249 =head2 PrintErrSpace($spaces)
11250  
11251 Print one or more spaces to stderr.
11252  
11253 Parameter Description
11254 1 $spaces Number of spaces if not one.
11255  
11256 =head2 PrintOutSpace($spaces)
11257  
11258 Print one or more spaces to stdout.
11259  
11260 Parameter Description
11261 1 $spaces Number of spaces if not one.
11262  
11263 =head2 PrintErrStringNL(@string)
11264  
11265 Print a constant string followed by a new line to stderr.
11266  
11267 Parameter Description
11268 1 @string Strings
11269  
11270 B<Example:>
11271  
11272  
11273 PrintOutStringNL "Hello World";
11274 PrintOutStringNL "Hello
11275 World";
11276  
11277 PrintErrStringNL "Hello World"; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11278  
11279  
11280 ok Assemble(debug => 0, eq => <<END);
11281 Hello World
11282 Hello
11283 World
11284 END
11285  
11286  
11287 =head2 PrintOutStringNL(@string)
11288  
11289 Print a constant string followed by a new line to stdout.
11290  
11291 Parameter Description
11292 1 @string Strings
11293  
11294 B<Example:>
11295  
11296  
11297  
11298 PrintOutStringNL "Hello World"; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11299  
11300  
11301 PrintOutStringNL "Hello
11302 World"; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11303  
11304 PrintErrStringNL "Hello World";
11305  
11306 ok Assemble(debug => 0, eq => <<END);
11307 Hello World
11308 Hello
11309 World
11310 END
11311  
11312  
11313 =head2 PrintRaxInHex($channel, $end)
11314  
11315 Write the content of register rax in hexadecimal in big endian notation to the specified channel.
11316  
11317 Parameter Description
11318 1 $channel Channel
11319 2 $end Optional end byte
11320  
11321 =head2 PrintErrRaxInHex()
11322  
11323 Write the content of register rax in hexadecimal in big endian notation to stderr.
11324  
11325  
11326 =head2 PrintOutRaxInHex()
11327  
11328 Write the content of register rax in hexadecimal in big endian notation to stderr.
11329  
11330  
11331 B<Example:>
11332  
11333  
11334 my $q = Rs('abababab');
11335 Mov(rax, "[$q]");
11336 PrintOutString "rax: ";
11337  
11338 PrintOutRaxInHex; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11339  
11340 PrintOutNL;
11341 Xor rax, rax;
11342 PrintOutString "rax: ";
11343  
11344 PrintOutRaxInHex; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11345  
11346 PrintOutNL;
11347  
11348 ok Assemble =~ m(rax: 6261 6261 6261 6261.*rax: 0000 0000 0000 0000)s;
11349  
11350  
11351 =head2 PrintOutRaxInReverseInHex()
11352  
11353 Write the content of register rax to stderr in hexadecimal in little endian notation.
11354  
11355  
11356 B<Example:>
11357  
11358  
11359 Mov rax, 0x07654321;
11360 Shl rax, 32;
11361 Or rax, 0x07654321;
11362 PushR rax;
11363  
11364 PrintOutRaxInHex;
11365 PrintOutNL;
11366  
11367 PrintOutRaxInReverseInHex; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11368  
11369 PrintOutNL;
11370  
11371 Mov rax, rsp;
11372 Mov rdi, 8;
11373 PrintOutMemoryInHex;
11374 PrintOutNL;
11375 PopR rax;
11376  
11377 Mov rax, 4096;
11378 PushR rax;
11379 Mov rax, rsp;
11380 Mov rdi, 8;
11381 PrintOutMemoryInHex;
11382 PrintOutNL;
11383 PopR rax;
11384  
11385 ok Assemble(debug => 0, eq => <<END);
11386 0765 4321 0765 4321
11387 2143 6507 2143 6507
11388 2143 6507 2143 6507
11389 0010 0000 0000 0000
11390 END
11391  
11392  
11393 =head2 PrintOneRegisterInHex($channel, $r)
11394  
11395 Print the named register as a hex strings.
11396  
11397 Parameter Description
11398 1 $channel Channel to print on
11399 2 $r Register to print
11400  
11401 =head2 PrintRegisterInHex($channel, @r)
11402  
11403 Print the named registers as hex strings.
11404  
11405 Parameter Description
11406 1 $channel Channel to print on
11407 2 @r Names of the registers to print
11408  
11409 =head2 PrintErrRegisterInHex(@r)
11410  
11411 Print the named registers as hex strings on stderr.
11412  
11413 Parameter Description
11414 1 @r Names of the registers to print
11415  
11416 =head2 PrintOutRegisterInHex(@r)
11417  
11418 Print the named registers as hex strings on stdout.
11419  
11420 Parameter Description
11421 1 @r Names of the registers to print
11422  
11423 B<Example:>
11424  
11425  
11426 my $q = Rs(('a'..'p')x4);
11427 Mov r8,"[$q]";
11428  
11429 PrintOutRegisterInHex r8; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11430  
11431  
11432 ok Assemble(debug => 0, eq => <<END);
11433 r8: 6867 6665 6463 6261
11434 END
11435  
11436  
11437 =head2 PrintOutRegistersInHex()
11438  
11439 Print the general purpose registers in hex.
11440  
11441  
11442 B<Example:>
11443  
11444  
11445 my $q = Rs('abababab');
11446 Mov(rax, 1);
11447 Mov(rbx, 2);
11448 Mov(rcx, 3);
11449 Mov(rdx, 4);
11450 Mov(r8, 5);
11451 Lea r9, "[rax+rbx]";
11452  
11453 PrintOutRegistersInHex; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11454  
11455  
11456 my $r = Assemble;
11457 ok $r =~ m( r8: 0000 0000 0000 0005.* r9: 0000 0000 0000 0003.*rax: 0000 0000 0000 0001)s;
11458 ok $r =~ m(rbx: 0000 0000 0000 0002.*rcx: 0000 0000 0000 0003.*rdx: 0000 0000 0000 0004)s;
11459  
11460  
11461 =head2 PrintErrZF()
11462  
11463 Print the zero flag without disturbing it on stderr.
11464  
11465  
11466 =head2 PrintOutZF()
11467  
11468 Print the zero flag without disturbing it on stdout.
11469  
11470  
11471 B<Example:>
11472  
11473  
11474 SetZF;
11475  
11476 PrintOutZF; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11477  
11478 ClearZF;
11479  
11480 PrintOutZF; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11481  
11482 SetZF;
11483  
11484 PrintOutZF; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11485  
11486 SetZF;
11487  
11488 PrintOutZF; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11489  
11490 ClearZF;
11491  
11492 PrintOutZF; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11493  
11494  
11495 SetZF;
11496 IfZ Then {PrintOutStringNL "Zero"}, Else {PrintOutStringNL "NOT zero"};
11497 ClearZF;
11498 IfNz Then {PrintOutStringNL "NOT zero"}, Else {PrintOutStringNL "Zero"};
11499  
11500 Mov r15, 5;
11501 Shr r15, 1; IfC Then {PrintOutStringNL "Carry"} , Else {PrintOutStringNL "NO carry"};
11502 Shr r15, 1; IfC Then {PrintOutStringNL "Carry"} , Else {PrintOutStringNL "NO carry"};
11503 Shr r15, 1; IfNc Then {PrintOutStringNL "NO carry"}, Else {PrintOutStringNL "Carry"};
11504 Shr r15, 1; IfNc Then {PrintOutStringNL "NO carry"}, Else {PrintOutStringNL "Carry"};
11505  
11506 ok Assemble(debug => 0, eq => <<END);
11507 ZF=1
11508 ZF=0
11509 ZF=1
11510 ZF=1
11511 ZF=0
11512 Zero
11513 NOT zero
11514 Carry
11515 NO carry
11516 Carry
11517 NO carry
11518 END
11519  
11520  
11521 =head2 PrintUtf8Char($channel)
11522  
11523 Print the utf 8 character addressed by rax to the specified channel. The character must be in little endian form.
11524  
11525 Parameter Description
11526 1 $channel Channel
11527  
11528 =head2 PrintErrUtf8Char()
11529  
11530 Print the utf 8 character addressed by rax to stderr.
11531  
11532  
11533 =head2 PrintOutUtf8Char()
11534  
11535 Print the utf 8 character addressed by rax to stdout.
11536  
11537  
11538 B<Example:>
11539  
11540  
11541 my $u = Rd(convertUtf32ToUtf8LE(ord('α')));
11542 Mov rax, $u;
11543  
11544 PrintOutUtf8Char; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11545  
11546 PrintOutNL;
11547  
11548 ok Assemble(debug => 0, trace => 0, eq => <<END);
11549 α
11550 END
11551  
11552  
11553 =head2 PrintErrUtf32($size, $address)
11554  
11555 Print the utf 8 character addressed by rax to stderr.
11556  
11557 Parameter Description
11558 1 $size Variable: number of characters to print
11559 2 $address Variable: address of memory
11560  
11561 =head2 PrintOutUtf32($size, $address)
11562  
11563 Print the utf 8 character addressed by rax to stdout.
11564  
11565 Parameter Description
11566 1 $size Variable: number of characters to print
11567 2 $address Variable: address of memory
11568  
11569 =head1 Variables
11570  
11571 Variable definitions and operations
11572  
11573 =head2 Definitions
11574  
11575 Variable definitions
11576  
11577 =head3 Variable($name, $expr, %options)
11578  
11579 Create a new variable with the specified name initialized via an optional expression.
11580  
11581 Parameter Description
11582 1 $name Name of variable
11583 2 $expr Optional expression initializing variable
11584 3 %options Options
11585  
11586 =head3 G($name, $expr, %options)
11587  
11588 Define a global variable.
11589  
11590 Parameter Description
11591 1 $name Name of variable
11592 2 $expr Initializing expression
11593 3 %options Options
11594  
11595 B<Example:>
11596  
11597  
11598 my $s = Subroutine
11599 {my ($p) = @_;
11600 $$p{v}->copy($$p{v} + $$p{k} + $$p{g} + 1);
11601 } [qw(v k g)], name => 'add';
11602  
11603 my $v = V(v, 1);
11604 my $k = K(k, 2);
11605  
11606 my $g = G(g, 3); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11607  
11608 $s->call($v, $k, $g);
11609 $v->outNL;
11610  
11611 ok Assemble(debug => 0, eq => <<END);
11612 v: 0000 0000 0000 0007
11613 END
11614  
11615  
11616 my $g = G g, 0; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11617  
11618 my $s = Subroutine
11619 {my ($p) = @_;
11620 $$p{g}->copy(K value, 1);
11621 } [qw(g)], name => 'ref2';
11622  
11623 my $t = Subroutine
11624 {my ($p) = @_;
11625 $s->call($$p{g});
11626 } [qw(g)], name => 'ref';
11627  
11628 $t->call($g);
11629 $g->outNL;
11630  
11631 ok Assemble(debug => 0, eq => <<END);
11632 g: 0000 0000 0000 0001
11633 END
11634  
11635  
11636 =head3 K($name, $expr, %options)
11637  
11638 Define a constant variable.
11639  
11640 Parameter Description
11641 1 $name Name of variable
11642 2 $expr Initializing expression
11643 3 %options Options
11644  
11645 B<Example:>
11646  
11647  
11648 my $s = Subroutine
11649 {my ($p) = @_;
11650 $$p{v}->copy($$p{v} + $$p{k} + $$p{g} + 1);
11651 } [qw(v k g)], name => 'add';
11652  
11653 my $v = V(v, 1);
11654  
11655 my $k = K(k, 2); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11656  
11657 my $g = G(g, 3);
11658 $s->call($v, $k, $g);
11659 $v->outNL;
11660  
11661 ok Assemble(debug => 0, eq => <<END);
11662 v: 0000 0000 0000 0007
11663 END
11664  
11665 my $g = G g, 0;
11666 my $s = Subroutine
11667 {my ($p) = @_;
11668  
11669 $$p{g}->copy(K value, 1); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11670  
11671 } [qw(g)], name => 'ref2';
11672  
11673 my $t = Subroutine
11674 {my ($p) = @_;
11675 $s->call($$p{g});
11676 } [qw(g)], name => 'ref';
11677  
11678 $t->call($g);
11679 $g->outNL;
11680  
11681 ok Assemble(debug => 0, eq => <<END);
11682 g: 0000 0000 0000 0001
11683 END
11684  
11685 my $a = V(a, 3); $a->outNL;
11686  
11687 my $b = K(b, 2); $b->outNL; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11688  
11689 my $c = $a + $b; $c->outNL;
11690 my $d = $c - $a; $d->outNL;
11691 my $g = $a * $b; $g->outNL;
11692 my $h = $g / $b; $h->outNL;
11693 my $i = $a % $b; $i->outNL;
11694  
11695 If ($a == 3,
11696 Then
11697 {PrintOutStringNL "a == 3"
11698 },
11699 Else
11700 {PrintOutStringNL "a != 3"
11701 });
11702  
11703 ++$a; $a->outNL;
11704 --$a; $a->outNL;
11705  
11706 ok Assemble(debug => 0, eq => <<END);
11707 a: 0000 0000 0000 0003
11708 b: 0000 0000 0000 0002
11709 (a add b): 0000 0000 0000 0005
11710 ((a add b) sub a): 0000 0000 0000 0002
11711 (a times b): 0000 0000 0000 0006
11712 ((a times b) / b): 0000 0000 0000 0003
11713 (a % b): 0000 0000 0000 0001
11714 a == 3
11715 a: 0000 0000 0000 0004
11716 a: 0000 0000 0000 0003
11717 END
11718  
11719  
11720 =head3 R($name)
11721  
11722 Define a reference variable.
11723  
11724 Parameter Description
11725 1 $name Name of variable
11726  
11727 =head3 V($name, $expr, %options)
11728  
11729 Define a variable.
11730  
11731 Parameter Description
11732 1 $name Name of variable
11733 2 $expr Initializing expression
11734 3 %options Options
11735  
11736 B<Example:>
11737  
11738  
11739 my $s = Subroutine
11740 {my ($p) = @_;
11741 $$p{v}->copy($$p{v} + $$p{k} + $$p{g} + 1);
11742 } [qw(v k g)], name => 'add';
11743  
11744  
11745 my $v = V(v, 1); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11746  
11747 my $k = K(k, 2);
11748 my $g = G(g, 3);
11749 $s->call($v, $k, $g);
11750 $v->outNL;
11751  
11752 ok Assemble(debug => 0, eq => <<END);
11753 v: 0000 0000 0000 0007
11754 END
11755  
11756 my $g = G g, 0;
11757 my $s = Subroutine
11758 {my ($p) = @_;
11759 $$p{g}->copy(K value, 1);
11760 } [qw(g)], name => 'ref2';
11761  
11762 my $t = Subroutine
11763 {my ($p) = @_;
11764 $s->call($$p{g});
11765 } [qw(g)], name => 'ref';
11766  
11767 $t->call($g);
11768 $g->outNL;
11769  
11770 ok Assemble(debug => 0, eq => <<END);
11771 g: 0000 0000 0000 0001
11772 END
11773  
11774  
11775 my $a = V(a, 3); $a->outNL; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
11776  
11777 my $b = K(b, 2); $b->outNL;
11778 my $c = $a + $b; $c->outNL;
11779 my $d = $c - $a; $d->outNL;
11780 my $g = $a * $b; $g->outNL;
11781 my $h = $g / $b; $h->outNL;
11782 my $i = $a % $b; $i->outNL;
11783  
11784 If ($a == 3,
11785 Then
11786 {PrintOutStringNL "a == 3"
11787 },
11788 Else
11789 {PrintOutStringNL "a != 3"
11790 });
11791  
11792 ++$a; $a->outNL;
11793 --$a; $a->outNL;
11794  
11795 ok Assemble(debug => 0, eq => <<END);
11796 a: 0000 0000 0000 0003
11797 b: 0000 0000 0000 0002
11798 (a add b): 0000 0000 0000 0005
11799 ((a add b) sub a): 0000 0000 0000 0002
11800 (a times b): 0000 0000 0000 0006
11801 ((a times b) / b): 0000 0000 0000 0003
11802 (a % b): 0000 0000 0000 0001
11803 a == 3
11804 a: 0000 0000 0000 0004
11805 a: 0000 0000 0000 0003
11806 END
11807  
11808  
11809 =head2 Print variables
11810  
11811 Print the values of variables or the memory addressed by them
11812  
11813 =head3 Nasm::X86::Variable::err($left, $title1, $title2)
11814  
11815 Dump the value of a variable on stderr.
11816  
11817 Parameter Description
11818 1 $left Left variable
11819 2 $title1 Optional leading title
11820 3 $title2 Optional trailing title
11821  
11822 =head3 Nasm::X86::Variable::out($left, $title1, $title2)
11823  
11824 Dump the value of a variable on stdout.
11825  
11826 Parameter Description
11827 1 $left Left variable
11828 2 $title1 Optional leading title
11829 3 $title2 Optional trailing title
11830  
11831 =head3 Nasm::X86::Variable::errNL($left, $title1, $title2)
11832  
11833 Dump the value of a variable on stderr and append a new line.
11834  
11835 Parameter Description
11836 1 $left Left variable
11837 2 $title1 Optional leading title
11838 3 $title2 Optional trailing title
11839  
11840 =head3 Nasm::X86::Variable::d($left, $title1, $title2)
11841  
11842 Dump the value of a variable on stderr and append a new line.
11843  
11844 Parameter Description
11845 1 $left Left variable
11846 2 $title1 Optional leading title
11847 3 $title2 Optional trailing title
11848  
11849 =head3 Nasm::X86::Variable::outNL($left, $title1, $title2)
11850  
11851 Dump the value of a variable on stdout and append a new line.
11852  
11853 Parameter Description
11854 1 $left Left variable
11855 2 $title1 Optional leading title
11856 3 $title2 Optional trailing title
11857  
11858 =head3 Nasm::X86::Variable::debug($left)
11859  
11860 Dump the value of a variable on stdout with an indication of where the dump came from.
11861  
11862 Parameter Description
11863 1 $left Left variable
11864  
11865 =head2 Operations
11866  
11867 Variable operations
11868  
11869 =head3 Nasm::X86::Variable::address($left, $offset)
11870  
11871 Get the address of a variable with an optional offset.
11872  
11873 Parameter Description
11874 1 $left Left variable
11875 2 $offset Optional offset
11876  
11877 =head3 Nasm::X86::Variable::copy($left, $right, $Transfer)
11878  
11879 Copy one variable into another.
11880  
11881 Parameter Description
11882 1 $left Left variable
11883 2 $right Right variable
11884 3 $Transfer Optional transfer register
11885  
11886 B<Example:>
11887  
11888  
11889 my $s = Subroutine
11890 {my ($p) = @_;
11891 $$p{v}->copy($$p{v} + $$p{k} + $$p{g} + 1);
11892 } [qw(v k g)], name => 'add';
11893  
11894 my $v = V(v, 1);
11895 my $k = K(k, 2);
11896 my $g = G(g, 3);
11897 $s->call($v, $k, $g);
11898 $v->outNL;
11899  
11900 ok Assemble(debug => 0, eq => <<END);
11901 v: 0000 0000 0000 0007
11902 END
11903  
11904 my $g = G g, 0;
11905 my $s = Subroutine
11906 {my ($p) = @_;
11907 $$p{g}->copy(K value, 1);
11908 } [qw(g)], name => 'ref2';
11909  
11910 my $t = Subroutine
11911 {my ($p) = @_;
11912 $s->call($$p{g});
11913 } [qw(g)], name => 'ref';
11914  
11915 $t->call($g);
11916 $g->outNL;
11917  
11918 ok Assemble(debug => 0, eq => <<END);
11919 g: 0000 0000 0000 0001
11920 END
11921  
11922  
11923 =head3 Nasm::X86::Variable::copyRef($left, $right, $Transfer)
11924  
11925 Copy a reference to a variable.
11926  
11927 Parameter Description
11928 1 $left Left variable
11929 2 $right Right variable
11930 3 $Transfer Optional transfer register
11931  
11932 =head3 Nasm::X86::Variable::copyZF($var)
11933  
11934 Copy the current state of the zero flag into a variable.
11935  
11936 Parameter Description
11937 1 $var Variable
11938  
11939 B<Example:>
11940  
11941  
11942 Mov r15, 1;
11943 my $z = V(zf);
11944 Cmp r15, 1; $z->copyZF; $z->outNL;
11945 Cmp r15, 2; $z->copyZF; $z->outNL;
11946 Cmp r15, 1; $z->copyZFInverted; $z->outNL;
11947 Cmp r15, 2; $z->copyZFInverted; $z->outNL;
11948  
11949 ok Assemble(debug => 0, eq => <<END);
11950 zf: 0000 0000 0000 0001
11951 zf: 0000 0000 0000 0000
11952 zf: 0000 0000 0000 0000
11953 zf: 0000 0000 0000 0001
11954 END
11955  
11956  
11957 =head3 Nasm::X86::Variable::copyZFInverted($var)
11958  
11959 Copy the opposite of the current state of the zero flag into a variable.
11960  
11961 Parameter Description
11962 1 $var Variable
11963  
11964 B<Example:>
11965  
11966  
11967 Mov r15, 1;
11968 my $z = V(zf);
11969 Cmp r15, 1; $z->copyZF; $z->outNL;
11970 Cmp r15, 2; $z->copyZF; $z->outNL;
11971 Cmp r15, 1; $z->copyZFInverted; $z->outNL;
11972 Cmp r15, 2; $z->copyZFInverted; $z->outNL;
11973  
11974 ok Assemble(debug => 0, eq => <<END);
11975 zf: 0000 0000 0000 0001
11976 zf: 0000 0000 0000 0000
11977 zf: 0000 0000 0000 0000
11978 zf: 0000 0000 0000 0001
11979 END
11980  
11981  
11982 =head3 Nasm::X86::Variable::equals($op, $left, $right)
11983  
11984 Equals operator.
11985  
11986 Parameter Description
11987 1 $op Operator
11988 2 $left Left variable
11989 3 $right Right variable
11990  
11991 =head3 Nasm::X86::Variable::assign($left, $op, $right)
11992  
11993 Assign to the left hand side the value of the right hand side.
11994  
11995 Parameter Description
11996 1 $left Left variable
11997 2 $op Operator
11998 3 $right Right variable
11999  
12000 =head3 Nasm::X86::Variable::plusAssign($left, $right)
12001  
12002 Implement plus and assign.
12003  
12004 Parameter Description
12005 1 $left Left variable
12006 2 $right Right variable
12007  
12008 =head3 Nasm::X86::Variable::minusAssign($left, $right)
12009  
12010 Implement minus and assign.
12011  
12012 Parameter Description
12013 1 $left Left variable
12014 2 $right Right variable
12015  
12016 =head3 Nasm::X86::Variable::arithmetic($op, $name, $left, $right)
12017  
12018 Return a variable containing the result of an arithmetic operation on the left hand and right hand side variables.
12019  
12020 Parameter Description
12021 1 $op Operator
12022 2 $name Operator name
12023 3 $left Left variable
12024 4 $right Right variable
12025  
12026 =head3 Nasm::X86::Variable::add($left, $right)
12027  
12028 Add the right hand variable to the left hand variable and return the result as a new variable.
12029  
12030 Parameter Description
12031 1 $left Left variable
12032 2 $right Right variable
12033  
12034 =head3 Nasm::X86::Variable::sub($left, $right)
12035  
12036 Subtract the right hand variable from the left hand variable and return the result as a new variable.
12037  
12038 Parameter Description
12039 1 $left Left variable
12040 2 $right Right variable
12041  
12042 =head3 Nasm::X86::Variable::times($left, $right)
12043  
12044 Multiply the left hand variable by the right hand variable and return the result as a new variable.
12045  
12046 Parameter Description
12047 1 $left Left variable
12048 2 $right Right variable
12049  
12050 =head3 Nasm::X86::Variable::division($op, $left, $right)
12051  
12052 Return a variable containing the result or the remainder that occurs when the left hand side is divided by the right hand side.
12053  
12054 Parameter Description
12055 1 $op Operator
12056 2 $left Left variable
12057 3 $right Right variable
12058  
12059 =head3 Nasm::X86::Variable::divide($left, $right)
12060  
12061 Divide the left hand variable by the right hand variable and return the result as a new variable.
12062  
12063 Parameter Description
12064 1 $left Left variable
12065 2 $right Right variable
12066  
12067 =head3 Nasm::X86::Variable::mod($left, $right)
12068  
12069 Divide the left hand variable by the right hand variable and return the remainder as a new variable.
12070  
12071 Parameter Description
12072 1 $left Left variable
12073 2 $right Right variable
12074  
12075 =head3 Nasm::X86::Variable::boolean($sub, $op, $left, $right)
12076  
12077 Combine the left hand variable with the right hand variable via a boolean operator.
12078  
12079 Parameter Description
12080 1 $sub Operator
12081 2 $op Operator name
12082 3 $left Left variable
12083 4 $right Right variable
12084  
12085 =head3 Nasm::X86::Variable::booleanZF($sub, $op, $left, $right)
12086  
12087 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.
12088  
12089 Parameter Description
12090 1 $sub Operator
12091 2 $op Operator name
12092 3 $left Left variable
12093 4 $right Right variable
12094  
12095 =head3 Nasm::X86::Variable::booleanC($cmov, $op, $left, $right)
12096  
12097 Combine the left hand variable with the right hand variable via a boolean operator using a conditional move instruction.
12098  
12099 Parameter Description
12100 1 $cmov Conditional move instruction name
12101 2 $op Operator name
12102 3 $left Left variable
12103 4 $right Right variable
12104  
12105 =head3 Nasm::X86::Variable::eq($left, $right)
12106  
12107 Check whether the left hand variable is equal to the right hand variable.
12108  
12109 Parameter Description
12110 1 $left Left variable
12111 2 $right Right variable
12112  
12113 =head3 Nasm::X86::Variable::ne($left, $right)
12114  
12115 Check whether the left hand variable is not equal to the right hand variable.
12116  
12117 Parameter Description
12118 1 $left Left variable
12119 2 $right Right variable
12120  
12121 =head3 Nasm::X86::Variable::ge($left, $right)
12122  
12123 Check whether the left hand variable is greater than or equal to the right hand variable.
12124  
12125 Parameter Description
12126 1 $left Left variable
12127 2 $right Right variable
12128  
12129 =head3 Nasm::X86::Variable::gt($left, $right)
12130  
12131 Check whether the left hand variable is greater than the right hand variable.
12132  
12133 Parameter Description
12134 1 $left Left variable
12135 2 $right Right variable
12136  
12137 =head3 Nasm::X86::Variable::le($left, $right)
12138  
12139 Check whether the left hand variable is less than or equal to the right hand variable.
12140  
12141 Parameter Description
12142 1 $left Left variable
12143 2 $right Right variable
12144  
12145 =head3 Nasm::X86::Variable::lt($left, $right)
12146  
12147 Check whether the left hand variable is less than the right hand variable.
12148  
12149 Parameter Description
12150 1 $left Left variable
12151 2 $right Right variable
12152  
12153 =head3 Nasm::X86::Variable::isRef($variable)
12154  
12155 Check whether the specified variable is a reference to another variable.
12156  
12157 Parameter Description
12158 1 $variable Variable
12159  
12160 =head3 Nasm::X86::Variable::setReg($variable, $register)
12161  
12162 Set the named registers from the content of the variable.
12163  
12164 Parameter Description
12165 1 $variable Variable
12166 2 $register Register to load
12167  
12168 =head3 Nasm::X86::Variable::getReg($variable, $register, @registers)
12169  
12170 Load the variable from the named registers.
12171  
12172 Parameter Description
12173 1 $variable Variable
12174 2 $register Register to load
12175 3 @registers Optional further registers to load from
12176  
12177 =head3 Nasm::X86::Variable::getConst($variable, $constant, $transfer)
12178  
12179 Load the variable from a constant in effect setting a variable to a specified value.
12180  
12181 Parameter Description
12182 1 $variable Variable
12183 2 $constant Constant to load
12184 3 $transfer Optional transfer register
12185  
12186 =head3 Nasm::X86::Variable::getConst22($variable, $constant)
12187  
12188 Load the variable from a constant in effect setting a variable to a specified value.
12189  
12190 Parameter Description
12191 1 $variable Variable
12192 2 $constant Constant to load
12193  
12194 =head3 Nasm::X86::Variable::incDec($left, $op)
12195  
12196 Increment or decrement a variable.
12197  
12198 Parameter Description
12199 1 $left Left variable operator
12200 2 $op Address of operator to perform inc or dec
12201  
12202 =head3 Nasm::X86::Variable::inc($left)
12203  
12204 Increment a variable.
12205  
12206 Parameter Description
12207 1 $left Variable
12208  
12209 =head3 Nasm::X86::Variable::dec($left)
12210  
12211 Decrement a variable.
12212  
12213 Parameter Description
12214 1 $left Variable
12215  
12216 =head3 Nasm::X86::Variable::str($left)
12217  
12218 The name of the variable.
12219  
12220 Parameter Description
12221 1 $left Variable
12222  
12223 =head3 Nasm::X86::Variable::min($left, $right)
12224  
12225 Minimum of two variables.
12226  
12227 Parameter Description
12228 1 $left Left variable
12229 2 $right Right variable or constant
12230  
12231 B<Example:>
12232  
12233  
12234 my $a = V("a", 1);
12235 my $b = V("b", 2);
12236 my $c = $a->min($b);
12237 my $d = $a->max($b);
12238 $a->outNL;
12239 $b->outNL;
12240 $c->outNL;
12241 $d->outNL;
12242  
12243 ok Assemble(debug => 0, eq => <<END);
12244 a: 0000 0000 0000 0001
12245 b: 0000 0000 0000 0002
12246 min: 0000 0000 0000 0001
12247 max: 0000 0000 0000 0002
12248 END
12249  
12250  
12251 =head3 Nasm::X86::Variable::max($left, $right)
12252  
12253 Maximum of two variables.
12254  
12255 Parameter Description
12256 1 $left Left variable
12257 2 $right Right variable or constant
12258  
12259 B<Example:>
12260  
12261  
12262 my $a = V("a", 1);
12263 my $b = V("b", 2);
12264 my $c = $a->min($b);
12265 my $d = $a->max($b);
12266 $a->outNL;
12267 $b->outNL;
12268 $c->outNL;
12269 $d->outNL;
12270  
12271 ok Assemble(debug => 0, eq => <<END);
12272 a: 0000 0000 0000 0001
12273 b: 0000 0000 0000 0002
12274 min: 0000 0000 0000 0001
12275 max: 0000 0000 0000 0002
12276 END
12277  
12278  
12279 =head3 Nasm::X86::Variable::and($left, $right)
12280  
12281 And two variables.
12282  
12283 Parameter Description
12284 1 $left Left variable
12285 2 $right Right variable
12286  
12287 =head3 Nasm::X86::Variable::or($left, $right)
12288  
12289 Or two variables.
12290  
12291 Parameter Description
12292 1 $left Left variable
12293 2 $right Right variable
12294  
12295 =head3 Nasm::X86::Variable::setMask($start, $length, $mask)
12296  
12297 Set the mask register to ones starting at the specified position for the specified length and zeroes elsewhere.
12298  
12299 Parameter Description
12300 1 $start Variable containing start of mask
12301 2 $length Variable containing length of mask
12302 3 $mask Mask register
12303  
12304 B<Example:>
12305  
12306  
12307 my $start = V("Start", 7);
12308 my $length = V("Length", 3);
12309 $start->setMask($length, k7);
12310 PrintOutRegisterInHex k7;
12311  
12312 ok Assemble(debug => 0, eq => <<END);
12313 k7: 0000 0000 0000 0380
12314 END
12315  
12316 my $z = V('zero', 0);
12317 my $o = V('one', 1);
12318 my $t = V('two', 2);
12319 $z->setMask($o, k7); PrintOutRegisterInHex k7;
12320 $z->setMask($t, k6); PrintOutRegisterInHex k6;
12321 $z->setMask($o+$t, k5); PrintOutRegisterInHex k5;
12322 $o->setMask($o, k4); PrintOutRegisterInHex k4;
12323 $o->setMask($t, k3); PrintOutRegisterInHex k3;
12324 $o->setMask($o+$t, k2); PrintOutRegisterInHex k2;
12325  
12326 $t->setMask($o, k1); PrintOutRegisterInHex k1;
12327 $t->setMask($t, k0); PrintOutRegisterInHex k0;
12328  
12329  
12330 ok Assemble(debug => 0, eq => <<END);
12331 k7: 0000 0000 0000 0001
12332 k6: 0000 0000 0000 0003
12333 k5: 0000 0000 0000 0007
12334 k4: 0000 0000 0000 0002
12335 k3: 0000 0000 0000 0006
12336 k2: 0000 0000 0000 000E
12337 k1: 0000 0000 0000 0004
12338 k0: 0000 0000 0000 000C
12339 END
12340  
12341  
12342 =head3 Nasm::X86::Variable::setMaskFirst($length, $mask)
12343  
12344 Set the first bits in the specified mask register.
12345  
12346 Parameter Description
12347 1 $length Variable containing length to set
12348 2 $mask Mask register
12349  
12350 =head3 Nasm::X86::Variable::setMaskBit($index, $mask)
12351  
12352 Set a bit in the specified mask register retaining the other bits.
12353  
12354 Parameter Description
12355 1 $index Variable containing bit position to set
12356 2 $mask Mask register
12357  
12358 =head3 Nasm::X86::Variable::clearMaskBit($index, $mask)
12359  
12360 Clear a bit in the specified mask register retaining the other bits.
12361  
12362 Parameter Description
12363 1 $index Variable containing bit position to clear
12364 2 $mask Mask register
12365  
12366 =head3 Nasm::X86::Variable::setBit($index, $mask)
12367  
12368 Set a bit in the specified register retaining the other bits.
12369  
12370 Parameter Description
12371 1 $index Variable containing bit position to set
12372 2 $mask Mask register
12373  
12374 =head3 Nasm::X86::Variable::clearBit($index, $mask)
12375  
12376 Clear a bit in the specified mask register retaining the other bits.
12377  
12378 Parameter Description
12379 1 $index Variable containing bit position to clear
12380 2 $mask Mask register
12381  
12382 =head3 Nasm::X86::Variable::setZmm($source, $zmm, $offset, $length)
12383  
12384 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.
12385  
12386 Parameter Description
12387 1 $source Variable containing the address of the source
12388 2 $zmm Number of zmm to load
12389 3 $offset Variable containing offset in zmm to move to
12390 4 $length Variable containing length of move
12391  
12392 B<Example:>
12393  
12394  
12395 my $s = Rb(0..128);
12396 my $source = V(Source, $s);
12397  
12398 if (1) # First block
12399 {my $offset = V(Offset, 7);
12400 my $length = V(Length, 3);
12401 $source->setZmm(0, $offset, $length);
12402 }
12403  
12404 if (1) # Second block
12405 {my $offset = V(Offset, 33);
12406 my $length = V(Length, 12);
12407 $source->setZmm(0, $offset, $length);
12408 }
12409  
12410 PrintOutRegisterInHex zmm0;
12411  
12412 ok Assemble(debug => 0, eq => <<END);
12413 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
12414 END
12415  
12416  
12417 =head3 Nasm::X86::Variable::loadZmm($source, $zmm)
12418  
12419 Load bytes from the memory addressed by the specified source variable into the numbered zmm register.
12420  
12421 Parameter Description
12422 1 $source Variable containing the address of the source
12423 2 $zmm Number of zmm to get
12424  
12425 =head3 loadFromZmm($register, $size, $zmm, $offset)
12426  
12427 Load the specified register from the offset located in the numbered zmm.
12428  
12429 Parameter Description
12430 1 $register Register to load
12431 2 $size "b|w|d|q" for size
12432 3 $zmm Numbered zmm register to load from
12433 4 $offset Constant offset in bytes
12434  
12435 =head3 putIntoZmm($register, $size, $zmm, $offset)
12436  
12437 Put the specified register into the numbered zmm at the specified offset in the zmm.
12438  
12439 Parameter Description
12440 1 $register Register to load
12441 2 $size Bwdq for size
12442 3 $zmm Numbered zmm register to load from
12443 4 $offset Constant offset in bytes
12444  
12445 =head3 LoadRegFromMm($mm, $offset, $reg)
12446  
12447 Load the specified register from the numbered zmm at the quad offset specified as a constant number.
12448  
12449 Parameter Description
12450 1 $mm Mm register
12451 2 $offset Offset in quads
12452 3 $reg General purpose register to load
12453  
12454 =head3 SaveRegIntoMm($mm, $offset, $reg)
12455  
12456 Save the specified register into the numbered zmm at the quad offset specified as a constant number.
12457  
12458 Parameter Description
12459 1 $mm Mm register
12460 2 $offset Offset in quads
12461 3 $reg General purpose register to load
12462  
12463 =head3 getBwdqFromMm($size, $mm, $offset, $Transfer, $target)
12464  
12465 Get the numbered byte|word|double word|quad word from the numbered zmm register and return it in a variable.
12466  
12467 Parameter Description
12468 1 $size Size of get
12469 2 $mm Mm register
12470 3 $offset Offset in bytes either as a constant or as a variable
12471 4 $Transfer Optional transfer register
12472 5 $target Optional target variable - if none supplied we create a variable
12473  
12474 =head3 getBFromXmm($xmm, $offset)
12475  
12476 Get the byte from the numbered xmm register and return it in a variable.
12477  
12478 Parameter Description
12479 1 $xmm Numbered xmm
12480 2 $offset Offset in bytes
12481  
12482 =head3 getWFromXmm($xmm, $offset)
12483  
12484 Get the word from the numbered xmm register and return it in a variable.
12485  
12486 Parameter Description
12487 1 $xmm Numbered xmm
12488 2 $offset Offset in bytes
12489  
12490 =head3 getDFromXmm($xmm, $offset)
12491  
12492 Get the double word from the numbered xmm register and return it in a variable.
12493  
12494 Parameter Description
12495 1 $xmm Numbered xmm
12496 2 $offset Offset in bytes
12497  
12498 =head3 getQFromXmm($xmm, $offset)
12499  
12500 Get the quad word from the numbered xmm register and return it in a variable.
12501  
12502 Parameter Description
12503 1 $xmm Numbered xmm
12504 2 $offset Offset in bytes
12505  
12506 =head3 getBFromZmm($zmm, $offset)
12507  
12508 Get the byte from the numbered zmm register and return it in a variable.
12509  
12510 Parameter Description
12511 1 $zmm Numbered zmm
12512 2 $offset Offset in bytes
12513  
12514 =head3 getWFromZmm($zmm, $offset)
12515  
12516 Get the word from the numbered zmm register and return it in a variable.
12517  
12518 Parameter Description
12519 1 $zmm Numbered zmm
12520 2 $offset Offset in bytes
12521  
12522 =head3 getDFromZmm($zmm, $offset, $transfer)
12523  
12524 Get the double word from the numbered zmm register and return it in a variable.
12525  
12526 Parameter Description
12527 1 $zmm Numbered zmm
12528 2 $offset Offset in bytes
12529 3 $transfer Optional transfer register
12530  
12531 B<Example:>
12532  
12533  
12534 my $s = Rb(0..8);
12535 my $c = V("Content", "[$s]");
12536 $c->putBIntoZmm(0, 4);
12537 $c->putWIntoZmm(0, 6);
12538 $c->putDIntoZmm(0, 10);
12539 $c->putQIntoZmm(0, 16);
12540 PrintOutRegisterInHex zmm0;
12541 getBFromZmm(0, 12)->outNL;
12542 getWFromZmm(0, 12)->outNL;
12543  
12544 getDFromZmm(0, 12, r15)->outNL; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
12545  
12546 getQFromZmm(0, 12)->outNL;
12547  
12548 ok Assemble(debug => 0, eq => <<END);
12549 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
12550 b at offset 12 in zmm0: 0000 0000 0000 0002
12551 w at offset 12 in zmm0: 0000 0000 0000 0302
12552 d at offset 12 in zmm0: 0000 0000 0000 0302
12553 q at offset 12 in zmm0: 0302 0100 0000 0302
12554 END
12555  
12556  
12557 =head3 getQFromZmm($zmm, $offset)
12558  
12559 Get the quad word from the numbered zmm register and return it in a variable.
12560  
12561 Parameter Description
12562 1 $zmm Numbered zmm
12563 2 $offset Offset in bytes
12564  
12565 =head3 Nasm::X86::Variable::getBFromZmm($variable, $zmm, $offset)
12566  
12567 Get the byte from the numbered zmm register and put it in a variable.
12568  
12569 Parameter Description
12570 1 $variable Variable
12571 2 $zmm Numbered zmm
12572 3 $offset Offset in bytes
12573  
12574 =head3 Nasm::X86::Variable::getWFromZmm($variable, $zmm, $offset)
12575  
12576 Get the word from the numbered zmm register and put it in a variable.
12577  
12578 Parameter Description
12579 1 $variable Variable
12580 2 $zmm Numbered zmm
12581 3 $offset Offset in bytes
12582  
12583 =head3 Nasm::X86::Variable::getDFromZmm($variable, $zmm, $offset, $transfer)
12584  
12585 Get the double word from the numbered zmm register and put it in a variable.
12586  
12587 Parameter Description
12588 1 $variable Variable
12589 2 $zmm Numbered zmm
12590 3 $offset Offset in bytes
12591 4 $transfer Transfer register
12592  
12593 =head3 Nasm::X86::Variable::getQFromZmm($variable, $zmm, $offset)
12594  
12595 Get the quad word from the numbered zmm register and put it in a variable.
12596  
12597 Parameter Description
12598 1 $variable Variable
12599 2 $zmm Numbered zmm
12600 3 $offset Offset in bytes
12601  
12602 =head3 Nasm::X86::Variable::putBwdqIntoMm($content, $size, $mm, $offset, $Transfer)
12603  
12604 Place the value of the content variable at the byte|word|double word|quad word in the numbered zmm register.
12605  
12606 Parameter Description
12607 1 $content Variable with content
12608 2 $size Size of put
12609 3 $mm Numbered zmm
12610 4 $offset Offset in bytes
12611 5 $Transfer Optional transfer register
12612  
12613 =head3 Nasm::X86::Variable::putBIntoXmm($content, $xmm, $offset)
12614  
12615 Place the value of the content variable at the byte in the numbered xmm register.
12616  
12617 Parameter Description
12618 1 $content Variable with content
12619 2 $xmm Numbered xmm
12620 3 $offset Offset in bytes
12621  
12622 =head3 Nasm::X86::Variable::putWIntoXmm($content, $xmm, $offset)
12623  
12624 Place the value of the content variable at the word in the numbered xmm register.
12625  
12626 Parameter Description
12627 1 $content Variable with content
12628 2 $xmm Numbered xmm
12629 3 $offset Offset in bytes
12630  
12631 =head3 Nasm::X86::Variable::putDIntoXmm($content, $xmm, $offset)
12632  
12633 Place the value of the content variable at the double word in the numbered xmm register.
12634  
12635 Parameter Description
12636 1 $content Variable with content
12637 2 $xmm Numbered xmm
12638 3 $offset Offset in bytes
12639  
12640 =head3 Nasm::X86::Variable::putQIntoXmm($content, $xmm, $offset)
12641  
12642 Place the value of the content variable at the quad word in the numbered xmm register.
12643  
12644 Parameter Description
12645 1 $content Variable with content
12646 2 $xmm Numbered xmm
12647 3 $offset Offset in bytes
12648  
12649 =head3 Nasm::X86::Variable::putBIntoZmm($content, $zmm, $offset)
12650  
12651 Place the value of the content variable at the byte in the numbered zmm register.
12652  
12653 Parameter Description
12654 1 $content Variable with content
12655 2 $zmm Numbered zmm
12656 3 $offset Offset in bytes
12657  
12658 =head3 Nasm::X86::Variable::putWIntoZmm($content, $zmm, $offset)
12659  
12660 Place the value of the content variable at the word in the numbered zmm register.
12661  
12662 Parameter Description
12663 1 $content Variable with content
12664 2 $zmm Numbered zmm
12665 3 $offset Offset in bytes
12666  
12667 =head3 Nasm::X86::Variable::putDIntoZmm($content, $zmm, $offset, $transfer)
12668  
12669 Place the value of the content variable at the double word in the numbered zmm register.
12670  
12671 Parameter Description
12672 1 $content Variable with content
12673 2 $zmm Numbered zmm
12674 3 $offset Offset in bytes
12675 4 $transfer Optional transfer register
12676  
12677 B<Example:>
12678  
12679  
12680 my $s = Rb(0..8);
12681 my $c = V("Content", "[$s]");
12682 $c->putBIntoZmm(0, 4);
12683 $c->putWIntoZmm(0, 6);
12684 $c->putDIntoZmm(0, 10);
12685 $c->putQIntoZmm(0, 16);
12686 PrintOutRegisterInHex zmm0;
12687 getBFromZmm(0, 12)->outNL;
12688 getWFromZmm(0, 12)->outNL;
12689 getDFromZmm(0, 12, r15)->outNL;
12690 getQFromZmm(0, 12)->outNL;
12691  
12692 ok Assemble(debug => 0, eq => <<END);
12693 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
12694 b at offset 12 in zmm0: 0000 0000 0000 0002
12695 w at offset 12 in zmm0: 0000 0000 0000 0302
12696 d at offset 12 in zmm0: 0000 0000 0000 0302
12697 q at offset 12 in zmm0: 0302 0100 0000 0302
12698 END
12699  
12700  
12701 =head3 Nasm::X86::Variable::putQIntoZmm($content, $zmm, $offset, $transfer)
12702  
12703 Place the value of the content variable at the quad word in the numbered zmm register.
12704  
12705 Parameter Description
12706 1 $content Variable with content
12707 2 $zmm Numbered zmm
12708 3 $offset Offset in bytes
12709 4 $transfer Optional transfer register
12710  
12711 =head2 Broadcast
12712  
12713 Broadcast from a variable into a zmm
12714  
12715 =head3 Nasm::X86::Variable::zBroadCastD($variable, $zmm)
12716  
12717 Broadcast a double word in a variable into the numbered zmm.
12718  
12719 Parameter Description
12720 1 $variable Variable containing value to broadcast
12721 2 $zmm Numbered zmm to broadcast to
12722  
12723 =head2 Stack
12724  
12725 Push and pop variables to and from the stack
12726  
12727 =head3 Nasm::X86::Variable::push($variable)
12728  
12729 Push a variable onto the stack.
12730  
12731 Parameter Description
12732 1 $variable Variable
12733  
12734 =head3 Nasm::X86::Variable::pop($variable)
12735  
12736 Pop a variable from the stack.
12737  
12738 Parameter Description
12739 1 $variable Variable
12740  
12741 =head2 Memory
12742  
12743 Actions on memory described by variables
12744  
12745 =head3 Nasm::X86::Variable::clearMemory($address, $size)
12746  
12747 Clear the memory described in this variable.
12748  
12749 Parameter Description
12750 1 $address Address of memory to clear
12751 2 $size Size of the memory to clear
12752  
12753 =head3 Nasm::X86::Variable::copyMemory($target, $source, $size)
12754  
12755 Copy from one block of memory to another.
12756  
12757 Parameter Description
12758 1 $target Address of target
12759 2 $source Address of source
12760 3 $size Length to copy
12761  
12762 =head3 Nasm::X86::Variable::printMemoryInHexNL($address, $channel, $size)
12763  
12764 Write, in hexadecimal, the memory addressed by a variable to stdout or stderr.
12765  
12766 Parameter Description
12767 1 $address Address of memory
12768 2 $channel Channel to print on
12769 3 $size Number of bytes to print
12770  
12771 =head3 Nasm::X86::Variable::printErrMemoryInHexNL($address, $size)
12772  
12773 Write the memory addressed by a variable to stderr.
12774  
12775 Parameter Description
12776 1 $address Address of memory
12777 2 $size Number of bytes to print
12778  
12779 =head3 Nasm::X86::Variable::printOutMemoryInHexNL($address, $size)
12780  
12781 Write the memory addressed by a variable to stdout.
12782  
12783 Parameter Description
12784 1 $address Address of memory
12785 2 $size Number of bytes to print
12786  
12787 B<Example:>
12788  
12789  
12790 my $u = Rd(ord('𝝰'), ord('𝝱'), ord('𝝲'), ord('𝝳'));
12791 Mov rax, $u;
12792 my $address = V(address)->getReg(rax);
12793 $address->printOutMemoryInHexNL(K(size, 16));
12794  
12795 ok Assemble(debug => 0, trace => 0, eq => <<END);
12796 70D7 0100 71D7 010072D7 0100 73D7 0100
12797 END
12798  
12799 my $v = V(var, 2);
12800  
12801 If $v == 0, Then {Mov rax, 0},
12802 Ef {$v == 1} Then {Mov rax, 1},
12803 Ef {$v == 2} Then {Mov rax, 2},
12804 Else {Mov rax, 3};
12805 PrintOutRegisterInHex rax;
12806 ok Assemble(debug => 0, trace => 0, eq => <<END);
12807 rax: 0000 0000 0000 0002
12808 END
12809  
12810  
12811 =head3 Nasm::X86::Variable::freeMemory($address, $size)
12812  
12813 Free the memory addressed by this variable for the specified length.
12814  
12815 Parameter Description
12816 1 $address Address of memory to free
12817 2 $size Size of the memory to free
12818  
12819 B<Example:>
12820  
12821  
12822 my $N = V(size, 2048);
12823 my $q = Rs('a'..'p');
12824 AllocateMemory($N, my $address = V(address));
12825  
12826 Vmovdqu8 xmm0, "[$q]";
12827 $address->setReg(rax);
12828 Vmovdqu8 "[rax]", xmm0;
12829 Mov rdi, 16;
12830 PrintOutMemory;
12831 PrintOutNL;
12832  
12833 FreeMemory(address => $address, size=> $N);
12834  
12835 ok Assemble(debug => 0, eq => <<END);
12836 abcdefghijklmnop
12837 END
12838  
12839  
12840 =head3 Nasm::X86::Variable::allocateMemory($size)
12841  
12842 Allocate the specified amount of memory via mmap and return its address.
12843  
12844 Parameter Description
12845 1 $size Size
12846  
12847 =head2 Structured Programming with variables
12848  
12849 Structured programming operations driven off variables.
12850  
12851 =head3 Nasm::X86::Variable::for($limit, $block)
12852  
12853 Iterate the block limit times.
12854  
12855 Parameter Description
12856 1 $limit Limit
12857 2 $block Block
12858  
12859 B<Example:>
12860  
12861  
12862 V(limit,10)->for(sub
12863 {my ($i, $start, $next, $end) = @_;
12864 $i->outNL;
12865 });
12866  
12867 ok Assemble(debug => 0, eq => <<END);
12868 index: 0000 0000 0000 0000
12869 index: 0000 0000 0000 0001
12870 index: 0000 0000 0000 0002
12871 index: 0000 0000 0000 0003
12872 index: 0000 0000 0000 0004
12873 index: 0000 0000 0000 0005
12874 index: 0000 0000 0000 0006
12875 index: 0000 0000 0000 0007
12876 index: 0000 0000 0000 0008
12877 index: 0000 0000 0000 0009
12878 END
12879  
12880  
12881 =head1 Stack
12882  
12883 Manage data on the stack
12884  
12885 =head2 Push, Pop, Peek
12886  
12887 Generic versions of push, pop, peek
12888  
12889 =head3 PopR(@r)
12890  
12891 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.
12892  
12893 Parameter Description
12894 1 @r Register
12895  
12896 B<Example:>
12897  
12898  
12899 Mov rax, 0x11111111;
12900 Mov rbx, 0x22222222;
12901 PushR my @save = (rax, rbx);
12902 Mov rax, 0x33333333;
12903  
12904 PopR; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
12905  
12906 PrintOutRegisterInHex rax;
12907 PrintOutRegisterInHex rbx;
12908  
12909 ok Assemble(debug => 0, eq => <<END);
12910 rax: 0000 0000 1111 1111
12911 rbx: 0000 0000 2222 2222
12912 END
12913  
12914  
12915 =head3 PopEax()
12916  
12917 We cannot pop a double word from the stack in 64 bit long mode using pop so we improvise.
12918  
12919  
12920 B<Example:>
12921  
12922  
12923 Mov r14, 0;
12924 Kmovq k0, r14;
12925 Ktestq k0, k0;
12926 IfZ Then {PrintOutStringNL "0 & 0 == 0"};
12927 PrintOutZF;
12928  
12929 LoadConstantIntoMaskRegister k1, r13, 1;
12930 Ktestq k1, k1;
12931 IfNz Then {PrintOutStringNL "1 & 1 != 0"};
12932 PrintOutZF;
12933  
12934 LoadConstantIntoMaskRegister k2, r13, eval "0b".(('1'x4).('0'x4))x2;
12935  
12936 PrintOutRegisterInHex k0, k1, k2;
12937  
12938 Mov r15, 0x89abcdef;
12939 Mov r14, 0x01234567;
12940 Shl r14, 32;
12941 Or r15, r14;
12942 Push r15;
12943 Push r15;
12944  
12945 PopEax; PrintRaxInHex($stdout, 3); PrintOutNL; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
12946  
12947  
12948 my $a = V('aaaa');
12949 $a->pop;
12950 $a->push;
12951 $a->outNL;
12952  
12953  
12954 PopEax; PrintRaxInHex($stdout, 3); PrintOutNL; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
12955  
12956  
12957 ok Assemble(debug => 0, eq => <<END);
12958 0 & 0 == 0
12959 ZF=1
12960 1 & 1 != 0
12961 ZF=0
12962 k0: 0000 0000 0000 0000
12963 k1: 0000 0000 0000 0001
12964 k2: 0000 0000 0000 F0F0
12965 89AB CDEF
12966 aaaa: 89AB CDEF 0123 4567
12967 0123 4567
12968 END
12969  
12970  
12971 =head3 PeekR($r)
12972  
12973 Peek at register on stack.
12974  
12975 Parameter Description
12976 1 $r Register
12977  
12978 =head3 PushZmm(@Z)
12979  
12980 Push several zmm registers.
12981  
12982 Parameter Description
12983 1 @Z Zmm register numbers
12984  
12985 =head3 PopZmm()
12986  
12987 Pop zmm registers.
12988  
12989  
12990 =head3 PushMask(@M)
12991  
12992 Push several Mask registers.
12993  
12994 Parameter Description
12995 1 @M Mask register numbers
12996  
12997 =head3 PopMask()
12998  
12999 Pop Mask registers.
13000  
13001  
13002 =head2 Declarations
13003  
13004 Declare variables and structures
13005  
13006 =head3 Structures
13007  
13008 Declare a structure
13009  
13010 =head4 Structure()
13011  
13012 Create a structure addressed by a register.
13013  
13014  
13015 =head4 Nasm::X86::Structure::field($structure, $length, $comment)
13016  
13017 Add a field of the specified length with an optional comment.
13018  
13019 Parameter Description
13020 1 $structure Structure data descriptor
13021 2 $length Length of data
13022 3 $comment Optional comment
13023  
13024 =head4 Nasm::X86::StructureField::addr($field, $register)
13025  
13026 Address a field in a structure by either the default register or the named register.
13027  
13028 Parameter Description
13029 1 $field Field
13030 2 $register Optional address register else rax
13031  
13032 =head4 All8Structure($N)
13033  
13034 Create a structure consisting of 8 byte fields.
13035  
13036 Parameter Description
13037 1 $N Number of variables required
13038  
13039 =head3 Stack Frame
13040  
13041 Declare local variables in a frame on the stack
13042  
13043 =head4 LocalData()
13044  
13045 Map local data.
13046  
13047  
13048 =head4 Nasm::X86::LocalData::start($local)
13049  
13050 Start a local data area on the stack.
13051  
13052 Parameter Description
13053 1 $local Local data descriptor
13054  
13055 =head4 Nasm::X86::LocalData::free($local)
13056  
13057 Free a local data area on the stack.
13058  
13059 Parameter Description
13060 1 $local Local data descriptor
13061  
13062 =head4 Nasm::X86::LocalData::variable($local, $length, $comment)
13063  
13064 Add a local variable.
13065  
13066 Parameter Description
13067 1 $local Local data descriptor
13068 2 $length Length of data
13069 3 $comment Optional comment
13070  
13071 =head4 Nasm::X86::LocalVariable::stack($variable)
13072  
13073 Address a local variable on the stack.
13074  
13075 Parameter Description
13076 1 $variable Variable
13077  
13078 =head4 Nasm::X86::LocalData::allocate8($local, @comments)
13079  
13080 Add some 8 byte local variables and return an array of variable definitions.
13081  
13082 Parameter Description
13083 1 $local Local data descriptor
13084 2 @comments Optional comment
13085  
13086 =head4 AllocateAll8OnStack($N)
13087  
13088 Create a local data descriptor consisting of the specified number of 8 byte local variables and return an array: (local data descriptor, variable definitions...).
13089  
13090 Parameter Description
13091 1 $N Number of variables required
13092  
13093 =head1 Operating system
13094  
13095 Interacting with the operating system.
13096  
13097 =head2 Processes
13098  
13099 Create and manage processes
13100  
13101 =head3 Fork()
13102  
13103 Fork.
13104  
13105  
13106 B<Example:>
13107  
13108  
13109  
13110 Fork; # Fork # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13111  
13112  
13113 Test rax,rax;
13114 IfNz # Parent
13115 Then
13116 {Mov rbx, rax;
13117 WaitPid;
13118 GetPid; # Pid of parent as seen in parent
13119 Mov rcx,rax;
13120 PrintOutRegisterInHex rax, rbx, rcx;
13121 },
13122 Else # Child
13123 {Mov r8,rax;
13124 GetPid; # Child pid as seen in child
13125 Mov r9,rax;
13126 GetPPid; # Parent pid as seen in child
13127 Mov r10,rax;
13128 PrintOutRegisterInHex r8, r9, r10;
13129 };
13130  
13131 my $r = Assemble;
13132  
13133 # r8: 0000 0000 0000 0000 #1 Return from fork as seen by child
13134 # r9: 0000 0000 0003 0C63 #2 Pid of child
13135 # r10: 0000 0000 0003 0C60 #3 Pid of parent from child
13136 # rax: 0000 0000 0003 0C63 #4 Return from fork as seen by parent
13137 # rbx: 0000 0000 0003 0C63 #5 Wait for child pid result
13138 # rcx: 0000 0000 0003 0C60 #6 Pid of parent
13139  
13140 if ($r =~ m(r8:( 0000){4}.*r9:(.*)\s{5,}r10:(.*)\s{5,}rax:(.*)\s{5,}rbx:(.*)\s{5,}rcx:(.*)\s{2,})s)
13141 {ok $2 eq $4;
13142 ok $2 eq $5;
13143 ok $3 eq $6;
13144 ok $2 gt $6;
13145 }
13146  
13147  
13148 =head3 GetPid()
13149  
13150 Get process identifier.
13151  
13152  
13153 B<Example:>
13154  
13155  
13156 Fork; # Fork
13157  
13158 Test rax,rax;
13159 IfNz # Parent
13160 Then
13161 {Mov rbx, rax;
13162 WaitPid;
13163  
13164 GetPid; # Pid of parent as seen in parent # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13165  
13166 Mov rcx,rax;
13167 PrintOutRegisterInHex rax, rbx, rcx;
13168 },
13169 Else # Child
13170 {Mov r8,rax;
13171  
13172 GetPid; # Child pid as seen in child # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13173  
13174 Mov r9,rax;
13175 GetPPid; # Parent pid as seen in child
13176 Mov r10,rax;
13177 PrintOutRegisterInHex r8, r9, r10;
13178 };
13179  
13180 my $r = Assemble;
13181  
13182 # r8: 0000 0000 0000 0000 #1 Return from fork as seen by child
13183 # r9: 0000 0000 0003 0C63 #2 Pid of child
13184 # r10: 0000 0000 0003 0C60 #3 Pid of parent from child
13185 # rax: 0000 0000 0003 0C63 #4 Return from fork as seen by parent
13186 # rbx: 0000 0000 0003 0C63 #5 Wait for child pid result
13187 # rcx: 0000 0000 0003 0C60 #6 Pid of parent
13188  
13189 if ($r =~ m(r8:( 0000){4}.*r9:(.*)\s{5,}r10:(.*)\s{5,}rax:(.*)\s{5,}rbx:(.*)\s{5,}rcx:(.*)\s{2,})s)
13190 {ok $2 eq $4;
13191 ok $2 eq $5;
13192 ok $3 eq $6;
13193 ok $2 gt $6;
13194 }
13195  
13196  
13197 =head3 GetPidInHex()
13198  
13199 Get process identifier in hex as 8 zero terminated bytes in rax.
13200  
13201  
13202 B<Example:>
13203  
13204  
13205  
13206 GetPidInHex; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13207  
13208 PrintOutRegisterInHex rax;
13209  
13210 ok Assemble =~ m(rax: 00);
13211  
13212  
13213 =head3 GetPPid()
13214  
13215 Get parent process identifier.
13216  
13217  
13218 B<Example:>
13219  
13220  
13221 Fork; # Fork
13222  
13223 Test rax,rax;
13224 IfNz # Parent
13225 Then
13226 {Mov rbx, rax;
13227 WaitPid;
13228 GetPid; # Pid of parent as seen in parent
13229 Mov rcx,rax;
13230 PrintOutRegisterInHex rax, rbx, rcx;
13231 },
13232 Else # Child
13233 {Mov r8,rax;
13234 GetPid; # Child pid as seen in child
13235 Mov r9,rax;
13236  
13237 GetPPid; # Parent pid as seen in child # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13238  
13239 Mov r10,rax;
13240 PrintOutRegisterInHex r8, r9, r10;
13241 };
13242  
13243 my $r = Assemble;
13244  
13245 # r8: 0000 0000 0000 0000 #1 Return from fork as seen by child
13246 # r9: 0000 0000 0003 0C63 #2 Pid of child
13247 # r10: 0000 0000 0003 0C60 #3 Pid of parent from child
13248 # rax: 0000 0000 0003 0C63 #4 Return from fork as seen by parent
13249 # rbx: 0000 0000 0003 0C63 #5 Wait for child pid result
13250 # rcx: 0000 0000 0003 0C60 #6 Pid of parent
13251  
13252 if ($r =~ m(r8:( 0000){4}.*r9:(.*)\s{5,}r10:(.*)\s{5,}rax:(.*)\s{5,}rbx:(.*)\s{5,}rcx:(.*)\s{2,})s)
13253 {ok $2 eq $4;
13254 ok $2 eq $5;
13255 ok $3 eq $6;
13256 ok $2 gt $6;
13257 }
13258  
13259  
13260 =head3 GetUid()
13261  
13262 Get userid of current process.
13263  
13264  
13265 B<Example:>
13266  
13267  
13268  
13269 GetUid; # Userid # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13270  
13271 PrintOutRegisterInHex rax;
13272  
13273 my $r = Assemble;
13274 ok $r =~ m(rax:( 0000){3});
13275  
13276  
13277 =head3 WaitPid()
13278  
13279 Wait for the pid in rax to complete.
13280  
13281  
13282 B<Example:>
13283  
13284  
13285 Fork; # Fork
13286  
13287 Test rax,rax;
13288 IfNz # Parent
13289 Then
13290 {Mov rbx, rax;
13291  
13292 WaitPid; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13293  
13294 GetPid; # Pid of parent as seen in parent
13295 Mov rcx,rax;
13296 PrintOutRegisterInHex rax, rbx, rcx;
13297 },
13298 Else # Child
13299 {Mov r8,rax;
13300 GetPid; # Child pid as seen in child
13301 Mov r9,rax;
13302 GetPPid; # Parent pid as seen in child
13303 Mov r10,rax;
13304 PrintOutRegisterInHex r8, r9, r10;
13305 };
13306  
13307 my $r = Assemble;
13308  
13309 # r8: 0000 0000 0000 0000 #1 Return from fork as seen by child
13310 # r9: 0000 0000 0003 0C63 #2 Pid of child
13311 # r10: 0000 0000 0003 0C60 #3 Pid of parent from child
13312 # rax: 0000 0000 0003 0C63 #4 Return from fork as seen by parent
13313 # rbx: 0000 0000 0003 0C63 #5 Wait for child pid result
13314 # rcx: 0000 0000 0003 0C60 #6 Pid of parent
13315  
13316 if ($r =~ m(r8:( 0000){4}.*r9:(.*)\s{5,}r10:(.*)\s{5,}rax:(.*)\s{5,}rbx:(.*)\s{5,}rcx:(.*)\s{2,})s)
13317 {ok $2 eq $4;
13318 ok $2 eq $5;
13319 ok $3 eq $6;
13320 ok $2 gt $6;
13321 }
13322  
13323  
13324 =head3 ReadTimeStampCounter()
13325  
13326 Read the time stamp counter and return the time in nanoseconds in rax.
13327  
13328  
13329 B<Example:>
13330  
13331  
13332 for(1..10)
13333  
13334 {ReadTimeStampCounter; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13335  
13336 PrintOutRegisterInHex rax;
13337 }
13338  
13339 my @s = split /
13340 /, Assemble;
13341 my @S = sort @s;
13342 is_deeply \@s, \@S;
13343  
13344  
13345 =head2 Memory
13346  
13347 Allocate and print memory
13348  
13349 =head3 PrintMemoryInHex($channel)
13350  
13351 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 .
13352  
13353 Parameter Description
13354 1 $channel Channel
13355  
13356 =head3 PrintErrMemoryInHex()
13357  
13358 Dump memory from the address in rax for the length in rdi on stderr.
13359  
13360  
13361 =head3 PrintOutMemoryInHex()
13362  
13363 Dump memory from the address in rax for the length in rdi on stdout.
13364  
13365  
13366 B<Example:>
13367  
13368  
13369 Mov rax, 0x07654321;
13370 Shl rax, 32;
13371 Or rax, 0x07654321;
13372 PushR rax;
13373  
13374 PrintOutRaxInHex;
13375 PrintOutNL;
13376 PrintOutRaxInReverseInHex;
13377 PrintOutNL;
13378  
13379 Mov rax, rsp;
13380 Mov rdi, 8;
13381  
13382 PrintOutMemoryInHex; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13383  
13384 PrintOutNL;
13385 PopR rax;
13386  
13387 Mov rax, 4096;
13388 PushR rax;
13389 Mov rax, rsp;
13390 Mov rdi, 8;
13391  
13392 PrintOutMemoryInHex; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13393  
13394 PrintOutNL;
13395 PopR rax;
13396  
13397 ok Assemble(debug => 0, eq => <<END);
13398 0765 4321 0765 4321
13399 2143 6507 2143 6507
13400 2143 6507 2143 6507
13401 0010 0000 0000 0000
13402 END
13403  
13404  
13405 =head3 PrintErrMemoryInHexNL()
13406  
13407 Dump memory from the address in rax for the length in rdi and then print a new line.
13408  
13409  
13410 =head3 PrintOutMemoryInHexNL()
13411  
13412 Dump memory from the address in rax for the length in rdi and then print a new line.
13413  
13414  
13415 B<Example:>
13416  
13417  
13418 my $N = 256;
13419 my $s = Rb 0..$N-1;
13420 AllocateMemory(K(size, $N), my $a = V(address));
13421 CopyMemory(V(source, $s), V(size, $N), target => $a);
13422  
13423 AllocateMemory(K(size, $N), my $b = V(address));
13424 CopyMemory(source => $a, target => $b, K(size, $N));
13425  
13426 $b->setReg(rax);
13427 Mov rdi, $N;
13428  
13429 PrintOutMemoryInHexNL; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13430  
13431  
13432 ok Assemble(debug=>0, eq => <<END);
13433 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
13434 END
13435  
13436  
13437 =head3 PrintMemory($channel)
13438  
13439 Print the memory addressed by rax for a length of rdi on the specified channel.
13440  
13441 Parameter Description
13442 1 $channel Channel
13443  
13444 B<Example:>
13445  
13446  
13447 my $file = G(file, Rs($0));
13448 my $size = G(size);
13449 my $address = G(address);
13450 ReadFile $file, $size, $address; # Read file
13451 $address->setReg(rax); # Address of file in memory
13452 $size ->setReg(rdi); # Length of file in memory
13453 PrintOutMemory; # Print contents of memory to stdout
13454  
13455 my $r = Assemble; # Assemble and execute
13456 ok stringMd5Sum($r) eq fileMd5Sum($0); # Output contains this file
13457  
13458  
13459 =head3 PrintMemoryNL()
13460  
13461 Print the memory addressed by rax for a length of rdi on the specified channel followed by a new line.
13462  
13463  
13464 =head3 PrintErrMemory()
13465  
13466 Print the memory addressed by rax for a length of rdi on stderr.
13467  
13468  
13469 =head3 PrintOutMemory()
13470  
13471 Print the memory addressed by rax for a length of rdi on stdout.
13472  
13473  
13474 B<Example:>
13475  
13476  
13477 Comment "Print a string from memory";
13478 my $s = "Hello World";
13479 Mov rax, Rs($s);
13480 Mov rdi, length $s;
13481  
13482 PrintOutMemory; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13483  
13484 Exit(0);
13485  
13486 ok Assemble =~ m(Hello World);
13487  
13488  
13489 =head3 PrintErrMemoryNL()
13490  
13491 Print the memory addressed by rax for a length of rdi followed by a new line on stderr.
13492  
13493  
13494 =head3 PrintOutMemoryNL()
13495  
13496 Print the memory addressed by rax for a length of rdi followed by a new line on stdout.
13497  
13498  
13499 B<Example:>
13500  
13501  
13502 my $s = Rs("Hello World
13503  
13504 Hello Skye");
13505 Mov rax, $s;
13506 Cstrlen;
13507 Mov rdi, r15;
13508  
13509 PrintOutMemoryNL; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13510  
13511  
13512 ok Assemble(debug => 0, eq => <<END);
13513 Hello World
13514  
13515 Hello Skye
13516 END
13517  
13518  
13519 =head3 AllocateMemory(@variables)
13520  
13521 Allocate the specified amount of memory via mmap and return its address.
13522  
13523 Parameter Description
13524 1 @variables Parameters
13525  
13526 B<Example:>
13527  
13528  
13529 my $N = V(size, 2048);
13530 my $q = Rs('a'..'p');
13531  
13532 AllocateMemory($N, my $address = V(address)); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13533  
13534  
13535 Vmovdqu8 xmm0, "[$q]";
13536 $address->setReg(rax);
13537 Vmovdqu8 "[rax]", xmm0;
13538 Mov rdi, 16;
13539 PrintOutMemory;
13540 PrintOutNL;
13541  
13542 FreeMemory(address => $address, size=> $N);
13543  
13544 ok Assemble(debug => 0, eq => <<END);
13545 abcdefghijklmnop
13546 END
13547  
13548 my $N = V(size, 4096); # Size of the initial allocation which should be one or more pages
13549  
13550  
13551 AllocateMemory($N, my $A = V(address)); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13552  
13553  
13554 ClearMemory($N, $A);
13555  
13556 $A->setReg(rax);
13557 Mov rdi, 128;
13558 PrintOutMemoryInHexNL;
13559  
13560 FreeMemory($N, $A);
13561  
13562 ok Assemble(debug => 1, eq => <<END);
13563 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
13564 END
13565  
13566 my $N = 256;
13567 my $s = Rb 0..$N-1;
13568  
13569 AllocateMemory(K(size, $N), my $a = V(address)); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13570  
13571 CopyMemory(V(source, $s), V(size, $N), target => $a);
13572  
13573  
13574 AllocateMemory(K(size, $N), my $b = V(address)); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13575  
13576 CopyMemory(source => $a, target => $b, K(size, $N));
13577  
13578 $b->setReg(rax);
13579 Mov rdi, $N;
13580 PrintOutMemoryInHexNL;
13581  
13582 ok Assemble(debug=>0, eq => <<END);
13583 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
13584 END
13585  
13586  
13587 =head3 FreeMemory(@variables)
13588  
13589 Free memory.
13590  
13591 Parameter Description
13592 1 @variables Variables
13593  
13594 B<Example:>
13595  
13596  
13597 my $N = V(size, 4096); # Size of the initial allocation which should be one or more pages
13598  
13599 AllocateMemory($N, my $A = V(address));
13600  
13601 ClearMemory($N, $A);
13602  
13603 $A->setReg(rax);
13604 Mov rdi, 128;
13605 PrintOutMemoryInHexNL;
13606  
13607  
13608 FreeMemory($N, $A); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13609  
13610  
13611 ok Assemble(debug => 1, eq => <<END);
13612 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
13613 END
13614  
13615  
13616 =head3 ClearMemory(@variables)
13617  
13618 Clear memory.
13619  
13620 Parameter Description
13621 1 @variables Variables
13622  
13623 B<Example:>
13624  
13625  
13626 K(loop, 8+1)->for(sub
13627 {my ($index, $start, $next, $end) = @_;
13628 $index->setReg(r15);
13629 Push r15;
13630 });
13631  
13632 Mov rax, rsp;
13633 Mov rdi, 8*9;
13634 PrintOutMemoryInHexNL;
13635  
13636 ClearMemory(K(size, 8*9), V(address, rax)); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13637  
13638 PrintOutMemoryInHexNL;
13639  
13640 ok Assemble(debug => 0, eq => <<END);
13641 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
13642 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
13643 END
13644  
13645 my $N = V(size, 4096); # Size of the initial allocation which should be one or more pages
13646  
13647 AllocateMemory($N, my $A = V(address));
13648  
13649  
13650 ClearMemory($N, $A); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13651  
13652  
13653 $A->setReg(rax);
13654 Mov rdi, 128;
13655 PrintOutMemoryInHexNL;
13656  
13657 FreeMemory($N, $A);
13658  
13659 ok Assemble(debug => 1, eq => <<END);
13660 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
13661 END
13662  
13663  
13664 =head3 MaskMemory22(@variables)
13665  
13666 Write the specified byte into locations in the target mask that correspond to the locations in the source that contain the specified byte.
13667  
13668 Parameter Description
13669 1 @variables Variables
13670  
13671 =head3 MaskMemoryInRange4_22(@variables)
13672  
13673 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.
13674  
13675 Parameter Description
13676 1 @variables Variables
13677  
13678 =head3 CopyMemory(@variables)
13679  
13680 Copy memory, the target is addressed by rax, the length is in rdi, the source is addressed by rsi.
13681  
13682 Parameter Description
13683 1 @variables Variables
13684  
13685 B<Example:>
13686  
13687  
13688 my $s = Rb 0; Rb 1; Rw 2; Rd 3; Rq 4;
13689 my $t = Db 0; Db 1; Dw 2; Dd 3; Dq 4;
13690  
13691 Vmovdqu8 xmm0, "[$s]";
13692 Vmovdqu8 xmm1, "[$t]";
13693 PrintOutRegisterInHex xmm0;
13694 PrintOutRegisterInHex xmm1;
13695 Sub rsp, 16;
13696  
13697 Mov rax, rsp; # Copy memory, the target is addressed by rax, the length is in rdi, the source is addressed by rsi
13698 Mov rdi, 16;
13699 Mov rsi, $s;
13700  
13701 CopyMemory(V(source, rsi), V(target, rax), V(size, rdi)); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13702  
13703 PrintOutMemoryInHex;
13704  
13705 my $r = Assemble;
13706 ok $r =~ m(xmm0: 0000 0000 0000 0004 0000 0003 0002 0100);
13707 ok $r =~ m(xmm1: 0000 0000 0000 0004 0000 0003 0002 0100);
13708 ok $r =~ m(0001 0200 0300 00000400 0000 0000 0000);
13709  
13710 my $N = 256;
13711 my $s = Rb 0..$N-1;
13712 AllocateMemory(K(size, $N), my $a = V(address));
13713  
13714 CopyMemory(V(source, $s), V(size, $N), target => $a); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13715  
13716  
13717 AllocateMemory(K(size, $N), my $b = V(address));
13718  
13719 CopyMemory(source => $a, target => $b, K(size, $N)); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13720  
13721  
13722 $b->setReg(rax);
13723 Mov rdi, $N;
13724 PrintOutMemoryInHexNL;
13725  
13726 ok Assemble(debug=>0, eq => <<END);
13727 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
13728 END
13729  
13730  
13731 =head2 Files
13732  
13733 Interact with the operating system via files.
13734  
13735 =head3 OpenRead()
13736  
13737 Open a file, whose name is addressed by rax, for read and return the file descriptor in rax.
13738  
13739  
13740 B<Example:>
13741  
13742  
13743 Mov rax, Rs($0); # File to read
13744  
13745 OpenRead; # Open file # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13746  
13747 PrintOutRegisterInHex rax;
13748 CloseFile; # Close file
13749 PrintOutRegisterInHex rax;
13750  
13751 Mov rax, Rs(my $f = "zzzTemporaryFile.txt"); # File to write
13752 OpenWrite; # Open file
13753 CloseFile; # Close file
13754  
13755 ok Assemble(debug => 0, eq => <<END);
13756 rax: 0000 0000 0000 0003
13757 rax: 0000 0000 0000 0000
13758 END
13759 ok -e $f; # Created file
13760 unlink $f;
13761  
13762  
13763 =head3 OpenWrite()
13764  
13765 Create the file named by the terminated string addressed by rax for write.
13766  
13767  
13768 B<Example:>
13769  
13770  
13771 Mov rax, Rs($0); # File to read
13772 OpenRead; # Open file
13773 PrintOutRegisterInHex rax;
13774 CloseFile; # Close file
13775 PrintOutRegisterInHex rax;
13776  
13777 Mov rax, Rs(my $f = "zzzTemporaryFile.txt"); # File to write
13778  
13779 OpenWrite; # Open file # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13780  
13781 CloseFile; # Close file
13782  
13783 ok Assemble(debug => 0, eq => <<END);
13784 rax: 0000 0000 0000 0003
13785 rax: 0000 0000 0000 0000
13786 END
13787 ok -e $f; # Created file
13788 unlink $f;
13789  
13790  
13791 =head3 CloseFile()
13792  
13793 Close the file whose descriptor is in rax.
13794  
13795  
13796 B<Example:>
13797  
13798  
13799 Mov rax, Rs($0); # File to read
13800 OpenRead; # Open file
13801 PrintOutRegisterInHex rax;
13802  
13803 CloseFile; # Close file # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13804  
13805 PrintOutRegisterInHex rax;
13806  
13807 Mov rax, Rs(my $f = "zzzTemporaryFile.txt"); # File to write
13808 OpenWrite; # Open file
13809  
13810 CloseFile; # Close file # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13811  
13812  
13813 ok Assemble(debug => 0, eq => <<END);
13814 rax: 0000 0000 0000 0003
13815 rax: 0000 0000 0000 0000
13816 END
13817 ok -e $f; # Created file
13818 unlink $f;
13819  
13820  
13821 =head3 StatSize()
13822  
13823 Stat a file whose name is addressed by rax to get its size in rax.
13824  
13825  
13826 B<Example:>
13827  
13828  
13829 Mov rax, Rs($0); # File to stat
13830  
13831 StatSize; # Stat the file # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13832  
13833 PrintOutRegisterInHex rax;
13834  
13835 my $r = Assemble =~ s( ) ()gsr;
13836 if ($r =~ m(rax:([0-9a-f]{16}))is) # Compare file size obtained with that from fileSize()
13837 {is_deeply $1, sprintf("%016X", fileSize($0));
13838 }
13839  
13840  
13841 =head3 ReadFile(@variables)
13842  
13843 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.
13844  
13845 Parameter Description
13846 1 @variables Variables
13847  
13848 B<Example:>
13849  
13850  
13851 my $file = G(file, Rs($0));
13852 my $size = G(size);
13853 my $address = G(address);
13854  
13855 ReadFile $file, $size, $address; # Read file # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13856  
13857 $address->setReg(rax); # Address of file in memory
13858 $size ->setReg(rdi); # Length of file in memory
13859 PrintOutMemory; # Print contents of memory to stdout
13860  
13861 my $r = Assemble; # Assemble and execute
13862 ok stringMd5Sum($r) eq fileMd5Sum($0); # Output contains this file
13863  
13864  
13865 =head3 executeFileViaBash(@variables)
13866  
13867 Execute the file named in the arena addressed by rax with bash.
13868  
13869 Parameter Description
13870 1 @variables Variables
13871  
13872 B<Example:>
13873  
13874  
13875 my $s = CreateArena; # Create a string
13876 $s->ql(<<END); # Write code to execute
13877 #!/usr/bin/bash
13878 whoami
13879 ls -la
13880 pwd
13881 END
13882 $s->write (my $f = V('file', Rs("zzz.sh"))); # Write code to a file
13883  
13884 executeFileViaBash($f); # Execute the file # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13885  
13886 unlinkFile ($f); # Delete the file
13887  
13888 my $u = qx(whoami); chomp($u);
13889 ok Assemble(emulator => 0) =~ m($u); # The Intel Software Development Emulator is way too slow on these operations.
13890  
13891  
13892 =head3 unlinkFile(@variables)
13893  
13894 Unlink the named file.
13895  
13896 Parameter Description
13897 1 @variables Variables
13898  
13899 B<Example:>
13900  
13901  
13902 my $s = CreateArena; # Create a string
13903 $s->ql(<<END); # Write code to execute
13904 #!/usr/bin/bash
13905 whoami
13906 ls -la
13907 pwd
13908 END
13909 $s->write (my $f = V('file', Rs("zzz.sh"))); # Write code to a file
13910 executeFileViaBash($f); # Execute the file
13911  
13912 unlinkFile ($f); # Delete the file # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13913  
13914  
13915 my $u = qx(whoami); chomp($u);
13916 ok Assemble(emulator => 0) =~ m($u); # The Intel Software Development Emulator is way too slow on these operations.
13917  
13918  
13919 =head1 Hash functions
13920  
13921 Hash functions
13922  
13923 =head2 Hash()
13924  
13925 Hash a string addressed by rax with length held in rdi and return the hash code in r15.
13926  
13927  
13928 B<Example:>
13929  
13930  
13931 Mov rax, "[rbp+24]";
13932 Cstrlen; # Length of string to hash
13933 Mov rdi, r15;
13934  
13935 Hash(); # Hash string # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13936  
13937  
13938 PrintOutRegisterInHex r15;
13939  
13940 my $e = Assemble keep=>'hash'; # Assemble to the specified file name
13941 ok qx($e "") =~ m(r15: 0000 3F80 0000 3F80); # Test well known hashes
13942 ok qx($e "a") =~ m(r15: 0000 3F80 C000 45B2);
13943  
13944  
13945 if (0) # Hash various strings # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
13946  
13947 {my %r; my %f; my $count = 0;
13948 my $N = RegisterSize zmm0;
13949  
13950 if (1) # Fixed blocks
13951 {for my $l(qw(a ab abc abcd), 'a a', 'a a')
13952 {for my $i(1..$N)
13953 {my $t = $l x $i;
13954 last if $N < length $t;
13955 my $s = substr($t.(' ' x $N), 0, $N);
13956 next if $f{$s}++;
13957 my $r = qx($e "$s");
13958 say STDERR "$count $r";
13959 if ($r =~ m(^.*r15:\s*(.*)$)m)
13960 {push $r{$1}->@*, $s;
13961 ++$count;
13962 }
13963 }
13964 }
13965 }
13966  
13967 if (1) # Variable blocks
13968 {for my $l(qw(a ab abc abcd), '', 'a a', 'a a')
13969 {for my $i(1..$N)
13970 {my $t = $l x $i;
13971 next if $f{$t}++;
13972 my $r = qx($e "$t");
13973 say STDERR "$count $r";
13974 if ($r =~ m(^.*r15:\s*(.*)$)m)
13975 {push $r{$1}->@*, $t;
13976 ++$count;
13977 }
13978 }
13979 }
13980 }
13981 for my $r(keys %r)
13982 {delete $r{$r} if $r{$r}->@* < 2;
13983 }
13984  
13985 say STDERR dump(\%r);
13986 say STDERR "Keys hashed: ", $count;
13987 confess "Duplicates : ", scalar keys(%r);
13988 }
13989  
13990  
13991 =head1 Unicode
13992  
13993 Convert utf8 to utf32
13994  
13995 =head2 GetNextUtf8CharAsUtf32(@parameters)
13996  
13997 Get the next utf8 encoded character from the addressed memory and return it as a utf32 char.
13998  
13999 Parameter Description
14000 1 @parameters Parameters
14001  
14002 =head2 ConvertUtf8ToUtf32(@parameters)
14003  
14004 Convert a string of utf8 to an allocated block of utf32 and return its address and length.
14005  
14006 Parameter Description
14007 1 @parameters Parameters
14008  
14009 B<Example:>
14010  
14011  
14012 my @p = my ($out, $size, $fail) = (V(out), V(size), V('fail'));
14013  
14014 my $Chars = Rb(0x24, 0xc2, 0xa2, 0xc9, 0x91, 0xE2, 0x82, 0xAC, 0xF0, 0x90, 0x8D, 0x88);
14015 my $chars = V(chars, $Chars);
14016  
14017 GetNextUtf8CharAsUtf32 in=>$chars, @p; # Dollar UTF-8 Encoding: 0x24 UTF-32 Encoding: 0x00000024
14018 $out->out('out1 : '); $size->outNL(' size : ');
14019  
14020 GetNextUtf8CharAsUtf32 in=>$chars+1, @p; # Cents UTF-8 Encoding: 0xC2 0xA2 UTF-32 Encoding: 0x000000a2
14021 $out->out('out2 : '); $size->outNL(' size : ');
14022  
14023 GetNextUtf8CharAsUtf32 in=>$chars+3, @p; # Alpha UTF-8 Encoding: 0xC9 0x91 UTF-32 Encoding: 0x00000251
14024 $out->out('out3 : '); $size->outNL(' size : ');
14025  
14026 GetNextUtf8CharAsUtf32 in=>$chars+5, @p; # Euro UTF-8 Encoding: 0xE2 0x82 0xAC UTF-32 Encoding: 0x000020AC
14027 $out->out('out4 : '); $size->outNL(' size : ');
14028  
14029 GetNextUtf8CharAsUtf32 in=>$chars+8, @p; # Gothic Letter Hwair UTF-8 Encoding 0xF0 0x90 0x8D 0x88 UTF-32 Encoding: 0x00010348
14030 $out->out('out5 : '); $size->outNL(' size : ');
14031  
14032 my $statement = qq(𝖺
14033 𝑎𝑠𝑠𝑖𝑔𝑛 【【𝖻 𝐩𝐥𝐮𝐬 𝖼】】
14034 AAAAAAAA); # A sample sentence to parse
14035  
14036 my $s = K(statement, Rutf8($statement));
14037 my $l = StringLength string => $s;
14038  
14039 AllocateMemory($l, my $address = V(address)); # Allocate enough memory for a copy of the string
14040 CopyMemory(source => $s, target => $address, $l);
14041  
14042 GetNextUtf8CharAsUtf32 in=>$address, @p;
14043 $out->out('outA : '); $size->outNL(' size : ');
14044  
14045 GetNextUtf8CharAsUtf32 in=>$address+4, @p;
14046 $out->out('outB : '); $size->outNL(' size : ');
14047  
14048 GetNextUtf8CharAsUtf32 in=>$address+5, @p;
14049 $out->out('outC : '); $size->outNL(' size : ');
14050  
14051 GetNextUtf8CharAsUtf32 in=>$address+30, @p;
14052 $out->out('outD : '); $size->outNL(' size : ');
14053  
14054 GetNextUtf8CharAsUtf32 in=>$address+35, @p;
14055 $out->out('outE : '); $size->outNL(' size : ');
14056  
14057 $address->printOutMemoryInHexNL($l);
14058  
14059 ok Assemble(debug => 0, eq => <<END);
14060 out1 : 0000 0000 0000 0024 size : 0000 0000 0000 0001
14061 out2 : 0000 0000 0000 00A2 size : 0000 0000 0000 0002
14062 out3 : 0000 0000 0000 0251 size : 0000 0000 0000 0002
14063 out4 : 0000 0000 0000 20AC size : 0000 0000 0000 0003
14064 out5 : 0000 0000 0001 0348 size : 0000 0000 0000 0004
14065 outA : 0000 0000 0001 D5BA size : 0000 0000 0000 0004
14066 outB : 0000 0000 0000 000A size : 0000 0000 0000 0001
14067 outC : 0000 0000 0000 0020 size : 0000 0000 0000 0001
14068 outD : 0000 0000 0000 0020 size : 0000 0000 0000 0001
14069 outE : 0000 0000 0000 0010 size : 0000 0000 0000 0002
14070 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
14071 END
14072  
14073  
14074 =head2 ClassifyInRange(@parameters)
14075  
14076 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.
14077  
14078 Parameter Description
14079 1 @parameters Parameters
14080  
14081 =head2 ClassifyWithInRange(@parameters)
14082  
14083 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.
14084  
14085 Parameter Description
14086 1 @parameters Parameters
14087  
14088 =head2 ClassifyWithInRangeAndSaveOffset(@parameters)
14089  
14090 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.
14091  
14092 Parameter Description
14093 1 @parameters Parameters
14094  
14095 =head1 Short Strings
14096  
14097 Operations on Short Strings
14098  
14099 =head2 CreateShortString($zmm)
14100  
14101 Create a description of a short string.
14102  
14103 Parameter Description
14104 1 $zmm Numbered zmm containing the string
14105  
14106 B<Example:>
14107  
14108  
14109  
14110 my $s = CreateShortString(0); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
14111  
14112 my $d = Rb(1..63);
14113 $s->load(K(address, $d), K(size, 9));
14114 PrintOutRegisterInHex xmm0;
14115  
14116 $s->len->outNL;
14117  
14118 $s->setLength(K(size, 7));
14119 PrintOutRegisterInHex xmm0;
14120  
14121 $s->append($s);
14122 PrintOutRegisterInHex ymm0;
14123  
14124 $s->appendByte(K(append,0xFF));
14125 PrintOutRegisterInHex ymm0;
14126  
14127 ok Assemble(debug => 0, trace => 0, eq => <<END);
14128 xmm0: 0000 0000 0000 0908 0706 0504 0302 0109
14129 size: 0000 0000 0000 0009
14130 xmm0: 0000 0000 0000 0908 0706 0504 0302 0107
14131 ymm0: 0000 0000 0000 0000 0000 0000 0000 0000 0007 0605 0403 0201 0706 0504 0302 010E
14132 ymm0: 0000 0000 0000 0000 0000 0000 0000 0000 FF07 0605 0403 0201 0706 0504 0302 010F
14133 END
14134  
14135  
14136 =head2 Nasm::X86::ShortString::clear($string)
14137  
14138 Clear a short string.
14139  
14140 Parameter Description
14141 1 $string String
14142  
14143 =head2 Nasm::X86::ShortString::load($string, $address, $length)
14144  
14145 Load the variable addressed data with the variable length into the short string.
14146  
14147 Parameter Description
14148 1 $string String
14149 2 $address Address
14150 3 $length Length
14151  
14152 B<Example:>
14153  
14154  
14155 my $s = CreateShortString(0);
14156 my $d = Rb(1..63);
14157 $s->load(K(address, $d), K(size, 9));
14158 PrintOutRegisterInHex xmm0;
14159  
14160 $s->len->outNL;
14161  
14162 $s->setLength(K(size, 7));
14163 PrintOutRegisterInHex xmm0;
14164  
14165 $s->append($s);
14166 PrintOutRegisterInHex ymm0;
14167  
14168 $s->appendByte(K(append,0xFF));
14169 PrintOutRegisterInHex ymm0;
14170  
14171 ok Assemble(debug => 0, trace => 0, eq => <<END);
14172 xmm0: 0000 0000 0000 0908 0706 0504 0302 0109
14173 size: 0000 0000 0000 0009
14174 xmm0: 0000 0000 0000 0908 0706 0504 0302 0107
14175 ymm0: 0000 0000 0000 0000 0000 0000 0000 0000 0007 0605 0403 0201 0706 0504 0302 010E
14176 ymm0: 0000 0000 0000 0000 0000 0000 0000 0000 FF07 0605 0403 0201 0706 0504 0302 010F
14177 END
14178  
14179  
14180 =head2 Nasm::X86::ShortString::loadDwordBytes($string, $byte, $address, $length, $Offset)
14181  
14182 Load the specified byte of each dword in the variable addressed data with the variable length into the short string.
14183  
14184 Parameter Description
14185 1 $string String
14186 2 $byte Byte offset 0-3
14187 3 $address Variable address
14188 4 $length Variable length
14189 5 $Offset Variable offset in short string at which to start
14190  
14191 =head2 Nasm::X86::ShortString::len($string)
14192  
14193 Return the length of a short string in a variable.
14194  
14195 Parameter Description
14196 1 $string String
14197  
14198 =head2 Nasm::X86::ShortString::setLength($string, $length)
14199  
14200 Set the length of the short string.
14201  
14202 Parameter Description
14203 1 $string String
14204 2 $length Variable size
14205  
14206 B<Example:>
14207  
14208  
14209 my $s = CreateShortString(0);
14210 my $d = Rb(1..63);
14211 $s->load(K(address, $d), K(size, 9));
14212 PrintOutRegisterInHex xmm0;
14213  
14214 $s->len->outNL;
14215  
14216 $s->setLength(K(size, 7));
14217 PrintOutRegisterInHex xmm0;
14218  
14219 $s->append($s);
14220 PrintOutRegisterInHex ymm0;
14221  
14222 $s->appendByte(K(append,0xFF));
14223 PrintOutRegisterInHex ymm0;
14224  
14225 ok Assemble(debug => 0, trace => 0, eq => <<END);
14226 xmm0: 0000 0000 0000 0908 0706 0504 0302 0109
14227 size: 0000 0000 0000 0009
14228 xmm0: 0000 0000 0000 0908 0706 0504 0302 0107
14229 ymm0: 0000 0000 0000 0000 0000 0000 0000 0000 0007 0605 0403 0201 0706 0504 0302 010E
14230 ymm0: 0000 0000 0000 0000 0000 0000 0000 0000 FF07 0605 0403 0201 0706 0504 0302 010F
14231 END
14232  
14233  
14234 =head2 Nasm::X86::ShortString::appendByte($string, $char)
14235  
14236 Append the lowest variable byte to the specified string.
14237  
14238 Parameter Description
14239 1 $string String
14240 2 $char Variable byte
14241  
14242 =head2 Nasm::X86::ShortString::append($left, $right)
14243  
14244 Append the right hand short string to the left hand short string.
14245  
14246 Parameter Description
14247 1 $left Target zmm
14248 2 $right Source zmm
14249  
14250 B<Example:>
14251  
14252  
14253 my $s = CreateShortString(0);
14254 my $d = Rb(1..63);
14255 $s->load(K(address, $d), K(size, 9));
14256 PrintOutRegisterInHex xmm0;
14257  
14258 $s->len->outNL;
14259  
14260 $s->setLength(K(size, 7));
14261 PrintOutRegisterInHex xmm0;
14262  
14263 $s->append($s);
14264 PrintOutRegisterInHex ymm0;
14265  
14266 $s->appendByte(K(append,0xFF));
14267 PrintOutRegisterInHex ymm0;
14268  
14269 ok Assemble(debug => 0, trace => 0, eq => <<END);
14270 xmm0: 0000 0000 0000 0908 0706 0504 0302 0109
14271 size: 0000 0000 0000 0009
14272 xmm0: 0000 0000 0000 0908 0706 0504 0302 0107
14273 ymm0: 0000 0000 0000 0000 0000 0000 0000 0000 0007 0605 0403 0201 0706 0504 0302 010E
14274 ymm0: 0000 0000 0000 0000 0000 0000 0000 0000 FF07 0605 0403 0201 0706 0504 0302 010F
14275 END
14276  
14277  
14278 =head1 Arenas
14279  
14280 An arena is single extensible block of memory which contains other data structures such as strings, arrays, trees within it.
14281  
14282 =head2 StringLength(@parameters)
14283  
14284 Length of a zero terminated string.
14285  
14286 Parameter Description
14287 1 @parameters Parameters
14288  
14289 B<Example:>
14290  
14291  
14292  
14293 StringLength(V(string, Rs("abcd")))->outNL; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
14294  
14295 Assemble(debug => 0, eq => <<END);
14296 size: 0000 0000 0000 0004
14297 END
14298  
14299  
14300 =head2 DescribeArena($bs)
14301  
14302 Describe a relocatable arena.
14303  
14304 Parameter Description
14305 1 $bs Optional variable addressing the start of the arena
14306  
14307 =head2 CreateArena(%options)
14308  
14309 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.
14310  
14311 Parameter Description
14312 1 %options Free=>1 adds a free chain.
14313  
14314 B<Example:>
14315  
14316  
14317  
14318 my $a = CreateArena; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
14319  
14320 $a->q('aa');
14321 $a->out;
14322 PrintOutNL;
14323 ok Assemble(debug => 0, eq => <<END);
14324 aa
14325 END
14326  
14327  
14328 my $a = CreateArena; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
14329  
14330  
14331 my $b = CreateArena; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
14332  
14333 $a->q('aa');
14334 $b->q('bb');
14335 $a->out;
14336 PrintOutNL;
14337 $b->out;
14338 PrintOutNL;
14339 ok Assemble(debug => 0, eq => <<END);
14340 aa
14341 bb
14342 END
14343  
14344  
14345 my $a = CreateArena; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
14346  
14347  
14348 my $b = CreateArena; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
14349  
14350 $a->q('aa');
14351 $a->q('AA');
14352 $a->out;
14353 PrintOutNL;
14354 ok Assemble(debug => 0, eq => <<END);
14355 aaAA
14356 END
14357  
14358  
14359 my $a = CreateArena; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
14360  
14361  
14362 my $b = CreateArena; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
14363  
14364 $a->q('aa');
14365 $b->q('bb');
14366 $a->q('AA');
14367 $b->q('BB');
14368 $a->q('aa');
14369 $b->q('bb');
14370 $a->out;
14371 $b->out;
14372 PrintOutNL;
14373 ok Assemble(debug => 0, eq => <<END);
14374 aaAAaabbBBbb
14375 END
14376  
14377  
14378 my $a = CreateArena; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
14379  
14380 $a->q('ab');
14381  
14382 my $b = CreateArena; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
14383  
14384 $b->append(source=>$a->bs);
14385 $b->append(source=>$a->bs);
14386 $a->append(source=>$b->bs);
14387 $b->append(source=>$a->bs);
14388 $a->append(source=>$b->bs);
14389 $b->append(source=>$a->bs);
14390 $b->append(source=>$a->bs);
14391 $b->append(source=>$a->bs);
14392 $b->append(source=>$a->bs);
14393  
14394  
14395 $a->out; PrintOutNL; # Print arena
14396 $b->out; PrintOutNL; # Print arena
14397 $a->length(my $sa = V(size)); $sa->outNL;
14398 $b->length(my $sb = V(size)); $sb->outNL;
14399 $a->clear;
14400 $a->length(my $sA = V(size)); $sA->outNL;
14401 $b->length(my $sB = V(size)); $sB->outNL;
14402  
14403 ok Assemble(debug => 0, eq => <<END);
14404 abababababababab
14405 ababababababababababababababababababababababababababababababababababababab
14406 size: 0000 0000 0000 0010
14407 size: 0000 0000 0000 004A
14408 size: 0000 0000 0000 0000
14409 size: 0000 0000 0000 004A
14410 END
14411  
14412  
14413 =head2 Nasm::X86::Arena::length($arena, @variables)
14414  
14415 Get the length of an arena.
14416  
14417 Parameter Description
14418 1 $arena Arena descriptor
14419 2 @variables Variables
14420  
14421 =head2 Nasm::X86::Arena::arenaSize($arena, @variables)
14422  
14423 Get the size of an arena.
14424  
14425 Parameter Description
14426 1 $arena Arena descriptor
14427 2 @variables Variables
14428  
14429 =head2 Nasm::X86::Arena::makeReadOnly($arena)
14430  
14431 Make an arena read only.
14432  
14433 Parameter Description
14434 1 $arena Arena descriptor
14435  
14436 =head2 Nasm::X86::Arena::makeWriteable($arena)
14437  
14438 Make an arena writable.
14439  
14440 Parameter Description
14441 1 $arena Arena descriptor
14442  
14443 =head2 Nasm::X86::Arena::allocate($arena, @variables)
14444  
14445 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.
14446  
14447 Parameter Description
14448 1 $arena Arena descriptor
14449 2 @variables Variables
14450  
14451 =head2 Nasm::X86::Arena::allocZmmBlock($arena, @variables)
14452  
14453 Allocate a block to hold a zmm register in the specified arena and return the offset of the block in a variable.
14454  
14455 Parameter Description
14456 1 $arena Arena
14457 2 @variables Variables
14458  
14459 =head2 Nasm::X86::Arena::allocBlock($arena, $bs)
14460  
14461 Allocate a block to hold a zmm register in the specified arena and return the offset of the block in a variable.
14462  
14463 Parameter Description
14464 1 $arena Arena
14465 2 $bs Address of arena
14466  
14467 B<Example:>
14468  
14469  
14470 my $a = CreateArena; $a->dump;
14471 my $b1 = $a->allocBlock($a->bs); $a->dump;
14472 my $b2 = $a->allocBlock($a->bs); $a->dump;
14473 $a->freeBlock($b2); $a->dump;
14474 $a->freeBlock($b1); $a->dump;
14475  
14476 ok Assemble(debug => 0, eq => <<END);
14477 Arena
14478 Size: 0000 0000 0000 1000
14479 Used: 0000 0000 0000 0018
14480 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
14481 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
14482 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
14483 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
14484 Arena
14485 Size: 0000 0000 0000 1000
14486 Used: 0000 0000 0000 0058
14487 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
14488 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
14489 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
14490 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
14491 Arena
14492 Size: 0000 0000 0000 1000
14493 Used: 0000 0000 0000 0098
14494 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
14495 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
14496 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
14497 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
14498 Arena
14499 Size: 0000 0000 0000 1000
14500 Used: 0000 0000 0000 0098
14501 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
14502 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
14503 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
14504 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
14505 Arena
14506 Size: 0000 0000 0000 1000
14507 Used: 0000 0000 0000 0098
14508 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
14509 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
14510 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
14511 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
14512 END
14513  
14514  
14515 =head2 Nasm::X86::Arena::m($arena, @variables)
14516  
14517 Append the content with length rdi addressed by rsi to the arena addressed by rax.
14518  
14519 Parameter Description
14520 1 $arena Arena descriptor
14521 2 @variables Variables
14522  
14523 =head2 Nasm::X86::Arena::q($arena, $string)
14524  
14525 Append a constant string to the arena.
14526  
14527 Parameter Description
14528 1 $arena Arena descriptor
14529 2 $string String
14530  
14531 =head2 Nasm::X86::Arena::ql($arena, $const)
14532  
14533 Append a quoted string containing new line characters to the arena addressed by rax.
14534  
14535 Parameter Description
14536 1 $arena Arena
14537 2 $const Constant
14538  
14539 =head2 Nasm::X86::Arena::char($arena, $char)
14540  
14541 Append a character expressed as a decimal number to the arena addressed by rax.
14542  
14543 Parameter Description
14544 1 $arena Arena descriptor
14545 2 $char Number of character to be appended
14546  
14547 =head2 Nasm::X86::Arena::nl($arena)
14548  
14549 Append a new line to the arena addressed by rax.
14550  
14551 Parameter Description
14552 1 $arena Arena descriptor
14553  
14554 =head2 Nasm::X86::Arena::z($arena)
14555  
14556 Append a trailing zero to the arena addressed by rax.
14557  
14558 Parameter Description
14559 1 $arena Arena descriptor
14560  
14561 =head2 Nasm::X86::Arena::append($arena, @variables)
14562  
14563 Append one arena to another.
14564  
14565 Parameter Description
14566 1 $arena Arena descriptor
14567 2 @variables Variables
14568  
14569 =head2 Nasm::X86::Arena::clear($arena)
14570  
14571 Clear the arena addressed by rax.
14572  
14573 Parameter Description
14574 1 $arena Arena descriptor
14575  
14576 =head2 Nasm::X86::Arena::write($arena, @variables)
14577  
14578 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.
14579  
14580 Parameter Description
14581 1 $arena Arena descriptor
14582 2 @variables Variables
14583  
14584 =head2 Nasm::X86::Arena::read($arena, @variables)
14585  
14586 Read the named file (terminated with a zero byte) and place it into the named arena.
14587  
14588 Parameter Description
14589 1 $arena Arena descriptor
14590 2 @variables Variables
14591  
14592 =head2 Nasm::X86::Arena::out($arena)
14593  
14594 Print the specified arena addressed by rax on sysout.
14595  
14596 Parameter Description
14597 1 $arena Arena descriptor
14598  
14599 =head2 Nasm::X86::Arena::dump($arena, $depth)
14600  
14601 Dump details of an arena.
14602  
14603 Parameter Description
14604 1 $arena Arena descriptor
14605 2 $depth Optional amount of memory to dump as the number of 64 byte blocks
14606  
14607 =head1 String
14608  
14609 Strings made from zmm sized blocks of text
14610  
14611 =head2 Nasm::X86::Arena::DescribeString($arena, %options)
14612  
14613 Describe a string and optionally set its first block .
14614  
14615 Parameter Description
14616 1 $arena Arena description
14617 2 %options {first=> offset of first block}
14618  
14619 =head2 Nasm::X86::Arena::CreateString($arena)
14620  
14621 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.
14622  
14623 Parameter Description
14624 1 $arena Arena description
14625  
14626 =head2 Nasm::X86::String::dump($String)
14627  
14628 Dump a string to sysout.
14629  
14630 Parameter Description
14631 1 $String String descriptor
14632  
14633 =head2 Nasm::X86::String::len($String, $bs, $first)
14634  
14635 Find the length of a string.
14636  
14637 Parameter Description
14638 1 $String String descriptor
14639 2 $bs Optional arena address
14640 3 $first Offset of first block
14641  
14642 B<Example:>
14643  
14644  
14645 my $c = Rb(0..255);
14646 my $S = CreateArena; my $s = $S->CreateString;
14647  
14648 $s->append(source=>V(source, $c), V(size, 165)); $s->dump;
14649 $s->deleteChar(V(position, 0x44)); $s->dump;
14650 $s->len->outNL;
14651  
14652 ok Assemble(debug => 0, eq => <<END);
14653 string Dump
14654 Offset: 0000 0000 0000 0018 Length: 0000 0000 0000 0037
14655 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
14656 Offset: 0000 0000 0000 0058 Length: 0000 0000 0000 0037
14657 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
14658 Offset: 0000 0000 0000 0098 Length: 0000 0000 0000 0037
14659 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
14660  
14661 string Dump
14662 Offset: 0000 0000 0000 0018 Length: 0000 0000 0000 0037
14663 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
14664 Offset: 0000 0000 0000 0058 Length: 0000 0000 0000 0036
14665 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
14666 Offset: 0000 0000 0000 0098 Length: 0000 0000 0000 0037
14667 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
14668  
14669 size: 0000 0000 0000 00A4
14670 END
14671  
14672  
14673 =head2 Nasm::X86::String::concatenate($target, $source)
14674  
14675 Concatenate two strings by appending a copy of the source to the target string.
14676  
14677 Parameter Description
14678 1 $target Target string
14679 2 $source Source string
14680  
14681 =head2 Nasm::X86::String::insertChar($String, @variables)
14682  
14683 Insert a character into a string.
14684  
14685 Parameter Description
14686 1 $String String
14687 2 @variables Variables
14688  
14689 B<Example:>
14690  
14691  
14692 my $c = Rb(0..255);
14693 my $S = CreateArena;
14694 my $s = $S->CreateString;
14695  
14696 $s->append(source=>V(source, $c), K(size, 54)); $s->dump;
14697  
14698 $s->insertChar(V(character, 0x77), K(position, 4)); $s->dump;
14699 $s->insertChar(V(character, 0x88), K(position, 5)); $s->dump;
14700 $s->insertChar(V(character, 0x99), K(position, 6)); $s->dump;
14701 $s->insertChar(V(character, 0xAA), K(position, 7)); $s->dump;
14702 $s->insertChar(V(character, 0xBB), K(position, 8)); $s->dump;
14703 $s->insertChar(V(character, 0xCC), K(position, 9)); $s->dump;
14704 $s->insertChar(V(character, 0xDD), K(position, 10)); $s->dump;
14705 $s->insertChar(V(character, 0xEE), K(position, 11)); $s->dump;
14706 $s->insertChar(V(character, 0xFF), K(position, 12)); $s->dump;
14707  
14708 ok Assemble(debug => 0, eq => <<END);
14709 string Dump
14710 Offset: 0000 0000 0000 0018 Length: 0000 0000 0000 0036
14711 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
14712  
14713 string Dump
14714 Offset: 0000 0000 0000 0018 Length: 0000 0000 0000 0037
14715 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
14716  
14717 string Dump
14718 Offset: 0000 0000 0000 0018 Length: 0000 0000 0000 0005
14719 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
14720 Offset: 0000 0000 0000 0058 Length: 0000 0000 0000 0033
14721 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
14722  
14723 string Dump
14724 Offset: 0000 0000 0000 0018 Length: 0000 0000 0000 0005
14725 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
14726 Offset: 0000 0000 0000 0058 Length: 0000 0000 0000 0034
14727 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
14728  
14729 string Dump
14730 Offset: 0000 0000 0000 0018 Length: 0000 0000 0000 0005
14731 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
14732 Offset: 0000 0000 0000 0058 Length: 0000 0000 0000 0035
14733 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
14734  
14735 string Dump
14736 Offset: 0000 0000 0000 0018 Length: 0000 0000 0000 0005
14737 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
14738 Offset: 0000 0000 0000 0058 Length: 0000 0000 0000 0036
14739 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
14740  
14741 string Dump
14742 Offset: 0000 0000 0000 0018 Length: 0000 0000 0000 0005
14743 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
14744 Offset: 0000 0000 0000 0058 Length: 0000 0000 0000 0037
14745 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
14746  
14747 string Dump
14748 Offset: 0000 0000 0000 0018 Length: 0000 0000 0000 0005
14749 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
14750 Offset: 0000 0000 0000 0058 Length: 0000 0000 0000 0005
14751 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
14752 Offset: 0000 0000 0000 0098 Length: 0000 0000 0000 0033
14753 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
14754  
14755 string Dump
14756 Offset: 0000 0000 0000 0018 Length: 0000 0000 0000 0005
14757 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
14758 Offset: 0000 0000 0000 0058 Length: 0000 0000 0000 0005
14759 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
14760 Offset: 0000 0000 0000 0098 Length: 0000 0000 0000 0034
14761 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
14762  
14763 string Dump
14764 Offset: 0000 0000 0000 0018 Length: 0000 0000 0000 0005
14765 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
14766 Offset: 0000 0000 0000 0058 Length: 0000 0000 0000 0005
14767 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
14768 Offset: 0000 0000 0000 0098 Length: 0000 0000 0000 0035
14769 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
14770  
14771 END
14772  
14773  
14774 =head2 Nasm::X86::String::deleteChar($String, @variables)
14775  
14776 Delete a character in a string.
14777  
14778 Parameter Description
14779 1 $String String
14780 2 @variables Variables
14781  
14782 B<Example:>
14783  
14784  
14785 my $c = Rb(0..255);
14786 my $S = CreateArena; my $s = $S->CreateString;
14787  
14788 $s->append(source=>V(source, $c), V(size, 165)); $s->dump;
14789 $s->deleteChar(V(position, 0x44)); $s->dump;
14790 $s->len->outNL;
14791  
14792 ok Assemble(debug => 0, eq => <<END);
14793 string Dump
14794 Offset: 0000 0000 0000 0018 Length: 0000 0000 0000 0037
14795 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
14796 Offset: 0000 0000 0000 0058 Length: 0000 0000 0000 0037
14797 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
14798 Offset: 0000 0000 0000 0098 Length: 0000 0000 0000 0037
14799 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
14800  
14801 string Dump
14802 Offset: 0000 0000 0000 0018 Length: 0000 0000 0000 0037
14803 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
14804 Offset: 0000 0000 0000 0058 Length: 0000 0000 0000 0036
14805 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
14806 Offset: 0000 0000 0000 0098 Length: 0000 0000 0000 0037
14807 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
14808  
14809 size: 0000 0000 0000 00A4
14810 END
14811  
14812  
14813 =head2 Nasm::X86::String::getCharacter($String, @variables)
14814  
14815 Get a character from a string.
14816  
14817 Parameter Description
14818 1 $String String
14819 2 @variables Variables
14820  
14821 =head2 Nasm::X86::String::append($String, @variables)
14822  
14823 Append the specified content in memory to the specified string.
14824  
14825 Parameter Description
14826 1 $String String descriptor
14827 2 @variables Variables
14828  
14829 =head2 Nasm::X86::String::appendShortString($string, $short)
14830  
14831 Append the content of the specified short string.
14832  
14833 Parameter Description
14834 1 $string String descriptor
14835 2 $short Short string
14836  
14837 B<Example:>
14838  
14839  
14840 my $a = CreateArena;
14841 my $S = $a->CreateString;
14842  
14843 my $s = CreateShortString(0);
14844 my $d = Rb(1..63);
14845 $s->load(K(address, $d), K(size, 9));
14846 $s->append($s);
14847  
14848 $S->appendShortString($s);
14849  
14850 $S->dump;
14851  
14852 ok Assemble(debug => 0, trace => 0, eq => <<END);
14853 string Dump
14854 Offset: 0000 0000 0000 0018 Length: 0000 0000 0000 0012
14855 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
14856  
14857 END
14858  
14859 my $a = CreateArena;
14860 my $t = $a->CreateTree;
14861  
14862 my $s = CreateShortString(0);
14863 my $d = Rb(1..63);
14864 $s->load(K(address, $d), K(size, 9));
14865  
14866 $t->insertShortString($s, K(data,42));
14867  
14868 $t->dump;
14869  
14870 ok Assemble(debug => 0, trace => 0, eq => <<END);
14871 Tree at: 0000 0000 0000 0018 length: 0000 0000 0000 0001
14872 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
14873 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
14874 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
14875 index: 0000 0000 0000 0000 key: 0000 0000 0403 0201 data: 0000 0000 0000 0098 subTree
14876 Tree at: 0000 0000 0000 0098 length: 0000 0000 0000 0001
14877 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
14878 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
14879 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
14880 index: 0000 0000 0000 0000 key: 0000 0000 0807 0605 data: 0000 0000 0000 0118 subTree
14881 Tree at: 0000 0000 0000 0118 length: 0000 0000 0000 0001
14882 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
14883 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
14884 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
14885 index: 0000 0000 0000 0000 key: 0000 0000 0000 0009 data: 0000 0000 0000 002A
14886 end
14887 end
14888 end
14889 END
14890  
14891  
14892 =head2 Nasm::X86::String::saveToShortString($string, $short, $first)
14893  
14894 Place as much as possible of the specified string into the specified short string.
14895  
14896 Parameter Description
14897 1 $string String descriptor
14898 2 $short Short string descriptor
14899 3 $first Optional offset to first block of string
14900  
14901 =head2 Nasm::X86::String::clear($String)
14902  
14903 Clear the block by freeing all but the first block.
14904  
14905 Parameter Description
14906 1 $String String descriptor
14907  
14908 =head1 Array
14909  
14910 Array constructed as a set of blocks in an arena
14911  
14912 =head2 Nasm::X86::Arena::DescribeArray($arena)
14913  
14914 Describe a dynamic array held in an arena.
14915  
14916 Parameter Description
14917 1 $arena Arena description
14918  
14919 =head2 Nasm::X86::Arena::CreateArray($arena)
14920  
14921 Create a dynamic array held in an arena.
14922  
14923 Parameter Description
14924 1 $arena Arena description
14925  
14926 =head2 Nasm::X86::Array::reload($array, %options)
14927  
14928 Reload the specified array description.
14929  
14930 Parameter Description
14931 1 $array Array descriptor
14932 2 %options {first=>first block of array if not the existing first node; arena=>arena used by array if not the existing arena}
14933  
14934 =head2 Nasm::X86::Array::dump($Array, @variables)
14935  
14936 Dump a array.
14937  
14938 Parameter Description
14939 1 $Array Array descriptor
14940 2 @variables Variables
14941  
14942 =head2 Nasm::X86::Array::push($Array, @variables)
14943  
14944 Push an element onto the array.
14945  
14946 Parameter Description
14947 1 $Array Array descriptor
14948 2 @variables Variables
14949  
14950 B<Example:>
14951  
14952  
14953 my $c = Rb(0..255);
14954 my $A = CreateArena; my $a = $A->CreateArray;
14955 my $l = V(limit, 15);
14956 my $L = $l + 5;
14957  
14958 my sub put # Put a constant or a variable
14959 {my ($e) = @_;
14960 $a->push(element => (ref($e) ? $e : V($e, $e)));
14961 };
14962  
14963 my sub get # Get a constant or a variable
14964 {my ($i) = @_;
14965 $a->get(index=>(my $v = ref($i) ? $i : K('index', $i)), my $e = V(element));
14966 $v->out("index: ", " "); $e->outNL;
14967 };
14968  
14969 $l->for(sub # Loop to the limit pushing
14970 {my ($index, $start, $next, $end) = @_;
14971 put($index+1);
14972 });
14973  
14974 $l->for(sub # Loop to the limit getting
14975 {my ($index, $start, $next, $end) = @_;
14976 get($index);
14977 });
14978  
14979 put(16);
14980 get(15);
14981  
14982 $L->for(sub
14983 {my ($index, $start, $next, $end) = @_;
14984 put($index+$l+2);
14985 });
14986  
14987 $L->for(sub
14988 {my ($index, $start, $next, $end) = @_;
14989 get($index + $l + 1);
14990 });
14991  
14992 if (1)
14993 {$a->put(my $i = V('index', 9), my $e = V(element, 0xFFF9));
14994 get(9);
14995 }
14996  
14997 if (1)
14998 {$a->put(my $i = V('index', 19), my $e = V(element, 0xEEE9));
14999 get(19);
15000 }
15001  
15002 ($l+$L+1)->for(sub
15003 {my ($i, $start, $next, $end) = @_;
15004 $a->pop(my $e = V(element));
15005 $e->outNL;
15006 });
15007  
15008 V(limit, 38)->for(sub # Push using a loop and reusing the freed space
15009 {my ($index, $start, $next, $end) = @_;
15010 $a->push(element=>$index*2);
15011 });
15012  
15013 V(limit, 38)->for(sub # Push using a loop and reusing the freed space
15014 {my ($index, $start, $next, $end) = @_;
15015 $a->pop(my $e = V(element));
15016 $e->outNL;
15017 });
15018  
15019 $a->dump;
15020  
15021 ok Assemble(debug => 0, eq => <<END);
15022 index: 0000 0000 0000 0000 element: 0000 0000 0000 0001
15023 index: 0000 0000 0000 0001 element: 0000 0000 0000 0002
15024 index: 0000 0000 0000 0002 element: 0000 0000 0000 0003
15025 index: 0000 0000 0000 0003 element: 0000 0000 0000 0004
15026 index: 0000 0000 0000 0004 element: 0000 0000 0000 0005
15027 index: 0000 0000 0000 0005 element: 0000 0000 0000 0006
15028 index: 0000 0000 0000 0006 element: 0000 0000 0000 0007
15029 index: 0000 0000 0000 0007 element: 0000 0000 0000 0008
15030 index: 0000 0000 0000 0008 element: 0000 0000 0000 0009
15031 index: 0000 0000 0000 0009 element: 0000 0000 0000 000A
15032 index: 0000 0000 0000 000A element: 0000 0000 0000 000B
15033 index: 0000 0000 0000 000B element: 0000 0000 0000 000C
15034 index: 0000 0000 0000 000C element: 0000 0000 0000 000D
15035 index: 0000 0000 0000 000D element: 0000 0000 0000 000E
15036 index: 0000 0000 0000 000E element: 0000 0000 0000 000F
15037 index: 0000 0000 0000 000F element: 0000 0000 0000 0010
15038 index: 0000 0000 0000 0010 element: 0000 0000 0000 0011
15039 index: 0000 0000 0000 0011 element: 0000 0000 0000 0012
15040 index: 0000 0000 0000 0012 element: 0000 0000 0000 0013
15041 index: 0000 0000 0000 0013 element: 0000 0000 0000 0014
15042 index: 0000 0000 0000 0014 element: 0000 0000 0000 0015
15043 index: 0000 0000 0000 0015 element: 0000 0000 0000 0016
15044 index: 0000 0000 0000 0016 element: 0000 0000 0000 0017
15045 index: 0000 0000 0000 0017 element: 0000 0000 0000 0018
15046 index: 0000 0000 0000 0018 element: 0000 0000 0000 0019
15047 index: 0000 0000 0000 0019 element: 0000 0000 0000 001A
15048 index: 0000 0000 0000 001A element: 0000 0000 0000 001B
15049 index: 0000 0000 0000 001B element: 0000 0000 0000 001C
15050 index: 0000 0000 0000 001C element: 0000 0000 0000 001D
15051 index: 0000 0000 0000 001D element: 0000 0000 0000 001E
15052 index: 0000 0000 0000 001E element: 0000 0000 0000 001F
15053 index: 0000 0000 0000 001F element: 0000 0000 0000 0020
15054 index: 0000 0000 0000 0020 element: 0000 0000 0000 0021
15055 index: 0000 0000 0000 0021 element: 0000 0000 0000 0022
15056 index: 0000 0000 0000 0022 element: 0000 0000 0000 0023
15057 index: 0000 0000 0000 0023 element: 0000 0000 0000 0024
15058 index: 0000 0000 0000 0009 element: 0000 0000 0000 FFF9
15059 index: 0000 0000 0000 0013 element: 0000 0000 0000 EEE9
15060 element: 0000 0000 0000 0024
15061 element: 0000 0000 0000 0023
15062 element: 0000 0000 0000 0022
15063 element: 0000 0000 0000 0021
15064 element: 0000 0000 0000 0020
15065 element: 0000 0000 0000 001F
15066 element: 0000 0000 0000 001E
15067 element: 0000 0000 0000 001D
15068 element: 0000 0000 0000 001C
15069 element: 0000 0000 0000 001B
15070 element: 0000 0000 0000 001A
15071 element: 0000 0000 0000 0019
15072 element: 0000 0000 0000 0018
15073 element: 0000 0000 0000 0017
15074 element: 0000 0000 0000 0016
15075 element: 0000 0000 0000 0015
15076 element: 0000 0000 0000 EEE9
15077 element: 0000 0000 0000 0013
15078 element: 0000 0000 0000 0012
15079 element: 0000 0000 0000 0011
15080 element: 0000 0000 0000 0010
15081 element: 0000 0000 0000 000F
15082 element: 0000 0000 0000 000E
15083 element: 0000 0000 0000 000D
15084 element: 0000 0000 0000 000C
15085 element: 0000 0000 0000 000B
15086 element: 0000 0000 0000 FFF9
15087 element: 0000 0000 0000 0009
15088 element: 0000 0000 0000 0008
15089 element: 0000 0000 0000 0007
15090 element: 0000 0000 0000 0006
15091 element: 0000 0000 0000 0005
15092 element: 0000 0000 0000 0004
15093 element: 0000 0000 0000 0003
15094 element: 0000 0000 0000 0002
15095 element: 0000 0000 0000 0001
15096 element: 0000 0000 0000 004A
15097 element: 0000 0000 0000 0048
15098 element: 0000 0000 0000 0046
15099 element: 0000 0000 0000 0044
15100 element: 0000 0000 0000 0042
15101 element: 0000 0000 0000 0040
15102 element: 0000 0000 0000 003E
15103 element: 0000 0000 0000 003C
15104 element: 0000 0000 0000 003A
15105 element: 0000 0000 0000 0038
15106 element: 0000 0000 0000 0036
15107 element: 0000 0000 0000 0034
15108 element: 0000 0000 0000 0032
15109 element: 0000 0000 0000 0030
15110 element: 0000 0000 0000 002E
15111 element: 0000 0000 0000 002C
15112 element: 0000 0000 0000 002A
15113 element: 0000 0000 0000 0028
15114 element: 0000 0000 0000 0026
15115 element: 0000 0000 0000 0024
15116 element: 0000 0000 0000 0022
15117 element: 0000 0000 0000 0020
15118 element: 0000 0000 0000 001E
15119 element: 0000 0000 0000 001C
15120 element: 0000 0000 0000 001A
15121 element: 0000 0000 0000 0018
15122 element: 0000 0000 0000 0016
15123 element: 0000 0000 0000 0014
15124 element: 0000 0000 0000 0012
15125 element: 0000 0000 0000 0010
15126 element: 0000 0000 0000 000E
15127 element: 0000 0000 0000 000C
15128 element: 0000 0000 0000 000A
15129 element: 0000 0000 0000 0008
15130 element: 0000 0000 0000 0006
15131 element: 0000 0000 0000 0004
15132 element: 0000 0000 0000 0002
15133 element: 0000 0000 0000 0000
15134 array
15135 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
15136 END
15137  
15138 my $c = Rb(0..255);
15139 my $A = CreateArena; my $a = $A->CreateArray;
15140  
15141 my sub put
15142 {my ($e) = @_;
15143 $a->push(element => V($e, $e));
15144 };
15145  
15146 my sub get
15147 {my ($i) = @_; # Parameters
15148 $a->get(my $v = V('index', $i), my $e = V(element));
15149 $v->out; PrintOutString " "; $e->outNL;
15150 };
15151  
15152 put($_) for 1..15; get(15);
15153  
15154 ok Assemble(debug => 2, eq => <<END);
15155 Index out of bounds on get from array, Index: 0000 0000 0000 000F Size: 0000 0000 0000 000F
15156 END
15157  
15158  
15159 =head2 Nasm::X86::Array::pop($Array, @variables)
15160  
15161 Pop an element from an array.
15162  
15163 Parameter Description
15164 1 $Array Array descriptor
15165 2 @variables Variables
15166  
15167 B<Example:>
15168  
15169  
15170 my $c = Rb(0..255);
15171 my $A = CreateArena; my $a = $A->CreateArray;
15172 my $l = V(limit, 15);
15173 my $L = $l + 5;
15174  
15175 my sub put # Put a constant or a variable
15176 {my ($e) = @_;
15177 $a->push(element => (ref($e) ? $e : V($e, $e)));
15178 };
15179  
15180 my sub get # Get a constant or a variable
15181 {my ($i) = @_;
15182 $a->get(index=>(my $v = ref($i) ? $i : K('index', $i)), my $e = V(element));
15183 $v->out("index: ", " "); $e->outNL;
15184 };
15185  
15186 $l->for(sub # Loop to the limit pushing
15187 {my ($index, $start, $next, $end) = @_;
15188 put($index+1);
15189 });
15190  
15191 $l->for(sub # Loop to the limit getting
15192 {my ($index, $start, $next, $end) = @_;
15193 get($index);
15194 });
15195  
15196 put(16);
15197 get(15);
15198  
15199 $L->for(sub
15200 {my ($index, $start, $next, $end) = @_;
15201 put($index+$l+2);
15202 });
15203  
15204 $L->for(sub
15205 {my ($index, $start, $next, $end) = @_;
15206 get($index + $l + 1);
15207 });
15208  
15209 if (1)
15210 {$a->put(my $i = V('index', 9), my $e = V(element, 0xFFF9));
15211 get(9);
15212 }
15213  
15214 if (1)
15215 {$a->put(my $i = V('index', 19), my $e = V(element, 0xEEE9));
15216 get(19);
15217 }
15218  
15219 ($l+$L+1)->for(sub
15220 {my ($i, $start, $next, $end) = @_;
15221 $a->pop(my $e = V(element));
15222 $e->outNL;
15223 });
15224  
15225 V(limit, 38)->for(sub # Push using a loop and reusing the freed space
15226 {my ($index, $start, $next, $end) = @_;
15227 $a->push(element=>$index*2);
15228 });
15229  
15230 V(limit, 38)->for(sub # Push using a loop and reusing the freed space
15231 {my ($index, $start, $next, $end) = @_;
15232 $a->pop(my $e = V(element));
15233 $e->outNL;
15234 });
15235  
15236 $a->dump;
15237  
15238 ok Assemble(debug => 0, eq => <<END);
15239 index: 0000 0000 0000 0000 element: 0000 0000 0000 0001
15240 index: 0000 0000 0000 0001 element: 0000 0000 0000 0002
15241 index: 0000 0000 0000 0002 element: 0000 0000 0000 0003
15242 index: 0000 0000 0000 0003 element: 0000 0000 0000 0004
15243 index: 0000 0000 0000 0004 element: 0000 0000 0000 0005
15244 index: 0000 0000 0000 0005 element: 0000 0000 0000 0006
15245 index: 0000 0000 0000 0006 element: 0000 0000 0000 0007
15246 index: 0000 0000 0000 0007 element: 0000 0000 0000 0008
15247 index: 0000 0000 0000 0008 element: 0000 0000 0000 0009
15248 index: 0000 0000 0000 0009 element: 0000 0000 0000 000A
15249 index: 0000 0000 0000 000A element: 0000 0000 0000 000B
15250 index: 0000 0000 0000 000B element: 0000 0000 0000 000C
15251 index: 0000 0000 0000 000C element: 0000 0000 0000 000D
15252 index: 0000 0000 0000 000D element: 0000 0000 0000 000E
15253 index: 0000 0000 0000 000E element: 0000 0000 0000 000F
15254 index: 0000 0000 0000 000F element: 0000 0000 0000 0010
15255 index: 0000 0000 0000 0010 element: 0000 0000 0000 0011
15256 index: 0000 0000 0000 0011 element: 0000 0000 0000 0012
15257 index: 0000 0000 0000 0012 element: 0000 0000 0000 0013
15258 index: 0000 0000 0000 0013 element: 0000 0000 0000 0014
15259 index: 0000 0000 0000 0014 element: 0000 0000 0000 0015
15260 index: 0000 0000 0000 0015 element: 0000 0000 0000 0016
15261 index: 0000 0000 0000 0016 element: 0000 0000 0000 0017
15262 index: 0000 0000 0000 0017 element: 0000 0000 0000 0018
15263 index: 0000 0000 0000 0018 element: 0000 0000 0000 0019
15264 index: 0000 0000 0000 0019 element: 0000 0000 0000 001A
15265 index: 0000 0000 0000 001A element: 0000 0000 0000 001B
15266 index: 0000 0000 0000 001B element: 0000 0000 0000 001C
15267 index: 0000 0000 0000 001C element: 0000 0000 0000 001D
15268 index: 0000 0000 0000 001D element: 0000 0000 0000 001E
15269 index: 0000 0000 0000 001E element: 0000 0000 0000 001F
15270 index: 0000 0000 0000 001F element: 0000 0000 0000 0020
15271 index: 0000 0000 0000 0020 element: 0000 0000 0000 0021
15272 index: 0000 0000 0000 0021 element: 0000 0000 0000 0022
15273 index: 0000 0000 0000 0022 element: 0000 0000 0000 0023
15274 index: 0000 0000 0000 0023 element: 0000 0000 0000 0024
15275 index: 0000 0000 0000 0009 element: 0000 0000 0000 FFF9
15276 index: 0000 0000 0000 0013 element: 0000 0000 0000 EEE9
15277 element: 0000 0000 0000 0024
15278 element: 0000 0000 0000 0023
15279 element: 0000 0000 0000 0022
15280 element: 0000 0000 0000 0021
15281 element: 0000 0000 0000 0020
15282 element: 0000 0000 0000 001F
15283 element: 0000 0000 0000 001E
15284 element: 0000 0000 0000 001D
15285 element: 0000 0000 0000 001C
15286 element: 0000 0000 0000 001B
15287 element: 0000 0000 0000 001A
15288 element: 0000 0000 0000 0019
15289 element: 0000 0000 0000 0018
15290 element: 0000 0000 0000 0017
15291 element: 0000 0000 0000 0016
15292 element: 0000 0000 0000 0015
15293 element: 0000 0000 0000 EEE9
15294 element: 0000 0000 0000 0013
15295 element: 0000 0000 0000 0012
15296 element: 0000 0000 0000 0011
15297 element: 0000 0000 0000 0010
15298 element: 0000 0000 0000 000F
15299 element: 0000 0000 0000 000E
15300 element: 0000 0000 0000 000D
15301 element: 0000 0000 0000 000C
15302 element: 0000 0000 0000 000B
15303 element: 0000 0000 0000 FFF9
15304 element: 0000 0000 0000 0009
15305 element: 0000 0000 0000 0008
15306 element: 0000 0000 0000 0007
15307 element: 0000 0000 0000 0006
15308 element: 0000 0000 0000 0005
15309 element: 0000 0000 0000 0004
15310 element: 0000 0000 0000 0003
15311 element: 0000 0000 0000 0002
15312 element: 0000 0000 0000 0001
15313 element: 0000 0000 0000 004A
15314 element: 0000 0000 0000 0048
15315 element: 0000 0000 0000 0046
15316 element: 0000 0000 0000 0044
15317 element: 0000 0000 0000 0042
15318 element: 0000 0000 0000 0040
15319 element: 0000 0000 0000 003E
15320 element: 0000 0000 0000 003C
15321 element: 0000 0000 0000 003A
15322 element: 0000 0000 0000 0038
15323 element: 0000 0000 0000 0036
15324 element: 0000 0000 0000 0034
15325 element: 0000 0000 0000 0032
15326 element: 0000 0000 0000 0030
15327 element: 0000 0000 0000 002E
15328 element: 0000 0000 0000 002C
15329 element: 0000 0000 0000 002A
15330 element: 0000 0000 0000 0028
15331 element: 0000 0000 0000 0026
15332 element: 0000 0000 0000 0024
15333 element: 0000 0000 0000 0022
15334 element: 0000 0000 0000 0020
15335 element: 0000 0000 0000 001E
15336 element: 0000 0000 0000 001C
15337 element: 0000 0000 0000 001A
15338 element: 0000 0000 0000 0018
15339 element: 0000 0000 0000 0016
15340 element: 0000 0000 0000 0014
15341 element: 0000 0000 0000 0012
15342 element: 0000 0000 0000 0010
15343 element: 0000 0000 0000 000E
15344 element: 0000 0000 0000 000C
15345 element: 0000 0000 0000 000A
15346 element: 0000 0000 0000 0008
15347 element: 0000 0000 0000 0006
15348 element: 0000 0000 0000 0004
15349 element: 0000 0000 0000 0002
15350 element: 0000 0000 0000 0000
15351 array
15352 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
15353 END
15354  
15355  
15356 =head2 Nasm::X86::Array::size($Array, $bs, $first)
15357  
15358 Return the size of an array as a variable.
15359  
15360 Parameter Description
15361 1 $Array Array descriptor
15362 2 $bs Optional arena address
15363 3 $first Optional first block
15364  
15365 B<Example:>
15366  
15367  
15368 my $N = 15;
15369 my $A = CreateArena;
15370 my $a = $A->CreateArray;
15371  
15372 $a->push(V(element, $_)) for 1..$N;
15373  
15374 K(loop, $N)->for(sub
15375 {my ($start, $end, $next) = @_;
15376 my $l = $a->size;
15377 If $l == 0, Then {Jmp $end};
15378 $a->pop(my $e = V(element));
15379 $e->outNL;
15380 });
15381  
15382 ok Assemble(debug => 0, eq => <<END);
15383 element: 0000 0000 0000 000F
15384 element: 0000 0000 0000 000E
15385 element: 0000 0000 0000 000D
15386 element: 0000 0000 0000 000C
15387 element: 0000 0000 0000 000B
15388 element: 0000 0000 0000 000A
15389 element: 0000 0000 0000 0009
15390 element: 0000 0000 0000 0008
15391 element: 0000 0000 0000 0007
15392 element: 0000 0000 0000 0006
15393 element: 0000 0000 0000 0005
15394 element: 0000 0000 0000 0004
15395 element: 0000 0000 0000 0003
15396 element: 0000 0000 0000 0002
15397 element: 0000 0000 0000 0001
15398 END
15399  
15400  
15401 =head2 Nasm::X86::Array::get($Array, @variables)
15402  
15403 Get an element from the array.
15404  
15405 Parameter Description
15406 1 $Array Array descriptor
15407 2 @variables Variables
15408  
15409 B<Example:>
15410  
15411  
15412 my $c = Rb(0..255);
15413 my $A = CreateArena; my $a = $A->CreateArray;
15414 my $l = V(limit, 15);
15415 my $L = $l + 5;
15416  
15417 my sub put # Put a constant or a variable
15418 {my ($e) = @_;
15419 $a->push(element => (ref($e) ? $e : V($e, $e)));
15420 };
15421  
15422 my sub get # Get a constant or a variable
15423 {my ($i) = @_;
15424 $a->get(index=>(my $v = ref($i) ? $i : K('index', $i)), my $e = V(element));
15425 $v->out("index: ", " "); $e->outNL;
15426 };
15427  
15428 $l->for(sub # Loop to the limit pushing
15429 {my ($index, $start, $next, $end) = @_;
15430 put($index+1);
15431 });
15432  
15433 $l->for(sub # Loop to the limit getting
15434 {my ($index, $start, $next, $end) = @_;
15435 get($index);
15436 });
15437  
15438 put(16);
15439 get(15);
15440  
15441 $L->for(sub
15442 {my ($index, $start, $next, $end) = @_;
15443 put($index+$l+2);
15444 });
15445  
15446 $L->for(sub
15447 {my ($index, $start, $next, $end) = @_;
15448 get($index + $l + 1);
15449 });
15450  
15451 if (1)
15452 {$a->put(my $i = V('index', 9), my $e = V(element, 0xFFF9));
15453 get(9);
15454 }
15455  
15456 if (1)
15457 {$a->put(my $i = V('index', 19), my $e = V(element, 0xEEE9));
15458 get(19);
15459 }
15460  
15461 ($l+$L+1)->for(sub
15462 {my ($i, $start, $next, $end) = @_;
15463 $a->pop(my $e = V(element));
15464 $e->outNL;
15465 });
15466  
15467 V(limit, 38)->for(sub # Push using a loop and reusing the freed space
15468 {my ($index, $start, $next, $end) = @_;
15469 $a->push(element=>$index*2);
15470 });
15471  
15472 V(limit, 38)->for(sub # Push using a loop and reusing the freed space
15473 {my ($index, $start, $next, $end) = @_;
15474 $a->pop(my $e = V(element));
15475 $e->outNL;
15476 });
15477  
15478 $a->dump;
15479  
15480 ok Assemble(debug => 0, eq => <<END);
15481 index: 0000 0000 0000 0000 element: 0000 0000 0000 0001
15482 index: 0000 0000 0000 0001 element: 0000 0000 0000 0002
15483 index: 0000 0000 0000 0002 element: 0000 0000 0000 0003
15484 index: 0000 0000 0000 0003 element: 0000 0000 0000 0004
15485 index: 0000 0000 0000 0004 element: 0000 0000 0000 0005
15486 index: 0000 0000 0000 0005 element: 0000 0000 0000 0006
15487 index: 0000 0000 0000 0006 element: 0000 0000 0000 0007
15488 index: 0000 0000 0000 0007 element: 0000 0000 0000 0008
15489 index: 0000 0000 0000 0008 element: 0000 0000 0000 0009
15490 index: 0000 0000 0000 0009 element: 0000 0000 0000 000A
15491 index: 0000 0000 0000 000A element: 0000 0000 0000 000B
15492 index: 0000 0000 0000 000B element: 0000 0000 0000 000C
15493 index: 0000 0000 0000 000C element: 0000 0000 0000 000D
15494 index: 0000 0000 0000 000D element: 0000 0000 0000 000E
15495 index: 0000 0000 0000 000E element: 0000 0000 0000 000F
15496 index: 0000 0000 0000 000F element: 0000 0000 0000 0010
15497 index: 0000 0000 0000 0010 element: 0000 0000 0000 0011
15498 index: 0000 0000 0000 0011 element: 0000 0000 0000 0012
15499 index: 0000 0000 0000 0012 element: 0000 0000 0000 0013
15500 index: 0000 0000 0000 0013 element: 0000 0000 0000 0014
15501 index: 0000 0000 0000 0014 element: 0000 0000 0000 0015
15502 index: 0000 0000 0000 0015 element: 0000 0000 0000 0016
15503 index: 0000 0000 0000 0016 element: 0000 0000 0000 0017
15504 index: 0000 0000 0000 0017 element: 0000 0000 0000 0018
15505 index: 0000 0000 0000 0018 element: 0000 0000 0000 0019
15506 index: 0000 0000 0000 0019 element: 0000 0000 0000 001A
15507 index: 0000 0000 0000 001A element: 0000 0000 0000 001B
15508 index: 0000 0000 0000 001B element: 0000 0000 0000 001C
15509 index: 0000 0000 0000 001C element: 0000 0000 0000 001D
15510 index: 0000 0000 0000 001D element: 0000 0000 0000 001E
15511 index: 0000 0000 0000 001E element: 0000 0000 0000 001F
15512 index: 0000 0000 0000 001F element: 0000 0000 0000 0020
15513 index: 0000 0000 0000 0020 element: 0000 0000 0000 0021
15514 index: 0000 0000 0000 0021 element: 0000 0000 0000 0022
15515 index: 0000 0000 0000 0022 element: 0000 0000 0000 0023
15516 index: 0000 0000 0000 0023 element: 0000 0000 0000 0024
15517 index: 0000 0000 0000 0009 element: 0000 0000 0000 FFF9
15518 index: 0000 0000 0000 0013 element: 0000 0000 0000 EEE9
15519 element: 0000 0000 0000 0024
15520 element: 0000 0000 0000 0023
15521 element: 0000 0000 0000 0022
15522 element: 0000 0000 0000 0021
15523 element: 0000 0000 0000 0020
15524 element: 0000 0000 0000 001F
15525 element: 0000 0000 0000 001E
15526 element: 0000 0000 0000 001D
15527 element: 0000 0000 0000 001C
15528 element: 0000 0000 0000 001B
15529 element: 0000 0000 0000 001A
15530 element: 0000 0000 0000 0019
15531 element: 0000 0000 0000 0018
15532 element: 0000 0000 0000 0017
15533 element: 0000 0000 0000 0016
15534 element: 0000 0000 0000 0015
15535 element: 0000 0000 0000 EEE9
15536 element: 0000 0000 0000 0013
15537 element: 0000 0000 0000 0012
15538 element: 0000 0000 0000 0011
15539 element: 0000 0000 0000 0010
15540 element: 0000 0000 0000 000F
15541 element: 0000 0000 0000 000E
15542 element: 0000 0000 0000 000D
15543 element: 0000 0000 0000 000C
15544 element: 0000 0000 0000 000B
15545 element: 0000 0000 0000 FFF9
15546 element: 0000 0000 0000 0009
15547 element: 0000 0000 0000 0008
15548 element: 0000 0000 0000 0007
15549 element: 0000 0000 0000 0006
15550 element: 0000 0000 0000 0005
15551 element: 0000 0000 0000 0004
15552 element: 0000 0000 0000 0003
15553 element: 0000 0000 0000 0002
15554 element: 0000 0000 0000 0001
15555 element: 0000 0000 0000 004A
15556 element: 0000 0000 0000 0048
15557 element: 0000 0000 0000 0046
15558 element: 0000 0000 0000 0044
15559 element: 0000 0000 0000 0042
15560 element: 0000 0000 0000 0040
15561 element: 0000 0000 0000 003E
15562 element: 0000 0000 0000 003C
15563 element: 0000 0000 0000 003A
15564 element: 0000 0000 0000 0038
15565 element: 0000 0000 0000 0036
15566 element: 0000 0000 0000 0034
15567 element: 0000 0000 0000 0032
15568 element: 0000 0000 0000 0030
15569 element: 0000 0000 0000 002E
15570 element: 0000 0000 0000 002C
15571 element: 0000 0000 0000 002A
15572 element: 0000 0000 0000 0028
15573 element: 0000 0000 0000 0026
15574 element: 0000 0000 0000 0024
15575 element: 0000 0000 0000 0022
15576 element: 0000 0000 0000 0020
15577 element: 0000 0000 0000 001E
15578 element: 0000 0000 0000 001C
15579 element: 0000 0000 0000 001A
15580 element: 0000 0000 0000 0018
15581 element: 0000 0000 0000 0016
15582 element: 0000 0000 0000 0014
15583 element: 0000 0000 0000 0012
15584 element: 0000 0000 0000 0010
15585 element: 0000 0000 0000 000E
15586 element: 0000 0000 0000 000C
15587 element: 0000 0000 0000 000A
15588 element: 0000 0000 0000 0008
15589 element: 0000 0000 0000 0006
15590 element: 0000 0000 0000 0004
15591 element: 0000 0000 0000 0002
15592 element: 0000 0000 0000 0000
15593 array
15594 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
15595 END
15596  
15597  
15598 =head2 Nasm::X86::Array::put($Array, @variables)
15599  
15600 Put an element into an array as long as it is with in its limits established by pushing.
15601  
15602 Parameter Description
15603 1 $Array Array descriptor
15604 2 @variables Variables
15605  
15606 B<Example:>
15607  
15608  
15609 my $c = Rb(0..255);
15610 my $A = CreateArena; my $a = $A->CreateArray;
15611 my $l = V(limit, 15);
15612 my $L = $l + 5;
15613  
15614 my sub put # Put a constant or a variable
15615 {my ($e) = @_;
15616 $a->push(element => (ref($e) ? $e : V($e, $e)));
15617 };
15618  
15619 my sub get # Get a constant or a variable
15620 {my ($i) = @_;
15621 $a->get(index=>(my $v = ref($i) ? $i : K('index', $i)), my $e = V(element));
15622 $v->out("index: ", " "); $e->outNL;
15623 };
15624  
15625 $l->for(sub # Loop to the limit pushing
15626 {my ($index, $start, $next, $end) = @_;
15627 put($index+1);
15628 });
15629  
15630 $l->for(sub # Loop to the limit getting
15631 {my ($index, $start, $next, $end) = @_;
15632 get($index);
15633 });
15634  
15635 put(16);
15636 get(15);
15637  
15638 $L->for(sub
15639 {my ($index, $start, $next, $end) = @_;
15640 put($index+$l+2);
15641 });
15642  
15643 $L->for(sub
15644 {my ($index, $start, $next, $end) = @_;
15645 get($index + $l + 1);
15646 });
15647  
15648 if (1)
15649 {$a->put(my $i = V('index', 9), my $e = V(element, 0xFFF9));
15650 get(9);
15651 }
15652  
15653 if (1)
15654 {$a->put(my $i = V('index', 19), my $e = V(element, 0xEEE9));
15655 get(19);
15656 }
15657  
15658 ($l+$L+1)->for(sub
15659 {my ($i, $start, $next, $end) = @_;
15660 $a->pop(my $e = V(element));
15661 $e->outNL;
15662 });
15663  
15664 V(limit, 38)->for(sub # Push using a loop and reusing the freed space
15665 {my ($index, $start, $next, $end) = @_;
15666 $a->push(element=>$index*2);
15667 });
15668  
15669 V(limit, 38)->for(sub # Push using a loop and reusing the freed space
15670 {my ($index, $start, $next, $end) = @_;
15671 $a->pop(my $e = V(element));
15672 $e->outNL;
15673 });
15674  
15675 $a->dump;
15676  
15677 ok Assemble(debug => 0, eq => <<END);
15678 index: 0000 0000 0000 0000 element: 0000 0000 0000 0001
15679 index: 0000 0000 0000 0001 element: 0000 0000 0000 0002
15680 index: 0000 0000 0000 0002 element: 0000 0000 0000 0003
15681 index: 0000 0000 0000 0003 element: 0000 0000 0000 0004
15682 index: 0000 0000 0000 0004 element: 0000 0000 0000 0005
15683 index: 0000 0000 0000 0005 element: 0000 0000 0000 0006
15684 index: 0000 0000 0000 0006 element: 0000 0000 0000 0007
15685 index: 0000 0000 0000 0007 element: 0000 0000 0000 0008
15686 index: 0000 0000 0000 0008 element: 0000 0000 0000 0009
15687 index: 0000 0000 0000 0009 element: 0000 0000 0000 000A
15688 index: 0000 0000 0000 000A element: 0000 0000 0000 000B
15689 index: 0000 0000 0000 000B element: 0000 0000 0000 000C
15690 index: 0000 0000 0000 000C element: 0000 0000 0000 000D
15691 index: 0000 0000 0000 000D element: 0000 0000 0000 000E
15692 index: 0000 0000 0000 000E element: 0000 0000 0000 000F
15693 index: 0000 0000 0000 000F element: 0000 0000 0000 0010
15694 index: 0000 0000 0000 0010 element: 0000 0000 0000 0011
15695 index: 0000 0000 0000 0011 element: 0000 0000 0000 0012
15696 index: 0000 0000 0000 0012 element: 0000 0000 0000 0013
15697 index: 0000 0000 0000 0013 element: 0000 0000 0000 0014
15698 index: 0000 0000 0000 0014 element: 0000 0000 0000 0015
15699 index: 0000 0000 0000 0015 element: 0000 0000 0000 0016
15700 index: 0000 0000 0000 0016 element: 0000 0000 0000 0017
15701 index: 0000 0000 0000 0017 element: 0000 0000 0000 0018
15702 index: 0000 0000 0000 0018 element: 0000 0000 0000 0019
15703 index: 0000 0000 0000 0019 element: 0000 0000 0000 001A
15704 index: 0000 0000 0000 001A element: 0000 0000 0000 001B
15705 index: 0000 0000 0000 001B element: 0000 0000 0000 001C
15706 index: 0000 0000 0000 001C element: 0000 0000 0000 001D
15707 index: 0000 0000 0000 001D element: 0000 0000 0000 001E
15708 index: 0000 0000 0000 001E element: 0000 0000 0000 001F
15709 index: 0000 0000 0000 001F element: 0000 0000 0000 0020
15710 index: 0000 0000 0000 0020 element: 0000 0000 0000 0021
15711 index: 0000 0000 0000 0021 element: 0000 0000 0000 0022
15712 index: 0000 0000 0000 0022 element: 0000 0000 0000 0023
15713 index: 0000 0000 0000 0023 element: 0000 0000 0000 0024
15714 index: 0000 0000 0000 0009 element: 0000 0000 0000 FFF9
15715 index: 0000 0000 0000 0013 element: 0000 0000 0000 EEE9
15716 element: 0000 0000 0000 0024
15717 element: 0000 0000 0000 0023
15718 element: 0000 0000 0000 0022
15719 element: 0000 0000 0000 0021
15720 element: 0000 0000 0000 0020
15721 element: 0000 0000 0000 001F
15722 element: 0000 0000 0000 001E
15723 element: 0000 0000 0000 001D
15724 element: 0000 0000 0000 001C
15725 element: 0000 0000 0000 001B
15726 element: 0000 0000 0000 001A
15727 element: 0000 0000 0000 0019
15728 element: 0000 0000 0000 0018
15729 element: 0000 0000 0000 0017
15730 element: 0000 0000 0000 0016
15731 element: 0000 0000 0000 0015
15732 element: 0000 0000 0000 EEE9
15733 element: 0000 0000 0000 0013
15734 element: 0000 0000 0000 0012
15735 element: 0000 0000 0000 0011
15736 element: 0000 0000 0000 0010
15737 element: 0000 0000 0000 000F
15738 element: 0000 0000 0000 000E
15739 element: 0000 0000 0000 000D
15740 element: 0000 0000 0000 000C
15741 element: 0000 0000 0000 000B
15742 element: 0000 0000 0000 FFF9
15743 element: 0000 0000 0000 0009
15744 element: 0000 0000 0000 0008
15745 element: 0000 0000 0000 0007
15746 element: 0000 0000 0000 0006
15747 element: 0000 0000 0000 0005
15748 element: 0000 0000 0000 0004
15749 element: 0000 0000 0000 0003
15750 element: 0000 0000 0000 0002
15751 element: 0000 0000 0000 0001
15752 element: 0000 0000 0000 004A
15753 element: 0000 0000 0000 0048
15754 element: 0000 0000 0000 0046
15755 element: 0000 0000 0000 0044
15756 element: 0000 0000 0000 0042
15757 element: 0000 0000 0000 0040
15758 element: 0000 0000 0000 003E
15759 element: 0000 0000 0000 003C
15760 element: 0000 0000 0000 003A
15761 element: 0000 0000 0000 0038
15762 element: 0000 0000 0000 0036
15763 element: 0000 0000 0000 0034
15764 element: 0000 0000 0000 0032
15765 element: 0000 0000 0000 0030
15766 element: 0000 0000 0000 002E
15767 element: 0000 0000 0000 002C
15768 element: 0000 0000 0000 002A
15769 element: 0000 0000 0000 0028
15770 element: 0000 0000 0000 0026
15771 element: 0000 0000 0000 0024
15772 element: 0000 0000 0000 0022
15773 element: 0000 0000 0000 0020
15774 element: 0000 0000 0000 001E
15775 element: 0000 0000 0000 001C
15776 element: 0000 0000 0000 001A
15777 element: 0000 0000 0000 0018
15778 element: 0000 0000 0000 0016
15779 element: 0000 0000 0000 0014
15780 element: 0000 0000 0000 0012
15781 element: 0000 0000 0000 0010
15782 element: 0000 0000 0000 000E
15783 element: 0000 0000 0000 000C
15784 element: 0000 0000 0000 000A
15785 element: 0000 0000 0000 0008
15786 element: 0000 0000 0000 0006
15787 element: 0000 0000 0000 0004
15788 element: 0000 0000 0000 0002
15789 element: 0000 0000 0000 0000
15790 array
15791 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
15792 END
15793  
15794  
15795 =head1 Tree
15796  
15797 Tree constructed as sets of blocks in an arena.
15798  
15799 =head2 Nasm::X86::Arena::DescribeTree($arena)
15800  
15801 Return a descriptor for a tree in the specified arena.
15802  
15803 Parameter Description
15804 1 $arena Arena descriptor
15805  
15806 =head2 Nasm::X86::Arena::CreateTree($arena, $bs)
15807  
15808 Create a tree in an arena.
15809  
15810 Parameter Description
15811 1 $arena Arena description
15812 2 $bs Optional arena address
15813  
15814 B<Example:>
15815  
15816  
15817 my $N = 12;
15818 my $b = CreateArena;
15819 my $t = $b->CreateTree;
15820  
15821 K(count, $N)->for(sub # Add some entries to the tree
15822 {my ($index, $start, $next, $end) = @_;
15823 my $k = $index + 1;
15824 $t->insert($k, $k + 0x100);
15825 $t->insert($k + $N, $k + 0x200);
15826 });
15827  
15828 $t->by(sub # Iterate through the tree
15829 {my ($iter, $end) = @_;
15830 $iter->key ->out('key: ');
15831 $iter->data->out(' data: ');
15832 my $D = V(depth);
15833 $iter->tree->depth($t->address, $iter->node, $D);
15834  
15835 $t->find($iter->key);
15836 $t->found->out(' found: '); $t->data->out(' data: '); $D->outNL(' depth: ');
15837 });
15838  
15839 $t->find(K(key, 0xffff)); $t->found->outNL('Found: '); # Find some entries
15840 $t->find(K(key, 0xd)); $t->found->outNL('Found: ');
15841 If ($t->found > 0,
15842 Then
15843 {$t->data->outNL("Data : ");
15844 });
15845  
15846 ok Assemble(debug => 0, eq => <<END);
15847 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
15848 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
15849 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
15850 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
15851 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
15852 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
15853 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
15854 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
15855 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
15856 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
15857 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
15858 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
15859 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
15860 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
15861 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
15862 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
15863 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
15864 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
15865 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
15866 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
15867 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
15868 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
15869 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
15870 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
15871 Found: 0000 0000 0000 0000
15872 Found: 0000 0000 0000 0001
15873 Data : 0000 0000 0000 0201
15874 END
15875  
15876  
15877 =head2 Nasm::X86::Tree::reload($tree, %options)
15878  
15879 Reload the specified tree description.
15880  
15881 Parameter Description
15882 1 $tree Tree descriptor
15883 2 %options {first=>first node of tree if not the existing first node; arena=>arena used by tree if not the existing arena}
15884  
15885 =head2 Nasm::X86::Tree::find($t, $key, $bs, $first)
15886  
15887 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.
15888  
15889 Parameter Description
15890 1 $t Tree descriptor
15891 2 $key Key field to search for
15892 3 $bs Optional arena address
15893 4 $first Optional start node
15894  
15895 =head2 Nasm::X86::Tree::findAndReload($t, $key)
15896  
15897 Find a key in the specified tree and clone it is it is a sub tree.
15898  
15899 Parameter Description
15900 1 $t Tree descriptor
15901 2 $key Key as a dword
15902  
15903 B<Example:>
15904  
15905  
15906 my $L = K(loop, 4);
15907 my $b = CreateArena;
15908 my $T = $b->CreateTree;
15909 my $t = $T->reload;
15910  
15911 $L->for(sub
15912 {my ($i, $start, $next, $end) = @_;
15913 $t->insertTreeAndReload($i);
15914 $t->first->outNL;
15915 });
15916  
15917 $t->insert($L, $L*2);
15918  
15919 my $f = $T->reload;
15920 $L->for(sub
15921 {my ($i, $start, $next, $end) = @_;
15922 $f->findAndReload($i);
15923 $i->out('i: '); $f->found->out(' f: '); $f->data->out(' d: '); $f->subTree->outNL(' s: ');
15924 });
15925 $f->find($L);
15926 $L->out('N: '); $f->found->out(' f: '); $f->data->out(' d: '); $f->subTree->outNL(' s: ');
15927  
15928 ok Assemble(debug => 0, eq => <<END);
15929 first: 0000 0000 0000 0098
15930 first: 0000 0000 0000 0118
15931 first: 0000 0000 0000 0198
15932 first: 0000 0000 0000 0218
15933 i: 0000 0000 0000 0000 f: 0000 0000 0000 0001 d: 0000 0000 0000 0098 s: 0000 0000 0000 0001
15934 i: 0000 0000 0000 0001 f: 0000 0000 0000 0001 d: 0000 0000 0000 0118 s: 0000 0000 0000 0001
15935 i: 0000 0000 0000 0002 f: 0000 0000 0000 0001 d: 0000 0000 0000 0198 s: 0000 0000 0000 0001
15936 i: 0000 0000 0000 0003 f: 0000 0000 0000 0001 d: 0000 0000 0000 0218 s: 0000 0000 0000 0001
15937 N: 0000 0000 0000 0004 f: 0000 0000 0000 0001 d: 0000 0000 0000 0008 s: 0000 0000 0000 0000
15938 END
15939  
15940  
15941 =head2 Nasm::X86::Tree::findShortString($tree, $string)
15942  
15943 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.
15944  
15945 Parameter Description
15946 1 $tree Tree descriptor
15947 2 $string Short string
15948  
15949 =head2 Nasm::X86::Tree::size($t)
15950  
15951 Return a variable containing the number of keys in the specified tree.
15952  
15953 Parameter Description
15954 1 $t Tree descriptor
15955  
15956 B<Example:>
15957  
15958  
15959 my $b = CreateArena;
15960 my $t = $b->CreateTree;
15961 my $s = $t->size;
15962 $s->outNL;
15963  
15964 V(count, 24)->for(sub
15965 {my ($index, $start, $next, $end) = @_;
15966 my $k = $index + 1; my $d = $k + 0x100;
15967 $t->insert($k, $d);
15968 my $s = $t->size;
15969 $s->outNL;
15970 });
15971  
15972 $t->getKeysDataNode($b->bs, $t->first, 31, 30, 29);
15973 PrintOutStringNL "Root"; $t->first->outNL('First: ');
15974 PrintOutRegisterInHex zmm31, zmm30, zmm29;
15975  
15976 $t->getKeysDataNode($b->bs, V(offset, 0xd8), 28,27,26);
15977 PrintOutStringNL "Left";
15978 PrintOutRegisterInHex zmm28, zmm27, zmm26;
15979  
15980 $t->getKeysDataNode($b->bs, V(offset, 0x258), 28,27,26);
15981 PrintOutStringNL "Left";
15982 PrintOutRegisterInHex zmm28, zmm27, zmm26;
15983  
15984 $t->getKeysDataNode($b->bs, V(offset, 0x198), 28,27,26);
15985 PrintOutStringNL "Left";
15986 PrintOutRegisterInHex zmm28, zmm27, zmm26;
15987  
15988 ok Assemble(debug => 0, eq => <<END);
15989 size: 0000 0000 0000 0000
15990 size: 0000 0000 0000 0001
15991 size: 0000 0000 0000 0002
15992 size: 0000 0000 0000 0003
15993 size: 0000 0000 0000 0004
15994 size: 0000 0000 0000 0005
15995 size: 0000 0000 0000 0006
15996 size: 0000 0000 0000 0007
15997 size: 0000 0000 0000 0008
15998 size: 0000 0000 0000 0009
15999 size: 0000 0000 0000 000A
16000 size: 0000 0000 0000 000B
16001 size: 0000 0000 0000 000C
16002 size: 0000 0000 0000 000D
16003 size: 0000 0000 0000 000E
16004 size: 0000 0000 0000 000F
16005 size: 0000 0000 0000 0010
16006 size: 0000 0000 0000 0011
16007 size: 0000 0000 0000 0012
16008 size: 0000 0000 0000 0013
16009 size: 0000 0000 0000 0014
16010 size: 0000 0000 0000 0015
16011 size: 0000 0000 0000 0016
16012 size: 0000 0000 0000 0017
16013 size: 0000 0000 0000 0018
16014 Root
16015 First: 0000 0000 0000 0018
16016 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
16017 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
16018 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
16019 Left
16020 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
16021 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
16022 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
16023 Left
16024 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
16025 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
16026 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
16027 Left
16028 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
16029 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
16030 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
16031 END
16032  
16033  
16034 =head2 Nasm::X86::Tree::insertDataOrTree($t, $tnd, $key, $data)
16035  
16036 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.
16037  
16038 Parameter Description
16039 1 $t Tree descriptor
16040 2 $tnd 0 - data or 1 - tree
16041 3 $key Key as a dword
16042 4 $data Data as a dword
16043  
16044 =head2 Nasm::X86::Tree::insert($t, $key, $data)
16045  
16046 Insert a dword into into the specified tree at the specified key.
16047  
16048 Parameter Description
16049 1 $t Tree descriptor
16050 2 $key Key as a dword
16051 3 $data Data as a dword
16052  
16053 =head2 Nasm::X86::Tree::insertTree($t, $key, $subTree)
16054  
16055 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.
16056  
16057 Parameter Description
16058 1 $t Tree descriptor
16059 2 $key Key as a dword
16060 3 $subTree Sub tree to insert else an empty one will be added
16061  
16062 B<Example:>
16063  
16064  
16065 my $b = CreateArena;
16066 my $t = $b->CreateTree;
16067 my $T = $b->CreateTree;
16068  
16069 $T->insert (K(key, 2), K(data, 4));
16070 $t->insertTree(K(key, 1), $T);
16071  
16072 $t->print;
16073  
16074 ok Assemble(debug => 0, eq => <<END);
16075 Tree at: 0000 0000 0000 0018
16076 key: 0000 0000 0000 0001 data: 0000 0000 0000 0098 depth: 0000 0000 0000 0001
16077 Tree at: 0000 0000 0000 0098
16078 key: 0000 0000 0000 0002 data: 0000 0000 0000 0004 depth: 0000 0000 0000 0001
16079 END
16080  
16081 my $L = K(loop, 11);
16082 my $b = CreateArena;
16083 my $B = CreateArena;
16084 my $t = $b->CreateTree;
16085 my $T = $B->CreateTree;
16086  
16087 $L->for(sub
16088 {my ($i, $start, $next, $end) = @_;
16089 $t->insert($i+0x11, K(data, 0xFF));
16090 $T->insert($i+0x22, K(data, 0xDD));
16091 });
16092  
16093 $b->dump;
16094 $B->dump;
16095  
16096 $t->print;
16097 $T->print;
16098  
16099 ok Assemble(debug => 0, eq => <<END);
16100 Arena
16101 Size: 0000 0000 0000 1000
16102 Used: 0000 0000 0000 0098
16103 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
16104 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
16105 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
16106 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
16107 Arena
16108 Size: 0000 0000 0000 1000
16109 Used: 0000 0000 0000 0098
16110 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
16111 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
16112 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
16113 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
16114 Tree at: 0000 0000 0000 0018
16115 key: 0000 0000 0000 0011 data: 0000 0000 0000 00FF depth: 0000 0000 0000 0001
16116 key: 0000 0000 0000 0012 data: 0000 0000 0000 00FF depth: 0000 0000 0000 0001
16117 key: 0000 0000 0000 0013 data: 0000 0000 0000 00FF depth: 0000 0000 0000 0001
16118 key: 0000 0000 0000 0014 data: 0000 0000 0000 00FF depth: 0000 0000 0000 0001
16119 key: 0000 0000 0000 0015 data: 0000 0000 0000 00FF depth: 0000 0000 0000 0001
16120 key: 0000 0000 0000 0016 data: 0000 0000 0000 00FF depth: 0000 0000 0000 0001
16121 key: 0000 0000 0000 0017 data: 0000 0000 0000 00FF depth: 0000 0000 0000 0001
16122 key: 0000 0000 0000 0018 data: 0000 0000 0000 00FF depth: 0000 0000 0000 0001
16123 key: 0000 0000 0000 0019 data: 0000 0000 0000 00FF depth: 0000 0000 0000 0001
16124 key: 0000 0000 0000 001A data: 0000 0000 0000 00FF depth: 0000 0000 0000 0001
16125 key: 0000 0000 0000 001B data: 0000 0000 0000 00FF depth: 0000 0000 0000 0001
16126 Tree at: 0000 0000 0000 0018
16127 key: 0000 0000 0000 0022 data: 0000 0000 0000 00DD depth: 0000 0000 0000 0001
16128 key: 0000 0000 0000 0023 data: 0000 0000 0000 00DD depth: 0000 0000 0000 0001
16129 key: 0000 0000 0000 0024 data: 0000 0000 0000 00DD depth: 0000 0000 0000 0001
16130 key: 0000 0000 0000 0025 data: 0000 0000 0000 00DD depth: 0000 0000 0000 0001
16131 key: 0000 0000 0000 0026 data: 0000 0000 0000 00DD depth: 0000 0000 0000 0001
16132 key: 0000 0000 0000 0027 data: 0000 0000 0000 00DD depth: 0000 0000 0000 0001
16133 key: 0000 0000 0000 0028 data: 0000 0000 0000 00DD depth: 0000 0000 0000 0001
16134 key: 0000 0000 0000 0029 data: 0000 0000 0000 00DD depth: 0000 0000 0000 0001
16135 key: 0000 0000 0000 002A data: 0000 0000 0000 00DD depth: 0000 0000 0000 0001
16136 key: 0000 0000 0000 002B data: 0000 0000 0000 00DD depth: 0000 0000 0000 0001
16137 key: 0000 0000 0000 002C data: 0000 0000 0000 00DD depth: 0000 0000 0000 0001
16138 END
16139  
16140  
16141 =head2 Nasm::X86::Tree::insertTreeAndReload($t, $key)
16142  
16143 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.
16144  
16145 Parameter Description
16146 1 $t Tree descriptor
16147 2 $key Key as a dword
16148  
16149 B<Example:>
16150  
16151  
16152 my $L = K(loop, 4);
16153 my $b = CreateArena;
16154 my $T = $b->CreateTree;
16155 my $t = $T->reload;
16156  
16157 $L->for(sub
16158 {my ($i, $start, $next, $end) = @_;
16159 $t->insertTreeAndReload($i);
16160 $t->first->outNL;
16161 });
16162  
16163 $t->insert($L, $L*2);
16164  
16165 my $f = $T->reload;
16166 $L->for(sub
16167 {my ($i, $start, $next, $end) = @_;
16168 $f->findAndReload($i);
16169 $i->out('i: '); $f->found->out(' f: '); $f->data->out(' d: '); $f->subTree->outNL(' s: ');
16170 });
16171 $f->find($L);
16172 $L->out('N: '); $f->found->out(' f: '); $f->data->out(' d: '); $f->subTree->outNL(' s: ');
16173  
16174 ok Assemble(debug => 0, eq => <<END);
16175 first: 0000 0000 0000 0098
16176 first: 0000 0000 0000 0118
16177 first: 0000 0000 0000 0198
16178 first: 0000 0000 0000 0218
16179 i: 0000 0000 0000 0000 f: 0000 0000 0000 0001 d: 0000 0000 0000 0098 s: 0000 0000 0000 0001
16180 i: 0000 0000 0000 0001 f: 0000 0000 0000 0001 d: 0000 0000 0000 0118 s: 0000 0000 0000 0001
16181 i: 0000 0000 0000 0002 f: 0000 0000 0000 0001 d: 0000 0000 0000 0198 s: 0000 0000 0000 0001
16182 i: 0000 0000 0000 0003 f: 0000 0000 0000 0001 d: 0000 0000 0000 0218 s: 0000 0000 0000 0001
16183 N: 0000 0000 0000 0004 f: 0000 0000 0000 0001 d: 0000 0000 0000 0008 s: 0000 0000 0000 0000
16184 END
16185  
16186  
16187 =head2 Nasm::X86::Tree::insertShortString($tree, $string, $data)
16188  
16189 Insert some data at the end of a chain of sub trees keyed by the contents of a short string.
16190  
16191 Parameter Description
16192 1 $tree Tree descriptor
16193 2 $string Short string
16194 3 $data Data as a dword
16195  
16196 =head2 Nasm::X86::Tree::leftOrRightMost($t, $dir, $bs, $node, $offset)
16197  
16198 Return the offset of the left most or right most node.
16199  
16200 Parameter Description
16201 1 $t Tree descriptor
16202 2 $dir Direction: left = 0 or right = 1
16203 3 $bs Arena address
16204 4 $node Start node
16205 5 $offset Offset of located node
16206  
16207 =head2 Nasm::X86::Tree::leftMost($t, $bs, $node, $offset)
16208  
16209 Return the offset of the left most node from the specified node.
16210  
16211 Parameter Description
16212 1 $t Tree descriptor
16213 2 $bs Arena address
16214 3 $node Start node
16215 4 $offset Returned offset
16216  
16217 =head2 Nasm::X86::Tree::rightMost($t, $bs, $node, $offset)
16218  
16219 Return the offset of the left most node from the specified node.
16220  
16221 Parameter Description
16222 1 $t Tree descriptor
16223 2 $bs Arena address
16224 3 $node Start node
16225 4 $offset Returned offset
16226  
16227 =head2 Nasm::X86::Tree::depth($t, $bs, $node, $depth)
16228  
16229 Return the depth of a node within a tree.
16230  
16231 Parameter Description
16232 1 $t Tree descriptor
16233 2 $bs Arena address
16234 3 $node Node
16235 4 $depth Return depth
16236  
16237 =head2 Sub trees
16238  
16239 Construct trees of trees.
16240  
16241 =head2 Print
16242  
16243 Print a tree
16244  
16245 =head3 Nasm::X86::Tree::print($t)
16246  
16247 Print a tree.
16248  
16249 Parameter Description
16250 1 $t Tree
16251  
16252 B<Example:>
16253  
16254  
16255 my $L = V(loop, 45);
16256  
16257 my $b = CreateArena;
16258 my $t = $b->CreateTree;
16259  
16260 $L->for(sub
16261 {my ($i, $start, $next, $end) = @_;
16262 my $l = $L - $i;
16263 If ($i % 2 == 0, sub
16264 {$t->insert($i, $l);
16265 $t->insertTree($l);
16266 });
16267 });
16268  
16269 $t->print;
16270  
16271 ok Assemble(debug => 0, eq => <<END);
16272 Tree at: 0000 0000 0000 0018
16273 key: 0000 0000 0000 0000 data: 0000 0000 0000 002D depth: 0000 0000 0000 0002
16274 key: 0000 0000 0000 0001 data: 0000 0000 0000 0ED8 depth: 0000 0000 0000 0002
16275 Tree at: 0000 0000 0000 0ED8
16276 key: 0000 0000 0000 0002 data: 0000 0000 0000 002B depth: 0000 0000 0000 0002
16277 key: 0000 0000 0000 0003 data: 0000 0000 0000 0E58 depth: 0000 0000 0000 0002
16278 Tree at: 0000 0000 0000 0E58
16279 key: 0000 0000 0000 0004 data: 0000 0000 0000 0029 depth: 0000 0000 0000 0002
16280 key: 0000 0000 0000 0005 data: 0000 0000 0000 0DD8 depth: 0000 0000 0000 0002
16281 Tree at: 0000 0000 0000 0DD8
16282 key: 0000 0000 0000 0006 data: 0000 0000 0000 0027 depth: 0000 0000 0000 0002
16283 key: 0000 0000 0000 0007 data: 0000 0000 0000 0D58 depth: 0000 0000 0000 0001
16284 Tree at: 0000 0000 0000 0D58
16285 key: 0000 0000 0000 0008 data: 0000 0000 0000 0025 depth: 0000 0000 0000 0002
16286 key: 0000 0000 0000 0009 data: 0000 0000 0000 0CD8 depth: 0000 0000 0000 0002
16287 Tree at: 0000 0000 0000 0CD8
16288 key: 0000 0000 0000 000A data: 0000 0000 0000 0023 depth: 0000 0000 0000 0002
16289 key: 0000 0000 0000 000B data: 0000 0000 0000 0C58 depth: 0000 0000 0000 0002
16290 Tree at: 0000 0000 0000 0C58
16291 key: 0000 0000 0000 000C data: 0000 0000 0000 0021 depth: 0000 0000 0000 0002
16292 key: 0000 0000 0000 000D data: 0000 0000 0000 0BD8 depth: 0000 0000 0000 0002
16293 Tree at: 0000 0000 0000 0BD8
16294 key: 0000 0000 0000 000E data: 0000 0000 0000 001F depth: 0000 0000 0000 0001
16295 key: 0000 0000 0000 000F data: 0000 0000 0000 0B58 depth: 0000 0000 0000 0002
16296 Tree at: 0000 0000 0000 0B58
16297 key: 0000 0000 0000 0010 data: 0000 0000 0000 001D depth: 0000 0000 0000 0002
16298 key: 0000 0000 0000 0011 data: 0000 0000 0000 0AD8 depth: 0000 0000 0000 0002
16299 Tree at: 0000 0000 0000 0AD8
16300 key: 0000 0000 0000 0012 data: 0000 0000 0000 001B depth: 0000 0000 0000 0002
16301 key: 0000 0000 0000 0013 data: 0000 0000 0000 0998 depth: 0000 0000 0000 0002
16302 Tree at: 0000 0000 0000 0998
16303 key: 0000 0000 0000 0014 data: 0000 0000 0000 0019 depth: 0000 0000 0000 0002
16304 key: 0000 0000 0000 0015 data: 0000 0000 0000 0918 depth: 0000 0000 0000 0002
16305 Tree at: 0000 0000 0000 0918
16306 key: 0000 0000 0000 0016 data: 0000 0000 0000 0017 depth: 0000 0000 0000 0002
16307 key: 0000 0000 0000 0017 data: 0000 0000 0000 0898 depth: 0000 0000 0000 0002
16308 Tree at: 0000 0000 0000 0898
16309 key: 0000 0000 0000 0018 data: 0000 0000 0000 0015 depth: 0000 0000 0000 0001
16310 key: 0000 0000 0000 0019 data: 0000 0000 0000 0818 depth: 0000 0000 0000 0002
16311 Tree at: 0000 0000 0000 0818
16312 key: 0000 0000 0000 001A data: 0000 0000 0000 0013 depth: 0000 0000 0000 0002
16313 key: 0000 0000 0000 001B data: 0000 0000 0000 06D8 depth: 0000 0000 0000 0002
16314 Tree at: 0000 0000 0000 06D8
16315 key: 0000 0000 0000 001C data: 0000 0000 0000 0011 depth: 0000 0000 0000 0002
16316 key: 0000 0000 0000 001D data: 0000 0000 0000 0658 depth: 0000 0000 0000 0002
16317 Tree at: 0000 0000 0000 0658
16318 key: 0000 0000 0000 001E data: 0000 0000 0000 000F depth: 0000 0000 0000 0002
16319 key: 0000 0000 0000 001F data: 0000 0000 0000 05D8 depth: 0000 0000 0000 0002
16320 Tree at: 0000 0000 0000 05D8
16321 key: 0000 0000 0000 0020 data: 0000 0000 0000 000D depth: 0000 0000 0000 0002
16322 key: 0000 0000 0000 0021 data: 0000 0000 0000 0398 depth: 0000 0000 0000 0001
16323 Tree at: 0000 0000 0000 0398
16324 key: 0000 0000 0000 0022 data: 0000 0000 0000 000B depth: 0000 0000 0000 0002
16325 key: 0000 0000 0000 0023 data: 0000 0000 0000 0318 depth: 0000 0000 0000 0002
16326 Tree at: 0000 0000 0000 0318
16327 key: 0000 0000 0000 0024 data: 0000 0000 0000 0009 depth: 0000 0000 0000 0002
16328 key: 0000 0000 0000 0025 data: 0000 0000 0000 0298 depth: 0000 0000 0000 0002
16329 Tree at: 0000 0000 0000 0298
16330 key: 0000 0000 0000 0026 data: 0000 0000 0000 0007 depth: 0000 0000 0000 0002
16331 key: 0000 0000 0000 0027 data: 0000 0000 0000 0218 depth: 0000 0000 0000 0002
16332 Tree at: 0000 0000 0000 0218
16333 key: 0000 0000 0000 0028 data: 0000 0000 0000 0005 depth: 0000 0000 0000 0002
16334 key: 0000 0000 0000 0029 data: 0000 0000 0000 0198 depth: 0000 0000 0000 0002
16335 Tree at: 0000 0000 0000 0198
16336 key: 0000 0000 0000 002A data: 0000 0000 0000 0003 depth: 0000 0000 0000 0002
16337 key: 0000 0000 0000 002B data: 0000 0000 0000 0118 depth: 0000 0000 0000 0002
16338 Tree at: 0000 0000 0000 0118
16339 key: 0000 0000 0000 002C data: 0000 0000 0000 0001 depth: 0000 0000 0000 0002
16340 key: 0000 0000 0000 002D data: 0000 0000 0000 0098 depth: 0000 0000 0000 0002
16341 Tree at: 0000 0000 0000 0098
16342 END
16343  
16344  
16345 =head3 Nasm::X86::Tree::dump($t, $first, $bs)
16346  
16347 Dump a tree and all its sub trees.
16348  
16349 Parameter Description
16350 1 $t Tree
16351 2 $first Optional offset to first node
16352 3 $bs Optional arena address
16353  
16354 B<Example:>
16355  
16356  
16357 my $L = V(loop, 15);
16358  
16359 my $b = CreateArena;
16360 my $t = $b->CreateTree;
16361  
16362 $L->for(sub
16363 {my ($i, $start, $next, $end) = @_;
16364 If ($i % 2 == 0,
16365 Then
16366 {$t->insert ($i, $i);
16367 },
16368 Else
16369 {$t->insertTree($i);
16370 });
16371 });
16372  
16373 $t->dump();
16374  
16375 ok Assemble(debug => 0, eq => <<END);
16376 Tree at: 0000 0000 0000 0018 length: 0000 0000 0000 0001
16377 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
16378 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
16379 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
16380 index: 0000 0000 0000 0000 key: 0000 0000 0000 0007 data: 0000 0000 0000 0218 subTree
16381 Tree at: 0000 0000 0000 0218 length: 0000 0000 0000 0000
16382 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
16383 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
16384 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
16385 end
16386 Tree at: 0000 0000 0000 0458 length: 0000 0000 0000 0007
16387 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
16388 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
16389 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
16390 index: 0000 0000 0000 0000 key: 0000 0000 0000 0000 data: 0000 0000 0000 0000
16391 index: 0000 0000 0000 0001 key: 0000 0000 0000 0001 data: 0000 0000 0000 0098 subTree
16392 index: 0000 0000 0000 0002 key: 0000 0000 0000 0002 data: 0000 0000 0000 0002
16393 index: 0000 0000 0000 0003 key: 0000 0000 0000 0003 data: 0000 0000 0000 0118 subTree
16394 index: 0000 0000 0000 0004 key: 0000 0000 0000 0004 data: 0000 0000 0000 0004
16395 index: 0000 0000 0000 0005 key: 0000 0000 0000 0005 data: 0000 0000 0000 0198 subTree
16396 index: 0000 0000 0000 0006 key: 0000 0000 0000 0006 data: 0000 0000 0000 0006
16397 Tree at: 0000 0000 0000 0098 length: 0000 0000 0000 0000
16398 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
16399 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
16400 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
16401 end
16402 Tree at: 0000 0000 0000 0118 length: 0000 0000 0000 0000
16403 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
16404 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
16405 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
16406 end
16407 Tree at: 0000 0000 0000 0198 length: 0000 0000 0000 0000
16408 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
16409 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
16410 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
16411 end
16412 end
16413 Tree at: 0000 0000 0000 0518 length: 0000 0000 0000 0007
16414 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
16415 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
16416 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
16417 index: 0000 0000 0000 0000 key: 0000 0000 0000 0008 data: 0000 0000 0000 0008
16418 index: 0000 0000 0000 0001 key: 0000 0000 0000 0009 data: 0000 0000 0000 0298 subTree
16419 index: 0000 0000 0000 0002 key: 0000 0000 0000 000A data: 0000 0000 0000 000A
16420 index: 0000 0000 0000 0003 key: 0000 0000 0000 000B data: 0000 0000 0000 0318 subTree
16421 index: 0000 0000 0000 0004 key: 0000 0000 0000 000C data: 0000 0000 0000 000C
16422 index: 0000 0000 0000 0005 key: 0000 0000 0000 000D data: 0000 0000 0000 0398 subTree
16423 index: 0000 0000 0000 0006 key: 0000 0000 0000 000E data: 0000 0000 0000 000E
16424 Tree at: 0000 0000 0000 0298 length: 0000 0000 0000 0000
16425 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
16426 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
16427 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
16428 end
16429 Tree at: 0000 0000 0000 0318 length: 0000 0000 0000 0000
16430 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
16431 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
16432 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
16433 end
16434 Tree at: 0000 0000 0000 0398 length: 0000 0000 0000 0000
16435 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
16436 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
16437 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
16438 end
16439 end
16440 end
16441 END
16442  
16443  
16444 =head2 Iteration
16445  
16446 Iterate through a tree non recursively
16447  
16448 =head3 Nasm::X86::Tree::iterator($t, $bs, $first)
16449  
16450 Iterate through a multi way tree starting either at the specified node or the first node of the specified tree.
16451  
16452 Parameter Description
16453 1 $t Tree
16454 2 $bs Optional arena else the arena associated with the tree
16455 3 $first Optionally the node to start at else the first node of the supplied tree will be used
16456  
16457 =head3 Nasm::X86::Tree::Iterator::next($iter)
16458  
16459 Next element in the tree.
16460  
16461 Parameter Description
16462 1 $iter Iterator
16463  
16464 =head3 Nasm::X86::Tree::by($t, $block, $bs, $first)
16465  
16466 Call the specified block with each (key, data) from the specified tree in order.
16467  
16468 Parameter Description
16469 1 $t Tree descriptor
16470 2 $block Block to execute
16471 3 $bs Arena address if not the one associated with the tree descriptor
16472 4 $first First node offset if not the root of the tree provided
16473  
16474 =head1 Quarks
16475  
16476 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.
16477  
16478 =head2 Nasm::X86::Arena::DescribeQuarks($arena)
16479  
16480 Return a descriptor for a tree in the specified arena.
16481  
16482 Parameter Description
16483 1 $arena Arena descriptor
16484  
16485 =head2 Nasm::X86::Arena::CreateQuarks($arena)
16486  
16487 Create quarks in a specified arena.
16488  
16489 Parameter Description
16490 1 $arena Arena description optional arena address
16491  
16492 B<Example:>
16493  
16494  
16495 my $N = 5;
16496 my $a = CreateArena; # Arena containing quarks
16497 my $Q = $a->CreateQuarks; # Quarks
16498  
16499 my $s = CreateShortString(0); # Short string used to load and unload quarks
16500 my $d = Rb(1..63);
16501  
16502 for my $i(1..$N) # Load a set of quarks
16503 {my $j = $i - 1;
16504 $s->load(K(address, $d), K(size, 4+$i));
16505 my $q = $Q->quarkFromShortString($s);
16506 $q->outNL("New quark $j: "); # New quark, new number
16507 }
16508 PrintOutNL;
16509  
16510 for my $i(reverse 1..$N) # Reload a set of quarks
16511 {my $j = $i - 1;
16512 $s->load(K(address, $d), K(size, 4+$i));
16513 my $q = $Q->quarkFromShortString($s);
16514 $q->outNL("Old quark $j: "); # Old quark, old number
16515 }
16516 PrintOutNL;
16517  
16518 for my $i(1..$N) # Dump quarks
16519 {my $j = $i - 1;
16520 $s->clear;
16521 $Q->shortStringFromQuark(K(quark, $j), $s);
16522 PrintOutString "Quark string $j: ";
16523 PrintOutRegisterInHex xmm0;
16524 }
16525  
16526 ok Assemble(debug => 0, trace => 0, eq => <<END);
16527 New quark 0: 0000 0000 0000 0000
16528 New quark 1: 0000 0000 0000 0001
16529 New quark 2: 0000 0000 0000 0002
16530 New quark 3: 0000 0000 0000 0003
16531 New quark 4: 0000 0000 0000 0004
16532  
16533 Old quark 4: 0000 0000 0000 0004
16534 Old quark 3: 0000 0000 0000 0003
16535 Old quark 2: 0000 0000 0000 0002
16536 Old quark 1: 0000 0000 0000 0001
16537 Old quark 0: 0000 0000 0000 0000
16538  
16539 Quark string 0: xmm0: 0000 0000 0000 0000 0000 0504 0302 0105
16540 Quark string 1: xmm0: 0000 0000 0000 0000 0006 0504 0302 0106
16541 Quark string 2: xmm0: 0000 0000 0000 0000 0706 0504 0302 0107
16542 Quark string 3: xmm0: 0000 0000 0000 0008 0706 0504 0302 0108
16543 Quark string 4: xmm0: 0000 0000 0000 0908 0706 0504 0302 0109
16544 END
16545  
16546 my $N = 5;
16547 my $a = CreateArena; # Arena containing quarks
16548 my $Q1 = $a->CreateQuarks; # Quarks
16549 my $Q2 = $a->CreateQuarks; # Quarks
16550  
16551 my $s = CreateShortString(0); # Short string used to load and unload quarks
16552 my $d = Rb(1..63);
16553  
16554 for my $i(1..$N) # Load first set of quarks
16555 {my $j = $i - 1;
16556 $s->load(K(address, $d), K(size, 4+$i));
16557 my $q = $Q1->quarkFromShortString($s);
16558 $q->outNL("Q1 $j: ");
16559 }
16560 PrintOutNL;
16561  
16562 for my $i(1..$N) # Load second set of quarks
16563 {my $j = $i - 1;
16564 $s->load(K(address, $d), K(size, 5+$i));
16565 my $q = $Q2->quarkFromShortString($s);
16566 $q->outNL("Q2 $j: ");
16567 }
16568 PrintOutNL;
16569  
16570 $Q1->quarkToQuark(K(three,3), $Q1)->outNL;
16571 $Q1->quarkToQuark(K(three,3), $Q2)->outNL;
16572 $Q2->quarkToQuark(K(two, 2), $Q1)->outNL;
16573 $Q2->quarkToQuark(K(two, 2), $Q2)->outNL;
16574  
16575 ok Assemble(debug => 0, trace => 0, eq => <<END);
16576 Q1 0: 0000 0000 0000 0000
16577 Q1 1: 0000 0000 0000 0001
16578 Q1 2: 0000 0000 0000 0002
16579 Q1 3: 0000 0000 0000 0003
16580 Q1 4: 0000 0000 0000 0004
16581  
16582 Q2 0: 0000 0000 0000 0000
16583 Q2 1: 0000 0000 0000 0001
16584 Q2 2: 0000 0000 0000 0002
16585 Q2 3: 0000 0000 0000 0003
16586 Q2 4: 0000 0000 0000 0004
16587  
16588 found: 0000 0000 0000 0003
16589 found: 0000 0000 0000 0002
16590 found: 0000 0000 0000 0003
16591 found: 0000 0000 0000 0002
16592 END
16593  
16594 my $s = CreateShortString(0); # Short string used to load and unload quarks
16595 my $d = Rb(1..63);
16596 $s->loadDwordBytes(0, K(address, $d), K(size, 9));
16597 PrintOutRegisterInHex xmm0;
16598  
16599 ok Assemble(debug => 0, trace => 0, eq => <<END);
16600 xmm0: 0000 0000 0000 211D 1915 110D 0905 0109
16601 END
16602  
16603  
16604 =head2 Nasm::X86::Quarks::reload($q, %options)
16605  
16606 Reload the description of a set of quarks.
16607  
16608 Parameter Description
16609 1 $q Quarks
16610 2 %options {arena=>arena to use; tree => first tree block; array => first array block}
16611  
16612 =head2 Nasm::X86::Quarks::quarkFromShortString($q, $string)
16613  
16614 Create a quark from a short string.
16615  
16616 Parameter Description
16617 1 $q Quarks
16618 2 $string Short string
16619  
16620 B<Example:>
16621  
16622  
16623 my $N = 5;
16624 my $a = CreateArena; # Arena containing quarks
16625 my $Q = $a->CreateQuarks; # Quarks
16626  
16627 my $s = CreateShortString(0); # Short string used to load and unload quarks
16628 my $d = Rb(1..63);
16629  
16630 for my $i(1..$N) # Load a set of quarks
16631 {my $j = $i - 1;
16632 $s->load(K(address, $d), K(size, 4+$i));
16633 my $q = $Q->quarkFromShortString($s);
16634 $q->outNL("New quark $j: "); # New quark, new number
16635 }
16636 PrintOutNL;
16637  
16638 for my $i(reverse 1..$N) # Reload a set of quarks
16639 {my $j = $i - 1;
16640 $s->load(K(address, $d), K(size, 4+$i));
16641 my $q = $Q->quarkFromShortString($s);
16642 $q->outNL("Old quark $j: "); # Old quark, old number
16643 }
16644 PrintOutNL;
16645  
16646 for my $i(1..$N) # Dump quarks
16647 {my $j = $i - 1;
16648 $s->clear;
16649 $Q->shortStringFromQuark(K(quark, $j), $s);
16650 PrintOutString "Quark string $j: ";
16651 PrintOutRegisterInHex xmm0;
16652 }
16653  
16654 ok Assemble(debug => 0, trace => 0, eq => <<END);
16655 New quark 0: 0000 0000 0000 0000
16656 New quark 1: 0000 0000 0000 0001
16657 New quark 2: 0000 0000 0000 0002
16658 New quark 3: 0000 0000 0000 0003
16659 New quark 4: 0000 0000 0000 0004
16660  
16661 Old quark 4: 0000 0000 0000 0004
16662 Old quark 3: 0000 0000 0000 0003
16663 Old quark 2: 0000 0000 0000 0002
16664 Old quark 1: 0000 0000 0000 0001
16665 Old quark 0: 0000 0000 0000 0000
16666  
16667 Quark string 0: xmm0: 0000 0000 0000 0000 0000 0504 0302 0105
16668 Quark string 1: xmm0: 0000 0000 0000 0000 0006 0504 0302 0106
16669 Quark string 2: xmm0: 0000 0000 0000 0000 0706 0504 0302 0107
16670 Quark string 3: xmm0: 0000 0000 0000 0008 0706 0504 0302 0108
16671 Quark string 4: xmm0: 0000 0000 0000 0908 0706 0504 0302 0109
16672 END
16673  
16674 my $N = 5;
16675 my $a = CreateArena; # Arena containing quarks
16676 my $Q1 = $a->CreateQuarks; # Quarks
16677 my $Q2 = $a->CreateQuarks; # Quarks
16678  
16679 my $s = CreateShortString(0); # Short string used to load and unload quarks
16680 my $d = Rb(1..63);
16681  
16682 for my $i(1..$N) # Load first set of quarks
16683 {my $j = $i - 1;
16684 $s->load(K(address, $d), K(size, 4+$i));
16685 my $q = $Q1->quarkFromShortString($s);
16686 $q->outNL("Q1 $j: ");
16687 }
16688 PrintOutNL;
16689  
16690 for my $i(1..$N) # Load second set of quarks
16691 {my $j = $i - 1;
16692 $s->load(K(address, $d), K(size, 5+$i));
16693 my $q = $Q2->quarkFromShortString($s);
16694 $q->outNL("Q2 $j: ");
16695 }
16696 PrintOutNL;
16697  
16698 $Q1->quarkToQuark(K(three,3), $Q1)->outNL;
16699 $Q1->quarkToQuark(K(three,3), $Q2)->outNL;
16700 $Q2->quarkToQuark(K(two, 2), $Q1)->outNL;
16701 $Q2->quarkToQuark(K(two, 2), $Q2)->outNL;
16702  
16703 ok Assemble(debug => 0, trace => 0, eq => <<END);
16704 Q1 0: 0000 0000 0000 0000
16705 Q1 1: 0000 0000 0000 0001
16706 Q1 2: 0000 0000 0000 0002
16707 Q1 3: 0000 0000 0000 0003
16708 Q1 4: 0000 0000 0000 0004
16709  
16710 Q2 0: 0000 0000 0000 0000
16711 Q2 1: 0000 0000 0000 0001
16712 Q2 2: 0000 0000 0000 0002
16713 Q2 3: 0000 0000 0000 0003
16714 Q2 4: 0000 0000 0000 0004
16715  
16716 found: 0000 0000 0000 0003
16717 found: 0000 0000 0000 0002
16718 found: 0000 0000 0000 0003
16719 found: 0000 0000 0000 0002
16720 END
16721  
16722 my $s = CreateShortString(0); # Short string used to load and unload quarks
16723 my $d = Rb(1..63);
16724 $s->loadDwordBytes(0, K(address, $d), K(size, 9));
16725 PrintOutRegisterInHex xmm0;
16726  
16727 ok Assemble(debug => 0, trace => 0, eq => <<END);
16728 xmm0: 0000 0000 0000 211D 1915 110D 0905 0109
16729 END
16730  
16731  
16732 =head2 Nasm::X86::Quarks::locateQuarkFromShortString($q, $string)
16733  
16734 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.
16735  
16736 Parameter Description
16737 1 $q Quarks
16738 2 $string Short string
16739  
16740 =head2 Nasm::X86::Quarks::shortStringFromQuark($q, $number, $string)
16741  
16742 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.
16743  
16744 Parameter Description
16745 1 $q Quarks
16746 2 $number Variable quark number
16747 3 $string Short string to load
16748  
16749 B<Example:>
16750  
16751  
16752 my $N = 5;
16753 my $a = CreateArena; # Arena containing quarks
16754 my $Q = $a->CreateQuarks; # Quarks
16755  
16756 my $s = CreateShortString(0); # Short string used to load and unload quarks
16757 my $d = Rb(1..63);
16758  
16759 for my $i(1..$N) # Load a set of quarks
16760 {my $j = $i - 1;
16761 $s->load(K(address, $d), K(size, 4+$i));
16762 my $q = $Q->quarkFromShortString($s);
16763 $q->outNL("New quark $j: "); # New quark, new number
16764 }
16765 PrintOutNL;
16766  
16767 for my $i(reverse 1..$N) # Reload a set of quarks
16768 {my $j = $i - 1;
16769 $s->load(K(address, $d), K(size, 4+$i));
16770 my $q = $Q->quarkFromShortString($s);
16771 $q->outNL("Old quark $j: "); # Old quark, old number
16772 }
16773 PrintOutNL;
16774  
16775 for my $i(1..$N) # Dump quarks
16776 {my $j = $i - 1;
16777 $s->clear;
16778 $Q->shortStringFromQuark(K(quark, $j), $s);
16779 PrintOutString "Quark string $j: ";
16780 PrintOutRegisterInHex xmm0;
16781 }
16782  
16783 ok Assemble(debug => 0, trace => 0, eq => <<END);
16784 New quark 0: 0000 0000 0000 0000
16785 New quark 1: 0000 0000 0000 0001
16786 New quark 2: 0000 0000 0000 0002
16787 New quark 3: 0000 0000 0000 0003
16788 New quark 4: 0000 0000 0000 0004
16789  
16790 Old quark 4: 0000 0000 0000 0004
16791 Old quark 3: 0000 0000 0000 0003
16792 Old quark 2: 0000 0000 0000 0002
16793 Old quark 1: 0000 0000 0000 0001
16794 Old quark 0: 0000 0000 0000 0000
16795  
16796 Quark string 0: xmm0: 0000 0000 0000 0000 0000 0504 0302 0105
16797 Quark string 1: xmm0: 0000 0000 0000 0000 0006 0504 0302 0106
16798 Quark string 2: xmm0: 0000 0000 0000 0000 0706 0504 0302 0107
16799 Quark string 3: xmm0: 0000 0000 0000 0008 0706 0504 0302 0108
16800 Quark string 4: xmm0: 0000 0000 0000 0908 0706 0504 0302 0109
16801 END
16802  
16803 my $N = 5;
16804 my $a = CreateArena; # Arena containing quarks
16805 my $Q1 = $a->CreateQuarks; # Quarks
16806 my $Q2 = $a->CreateQuarks; # Quarks
16807  
16808 my $s = CreateShortString(0); # Short string used to load and unload quarks
16809 my $d = Rb(1..63);
16810  
16811 for my $i(1..$N) # Load first set of quarks
16812 {my $j = $i - 1;
16813 $s->load(K(address, $d), K(size, 4+$i));
16814 my $q = $Q1->quarkFromShortString($s);
16815 $q->outNL("Q1 $j: ");
16816 }
16817 PrintOutNL;
16818  
16819 for my $i(1..$N) # Load second set of quarks
16820 {my $j = $i - 1;
16821 $s->load(K(address, $d), K(size, 5+$i));
16822 my $q = $Q2->quarkFromShortString($s);
16823 $q->outNL("Q2 $j: ");
16824 }
16825 PrintOutNL;
16826  
16827 $Q1->quarkToQuark(K(three,3), $Q1)->outNL;
16828 $Q1->quarkToQuark(K(three,3), $Q2)->outNL;
16829 $Q2->quarkToQuark(K(two, 2), $Q1)->outNL;
16830 $Q2->quarkToQuark(K(two, 2), $Q2)->outNL;
16831  
16832 ok Assemble(debug => 0, trace => 0, eq => <<END);
16833 Q1 0: 0000 0000 0000 0000
16834 Q1 1: 0000 0000 0000 0001
16835 Q1 2: 0000 0000 0000 0002
16836 Q1 3: 0000 0000 0000 0003
16837 Q1 4: 0000 0000 0000 0004
16838  
16839 Q2 0: 0000 0000 0000 0000
16840 Q2 1: 0000 0000 0000 0001
16841 Q2 2: 0000 0000 0000 0002
16842 Q2 3: 0000 0000 0000 0003
16843 Q2 4: 0000 0000 0000 0004
16844  
16845 found: 0000 0000 0000 0003
16846 found: 0000 0000 0000 0002
16847 found: 0000 0000 0000 0003
16848 found: 0000 0000 0000 0002
16849 END
16850  
16851 my $s = CreateShortString(0); # Short string used to load and unload quarks
16852 my $d = Rb(1..63);
16853 $s->loadDwordBytes(0, K(address, $d), K(size, 9));
16854 PrintOutRegisterInHex xmm0;
16855  
16856 ok Assemble(debug => 0, trace => 0, eq => <<END);
16857 xmm0: 0000 0000 0000 211D 1915 110D 0905 0109
16858 END
16859  
16860  
16861 =head2 Nasm::X86::Quarks::quarkToQuark($Q, $number, $q)
16862  
16863 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 forst set we return -1, if it cannot be found in teh seciond set we return -2 else the number of the matching quark.
16864  
16865 Parameter Description
16866 1 $Q Firsts et of quarks
16867 2 $number Variable quark number in first set
16868 3 $q Second set of quarks
16869  
16870 =head2 Nasm::X86::Quarks::quarkFromSub($q, $sub)
16871  
16872 Create a quark from a subroutine definition
16873  
16874 Parameter Description
16875 1 $q Quarks
16876 2 $sub Subroutine definition
16877  
16878 B<Example:>
16879  
16880  
16881 my $s1 = Subroutine
16882 {PrintOutStringNL "11111";
16883 } [], name => 'test1';
16884  
16885 my $s2 = Subroutine
16886 {PrintOutStringNL "22222";
16887 } [], name => 'test2';
16888  
16889 my $a = CreateArena;
16890 my $q = $a->CreateQuarks;
16891 my $n1 = $q->quarkFromSub($s1);
16892 my $n2 = $q->quarkFromSub($s2);
16893  
16894 my $S1 = $q->subFromQuark($n1);
16895 $s1->V->outNL;
16896 $S1 ->outNL(" sub: ");
16897  
16898 my $S2 = $q->subFromQuark($n2);
16899 $s2->V->outNL;
16900 $S2 ->outNL(" sub: ");
16901  
16902 $q->call($n1);
16903 $q->call($n2);
16904  
16905 ok Assemble(debug => 0, trace => 0, eq => <<END);
16906 call: 0000 0000 0040 1006
16907 sub: 0000 0000 0040 1006
16908 call: 0000 0000 0040 107A
16909 sub: 0000 0000 0040 107A
16910 11111
16911 22222
16912 END
16913  
16914  
16915 =head2 Nasm::X86::Quarks::subFromQuark($q, $number)
16916  
16917 Create a quark from a subroutine definition
16918  
16919 Parameter Description
16920 1 $q Quarks
16921 2 $number Variable subroutine number
16922  
16923 B<Example:>
16924  
16925  
16926 my $s1 = Subroutine
16927 {PrintOutStringNL "11111";
16928 } [], name => 'test1';
16929  
16930 my $s2 = Subroutine
16931 {PrintOutStringNL "22222";
16932 } [], name => 'test2';
16933  
16934 my $a = CreateArena;
16935 my $q = $a->CreateQuarks;
16936 my $n1 = $q->quarkFromSub($s1);
16937 my $n2 = $q->quarkFromSub($s2);
16938  
16939 my $S1 = $q->subFromQuark($n1);
16940 $s1->V->outNL;
16941 $S1 ->outNL(" sub: ");
16942  
16943 my $S2 = $q->subFromQuark($n2);
16944 $s2->V->outNL;
16945 $S2 ->outNL(" sub: ");
16946  
16947 $q->call($n1);
16948 $q->call($n2);
16949  
16950 ok Assemble(debug => 0, trace => 0, eq => <<END);
16951 call: 0000 0000 0040 1006
16952 sub: 0000 0000 0040 1006
16953 call: 0000 0000 0040 107A
16954 sub: 0000 0000 0040 107A
16955 11111
16956 22222
16957 END
16958  
16959  
16960 =head2 Nasm::X86::Quarks::call($q, $number)
16961  
16962 Call a subroutine via its quark number. Return one in a variable if the subroutine was found and called else zero.
16963  
16964 Parameter Description
16965 1 $q Quarks
16966 2 $number Variable subroutine number
16967  
16968 =head1 Assemble
16969  
16970 Assemble generated code
16971  
16972 =head2 CallC($sub, @parameters)
16973  
16974 Call a C subroutine.
16975  
16976 Parameter Description
16977 1 $sub Name of the sub to call
16978 2 @parameters Parameters
16979  
16980 B<Example:>
16981  
16982  
16983 my $format = Rs "Hello %s
16984 ";
16985 my $data = Rs "World";
16986  
16987 Extern qw(printf exit malloc strcpy); Link 'c';
16988  
16989  
16990 CallC 'malloc', length($format)+1; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
16991  
16992 Mov r15, rax;
16993  
16994 CallC 'strcpy', r15, $format; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
16995  
16996  
16997 CallC 'printf', r15, $data; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
16998  
16999  
17000 CallC 'exit', 0; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
17001  
17002  
17003 ok Assemble(eq => <<END);
17004 Hello World
17005 END
17006  
17007  
17008 =head2 Extern(@externalReferences)
17009  
17010 Name external references.
17011  
17012 Parameter Description
17013 1 @externalReferences External references
17014  
17015 B<Example:>
17016  
17017  
17018 my $format = Rs "Hello %s
17019 ";
17020 my $data = Rs "World";
17021  
17022  
17023 Extern qw(printf exit malloc strcpy); Link 'c'; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
17024  
17025  
17026 CallC 'malloc', length($format)+1;
17027 Mov r15, rax;
17028 CallC 'strcpy', r15, $format;
17029 CallC 'printf', r15, $data;
17030 CallC 'exit', 0;
17031  
17032 ok Assemble(eq => <<END);
17033 Hello World
17034 END
17035  
17036  
17037 =head2 Link(@libraries)
17038  
17039 Libraries to link with.
17040  
17041 Parameter Description
17042 1 @libraries External references
17043  
17044 B<Example:>
17045  
17046  
17047 my $format = Rs "Hello %s
17048 ";
17049 my $data = Rs "World";
17050  
17051  
17052 Extern qw(printf exit malloc strcpy); Link 'c'; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
17053  
17054  
17055 CallC 'malloc', length($format)+1;
17056 Mov r15, rax;
17057 CallC 'strcpy', r15, $format;
17058 CallC 'printf', r15, $data;
17059 CallC 'exit', 0;
17060  
17061 ok Assemble(eq => <<END);
17062 Hello World
17063 END
17064  
17065  
17066 =head2 Start()
17067  
17068 Initialize the assembler.
17069  
17070  
17071 =head2 Exit($c)
17072  
17073 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.
17074  
17075 Parameter Description
17076 1 $c Return code
17077  
17078 B<Example:>
17079  
17080  
17081 Comment "Print a string from memory";
17082 my $s = "Hello World";
17083 Mov rax, Rs($s);
17084 Mov rdi, length $s;
17085 PrintOutMemory;
17086  
17087 Exit(0); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
17088  
17089  
17090 ok Assemble =~ m(Hello World);
17091  
17092  
17093 =head2 Assemble(%options)
17094  
17095 Assemble the generated code.
17096  
17097 Parameter Description
17098 1 %options Options
17099  
17100 B<Example:>
17101  
17102  
17103 PrintOutStringNL "Hello World";
17104 PrintOutStringNL "Hello
17105 World";
17106 PrintErrStringNL "Hello World";
17107  
17108  
17109 ok Assemble(debug => 0, eq => <<END); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
17110  
17111 Hello World
17112 Hello
17113 World
17114 END
17115  
17116  
17117  
17118 =head1 Hash Definitions
17119  
17120  
17121  
17122  
17123 =head2 Nasm::X86 Definition
17124  
17125  
17126 Tree.
17127  
17128  
17129  
17130  
17131 =head3 Output fields
17132  
17133  
17134 =head4 N
17135  
17136 Initial allocation
17137  
17138 =head4 arena
17139  
17140 The arena containing the quarks
17141  
17142 =head4 args
17143  
17144 Hash of {argument name, argument variable}
17145  
17146 =head4 bs
17147  
17148 Arena containing tree
17149  
17150 =head4 constant
17151  
17152 Constant if true
17153  
17154 =head4 count
17155  
17156 Counter - number of node
17157  
17158 =head4 data
17159  
17160 Data at this position
17161  
17162 =head4 depth
17163  
17164 Lexical depth
17165  
17166 =head4 end
17167  
17168 End label for this subroutine
17169  
17170 =head4 expr
17171  
17172 Expression that initializes the variable
17173  
17174 =head4 first
17175  
17176 Variable addressing offset to first block of keys.
17177  
17178 =head4 found
17179  
17180 Variable indicating whether the last find was successful or not
17181  
17182 =head4 free
17183  
17184 Free chain offset
17185  
17186 =head4 global
17187  
17188 Global if true
17189  
17190 =head4 key
17191  
17192 Key at this position
17193  
17194 =head4 label
17195  
17196 Address in memory
17197  
17198 =head4 leftLength
17199  
17200 Left split length
17201  
17202 =head4 length
17203  
17204 Maximum length in a block
17205  
17206 =head4 lengthOffset
17207  
17208 Offset of length in keys block. The length field is a word - see: "MultiWayTree.svg"
17209  
17210 =head4 level
17211  
17212 Lexical level
17213  
17214 =head4 links
17215  
17216 Location of links in bytes in zmm
17217  
17218 =head4 loop
17219  
17220 Offset of keys, data, node loop.
17221  
17222 =head4 maxKeys
17223  
17224 Maximum number of keys.
17225  
17226 =head4 maximumLength
17227  
17228 The maximum length of a short string
17229  
17230 =head4 more
17231  
17232 Iteration not yet finished
17233  
17234 =head4 name
17235  
17236 Name of the variable
17237  
17238 =head4 nameString
17239  
17240 Name of the sub as a string constant
17241  
17242 =head4 next
17243  
17244 Location of next offset in block in bytes
17245  
17246 =head4 node
17247  
17248 Current node within tree
17249  
17250 =head4 numbersToStrings
17251  
17252 Array mapping numbers to strings
17253  
17254 =head4 options
17255  
17256 Options
17257  
17258 =head4 parameters
17259  
17260 Parameters
17261  
17262 =head4 pos
17263  
17264 Current position within node
17265  
17266 =head4 prev
17267  
17268 Location of prev offset in block in bytes
17269  
17270 =head4 reference
17271  
17272 Reference to another variable
17273  
17274 =head4 rightLength
17275  
17276 Right split length
17277  
17278 =head4 size
17279  
17280 Size field offset
17281  
17282 =head4 slots1
17283  
17284 Number of slots in first block
17285  
17286 =head4 slots2
17287  
17288 Number of slots in second and subsequent blocks
17289  
17290 =head4 splittingKey
17291  
17292 POint at which to split a full block
17293  
17294 =head4 start
17295  
17296 Start label for this subroutine
17297  
17298 =head4 stringsToNumbers
17299  
17300 A tree mapping strings to numbers
17301  
17302 =head4 subTree
17303  
17304 Variable indicating whether the last find found a sub tree
17305  
17306 =head4 tree
17307  
17308 Tree we are iterating over
17309  
17310 =head4 treeBits
17311  
17312 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 .
17313  
17314 =head4 treeBitsMask
17315  
17316 Total of 14 tree bits
17317  
17318 =head4 up
17319  
17320 Offset of up in data block.
17321  
17322 =head4 used
17323  
17324 Used field offset
17325  
17326 =head4 variables
17327  
17328 Argument variables
17329  
17330 =head4 vars
17331  
17332 Number of variables in subroutine
17333  
17334 =head4 width
17335  
17336 Width of a key or data slot.
17337  
17338 =head4 x
17339  
17340 The associated xmm register
17341  
17342 =head4 z
17343  
17344 The full name of the zmm register
17345  
17346 =head4 zmm
17347  
17348 The number of the zmm register containing the string
17349  
17350  
17351  
17352 =head1 Attributes
17353  
17354  
17355 The following is a list of all the attributes in this package. A method coded
17356 with the same name in your package will over ride the method of the same name
17357 in this package and thus provide your value for the attribute in place of the
17358 default value supplied for this attribute by this package.
17359  
17360 =head2 Replaceable Attribute List
17361  
17362  
17363 Pi32 Pi64
17364  
17365  
17366 =head2 Pi32
17367  
17368 Pi as a 32 bit float.
17369  
17370  
17371 =head2 Pi64
17372  
17373 Pi as a 64 bit float.
17374  
17375  
17376  
17377  
17378 =head1 Private Methods
17379  
17380 =head2 Label({return "l".++$Labels unless @_;)
17381  
17382 Create a unique label or reuse the one supplied.
17383  
17384 Parameter Description
17385 1 {return "l".++$Labels unless @_; Generate a label
17386  
17387 =head2 Dbwdq($s, @d)
17388  
17389 Layout data.
17390  
17391 Parameter Description
17392 1 $s Element size
17393 2 @d Data to be laid out
17394  
17395 =head2 Rbwdq($s, @d)
17396  
17397 Layout data.
17398  
17399 Parameter Description
17400 1 $s Element size
17401 2 @d Data to be laid out
17402  
17403 =head2 Nasm::X86::Sub::callTo($sub, $mode, $label, @parameters)
17404  
17405 Call a sub passing it some parameters.
17406  
17407 Parameter Description
17408 1 $sub Subroutine descriptor
17409 2 $mode Mode 0 - direct call or 1 - indirect call
17410 3 $label Label of sub
17411 4 @parameters Parameter variables
17412  
17413 =head2 hexTranslateTable()
17414  
17415 Create/address a hex translate table and return its label.
17416  
17417  
17418 =head2 PrintOutRipInHex()
17419  
17420 Print the instruction pointer in hex.
17421  
17422  
17423 =head2 PrintOutRflagsInHex()
17424  
17425 Print the flags register in hex.
17426  
17427  
17428 =head2 PrintUtf32($channel, $size, $address)
17429  
17430 Print the specified number of utf32 characters at the specified address to the specified channel.
17431  
17432 Parameter Description
17433 1 $channel Channel
17434 2 $size Variable: number of characters to print
17435 3 $address Variable: address of memory
17436  
17437 =head2 Nasm::X86::Variable::dump($left, $channel, $newLine, $title1, $title2)
17438  
17439 Dump the value of a variable to the specified channel adding an optional title and new line if requested.
17440  
17441 Parameter Description
17442 1 $left Left variable
17443 2 $channel Channel
17444 3 $newLine New line required
17445 4 $title1 Optional leading title
17446 5 $title2 Optional trailing title
17447  
17448 B<Example:>
17449  
17450  
17451 my $a = V(a, 3); $a->outNL;
17452 my $b = K(b, 2); $b->outNL;
17453 my $c = $a + $b; $c->outNL;
17454 my $d = $c - $a; $d->outNL;
17455 my $g = $a * $b; $g->outNL;
17456 my $h = $g / $b; $h->outNL;
17457 my $i = $a % $b; $i->outNL;
17458  
17459 If ($a == 3,
17460 Then
17461 {PrintOutStringNL "a == 3"
17462 },
17463 Else
17464 {PrintOutStringNL "a != 3"
17465 });
17466  
17467 ++$a; $a->outNL;
17468 --$a; $a->outNL;
17469  
17470 ok Assemble(debug => 0, eq => <<END);
17471 a: 0000 0000 0000 0003
17472 b: 0000 0000 0000 0002
17473 (a add b): 0000 0000 0000 0005
17474 ((a add b) sub a): 0000 0000 0000 0002
17475 (a times b): 0000 0000 0000 0006
17476 ((a times b) / b): 0000 0000 0000 0003
17477 (a % b): 0000 0000 0000 0001
17478 a == 3
17479 a: 0000 0000 0000 0004
17480 a: 0000 0000 0000 0003
17481 END
17482  
17483  
17484 =head2 PushRR(@r)
17485  
17486 Push registers onto the stack without tracking.
17487  
17488 Parameter Description
17489 1 @r Register
17490  
17491 =head2 PushR(@r)
17492  
17493 Push registers onto the stack.
17494  
17495 Parameter Description
17496 1 @r Register
17497  
17498 B<Example:>
17499  
17500  
17501 Mov rax, 0x11111111;
17502 Mov rbx, 0x22222222;
17503  
17504 PushR my @save = (rax, rbx); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
17505  
17506 Mov rax, 0x33333333;
17507 PopR;
17508 PrintOutRegisterInHex rax;
17509 PrintOutRegisterInHex rbx;
17510  
17511 ok Assemble(debug => 0, eq => <<END);
17512 rax: 0000 0000 1111 1111
17513 rbx: 0000 0000 2222 2222
17514 END
17515  
17516  
17517 =head2 PopRR(@r)
17518  
17519 Pop registers from the stack without tracking.
17520  
17521 Parameter Description
17522 1 @r Register
17523  
17524 =head2 ClassifyRange($recordOffsetInRange, @parameters)
17525  
17526 Implementation of ClassifyInRange and ClassifyWithinRange.
17527  
17528 Parameter Description
17529 1 $recordOffsetInRange Record offset in classification in high byte if 1 else in classification if 2
17530 2 @parameters Parameters
17531  
17532 =head2 Cstrlen()
17533  
17534 Length of the C style string addressed by rax returning the length in r15.
17535  
17536  
17537 B<Example:>
17538  
17539  
17540 my $s = Rs("Hello World
17541  
17542 Hello Skye");
17543 Mov rax, $s;
17544  
17545 Cstrlen; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
17546  
17547 Mov rdi, r15;
17548 PrintOutMemoryNL;
17549  
17550 ok Assemble(debug => 0, eq => <<END);
17551 Hello World
17552  
17553 Hello Skye
17554 END
17555  
17556  
17557 =head2 Nasm::X86::Arena::chain($arena, $bs, $variable, @offsets)
17558  
17559 Return a variable with the end point of a chain of double words in the arena starting at the specified variable.
17560  
17561 Parameter Description
17562 1 $arena Arena descriptor
17563 2 $bs Arena locator
17564 3 $variable Start variable
17565 4 @offsets Offsets chain
17566  
17567 B<Example:>
17568  
17569  
17570 my $format = Rd(map{4*$_+24} 0..64);
17571  
17572 my $b = CreateArena;
17573 my $a = $b->allocBlock($b->bs);
17574 Vmovdqu8 zmm31, "[$format]";
17575 $b->putBlock($b->bs, $a, 31);
17576 my $r = $b->chain($b->bs, V(start, 0x18), 4); $r->outNL("chain1: ");
17577 my $s = $b->chain($b->bs, $r, 4); $s->outNL("chain2: ");
17578 my $t = $b->chain($b->bs, $s, 4); $t->outNL("chain3: ");
17579 my $A = $b->chain($b->bs, V(start, 0x18), 4, 4, 4); $A->outNL("chain4: "); # Get a long chain
17580  
17581 $b->putChain($b->bs, V(start, 0x18), V(end, 0xff), 4, 4, 4); # Put at the end of a long chain
17582  
17583 $b->dump;
17584  
17585 my $sub = Subroutine
17586 {my ($p) = @_; # Parameters
17587 If ($$p{c} == -1,
17588 sub {PrintOutStringNL "C is minus one"},
17589 sub {PrintOutStringNL "C is NOT minus one"},
17590 );
17591 If ($$p{d} == -1,
17592 sub {PrintOutStringNL "D is minus one"},
17593 sub {PrintOutStringNL "D is NOT minus one"},
17594 );
17595  
17596 $$p{c}->outNL;
17597  
17598 $$p{e} += 1;
17599 $$p{e}->outNL('E: ');
17600  
17601 $$p{f}->outNL('F1: ');
17602 $$p{f}++;
17603 $$p{f}->outNL('F2: ');
17604 } [qw(c d e f)], name=> 'aaa';
17605  
17606 my $c = K(c, -1);
17607 my $d = K(d, -1);
17608 my $e = V(e, 1);
17609 my $f = V(f, 2);
17610  
17611 $sub->call($c, $d, $e, $f);
17612 $f->outNL('F3: ');
17613  
17614 ok Assemble(debug => 0, eq => <<END);
17615 chain1: 0000 0000 0000 001C
17616 chain2: 0000 0000 0000 0020
17617 chain3: 0000 0000 0000 0024
17618 chain4: 0000 0000 0000 0024
17619 Arena
17620 Size: 0000 0000 0000 1000
17621 Used: 0000 0000 0000 0058
17622 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
17623 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
17624 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
17625 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
17626 C is minus one
17627 D is minus one
17628 c: FFFF FFFF FFFF FFFF
17629 E: 0000 0000 0000 0002
17630 F1: 0000 0000 0000 0002
17631 F2: 0000 0000 0000 0003
17632 F3: 0000 0000 0000 0003
17633 END
17634  
17635  
17636 =head2 Nasm::X86::Arena::putChain($arena, $bs, $start, $value, @offsets)
17637  
17638 Write the double word in the specified variable to the double word location at the the specified offset in the specified arena.
17639  
17640 Parameter Description
17641 1 $arena Arena descriptor
17642 2 $bs Arena locator variable
17643 3 $start Start variable
17644 4 $value Value to put as a variable
17645 5 @offsets Offsets chain
17646  
17647 =head2 Nasm::X86::Arena::updateSpace($arena, @variables)
17648  
17649 Make sure that the arena addressed by rax has enough space to accommodate content of length rdi.
17650  
17651 Parameter Description
17652 1 $arena Arena descriptor
17653 2 @variables Variables
17654  
17655 =head2 Nasm::X86::Arena::blockSize($arena)
17656  
17657 Size of a block.
17658  
17659 Parameter Description
17660 1 $arena Arena
17661  
17662 =head2 Nasm::X86::Arena::firstFreeBlock($arena)
17663  
17664 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.
17665  
17666 Parameter Description
17667 1 $arena Arena address as a variable
17668  
17669 =head2 Nasm::X86::Arena::setFirstFreeBlock($arena, $offset)
17670  
17671 Set the first free block field from a variable.
17672  
17673 Parameter Description
17674 1 $arena Arena descriptor
17675 2 $offset First free block offset as a variable
17676  
17677 =head2 Nasm::X86::Arena::freeBlock($arena, @variables)
17678  
17679 Free a block in an arena by placing it on the free chain.
17680  
17681 Parameter Description
17682 1 $arena Arena descriptor
17683 2 @variables Variables
17684  
17685 B<Example:>
17686  
17687  
17688 my $a = CreateArena; $a->dump;
17689 my $b1 = $a->allocBlock($a->bs); $a->dump;
17690 my $b2 = $a->allocBlock($a->bs); $a->dump;
17691 $a->freeBlock($b2); $a->dump;
17692 $a->freeBlock($b1); $a->dump;
17693  
17694 ok Assemble(debug => 0, eq => <<END);
17695 Arena
17696 Size: 0000 0000 0000 1000
17697 Used: 0000 0000 0000 0018
17698 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
17699 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
17700 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
17701 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
17702 Arena
17703 Size: 0000 0000 0000 1000
17704 Used: 0000 0000 0000 0058
17705 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
17706 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
17707 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
17708 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
17709 Arena
17710 Size: 0000 0000 0000 1000
17711 Used: 0000 0000 0000 0098
17712 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
17713 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
17714 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
17715 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
17716 Arena
17717 Size: 0000 0000 0000 1000
17718 Used: 0000 0000 0000 0098
17719 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
17720 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
17721 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
17722 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
17723 Arena
17724 Size: 0000 0000 0000 1000
17725 Used: 0000 0000 0000 0098
17726 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
17727 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
17728 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
17729 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
17730 END
17731  
17732  
17733 =head2 Nasm::X86::Arena::getBlock($arena, $address, $block, $zmm, $work1, $work2)
17734  
17735 Get the block with the specified offset in the specified string and return it in the numbered zmm.
17736  
17737 Parameter Description
17738 1 $arena Arena descriptor
17739 2 $address Arena address variable
17740 3 $block Offset of the block as a variable
17741 4 $zmm Number of zmm register to contain block
17742 5 $work1 First optional work register
17743 6 $work2 Second optional work register
17744  
17745 =head2 Nasm::X86::Arena::putBlock($arena, $address, $block, $zmm, $work1, $work2)
17746  
17747 Write the numbered zmm to the block at the specified offset in the specified arena.
17748  
17749 Parameter Description
17750 1 $arena Arena descriptor
17751 2 $address Arena address variable
17752 3 $block Offset of the block as a variable
17753 4 $zmm Number of zmm register to contain block
17754 5 $work1 First optional work register
17755 6 $work2 Second optional work register
17756  
17757 =head2 Nasm::X86::String::address($String)
17758  
17759 Address of a string.
17760  
17761 Parameter Description
17762 1 $String String descriptor
17763  
17764 =head2 Nasm::X86::String::allocBlock($String, $arena)
17765  
17766 Allocate a block to hold a zmm register in the specified arena and return the offset of the block in a variable.
17767  
17768 Parameter Description
17769 1 $String String descriptor
17770 2 $arena Arena address
17771  
17772 =head2 Nasm::X86::String::getBlockLength($String, $zmm)
17773  
17774 Get the block length of the numbered zmm and return it in a variable.
17775  
17776 Parameter Description
17777 1 $String String descriptor
17778 2 $zmm Number of zmm register
17779  
17780 =head2 Nasm::X86::String::setBlockLengthInZmm($String, $length, $zmm)
17781  
17782 Set the block length of the numbered zmm to the specified length.
17783  
17784 Parameter Description
17785 1 $String String descriptor
17786 2 $length Length as a variable
17787 3 $zmm Number of zmm register
17788  
17789 =head2 Nasm::X86::String::getBlock($String, $bsa, $block, $zmm)
17790  
17791 Get the block with the specified offset in the specified string and return it in the numbered zmm.
17792  
17793 Parameter Description
17794 1 $String String descriptor
17795 2 $bsa Arena variable
17796 3 $block Offset of the block as a variable
17797 4 $zmm Number of zmm register to contain block
17798  
17799 =head2 Nasm::X86::String::putBlock($String, $bsa, $block, $zmm)
17800  
17801 Write the numbered zmm to the block at the specified offset in the specified arena.
17802  
17803 Parameter Description
17804 1 $String String descriptor
17805 2 $bsa Arena variable
17806 3 $block Block in arena
17807 4 $zmm Content variable
17808  
17809 =head2 Nasm::X86::String::getNextAndPrevBlockOffsetFromZmm($String, $zmm)
17810  
17811 Get the offsets of the next and previous blocks as variables from the specified zmm.
17812  
17813 Parameter Description
17814 1 $String String descriptor
17815 2 $zmm Zmm containing block
17816  
17817 =head2 Nasm::X86::String::putNextandPrevBlockOffsetIntoZmm($String, $zmm, $next, $prev)
17818  
17819 Save next and prev offsets into a zmm representing a block.
17820  
17821 Parameter Description
17822 1 $String String descriptor
17823 2 $zmm Zmm containing block
17824 3 $next Next offset as a variable
17825 4 $prev Prev offset as a variable
17826  
17827 =head2 Nasm::X86::Array::address($Array)
17828  
17829 Address of a string.
17830  
17831 Parameter Description
17832 1 $Array Array descriptor
17833  
17834 =head2 Nasm::X86::Array::allocBlock($Array, $bs)
17835  
17836 Allocate a block to hold a zmm register in the specified arena and return the offset of the block in a variable.
17837  
17838 Parameter Description
17839 1 $Array Array descriptor
17840 2 $bs Arena address
17841  
17842 =head2 Nasm::X86::Tree::allocKeysDataNode($t, $bs, $K, $D, $N)
17843  
17844 Allocate a keys/data/node block and place it in the numbered zmm registers.
17845  
17846 Parameter Description
17847 1 $t Tree descriptor
17848 2 $bs Arena address
17849 3 $K Numbered zmm for keys
17850 4 $D Numbered zmm for data
17851 5 $N Numbered zmm for children
17852  
17853 =head2 Nasm::X86::Tree::splitNode($t, $bs, $node, $key, @variables)
17854  
17855 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.
17856  
17857 Parameter Description
17858 1 $t Tree descriptor
17859 2 $bs Backing arena
17860 3 $node Offset of node
17861 4 $key Key
17862 5 @variables Variables
17863  
17864 =head2 Nasm::X86::Tree::reParent($t, $bs, $PK, $PD, $PN, @variables)
17865  
17866 Reparent the children of a node held in registers. The children are in the backing arena not registers.
17867  
17868 Parameter Description
17869 1 $t Tree descriptor
17870 2 $bs Backing arena
17871 3 $PK Numbered zmm key node
17872 4 $PD Numbered zmm data node
17873 5 $PN Numbered zmm child node
17874 6 @variables Variables
17875  
17876 =head2 Nasm::X86::Tree::transferTreeBitsFromParent($t, $parent, $left, $right)
17877  
17878 Transfer tree bits when splitting a full node.
17879  
17880 Parameter Description
17881 1 $t Tree descriptor
17882 2 $parent Numbered parent zmm
17883 3 $left Numbered left zmm
17884 4 $right Numbered right zmm
17885  
17886 B<Example:>
17887  
17888  
17889 my $B = Rb(0..63);
17890 Vmovdqu8 zmm0, "[$B]";
17891 loadFromZmm r15, w, zmm, 14;
17892  
17893 my $b = CreateArena;
17894 my $t = $b->CreateTree;
17895 $t->getTreeBits(0, r14);
17896  
17897 PrintOutRegisterInHex zmm0, r15, r14;
17898  
17899 Mov r14, my $treeBits = 0xDCBA;
17900 $t->putTreeBits(1, r14);
17901 PrintOutRegisterInHex zmm1;
17902  
17903 $t->transferTreeBitsFromParent(1, 2, 3);
17904 PrintOutStringNL "Split:";
17905 PrintOutRegisterInHex zmm1, zmm2, zmm3;
17906  
17907 my $left = $treeBits & ((1<<$t->leftLength) - 1);
17908 my $right = ($treeBits >> ($t->leftLength + 1)) & ((1<<$t->rightLength) - 1);
17909  
17910 my $l = sprintf("%02X", $left);
17911 my $r = sprintf("%02X", $right);
17912  
17913 ok Assemble(debug => 0, eq => <<END);
17914 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
17915 r15: 0000 0000 0000 0F0E
17916 r14: 0000 0000 0000 3B3A
17917 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
17918 Split:
17919 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
17920 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
17921 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
17922 END
17923  
17924  
17925 =head2 Nasm::X86::Tree::transferTreeBitsFromLeftOrRight($t, $rnl, $point, $parent, $left, $right)
17926  
17927 Transfer tree bits when splitting a full left or right node.
17928  
17929 Parameter Description
17930 1 $t Tree descriptor
17931 2 $rnl 0 - left 1 - right
17932 3 $point Register indicating point of left in parent
17933 4 $parent Numbered parent zmm
17934 5 $left Numbered left zmm
17935 6 $right Numbered right zmm
17936  
17937 =head2 Nasm::X86::Tree::transferTreeBitsFromLeft($t, $point, $parent, $left, $right)
17938  
17939 Transfer tree bits when splitting a full left node.
17940  
17941 Parameter Description
17942 1 $t Tree descriptor
17943 2 $point Register indicating point of left in parent
17944 3 $parent Numbered parent zmm
17945 4 $left Numbered left zmm
17946 5 $right Numbered right zmm
17947  
17948 B<Example:>
17949  
17950  
17951 my $b = CreateArena;
17952 my $t = $b->CreateTree;
17953 my $lR = "110110";
17954 my $lP = "1";
17955 my $lL = "1110111";
17956  
17957 my $p1 = "01010_110010";
17958 my $p2 = "1";
17959  
17960 my $epe = sprintf("%04X", eval "0b$p1$lP$p2");
17961 my $ele = sprintf("%04X", eval "0b$lL" );
17962 my $ere = sprintf("%04X", eval "0b$lR" );
17963  
17964 my @expected;
17965 for my $i(0..1)
17966 {Mov r15, eval "0b$lR$lP$lL"; $t->putTreeBits(1+$i, r15);
17967 Mov r15, eval "0b$p1$p2"; $t->putTreeBits(0, r15);
17968  
17969 PrintOutRegisterInHex zmm 0, 1+$i;
17970  
17971 Mov r15, 0b10;
17972 $t->transferTreeBitsFromLeft (r15, 0, 1, 2) unless $i;
17973 $t->transferTreeBitsFromRight(r15, 0, 1, 2) if $i;
17974 PrintOutRegisterInHex zmm 0..2;
17975  
17976 my $zzz = $i ? "zmm2" : "zmm1";
17977 push @expected, <<END;
17978 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
17979 $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
17980 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
17981 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
17982 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
17983 END
17984 }
17985  
17986 ok Assemble(debug => 0, eq => join "", @expected);
17987  
17988  
17989 =head2 Nasm::X86::Tree::transferTreeBitsFromRight($t, $point, $parent, $left, $right)
17990  
17991 Transfer tree bits when splitting a full right node.
17992  
17993 Parameter Description
17994 1 $t Tree descriptor
17995 2 $point Register indicating point of right in parent
17996 3 $parent Numbered parent zmm
17997 4 $left Numbered left zmm
17998 5 $right Numbered right zmm
17999  
18000 B<Example:>
18001  
18002  
18003 my $b = CreateArena;
18004 my $t = $b->CreateTree;
18005 my $lR = "110110";
18006 my $lP = "1";
18007 my $lL = "1110111";
18008  
18009 my $p1 = "01010_110010";
18010 my $p2 = "1";
18011  
18012 my $epe = sprintf("%04X", eval "0b$p1$lP$p2");
18013 my $ele = sprintf("%04X", eval "0b$lL" );
18014 my $ere = sprintf("%04X", eval "0b$lR" );
18015  
18016 my @expected;
18017 for my $i(0..1)
18018 {Mov r15, eval "0b$lR$lP$lL"; $t->putTreeBits(1+$i, r15);
18019 Mov r15, eval "0b$p1$p2"; $t->putTreeBits(0, r15);
18020  
18021 PrintOutRegisterInHex zmm 0, 1+$i;
18022  
18023 Mov r15, 0b10;
18024 $t->transferTreeBitsFromLeft (r15, 0, 1, 2) unless $i;
18025 $t->transferTreeBitsFromRight(r15, 0, 1, 2) if $i;
18026 PrintOutRegisterInHex zmm 0..2;
18027  
18028 my $zzz = $i ? "zmm2" : "zmm1";
18029 push @expected, <<END;
18030 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
18031 $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
18032 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
18033 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
18034 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
18035 END
18036 }
18037  
18038 ok Assemble(debug => 0, eq => join "", @expected);
18039  
18040  
18041 =head2 Nasm::X86::Tree::splitFullRoot($t, $bs)
18042  
18043 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.
18044  
18045 Parameter Description
18046 1 $t Tree descriptor
18047 2 $bs Arena address
18048  
18049 =head2 Nasm::X86::Tree::splitFullLeftOrRightNode($t, $right)
18050  
18051 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.
18052  
18053 Parameter Description
18054 1 $t Tree descriptor
18055 2 $right 0 left or 1 right
18056  
18057 =head2 Nasm::X86::Tree::splitFullLeftNode($t)
18058  
18059 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.
18060  
18061 Parameter Description
18062 1 $t Tree descriptor
18063  
18064 B<Example:>
18065  
18066  
18067 my $Sk = Rd(17..28, 0, 0, 12, 0xFF);
18068 my $Sd = Rd(17..28, 0, 0, 0xDD, 0xEE);
18069 my $Sn = Rd(1..13, 0, 0, 0xCC);
18070  
18071 my $sk = Rd(1..14, 14, 0xA1);
18072 my $sd = Rd(1..14, 0xCC, 0xA2);
18073 my $sn = Rd(1..15, 0xA3);
18074  
18075 my $rk = Rd((0)x14, 14, 0xB1);
18076 my $rd = Rd((0)x14, 0xCC, 0xB2);
18077 my $rn = Rd((0)x15, 0xB3);
18078  
18079 my $b = CreateArena;
18080 my $t = $b->CreateTree;
18081  
18082 Vmovdqu8 zmm31, "[$Sk]";
18083 Vmovdqu8 zmm30, "[$Sd]";
18084 Vmovdqu8 zmm29, "[$Sn]";
18085  
18086 Vmovdqu8 zmm28, "[$sk]";
18087 Vmovdqu8 zmm27, "[$sd]";
18088 Vmovdqu8 zmm26, "[$sn]";
18089  
18090 Vmovdqu8 zmm25, "[$rk]";
18091 Vmovdqu8 zmm24, "[$rd]";
18092 Vmovdqu8 zmm23, "[$rn]";
18093  
18094 $t->splitFullLeftNode;
18095  
18096 PrintOutRegisterInHex reverse zmm(23..31);
18097  
18098 ok Assemble(debug => 0, eq => <<END);
18099 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
18100 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
18101 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
18102 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
18103 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
18104 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
18105 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
18106 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
18107 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
18108 END
18109  
18110 my $tk = Rd(1, (0) x 13, 1, 0xC1);
18111 my $td = Rd(1, (0) x 14, 0xC2);
18112 my $tn = Rd(1, 0xAA, (0) x 13, 0xCC);
18113  
18114 my $lk = Rd(1..14, 14, 0xA1);
18115 my $ld = Rd(1..14, 0xCC, 0xA2);
18116 my $ln = Rd(1..15, 0xAA);
18117  
18118 my $rk = Rd((0)x14, 14, 0xB1);
18119 my $rd = Rd((0)x14, 0xCC, 0xB2);
18120 my $rn = Rd((0)x15, 0xBB);
18121  
18122 my $b = CreateArena;
18123 my $t = $b->CreateTree;
18124  
18125 Vmovdqu8 zmm31, "[$tk]";
18126 Vmovdqu8 zmm30, "[$td]";
18127 Vmovdqu8 zmm29, "[$tn]";
18128  
18129 Vmovdqu8 zmm28, "[$lk]";
18130 Vmovdqu8 zmm27, "[$ld]";
18131 Vmovdqu8 zmm26, "[$ln]";
18132  
18133 Vmovdqu8 zmm25, "[$rk]";
18134 Vmovdqu8 zmm24, "[$rd]";
18135 Vmovdqu8 zmm23, "[$rn]";
18136  
18137 $t->splitFullLeftNode;
18138  
18139 PrintOutRegisterInHex reverse zmm(23..31);
18140  
18141 ok Assemble(debug => 0, eq => <<END);
18142 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
18143 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
18144 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
18145 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
18146 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
18147 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
18148 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
18149 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
18150 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
18151 END
18152  
18153  
18154 =head2 Nasm::X86::Tree::splitFullRightNode($t)
18155  
18156 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.
18157  
18158 Parameter Description
18159 1 $t Tree descriptor
18160  
18161 B<Example:>
18162  
18163  
18164 my $tk = Rd(1..12, 0, 0, 12, 0xC1);
18165 my $td = Rd(1..12, 0, 0, 0, 0xC2);
18166 my $tn = Rd(1, 0xBB, 3..13, 0, 0, 0xCC);
18167  
18168 my $lk = Rd(17..30, 14, 0xA1);
18169 my $ld = Rd(17..30, 0xCC, 0xA2);
18170 my $ln = Rd(17..31, 0xAA);
18171  
18172 my $rk = Rd(17..30, 14, 0xB1);
18173 my $rd = Rd(17..30, 0xCC, 0xB2);
18174 my $rn = Rd(17..31, 0xBB);
18175  
18176 my $b = CreateArena;
18177 my $t = $b->CreateTree;
18178  
18179 Vmovdqu8 zmm31, "[$tk]";
18180 Vmovdqu8 zmm30, "[$td]";
18181 Vmovdqu8 zmm29, "[$tn]";
18182  
18183 Vmovdqu8 zmm28, "[$lk]";
18184 Vmovdqu8 zmm27, "[$ld]";
18185 Vmovdqu8 zmm26, "[$ln]";
18186  
18187 Vmovdqu8 zmm25, "[$rk]";
18188 Vmovdqu8 zmm24, "[$rd]";
18189 Vmovdqu8 zmm23, "[$rn]";
18190  
18191 $t->splitFullRightNode;
18192  
18193 PrintOutRegisterInHex reverse zmm(23..31);
18194  
18195 ok Assemble(debug => 0, eq => <<END);
18196 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
18197 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
18198 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
18199 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
18200 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
18201 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
18202 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
18203 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
18204 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
18205 END
18206  
18207  
18208 =head2 Nasm::X86::Tree::findAndSplit($t, $bs, $first, $key, $compare, $offset, $index)
18209  
18210 Find a key in a tree which is known to contain at least one key splitting full nodes along the path to the key.
18211  
18212 Parameter Description
18213 1 $t Tree descriptor
18214 2 $bs Arena address
18215 3 $first Start node
18216 4 $key Key to find
18217 5 $compare Last comparison result variable
18218 6 $offset Offset of last node found
18219 7 $index Index within last node found
18220  
18221 =head2 Nasm::X86::Tree::getKeysData($t, $bs, $offset, $zmmKeys, $zmmData, $work1, $work2)
18222  
18223 Load the keys and data blocks for a node.
18224  
18225 Parameter Description
18226 1 $t Tree descriptor
18227 2 $bs Arena address
18228 3 $offset Offset as a variable
18229 4 $zmmKeys Numbered zmm for keys
18230 5 $zmmData Numbered data for keys
18231 6 $work1 Optional first work register
18232 7 $work2 Optional second work register
18233  
18234 =head2 Nasm::X86::Tree::putKeysData($t, $bs, $offset, $zmmKeys, $zmmData, $work1, $work2)
18235  
18236 Save the key and data blocks for a node.
18237  
18238 Parameter Description
18239 1 $t Tree descriptor
18240 2 $bs Arena address
18241 3 $offset Offset as a variable
18242 4 $zmmKeys Numbered zmm for keys
18243 5 $zmmData Numbered data for keys
18244 6 $work1 Optional first work register
18245 7 $work2 Optional second work register
18246  
18247 =head2 Nasm::X86::Tree::getKeysDataNode($t, $bs, $offset, $zmmKeys, $zmmData, $zmmNode, $work1, $work2)
18248  
18249 Load the keys, data and child nodes for a node.
18250  
18251 Parameter Description
18252 1 $t Tree descriptor
18253 2 $bs Arena address
18254 3 $offset Offset as a variable
18255 4 $zmmKeys Numbered zmm for keys
18256 5 $zmmData Numbered data for keys
18257 6 $zmmNode Numbered numbered for keys
18258 7 $work1 Optional first work register
18259 8 $work2 Optional second work register
18260  
18261 =head2 Nasm::X86::Tree::putKeysDataNode($t, $bs, $offset, $zmmKeys, $zmmData, $zmmNode, $work1, $work2)
18262  
18263 Save the keys, data and child nodes for a node.
18264  
18265 Parameter Description
18266 1 $t Tree descriptor
18267 2 $bs Arena address
18268 3 $offset Offset as a variable
18269 4 $zmmKeys Numbered zmm for keys
18270 5 $zmmData Numbered data for keys
18271 6 $zmmNode Numbered numbered for keys
18272 7 $work1 Optional first work register
18273 8 $work2 Optional second work register
18274  
18275 =head2 Nasm::X86::Tree::getLengthInKeys($t, $zmm)
18276  
18277 Get the length of the keys block in the numbered zmm and return it as a variable.
18278  
18279 Parameter Description
18280 1 $t Tree descriptor
18281 2 $zmm Zmm number
18282  
18283 =head2 Nasm::X86::Tree::putLengthInKeys($t, $zmm, $length)
18284  
18285 Get the length of the block in the numbered zmm from the specified variable.
18286  
18287 Parameter Description
18288 1 $t Tree
18289 2 $zmm Zmm number
18290 3 $length Length variable
18291  
18292 =head2 Nasm::X86::Tree::getUpFromData11($t, $zmm, $transfer)
18293  
18294 Get the up offset from the data block in the numbered zmm and return it as a variable.
18295  
18296 Parameter Description
18297 1 $t Tree descriptor
18298 2 $zmm Zmm number
18299 3 $transfer Transfer register
18300  
18301 =head2 Nasm::X86::Tree::putUpIntoData11($t, $offset, $zmm, $transfer)
18302  
18303 Put the offset of the parent keys block expressed as a variable into the numbered zmm.
18304  
18305 Parameter Description
18306 1 $t Tree descriptor
18307 2 $offset Variable containing up offset
18308 3 $zmm Zmm number
18309 4 $transfer Optional transfer register
18310  
18311 =head2 Nasm::X86::Tree::getUpFromData($t, $zmm, $transfer)
18312  
18313 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.
18314  
18315 Parameter Description
18316 1 $t Tree descriptor
18317 2 $zmm Zmm number
18318 3 $transfer Transfer register
18319  
18320 =head2 Nasm::X86::Tree::getUpFromDataNM($t, $zmm, $transfer)
18321  
18322 Get the compressed up offset//count from the data block in the numbered zmm and return it as a variable.
18323  
18324 Parameter Description
18325 1 $t Tree descriptor
18326 2 $zmm Zmm number
18327 3 $transfer Transfer register
18328  
18329 =head2 Nasm::X86::Tree::putUpIntoData($t, $offset, $zmm, $transfer)
18330  
18331 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.
18332  
18333 Parameter Description
18334 1 $t Tree descriptor
18335 2 $offset Variable containing up offset
18336 3 $zmm Zmm number
18337 4 $transfer Transfer register
18338  
18339 =head2 Nasm::X86::Tree::getCountFromData($t, $zmm, $transfer)
18340  
18341 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.
18342  
18343 Parameter Description
18344 1 $t Tree descriptor
18345 2 $zmm Zmm number
18346 3 $transfer Transfer register
18347  
18348 =head2 Nasm::X86::Tree::incCountInData($t, $zmm, $transfer)
18349  
18350 Increment the count field in the up field of the data block associate with the root node.
18351  
18352 Parameter Description
18353 1 $t Tree descriptor
18354 2 $zmm Zmm number
18355 3 $transfer Transfer register
18356  
18357 =head2 Nasm::X86::Tree::decCountInData($t, $zmm, $transfer)
18358  
18359 Decrement the count field in the up field of the data block associate with the root node.
18360  
18361 Parameter Description
18362 1 $t Tree descriptor
18363 2 $zmm Zmm number
18364 3 $transfer Transfer register
18365  
18366 =head2 Nasm::X86::Tree::getLoop($t, $zmm, $transfer)
18367  
18368 Return the value of the loop field as a variable.
18369  
18370 Parameter Description
18371 1 $t Tree descriptor
18372 2 $zmm Numbered zmm
18373 3 $transfer Optional transfer register
18374  
18375 =head2 Nasm::X86::Tree::putLoop($t, $value, $zmm, $transfer)
18376  
18377 Set the value of the loop field from a variable.
18378  
18379 Parameter Description
18380 1 $t Tree descriptor
18381 2 $value Variable containing offset of next loop entry
18382 3 $zmm Numbered zmm
18383 4 $transfer Optional transfer register
18384  
18385 =head2 Nasm::X86::Tree::nodeFromData($t, $data, $node)
18386  
18387 Load the the node block into the numbered zmm corresponding to the data block held in the numbered zmm.
18388  
18389 Parameter Description
18390 1 $t Tree descriptor
18391 2 $data Numbered zmm containing data
18392 3 $node Numbered zmm to hold node block
18393  
18394 =head2 Nasm::X86::Tree::address($t)
18395  
18396 Address of the arena containing a tree.
18397  
18398 Parameter Description
18399 1 $t Tree descriptor
18400  
18401 =head2 Nasm::X86::Tree::allocBlock($t, $bs)
18402  
18403 Allocate a block to hold a zmm register in the specified arena and return the offset of the block in a variable.
18404  
18405 Parameter Description
18406 1 $t Tree descriptor
18407 2 $bs Variables
18408  
18409 =head2 Nasm::X86::Tree::testTree($t, $position, $zmm)
18410  
18411 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.
18412  
18413 Parameter Description
18414 1 $t Tree descriptor
18415 2 $position Variable holding index of position to test
18416 3 $zmm Numbered zmm register holding the keys for a node in the tree
18417  
18418 =head2 Nasm::X86::Tree::isTree($t, $register, $zmm)
18419  
18420 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.
18421  
18422 Parameter Description
18423 1 $t Tree descriptor
18424 2 $register Word register holding a bit shifted into the position to test
18425 3 $zmm Numbered zmm register holding the keys for a node in the tree
18426  
18427 =head2 Nasm::X86::Tree::setOrClearTree($t, $set, $register, $zmm)
18428  
18429 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.
18430  
18431 Parameter Description
18432 1 $t Tree descriptor
18433 2 $set Set if true else clear
18434 3 $register Register holding a single one in the lowest 14 bits at the insertion point
18435 4 $zmm Numbered zmm register holding the keys for a node in the tree
18436  
18437 =head2 Nasm::X86::Tree::setTree($t, $register, $zmm)
18438  
18439 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.
18440  
18441 Parameter Description
18442 1 $t Tree descriptor
18443 2 $register Register holding data element index 0..13
18444 3 $zmm Numbered zmm register holding the keys for a node in the tree
18445  
18446 =head2 Nasm::X86::Tree::clearTree($t, $register, $zmm)
18447  
18448 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.
18449  
18450 Parameter Description
18451 1 $t Tree descriptor
18452 2 $register Register holding data element index 0..13
18453 3 $zmm Numbered zmm register holding the keys for a node in the tree
18454  
18455 =head2 Nasm::X86::Tree::getTreeBits($t, $zmm, $register)
18456  
18457 Load the tree bits from the numbered zmm into the specified register.
18458  
18459 Parameter Description
18460 1 $t Tree descriptor
18461 2 $zmm Numbered zmm
18462 3 $register Target register
18463  
18464 =head2 Nasm::X86::Tree::putTreeBits($t, $zmm, $register)
18465  
18466 Put the tree bits in the specified register into the numbered zmm.
18467  
18468 Parameter Description
18469 1 $t Tree descriptor
18470 2 $zmm Numbered zmm
18471 3 $register Target register
18472  
18473 =head2 Nasm::X86::Tree::expandTreeBitsWithZeroOrOne($t, $onz, $zmm, $point)
18474  
18475 Insert a zero or one into the tree bits field in the numbered zmm at the specified point.
18476  
18477 Parameter Description
18478 1 $t Tree descriptor
18479 2 $onz 0 - zero or 1 - one
18480 3 $zmm Numbered zmm
18481 4 $point Register indicating point
18482  
18483 =head2 Nasm::X86::Tree::expandTreeBitsWithZero($t, $zmm, $point)
18484  
18485 Insert a zero into the tree bits field in the numbered zmm at the specified point.
18486  
18487 Parameter Description
18488 1 $t Tree descriptor
18489 2 $zmm Numbered zmm
18490 3 $point Register indicating point
18491  
18492 =head2 Nasm::X86::Tree::expandTreeBitsWithOne($t, $zmm, $point)
18493  
18494 Insert a one into the tree bits field in the numbered zmm at the specified point.
18495  
18496 Parameter Description
18497 1 $t Tree descriptor
18498 2 $zmm Numbered zmm
18499 3 $point Register indicating point
18500  
18501 =head2 LocateIntelEmulator()
18502  
18503 Locate the Intel Software Development Emulator.
18504  
18505  
18506 =head2 getInstructionCount()
18507  
18508 Get the number of instructions executed from the emulator mix file.
18509  
18510  
18511 =head2 Optimize(%options)
18512  
18513 Perform code optimizations.
18514  
18515 Parameter Description
18516 1 %options Options
18517  
18518 =head2 removeNonAsciiChars($string)
18519  
18520 Return a copy of the specified string with all the non ascii characters removed.
18521  
18522 Parameter Description
18523 1 $string String
18524  
18525 =head2 totalBytesAssembled()
18526  
18527 Total size in bytes of all files assembled during testing.
18528  
18529  
18530  
18531 =head1 Index
18532  
18533  
18534 1 L<All8Structure|/All8Structure> - Create a structure consisting of 8 byte fields.
18535  
18536 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.
18537  
18538 3 L<AllocateMemory|/AllocateMemory> - Allocate the specified amount of memory via mmap and return its address.
18539  
18540 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.
18541  
18542 5 L<Assemble|/Assemble> - Assemble the generated code.
18543  
18544 6 L<CallC|/CallC> - Call a C subroutine.
18545  
18546 7 L<CheckGeneralPurposeRegister|/CheckGeneralPurposeRegister> - Check that a register is in fact a general purpose register.
18547  
18548 8 L<CheckMaskRegister|/CheckMaskRegister> - Check that a register is in fact a mask register.
18549  
18550 9 L<CheckNumberedGeneralPurposeRegister|/CheckNumberedGeneralPurposeRegister> - Check that a register is in fact a numbered general purpose register.
18551  
18552 10 L<ChooseRegisters|/ChooseRegisters> - Choose the specified numbers of registers excluding those on the specified list.
18553  
18554 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.
18555  
18556 12 L<ClassifyRange|/ClassifyRange> - Implementation of ClassifyInRange and ClassifyWithinRange.
18557  
18558 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.
18559  
18560 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.
18561  
18562 15 L<ClearMemory|/ClearMemory> - Clear memory.
18563  
18564 16 L<ClearRegisters|/ClearRegisters> - Clear registers by setting them to zero.
18565  
18566 17 L<ClearZF|/ClearZF> - Clear the zero flag.
18567  
18568 18 L<CloseFile|/CloseFile> - Close the file whose descriptor is in rax.
18569  
18570 19 L<Comment|/Comment> - Insert a comment into the assembly code.
18571  
18572 20 L<CommentWithTraceBack|/CommentWithTraceBack> - Insert a comment into the assembly code with a traceback showing how it was generated.
18573  
18574 21 L<ConvertUtf8ToUtf32|/ConvertUtf8ToUtf32> - Convert a string of utf8 to an allocated block of utf32 and return its address and length.
18575  
18576 22 L<CopyMemory|/CopyMemory> - Copy memory, the target is addressed by rax, the length is in rdi, the source is addressed by rsi.
18577  
18578 23 L<cr|/cr> - Call a subroutine with a reordering of the registers.
18579  
18580 24 L<CreateArena|/CreateArena> - Create an relocatable arena and returns its address in rax.
18581  
18582 25 L<CreateShortString|/CreateShortString> - Create a description of a short string.
18583  
18584 26 L<Cstrlen|/Cstrlen> - Length of the C style string addressed by rax returning the length in r15.
18585  
18586 27 L<Db|/Db> - Layout bytes in the data segment and return their label.
18587  
18588 28 L<Dbwdq|/Dbwdq> - Layout data.
18589  
18590 29 L<DComment|/DComment> - Insert a comment into the data segment.
18591  
18592 30 L<Dd|/Dd> - Layout double words in the data segment and return their label.
18593  
18594 31 L<DescribeArena|/DescribeArena> - Describe a relocatable arena.
18595  
18596 32 L<Dq|/Dq> - Layout quad words in the data segment and return their label.
18597  
18598 33 L<Ds|/Ds> - Layout bytes in memory and return their label.
18599  
18600 34 L<Dw|/Dw> - Layout words in the data segment and return their label.
18601  
18602 35 L<Ef|/Ef> - Else if block for an If statement.
18603  
18604 36 L<Else|/Else> - Else block for an If statement.
18605  
18606 37 L<executeFileViaBash|/executeFileViaBash> - Execute the file named in the arena addressed by rax with bash.
18607  
18608 38 L<Exit|/Exit> - Exit with the specified return code or zero if no return code supplied.
18609  
18610 39 L<Extern|/Extern> - Name external references.
18611  
18612 40 L<Fail|/Fail> - Fail block for an L<AndBlock>.
18613  
18614 41 L<For|/For> - For - iterate the block as long as register is less than limit incrementing by increment each time.
18615  
18616 42 L<ForEver|/ForEver> - Iterate for ever.
18617  
18618 43 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.
18619  
18620 44 L<Fork|/Fork> - Fork.
18621  
18622 45 L<FreeMemory|/FreeMemory> - Free memory.
18623  
18624 46 L<G|/G> - Define a global variable.
18625  
18626 47 L<getBFromXmm|/getBFromXmm> - Get the byte from the numbered xmm register and return it in a variable.
18627  
18628 48 L<getBFromZmm|/getBFromZmm> - Get the byte from the numbered zmm register and return it in a variable.
18629  
18630 49 L<getBwdqFromMm|/getBwdqFromMm> - Get the numbered byte|word|double word|quad word from the numbered zmm register and return it in a variable.
18631  
18632 50 L<getDFromXmm|/getDFromXmm> - Get the double word from the numbered xmm register and return it in a variable.
18633  
18634 51 L<getDFromZmm|/getDFromZmm> - Get the double word from the numbered zmm register and return it in a variable.
18635  
18636 52 L<getInstructionCount|/getInstructionCount> - Get the number of instructions executed from the emulator mix file.
18637  
18638 53 L<GetNextUtf8CharAsUtf32|/GetNextUtf8CharAsUtf32> - Get the next utf8 encoded character from the addressed memory and return it as a utf32 char.
18639  
18640 54 L<GetPid|/GetPid> - Get process identifier.
18641  
18642 55 L<GetPidInHex|/GetPidInHex> - Get process identifier in hex as 8 zero terminated bytes in rax.
18643  
18644 56 L<GetPPid|/GetPPid> - Get parent process identifier.
18645  
18646 57 L<getQFromXmm|/getQFromXmm> - Get the quad word from the numbered xmm register and return it in a variable.
18647  
18648 58 L<getQFromZmm|/getQFromZmm> - Get the quad word from the numbered zmm register and return it in a variable.
18649  
18650 59 L<GetUid|/GetUid> - Get userid of current process.
18651  
18652 60 L<getWFromXmm|/getWFromXmm> - Get the word from the numbered xmm register and return it in a variable.
18653  
18654 61 L<getWFromZmm|/getWFromZmm> - Get the word from the numbered zmm register and return it in a variable.
18655  
18656 62 L<Hash|/Hash> - Hash a string addressed by rax with length held in rdi and return the hash code in r15.
18657  
18658 63 L<hexTranslateTable|/hexTranslateTable> - Create/address a hex translate table and return its label.
18659  
18660 64 L<If|/If> - If.
18661  
18662 65 L<IfC|/IfC> - If the carry flag is set then execute the then block else the else block.
18663  
18664 66 L<IfEq|/IfEq> - If equal execute the then block else the else block.
18665  
18666 67 L<IfGe|/IfGe> - If greater than or equal execute the then block else the else block.
18667  
18668 68 L<IfGt|/IfGt> - If greater than execute the then block else the else block.
18669  
18670 69 L<IfLe|/IfLe> - If less than or equal execute the then block else the else block.
18671  
18672 70 L<IfLt|/IfLt> - If less than execute the then block else the else block.
18673  
18674 71 L<IfNc|/IfNc> - If the carry flag is not set then execute the then block else the else block.
18675  
18676 72 L<IfNe|/IfNe> - If not equal execute the then block else the else block.
18677  
18678 73 L<IfNz|/IfNz> - If the zero flag is not set then execute the then block else the else block.
18679  
18680 74 L<IfZ|/IfZ> - If the zero flag is set then execute the then block else the else block.
18681  
18682 75 L<InsertOneIntoRegisterAtPoint|/InsertOneIntoRegisterAtPoint> - Insert a one into the specified register at the point indicated by another register.
18683  
18684 76 L<InsertZeroIntoRegisterAtPoint|/InsertZeroIntoRegisterAtPoint> - Insert a zero into the specified register at the point indicated by another register.
18685  
18686 77 L<K|/K> - Define a constant variable.
18687  
18688 78 L<Label|/Label> - Create a unique label or reuse the one supplied.
18689  
18690 79 L<Link|/Link> - Libraries to link with.
18691  
18692 80 L<LoadBitsIntoMaskRegister|/LoadBitsIntoMaskRegister> - Load a bit string specification into a mask register.
18693  
18694 81 L<LoadConstantIntoMaskRegister|/LoadConstantIntoMaskRegister> - Set a mask register equal to a constant.
18695  
18696 82 L<loadFromZmm|/loadFromZmm> - Load the specified register from the offset located in the numbered zmm.
18697  
18698 83 L<LoadRegFromMm|/LoadRegFromMm> - Load the specified register from the numbered zmm at the quad offset specified as a constant number.
18699  
18700 84 L<LoadZmm|/LoadZmm> - Load a numbered zmm with the specified bytes.
18701  
18702 85 L<LocalData|/LocalData> - Map local data.
18703  
18704 86 L<LocateIntelEmulator|/LocateIntelEmulator> - Locate the Intel Software Development Emulator.
18705  
18706 87 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.
18707  
18708 88 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.
18709  
18710 89 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.
18711  
18712 90 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.
18713  
18714 91 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.
18715  
18716 92 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.
18717  
18718 93 L<Nasm::X86::Arena::append|/Nasm::X86::Arena::append> - Append one arena to another.
18719  
18720 94 L<Nasm::X86::Arena::arenaSize|/Nasm::X86::Arena::arenaSize> - Get the size of an arena.
18721  
18722 95 L<Nasm::X86::Arena::blockSize|/Nasm::X86::Arena::blockSize> - Size of a block.
18723  
18724 96 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.
18725  
18726 97 L<Nasm::X86::Arena::char|/Nasm::X86::Arena::char> - Append a character expressed as a decimal number to the arena addressed by rax.
18727  
18728 98 L<Nasm::X86::Arena::clear|/Nasm::X86::Arena::clear> - Clear the arena addressed by rax.
18729  
18730 99 L<Nasm::X86::Arena::CreateArray|/Nasm::X86::Arena::CreateArray> - Create a dynamic array held in an arena.
18731  
18732 100 L<Nasm::X86::Arena::CreateQuarks|/Nasm::X86::Arena::CreateQuarks> - Create quarks in a specified arena.
18733  
18734 101 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.
18735  
18736 102 L<Nasm::X86::Arena::CreateTree|/Nasm::X86::Arena::CreateTree> - Create a tree in an arena.
18737  
18738 103 L<Nasm::X86::Arena::DescribeArray|/Nasm::X86::Arena::DescribeArray> - Describe a dynamic array held in an arena.
18739  
18740 104 L<Nasm::X86::Arena::DescribeQuarks|/Nasm::X86::Arena::DescribeQuarks> - Return a descriptor for a tree in the specified arena.
18741  
18742 105 L<Nasm::X86::Arena::DescribeString|/Nasm::X86::Arena::DescribeString> - Describe a string and optionally set its first block .
18743  
18744 106 L<Nasm::X86::Arena::DescribeTree|/Nasm::X86::Arena::DescribeTree> - Return a descriptor for a tree in the specified arena.
18745  
18746 107 L<Nasm::X86::Arena::dump|/Nasm::X86::Arena::dump> - Dump details of an arena.
18747  
18748 108 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.
18749  
18750 109 L<Nasm::X86::Arena::freeBlock|/Nasm::X86::Arena::freeBlock> - Free a block in an arena by placing it on the free chain.
18751  
18752 110 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.
18753  
18754 111 L<Nasm::X86::Arena::length|/Nasm::X86::Arena::length> - Get the length of an arena.
18755  
18756 112 L<Nasm::X86::Arena::m|/Nasm::X86::Arena::m> - Append the content with length rdi addressed by rsi to the arena addressed by rax.
18757  
18758 113 L<Nasm::X86::Arena::makeReadOnly|/Nasm::X86::Arena::makeReadOnly> - Make an arena read only.
18759  
18760 114 L<Nasm::X86::Arena::makeWriteable|/Nasm::X86::Arena::makeWriteable> - Make an arena writable.
18761  
18762 115 L<Nasm::X86::Arena::nl|/Nasm::X86::Arena::nl> - Append a new line to the arena addressed by rax.
18763  
18764 116 L<Nasm::X86::Arena::out|/Nasm::X86::Arena::out> - Print the specified arena addressed by rax on sysout.
18765  
18766 117 L<Nasm::X86::Arena::putBlock|/Nasm::X86::Arena::putBlock> - Write the numbered zmm to the block at the specified offset in the specified arena.
18767  
18768 118 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.
18769  
18770 119 L<Nasm::X86::Arena::q|/Nasm::X86::Arena::q> - Append a constant string to the arena.
18771  
18772 120 L<Nasm::X86::Arena::ql|/Nasm::X86::Arena::ql> - Append a quoted string containing new line characters to the arena addressed by rax.
18773  
18774 121 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.
18775  
18776 122 L<Nasm::X86::Arena::setFirstFreeBlock|/Nasm::X86::Arena::setFirstFreeBlock> - Set the first free block field from a variable.
18777  
18778 123 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.
18779  
18780 124 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.
18781  
18782 125 L<Nasm::X86::Arena::z|/Nasm::X86::Arena::z> - Append a trailing zero to the arena addressed by rax.
18783  
18784 126 L<Nasm::X86::Array::address|/Nasm::X86::Array::address> - Address of a string.
18785  
18786 127 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.
18787  
18788 128 L<Nasm::X86::Array::dump|/Nasm::X86::Array::dump> - Dump a array.
18789  
18790 129 L<Nasm::X86::Array::get|/Nasm::X86::Array::get> - Get an element from the array.
18791  
18792 130 L<Nasm::X86::Array::pop|/Nasm::X86::Array::pop> - Pop an element from an array.
18793  
18794 131 L<Nasm::X86::Array::push|/Nasm::X86::Array::push> - Push an element onto the array.
18795  
18796 132 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.
18797  
18798 133 L<Nasm::X86::Array::reload|/Nasm::X86::Array::reload> - Reload the specified array description.
18799  
18800 134 L<Nasm::X86::Array::size|/Nasm::X86::Array::size> - Return the size of an array as a variable.
18801  
18802 135 L<Nasm::X86::LocalData::allocate8|/Nasm::X86::LocalData::allocate8> - Add some 8 byte local variables and return an array of variable definitions.
18803  
18804 136 L<Nasm::X86::LocalData::free|/Nasm::X86::LocalData::free> - Free a local data area on the stack.
18805  
18806 137 L<Nasm::X86::LocalData::start|/Nasm::X86::LocalData::start> - Start a local data area on the stack.
18807  
18808 138 L<Nasm::X86::LocalData::variable|/Nasm::X86::LocalData::variable> - Add a local variable.
18809  
18810 139 L<Nasm::X86::LocalVariable::stack|/Nasm::X86::LocalVariable::stack> - Address a local variable on the stack.
18811  
18812 140 L<Nasm::X86::Quarks::call|/Nasm::X86::Quarks::call> - Call a subroutine via its quark number.
18813  
18814 141 L<Nasm::X86::Quarks::locateQuarkFromShortString|/Nasm::X86::Quarks::locateQuarkFromShortString> - Locate (if possible) but do not create a quark from a short string.
18815  
18816 142 L<Nasm::X86::Quarks::quarkFromShortString|/Nasm::X86::Quarks::quarkFromShortString> - Create a quark from a short string.
18817  
18818 143 L<Nasm::X86::Quarks::quarkFromSub|/Nasm::X86::Quarks::quarkFromSub> - Create a quark from a subroutine definition
18819  
18820 144 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.
18821  
18822 145 L<Nasm::X86::Quarks::reload|/Nasm::X86::Quarks::reload> - Reload the description of a set of quarks.
18823  
18824 146 L<Nasm::X86::Quarks::shortStringFromQuark|/Nasm::X86::Quarks::shortStringFromQuark> - Load a short string from the quark with the specified number.
18825  
18826 147 L<Nasm::X86::Quarks::subFromQuark|/Nasm::X86::Quarks::subFromQuark> - Create a quark from a subroutine definition
18827  
18828 148 L<Nasm::X86::ShortString::append|/Nasm::X86::ShortString::append> - Append the right hand short string to the left hand short string.
18829  
18830 149 L<Nasm::X86::ShortString::appendByte|/Nasm::X86::ShortString::appendByte> - Append the lowest variable byte to the specified string.
18831  
18832 150 L<Nasm::X86::ShortString::clear|/Nasm::X86::ShortString::clear> - Clear a short string.
18833  
18834 151 L<Nasm::X86::ShortString::len|/Nasm::X86::ShortString::len> - Return the length of a short string in a variable.
18835  
18836 152 L<Nasm::X86::ShortString::load|/Nasm::X86::ShortString::load> - Load the variable addressed data with the variable length into the short string.
18837  
18838 153 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.
18839  
18840 154 L<Nasm::X86::ShortString::setLength|/Nasm::X86::ShortString::setLength> - Set the length of the short string.
18841  
18842 155 L<Nasm::X86::String::address|/Nasm::X86::String::address> - Address of a string.
18843  
18844 156 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.
18845  
18846 157 L<Nasm::X86::String::append|/Nasm::X86::String::append> - Append the specified content in memory to the specified string.
18847  
18848 158 L<Nasm::X86::String::appendShortString|/Nasm::X86::String::appendShortString> - Append the content of the specified short string.
18849  
18850 159 L<Nasm::X86::String::clear|/Nasm::X86::String::clear> - Clear the block by freeing all but the first block.
18851  
18852 160 L<Nasm::X86::String::concatenate|/Nasm::X86::String::concatenate> - Concatenate two strings by appending a copy of the source to the target string.
18853  
18854 161 L<Nasm::X86::String::deleteChar|/Nasm::X86::String::deleteChar> - Delete a character in a string.
18855  
18856 162 L<Nasm::X86::String::dump|/Nasm::X86::String::dump> - Dump a string to sysout.
18857  
18858 163 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.
18859  
18860 164 L<Nasm::X86::String::getBlockLength|/Nasm::X86::String::getBlockLength> - Get the block length of the numbered zmm and return it in a variable.
18861  
18862 165 L<Nasm::X86::String::getCharacter|/Nasm::X86::String::getCharacter> - Get a character from a string.
18863  
18864 166 L<Nasm::X86::String::getNextAndPrevBlockOffsetFromZmm|/Nasm::X86::String::getNextAndPrevBlockOffsetFromZmm> - Get the offsets of the next and previous blocks as variables from the specified zmm.
18865  
18866 167 L<Nasm::X86::String::insertChar|/Nasm::X86::String::insertChar> - Insert a character into a string.
18867  
18868 168 L<Nasm::X86::String::len|/Nasm::X86::String::len> - Find the length of a string.
18869  
18870 169 L<Nasm::X86::String::putBlock|/Nasm::X86::String::putBlock> - Write the numbered zmm to the block at the specified offset in the specified arena.
18871  
18872 170 L<Nasm::X86::String::putNextandPrevBlockOffsetIntoZmm|/Nasm::X86::String::putNextandPrevBlockOffsetIntoZmm> - Save next and prev offsets into a zmm representing a block.
18873  
18874 171 L<Nasm::X86::String::saveToShortString|/Nasm::X86::String::saveToShortString> - Place as much as possible of the specified string into the specified short string.
18875  
18876 172 L<Nasm::X86::String::setBlockLengthInZmm|/Nasm::X86::String::setBlockLengthInZmm> - Set the block length of the numbered zmm to the specified length.
18877  
18878 173 L<Nasm::X86::Structure::field|/Nasm::X86::Structure::field> - Add a field of the specified length with an optional comment.
18879  
18880 174 L<Nasm::X86::StructureField::addr|/Nasm::X86::StructureField::addr> - Address a field in a structure by either the default register or the named register.
18881  
18882 175 L<Nasm::X86::Sub::call|/Nasm::X86::Sub::call> - Call a sub passing it some parameters.
18883  
18884 176 L<Nasm::X86::Sub::callTo|/Nasm::X86::Sub::callTo> - Call a sub passing it some parameters.
18885  
18886 177 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.
18887  
18888 178 L<Nasm::X86::Sub::via|/Nasm::X86::Sub::via> - Call a sub by reference passing it some parameters.
18889  
18890 179 L<Nasm::X86::Tree::address|/Nasm::X86::Tree::address> - Address of the arena containing a tree.
18891  
18892 180 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.
18893  
18894 181 L<Nasm::X86::Tree::allocKeysDataNode|/Nasm::X86::Tree::allocKeysDataNode> - Allocate a keys/data/node block and place it in the numbered zmm registers.
18895  
18896 182 L<Nasm::X86::Tree::by|/Nasm::X86::Tree::by> - Call the specified block with each (key, data) from the specified tree in order.
18897  
18898 183 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.
18899  
18900 184 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.
18901  
18902 185 L<Nasm::X86::Tree::depth|/Nasm::X86::Tree::depth> - Return the depth of a node within a tree.
18903  
18904 186 L<Nasm::X86::Tree::dump|/Nasm::X86::Tree::dump> - Dump a tree and all its sub trees.
18905  
18906 187 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.
18907  
18908 188 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.
18909  
18910 189 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.
18911  
18912 190 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.
18913  
18914 191 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.
18915  
18916 192 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.
18917  
18918 193 L<Nasm::X86::Tree::findShortString|/Nasm::X86::Tree::findShortString> - Find the data at the end of a key chain held in a short string.
18919  
18920 194 L<Nasm::X86::Tree::getCountFromData|/Nasm::X86::Tree::getCountFromData> - Get the number of keys in the tree.
18921  
18922 195 L<Nasm::X86::Tree::getKeysData|/Nasm::X86::Tree::getKeysData> - Load the keys and data blocks for a node.
18923  
18924 196 L<Nasm::X86::Tree::getKeysDataNode|/Nasm::X86::Tree::getKeysDataNode> - Load the keys, data and child nodes for a node.
18925  
18926 197 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.
18927  
18928 198 L<Nasm::X86::Tree::getLoop|/Nasm::X86::Tree::getLoop> - Return the value of the loop field as a variable.
18929  
18930 199 L<Nasm::X86::Tree::getTreeBits|/Nasm::X86::Tree::getTreeBits> - Load the tree bits from the numbered zmm into the specified register.
18931  
18932 200 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.
18933  
18934 201 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.
18935  
18936 202 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.
18937  
18938 203 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.
18939  
18940 204 L<Nasm::X86::Tree::insert|/Nasm::X86::Tree::insert> - Insert a dword into into the specified tree at the specified key.
18941  
18942 205 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.
18943  
18944 206 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.
18945  
18946 207 L<Nasm::X86::Tree::insertTree|/Nasm::X86::Tree::insertTree> - Insert a sub tree into the specified tree tree under the specified key.
18947  
18948 208 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.
18949  
18950 209 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.
18951  
18952 210 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.
18953  
18954 211 L<Nasm::X86::Tree::Iterator::next|/Nasm::X86::Tree::Iterator::next> - Next element in the tree.
18955  
18956 212 L<Nasm::X86::Tree::leftMost|/Nasm::X86::Tree::leftMost> - Return the offset of the left most node from the specified node.
18957  
18958 213 L<Nasm::X86::Tree::leftOrRightMost|/Nasm::X86::Tree::leftOrRightMost> - Return the offset of the left most or right most node.
18959  
18960 214 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.
18961  
18962 215 L<Nasm::X86::Tree::print|/Nasm::X86::Tree::print> - Print a tree.
18963  
18964 216 L<Nasm::X86::Tree::putKeysData|/Nasm::X86::Tree::putKeysData> - Save the key and data blocks for a node.
18965  
18966 217 L<Nasm::X86::Tree::putKeysDataNode|/Nasm::X86::Tree::putKeysDataNode> - Save the keys, data and child nodes for a node.
18967  
18968 218 L<Nasm::X86::Tree::putLengthInKeys|/Nasm::X86::Tree::putLengthInKeys> - Get the length of the block in the numbered zmm from the specified variable.
18969  
18970 219 L<Nasm::X86::Tree::putLoop|/Nasm::X86::Tree::putLoop> - Set the value of the loop field from a variable.
18971  
18972 220 L<Nasm::X86::Tree::putTreeBits|/Nasm::X86::Tree::putTreeBits> - Put the tree bits in the specified register into the numbered zmm.
18973  
18974 221 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.
18975  
18976 222 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.
18977  
18978 223 L<Nasm::X86::Tree::reload|/Nasm::X86::Tree::reload> - Reload the specified tree description.
18979  
18980 224 L<Nasm::X86::Tree::reParent|/Nasm::X86::Tree::reParent> - Reparent the children of a node held in registers.
18981  
18982 225 L<Nasm::X86::Tree::rightMost|/Nasm::X86::Tree::rightMost> - Return the offset of the left most node from the specified node.
18983  
18984 226 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.
18985  
18986 227 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.
18987  
18988 228 L<Nasm::X86::Tree::size|/Nasm::X86::Tree::size> - Return a variable containing the number of keys in the specified tree.
18989  
18990 229 L<Nasm::X86::Tree::splitFullLeftNode|/Nasm::X86::Tree::splitFullLeftNode> - Split a full left node block held in 28.
18991  
18992 230 L<Nasm::X86::Tree::splitFullLeftOrRightNode|/Nasm::X86::Tree::splitFullLeftOrRightNode> - Split a full a full left node (held in 28.
18993  
18994 231 L<Nasm::X86::Tree::splitFullRightNode|/Nasm::X86::Tree::splitFullRightNode> - Split a full right node block held in 25.
18995  
18996 232 L<Nasm::X86::Tree::splitFullRoot|/Nasm::X86::Tree::splitFullRoot> - Split a full root block held in 31.
18997  
18998 233 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.
18999  
19000 234 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.
19001  
19002 235 L<Nasm::X86::Tree::transferTreeBitsFromLeft|/Nasm::X86::Tree::transferTreeBitsFromLeft> - Transfer tree bits when splitting a full left node.
19003  
19004 236 L<Nasm::X86::Tree::transferTreeBitsFromLeftOrRight|/Nasm::X86::Tree::transferTreeBitsFromLeftOrRight> - Transfer tree bits when splitting a full left or right node.
19005  
19006 237 L<Nasm::X86::Tree::transferTreeBitsFromParent|/Nasm::X86::Tree::transferTreeBitsFromParent> - Transfer tree bits when splitting a full node.
19007  
19008 238 L<Nasm::X86::Tree::transferTreeBitsFromRight|/Nasm::X86::Tree::transferTreeBitsFromRight> - Transfer tree bits when splitting a full right node.
19009  
19010 239 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.
19011  
19012 240 L<Nasm::X86::Variable::address|/Nasm::X86::Variable::address> - Get the address of a variable with an optional offset.
19013  
19014 241 L<Nasm::X86::Variable::allocateMemory|/Nasm::X86::Variable::allocateMemory> - Allocate the specified amount of memory via mmap and return its address.
19015  
19016 242 L<Nasm::X86::Variable::and|/Nasm::X86::Variable::and> - And two variables.
19017  
19018 243 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.
19019  
19020 244 L<Nasm::X86::Variable::assign|/Nasm::X86::Variable::assign> - Assign to the left hand side the value of the right hand side.
19021  
19022 245 L<Nasm::X86::Variable::boolean|/Nasm::X86::Variable::boolean> - Combine the left hand variable with the right hand variable via a boolean operator.
19023  
19024 246 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.
19025  
19026 247 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.
19027  
19028 248 L<Nasm::X86::Variable::clearBit|/Nasm::X86::Variable::clearBit> - Clear a bit in the specified mask register retaining the other bits.
19029  
19030 249 L<Nasm::X86::Variable::clearMaskBit|/Nasm::X86::Variable::clearMaskBit> - Clear a bit in the specified mask register retaining the other bits.
19031  
19032 250 L<Nasm::X86::Variable::clearMemory|/Nasm::X86::Variable::clearMemory> - Clear the memory described in this variable.
19033  
19034 251 L<Nasm::X86::Variable::copy|/Nasm::X86::Variable::copy> - Copy one variable into another.
19035  
19036 252 L<Nasm::X86::Variable::copyMemory|/Nasm::X86::Variable::copyMemory> - Copy from one block of memory to another.
19037  
19038 253 L<Nasm::X86::Variable::copyRef|/Nasm::X86::Variable::copyRef> - Copy a reference to a variable.
19039  
19040 254 L<Nasm::X86::Variable::copyZF|/Nasm::X86::Variable::copyZF> - Copy the current state of the zero flag into a variable.
19041  
19042 255 L<Nasm::X86::Variable::copyZFInverted|/Nasm::X86::Variable::copyZFInverted> - Copy the opposite of the current state of the zero flag into a variable.
19043  
19044 256 L<Nasm::X86::Variable::d|/Nasm::X86::Variable::d> - Dump the value of a variable on stderr and append a new line.
19045  
19046 257 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.
19047  
19048 258 L<Nasm::X86::Variable::dec|/Nasm::X86::Variable::dec> - Decrement a variable.
19049  
19050 259 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.
19051  
19052 260 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.
19053  
19054 261 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.
19055  
19056 262 L<Nasm::X86::Variable::eq|/Nasm::X86::Variable::eq> - Check whether the left hand variable is equal to the right hand variable.
19057  
19058 263 L<Nasm::X86::Variable::equals|/Nasm::X86::Variable::equals> - Equals operator.
19059  
19060 264 L<Nasm::X86::Variable::err|/Nasm::X86::Variable::err> - Dump the value of a variable on stderr.
19061  
19062 265 L<Nasm::X86::Variable::errNL|/Nasm::X86::Variable::errNL> - Dump the value of a variable on stderr and append a new line.
19063  
19064 266 L<Nasm::X86::Variable::for|/Nasm::X86::Variable::for> - Iterate the block limit times.
19065  
19066 267 L<Nasm::X86::Variable::freeMemory|/Nasm::X86::Variable::freeMemory> - Free the memory addressed by this variable for the specified length.
19067  
19068 268 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.
19069  
19070 269 L<Nasm::X86::Variable::getBFromZmm|/Nasm::X86::Variable::getBFromZmm> - Get the byte from the numbered zmm register and put it in a variable.
19071  
19072 270 L<Nasm::X86::Variable::getConst|/Nasm::X86::Variable::getConst> - Load the variable from a constant in effect setting a variable to a specified value.
19073  
19074 271 L<Nasm::X86::Variable::getConst22|/Nasm::X86::Variable::getConst22> - Load the variable from a constant in effect setting a variable to a specified value.
19075  
19076 272 L<Nasm::X86::Variable::getDFromZmm|/Nasm::X86::Variable::getDFromZmm> - Get the double word from the numbered zmm register and put it in a variable.
19077  
19078 273 L<Nasm::X86::Variable::getQFromZmm|/Nasm::X86::Variable::getQFromZmm> - Get the quad word from the numbered zmm register and put it in a variable.
19079  
19080 274 L<Nasm::X86::Variable::getReg|/Nasm::X86::Variable::getReg> - Load the variable from the named registers.
19081  
19082 275 L<Nasm::X86::Variable::getWFromZmm|/Nasm::X86::Variable::getWFromZmm> - Get the word from the numbered zmm register and put it in a variable.
19083  
19084 276 L<Nasm::X86::Variable::gt|/Nasm::X86::Variable::gt> - Check whether the left hand variable is greater than the right hand variable.
19085  
19086 277 L<Nasm::X86::Variable::inc|/Nasm::X86::Variable::inc> - Increment a variable.
19087  
19088 278 L<Nasm::X86::Variable::incDec|/Nasm::X86::Variable::incDec> - Increment or decrement a variable.
19089  
19090 279 L<Nasm::X86::Variable::isRef|/Nasm::X86::Variable::isRef> - Check whether the specified variable is a reference to another variable.
19091  
19092 280 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.
19093  
19094 281 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.
19095  
19096 282 L<Nasm::X86::Variable::lt|/Nasm::X86::Variable::lt> - Check whether the left hand variable is less than the right hand variable.
19097  
19098 283 L<Nasm::X86::Variable::max|/Nasm::X86::Variable::max> - Maximum of two variables.
19099  
19100 284 L<Nasm::X86::Variable::min|/Nasm::X86::Variable::min> - Minimum of two variables.
19101  
19102 285 L<Nasm::X86::Variable::minusAssign|/Nasm::X86::Variable::minusAssign> - Implement minus and assign.
19103  
19104 286 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.
19105  
19106 287 L<Nasm::X86::Variable::ne|/Nasm::X86::Variable::ne> - Check whether the left hand variable is not equal to the right hand variable.
19107  
19108 288 L<Nasm::X86::Variable::or|/Nasm::X86::Variable::or> - Or two variables.
19109  
19110 289 L<Nasm::X86::Variable::out|/Nasm::X86::Variable::out> - Dump the value of a variable on stdout.
19111  
19112 290 L<Nasm::X86::Variable::outNL|/Nasm::X86::Variable::outNL> - Dump the value of a variable on stdout and append a new line.
19113  
19114 291 L<Nasm::X86::Variable::plusAssign|/Nasm::X86::Variable::plusAssign> - Implement plus and assign.
19115  
19116 292 L<Nasm::X86::Variable::pop|/Nasm::X86::Variable::pop> - Pop a variable from the stack.
19117  
19118 293 L<Nasm::X86::Variable::printErrMemoryInHexNL|/Nasm::X86::Variable::printErrMemoryInHexNL> - Write the memory addressed by a variable to stderr.
19119  
19120 294 L<Nasm::X86::Variable::printMemoryInHexNL|/Nasm::X86::Variable::printMemoryInHexNL> - Write, in hexadecimal, the memory addressed by a variable to stdout or stderr.
19121  
19122 295 L<Nasm::X86::Variable::printOutMemoryInHexNL|/Nasm::X86::Variable::printOutMemoryInHexNL> - Write the memory addressed by a variable to stdout.
19123  
19124 296 L<Nasm::X86::Variable::push|/Nasm::X86::Variable::push> - Push a variable onto the stack.
19125  
19126 297 L<Nasm::X86::Variable::putBIntoXmm|/Nasm::X86::Variable::putBIntoXmm> - Place the value of the content variable at the byte in the numbered xmm register.
19127  
19128 298 L<Nasm::X86::Variable::putBIntoZmm|/Nasm::X86::Variable::putBIntoZmm> - Place the value of the content variable at the byte in the numbered zmm register.
19129  
19130 299 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.
19131  
19132 300 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.
19133  
19134 301 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.
19135  
19136 302 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.
19137  
19138 303 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.
19139  
19140 304 L<Nasm::X86::Variable::putWIntoXmm|/Nasm::X86::Variable::putWIntoXmm> - Place the value of the content variable at the word in the numbered xmm register.
19141  
19142 305 L<Nasm::X86::Variable::putWIntoZmm|/Nasm::X86::Variable::putWIntoZmm> - Place the value of the content variable at the word in the numbered zmm register.
19143  
19144 306 L<Nasm::X86::Variable::setBit|/Nasm::X86::Variable::setBit> - Set a bit in the specified register retaining the other bits.
19145  
19146 307 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.
19147  
19148 308 L<Nasm::X86::Variable::setMaskBit|/Nasm::X86::Variable::setMaskBit> - Set a bit in the specified mask register retaining the other bits.
19149  
19150 309 L<Nasm::X86::Variable::setMaskFirst|/Nasm::X86::Variable::setMaskFirst> - Set the first bits in the specified mask register.
19151  
19152 310 L<Nasm::X86::Variable::setReg|/Nasm::X86::Variable::setReg> - Set the named registers from the content of the variable.
19153  
19154 311 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.
19155  
19156 312 L<Nasm::X86::Variable::str|/Nasm::X86::Variable::str> - The name of the variable.
19157  
19158 313 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.
19159  
19160 314 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.
19161  
19162 315 L<Nasm::X86::Variable::zBroadCastD|/Nasm::X86::Variable::zBroadCastD> - Broadcast a double word in a variable into the numbered zmm.
19163  
19164 316 L<OnSegv|/OnSegv> - Request a trace back followed by exit on a B<segv> signal.
19165  
19166 317 L<OpenRead|/OpenRead> - Open a file, whose name is addressed by rax, for read and return the file descriptor in rax.
19167  
19168 318 L<OpenWrite|/OpenWrite> - Create the file named by the terminated string addressed by rax for write.
19169  
19170 319 L<Optimize|/Optimize> - Perform code optimizations.
19171  
19172 320 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.
19173  
19174 321 L<Pass|/Pass> - Pass block for an L<OrBlock>.
19175  
19176 322 L<PeekR|/PeekR> - Peek at register on stack.
19177  
19178 323 L<PopEax|/PopEax> - We cannot pop a double word from the stack in 64 bit long mode using pop so we improvise.
19179  
19180 324 L<PopMask|/PopMask> - Pop Mask registers.
19181  
19182 325 L<PopR|/PopR> - Pop registers from the stack.
19183  
19184 326 L<PopRR|/PopRR> - Pop registers from the stack without tracking.
19185  
19186 327 L<PopZmm|/PopZmm> - Pop zmm registers.
19187  
19188 328 L<PrintErrMemory|/PrintErrMemory> - Print the memory addressed by rax for a length of rdi on stderr.
19189  
19190 329 L<PrintErrMemoryInHex|/PrintErrMemoryInHex> - Dump memory from the address in rax for the length in rdi on stderr.
19191  
19192 330 L<PrintErrMemoryInHexNL|/PrintErrMemoryInHexNL> - Dump memory from the address in rax for the length in rdi and then print a new line.
19193  
19194 331 L<PrintErrMemoryNL|/PrintErrMemoryNL> - Print the memory addressed by rax for a length of rdi followed by a new line on stderr.
19195  
19196 332 L<PrintErrNL|/PrintErrNL> - Print a new line to stderr.
19197  
19198 333 L<PrintErrRaxInHex|/PrintErrRaxInHex> - Write the content of register rax in hexadecimal in big endian notation to stderr.
19199  
19200 334 L<PrintErrRegisterInHex|/PrintErrRegisterInHex> - Print the named registers as hex strings on stderr.
19201  
19202 335 L<PrintErrSpace|/PrintErrSpace> - Print one or more spaces to stderr.
19203  
19204 336 L<PrintErrString|/PrintErrString> - Print a constant string to stderr.
19205  
19206 337 L<PrintErrStringNL|/PrintErrStringNL> - Print a constant string followed by a new line to stderr.
19207  
19208 338 L<PrintErrTraceBack|/PrintErrTraceBack> - Print sub routine track back on stderr.
19209  
19210 339 L<PrintErrUtf32|/PrintErrUtf32> - Print the utf 8 character addressed by rax to stderr.
19211  
19212 340 L<PrintErrUtf8Char|/PrintErrUtf8Char> - Print the utf 8 character addressed by rax to stderr.
19213  
19214 341 L<PrintErrZF|/PrintErrZF> - Print the zero flag without disturbing it on stderr.
19215  
19216 342 L<PrintMemory|/PrintMemory> - Print the memory addressed by rax for a length of rdi on the specified channel.
19217  
19218 343 L<PrintMemoryInHex|/PrintMemoryInHex> - Dump memory from the address in rax for the length in rdi on the specified channel.
19219  
19220 344 L<PrintMemoryNL|/PrintMemoryNL> - Print the memory addressed by rax for a length of rdi on the specified channel followed by a new line.
19221  
19222 345 L<PrintNL|/PrintNL> - Print a new line to stdout or stderr.
19223  
19224 346 L<PrintOneRegisterInHex|/PrintOneRegisterInHex> - Print the named register as a hex strings.
19225  
19226 347 L<PrintOutMemory|/PrintOutMemory> - Print the memory addressed by rax for a length of rdi on stdout.
19227  
19228 348 L<PrintOutMemoryInHex|/PrintOutMemoryInHex> - Dump memory from the address in rax for the length in rdi on stdout.
19229  
19230 349 L<PrintOutMemoryInHexNL|/PrintOutMemoryInHexNL> - Dump memory from the address in rax for the length in rdi and then print a new line.
19231  
19232 350 L<PrintOutMemoryNL|/PrintOutMemoryNL> - Print the memory addressed by rax for a length of rdi followed by a new line on stdout.
19233  
19234 351 L<PrintOutNL|/PrintOutNL> - Print a new line to stderr.
19235  
19236 352 L<PrintOutRaxInHex|/PrintOutRaxInHex> - Write the content of register rax in hexadecimal in big endian notation to stderr.
19237  
19238 353 L<PrintOutRaxInReverseInHex|/PrintOutRaxInReverseInHex> - Write the content of register rax to stderr in hexadecimal in little endian notation.
19239  
19240 354 L<PrintOutRegisterInHex|/PrintOutRegisterInHex> - Print the named registers as hex strings on stdout.
19241  
19242 355 L<PrintOutRegistersInHex|/PrintOutRegistersInHex> - Print the general purpose registers in hex.
19243  
19244 356 L<PrintOutRflagsInHex|/PrintOutRflagsInHex> - Print the flags register in hex.
19245  
19246 357 L<PrintOutRipInHex|/PrintOutRipInHex> - Print the instruction pointer in hex.
19247  
19248 358 L<PrintOutSpace|/PrintOutSpace> - Print one or more spaces to stdout.
19249  
19250 359 L<PrintOutString|/PrintOutString> - Print a constant string to stdout.
19251  
19252 360 L<PrintOutStringNL|/PrintOutStringNL> - Print a constant string followed by a new line to stdout.
19253  
19254 361 L<PrintOutTraceBack|/PrintOutTraceBack> - Print sub routine track back on stdout.
19255  
19256 362 L<PrintOutUtf32|/PrintOutUtf32> - Print the utf 8 character addressed by rax to stdout.
19257  
19258 363 L<PrintOutUtf8Char|/PrintOutUtf8Char> - Print the utf 8 character addressed by rax to stdout.
19259  
19260 364 L<PrintOutZF|/PrintOutZF> - Print the zero flag without disturbing it on stdout.
19261  
19262 365 L<PrintRaxInHex|/PrintRaxInHex> - Write the content of register rax in hexadecimal in big endian notation to the specified channel.
19263  
19264 366 L<PrintRegisterInHex|/PrintRegisterInHex> - Print the named registers as hex strings.
19265  
19266 367 L<PrintSpace|/PrintSpace> - Print one or more spaces to the specified channel.
19267  
19268 368 L<PrintString|/PrintString> - Print a constant string to the specified channel.
19269  
19270 369 L<PrintStringNL|/PrintStringNL> - Print a constant string to the specified channel followed by a new line.
19271  
19272 370 L<PrintTraceBack|/PrintTraceBack> - Trace the call stack.
19273  
19274 371 L<PrintUtf32|/PrintUtf32> - Print the specified number of utf32 characters at the specified address to the specified channel.
19275  
19276 372 L<PrintUtf8Char|/PrintUtf8Char> - Print the utf 8 character addressed by rax to the specified channel.
19277  
19278 373 L<PushMask|/PushMask> - Push several Mask registers.
19279  
19280 374 L<PushR|/PushR> - Push registers onto the stack.
19281  
19282 375 L<PushRR|/PushRR> - Push registers onto the stack without tracking.
19283  
19284 376 L<PushZmm|/PushZmm> - Push several zmm registers.
19285  
19286 377 L<putIntoZmm|/putIntoZmm> - Put the specified register into the numbered zmm at the specified offset in the zmm.
19287  
19288 378 L<R|/R> - Define a reference variable.
19289  
19290 379 L<Rb|/Rb> - Layout bytes in the data segment and return their label.
19291  
19292 380 L<Rbwdq|/Rbwdq> - Layout data.
19293  
19294 381 L<RComment|/RComment> - Insert a comment into the read only data segment.
19295  
19296 382 L<Rd|/Rd> - Layout double words in the data segment and return their label.
19297  
19298 383 L<ReadFile|/ReadFile> - Read a file whose name is addressed by rax into memory.
19299  
19300 384 L<ReadTimeStampCounter|/ReadTimeStampCounter> - Read the time stamp counter and return the time in nanoseconds in rax.
19301  
19302 385 L<RegistersAvailable|/RegistersAvailable> - Add a new set of registers that are available.
19303  
19304 386 L<RegistersFree|/RegistersFree> - Remove the current set of registers known to be free.
19305  
19306 387 L<RegisterSize|/RegisterSize> - Return the size of a register.
19307  
19308 388 L<removeNonAsciiChars|/removeNonAsciiChars> - Return a copy of the specified string with all the non ascii characters removed.
19309  
19310 389 L<ReorderSyscallRegisters|/ReorderSyscallRegisters> - Map the list of registers provided to the 64 bit system call sequence.
19311  
19312 390 L<RestoreFirstFour|/RestoreFirstFour> - Restore the first 4 parameter registers.
19313  
19314 391 L<RestoreFirstFourExceptRax|/RestoreFirstFourExceptRax> - Restore the first 4 parameter registers except rax so it can return its value.
19315  
19316 392 L<RestoreFirstFourExceptRaxAndRdi|/RestoreFirstFourExceptRaxAndRdi> - Restore the first 4 parameter registers except rax and rdi so we can return a pair of values.
19317  
19318 393 L<RestoreFirstSeven|/RestoreFirstSeven> - Restore the first 7 parameter registers.
19319  
19320 394 L<RestoreFirstSevenExceptRax|/RestoreFirstSevenExceptRax> - Restore the first 7 parameter registers except rax which is being used to return the result.
19321  
19322 395 L<RestoreFirstSevenExceptRaxAndRdi|/RestoreFirstSevenExceptRaxAndRdi> - Restore the first 7 parameter registers except rax and rdi which are being used to return the results.
19323  
19324 396 L<Rq|/Rq> - Layout quad words in the data segment and return their label.
19325  
19326 397 L<Rs|/Rs> - Layout bytes in read only memory and return their label.
19327  
19328 398 L<Rutf8|/Rutf8> - Layout a utf8 encoded string as bytes in read only memory and return their label.
19329  
19330 399 L<Rw|/Rw> - Layout words in the data segment and return their label.
19331  
19332 400 L<SaveFirstFour|/SaveFirstFour> - Save the first 4 parameter registers making any parameter registers read only.
19333  
19334 401 L<SaveFirstSeven|/SaveFirstSeven> - Save the first 7 parameter registers.
19335  
19336 402 L<SaveRegIntoMm|/SaveRegIntoMm> - Save the specified register into the numbered zmm at the quad offset specified as a constant number.
19337  
19338 403 L<SetLabel|/SetLabel> - Create (if necessary) and set a label in the code section returning the label so set.
19339  
19340 404 L<SetMaskRegister|/SetMaskRegister> - Set the mask register to ones starting at the specified position for the specified length and zeroes elsewhere.
19341  
19342 405 L<SetZF|/SetZF> - Set the zero flag.
19343  
19344 406 L<Start|/Start> - Initialize the assembler.
19345  
19346 407 L<StatSize|/StatSize> - Stat a file whose name is addressed by rax to get its size in rax.
19347  
19348 408 L<StringLength|/StringLength> - Length of a zero terminated string.
19349  
19350 409 L<Structure|/Structure> - Create a structure addressed by a register.
19351  
19352 410 L<Subroutine|/Subroutine> - Create a subroutine that can be called in assembler code.
19353  
19354 411 L<SubroutineStartStack|/SubroutineStartStack> - Initialize a new stack frame.
19355  
19356 412 L<Then|/Then> - Then block for an If statement.
19357  
19358 413 L<totalBytesAssembled|/totalBytesAssembled> - Total size in bytes of all files assembled during testing.
19359  
19360 414 L<unlinkFile|/unlinkFile> - Unlink the named file.
19361  
19362 415 L<UnReorderSyscallRegisters|/UnReorderSyscallRegisters> - Recover the initial values in registers that were reordered.
19363  
19364 416 L<V|/V> - Define a variable.
19365  
19366 417 L<Variable|/Variable> - Create a new variable with the specified name initialized via an optional expression.
19367  
19368 418 L<WaitPid|/WaitPid> - Wait for the pid in rax to complete.
19369  
19370 419 L<xmm|/xmm> - Add xmm to the front of a list of register expressions.
19371  
19372 420 L<ymm|/ymm> - Add ymm to the front of a list of register expressions.
19373  
19374 421 L<zmm|/zmm> - Add zmm to the front of a list of register expressions.
19375  
19376 =head1 Installation
19377  
19378 This module is written in 100% Pure Perl and, thus, it is easy to read,
19379 comprehend, use, modify and install via B<cpan>:
19380  
19381 sudo cpan install Nasm::X86
19382  
19383 =head1 Author
19384  
19385 L<philiprbrenan@gmail.com|mailto:philiprbrenan@gmail.com>
19386  
19387 L<http://www.appaapps.com|http://www.appaapps.com>
19388  
19389 =head1 Copyright
19390  
19391 Copyright (c) 2016-2021 Philip R Brenan.
19392  
19393 This module is free software. It may be used, redistributed and/or modified
19394 under the same terms as Perl itself.
19395  
19396 =cut
19397  
19398  
19399  
19400 # Tests and documentation
19401  
19402 sub test
19403 1 ▶ {my $p = __PACKAGE__;
Subroutine test: called CC=5 SCAR=17.4
Pod undocumented
19404 1 binmode($_, ":utf8") for *STDOUT, *STDERR;
19405 1 ▶ return if eval "eof(${p}::DATA)";
Branch: 1 branch
BranchTrueFalseTotal
if eval "eof(${p}::DATA)" 0 1 1
19406 1 my $s = eval "join('', <${p}::DATA>)";
19407 1 ▶ $@ and die $@;
Branch: 1 branch
BranchTrueFalseTotal
$@ and die $@ 0 1 1
19408 1 ▶ eval $s;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
19409 0 ▶ $@ and die $@;
Branch: 1 branch
BranchTrueFalseTotal
$@ and die $@ 0 0 0
19410 0 1
19411 }
19412  
19413 1 ▶test unless caller;
Branch: 1 branch
BranchTrueFalseTotal
unless caller 0 1 1
19414  
19415 1 1;
19416 # podDocumentation
19417 __DATA__
↑ Summary Build »