1%def const(helper="UndefinedConstHandler"):
2    /* const/class vAA, type@BBBB */
3    /* const/method-handle vAA, method_handle@BBBB */
4    /* const/method-type vAA, proto@BBBB */
5    /* const/string vAA, string@@BBBB */
6    .extern $helper
7    EXPORT_PC
8    movzwl  2(rPC), %eax                    # eax <- BBBB
9    movl    %eax, OUT_ARG0(%esp)
10    movl    rINST, OUT_ARG1(%esp)
11    leal    OFF_FP_SHADOWFRAME(rFP), %eax
12    movl    %eax, OUT_ARG2(%esp)
13    movl    rSELF, %eax
14    movl    %eax, OUT_ARG3(%esp)
15    call    SYMBOL($helper)                 # (index, tgt_reg, shadow_frame, self)
16    RESTORE_IBASE
17    testb   %al, %al
18    jnz     MterpPossibleException
19    ADVANCE_PC_FETCH_AND_GOTO_NEXT 2
20
21%def unused():
22/*
23 * Bail to reference interpreter to throw.
24 */
25    jmp     MterpFallback
26
27%def op_const():
28    /* const vAA, #+BBBBbbbb */
29    movl    2(rPC), %eax                    # grab all 32 bits at once
30    SET_VREG %eax, rINST                    # vAA<- eax
31    ADVANCE_PC_FETCH_AND_GOTO_NEXT 3
32
33%def op_const_16():
34    /* const/16 vAA, #+BBBB */
35    movswl  2(rPC), %ecx                    # ecx <- ssssBBBB
36    SET_VREG %ecx, rINST                    # vAA <- ssssBBBB
37    ADVANCE_PC_FETCH_AND_GOTO_NEXT 2
38
39%def op_const_4():
40    /* const/4 vA, #+B */
41    movsx   rINSTbl, %eax                   # eax <-ssssssBx
42    movl    $$0xf, rINST
43    andl    %eax, rINST                     # rINST <- A
44    sarl    $$4, %eax
45    SET_VREG %eax, rINST
46    ADVANCE_PC_FETCH_AND_GOTO_NEXT 1
47
48%def op_const_class():
49%  const(helper="MterpConstClass")
50
51%def op_const_high16():
52    /* const/high16 vAA, #+BBBB0000 */
53    movzwl  2(rPC), %eax                    # eax <- 0000BBBB
54    sall    $$16, %eax                      # eax <- BBBB0000
55    SET_VREG %eax, rINST                    # vAA <- eax
56    ADVANCE_PC_FETCH_AND_GOTO_NEXT 2
57
58%def op_const_method_handle():
59%  const(helper="MterpConstMethodHandle")
60
61%def op_const_method_type():
62%  const(helper="MterpConstMethodType")
63
64%def op_const_string():
65%  const(helper="MterpConstString")
66
67%def op_const_string_jumbo():
68    /* const/string vAA, String@BBBBBBBB */
69    EXPORT_PC
70    movl    2(rPC), %eax                    # eax <- BBBB
71    movl    %eax, OUT_ARG0(%esp)
72    movl    rINST, OUT_ARG1(%esp)
73    leal    OFF_FP_SHADOWFRAME(rFP), %eax
74    movl    %eax, OUT_ARG2(%esp)
75    movl    rSELF, %eax
76    movl    %eax, OUT_ARG3(%esp)
77    call    SYMBOL(MterpConstString)        # (index, tgt_reg, shadow_frame, self)
78    RESTORE_IBASE
79    testb   %al, %al
80    jnz     MterpPossibleException
81    ADVANCE_PC_FETCH_AND_GOTO_NEXT 3
82
83%def op_const_wide():
84    /* const-wide vAA, #+HHHHhhhhBBBBbbbb */
85    movl    2(rPC), %eax                    # eax <- lsw
86    movzbl  rINSTbl, %ecx                   # ecx <- AA
87    movl    6(rPC), rINST                   # rINST <- msw
88    SET_VREG %eax, %ecx
89    SET_VREG_HIGH  rINST, %ecx
90    ADVANCE_PC_FETCH_AND_GOTO_NEXT 5
91
92%def op_const_wide_16():
93    /* const-wide/16 vAA, #+BBBB */
94    movswl  2(rPC), %eax                    # eax <- ssssBBBB
95    movl    rIBASE, %ecx                    # preserve rIBASE (cltd trashes it)
96    cltd                                    # rIBASE:eax <- ssssssssssssBBBB
97    SET_VREG_HIGH rIBASE, rINST             # store msw
98    SET_VREG %eax, rINST                    # store lsw
99    movl    %ecx, rIBASE                    # restore rIBASE
100    ADVANCE_PC_FETCH_AND_GOTO_NEXT 2
101
102%def op_const_wide_32():
103    /* const-wide/32 vAA, #+BBBBbbbb */
104    movl    2(rPC), %eax                    # eax <- BBBBbbbb
105    movl    rIBASE, %ecx                    # preserve rIBASE (cltd trashes it)
106    cltd                                    # rIBASE:eax <- ssssssssssssBBBB
107    SET_VREG_HIGH rIBASE, rINST             # store msw
108    SET_VREG %eax, rINST                    # store lsw
109    movl    %ecx, rIBASE                    # restore rIBASE
110    ADVANCE_PC_FETCH_AND_GOTO_NEXT 3
111
112%def op_const_wide_high16():
113    /* const-wide/high16 vAA, #+BBBB000000000000 */
114    movzwl  2(rPC), %eax                    # eax <- 0000BBBB
115    sall    $$16, %eax                      # eax <- BBBB0000
116    SET_VREG_HIGH %eax, rINST               # v[AA+1] <- eax
117    xorl    %eax, %eax
118    SET_VREG %eax, rINST                    # v[AA+0] <- eax
119    ADVANCE_PC_FETCH_AND_GOTO_NEXT 2
120
121%def op_monitor_enter():
122/*
123 * Synchronize on an object.
124 */
125    /* monitor-enter vAA */
126    EXPORT_PC
127    GET_VREG %ecx, rINST
128    movl    %ecx, OUT_ARG0(%esp)
129    movl    rSELF, %eax
130    movl    %eax, OUT_ARG1(%esp)
131    call    SYMBOL(artLockObjectFromCode)   # (object, self)
132    RESTORE_IBASE
133    testb   %al, %al
134    jnz     MterpException
135    ADVANCE_PC 1
136    movl    rSELF, %eax
137    cmpb    LITERAL(0), THREAD_USE_MTERP_OFFSET(%eax)
138    jz      MterpFallback
139    FETCH_INST
140    GOTO_NEXT
141
142%def op_monitor_exit():
143/*
144 * Unlock an object.
145 *
146 * Exceptions that occur when unlocking a monitor need to appear as
147 * if they happened at the following instruction.  See the Dalvik
148 * instruction spec.
149 */
150    /* monitor-exit vAA */
151    EXPORT_PC
152    GET_VREG %ecx, rINST
153    movl    %ecx, OUT_ARG0(%esp)
154    movl    rSELF, %eax
155    movl    %eax, OUT_ARG1(%esp)
156    call    SYMBOL(artUnlockObjectFromCode) # (object, self)
157    RESTORE_IBASE
158    testb   %al, %al
159    jnz     MterpException
160    ADVANCE_PC 1
161    movl    rSELF, %eax
162    cmpb    LITERAL(0), THREAD_USE_MTERP_OFFSET(%eax)
163    jz      MterpFallback
164    FETCH_INST
165    GOTO_NEXT
166
167%def op_move(is_object="0"):
168    /* for move, move-object, long-to-int */
169    /* op vA, vB */
170    movzbl  rINSTbl, %eax                   # eax <- BA
171    andb    $$0xf, %al                      # eax <- A
172    shrl    $$4, rINST                      # rINST <- B
173    GET_VREG rINST, rINST
174    .if $is_object
175    SET_VREG_OBJECT rINST, %eax             # fp[A] <- fp[B]
176    .else
177    SET_VREG rINST, %eax                    # fp[A] <- fp[B]
178    .endif
179    ADVANCE_PC_FETCH_AND_GOTO_NEXT 1
180
181%def op_move_16(is_object="0"):
182    /* for: move/16, move-object/16 */
183    /* op vAAAA, vBBBB */
184    movzwl  4(rPC), %ecx                    # ecx <- BBBB
185    movzwl  2(rPC), %eax                    # eax <- AAAA
186    GET_VREG rINST, %ecx
187    .if $is_object
188    SET_VREG_OBJECT rINST, %eax             # fp[A] <- fp[B]
189    .else
190    SET_VREG rINST, %eax                    # fp[A] <- fp[B]
191    .endif
192    ADVANCE_PC_FETCH_AND_GOTO_NEXT 3
193
194%def op_move_exception():
195    /* move-exception vAA */
196    movl    rSELF, %ecx
197    movl    THREAD_EXCEPTION_OFFSET(%ecx), %eax
198    SET_VREG_OBJECT %eax, rINST             # fp[AA] <- exception object
199    movl    $$0, THREAD_EXCEPTION_OFFSET(%ecx)
200    ADVANCE_PC_FETCH_AND_GOTO_NEXT 1
201
202%def op_move_from16(is_object="0"):
203    /* for: move/from16, move-object/from16 */
204    /* op vAA, vBBBB */
205    movzx   rINSTbl, %eax                   # eax <- AA
206    movw    2(rPC), rINSTw                  # rINSTw <- BBBB
207    GET_VREG rINST, rINST                   # rINST <- fp[BBBB]
208    .if $is_object
209    SET_VREG_OBJECT rINST, %eax             # fp[A] <- fp[B]
210    .else
211    SET_VREG rINST, %eax                    # fp[A] <- fp[B]
212    .endif
213    ADVANCE_PC_FETCH_AND_GOTO_NEXT 2
214
215%def op_move_object():
216%  op_move(is_object="1")
217
218%def op_move_object_16():
219%  op_move_16(is_object="1")
220
221%def op_move_object_from16():
222%  op_move_from16(is_object="1")
223
224%def op_move_result(is_object="0"):
225    /* for: move-result, move-result-object */
226    /* op vAA */
227    movl    OFF_FP_RESULT_REGISTER(rFP), %eax    # get pointer to result JType.
228    movl    (%eax), %eax                    # r0 <- result.i.
229    .if $is_object
230    SET_VREG_OBJECT %eax, rINST             # fp[A] <- fp[B]
231    .else
232    SET_VREG %eax, rINST                    # fp[A] <- fp[B]
233    .endif
234    ADVANCE_PC_FETCH_AND_GOTO_NEXT 1
235
236%def op_move_result_object():
237%  op_move_result(is_object="1")
238
239%def op_move_result_wide():
240    /* move-result-wide vAA */
241    movl    OFF_FP_RESULT_REGISTER(rFP), %eax    # get pointer to result JType.
242    movl    4(%eax), %ecx                   # Get high
243    movl    (%eax), %eax                    # Get low
244    SET_VREG %eax, rINST                    # v[AA+0] <- eax
245    SET_VREG_HIGH %ecx, rINST               # v[AA+1] <- ecx
246    ADVANCE_PC_FETCH_AND_GOTO_NEXT 1
247
248%def op_move_wide():
249    /* move-wide vA, vB */
250    /* NOTE: regs can overlap, e.g. "move v6,v7" or "move v7,v6" */
251    movzbl  rINSTbl, %ecx                   # ecx <- BA
252    sarl    $$4, rINST                      # rINST <- B
253    andb    $$0xf, %cl                      # ecx <- A
254    GET_WIDE_FP_VREG %xmm0, rINST           # xmm0 <- v[B]
255    SET_WIDE_FP_VREG %xmm0, %ecx            # v[A] <- xmm0
256    ADVANCE_PC_FETCH_AND_GOTO_NEXT 1
257
258%def op_move_wide_16():
259    /* move-wide/16 vAAAA, vBBBB */
260    /* NOTE: regs can overlap, e.g. "move v6,v7" or "move v7,v6" */
261    movzwl  4(rPC), %ecx                    # ecx<- BBBB
262    movzwl  2(rPC), %eax                    # eax<- AAAA
263    GET_WIDE_FP_VREG %xmm0, %ecx            # xmm0 <- v[B]
264    SET_WIDE_FP_VREG %xmm0, %eax            # v[A] <- xmm0
265    ADVANCE_PC_FETCH_AND_GOTO_NEXT 3
266
267%def op_move_wide_from16():
268    /* move-wide/from16 vAA, vBBBB */
269    /* NOTE: regs can overlap, e.g. "move v6,v7" or "move v7,v6" */
270    movzwl  2(rPC), %ecx                    # ecx <- BBBB
271    movzbl  rINSTbl, %eax                   # eax <- AAAA
272    GET_WIDE_FP_VREG %xmm0, %ecx            # xmm0 <- v[B]
273    SET_WIDE_FP_VREG %xmm0, %eax            # v[A] <- xmm0
274    ADVANCE_PC_FETCH_AND_GOTO_NEXT 2
275
276%def op_nop():
277    ADVANCE_PC_FETCH_AND_GOTO_NEXT 1
278
279%def op_unused_3e():
280%  unused()
281
282%def op_unused_3f():
283%  unused()
284
285%def op_unused_40():
286%  unused()
287
288%def op_unused_41():
289%  unused()
290
291%def op_unused_42():
292%  unused()
293
294%def op_unused_43():
295%  unused()
296
297%def op_unused_79():
298%  unused()
299
300%def op_unused_7a():
301%  unused()
302
303%def op_unused_f3():
304%  unused()
305
306%def op_unused_f4():
307%  unused()
308
309%def op_unused_f5():
310%  unused()
311
312%def op_unused_f6():
313%  unused()
314
315%def op_unused_f7():
316%  unused()
317
318%def op_unused_f8():
319%  unused()
320
321%def op_unused_f9():
322%  unused()
323
324%def op_unused_fc():
325%  unused()
326
327%def op_unused_fd():
328%  unused()
329