Skip to content

Commit

Permalink
Merge pull request #109 from sfleischman105/Beta-Branch
Browse files Browse the repository at this point in the history
Update `pleco` to 0.4.1 and `pleco_engine` to 0.1.2
  • Loading branch information
sfleischman105 authored Apr 19, 2018
2 parents 0f324d5 + ce19f92 commit aa677b8
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 32 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ UCI (Universal Chess Interface) compatible engine.
The overall goal for this project is to utilize the efficiency of Rust to create a Chess AI matching the speed of modern chess engines.
For the engine, the majority of the code is a direct port of Stockfish's C++ code. See [their website](https://stockfishchess.org/) for
more information about the engine. As such, the credit for all of the advanced algorithms used for searching, evaluation,
and many others, go directly to the maintainers and authors of Stockfish. This project is simply for speed comparisons
and many others, go directly to the maintainers and authors of Stockfish. This project is for speed comparisons
between the two languages, as well as for educational purposes.

- [Documentation](https://docs.rs/pleco), [crates.io](https://crates.io/crates/pleco) for library functionality
Expand Down
2 changes: 1 addition & 1 deletion pleco/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pleco"
version = "0.4.0"
version = "0.4.1"
authors = ["Stephen Fleischman <stephenf@cs.washington.edu>"]
description = "A blazingly-fast chess library."
homepage = "https://github.com/sfleischman105/Pleco"
Expand Down
1 change: 1 addition & 0 deletions pleco/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
#![feature(pointer_methods)]
#![feature(cfg_target_feature, target_feature)]
#![feature(stdsimd)]
#![feature(nonnull_cast)]

#![allow(dead_code)]

Expand Down
13 changes: 6 additions & 7 deletions pleco/src/tools/tt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

use std::ptr::NonNull;
use std::mem;
use std::heap::{Alloc, Layout, Heap};
use std::heap::{Alloc, Layout, Global};
use std::cmp::min;
use std::cell::UnsafeCell;

Expand Down Expand Up @@ -423,8 +423,7 @@ impl TranspositionTable {

/// De-allocates the current heap.
unsafe fn de_alloc(&self) {
Heap.dealloc((*self.clusters.get()).as_ptr() as *mut _,
Layout::array::<Cluster>(*self.cap.get()).unwrap());
Global.dealloc((*self.clusters.get()).as_opaque(), Layout::array::<Cluster>(*self.cap.get()).unwrap());
}

/// Returns the % of the hash table that is full.
Expand Down Expand Up @@ -481,13 +480,13 @@ unsafe fn cluster_first_entry(cluster: *mut Cluster) -> *mut Entry {
#[inline]
fn alloc_room(size: usize) -> NonNull<Cluster> {
unsafe {
let ptr = Heap.alloc_zeroed(Layout::array::<Cluster>(size).unwrap());
let ptr = Global.alloc_zeroed(Layout::array::<Cluster>(size).unwrap());

let new_ptr = match ptr {
Ok(ptr) => ptr,
Err(err) => Heap.oom(err),
Ok(ptr) => ptr.cast(),
Err(_err) => Global.oom(),
};
NonNull::new(new_ptr as *mut Cluster).unwrap()
new_ptr
}

}
Expand Down
4 changes: 2 additions & 2 deletions pleco_engine/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pleco_engine"
version = "0.1.1" # Reminder to change in ./engine.rs
version = "0.1.2" # Reminder to change in ./engine.rs
authors = ["Stephen Fleischman <stephenf@cs.washington.edu>"]
description = "A blazingly-fast Chess AI."
homepage = "https://github.com/sfleischman105/Pleco"
Expand Down Expand Up @@ -67,7 +67,7 @@ path = "src/lib.rs"
doctest = true

[dependencies]
pleco = { path = "../pleco", version = "0.4.0" }
pleco = { path = "../pleco", version = "0.4.1" }
clippy = {version = "0.0.191", optional = true}
chrono = "0.4.1"
rand = "0.4.2"
Expand Down
14 changes: 7 additions & 7 deletions pleco_engine/src/consts.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Constant values and static structures.
use std::heap::{Alloc, Layout, Heap};
use std::heap::{Alloc, Layout, Global};

use std::ptr::{NonNull, self};
use std::sync::atomic::AtomicBool;
Expand Down Expand Up @@ -52,10 +52,10 @@ pub fn init_globals() {
fn init_tt() {
unsafe {
let layout = Layout::new::<TranspositionTable>();
let result = Heap.alloc_zeroed(layout);
let result = Global.alloc_zeroed(layout);
let new_ptr: *mut TranspositionTable = match result {
Ok(ptr) => ptr as *mut TranspositionTable,
Err(err) => Heap.oom(err),
Ok(ptr) => ptr.cast().as_ptr() as *mut TranspositionTable,
Err(_err) => Global.oom(),
};
ptr::write(new_ptr, TranspositionTable::new(DEFAULT_TT_SIZE));
TT_TABLE = NonNull::new_unchecked(new_ptr);
Expand All @@ -65,10 +65,10 @@ fn init_tt() {
fn init_timer() {
unsafe {
let layout = Layout::new::<TimeManager>();
let result = Heap.alloc_zeroed(layout);
let result = Global.alloc_zeroed(layout);
let new_ptr: *mut TimeManager = match result {
Ok(ptr) => ptr as *mut TimeManager,
Err(err) => Heap.oom(err),
Ok(ptr) => ptr.cast().as_ptr() as *mut TimeManager,
Err(_err) => Global.oom(),
};
ptr::write(new_ptr, TimeManager::uninitialized());
TIMER = NonNull::new_unchecked(new_ptr);
Expand Down
2 changes: 1 addition & 1 deletion pleco_engine/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use num_cpus;

pub static ID_NAME: &str = "Pleco";
pub static ID_AUTHORS: &str = "Stephen Fleischman";
pub static VERSION: &str = "0.1.1";
pub static VERSION: &str = "0.1.2";

#[derive(PartialEq)]
enum SearchType {
Expand Down
1 change: 1 addition & 0 deletions pleco_engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#![feature(fused)]
#![feature(const_fn)]
#![feature(box_into_raw_non_null)]
#![feature(nonnull_cast)]

//#![crate_type = "staticlib"]

Expand Down
10 changes: 5 additions & 5 deletions pleco_engine/src/tables/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub mod capture_piece_history;
pub mod butterfly;

use std::ptr::NonNull;
use std::heap::{Alloc, Layout, Heap};
use std::heap::{Alloc, Layout, Global};
use std::mem;
use std::ptr;
use std::ops::*;
Expand Down Expand Up @@ -138,17 +138,17 @@ impl<T: Sized + TableBaseConst> TableBase<T> {

// allocates space.
unsafe fn alloc() -> NonNull<T> {
let ptr = Heap.alloc_zeroed(Layout::array::<T>(T::ENTRY_COUNT).unwrap());
let ptr = Global.alloc_zeroed(Layout::array::<T>(T::ENTRY_COUNT).unwrap());
let new_ptr = match ptr {
Ok(ptr) => ptr,
Err(err) => Heap.oom(err),
Ok(ptr) => ptr.cast().as_ptr(),
Err(_err) => Global.oom(),
};
NonNull::new(new_ptr as *mut T).unwrap()
}

/// de-allocates the current table.
unsafe fn de_alloc(&mut self) {
Heap.dealloc(self.table.as_ptr() as *mut _,
Global.dealloc(self.table.as_opaque(),
Layout::array::<T>(T::ENTRY_COUNT).unwrap());
}
}
Expand Down
16 changes: 8 additions & 8 deletions pleco_engine/src/threadpool/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Contains the ThreadPool and the individual Threads.

use std::heap::{Alloc, Layout, Heap};
use std::heap::{Alloc, Layout, Global};
use std::sync::atomic::{AtomicBool,Ordering};
use std::thread::{JoinHandle,self};
use std::sync::{Once, ONCE_INIT};
Expand Down Expand Up @@ -39,10 +39,10 @@ pub fn init_threadpool() {
.stack_size(THREAD_STACK_SIZE);
let handle = scoped::builder_spawn_unsafe(builder, move || {
let layout = Layout::new::<ThreadPool>();
let result = Heap.alloc_zeroed(layout);
let result = Global.alloc_zeroed(layout);
let new_ptr: *mut ThreadPool = match result {
Ok(ptr) => ptr as *mut ThreadPool,
Err(err) => Heap.oom(err),
Ok(ptr) => ptr.cast().as_ptr() as *mut ThreadPool,
Err(_err) => Global.oom(),
};
ptr::write(new_ptr, ThreadPool::new());
THREADPOOL = NonNull::new_unchecked(new_ptr);
Expand Down Expand Up @@ -138,10 +138,10 @@ impl ThreadPool {
let layout = Layout::new::<Searcher>();
let cond = if len == 0 {self.main_cond.clone()} else {self.thread_cond.clone()};
unsafe {
let result = Heap.alloc_zeroed(layout);
let result = Global.alloc_zeroed(layout);
let new_ptr: *mut Searcher = match result {
Ok(ptr) => ptr as *mut Searcher,
Err(err) => Heap.oom(err),
Ok(ptr) => ptr.cast().as_ptr() as *mut Searcher,
Err(_err) => Global.oom(),
};
ptr::write(new_ptr, Searcher::new(len, cond));
self.threads.push(UnsafeCell::new(new_ptr));
Expand Down Expand Up @@ -217,7 +217,7 @@ impl ThreadPool {
while let Some(unc) = self.threads.pop() {
let th: *mut Searcher = *unc.get();
let layout = Layout::new::<Searcher>();
Heap.dealloc(th as *mut _, layout);
Global.dealloc(NonNull::new_unchecked(th).as_opaque(), layout);
}
}

Expand Down

0 comments on commit aa677b8

Please sign in to comment.