Skip to content

Commit

Permalink
Refactor three_billion_instructions into library
Browse files Browse the repository at this point in the history
Summary: Want to use it in a test for code to measure current thread instruction counts.

Reviewed By: krallin

Differential Revision: D54375084

fbshipit-source-id: 0dc23a11e94136604c23541352a93dcd6bf28172
  • Loading branch information
stepancheg authored and facebook-github-bot committed Feb 29, 2024
1 parent 7861e7e commit b98fd06
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/buck2_miniperf/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ rust_library(
}),
test_env = {
"MINIPERF": "$(exe_target :buck2_miniperf)",
"THREE_BILLION_INSTRUCTIONS": "$(exe_target //buck2/shed/three_billion_instructions:three_billion_instructions)",
"THREE_BILLION_INSTRUCTIONS": "$(exe_target //buck2/shed/three_billion_instructions:three_billion_instructions-bin)",
},
)
12 changes: 11 additions & 1 deletion shed/three_billion_instructions/BUCK
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
load("@fbcode_macros//build_defs:rust_binary.bzl", "rust_binary")
load("@fbcode_macros//build_defs:rust_library.bzl", "rust_library")
load("@fbsource//tools/build_defs:glob_defs.bzl", "glob")

oncall("build_infra")

rust_binary(
rust_library(
name = "three_billion_instructions",
srcs = glob(
["src/**/*.rs"],
),
)

rust_binary(
name = "three_billion_instructions-bin",
srcs = ["bin/three_billion_instructions.rs"],
crate_root = "bin/three_billion_instructions.rs",
deps = [
":three_billion_instructions",
],
)
15 changes: 15 additions & 0 deletions shed/three_billion_instructions/bin/three_billion_instructions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under both the MIT license found in the
* LICENSE-MIT file in the root directory of this source tree and the Apache
* License, Version 2.0 found in the LICENSE-APACHE file in the root directory
* of this source tree.
*/

use three_billion_instructions::three_billion_instructions;

/// Run 3B instructions.
fn main() {
three_billion_instructions();
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,28 @@
*/

/// Run 3B instructions.
fn main() {
pub fn three_billion_instructions() {
let mut x = 1_000_000_000u64;

#[cfg(target_arch = "x86_64")]
unsafe {
std::arch::asm!(
"2:",
"sub {0:r}, 1",
"cmp {0:r}, 0",
"jne 2b",
inout(reg) x,
"2:",
"sub {0:r}, 1",
"cmp {0:r}, 0",
"jne 2b",
inout(reg) x,
);
}

#[cfg(target_arch = "aarch64")]
unsafe {
std::arch::asm!(
"2:",
"sub {0:x}, {0:x}, 1",
"cmp {0:x}, 0",
"bne 2b",
inout(reg) x,
"2:",
"sub {0:x}, {0:x}, 1",
"cmp {0:x}, 0",
"bne 2b",
inout(reg) x,
);
}

Expand Down

0 comments on commit b98fd06

Please sign in to comment.