5 <title>Mu -
302stack_allocate.subx
</title>
6 <meta name=
"Generator" content=
"Vim/8.2">
7 <meta name=
"plugin-version" content=
"vim8.1_v2">
8 <meta name=
"syntax" content=
"none">
9 <meta name=
"settings" content=
"number_lines,use_css,pre_wrap,no_foldcolumn,expand_tabs,line_ids,prevent_copy=,use_input_for_pc=fallback">
10 <meta name=
"colorscheme" content=
"minimal-light">
13 pre { white-space: pre-wrap; font-family: monospace; color: #000000; background-color: #ffffd7; }
14 body { font-size:12pt; font-family: monospace; color: #000000; background-color: #ffffd7; }
16 * { font-size:12pt; font-size: 1em; }
17 .subxComment { color: #005faf; }
18 .SpecialChar { color: #d70000; }
20 .subxFunction { color: #af5f00; text-decoration: underline; }
21 .Constant { color: #008787; }
22 .CommentedCode { color: #8a8a8a; }
29 /* function to open any folds containing a jumped-to line before jumping to it */
33 lineNum
= window
.location
.hash
;
34 lineNum
= lineNum
.substr(1); /* strip off '#' */
36 if (lineNum
.indexOf('L') == -1) {
37 lineNum
= 'L'+lineNum
;
39 var lineElem
= document
.getElementById(lineNum
);
40 /* Always jump to new location even if the line was hidden inside a fold, or
41 * we corrected the raw number to a line ID.
44 lineElem
.scrollIntoView(true);
48 if ('onhashchange' in window
) {
49 window
.onhashchange
= JumpToLine
;
55 <body onload='JumpToLine();'
>
56 <a href='https://github.com/akkartik/mu/blob/main/
302stack_allocate.subx'
>https://github.com/akkartik/mu/blob/main/
302stack_allocate.subx
</a>
57 <pre id='vimCodeElement'
>
58 <span id=
"L1" class=
"LineNr"> 1 </span><span class=
"subxComment"># A function which pushes n zeros on the stack.
</span>
59 <span id=
"L2" class=
"LineNr"> 2 </span><span class=
"subxComment"># Really only intended to be called from code generated by mu.subx (for array
</span>
60 <span id=
"L3" class=
"LineNr"> 3 </span><span class=
"subxComment"># vars on the stack).
</span>
61 <span id=
"L4" class=
"LineNr"> 4 </span>
62 <span id=
"L5" class=
"LineNr"> 5 </span>== code
63 <span id=
"L6" class=
"LineNr"> 6 </span>
64 <span id=
"L7" class=
"LineNr"> 7 </span><span class=
"CommentedCode">#? Entry:
</span>
65 <span id=
"L8" class=
"LineNr"> 8 </span><span class=
"CommentedCode">#? # . prologue
</span>
66 <span id=
"L9" class=
"LineNr"> 9 </span><span class=
"CommentedCode">#?
89/
<- %ebp
4/r32/esp
</span>
67 <span id=
"L10" class=
"LineNr">10 </span><span class=
"CommentedCode">#? #
</span>
68 <span id=
"L11" class=
"LineNr">11 </span><span class=
"CommentedCode">#?
68/push
0xfcfdfeff/imm32
</span>
69 <span id=
"L12" class=
"LineNr">12 </span><span class=
"CommentedCode">#? b8/copy-to-eax
0x34353637/imm32
</span>
70 <span id=
"L13" class=
"LineNr">13 </span><span class=
"CommentedCode">#? $dump-stack0:
</span>
71 <span id=
"L14" class=
"LineNr">14 </span><span class=
"CommentedCode">#? (push-n-zero-bytes
4)
</span>
72 <span id=
"L15" class=
"LineNr">15 </span><span class=
"CommentedCode">#?
68/push
0x20/imm32
</span>
73 <span id=
"L16" class=
"LineNr">16 </span><span class=
"CommentedCode">#? $dump-stack9:
</span>
74 <span id=
"L17" class=
"LineNr">17 </span><span class=
"CommentedCode">#? b8/copy-to-eax
1/imm32/exit
</span>
75 <span id=
"L18" class=
"LineNr">18 </span><span class=
"CommentedCode">#? cd/syscall
0x80/imm8
</span>
76 <span id=
"L19" class=
"LineNr">19 </span>
77 <span id=
"L20" class=
"LineNr">20 </span><span class=
"subxComment"># This is not a regular function, so it won't be idiomatic.
</span>
78 <span id=
"L21" class=
"LineNr">21 </span><span class=
"subxComment"># Registers must be properly restored.
</span>
79 <span id=
"L22" class=
"LineNr">22 </span><span class=
"subxComment"># Registers can be spilled, but that modifies the stack and needs to be
</span>
80 <span id=
"L23" class=
"LineNr">23 </span><span class=
"subxComment"># cleaned up.
</span>
81 <span id=
"L24" class=
"LineNr">24 </span>
82 <span id=
"L25" class=
"LineNr">25 </span><span class=
"subxComment"># Overhead:
</span>
83 <span id=
"L26" class=
"LineNr">26 </span><span class=
"subxComment">#
62 + n*
6 instructions to push n bytes.
</span>
84 <span id=
"L27" class=
"LineNr">27 </span><span class=
"subxComment"># If we just emitted code to push n zeroes, it would be:
</span>
85 <span id=
"L28" class=
"LineNr">28 </span><span class=
"subxComment">#
5 bytes for
4 zero bytes, so
1.25 bytes per zero. And that's not even
</span>
86 <span id=
"L29" class=
"LineNr">29 </span><span class=
"subxComment"># instructions.
</span>
87 <span id=
"L30" class=
"LineNr">30 </span><span class=
"subxComment"># But on the other hand it would destroy the instruction cache, where this
</span>
88 <span id=
"L31" class=
"LineNr">31 </span><span class=
"subxComment"># approach requires
15 instructions, fixed.
</span>
89 <span id=
"L32" class=
"LineNr">32 </span>
90 <span id=
"L33" class=
"LineNr">33 </span><span class=
"subxComment"># n must be positive
</span>
91 <span id=
"L34" class=
"LineNr">34 </span><span class=
"subxFunction">push-n-zero-bytes
</span>:
<span class=
"subxComment"># n: int
</span>
92 <span id=
"L35" class=
"LineNr">35 </span><span class=
"Constant">$push-n-zero-bytes:prologue
</span>:
93 <span id=
"L36" class=
"LineNr">36 </span> 89/
<- *
<span class=
"SpecialChar"><a href='
302stack_allocate.subx.html#L56'
>Push-n-zero-bytes-ebp
</a></span> 5/r32/ebp
<span class=
"subxComment"># spill ebp without affecting stack
</span>
94 <span id=
"L37" class=
"LineNr">37 </span> 89/
<- %ebp
4/r32/esp
95 <span id=
"L38" class=
"LineNr">38 </span><span class=
"Constant">$push-n-zero-bytes:copy-ra
</span>:
96 <span id=
"L39" class=
"LineNr">39 </span> <span class=
"subxComment"># -- esp = ebp
</span>
97 <span id=
"L40" class=
"LineNr">40 </span> 89/
<- *
<span class=
"SpecialChar"><a href='
302stack_allocate.subx.html#L60'
>Push-n-zero-bytes-eax
</a></span> 0/r32/eax
98 <span id=
"L41" class=
"LineNr">41 </span> 8b/-
> *esp
0/r32/eax
99 <span id=
"L42" class=
"LineNr">42 </span> 2b/subtract *(ebp+
4)
4/r32/esp
100 <span id=
"L43" class=
"LineNr">43 </span> <span class=
"subxComment"># -- esp+n = ebp
</span>
101 <span id=
"L44" class=
"LineNr">44 </span> 89/
<- *esp
0/r32/eax
102 <span id=
"L45" class=
"LineNr">45 </span> 8b/-
> *
<span class=
"SpecialChar"><a href='
302stack_allocate.subx.html#L60'
>Push-n-zero-bytes-eax
</a></span> 0/r32/eax
103 <span id=
"L46" class=
"LineNr">46 </span><span class=
"Constant">$push-n-zero-bytes:bulk-cleaning
</span>:
104 <span id=
"L47" class=
"LineNr">47 </span> 89/
<- *
<span class=
"SpecialChar"><a href='
302stack_allocate.subx.html#L58'
>Push-n-zero-bytes-esp
</a></span> 4/r32/esp
105 <span id=
"L48" class=
"LineNr">48 </span> 81 0/subop/add *
<span class=
"SpecialChar"><a href='
302stack_allocate.subx.html#L58'
>Push-n-zero-bytes-esp
</a></span> 4/imm32
106 <span id=
"L49" class=
"LineNr">49 </span> 81 0/subop/add *(ebp+
4)
4/imm32
107 <span id=
"L50" class=
"LineNr">50 </span> (
<a href='
120allocate.subx.html#L869'
>zero-out
</a> *
<span class=
"SpecialChar"><a href='
302stack_allocate.subx.html#L58'
>Push-n-zero-bytes-esp
</a></span> *(ebp+
4))
<span class=
"subxComment"># n+
4</span>
108 <span id=
"L51" class=
"LineNr">51 </span><span class=
"Constant">$push-n-zero-bytes:epilogue
</span>:
109 <span id=
"L52" class=
"LineNr">52 </span> 8b/-
> *
<span class=
"SpecialChar"><a href='
302stack_allocate.subx.html#L56'
>Push-n-zero-bytes-ebp
</a></span> 5/r32/ebp
<span class=
"subxComment"># restore spill
</span>
110 <span id=
"L53" class=
"LineNr">53 </span> c3/return
111 <span id=
"L54" class=
"LineNr">54 </span>
112 <span id=
"L55" class=
"LineNr">55 </span>== data
113 <span id=
"L56" class=
"LineNr">56 </span><span class=
"SpecialChar">Push-n-zero-bytes-ebp
</span>:
<span class=
"subxComment"># (addr int)
</span>
114 <span id=
"L57" class=
"LineNr">57 </span> 0/imm32
115 <span id=
"L58" class=
"LineNr">58 </span><span class=
"SpecialChar">Push-n-zero-bytes-esp
</span>:
<span class=
"subxComment"># (addr int)
</span>
116 <span id=
"L59" class=
"LineNr">59 </span> 0/imm32
117 <span id=
"L60" class=
"LineNr">60 </span><span class=
"SpecialChar">Push-n-zero-bytes-eax
</span>:
118 <span id=
"L61" class=
"LineNr">61 </span> 0/imm32
122 <!-- vim: set foldmethod=manual : -->