/[pcre]/code/trunk/sljit/sljitLir.h
ViewVC logotype

Contents of /code/trunk/sljit/sljitLir.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 715 - (show annotations) (download)
Sat Oct 1 06:42:38 2011 UTC (3 years, 1 month ago) by zherczeg
File MIME type: text/plain
File size: 28810 byte(s)
A fix for signed/unsigned comparison warnings reported by Visual C++ in the JIT compiler
1 /*
2 * Stack-less Just-In-Time compiler
3 *
4 * Copyright 2009-2010 Zoltan Herczeg (hzmester@freemail.hu). All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without modification, are
7 * permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright notice, this list of
10 * conditions and the following disclaimer.
11 *
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.
15 *
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.
25 */
26
27 #ifndef _SLJIT_LIR_H_
28 #define _SLJIT_LIR_H_
29
30 /*
31 ------------------------------------------------------------------------
32 Stack-Less JIT compiler for multiple architectures (x86, ARM, PowerPC)
33 ------------------------------------------------------------------------
34
35 Short description
36 Advantages:
37 - The execution can be continued from any LIR instruction
38 In other words, jump into and out of the code is safe
39 - Both target of (conditional) jump and call instructions
40 and constants can be dynamically modified during runtime
41 - although it is not suggested to do it frequently
42 - very effective to cache an important value once
43 - A fixed stack space can be allocated for local variables
44 - The compiler is thread-safe
45 Disadvantages:
46 - Limited number of registers (only 6+4 integer registers, max 3+2
47 temporary and max 3+2 general, and 4 floating point registers)
48 In practice:
49 - This approach is very effective for interpreters
50 - One of the general registers typically points to a stack interface
51 - It can jump to any exception handler anytime (even for another
52 function. It is safe for SLJIT.)
53 - Fast paths can be modified during runtime reflecting the changes
54 of the fastest execution path of the dynamic language
55 - SLJIT supports complex memory addressing modes
56 - mainly position independent code
57 - Optimizations (perhaps later)
58 - Only for basic blocks (when no labels inserted between LIR instructions)
59 */
60
61 #if !(defined SLJIT_NO_DEFAULT_CONFIG && SLJIT_NO_DEFAULT_CONFIG)
62 #include "sljitConfig.h"
63 #endif
64 #include "sljitConfigInternal.h"
65
66 /* --------------------------------------------------------------------- */
67 /* Error codes */
68 /* --------------------------------------------------------------------- */
69
70 /* Indicates no error. */
71 #define SLJIT_SUCCESS 0
72 /* After the call of sljit_generate_code(), the error code of the compiler
73 is set to this value to avoid future sljit calls (in debug mode at least).
74 The complier should be freed after sljit_generate_code(). */
75 #define SLJIT_ERR_COMPILED 1
76 /* Cannot allocate non executable memory. */
77 #define SLJIT_ERR_ALLOC_FAILED 2
78 /* Cannot allocate executable memory.
79 Only for sljit_generate_code() */
80 #define SLJIT_ERR_EX_ALLOC_FAILED 3
81 /* return value for SLJIT_CONFIG_UNSUPPORTED empty architecture. */
82 #define SLJIT_ERR_UNSUPPORTED 4
83
84 /* --------------------------------------------------------------------- */
85 /* Registers */
86 /* --------------------------------------------------------------------- */
87
88 #define SLJIT_UNUSED 0
89
90 #define SLJIT_TEMPORARY_REG1 1
91 #define SLJIT_TEMPORARY_REG2 2
92 #define SLJIT_TEMPORARY_REG3 3
93 /* Note: Extra Registers cannot be used for memory addressing. */
94 /* Note: on x86-32, these registers are emulated (using stack loads & stores). */
95 #define SLJIT_TEMPORARY_EREG1 4
96 #define SLJIT_TEMPORARY_EREG2 5
97
98 #define SLJIT_GENERAL_REG1 6
99 #define SLJIT_GENERAL_REG2 7
100 #define SLJIT_GENERAL_REG3 8
101 /* Note: Extra Registers cannot be used for memory addressing. */
102 /* Note: on x86-32, these registers are emulated (using stack loads & stores). */
103 #define SLJIT_GENERAL_EREG1 9
104 #define SLJIT_GENERAL_EREG2 10
105
106 /* Read-only register (cannot be the destination of an operation). */
107 /* Note: SLJIT_MEM2( ... , SLJIT_LOCALS_REG) is not supported (x86 limitation). */
108 /* Note: SLJIT_LOCALS_REG is not necessary the real stack pointer. See sljit_emit_enter. */
109 #define SLJIT_LOCALS_REG 11
110
111 /* Number of registers. */
112 #define SLJIT_NO_TMP_REGISTERS 5
113 #define SLJIT_NO_GEN_REGISTERS 5
114 #define SLJIT_NO_REGISTERS 11
115
116 /* Return with machine word. */
117
118 #define SLJIT_RETURN_REG SLJIT_TEMPORARY_REG1
119
120 /* x86 prefers temporary registers for special purposes. If other
121 registers are used such purpose, it costs a little performance
122 drawback. It doesn't matter for other archs. */
123
124 #define SLJIT_PREF_SHIFT_REG SLJIT_TEMPORARY_REG3
125
126 /* --------------------------------------------------------------------- */
127 /* Floating point registers */
128 /* --------------------------------------------------------------------- */
129
130 /* Note: SLJIT_UNUSED as destination is not valid for floating point
131 operations, since they cannot be used for setting flags. */
132
133 /* Floating point operations are performed on double precision values. */
134
135 #define SLJIT_FLOAT_REG1 1
136 #define SLJIT_FLOAT_REG2 2
137 #define SLJIT_FLOAT_REG3 3
138 #define SLJIT_FLOAT_REG4 4
139
140 /* --------------------------------------------------------------------- */
141 /* Main structures and functions */
142 /* --------------------------------------------------------------------- */
143
144 struct sljit_memory_fragment {
145 struct sljit_memory_fragment *next;
146 sljit_uw used_size;
147 sljit_ub memory[1];
148 };
149
150 struct sljit_label {
151 struct sljit_label *next;
152 sljit_uw addr;
153 /* The maximum size difference. */
154 sljit_uw size;
155 };
156
157 struct sljit_jump {
158 struct sljit_jump *next;
159 sljit_uw addr;
160 sljit_w flags;
161 union {
162 sljit_uw target;
163 struct sljit_label* label;
164 } u;
165 };
166
167 struct sljit_const {
168 struct sljit_const *next;
169 sljit_uw addr;
170 };
171
172 struct sljit_compiler {
173 int error;
174
175 struct sljit_label *labels;
176 struct sljit_jump *jumps;
177 struct sljit_const *consts;
178 struct sljit_label *last_label;
179 struct sljit_jump *last_jump;
180 struct sljit_const *last_const;
181
182 struct sljit_memory_fragment *buf;
183 struct sljit_memory_fragment *abuf;
184
185 /* Used local registers. */
186 int temporaries;
187 /* Used general registers. */
188 int generals;
189 /* Local stack size. */
190 int local_size;
191 /* Code size. */
192 sljit_uw size;
193
194 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
195 int args;
196 int temporaries_start;
197 int generals_start;
198 #endif
199
200 #if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
201 int mode32;
202 #endif
203
204 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) || (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
205 int flags_saved;
206 #endif
207
208 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
209 /* Constant pool handling. */
210 sljit_uw *cpool;
211 sljit_ub *cpool_unique;
212 sljit_uw cpool_diff;
213 sljit_uw cpool_fill;
214 /* General fields. */
215 /* Contains pointer, "ldr pc, [...]" pairs. */
216 sljit_uw patches;
217 #endif
218
219 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7)
220 /* Temporary fields. */
221 sljit_uw shift_imm;
222 int cache_arg;
223 sljit_w cache_argw;
224 #endif
225
226 #if (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
227 int cache_arg;
228 sljit_w cache_argw;
229 #endif
230
231 #if (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) || (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
232 int has_locals;
233 sljit_w imm;
234 int cache_arg;
235 sljit_w cache_argw;
236 #endif
237
238 #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
239 int has_locals;
240 int delay_slot;
241 int cache_arg;
242 sljit_w cache_argw;
243 #endif
244
245 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
246 FILE* verbose;
247 #endif
248
249 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) || (defined SLJIT_DEBUG && SLJIT_DEBUG)
250 int skip_checks;
251 #endif
252 };
253
254 /* --------------------------------------------------------------------- */
255 /* Main functions */
256 /* --------------------------------------------------------------------- */
257
258 /* Creates an sljit compiler.
259 Returns NULL if failed. */
260 struct sljit_compiler* sljit_create_compiler(void);
261 /* Free everything except the codes. */
262 void sljit_free_compiler(struct sljit_compiler *compiler);
263
264 static SLJIT_INLINE int sljit_get_compiler_error(struct sljit_compiler *compiler) { return compiler->error; }
265
266 /*
267 Allocate a small amount of memory. The size must be <= 64 bytes on 32 bit,
268 and <= 128 bytes on 64 bit architectures. The memory area is owned by the compiler,
269 and freed by sljit_free_compiler. The returned pointer is sizeof(sljit_w) aligned.
270 Excellent for allocating small blocks during the compiling, and no need to worry
271 about freeing them. The size is enough to contain at most 16 pointers.
272 If the size is outside of the range, the function will return with NULL,
273 but this return value does not indicate that there is no more memory (does
274 not set the compiler to out-of-memory status).
275 */
276 void* sljit_alloc_memory(struct sljit_compiler *compiler, int size);
277
278 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
279 /* Passing NULL disables verbose. */
280 void sljit_compiler_verbose(struct sljit_compiler *compiler, FILE* verbose);
281 #endif
282
283 void* sljit_generate_code(struct sljit_compiler *compiler);
284 void sljit_free_code(void* code);
285
286 /* Instruction generation. Returns with error code. */
287
288 /*
289 Entry instruction. The instruction has "args" number of arguments
290 and will use the first "general" number of general registers.
291 The arguments are passed into the general registers (arg1 to general_reg1, and so on).
292 Thus, "args" must be less or equal than "general". A local_size extra
293 stack space is allocated for the jit code (must be less or equal than
294 SLJIT_MAX_LOCAL_SIZE), which can accessed through SLJIT_LOCALS_REG (see
295 the notes there). SLJIT_LOCALS_REG is not necessary the real stack pointer!
296 It just points somewhere in the stack if local_size > 0 (!). Thus, the only
297 thing which is known that the memory area between SLJIT_LOCALS_REG and
298 SLJIT_LOCALS_REG + local_size is a valid stack area if local_size > 0
299 */
300
301 /* Note: multiple calls of this function overwrites the previous call. */
302
303 #define SLJIT_MAX_LOCAL_SIZE 65536
304
305 int sljit_emit_enter(struct sljit_compiler *compiler, int args, int temporaries, int generals, int local_size);
306
307 /* Since sljit_emit_return (and many asserts) uses variables which are initialized
308 by sljit_emit_enter, a simple return is not possible if these variables are not
309 initialized. sljit_fake_enter does not emit any instruction, just initialize
310 those variables. */
311
312 /* Note: multiple calls of this function overwrites the previous call. */
313
314 void sljit_fake_enter(struct sljit_compiler *compiler, int args, int temporaries, int generals, int local_size);
315
316 /* Return from jit. See below the possible values for src and srcw. */
317 int sljit_emit_return(struct sljit_compiler *compiler, int src, sljit_w srcw);
318
319 /* Really fast calling method for utility functions inside sljit (see SLJIT_FAST_CALL).
320 All registers and even the stack frame is passed to the callee. The return address is
321 preserved in dst/dstw by sljit_emit_fast_enter, and sljit_emit_fast_return can
322 use this as a return value later. */
323
324 /* Note: only for sljit specific, non ABI compilant calls. Fast, since only a few machine instructions
325 are needed. Excellent for small uility functions, where saving general registers and setting up
326 a new stack frame would cost too much performance. However, it is still possible to return
327 to the address of the caller (or anywhere else). */
328
329 /* Note: flags are not changed (unlike sljit_emit_enter / sljit_emit_return). */
330
331 /* Note: although sljit_emit_fast_return could be replaced by an ijump, it is not suggested,
332 since many architectures do clever branch prediction on call / return instruction pairs. */
333
334 int sljit_emit_fast_enter(struct sljit_compiler *compiler, int dst, sljit_w dstw, int args, int temporaries, int generals, int local_size);
335 int sljit_emit_fast_return(struct sljit_compiler *compiler, int src, sljit_w srcw);
336
337 /*
338 Source and destination values for arithmetical instructions
339 imm - a simple immediate value (cannot be used as a destination)
340 reg - any of the registers (immediate argument must be 0)
341 [imm] - absolute immediate memory address
342 [reg+imm] - indirect memory address
343 [reg+(reg<<imm)] - indirect indexed memory address (shift must be between 0 and 3)
344 useful for (byte, half, int, sljit_w) array access
345 (fully supported by both x86 and ARM architectures, and cheap operation on others)
346 */
347
348 /*
349 IMPORATNT NOTE: memory access MUST be naturally aligned.
350 length | alignment
351 ---------+-----------
352 byte | 1 byte (not aligned)
353 half | 2 byte (real_address & 0x1 == 0)
354 int | 4 byte (real_address & 0x3 == 0)
355 sljit_w | 4 byte if SLJIT_32BIT_ARCHITECTURE defined
356 | 8 byte if SLJIT_64BIT_ARCHITECTURE defined
357 (This is a strict requirement for embedded systems.)
358
359 Note: different architectures have different addressing limitations
360 Thus sljit may generate several instructions for other addressing modes
361 x86: all addressing modes supported, but write-back is not supported
362 (requires an extra instruction). On x86-64 only 32 bit signed
363 integers are supported by the architecture.
364 arm: [reg+imm] supported for small immediates (-4095 <= imm <= 4095
365 or -255 <= imm <= 255 for loading signed bytes, any halfs or doubles)
366 [reg+(reg<<imm)] are supported or requires only two instructions
367 Write back is limited to small immediates on thumb2
368 ppc: [reg+imm], -65535 <= imm <= 65535. 64 bit moves requires immediates
369 divisible by 4. [reg+reg] supported, write-back supported
370 [reg+(reg<<imm)] (imm != 0) is cheap (requires two instructions)
371 */
372
373 /* Register output: simply the name of the register.
374 For destination, you can use SLJIT_UNUSED as well. */
375 #define SLJIT_MEM 0x100
376 #define SLJIT_MEM0() (SLJIT_MEM)
377 #define SLJIT_MEM1(r1) (SLJIT_MEM | (r1))
378 #define SLJIT_MEM2(r1, r2) (SLJIT_MEM | (r1) | ((r2) << 4))
379 #define SLJIT_IMM 0x200
380
381 /* Set 32 bit operation mode (I) on 64 bit CPUs. The flag is totally ignored on
382 32 bit CPUs. The arithmetic instruction uses only the lower 32 bit of the
383 input register(s), and set the flags according to the 32 bit result. If the
384 destination is a register, the higher 32 bit of the result is undefined.
385 The addressing modes (SLJIT_MEM1/SLJIT_MEM2 macros) are unaffected by this flag. */
386 #define SLJIT_INT_OP 0x100
387
388 /* Common CPU status flags for all architectures (x86, ARM, PPC)
389 - carry flag
390 - overflow flag
391 - zero flag
392 - negative/positive flag (depends on arc)
393 On mips, these flags are emulated by software. */
394
395 /* By default, the instructions may, or may not set the CPU status flags.
396 Forcing to set or keep status flags can be done with the following flags: */
397
398 /* Note: sljit tries to emit the minimum number of instructions. Using these
399 flags can increase them, so use them wisely to avoid unnecessary code generation. */
400
401 /* Set Equal (Zero) status flag (E). */
402 #define SLJIT_SET_E 0x0200
403 /* Set signed status flag (S). */
404 #define SLJIT_SET_S 0x0400
405 /* Set unsgined status flag (U). */
406 #define SLJIT_SET_U 0x0800
407 /* Set signed overflow flag (O). */
408 #define SLJIT_SET_O 0x1000
409 /* Set carry flag (C).
410 Note: Kinda unsigned overflow, but behaves differently on various cpus. */
411 #define SLJIT_SET_C 0x2000
412 /* Do not modify the flags (K).
413 Note: This flag cannot be combined with any other SLJIT_SET_* flag. */
414 #define SLJIT_KEEP_FLAGS 0x4000
415
416 /* Notes:
417 - you cannot postpone conditional jump instructions except if noted that
418 the instruction does not set flags (See: SLJIT_KEEP_FLAGS).
419 - flag combinations: '|' means 'logical or'. */
420
421 /* Flags: - (never set any flags)
422 Note: breakpoint instruction is not supported by all architectures (namely ppc)
423 It falls back to SLJIT_NOP in those cases. */
424 #define SLJIT_BREAKPOINT 0
425 /* Flags: - (never set any flags)
426 Note: may or may not cause an extra cycle wait
427 it can even decrease the runtime in a few cases. */
428 #define SLJIT_NOP 1
429
430 int sljit_emit_op0(struct sljit_compiler *compiler, int op);
431
432 /* Notes for MOV instructions:
433 U = Mov with update (post form). If source or destination defined as SLJIT_MEM1(r1)
434 or SLJIT_MEM2(r1, r2), r1 is increased by the sum of r2 and the constant argument
435 UB = unsigned byte (8 bit)
436 SB = signed byte (8 bit)
437 UH = unsgined half (16 bit)
438 SH = unsgined half (16 bit) */
439
440 /* Flags: - (never set any flags) */
441 #define SLJIT_MOV 2
442 /* Flags: - (never set any flags) */
443 #define SLJIT_MOV_UB 3
444 /* Flags: - (never set any flags) */
445 #define SLJIT_MOV_SB 4
446 /* Flags: - (never set any flags) */
447 #define SLJIT_MOV_UH 5
448 /* Flags: - (never set any flags) */
449 #define SLJIT_MOV_SH 6
450 /* Flags: - (never set any flags) */
451 #define SLJIT_MOV_UI 7
452 /* Flags: - (never set any flags) */
453 #define SLJIT_MOV_SI 8
454 /* Flags: - (never set any flags) */
455 #define SLJIT_MOVU 9
456 /* Flags: - (never set any flags) */
457 #define SLJIT_MOVU_UB 10
458 /* Flags: - (never set any flags) */
459 #define SLJIT_MOVU_SB 11
460 /* Flags: - (never set any flags) */
461 #define SLJIT_MOVU_UH 12
462 /* Flags: - (never set any flags) */
463 #define SLJIT_MOVU_SH 13
464 /* Flags: - (never set any flags) */
465 #define SLJIT_MOVU_UI 14
466 /* Flags: - (never set any flags) */
467 #define SLJIT_MOVU_SI 15
468 /* Flags: I | E | K */
469 #define SLJIT_NOT 16
470 /* Flags: I | E | O | K */
471 #define SLJIT_NEG 17
472 /* Count leading zeroes
473 Flags: I | E | K */
474 #define SLJIT_CLZ 18
475
476 int sljit_emit_op1(struct sljit_compiler *compiler, int op,
477 int dst, sljit_w dstw,
478 int src, sljit_w srcw);
479
480 /* Flags: I | E | O | C | K */
481 #define SLJIT_ADD 19
482 /* Flags: I | C | K */
483 #define SLJIT_ADDC 20
484 /* Flags: I | E | S | U | O | C | K */
485 #define SLJIT_SUB 21
486 /* Flags: I | C | K */
487 #define SLJIT_SUBC 22
488 /* Note: integer mul */
489 /* Flags: I | O (see SLJIT_C_MUL_*) | K */
490 #define SLJIT_MUL 23
491 /* Flags: I | E | K */
492 #define SLJIT_AND 24
493 /* Flags: I | E | K */
494 #define SLJIT_OR 25
495 /* Flags: I | E | K */
496 #define SLJIT_XOR 26
497 /* Flags: I | E | K */
498 #define SLJIT_SHL 27
499 /* Flags: I | E | K */
500 #define SLJIT_LSHR 28
501 /* Flags: I | E | K */
502 #define SLJIT_ASHR 29
503
504 int sljit_emit_op2(struct sljit_compiler *compiler, int op,
505 int dst, sljit_w dstw,
506 int src1, sljit_w src1w,
507 int src2, sljit_w src2w);
508
509 int sljit_is_fpu_available(void);
510
511 /* Note: dst is the left and src is the right operand for SLJIT_FCMP.
512 Note: NaN check is always performed. If SLJIT_C_FLOAT_NAN is set,
513 the comparison result is unpredictable.
514 Flags: E | S (see SLJIT_C_FLOAT_*) */
515 #define SLJIT_FCMP 30
516 /* Flags: - (never set any flags) */
517 #define SLJIT_FMOV 31
518 /* Flags: - (never set any flags) */
519 #define SLJIT_FNEG 32
520 /* Flags: - (never set any flags) */
521 #define SLJIT_FABS 33
522
523 int sljit_emit_fop1(struct sljit_compiler *compiler, int op,
524 int dst, sljit_w dstw,
525 int src, sljit_w srcw);
526
527 /* Flags: - (never set any flags) */
528 #define SLJIT_FADD 34
529 /* Flags: - (never set any flags) */
530 #define SLJIT_FSUB 35
531 /* Flags: - (never set any flags) */
532 #define SLJIT_FMUL 36
533 /* Flags: - (never set any flags) */
534 #define SLJIT_FDIV 37
535
536 int sljit_emit_fop2(struct sljit_compiler *compiler, int op,
537 int dst, sljit_w dstw,
538 int src1, sljit_w src1w,
539 int src2, sljit_w src2w);
540
541 /* Label and jump instructions. */
542
543 struct sljit_label* sljit_emit_label(struct sljit_compiler *compiler);
544
545 /* Invert conditional instruction: xor (^) with 0x1 */
546 #define SLJIT_C_EQUAL 0
547 #define SLJIT_C_ZERO 0
548 #define SLJIT_C_NOT_EQUAL 1
549 #define SLJIT_C_NOT_ZERO 1
550
551 #define SLJIT_C_LESS 2
552 #define SLJIT_C_GREATER_EQUAL 3
553 #define SLJIT_C_GREATER 4
554 #define SLJIT_C_LESS_EQUAL 5
555 #define SLJIT_C_SIG_LESS 6
556 #define SLJIT_C_SIG_GREATER_EQUAL 7
557 #define SLJIT_C_SIG_GREATER 8
558 #define SLJIT_C_SIG_LESS_EQUAL 9
559
560 #define SLJIT_C_OVERFLOW 10
561 #define SLJIT_C_NOT_OVERFLOW 11
562
563 #define SLJIT_C_MUL_OVERFLOW 12
564 #define SLJIT_C_MUL_NOT_OVERFLOW 13
565
566 #define SLJIT_C_FLOAT_EQUAL 14
567 #define SLJIT_C_FLOAT_NOT_EQUAL 15
568 #define SLJIT_C_FLOAT_LESS 16
569 #define SLJIT_C_FLOAT_GREATER_EQUAL 17
570 #define SLJIT_C_FLOAT_GREATER 18
571 #define SLJIT_C_FLOAT_LESS_EQUAL 19
572 #define SLJIT_C_FLOAT_NAN 20
573 #define SLJIT_C_FLOAT_NOT_NAN 21
574
575 #define SLJIT_JUMP 22
576 #define SLJIT_CALL0 23
577 #define SLJIT_CALL1 24
578 #define SLJIT_CALL2 25
579 #define SLJIT_CALL3 26
580
581 /* Fast calling method. See sljit_emit_fast_enter / sljit_emit_fast_return. */
582 #define SLJIT_FAST_CALL SLJIT_CALL0
583
584 /* The target can be changed during runtime (see: sljit_set_jump_addr). */
585 #define SLJIT_REWRITABLE_JUMP 0x1000
586
587 /* Emit a jump instruction. The destination is not set, only the type of the jump.
588 type must be between SLJIT_C_EQUAL and SLJIT_CALL3
589 type can be combined (or'ed) with SLJIT_REWRITABLE_JUMP
590 Flags: - (never set any flags) for both conditional and unconditional jumps.
591 Flags: destroy all flags for calls. */
592 struct sljit_jump* sljit_emit_jump(struct sljit_compiler *compiler, int type);
593
594 /* Basic arithmetic comparison. In most architectures it is equal to
595 an SLJIT_SUB operation (with SLJIT_UNUSED destination) followed by a
596 sljit_emit_jump. However some architectures (i.e: MIPS) may employ
597 special optimizations here. It is suggested to use this comparison
598 form when flags are unimportant.
599 type must be between SLJIT_C_EQUAL and SLJIT_C_SIG_LESS_EQUAL
600 type can be combined (or'ed) with SLJIT_REWRITABLE_JUMP or SLJIT_INT_OP
601 Flags: destroy flags. */
602 struct sljit_jump* sljit_emit_cmp(struct sljit_compiler *compiler, int type,
603 int src1, sljit_w src1w,
604 int src2, sljit_w src2w);
605
606 /* Set the destination of the jump to this label. */
607 void sljit_set_label(struct sljit_jump *jump, struct sljit_label* label);
608 /* Only for jumps defined with SLJIT_REWRITABLE_JUMP flag.
609 Note: use sljit_emit_ijump for fixed jumps. */
610 void sljit_set_target(struct sljit_jump *jump, sljit_uw target);
611
612 /* Call function or jump anywhere. Both direct and indirect form
613 type must be between SLJIT_JUMP and SLJIT_CALL3
614 Direct form: set src to SLJIT_IMM() and srcw to the address
615 Indirect form: any other valid addressing mode
616 Flags: - (never set any flags) for unconditional jumps.
617 Flags: destroy all flags for calls. */
618 int sljit_emit_ijump(struct sljit_compiler *compiler, int type, int src, sljit_w srcw);
619
620 /* If op == SLJIT_MOV:
621 Set dst to 1 if condition is fulfilled, 0 otherwise
622 type must be between SLJIT_C_EQUAL and SLJIT_C_FLOAT_NOT_NAN
623 Flags: - (never set any flags)
624 If op == SLJIT_OR
625 Dst is used as src as well, and set its lowest bit to 1 if
626 the condition is fulfilled. Otherwise it does nothing.
627 Flags: E | K
628 Note: sljit_emit_cond_value does nothing, if dst is SLJIT_UNUSED (regardless of op). */
629 int sljit_emit_cond_value(struct sljit_compiler *compiler, int op, int dst, sljit_w dstw, int type);
630
631 /* The constant can be changed runtime (see: sljit_set_const)
632 Flags: - (never set any flags) */
633 struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, int dst, sljit_w dstw, sljit_w init_value);
634
635 /* After the code generation the address for label, jump and const instructions
636 are computed. Since these structures are freed sljit_free_compiler, the
637 addresses must be preserved by the user program elsewere. */
638 static SLJIT_INLINE sljit_uw sljit_get_label_addr(struct sljit_label *label) { return label->addr; }
639 static SLJIT_INLINE sljit_uw sljit_get_jump_addr(struct sljit_jump *jump) { return jump->addr; }
640 static SLJIT_INLINE sljit_uw sljit_get_const_addr(struct sljit_const *const_) { return const_->addr; }
641
642 /* Only the address is required to rewrite the code. */
643 void sljit_set_jump_addr(sljit_uw addr, sljit_uw new_addr);
644 void sljit_set_const(sljit_uw addr, sljit_w new_constant);
645
646 /* --------------------------------------------------------------------- */
647 /* Miscellaneous utility functions */
648 /* --------------------------------------------------------------------- */
649
650 #define SLJIT_MAJOR_VERSION 0
651 #define SLJIT_MINOR_VERSION 82
652
653 /* Get the human readable name of the platfrom.
654 Can be useful for debugging on platforms like ARM, where ARM and
655 Thumb2 functions can be mixed. */
656 SLJIT_CONST char* sljit_get_platform_name(void);
657
658 /* Portble helper function to get an offset of a member. */
659 #define SLJIT_OFFSETOF(base, member) ((sljit_w)(&((base*)0x10)->member) - 0x10)
660
661 #if (defined SLJIT_UTIL_GLOBAL_LOCK && SLJIT_UTIL_GLOBAL_LOCK)
662 /* This global lock is useful to compile common functions. */
663 void SLJIT_CALL sljit_grab_lock(void);
664 void SLJIT_CALL sljit_release_lock(void);
665 #endif
666
667 #if (defined SLJIT_UTIL_STACK && SLJIT_UTIL_STACK)
668
669 /* The sljit_stack is a utiliy feature of sljit, which allocates a
670 writable memory region between base (inclusive) and limit (exclusive).
671 Both base and limit is a pointer, and base is always <= than limit.
672 This feature uses the "address space reserve" feature
673 of modern operating systems. Basically we don't need to allocate a
674 huge memory block in one step for the worst case, we can start with
675 a smaller chunk and extend it later. Since the address space is
676 reserved, the data never copied to other regions, thus it is safe
677 to store pointers here. */
678
679 /* Note: The base field is aligned to PAGE_SIZE bytes (usually 4k or more).
680 Note: stack growing should not happen in small steps: 4k, 16k or even
681 bigger growth is better.
682 Note: this structure may not be supported by all operating systems.
683 Some kind of fallback mechanism is suggested when SLJIT_UTIL_STACK
684 is not defined. */
685
686 struct sljit_stack {
687 /* User data, anything can be stored here.
688 Starting with the same value as base. */
689 sljit_uw top;
690 /* These members are read only. */
691 sljit_uw base;
692 sljit_uw limit;
693 sljit_uw max_limit;
694 };
695
696 /* Returns NULL if unsuccessful.
697 Note: limit and max_limit contains the size for stack allocation
698 Note: the top field is initialized to base. */
699 struct sljit_stack* SLJIT_CALL sljit_allocate_stack(sljit_w limit, sljit_w max_limit);
700 void SLJIT_CALL sljit_free_stack(struct sljit_stack* stack);
701
702 /* Can be used to increase (allocate) or decrease (free) the memory area.
703 Returns with a non-zero value if unsuccessful. If new_limit is greater than
704 max_limit, it will fail. It is very easy to implement a stack data structure,
705 since the growth ratio can be added to the current limit, and sljit_stack_resize
706 will do all the necessary checks. The fields of the stack are not changed if
707 sljit_stack_resize fails. */
708 sljit_w SLJIT_CALL sljit_stack_resize(struct sljit_stack* stack, sljit_uw new_limit);
709
710 #endif /* (defined SLJIT_UTIL_STACK && SLJIT_UTIL_STACK) */
711
712 #if !(defined SLJIT_INDIRECT_CALL && SLJIT_INDIRECT_CALL)
713
714 /* Get the entry address of a given function. */
715 #define SLJIT_FUNC_OFFSET(func_name) ((sljit_w)func_name)
716
717 #else /* !(defined SLJIT_INDIRECT_CALL && SLJIT_INDIRECT_CALL) */
718
719 /* All JIT related code should be placed in the same context (library, binary, etc.). */
720
721 #define SLJIT_FUNC_OFFSET(func_name) ((sljit_w)*(void**)func_name)
722
723 /* For powerpc64, the function pointers point to a context descriptor. */
724 struct sljit_function_context {
725 sljit_w addr;
726 sljit_w r2;
727 sljit_w r11;
728 };
729
730 /* Fill the context arguments using the addr and the function.
731 If func_ptr is NULL, it will not be set to the address of context
732 If addr is NULL, the function address also comes from the func pointer. */
733 void sljit_set_function_context(void** func_ptr, struct sljit_function_context* context, sljit_w addr, void* func);
734
735 #endif /* !(defined SLJIT_INDIRECT_CALL && SLJIT_INDIRECT_CALL) */
736
737 #endif /* _SLJIT_LIR_H_ */

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12