Ich habe zwei Funktionen geschrieben, die aus einem LongWord einen speziellen 28bit-Integer machen und vice versa. Dieser ist folgendermaßen aufgebaut:
0xxxxxxx 0xxxxxxx 0xxxxxxx 0xxxxxxxalso jeweils das höchstwertige Bit auf 0 gesetzt, wobei das Least Significant Byte rechts steht und nicht links. Vorzeichen gibt es nicht, dargestellt wird dieser Integertyp in einem array[0..3] of Byte.
Die Funktionen sind einige Takte schneller als das Ergebnis des kompilierten Delphi-Codes (steht in den Kommentaren) und benötigt keine Stackzugriffe (im Gegensatz zum Delphi-Kompilat).
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:
| function Int28ToLongWord(aValue: TInt28): LongWord; asm MOV EDX, EAX; XOR EAX, EAX; OR AL, DL; SHL EAX, $07; OR AL, DH; SHL EAX, $07; SHR EDX, $10; OR AL, DL; SHL EAX, $07; OR AL, DH; end;
function LongWordToInt28(aValue: LongWord): TInt28; asm MOV EDX, EAX; SHL AX, $08; SHR EDX, $07; MOV AL, DL; SHL EAX, $10; SHR EDX, $07; MOV AH, DL; SHR EDX, $07; MOV AL, DL; AND EAX, $7F7F7F7F; end; |
Geht das Ganze vielleicht noch schneller oder habe ich sogar irgendwo eine Schwachstelle übersehen (Stichprobenartige Testläufe lieferten jedes Mal das richtige Ergebnis)?
Your computer is designed to become slower and more unreliable over time, so you have to upgrade. But if you'd like some false hope, I can tell you how to defragment your disk.