Created
January 18, 2012 16:39
-
-
Save antirez/1633930 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unsigned long zslGetRank(zskiplist *zsl, double score, robj *o) { | |
zskiplistNode *x; | |
unsigned long rank = 0; | |
int i; | |
x = zsl->header; | |
for (i = zsl->level-1; i >= 0; i--) { | |
while (x->level[i].forward && | |
(x->level[i].forward->score < score || | |
(x->level[i].forward->score == score && | |
compareStringObjects(x->level[i].forward->obj,o) <= 0))) { | |
rank += x->level[i].span; | |
x = x->level[i].forward; | |
} | |
/* x might be equal to zsl->header, so test if obj is non-NULL */ | |
if (x->obj && equalStringObjects(x->obj,o)) { | |
return rank; | |
} | |
} | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Dump of assembler code for function zslGetRank: | |
0x0000000000427fd0 <+0>: push %r14 | |
0x0000000000427fd2 <+2>: push %r13 | |
0x0000000000427fd4 <+4>: mov %rsi,%r13 | |
0x0000000000427fd7 <+7>: push %r12 | |
0x0000000000427fd9 <+9>: push %rbp | |
0x0000000000427fda <+10>: push %rbx | |
0x0000000000427fdb <+11>: sub $0x10,%rsp | |
0x0000000000427fdf <+15>: mov 0x18(%rdi),%r14d | |
0x0000000000427fe3 <+19>: mov (%rdi),%rbx | |
0x0000000000427fe6 <+22>: sub $0x1,%r14d | |
0x0000000000427fea <+26>: js 0x428076 <zslGetRank+166> | |
0x0000000000427ff0 <+32>: xor %r12d,%r12d | |
0x0000000000427ff3 <+35>: nopl 0x0(%rax,%rax,1) | |
0x0000000000427ff8 <+40>: movslq %r14d,%rbp | |
0x0000000000427ffb <+43>: add $0x1,%rbp | |
0x0000000000427fff <+47>: shl $0x4,%rbp | |
0x0000000000428003 <+51>: mov 0x8(%rbx,%rbp,1),%rax | |
0x0000000000428008 <+56>: test %rax,%rax | |
0x000000000042800b <+59>: je 0x428052 <zslGetRank+130> | |
0x000000000042800d <+61>: nopl (%rax) | |
0x0000000000428010 <+64>: movsd 0x8(%rax),%xmm1 | |
0x0000000000428015 <+69>: ucomisd %xmm1,%xmm0 | |
0x0000000000428019 <+73>: ja 0x42803c <zslGetRank+108> | |
0x000000000042801b <+75>: ucomisd %xmm0,%xmm1 | |
0x000000000042801f <+79>: jne 0x428052 <zslGetRank+130> | |
0x0000000000428021 <+81>: jp 0x428052 <zslGetRank+130> | |
0x0000000000428023 <+83>: mov (%rax),%rdi | |
0x0000000000428026 <+86>: mov %r13,%rsi | |
0x0000000000428029 <+89>: movsd %xmm0,(%rsp) | |
0x000000000042802e <+94>: callq 0x41b840 <compareStringObjects> | |
0x0000000000428033 <+99>: test %eax,%eax | |
0x0000000000428035 <+101>: movsd (%rsp),%xmm0 | |
0x000000000042803a <+106>: jg 0x428052 <zslGetRank+130> | |
0x000000000042803c <+108>: mov 0x10(%rbp,%rbx,1),%eax | |
0x0000000000428040 <+112>: mov 0x8(%rbx,%rbp,1),%rbx | |
0x0000000000428045 <+117>: add %rax,%r12 | |
0x0000000000428048 <+120>: mov 0x8(%rbx,%rbp,1),%rax | |
0x000000000042804d <+125>: test %rax,%rax | |
0x0000000000428050 <+128>: jne 0x428010 <zslGetRank+64> | |
0x0000000000428052 <+130>: mov (%rbx),%rdi | |
0x0000000000428055 <+133>: test %rdi,%rdi | |
0x0000000000428058 <+136>: je 0x428070 <zslGetRank+160> | |
0x000000000042805a <+138>: mov %r13,%rsi | |
0x000000000042805d <+141>: movsd %xmm0,(%rsp) | |
0x0000000000428062 <+146>: callq 0x41b910 <equalStringObjects> | |
0x0000000000428067 <+151>: test %eax,%eax | |
0x0000000000428069 <+153>: movsd (%rsp),%xmm0 | |
0x000000000042806e <+158>: jne 0x428079 <zslGetRank+169> | |
0x0000000000428070 <+160>: sub $0x1,%r14d | |
0x0000000000428074 <+164>: jns 0x427ff8 <zslGetRank+40> | |
0x0000000000428076 <+166>: xor %r12d,%r12d | |
0x0000000000428079 <+169>: add $0x10,%rsp | |
0x000000000042807d <+173>: mov %r12,%rax | |
0x0000000000428080 <+176>: pop %rbx | |
0x0000000000428081 <+177>: pop %rbp | |
0x0000000000428082 <+178>: pop %r12 | |
0x0000000000428084 <+180>: pop %r13 | |
0x0000000000428086 <+182>: pop %r14 | |
0x0000000000428088 <+184>: retq |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment