|  | 
| 120 | 120 |  */ | 
| 121 | 121 | 
 | 
| 122 | 122 | /* Internal */ | 
| 123 |  | -RVOP(nop, { rv->X[rv_reg_zero] = 0; }, GEN({/* no operation */})) | 
|  | 123 | +RVOP( | 
|  | 124 | +    nop, | 
|  | 125 | +    { rv->X[rv_reg_zero] = 0; }, | 
|  | 126 | +    GEN({/* no operation */})) | 
| 124 | 127 | 
 | 
| 125 | 128 | /* LUI is used to build 32-bit constants and uses the U-type format. LUI | 
| 126 | 129 |  * places the U-immediate value in the top 20 bits of the destination | 
| @@ -364,78 +367,72 @@ RVOP( | 
| 364 | 367 |     (type) x cond (type) y | 
| 365 | 368 | /* clang-format on */ | 
| 366 | 369 | 
 | 
| 367 |  | -#define BRANCH_FUNC(type, cond)                                             \ | 
| 368 |  | -    IIF(RV32_HAS(EXT_C))(, const uint32_t pc = PC;);                        \ | 
| 369 |  | -    if (BRANCH_COND(type, rv->X[ir->rs1], rv->X[ir->rs2], cond)) {          \ | 
| 370 |  | -        IIF(RV32_HAS(SYSTEM))                                               \ | 
| 371 |  | -        (                                                                   \ | 
| 372 |  | -            {                                                               \ | 
| 373 |  | -                if (!rv->is_trapped) {                                      \ | 
| 374 |  | -                    is_branch_taken = false;                                \ | 
| 375 |  | -                }                                                           \ | 
| 376 |  | -            },                                                              \ | 
| 377 |  | -            is_branch_taken = false;);                                      \ | 
| 378 |  | -        struct rv_insn *untaken = ir->branch_untaken;                       \ | 
| 379 |  | -        if (!untaken)                                                       \ | 
| 380 |  | -            goto nextop;                                                    \ | 
| 381 |  | -        IIF(RV32_HAS(JIT))                                                  \ | 
| 382 |  | -        (                                                                   \ | 
| 383 |  | -            {                                                               \ | 
| 384 |  | -                block_t *next = cache_get(rv->block_cache, PC + 4, true);   \ | 
| 385 |  | -                if (next IIF(RV32_HAS(SYSTEM))(                             \ | 
| 386 |  | -                        &&next->satp == rv->csr_satp, )) {                  \ | 
| 387 |  | -                    if (!set_add(&pc_set, PC + 4))                          \ | 
| 388 |  | -                        has_loops = true;                                   \ | 
| 389 |  | -                    if (cache_hot(rv->block_cache, PC + 4))                 \ | 
| 390 |  | -                        goto nextop;                                        \ | 
| 391 |  | -                }                                                           \ | 
| 392 |  | -            }, );                                                           \ | 
| 393 |  | -        PC += 4;                                                            \ | 
| 394 |  | -        IIF(RV32_HAS(SYSTEM))                                               \ | 
| 395 |  | -        (                                                                   \ | 
| 396 |  | -            {                                                               \ | 
| 397 |  | -                if (!rv->is_trapped) {                                      \ | 
| 398 |  | -                    last_pc = PC;                                           \ | 
| 399 |  | -                    MUST_TAIL return untaken->impl(rv, untaken, cycle, PC); \ | 
| 400 |  | -                }                                                           \ | 
| 401 |  | -            }, );                                                           \ | 
| 402 |  | -        goto end_op;                                                        \ | 
| 403 |  | -    }                                                                       \ | 
| 404 |  | -    IIF(RV32_HAS(SYSTEM))                                                   \ | 
| 405 |  | -    (                                                                       \ | 
| 406 |  | -        {                                                                   \ | 
| 407 |  | -            if (!rv->is_trapped) {                                          \ | 
| 408 |  | -                is_branch_taken = true;                                     \ | 
| 409 |  | -            }                                                               \ | 
| 410 |  | -        },                                                                  \ | 
| 411 |  | -        is_branch_taken = true;);                                           \ | 
| 412 |  | -    PC += ir->imm;                                                          \ | 
| 413 |  | -    /* check instruction misaligned */                                      \ | 
| 414 |  | -    IIF(RV32_HAS(EXT_C))                                                    \ | 
| 415 |  | -    (, RV_EXC_MISALIGN_HANDLER(pc, INSN, false, 0););                       \ | 
| 416 |  | -    struct rv_insn *taken = ir->branch_taken;                               \ | 
| 417 |  | -    if (taken) {                                                            \ | 
| 418 |  | -        IIF(RV32_HAS(JIT))                                                  \ | 
| 419 |  | -        (                                                                   \ | 
| 420 |  | -            {                                                               \ | 
| 421 |  | -                block_t *next = cache_get(rv->block_cache, PC, true);       \ | 
| 422 |  | -                if (next IIF(RV32_HAS(SYSTEM))(                             \ | 
| 423 |  | -                        &&next->satp == rv->csr_satp, )) {                  \ | 
| 424 |  | -                    if (!set_add(&pc_set, PC))                              \ | 
| 425 |  | -                        has_loops = true;                                   \ | 
| 426 |  | -                    if (cache_hot(rv->block_cache, PC))                     \ | 
| 427 |  | -                        goto end_op;                                        \ | 
| 428 |  | -                }                                                           \ | 
| 429 |  | -            }, );                                                           \ | 
| 430 |  | -        IIF(RV32_HAS(SYSTEM))                                               \ | 
| 431 |  | -        (                                                                   \ | 
| 432 |  | -            {                                                               \ | 
| 433 |  | -                if (!rv->is_trapped) {                                      \ | 
| 434 |  | -                    last_pc = PC;                                           \ | 
| 435 |  | -                    MUST_TAIL return taken->impl(rv, taken, cycle, PC);     \ | 
| 436 |  | -                }                                                           \ | 
| 437 |  | -            }, );                                                           \ | 
| 438 |  | -    }                                                                       \ | 
|  | 370 | +#define BRANCH_FUNC(type, cond)                                               \ | 
|  | 371 | +    IIF(RV32_HAS(EXT_C))(, const uint32_t pc = PC;);                          \ | 
|  | 372 | +    if (BRANCH_COND(type, rv->X[ir->rs1], rv->X[ir->rs2], cond)) {            \ | 
|  | 373 | +        IIF(RV32_HAS(SYSTEM))                                                 \ | 
|  | 374 | +        (                                                                     \ | 
|  | 375 | +            {                                                                 \ | 
|  | 376 | +                if (!rv->is_trapped) {                                        \ | 
|  | 377 | +                    is_branch_taken = false;                                  \ | 
|  | 378 | +                }                                                             \ | 
|  | 379 | +            },                                                                \ | 
|  | 380 | +            is_branch_taken = false;);                                        \ | 
|  | 381 | +        struct rv_insn *untaken = ir->branch_untaken;                         \ | 
|  | 382 | +        if (!untaken)                                                         \ | 
|  | 383 | +            goto nextop;                                                      \ | 
|  | 384 | +        IIF(RV32_HAS(JIT))                                                    \ | 
|  | 385 | +        ({                                                                    \ | 
|  | 386 | +            block_t *next = cache_get(rv->block_cache, PC + 4, true);         \ | 
|  | 387 | +            if (next IIF(RV32_HAS(SYSTEM))(&&next->satp == rv->csr_satp, )) { \ | 
|  | 388 | +                if (!set_add(&pc_set, PC + 4))                                \ | 
|  | 389 | +                    has_loops = true;                                         \ | 
|  | 390 | +                if (cache_hot(rv->block_cache, PC + 4))                       \ | 
|  | 391 | +                    goto nextop;                                              \ | 
|  | 392 | +            }                                                                 \ | 
|  | 393 | +        }, );                                                                 \ | 
|  | 394 | +        PC += 4;                                                              \ | 
|  | 395 | +        IIF(RV32_HAS(SYSTEM))                                                 \ | 
|  | 396 | +        ({                                                                    \ | 
|  | 397 | +            if (!rv->is_trapped) {                                            \ | 
|  | 398 | +                last_pc = PC;                                                 \ | 
|  | 399 | +                MUST_TAIL return untaken->impl(rv, untaken, cycle, PC);       \ | 
|  | 400 | +            }                                                                 \ | 
|  | 401 | +        }, );                                                                 \ | 
|  | 402 | +        goto end_op;                                                          \ | 
|  | 403 | +    }                                                                         \ | 
|  | 404 | +    IIF(RV32_HAS(SYSTEM))                                                     \ | 
|  | 405 | +    (                                                                         \ | 
|  | 406 | +        {                                                                     \ | 
|  | 407 | +            if (!rv->is_trapped) {                                            \ | 
|  | 408 | +                is_branch_taken = true;                                       \ | 
|  | 409 | +            }                                                                 \ | 
|  | 410 | +        },                                                                    \ | 
|  | 411 | +        is_branch_taken = true;);                                             \ | 
|  | 412 | +    PC += ir->imm;                                                            \ | 
|  | 413 | +    /* check instruction misaligned */                                        \ | 
|  | 414 | +    IIF(RV32_HAS(EXT_C))                                                      \ | 
|  | 415 | +    (, RV_EXC_MISALIGN_HANDLER(pc, INSN, false, 0););                         \ | 
|  | 416 | +    struct rv_insn *taken = ir->branch_taken;                                 \ | 
|  | 417 | +    if (taken) {                                                              \ | 
|  | 418 | +        IIF(RV32_HAS(JIT))                                                    \ | 
|  | 419 | +        ({                                                                    \ | 
|  | 420 | +            block_t *next = cache_get(rv->block_cache, PC, true);             \ | 
|  | 421 | +            if (next IIF(RV32_HAS(SYSTEM))(&&next->satp == rv->csr_satp, )) { \ | 
|  | 422 | +                if (!set_add(&pc_set, PC))                                    \ | 
|  | 423 | +                    has_loops = true;                                         \ | 
|  | 424 | +                if (cache_hot(rv->block_cache, PC))                           \ | 
|  | 425 | +                    goto end_op;                                              \ | 
|  | 426 | +            }                                                                 \ | 
|  | 427 | +        }, );                                                                 \ | 
|  | 428 | +        IIF(RV32_HAS(SYSTEM))                                                 \ | 
|  | 429 | +        ({                                                                    \ | 
|  | 430 | +            if (!rv->is_trapped) {                                            \ | 
|  | 431 | +                last_pc = PC;                                                 \ | 
|  | 432 | +                MUST_TAIL return taken->impl(rv, taken, cycle, PC);           \ | 
|  | 433 | +            }                                                                 \ | 
|  | 434 | +        }, );                                                                 \ | 
|  | 435 | +    }                                                                         \ | 
| 439 | 436 |     goto end_op; | 
| 440 | 437 | 
 | 
| 441 | 438 | /* In RV32I and RV64I, if the branch is taken, set pc = pc + offset, where | 
|  | 
0 commit comments