[llvm] r342369 - [llvm-exegesis] Add predefined floating point values so we can test impact of special values on latency.
Guillaume Chatelet via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 17 04:09:32 PDT 2018
Author: gchatelet
Date: Mon Sep 17 04:09:32 2018
New Revision: 342369
URL: http://llvm.org/viewvc/llvm-project?rev=342369&view=rev
Log:
[llvm-exegesis] Add predefined floating point values so we can test impact of special values on latency.
Summary: This will be useful to generate many configurations and test instruction regimes (NaN, Inf, subnormal, normal).
Reviewers: courbet
Subscribers: mgorny, tschuett, llvm-commits
Differential Revision: https://reviews.llvm.org/D51858
Added:
llvm/trunk/tools/llvm-exegesis/lib/RegisterValue.cpp
llvm/trunk/tools/llvm-exegesis/lib/RegisterValue.h
llvm/trunk/unittests/tools/llvm-exegesis/RegisterValueTest.cpp
Modified:
llvm/trunk/tools/llvm-exegesis/lib/CMakeLists.txt
llvm/trunk/unittests/tools/llvm-exegesis/CMakeLists.txt
Modified: llvm/trunk/tools/llvm-exegesis/lib/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/CMakeLists.txt?rev=342369&r1=342368&r2=342369&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/CMakeLists.txt (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/CMakeLists.txt Mon Sep 17 04:09:32 2018
@@ -20,6 +20,7 @@ add_library(LLVMExegesis
PerfHelper.cpp
RegisterAliasing.cpp
SnippetGenerator.cpp
+ RegisterValue.cpp
Target.cpp
Uops.cpp
)
Added: llvm/trunk/tools/llvm-exegesis/lib/RegisterValue.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/RegisterValue.cpp?rev=342369&view=auto
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/RegisterValue.cpp (added)
+++ llvm/trunk/tools/llvm-exegesis/lib/RegisterValue.cpp Mon Sep 17 04:09:32 2018
@@ -0,0 +1,48 @@
+//===-- RegisterValue.cpp ---------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "RegisterValue.h"
+#include "llvm/ADT/APFloat.h"
+
+namespace exegesis {
+
+static llvm::APFloat getFloatValue(const llvm::fltSemantics &FltSemantics,
+ PredefinedValues Value) {
+ switch (Value) {
+ case PredefinedValues::POS_ZERO:
+ return llvm::APFloat::getZero(FltSemantics);
+ case PredefinedValues::NEG_ZERO:
+ return llvm::APFloat::getZero(FltSemantics, true);
+ case PredefinedValues::ONE:
+ return llvm::APFloat(FltSemantics, "1");
+ case PredefinedValues::TWO:
+ return llvm::APFloat(FltSemantics, "2");
+ case PredefinedValues::INF:
+ return llvm::APFloat::getInf(FltSemantics);
+ case PredefinedValues::QNAN:
+ return llvm::APFloat::getQNaN(FltSemantics);
+ case PredefinedValues::SMALLEST_NORM:
+ return llvm::APFloat::getSmallestNormalized(FltSemantics);
+ case PredefinedValues::LARGEST:
+ return llvm::APFloat::getLargest(FltSemantics);
+ case PredefinedValues::ULP:
+ return llvm::APFloat::getSmallest(FltSemantics);
+ case PredefinedValues::ONE_PLUS_ULP:
+ auto Output = getFloatValue(FltSemantics, PredefinedValues::ONE);
+ Output.next(false);
+ return Output;
+ }
+}
+
+llvm::APInt bitcastFloatValue(const llvm::fltSemantics &FltSemantics,
+ PredefinedValues Value) {
+ return getFloatValue(FltSemantics, Value).bitcastToAPInt();
+}
+
+} // namespace exegesis
Added: llvm/trunk/tools/llvm-exegesis/lib/RegisterValue.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/RegisterValue.h?rev=342369&view=auto
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/RegisterValue.h (added)
+++ llvm/trunk/tools/llvm-exegesis/lib/RegisterValue.h Mon Sep 17 04:09:32 2018
@@ -0,0 +1,38 @@
+//===-- RegisterValue.h -----------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+///
+/// Defines a Target independent value for a Register. This is useful to explore
+/// the influence of the instruction input values on its execution time.
+///
+//===----------------------------------------------------------------------===//
+
+#include <llvm/ADT/APFloat.h>
+
+namespace exegesis {
+
+enum class PredefinedValues {
+ POS_ZERO, // Positive zero
+ NEG_ZERO, // Negative zero
+ ONE, // 1.0
+ TWO, // 2.0
+ INF, // Infinity
+ QNAN, // Quiet NaN
+ ULP, // One Unit in the last place
+ SMALLEST = ULP, // The minimum subnormal number
+ SMALLEST_NORM, // The minimum normal number
+ LARGEST, // The maximum normal number
+ ONE_PLUS_ULP, // The value just after 1.0
+};
+
+llvm::APInt bitcastFloatValue(const llvm::fltSemantics &FltSemantics,
+ PredefinedValues Value);
+
+} // namespace exegesis
Modified: llvm/trunk/unittests/tools/llvm-exegesis/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/tools/llvm-exegesis/CMakeLists.txt?rev=342369&r1=342368&r2=342369&view=diff
==============================================================================
--- llvm/trunk/unittests/tools/llvm-exegesis/CMakeLists.txt (original)
+++ llvm/trunk/unittests/tools/llvm-exegesis/CMakeLists.txt Mon Sep 17 04:09:32 2018
@@ -15,6 +15,7 @@ add_llvm_unittest(LLVMExegesisTests
BenchmarkRunnerTest.cpp
ClusteringTest.cpp
PerfHelperTest.cpp
+ RegisterValueTest.cpp
)
target_link_libraries(LLVMExegesisTests PRIVATE LLVMExegesis)
Added: llvm/trunk/unittests/tools/llvm-exegesis/RegisterValueTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/tools/llvm-exegesis/RegisterValueTest.cpp?rev=342369&view=auto
==============================================================================
--- llvm/trunk/unittests/tools/llvm-exegesis/RegisterValueTest.cpp (added)
+++ llvm/trunk/unittests/tools/llvm-exegesis/RegisterValueTest.cpp Mon Sep 17 04:09:32 2018
@@ -0,0 +1,71 @@
+//===-- RegisterValueTest.cpp -----------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "RegisterValue.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace exegesis {
+
+namespace {
+
+#define CHECK(EXPECTED, ACTUAL) \
+ EXPECT_EQ(llvm::APInt(SizeInBits, EXPECTED, 16), \
+ bitcastFloatValue(Semantic, PredefinedValues::ACTUAL))
+
+TEST(RegisterValueTest, Half) {
+ const size_t SizeInBits = 16;
+ const auto &Semantic = llvm::APFloatBase::IEEEhalf();
+ CHECK("0000", POS_ZERO);
+ CHECK("8000", NEG_ZERO);
+ CHECK("3C00", ONE);
+ CHECK("4000", TWO);
+ CHECK("7C00", INF);
+ CHECK("7E00", QNAN);
+ CHECK("7BFF", LARGEST);
+ CHECK("0400", SMALLEST_NORM);
+ CHECK("0001", SMALLEST);
+ CHECK("0001", ULP);
+ CHECK("3C01", ONE_PLUS_ULP);
+}
+
+TEST(RegisterValueTest, Single) {
+ const size_t SizeInBits = 32;
+ const auto &Semantic = llvm::APFloatBase::IEEEsingle();
+ CHECK("00000000", POS_ZERO);
+ CHECK("80000000", NEG_ZERO);
+ CHECK("3F800000", ONE);
+ CHECK("40000000", TWO);
+ CHECK("7F800000", INF);
+ CHECK("7FC00000", QNAN);
+ CHECK("7F7FFFFF", LARGEST);
+ CHECK("00800000", SMALLEST_NORM);
+ CHECK("00000001", SMALLEST);
+ CHECK("00000001", ULP);
+ CHECK("3F800001", ONE_PLUS_ULP);
+}
+
+TEST(RegisterValueTest, Double) {
+ const size_t SizeInBits = 64;
+ const auto &Semantic = llvm::APFloatBase::IEEEdouble();
+ CHECK("0000000000000000", POS_ZERO);
+ CHECK("8000000000000000", NEG_ZERO);
+ CHECK("3FF0000000000000", ONE);
+ CHECK("4000000000000000", TWO);
+ CHECK("7FF0000000000000", INF);
+ CHECK("7FF8000000000000", QNAN);
+ CHECK("7FEFFFFFFFFFFFFF", LARGEST);
+ CHECK("0010000000000000", SMALLEST_NORM);
+ CHECK("0000000000000001", SMALLEST);
+ CHECK("0000000000000001", ULP);
+ CHECK("3FF0000000000001", ONE_PLUS_ULP);
+}
+
+} // namespace
+} // namespace exegesis
More information about the llvm-commits
mailing list