2 * Stack-less Just-In-Time compiler
4 * Copyright Zoltan Herczeg (hzmester@freemail.hu). All rights reserved.
6 * Redistribution and use in source and binary forms, with or without modification, are
7 * permitted provided that the following conditions are met:
9 * 1. Redistributions of source code must retain the above copyright notice, this list of
10 * conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
13 * of conditions and the following disclaimer in the documentation and/or other materials
14 * provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND CONTRIBUTORS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19 * SHALL THE COPYRIGHT HOLDER(S) OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
22 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
24 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 SLJIT_API_FUNC_ATTRIBUTE
const char* sljit_get_platform_name(void)
29 return "SPARC" SLJIT_CPUINFO
;
32 /* Length of an instruction word
33 Both for sparc-32 and sparc-64 */
34 typedef sljit_u32 sljit_ins
;
36 #if (defined SLJIT_CACHE_FLUSH_OWN_IMPL && SLJIT_CACHE_FLUSH_OWN_IMPL)
38 static void sparc_cache_flush(sljit_ins
*from
, sljit_ins
*to
)
40 #if defined(__SUNPRO_C) && __SUNPRO_C < 0x590
42 /* if (from == to) return */
47 /* loop until from >= to */
55 /* The comparison was done above. */
57 /* nop is not necessary here, since the
58 sub operation has no side effect. */
64 if (SLJIT_UNLIKELY(from
== to
))
72 /* Operates at least on doubleword. */
77 /* Flush the last word. */
87 #endif /* (defined SLJIT_CACHE_FLUSH_OWN_IMPL && SLJIT_CACHE_FLUSH_OWN_IMPL) */
89 /* TMP_REG2 is not used by getput_arg */
90 #define TMP_REG1 (SLJIT_NUMBER_OF_REGISTERS + 2)
91 #define TMP_REG2 (SLJIT_NUMBER_OF_REGISTERS + 3)
92 #define TMP_REG3 (SLJIT_NUMBER_OF_REGISTERS + 4)
93 /* This register is modified by calls, which affects the instruction
94 in the delay slot if it is used as a source register. */
95 #define TMP_LINK (SLJIT_NUMBER_OF_REGISTERS + 5)
97 #define TMP_FREG1 (SLJIT_NUMBER_OF_FLOAT_REGISTERS + 1)
98 #define TMP_FREG2 (SLJIT_NUMBER_OF_FLOAT_REGISTERS + 2)
100 static const sljit_u8 reg_map
[SLJIT_NUMBER_OF_REGISTERS
+ 6] = {
101 0, 8, 9, 10, 11, 23, 22, 21, 20, 19, 18, 17, 16, 29, 28, 27, 26, 25, 24, 14, 1, 12, 13, 15
104 static const sljit_u8 freg_map
[SLJIT_NUMBER_OF_FLOAT_REGISTERS
+ 3] = {
105 0, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30
108 /* --------------------------------------------------------------------- */
109 /* Instrucion forms */
110 /* --------------------------------------------------------------------- */
112 #define D(d) ((sljit_ins)reg_map[d] << 25)
113 #define FD(d) ((sljit_ins)freg_map[d] << 25)
114 #define FDN(d) (((sljit_ins)freg_map[d] | 0x1) << 25)
115 #define DA(d) ((sljit_ins)(d) << 25)
116 #define S1(s1) ((sljit_ins)reg_map[s1] << 14)
117 #define FS1(s1) ((sljit_ins)freg_map[s1] << 14)
118 #define S1A(s1) ((sljit_ins)(s1) << 14)
119 #define S2(s2) ((sljit_ins)reg_map[s2])
120 #define FS2(s2) ((sljit_ins)freg_map[s2])
121 #define FS2N(s2) ((sljit_ins)freg_map[s2] | 0x1)
122 #define S2A(s2) ((sljit_ins)(s2))
123 #define IMM_ARG 0x2000
124 #define DOP(op) ((sljit_ins)(op) << 5)
125 #define IMM(imm) (((sljit_ins)(imm) & 0x1fff) | IMM_ARG)
127 #define DR(dr) (reg_map[dr])
128 #define DRF(dr, flags) ((sljit_s32)(reg_map[dr] | ((flags) & SET_FLAGS)))
129 #define OPC1(opcode) ((sljit_ins)(opcode) << 30)
130 #define OPC2(opcode) ((sljit_ins)(opcode) << 22)
131 #define OPC3(opcode) ((sljit_ins)(opcode) << 19)
132 #define SET_FLAGS OPC3(0x10)
134 #define ADD (OPC1(0x2) | OPC3(0x00))
135 #define ADDC (OPC1(0x2) | OPC3(0x08))
136 #define AND (OPC1(0x2) | OPC3(0x01))
137 #define ANDN (OPC1(0x2) | OPC3(0x05))
138 #define CALL (OPC1(0x1))
139 #define FABSS (OPC1(0x2) | OPC3(0x34) | DOP(0x09))
140 #define FADDD (OPC1(0x2) | OPC3(0x34) | DOP(0x42))
141 #define FADDS (OPC1(0x2) | OPC3(0x34) | DOP(0x41))
142 #define FCMPD (OPC1(0x2) | OPC3(0x35) | DOP(0x52))
143 #define FCMPS (OPC1(0x2) | OPC3(0x35) | DOP(0x51))
144 #define FDIVD (OPC1(0x2) | OPC3(0x34) | DOP(0x4e))
145 #define FDIVS (OPC1(0x2) | OPC3(0x34) | DOP(0x4d))
146 #define FDTOI (OPC1(0x2) | OPC3(0x34) | DOP(0xd2))
147 #define FDTOS (OPC1(0x2) | OPC3(0x34) | DOP(0xc6))
148 #define FITOD (OPC1(0x2) | OPC3(0x34) | DOP(0xc8))
149 #define FITOS (OPC1(0x2) | OPC3(0x34) | DOP(0xc4))
150 #define FMOVS (OPC1(0x2) | OPC3(0x34) | DOP(0x01))
151 #define FMULD (OPC1(0x2) | OPC3(0x34) | DOP(0x4a))
152 #define FMULS (OPC1(0x2) | OPC3(0x34) | DOP(0x49))
153 #define FNEGS (OPC1(0x2) | OPC3(0x34) | DOP(0x05))
154 #define FSTOD (OPC1(0x2) | OPC3(0x34) | DOP(0xc9))
155 #define FSTOI (OPC1(0x2) | OPC3(0x34) | DOP(0xd1))
156 #define FSUBD (OPC1(0x2) | OPC3(0x34) | DOP(0x46))
157 #define FSUBS (OPC1(0x2) | OPC3(0x34) | DOP(0x45))
158 #define JMPL (OPC1(0x2) | OPC3(0x38))
159 #define LDD (OPC1(0x3) | OPC3(0x03))
160 #define LDDF (OPC1(0x3) | OPC3(0x23))
161 #define LDF (OPC1(0x3) | OPC3(0x20))
162 #define LDUW (OPC1(0x3) | OPC3(0x00))
163 #define NOP (OPC1(0x0) | OPC2(0x04))
164 #define OR (OPC1(0x2) | OPC3(0x02))
165 #define ORN (OPC1(0x2) | OPC3(0x06))
166 #define RDY (OPC1(0x2) | OPC3(0x28) | S1A(0))
167 #define RESTORE (OPC1(0x2) | OPC3(0x3d))
168 #define SAVE (OPC1(0x2) | OPC3(0x3c))
169 #define SETHI (OPC1(0x0) | OPC2(0x04))
170 #define SLL (OPC1(0x2) | OPC3(0x25))
171 #define SLLX (OPC1(0x2) | OPC3(0x25) | (1 << 12))
172 #define SRA (OPC1(0x2) | OPC3(0x27))
173 #define SRAX (OPC1(0x2) | OPC3(0x27) | (1 << 12))
174 #define SRL (OPC1(0x2) | OPC3(0x26))
175 #define SRLX (OPC1(0x2) | OPC3(0x26) | (1 << 12))
176 #define STD (OPC1(0x3) | OPC3(0x07))
177 #define STDF (OPC1(0x3) | OPC3(0x27))
178 #define STF (OPC1(0x3) | OPC3(0x24))
179 #define STW (OPC1(0x3) | OPC3(0x04))
180 #define SUB (OPC1(0x2) | OPC3(0x04))
181 #define SUBC (OPC1(0x2) | OPC3(0x0c))
182 #define TA (OPC1(0x2) | OPC3(0x3a) | (8 << 25))
183 #define WRY (OPC1(0x2) | OPC3(0x30) | DA(0))
184 #define XOR (OPC1(0x2) | OPC3(0x03))
185 #define XNOR (OPC1(0x2) | OPC3(0x07))
187 #if (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
188 #define MAX_DISP (0x1fffff)
189 #define MIN_DISP (-0x200000)
190 #define DISP_MASK ((sljit_ins)0x3fffff)
192 #define BICC (OPC1(0x0) | OPC2(0x2))
193 #define FBFCC (OPC1(0x0) | OPC2(0x6))
195 #define SDIV (OPC1(0x2) | OPC3(0x0f))
196 #define SMUL (OPC1(0x2) | OPC3(0x0b))
197 #define UDIV (OPC1(0x2) | OPC3(0x0e))
198 #define UMUL (OPC1(0x2) | OPC3(0x0a))
203 #define SIMM_MAX (0x0fff)
204 #define SIMM_MIN (-0x1000)
206 /* dest_reg is the absolute name of the register
207 Useful for reordering instructions in the delay slot. */
208 static sljit_s32
push_inst(struct sljit_compiler
*compiler
, sljit_ins ins
, sljit_s32 delay_slot
)
211 SLJIT_ASSERT((delay_slot
& DST_INS_MASK
) == UNMOVABLE_INS
212 || (delay_slot
& DST_INS_MASK
) == MOVABLE_INS
213 || (delay_slot
& DST_INS_MASK
) == ((ins
>> 25) & 0x1f));
214 ptr
= (sljit_ins
*)ensure_buf(compiler
, sizeof(sljit_ins
));
218 compiler
->delay_slot
= delay_slot
;
219 return SLJIT_SUCCESS
;
222 static SLJIT_INLINE sljit_ins
* detect_jump_type(struct sljit_jump
*jump
, sljit_ins
*code_ptr
, sljit_ins
*code
, sljit_sw executable_offset
)
225 sljit_uw target_addr
;
227 sljit_ins saved_inst
;
229 if (jump
->flags
& SLJIT_REWRITABLE_JUMP
)
232 if (jump
->flags
& JUMP_ADDR
)
233 target_addr
= jump
->u
.target
;
235 SLJIT_ASSERT(jump
->flags
& JUMP_LABEL
);
236 target_addr
= (sljit_uw
)(code
+ jump
->u
.label
->size
) + (sljit_uw
)executable_offset
;
238 inst
= (sljit_ins
*)jump
->addr
;
240 #if (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
241 if (jump
->flags
& IS_CALL
) {
242 /* Call is always patchable on sparc 32. */
243 jump
->flags
|= PATCH_CALL
;
244 if (jump
->flags
& IS_MOVABLE
) {
247 jump
->addr
-= sizeof(sljit_ins
);
255 /* Both calls and BPr instructions shall not pass this point. */
256 #error "Implementation required"
259 if (jump
->flags
& IS_COND
)
262 diff
= ((sljit_sw
)target_addr
- (sljit_sw
)(inst
- 1) - executable_offset
) >> 2;
264 if (jump
->flags
& IS_MOVABLE
) {
265 if (diff
<= MAX_DISP
&& diff
>= MIN_DISP
) {
266 jump
->flags
|= PATCH_B
;
268 if (jump
->flags
& IS_COND
) {
269 saved_inst
= inst
[0];
270 inst
[0] = inst
[1] ^ (1 << 28);
271 inst
[1] = saved_inst
;
274 inst
[0] = BICC
| DA(0x8);
276 jump
->addr
= (sljit_uw
)inst
;
281 diff
+= SSIZE_OF(ins
);
283 if (diff
<= MAX_DISP
&& diff
>= MIN_DISP
) {
284 jump
->flags
|= PATCH_B
;
285 if (jump
->flags
& IS_COND
)
286 inst
[0] ^= (1 << 28);
288 inst
[0] = BICC
| DA(0x8);
290 jump
->addr
= (sljit_uw
)inst
;
297 SLJIT_API_FUNC_ATTRIBUTE
void* sljit_generate_code(struct sljit_compiler
*compiler
)
299 struct sljit_memory_fragment
*buf
;
306 sljit_sw executable_offset
;
309 struct sljit_label
*label
;
310 struct sljit_jump
*jump
;
311 struct sljit_const
*const_
;
312 struct sljit_put_label
*put_label
;
315 CHECK_PTR(check_sljit_generate_code(compiler
));
316 reverse_buf(compiler
);
318 code
= (sljit_ins
*)SLJIT_MALLOC_EXEC(compiler
->size
* sizeof(sljit_ins
), compiler
->exec_allocator_data
);
319 PTR_FAIL_WITH_EXEC_IF(code
);
325 executable_offset
= SLJIT_EXEC_OFFSET(code
);
327 label
= compiler
->labels
;
328 jump
= compiler
->jumps
;
329 const_
= compiler
->consts
;
330 put_label
= compiler
->put_labels
;
333 buf_ptr
= (sljit_ins
*)buf
->memory
;
334 buf_end
= buf_ptr
+ (buf
->used_size
>> 2);
336 *code_ptr
= *buf_ptr
++;
337 if (next_addr
== word_count
) {
338 SLJIT_ASSERT(!label
|| label
->size
>= word_count
);
339 SLJIT_ASSERT(!jump
|| jump
->addr
>= word_count
);
340 SLJIT_ASSERT(!const_
|| const_
->addr
>= word_count
);
341 SLJIT_ASSERT(!put_label
|| put_label
->addr
>= word_count
);
343 /* These structures are ordered by their address. */
344 if (label
&& label
->size
== word_count
) {
345 /* Just recording the address. */
346 label
->addr
= (sljit_uw
)SLJIT_ADD_EXEC_OFFSET(code_ptr
, executable_offset
);
347 label
->size
= (sljit_uw
)(code_ptr
- code
);
350 if (jump
&& jump
->addr
== word_count
) {
351 #if (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
352 jump
->addr
= (sljit_uw
)(code_ptr
- 3);
354 jump
->addr
= (sljit_uw
)(code_ptr
- 6);
356 code_ptr
= detect_jump_type(jump
, code_ptr
, code
, executable_offset
);
359 if (const_
&& const_
->addr
== word_count
) {
360 /* Just recording the address. */
361 const_
->addr
= (sljit_uw
)code_ptr
;
362 const_
= const_
->next
;
364 if (put_label
&& put_label
->addr
== word_count
) {
365 SLJIT_ASSERT(put_label
->label
);
366 put_label
->addr
= (sljit_uw
)code_ptr
;
367 put_label
= put_label
->next
;
369 next_addr
= compute_next_addr(label
, jump
, const_
, put_label
);
373 } while (buf_ptr
< buf_end
);
378 if (label
&& label
->size
== word_count
) {
379 label
->addr
= (sljit_uw
)SLJIT_ADD_EXEC_OFFSET(code_ptr
, executable_offset
);
380 label
->size
= (sljit_uw
)(code_ptr
- code
);
384 SLJIT_ASSERT(!label
);
386 SLJIT_ASSERT(!const_
);
387 SLJIT_ASSERT(!put_label
);
388 SLJIT_ASSERT(code_ptr
- code
<= (sljit_s32
)compiler
->size
);
390 jump
= compiler
->jumps
;
393 addr
= (sljit_sw
)((jump
->flags
& JUMP_LABEL
) ? jump
->u
.label
->addr
: jump
->u
.target
);
394 buf_ptr
= (sljit_ins
*)jump
->addr
;
396 if (jump
->flags
& PATCH_CALL
) {
397 addr
= (addr
- (sljit_sw
)SLJIT_ADD_EXEC_OFFSET(buf_ptr
, executable_offset
)) >> 2;
398 SLJIT_ASSERT(addr
<= 0x1fffffff && addr
>= -0x20000000);
399 buf_ptr
[0] = CALL
| ((sljit_ins
)addr
& 0x3fffffff);
402 if (jump
->flags
& PATCH_B
) {
403 addr
= (addr
- (sljit_sw
)SLJIT_ADD_EXEC_OFFSET(buf_ptr
, executable_offset
)) >> 2;
404 SLJIT_ASSERT(addr
<= MAX_DISP
&& addr
>= MIN_DISP
);
405 buf_ptr
[0] = (buf_ptr
[0] & ~DISP_MASK
) | ((sljit_ins
)addr
& DISP_MASK
);
409 /* Set the fields of immediate loads. */
410 #if (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
411 SLJIT_ASSERT(((buf_ptr
[0] & 0xc1cfffff) == 0x01000000) && ((buf_ptr
[1] & 0xc1f83fff) == 0x80102000));
412 buf_ptr
[0] |= (sljit_ins
)(addr
>> 10) & 0x3fffff;
413 buf_ptr
[1] |= (sljit_ins
)addr
& 0x3ff;
415 #error "Implementation required"
421 put_label
= compiler
->put_labels
;
423 addr
= (sljit_sw
)put_label
->label
->addr
;
424 buf_ptr
= (sljit_ins
*)put_label
->addr
;
426 #if (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
427 SLJIT_ASSERT(((buf_ptr
[0] & 0xc1cfffff) == 0x01000000) && ((buf_ptr
[1] & 0xc1f83fff) == 0x80102000));
428 buf_ptr
[0] |= (addr
>> 10) & 0x3fffff;
429 buf_ptr
[1] |= addr
& 0x3ff;
431 #error "Implementation required"
433 put_label
= put_label
->next
;
436 compiler
->error
= SLJIT_ERR_COMPILED
;
437 compiler
->executable_offset
= executable_offset
;
438 compiler
->executable_size
= (sljit_uw
)(code_ptr
- code
) * sizeof(sljit_ins
);
440 code
= (sljit_ins
*)SLJIT_ADD_EXEC_OFFSET(code
, executable_offset
);
441 code_ptr
= (sljit_ins
*)SLJIT_ADD_EXEC_OFFSET(code_ptr
, executable_offset
);
443 SLJIT_CACHE_FLUSH(code
, code_ptr
);
444 SLJIT_UPDATE_WX_FLAGS(code
, code_ptr
, 1);
448 SLJIT_API_FUNC_ATTRIBUTE sljit_s32
sljit_has_cpu_feature(sljit_s32 feature_type
)
450 switch (feature_type
) {
452 #ifdef SLJIT_IS_FPU_AVAILABLE
453 return SLJIT_IS_FPU_AVAILABLE
;
455 /* Available by default. */
459 case SLJIT_HAS_ZERO_REGISTER
:
462 #if (defined SLJIT_CONFIG_SPARC_64 && SLJIT_CONFIG_SPARC_64)
472 SLJIT_API_FUNC_ATTRIBUTE sljit_s32
sljit_cmp_info(sljit_s32 type
)
474 return (type
>= SLJIT_UNORDERED
&& type
<= SLJIT_ORDERED_LESS_EQUAL
);
477 /* --------------------------------------------------------------------- */
479 /* --------------------------------------------------------------------- */
481 /* Creates an index in data_transfer_insts array. */
482 #define LOAD_DATA 0x01
483 #define WORD_DATA 0x00
484 #define BYTE_DATA 0x02
485 #define HALF_DATA 0x04
486 #define INT_DATA 0x06
487 #define SIGNED_DATA 0x08
488 /* Separates integer and floating point registers */
490 #define DOUBLE_DATA 0x10
491 #define SINGLE_DATA 0x12
493 #define MEM_MASK 0x1f
495 #define ARG_TEST 0x00020
496 #define ALT_KEEP_CACHE 0x00040
497 #define CUMULATIVE_OP 0x00080
498 #define IMM_OP 0x00100
499 #define MOVE_OP 0x00200
500 #define SRC2_IMM 0x00400
502 #define REG_DEST 0x00800
503 #define REG2_SOURCE 0x01000
504 #define SLOW_SRC1 0x02000
505 #define SLOW_SRC2 0x04000
506 #define SLOW_DEST 0x08000
508 /* SET_FLAGS (0x10 << 19) also belong here! */
510 #if (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
511 #include "sljitNativeSPARC_32.c"
513 #include "sljitNativeSPARC_64.c"
516 SLJIT_API_FUNC_ATTRIBUTE sljit_s32
sljit_emit_enter(struct sljit_compiler
*compiler
,
517 sljit_s32 options
, sljit_s32 arg_types
, sljit_s32 scratches
, sljit_s32 saveds
,
518 sljit_s32 fscratches
, sljit_s32 fsaveds
, sljit_s32 local_size
)
520 sljit_s32 reg_index
, types
, tmp
;
521 sljit_u32 float_offset
, args_offset
;
522 sljit_s32 saved_arg_index
, scratch_arg_index
, float_arg_index
;
525 CHECK(check_sljit_emit_enter(compiler
, options
, arg_types
, scratches
, saveds
, fscratches
, fsaveds
, local_size
));
526 set_emit_enter(compiler
, options
, arg_types
, scratches
, saveds
, fscratches
, fsaveds
, local_size
);
528 local_size
= (local_size
+ SLJIT_LOCALS_OFFSET
+ 7) & ~0x7;
529 compiler
->local_size
= local_size
;
531 if (local_size
<= -SIMM_MIN
) {
532 FAIL_IF(push_inst(compiler
, SAVE
| D(SLJIT_SP
) | S1(SLJIT_SP
) | IMM(-local_size
), UNMOVABLE_INS
));
535 FAIL_IF(load_immediate(compiler
, TMP_REG1
, -local_size
));
536 FAIL_IF(push_inst(compiler
, SAVE
| D(SLJIT_SP
) | S1(SLJIT_SP
) | S2(TMP_REG1
), UNMOVABLE_INS
));
539 arg_types
>>= SLJIT_ARG_SHIFT
;
542 float_offset
= 16 * sizeof(sljit_sw
);
545 while (types
&& reg_index
< 24 + 6) {
546 switch (types
& SLJIT_ARG_MASK
) {
547 case SLJIT_ARG_TYPE_F64
:
548 if (reg_index
& 0x1) {
549 FAIL_IF(push_inst(compiler
, STW
| DA(reg_index
) | S1(SLJIT_SP
) | IMM(float_offset
), MOVABLE_INS
));
550 if (reg_index
>= 24 + 6 - 1)
552 FAIL_IF(push_inst(compiler
, STW
| DA(reg_index
+ 1) | S1(SLJIT_SP
) | IMM(float_offset
+ sizeof(sljit_sw
)), MOVABLE_INS
));
554 FAIL_IF(push_inst(compiler
, STD
| DA(reg_index
) | S1(SLJIT_SP
) | IMM(float_offset
), MOVABLE_INS
));
556 float_offset
+= sizeof(sljit_f64
);
559 case SLJIT_ARG_TYPE_F32
:
560 FAIL_IF(push_inst(compiler
, STW
| DA(reg_index
) | S1(SLJIT_SP
) | IMM(float_offset
), MOVABLE_INS
));
561 float_offset
+= sizeof(sljit_f64
);
566 types
>>= SLJIT_ARG_SHIFT
;
569 args_offset
= (16 + 1 + 6) * sizeof(sljit_sw
);
570 float_offset
= 16 * sizeof(sljit_sw
);
572 saved_arg_index
= 24;
573 scratch_arg_index
= 8 - 1;
577 switch (arg_types
& SLJIT_ARG_MASK
) {
578 case SLJIT_ARG_TYPE_F64
:
579 if (reg_index
< 24 + 6 - 1) {
580 FAIL_IF(push_inst(compiler
, LDDF
| FD(float_arg_index
) | S1(SLJIT_SP
) | IMM(float_offset
), MOVABLE_INS
));
581 } else if (reg_index
< 24 + 6) {
582 FAIL_IF(push_inst(compiler
, LDF
| FD(float_arg_index
) | S1(SLJIT_SP
) | IMM(float_offset
), MOVABLE_INS
));
583 FAIL_IF(push_inst(compiler
, LDF
| FD(float_arg_index
) | (1 << 25) | S1A(30) | IMM(args_offset
), MOVABLE_INS
));
585 FAIL_IF(push_inst(compiler
, LDF
| FD(float_arg_index
) | S1A(30) | IMM(args_offset
), MOVABLE_INS
));
586 FAIL_IF(push_inst(compiler
, LDF
| FD(float_arg_index
) | (1 << 25) | S1A(30) | IMM(args_offset
+ sizeof(sljit_sw
)), MOVABLE_INS
));
590 float_offset
+= sizeof(sljit_f64
);
593 case SLJIT_ARG_TYPE_F32
:
594 if (reg_index
< 24 + 6)
595 FAIL_IF(push_inst(compiler
, LDF
| FD(float_arg_index
) | S1(SLJIT_SP
) | IMM(float_offset
), MOVABLE_INS
));
597 FAIL_IF(push_inst(compiler
, LDF
| FD(float_arg_index
) | S1A(30) | IMM(args_offset
), MOVABLE_INS
));
599 float_offset
+= sizeof(sljit_f64
);
604 if (!(arg_types
& SLJIT_ARG_TYPE_SCRATCH_REG
)) {
605 tmp
= saved_arg_index
++;
606 if (tmp
== reg_index
)
609 tmp
= scratch_arg_index
;
611 if (reg_index
< 24 + 6)
612 FAIL_IF(push_inst(compiler
, OR
| DA(tmp
) | S1(0) | S2A(reg_index
), tmp
));
614 FAIL_IF(push_inst(compiler
, LDUW
| DA(tmp
) | S1A(30) | IMM(args_offset
), tmp
));
619 arg_types
>>= SLJIT_ARG_SHIFT
;
622 return SLJIT_SUCCESS
;
625 SLJIT_API_FUNC_ATTRIBUTE sljit_s32
sljit_set_context(struct sljit_compiler
*compiler
,
626 sljit_s32 options
, sljit_s32 arg_types
, sljit_s32 scratches
, sljit_s32 saveds
,
627 sljit_s32 fscratches
, sljit_s32 fsaveds
, sljit_s32 local_size
)
630 CHECK(check_sljit_set_context(compiler
, options
, arg_types
, scratches
, saveds
, fscratches
, fsaveds
, local_size
));
631 set_set_context(compiler
, options
, arg_types
, scratches
, saveds
, fscratches
, fsaveds
, local_size
);
633 compiler
->local_size
= (local_size
+ SLJIT_LOCALS_OFFSET
+ 7) & ~0x7;
634 return SLJIT_SUCCESS
;
637 SLJIT_API_FUNC_ATTRIBUTE sljit_s32
sljit_emit_return_void(struct sljit_compiler
*compiler
)
640 CHECK(check_sljit_emit_return_void(compiler
));
642 FAIL_IF(push_inst(compiler
, JMPL
| D(0) | S1A(31) | IMM(8), UNMOVABLE_INS
));
643 return push_inst(compiler
, RESTORE
| D(SLJIT_R0
) | S1(SLJIT_R0
) | S2(0), UNMOVABLE_INS
);
646 SLJIT_API_FUNC_ATTRIBUTE sljit_s32
sljit_emit_return(struct sljit_compiler
*compiler
, sljit_s32 op
, sljit_s32 src
, sljit_sw srcw
)
649 CHECK(check_sljit_emit_return(compiler
, op
, src
, srcw
));
651 if (TYPE_CAST_NEEDED(op
) || !FAST_IS_REG(src
)) {
652 FAIL_IF(emit_mov_before_return(compiler
, op
, src
, srcw
));
656 FAIL_IF(push_inst(compiler
, JMPL
| D(0) | S1A(31) | IMM(8), UNMOVABLE_INS
));
657 return push_inst(compiler
, RESTORE
| D(SLJIT_R0
) | S1(src
) | S2(0), UNMOVABLE_INS
);
660 /* --------------------------------------------------------------------- */
662 /* --------------------------------------------------------------------- */
664 #if (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
665 #define ARCH_32_64(a, b) a
667 #define ARCH_32_64(a, b) b
670 static const sljit_ins data_transfer_insts
[16 + 4] = {
671 /* u w s */ ARCH_32_64(OPC1(3) | OPC3(0x04) /* stw */, OPC1(3) | OPC3(0x0e) /* stx */),
672 /* u w l */ ARCH_32_64(OPC1(3) | OPC3(0x00) /* lduw */, OPC1(3) | OPC3(0x0b) /* ldx */),
673 /* u b s */ OPC1(3) | OPC3(0x05) /* stb */,
674 /* u b l */ OPC1(3) | OPC3(0x01) /* ldub */,
675 /* u h s */ OPC1(3) | OPC3(0x06) /* sth */,
676 /* u h l */ OPC1(3) | OPC3(0x02) /* lduh */,
677 /* u i s */ OPC1(3) | OPC3(0x04) /* stw */,
678 /* u i l */ OPC1(3) | OPC3(0x00) /* lduw */,
680 /* s w s */ ARCH_32_64(OPC1(3) | OPC3(0x04) /* stw */, OPC1(3) | OPC3(0x0e) /* stx */),
681 /* s w l */ ARCH_32_64(OPC1(3) | OPC3(0x00) /* lduw */, OPC1(3) | OPC3(0x0b) /* ldx */),
682 /* s b s */ OPC1(3) | OPC3(0x05) /* stb */,
683 /* s b l */ OPC1(3) | OPC3(0x09) /* ldsb */,
684 /* s h s */ OPC1(3) | OPC3(0x06) /* sth */,
685 /* s h l */ OPC1(3) | OPC3(0x0a) /* ldsh */,
686 /* s i s */ OPC1(3) | OPC3(0x04) /* stw */,
687 /* s i l */ ARCH_32_64(OPC1(3) | OPC3(0x00) /* lduw */, OPC1(3) | OPC3(0x08) /* ldsw */),
689 /* d s */ OPC1(3) | OPC3(0x27),
690 /* d l */ OPC1(3) | OPC3(0x23),
691 /* s s */ OPC1(3) | OPC3(0x24),
692 /* s l */ OPC1(3) | OPC3(0x20),
697 /* Can perform an operation using at most 1 instruction. */
698 static sljit_s32
getput_arg_fast(struct sljit_compiler
*compiler
, sljit_u32 flags
, sljit_s32 reg
, sljit_s32 arg
, sljit_sw argw
)
700 SLJIT_ASSERT(arg
& SLJIT_MEM
);
702 if ((!(arg
& OFFS_REG_MASK
) && argw
<= SIMM_MAX
&& argw
>= SIMM_MIN
)
703 || ((arg
& OFFS_REG_MASK
) && (argw
& 0x3) == 0)) {
704 /* Works for both absoulte and relative addresses (immediate case). */
705 if (SLJIT_UNLIKELY(flags
& ARG_TEST
))
707 FAIL_IF(push_inst(compiler
, data_transfer_insts
[flags
& MEM_MASK
]
708 | ((flags
& MEM_MASK
) <= GPR_REG
? D(reg
) : FD(reg
))
709 | S1(arg
& REG_MASK
) | ((arg
& OFFS_REG_MASK
) ? S2(OFFS_REG(arg
)) : IMM(argw
)),
710 ((flags
& MEM_MASK
) <= GPR_REG
&& (flags
& LOAD_DATA
)) ? DR(reg
) : MOVABLE_INS
));
716 /* See getput_arg below.
717 Note: can_cache is called only for binary operators. Those
718 operators always uses word arguments without write back. */
719 static sljit_s32
can_cache(sljit_s32 arg
, sljit_sw argw
, sljit_s32 next_arg
, sljit_sw next_argw
)
721 SLJIT_ASSERT((arg
& SLJIT_MEM
) && (next_arg
& SLJIT_MEM
));
723 /* Simple operation except for updates. */
724 if (arg
& OFFS_REG_MASK
) {
728 if ((arg
& OFFS_REG_MASK
) == (next_arg
& OFFS_REG_MASK
) && argw
== next_argw
)
733 if (((next_argw
- argw
) <= SIMM_MAX
&& (next_argw
- argw
) >= SIMM_MIN
))
738 /* Emit the necessary instructions. See can_cache above. */
739 static sljit_s32
getput_arg(struct sljit_compiler
*compiler
, sljit_u32 flags
, sljit_s32 reg
, sljit_s32 arg
, sljit_sw argw
, sljit_s32 next_arg
, sljit_sw next_argw
)
741 sljit_s32 base
, arg2
, delay_slot
;
744 SLJIT_ASSERT(arg
& SLJIT_MEM
);
745 if (!(next_arg
& SLJIT_MEM
)) {
750 base
= arg
& REG_MASK
;
751 if (SLJIT_UNLIKELY(arg
& OFFS_REG_MASK
)) {
754 /* Using the cache. */
755 if (((SLJIT_MEM
| (arg
& OFFS_REG_MASK
)) == compiler
->cache_arg
) && (argw
== compiler
->cache_argw
))
758 if ((arg
& OFFS_REG_MASK
) == (next_arg
& OFFS_REG_MASK
) && argw
== (next_argw
& 0x3)) {
759 compiler
->cache_arg
= SLJIT_MEM
| (arg
& OFFS_REG_MASK
);
760 compiler
->cache_argw
= argw
;
763 else if ((flags
& LOAD_DATA
) && ((flags
& MEM_MASK
) <= GPR_REG
) && reg
!= base
&& reg
!= OFFS_REG(arg
))
765 else /* It must be a mov operation, so tmp1 must be free to use. */
767 FAIL_IF(push_inst(compiler
, SLL_W
| D(arg2
) | S1(OFFS_REG(arg
)) | IMM_ARG
| (sljit_ins
)argw
, DR(arg2
)));
771 /* Using the cache. */
772 if ((compiler
->cache_arg
== SLJIT_MEM
) && (argw
- compiler
->cache_argw
) <= SIMM_MAX
&& (argw
- compiler
->cache_argw
) >= SIMM_MIN
) {
773 if (argw
!= compiler
->cache_argw
) {
774 FAIL_IF(push_inst(compiler
, ADD
| D(TMP_REG3
) | S1(TMP_REG3
) | IMM(argw
- compiler
->cache_argw
), DR(TMP_REG3
)));
775 compiler
->cache_argw
= argw
;
779 if ((next_argw
- argw
) <= SIMM_MAX
&& (next_argw
- argw
) >= SIMM_MIN
) {
780 compiler
->cache_arg
= SLJIT_MEM
;
781 compiler
->cache_argw
= argw
;
784 else if ((flags
& LOAD_DATA
) && ((flags
& MEM_MASK
) <= GPR_REG
) && reg
!= base
)
786 else /* It must be a mov operation, so tmp1 must be free to use. */
788 FAIL_IF(load_immediate(compiler
, arg2
, argw
));
792 dest
= ((flags
& MEM_MASK
) <= GPR_REG
? D(reg
) : FD(reg
));
793 delay_slot
= ((flags
& MEM_MASK
) <= GPR_REG
&& (flags
& LOAD_DATA
)) ? DR(reg
) : MOVABLE_INS
;
795 return push_inst(compiler
, data_transfer_insts
[flags
& MEM_MASK
] | dest
| S1(arg2
) | IMM(0), delay_slot
);
796 return push_inst(compiler
, data_transfer_insts
[flags
& MEM_MASK
] | dest
| S1(base
) | S2(arg2
), delay_slot
);
799 static SLJIT_INLINE sljit_s32
emit_op_mem(struct sljit_compiler
*compiler
, sljit_u32 flags
, sljit_s32 reg
, sljit_s32 arg
, sljit_sw argw
)
801 if (getput_arg_fast(compiler
, flags
, reg
, arg
, argw
))
802 return compiler
->error
;
803 compiler
->cache_arg
= 0;
804 compiler
->cache_argw
= 0;
805 return getput_arg(compiler
, flags
, reg
, arg
, argw
, 0, 0);
808 static SLJIT_INLINE sljit_s32
emit_op_mem2(struct sljit_compiler
*compiler
, sljit_u32 flags
, sljit_s32 reg
, sljit_s32 arg1
, sljit_sw arg1w
, sljit_s32 arg2
, sljit_sw arg2w
)
810 if (getput_arg_fast(compiler
, flags
, reg
, arg1
, arg1w
))
811 return compiler
->error
;
812 return getput_arg(compiler
, flags
, reg
, arg1
, arg1w
, arg2
, arg2w
);
815 static sljit_s32
emit_op(struct sljit_compiler
*compiler
, sljit_s32 op
, sljit_u32 flags
,
816 sljit_s32 dst
, sljit_sw dstw
,
817 sljit_s32 src1
, sljit_sw src1w
,
818 sljit_s32 src2
, sljit_sw src2w
)
820 /* arg1 goes to TMP_REG1 or src reg
821 arg2 goes to TMP_REG2, imm or src reg
822 TMP_REG3 can be used for caching
823 result goes to TMP_REG2, so put result can use TMP_REG1 and TMP_REG3. */
824 sljit_s32 dst_r
= TMP_REG2
;
827 sljit_s32 sugg_src2_r
= TMP_REG2
;
829 if (!(flags
& ALT_KEEP_CACHE
)) {
830 compiler
->cache_arg
= 0;
831 compiler
->cache_argw
= 0;
834 if (dst
!= TMP_REG2
) {
835 if (FAST_IS_REG(dst
)) {
841 else if ((dst
& SLJIT_MEM
) && !getput_arg_fast(compiler
, flags
| ARG_TEST
, TMP_REG1
, dst
, dstw
))
845 if (flags
& IMM_OP
) {
846 if ((src2
& SLJIT_IMM
) && src2w
) {
847 if (src2w
<= SIMM_MAX
&& src2w
>= SIMM_MIN
) {
852 if (!(flags
& SRC2_IMM
) && (flags
& CUMULATIVE_OP
) && (src1
& SLJIT_IMM
) && src1w
) {
853 if (src1w
<= SIMM_MAX
&& src1w
>= SIMM_MIN
) {
857 /* And swap arguments. */
861 /* src2w = src2_r unneeded. */
867 if (FAST_IS_REG(src1
))
869 else if (src1
& SLJIT_IMM
) {
871 FAIL_IF(load_immediate(compiler
, TMP_REG1
, src1w
));
878 if (getput_arg_fast(compiler
, flags
| LOAD_DATA
, TMP_REG1
, src1
, src1w
))
879 FAIL_IF(compiler
->error
);
886 if (FAST_IS_REG(src2
)) {
888 flags
|= REG2_SOURCE
;
889 if ((flags
& (REG_DEST
| MOVE_OP
)) == MOVE_OP
)
892 else if (src2
& SLJIT_IMM
) {
893 if (!(flags
& SRC2_IMM
)) {
895 FAIL_IF(load_immediate(compiler
, sugg_src2_r
, src2w
));
896 src2_r
= sugg_src2_r
;
900 if (flags
& MOVE_OP
) {
910 if (getput_arg_fast(compiler
, flags
| LOAD_DATA
, sugg_src2_r
, src2
, src2w
))
911 FAIL_IF(compiler
->error
);
914 src2_r
= sugg_src2_r
;
917 if ((flags
& (SLOW_SRC1
| SLOW_SRC2
)) == (SLOW_SRC1
| SLOW_SRC2
)) {
918 SLJIT_ASSERT(src2_r
== TMP_REG2
);
919 if (!can_cache(src1
, src1w
, src2
, src2w
) && can_cache(src1
, src1w
, dst
, dstw
)) {
920 FAIL_IF(getput_arg(compiler
, flags
| LOAD_DATA
, TMP_REG2
, src2
, src2w
, src1
, src1w
));
921 FAIL_IF(getput_arg(compiler
, flags
| LOAD_DATA
, TMP_REG1
, src1
, src1w
, dst
, dstw
));
924 FAIL_IF(getput_arg(compiler
, flags
| LOAD_DATA
, TMP_REG1
, src1
, src1w
, src2
, src2w
));
925 FAIL_IF(getput_arg(compiler
, flags
| LOAD_DATA
, TMP_REG2
, src2
, src2w
, dst
, dstw
));
928 else if (flags
& SLOW_SRC1
)
929 FAIL_IF(getput_arg(compiler
, flags
| LOAD_DATA
, TMP_REG1
, src1
, src1w
, dst
, dstw
));
930 else if (flags
& SLOW_SRC2
)
931 FAIL_IF(getput_arg(compiler
, flags
| LOAD_DATA
, sugg_src2_r
, src2
, src2w
, dst
, dstw
));
933 FAIL_IF(emit_single_op(compiler
, op
, flags
, dst_r
, src1_r
, src2_r
));
935 if (dst
& SLJIT_MEM
) {
936 if (!(flags
& SLOW_DEST
)) {
937 getput_arg_fast(compiler
, flags
, dst_r
, dst
, dstw
);
938 return compiler
->error
;
940 return getput_arg(compiler
, flags
, dst_r
, dst
, dstw
, 0, 0);
943 return SLJIT_SUCCESS
;
946 SLJIT_API_FUNC_ATTRIBUTE sljit_s32
sljit_emit_op0(struct sljit_compiler
*compiler
, sljit_s32 op
)
949 CHECK(check_sljit_emit_op0(compiler
, op
));
953 case SLJIT_BREAKPOINT
:
954 return push_inst(compiler
, TA
, UNMOVABLE_INS
);
956 return push_inst(compiler
, NOP
, UNMOVABLE_INS
);
959 #if (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
960 FAIL_IF(push_inst(compiler
, (op
== SLJIT_LMUL_UW
? UMUL
: SMUL
) | D(SLJIT_R0
) | S1(SLJIT_R0
) | S2(SLJIT_R1
), DR(SLJIT_R0
)));
961 return push_inst(compiler
, RDY
| D(SLJIT_R1
), DR(SLJIT_R1
));
963 #error "Implementation required"
965 case SLJIT_DIVMOD_UW
:
966 case SLJIT_DIVMOD_SW
:
969 SLJIT_COMPILE_ASSERT((SLJIT_DIVMOD_UW
& 0x2) == 0 && SLJIT_DIV_UW
- 0x2 == SLJIT_DIVMOD_UW
, bad_div_opcode_assignments
);
970 #if (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
971 if ((op
| 0x2) == SLJIT_DIV_UW
)
972 FAIL_IF(push_inst(compiler
, WRY
| S1(0), MOVABLE_INS
));
974 FAIL_IF(push_inst(compiler
, SRA
| D(TMP_REG1
) | S1(SLJIT_R0
) | IMM(31), DR(TMP_REG1
)));
975 FAIL_IF(push_inst(compiler
, WRY
| S1(TMP_REG1
), MOVABLE_INS
));
977 if (op
<= SLJIT_DIVMOD_SW
)
978 FAIL_IF(push_inst(compiler
, OR
| D(TMP_REG2
) | S1(0) | S2(SLJIT_R0
), DR(TMP_REG2
)));
979 FAIL_IF(push_inst(compiler
, ((op
| 0x2) == SLJIT_DIV_UW
? UDIV
: SDIV
) | D(SLJIT_R0
) | S1(SLJIT_R0
) | S2(SLJIT_R1
), DR(SLJIT_R0
)));
980 if (op
>= SLJIT_DIV_UW
)
981 return SLJIT_SUCCESS
;
982 FAIL_IF(push_inst(compiler
, SMUL
| D(SLJIT_R1
) | S1(SLJIT_R0
) | S2(SLJIT_R1
), DR(SLJIT_R1
)));
983 return push_inst(compiler
, SUB
| D(SLJIT_R1
) | S1(TMP_REG2
) | S2(SLJIT_R1
), DR(SLJIT_R1
));
985 #error "Implementation required"
988 case SLJIT_SKIP_FRAMES_BEFORE_RETURN
:
989 return SLJIT_SUCCESS
;
992 return SLJIT_SUCCESS
;
995 SLJIT_API_FUNC_ATTRIBUTE sljit_s32
sljit_emit_op1(struct sljit_compiler
*compiler
, sljit_s32 op
,
996 sljit_s32 dst
, sljit_sw dstw
,
997 sljit_s32 src
, sljit_sw srcw
)
999 sljit_u32 flags
= HAS_FLAGS(op
) ? SET_FLAGS
: 0;
1002 CHECK(check_sljit_emit_op1(compiler
, op
, dst
, dstw
, src
, srcw
));
1003 ADJUST_LOCAL_OFFSET(dst
, dstw
);
1004 ADJUST_LOCAL_OFFSET(src
, srcw
);
1006 op
= GET_OPCODE(op
);
1009 #if (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
1015 return emit_op(compiler
, SLJIT_MOV
, flags
| WORD_DATA
| MOVE_OP
, dst
, dstw
, TMP_REG1
, 0, src
, srcw
);
1018 return emit_op(compiler
, SLJIT_MOV_U8
, flags
| BYTE_DATA
| MOVE_OP
, dst
, dstw
, TMP_REG1
, 0, src
, (src
& SLJIT_IMM
) ? (sljit_u8
)srcw
: srcw
);
1021 return emit_op(compiler
, SLJIT_MOV_S8
, flags
| BYTE_DATA
| SIGNED_DATA
| MOVE_OP
, dst
, dstw
, TMP_REG1
, 0, src
, (src
& SLJIT_IMM
) ? (sljit_s8
)srcw
: srcw
);
1024 return emit_op(compiler
, SLJIT_MOV_U16
, flags
| HALF_DATA
| MOVE_OP
, dst
, dstw
, TMP_REG1
, 0, src
, (src
& SLJIT_IMM
) ? (sljit_u16
)srcw
: srcw
);
1027 return emit_op(compiler
, SLJIT_MOV_S16
, flags
| HALF_DATA
| SIGNED_DATA
| MOVE_OP
, dst
, dstw
, TMP_REG1
, 0, src
, (src
& SLJIT_IMM
) ? (sljit_s16
)srcw
: srcw
);
1031 return emit_op(compiler
, op
, flags
, dst
, dstw
, TMP_REG1
, 0, src
, srcw
);
1034 return SLJIT_SUCCESS
;
1037 SLJIT_API_FUNC_ATTRIBUTE sljit_s32
sljit_emit_op2(struct sljit_compiler
*compiler
, sljit_s32 op
,
1038 sljit_s32 dst
, sljit_sw dstw
,
1039 sljit_s32 src1
, sljit_sw src1w
,
1040 sljit_s32 src2
, sljit_sw src2w
)
1042 sljit_u32 flags
= HAS_FLAGS(op
) ? SET_FLAGS
: 0;
1045 CHECK(check_sljit_emit_op2(compiler
, op
, 0, dst
, dstw
, src1
, src1w
, src2
, src2w
));
1046 ADJUST_LOCAL_OFFSET(dst
, dstw
);
1047 ADJUST_LOCAL_OFFSET(src1
, src1w
);
1048 ADJUST_LOCAL_OFFSET(src2
, src2w
);
1050 op
= GET_OPCODE(op
);
1058 return emit_op(compiler
, op
, flags
| CUMULATIVE_OP
| IMM_OP
, dst
, dstw
, src1
, src1w
, src2
, src2w
);
1062 return emit_op(compiler
, op
, flags
| IMM_OP
, dst
, dstw
, src1
, src1w
, src2
, src2w
);
1067 #if (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
1068 if (src2
& SLJIT_IMM
)
1071 SLJIT_UNREACHABLE();
1073 return emit_op(compiler
, op
, flags
| IMM_OP
, dst
, dstw
, src1
, src1w
, src2
, src2w
);
1076 return SLJIT_SUCCESS
;
1079 SLJIT_API_FUNC_ATTRIBUTE sljit_s32
sljit_emit_op2u(struct sljit_compiler
*compiler
, sljit_s32 op
,
1080 sljit_s32 src1
, sljit_sw src1w
,
1081 sljit_s32 src2
, sljit_sw src2w
)
1084 CHECK(check_sljit_emit_op2(compiler
, op
, 1, 0, 0, src1
, src1w
, src2
, src2w
));
1086 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
1087 || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1088 compiler
->skip_checks
= 1;
1090 return sljit_emit_op2(compiler
, op
, TMP_REG2
, 0, src1
, src1w
, src2
, src2w
);
1093 SLJIT_API_FUNC_ATTRIBUTE sljit_s32
sljit_emit_op_src(struct sljit_compiler
*compiler
, sljit_s32 op
,
1094 sljit_s32 src
, sljit_sw srcw
)
1097 CHECK(check_sljit_emit_op_src(compiler
, op
, src
, srcw
));
1098 ADJUST_LOCAL_OFFSET(src
, srcw
);
1101 case SLJIT_FAST_RETURN
:
1102 if (FAST_IS_REG(src
))
1103 FAIL_IF(push_inst(compiler
, OR
| D(TMP_LINK
) | S1(0) | S2(src
), DR(TMP_LINK
)));
1105 FAIL_IF(emit_op_mem(compiler
, WORD_DATA
| LOAD_DATA
, TMP_LINK
, src
, srcw
));
1107 FAIL_IF(push_inst(compiler
, JMPL
| D(0) | S1(TMP_LINK
) | IMM(8), UNMOVABLE_INS
));
1108 return push_inst(compiler
, NOP
, UNMOVABLE_INS
);
1109 case SLJIT_SKIP_FRAMES_BEFORE_FAST_RETURN
:
1110 case SLJIT_PREFETCH_L1
:
1111 case SLJIT_PREFETCH_L2
:
1112 case SLJIT_PREFETCH_L3
:
1113 case SLJIT_PREFETCH_ONCE
:
1114 return SLJIT_SUCCESS
;
1117 return SLJIT_SUCCESS
;
1120 SLJIT_API_FUNC_ATTRIBUTE sljit_s32
sljit_get_register_index(sljit_s32 reg
)
1122 CHECK_REG_INDEX(check_sljit_get_register_index(reg
));
1123 return reg_map
[reg
];
1126 SLJIT_API_FUNC_ATTRIBUTE sljit_s32
sljit_get_float_register_index(sljit_s32 reg
)
1128 CHECK_REG_INDEX(check_sljit_get_float_register_index(reg
));
1129 return freg_map
[reg
];
1132 SLJIT_API_FUNC_ATTRIBUTE sljit_s32
sljit_emit_op_custom(struct sljit_compiler
*compiler
,
1133 void *instruction
, sljit_u32 size
)
1136 CHECK(check_sljit_emit_op_custom(compiler
, instruction
, size
));
1138 return push_inst(compiler
, *(sljit_ins
*)instruction
, UNMOVABLE_INS
);
1141 /* --------------------------------------------------------------------- */
1142 /* Floating point operators */
1143 /* --------------------------------------------------------------------- */
1145 #define FLOAT_DATA(op) ((sljit_ins)DOUBLE_DATA | (((sljit_ins)(op) & SLJIT_32) >> 7))
1146 #define SELECT_FOP(op, single, double) ((op & SLJIT_32) ? single : double)
1147 #define FLOAT_TMP_MEM_OFFSET (22 * sizeof(sljit_sw))
1149 static SLJIT_INLINE sljit_s32
sljit_emit_fop1_conv_sw_from_f64(struct sljit_compiler
*compiler
, sljit_s32 op
,
1150 sljit_s32 dst
, sljit_sw dstw
,
1151 sljit_s32 src
, sljit_sw srcw
)
1153 if (src
& SLJIT_MEM
) {
1154 FAIL_IF(emit_op_mem2(compiler
, FLOAT_DATA(op
) | LOAD_DATA
, TMP_FREG1
, src
, srcw
, dst
, dstw
));
1158 FAIL_IF(push_inst(compiler
, SELECT_FOP(op
, FSTOI
, FDTOI
) | FD(TMP_FREG1
) | FS2(src
), MOVABLE_INS
));
1160 if (FAST_IS_REG(dst
)) {
1161 FAIL_IF(emit_op_mem2(compiler
, SINGLE_DATA
, TMP_FREG1
, SLJIT_MEM1(SLJIT_SP
), FLOAT_TMP_MEM_OFFSET
, SLJIT_MEM1(SLJIT_SP
), FLOAT_TMP_MEM_OFFSET
));
1162 return emit_op_mem2(compiler
, WORD_DATA
| LOAD_DATA
, dst
, SLJIT_MEM1(SLJIT_SP
), FLOAT_TMP_MEM_OFFSET
, SLJIT_MEM1(SLJIT_SP
), FLOAT_TMP_MEM_OFFSET
);
1165 /* Store the integer value from a VFP register. */
1166 return emit_op_mem2(compiler
, SINGLE_DATA
, TMP_FREG1
, dst
, dstw
, 0, 0);
1169 static SLJIT_INLINE sljit_s32
sljit_emit_fop1_conv_f64_from_sw(struct sljit_compiler
*compiler
, sljit_s32 op
,
1170 sljit_s32 dst
, sljit_sw dstw
,
1171 sljit_s32 src
, sljit_sw srcw
)
1173 sljit_s32 dst_r
= FAST_IS_REG(dst
) ? dst
: TMP_FREG1
;
1175 if (src
& SLJIT_IMM
) {
1176 if (GET_OPCODE(op
) == SLJIT_CONV_F64_FROM_S32
)
1177 srcw
= (sljit_s32
)srcw
;
1179 FAIL_IF(load_immediate(compiler
, TMP_REG1
, srcw
));
1184 if (FAST_IS_REG(src
)) {
1185 FAIL_IF(emit_op_mem2(compiler
, WORD_DATA
, src
, SLJIT_MEM1(SLJIT_SP
), FLOAT_TMP_MEM_OFFSET
, SLJIT_MEM1(SLJIT_SP
), FLOAT_TMP_MEM_OFFSET
));
1186 src
= SLJIT_MEM1(SLJIT_SP
);
1187 srcw
= FLOAT_TMP_MEM_OFFSET
;
1190 FAIL_IF(emit_op_mem2(compiler
, SINGLE_DATA
| LOAD_DATA
, TMP_FREG1
, src
, srcw
, dst
, dstw
));
1191 FAIL_IF(push_inst(compiler
, SELECT_FOP(op
, FITOS
, FITOD
) | FD(dst_r
) | FS2(TMP_FREG1
), MOVABLE_INS
));
1193 if (dst
& SLJIT_MEM
)
1194 return emit_op_mem2(compiler
, FLOAT_DATA(op
), TMP_FREG1
, dst
, dstw
, 0, 0);
1195 return SLJIT_SUCCESS
;
1198 static SLJIT_INLINE sljit_s32
sljit_emit_fop1_cmp(struct sljit_compiler
*compiler
, sljit_s32 op
,
1199 sljit_s32 src1
, sljit_sw src1w
,
1200 sljit_s32 src2
, sljit_sw src2w
)
1202 if (src1
& SLJIT_MEM
) {
1203 FAIL_IF(emit_op_mem2(compiler
, FLOAT_DATA(op
) | LOAD_DATA
, TMP_FREG1
, src1
, src1w
, src2
, src2w
));
1207 if (src2
& SLJIT_MEM
) {
1208 FAIL_IF(emit_op_mem2(compiler
, FLOAT_DATA(op
) | LOAD_DATA
, TMP_FREG2
, src2
, src2w
, 0, 0));
1212 return push_inst(compiler
, SELECT_FOP(op
, FCMPS
, FCMPD
) | FS1(src1
) | FS2(src2
), FCC_IS_SET
| MOVABLE_INS
);
1215 SLJIT_API_FUNC_ATTRIBUTE sljit_s32
sljit_emit_fop1(struct sljit_compiler
*compiler
, sljit_s32 op
,
1216 sljit_s32 dst
, sljit_sw dstw
,
1217 sljit_s32 src
, sljit_sw srcw
)
1222 compiler
->cache_arg
= 0;
1223 compiler
->cache_argw
= 0;
1225 SLJIT_COMPILE_ASSERT((SLJIT_32
== 0x100) && !(DOUBLE_DATA
& 0x2), float_transfer_bit_error
);
1226 SELECT_FOP1_OPERATION_WITH_CHECKS(compiler
, op
, dst
, dstw
, src
, srcw
);
1228 if (GET_OPCODE(op
) == SLJIT_CONV_F64_FROM_F32
)
1231 dst_r
= FAST_IS_REG(dst
) ? dst
: TMP_FREG1
;
1233 if (src
& SLJIT_MEM
) {
1234 FAIL_IF(emit_op_mem2(compiler
, FLOAT_DATA(op
) | LOAD_DATA
, dst_r
, src
, srcw
, dst
, dstw
));
1238 switch (GET_OPCODE(op
)) {
1241 if (dst_r
!= TMP_FREG1
) {
1242 FAIL_IF(push_inst(compiler
, FMOVS
| FD(dst_r
) | FS2(src
), MOVABLE_INS
));
1243 if (!(op
& SLJIT_32
))
1244 FAIL_IF(push_inst(compiler
, FMOVS
| FDN(dst_r
) | FS2N(src
), MOVABLE_INS
));
1251 FAIL_IF(push_inst(compiler
, FNEGS
| FD(dst_r
) | FS2(src
), MOVABLE_INS
));
1252 if (dst_r
!= src
&& !(op
& SLJIT_32
))
1253 FAIL_IF(push_inst(compiler
, FMOVS
| FDN(dst_r
) | FS2N(src
), MOVABLE_INS
));
1256 FAIL_IF(push_inst(compiler
, FABSS
| FD(dst_r
) | FS2(src
), MOVABLE_INS
));
1257 if (dst_r
!= src
&& !(op
& SLJIT_32
))
1258 FAIL_IF(push_inst(compiler
, FMOVS
| FDN(dst_r
) | FS2N(src
), MOVABLE_INS
));
1260 case SLJIT_CONV_F64_FROM_F32
:
1261 FAIL_IF(push_inst(compiler
, SELECT_FOP(op
, FSTOD
, FDTOS
) | FD(dst_r
) | FS2(src
), MOVABLE_INS
));
1266 if (dst
& SLJIT_MEM
)
1267 FAIL_IF(emit_op_mem2(compiler
, FLOAT_DATA(op
), dst_r
, dst
, dstw
, 0, 0));
1268 return SLJIT_SUCCESS
;
1271 SLJIT_API_FUNC_ATTRIBUTE sljit_s32
sljit_emit_fop2(struct sljit_compiler
*compiler
, sljit_s32 op
,
1272 sljit_s32 dst
, sljit_sw dstw
,
1273 sljit_s32 src1
, sljit_sw src1w
,
1274 sljit_s32 src2
, sljit_sw src2w
)
1276 sljit_s32 dst_r
, flags
= 0;
1279 CHECK(check_sljit_emit_fop2(compiler
, op
, dst
, dstw
, src1
, src1w
, src2
, src2w
));
1280 ADJUST_LOCAL_OFFSET(dst
, dstw
);
1281 ADJUST_LOCAL_OFFSET(src1
, src1w
);
1282 ADJUST_LOCAL_OFFSET(src2
, src2w
);
1284 compiler
->cache_arg
= 0;
1285 compiler
->cache_argw
= 0;
1287 dst_r
= FAST_IS_REG(dst
) ? dst
: TMP_FREG2
;
1289 if (src1
& SLJIT_MEM
) {
1290 if (getput_arg_fast(compiler
, FLOAT_DATA(op
) | LOAD_DATA
, TMP_FREG1
, src1
, src1w
)) {
1291 FAIL_IF(compiler
->error
);
1297 if (src2
& SLJIT_MEM
) {
1298 if (getput_arg_fast(compiler
, FLOAT_DATA(op
) | LOAD_DATA
, TMP_FREG2
, src2
, src2w
)) {
1299 FAIL_IF(compiler
->error
);
1305 if ((flags
& (SLOW_SRC1
| SLOW_SRC2
)) == (SLOW_SRC1
| SLOW_SRC2
)) {
1306 if (!can_cache(src1
, src1w
, src2
, src2w
) && can_cache(src1
, src1w
, dst
, dstw
)) {
1307 FAIL_IF(getput_arg(compiler
, FLOAT_DATA(op
) | LOAD_DATA
, TMP_FREG2
, src2
, src2w
, src1
, src1w
));
1308 FAIL_IF(getput_arg(compiler
, FLOAT_DATA(op
) | LOAD_DATA
, TMP_FREG1
, src1
, src1w
, dst
, dstw
));
1311 FAIL_IF(getput_arg(compiler
, FLOAT_DATA(op
) | LOAD_DATA
, TMP_FREG1
, src1
, src1w
, src2
, src2w
));
1312 FAIL_IF(getput_arg(compiler
, FLOAT_DATA(op
) | LOAD_DATA
, TMP_FREG2
, src2
, src2w
, dst
, dstw
));
1315 else if (flags
& SLOW_SRC1
)
1316 FAIL_IF(getput_arg(compiler
, FLOAT_DATA(op
) | LOAD_DATA
, TMP_FREG1
, src1
, src1w
, dst
, dstw
));
1317 else if (flags
& SLOW_SRC2
)
1318 FAIL_IF(getput_arg(compiler
, FLOAT_DATA(op
) | LOAD_DATA
, TMP_FREG2
, src2
, src2w
, dst
, dstw
));
1320 if (flags
& SLOW_SRC1
)
1322 if (flags
& SLOW_SRC2
)
1325 switch (GET_OPCODE(op
)) {
1327 FAIL_IF(push_inst(compiler
, SELECT_FOP(op
, FADDS
, FADDD
) | FD(dst_r
) | FS1(src1
) | FS2(src2
), MOVABLE_INS
));
1331 FAIL_IF(push_inst(compiler
, SELECT_FOP(op
, FSUBS
, FSUBD
) | FD(dst_r
) | FS1(src1
) | FS2(src2
), MOVABLE_INS
));
1335 FAIL_IF(push_inst(compiler
, SELECT_FOP(op
, FMULS
, FMULD
) | FD(dst_r
) | FS1(src1
) | FS2(src2
), MOVABLE_INS
));
1339 FAIL_IF(push_inst(compiler
, SELECT_FOP(op
, FDIVS
, FDIVD
) | FD(dst_r
) | FS1(src1
) | FS2(src2
), MOVABLE_INS
));
1343 if (dst_r
== TMP_FREG2
)
1344 FAIL_IF(emit_op_mem2(compiler
, FLOAT_DATA(op
), TMP_FREG2
, dst
, dstw
, 0, 0));
1346 return SLJIT_SUCCESS
;
1352 /* --------------------------------------------------------------------- */
1353 /* Other instructions */
1354 /* --------------------------------------------------------------------- */
1356 SLJIT_API_FUNC_ATTRIBUTE sljit_s32
sljit_emit_fast_enter(struct sljit_compiler
*compiler
, sljit_s32 dst
, sljit_sw dstw
)
1359 CHECK(check_sljit_emit_fast_enter(compiler
, dst
, dstw
));
1360 ADJUST_LOCAL_OFFSET(dst
, dstw
);
1362 if (FAST_IS_REG(dst
))
1363 return push_inst(compiler
, OR
| D(dst
) | S1(0) | S2(TMP_LINK
), UNMOVABLE_INS
);
1366 FAIL_IF(emit_op_mem(compiler
, WORD_DATA
, TMP_LINK
, dst
, dstw
));
1367 compiler
->delay_slot
= UNMOVABLE_INS
;
1368 return SLJIT_SUCCESS
;
1371 /* --------------------------------------------------------------------- */
1372 /* Conditional instructions */
1373 /* --------------------------------------------------------------------- */
1375 SLJIT_API_FUNC_ATTRIBUTE
struct sljit_label
* sljit_emit_label(struct sljit_compiler
*compiler
)
1377 struct sljit_label
*label
;
1380 CHECK_PTR(check_sljit_emit_label(compiler
));
1382 if (compiler
->last_label
&& compiler
->last_label
->size
== compiler
->size
)
1383 return compiler
->last_label
;
1385 label
= (struct sljit_label
*)ensure_abuf(compiler
, sizeof(struct sljit_label
));
1386 PTR_FAIL_IF(!label
);
1387 set_label(label
, compiler
);
1388 compiler
->delay_slot
= UNMOVABLE_INS
;
1392 static sljit_ins
get_cc(struct sljit_compiler
*compiler
, sljit_s32 type
)
1396 case SLJIT_UNORDERED_OR_NOT_EQUAL
:
1399 case SLJIT_NOT_EQUAL
:
1401 case SLJIT_ORDERED_EQUAL
:
1405 case SLJIT_UNORDERED_OR_GREATER
:
1409 case SLJIT_GREATER_EQUAL
:
1410 case SLJIT_NOT_CARRY
:
1411 case SLJIT_F_LESS_EQUAL
:
1412 case SLJIT_ORDERED_LESS_EQUAL
:
1416 case SLJIT_UNORDERED_OR_GREATER_EQUAL
:
1419 case SLJIT_LESS_EQUAL
:
1421 case SLJIT_ORDERED_LESS
:
1424 case SLJIT_SIG_LESS
:
1425 case SLJIT_UNORDERED_OR_LESS
:
1428 case SLJIT_SIG_GREATER_EQUAL
:
1429 case SLJIT_F_GREATER_EQUAL
:
1430 case SLJIT_ORDERED_GREATER_EQUAL
:
1433 case SLJIT_SIG_GREATER
:
1434 case SLJIT_UNORDERED_OR_EQUAL
:
1437 case SLJIT_SIG_LESS_EQUAL
:
1438 case SLJIT_F_NOT_EQUAL
:
1439 case SLJIT_ORDERED_NOT_EQUAL
:
1442 case SLJIT_OVERFLOW
:
1443 if (!(compiler
->status_flags_state
& (SLJIT_CURRENT_FLAGS_ADD
| SLJIT_CURRENT_FLAGS_SUB
)))
1447 case SLJIT_UNORDERED
:
1450 case SLJIT_NOT_OVERFLOW
:
1451 if (!(compiler
->status_flags_state
& (SLJIT_CURRENT_FLAGS_ADD
| SLJIT_CURRENT_FLAGS_SUB
)))
1458 case SLJIT_F_GREATER
:
1459 case SLJIT_ORDERED_GREATER
:
1462 case SLJIT_UNORDERED_OR_LESS_EQUAL
:
1466 SLJIT_UNREACHABLE();
1471 SLJIT_API_FUNC_ATTRIBUTE
struct sljit_jump
* sljit_emit_jump(struct sljit_compiler
*compiler
, sljit_s32 type
)
1473 struct sljit_jump
*jump
;
1476 CHECK_PTR(check_sljit_emit_jump(compiler
, type
));
1478 jump
= (struct sljit_jump
*)ensure_abuf(compiler
, sizeof(struct sljit_jump
));
1480 set_jump(jump
, compiler
, type
& SLJIT_REWRITABLE_JUMP
);
1483 if (type
< SLJIT_F_EQUAL
) {
1484 jump
->flags
|= IS_COND
;
1485 if (((compiler
->delay_slot
& DST_INS_MASK
) != UNMOVABLE_INS
) && !(compiler
->delay_slot
& ICC_IS_SET
))
1486 jump
->flags
|= IS_MOVABLE
;
1487 #if (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
1488 PTR_FAIL_IF(push_inst(compiler
, BICC
| get_cc(compiler
, type
^ 1) | 5, UNMOVABLE_INS
));
1490 #error "Implementation required"
1493 else if (type
< SLJIT_JUMP
) {
1494 jump
->flags
|= IS_COND
;
1495 if (((compiler
->delay_slot
& DST_INS_MASK
) != UNMOVABLE_INS
) && !(compiler
->delay_slot
& FCC_IS_SET
))
1496 jump
->flags
|= IS_MOVABLE
;
1497 #if (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
1498 PTR_FAIL_IF(push_inst(compiler
, FBFCC
| get_cc(compiler
, type
^ 1) | 5, UNMOVABLE_INS
));
1500 #error "Implementation required"
1504 if ((compiler
->delay_slot
& DST_INS_MASK
) != UNMOVABLE_INS
)
1505 jump
->flags
|= IS_MOVABLE
;
1506 if (type
>= SLJIT_FAST_CALL
)
1507 jump
->flags
|= IS_CALL
;
1510 PTR_FAIL_IF(emit_const(compiler
, TMP_REG1
, 0));
1511 PTR_FAIL_IF(push_inst(compiler
, JMPL
| D(type
>= SLJIT_FAST_CALL
? TMP_LINK
: 0) | S1(TMP_REG1
) | IMM(0), UNMOVABLE_INS
));
1512 jump
->addr
= compiler
->size
;
1513 PTR_FAIL_IF(push_inst(compiler
, NOP
, UNMOVABLE_INS
));
1518 SLJIT_API_FUNC_ATTRIBUTE
struct sljit_jump
* sljit_emit_call(struct sljit_compiler
*compiler
, sljit_s32 type
,
1519 sljit_s32 arg_types
)
1522 CHECK_PTR(check_sljit_emit_call(compiler
, type
, arg_types
));
1524 PTR_FAIL_IF(call_with_args(compiler
, arg_types
, NULL
));
1526 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
1527 || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1528 compiler
->skip_checks
= 1;
1531 return sljit_emit_jump(compiler
, type
);
1534 SLJIT_API_FUNC_ATTRIBUTE sljit_s32
sljit_emit_ijump(struct sljit_compiler
*compiler
, sljit_s32 type
, sljit_s32 src
, sljit_sw srcw
)
1536 struct sljit_jump
*jump
= NULL
;
1540 CHECK(check_sljit_emit_ijump(compiler
, type
, src
, srcw
));
1541 ADJUST_LOCAL_OFFSET(src
, srcw
);
1543 if (FAST_IS_REG(src
))
1545 else if (src
& SLJIT_IMM
) {
1546 jump
= (struct sljit_jump
*)ensure_abuf(compiler
, sizeof(struct sljit_jump
));
1548 set_jump(jump
, compiler
, JUMP_ADDR
);
1549 jump
->u
.target
= (sljit_uw
)srcw
;
1551 if ((compiler
->delay_slot
& DST_INS_MASK
) != UNMOVABLE_INS
)
1552 jump
->flags
|= IS_MOVABLE
;
1553 if (type
>= SLJIT_FAST_CALL
)
1554 jump
->flags
|= IS_CALL
;
1556 FAIL_IF(emit_const(compiler
, TMP_REG1
, 0));
1560 FAIL_IF(emit_op_mem(compiler
, WORD_DATA
| LOAD_DATA
, TMP_REG1
, src
, srcw
));
1564 FAIL_IF(push_inst(compiler
, JMPL
| D(type
>= SLJIT_FAST_CALL
? TMP_LINK
: 0) | S1(src_r
) | IMM(0), UNMOVABLE_INS
));
1566 jump
->addr
= compiler
->size
;
1567 return push_inst(compiler
, NOP
, UNMOVABLE_INS
);
1570 SLJIT_API_FUNC_ATTRIBUTE sljit_s32
sljit_emit_icall(struct sljit_compiler
*compiler
, sljit_s32 type
,
1571 sljit_s32 arg_types
,
1572 sljit_s32 src
, sljit_sw srcw
)
1575 CHECK(check_sljit_emit_icall(compiler
, type
, arg_types
, src
, srcw
));
1577 if (src
& SLJIT_MEM
) {
1578 ADJUST_LOCAL_OFFSET(src
, srcw
);
1579 FAIL_IF(emit_op_mem(compiler
, WORD_DATA
| LOAD_DATA
, TMP_REG1
, src
, srcw
));
1583 FAIL_IF(call_with_args(compiler
, arg_types
, &src
));
1585 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
1586 || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1587 compiler
->skip_checks
= 1;
1590 return sljit_emit_ijump(compiler
, type
, src
, srcw
);
1593 SLJIT_API_FUNC_ATTRIBUTE sljit_s32
sljit_emit_op_flags(struct sljit_compiler
*compiler
, sljit_s32 op
,
1594 sljit_s32 dst
, sljit_sw dstw
,
1598 sljit_u32 flags
= HAS_FLAGS(op
) ? SET_FLAGS
: 0;
1601 CHECK(check_sljit_emit_op_flags(compiler
, op
, dst
, dstw
, type
));
1602 ADJUST_LOCAL_OFFSET(dst
, dstw
);
1604 #if (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
1605 op
= GET_OPCODE(op
);
1606 reg
= (op
< SLJIT_ADD
&& FAST_IS_REG(dst
)) ? dst
: TMP_REG2
;
1608 compiler
->cache_arg
= 0;
1609 compiler
->cache_argw
= 0;
1611 if (op
>= SLJIT_ADD
&& (dst
& SLJIT_MEM
))
1612 FAIL_IF(emit_op_mem2(compiler
, WORD_DATA
| LOAD_DATA
, TMP_REG1
, dst
, dstw
, dst
, dstw
));
1614 if (type
< SLJIT_F_EQUAL
)
1615 FAIL_IF(push_inst(compiler
, BICC
| get_cc(compiler
, type
) | 3, UNMOVABLE_INS
));
1617 FAIL_IF(push_inst(compiler
, FBFCC
| get_cc(compiler
, type
) | 3, UNMOVABLE_INS
));
1619 FAIL_IF(push_inst(compiler
, OR
| D(reg
) | S1(0) | IMM(1), UNMOVABLE_INS
));
1620 FAIL_IF(push_inst(compiler
, OR
| D(reg
) | S1(0) | IMM(0), UNMOVABLE_INS
));
1622 if (op
>= SLJIT_ADD
) {
1623 flags
|= CUMULATIVE_OP
| IMM_OP
| ALT_KEEP_CACHE
;
1624 if (dst
& SLJIT_MEM
)
1625 return emit_op(compiler
, op
, flags
, dst
, dstw
, TMP_REG1
, 0, TMP_REG2
, 0);
1626 return emit_op(compiler
, op
, flags
, dst
, 0, dst
, 0, TMP_REG2
, 0);
1629 if (!(dst
& SLJIT_MEM
))
1630 return SLJIT_SUCCESS
;
1632 return emit_op_mem(compiler
, WORD_DATA
, TMP_REG2
, dst
, dstw
);
1634 #error "Implementation required"
1638 SLJIT_API_FUNC_ATTRIBUTE sljit_s32
sljit_emit_cmov(struct sljit_compiler
*compiler
, sljit_s32 type
,
1640 sljit_s32 src
, sljit_sw srcw
)
1643 CHECK(check_sljit_emit_cmov(compiler
, type
, dst_reg
, src
, srcw
));
1645 #if (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
1646 return sljit_emit_cmov_generic(compiler
, type
, dst_reg
, src
, srcw
);;
1648 #error "Implementation required"
1652 SLJIT_API_FUNC_ATTRIBUTE
struct sljit_const
* sljit_emit_const(struct sljit_compiler
*compiler
, sljit_s32 dst
, sljit_sw dstw
, sljit_sw init_value
)
1654 struct sljit_const
*const_
;
1658 CHECK_PTR(check_sljit_emit_const(compiler
, dst
, dstw
, init_value
));
1659 ADJUST_LOCAL_OFFSET(dst
, dstw
);
1661 const_
= (struct sljit_const
*)ensure_abuf(compiler
, sizeof(struct sljit_const
));
1662 PTR_FAIL_IF(!const_
);
1663 set_const(const_
, compiler
);
1665 dst_r
= FAST_IS_REG(dst
) ? dst
: TMP_REG2
;
1666 PTR_FAIL_IF(emit_const(compiler
, dst_r
, init_value
));
1668 if (dst
& SLJIT_MEM
)
1669 PTR_FAIL_IF(emit_op_mem(compiler
, WORD_DATA
, TMP_REG2
, dst
, dstw
));
1673 SLJIT_API_FUNC_ATTRIBUTE
struct sljit_put_label
* sljit_emit_put_label(struct sljit_compiler
*compiler
, sljit_s32 dst
, sljit_sw dstw
)
1675 struct sljit_put_label
*put_label
;
1679 CHECK_PTR(check_sljit_emit_put_label(compiler
, dst
, dstw
));
1680 ADJUST_LOCAL_OFFSET(dst
, dstw
);
1682 put_label
= (struct sljit_put_label
*)ensure_abuf(compiler
, sizeof(struct sljit_put_label
));
1683 PTR_FAIL_IF(!put_label
);
1684 set_put_label(put_label
, compiler
, 0);
1686 dst_r
= FAST_IS_REG(dst
) ? dst
: TMP_REG2
;
1687 PTR_FAIL_IF(emit_const(compiler
, dst_r
, 0));
1689 if (dst
& SLJIT_MEM
)
1690 PTR_FAIL_IF(emit_op_mem(compiler
, WORD_DATA
, TMP_REG2
, dst
, dstw
));