mozilla

Revision 100582 of LIR

  • Revision slug: Nanojit/LIR
  • Revision title: LIR
  • Revision id: 100582
  • Created:
  • Creator: Jorend
  • Is current revision? No
  • Comment page created, 806 words added

Revision Content

In Nanojit, LIR is the source language for compilation to machine code. LIR stands for low-level intermediate representation.

The LIR instruction set

The names of the operands and results below indicate the types required by LIR. Names starting with i indicate 32-bit integer values. (Signed and unsigned integers are not distinct types in LIR.) Results starting with b are also 32-bit integers but additionally are conditions. Operand names starting with b must be conditions. Names starting with q indicate 64-bit integer values. Names starting with f indicate 64-bit floating-point values. (A few instructions can operate on either 64-bit type. These cases are explicitly noted below.)

Special operations

start

nearskip

skip

neartramp

tramp

Operations that are weird but don't count as special

addp

param

file

line

alloc

Allocate stack space, as though with the C standard library function alloca.

Non-pure operations

st

32-bit store.

stq

64-bit store.

sti

32-bit store.

stqi

64-bit store.

ld

32-bit load. This instruction is never removed by common subexpression elimination.

ldq

64-bit load.

ldcb

8-bit load. This instruction may be removed by common subexpression elimination.

ldcs

16-bit load. This instruction may be removed by common subexpression elimination.

ldc

32-bit load. This instruction may be removed by common subexpression elimination.

ldqc

64-bit load. This instruction may be removed by common subexpression elimination.

live

Extend live range of reference.

calli

Indirect subroutine call returning a 32-bit integer value.

call

Subroutine call returning a 32-bit integer value.

callh

fcalli

Indirect subroutine call returning a 64-bit integer or floating point value.

fcall

Subroutine call returning a 64-bit integer or floating point value.

ret

fret

Branches

loop

Loop fragment.

x

Exit unconditionally.

xt

Exit if true.

xf

Exit if false.

xbarrier

Do not exit but emit writes to flush all values to the stack.

j

Jump unconditionally.

jt

Jump if true.

jf

Jump if false.

label

A jump target.

ji

Indirect jump.

Comparisons

eq

32-bit integer equality test.

result = eq i1, i2

There is no not-equal instruction. Instead, flip the instruction that uses the result, or add a not instruction.

lt

Signed 32-bit integer less-than test.

b = lt i1, i2

gt

Signed 32-bit integer greater-than test.

b = gt i1, i2

le

Signed 32-bit integer less-than-or-equals test.

b = le i1, i2

ge

Signed 32-bit integer greater-than-or-equals test.

b = ge i1, i2

ult

Unsigned 32-bit integer less-than test.

b = ult i1, i2

ugt

Unsigned 32-bit integer greater-than test.

b = ugt i1, i2

ule

Unsigned 32-bit integer less-than-or-equals test.

b = ule i1, i2

uge

Unsigned 32-bit integer greater-than-or-equals test.

b = uge i1, i2

feq

Floating-point equality test.

b = feq f1, f2

flt

Floating-point less-than test.

b = flt f1, f2

fgt

Floating-point greater-than test.

b = fgt f1, f2

fle

Floating-point less-than-or-equals test.

b = fle f1, f2

fge

Floating-point greater-than-or-equals test.

b = fge f1, f2

Constants

short

int

quad

Conditional moves

2

cmov

qcmov

Arithmetic

neg

32-bit integer negation.

result = neg i1

add

32-bit integer addition.

result = add i1, i2

qiadd

64-bit integer addition.

result = qiadd q1, q2

sub

32-bit integer subtraction.

result = sub i1, i2

mul

32-bit integer multiplication.

result = mul i1, i2

and

32-bit bitwise AND.

result = and i1, i2

qiand

64-bit bitwise AND.

result = qiand q1, q2

or

32-bit bitwise OR.

result = or i1, i2

