162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 262306a36Sopenharmony_ci#ifndef _UAPI__ASM_ALPHA_FPU_H 362306a36Sopenharmony_ci#define _UAPI__ASM_ALPHA_FPU_H 462306a36Sopenharmony_ci 562306a36Sopenharmony_ci 662306a36Sopenharmony_ci/* 762306a36Sopenharmony_ci * Alpha floating-point control register defines: 862306a36Sopenharmony_ci */ 962306a36Sopenharmony_ci#define FPCR_DNOD (1UL<<47) /* denorm INV trap disable */ 1062306a36Sopenharmony_ci#define FPCR_DNZ (1UL<<48) /* denorms to zero */ 1162306a36Sopenharmony_ci#define FPCR_INVD (1UL<<49) /* invalid op disable (opt.) */ 1262306a36Sopenharmony_ci#define FPCR_DZED (1UL<<50) /* division by zero disable (opt.) */ 1362306a36Sopenharmony_ci#define FPCR_OVFD (1UL<<51) /* overflow disable (optional) */ 1462306a36Sopenharmony_ci#define FPCR_INV (1UL<<52) /* invalid operation */ 1562306a36Sopenharmony_ci#define FPCR_DZE (1UL<<53) /* division by zero */ 1662306a36Sopenharmony_ci#define FPCR_OVF (1UL<<54) /* overflow */ 1762306a36Sopenharmony_ci#define FPCR_UNF (1UL<<55) /* underflow */ 1862306a36Sopenharmony_ci#define FPCR_INE (1UL<<56) /* inexact */ 1962306a36Sopenharmony_ci#define FPCR_IOV (1UL<<57) /* integer overflow */ 2062306a36Sopenharmony_ci#define FPCR_UNDZ (1UL<<60) /* underflow to zero (opt.) */ 2162306a36Sopenharmony_ci#define FPCR_UNFD (1UL<<61) /* underflow disable (opt.) */ 2262306a36Sopenharmony_ci#define FPCR_INED (1UL<<62) /* inexact disable (opt.) */ 2362306a36Sopenharmony_ci#define FPCR_SUM (1UL<<63) /* summary bit */ 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_ci#define FPCR_DYN_SHIFT 58 /* first dynamic rounding mode bit */ 2662306a36Sopenharmony_ci#define FPCR_DYN_CHOPPED (0x0UL << FPCR_DYN_SHIFT) /* towards 0 */ 2762306a36Sopenharmony_ci#define FPCR_DYN_MINUS (0x1UL << FPCR_DYN_SHIFT) /* towards -INF */ 2862306a36Sopenharmony_ci#define FPCR_DYN_NORMAL (0x2UL << FPCR_DYN_SHIFT) /* towards nearest */ 2962306a36Sopenharmony_ci#define FPCR_DYN_PLUS (0x3UL << FPCR_DYN_SHIFT) /* towards +INF */ 3062306a36Sopenharmony_ci#define FPCR_DYN_MASK (0x3UL << FPCR_DYN_SHIFT) 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_ci#define FPCR_MASK 0xffff800000000000L 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_ci/* 3562306a36Sopenharmony_ci * IEEE trap enables are implemented in software. These per-thread 3662306a36Sopenharmony_ci * bits are stored in the "ieee_state" field of "struct thread_info". 3762306a36Sopenharmony_ci * Thus, the bits are defined so as not to conflict with the 3862306a36Sopenharmony_ci * floating-point enable bit (which is architected). On top of that, 3962306a36Sopenharmony_ci * we want to make these bits compatible with OSF/1 so 4062306a36Sopenharmony_ci * ieee_set_fp_control() etc. can be implemented easily and 4162306a36Sopenharmony_ci * compatibly. The corresponding definitions are in 4262306a36Sopenharmony_ci * /usr/include/machine/fpu.h under OSF/1. 4362306a36Sopenharmony_ci */ 4462306a36Sopenharmony_ci#define IEEE_TRAP_ENABLE_INV (1UL<<1) /* invalid op */ 4562306a36Sopenharmony_ci#define IEEE_TRAP_ENABLE_DZE (1UL<<2) /* division by zero */ 4662306a36Sopenharmony_ci#define IEEE_TRAP_ENABLE_OVF (1UL<<3) /* overflow */ 4762306a36Sopenharmony_ci#define IEEE_TRAP_ENABLE_UNF (1UL<<4) /* underflow */ 4862306a36Sopenharmony_ci#define IEEE_TRAP_ENABLE_INE (1UL<<5) /* inexact */ 4962306a36Sopenharmony_ci#define IEEE_TRAP_ENABLE_DNO (1UL<<6) /* denorm */ 5062306a36Sopenharmony_ci#define IEEE_TRAP_ENABLE_MASK (IEEE_TRAP_ENABLE_INV | IEEE_TRAP_ENABLE_DZE |\ 5162306a36Sopenharmony_ci IEEE_TRAP_ENABLE_OVF | IEEE_TRAP_ENABLE_UNF |\ 5262306a36Sopenharmony_ci IEEE_TRAP_ENABLE_INE | IEEE_TRAP_ENABLE_DNO) 5362306a36Sopenharmony_ci 5462306a36Sopenharmony_ci/* Denorm and Underflow flushing */ 5562306a36Sopenharmony_ci#define IEEE_MAP_DMZ (1UL<<12) /* Map denorm inputs to zero */ 5662306a36Sopenharmony_ci#define IEEE_MAP_UMZ (1UL<<13) /* Map underflowed outputs to zero */ 5762306a36Sopenharmony_ci 5862306a36Sopenharmony_ci#define IEEE_MAP_MASK (IEEE_MAP_DMZ | IEEE_MAP_UMZ) 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_ci/* status bits coming from fpcr: */ 6162306a36Sopenharmony_ci#define IEEE_STATUS_INV (1UL<<17) 6262306a36Sopenharmony_ci#define IEEE_STATUS_DZE (1UL<<18) 6362306a36Sopenharmony_ci#define IEEE_STATUS_OVF (1UL<<19) 6462306a36Sopenharmony_ci#define IEEE_STATUS_UNF (1UL<<20) 6562306a36Sopenharmony_ci#define IEEE_STATUS_INE (1UL<<21) 6662306a36Sopenharmony_ci#define IEEE_STATUS_DNO (1UL<<22) 6762306a36Sopenharmony_ci 6862306a36Sopenharmony_ci#define IEEE_STATUS_MASK (IEEE_STATUS_INV | IEEE_STATUS_DZE | \ 6962306a36Sopenharmony_ci IEEE_STATUS_OVF | IEEE_STATUS_UNF | \ 7062306a36Sopenharmony_ci IEEE_STATUS_INE | IEEE_STATUS_DNO) 7162306a36Sopenharmony_ci 7262306a36Sopenharmony_ci#define IEEE_SW_MASK (IEEE_TRAP_ENABLE_MASK | \ 7362306a36Sopenharmony_ci IEEE_STATUS_MASK | IEEE_MAP_MASK) 7462306a36Sopenharmony_ci 7562306a36Sopenharmony_ci#define IEEE_CURRENT_RM_SHIFT 32 7662306a36Sopenharmony_ci#define IEEE_CURRENT_RM_MASK (3UL<<IEEE_CURRENT_RM_SHIFT) 7762306a36Sopenharmony_ci 7862306a36Sopenharmony_ci#define IEEE_STATUS_TO_EXCSUM_SHIFT 16 7962306a36Sopenharmony_ci 8062306a36Sopenharmony_ci#define IEEE_INHERIT (1UL<<63) /* inherit on thread create? */ 8162306a36Sopenharmony_ci 8262306a36Sopenharmony_ci/* 8362306a36Sopenharmony_ci * Convert the software IEEE trap enable and status bits into the 8462306a36Sopenharmony_ci * hardware fpcr format. 8562306a36Sopenharmony_ci * 8662306a36Sopenharmony_ci * Digital Unix engineers receive my thanks for not defining the 8762306a36Sopenharmony_ci * software bits identical to the hardware bits. The chip designers 8862306a36Sopenharmony_ci * receive my thanks for making all the not-implemented fpcr bits 8962306a36Sopenharmony_ci * RAZ forcing us to use system calls to read/write this value. 9062306a36Sopenharmony_ci */ 9162306a36Sopenharmony_ci 9262306a36Sopenharmony_cistatic inline unsigned long 9362306a36Sopenharmony_ciieee_swcr_to_fpcr(unsigned long sw) 9462306a36Sopenharmony_ci{ 9562306a36Sopenharmony_ci unsigned long fp; 9662306a36Sopenharmony_ci fp = (sw & IEEE_STATUS_MASK) << 35; 9762306a36Sopenharmony_ci fp |= (sw & IEEE_MAP_DMZ) << 36; 9862306a36Sopenharmony_ci fp |= (sw & IEEE_STATUS_MASK ? FPCR_SUM : 0); 9962306a36Sopenharmony_ci fp |= (~sw & (IEEE_TRAP_ENABLE_INV 10062306a36Sopenharmony_ci | IEEE_TRAP_ENABLE_DZE 10162306a36Sopenharmony_ci | IEEE_TRAP_ENABLE_OVF)) << 48; 10262306a36Sopenharmony_ci fp |= (~sw & (IEEE_TRAP_ENABLE_UNF | IEEE_TRAP_ENABLE_INE)) << 57; 10362306a36Sopenharmony_ci fp |= (sw & IEEE_MAP_UMZ ? FPCR_UNDZ | FPCR_UNFD : 0); 10462306a36Sopenharmony_ci fp |= (~sw & IEEE_TRAP_ENABLE_DNO) << 41; 10562306a36Sopenharmony_ci return fp; 10662306a36Sopenharmony_ci} 10762306a36Sopenharmony_ci 10862306a36Sopenharmony_cistatic inline unsigned long 10962306a36Sopenharmony_ciieee_fpcr_to_swcr(unsigned long fp) 11062306a36Sopenharmony_ci{ 11162306a36Sopenharmony_ci unsigned long sw; 11262306a36Sopenharmony_ci sw = (fp >> 35) & IEEE_STATUS_MASK; 11362306a36Sopenharmony_ci sw |= (fp >> 36) & IEEE_MAP_DMZ; 11462306a36Sopenharmony_ci sw |= (~fp >> 48) & (IEEE_TRAP_ENABLE_INV 11562306a36Sopenharmony_ci | IEEE_TRAP_ENABLE_DZE 11662306a36Sopenharmony_ci | IEEE_TRAP_ENABLE_OVF); 11762306a36Sopenharmony_ci sw |= (~fp >> 57) & (IEEE_TRAP_ENABLE_UNF | IEEE_TRAP_ENABLE_INE); 11862306a36Sopenharmony_ci sw |= (fp >> 47) & IEEE_MAP_UMZ; 11962306a36Sopenharmony_ci sw |= (~fp >> 41) & IEEE_TRAP_ENABLE_DNO; 12062306a36Sopenharmony_ci return sw; 12162306a36Sopenharmony_ci} 12262306a36Sopenharmony_ci 12362306a36Sopenharmony_ci 12462306a36Sopenharmony_ci#endif /* _UAPI__ASM_ALPHA_FPU_H */ 125