Skip to content

Many optimizations and updated shootout benchmarks #5962

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
1a36b0f
librustc: Remove `fail_unless!`
pcwalton Mar 29, 2013
f903ae9
librustc: Implement fast-ffi and use it in various places
pcwalton Mar 29, 2013
af42d37
rustllvm: Fix RustWrapper.cpp
pcwalton Apr 1, 2013
3ffaaab
librustc: Switch the `@`s in types with `~`
pcwalton Apr 1, 2013
04df19c
librustc: Take primitive types out of the type hash table.
pcwalton Apr 2, 2013
53f54dd
librustc: Remove def_ids from types.
pcwalton Apr 2, 2013
4c29b4c
librustc: Optimize metadata::decoder::item_name.
pcwalton Apr 2, 2013
2dbe20a
libstd: Micro-optimize vuint_at
pcwalton Apr 3, 2013
ca8e99f
rt: Fix scalability problem with big stacks on 32 bit
pcwalton Apr 5, 2013
0b0ca59
librustc: Improve inlining behavior.
pcwalton Apr 7, 2013
90b65c8
llvm: Fixes for RustWrapper.
pcwalton Apr 12, 2013
9738c2a
test: Rewrite nbody and spectralnorm shootout benchmarks
pcwalton Apr 16, 2013
10aa1c3
test: Add fannkuch-redux and fasta-redux shootout benchmarks
pcwalton Apr 17, 2013
1d32313
test: Add k-nucleotide
pcwalton Apr 18, 2013
bc0dd7f
Move shootout-k-nucleotide to bench
pcwalton Apr 18, 2013
7720c15
test: Implement pidigits and reverse-complement
pcwalton Apr 18, 2013
c995a62
librustc: WIP patch for using the return value.
pcwalton Apr 18, 2013
9902e79
rt: Remove dump_stacks
pcwalton Apr 19, 2013
af4ea11
test: Rewrite mandelbrot benchmark.
pcwalton Apr 19, 2013
f93b3cd
librustc: Remove debug code; xfail-pretty reverse-complement.
pcwalton Apr 19, 2013
dcea717
librustc: Fix botched merge. rs=merge
pcwalton Apr 19, 2013
d2b6448
test: xfail some benchmarks that require external libraries or inputs
pcwalton Apr 20, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/libcore/core.rc
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ pub use str::{StrSlice};
pub use container::{Container, Mutable};
pub use vec::{CopyableVector, ImmutableVector};
pub use vec::{ImmutableEqVector, ImmutableCopyableVector};
pub use vec::{OwnedVector, OwnedCopyableVector};
pub use vec::{OwnedVector, OwnedCopyableVector, MutableVector};
pub use iter::{BaseIter, ExtendedIter, EqIter, CopyableIter};
pub use iter::{CopyableOrderedIter, CopyableNonstrictIter, Times};
pub use iter::{ExtendedMutableIter};

pub use num::{Num, NumCast};
pub use ptr::Ptr;
Expand Down
40 changes: 17 additions & 23 deletions src/libcore/hashmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use container::{Container, Mutable, Map, Set};
use cmp::{Eq, Equiv};
use hash::Hash;
use to_bytes::IterBytes;
use iter::BaseIter;
use hash::Hash;
use iter;
Expand Down Expand Up @@ -72,7 +71,7 @@ fn linear_map_with_capacity_and_keys<K:Eq + Hash,V>(
}
}

