-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathasm.inc
67 lines (59 loc) · 1.32 KB
/
asm.inc
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
67
{$IFDEF i386}
{$IFDEF FPC}
{$ASMMODE intel}
{$ENDIF}
function ror(x: Cardinal; y: Byte): Cardinal; assembler;
asm
mov cl,dl
ror eax,cl
end;
function rol(x: Cardinal; y: Byte): Cardinal; assembler;
asm
mov cl,dl
rol eax,cl
end;
function bswap(x: Cardinal): Cardinal; assembler;
asm
bswap eax
end;
function swap64(x: int64): int64; assembler;
asm
mov edx,dword ptr[x]
mov eax,dword ptr[x+4]
bswap edx
bswap eax
end;
{$ELSE}
function ror(x: Cardinal; y: Byte): Cardinal;
begin
ror:=
(x shr y) +
(x shl (32-y));
end;
function rol(x: Cardinal; y: Byte): Cardinal;
begin
rol:=
(x shl y) +
(x shr (32-y));
end;
function bswap(x: Cardinal): Cardinal;
begin
bswap:=
((x and $000000FF) shl 24) +
((x and $0000FF00) shl 8) +
((x and $00FF0000) shr 8) +
((x and $FF000000) shr 24);
end;
function swap64(x: uint64): uint64;
begin
swap64:=
((x and $00000000000000FF) shl 56) +
((x and $000000000000FF00) shl 40) +
((x and $0000000000FF0000) shl 24) +
((x and $00000000FF000000) shl 8) +
((x and $000000FF00000000) shr 8) +
((x and $0000FF0000000000) shr 24) +
((x and $00FF000000000000) shr 40) +
((x and $FF00000000000000) shr 56);
end;
{$ENDIF}