Code: Select all
'by UEZ
Function _ASM_Sin6th(fX As Double) As Double 'by Eukalyptus
Asm
jmp 0f
1: .Double 683565275.57643158
2: .Double -0.0000000061763971109087229
3: .Double 6755399441055744.0
0:
movq xmm0, [fX]
mulsd xmm0, [1b]
addsd xmm0, [3b]
movd ebx, xmm0
lea eax, [ebx*2+0x80000000]
sar eax, 2
imul eax
sar ebx, 31
lea eax, [edx*2-0x70000000]
lea ecx, [edx*8+edx-0x24000000]
imul edx
Xor ecx, ebx
lea eax, [edx*8+edx+0x44A00000]
imul ecx
cvtsi2sd xmm0, edx
mulsd xmm0, [2b]
movq [Function], xmm0
End Asm
End Function
'by UEZ
Function _ASM_Cos6th(fX As Double) As Double 'by Eukalyptus
Asm
jmp 0f
1: .Double 683565275.57643158
2: .Double -0.0000000061763971109087229
3: .Double 6755399441055744.0
0:
movq xmm0, [fX]
mulsd xmm0, [1b]
addsd xmm0, [3b]
movd ebx, xmm0
Add ebx, 0x40000000 'SinToCos
lea eax, [ebx*2+0x80000000]
sar eax, 2
imul eax
sar ebx, 31
lea eax, [edx*2-0x70000000]
lea ecx, [edx*8+edx-0x24000000]
imul edx
Xor ecx, ebx
lea eax, [edx*8+edx+0x44A00000]
imul ecx
cvtsi2sd xmm0, edx
mulsd xmm0, [2b]
movq [Function], xmm0
End Asm
End Function
private function fast_round(byval x as double) as long
dim MAGIC_ROUND as const double = 6755399441055744.0
union fast_trunc
d as double
type
lw as long
hw as long
end type
end union
dim fast_trunc as fast_trunc
fast_trunc.d = x
fast_trunc.d += MAGIC_ROUND
return fast_trunc.lw
end function
private function fast_sin(byval x as double) as double
static PI as const double = 3.14159265358979323846264338327950288
static PIhalh as const double = 1.5707963267948966192313216916398
static INVPI as const double = 0.31830988618379067153776752674502872
static A as const double = 0.7877963415144895477052689270382604344650e-2
static B as const double = -0.1664011173315512939367501065243766307762
static C as const double = 0.9999769956705319409897753213423989053597
dim k as long
dim x2 as double
k = fast_round(INVPI * x)
x -= k * PI
x2 = x * x
x = x * (C + (x2 * (B + (A * x2))))
if k mod 2 then
x = -x
end if
return x
end function
private function fast_sin2(byval x as double) as double
static PI as const double = 3.14159265358979323846264338327950288
static PIhalh as const double = 1.5707963267948966192313216916398
static INVPI as const double = 0.31830988618379067153776752674502872
static A as const double = -.1540557313583959620200034139475826213673
static B as const double = 0.9975701467242784884900775894558674706250
dim k as long
dim x2 as double
k = fast_round(INVPI * x)
x -= k * PI
x2 = x * x
x = x * (B + (A * x2))
if k mod 2 then
x = -x
end if
return x
end function
private function fast_cos(byval x as double) as double
static PI as const double = 3.14159265358979323846264338327950288
static PIhalh as const double = 1.5707963267948966192313216916398
static INVPI as const double = 0.31830988618379067153776752674502872
static A as const double = 0.7877963415144895477052689270382604344650e-2
static B as const double = -0.1664011173315512939367501065243766307762
static C as const double = 0.9999769956705319409897753213423989053597
dim k as long
dim x2 as double
x = PIhalh - x
k = fast_round(INVPI * x)
x -= k * PI
x2 = x * x
x = x * (C + (x2 * (B + (A * x2))))
if k mod 2 then
x = -x
end if
return x
end function
private function fast_cos2(byval x as double) as double
static PI as const double = 3.14159265358979323846264338327950288
static PIhalh as const double = 1.5707963267948966192313216916398
static INVPI as const double = 0.31830988618379067153776752674502872
static A as const double = -.1540557313583959620200034139475826213673
static B as const double = 0.9975701467242784884900775894558674706250
dim k as long
dim x2 as double
x = PIhalh - x
k = fast_round(INVPI * x)
x -= k * PI
x2 = x * x
x = x * (B + (A * x2))
if k mod 2 then
x = -x
end if
return x
end function
Print "just now starting"
dim as double s, t
dim as double x
dim as integer k
s=0
t=timer
for k=1 to 100000000
x=k
s+=_ASM_Sin6th(x)
next
t=timer-t
Print "_ASM_Sin6th time: seconds = ";
Print using "##.### sum = ##.####";t;s;: Print " true 1.713649346570576"
s=0
t=timer
for k=1 to 100000000
x=k
s+=_ASM_Cos6th(x)
next
t=timer-t
Print "_ASM_Cos6th time: seconds = ";
Print using "##.### sum = ##.####";t;s;: Print " true 0.1709843554183985"
Print "------------------------"
s=0
t=timer
for k=1 to 100000000
x=k
s+=fast_sin(x)
next
t=timer-t
Print "fast_sin time: seconds = ";
Print using "##.### sum = ##.####";t;s;: Print " true 1.713649346570576"
s=0
t=timer
for k=1 to 100000000
x=k
s+=fast_cos(x)
next
t=timer-t
Print "fast_cos time: seconds = ";
Print using "##.### sum = ##.####";t;s;: Print " true 0.1709843554183985"
Print "------------------------"
s=0
t=timer
for k=1 to 100000000
x=k
s+=fast_sin2(x)
next
t=timer-t
Print "fast_sin2 time: seconds = ";
Print using "##.### sum = ##.####";t;s;: Print " true 1.713649346570576"
s=0
t=timer
for k=1 to 100000000
x=k
s+=fast_cos2(x)
next
t=timer-t
Print "fast_cos2 time: seconds = ";
Print using "##.### sum = ##.####";t;s;: Print " true 0.1709843554183985"
Print "------------------------"
s=0
t=timer
for k=1 to 100000000
x=k
s+=sin(x)
next
t=timer-t
Print "FB built-in sin time: seconds = ";
Print using "##.### sum = ##.###############";t;s;: Print " true 1.713649346570576"
s=0
t=timer
for k=1 to 100000000
x=k
s+=cos(x)
next
t=timer-t
Print "FB built-in cos time: seconds = ";
Print using "##.### sum = ##.###############";t;s;: Print " true 0.1709843554183985"
Code: Select all
just now starting
_ASM_Sin6th time: seconds = 0.393 sum = 29.1971 true 1.713649346570576
_ASM_Cos6th time: seconds = 0.408 sum = 9.3472 true 0.1709843554183985
------------------------
fast_sin time: seconds = 0.156 sum = 1.7134 true 1.713649346570576
fast_cos time: seconds = 0.181 sum = 0.1707 true 0.1709843554183985
------------------------
fast_sin2 time: seconds = 0.138 sum = 1.7187 true 1.713649346570576
fast_cos2 time: seconds = 0.158 sum = 0.1785 true 0.1709843554183985
------------------------
FB built-in sin time: seconds = 2.841 sum = 1.713649346570280 true 1.713649346570576
FB built-in cos time: seconds = 2.870 sum = 0.170984355418202 true 0.1709843554183985