Skip to content

Commit

Permalink
add fp16/fp32 convert intrinsics
Browse files Browse the repository at this point in the history
  • Loading branch information
katsu560 authored and ggerganov committed Dec 6, 2022
1 parent 9fe7306 commit 35b40a9
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions ggml.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,16 @@ ggml_fp16_t ggml_fp32_to_fp16(float x) {
// FP16 <-> FP32
// ref: https://github.com/Maratyszcza/FP16

#ifdef __F16C__
float ggml_fp16_to_fp32(ggml_fp16_t h) {
return _cvtsh_ss(h);
}
ggml_fp16_t ggml_fp32_to_fp16(float f) {
return _cvtss_sh(f, 0);
}

#else

static inline float fp32_from_bits(uint32_t w) {
union {
uint32_t as_bits;
Expand Down Expand Up @@ -196,6 +206,7 @@ ggml_fp16_t ggml_fp32_to_fp16(float f) {
return (sign >> 16) | (shl1_w > UINT32_C(0xFF000000) ? UINT16_C(0x7E00) : nonsign);
}
#endif
#endif

//
// global data
Expand Down

0 comments on commit 35b40a9

Please sign in to comment.