summaryrefslogtreecommitdiff
path: root/2020/05/seat_id_ssse3.asm
blob: 4d51cbe36a04dca89aa0cd788f4cd272418f1de7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
global seat_id

section .rodata
    align 16
    xmm_shuf:   db 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 10, 11, 12, 13, 14, 15
    xmm_cmp:    db 1, 'RBBBBBBB', 1, 1, 1, 1, 1, 1, 1

section .text

seat_id:
    movq        xmm0, qword [rdi]       ; load first 8 bytes
    pshufb      xmm0, [rel xmm_shuf]    ; reverse byte order and already shift left once
    pcmpeqb     xmm0, [rel xmm_cmp]
    pmovmskb    eax, xmm0               ; store mask in return value
    xor         ecx, ecx
    cmp         byte [rdi + 8], 'R'
    sete        cl
    or          eax, ecx
    shl         eax, 1
    cmp         byte [rdi + 9], 'R'
    sete        cl
    or          eax, ecx
    ret