priv impl<K:Hash + IterBytes + Eq,V> HashMap<K, V> {
priv impl<K:Hash + Eq,V> HashMap<K, V> {
#[inline(always)]
fn to_bucket(&self, h: uint) -> uint {
// A good hash function with entropy spread over all of the
Expand Down Expand Up @@ -111,9 +110,8 @@ priv impl<K:Hash + IterBytes + Eq,V> HashMap<K, V> {
}

#[inline(always)]
fn bucket_for_key_equiv<Q:Hash + IterBytes + Equiv<K>>(&self,
k: &Q)
-> SearchResult {
fn bucket_for_key_equiv<Q:Hash + Equiv<K>>(&self, k: &Q)
-> SearchResult {
let hash = k.hash_keyed(self.k0, self.k1) as uint;
self.bucket_for_key_with_hash_equiv(hash, k)
}
Expand Down Expand Up @@ -303,15 +301,15 @@ priv impl<K:Hash + IterBytes + Eq,V> HashMap<K, V> {
}
}

impl<K:Hash + IterBytes + Eq,V> Container for HashMap<K, V> {
impl<K:Hash + Eq,V> Container for HashMap<K, V> {
/// Return the number of elements in the map
fn len(&const self) -> uint { self.size }

/// Return true if the map contains no elements
fn is_empty(&const self) -> bool { self.len() == 0 }
}

impl<K:Hash + IterBytes + Eq,V> Mutable for HashMap<K, V> {
impl<K:Hash + Eq,V> Mutable for HashMap<K, V> {
/// Clear the map, removing all key-value pairs.
fn clear(&mut self) {
for uint::range(0, self.buckets.len()) |idx| {
Expand All @@ -321,7 +319,7 @@ impl<K:Hash + IterBytes + Eq,V> Mutable for HashMap<K, V> {
}
}

impl<K:Hash + IterBytes + Eq,V> Map<K, V> for HashMap<K, V> {
impl<K:Hash + Eq,V> Map<K, V> for HashMap<K, V> {
/// Return true if the map contains a value for the specified key
fn contains_key(&self, k: &K) -> bool {
match self.bucket_for_key(k) {
Expand Down Expand Up @@ -458,7 +456,7 @@ impl<K:Hash + IterBytes + Eq,V> Map<K, V> for HashMap<K, V> {
}
}

pub impl<K: Hash + IterBytes + Eq, V> HashMap<K, V> {
pub impl<K: Hash + Eq, V> HashMap<K, V> {
/// Create an empty HashMap
fn new() -> HashMap<K, V> {
HashMap::with_capacity(INITIAL_CAPACITY)
Expand Down Expand Up @@ -669,8 +667,7 @@ pub impl<K: Hash + IterBytes + Eq, V> HashMap<K, V> {

/// Return true if the map contains a value for the specified key,
/// using equivalence
fn contains_key_equiv<Q:Hash + IterBytes + Equiv<K>>(&self, key: &Q)
-> bool {
fn contains_key_equiv<Q:Hash + Equiv<K>>(&self, key: &Q) -> bool {
match self.bucket_for_key_equiv(key) {
FoundEntry(_) => {true}
TableFull | FoundHole(_) => {false}
Expand All @@ -680,8 +677,7 @@ pub impl<K: Hash + IterBytes + Eq, V> HashMap<K, V> {
/// Return the value corresponding to the key in the map, using
/// equivalence
#[cfg(stage0)]
fn find_equiv<Q:Hash + IterBytes + Equiv<K>>(&self, k: &Q)
-> Option<&'self V> {
fn find_equiv<Q:Hash + Equiv<K>>(&self, k: &Q) -> Option<&'self V> {
match self.bucket_for_key_equiv(k) {
FoundEntry(idx) => Some(self.value_for_bucket(idx)),
TableFull | FoundHole(_) => None,
Expand All @@ -693,17 +689,15 @@ pub impl<K: Hash + IterBytes + Eq, V> HashMap<K, V> {
#[cfg(stage1)]
#[cfg(stage2)]
#[cfg(stage3)]
fn find_equiv<'a, Q:Hash + IterBytes + Equiv<K>>(
&'a self, k: &Q) -> Option<&'a V>
{
fn find_equiv<'a, Q:Hash + Equiv<K>>(&'a self, k: &Q) -> Option<&'a V> {
match self.bucket_for_key_equiv(k) {
FoundEntry(idx) => Some(self.value_for_bucket(idx)),
TableFull | FoundHole(_) => None,
}
}
}

impl<K:Hash + IterBytes + Eq,V:Eq> Eq for HashMap<K, V> {
impl<K:Hash + Eq,V:Eq> Eq for HashMap<K, V> {
fn eq(&self, other: &HashMap<K, V>) -> bool {
if self.len() != other.len() { return false; }

Expand All @@ -724,31 +718,31 @@ pub struct HashSet<T> {
priv map: HashMap<T, ()>
}

impl<T:Hash + IterBytes + Eq> BaseIter<T> for HashSet<T> {
impl<T:Hash + Eq> BaseIter<T> for HashSet<T> {
/// Visit all values in order
fn each(&self, f: &fn(&T) -> bool) { self.map.each_key(f) }
fn size_hint(&self) -> Option<uint> { Some(self.len()) }
}

impl<T:Hash + IterBytes + Eq> Eq for HashSet<T> {
impl<T:Hash + Eq> Eq for HashSet<T> {
fn eq(&self, other: &HashSet<T>) -> bool { self.map == other.map }
fn ne(&self, other: &HashSet<T>) -> bool { self.map != other.map }
}

impl<T:Hash + IterBytes + Eq> Container for HashSet<T> {
impl<T:Hash + Eq> Container for HashSet<T> {
/// Return the number of elements in the set
fn len(&const self) -> uint { self.map.len() }

/// Return true if the set contains no elements
fn is_empty(&const self) -> bool { self.map.is_empty() }
}

impl<T:Hash + IterBytes + Eq> Mutable for HashSet<T> {
impl<T:Hash + Eq> Mutable for HashSet<T> {
/// Clear the set, removing all values.
fn clear(&mut self) { self.map.clear() }
}

impl<T:Hash + IterBytes + Eq> Set<T> for HashSet<T> {
impl<T:Hash + Eq> Set<T> for HashSet<T> {
/// Return true if the set contains a value
fn contains(&self, value: &T) -> bool { self.map.contains_key(value) }

Expand Down Expand Up @@ -816,7 +810,7 @@ impl<T:Hash + IterBytes + Eq> Set<T> for HashSet<T> {
}
}

pub impl <T:Hash + IterBytes + Eq> HashSet<T> {
pub impl <T:Hash + Eq> HashSet<T> {
/// Create an empty HashSet
fn new() -> HashSet<T> {
HashSet::with_capacity(INITIAL_CAPACITY)
Expand Down
4 changes: 4 additions & 0 deletions src/libcore/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ pub trait ExtendedIter<A> {
fn flat_map_to_vec<B,IB: BaseIter<B>>(&self, op: &fn(&A) -> IB) -> ~[B];
}

pub trait ExtendedMutableIter<A> {
fn eachi_mut(&mut self, blk: &fn(uint, &mut A) -> bool);
}

pub trait EqIter<A:Eq> {
fn contains(&self, x: &A) -> bool;
fn count(&self, x: &A) -> uint;
Expand Down
14 changes: 14 additions & 0 deletions src/libcore/libc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1097,9 +1097,12 @@ pub mod funcs {
unsafe fn setbuf(stream: *FILE, buf: *c_char);
// Omitted: printf and scanf variants.
unsafe fn fgetc(stream: *FILE) -> c_int;
#[fast_ffi]
unsafe fn fgets(buf: *mut c_char, n: c_int,
stream: *FILE) -> *c_char;
#[fast_ffi]
unsafe fn fputc(c: c_int, stream: *FILE) -> c_int;
#[fast_ffi]
unsafe fn fputs(s: *c_char, stream: *FILE) -> *c_char;
// Omitted: getc, getchar (might be macros).

Expand All @@ -1109,8 +1112,10 @@ pub mod funcs {
// Omitted: putc, putchar (might be macros).
unsafe fn puts(s: *c_char) -> c_int;
unsafe fn ungetc(c: c_int, stream: *FILE) -> c_int;
#[fast_ffi]
unsafe fn fread(ptr: *mut c_void, size: size_t,
nobj: size_t, stream: *FILE) -> size_t;
#[fast_ffi]
unsafe fn fwrite(ptr: *c_void, size: size_t,
nobj: size_t, stream: *FILE) -> size_t;
unsafe fn fseek(stream: *FILE, offset: c_long,
Expand Down Expand Up @@ -1144,9 +1149,13 @@ pub mod funcs {
-> c_long;
unsafe fn strtoul(s: *c_char, endp: **c_char, base: c_int)
-> c_ulong;
#[fast_ffi]
unsafe fn calloc(nobj: size_t, size: size_t) -> *c_void;
#[fast_ffi]
unsafe fn malloc(size: size_t) -> *c_void;
#[fast_ffi]
unsafe fn realloc(p: *c_void, size: size_t) -> *c_void;
#[fast_ffi]
unsafe fn free(p: *c_void);
unsafe fn abort() -> !;
unsafe fn exit(status: c_int) -> !;
Expand Down Expand Up @@ -1257,6 +1266,7 @@ pub mod funcs {
unsafe fn pclose(stream: *FILE) -> c_int;

#[link_name = "_fdopen"]
#[fast_ffi]
unsafe fn fdopen(fd: c_int, mode: *c_char) -> *FILE;

#[link_name = "_fileno"]
Expand Down Expand Up @@ -1340,6 +1350,7 @@ pub mod funcs {
textmode: c_int) -> c_int;

#[link_name = "_read"]
#[fast_ffi]
unsafe fn read(fd: c_int, buf: *mut c_void, count: c_uint)
-> c_int;

Expand All @@ -1350,6 +1361,7 @@ pub mod funcs {
unsafe fn unlink(c: *c_char) -> c_int;

#[link_name = "_write"]
#[fast_ffi]
unsafe fn write(fd: c_int, buf: *c_void, count: c_uint)
-> c_int;
}
Expand Down Expand Up @@ -1502,6 +1514,7 @@ pub mod funcs {
unsafe fn pathconf(path: *c_char, name: c_int) -> c_long;
unsafe fn pause() -> c_int;
unsafe fn pipe(fds: *mut c_int) -> c_int;
#[fast_ffi]
unsafe fn read(fd: c_int, buf: *mut c_void,
count: size_t) -> ssize_t;
unsafe fn rmdir(path: *c_char) -> c_int;
Expand All @@ -1514,6 +1527,7 @@ pub mod funcs {
unsafe fn tcgetpgrp(fd: c_int) -> pid_t;
unsafe fn ttyname(fd: c_int) -> *c_char;
unsafe fn unlink(c: *c_char) -> c_int;
#[fast_ffi]
unsafe fn write(fd: c_int, buf: *c_void, count: size_t)
-> ssize_t;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/num/int-template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,4 +503,4 @@ mod tests {
fn test_range_step_zero_step() {
for range_step(0,10,0) |_i| {}
}
}
}
2 changes: 1 addition & 1 deletion src/libcore/num/uint-template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,4 +474,4 @@ mod tests {
fn test_range_step_zero_step_down() {
for range_step(0,-10,0) |_i| {}
}
}
}
4 changes: 2 additions & 2 deletions src/libcore/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub use container::{Container, Mutable, Map, Set};
pub use hash::Hash;
pub use iter::{BaseIter, ReverseIter, MutableIter, ExtendedIter, EqIter};
pub use iter::{CopyableIter, CopyableOrderedIter, CopyableNonstrictIter};
pub use iter::Times;
pub use iter::{Times, ExtendedMutableIter};
pub use num::{Num, NumCast};
pub use path::GenericPath;
pub use path::Path;
Expand All @@ -46,7 +46,7 @@ pub use to_str::ToStr;
pub use tuple::{CopyableTuple, ImmutableTuple, ExtendedTupleOps};
pub use vec::{CopyableVector, ImmutableVector};
pub use vec::{ImmutableEqVector, ImmutableCopyableVector};
pub use vec::{OwnedVector, OwnedCopyableVector};
pub use vec::{OwnedVector, OwnedCopyableVector, MutableVector};
pub use io::{Reader, ReaderUtil, Writer, WriterUtil};

/* Reexported runtime types */
Expand Down
18 changes: 18 additions & 0 deletions src/libcore/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ pub fn from_bytes_with_null<'a>(vv: &'a [u8]) -> &'a str {
return unsafe { raw::from_bytes_with_null(vv) };
}

pub fn from_bytes_slice<'a>(vector: &'a [u8]) -> &'a str {
unsafe {
assert!(is_utf8(vector));
let (ptr, len): (*u8, uint) = ::cast::transmute(vector);
let string: &'a str = ::cast::transmute((ptr, len + 1));
string
}
}

/// Copy a slice into a new unique str
pub fn from_slice(s: &str) -> ~str {
unsafe { raw::slice_bytes_owned(s, 0, len(s)) }
Expand Down Expand Up @@ -421,6 +430,15 @@ pub fn byte_slice<T>(s: &str, f: &fn(v: &[u8]) -> T) -> T {
}
}

/// Work with the string as a byte slice, not including trailing null, without
/// a callback.
#[inline(always)]
pub fn byte_slice_no_callback<'a>(s: &'a str) -> &'a [u8] {
unsafe {
cast::transmute(s)
}
}

/// Convert a string to a unique vector of characters
pub fn to_chars(s: &str) -> ~[char] {
let mut buf = ~[];
Expand Down
12 changes: 10 additions & 2 deletions src/libcore/unstable/lang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ pub mod rustrt {

#[rust_stack]
unsafe fn rust_upcall_free(ptr: *c_char);

#[fast_ffi]
unsafe fn rust_upcall_malloc_noswitch(td: *c_char,
size: uintptr_t)
-> *c_char;

#[fast_ffi]
unsafe fn rust_upcall_free_noswitch(ptr: *c_char);
}
}

Expand Down Expand Up @@ -81,7 +89,7 @@ pub unsafe fn exchange_free(ptr: *c_char) {
#[lang="malloc"]
#[inline(always)]
pub unsafe fn local_malloc(td: *c_char, size: uintptr_t) -> *c_char {
return rustrt::rust_upcall_malloc(td, size);
return rustrt::rust_upcall_malloc_noswitch(td, size);
}

// NB: Calls to free CANNOT be allowed to fail, as throwing an exception from
Expand All @@ -90,7 +98,7 @@ pub unsafe fn local_malloc(td: *c_char, size: uintptr_t) -> *c_char {
#[lang="free"]
#[inline(always)]
pub unsafe fn local_free(ptr: *c_char) {
rustrt::rust_upcall_free(ptr);
rustrt::rust_upcall_free_noswitch(ptr);
}

#[lang="borrow_as_imm"]
Expand Down
Loading