Rivoreo Source Code Repositories
src.rivoreo.one
/
compiler-explorer
/
6c6d1bb0971b261f508e42a6dfc2e3f34db0ed3b
/
.
/
examples
/
rust
/
sum_over_array_opt.rs
blob: 094f341b781e1742c9b21c2076d7cc6d0eac2886 [
file
] [
log
] [
blame
] [
raw
]
#![
feature
(
core_intrinsics
)]
// Requires the use of the nightly rust
// Compile with -O
pub
fn
sum_array
(
x
:
&[
i32
])
->
i32
{
unsafe
{
std
::
intrinsics
::
assume
(
x
.
as_ptr
()
as
usize
%
64
==
0
);
}
x
.
iter
().
fold
(
0
,
|
sum
,
next
|
sum
+
*
next
)
}