mschnell hat geschrieben:
Zeig 'mal den Assembler-code von beiden Varianten !
GetBit und SetBit im Umgang mit DWord:
Code: Alles auswählen
# GetBit:
.globl UGRAPHCOM_TGRAPHCOM_$__GETBIT$LONGWORD$BYTE$$BOOLEAN
.type UGRAPHCOM_TGRAPHCOM_$__GETBIT$LONGWORD$BYTE$$BOOLEAN,@function
UGRAPHCOM_TGRAPHCOM_$__GETBIT$LONGWORD$BYTE$$BOOLEAN:
# Temps allocated between rsp+0 and rsp+0
# Var Value located in register esi
# Var Bit located in register cl
# Var $self located in register rdi
# Var $result located in register al
# [96] begin
movb %dl,%cl
# [97] Result := (Value and (1 shl Bit)) <> 0;
movzbl %cl,%ecx
movl $1,%eax
shll %cl,%eax
andl %esi,%eax
andl $4294967295,%eax
testq %rax,%rax
setneb %al
# [98] end;
ret
.Le2:
.size UGRAPHCOM_TGRAPHCOM_$__GETBIT$LONGWORD$BYTE$$BOOLEAN, .Le2 - UGRAPHCOM_TGRAPHCOM_$__GETBIT$LONGWORD$BYTE$$BOOLEAN
.section .text
.balign 8,0x90
# SetBit:
.globl UGRAPHCOM_TGRAPHCOM_$__SETBIT$LONGWORD$BYTE$$LONGWORD
.type UGRAPHCOM_TGRAPHCOM_$__SETBIT$LONGWORD$BYTE$$LONGWORD,@function
UGRAPHCOM_TGRAPHCOM_$__SETBIT$LONGWORD$BYTE$$LONGWORD:
# Temps allocated between rsp+0 and rsp+0
# Var Value located in register esi
# Var Bit located in register cl
# Var $self located in register rdi
# Var $result located in register eax
# [103] begin
movb %dl,%cl
# [104] Result := Value or (1 shl Bit);
movzbl %cl,%ecx
movl $1,%eax
shll %cl,%eax
movslq %eax,%rax
andl $4294967295,%esi
orq %rsi,%rax
# [105] end;
ret
.Le3:
.size UGRAPHCOM_TGRAPHCOM_$__SETBIT$LONGWORD$BYTE$$LONGWORD, .Le3 - UGRAPHCOM_TGRAPHCOM_$__SETBIT$LONGWORD$BYTE$$LONGWORD
.section .text
.balign 8,0x90
GetBit und SetBit im Umgang mit QWord:
Code: Alles auswählen
# Zunächst der GetBit-Code:
.globl UGRAPHCOM_TGRAPHCOM_$__GETBIT$QWORD$BYTE$$BOOLEAN
.type UGRAPHCOM_TGRAPHCOM_$__GETBIT$QWORD$BYTE$$BOOLEAN,@function
UGRAPHCOM_TGRAPHCOM_$__GETBIT$QWORD$BYTE$$BOOLEAN:
# Temps allocated between rsp+0 and rsp+0
# Var Value located in register rsi
# Var Bit located in register cl
# Var $self located in register rdi
# Var $result located in register al
# [96] begin
movb %dl,%cl
# [97] Result := (Value and (qword(1) shl Bit)) <> 0;
movzbl %cl,%ecx
movq $1,%rax
shlq %cl,%rax
andq %rsi,%rax
testq %rax,%rax
setneb %al
# [98] end;
ret
.Le2:
.size UGRAPHCOM_TGRAPHCOM_$__GETBIT$QWORD$BYTE$$BOOLEAN, .Le2 - UGRAPHCOM_TGRAPHCOM_$__GETBIT$QWORD$BYTE$$BOOLEAN
.section .text
.balign 8,0x90
# Nun der SetBit-Code:
.globl UGRAPHCOM_TGRAPHCOM_$__SETBIT$QWORD$BYTE$$QWORD
.type UGRAPHCOM_TGRAPHCOM_$__SETBIT$QWORD$BYTE$$QWORD,@function
UGRAPHCOM_TGRAPHCOM_$__SETBIT$QWORD$BYTE$$QWORD:
# Temps allocated between rsp+0 and rsp+0
# Var Value located in register rsi
# Var Bit located in register cl
# Var $self located in register rdi
# Var $result located in register rax
# [103] begin
movb %dl,%cl
# [104] Result := Value or (qword(1) shl Bit);
movzbl %cl,%ecx
movq $1,%rax
shlq %cl,%rax
orq %rsi,%rax
# [105] end;
ret
.Le3:
.size UGRAPHCOM_TGRAPHCOM_$__SETBIT$QWORD$BYTE$$QWORD, .Le3 - UGRAPHCOM_TGRAPHCOM_$__SETBIT$QWORD$BYTE$$QWORD
.section .text
.balign 8,0x90
Im DWord-Code gibt es eine Zeile zusätzlich, im Fall von GetBit
wobei mir (mit meinen bescheidenen Assembler-Kenntnissen) der Sinn dieser Zeile nicht einleuchtet. Wird nicht mit
schon alles notwendige getan?
Die Zeilen wurden zu 64 bit kompiliert.
Wenn ich die DWord- und die QWord-Methode getrennt voneinander in einem Benchmark teste, kommen vergleichbare Zeiten bei raus.
Viele Grüße, Euklid