<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" href="../style/style.css" />
<title>FSCALE: Scale (x86 Instruction Set Reference)</title>
</head>
<body>
<div class="main_container"><h1>x86 Instruction Set Reference</h1>
<title>FSCALE: Scale (x86 Instruction Set Reference)</title>
<h1>FSCALE</h1>
<h2>Scale</h2>
<object>
<table class="box">
<tr>
<th>Opcode</th>
<th>Mnemonic</th>
<th>Description</th>
</tr>
<tr>
<td class="grid"><code>D9 FD</code></td>
<td class="grid"><code>FSCALE</code></td>
<td class="grid">Scale ST(0) by ST(1).</td>
</tr>
</table>
</object>
<object>
<table class="box">
<tr>
<th>Description</th>
</tr>
<tr>
<td class="instruction_set_reference_box">
<p>Truncates the value in the source operand (toward 0) to an integral value and adds that value to the exponent of the destination operand. The destination and source operands are floating-point values located in registers ST(0) and ST(1), respectively. This instruction provides rapid multiplication or division by integral powers of 2. The following table shows the results obtained when scaling various classes of numbers, assuming that neither overflow nor underflow occurs.</p>
<div>
<table class="grid">
<caption>FSCALE Results</caption>
<tr><td>-</td><td>ST(1): -inf</td><td>ST(1): -F</td><td>ST(1): -0</td><td>ST(1): +0</td><td>ST(1): +F</td><td>ST(1): +inf</td><td>ST(1): NaN</td></tr>
<tr><td>ST(0): -inf</td><td>NaN</td><td>-inf</td><td>-inf</td><td>-inf</td><td>-inf</td><td>-inf</td><td>NaN</td></tr>
<tr><td>ST(0): -F</td><td>-0</td><td>-F</td><td>-F</td><td>-F</td><td>-F</td><td>-inf</td><td>NaN</td></tr>
<tr><td>ST(0): -0</td><td>-0</td><td>-0</td><td>-0</td><td>-0</td><td>-0</td><td>NaN</td><td>NaN</td></tr>
<tr><td>ST(0): +0</td><td>+0</td><td>+0</td><td>+0</td><td>+0</td><td>+0</td><td>NaN</td><td>NaN</td></tr>
<tr><td>ST(0): +F</td><td>+0</td><td>+F</td><td>+F</td><td>+F</td><td>+F</td><td>+inf</td><td>NaN</td></tr>
<tr><td>ST(0): +inf</td><td>NaN</td><td>+inf</td><td>+inf</td><td>+inf</td><td>+inf</td><td>+inf</td><td>NaN</td></tr>
<tr><td>ST(0): NaN</td><td>NaN</td><td>NaN</td><td>NaN</td><td>NaN</td><td>NaN</td><td>NaN</td><td>NaN</td></tr>
<tfoot>
<tr><td colspan="8">F Means finite floating-point value.</td></tr>
</tfoot>
</table>
</div>
<p>In most cases, only the exponent is changed and the mantissa remains unchanged.</p>
<p>However, when the value being scaled in ST(0) is a denormal value, the mantissa is also changed and the result may turn out to be a normalized number. Similarly, if overflow or underflow results from a scale operation, the resulting mantissa will differ from the source's mantissa.</p>
<p>The FSCALE instruction can also be used to reverse the action of the FXTRACT instruction, as shown in the following example: FXTRACT; FSCALE; FSTP ST(1); In this example, the FXTRACT instruction extracts the mantissa and exponent from the value in ST(0) and stores them in ST(0) and ST(1) respectively. The FSCALE then scales the mantissa in ST(0) by the exponent in ST(1), recreating the original value before the FXTRACT operation was performed. The FSTP ST(1) instruction overwrites the exponent (extracted by the FXTRACT instruction) with the recreated value, which returns the stack to its original state with only one register [ST(0)] occupied.</p>
</td>
</tr>
</table>
</object>
<object>
<table class="box">
<tr>
<th>Operation</th>
</tr>
<tr>
<td class="instruction_set_reference_box">
<pre>ST<span class="operator">(</span><span class="number">0</span><span class="operator">)</span> <span class="operator">=</span> ST<span class="operator">(</span><span class="number">0</span><span class="operator">)</span> <span class="operator">*</span> <span class="number">2</span>RoundTowardZero<span class="operator">(</span>ST<span class="operator">(</span><span class="number">1</span><span class="operator">)</span><span class="operator">)</span><span class="operator">;</span>
</pre>
</td>
</tr>
</table>
</object>
<object>
<table class="box">
<tr>
<th>FPU flags affected</th>
</tr>
<tr>
<td class="instruction_set_reference_box">
<p>C1 Set to 0 if stack underflow occurred.
Set if result was rounded up; cleared otherwise.
C0, C2, C3 Undefined.
</p>
</td>
</tr>
</table>
</object>
<object>
<table class="box">
<tr>
<th>Floating-Point Exceptions</th>
</tr>
<tr>
<td class="instruction_set_reference_box">
<div>
<table class="operations_table">
<tr><td><code>#IS</code></td><td>Stack underflow occurred.</td></tr>
<tr><td><code>#IS</code></td><td>Stack underflow occurred.</td></tr>
<tr><td><code>#IA</code></td><td>Source operand is an SNaN value or unsupported format.</td></tr>
<tr><td><code>#D</code></td><td>Source operand is a denormal value.</td></tr>
<tr><td><code>#U</code></td><td>Result is too small for destination format.</td></tr>
<tr><td><code>#O</code></td><td>Result is too large for destination format.</td></tr>
</table>
</div>
</td>
</tr>
</table>
</object>
<object>
<table class="box">
<tr>
<th>Protected Mode Exceptions</th>
</tr>
<tr>
<td class="instruction_set_reference_box">
<div>
<table class="operations_table">
<tr><td><code>#NM</code></td><td>EM or TS in CR0 is set.</td></tr>
</table>
</div>
</td>
</tr>
</table>
</object>
<object>
<table class="box">
<tr>
<th>Real-Address Mode Exceptions</th>
</tr>
<tr>
<td class="instruction_set_reference_box">
<div>
<table class="operations_table">
<tr><td><code>#NM</code></td><td>EM or TS in CR0 is set.</td></tr>
</table>
</div>
</td>
</tr>
</table>
</object>
<object>
<table class="box">
<tr>
<th>Virtual-8086 Mode Exceptions</th>
</tr>
<tr>
<td class="instruction_set_reference_box">
<div>
<table class="operations_table">
<tr><td><code>#NM</code></td><td>EM or TS in CR0 is set.</td></tr>
</table>
</div>
</td>
</tr>
</table>
</object>
<object>
<table class="box">
<tr>
<th>Instruction</th>
<th>Latency</th>
<th>Throughput</th>
<th>Execution Unit</th>
</tr>
<tr><td class="grid"><code>CPUID</code></td><td class="grid">0F3n/0F2n</td><td class="grid">0F3n/0F2n</td><td class="grid">0F2n</td></tr>
<tr><td class="grid"><code>FSCALE</code></td><td class="grid">60</td><td class="grid">7</td><td class="grid">-</td></tr>
</table>
</object>
</div>
</body>
</html>
