FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
TF2-Source-Code/tf2_src/mathlib/randsse.cpp at master · sr2echa/TF2-Source-Code · GitHub
sr2echa
/
TF2-Source-Code
Public
Notifications
You must be signed in to change notification settings
Fork
22
Star
81
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
TF2-Source-Code
/
tf2_src
/
mathlib
/
randsse.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
109 lines (88 loc) · 2.3 KB
Breadcrumbs
TF2-Source-Code
/
tf2_src
/
mathlib
/
randsse.cpp
Copy path
File metadata and controls
109 lines (88 loc) · 2.3 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//
========= Copyright Valve Corporation, All rights reserved. ============//
//
//
Purpose: generates 4 randum numbers in the range 0..1 quickly, using SIMD
//
//
=====================================================================================//
#
include
<
math.h
>
#
include
<
float.h
>
//
Needed for FLT_EPSILON
#
include
"
basetypes.h
"
#
include
<
memory.h
>
#
include
"
tier0/dbg.h
"
#
include
"
mathlib/mathlib.h
"
#
include
"
mathlib/vector.h
"
#
include
"
mathlib/ssemath.h
"
//
memdbgon must be the last include file in a .cpp file!!!
#
include
"
tier0/memdbgon.h
"
//
see knuth volume 3 for insight.
class
SIMDRandStreamContext
{
fltx4 m_RandY[
55
];
fltx4 *m_pRand_J, *m_pRand_K;
public:
void
Seed
( uint32 seed )
{
m_pRand_J=m_RandY+
23
; m_pRand_K=m_RandY+
54
;
for
(
int
i=
0
;i<
55
;i++)
{
for
(
int
j=
0
;j<
4
;j++)
{
SubFloat
( m_RandY[i], j) = (seed>>
16
)/
65536.0
;
seed=(seed+
1
)*
3141592621u
;
}
}
}
inline
fltx4
RandSIMD
(
void
)
{
//
ret= rand[k]+rand[j]
fltx4 retval=
AddSIMD
( *m_pRand_K, *m_pRand_J );
//
if ( ret>=1.0) ret-=1.0
fltx4 overflow_mask=
CmpGeSIMD
( retval, Four_Ones );
retval=
SubSIMD
( retval,
AndSIMD
( Four_Ones, overflow_mask ) );
*m_pRand_K = retval;
//
update pointers w/ wrap-around
if
( --m_pRand_J < m_RandY )
m_pRand_J=m_RandY+
54
;
if
( --m_pRand_K < m_RandY )
m_pRand_K=m_RandY+
54
;
return
retval;
}
};
#
define
MAX_SIMULTANEOUS_RANDOM_STREAMS
32
static
SIMDRandStreamContext s_SIMDRandContexts[
MAX_SIMULTANEOUS_RANDOM_STREAMS
];
static
volatile
int
s_nRandContextsInUse[
MAX_SIMULTANEOUS_RANDOM_STREAMS
];
void
SeedRandSIMD
(uint32 seed)
{
for
(
int
i =
0
; i<
MAX_SIMULTANEOUS_RANDOM_STREAMS
; i++)
s_SIMDRandContexts[i].
Seed
( seed+i );
}
fltx4
RandSIMD
(
int
nContextIndex )
{
return
s_SIMDRandContexts[nContextIndex].
RandSIMD
();
}
int
GetSIMDRandContext
(
void
)
{
for
(;;)
{
for
(
int
i=
0
; i <
NELEMS
( s_SIMDRandContexts ); i++)
{
if
( ! s_nRandContextsInUse[i] )
//
available?
{
//
try to take it!
if
(
ThreadInterlockedAssignIf
( &( s_nRandContextsInUse[i]),
1
,
0
) )
{
return
i;
//
done!
}
}
}
Assert
(
0
);
//
why don't we have enough buffers?
ThreadSleep
();
}
}
void
ReleaseSIMDRandContext
(
int
nContext )
{
s_nRandContextsInUse[ nContext ] =
0
;
}
fltx4
RandSIMD
(
void
)
{
return
s_SIMDRandContexts[
0
].
RandSIMD
();
}
Back
|
FazBrowse Home
|
New Git URL