-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
auto merge of #5424 : luqmana/rust/inline-rt, r=brson
As per #2521. Inlining seems to improve performance slightly: Inlined Not Inlined x86: 13.5482 14.4112 x86_64: 17.4712 18.0696 (Average of 5 runs timed with `time`) ```Rust fn foo() -> int { int::from_str(~"28098").unwrap() } fn main() { for 1000000.times { foo(); foo(); foo(); foo(); foo(); } } ``` All run on: Linux 3.2.0-0.bpo.4-amd64 #1 SMP Debian 3.2.35-2~bpo60+1 x86_64 GNU/Linux The MIPS and ARM bits I didn't inline since I'm not as familiar with them and I also can't test them. All green on try.
- Loading branch information
Showing
8 changed files
with
217 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// Getting the stack pointer and getting/setting sp limit. | ||
|
||
#ifndef SP_H | ||
#define SP_H | ||
|
||
#include "../../rust_globals.h" | ||
|
||
// Gets a pointer to the vicinity of the current stack pointer | ||
extern "C" uintptr_t get_sp(); | ||
|
||
// Gets the pointer to the end of the Rust stack from a platform- | ||
// specific location in the thread control block | ||
extern "C" CDECL uintptr_t get_sp_limit(); | ||
|
||
// Records the pointer to the end of the Rust stack in a platform- | ||
// specific location in the thread control block | ||
extern "C" CDECL void record_sp_limit(void *limit); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +0,0 @@ | ||
.text | ||
|
||
#if defined(__APPLE__) || defined(_WIN32) | ||
#define RECORD_SP_LIMIT _record_sp_limit | ||
#define GET_SP_LIMIT _get_sp_limit | ||
#define GET_SP _get_sp | ||
#else | ||
#define RECORD_SP_LIMIT record_sp_limit | ||
#define GET_SP_LIMIT get_sp_limit | ||
#define GET_SP get_sp | ||
#endif | ||
|
||
.globl RECORD_SP_LIMIT | ||
.globl GET_SP_LIMIT | ||
.globl GET_SP | ||
|
||
#if defined(__linux__) || defined(__FreeBSD__) | ||
RECORD_SP_LIMIT: | ||
movl 4(%esp), %eax | ||
movl %eax, %gs:48 | ||
ret | ||
#endif | ||
|
||
#if defined(__APPLE__) | ||
RECORD_SP_LIMIT: | ||
movl $0x48+90*4, %eax | ||
movl 4(%esp), %ecx | ||
movl %ecx, %gs:(%eax) | ||
ret | ||
#endif | ||
|
||
#if defined(_WIN32) | ||
RECORD_SP_LIMIT: | ||
movl 4(%esp), %eax | ||
movl %eax, %fs:0x14 | ||
ret | ||
#endif | ||
|
||
#if defined(__linux__) || defined(__FreeBSD__) | ||
GET_SP_LIMIT: | ||
movl %gs:48, %eax | ||
ret | ||
#endif | ||
|
||
#if defined(__APPLE__) | ||
GET_SP_LIMIT: | ||
movl $0x48+90*4, %ecx | ||
movl %gs:(%ecx), %eax | ||
ret | ||
#endif | ||
|
||
#if defined(_WIN32) | ||
GET_SP_LIMIT: | ||
movl %fs:0x14, %eax | ||
ret | ||
#endif | ||
|
||
GET_SP: | ||
movl %esp, %eax | ||
ret | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// Getting the stack pointer and getting/setting sp limit. | ||
|
||
#ifndef SP_H | ||
#define SP_H | ||
|
||
#include "../../rust_globals.h" | ||
|
||
// Gets a pointer to the vicinity of the current stack pointer | ||
extern "C" ALWAYS_INLINE uintptr_t get_sp() { | ||
uintptr_t sp; | ||
asm volatile ( | ||
"movl %%esp, %0" | ||
: "=m"(sp)); | ||
return sp; | ||
} | ||
|
||
// Gets the pointer to the end of the Rust stack from a platform- | ||
// specific location in the thread control block | ||
extern "C" CDECL ALWAYS_INLINE uintptr_t get_sp_limit() { | ||
uintptr_t limit; | ||
|
||
#if defined(__linux__) || defined(__FreeBSD__) | ||
asm volatile ( | ||
"movl %%gs:48, %0" | ||
: "=r"(limit)); | ||
#elif defined(__APPLE__) | ||
asm volatile ( | ||
"movl $0x48+90*4, %%ecx\n\t" | ||
"movl %%gs:(%%ecx), %0" | ||
: "=r"(limit) | ||
:: "ecx"); | ||
#elif defined(_WIN32) | ||
asm volatile ( | ||
"movl %%fs:0x14, %0" | ||
: "=r"(limit)); | ||
#endif | ||
|
||
return limit; | ||
} | ||
|
||
// Records the pointer to the end of the Rust stack in a platform- | ||
// specific location in the thread control block | ||
extern "C" CDECL ALWAYS_INLINE void record_sp_limit(void *limit) { | ||
#if defined(__linux__) || defined(__FreeBSD__) | ||
asm volatile ( | ||
"movl %0, %%gs:48" | ||
:: "r"(limit)); | ||
#elif defined(__APPLE__) | ||
asm volatile ( | ||
"movl $0x48+90*4, %%eax\n\t" | ||
"movl %0, %%gs:(%%eax)" | ||
:: "r"(limit) | ||
: "eax"); | ||
#elif defined(_WIN32) | ||
asm volatile ( | ||
"movl %0, %%fs:0x14" | ||
:: "r"(limit)); | ||
#endif | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// Getting the stack pointer and getting/setting sp limit. | ||
|
||
#ifndef SP_H | ||
#define SP_H | ||
|
||
#include "../../rust_globals.h" | ||
|
||
// Gets a pointer to the vicinity of the current stack pointer | ||
extern "C" uintptr_t get_sp(); | ||
|
||
// Gets the pointer to the end of the Rust stack from a platform- | ||
// specific location in the thread control block | ||
extern "C" CDECL uintptr_t get_sp_limit(); | ||
|
||
// Records the pointer to the end of the Rust stack in a platform- | ||
// specific location in the thread control block | ||
extern "C" CDECL void record_sp_limit(void *limit); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +0,0 @@ | ||
.text | ||
|
||
#if defined(__APPLE__) || defined(_WIN32) | ||
#define RECORD_SP_LIMIT _record_sp_limit | ||
#define GET_SP_LIMIT _get_sp_limit | ||
#define GET_SP _get_sp | ||
#else | ||
#define RECORD_SP_LIMIT record_sp_limit | ||
#define GET_SP_LIMIT get_sp_limit | ||
#define GET_SP get_sp | ||
#endif | ||
|
||
.globl RECORD_SP_LIMIT | ||
.globl GET_SP_LIMIT | ||
.globl GET_SP | ||
|
||
#if defined(__linux__) | ||
RECORD_SP_LIMIT: | ||
movq %rdi, %fs:112 | ||
ret | ||
#elif defined(__APPLE__) | ||
RECORD_SP_LIMIT: | ||
movq $0x60+90*8, %rsi | ||
movq %rdi, %gs:(%rsi) | ||
ret | ||
#elif defined(__FreeBSD__) | ||
RECORD_SP_LIMIT: | ||
movq %rdi, %fs:24 | ||
ret | ||
#else | ||
RECORD_SP_LIMIT: | ||
ret | ||
#endif | ||
|
||
#if defined(__linux__) | ||
GET_SP_LIMIT: | ||
movq %fs:112, %rax | ||
ret | ||
#elif defined(__APPLE__) | ||
GET_SP_LIMIT: | ||
movq $0x60+90*8, %rsi | ||
movq %gs:(%rsi), %rax | ||
ret | ||
#elif defined(__FreeBSD__) | ||
GET_SP_LIMIT: | ||
movq %fs:24, %rax | ||
ret | ||
#endif | ||
|
||
GET_SP: | ||
movq %rsp, %rax | ||
ret | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// Getting the stack pointer and getting/setting sp limit. | ||
|
||
#ifndef SP_H | ||
#define SP_H | ||
|
||
#include "../../rust_globals.h" | ||
|
||
// Gets a pointer to the vicinity of the current stack pointer | ||
extern "C" ALWAYS_INLINE uintptr_t get_sp() { | ||
uintptr_t sp; | ||
asm volatile ( | ||
"movq %%rsp, %0" | ||
: "=m"(sp)); | ||
return sp; | ||
} | ||
|
||
// Gets the pointer to the end of the Rust stack from a platform- | ||
// specific location in the thread control block | ||
extern "C" CDECL ALWAYS_INLINE uintptr_t get_sp_limit() { | ||
uintptr_t limit; | ||
|
||
#if defined(__linux__) | ||
asm volatile ( | ||
"movq %%fs:112, %0" | ||
: "=r"(limit)); | ||
#elif defined(__APPLE__) | ||
asm volatile ( | ||
"movq $0x60+90*8, %%rsi\n\t" | ||
"movq %%gs:(%%rsi), %0" | ||
: "=r"(limit) | ||
:: "rsi"); | ||
#elif defined(__FreeBSD__) | ||
asm volatile ( | ||
"movq %%fs:24, %0" | ||
: "=r"(limit)); | ||
#endif | ||
|
||
return limit; | ||
} | ||
|
||
// Records the pointer to the end of the Rust stack in a platform- | ||
// specific location in the thread control block | ||
extern "C" CDECL ALWAYS_INLINE void record_sp_limit(void *limit) { | ||
#if defined(__linux__) | ||
asm volatile ( | ||
"movq %0, %%fs:112" | ||
:: "r"(limit)); | ||
#elif defined(__APPLE__) | ||
asm volatile ( | ||
"movq $0x60+90*8, %%rsi\n\t" | ||
"movq %0, %%gs:(%%rsi)" | ||
:: "r"(limit) | ||
: "rsi"); | ||
#elif defined(__FreeBSD__) | ||
asm volatile ( | ||
"movq %0, %%fs:24" | ||
:: "r"(limit)); | ||
#endif | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters