katsu560 commited on
Commit
03a5fa2
·
1 Parent(s): 793fa90

add fp16/fp32 convert intrinsics

Browse files
Files changed (1) hide show
  1. ggml.c +11 -0
ggml.c CHANGED
@@ -131,6 +131,16 @@ ggml_fp16_t ggml_fp32_to_fp16(float x) {
131
  // FP16 <-> FP32
132
  // ref: https://github.com/Maratyszcza/FP16
133
 
 
 
 
 
 
 
 
 
 
 
134
  static inline float fp32_from_bits(uint32_t w) {
135
  union {
136
  uint32_t as_bits;
@@ -196,6 +206,7 @@ ggml_fp16_t ggml_fp32_to_fp16(float f) {
196
  return (sign >> 16) | (shl1_w > UINT32_C(0xFF000000) ? UINT16_C(0x7E00) : nonsign);
197
  }
198
  #endif
 
199
 
200
  //
201
  // global data
 
131
  // FP16 <-> FP32
132
  // ref: https://github.com/Maratyszcza/FP16
133
 
134
+ #ifdef __F16C__
135
+ float ggml_fp16_to_fp32(ggml_fp16_t h) {
136
+ return _cvtsh_ss(h);
137
+ }
138
+ ggml_fp16_t ggml_fp32_to_fp16(float f) {
139
+ return _cvtss_sh(f, 0);
140
+ }
141
+
142
+ #else
143
+
144
  static inline float fp32_from_bits(uint32_t w) {
145
  union {
146
  uint32_t as_bits;
 
206
  return (sign >> 16) | (shl1_w > UINT32_C(0xFF000000) ? UINT16_C(0x7E00) : nonsign);
207
  }
208
  #endif
209
+ #endif
210
 
211
  //
212
  // global data