diff options
author | Kartik Agaram <vc@akkartik.com> | 2020-05-25 00:49:21 -0700 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2020-05-25 00:49:21 -0700 |
commit | a01ddfa22d2cbfcdfee43d2a8f7327e91ee4ccc7 (patch) | |
tree | c9a7d6a850b849187655600916393e44d67e88af /html/mu_instructions.html | |
parent | 3351d83f8bd920a6e7faab723af8255ae7671f26 (diff) | |
download | mu-a01ddfa22d2cbfcdfee43d2a8f7327e91ee4ccc7.tar.gz |
6404
Diffstat (limited to 'html/mu_instructions.html')
-rw-r--r-- | html/mu_instructions.html | 49 |
1 files changed, 39 insertions, 10 deletions
diff --git a/html/mu_instructions.html b/html/mu_instructions.html index cc6b0095..55443132 100644 --- a/html/mu_instructions.html +++ b/html/mu_instructions.html @@ -15,7 +15,7 @@ body { font-family: monospace; color: #000000; background-color: #c6c6c6; } * { font-size: 1em; } .Comment { color: #005faf; } .Constant { color: #008787; } -.Special { color: #ff6060; } +.Special { color: #d70000; } .PreProc { color: #c000c0; } .SalientComment { color: #0000af; } --> @@ -191,24 +191,53 @@ var/reg: (addr T) <span class="Special"><-</span> address var2: T Array operations (TODO: bounds-checking) -var/reg <span class="Special"><-</span> length arr/reg2: (addr array T) - => <span class="Constant">"8b/-> *"</span> reg2 <span class="Constant">" "</span> reg <span class="Constant">"/r32"</span> -var/reg <span class="Special"><-</span> index arr/rega: (addr array T), idx/regi: int <span class="Comment"># if size(T) is 4 or 8</span> - => <span class="Constant">"8d/copy-address *("</span> rega <span class="Constant">"+"</span> regi <span class="Constant">"<<"</span> log2(size(T)) <span class="Constant">"+4) "</span> reg <span class="Constant">"/r32"</span> +var/reg <span class="Special"><-</span> index arr/rega: (addr array T), idx/regi: int + | if size-of(T) is <span class="Constant">4</span> or <span class="Constant">8</span> + => <span class="Constant">"8d/copy-address *("</span> rega <span class="Constant">"+"</span> regi <span class="Constant">"<<"</span> log2(size-of(T)) <span class="Constant">"+4) "</span> reg <span class="Constant">"/r32"</span> var/reg <span class="Special"><-</span> index arr: (array T sz), idx/regi: int - => <span class="Constant">"8d/copy-address *(ebp+"</span> regi <span class="Constant">"<<"</span> log2(size(T)) <span class="Constant">"+"</span> (arr.stack-offset + <span class="Constant">4</span>) <span class="Constant">") "</span> reg <span class="Constant">"/r32"</span> + => <span class="Constant">"8d/copy-address *(ebp+"</span> regi <span class="Constant">"<<"</span> log2(size-of(T)) <span class="Constant">"+"</span> (arr.stack-offset + <span class="Constant">4</span>) <span class="Constant">") "</span> reg <span class="Constant">"/r32"</span> var/reg <span class="Special"><-</span> index arr/rega: (addr array T), n - => <span class="Constant">"8d/copy-address *("</span> rega <span class="Constant">"+"</span> (n*size(T)+<span class="Constant">4</span>) <span class="Constant">") "</span> reg <span class="Constant">"/r32"</span> + => <span class="Constant">"8d/copy-address *("</span> rega <span class="Constant">"+"</span> (n*size-of(T)+<span class="Constant">4</span>) <span class="Constant">") "</span> reg <span class="Constant">"/r32"</span> var/reg <span class="Special"><-</span> index arr: (array T sz), n - => <span class="Constant">"8d/copy-address *(ebp+"</span> (arr.stack-offset+<span class="Constant">4</span>+n*size(T)) <span class="Constant">") "</span> reg <span class="Constant">"/r32"</span> + => <span class="Constant">"8d/copy-address *(ebp+"</span> (arr.stack-offset+<span class="Constant">4</span>+n*size-of(T)) <span class="Constant">") "</span> reg <span class="Constant">"/r32"</span> var/reg: (offset T) <span class="Special"><-</span> compute-offset arr: (addr array T), idx/regi: int <span class="Comment"># arr can be in reg or mem</span> - => <span class="Constant">"69/multiply %"</span> regi <span class="Constant">" "</span> size(T) <span class="Constant">"/imm32 "</span> reg <span class="Constant">"/r32"</span> + => <span class="Constant">"69/multiply %"</span> regi <span class="Constant">" "</span> size-of(T) <span class="Constant">"/imm32 "</span> reg <span class="Constant">"/r32"</span> var/reg: (offset T) <span class="Special"><-</span> compute-offset arr: (addr array T), idx: int <span class="Comment"># arr can be in reg or mem</span> - => <span class="Constant">"69/multiply *(ebp+"</span> idx.stack-offset <span class="Constant">") "</span> size(T) <span class="Constant">"/imm32 "</span> reg <span class="Constant">"/r32"</span> + => <span class="Constant">"69/multiply *(ebp+"</span> idx.stack-offset <span class="Constant">") "</span> size-of(T) <span class="Constant">"/imm32 "</span> reg <span class="Constant">"/r32"</span> var/reg <span class="Special"><-</span> index arr/rega: (addr array T), o/rego: offset => <span class="Constant">"8d/copy-address *("</span> rega <span class="Constant">"+"</span> rego <span class="Constant">"+4) "</span> reg <span class="Constant">"/r32"</span> +Computing the length of an array is complex. + +var/reg <span class="Special"><-</span> length arr/reg2: (addr array T) + | if T is byte (TODO) + => <span class="Constant">"8b/-> *"</span> reg2 <span class="Constant">" "</span> reg <span class="Constant">"/r32"</span> + | if size-of(T) is <span class="Constant">4</span> or <span class="Constant">8</span> or <span class="Constant">16</span> or <span class="Constant">32</span> or <span class="Constant">64</span> or <span class="Constant">128</span> + => <span class="Constant">"8b/-> *"</span> reg2 <span class="Constant">" "</span> reg <span class="Constant">"/r32"</span> + <span class="Constant">"c1/shift 5/subop/logic-right %"</span> reg <span class="Constant">" "</span> log2(size-of(T)) <span class="Constant">"/imm8"</span> + | otherwise + x86 has no instruction to divide by a literal, so + we need up to <span class="Constant">3</span> extra registers! <span class="Constant">eax</span>/<span class="Constant">edx</span> for division and say <span class="Constant">ecx</span> + => if reg is not <span class="Constant">eax</span> + <span class="Constant">"50/push-eax"</span> + if reg is not <span class="Constant">ecx</span> + <span class="Constant">"51/push-ecx"</span> + if reg is not <span class="Constant">edx</span> + <span class="Constant">"52/push-edx"</span> + <span class="Constant">"8b/-> *"</span> reg2 <span class="Constant">" eax/r32"</span> + <span class="Constant">"31/xor %edx 2/r32/edx"</span> <span class="Comment"># sign-extend, but array size can't be negative</span> + <span class="Constant">"b9/copy-to-ecx "</span> size-of(T) <span class="Constant">"/imm32"</span> + <span class="Constant">"f7 7/subop/idiv-eax-edx-by %ecx"</span> + if reg is not <span class="Constant">eax</span> + <span class="Constant">"89/<- %"</span> reg <span class="Constant">" 0/r32/eax"</span> + if reg is not <span class="Constant">edx</span> + <span class="Constant">"5a/pop-to-edx"</span> + if reg is not <span class="Constant">ecx</span> + <span class="Constant">"59/pop-to-ecx"</span> + if reg is not <span class="Constant">eax</span> + <span class="Constant">"58/pop-to-eax"</span> + <span class="Comment"># User-defined types</span> If a record (product) type T was defined to have elements a, b, c, ... of |