File: remove_math_h_dependency_from_fp16_h.patch

package info (click to toggle)
onnxruntime 1.21.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 333,732 kB
  • sloc: cpp: 3,153,079; python: 179,219; ansic: 109,131; asm: 37,791; cs: 34,424; perl: 13,070; java: 11,047; javascript: 6,330; pascal: 4,126; sh: 3,277; xml: 598; objc: 281; makefile: 59
file content (29 lines) | stat: -rw-r--r-- 932 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
diff --git a/include/fp16/fp16.h b/include/fp16/fp16.h
index 2b61fff..1947805 100644
--- a/include/fp16/fp16.h
+++ b/include/fp16/fp16.h
@@ -4,10 +4,8 @@
 
 #if defined(__cplusplus) && (__cplusplus >= 201103L)
 	#include <cstdint>
-	#include <cmath>
 #elif !defined(__OPENCL_VERSION__)
 	#include <stdint.h>
-	#include <math.h>
 #endif
 
 #ifdef _MSC_VER
@@ -228,9 +226,11 @@ static inline uint16_t fp16_ieee_from_fp32_value(float f) {
 	const float scale_to_inf = fp32_from_bits(UINT32_C(0x77800000));
 	const float scale_to_zero = fp32_from_bits(UINT32_C(0x08800000));
 #endif
-	float base = (fabsf(f) * scale_to_inf) * scale_to_zero;
-
 	const uint32_t w = fp32_to_bits(f);
+	const float abs_f = fp32_from_bits(w & UINT32_C(0x7FFFFFFF));
+
+	float base = (abs_f * scale_to_inf) * scale_to_zero;
+
 	const uint32_t shl1_w = w + w;
 	const uint32_t sign = w & UINT32_C(0x80000000);
 	uint32_t bias = shl1_w & UINT32_C(0xFF000000);