From: K.Kosako Date: Wed, 6 Feb 2019 07:40:44 +0000 (+0900) Subject: use direct threaded code for GNU C X-Git-Tag: v6.9.2_rc1~65^2~61 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b00cc7757f860ea005281c11550dfc2ddab5fe54;p=onig use direct threaded code for GNU C --- diff --git a/src/regcomp.c b/src/regcomp.c index 792485a..4889833 100644 --- a/src/regcomp.c +++ b/src/regcomp.c @@ -6128,6 +6128,8 @@ onig_compile(regex_t* reg, const UChar* pattern, const UChar* pattern_end, { #define OPS_INIT_SIZE 8 + extern int onig_init_for_match_at(regex_t* reg); + int r; Node* root; ScanEnv scan_env; @@ -6271,6 +6273,13 @@ onig_compile(regex_t* reg, const UChar* pattern, const UChar* pattern_end, onig_print_compiled_byte_code_list(stderr, reg); #endif +#ifdef USE_THREADED_CODE +#ifdef USE_DIRECT_THREADED_CODE + /* opcode -> opaddr */ + onig_init_for_match_at(reg); +#endif +#endif + end: return r; diff --git a/src/regexec.c b/src/regexec.c index 0ff8612..be3c387 100644 --- a/src/regexec.c +++ b/src/regexec.c @@ -2367,9 +2367,6 @@ typedef struct { } posix_regmatch_t; -#ifdef __GNUC__ -#define USE_THREADED_CODE -#endif #ifdef USE_THREADED_CODE @@ -2379,7 +2376,11 @@ typedef struct { #define DEFAULT_OP /* L_DEFAULT: */ #define NEXT_OP sprev = sbegin; JUMP_OP #define JUMP_OP GOTO_OP +#ifdef USE_DIRECT_THREADED_CODE +#define GOTO_OP goto *(p->opaddr) +#else #define GOTO_OP goto *opcode_to_label[p->opcode] +#endif #define BREAK_OP /* Nothing */ #else @@ -2449,7 +2450,12 @@ match_at(regex_t* reg, const UChar* str, const UChar* end, const UChar* in_right_range, const UChar* sstart, UChar* sprev, MatchArg* msa) { - static Operation FinishCode[] = { { OP_FINISH } }; + +#if defined(USE_THREADED_CODE) && defined(USE_DIRECT_THREADED_CODE) + static Operation FinishCode[] = { { {.opaddr=&&L_FINISH} } }; +#else + static Operation FinishCode[] = { { {OP_FINISH} } }; +#endif #ifdef USE_THREADED_CODE static const void *opcode_to_label[] = { @@ -2584,6 +2590,22 @@ match_at(regex_t* reg, const UChar* str, const UChar* end, static unsigned int counter = 1; #endif +#ifdef USE_THREADED_CODE +#ifdef USE_DIRECT_THREADED_CODE + if (IS_NULL(msa)) { + for (i = 0; i < reg->ops_used; i++) { + const void* addr; + /* fprintf(stdout, "code: %d, ", p->opcode); */ + addr = opcode_to_label[p->opcode]; + p->opaddr = addr; + /* fprintf(stdout, "addr: %p\n", p->opaddr); */ + p++; + } + return ONIG_NORMAL; + } +#endif +#endif + #ifdef USE_CALLOUT msa->mp->match_at_call_counter++; #endif @@ -3620,20 +3642,7 @@ match_at(regex_t* reg, const UChar* str, const UChar* end, fprintf(stderr, "EMPTY_CHECK_END: skip id:%d, s:%p\n", (int )mem, s); #endif empty_check_found: - /* empty loop founded, skip next instruction */ - switch (p->opcode) { - case OP_JUMP: - case OP_PUSH: - case OP_REPEAT_INC: - case OP_REPEAT_INC_NG: - case OP_REPEAT_INC_SG: - case OP_REPEAT_INC_NG_SG: - INC_OP; - break; - default: - goto unexpected_bytecode_error; - break; - } + INC_OP; } } JUMP_OUT; @@ -4070,10 +4079,6 @@ match_at(regex_t* reg, const UChar* str, const UChar* end, STACK_SAVE; return ONIGERR_UNDEFINED_BYTECODE; - unexpected_bytecode_error: - STACK_SAVE; - return ONIGERR_UNEXPECTED_BYTECODE; - #ifdef USE_RETRY_LIMIT_IN_MATCH retry_limit_in_match_over: STACK_SAVE; @@ -5372,6 +5377,18 @@ onig_get_used_stack_size_in_callout(OnigCalloutArgs* a, int* used_num, int* used return ONIG_NORMAL; } +#ifdef USE_THREADED_CODE +#ifdef USE_DIRECT_THREADED_CODE +extern int +onig_init_for_match_at(regex_t* reg) +{ + return match_at(reg, (const UChar* )NULL, (const UChar* )NULL, + (const UChar* )NULL, (const UChar* )NULL, (UChar* )NULL, + (MatchArg* )NULL); +} +#endif +#endif + /* builtin callout functions */ diff --git a/src/regint.h b/src/regint.h index d750a8d..f8ba337 100644 --- a/src/regint.h +++ b/src/regint.h @@ -54,6 +54,10 @@ #define PLATFORM_UNALIGNED_WORD_ACCESS #endif +#ifdef __GNUC__ +#define USE_THREADED_CODE +#endif + /* config */ /* spec. config */ #define USE_CALL @@ -63,6 +67,9 @@ #define USE_NEWLINE_AT_END_OF_STRING_HAS_EMPTY_LINE /* /\n$/ =~ "\n" */ #define USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR #define USE_RETRY_LIMIT_IN_MATCH +#ifdef USE_THREADED_CODE +#define USE_DIRECT_THREADED_CODE +#endif /* internal config */ #define USE_OP_PUSH_OR_JUMP_EXACT @@ -791,7 +798,10 @@ typedef int ModeType; typedef struct { - enum OpCode opcode; + union { + enum OpCode opcode; + const void* opaddr; + }; union { struct { UChar* s;