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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1215 by zherczeg, Fri Nov 9 08:13:13 2012 UTC revision 1216 by zherczeg, Fri Nov 9 13:05:29 2012 UTC
# Line 34  Line 34 
34    
35     Short description     Short description
36      Advantages:      Advantages:
37        - The execution can be continued from any LIR instruction        - The execution can be continued from any LIR instruction. In other
38          In other words, jump into and out of the code is safe          words, it is possible to jump to any label from anywhere, even from
39        - Both target of (conditional) jump and call instructions          a code fragment, which is compiled later, if both compiled code
40          and constants can be dynamically modified during runtime          shares the same context. See sljit_emit_enter for more details
41          - Supports self modifying code: target of (conditional) jump and call
42            instructions and some constant values can be dynamically modified
43            during runtime
44          - although it is not suggested to do it frequently          - although it is not suggested to do it frequently
45          - very effective to cache an important value once          - can be used for inline caching: save an important value once
46              in the instruction stream
47            - since this feature limits the optimization possibilities, a
48              special flag must be passed at compile time when these
49              instructions are emitted
50        - A fixed stack space can be allocated for local variables        - A fixed stack space can be allocated for local variables
51        - The compiler is thread-safe        - The compiler is thread-safe
52        - The compiler is highly configurable through preprocessor macros.        - The compiler is highly configurable through preprocessor macros.
# Line 47  Line 54 
54          threaded applications), and you can use your own system functions          threaded applications), and you can use your own system functions
55          (including memory allocators). See sljitConfig.h          (including memory allocators). See sljitConfig.h
56      Disadvantages:      Disadvantages:
57          - No automatic register allocation, and temporary results are
58            not stored on the stack. (hence the name comes)
59        - Limited number of registers (only 6+4 integer registers, max 3+2        - Limited number of registers (only 6+4 integer registers, max 3+2
60          scratch, max 3+2 saved and 6 floating point registers)          scratch, max 3+2 saved and 6 floating point registers)
61      In practice:      In practice:
62        - This approach is very effective for interpreters        - This approach is very effective for interpreters
63          - One of the saved registers typically points to a stack interface          - One of the saved registers typically points to a stack interface
64          - It can jump to any exception handler anytime (even for another          - It can jump to any exception handler anytime (even if it belongs
65            function. It is safe for SLJIT.)            to another function)
66          - Fast paths can be modified during runtime reflecting the changes          - Hot paths can be modified during runtime reflecting the changes
67            of the fastest execution path of the dynamic language            of the fastest execution path of the dynamic language
68          - SLJIT supports complex memory addressing modes          - SLJIT supports complex memory addressing modes
69          - mainly position independent code          - mainly position and context independent code (except some cases)
       - Optimizations (perhaps later)  
         - Only for basic blocks (when no labels inserted between LIR instructions)  
