Rivoreo Source Code Repositories
src.rivoreo.one
/
compiler-explorer
/
d4ae1a0787e95d2258e37e954f4b6dda3bce8f34
/
.
/
examples
/
rust
/
Sum_over_array_(Optimized).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
)
}