target-xtensa: implement FP coprocessor option
v3 cover target-xtensa: implement FP coprocessor option
This series implements floating point coprocessor and coprocessor context options for xtensa and fixes a couple of bugs to make it work.
Changes v2->v3:
- add comment to the NO_SIGNALING_NANS definition
- reword explanation for UTRUNC.S
Changes v1->v2:
- add NO_SIGNALING_NANS and drop float32_maybe_silence_nan specialization
- fix fp registers access in gdbstub
- replace float32_mul/div in FP-to-integer convertors with float32_scalbn
- reimplement comparison with zero in FP-to-integer convertors
Max Filippov (10):
softfloat: make float_muladd_negate_* flags independent
softfloat: add NO_SIGNALING_NANS
target-xtensa: handle boolean option in overlays
target-xtensa: specialize softfloat NaN rules
target-xtensa: add FP registers
target-xtensa: implement LSCX and LSCI groups
target-xtensa: implement FP0 arithmetic
target-xtensa: implement FP0 conversions
target-xtensa: implement FP1 group
target-xtensa: implement coprocessor context option
fpu/softfloat-specialize.h | 72 +++++++++- fpu/softfloat.h | 7 +- gdbstub.c | 8 + target-xtensa/cpu.h | 8 + target-xtensa/helper.h | 21 +++ target-xtensa/op_helper.c | 134 +++++++++++++++++ target-xtensa/overlay_tool.h | 1 + target-xtensa/translate.c | 338 ++++++++++++++++++++++++++++++++++++++++-- 8 files changed, 573 insertions(+), 16 deletions(-)
Signature · 1 line
1.7.7.6
PATCH v3 1/10 softfloat: make float_muladd_negate_* flags independent
Flags passed into float{32,64}_muladd are treated as bits; assign independent bits to float_muladd_negate_* to allow precise control over what gets negated in float{32,64}_muladd.
--- fpu/softfloat.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
fpu/softfloat.h +1 -1
@@ -219,7 +219,7 @@ void float_raise( int8 flags STATUS_PARAM);enum { float_muladd_negate_c =1 , float_muladd_negate_product =2 , - float_muladd_negate_result =3 , + float_muladd_negate_result =4 , };/*----------------------------------------------------------------------------
Signature · 1 line
1.7.7.6
PATCH v3 2/10 softfloat: add NO_SIGNALING_NANS
In reply to Max FilippovArchitectures that don't have signaling NaNs can define NO_SIGNALING_NANS, it will make float*_is_quiet_nan return 1 for any NaN and float*_is_signaling_nan always return 0.
--- fpu/softfloat-specialize.h | 67 ++++++++++++++++++++++++++++++++++++++++++++ fpu/softfloat.h | 5 +++ 2 files changed, 72 insertions(+), 0 deletions(-)
fpu/softfloat-specialize.h +67 -0
@@ -41,6 +41,13 @@ these four paragraphs for those parts of this code that are retained.#define SNAN_BIT_IS_ONE 0#endif +#if defined(TARGET_XTENSA ) +/* Define for architectures which deviate from IEEE in not supporting +* signaling NaNs (so all NaNs are treated as quiet). +*/ +#define NO_SIGNALING_NANS 1 +#endif +/*---------------------------------------------------------------------------- | The pattern for a default generated half-precision NaN. *----------------------------------------------------------------------------*/
@@ -127,6 +134,17 @@ typedef struct {uint64_t high, low; } commonNaNT; +#ifdef NO_SIGNALING_NANS +int float16_is_quiet_nan (float16 a_) +{ +return float16_is_any_nan (a_); +} + +int float16_is_signaling_nan (float16 a_) +{ +return 0 ; +} +#else /*---------------------------------------------------------------------------- | Returns 1 if the half-precision floating-point value `a' is a quiet | NaN; otherwise returns 0.
@@ -156,6 +174,7 @@ int float16_is_signaling_nan(float16 a_)return (((a >>9 ) &0x3F ) ==0x3E ) && (a &0x1FF ); #endif } +#endif /*---------------------------------------------------------------------------- | Returns a quiet NaN if the half-precision floating point value `a' is a
@@ -217,6 +236,17 @@ static float16 commonNaNToFloat16(commonNaNT a STATUS_PARAM) } } +#ifdef NO_SIGNALING_NANS +int float32_is_quiet_nan (float32 a_) +{ +return float32_is_any_nan (a_); +} + +int float32_is_signaling_nan (float32 a_) +{ +return 0 ; +} +#else /*---------------------------------------------------------------------------- | Returns 1 if the single-precision floating-point value `a' is a quiet | NaN; otherwise returns 0.
@@ -246,6 +276,7 @@ int float32_is_signaling_nan( float32 a_ )return ( ( ( a>>22 ) &0x1FF ) ==0x1FE ) && ( a &0x003FFFFF ); #endif } +#endif /*---------------------------------------------------------------------------- | Returns a quiet NaN if the single-precision floating point value `a' is a
@@ -586,6 +617,17 @@ static float32 propagateFloat32MulAddNaN(float32 a, float32 b, } } +#ifdef NO_SIGNALING_NANS +int float64_is_quiet_nan (float64 a_) +{ +return float64_is_any_nan (a_); +} + +int float64_is_signaling_nan (float64 a_) +{ +return 0 ; +} +#else /*---------------------------------------------------------------------------- | Returns 1 if the double-precision floating-point value `a' is a quiet | NaN; otherwise returns 0.
@@ -619,6 +661,7 @@ int float64_is_signaling_nan( float64 a_ ) && ( a &LIT64 (0x0007FFFFFFFFFFFF ) ); #endif } +#endif /*---------------------------------------------------------------------------- | Returns a quiet NaN if the double-precision floating point value `a' is a
@@ -773,6 +816,17 @@ static float64 propagateFloat64MulAddNaN(float64 a, float64 b, } } +#ifdef NO_SIGNALING_NANS +int floatx80_is_quiet_nan (floatx80 a_) +{ +return floatx80_is_any_nan (a_); +} + +int floatx80_is_signaling_nan (floatx80 a_) +{ +return 0 ; +} +#else /*---------------------------------------------------------------------------- | Returns 1 if the extended double-precision floating-point value `a' is a | quiet NaN; otherwise returns 0. This slightly differs from the same
@@ -816,6 +870,7 @@ int floatx80_is_signaling_nan( floatx80 a ) && ( a.low == aLow ); #endif } +#endif /*---------------------------------------------------------------------------- | Returns a quiet NaN if the extended double-precision floating point value
@@ -929,6 +984,17 @@ static floatx80 propagateFloatx80NaN( floatx80 a, floatx80 b STATUS_PARAM) } } +#ifdef NO_SIGNALING_NANS +int float128_is_quiet_nan (float128 a_) +{ +return float128_is_any_nan (a_); +} + +int float128_is_signaling_nan (float128 a_) +{ +return 0 ; +} +#else /*---------------------------------------------------------------------------- | Returns 1 if the quadruple-precision floating-point value `a' is a quiet | NaN; otherwise returns 0.
@@ -964,6 +1030,7 @@ int float128_is_signaling_nan( float128 a ) && ( a.low || ( a.high &LIT64 (0x00007FFFFFFFFFFF ) ) ); #endif } +#endif /*---------------------------------------------------------------------------- | Returns a quiet NaN if the quadruple-precision floating point value `a' is
fpu/softfloat.h +5 -0
@@ -251,6 +251,11 @@ int float16_is_quiet_nan( float16 );int float16_is_signaling_nan (float16 );float16 float16_maybe_silence_nan (float16 ); +INLINE int float16_is_any_nan(float16 a) +{ +return ((float16_val (a) & ~0x8000 ) >0x7c00 ); +} +/*---------------------------------------------------------------------------- | The pattern for a default generated half-precision NaN. *----------------------------------------------------------------------------*/
Signature · 1 line
1.7.7.6
PATCH v3 3/10 target-xtensa: handle boolean option in overlays
In reply to Max Filippov--- target-xtensa/overlay_tool.h | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
target-xtensa/overlay_tool.h +1 -0
@@ -58,6 +58,7 @@XCHAL_OPTION (XCHAL_HAVE_SEXT ,XTENSA_OPTION_MISC_OP_SEXT ) | \XCHAL_OPTION (XCHAL_HAVE_CLAMPS ,XTENSA_OPTION_MISC_OP_CLAMPS ) | \XCHAL_OPTION (XCHAL_HAVE_CP ,XTENSA_OPTION_COPROCESSOR ) | \ +XCHAL_OPTION (XCHAL_HAVE_BOOLEANS ,XTENSA_OPTION_BOOLEAN ) | \XCHAL_OPTION (XCHAL_HAVE_FP ,XTENSA_OPTION_FP_COPROCESSOR ) | \XCHAL_OPTION (XCHAL_HAVE_RELEASE_SYNC ,XTENSA_OPTION_MP_SYNCHRO ) | \ XCHAL_OPTION(XCHAL_HAVE_S32C1I, XTENSA_OPTION_CONDITIONAL_STORE) | \
Signature · 1 line
1.7.7.6
PATCH v3 4/10 target-xtensa: specialize softfloat NaN rules
In reply to Max FilippovNaN propagation rule: leftmost NaN in the expression gets propagated to the result.
--- fpu/softfloat-specialize.h | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
fpu/softfloat-specialize.h +3 -2
@@ -64,7 +64,8 @@ const float16 float16_default_nan = const_float16(0xFE00);*----------------------------------------------------------------------------*/ #if defined(TARGET_SPARC )const float32 float32_default_nan =const_float32 (0x7FFFFFFF ); -#elif defined(TARGET_PPC ) || defined(TARGET_ARM ) || defined(TARGET_ALPHA ) +#elif defined(TARGET_PPC ) || defined(TARGET_ARM ) || defined(TARGET_ALPHA ) || \ + defined(TARGET_XTENSA )const float32 float32_default_nan =const_float32 (0x7FC00000 );#elif SNAN_BIT_IS_ONE const float32 float32_default_nan =const_float32 (0x7FBFFFFF );
@@ -403,7 +404,7 @@ static int pickNaN(flag aIsQNaN, flag aIsSNaN, flag bIsQNaN, flag bIsSNaN, return 1; } } -#elif defined(TARGET_PPC) +#elif defined(TARGET_PPC) || defined(TARGET_XTENSA)static int pickNaN (flag aIsQNaN,flag aIsSNaN,flag bIsQNaN,flag bIsSNaN,flag aIsLargerSignificand) {
Signature · 1 line
1.7.7.6
PATCH v3 5/10 target-xtensa: add FP registers
In reply to Max FilippovThere are 16 32-bit FP registers (f0 - f15), control and status user registers (fcr, fsr).
See ISA, 4.3.10 for more details.
--- gdbstub.c | 8 +++++++ target-xtensa/cpu.h | 3 ++ target-xtensa/helper.h | 2 + target-xtensa/op_helper.c | 13 +++++++++++ target-xtensa/translate.c | 52 ++++++++++++++++++++++++++++++++++++++------ 5 files changed, 71 insertions(+), 7 deletions(-)
gdbstub.c +8 -0
@@ -1660,6 +1660,10 @@ static int cpu_gdb_read_register(CPUXtensaState *env, uint8_t *mem_buf, int n)GET_REG32 (env->uregs[reg->targno &0xff ]);break ; +case 4 :/*f*/ +GET_REG32 (float32_val (env->fregs[reg->targno &0x0f ])); +break ; +case 8 :/*a*/ GET_REG32 (env->regs[reg->targno &0x0f ]);break ;
@@ -1700,6 +1704,10 @@ static int cpu_gdb_write_register(CPUXtensaState *env, uint8_t *mem_buf, int n) env->uregs[reg->targno &0xff ] = tmp;break ; +case 4 :/*f*/ + env->fregs[reg->targno &0x0f ] =make_float32 (tmp); +break ; +case 8 :/*a*/ env->regs[reg->targno &0x0f ] = tmp;break ;
target-xtensa/cpu.h +3 -0
@@ -36,6 +36,7 @@#include "config.h" #include "qemu-common.h" #include "cpu-defs.h" +#include "fpu/softfloat.h" #define TARGET_HAS_ICE 1
@@ -325,6 +326,8 @@ typedef struct CPUXtensaState {uint32_t sregs[256 ];uint32_t uregs[256 ];uint32_t phys_regs[MAX_NAREG ]; +float32 fregs[16 ]; +float_status fp_status;xtensa_tlb_entry itlb[7 ][MAX_TLB_WAY_SIZE ];xtensa_tlb_entry dtlb[10 ][MAX_TLB_WAY_SIZE ];
target-xtensa/helper.h +2 -0
@@ -36,4 +36,6 @@ DEF_HELPER_3(wsr_ibreaka, void, env, i32, i32) DEF_HELPER_3(wsr_dbreaka, void, env, i32, i32) DEF_HELPER_3(wsr_dbreakc, void, env, i32, i32) +DEF_HELPER_2(wur_fcr, void, env, i32) +#include "def-helper.h"
target-xtensa/op_helper.c +13 -0
@@ -771,3 +771,16 @@ void HELPER(wsr_dbreakc)(CPUXtensaState *env, uint32_t i, uint32_t v) } env->sregs[DBREAKC + i] = v; } + +void HELPER (wur_fcr )(CPUXtensaState *env,uint32_t v) +{ +static const int rounding_mode[] = { + float_round_nearest_even, + float_round_to_zero, + float_round_up, + float_round_down, + }; + + env->uregs[FCR ] = v &0xfffff07f ; +set_float_rounding_mode (rounding_mode[v &3 ], &env->fp_status); +}
target-xtensa/translate.c +45 -7
88 lines not on this page · raw message
Signature · 1 line
1.7.7.6
PATCH v3 6/10 target-xtensa: implement LSCX and LSCI groups
In reply to Max FilippovThese are load/store instructions for FP registers with immediate or register index and optional base post-update.
See ISA, 4.3.10 for more details.
--- target-xtensa/translate.c | 58 +++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 54 insertions(+), 4 deletions(-)
target-xtensa/translate.c +54 -4
@@ -1825,8 +1825,33 @@ static void disas_xtensa_insn(DisasContext *dc)break ;case 8 :/*LSCXp*/ -HAS_OPTION (XTENSA_OPTION_COPROCESSOR ); -TBD (); +switch (OP2 ) { +case 0 :/*LSXf*/ +case 1 :/*LSXUf*/ +case 4 :/*SSXf*/ +case 5 :/*SSXUf*/ +HAS_OPTION (XTENSA_OPTION_FP_COPROCESSOR ); +gen_window_check2 (dc,RRR_S ,RRR_T ); + { +TCGv_i32 addr =tcg_temp_new_i32 (); +tcg_gen_add_i32 (addr, cpu_R[RRR_S ], cpu_R[RRR_T ]); +gen_load_store_alignment (dc,2 , addr, false); +if (OP2 &0x4 ) { +tcg_gen_qemu_st32 (cpu_FR[RRR_R ], addr, dc->cring); + }else { +tcg_gen_qemu_ld32u (cpu_FR[RRR_R ], addr, dc->cring); + } +if (OP2 &0x1 ) { +tcg_gen_mov_i32 (cpu_R[RRR_S ], addr); + } +tcg_temp_free (addr); + } +break ; + +default :/*reserved*/ +RESERVED (); +break ; + }break ;case 9 :/*LSC4*/
@@ -2100,8 +2125,33 @@ static void disas_xtensa_insn(DisasContext *dc)break ;case 3 :/*LSCIp*/ -HAS_OPTION (XTENSA_OPTION_COPROCESSOR ); -TBD (); +switch (RRI8_R ) { +case 0 :/*LSIf*/ +case 4 :/*SSIf*/ +case 8 :/*LSIUf*/ +case 12 :/*SSIUf*/ +HAS_OPTION (XTENSA_OPTION_FP_COPROCESSOR ); +gen_window_check1 (dc,RRI8_S ); + { +TCGv_i32 addr =tcg_temp_new_i32 (); +tcg_gen_addi_i32 (addr, cpu_R[RRI8_S ],RRI8_IMM8 <<2 ); +gen_load_store_alignment (dc,2 , addr, false); +if (RRI8_R &0x4 ) { +tcg_gen_qemu_st32 (cpu_FR[RRI8_T ], addr, dc->cring); + }else { +tcg_gen_qemu_ld32u (cpu_FR[RRI8_T ], addr, dc->cring); + } +if (RRI8_R &0x8 ) { +tcg_gen_mov_i32 (cpu_R[RRI8_S ], addr); + } +tcg_temp_free (addr); + } +break ; + +default :/*reserved*/ +RESERVED (); +break ; + }break ;case 4 :/*MAC16d*/
Signature · 1 line
1.7.7.6
PATCH v3 7/10 target-xtensa: implement FP0 arithmetic
In reply to Max FilippovThese are FP arithmetic opcodes.
See ISA, 4.3.10 for more details.
--- target-xtensa/helper.h | 7 +++++ target-xtensa/op_helper.c | 37 +++++++++++++++++++++++++++ target-xtensa/translate.c | 61 ++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 104 insertions(+), 1 deletions(-)
target-xtensa/helper.h +7 -0
@@ -37,5 +37,12 @@ DEF_HELPER_3(wsr_dbreaka, void, env, i32, i32) DEF_HELPER_3(wsr_dbreakc, void, env, i32, i32) DEF_HELPER_2(wur_fcr, void, env, i32) +DEF_HELPER_FLAGS_1(abs_s, TCG_CALL_CONST | TCG_CALL_PURE, f32, f32) +DEF_HELPER_FLAGS_1(neg_s, TCG_CALL_CONST | TCG_CALL_PURE, f32, f32) +DEF_HELPER_3(add_s, f32, env, f32, f32) +DEF_HELPER_3(sub_s, f32, env, f32, f32) +DEF_HELPER_3(mul_s, f32, env, f32, f32) +DEF_HELPER_4(madd_s, f32, env, f32, f32, f32) +DEF_HELPER_4(msub_s, f32, env, f32, f32, f32)#include "def-helper.h"
target-xtensa/op_helper.c +37 -0
@@ -784,3 +784,40 @@ void HELPER(wur_fcr)(CPUXtensaState *env, uint32_t v) env->uregs[FCR ] = v &0xfffff07f ;set_float_rounding_mode (rounding_mode[v &3 ], &env->fp_status); } + +float32 HELPER (abs_s )(float32 v) +{ +return float32_abs (v); +} + +float32 HELPER (neg_s )(float32 v) +{ +return float32_chs (v); +} + +float32 HELPER (add_s )(CPUXtensaState *env,float32 a,float32 b) +{ +return float32_add (a, b, &env->fp_status); +} + +float32 HELPER (sub_s )(CPUXtensaState *env,float32 a,float32 b) +{ +return float32_sub (a, b, &env->fp_status); +} + +float32 HELPER (mul_s )(CPUXtensaState *env,float32 a,float32 b) +{ +return float32_mul (a, b, &env->fp_status); +} + +float32 HELPER (madd_s )(CPUXtensaState *env,float32 a,float32 b,float32 c) +{ +return float32_muladd (b, c, a,0 , + &env->fp_status); +} + +float32 HELPER (msub_s )(CPUXtensaState *env,float32 a,float32 b,float32 c) +{ +return float32_muladd (b, c, a, float_muladd_negate_product, + &env->fp_status); +}
target-xtensa/translate.c +60 -1
67 lines not on this page · raw message
Signature · 1 line
1.7.7.6
PATCH v3 8/10 target-xtensa: implement FP0 conversions
In reply to Max FilippovThese are FP to integer and integer to FP conversion opcodes. See ISA, 4.3.10 for more details.
Note that ISA description for utrunc.s is currently incorrect and will be fixed in future revisions.
--- target-xtensa/helper.h | 4 +++ target-xtensa/op_helper.c | 37 ++++++++++++++++++++++++++++++++++ target-xtensa/translate.c | 48 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 0 deletions(-)
target-xtensa/helper.h +4 -0
@@ -44,5 +44,9 @@ DEF_HELPER_3(sub_s, f32, env, f32, f32) DEF_HELPER_3(mul_s, f32, env, f32, f32) DEF_HELPER_4(madd_s, f32, env, f32, f32, f32) DEF_HELPER_4(msub_s, f32, env, f32, f32, f32) +DEF_HELPER_FLAGS_3(ftoi, TCG_CALL_CONST | TCG_CALL_PURE, i32, f32, i32, i32) +DEF_HELPER_FLAGS_3(ftoui, TCG_CALL_CONST | TCG_CALL_PURE, i32, f32, i32, i32) +DEF_HELPER_3(itof, f32, env, i32, i32) +DEF_HELPER_3(uitof, f32, env, i32, i32)#include "def-helper.h"
target-xtensa/op_helper.c +37 -0
@@ -821,3 +821,40 @@ float32 HELPER(msub_s)(CPUXtensaState *env, float32 a, float32 b, float32 c)return float32_muladd (b, c, a, float_muladd_negate_product, &env->fp_status); } + +uint32_t HELPER (ftoi )(float32 v,uint32_t rounding_mode,uint32_t scale) +{ +float_status fp_status = {0 }; + +set_float_rounding_mode (rounding_mode, &fp_status); +return float32_to_int32 ( +float32_scalbn (v, scale, &fp_status), &fp_status); +} + +uint32_t HELPER (ftoui )(float32 v,uint32_t rounding_mode,uint32_t scale) +{ +float_status fp_status = {0 }; +float32 res; + +set_float_rounding_mode (rounding_mode, &fp_status); + + res =float32_scalbn (v, scale, &fp_status); + +if (float32_is_neg (v) && !float32_is_any_nan (v)) { +return float32_to_int32 (res, &fp_status); + }else { +return float32_to_uint32 (res, &fp_status); + } +} + +float32 HELPER (itof )(CPUXtensaState *env,uint32_t v,uint32_t scale) +{ +return float32_scalbn (int32_to_float32 (v, &env->fp_status), + (int32_t )scale, &env->fp_status); +} + +float32 HELPER (uitof )(CPUXtensaState *env,uint32_t v,uint32_t scale) +{ +return float32_scalbn (uint32_to_float32 (v, &env->fp_status), + (int32_t )scale, &env->fp_status); +}
target-xtensa/translate.c +48 -0
54 lines not on this page · raw message
Signature · 1 line
1.7.7.6
PATCH v3 9/10 target-xtensa: implement FP1 group
In reply to Max FilippovThese are comparison and conditional move opcodes. See ISA, 4.3.10 for more details.
--- target-xtensa/helper.h | 8 ++++ target-xtensa/op_helper.c | 47 ++++++++++++++++++++++++++ target-xtensa/translate.c | 81 ++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 135 insertions(+), 1 deletions(-)
target-xtensa/helper.h +8 -0
@@ -49,4 +49,12 @@ DEF_HELPER_FLAGS_3(ftoui, TCG_CALL_CONST | TCG_CALL_PURE, i32, f32, i32, i32) DEF_HELPER_3(itof, f32, env, i32, i32) DEF_HELPER_3(uitof, f32, env, i32, i32) +DEF_HELPER_4(un_s, void, env, i32, f32, f32) +DEF_HELPER_4(oeq_s, void, env, i32, f32, f32) +DEF_HELPER_4(ueq_s, void, env, i32, f32, f32) +DEF_HELPER_4(olt_s, void, env, i32, f32, f32) +DEF_HELPER_4(ult_s, void, env, i32, f32, f32) +DEF_HELPER_4(ole_s, void, env, i32, f32, f32) +DEF_HELPER_4(ule_s, void, env, i32, f32, f32) +#include "def-helper.h"
target-xtensa/op_helper.c +47 -0
50 lines not on this page · raw message
target-xtensa/translate.c +80 -1
87 lines not on this page · raw message
Signature · 1 line
1.7.7.6
PATCH v3 10/10 target-xtensa: implement coprocessor context option
In reply to Max FilippovIn case Coprocessor Context option is enabled CPENABLE SR bits control whether access to coprocessors is allowed or would rise one of CoprocessorXDisabled exceptions.
See ISA, 4.4.5 for more details.
FP is coprocessor 0.
--- target-xtensa/cpu.h | 5 +++++ target-xtensa/translate.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 0 deletions(-)
target-xtensa/cpu.h +5 -0
@@ -468,6 +468,8 @@ static inline int cpu_mmu_index(CPUXtensaState *env)#define XTENSA_TBFLAG_LITBASE 0x8#define XTENSA_TBFLAG_DEBUG 0x10#define XTENSA_TBFLAG_ICOUNT 0x20 +#define XTENSA_TBFLAG_CPENABLE_MASK 0x3fc0 +#define XTENSA_TBFLAG_CPENABLE_SHIFT 6static inline void cpu_get_tb_cpu_state (CPUXtensaState *env,target_ulong *pc,target_ulong *cs_base,int *flags)
@@ -491,6 +493,9 @@ static inline void cpu_get_tb_cpu_state(CPUXtensaState *env, target_ulong *pc, *flags |=XTENSA_TBFLAG_ICOUNT ; } } +if (xtensa_option_enabled (env->config,XTENSA_OPTION_COPROCESSOR )) { + *flags |= env->sregs[CPENABLE ] <<XTENSA_TBFLAG_CPENABLE_SHIFT ; + } }#include "cpu-all.h"
target-xtensa/translate.c +38 -0
@@ -65,6 +65,8 @@ typedef struct DisasContext {bool debug;bool icount;TCGv_i32 next_icount; + +unsigned cpenable; } DisasContext;static TCGv_ptr cpu_env;
@@ -331,6 +333,15 @@ static void gen_check_privilege(DisasContext *dc) } } +static void gen_check_cpenable (DisasContext *dc,unsigned cp) +{ +if (option_enabled (dc,XTENSA_OPTION_COPROCESSOR ) && + !(dc->cpenable & (1 << cp))) { +gen_exception_cause (dc,COPROCESSOR0_DISABLED + cp); + dc->is_jmp =DISAS_UPDATE ; + } +} +static void gen_jump_slot (DisasContext *dc,TCGv dest,int slot) {tcg_gen_mov_i32 (cpu_pc, dest);
@@ -579,6 +590,13 @@ static void gen_wsr_dbreakc(DisasContext *dc, uint32_t sr, TCGv_i32 v) } } +static void gen_wsr_cpenable (DisasContext *dc,uint32_t sr,TCGv_i32 v) +{ +tcg_gen_andi_i32 (cpu_SR[sr], v,0xff ); +/* This can change tb->flags, so exit tb */ +gen_jumpi_check_loop_end (dc,-1 ); +} +static void gen_wsr_intset (DisasContext *dc,uint32_t sr,TCGv_i32 v) { tcg_gen_andi_i32(cpu_SR[sr], v,
@@ -681,6 +699,7 @@ static void gen_wsr(DisasContext *dc, uint32_t sr, TCGv_i32 s) [DBREAKA + 1] = gen_wsr_dbreaka, [DBREAKC] = gen_wsr_dbreakc, [DBREAKC + 1] = gen_wsr_dbreakc, + [CPENABLE] = gen_wsr_cpenable, [INTSET] = gen_wsr_intset, [INTCLEAR] = gen_wsr_intclear, [INTENABLE] = gen_wsr_intenable,
@@ -1832,6 +1851,7 @@ static void disas_xtensa_insn(DisasContext *dc)case 5 :/*SSXUf*/ HAS_OPTION (XTENSA_OPTION_FP_COPROCESSOR );gen_window_check2 (dc,RRR_S ,RRR_T ); +gen_check_cpenable (dc,0 ); {TCGv_i32 addr =tcg_temp_new_i32 ();tcg_gen_add_i32 (addr, cpu_R[RRR_S ], cpu_R[RRR_T ]);
@@ -1891,26 +1911,31 @@ static void disas_xtensa_insn(DisasContext *dc)HAS_OPTION (XTENSA_OPTION_FP_COPROCESSOR );switch (OP2 ) {case 0 :/*ADD.Sf*/ +gen_check_cpenable (dc,0 );gen_helper_add_s (cpu_FR[RRR_R ], cpu_env, cpu_FR[RRR_S ], cpu_FR[RRR_T ]);break ;case 1 :/*SUB.Sf*/ +gen_check_cpenable (dc,0 );gen_helper_sub_s (cpu_FR[RRR_R ], cpu_env, cpu_FR[RRR_S ], cpu_FR[RRR_T ]);break ;case 2 :/*MUL.Sf*/ +gen_check_cpenable (dc,0 );gen_helper_mul_s (cpu_FR[RRR_R ], cpu_env, cpu_FR[RRR_S ], cpu_FR[RRR_T ]);break ;case 4 :/*MADD.Sf*/ +gen_check_cpenable (dc,0 );gen_helper_madd_s (cpu_FR[RRR_R ], cpu_env, cpu_FR[RRR_R ], cpu_FR[RRR_S ], cpu_FR[RRR_T ]);break ;case 5 :/*MSUB.Sf*/ +gen_check_cpenable (dc,0 );gen_helper_msub_s (cpu_FR[RRR_R ], cpu_env, cpu_FR[RRR_R ], cpu_FR[RRR_S ], cpu_FR[RRR_T ]);break ;
@@ -1921,6 +1946,7 @@ static void disas_xtensa_insn(DisasContext *dc)case 11 :/*CEIL.Sf*/ case 14 :/*UTRUNC.Sf*/ gen_window_check1 (dc,RRR_R ); +gen_check_cpenable (dc,0 ); {static const unsigned rounding_mode_const[] = { float_round_nearest_even,
@@ -1949,6 +1975,7 @@ static void disas_xtensa_insn(DisasContext *dc)case 12 :/*FLOAT.Sf*/ case 13 :/*UFLOAT.Sf*/ gen_window_check1 (dc,RRR_S ); +gen_check_cpenable (dc,0 ); {TCGv_i32 scale =tcg_const_i32 (-RRR_T );
@@ -1966,24 +1993,29 @@ static void disas_xtensa_insn(DisasContext *dc)case 15 :/*FP1OP*/ switch (RRR_T ) {case 0 :/*MOV.Sf*/ +gen_check_cpenable (dc,0 );tcg_gen_mov_i32 (cpu_FR[RRR_R ], cpu_FR[RRR_S ]);break ;case 1 :/*ABS.Sf*/ +gen_check_cpenable (dc,0 );gen_helper_abs_s (cpu_FR[RRR_R ], cpu_FR[RRR_S ]);break ;case 4 :/*RFRf*/ gen_window_check1 (dc,RRR_R ); +gen_check_cpenable (dc,0 );tcg_gen_mov_i32 (cpu_R[RRR_R ], cpu_FR[RRR_S ]);break ;case 5 :/*WFRf*/ gen_window_check1 (dc,RRR_S ); +gen_check_cpenable (dc,0 );tcg_gen_mov_i32 (cpu_FR[RRR_R ], cpu_R[RRR_S ]);break ;case 6 :/*NEG.Sf*/ +gen_check_cpenable (dc,0 );gen_helper_neg_s (cpu_FR[RRR_R ], cpu_FR[RRR_S ]);break ;
@@ -2006,6 +2038,7 @@ static void disas_xtensa_insn(DisasContext *dc) do { \ TCGv_i32 bit = tcg_const_i32(1 << br); \ \ + gen_check_cpenable(dc, 0); \ gen_helper_##rel(cpu_env, bit, cpu_FR[a], cpu_FR[b]); \ tcg_temp_free(bit); \ } while (0)
@@ -2046,6 +2079,7 @@ static void disas_xtensa_insn(DisasContext *dc)case 10 :/*MOVLTZ.Sf*/ case 11 :/*MOVGEZ.Sf*/ gen_window_check1 (dc,RRR_T ); +gen_check_cpenable (dc,0 ); {static const TCGCond cond[] = {TCG_COND_NE ,
@@ -2063,6 +2097,7 @@ static void disas_xtensa_insn(DisasContext *dc)case 12 :/*MOVF.Sf*/ case 13 :/*MOVT.Sf*/ HAS_OPTION (XTENSA_OPTION_BOOLEAN ); +gen_check_cpenable (dc,0 ); {int label =gen_new_label ();TCGv_i32 tmp =tcg_temp_new_i32 ();
@@ -2318,6 +2353,7 @@ static void disas_xtensa_insn(DisasContext *dc)case 12 :/*SSIUf*/ HAS_OPTION (XTENSA_OPTION_FP_COPROCESSOR );gen_window_check1 (dc,RRI8_S ); +gen_check_cpenable (dc,0 ); {TCGv_i32 addr =tcg_temp_new_i32 ();tcg_gen_addi_i32 (addr, cpu_R[RRI8_S ],RRI8_IMM8 <<2 );
@@ -2833,6 +2869,8 @@ static void gen_intermediate_code_internal( dc.ccount_delta =0 ; dc.debug = tb->flags &XTENSA_TBFLAG_DEBUG ; dc.icount = tb->flags &XTENSA_TBFLAG_ICOUNT ; + dc.cpenable = (tb->flags &XTENSA_TBFLAG_CPENABLE_MASK ) >> +XTENSA_TBFLAG_CPENABLE_SHIFT ;init_litbase (&dc);init_sar_tracker (&dc);
Signature · 1 line
1.7.7.6
Re: [Qemu-devel] [PATCH v3 08/10] target-xtensa: implement FP0 conversions
In reply to Max FilippovQuoted 14 lines · Max Filippov
target-xtensa/op_helper.c +14
-0+uint32_t HELPER (ftoi )(float32 v,uint32_t rounding_mode,uint32_t scale) +{ +float_status fp_status = {0 }; + +set_float_rounding_mode (rounding_mode, &fp_status); +return float32_to_int32 ( +float32_scalbn (v, scale, &fp_status), &fp_status); +} + +uint32_t HELPER (ftoui )(float32 v,uint32_t rounding_mode,uint32_t scale) +{ +float_status fp_status = {0 }; +float32 res; +
target-xtensa/op_helper.c float32 HELPER(msub_s)(CPUXtensaState *env, float32 a, float32 b, float32 c) · line 848
Quoted 10 lines
target-xtensa/op_helper.c +10
-0+set_float_rounding_mode (rounding_mode, &fp_status); + + res =float32_scalbn (v, scale, &fp_status); + +if (float32_is_neg (v) && !float32_is_any_nan (v)) { +return float32_to_int32 (res, &fp_status); + }else { +return float32_to_uint32 (res, &fp_status); + } +}
Are you really intending to discard any exceptions raised here?
r~
Re: [Qemu-devel] [PATCH v3 08/10] target-xtensa: implement FP0 conversions
Quoted 19 lines · Richard Henderson
Quoted 18 lines · Max Filippov
target-xtensa/op_helper.c +18
-0+uint32_t HELPER (ftoi )(float32 v,uint32_t rounding_mode,uint32_t scale) +{ +float_status fp_status = {0 }; + +set_float_rounding_mode (rounding_mode, &fp_status); +return float32_to_int32 ( +float32_scalbn (v, scale, &fp_status), &fp_status); +} + +uint32_t HELPER (ftoui )(float32 v,uint32_t rounding_mode,uint32_t scale) +{ +float_status fp_status = {0 }; +float32 res; + +set_float_rounding_mode (rounding_mode, &fp_status); + + res =float32_scalbn (v, scale, &fp_status); +
Quoted 8 lines
target-xtensa/op_helper.c float32 HELPER(msub_s)(CPUXtensaState *env, float32 a, float32 b, float32 c) · line 848
Quoted 6 lines
target-xtensa/op_helper.c +6
-0+if (float32_is_neg (v) && !float32_is_any_nan (v)) { +return float32_to_int32 (res, &fp_status); + }else { +return float32_to_uint32 (res, &fp_status); + } +}Are you really intending to discard any exceptions raised here?
Yes, as specified in the ISA and as unit tests on Tensilica ISS show.
Signature · 2 lines
Thanks. -- Max
Blue Swirl
AppliedQuoted 2 lines · Max Filippov
This series implements floating point coprocessor and coprocessor context options for xtensa and fixes a couple of bugs to make it work.
Thanks, applied all.
Quoted 36 lines
Changes
v2->v3:
- add comment to theNO_SIGNALING_NANSdefinition
- reword explanation forUTRUNC.SChanges
v1->v2:
- addNO_SIGNALING_NANSand dropfloat32_maybe_silence_nanspecialization
- fix fp registers access in gdbstub
- replace float32_mul/div in FP-to-integer convertors withfloat32_scalbn
- reimplement comparison with zero in FP-to-integer convertorsMax Filippov (10):
softfloat: make float_muladd_negate_* flags independent
softfloat: addNO_SIGNALING_NANS
target-xtensa: handle boolean option in overlays
target-xtensa: specialize softfloat NaN rules
target-xtensa: add FP registers
target-xtensa: implement LSCX and LSCI groups
target-xtensa: implement FP0 arithmetic
target-xtensa: implement FP0 conversions
target-xtensa: implement FP1 group
target-xtensa: implement coprocessor context optionfpu/softfloat-specialize.h | 72 +++++++++- fpu/softfloat.h | 7 +- gdbstub.c | 8 + target-xtensa/cpu.h | 8 + target-xtensa/helper.h | 21 +++ target-xtensa/op_helper.c | 134 +++++++++++++++++ target-xtensa/overlay_tool.h | 1 + target-xtensa/translate.c | 338 ++++++++++++++++++++++++++++++++++++++++-- 8 files changed, 573 insertions(+), 16 deletions(-)--
1.7.7.6