1 page.title=Bytecode for the Dalvik VM 2 @jd:body 3 4 <!-- 5 Copyright 2013 The Android Open Source Project 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18 --> 19 <h2>General Design</h2> 20 21 <ul> 22 <li>The machine model and calling conventions are meant to approximately 23 imitate common real architectures and C-style calling conventions: 24 <ul> 25 <li>The VM is register-based, and frames are fixed in size upon creation. 26 Each frame consists of a particular number of registers (specified by 27 the method) as well as any adjunct data needed to execute the method, 28 such as (but not limited to) the program counter and a reference to the 29 <code>.dex</code> file that contains the method. 30 </li> 31 <li>When used for bit values (such as integers and floating point 32 numbers), registers are considered 32 bits wide. Adjacent register 33 pairs are used for 64-bit values. There is no alignment requirement 34 for register pairs. 35 </li> 36 <li>When used for object references, registers are considered wide enough 37 to hold exactly one such reference. 38 </li> 39 <li>In terms of bitwise representation, <code>(Object) null == (int) 40 0</code>. 41 </li> 42 <li>The <i>N</i> arguments to a method land in the last <i>N</i> registers 43 of the method's invocation frame, in order. Wide arguments consume 44 two registers. Instance methods are passed a <code>this</code> reference 45 as their first argument. 46 </li> 47 </ul> 48 <li>The storage unit in the instruction stream is a 16-bit unsigned quantity. 49 Some bits in some instructions are ignored / must-be-zero. 50 </li> 51 <li>Instructions aren't gratuitously limited to a particular type. For 52 example, instructions that move 32-bit register values without interpretation 53 don't have to specify whether they are moving ints or floats. 54 </li> 55 <li>There are separately enumerated and indexed constant pools for 56 references to strings, types, fields, and methods. 57 </li> 58 <li>Bitwise literal data is represented in-line in the instruction stream.</li> 59 <li>Because, in practice, it is uncommon for a method to need more than 60 16 registers, and because needing more than eight registers <i>is</i> 61 reasonably common, many instructions are limited to only addressing 62 the first 16 63 registers. When reasonably possible, instructions allow references to 64 up to the first 256 registers. In addition, some instructions have variants 65 that allow for much larger register counts, including a pair of catch-all 66 <code>move</code> instructions that can address registers in the range 67 <code>v0</code> – <code>v65535</code>. 68 In cases where an instruction variant isn't 69 available to address a desired register, it is expected that the register 70 contents get moved from the original register to a low register (before the 71 operation) and/or moved from a low result register to a high register 72 (after the operation). 73 </li> 74 <li>There are several "pseudo-instructions" that are used to hold 75 variable-length data payloads, which are referred to by regular 76 instructions (for example, 77 <code>fill-array-data</code>). Such instructions must never be 78 encountered during the normal flow of execution. In addition, the 79 instructions must be located on even-numbered bytecode offsets (that is, 80 4-byte aligned). In order to meet this requirement, dex generation tools 81 must emit an extra <code>nop</code> instruction as a spacer if such an 82 instruction would otherwise be unaligned. Finally, though not required, 83 it is expected that most tools will choose to emit these instructions at 84 the ends of methods, since otherwise it would likely be the case that 85 additional instructions would be needed to branch around them. 86 </li> 87 <li>When installed on a running system, some instructions may be altered, 88 changing their format, as an install-time static linking optimization. 89 This is to allow for faster execution once linkage is known. 90 See the associated 91 <a href="instruction-formats.html">instruction formats document</a> 92 for the suggested variants. The word "suggested" is used advisedly; 93 it is not mandatory to implement these. 94 </li> 95 <li>Human-syntax and mnemonics: 96 <ul> 97 <li>Dest-then-source ordering for arguments.</li> 98 <li>Some opcodes have a disambiguating name suffix to indicate the type(s) 99 they operate on: 100 <ul> 101 <li>Type-general 32-bit opcodes are unmarked.</li> 102 <li>Type-general 64-bit opcodes are suffixed with <code>-wide</code>.</li> 103 <li>Type-specific opcodes are suffixed with their type (or a 104 straightforward abbreviation), one of: <code>-boolean</code> 105 <code>-byte</code> <code>-char</code> <code>-short</code> 106 <code>-int</code> <code>-long</code> <code>-float</code> 107 <code>-double</code> <code>-object</code> <code>-string</code> 108 <code>-class</code> <code>-void</code>.</li> 109 </ul> 110 </li> 111 <li>Some opcodes have a disambiguating suffix to distinguish 112 otherwise-identical operations that have different instruction layouts 113 or options. These suffixes are separated from the main names with a slash 114 ("<code>/</code>") and mainly exist at all to make there be a one-to-one 115 mapping with static constants in the code that generates and interprets 116 executables (that is, to reduce ambiguity for humans). 117 </li> 118 <li>In the descriptions here, the width of a value (indicating, e.g., the 119 range of a constant or the number of registers possibly addressed) is 120 emphasized by the use of a character per four bits of width. 121 </li> 122 <li>For example, in the instruction 123 "<code>move-wide/from16 vAA, vBBBB</code>": 124 <ul> 125 <li>"<code>move</code>" is the base opcode, indicating the base operation 126 (move a register's value).</li> 127 <li>"<code>wide</code>" is the name suffix, indicating that it operates 128 on wide (64 bit) data.</li> 129 <li>"<code>from16</code>" is the opcode suffix, indicating a variant 130 that has a 16-bit register reference as a source.</li> 131 <li>"<code>vAA</code>" is the destination register (implied by the 132 operation; again, the rule is that destination arguments always come 133 first), which must be in the range <code>v0</code> – 134 <code>v255</code>.</li> 135 <li>"<code>vBBBB</code>" is the source register, which must be in the 136 range <code>v0</code> – <code>v65535</code>.</li> 137 </ul> 138 </li> 139 </ul> 140 </li> 141 <li>See the <a href="instruction-formats.html">instruction formats 142 document</a> for more details about the various instruction formats 143 (listed under "Op & Format") as well as details about the opcode 144 syntax. 145 </li> 146 <li>See the <a href="dex-format.html"><code>.dex</code> file format 147 document</a> for more details about where the bytecode fits into 148 the bigger picture. 149 </li> 150 </ul> 151 152 <h2>Summary of Instruction Set</h2> 153 154 <table class="instruc"> 155 <thead> 156 <tr> 157 <th>Op & Format</th> 158 <th>Mnemonic / Syntax</th> 159 <th>Arguments</th> 160 <th>Description</th> 161 </tr> 162 </thead> 163 <tbody> 164 <tr> 165 <td>00 10x</td> 166 <td>nop</td> 167 <td> </td> 168 <td>Waste cycles. 169 <p><b>Note:</b> 170 Data-bearing pseudo-instructions are tagged with this opcode, in which 171 case the high-order byte of the opcode unit indicates the nature of 172 the data. See "<code>packed-switch-payload</code> Format", 173 "<code>sparse-switch-payload</code> Format", and 174 "<code>fill-array-data-payload</code> Format" below.</p> 175 </td> 176 </tr> 177 <tr> 178 <td>01 12x</td> 179 <td>move vA, vB</td> 180 <td><code>A:</code> destination register (4 bits)<br/> 181 <code>B:</code> source register (4 bits)</td> 182 <td>Move the contents of one non-object register to another.</td> 183 </tr> 184 <tr> 185 <td>02 22x</td> 186 <td>move/from16 vAA, vBBBB</td> 187 <td><code>A:</code> destination register (8 bits)<br/> 188 <code>B:</code> source register (16 bits)</td> 189 <td>Move the contents of one non-object register to another.</td> 190 </tr> 191 <tr> 192 <td>03 32x</td> 193 <td>move/16 vAAAA, vBBBB</td> 194 <td><code>A:</code> destination register (16 bits)<br/> 195 <code>B:</code> source register (16 bits)</td> 196 <td>Move the contents of one non-object register to another.</td> 197 </tr> 198 <tr> 199 <td>04 12x</td> 200 <td>move-wide vA, vB</td> 201 <td><code>A:</code> destination register pair (4 bits)<br/> 202 <code>B:</code> source register pair (4 bits)</td> 203 <td>Move the contents of one register-pair to another. 204 <p><b>Note:</b> 205 It is legal to move from <code>v<i>N</i></code> to either 206 <code>v<i>N-1</i></code> or <code>v<i>N+1</i></code>, so implementations 207 must arrange for both halves of a register pair to be read before 208 anything is written.</p> 209 </td> 210 </tr> 211 <tr> 212 <td>05 22x</td> 213 <td>move-wide/from16 vAA, vBBBB</td> 214 <td><code>A:</code> destination register pair (8 bits)<br/> 215 <code>B:</code> source register pair (16 bits)</td> 216 <td>Move the contents of one register-pair to another. 217 <p><b>Note:</b> 218 Implementation considerations are the same as <code>move-wide</code>, 219 above.</p> 220 </td> 221 </tr> 222 <tr> 223 <td>06 32x</td> 224 <td>move-wide/16 vAAAA, vBBBB</td> 225 <td><code>A:</code> destination register pair (16 bits)<br/> 226 <code>B:</code> source register pair (16 bits)</td> 227 <td>Move the contents of one register-pair to another. 228 <p><b>Note:</b> 229 Implementation considerations are the same as <code>move-wide</code>, 230 above.</p> 231 </td> 232 </tr> 233 <tr> 234 <td>07 12x</td> 235 <td>move-object vA, vB</td> 236 <td><code>A:</code> destination register (4 bits)<br/> 237 <code>B:</code> source register (4 bits)</td> 238 <td>Move the contents of one object-bearing register to another.</td> 239 </tr> 240 <tr> 241 <td>08 22x</td> 242 <td>move-object/from16 vAA, vBBBB</td> 243 <td><code>A:</code> destination register (8 bits)<br/> 244 <code>B:</code> source register (16 bits)</td> 245 <td>Move the contents of one object-bearing register to another.</td> 246 </tr> 247 <tr> 248 <td>09 32x</td> 249 <td>move-object/16 vAAAA, vBBBB</td> 250 <td><code>A:</code> destination register (16 bits)<br/> 251 <code>B:</code> source register (16 bits)</td> 252 <td>Move the contents of one object-bearing register to another.</td> 253 </tr> 254 <tr> 255 <td>0a 11x</td> 256 <td>move-result vAA</td> 257 <td><code>A:</code> destination register (8 bits)</td> 258 <td>Move the single-word non-object result of the most recent 259 <code>invoke-<i>kind</i></code> into the indicated register. 260 This must be done as the instruction immediately after an 261 <code>invoke-<i>kind</i></code> whose (single-word, non-object) result 262 is not to be ignored; anywhere else is invalid.</td> 263 </tr> 264 <tr> 265 <td>0b 11x</td> 266 <td>move-result-wide vAA</td> 267 <td><code>A:</code> destination register pair (8 bits)</td> 268 <td>Move the double-word result of the most recent 269 <code>invoke-<i>kind</i></code> into the indicated register pair. 270 This must be done as the instruction immediately after an 271 <code>invoke-<i>kind</i></code> whose (double-word) result 272 is not to be ignored; anywhere else is invalid.</td> 273 </tr> 274 <tr> 275 <td>0c 11x</td> 276 <td>move-result-object vAA</td> 277 <td><code>A:</code> destination register (8 bits)</td> 278 <td>Move the object result of the most recent <code>invoke-<i>kind</i></code> 279 into the indicated register. This must be done as the instruction 280 immediately after an <code>invoke-<i>kind</i></code> or 281 <code>filled-new-array</code> 282 whose (object) result is not to be ignored; anywhere else is invalid.</td> 283 </tr> 284 <tr> 285 <td>0d 11x</td> 286 <td>move-exception vAA</td> 287 <td><code>A:</code> destination register (8 bits)</td> 288 <td>Save a just-caught exception into the given register. This must 289 be the first instruction of any exception handler whose caught 290 exception is not to be ignored, and this instruction must <i>only</i> 291 ever occur as the first instruction of an exception handler; anywhere 292 else is invalid.</td> 293 </tr> 294 <tr> 295 <td>0e 10x</td> 296 <td>return-void</td> 297 <td> </td> 298 <td>Return from a <code>void</code> method.</td> 299 </tr> 300 <tr> 301 <td>0f 11x</td> 302 <td>return vAA</td> 303 <td><code>A:</code> return value register (8 bits)</td> 304 <td>Return from a single-width (32-bit) non-object value-returning 305 method. 306 </td> 307 </tr> 308 <tr> 309 <td>10 11x</td> 310 <td>return-wide vAA</td> 311 <td><code>A:</code> return value register-pair (8 bits)</td> 312 <td>Return from a double-width (64-bit) value-returning method.</td> 313 </tr> 314 <tr> 315 <td>11 11x</td> 316 <td>return-object vAA</td> 317 <td><code>A:</code> return value register (8 bits)</td> 318 <td>Return from an object-returning method.</td> 319 </tr> 320 <tr> 321 <td>12 11n</td> 322 <td>const/4 vA, #+B</td> 323 <td><code>A:</code> destination register (4 bits)<br/> 324 <code>B:</code> signed int (4 bits)</td> 325 <td>Move the given literal value (sign-extended to 32 bits) into 326 the specified register.</td> 327 </tr> 328 <tr> 329 <td>13 21s</td> 330 <td>const/16 vAA, #+BBBB</td> 331 <td><code>A:</code> destination register (8 bits)<br/> 332 <code>B:</code> signed int (16 bits)</td> 333 <td>Move the given literal value (sign-extended to 32 bits) into 334 the specified register.</td> 335 </tr> 336 <tr> 337 <td>14 31i</td> 338 <td>const vAA, #+BBBBBBBB</td> 339 <td><code>A:</code> destination register (8 bits)<br/> 340 <code>B:</code> arbitrary 32-bit constant</td> 341 <td>Move the given literal value into the specified register.</td> 342 </tr> 343 <tr> 344 <td>15 21h</td> 345 <td>const/high16 vAA, #+BBBB0000</td> 346 <td><code>A:</code> destination register (8 bits)<br/> 347 <code>B:</code> signed int (16 bits)</td> 348 <td>Move the given literal value (right-zero-extended to 32 bits) into 349 the specified register.</td> 350 </tr> 351 <tr> 352 <td>16 21s</td> 353 <td>const-wide/16 vAA, #+BBBB</td> 354 <td><code>A:</code> destination register (8 bits)<br/> 355 <code>B:</code> signed int (16 bits)</td> 356 <td>Move the given literal value (sign-extended to 64 bits) into 357 the specified register-pair.</td> 358 </tr> 359 <tr> 360 <td>17 31i</td> 361 <td>const-wide/32 vAA, #+BBBBBBBB</td> 362 <td><code>A:</code> destination register (8 bits)<br/> 363 <code>B:</code> signed int (32 bits)</td> 364 <td>Move the given literal value (sign-extended to 64 bits) into 365 the specified register-pair.</td> 366 </tr> 367 <tr> 368 <td>18 51l</td> 369 <td>const-wide vAA, #+BBBBBBBBBBBBBBBB</td> 370 <td><code>A:</code> destination register (8 bits)<br/> 371 <code>B:</code> arbitrary double-width (64-bit) constant</td> 372 <td>Move the given literal value into 373 the specified register-pair.</td> 374 </tr> 375 <tr> 376 <td>19 21h</td> 377 <td>const-wide/high16 vAA, #+BBBB000000000000</td> 378 <td><code>A:</code> destination register (8 bits)<br/> 379 <code>B:</code> signed int (16 bits)</td> 380 <td>Move the given literal value (right-zero-extended to 64 bits) into 381 the specified register-pair.</td> 382 </tr> 383 <tr> 384 <td>1a 21c</td> 385 <td>const-string vAA, string@BBBB</td> 386 <td><code>A:</code> destination register (8 bits)<br/> 387 <code>B:</code> string index</td> 388 <td>Move a reference to the string specified by the given index into the 389 specified register.</td> 390 </tr> 391 <tr> 392 <td>1b 31c</td> 393 <td>const-string/jumbo vAA, string@BBBBBBBB</td> 394 <td><code>A:</code> destination register (8 bits)<br/> 395 <code>B:</code> string index</td> 396 <td>Move a reference to the string specified by the given index into the 397 specified register.</td> 398 </tr> 399 <tr> 400 <td>1c 21c</td> 401 <td>const-class vAA, type@BBBB</td> 402 <td><code>A:</code> destination register (8 bits)<br/> 403 <code>B:</code> type index</td> 404 <td>Move a reference to the class specified by the given index into the 405 specified register. In the case where the indicated type is primitive, 406 this will store a reference to the primitive type's degenerate 407 class.</td> 408 </tr> 409 <tr> 410 <td>1d 11x</td> 411 <td>monitor-enter vAA</td> 412 <td><code>A:</code> reference-bearing register (8 bits)</td> 413 <td>Acquire the monitor for the indicated object.</td> 414 </tr> 415 <tr> 416 <td>1e 11x</td> 417 <td>monitor-exit vAA</td> 418 <td><code>A:</code> reference-bearing register (8 bits)</td> 419 <td>Release the monitor for the indicated object. 420 <p><b>Note:</b> 421 If this instruction needs to throw an exception, it must do 422 so as if the pc has already advanced past the instruction. 423 It may be useful to think of this as the instruction successfully 424 executing (in a sense), and the exception getting thrown <i>after</i> 425 the instruction but <i>before</i> the next one gets a chance to 426 run. This definition makes it possible for a method to use 427 a monitor cleanup catch-all (e.g., <code>finally</code>) block as 428 the monitor cleanup for that block itself, as a way to handle the 429 arbitrary exceptions that might get thrown due to the historical 430 implementation of <code>Thread.stop()</code>, while still managing 431 to have proper monitor hygiene.</p> 432 </td> 433 </tr> 434 <tr> 435 <td>1f 21c</td> 436 <td>check-cast vAA, type@BBBB</td> 437 <td><code>A:</code> reference-bearing register (8 bits)<br/> 438 <code>B:</code> type index (16 bits)</td> 439 <td>Throw a <code>ClassCastException</code> if the reference in the 440 given register cannot be cast to the indicated type. 441 <p><b>Note:</b> Since <code>A</code> must always be a reference 442 (and not a primitive value), this will necessarily fail at runtime 443 (that is, it will throw an exception) if <code>B</code> refers to a 444 primitive type.</p> 445 </td> 446 </tr> 447 <tr> 448 <td>20 22c</td> 449 <td>instance-of vA, vB, type@CCCC</td> 450 <td><code>A:</code> destination register (4 bits)<br/> 451 <code>B:</code> reference-bearing register (4 bits)<br/> 452 <code>C:</code> type index (16 bits)</td> 453 <td>Store in the given destination register <code>1</code> 454 if the indicated reference is an instance of the given type, 455 or <code>0</code> if not. 456 <p><b>Note:</b> Since <code>B</code> must always be a reference 457 (and not a primitive value), this will always result 458 in <code>0</code> being stored if <code>C</code> refers to a primitive 459 type.</td> 460 </tr> 461 <tr> 462 <td>21 12x</td> 463 <td>array-length vA, vB</td> 464 <td><code>A:</code> destination register (4 bits)<br/> 465 <code>B:</code> array reference-bearing register (4 bits)</td> 466 <td>Store in the given destination register the length of the indicated 467 array, in entries</td> 468 </tr> 469 <tr> 470 <td>22 21c</td> 471 <td>new-instance vAA, type@BBBB</td> 472 <td><code>A:</code> destination register (8 bits)<br/> 473 <code>B:</code> type index</td> 474 <td>Construct a new instance of the indicated type, storing a 475 reference to it in the destination. The type must refer to a 476 non-array class.</td> 477 </tr> 478 <tr> 479 <td>23 22c</td> 480 <td>new-array vA, vB, type@CCCC</td> 481 <td><code>A:</code> destination register (8 bits)<br/> 482 <code>B:</code> size register<br/> 483 <code>C:</code> type index</td> 484 <td>Construct a new array of the indicated type and size. The type 485 must be an array type.</td> 486 </tr> 487 <tr> 488 <td>24 35c</td> 489 <td>filled-new-array {vC, vD, vE, vF, vG}, type@BBBB</td> 490 <td> 491 <code>A:</code> array size and argument word count (4 bits)<br/> 492 <code>B:</code> type index (16 bits)<br/> 493 <code>C..G:</code> argument registers (4 bits each) 494 </td> 495 <td>Construct an array of the given type and size, filling it with the 496 supplied contents. The type must be an array type. The array's 497 contents must be single-word (that is, 498 no arrays of <code>long</code> or <code>double</code>, but reference 499 types are acceptable). The constructed 500 instance is stored as a "result" in the same way that the method invocation 501 instructions store their results, so the constructed instance must 502 be moved to a register with an immediately subsequent 503 <code>move-result-object</code> instruction (if it is to be used).</td> 504 </tr> 505 <tr> 506 <td>25 3rc</td> 507 <td>filled-new-array/range {vCCCC .. vNNNN}, type@BBBB</td> 508 <td><code>A:</code> array size and argument word count (8 bits)<br/> 509 <code>B:</code> type index (16 bits)<br/> 510 <code>C:</code> first argument register (16 bits)<br/> 511 <code>N = A + C - 1</code></td> 512 <td>Construct an array of the given type and size, filling it with 513 the supplied contents. Clarifications and restrictions are the same 514 as <code>filled-new-array</code>, described above.</td> 515 </tr> 516 <tr> 517 <td>26 31t</td> 518 <td>fill-array-data vAA, +BBBBBBBB <i>(with supplemental data as specified 519 below in "<code>fill-array-data-payload</code> Format")</i></td> 520 <td><code>A:</code> array reference (8 bits)<br/> 521 <code>B:</code> signed "branch" offset to table data pseudo-instruction 522 (32 bits) 523 </td> 524 <td>Fill the given array with the indicated data. The reference must be 525 to an array of primitives, and the data table must match it in type and 526 must contain no more elements than will fit in the array. That is, 527 the array may be larger than the table, and if so, only the initial 528 elements of the array are set, leaving the remainder alone. 529 </td> 530 </tr> 531 <tr> 532 <td>27 11x</td> 533 <td>throw vAA</td> 534 <td><code>A:</code> exception-bearing register (8 bits)<br/></td> 535 <td>Throw the indicated exception.</td> 536 </tr> 537 <tr> 538 <td>28 10t</td> 539 <td>goto +AA</td> 540 <td><code>A:</code> signed branch offset (8 bits)</td> 541 <td>Unconditionally jump to the indicated instruction. 542 <p><b>Note:</b> 543 The branch offset must not be <code>0</code>. (A spin 544 loop may be legally constructed either with <code>goto/32</code> or 545 by including a <code>nop</code> as a target before the branch.)</p> 546 </td> 547 </tr> 548 <tr> 549 <td>29 20t</td> 550 <td>goto/16 +AAAA</td> 551 <td><code>A:</code> signed branch offset (16 bits)<br/></td> 552 <td>Unconditionally jump to the indicated instruction. 553 <p><b>Note:</b> 554 The branch offset must not be <code>0</code>. (A spin 555 loop may be legally constructed either with <code>goto/32</code> or 556 by including a <code>nop</code> as a target before the branch.)</p> 557 </td> 558 </tr> 559 <tr> 560 <td>2a 30t</td> 561 <td>goto/32 +AAAAAAAA</td> 562 <td><code>A:</code> signed branch offset (32 bits)<br/></td> 563 <td>Unconditionally jump to the indicated instruction.</td> 564 </tr> 565 <tr> 566 <td>2b 31t</td> 567 <td>packed-switch vAA, +BBBBBBBB <i>(with supplemental data as 568 specified below in "<code>packed-switch-payload</code> Format")</i></td> 569 <td><code>A:</code> register to test<br/> 570 <code>B:</code> signed "branch" offset to table data pseudo-instruction 571 (32 bits) 572 </td> 573 <td>Jump to a new instruction based on the value in the 574 given register, using a table of offsets corresponding to each value 575 in a particular integral range, or fall through to the next 576 instruction if there is no match. 577 </td> 578 </tr> 579 <tr> 580 <td>2c 31t</td> 581 <td>sparse-switch vAA, +BBBBBBBB <i>(with supplemental data as 582 specified below in "<code>sparse-switch-payload</code> Format")</i></td> 583 <td><code>A:</code> register to test<br/> 584 <code>B:</code> signed "branch" offset to table data pseudo-instruction 585 (32 bits) 586 </td> 587 <td>Jump to a new instruction based on the value in the given 588 register, using an ordered table of value-offset pairs, or fall 589 through to the next instruction if there is no match. 590 </td> 591 </tr> 592 <tr> 593 <td>2d..31 23x</td> 594 <td>cmp<i>kind</i> vAA, vBB, vCC<br/> 595 2d: cmpl-float <i>(lt bias)</i><br/> 596 2e: cmpg-float <i>(gt bias)</i><br/> 597 2f: cmpl-double <i>(lt bias)</i><br/> 598 30: cmpg-double <i>(gt bias)</i><br/> 599 31: cmp-long 600 </td> 601 <td><code>A:</code> destination register (8 bits)<br/> 602 <code>B:</code> first source register or pair<br/> 603 <code>C:</code> second source register or pair</td> 604 <td>Perform the indicated floating point or <code>long</code> comparison, 605 setting <code>a</code> to <code>0</code> if <code>b == c</code>, 606 <code>1</code> if <code>b > c</code>, 607 or <code>-1</code> if <code>b < c</code>. 608 The "bias" listed for the floating point operations 609 indicates how <code>NaN</code> comparisons are treated: "gt bias" 610 instructions return <code>1</code> for <code>NaN</code> comparisons, 611 and "lt bias" instructions return <code>-1</code>. 612 <p>For example, to check to see if floating point 613 <code>x < y</code> it is advisable to use 614 <code>cmpg-float</code>; a result of <code>-1</code> indicates that 615 the test was true, and the other values indicate it was false either 616 due to a valid comparison or because one of the values was 617 <code>NaN</code>.</p> 618 </td> 619 </tr> 620 <tr> 621 <td>32..37 22t</td> 622 <td>if-<i>test</i> vA, vB, +CCCC<br/> 623 32: if-eq<br/> 624 33: if-ne<br/> 625 34: if-lt<br/> 626 35: if-ge<br/> 627 36: if-gt<br/> 628 37: if-le<br/> 629 </td> 630 <td><code>A:</code> first register to test (4 bits)<br/> 631 <code>B:</code> second register to test (4 bits)<br/> 632 <code>C:</code> signed branch offset (16 bits)</td> 633 <td>Branch to the given destination if the given two registers' values 634 compare as specified. 635 <p><b>Note:</b> 636 The branch offset must not be <code>0</code>. (A spin 637 loop may be legally constructed either by branching around a 638 backward <code>goto</code> or by including a <code>nop</code> as 639 a target before the branch.)</p> 640 </td> 641 </tr> 642 <tr> 643 <td>38..3d 21t</td> 644 <td>if-<i>test</i>z vAA, +BBBB<br/> 645 38: if-eqz<br/> 646 39: if-nez<br/> 647 3a: if-ltz<br/> 648 3b: if-gez<br/> 649 3c: if-gtz<br/> 650 3d: if-lez<br/> 651 </td> 652 <td><code>A:</code> register to test (8 bits)<br/> 653 <code>B:</code> signed branch offset (16 bits)</td> 654 <td>Branch to the given destination if the given register's value compares 655 with 0 as specified. 656 <p><b>Note:</b> 657 The branch offset must not be <code>0</code>. (A spin 658 loop may be legally constructed either by branching around a 659 backward <code>goto</code> or by including a <code>nop</code> as 660 a target before the branch.)</p> 661 </td> 662 </tr> 663 <tr> 664 <td>3e..43 10x</td> 665 <td><i>(unused)</i></td> 666 <td> </td> 667 <td><i>(unused)</i></td> 668 </tr> 669 <tr> 670 <td>44..51 23x</td> 671 <td><i>arrayop</i> vAA, vBB, vCC<br/> 672 44: aget<br/> 673 45: aget-wide<br/> 674 46: aget-object<br/> 675 47: aget-boolean<br/> 676 48: aget-byte<br/> 677 49: aget-char<br/> 678 4a: aget-short<br/> 679 4b: aput<br/> 680 4c: aput-wide<br/> 681 4d: aput-object<br/> 682 4e: aput-boolean<br/> 683 4f: aput-byte<br/> 684 50: aput-char<br/> 685 51: aput-short 686 </td> 687 <td><code>A:</code> value register or pair; may be source or dest 688 (8 bits)<br/> 689 <code>B:</code> array register (8 bits)<br/> 690 <code>C:</code> index register (8 bits)</td> 691 <td>Perform the identified array operation at the identified index of 692 the given array, loading or storing into the value register.</td> 693 </tr> 694 <tr> 695 <td>52..5f 22c</td> 696 <td>i<i>instanceop</i> vA, vB, field@CCCC<br/> 697 52: iget<br/> 698 53: iget-wide<br/> 699 54: iget-object<br/> 700 55: iget-boolean<br/> 701 56: iget-byte<br/> 702 57: iget-char<br/> 703 58: iget-short<br/> 704 59: iput<br/> 705 5a: iput-wide<br/> 706 5b: iput-object<br/> 707 5c: iput-boolean<br/> 708 5d: iput-byte<br/> 709 5e: iput-char<br/> 710 5f: iput-short 711 </td> 712 <td><code>A:</code> value register or pair; may be source or dest 713 (4 bits)<br/> 714 <code>B:</code> object register (4 bits)<br/> 715 <code>C:</code> instance field reference index (16 bits)</td> 716 <td>Perform the identified object instance field operation with 717 the identified field, loading or storing into the value register. 718 <p><b>Note:</b> These opcodes are reasonable candidates for static linking, 719 altering the field argument to be a more direct offset.</p> 720 </td> 721 </tr> 722 <tr> 723 <td>60..6d 21c</td> 724 <td>s<i>staticop</i> vAA, field@BBBB<br/> 725 60: sget<br/> 726 61: sget-wide<br/> 727 62: sget-object<br/> 728 63: sget-boolean<br/> 729 64: sget-byte<br/> 730 65: sget-char<br/> 731 66: sget-short<br/> 732 67: sput<br/> 733 68: sput-wide<br/> 734 69: sput-object<br/> 735 6a: sput-boolean<br/> 736 6b: sput-byte<br/> 737 6c: sput-char<br/> 738 6d: sput-short 739 </td> 740 <td><code>A:</code> value register or pair; may be source or dest 741 (8 bits)<br/> 742 <code>B:</code> static field reference index (16 bits)</td> 743 <td>Perform the identified object static field operation with the identified 744 static field, loading or storing into the value register. 745 <p><b>Note:</b> These opcodes are reasonable candidates for static linking, 746 altering the field argument to be a more direct offset.</p> 747 </td> 748 </tr> 749 <tr> 750 <td>6e..72 35c</td> 751 <td>invoke-<i>kind</i> {vC, vD, vE, vF, vG}, meth@BBBB<br/> 752 6e: invoke-virtual<br/> 753 6f: invoke-super<br/> 754 70: invoke-direct<br/> 755 71: invoke-static<br/> 756 72: invoke-interface 757 </td> 758 <td> 759 <code>A:</code> argument word count (4 bits)<br/> 760 <code>B:</code> method reference index (16 bits)<br/> 761 <code>C..G:</code> argument registers (4 bits each) 762 </td> 763 <td>Call the indicated method. The result (if any) may be stored 764 with an appropriate <code>move-result*</code> variant as the immediately 765 subsequent instruction. 766 <p><code>invoke-virtual</code> is used to invoke a normal virtual 767 method (a method that is not <code>private</code>, <code>static</code>, 768 or <code>final</code>, and is also not a constructor).</p> 769 <p><code>invoke-super</code> is used to invoke the closest superclass's 770 virtual method (as opposed to the one with the same <code>method_id</code> 771 in the calling class). The same method restrictions hold as for 772 <code>invoke-virtual</code>.</p> 773 <p><code>invoke-direct</code> is used to invoke a non-<code>static</code> 774 direct method (that is, an instance method that is by its nature 775 non-overridable, namely either a <code>private</code> instance method 776 or a constructor).</p> 777 <p><code>invoke-static</code> is used to invoke a <code>static</code> 778 method (which is always considered a direct method).</p> 779 <p><code>invoke-interface</code> is used to invoke an 780 <code>interface</code> method, that is, on an object whose concrete 781 class isn't known, using a <code>method_id</code> that refers to 782 an <code>interface</code>.</p> 783 <p><b>Note:</b> These opcodes are reasonable candidates for static linking, 784 altering the method argument to be a more direct offset 785 (or pair thereof).</p> 786 </td> 787 </tr> 788 <tr> 789 <td>73 10x</td> 790 <td><i>(unused)</i></td> 791 <td> </td> 792 <td><i>(unused)</i></td> 793 </tr> 794 <tr> 795 <td>74..78 3rc</td> 796 <td>invoke-<i>kind</i>/range {vCCCC .. vNNNN}, meth@BBBB<br/> 797 74: invoke-virtual/range<br/> 798 75: invoke-super/range<br/> 799 76: invoke-direct/range<br/> 800 77: invoke-static/range<br/> 801 78: invoke-interface/range 802 </td> 803 <td><code>A:</code> argument word count (8 bits)<br/> 804 <code>B:</code> method reference index (16 bits)<br/> 805 <code>C:</code> first argument register (16 bits)<br/> 806 <code>N = A + C - 1</code></td> 807 <td>Call the indicated method. See first <code>invoke-<i>kind</i></code> 808 description above for details, caveats, and suggestions. 809 </td> 810 </tr> 811 <tr> 812 <td>79..7a 10x</td> 813 <td><i>(unused)</i></td> 814 <td> </td> 815 <td><i>(unused)</i></td> 816 </tr> 817 <tr> 818 <td>7b..8f 12x</td> 819 <td><i>unop</i> vA, vB<br/> 820 7b: neg-int<br/> 821 7c: not-int<br/> 822 7d: neg-long<br/> 823 7e: not-long<br/> 824 7f: neg-float<br/> 825 80: neg-double<br/> 826 81: int-to-long<br/> 827 82: int-to-float<br/> 828 83: int-to-double<br/> 829 84: long-to-int<br/> 830 85: long-to-float<br/> 831 86: long-to-double<br/> 832 87: float-to-int<br/> 833 88: float-to-long<br/> 834 89: float-to-double<br/> 835 8a: double-to-int<br/> 836 8b: double-to-long<br/> 837 8c: double-to-float<br/> 838 8d: int-to-byte<br/> 839 8e: int-to-char<br/> 840 8f: int-to-short 841 </td> 842 <td><code>A:</code> destination register or pair (4 bits)<br/> 843 <code>B:</code> source register or pair (4 bits)</td> 844 <td>Perform the identified unary operation on the source register, 845 storing the result in the destination register.</td> 846 </tr> 847 848 <tr> 849 <td>90..af 23x</td> 850 <td><i>binop</i> vAA, vBB, vCC<br/> 851 90: add-int<br/> 852 91: sub-int<br/> 853 92: mul-int<br/> 854 93: div-int<br/> 855 94: rem-int<br/> 856 95: and-int<br/> 857 96: or-int<br/> 858 97: xor-int<br/> 859 98: shl-int<br/> 860 99: shr-int<br/> 861 9a: ushr-int<br/> 862 9b: add-long<br/> 863 9c: sub-long<br/> 864 9d: mul-long<br/> 865 9e: div-long<br/> 866 9f: rem-long<br/> 867 a0: and-long<br/> 868 a1: or-long<br/> 869 a2: xor-long<br/> 870 a3: shl-long<br/> 871 a4: shr-long<br/> 872 a5: ushr-long<br/> 873 a6: add-float<br/> 874 a7: sub-float<br/> 875 a8: mul-float<br/> 876 a9: div-float<br/> 877 aa: rem-float<br/> 878 ab: add-double<br/> 879 ac: sub-double<br/> 880 ad: mul-double<br/> 881 ae: div-double<br/> 882 af: rem-double 883 </td> 884 <td><code>A:</code> destination register or pair (8 bits)<br/> 885 <code>B:</code> first source register or pair (8 bits)<br/> 886 <code>C:</code> second source register or pair (8 bits)</td> 887 <td>Perform the identified binary operation on the two source registers, 888 storing the result in the first source register.</td> 889 </tr> 890 <tr> 891 <td>b0..cf 12x</td> 892 <td><i>binop</i>/2addr vA, vB<br/> 893 b0: add-int/2addr<br/> 894 b1: sub-int/2addr<br/> 895 b2: mul-int/2addr<br/> 896 b3: div-int/2addr<br/> 897 b4: rem-int/2addr<br/> 898 b5: and-int/2addr<br/> 899 b6: or-int/2addr<br/> 900 b7: xor-int/2addr<br/> 901 b8: shl-int/2addr<br/> 902 b9: shr-int/2addr<br/> 903 ba: ushr-int/2addr<br/> 904 bb: add-long/2addr<br/> 905 bc: sub-long/2addr<br/> 906 bd: mul-long/2addr<br/> 907 be: div-long/2addr<br/> 908 bf: rem-long/2addr<br/> 909 c0: and-long/2addr<br/> 910 c1: or-long/2addr<br/> 911 c2: xor-long/2addr<br/> 912 c3: shl-long/2addr<br/> 913 c4: shr-long/2addr<br/> 914 c5: ushr-long/2addr<br/> 915 c6: add-float/2addr<br/> 916 c7: sub-float/2addr<br/> 917 c8: mul-float/2addr<br/> 918 c9: div-float/2addr<br/> 919 ca: rem-float/2addr<br/> 920 cb: add-double/2addr<br/> 921 cc: sub-double/2addr<br/> 922 cd: mul-double/2addr<br/> 923 ce: div-double/2addr<br/> 924 cf: rem-double/2addr 925 </td> 926 <td><code>A:</code> destination and first source register or pair 927 (4 bits)<br/> 928 <code>B:</code> second source register or pair (4 bits)</td> 929 <td>Perform the identified binary operation on the two source registers, 930 storing the result in the first source register.</td> 931 </tr> 932 <tr> 933 <td>d0..d7 22s</td> 934 <td><i>binop</i>/lit16 vA, vB, #+CCCC<br/> 935 d0: add-int/lit16<br/> 936 d1: rsub-int (reverse subtract)<br/> 937 d2: mul-int/lit16<br/> 938 d3: div-int/lit16<br/> 939 d4: rem-int/lit16<br/> 940 d5: and-int/lit16<br/> 941 d6: or-int/lit16<br/> 942 d7: xor-int/lit16 943 </td> 944 <td><code>A:</code> destination register (4 bits)<br/> 945 <code>B:</code> source register (4 bits)<br/> 946 <code>C:</code> signed int constant (16 bits)</td> 947 <td>Perform the indicated binary op on the indicated register (first 948 argument) and literal value (second argument), storing the result in 949 the destination register. 950 <p><b>Note:</b> 951 <code>rsub-int</code> does not have a suffix since this version is the 952 main opcode of its family. Also, see below for details on its semantics. 953 </p> 954 </td> 955 </tr> 956 <tr> 957 <td>d8..e2 22b</td> 958 <td><i>binop</i>/lit8 vAA, vBB, #+CC<br/> 959 d8: add-int/lit8<br/> 960 d9: rsub-int/lit8<br/> 961 da: mul-int/lit8<br/> 962 db: div-int/lit8<br/> 963 dc: rem-int/lit8<br/> 964 dd: and-int/lit8<br/> 965 de: or-int/lit8<br/> 966 df: xor-int/lit8<br/> 967 e0: shl-int/lit8<br/> 968 e1: shr-int/lit8<br/> 969 e2: ushr-int/lit8 970 </td> 971 <td><code>A:</code> destination register (8 bits)<br/> 972 <code>B:</code> source register (8 bits)<br/> 973 <code>C:</code> signed int constant (8 bits)</td> 974 <td>Perform the indicated binary op on the indicated register (first 975 argument) and literal value (second argument), storing the result 976 in the destination register. 977 <p><b>Note:</b> See below for details on the semantics of 978 <code>rsub-int</code>.</p> 979 </td> 980 </tr> 981 <tr> 982 <td>e3..ff 10x</td> 983 <td><i>(unused)</i></td> 984 <td> </td> 985 <td><i>(unused)</i></td> 986 </tr> 987 </tbody> 988 </table> 989 990 <h2>packed-switch-payload Format</h2> 991 992 <table class="supplement"> 993 <thead> 994 <tr> 995 <th>Name</th> 996 <th>Format</th> 997 <th>Description</th> 998 </tr> 999 </thead> 1000 <tbody> 1001 <tr> 1002 <td>ident</td> 1003 <td>ushort = 0x0100</td> 1004 <td>identifying pseudo-opcode</td> 1005 </tr> 1006 <tr> 1007 <td>size</td> 1008 <td>ushort</td> 1009 <td>number of entries in the table</td> 1010 </tr> 1011 <tr> 1012 <td>first_key</td> 1013 <td>int</td> 1014 <td>first (and lowest) switch case value</td> 1015 </tr> 1016 <tr> 1017 <td>targets</td> 1018 <td>int[]</td> 1019 <td>list of <code>size</code> relative branch targets. The targets are 1020 relative to the address of the switch opcode, not of this table. 1021 </td> 1022 </tr> 1023 </tbody> 1024 </table> 1025 1026 <p><b>Note:</b> The total number of code units for an instance of this 1027 table is <code>(size * 2) + 4</code>.</p> 1028 1029 <h2>sparse-switch-payload Format</h2> 1030 1031 <table class="supplement"> 1032 <thead> 1033 <tr> 1034 <th>Name</th> 1035 <th>Format</th> 1036 <th>Description</th> 1037 </tr> 1038 </thead> 1039 <tbody> 1040 <tr> 1041 <td>ident</td> 1042 <td>ushort = 0x0200</td> 1043 <td>identifying pseudo-opcode</td> 1044 </tr> 1045 <tr> 1046 <td>size</td> 1047 <td>ushort</td> 1048 <td>number of entries in the table</td> 1049 </tr> 1050 <tr> 1051 <td>keys</td> 1052 <td>int[]</td> 1053 <td>list of <code>size</code> key values, sorted low-to-high</td> 1054 </tr> 1055 <tr> 1056 <td>targets</td> 1057 <td>int[]</td> 1058 <td>list of <code>size</code> relative branch targets, each corresponding 1059 to the key value at the same index. The targets are 1060 relative to the address of the switch opcode, not of this table. 1061 </td> 1062 </tr> 1063 </tbody> 1064 </table> 1065 1066 <p><b>Note:</b> The total number of code units for an instance of this 1067 table is <code>(size * 4) + 2</code>.</p> 1068 1069 <h2>fill-array-data-payload Format</h2> 1070 1071 <table class="supplement"> 1072 <thead> 1073 <tr> 1074 <th>Name</th> 1075 <th>Format</th> 1076 <th>Description</th> 1077 </tr> 1078 </thead> 1079 <tbody> 1080 <tr> 1081 <td>ident</td> 1082 <td>ushort = 0x0300</td> 1083 <td>identifying pseudo-opcode</td> 1084 </tr> 1085 <tr> 1086 <td>element_width</td> 1087 <td>ushort</td> 1088 <td>number of bytes in each element</td> 1089 </tr> 1090 <tr> 1091 <td>size</td> 1092 <td>uint</td> 1093 <td>number of elements in the table</td> 1094 </tr> 1095 <tr> 1096 <td>data</td> 1097 <td>ubyte[]</td> 1098 <td>data values</td> 1099 </tr> 1100 </tbody> 1101 </table> 1102 1103 <p><b>Note:</b> The total number of code units for an instance of this 1104 table is <code>(size * element_width + 1) / 2 + 4</code>.</p> 1105 1106 1107 <h2>Mathematical Operation Details</h2> 1108 1109 <p><b>Note:</b> Floating point operations must follow IEEE 754 rules, using 1110 round-to-nearest and gradual underflow, except where stated otherwise.</p> 1111 1112 <table class="math"> 1113 <thead> 1114 <tr> 1115 <th>Opcode</th> 1116 <th>C Semantics</th> 1117 <th>Notes</th> 1118 </tr> 1119 </thead> 1120 <tbody> 1121 <tr> 1122 <td>neg-int</td> 1123 <td>int32 a;<br/> 1124 int32 result = -a; 1125 </td> 1126 <td>Unary twos-complement.</td> 1127 </tr> 1128 <tr> 1129 <td>not-int</td> 1130 <td>int32 a;<br/> 1131 int32 result = ~a; 1132 </td> 1133 <td>Unary ones-complement.</td> 1134 </tr> 1135 <tr> 1136 <td>neg-long</td> 1137 <td>int64 a;<br/> 1138 int64 result = -a; 1139 </td> 1140 <td>Unary twos-complement.</td> 1141 </tr> 1142 <tr> 1143 <td>not-long</td> 1144 <td>int64 a;<br/> 1145 int64 result = ~a; 1146 </td> 1147 <td>Unary ones-complement.</td> 1148 </tr> 1149 <tr> 1150 <td>neg-float</td> 1151 <td>float a;<br/> 1152 float result = -a; 1153 </td> 1154 <td>Floating point negation.</td> 1155 </tr> 1156 <tr> 1157 <td>neg-double</td> 1158 <td>double a;<br/> 1159 double result = -a; 1160 </td> 1161 <td>Floating point negation.</td> 1162 </tr> 1163 <tr> 1164 <td>int-to-long</td> 1165 <td>int32 a;<br/> 1166 int64 result = (int64) a; 1167 </td> 1168 <td>Sign extension of <code>int32</code> into <code>int64</code>.</td> 1169 </tr> 1170 <tr> 1171 <td>int-to-float</td> 1172 <td>int32 a;<br/> 1173 float result = (float) a; 1174 </td> 1175 <td>Conversion of <code>int32</code> to <code>float</code>, using 1176 round-to-nearest. This loses precision for some values. 1177 </td> 1178 </tr> 1179 <tr> 1180 <td>int-to-double</td> 1181 <td>int32 a;<br/> 1182 double result = (double) a; 1183 </td> 1184 <td>Conversion of <code>int32</code> to <code>double</code>.</td> 1185 </tr> 1186 <tr> 1187 <td>long-to-int</td> 1188 <td>int64 a;<br/> 1189 int32 result = (int32) a; 1190 </td> 1191 <td>Truncation of <code>int64</code> into <code>int32</code>.</td> 1192 </tr> 1193 <tr> 1194 <td>long-to-float</td> 1195 <td>int64 a;<br/> 1196 float result = (float) a; 1197 </td> 1198 <td>Conversion of <code>int64</code> to <code>float</code>, using 1199 round-to-nearest. This loses precision for some values. 1200 </td> 1201 </tr> 1202 <tr> 1203 <td>long-to-double</td> 1204 <td>int64 a;<br/> 1205 double result = (double) a; 1206 </td> 1207 <td>Conversion of <code>int64</code> to <code>double</code>, using 1208 round-to-nearest. This loses precision for some values. 1209 </td> 1210 </tr> 1211 <tr> 1212 <td>float-to-int</td> 1213 <td>float a;<br/> 1214 int32 result = (int32) a; 1215 </td> 1216 <td>Conversion of <code>float</code> to <code>int32</code>, using 1217 round-toward-zero. <code>NaN</code> and <code>-0.0</code> (negative zero) 1218 convert to the integer <code>0</code>. Infinities and values with 1219 too large a magnitude to be represented get converted to either 1220 <code>0x7fffffff</code> or <code>-0x80000000</code> depending on sign. 1221 </td> 1222 </tr> 1223 <tr> 1224 <td>float-to-long</td> 1225 <td>float a;<br/> 1226 int64 result = (int64) a; 1227 </td> 1228 <td>Conversion of <code>float</code> to <code>int64</code>, using 1229 round-toward-zero. The same special case rules as for 1230 <code>float-to-int</code> apply here, except that out-of-range values 1231 get converted to either <code>0x7fffffffffffffff</code> or 1232 <code>-0x8000000000000000</code> depending on sign. 1233 </td> 1234 </tr> 1235 <tr> 1236 <td>float-to-double</td> 1237 <td>float a;<br/> 1238 double result = (double) a; 1239 </td> 1240 <td>Conversion of <code>float</code> to <code>double</code>, preserving 1241 the value exactly. 1242 </td> 1243 </tr> 1244 <tr> 1245 <td>double-to-int</td> 1246 <td>double a;<br/> 1247 int32 result = (int32) a; 1248 </td> 1249 <td>Conversion of <code>double</code> to <code>int32</code>, using 1250 round-toward-zero. The same special case rules as for 1251 <code>float-to-int</code> apply here. 1252 </td> 1253 </tr> 1254 <tr> 1255 <td>double-to-long</td> 1256 <td>double a;<br/> 1257 int64 result = (int64) a; 1258 </td> 1259 <td>Conversion of <code>double</code> to <code>int64</code>, using 1260 round-toward-zero. The same special case rules as for 1261 <code>float-to-long</code> apply here. 1262 </td> 1263 </tr> 1264 <tr> 1265 <td>double-to-float</td> 1266 <td>double a;<br/> 1267 float result = (float) a; 1268 </td> 1269 <td>Conversion of <code>double</code> to <code>float</code>, using 1270 round-to-nearest. This loses precision for some values. 1271 </td> 1272 </tr> 1273 <tr> 1274 <td>int-to-byte</td> 1275 <td>int32 a;<br/> 1276 int32 result = (a << 24) >> 24; 1277 </td> 1278 <td>Truncation of <code>int32</code> to <code>int8</code>, sign 1279 extending the result. 1280 </td> 1281 </tr> 1282 <tr> 1283 <td>int-to-char</td> 1284 <td>int32 a;<br/> 1285 int32 result = a & 0xffff; 1286 </td> 1287 <td>Truncation of <code>int32</code> to <code>uint16</code>, without 1288 sign extension. 1289 </td> 1290 </tr> 1291 <tr> 1292 <td>int-to-short</td> 1293 <td>int32 a;<br/> 1294 int32 result = (a << 16) >> 16; 1295 </td> 1296 <td>Truncation of <code>int32</code> to <code>int16</code>, sign 1297 extending the result. 1298 </td> 1299 </tr> 1300 <tr> 1301 <td>add-int</td> 1302 <td>int32 a, b;<br/> 1303 int32 result = a + b; 1304 </td> 1305 <td>Twos-complement addition.</td> 1306 </tr> 1307 <tr> 1308 <td>sub-int</td> 1309 <td>int32 a, b;<br/> 1310 int32 result = a - b; 1311 </td> 1312 <td>Twos-complement subtraction.</td> 1313 </tr> 1314 <tr> 1315 <td>rsub-int</td> 1316 <td>int32 a, b;<br/> 1317 int32 result = b - a; 1318 </td> 1319 <td>Twos-complement reverse subtraction.</td> 1320 </tr> 1321 <tr> 1322 <td>mul-int</td> 1323 <td>int32 a, b;<br/> 1324 int32 result = a * b; 1325 </td> 1326 <td>Twos-complement multiplication.</td> 1327 </tr> 1328 <tr> 1329 <td>div-int</td> 1330 <td>int32 a, b;<br/> 1331 int32 result = a / b; 1332 </td> 1333 <td>Twos-complement division, rounded towards zero (that is, truncated to 1334 integer). This throws <code>ArithmeticException</code> if 1335 <code>b == 0</code>. 1336 </td> 1337 </tr> 1338 <tr> 1339 <td>rem-int</td> 1340 <td>int32 a, b;<br/> 1341 int32 result = a % b; 1342 </td> 1343 <td>Twos-complement remainder after division. The sign of the result 1344 is the same as that of <code>a</code>, and it is more precisely 1345 defined as <code>result == a - (a / b) * b</code>. This throws 1346 <code>ArithmeticException</code> if <code>b == 0</code>. 1347 </td> 1348 </tr> 1349 <tr> 1350 <td>and-int</td> 1351 <td>int32 a, b;<br/> 1352 int32 result = a & b; 1353 </td> 1354 <td>Bitwise AND.</td> 1355 </tr> 1356 <tr> 1357 <td>or-int</td> 1358 <td>int32 a, b;<br/> 1359 int32 result = a | b; 1360 </td> 1361 <td>Bitwise OR.</td> 1362 </tr> 1363 <tr> 1364 <td>xor-int</td> 1365 <td>int32 a, b;<br/> 1366 int32 result = a ^ b; 1367 </td> 1368 <td>Bitwise XOR.</td> 1369 </tr> 1370 <tr> 1371 <td>shl-int</td> 1372 <td>int32 a, b;<br/> 1373 int32 result = a << (b & 0x1f); 1374 </td> 1375 <td>Bitwise shift left (with masked argument).</td> 1376 </tr> 1377 <tr> 1378 <td>shr-int</td> 1379 <td>int32 a, b;<br/> 1380 int32 result = a >> (b & 0x1f); 1381 </td> 1382 <td>Bitwise signed shift right (with masked argument).</td> 1383 </tr> 1384 <tr> 1385 <td>ushr-int</td> 1386 <td>uint32 a, b;<br/> 1387 int32 result = a >> (b & 0x1f); 1388 </td> 1389 <td>Bitwise unsigned shift right (with masked argument).</td> 1390 </tr> 1391 <tr> 1392 <td>add-long</td> 1393 <td>int64 a, b;<br/> 1394 int64 result = a + b; 1395 </td> 1396 <td>Twos-complement addition.</td> 1397 </tr> 1398 <tr> 1399 <td>sub-long</td> 1400 <td>int64 a, b;<br/> 1401 int64 result = a - b; 1402 </td> 1403 <td>Twos-complement subtraction.</td> 1404 </tr> 1405 <tr> 1406 <td>mul-long</td> 1407 <td>int64 a, b;<br/> 1408 int64 result = a * b; 1409 </td> 1410 <td>Twos-complement multiplication.</td> 1411 </tr> 1412 <tr> 1413 <td>div-long</td> 1414 <td>int64 a, b;<br/> 1415 int64 result = a / b; 1416 </td> 1417 <td>Twos-complement division, rounded towards zero (that is, truncated to 1418 integer). This throws <code>ArithmeticException</code> if 1419 <code>b == 0</code>. 1420 </td> 1421 </tr> 1422 <tr> 1423 <td>rem-long</td> 1424 <td>int64 a, b;<br/> 1425 int64 result = a % b; 1426 </td> 1427 <td>Twos-complement remainder after division. The sign of the result 1428 is the same as that of <code>a</code>, and it is more precisely 1429 defined as <code>result == a - (a / b) * b</code>. This throws 1430 <code>ArithmeticException</code> if <code>b == 0</code>. 1431 </td> 1432 </tr> 1433 <tr> 1434 <td>and-long</td> 1435 <td>int64 a, b;<br/> 1436 int64 result = a & b; 1437 </td> 1438 <td>Bitwise AND.</td> 1439 </tr> 1440 <tr> 1441 <td>or-long</td> 1442 <td>int64 a, b;<br/> 1443 int64 result = a | b; 1444 </td> 1445 <td>Bitwise OR.</td> 1446 </tr> 1447 <tr> 1448 <td>xor-long</td> 1449 <td>int64 a, b;<br/> 1450 int64 result = a ^ b; 1451 </td> 1452 <td>Bitwise XOR.</td> 1453 </tr> 1454 <tr> 1455 <td>shl-long</td> 1456 <td>int64 a, b;<br/> 1457 int64 result = a << (b & 0x3f); 1458 </td> 1459 <td>Bitwise shift left (with masked argument).</td> 1460 </tr> 1461 <tr> 1462 <td>shr-long</td> 1463 <td>int64 a, b;<br/> 1464 int64 result = a >> (b & 0x3f); 1465 </td> 1466 <td>Bitwise signed shift right (with masked argument).</td> 1467 </tr> 1468 <tr> 1469 <td>ushr-long</td> 1470 <td>uint64 a, b;<br/> 1471 int64 result = a >> (b & 0x3f); 1472 </td> 1473 <td>Bitwise unsigned shift right (with masked argument).</td> 1474 </tr> 1475 <tr> 1476 <td>add-float</td> 1477 <td>float a, b;<br/> 1478 float result = a + b; 1479 </td> 1480 <td>Floating point addition.</td> 1481 </tr> 1482 <tr> 1483 <td>sub-float</td> 1484 <td>float a, b;<br/> 1485 float result = a - b; 1486 </td> 1487 <td>Floating point subtraction.</td> 1488 </tr> 1489 <tr> 1490 <td>mul-float</td> 1491 <td>float a, b;<br/> 1492 float result = a * b; 1493 </td> 1494 <td>Floating point multiplication.</td> 1495 </tr> 1496 <tr> 1497 <td>div-float</td> 1498 <td>float a, b;<br/> 1499 float result = a / b; 1500 </td> 1501 <td>Floating point division.</td> 1502 </tr> 1503 <tr> 1504 <td>rem-float</td> 1505 <td>float a, b;<br/> 1506 float result = a % b; 1507 </td> 1508 <td>Floating point remainder after division. This function is different 1509 than IEEE 754 remainder and is defined as 1510 <code>result == a - roundTowardZero(a / b) * b</code>. 1511 </td> 1512 </tr> 1513 <tr> 1514 <td>add-double</td> 1515 <td>double a, b;<br/> 1516 double result = a + b; 1517 </td> 1518 <td>Floating point addition.</td> 1519 </tr> 1520 <tr> 1521 <td>sub-double</td> 1522 <td>double a, b;<br/> 1523 double result = a - b; 1524 </td> 1525 <td>Floating point subtraction.</td> 1526 </tr> 1527 <tr> 1528 <td>mul-double</td> 1529 <td>double a, b;<br/> 1530 double result = a * b; 1531 </td> 1532 <td>Floating point multiplication.</td> 1533 </tr> 1534 <tr> 1535 <td>div-double</td> 1536 <td>double a, b;<br/> 1537 double result = a / b; 1538 </td> 1539 <td>Floating point division.</td> 1540 </tr> 1541 <tr> 1542 <td>rem-double</td> 1543 <td>double a, b;<br/> 1544 double result = a % b; 1545 </td> 1546 <td>Floating point remainder after division. This function is different 1547 than IEEE 754 remainder and is defined as 1548 <code>result == a - roundTowardZero(a / b) * b</code>. 1549 </td> 1550 </tr> 1551 </tbody> 1552 </table> 1553