Commit 44e92e03 authored by Vincent Chen's avatar Vincent Chen Committed by Greentime Hu
Browse files

nds32: support denormalized result through FP emulator



Currently, the nds32 FPU dose not support the arithmetic of denormalized
number. When the nds32 FPU finds the result of the instruction is a
denormlized number, the nds32 FPU considers it to be an underflow condition
and rounds the result to an appropriate number. It may causes some loss
of precision. This commit proposes a solution to re-execute the
instruction by the FPU emulator to enhance the precision. To transfer
calculations from user space to kernel space, this feature will enable
the underflow exception trap by default. Enabling this feature may cause
some side effects:
  1. Performance loss due to extra FPU exception
  2. Need another scheme to control real underflow trap
       A new parameter, UDF_trap, which is belong to FPU context is used
     to control underflow trap.

User can configure this feature via CONFIG_SUPPORT_DENORMAL_ARITHMETIC

Signed-off-by: default avatarVincent Chen <vincentc@andestech.com>
Acked-by: default avatarGreentime Hu <greentime@andestech.com>
Signed-off-by: default avatarGreentime Hu <greentime@andestech.com>
parent 1ac83250
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -28,6 +28,19 @@ config LAZY_FPU

	  For nomal case, say Y.

config SUPPORT_DENORMAL_ARITHMETIC
	bool "Denormal arithmetic support"
	depends on FPU
	default n
	help
	  Say Y here to enable arithmetic of denormalized number. Enabling
	  this feature can enhance the precision for tininess number.
	  However, performance loss in float pointe calculations is
	  possibly significant due to additional FPU exception.

	  If the calculated tolerance for tininess number is not critical,
	  say N to prevent performance loss.

config HWZOL
	bool "hardware zero overhead loop support"
	depends on CPU_D10 || CPU_D15
+11 −0
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@
 */

#include <asm/ptrace.h>
#include <asm/fpu.h>

typedef unsigned long elf_greg_t;
typedef unsigned long elf_freg_t[3];
@@ -159,8 +160,18 @@ struct elf32_hdr;

#endif


#if IS_ENABLED(CONFIG_FPU)
#define FPU_AUX_ENT	NEW_AUX_ENT(AT_FPUCW, FPCSR_INIT)
#else
#define FPU_AUX_ENT	NEW_AUX_ENT(AT_IGNORE, 0)
#endif

#define ARCH_DLINFO						\
do {								\
	/* Optional FPU initialization */			\
	FPU_AUX_ENT;						\
								\
	NEW_AUX_ENT(AT_SYSINFO_EHDR,				\
		    (elf_addr_t)current->mm->context.vdso);	\
} while (0)
+11 −0
Original line number Diff line number Diff line
@@ -28,7 +28,18 @@ extern int do_fpuemu(struct pt_regs *regs, struct fpu_struct *fpu);
#define sNAN64    0xFFFFFFFFFFFFFFFFULL
#define sNAN32    0xFFFFFFFFUL

#if IS_ENABLED(CONFIG_SUPPORT_DENORMAL_ARITHMETIC)
/*
 * Denormalized number is unsupported by nds32 FPU. Hence the operation
 * is treated as underflow cases when the final result is a denormalized
 * number. To enhance precision, underflow exception trap should be
 * enabled by default and kerenl will re-execute it by fpu emulator
 * when getting underflow exception.
 */
#define FPCSR_INIT  FPCSR_mskUDFE
#else
#define FPCSR_INIT  0x0UL
#endif

extern const struct fpu_struct init_fpuregs;

+1 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@
asmlinkage long sys_cacheflush(unsigned long addr, unsigned long len, unsigned int op);
asmlinkage long sys_fadvise64_64_wrapper(int fd, int advice, loff_t offset, loff_t len);
asmlinkage long sys_rt_sigreturn_wrapper(void);
asmlinkage long sys_udftrap(int option);

#include <asm-generic/syscalls.h>

+7 −0
Original line number Diff line number Diff line
@@ -4,6 +4,13 @@
#ifndef __ASM_AUXVEC_H
#define __ASM_AUXVEC_H

/*
 * This entry gives some information about the FPU initialization
 * performed by the kernel.
 */
#define AT_FPUCW	18	/* Used FPU control word.  */


/* VDSO location */
#define AT_SYSINFO_EHDR	33

Loading