Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize rdbEncodeInteger using bit operations #196

Open
wants to merge 1 commit into
base: unstable
Choose a base branch
from

Commits on Jun 13, 2020

  1. Optimize rdbEncodeInteger using bit operations

    use sign extension mov instructions into 8/16/32 bits int registers to check if value fits
    into 8/16/32 bit width.
    ```
    int function(long long value){
        struct SignExtendBits{
            long long bits8: 8;
            long long bits16: 16;
            long long bits32: 32;
        } v;
    
        v.bits8 = value;
        if ( v.bits8 == value ) return 1;
        m.bits16 = value;
        if ( m.bits16 == value ) return 2;
        m.bits32 = value;
        if ( m.bits32 == value ) return 3;
    
        return 0;
    }
    
    Compiles to compact code even with -O1 :
    function(long long):
            movsx rcx, dil
            mov eax, 1
            cmp rcx, rdi
            je .LBB1_3
            movsx rcx, di
            mov eax, 2
            cmp rcx, rdi
            je .LBB1_3
            movsxd rcx, edi
            xor eax, eax
            cmp rcx, rdi
            sete al
            shl eax, 2
    .LBB1_3:
            ret
    ```
    tryfinally committed Jun 13, 2020
    Configuration menu
    Copy the full SHA
    235f655 View commit details
    Browse the repository at this point in the history