11//! Constant values and static structures.
2- use std:: mem;
2+ use std:: mem:: MaybeUninit ;
33use std:: ptr;
44use std:: sync:: atomic:: compiler_fence;
55use std:: sync:: atomic:: AtomicBool ;
@@ -22,22 +22,15 @@ pub const DEFAULT_TT_SIZE: usize = 256;
2222pub const PAWN_TABLE_SIZE : usize = 16384 ;
2323pub const MATERIAL_TABLE_SIZE : usize = 8192 ;
2424
25- const TT_ALLOC_SIZE : usize = mem:: size_of :: < TranspositionTable > ( ) ;
26- const TIMER_ALLOC_SIZE : usize = mem:: size_of :: < TimeManager > ( ) ;
27-
28- // A object that is the same size as a transposition table
29- type DummyTranspositionTable = [ u8 ; TT_ALLOC_SIZE ] ;
30- type DummyTimeManager = [ u8 ; TIMER_ALLOC_SIZE ] ;
31-
3225pub static USE_STDOUT : AtomicBool = AtomicBool :: new ( true ) ;
3326
3427static INITIALIZED : Once = Once :: new ( ) ;
3528
3629/// Global Transposition Table
37- static mut TT_TABLE : DummyTranspositionTable = [ 0 ; TT_ALLOC_SIZE ] ;
30+ static mut TT_TABLE : MaybeUninit < TranspositionTable > = MaybeUninit :: uninit ( ) ;
3831
3932// Global Timer
40- static mut TIMER : DummyTimeManager = [ 0 ; TIMER_ALLOC_SIZE ] ;
33+ static mut TIMER : MaybeUninit < TimeManager > = MaybeUninit :: uninit ( ) ;
4134
4235#[ cold]
4336pub fn init_globals ( ) {
@@ -56,29 +49,30 @@ pub fn init_globals() {
5649#[ cold]
5750fn init_tt ( ) {
5851 unsafe {
59- let tt = & mut TT_TABLE as * mut DummyTranspositionTable as * mut TranspositionTable ;
60- ptr:: write ( tt, TranspositionTable :: new ( DEFAULT_TT_SIZE ) ) ;
52+ ptr:: write (
53+ TT_TABLE . as_mut_ptr ( ) ,
54+ TranspositionTable :: new ( DEFAULT_TT_SIZE ) ,
55+ ) ;
6156 }
6257}
6358
6459// Initializes the global Timer
6560#[ cold]
6661fn init_timer ( ) {
6762 unsafe {
68- let timer: * mut TimeManager = & mut TIMER as * mut DummyTimeManager as * mut TimeManager ;
69- ptr:: write ( timer, TimeManager :: uninitialized ( ) ) ;
63+ ptr:: write ( TIMER . as_mut_ptr ( ) , TimeManager :: uninitialized ( ) ) ;
7064 }
7165}
7266
7367// Returns access to the global timer
7468pub fn timer ( ) -> & ' static TimeManager {
75- unsafe { & * ( & TIMER as * const DummyTimeManager as * const TimeManager ) }
69+ unsafe { & * TIMER . as_ptr ( ) }
7670}
7771
7872/// Returns access to the global transposition table
7973#[ inline( always) ]
8074pub fn tt ( ) -> & ' static TranspositionTable {
81- unsafe { & * ( & TT_TABLE as * const DummyTranspositionTable as * const TranspositionTable ) }
75+ unsafe { & * TT_TABLE . as_ptr ( ) }
8276}
8377
8478pub trait PVNode {
0 commit comments