Skip to content
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

Add liballoc impl SpecFromElem for i8 #73529

Merged
merged 1 commit into from
Jun 27, 2020

Conversation

pickfire
Copy link
Contributor

@pickfire pickfire commented Jun 20, 2020

Speedup vec![1_i8; N] for non-zero element.

Before
test do_bench_from_elem_i8 ... bench: 130 ns/iter (+/- 7) = 61 MB/s
test do_bench_from_elem_u8 ... bench: 121 ns/iter (+/- 4) = 66 MB/s
After
test do_bench_from_elem_i8 ... bench: 123 ns/iter (+/- 7) = 65 MB/s
test do_bench_from_elem_u8 ... bench: 121 ns/iter (+/- 5) = 66 MB/s

No speed difference if element is already zero.

#[bench]
fn do_bench_from_elem_i8(b: &mut Bencher) {
    b.bytes = 8 as u64;
    b.iter(|| {
        let dst = ve::vec![10_i8; 100];
        assert_eq!(dst.len(), 100);
        assert!(dst.iter().all(|x| *x == 10));
    })
}

As suggested by @cuviper
https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/SpecForElem.20for.20other.20integers

r? @cuviper
CC @joshtriplett

Edit: Wow, I just realized both reviewers are Josh.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 20, 2020
@rust-highfive
Copy link
Collaborator

The job mingw-check of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
##[section]Starting: Linux mingw-check
##[section]Starting: Initialize job
Agent name: 'Azure Pipelines 11'
Agent machine name: 'fv-az578'
Current agent version: '2.170.1'
##[group]Operating System
16.04.6
LTS
LTS
##[endgroup]
##[group]Virtual Environment
Environment: ubuntu-16.04
Version: 20200614.1
Included Software: https://github.com/actions/virtual-environments/blob/ubuntu16/20200614.1/images/linux/Ubuntu1604-README.md
##[endgroup]
Agent running as: 'vsts'
Prepare build directory.
Set build variables.
Download all required tasks.
Download all required tasks.
Downloading task: Bash (3.163.3)
Checking job knob settings.
   Knob: AgentToolsDirectory = /opt/hostedtoolcache Source: ${AGENT_TOOLSDIRECTORY} 
   Knob: AgentPerflog = /home/vsts/perflog Source: ${VSTS_AGENT_PERFLOG} 
Start tracking orphan processes.
##[section]Finishing: Initialize job
##[section]Starting: Configure Job Name
==============================================================================
---
========================== Starting Command Output ===========================
[command]/bin/bash --noprofile --norc /home/vsts/work/_temp/f047fbcc-7393-433f-bdbb-926914efc169.sh

##[section]Finishing: Disable git automatic line ending conversion
##[section]Starting: Checkout rust-lang/rust@refs/pull/73529/merge to s
Task         : Get sources
Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
Version      : 1.0.0
Author       : Microsoft
---
##[command]git remote add origin https://github.com/rust-lang/rust
##[command]git config gc.auto 0
##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
##[command]git config --get-all http.proxy
##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/73529/merge:refs/remotes/pull/73529/merge
---
 ---> a9ec21d337b3
Step 6/7 : ENV RUN_CHECK_WITH_PARALLEL_QUERIES 1
 ---> Using cache
 ---> 5ff2c13d8dba
Step 7/7 : ENV SCRIPT python3 ../x.py test src/tools/expand-yaml-anchors &&            python3 ../x.py check --target=i686-pc-windows-gnu --host=i686-pc-windows-gnu &&            python3 ../x.py build --stage 0 src/tools/build-manifest &&            python3 ../x.py test --stage 0 src/tools/compiletest &&            python3 ../x.py test src/tools/tidy &&            python3 ../x.py doc --stage 0 src/libstd &&            /scripts/validate-toolstate.sh
 ---> 6b931e755c7e
Successfully built 6b931e755c7e
Successfully tagged rust-ci:latest
Built container sha256:6b931e755c7ea1f69816640eb9df74fafd40a545d0e5aa8341d35009dabb0f3c
---
    Checking alloc v0.0.0 (/checkout/src/liballoc)
error[E0053]: method `from_elem` has an incompatible type for trait
    --> src/liballoc/vec.rs:1808:41
     |
1795 |     fn from_elem(elem: Self, n: usize) -> Vec<Self>;
     |                                           --------- type in trait
