99#include < math.h>
1010#include < algorithm>
1111#include < cstring>
12+ #include < limits>
1213#include < numeric>
1314
1415namespace impl {
@@ -17,8 +18,7 @@ namespace kernels {
1718
1819// Quantize a fp32 value to an int8_t/uint8_t value
1920template <typename T>
20- __attribute__ ((always_inline)) T
21- quantize (const float x, float scale, int32_t zero_point) {
21+ T quantize (const float x, float scale, int32_t zero_point) {
2222 constexpr float min_val = std::numeric_limits<T>::min ();
2323 constexpr float max_val = std::numeric_limits<T>::max ();
2424 float tmp = roundf (x * scale + zero_point);
@@ -40,8 +40,7 @@ void quantize(
4040
4141// Dequantize an int8_t/uint8_t value to an fp32 value
4242template <typename T>
43- __attribute__ ((always_inline)) float
44- dequantize (const T x, float scale, int32_t zero_point) {
43+ float dequantize (const T x, float scale, int32_t zero_point) {
4544 return scale * (x - zero_point);
4645}
4746
@@ -60,9 +59,8 @@ void dequantize(
6059
6160// explicit template instantiation
6261
63- #define typed_quantize_val (dtype ) \
64- template __attribute__((always_inline)) dtype quantize ( \
65- const float x, float inv_scale, int32_t zero_point);
62+ #define typed_quantize_val (dtype ) \
63+ template dtype quantize (const float x, float inv_scale, int32_t zero_point);
6664typed_quantize_val (int8_t );
6765typed_quantize_val (uint8_t );
6866typed_quantize_val (int16_t );
@@ -82,9 +80,8 @@ typed_quantize_vec(int16_t);
8280typed_quantize_vec (int32_t );
8381#undef typed_quantize_vec
8482
85- #define typed_dequantize_val (dtype ) \
86- template __attribute__((always_inline)) float dequantize ( \
87- const dtype x, float scale, int32_t zero_point);
83+ #define typed_dequantize_val (dtype ) \
84+ template float dequantize (const dtype x, float scale, int32_t zero_point);
8885typed_dequantize_val (int8_t );
8986typed_dequantize_val (uint8_t );
9087typed_dequantize_val (int16_t );
0 commit comments