target/arm: Implement ARMv8.5-FRINT
cover target/arm: Implement ARMv8.5-FRINT
Based-on: the ARMv8.2-FHM patch set, although I don't know that this is an actual dependency; it's just the tree I started with.
There is not yet support for this extension within FVP, so I've self-tested it against my own understanding of what is supposed to go on with the file below.
r~
Richard Henderson (2):
target/arm: Restructure handle_fp_1src_{single,double} target/arm: Implement ARMv8.5-FRINT
target/arm/cpu.h | 5 ++ target/arm/helper.h | 5 ++ target/arm/cpu64.c | 1 + target/arm/translate-a64.c | 161 ++++++++++++++++++++++++++----------- target/arm/vfp_helper.c | 96 ++++++++++++++++++++++ 5 files changed, 222 insertions(+), 46 deletions(-)
Signature · 119 lines
#include <stdio.h>
#include <limits.h>
asm(".arch armv8.5-a");
static const float f32_i32_z[][2] = {
{ 0, 0 },
{ -0.0, -0.0 },
{ 0.9, 0.0 },
{ 1.0, 1.0 },
{ 1.1, 1.0 },
{ 1.9, 1.0 },
{ 0x1.fffffep30, 0x1.fffffep30 }, /* 2^31 - epsilon */
{ -0x1p31, -0x1.0p31 }, /* -2^31 = INT32_MIN */
{ 0x1.0p31, -0x1.0p31 }, /* overflow */
{ 0x1.0p32, -0x1.0p31 }, /* overflow */
{ -0x1.0p32, -0x1.0p31 }, /* overflow */
{ __builtin_inf(), -0x1.0p31 }, /* overflow */
};
static const double f64_i32_z[][2] = {
{ 0, 0 },
{ -0.0, -0.0 },
{ 0.9, 0.0 },
{ 1.0, 1.0 },
{ 1.1, 1.0 },
{ 1.9, 1.0 },
{ 2147483647, 2147483647 }, /* 2^31 - 1 = INT32_MAX */
{ -0x1p31, -0x1.0p31 }, /* -2^31 = INT32_MIN */
{ 0x1.0p31, -0x1.0p31 }, /* overflow */
{ 0x1.0p32, -0x1.0p31 }, /* overflow */
{ -0x1.0p32, -0x1.0p31 }, /* overflow */
{ __builtin_inf(), -0x1.0p31 }, /* overflow */
};
static const float f32_i64_z[][2] = {
{ 0, 0 },
{ -0.0, -0.0 },
{ 0.9, 0.0 },
{ 1.0, 1.0 },
{ 1.1, 1.0 },
{ 1.9, 1.0 },
{ 0x1.fffffep30, 0x1.fffffep30 }, /* 2^31 - epsilon */
{ -0x1p31, -0x1.0p31 }, /* -2^31 = INT32_MIN */
{ 0x1.0p31, 0x1.0p31 },
{ 0x1.0p32, 0x1.0p32 },
{ -0x1.0p32, -0x1.0p32 },
{ 0x1.0p62, 0x1.0p62 },
{ 0x1.fffffep62, 0x1.fffffep62 }, /* 2^63 - epsilon */
{ -0x1.0p63, -0x1.0p63 }, /* -2^63 = INT64_MIN */
{ 0x1.0p63, -0x1.0p63 }, /* overflow */
{ 0x1.0p64, -0x1.0p63 }, /* overflow */
{ -0x1.0p64, -0x1.0p63 }, /* overflow */
{ __builtin_inf(), -0x1.0p63 }, /* overflow */
};
static const double f64_i64_z[][2] = {
{ 0, 0 },
{ -0.0, -0.0 },
{ 0.9, 0.0 },
{ 1.0, 1.0 },
{ 1.1, 1.0 },
{ 1.9, 1.0 },
{ 2147483647, 2147483647 }, /* 2^31 - 1 = INT32_MAX */
{ -0x1p31, -0x1.0p31 }, /* -2^31 = INT32_MIN */
{ 0x1.0p31, 0x1.0p31 },
{ 0x1.0p32, 0x1.0p32 },
{ -0x1.0p32, -0x1.0p32 },
{ 0x1.0p62, 0x1.0p62 },
{ 0x1.fffffffffffffp62, 0x1.fffffffffffffp62 }, /* 2^63 - epsilon */
{ -0x1.0p63, -0x1.0p63 }, /* -2^63 = INT64_MIN */
{ 0x1.0p63, -0x1.0p63 }, /* overflow */
{ 0x1.0p64, -0x1.0p63 }, /* overflow */
{ -0x1.0p64, -0x1.0p63 }, /* overflow */
{ __builtin_inf(), -0x1.0p63 }, /* overflow */
};
int main()
{
int i;
for (i = 0; i < sizeof(f32_i32_z)/sizeof(f32_i32_z[0]); i++) {
float x;
asm("frint32z %s0,%s1" : "=w"(x) : "w"(f32_i32_z[i][0]));
if (x != f32_i32_z[i][1]) {
printf("%-2d: frint(%a) -> %a != %a\n",
i, f32_i32_z[i][0], x, f32_i32_z[i][1]);
}
}
for (i = 0; i < sizeof(f32_i64_z)/sizeof(f32_i64_z[0]); i++) {
float x;
asm("frint64z %s0,%s1" : "=w"(x) : "w"(f32_i64_z[i][0]));
if (x != f32_i64_z[i][1]) {
printf("%-2d: frint(%a) -> %a != %a\n",
i, f32_i64_z[i][0], x, f32_i64_z[i][1]);
}
}
for (i = 0; i < sizeof(f64_i32_z)/sizeof(f64_i32_z[0]); i++) {
double x;
asm("frint32z %d0,%d1" : "=w"(x) : "w"(f64_i32_z[i][0]));
if (x != f64_i32_z[i][1]) {
printf("%-2d: frint(%a) -> %a != %a\n",
i, f64_i32_z[i][0], x, f64_i32_z[i][1]);
}
}
for (i = 0; i < sizeof(f64_i64_z)/sizeof(f64_i64_z[0]); i++) {
double x;
asm("frint64z %d0,%d1" : "=w"(x) : "w"(f64_i64_z[i][0]));
if (x != f64_i64_z[i][1]) {
printf("%-2d: frint(%a) -> %a != %a\n",
i, f64_i64_z[i][0], x, f64_i64_z[i][1]);
}
}
return 0;
}PATCH 1/2 target/arm: Restructure handle_fp_1src_{single, double}
This will allow sharing code that adjusts rmode beyond the existing users.
--- target/arm/translate-a64.c | 90 +++++++++++++++++++++----------------- 1 file changed, 49 insertions(+), 41 deletions(-)
target/arm/translate-a64.c +49 -41
@@ -5505,55 +5505,59 @@ static void handle_fp_1src_half(DisasContext *s, int opcode, int rd, int rn)/* Floating-point data-processing (1 source) - single precision */ static void handle_fp_1src_single (DisasContext *s,int opcode,int rd,int rn) { +void (*gen_fpst)(TCGv_i32 ,TCGv_i32 ,TCGv_ptr ); +TCGv_i32 tcg_op, tcg_res;TCGv_ptr fpst; -TCGv_i32 tcg_op; -TCGv_i32 tcg_res; +int rmode =-1 ; - fpst =get_fpstatus_ptr (false); tcg_op =read_fp_sreg (s, rn); tcg_res =tcg_temp_new_i32 ();switch (opcode) {case 0x0 :/* FMOV */ tcg_gen_mov_i32 (tcg_res, tcg_op); -break ; + goto done;case 0x1 :/* FABS */ gen_helper_vfp_abss (tcg_res, tcg_op); -break ; + goto done;case 0x2 :/* FNEG */ gen_helper_vfp_negs (tcg_res, tcg_op); -break ; + goto done;case 0x3 :/* FSQRT */ gen_helper_vfp_sqrts (tcg_res, tcg_op, cpu_env); -break ; + goto done;case 0x8 :/* FRINTN */ case 0x9 :/* FRINTP */ case 0xa :/* FRINTM */ case 0xb :/* FRINTZ */ case 0xc :/* FRINTA */ - { -TCGv_i32 tcg_rmode =tcg_const_i32 (arm_rmode_to_sf (opcode &7 )); - -gen_helper_set_rmode (tcg_rmode, tcg_rmode, fpst); -gen_helper_rints (tcg_res, tcg_op, fpst); - -gen_helper_set_rmode (tcg_rmode, tcg_rmode, fpst); -tcg_temp_free_i32 (tcg_rmode); + rmode =arm_rmode_to_sf (opcode &7 ); + gen_fpst = gen_helper_rints;break ; - }case 0xe :/* FRINTX */ -gen_helper_rints_exact (tcg_res, tcg_op, fpst); + gen_fpst = gen_helper_rints_exact;break ;case 0xf :/* FRINTI */ -gen_helper_rints (tcg_res, tcg_op, fpst); + gen_fpst = gen_helper_rints;break ;default : -abort (); +g_assert_not_reached (); } -write_fp_sreg (s, rd, tcg_res); - + fpst =get_fpstatus_ptr (false); +if (rmode >=0 ) { +TCGv_i32 tcg_rmode =tcg_const_i32 (rmode); +gen_helper_set_rmode (tcg_rmode, tcg_rmode, fpst); +gen_fpst (tcg_res, tcg_op, fpst); +gen_helper_set_rmode (tcg_rmode, tcg_rmode, fpst); +tcg_temp_free_i32 (tcg_rmode); + }else { +gen_fpst (tcg_res, tcg_op, fpst); + }tcg_temp_free_ptr (fpst); + + done: +write_fp_sreg (s, rd, tcg_res);tcg_temp_free_i32 (tcg_op);tcg_temp_free_i32 (tcg_res); }
@@ -5561,9 +5565,10 @@ static void handle_fp_1src_single(DisasContext *s, int opcode, int rd, int rn)/* Floating-point data-processing (1 source) - double precision */ static void handle_fp_1src_double (DisasContext *s,int opcode,int rd,int rn) { +void (*gen_fpst)(TCGv_i64 ,TCGv_i64 ,TCGv_ptr ); +TCGv_i64 tcg_op, tcg_res;TCGv_ptr fpst; -TCGv_i64 tcg_op; -TCGv_i64 tcg_res; +int rmode =-1 ;switch (opcode) {case 0x0 :/* FMOV */
@@ -5571,48 +5576,51 @@ static void handle_fp_1src_double(DisasContext *s, int opcode, int rd, int rn)return ; } - fpst =get_fpstatus_ptr (false); tcg_op =read_fp_dreg (s, rn); tcg_res =tcg_temp_new_i64 ();switch (opcode) {case 0x1 :/* FABS */ gen_helper_vfp_absd (tcg_res, tcg_op); -break ; + goto done;case 0x2 :/* FNEG */ gen_helper_vfp_negd (tcg_res, tcg_op); -break ; + goto done;case 0x3 :/* FSQRT */ gen_helper_vfp_sqrtd (tcg_res, tcg_op, cpu_env); -break ; + goto done;case 0x8 :/* FRINTN */ case 0x9 :/* FRINTP */ case 0xa :/* FRINTM */ case 0xb :/* FRINTZ */ case 0xc :/* FRINTA */ - { -TCGv_i32 tcg_rmode =tcg_const_i32 (arm_rmode_to_sf (opcode &7 )); - -gen_helper_set_rmode (tcg_rmode, tcg_rmode, fpst); -gen_helper_rintd (tcg_res, tcg_op, fpst); - -gen_helper_set_rmode (tcg_rmode, tcg_rmode, fpst); -tcg_temp_free_i32 (tcg_rmode); + rmode =arm_rmode_to_sf (opcode &7 ); + gen_fpst = gen_helper_rintd;break ; - }case 0xe :/* FRINTX */ -gen_helper_rintd_exact (tcg_res, tcg_op, fpst); + gen_fpst = gen_helper_rintd_exact;break ;case 0xf :/* FRINTI */ -gen_helper_rintd (tcg_res, tcg_op, fpst); + gen_fpst = gen_helper_rintd;break ;default : -abort (); +g_assert_not_reached (); } -write_fp_dreg (s, rd, tcg_res); - + fpst =get_fpstatus_ptr (false); +if (rmode >=0 ) { +TCGv_i32 tcg_rmode =tcg_const_i32 (rmode); +gen_helper_set_rmode (tcg_rmode, tcg_rmode, fpst); +gen_fpst (tcg_res, tcg_op, fpst); +gen_helper_set_rmode (tcg_rmode, tcg_rmode, fpst); +tcg_temp_free_i32 (tcg_rmode); + }else { +gen_fpst (tcg_res, tcg_op, fpst); + }tcg_temp_free_ptr (fpst); + + done: +write_fp_dreg (s, rd, tcg_res);tcg_temp_free_i64 (tcg_op);tcg_temp_free_i64 (tcg_res); }
Signature · 1 line
2.17.1
PATCH 2/2 target/arm: Implement ARMv8.5-FRINT
In reply to Richard Henderson--- target/arm/cpu.h | 5 ++ target/arm/helper.h | 5 ++ target/arm/cpu64.c | 1 + target/arm/translate-a64.c | 71 ++++++++++++++++++++++++++-- target/arm/vfp_helper.c | 96 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 173 insertions(+), 5 deletions(-)
target/arm/cpu.h +5 -0
@@ -3391,6 +3391,11 @@ static inline bool isar_feature_aa64_pauth(const ARMISARegisters *id) FIELD_DP64(0, ID_AA64ISAR1, GPI, 0xf))) != 0; } +static inline bool isar_feature_aa64_frint (const ARMISARegisters *id) +{ +return FIELD_EX64 (id->id_aa64isar1,ID_AA64ISAR1 ,FRINTTS ) !=0 ; +} +static inline bool isar_feature_aa64_fp16 (const ARMISARegisters *id) {/* We always set the AdvSIMD and FP fields identically wrt FP16. */
target/arm/helper.h +5 -0
@@ -686,6 +686,11 @@ DEF_HELPER_FLAGS_5(gvec_fmlal_idx_a32, TCG_CALL_NO_RWG,DEF_HELPER_FLAGS_5 (gvec_fmlal_idx_a64,TCG_CALL_NO_RWG , void, ptr, ptr, ptr, ptr, i32) +DEF_HELPER_FLAGS_2(frint32_s, TCG_CALL_NO_RWG, f32, f32, ptr) +DEF_HELPER_FLAGS_2(frint64_s, TCG_CALL_NO_RWG, f32, f32, ptr) +DEF_HELPER_FLAGS_2(frint32_d, TCG_CALL_NO_RWG, f64, f64, ptr) +DEF_HELPER_FLAGS_2(frint64_d, TCG_CALL_NO_RWG, f64, f64, ptr) +#ifdef TARGET_AARCH64 #include "helper-a64.h" #include "helper-sve.h"
target/arm/cpu64.c +1 -0
@@ -318,6 +318,7 @@ static void aarch64_max_initfn(Object *obj) t =FIELD_DP64 (t,ID_AA64ISAR1 ,API ,0 ); t =FIELD_DP64 (t,ID_AA64ISAR1 ,GPA ,1 ); t =FIELD_DP64 (t,ID_AA64ISAR1 ,GPI ,0 ); + t =FIELD_DP64 (t,ID_AA64ISAR1 ,FRINTTS ,1 ); cpu->isar.id_aa64isar1 = t; t = cpu->isar.id_aa64pfr0;
target/arm/translate-a64.c +66 -5
137 lines not on this page · raw message
target/arm/vfp_helper.c +96 -0
99 lines not on this page · raw message
Signature · 1 line
2.17.1
Hi Richard,
Quoted 7 lines · Richard Henderson
Based-on: the ARMv8.2-FHM patch set, although I don't know that this is an actual dependency; it's just the tree I started with.
There is not yet support for this extension within FVP, so I've self-tested it against my own understanding of what is supposed to go on with the file below.
I ran some tests and found no issue. Your understanding looks correct :-)
Thanks,
Laurent
Quoted 137 lines
r~
Richard Henderson (2):
target/arm: Restructure handle_fp_1src_{single,double} target/arm: Implement ARMv8.5-FRINTtarget/arm/cpu.h | 5 ++ target/arm/helper.h | 5 ++ target/arm/cpu64.c | 1 + target/arm/translate-a64.c | 161 ++++++++++++++++++++++++++----------- target/arm/vfp_helper.c | 96 ++++++++++++++++++++++ 5 files changed, 222 insertions(+), 46 deletions(-)--
#include <
stdio.h>
#include <limits.h>
asm(".arch armv8.5-a");static const float f32_i32_z[][2] = { { 0, 0 }, { -0.0, -0.0 }, { 0.9, 0.0 }, { 1.0, 1.0 }, { 1.1, 1.0 }, { 1.9, 1.0 }, { 0x1.fffffep30, 0x1.fffffep30 }, /* 2^31 - epsilon */ { -0x1p31, -0x1.0p31 }, /* -2^31 = INT32_MIN */ { 0x1.0p31, -0x1.0p31 }, /* overflow */ { 0x1.0p32, -0x1.0p31 }, /* overflow */ { -0x1.0p32, -0x1.0p31 }, /* overflow */ { __builtin_inf(), -0x1.0p31 }, /* overflow */ };static const double f64_i32_z[][2] = { { 0, 0 }, { -0.0, -0.0 }, { 0.9, 0.0 }, { 1.0, 1.0 }, { 1.1, 1.0 }, { 1.9, 1.0 }, { 2147483647, 2147483647 }, /* 2^31 - 1 = INT32_MAX */ { -0x1p31, -0x1.0p31 }, /* -2^31 = INT32_MIN */ { 0x1.0p31, -0x1.0p31 }, /* overflow */ { 0x1.0p32, -0x1.0p31 }, /* overflow */ { -0x1.0p32, -0x1.0p31 }, /* overflow */ { __builtin_inf(), -0x1.0p31 }, /* overflow */ };static const float f32_i64_z[][2] = { { 0, 0 }, { -0.0, -0.0 }, { 0.9, 0.0 }, { 1.0, 1.0 }, { 1.1, 1.0 }, { 1.9, 1.0 }, { 0x1.fffffep30, 0x1.fffffep30 }, /* 2^31 - epsilon */ { -0x1p31, -0x1.0p31 }, /* -2^31 = INT32_MIN */ { 0x1.0p31, 0x1.0p31 }, { 0x1.0p32, 0x1.0p32 }, { -0x1.0p32, -0x1.0p32 }, { 0x1.0p62, 0x1.0p62 }, { 0x1.fffffep62, 0x1.fffffep62 }, /* 2^63 - epsilon */ { -0x1.0p63, -0x1.0p63 }, /* -2^63 = INT64_MIN */ { 0x1.0p63, -0x1.0p63 }, /* overflow */ { 0x1.0p64, -0x1.0p63 }, /* overflow */ { -0x1.0p64, -0x1.0p63 }, /* overflow */ { __builtin_inf(), -0x1.0p63 }, /* overflow */ };static const double f64_i64_z[][2] = { { 0, 0 }, { -0.0, -0.0 }, { 0.9, 0.0 }, { 1.0, 1.0 }, { 1.1, 1.0 }, { 1.9, 1.0 }, { 2147483647, 2147483647 }, /* 2^31 - 1 = INT32_MAX */ { -0x1p31, -0x1.0p31 }, /* -2^31 = INT32_MIN */ { 0x1.0p31, 0x1.0p31 }, { 0x1.0p32, 0x1.0p32 }, { -0x1.0p32, -0x1.0p32 }, { 0x1.0p62, 0x1.0p62 }, { 0x1.fffffffffffffp62, 0x1.fffffffffffffp62 }, /* 2^63 - epsilon */ { -0x1.0p63, -0x1.0p63 }, /* -2^63 = INT64_MIN */ { 0x1.0p63, -0x1.0p63 }, /* overflow */ { 0x1.0p64, -0x1.0p63 }, /* overflow */ { -0x1.0p64, -0x1.0p63 }, /* overflow */ { __builtin_inf(), -0x1.0p63 }, /* overflow */ };int
main(){ int i; for (i = 0; i < sizeof(f32_i32_z)/sizeof(f32_i32_z[0]); i++) { float x; asm("frint32z %s0,%s1" : "=w"(x) : "w"(f32_i32_z[i][0])); if (x != f32_i32_z[i][1]) { printf("%-2d: frint(%a) -> %a != %a\n", i, f32_i32_z[i][0], x, f32_i32_z[i][1]); } } for (i = 0; i < sizeof(f32_i64_z)/sizeof(f32_i64_z[0]); i++) { float x; asm("frint64z %s0,%s1" : "=w"(x) : "w"(f32_i64_z[i][0])); if (x != f32_i64_z[i][1]) { printf("%-2d: frint(%a) -> %a != %a\n", i, f32_i64_z[i][0], x, f32_i64_z[i][1]); } } for (i = 0; i < sizeof(f64_i32_z)/sizeof(f64_i32_z[0]); i++) { double x; asm("frint32z %d0,%d1" : "=w"(x) : "w"(f64_i32_z[i][0])); if (x != f64_i32_z[i][1]) { printf("%-2d: frint(%a) -> %a != %a\n", i, f64_i32_z[i][0], x, f64_i32_z[i][1]); } } for (i = 0; i < sizeof(f64_i64_z)/sizeof(f64_i64_z[0]); i++) { double x; asm("frint64z %d0,%d1" : "=w"(x) : "w"(f64_i64_z[i][0])); if (x != f64_i64_z[i][1]) { printf("%-2d: frint(%a) -> %a != %a\n", i, f64_i64_z[i][0], x, f64_i64_z[i][1]); } } return 0; }