qior

64-bit bitwise OR.

result = qior q1, q2

xor

32-bit bitwise XOR.

result = or i1, i2

not

32-bit bitwise NOT.

result = not i1

lsh

32-bit left shift.

result = lsh i1, i2

qilsh

64-bit left shift.

result = qilsh q1, q2

rsh

32-bit right shift with sign extend.

result = rsh i1, i2

The two most significant bits of the result value are the same.

ush

32-bit unsigned right shift.

result = ush i1, i2

The most significant bit of the result value is 0.

ov

result = ov i1

cs

result = cs i1

Floating-point arithmetic

fneg

Floating-point negation.

result = fneg f1

fadd

Floating-point addition.

result = fadd f1, f2

fsub

Floating-point subtraction.

result = fsub f1, f2

fmul

32-bit integer multiplication.

result = mul f1, f2

fdiv

Numeric conversions

qlo

Get the low 32 bits of a 64-bit value.

result = qlo q

qhi

Get the high 32 bits of a 64-bit value.

result = qhi q

qjoin

Join two 32-bit values to form a 64-bit value.

qresult = qjoin i1, i2

i2f

Convert signed 32-bit integer to floating-point number.

fresult = i2f i1

u2f

Convert unsigned 32-bit integer to floating-point number.

fresult = u2f i1

Revision Source