70    
71      For valgrind users:      For valgrind users:
72        - pass --smc-check=all argument to valgrind, since JIT is a "self-modifying code"        - pass --smc-check=all argument to valgrind, since JIT is a "self-modifying code"
# Line 99  of sljitConfigInternal.h */ Line 106  of sljitConfigInternal.h */
106    
107  #define SLJIT_UNUSED            0  #define SLJIT_UNUSED            0
108    
109  /* Scratch (temporary) registers may not preserve their values across function calls. */  /* Scratch (temporary) registers whose may not preserve their values
110       across function calls. */
111  #define SLJIT_SCRATCH_REG1      1  #define SLJIT_SCRATCH_REG1      1
112  #define SLJIT_SCRATCH_REG2      2  #define SLJIT_SCRATCH_REG2      2
113  #define SLJIT_SCRATCH_REG3      3  #define SLJIT_SCRATCH_REG3      3
114  /* Note: extra registers cannot be used for memory addressing. */  /* Note: extra registers cannot be used for memory addressing. */
115  /* Note: on x86-32, these registers are emulated (using stack loads & stores). */  /* Note: on x86-32, these registers are emulated (using stack
116       loads & stores). */
117  #define SLJIT_TEMPORARY_EREG1   4  #define SLJIT_TEMPORARY_EREG1   4
118  #define SLJIT_TEMPORARY_EREG2   5  #define SLJIT_TEMPORARY_EREG2   5
119    
# Line 113  of sljitConfigInternal.h */ Line 122  of sljitConfigInternal.h */
122  #define SLJIT_SAVED_REG2        7  #define SLJIT_SAVED_REG2        7
123  #define SLJIT_SAVED_REG3        8  #define SLJIT_SAVED_REG3        8
124  /* Note: extra registers cannot be used for memory addressing. */  /* Note: extra registers cannot be used for memory addressing. */
125  /* Note: on x86-32, these registers are emulated (using stack loads & stores). */  /* Note: on x86-32, these registers are emulated (using stack
126       loads & stores). */
127  #define SLJIT_SAVED_EREG1       9  #define SLJIT_SAVED_EREG1       9
128  #define SLJIT_SAVED_EREG2       10  #define SLJIT_SAVED_EREG2       10
129    
130  /* Read-only register (cannot be the destination of an operation).  /* Read-only register (cannot be the destination of an operation).
131     Only SLJIT_MEM1(SLJIT_LOCALS_REG) addressing mode is allowed since     Only SLJIT_MEM1(SLJIT_LOCALS_REG) addressing mode is allowed since
132     several ABIs has certain limitations about the stack layout. However     several ABIs has certain limitations about the stack layout. However
133     sljit_get_local_base() can be used to obtain the offset of a value. */     sljit_get_local_base() can be used to obtain the offset of a value
134       on the stack. */
135  #define SLJIT_LOCALS_REG        11  #define SLJIT_LOCALS_REG        11
136    
137  /* Number of registers. */  /* Number of registers. */
# Line 147  of sljitConfigInternal.h */ Line 158  of sljitConfigInternal.h */
158  /* Note: SLJIT_UNUSED as destination is not valid for floating point  /* Note: SLJIT_UNUSED as destination is not valid for floating point
159       operations, since they cannot be used for setting flags. */       operations, since they cannot be used for setting flags. */
160    
161  /* Floating point operations are performed on double precision values. */  /* Floating point operations are performed on double or
162       single precision values. */
163    
164  #define SLJIT_FLOAT_REG1        1  #define SLJIT_FLOAT_REG1        1
165  #define SLJIT_FLOAT_REG2        2  #define SLJIT_FLOAT_REG2        2
# Line 290  struct sljit_compiler { Line 302  struct sljit_compiler {
302  /* Creates an sljit compiler.  /* Creates an sljit compiler.
303     Returns NULL if failed. */     Returns NULL if failed. */
304  SLJIT_API_FUNC_ATTRIBUTE struct sljit_compiler* sljit_create_compiler(void);  SLJIT_API_FUNC_ATTRIBUTE struct sljit_compiler* sljit_create_compiler(void);
305  /* Free everything except the codes. */  
306    /* Free everything except the compiled machine code. */
307  SLJIT_API_FUNC_ATTRIBUTE void sljit_free_compiler(struct sljit_compiler *compiler);  SLJIT_API_FUNC_ATTRIBUTE void sljit_free_compiler(struct sljit_compiler *compiler);
308    
309    /* Returns the current error code. If an error is occured, future sljit
310       calls which uses the same compiler argument returns early with the same
311       error code. Thus there is no need for checking the error after every
312       call, it is enough to do it before the code is compiled. Removing
313       these checks increases the performance of the compiling process. */
314  static SLJIT_INLINE sljit_si sljit_get_compiler_error(struct sljit_compiler *compiler) { return compiler->error; }  static SLJIT_INLINE sljit_si sljit_get_compiler_error(struct sljit_compiler *compiler) { return compiler->error; }
315    
316  /*  /*
317     Allocate a small amount of memory. The size must be <= 64 bytes on 32 bit,     Allocate a small amount of memory. The size must be <= 64 bytes on 32 bit,
318     and <= 128 bytes on 64 bit architectures. The memory area is owned by the compiler,     and <= 128 bytes on 64 bit architectures. The memory area is owned by the
319     and freed by sljit_free_compiler. The returned pointer is sizeof(sljit_sw) aligned.     compiler, and freed by sljit_free_compiler. The returned pointer is
320     Excellent for allocating small blocks during the compiling, and no need to worry     sizeof(sljit_sw) aligned. Excellent for allocating small blocks during
321     about freeing them. The size is enough to contain at most 16 pointers.     the compiling, and no need to worry about freeing them. The size is
322     If the size is outside of the range, the function will return with NULL,     enough to contain at most 16 pointers. If the size is outside of the range,
323     but this return value does not indicate that there is no more memory (does     the function will return with NULL. However, this return value does not
324     not set the compiler to out-of-memory status).     indicate that there is no more memory (does not set the current error code
325       of the compiler to out-of-memory status).
326  */  */
327  SLJIT_API_FUNC_ATTRIBUTE void* sljit_alloc_memory(struct sljit_compiler *compiler, sljit_si size);  SLJIT_API_FUNC_ATTRIBUTE void* sljit_alloc_memory(struct sljit_compiler *compiler, sljit_si size);
328    
# Line 316  SLJIT_API_FUNC_ATTRIBUTE void* sljit_gen Line 335  SLJIT_API_FUNC_ATTRIBUTE void* sljit_gen
335  SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code);  SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code);
336    
337  /*  /*
338     After the code generation we can retrieve the allocated executable memory size,     After the machine code generation is finished we can retrieve the allocated
339     although this area may not be fully filled with instructions depending on some     executable memory size, although this area may not be fully filled with
340     optimizations. This function is useful only for statistical purposes.     instructions depending on some optimizations. This function is useful only
341       for statistical purposes.
342    
343     Before a successful code generation, this function returns with 0.     Before a successful code generation, this function returns with 0.
344  */  */
345  static SLJIT_INLINE sljit_uw sljit_get_generated_code_size(struct sljit_compiler *compiler) { return compiler->executable_size; }  static SLJIT_INLINE sljit_uw sljit_get_generated_code_size(struct sljit_compiler *compiler) { return compiler->executable_size; }
346    
347  /* Instruction generation. Returns with error code. */  /* Instruction generation. Returns with any error code. If there is no
348       error, they return with SLJIT_SUCCESS. */
349    
350  /*  /*
351     The executable code is basically a function call from the viewpoint of     The executable code is basically a function call from the viewpoint of
# Line 347  static SLJIT_INLINE sljit_uw sljit_get_g Line 368  static SLJIT_INLINE sljit_uw sljit_get_g
368     SLJIT_LOCALS_REG + local_size (exclusive) can be modified freely     SLJIT_LOCALS_REG + local_size (exclusive) can be modified freely
369     until the function returns. The stack space is uninitialized.     until the function returns. The stack space is uninitialized.
370    
371     Note: every call of sljit_emit_enter and sljit_set_context overwrites     Note: every call of sljit_emit_enter and sljit_set_context
372           the previous context. */           overwrites the previous context. */
373    
374  #define SLJIT_MAX_LOCAL_SIZE    65536  #define SLJIT_MAX_LOCAL_SIZE    65536
375    
# Line 360  SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_ Line 381  SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_
381     functions (like sljit_emit_return) requres this context to be able to generate     functions (like sljit_emit_return) requres this context to be able to generate
382     the appropriate code. However, some code fragments (like inline cache) may have     the appropriate code. However, some code fragments (like inline cache) may have
383     no normal entry point so their context is unknown for the compiler. Using the     no normal entry point so their context is unknown for the compiler. Using the
384     function below we can specify thir context.     function below we can specify their context.
385    
386     Note: every call of sljit_emit_enter and sljit_set_context overwrites     Note: every call of sljit_emit_enter and sljit_set_context overwrites
387           the previous context. */           the previous context. */
388    
 /* Note: multiple calls of this function overwrites the previous call. */  
   
