-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfastqueue_x86_64.asm
67 lines (59 loc) · 1.56 KB
/
fastqueue_x86_64.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
; Created by Anders Cedronius
section .text
bits 64
BUFFER_MASK equ 15
L1_CACHE equ 64
SHIFT_NO equ ((L1_CACHE) / ((L1_CACHE) % 255 + 1) / 255 % 255 * 8 + 7 - 86 / ((L1_CACHE) % 255 + 12))
global push_item
global pop_item
global verify_mask
global verify_cache_size
verify_mask:
mov rax,rdi
sub rax, BUFFER_MASK
ret
verify_cache_size:
mov rax,rdi
sub rax, L1_CACHE
ret
push_item:
mov r11, [rdi + (L1_CACHE * 1)] ;mWritePositionPush
push_loop:
cmp [rdi + (L1_CACHE * 6)], byte 0 ;mExitThreadSemaphore
jnz exit_loop
mov rcx, r11
sub rcx, [rdi + (L1_CACHE * 2)] ;mReadPositionPush
cmp rcx, BUFFER_MASK
jge push_loop
mov rax, r11
inc r11
and rax, BUFFER_MASK
shl rax, SHIFT_NO
add rax, (L1_CACHE * 7) ;mRingBuffer
mov [rdi + rax], rsi
sfence
mov [rdi + (L1_CACHE * 1)], r11 ;mWritePositionPush
mov [rdi + (L1_CACHE * 3)], r11 ;mWritePositionPop
exit_loop:
ret
pop_item:
mov rcx, [rdi + (L1_CACHE * 4)] ;mReadPositionPop
cmp rcx, [rdi + (L1_CACHE * 3)] ;mWritePositionPop
jne entry_found
sub rcx, [rdi + (L1_CACHE * 5)] ;mExitThread (0 = true)
jnz pop_item
cmp [rdi + (L1_CACHE * 6)], byte 0 ;mExitThreadSemaphore (1 = true)
jz pop_item
xor rax, rax
ret
entry_found:
mov r11, rcx
inc r11
and rcx, BUFFER_MASK
shl rcx, SHIFT_NO
add rcx, (L1_CACHE * 7) ;mRingBuffer
mov rax, [rdi + rcx]
lfence
mov [rdi + (L1_CACHE * 4)], r11 ;mReadPositionPop
mov [rdi + (L1_CACHE * 2)], r11 ;mReadPositionPush
ret