<p>In Nanojit, <strong>LIR</strong> is the source language for compilation to machine code. LIR stands for <em>low-level intermediate representation</em>.</p>
<h2>The LIR instruction set</h2>
<p>The names of the operands and results below indicate the types required by LIR. Names starting with <em>i</em> indicate 32-bit integer values. (Signed and unsigned integers are not distinct types in LIR.) Results starting with <em>b</em> are also 32-bit integers but additionally are conditions. Operand names starting with <em>b</em> must be conditions. Names starting with <em>q</em> indicate 64-bit integer values. Names starting with <em>f</em> indicate 64-bit floating-point values. (A few instructions can operate on either 64-bit type. These cases are explicitly noted below.)</p>
<h3>Special operations</h3>
<h4>start</h4>
<h4>nearskip</h4>
<h4>skip</h4>
<h4>neartramp</h4>
<h4>tramp</h4>
<h3>Operations that are weird but don't count as special</h3>
<h4>addp</h4>
<h4>param</h4>
<h4>file</h4>
<h4>line</h4>
<h4>alloc</h4>
<p>Allocate stack space, as though with the C standard library function <code>alloca</code>.</p>
<h3>Non-pure operations</h3>
<h4>st</h4>
<p>32-bit store.</p>
<h4>stq</h4>
<p>64-bit store.</p>
<h4>sti</h4>
<p>32-bit store.</p>
<h4>stqi</h4>
<p>64-bit store.</p>
<h4>ld</h4>
<p>32-bit load. This instruction is never removed by common subexpression elimination.</p>
<h4>ldq</h4>
<p>64-bit load.</p>
<h4>ldcb</h4>
<p>8-bit load. This instruction may be removed by common subexpression elimination.</p>
<h4>ldcs</h4>
<p>16-bit load. This instruction may be removed by common subexpression elimination.</p>
<h4>ldc</h4>
<p>32-bit load. This instruction may be removed by common subexpression elimination.</p>
<h4>ldqc</h4>
<p>64-bit load. This instruction may be removed by common subexpression elimination.</p>
<h4>live</h4>
<p>Extend live range of reference.</p>
<h4>calli</h4>
<p>Indirect subroutine call returning a 32-bit integer value.</p>
<h4>call</h4>
<p>Subroutine call returning a 32-bit integer value.</p>
<h4>callh</h4>
<h4>fcalli</h4>
<p>Indirect subroutine call returning a 64-bit integer or floating point value.</p>
<h4>fcall</h4>
<p>Subroutine call returning a 64-bit integer or floating point value.</p>
<h4>ret</h4>
<h4>fret</h4>
<h3>Branches</h3>
<h4>loop</h4>
<p>Loop fragment.</p>
<h4>x</h4>
<p>Exit unconditionally.</p>
<h4>xt</h4>
<p>Exit if true.</p>
<h4>xf</h4>
<p>Exit if false.</p>
<h4>xbarrier</h4>
<p>Do not exit but emit writes to flush all values to the stack.</p>
<h4>j</h4>
<p>Jump unconditionally.</p>
<h4>jt</h4>
<p>Jump if true.</p>
<h4>jf</h4>
<p>Jump if false.</p>
<h4>label</h4>
<p>A jump target.</p>
<h4>ji</h4>
<p>Indirect jump.</p>
<h3>Comparisons</h3>
<h4>eq</h4>
<p>32-bit integer equality test.</p>
<pre><var>result</var> = eq <var>i1</var>, <var>i2</var></pre>
<p>There is no not-equal instruction. Instead, flip the instruction that uses the result, or add a <code>not</code> instruction.</p>
<h4>lt</h4>
<p>Signed 32-bit integer less-than test.</p>
<pre><var>b</var> = lt <var>i1</var>, <var>i2</var></pre>
<h4>gt</h4>
<p>Signed 32-bit integer greater-than test.</p>
<pre><var>b</var> = gt <var>i1</var>, <var>i2</var></pre>
<h4>le</h4>
<p>Signed 32-bit integer less-than-or-equals test.</p>
<pre><var>b</var> = le <var>i1</var>, <var>i2</var></pre>
<h4>ge</h4>
<p>Signed 32-bit integer greater-than-or-equals test.</p>
<pre><var>b</var> = ge <var>i1</var>, <var>i2</var></pre>
<h4>ult</h4>
<p>Unsigned 32-bit integer less-than test.</p>
<pre><var>b</var> = ult <var>i1</var>, <var>i2</var></pre>
<h4>ugt</h4>
<p>Unsigned 32-bit integer greater-than test.</p>
<pre><var>b</var> = ugt <var>i1</var>, <var>i2</var></pre>
<h4>ule</h4>
<p>Unsigned 32-bit integer less-than-or-equals test.</p>
<pre><var>b</var> = ule <var>i1</var>, <var>i2</var></pre>
<h4>uge</h4>
<p>Unsigned 32-bit integer greater-than-or-equals test.</p>
<pre><var>b</var> = uge <var>i1</var>, <var>i2</var></pre>
<h4>feq</h4>
<p>Floating-point equality test.</p>
<pre><var>b</var> = feq <var>f1</var>, <var>f2</var></pre>
<h4>flt</h4>
<p>Floating-point less-than test.</p>
<pre><var>b</var> = flt <var>f1</var>, <var>f2</var></pre>
<h4>fgt</h4>
<p>Floating-point greater-than test.</p>
<pre><var>b</var> = fgt <var>f1</var>, <var>f2</var></pre>
<h4>fle</h4>
<p>Floating-point less-than-or-equals test.</p>
<pre><var>b</var> = fle <var>f1</var>, <var>f2</var></pre>
<h4>fge</h4>
<p>Floating-point greater-than-or-equals test.</p>
<pre><var>b</var> = fge <var>f1</var>, <var>f2</var></pre>
<h3>Constants</h3>
<h4>short</h4>
<h4>int</h4>
<h4>quad</h4>
<h3>Conditional moves</h3>
<h4>2</h4>
<h4>cmov</h4>
<h4>qcmov</h4>
<h3>Arithmetic</h3>
<h4>neg</h4>
<p>32-bit integer negation.</p>
<pre><var>result</var> = neg <var>i1</var></pre>
<h4>add</h4>
<p>32-bit integer addition.</p>
<pre><var>result</var> = add <var>i1</var>, <var>i2</var></pre>
<h4>qiadd</h4>
<p>64-bit integer addition.</p>
<pre><var>result</var> = qiadd <var>q1</var>, <var>q2</var></pre>
<h4>sub</h4>
<p>32-bit integer subtraction.</p>
<pre><var>result</var> = sub <var>i1</var>, <var>i2</var></pre>
<h4>mul</h4>
<p>32-bit integer multiplication.</p>
<pre><var>result</var> = mul <var>i1</var>, <var>i2</var></pre>
<h4>and</h4>
<p>32-bit bitwise AND.</p>
<pre><var>result</var> = and <var>i1</var>, <var>i2</var></pre>
<h4>qiand</h4>
<p>64-bit bitwise AND.</p>
<pre><var>result</var> = qiand <var>q1</var>, <var>q2</var></pre>
<h4>or</h4>
<p>32-bit bitwise OR.</p>
<pre><var>result</var> = or <var>i1</var>, <var>i2</var></pre>
<h4>qior</h4>
<p>64-bit bitwise OR.</p>
<pre><var>result</var> = qior <var>q1</var>, <var>q2</var></pre>
<h4>xor</h4>
<p>32-bit bitwise XOR.</p>
<pre><var>result</var> = or <var>i1</var>, <var>i2</var></pre>
<h4>not</h4>
<p>32-bit bitwise NOT.</p>
<pre><var>result</var> = not <var>i1</var></pre>
<h4>lsh</h4>
<p>32-bit left shift.</p>
<pre><var>result</var> = lsh <var>i1</var>, <var>i2</var></pre>
<h4>qilsh</h4>
<p>64-bit left shift.</p>
<pre><var>result</var> = qilsh <var>q1</var>, <var>q2</var></pre>
<h4>rsh</h4>
<p>32-bit right shift with sign extend.</p>
<pre><var>result</var> = rsh <var>i1</var>, <var>i2</var></pre>
<p>The two most significant bits of the result value are the same.</p>
<h4>ush</h4>
<p>32-bit unsigned right shift.</p>
<pre><var>result</var> = ush <var>i1</var>, <var>i2</var></pre>
<p>The most significant bit of the result value is 0.</p>
<h4>ov</h4>
<pre><var>result</var> = ov <var>i1</var></pre>
<h4>cs</h4>
<pre><var>result</var> = cs <var>i1</var></pre>
<h3>Floating-point arithmetic</h3>
<h4>fneg</h4>
<p>Floating-point negation.</p>
<pre><var>result</var> = fneg <var>f1</var></pre>
<h4>fadd</h4>
<p>Floating-point addition.</p>
<pre><var>result</var> = fadd <var>f1</var>, <var>f2</var></pre>
<h4>fsub</h4>
<p>Floating-point subtraction.</p>
<pre><var>result</var> = fsub <var>f1</var>, <var>f2</var></pre>
<h4>fmul</h4>
<p>32-bit integer multiplication.</p>
<pre><var>result</var> = mul <var>f1</var>, <var>f2</var></pre>
<h4>fdiv</h4>
<h3>Numeric conversions</h3>
<h4>qlo</h4>
<p>Get the low 32 bits of a 64-bit value.</p>
<pre><var>result</var> = qlo <var>q</var></pre>
<h4>qhi</h4>
<p>Get the high 32 bits of a 64-bit value.</p>
<pre><var>result</var> = qhi <var>q</var></pre>
<h4>qjoin</h4>
<p>Join two 32-bit values to form a 64-bit value.</p>
<pre><var>qresult</var> = qjoin <var>i1</var>, <var>i2</var></pre>
<h4>i2f</h4>
<p>Convert signed 32-bit integer to floating-point number.</p>
<pre><var>fresult</var> = i2f <var>i1</var></pre>
<h4>u2f</h4>
<p>Convert unsigned 32-bit integer to floating-point number.</p>
<pre><var>fresult</var> = u2f <var>i1</var></pre>
Revert to this revision