aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/juicebox_asm/lib.rs.html
diff options
context:
space:
mode:
authorjohannst <johannst@users.noreply.github.com>2023-12-05 22:08:06 +0000
committerjohannst <johannst@users.noreply.github.com>2023-12-05 22:08:06 +0000
commit2294180c3778d0fcfa877818e98c420fcd54bb8a (patch)
tree8240452d6b80d397f1b5a9425c1a986c20e710e5 /src/juicebox_asm/lib.rs.html
parente37c8e0f9319e3df3ff801f5a38f4717a8a20b28 (diff)
downloadjuicebox-asm-2294180c3778d0fcfa877818e98c420fcd54bb8a.tar.gz
juicebox-asm-2294180c3778d0fcfa877818e98c420fcd54bb8a.zip
deploy: 7e98f5def5942969f97f5f015e7fb8417793d132
Diffstat (limited to 'src/juicebox_asm/lib.rs.html')
-rw-r--r--src/juicebox_asm/lib.rs.html124
1 files changed, 121 insertions, 3 deletions
diff --git a/src/juicebox_asm/lib.rs.html b/src/juicebox_asm/lib.rs.html
index 4d6d4fe..83c8f81 100644
--- a/src/juicebox_asm/lib.rs.html
+++ b/src/juicebox_asm/lib.rs.html
@@ -1,4 +1,4 @@
-<!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/lib.rs`."><title>lib.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/SourceSerif4-Bold-a2c9cd1067f8b328.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-cb6f1f67f1bcd037.css" id="mainThemeStyle"><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.73.0 (cc66ad468 2023-10-03)" data-channel="1.73.0" data-search-js="search-6dfdfced5eff6596.js" data-settings-js="settings-de11bff964e9d4e5.js" data-settings-css="settings-8c76f75bfb6bd192.css" data-theme-light-css="light-1596385f77d47ef2.css" data-theme-dark-css="dark-0a43001d3fc2282c.css" data-theme-ayu-css="ayu-fd19013d6ce078bf.css" ><script src="../../static.files/storage-db41da1a38ea3cb8.js"></script><script defer src="../../static.files/src-script-3280b574d94e47b4.js"></script><script defer src="../../src-files.js"></script><script defer src="../../static.files/main-0795b7d26be81095.js"></script><noscript><link rel="stylesheet" media="(prefers-color-scheme:light)" href="../../static.files/light-1596385f77d47ef2.css"><link rel="stylesheet" media="(prefers-color-scheme:dark)" href="../../static.files/dark-0a43001d3fc2282c.css"><link rel="stylesheet" href="../../static.files/noscript-cffde32267a19fd6.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><main><nav class="sub"><a class="sub-logo-container" href="../../juicebox_asm/index.html"><img class="rust-logo" src="../../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><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" title="help" tabindex="-1"><a href="../../help.html">?</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>
+<!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/lib.rs`."><title>lib.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/SourceSerif4-Bold-a2c9cd1067f8b328.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-fa3bb1812debf86c.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.74.0 (79e9716c9 2023-11-13)" data-channel="1.74.0" data-search-js="search-8be46b629f5f14a8.js" data-settings-js="settings-74424d7eec62a23e.js" ><script src="../../static.files/storage-fec3eaa3851e447d.js"></script><script defer src="../../static.files/src-script-3280b574d94e47b4.js"></script><script defer src="../../src-files.js"></script><script defer src="../../static.files/main-c5bd66d33317d69f.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-5d8b3c7633ad77ba.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><main><nav class="sub"><a class="sub-logo-container" href="../../juicebox_asm/index.html"><img class="rust-logo" src="../../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><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" title="help" tabindex="-1"><a href="../../help.html">?</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>
@@ -408,6 +408,65 @@
<a href="#408" id="408">408</a>
<a href="#409" id="409">409</a>
<a href="#410" id="410">410</a>
+<a href="#411" id="411">411</a>
+<a href="#412" id="412">412</a>
+<a href="#413" id="413">413</a>
+<a href="#414" id="414">414</a>
+<a href="#415" id="415">415</a>
+<a href="#416" id="416">416</a>
+<a href="#417" id="417">417</a>
+<a href="#418" id="418">418</a>
+<a href="#419" id="419">419</a>
+<a href="#420" id="420">420</a>
+<a href="#421" id="421">421</a>
+<a href="#422" id="422">422</a>
+<a href="#423" id="423">423</a>
+<a href="#424" id="424">424</a>
+<a href="#425" id="425">425</a>
+<a href="#426" id="426">426</a>
+<a href="#427" id="427">427</a>
+<a href="#428" id="428">428</a>
+<a href="#429" id="429">429</a>
+<a href="#430" id="430">430</a>
+<a href="#431" id="431">431</a>
+<a href="#432" id="432">432</a>
+<a href="#433" id="433">433</a>
+<a href="#434" id="434">434</a>
+<a href="#435" id="435">435</a>
+<a href="#436" id="436">436</a>
+<a href="#437" id="437">437</a>
+<a href="#438" id="438">438</a>
+<a href="#439" id="439">439</a>
+<a href="#440" id="440">440</a>
+<a href="#441" id="441">441</a>
+<a href="#442" id="442">442</a>
+<a href="#443" id="443">443</a>
+<a href="#444" id="444">444</a>
+<a href="#445" id="445">445</a>
+<a href="#446" id="446">446</a>
+<a href="#447" id="447">447</a>
+<a href="#448" id="448">448</a>
+<a href="#449" id="449">449</a>
+<a href="#450" id="450">450</a>
+<a href="#451" id="451">451</a>
+<a href="#452" id="452">452</a>
+<a href="#453" id="453">453</a>
+<a href="#454" id="454">454</a>
+<a href="#455" id="455">455</a>
+<a href="#456" id="456">456</a>
+<a href="#457" id="457">457</a>
+<a href="#458" id="458">458</a>
+<a href="#459" id="459">459</a>
+<a href="#460" id="460">460</a>
+<a href="#461" id="461">461</a>
+<a href="#462" id="462">462</a>
+<a href="#463" id="463">463</a>
+<a href="#464" id="464">464</a>
+<a href="#465" id="465">465</a>
+<a href="#466" id="466">466</a>
+<a href="#467" id="467">467</a>
+<a href="#468" id="468">468</a>
+<a href="#469" id="469">469</a>
</pre></div><pre class="rust"><code><span class="doccomment">//! A simple `x64` jit assembler with a minimal runtime to execute emitted code for fun.
//!
//! The following is an fibonacci example implementation.
@@ -471,8 +530,8 @@
//! asm.ret();
//!
//! // Move code into executable page and get function pointer to it.
-//! let rt = Runtime::new(&amp;asm.into_code());
-//! let fib = unsafe { rt.as_fn::&lt;extern &quot;C&quot; fn(u64) -&gt; u64&gt;() };
+//! let mut rt = Runtime::new();
+//! let fib = unsafe { rt.add_code::&lt;extern &quot;C&quot; fn(u64) -&gt; u64&gt;(&amp;asm.into_code()) };
//!
//! for n in 0..15 {
//! let fib_jit = fib(n);
@@ -683,6 +742,42 @@
<span class="self">self</span>.emit(<span class="kw-2">&amp;</span>[opc, modrm]);
}
+ <span class="doccomment">/// Encode a memory-immediate instruction.
+ </span><span class="kw">fn </span>encode_mi&lt;T: Imm&gt;(<span class="kw-2">&amp;mut </span><span class="self">self</span>, opc: u8, opc_ext: u8, op1: MemOp, op2: T)
+ <span class="kw">where
+ </span><span class="self">Self</span>: EncodeMI&lt;T&gt;,
+ {
+ <span class="comment">// MI operand encoding.
+ // op1 -&gt; modrm.rm
+ // op2 -&gt; imm
+ </span><span class="kw">let </span>mode = <span class="kw">match </span>op1 {
+ MemOp::Indirect(..) =&gt; {
+ <span class="macro">assert!</span>(!op1.base().need_sib() &amp;&amp; !op1.base().is_pc_rel());
+ <span class="number">0b00
+ </span>}
+ MemOp::IndirectDisp(..) =&gt; {
+ <span class="macro">assert!</span>(!op1.base().need_sib());
+ <span class="number">0b10
+ </span>}
+ };
+
+ <span class="kw">let </span>modrm = modrm(
+ mode, <span class="comment">/* mode */
+ </span>opc_ext, <span class="comment">/* reg */
+ </span>op1.base().idx(), <span class="comment">/* rm */
+ </span>);
+
+ <span class="kw">let </span>prefix = &lt;<span class="self">Self </span><span class="kw">as </span>EncodeMI&lt;T&gt;&gt;::legacy_prefix();
+ <span class="kw">let </span>rex = &lt;<span class="self">Self </span><span class="kw">as </span>EncodeMI&lt;T&gt;&gt;::rex(<span class="kw-2">&amp;</span>op1);
+
+ <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="kw">if let </span>MemOp::IndirectDisp(<span class="kw">_</span>, disp) = op1 {
+ <span class="self">self</span>.emit(<span class="kw-2">&amp;</span>disp.to_ne_bytes());
+ }
+ <span class="self">self</span>.emit(op2.bytes());
+ }
+
<span class="doccomment">/// Encode a memory-register instruction.
</span><span class="kw">fn </span>encode_mr&lt;T: Reg&gt;(<span class="kw-2">&amp;mut </span><span class="self">self</span>, opc: u8, op1: MemOp, op2: T)
<span class="kw">where
@@ -818,4 +913,27 @@
}
<span class="kw">impl </span>EncodeMR&lt;Reg32&gt; <span class="kw">for </span>Asm {}
<span class="kw">impl </span>EncodeMR&lt;Reg64&gt; <span class="kw">for </span>Asm {}
+
+<span class="doccomment">/// Encode helper for memory-immediate instructions.
+</span><span class="kw">trait </span>EncodeMI&lt;T: Imm&gt; {
+ <span class="kw">fn </span>legacy_prefix() -&gt; <span class="prelude-ty">Option</span>&lt;u8&gt; {
+ <span class="prelude-val">None
+ </span>}
+
+ <span class="kw">fn </span>rex(op1: <span class="kw-2">&amp;</span>MemOp) -&gt; <span class="prelude-ty">Option</span>&lt;u8&gt; {
+ <span class="kw">if </span>op1.base().is_ext() {
+ <span class="prelude-val">Some</span>(rex(<span class="bool-val">false</span>, <span class="number">0</span>, <span class="number">0</span>, op1.base().idx()))
+ } <span class="kw">else </span>{
+ <span class="prelude-val">None
+ </span>}
+ }
+}
+
+<span class="kw">impl </span>EncodeMI&lt;Imm8&gt; <span class="kw">for </span>Asm {}
+<span class="kw">impl </span>EncodeMI&lt;Imm16&gt; <span class="kw">for </span>Asm {
+ <span class="kw">fn </span>legacy_prefix() -&gt; <span class="prelude-ty">Option</span>&lt;u8&gt; {
+ <span class="prelude-val">Some</span>(<span class="number">0x66</span>)
+ }
+}
+<span class="kw">impl </span>EncodeMI&lt;Imm32&gt; <span class="kw">for </span>Asm {}
</code></pre></div></section></main></body></html> \ No newline at end of file