...
1808 |     fn from_elem(elem: i8, n: usize) -> Vec<u8> {
     |                                         ^^^^^^^ expected `i8`, found `u8`
     = note: expected fn pointer `fn(_, _) -> vec::Vec<i8>`
                found fn pointer `fn(_, _) -> vec::Vec<u8>`

error[E0308]: mismatched types
error[E0308]: mismatched types
    --> src/liballoc/vec.rs:1814:46
     |
1814 |             ptr::write_bytes(v.as_mut_ptr(), elem, n);
     |                                              ^^^^ expected `u8`, found `i8`
help: you can convert an `i8` to `u8` and panic if the converted value wouldn't fit
     |
     |
1814 |             ptr::write_bytes(v.as_mut_ptr(), elem.try_into().unwrap(), n);

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0053, E0308.
---
  local time: Sat Jun 20 03:17:31 UTC 2020
  network time: Sat, 20 Jun 2020 03:17:31 GMT
== end clock drift check ==

##[error]Bash exited with code '1'.
##[section]Finishing: Run build
##[section]Starting: Checkout rust-lang/rust@refs/pull/73529/merge to s
Task         : Get sources
Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
Version      : 1.0.0
Author       : Microsoft
Author       : Microsoft
Help         : [More Information](https://go.microsoft.com/fwlink/?LinkId=798199)
==============================================================================
Cleaning any cached credential from repository: rust-lang/rust (GitHub)
##[section]Finishing: Checkout rust-lang/rust@refs/pull/73529/merge to s
Cleaning up task key
Start cleaning up orphan processes.
Terminate orphan process: pid (4190) (python)
##[section]Finishing: Finalize Job

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @rust-lang/infra. (Feature Requests)

@rust-highfive
Copy link
Collaborator

The job mingw-check of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
##[section]Starting: Linux mingw-check
##[section]Starting: Initialize job
Agent name: 'Azure Pipelines 5'
Agent machine name: 'fv-az578'
Current agent version: '2.170.1'
##[group]Operating System
16.04.6
LTS
LTS
##[endgroup]
##[group]Virtual Environment
Environment: ubuntu-16.04
Version: 20200614.1
Included Software: https://github.com/actions/virtual-environments/blob/ubuntu16/20200614.1/images/linux/Ubuntu1604-README.md
##[endgroup]
Agent running as: 'vsts'
Prepare build directory.
Set build variables.
Download all required tasks.
Download all required tasks.
Downloading task: Bash (3.163.3)
Checking job knob settings.
   Knob: AgentToolsDirectory = /opt/hostedtoolcache Source: ${AGENT_TOOLSDIRECTORY} 
   Knob: AgentPerflog = /home/vsts/perflog Source: ${VSTS_AGENT_PERFLOG} 
Start tracking orphan processes.
##[section]Finishing: Initialize job
##[section]Starting: Configure Job Name
==============================================================================
---
========================== Starting Command Output ===========================
[command]/bin/bash --noprofile --norc /home/vsts/work/_temp/aef24d44-6704-484d-907e-ae8489e9de4e.sh

##[section]Finishing: Disable git automatic line ending conversion
##[section]Starting: Checkout rust-lang/rust@refs/pull/73529/merge to s
Task         : Get sources
Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
Version      : 1.0.0
Author       : Microsoft
---
##[command]git remote add origin https://github.com/rust-lang/rust
##[command]git config gc.auto 0
##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
##[command]git config --get-all http.proxy
##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/73529/merge:refs/remotes/pull/73529/merge
---
 ---> a9ec21d337b3
Step 6/7 : ENV RUN_CHECK_WITH_PARALLEL_QUERIES 1
 ---> Using cache
 ---> 5ff2c13d8dba
Step 7/7 : ENV SCRIPT python3 ../x.py test src/tools/expand-yaml-anchors &&            python3 ../x.py check --target=i686-pc-windows-gnu --host=i686-pc-windows-gnu &&            python3 ../x.py build --stage 0 src/tools/build-manifest &&            python3 ../x.py test --stage 0 src/tools/compiletest &&            python3 ../x.py test src/tools/tidy &&            python3 ../x.py doc --stage 0 src/libstd &&            /scripts/validate-toolstate.sh
 ---> 6b931e755c7e
Successfully built 6b931e755c7e
Successfully tagged rust-ci:latest
Built container sha256:6b931e755c7ea1f69816640eb9df74fafd40a545d0e5aa8341d35009dabb0f3c
---
    Checking alloc v0.0.0 (/checkout/src/liballoc)
error[E0053]: method `from_elem` has an incompatible type for trait
    --> src/liballoc/vec.rs:1808:41
     |
1795 |     fn from_elem(elem: Self, n: usize) -> Vec<Self>;
     |                                           --------- type in trait
...
1808 |     fn from_elem(elem: i8, n: usize) -> Vec<u8> {
     |                                         ^^^^^^^ expected `i8`, found `u8`
     = note: expected fn pointer `fn(_, _) -> vec::Vec<i8>`
                found fn pointer `fn(_, _) -> vec::Vec<u8>`

    Checking rustc-demangle v0.1.16
---
  local time: Sat Jun 20 03:26:34 UTC 2020
  network time: Sat, 20 Jun 2020 03:26:35 GMT
== end clock drift check ==

##[error]Bash exited with code '1'.
##[section]Finishing: Run build
##[section]Starting: Checkout rust-lang/rust@refs/pull/73529/merge to s
Task         : Get sources
Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
Version      : 1.0.0
Author       : Microsoft
Author       : Microsoft
Help         : [More Information](https://go.microsoft.com/fwlink/?LinkId=798199)
==============================================================================
Cleaning any cached credential from repository: rust-lang/rust (GitHub)
##[section]Finishing: Checkout rust-lang/rust@refs/pull/73529/merge to s
Cleaning up task key
Start cleaning up orphan processes.
Terminate orphan process: pid (4649) (python)
##[section]Finishing: Finalize Job

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @rust-lang/infra. (Feature Requests)

@rust-highfive
Copy link
Collaborator

The job mingw-check of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
##[section]Starting: Linux mingw-check
##[section]Starting: Initialize job
Agent name: 'Azure Pipelines 14'
Agent machine name: 'fv-az619'
Current agent version: '2.170.1'
##[group]Operating System
16.04.6
LTS
LTS
##[endgroup]
##[group]Virtual Environment
Environment: ubuntu-16.04
Version: 20200614.1
Included Software: https://github.com/actions/virtual-environments/blob/ubuntu16/20200614.1/images/linux/Ubuntu1604-README.md
##[endgroup]
Agent running as: 'vsts'
Prepare build directory.
Set build variables.
Download all required tasks.
Download all required tasks.
Downloading task: Bash (3.163.3)
Checking job knob settings.
   Knob: AgentToolsDirectory = /opt/hostedtoolcache Source: ${AGENT_TOOLSDIRECTORY} 
   Knob: AgentPerflog = /home/vsts/perflog Source: ${VSTS_AGENT_PERFLOG} 
Start tracking orphan processes.
##[section]Finishing: Initialize job
##[section]Starting: Configure Job Name
==============================================================================
---
========================== Starting Command Output ===========================
[command]/bin/bash --noprofile --norc /home/vsts/work/_temp/cac80ae1-0bd2-4e39-aa9b-b0e9ee41a7ae.sh

##[section]Finishing: Disable git automatic line ending conversion
##[section]Starting: Checkout rust-lang/rust@refs/pull/73529/merge to s
Task         : Get sources
Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
Version      : 1.0.0
Author       : Microsoft
---
##[command]git remote add origin https://github.com/rust-lang/rust
##[command]git config gc.auto 0
##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
##[command]git config --get-all http.proxy
##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/73529/merge:refs/remotes/pull/73529/merge
---
 ---> a9ec21d337b3
Step 6/7 : ENV RUN_CHECK_WITH_PARALLEL_QUERIES 1
 ---> Using cache
 ---> 5ff2c13d8dba
Step 7/7 : ENV SCRIPT python3 ../x.py test src/tools/expand-yaml-anchors &&            python3 ../x.py check --target=i686-pc-windows-gnu --host=i686-pc-windows-gnu &&            python3 ../x.py build --stage 0 src/tools/build-manifest &&            python3 ../x.py test --stage 0 src/tools/compiletest &&            python3 ../x.py test src/tools/tidy &&            python3 ../x.py doc --stage 0 src/libstd &&            /scripts/validate-toolstate.sh
 ---> 6b931e755c7e
Successfully built 6b931e755c7e
Successfully tagged rust-ci:latest
Built container sha256:6b931e755c7ea1f69816640eb9df74fafd40a545d0e5aa8341d35009dabb0f3c
---
    Checking alloc v0.0.0 (/checkout/src/liballoc)
error[E0053]: method `from_elem` has an incompatible type for trait
    --> src/liballoc/vec.rs:1808:41
     |
1795 |     fn from_elem(elem: Self, n: usize) -> Vec<Self>;
     |                                           --------- type in trait
...
1808 |     fn from_elem(elem: i8, n: usize) -> Vec<u8> {
     |                                         ^^^^^^^ expected `i8`, found `u8`
     = note: expected fn pointer `fn(_, _) -> vec::Vec<i8>`
                found fn pointer `fn(_, _) -> vec::Vec<u8>`

    Checking cfg-if v0.1.10
---
  local time: Sat Jun 20 03:51:35 UTC 2020
  network time: Sat, 20 Jun 2020 03:51:35 GMT
== end clock drift check ==

##[error]Bash exited with code '1'.
##[section]Finishing: Run build
##[section]Starting: Checkout rust-lang/rust@refs/pull/73529/merge to s
Task         : Get sources
Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
Version      : 1.0.0
Author       : Microsoft
Author       : Microsoft
Help         : [More Information](https://go.microsoft.com/fwlink/?LinkId=798199)
==============================================================================
Cleaning any cached credential from repository: rust-lang/rust (GitHub)
##[section]Finishing: Checkout rust-lang/rust@refs/pull/73529/merge to s
Cleaning up task key
Start cleaning up orphan processes.
Terminate orphan process: pid (7018) (python)
##[section]Finishing: Finalize Job

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @rust-lang/infra. (Feature Requests)

Speedup vec![1_i8; N] for non-zero element.

Before
test do_bench_from_elem_i8        ... bench:         130 ns/iter (+/- 7) = 61 MB/s
test do_bench_from_elem_u8        ... bench:         121 ns/iter (+/- 4) = 66 MB/s
After
test do_bench_from_elem_i8        ... bench:         123 ns/iter (+/- 7) = 65 MB/s
test do_bench_from_elem_u8        ... bench:         121 ns/iter (+/- 5) = 66 MB/s

No speed difference if element is already zero.

    #[bench]
    fn do_bench_from_elem_i8(b: &mut Bencher) {
        b.bytes = 8 as u64;
        b.iter(|| {
            let dst = ve::vec![10_i8; 100];
            assert_eq!(dst.len(), 100);
            assert!(dst.iter().all(|x| *x == 10));
        })
    }

As suggested by @cuviper
https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/SpecForElem.20for.20other.20integers
@cuviper
Copy link
Member

cuviper commented Jun 26, 2020

@bors r+

@bors
Copy link
Contributor

bors commented Jun 26, 2020

📌 Commit f66bcc5 has been approved by cuviper

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 26, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 27, 2020
…arth

Rollup of 12 pull requests

Successful merges:

 - rust-lang#72771 (Warn if linking to a private item)
 - rust-lang#72937 (Fortanix SGX target libunwind build process changes)
 - rust-lang#73485 (Perform obligation deduplication to avoid buggy `ExistentialMismatch`)
 - rust-lang#73529 (Add liballoc impl SpecFromElem for i8)
 - rust-lang#73579 (add missing doc links)
 - rust-lang#73627 (Shortcuts for min/max on double-ended BTreeMap/BTreeSet iterators)
 - rust-lang#73691 (Bootstrap: detect Windows based on sys.platform)
 - rust-lang#73694 (Document the Self keyword)
 - rust-lang#73718 (Document the super keyword)
 - rust-lang#73728 (Document some invariants correctly/more)
 - rust-lang#73738 (Remove irrelevant comment)
 - rust-lang#73765 (Remove blank line)

Failed merges:

r? @ghost
@pickfire
Copy link
Contributor Author

I don't know offhand how to get the compiler to generate a rep stosw (or d or q). (And in any case, it would need benchmarking to ensure that it's actually faster.)
I don't know if that would be a performance win, though it might be worth benchmarking (via a cfg-guarded specialization).

I believe we should add some TODO there from @joshtriplett for the other stuff but since I am not sure how to get those working.

@bors bors merged commit 23b0776 into rust-lang:master Jun 27, 2020
@pickfire pickfire deleted the liballoc-specfromelem-i8 branch June 27, 2020 06:46
@cuviper cuviper added this to the 1.46 milestone May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants