/*1* fp_emu.h2*3* Copyright Roman Zippel, 1997. All rights reserved.4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions7* are met:8* 1. Redistributions of source code must retain the above copyright9* notice, and the entire permission notice in its entirety,10* including the disclaimer of warranties.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14* 3. The name of the author may not be used to endorse or promote15* products derived from this software without specific prior16* written permission.17*18* ALTERNATIVELY, this product may be distributed under the terms of19* the GNU General Public License, in which case the provisions of the GPL are20* required INSTEAD OF the above restrictions. (This clause is21* necessary due to a potential bad interaction between the GPL and22* the restrictions contained in a BSD-style copyright.)23*24* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED25* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES26* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE27* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,28* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES29* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR30* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)31* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,32* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)33* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED34* OF THE POSSIBILITY OF SUCH DAMAGE.35*/3637#ifndef _FP_EMU_H38#define _FP_EMU_H3940#ifdef __ASSEMBLY__41#include <asm/asm-offsets.h>42#endif43#include <asm/math-emu.h>4445#ifndef __ASSEMBLY__4647#define IS_INF(a) ((a)->exp == 0x7fff)48#define IS_ZERO(a) ((a)->mant.m64 == 0)495051#define fp_set_sr(bit) ({ \52FPDATA->fpsr |= 1 << (bit); \53})5455#define fp_set_quotient(quotient) ({ \56FPDATA->fpsr &= 0xff00ffff; \57FPDATA->fpsr |= ((quotient) & 0xff) << 16; \58})5960/* linkage for several useful functions */6162/* Normalize the extended struct, return 0 for a NaN */63#define fp_normalize_ext(fpreg) ({ \64register struct fp_ext *reg asm ("a0") = fpreg; \65register int res asm ("d0"); \66\67asm volatile ("jsr fp_conv_ext2ext" \68: "=d" (res) : "a" (reg) \69: "a1", "d1", "d2", "memory"); \70res; \71})7273#define fp_copy_ext(dest, src) ({ \74*dest = *src; \75})7677#define fp_monadic_check(dest, src) ({ \78fp_copy_ext(dest, src); \79if (!fp_normalize_ext(dest)) \80return dest; \81})8283#define fp_dyadic_check(dest, src) ({ \84if (!fp_normalize_ext(dest)) \85return dest; \86if (!fp_normalize_ext(src)) { \87fp_copy_ext(dest, src); \88return dest; \89} \90})9192extern const struct fp_ext fp_QNaN;93extern const struct fp_ext fp_Inf;9495#define fp_set_nan(dest) ({ \96fp_set_sr(FPSR_EXC_OPERR); \97*dest = fp_QNaN; \98})99100/* TODO check rounding mode? */101#define fp_set_ovrflw(dest) ({ \102fp_set_sr(FPSR_EXC_OVFL); \103dest->exp = 0x7fff; \104dest->mant.m64 = 0; \105})106107#define fp_conv_ext2long(src) ({ \108register struct fp_ext *__src asm ("a0") = src; \109register int __res asm ("d0"); \110\111asm volatile ("jsr fp_conv_ext2long" \112: "=d" (__res) : "a" (__src) \113: "a1", "d1", "d2", "memory"); \114__res; \115})116117#define fp_conv_long2ext(dest, src) ({ \118register struct fp_ext *__dest asm ("a0") = dest; \119register int __src asm ("d0") = src; \120\121asm volatile ("jsr fp_conv_ext2long" \122: : "d" (__src), "a" (__dest) \123: "a1", "d1", "d2", "memory"); \124})125126#else /* __ASSEMBLY__ */127128/*129* set, reset or clear a bit in the fp status register130*/131.macro fp_set_sr bit132bset #(\bit&7),(FPD_FPSR+3-(\bit/8),FPDATA)133.endm134135.macro fp_clr_sr bit136bclr #(\bit&7),(FPD_FPSR+3-(\bit/8),FPDATA)137.endm138139.macro fp_tst_sr bit140btst #(\bit&7),(FPD_FPSR+3-(\bit/8),FPDATA)141.endm142143#endif /* __ASSEMBLY__ */144145#endif /* _FP_EMU_H */146147148