aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorjohannst <johannst@users.noreply.github.com>2024-03-18 22:02:54 +0000
committerjohannst <johannst@users.noreply.github.com>2024-03-18 22:02:54 +0000
commit52a0308e18fbbec25f0e9f31ec8f11589a35f351 (patch)
tree522424f6d94aeb9c3fff16a109c5f85efb97d66c /src
parent596eaec7fa9678939031eb1a434735c51f3ecec2 (diff)
downloadjuicebox-asm-52a0308e18fbbec25f0e9f31ec8f11589a35f351.tar.gz
juicebox-asm-52a0308e18fbbec25f0e9f31ec8f11589a35f351.zip
deploy: 7653ced7e8ce18b9ada2b666c63832007f8becf2
Diffstat (limited to 'src')
-rw-r--r--src/juicebox_asm/asm.rs.html6
-rw-r--r--src/juicebox_asm/insn.rs.html32
-rw-r--r--src/juicebox_asm/insn/add.rs.html4
-rw-r--r--src/juicebox_asm/insn/cmovnz.rs.html18
-rw-r--r--src/juicebox_asm/insn/cmovz.rs.html18
-rw-r--r--src/juicebox_asm/insn/mov.rs.html8
-rw-r--r--src/juicebox_asm/insn/test.rs.html4
-rw-r--r--src/tiny_vm/tiny_vm.rs.html14
8 files changed, 87 insertions, 17 deletions
diff --git a/src/juicebox_asm/asm.rs.html b/src/juicebox_asm/asm.rs.html
index e58260d..4418397 100644
--- a/src/juicebox_asm/asm.rs.html
+++ b/src/juicebox_asm/asm.rs.html
@@ -343,6 +343,7 @@
<a href="#342" id="342">342</a>
<a href="#343" id="343">343</a>
<a href="#344" id="344">344</a>
+<a href="#345" id="345">345</a>
</pre></div><pre class="rust"><code><span class="doccomment">//! The `x64` jit assembler.
</span><span class="kw">use crate</span>::<span class="kw-2">*</span>;
@@ -437,7 +438,7 @@
<span class="comment">// -- Encode utilities.
</span><span class="doccomment">/// Encode an register-register instruction.
- </span><span class="kw">pub</span>(<span class="kw">crate</span>) <span class="kw">fn </span>encode_rr&lt;T: Reg&gt;(<span class="kw-2">&amp;mut </span><span class="self">self</span>, opc: u8, op1: T, op2: T)
+ </span><span class="kw">pub</span>(<span class="kw">crate</span>) <span class="kw">fn </span>encode_rr&lt;T: Reg&gt;(<span class="kw-2">&amp;mut </span><span class="self">self</span>, opc: <span class="kw-2">&amp;</span>[u8], op1: T, op2: T)
<span class="kw">where
</span><span class="self">Self</span>: EncodeRR&lt;T&gt;,
{
@@ -454,7 +455,8 @@
<span class="kw">let </span>rex = &lt;<span class="self">Self </span><span class="kw">as </span>EncodeRR&lt;T&gt;&gt;::rex(op1, op2);
<span class="self">self</span>.emit_optional(<span class="kw-2">&amp;</span>[prefix, rex]);
- <span class="self">self</span>.emit(<span class="kw-2">&amp;</span>[opc, modrm]);
+ <span class="self">self</span>.emit(opc);
+ <span class="self">self</span>.emit(<span class="kw-2">&amp;</span>[modrm]);
}
<span class="doccomment">/// Encode an offset-immediate instruction.
diff --git a/src/juicebox_asm/insn.rs.html b/src/juicebox_asm/insn.rs.html
index 7198773..029258c 100644
--- a/src/juicebox_asm/insn.rs.html
+++ b/src/juicebox_asm/insn.rs.html
@@ -86,10 +86,28 @@
<a href="#85" id="85">85</a>
<a href="#86" id="86">86</a>
<a href="#87" id="87">87</a>
+<a href="#88" id="88">88</a>
+<a href="#89" id="89">89</a>
+<a href="#90" id="90">90</a>
+<a href="#91" id="91">91</a>
+<a href="#92" id="92">92</a>
+<a href="#93" id="93">93</a>
+<a href="#94" id="94">94</a>
+<a href="#95" id="95">95</a>
+<a href="#96" id="96">96</a>
+<a href="#97" id="97">97</a>
+<a href="#98" id="98">98</a>
+<a href="#99" id="99">99</a>
+<a href="#100" id="100">100</a>
+<a href="#101" id="101">101</a>
+<a href="#102" id="102">102</a>
+<a href="#103" id="103">103</a>
</pre></div><pre class="rust"><code><span class="doccomment">//! Trait definitions of various instructions.
</span><span class="kw">mod </span>add;
<span class="kw">mod </span>call;
+<span class="kw">mod </span>cmovnz;
+<span class="kw">mod </span>cmovz;
<span class="kw">mod </span>cmp;
<span class="kw">mod </span>dec;
<span class="kw">mod </span>jmp;
@@ -114,6 +132,20 @@
</span><span class="kw">fn </span>call(<span class="kw-2">&amp;mut </span><span class="self">self</span>, op1: T);
}
+<span class="kw">pub trait </span>Cmovnz&lt;T, U&gt; {
+ <span class="doccomment">/// Emit a (conditional) move if not zero instruction.
+ ///
+ /// Move is only commited if (ZF=0).
+ </span><span class="kw">fn </span>cmovnz(<span class="kw-2">&amp;mut </span><span class="self">self</span>, op1: T, op2: U);
+}
+
+<span class="kw">pub trait </span>Cmovz&lt;T, U&gt; {
+ <span class="doccomment">/// Emit a (conditional) move if zero instruction.
+ ///
+ /// Move is only commited if (ZF=1).
+ </span><span class="kw">fn </span>cmovz(<span class="kw-2">&amp;mut </span><span class="self">self</span>, op1: T, op2: U);
+}
+
<span class="doccomment">/// Trait for [`cmp`](https://www.felixcloutier.com/x86/cmp) instruction kinds.
</span><span class="kw">pub trait </span>Cmp&lt;T, U&gt; {
<span class="doccomment">/// Emit a compare instruction.
diff --git a/src/juicebox_asm/insn/add.rs.html b/src/juicebox_asm/insn/add.rs.html
index a6ac132..6146498 100644
--- a/src/juicebox_asm/insn/add.rs.html
+++ b/src/juicebox_asm/insn/add.rs.html
@@ -30,13 +30,13 @@
<span class="kw">impl </span>Add&lt;Reg64, Reg64&gt; <span class="kw">for </span>Asm {
<span class="kw">fn </span>add(<span class="kw-2">&amp;mut </span><span class="self">self</span>, op1: Reg64, op2: Reg64) {
- <span class="self">self</span>.encode_rr(<span class="number">0x01</span>, op1, op2);
+ <span class="self">self</span>.encode_rr(<span class="kw-2">&amp;</span>[<span class="number">0x01</span>], op1, op2);
}
}
<span class="kw">impl </span>Add&lt;Reg32, Reg32&gt; <span class="kw">for </span>Asm {
<span class="kw">fn </span>add(<span class="kw-2">&amp;mut </span><span class="self">self</span>, op1: Reg32, op2: Reg32) {
- <span class="self">self</span>.encode_rr(<span class="number">0x01</span>, op1, op2);
+ <span class="self">self</span>.encode_rr(<span class="kw-2">&amp;</span>[<span class="number">0x01</span>], op1, op2);
}
}
diff --git a/src/juicebox_asm/insn/cmovnz.rs.html b/src/juicebox_asm/insn/cmovnz.rs.html
new file mode 100644
index 0000000..29bfb58
--- /dev/null
+++ b/src/juicebox_asm/insn/cmovnz.rs.html
@@ -0,0 +1,18 @@
+<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Source of the Rust file `src/insn/cmovnz.rs`."><title>cmovnz.rs - source</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../static.files/SourceSerif4-Regular-46f98efaafac5295.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><link rel="stylesheet" href="../../../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../../../static.files/rustdoc-ac92e1bbe349e143.css"><meta name="rustdoc-vars" data-root-path="../../../" data-static-root-path="../../../static.files/" data-current-crate="juicebox_asm" data-themes="" data-resource-suffix="" data-rustdoc-version="1.76.0 (07dca489a 2024-02-04)" data-channel="1.76.0" data-search-js="search-2b6ce74ff89ae146.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="../../../static.files/storage-f2adc0d6ca4d09fb.js"></script><script defer src="../../../static.files/src-script-39ed315d46fb705f.js"></script><script defer src="../../../src-files.js"></script><script defer src="../../../static.files/main-305769736d49e732.js"></script><noscript><link rel="stylesheet" href="../../../static.files/noscript-feafe1bb7466e4bd.css"></noscript><link rel="alternate icon" type="image/png" href="../../../static.files/favicon-16x16-8b506e7a72182f1c.png"><link rel="alternate icon" type="image/png" href="../../../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../../../static.files/favicon-2c020d218678b618.svg"></head><body class="rustdoc src"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"></nav><div class="sidebar-resizer"></div>
+ <main><nav class="sub"><form class="search-form"><span></span><input class="search-input" name="search" aria-label="Run search in the documentation" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" tabindex="-1"><a href="../../../help.html" title="help">?</a></div><div id="settings-menu" tabindex="-1"><a href="../../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../../static.files/wheel-7b819b6101059cd0.svg"></a></div></form></nav><section id="main-content" class="content"><div class="example-wrap"><div data-nosnippet><pre class="src-line-numbers"><a href="#1" id="1">1</a>
+<a href="#2" id="2">2</a>
+<a href="#3" id="3">3</a>
+<a href="#4" id="4">4</a>
+<a href="#5" id="5">5</a>
+<a href="#6" id="6">6</a>
+<a href="#7" id="7">7</a>
+<a href="#8" id="8">8</a>
+</pre></div><pre class="rust"><code><span class="kw">use </span><span class="kw">super</span>::Cmovnz;
+<span class="kw">use crate</span>::{Asm, Reg64};
+
+<span class="kw">impl </span>Cmovnz&lt;Reg64, Reg64&gt; <span class="kw">for </span>Asm {
+ <span class="kw">fn </span>cmovnz(<span class="kw-2">&amp;mut </span><span class="self">self</span>, op1: Reg64, op2: Reg64) {
+ <span class="self">self</span>.encode_rr(<span class="kw-2">&amp;</span>[<span class="number">0x0f</span>, <span class="number">0x45</span>], op2, op1);
+ }
+}
+</code></pre></div></section></main></body></html> \ No newline at end of file
diff --git a/src/juicebox_asm/insn/cmovz.rs.html b/src/juicebox_asm/insn/cmovz.rs.html
new file mode 100644
index 0000000..ecb62f1
--- /dev/null
+++ b/src/juicebox_asm/insn/cmovz.rs.html
@@ -0,0 +1,18 @@
+<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Source of the Rust file `src/insn/cmovz.rs`."><title>cmovz.rs - source</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../static.files/SourceSerif4-Regular-46f98efaafac5295.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><link rel="stylesheet" href="../../../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../../../static.files/rustdoc-ac92e1bbe349e143.css"><meta name="rustdoc-vars" data-root-path="../../../" data-static-root-path="../../../static.files/" data-current-crate="juicebox_asm" data-themes="" data-resource-suffix="" data-rustdoc-version="1.76.0 (07dca489a 2024-02-04)" data-channel="1.76.0" data-search-js="search-2b6ce74ff89ae146.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="../../../static.files/storage-f2adc0d6ca4d09fb.js"></script><script defer src="../../../static.files/src-script-39ed315d46fb705f.js"></script><script defer src="../../../src-files.js"></script><script defer src="../../../static.files/main-305769736d49e732.js"></script><noscript><link rel="stylesheet" href="../../../static.files/noscript-feafe1bb7466e4bd.css"></noscript><link rel="alternate icon" type="image/png" href="../../../static.files/favicon-16x16-8b506e7a72182f1c.png"><link rel="alternate icon" type="image/png" href="../../../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../../../static.files/favicon-2c020d218678b618.svg"></head><body class="rustdoc src"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"></nav><div class="sidebar-resizer"></div>
+ <main><nav class="sub"><form class="search-form"><span></span><input class="search-input" name="search" aria-label="Run search in the documentation" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" tabindex="-1"><a href="../../../help.html" title="help">?</a></div><div id="settings-menu" tabindex="-1"><a href="../../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../../static.files/wheel-7b819b6101059cd0.svg"></a></div></form></nav><section id="main-content" class="content"><div class="example-wrap"><div data-nosnippet><pre class="src-line-numbers"><a href="#1" id="1">1</a>
+<a href="#2" id="2">2</a>
+<a href="#3" id="3">3</a>
+<a href="#4" id="4">4</a>
+<a href="#5" id="5">5</a>
+<a href="#6" id="6">6</a>
+<a href="#7" id="7">7</a>
+<a href="#8" id="8">8</a>
+</pre></div><pre class="rust"><code><span class="kw">use </span><span class="kw">super</span>::Cmovz;
+<span class="kw">use crate</span>::{Asm, Reg64};
+
+<span class="kw">impl </span>Cmovz&lt;Reg64, Reg64&gt; <span class="kw">for </span>Asm {
+ <span class="kw">fn </span>cmovz(<span class="kw-2">&amp;mut </span><span class="self">self</span>, op1: Reg64, op2: Reg64) {
+ <span class="self">self</span>.encode_rr(<span class="kw-2">&amp;</span>[<span class="number">0x0f</span>, <span class="number">0x44</span>], op2, op1);
+ }
+}
+</code></pre></div></section></main></body></html> \ No newline at end of file
diff --git a/src/juicebox_asm/insn/mov.rs.html b/src/juicebox_asm/insn/mov.rs.html
index 6d6e6e7..8f10e31 100644
--- a/src/juicebox_asm/insn/mov.rs.html
+++ b/src/juicebox_asm/insn/mov.rs.html
@@ -120,25 +120,25 @@
</span><span class="kw">impl </span>Mov&lt;Reg64, Reg64&gt; <span class="kw">for </span>Asm {
<span class="kw">fn </span>mov(<span class="kw-2">&amp;mut </span><span class="self">self</span>, op1: Reg64, op2: Reg64) {
- <span class="self">self</span>.encode_rr(<span class="number">0x89</span>, op1, op2);
+ <span class="self">self</span>.encode_rr(<span class="kw-2">&amp;</span>[<span class="number">0x89</span>], op1, op2);
}
}
<span class="kw">impl </span>Mov&lt;Reg32, Reg32&gt; <span class="kw">for </span>Asm {
<span class="kw">fn </span>mov(<span class="kw-2">&amp;mut </span><span class="self">self</span>, op1: Reg32, op2: Reg32) {
- <span class="self">self</span>.encode_rr(<span class="number">0x89</span>, op1, op2);
+ <span class="self">self</span>.encode_rr(<span class="kw-2">&amp;</span>[<span class="number">0x89</span>], op1, op2);
}
}
<span class="kw">impl </span>Mov&lt;Reg16, Reg16&gt; <span class="kw">for </span>Asm {
<span class="kw">fn </span>mov(<span class="kw-2">&amp;mut </span><span class="self">self</span>, op1: Reg16, op2: Reg16) {
- <span class="self">self</span>.encode_rr(<span class="number">0x89</span>, op1, op2);
+ <span class="self">self</span>.encode_rr(<span class="kw-2">&amp;</span>[<span class="number">0x89</span>], op1, op2);
}
}
<span class="kw">impl </span>Mov&lt;Reg8, Reg8&gt; <span class="kw">for </span>Asm {
<span class="kw">fn </span>mov(<span class="kw-2">&amp;mut </span><span class="self">self</span>, op1: Reg8, op2: Reg8) {
- <span class="self">self</span>.encode_rr(<span class="number">0x88</span>, op1, op2);
+ <span class="self">self</span>.encode_rr(<span class="kw-2">&amp;</span>[<span class="number">0x88</span>], op1, op2);
}
}
diff --git a/src/juicebox_asm/insn/test.rs.html b/src/juicebox_asm/insn/test.rs.html
index 6a0372d..53a4e39 100644
--- a/src/juicebox_asm/insn/test.rs.html
+++ b/src/juicebox_asm/insn/test.rs.html
@@ -24,13 +24,13 @@
<span class="kw">impl </span>Test&lt;Reg64, Reg64&gt; <span class="kw">for </span>Asm {
<span class="kw">fn </span>test(<span class="kw-2">&amp;mut </span><span class="self">self</span>, op1: Reg64, op2: Reg64) {
- <span class="self">self</span>.encode_rr(<span class="number">0x85</span>, op1, op2);
+ <span class="self">self</span>.encode_rr(<span class="kw-2">&amp;</span>[<span class="number">0x85</span>], op1, op2);
}
}
<span class="kw">impl </span>Test&lt;Reg32, Reg32&gt; <span class="kw">for </span>Asm {
<span class="kw">fn </span>test(<span class="kw-2">&amp;mut </span><span class="self">self</span>, op1: Reg32, op2: Reg32) {
- <span class="self">self</span>.encode_rr(<span class="number">0x85</span>, op1, op2);
+ <span class="self">self</span>.encode_rr(<span class="kw-2">&amp;</span>[<span class="number">0x85</span>], op1, op2);
}
}
diff --git a/src/tiny_vm/tiny_vm.rs.html b/src/tiny_vm/tiny_vm.rs.html
index 938bc61..e8937f6 100644
--- a/src/tiny_vm/tiny_vm.rs.html
+++ b/src/tiny_vm/tiny_vm.rs.html
@@ -744,7 +744,7 @@
</span><span class="kw">use </span>juicebox_asm::insn::<span class="kw-2">*</span>;
<span class="kw">use </span>juicebox_asm::Runtime;
-<span class="kw">use </span>juicebox_asm::{Asm, Imm16, Imm64, Label, MemOp, Reg16, Reg64};
+<span class="kw">use </span>juicebox_asm::{Asm, Imm16, Imm64, MemOp, Reg16, Reg64};
<span class="doccomment">/// A guest physical address.
</span><span class="kw">pub struct </span>PhysAddr(<span class="kw">pub </span>u16);
@@ -1036,13 +1036,13 @@
TinyInsn::BranchZero(a, disp) =&gt; {
bb.cmp(reg_op(a), Imm16::from(<span class="number">0u16</span>));
bb.mov(Reg64::rax, Imm64::from(bb_icnt()));
- bb.mov(Reg64::rdx, Imm64::from(reenter_pc(disp)));
+ <span class="comment">// Default fall-through PC (branch not taken).
+ </span>bb.mov(Reg64::rdx, Imm64::from(reenter_pc(pc)));
+
+ <span class="comment">// Conditionally update PC if condition is ZERO (branch taken).
+ </span>bb.mov(Reg64::r11, Imm64::from(reenter_pc(disp)));
+ bb.cmovz(Reg64::rdx, Reg64::r11);
- <span class="kw">let </span><span class="kw-2">mut </span>skip_next_pc = Label::new();
- <span class="comment">// If register is zero, skip setting next pc as reenter pc.
- </span>bb.jz(<span class="kw-2">&amp;mut </span>skip_next_pc);
- bb.mov(Reg64::rdx, Imm64::from(reenter_pc(pc)));
- bb.bind(<span class="kw-2">&amp;mut </span>skip_next_pc);
bb.ret();
<span class="kw">break </span><span class="lifetime">'outer</span>;
}