aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJerry Ge <jerry.ge@arm.com>2023-03-06 13:07:36 -0800
committerEric Kunze <eric.kunze@arm.com>2023-03-17 18:47:04 +0000
commitcf305dbb7f3e3be7c4e6c71174e1183eb489ec03 (patch)
treea542921c739be36ff3133a20017e500b5405cb91
parent2eb3d63318c139eda94775730878c6c2168ac148 (diff)
downloadreference_model-cf305dbb7f3e3be7c4e6c71174e1183eb489ec03.tar.gz
Refactor 1L to INT64_C()
Signed-off-by: Jerry Ge <jerry.ge@arm.com> Change-Id: If3f8c5a1f2dffac36448101959557f86b6ab6c7f
-rw-r--r--reference_model/include/debug_types.h9
-rw-r--r--reference_model/src/arith_util.h4
-rw-r--r--reference_model/src/ops/ewise_binary.cc2
-rw-r--r--reference_model/src/ops/template_types.h34
-rw-r--r--reference_model/src/quant_util.h20
5 files changed, 35 insertions, 34 deletions
diff --git a/reference_model/include/debug_types.h b/reference_model/include/debug_types.h
index bd93f19..9ff0098 100644
--- a/reference_model/include/debug_types.h
+++ b/reference_model/include/debug_types.h
@@ -1,5 +1,5 @@
-// Copyright (c) 2020, ARM Limited.
+// Copyright (c) 2020-2023, ARM Limited.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@
* Defines fundamental debugger datatypes for the functional model
*/
+#include<stdint.h>
#ifndef DEBUG_TYPES_H_
#define DEBUG_TYPES_H_
@@ -42,13 +43,13 @@ extern "C"
typedef enum func_debug_mode_e
{
DEBUG_NONE = 0x0,
-#define DEBUG_MODE(NAME, BIT) DEBUG_##NAME = (1UL << BIT),
+#define DEBUG_MODE(NAME, BIT) DEBUG_##NAME = (UINT64_C(1) << BIT),
#include "debug_modes.def"
#undef DEBUG_MODE
- DEBUG_ALL = 0xffffffffffffffffUL
+ DEBUG_ALL = UINT64_C(0xffffffffffffffff)
} func_debug_mode_e;
-#define DEBUG_INST_ALL 0xffffffffffffffffUL
+#define DEBUG_INST_ALL UINT64_C(0xffffffffffffffff)
#ifdef __cplusplus
}
diff --git a/reference_model/src/arith_util.h b/reference_model/src/arith_util.h
index 9c84a03..59bdf44 100644
--- a/reference_model/src/arith_util.h
+++ b/reference_model/src/arith_util.h
@@ -1,5 +1,5 @@
-// Copyright (c) 2020, ARM Limited.
+// Copyright (c) 2020-2023, ARM Limited.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -105,7 +105,7 @@ inline size_t _count_leading_ones(T val)
#define DIV_CEIL(a, b) ((a) % (b) ? ((a) / (b) + 1) : ((a) / (b)))
// Returns a mask of 1's of this size
-#define ONES_MASK(SIZE) ((uint64_t)((SIZE) >= 64 ? 0xffffffffffffffffULL : ((uint64_t)(1) << (SIZE)) - 1))
+#define ONES_MASK(SIZE) ((uint64_t)((SIZE) >= 64 ? UINT64_C(0xffffffffffffffff) : (UINT64_C(1) << (SIZE)) - 1))
// Returns a field of bits from HIGH_BIT to LOW_BIT, right-shifted
// include both side, equivalent VAL[LOW_BIT:HIGH_BIT] in verilog
diff --git a/reference_model/src/ops/ewise_binary.cc b/reference_model/src/ops/ewise_binary.cc
index c697db0..16386af 100644
--- a/reference_model/src/ops/ewise_binary.cc
+++ b/reference_model/src/ops/ewise_binary.cc
@@ -434,7 +434,7 @@ int OpMul<Rank, InDtype, OutDtype>::register_fcn()
int64_t result;
if (shift > 0)
{
- int64_t round = 1L << (shift - 1);
+ int64_t round = INT64_C(1) << (shift - 1);
result = static_cast<int64_t>(a) * static_cast<int64_t>(b) + round;
result = result >> shift;
diff --git a/reference_model/src/ops/template_types.h b/reference_model/src/ops/template_types.h
index 6b28502..ece14b1 100644
--- a/reference_model/src/ops/template_types.h
+++ b/reference_model/src/ops/template_types.h
@@ -1,5 +1,5 @@
-// Copyright (c) 2020-2022, ARM Limited.
+// Copyright (c) 2020-2023, ARM Limited.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -196,83 +196,83 @@ struct GetNumBits<DType_FP16>
template <DType T>
struct GetQMin
{
- static constexpr int64_t value = 0L;
+ static constexpr int64_t value = INT64_C(0);
};
template <>
struct GetQMin<DType_UINT8>
{
- static constexpr int64_t value = 0L;
+ static constexpr int64_t value = INT64_C(0);
};
template <>
struct GetQMin<DType_UINT16>
{
- static constexpr int64_t value = 0L;
+ static constexpr int64_t value = INT64_C(0);
};
template <>
struct GetQMin<DType_INT4>
{
- static constexpr int64_t value = -8L;
+ static constexpr int64_t value = INT64_C(-8);
};
template <>
struct GetQMin<DType_INT8>
{
- static constexpr int64_t value = -128L;
+ static constexpr int64_t value = INT64_C(-128);
};
template <>
struct GetQMin<DType_INT16>
{
- static constexpr int64_t value = -32768L;
+ static constexpr int64_t value = INT64_C(-32768);
};
template <>
struct GetQMin<DType_INT32>
{
- static constexpr int64_t value = -(1L << 31);
+ static constexpr int64_t value = -(INT64_C(1) << 31);
};
template <>
struct GetQMin<DType_INT48>
{
- static constexpr int64_t value = -(1L << 47);
+ static constexpr int64_t value = -(INT64_C(1) << 47);
};
template <DType T>
struct GetQMax
{
- static constexpr int64_t value = 0L;
+ static constexpr int64_t value = INT64_C(0);
};
template <>
struct GetQMax<DType_UINT8>
{
- static constexpr int64_t value = 255L;
+ static constexpr int64_t value = INT64_C(255);
};
template <>
struct GetQMax<DType_UINT16>
{
- static constexpr int64_t value = 65535L;
+ static constexpr int64_t value = INT64_C(65535);
};
template <>
struct GetQMax<DType_INT4>
{
- static constexpr int64_t value = 7L;
+ static constexpr int64_t value = INT64_C(7);
};
template <>
struct GetQMax<DType_INT8>
{
- static constexpr int64_t value = 127L;
+ static constexpr int64_t value = INT64_C(127);
};
template <>
struct GetQMax<DType_INT16>
{
- static constexpr int64_t value = 32767L;
+ static constexpr int64_t value = INT64_C(32767);
};
template <>
struct GetQMax<DType_INT32>
{
- static constexpr int64_t value = (1L << 31) - 1;
+ static constexpr int64_t value = (INT64_C(1) << 31) - 1;
};
template <>
struct GetQMax<DType_INT48>
{
- static constexpr int64_t value = (1L << 47) - 1;
+ static constexpr int64_t value = (INT64_C(1) << 47) - 1;
};
}; // namespace TosaReference
diff --git a/reference_model/src/quant_util.h b/reference_model/src/quant_util.h
index 2e5c2e5..a264965 100644
--- a/reference_model/src/quant_util.h
+++ b/reference_model/src/quant_util.h
@@ -1,5 +1,5 @@
-// Copyright (c) 2020-2021, ARM Limited.
+// Copyright (c) 2020-2023, ARM Limited.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -37,7 +37,7 @@ public:
ASSERT_MSG(value > 0, "AvgPool2d reciprocal_scale() error: # of elements should be > 1 but is %d", value);
uint32_t value_u32 = (uint32_t)value;
int32_t k = 32 - LEADING_ZEROS_32(value_u32 - 1); // (1<<k)/2 < value <= (1<<k)
- int64_t numerator = ((1L << 30) + 1) << k;
+ int64_t numerator = ((INT64_C(1) << 30) + 1) << k;
multiplier = numerator / value; // (1<<30) <= multiplier < (1<<31)
shift = 30 + k;
}
@@ -55,8 +55,8 @@ public:
"apply_scale_32(): shift value should stay within [2, 62] but is " + std::to_string(shift);
throw desc;
}
- int64_t low_val = -1L << (shift - 1);
- int64_t high_val = 1L << (shift - 1);
+ int64_t low_val = INT64_C(-1) << (shift - 1);
+ int64_t high_val = INT64_C(1) << (shift - 1);
if (value < low_val || value >= high_val)
{
std::string desc = "apply_scale_32(): value should stay within [" + std::to_string(low_val) + ", " +
@@ -64,17 +64,17 @@ public:
std::to_string(shift);
throw desc;
}
- int64_t round = 1L << (shift - 1);
+ int64_t round = INT64_C(1) << (shift - 1);
if (double_round)
{
if (shift > 31 && value >= 0)
- round += (1L << 30);
+ round += (INT64_C(1) << 30);
if (shift > 31 && value < 0)
- round -= (1L << 30);
+ round -= (INT64_C(1) << 30);
}
int64_t result = (int64_t)value * multiplier + round;
result = result >> shift;
- if (result < -(1L << 31) || result >= (1L << 31))
+ if (result < -(INT64_C(1) << 31) || result >= (INT64_C(1) << 31))
{
std::string desc = "apply_scale_32() error: scaled result exceeds int32 numeric range";
throw desc;
@@ -95,10 +95,10 @@ public:
"apply_scale_16(): shift value should stay within [2, 62] but is " + std::to_string(shift);
throw desc;
}
- int64_t round = 1L << (shift - 1);
+ int64_t round = INT64_C(1) << (shift - 1);
int64_t result = value * (int64_t)multiplier + round;
result = result >> shift;
- if (result < -(1L << 31) || result >= (1L << 31))
+ if (result < -(INT64_C(1) << 31) || result >= (INT64_C(1) << 31))
{
std::string desc = "apply_scale_16() error: scaled result exceeds int32 numeric range";
throw desc;