Add HVX IEEE floating-point conversion instructions:
- vconv_hf_h, vconv_h_hf, vconv_sf_w, vconv_w_sf: vconv operations
- vcvt_hf_sf, vcvt_sf_hf: float <-> half float conversions
- vcvt_hf_b, vcvt_hf_h, vcvt_hf_ub, vcvt_hf_uh: int to half float
- vcvt_b_hf, vcvt_h_hf, vcvt_ub_hf, vcvt_uh_hf: half float to int
Signed-off-by: Matheus Tavares Bernardino <matheus.bernardino@oss.qualcomm.com>
---
target/hexagon/mmvec/kvx_ieee.h | 21 +++++
target/hexagon/mmvec/kvx_ieee.c | 98 ++++++++++++++++++++
target/hexagon/imported/mmvec/encode_ext.def | 18 ++++
target/hexagon/imported/mmvec/ext.idef | 97 +++++++++++++++++++
4 files changed, 234 insertions(+)
diff --git a/target/hexagon/mmvec/kvx_ieee.c b/target/hexagon/mmvec/kvx_ieee.c
index 33621a15f3..bbeec09707 100644
--- a/target/hexagon/mmvec/kvx_ieee.c
+++ b/target/hexagon/mmvec/kvx_ieee.c
@@ -131,3 +131,101 @@ uint16_t qf_min_hf(uint16_t a1, uint16_t a2, float_status *fp_status)
if (float16_is_pos_nan(f2) || float16_is_neg_nan(f1)) return a1;
return fp_min_hf(a1, a2, fp_status);
}
+
+uint16_t f32_to_f16(uint32_t a, float_status *fp_status)
+{
+ return float16_val(float32_to_float16(make_float32(a), true, fp_status));
+}
+
+uint32_t f16_to_f32(uint16_t a, float_status *fp_status)
+{
+ return float32_val(float16_to_float32(make_float16(a), true, fp_status));
+}
+
+uint16_t f16_to_uh(uint16_t op1, float_status *fp_status)
+{
+ return float16_to_uint16_scalbn(make_float16(op1),
+ float_round_nearest_even,
Does HVX always use this rounding mode? The scalar core uses the rounding mode in USR.
There are several more instances below.
+ 0, fp_status);
+}
+
+int16_t f16_to_h(uint16_t op1, float_status *fp_status)
+{
+ return float16_to_int16_scalbn(make_float16(op1),
+ float_round_nearest_even,
+ 0, fp_status);
+}
+
+uint8_t f16_to_ub(uint16_t op1, float_status *fp_status)
+{
+ return float16_to_uint8_scalbn(make_float16(op1),
+ float_round_nearest_even,
+ 0, fp_status);
+}
+
+int8_t f16_to_b(uint16_t op1, float_status *fp_status)
+{
+ return float16_to_int8_scalbn(make_float16(op1),
+ float_round_nearest_even,
+ 0, fp_status);
+}
+
+uint16_t uh_to_f16(uint16_t op1)
+{
+ return uint64_to_float16_scalbn(op1, float_round_nearest_even, 0);
+}
+
+uint16_t h_to_f16(int16_t op1)
+{
+ return int64_to_float16_scalbn(op1, float_round_nearest_even, 0);
+}
+
+uint16_t ub_to_f16(uint8_t op1)
+{
+ return uint64_to_float16_scalbn(op1, float_round_nearest_even, 0);
+}
+
+uint16_t b_to_f16(int8_t op1)
+{
+ return int64_to_float16_scalbn(op1, float_round_nearest_even, 0);
+}
+
+int32_t conv_sf_w(int32_t a, float_status *fp_status)
+{
+ return float32_val(int32_to_float32(a, fp_status));
+}
+
+int16_t conv_hf_h(int16_t a, float_status *fp_status)
+{
+ return float16_val(int16_to_float16(a, fp_status));
+}
+
+int32_t conv_w_sf(uint32_t a, float_status *fp_status)
+{
+ float_status scratch_fpst = {};
+ const float32 W_MAX = int32_to_float32(INT32_MAX, &scratch_fpst);
+ const float32 W_MIN = int32_to_float32(INT32_MIN, &scratch_fpst);
+ float32 f1 = make_float32(a);
+
+ if (float32_is_any_nan(f1) || float32_is_infinity(f1) ||
+ float32_le_quiet(W_MAX, f1, fp_status) ||
+ float32_le_quiet(f1, W_MIN, fp_status)) {
+ return float32_is_neg(f1) ? INT32_MIN : INT32_MAX;
+ }
Does float32_to_int32 handle these checks?
+ return float32_to_int32_round_to_zero(f1, fp_status);
Rounding mode?
+}
+
+int16_t conv_h_hf(uint16_t a, float_status *fp_status)
+{/
+ float_status scratch_fpst = {};
+ const float16 H_MAX = int16_to_float16(INT16_MAX, &scratch_fpst);
+ const float16 H_MIN = int16_to_float16(INT16_MIN, &scratch_fpst);
+ float16 f1 = make_float16(a);
+
+ if (float16_is_any_nan(f1) || float16_is_infinity(f1) ||
+ float16_le_quiet(H_MAX, f1, fp_status) ||
+ float16_le_quiet(f1, H_MIN, fp_status)) {
+ return float16_is_neg(f1) ? INT16_MIN : INT16_MAX;
+ }
+ return float16_to_int16_round_to_zero(f1, fp_status);
+}
Ditto
Thanks,
Taylor