389  SLJIT_API_FUNC_ATTRIBUTE void sljit_set_context(struct sljit_compiler *compiler,  SLJIT_API_FUNC_ATTRIBUTE void sljit_set_context(struct sljit_compiler *compiler,
390          sljit_si args, sljit_si scratches, sljit_si saveds, sljit_si local_size);          sljit_si args, sljit_si scratches, sljit_si saveds, sljit_si local_size);
391    
# Line 375  SLJIT_API_FUNC_ATTRIBUTE void sljit_set_ Line 394  SLJIT_API_FUNC_ATTRIBUTE void sljit_set_
394     SLJIT_MOV_P (see sljit_emit_op1). As for src and srcw they must be 0 if op     SLJIT_MOV_P (see sljit_emit_op1). As for src and srcw they must be 0 if op
395     is SLJIT_UNUSED, otherwise see below the description about source and     is SLJIT_UNUSED, otherwise see below the description about source and
396     destination arguments. */     destination arguments. */
397    
398  SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_return(struct sljit_compiler *compiler, sljit_si op,  SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_return(struct sljit_compiler *compiler, sljit_si op,
399          sljit_si src, sljit_sw srcw);          sljit_si src, sljit_sw srcw);
400    
401  /* Really fast calling method for utility functions inside sljit (see SLJIT_FAST_CALL).  /* Fast calling mechanism for utility functions (see SLJIT_FAST_CALL). All registers and
402     All registers and even the stack frame is passed to the callee. The return address is     even the stack frame is passed to the callee. The return address is preserved in
403     preserved in dst/dstw by sljit_emit_fast_enter (the type of the value stored by this     dst/dstw by sljit_emit_fast_enter (the type of the value stored by this function
404     function is sljit_p), and sljit_emit_fast_return can use this as a return value later. */     is sljit_p), and sljit_emit_fast_return can use this as a return value later. */
405    
406  /* Note: only for sljit specific, non ABI compilant calls. Fast, since only a few machine  /* Note: only for sljit specific, non ABI compilant calls. Fast, since only a few machine
407     instructions are needed. Excellent for small uility functions, where saving registers     instructions are needed. Excellent for small uility functions, where saving registers
# Line 445  SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_ Line 465  SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_
465             Write-back is supported except for one instruction: 32 bit signed             Write-back is supported except for one instruction: 32 bit signed
466                  load with [reg+imm] addressing mode on 64 bit.                  load with [reg+imm] addressing mode on 64 bit.
467     mips:   [reg+imm], -65536 <= imm <= 65535     mips:   [reg+imm], -65536 <= imm <= 65535
            Nothing else is supported  
468     sparc:  [reg+imm], -4096 <= imm <= 4095     sparc:  [reg+imm], -4096 <= imm <= 4095
469             [reg+reg] is supported             [reg+reg] is supported
            Nothing else is supported  
470  */  */
471    
472  /* Register output: simply the name of the register.  /* Register output: simply the name of the register.
# Line 880  SLJIT_API_FUNC_ATTRIBUTE void sljit_set_ Line 898  SLJIT_API_FUNC_ATTRIBUTE void sljit_set_
898  #define SLJIT_MAJOR_VERSION     0  #define SLJIT_MAJOR_VERSION     0
899  #define SLJIT_MINOR_VERSION     90  #define SLJIT_MINOR_VERSION     90
900    
901  /* Get the human readable name of the platfrom.  /* Get the human readable name of the platfrom. Can be useful on platforms
902     Can be useful for debugging on platforms like ARM, where ARM and     like ARM, where ARM and Thumb2 functions can be mixed, and
903     Thumb2 functions can be mixed. */     it is useful to know the type of the code generator. */
904  SLJIT_API_FUNC_ATTRIBUTE SLJIT_CONST char* sljit_get_platform_name(void);  SLJIT_API_FUNC_ATTRIBUTE SLJIT_CONST char* sljit_get_platform_name(void);
905    
906  /* Portble helper function to get an offset of a member. */  /* Portble helper function to get an offset of a member. */

Legend:
Removed from v.1215  
changed lines
  Added in v.1216

  ViewVC Help
Powered by ViewVC 1.1.5