155111Storek /* 2*63319Sbostic * Copyright (c) 1992, 1993 3*63319Sbostic * The Regents of the University of California. All rights reserved. 455111Storek * 555111Storek * This software was developed by the Computer Systems Engineering group 655111Storek * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 755111Storek * contributed to Berkeley. 855111Storek * 955500Sbostic * All advertising materials mentioning features or use of this software 1055500Sbostic * must display the following acknowledgement: 1155500Sbostic * This product includes software developed by the University of 1259195Storek * California, Lawrence Berkeley Laboratory. 1355500Sbostic * 1455111Storek * %sccs.include.redist.c% 1555111Storek * 16*63319Sbostic * @(#)fpu_arith.h 8.1 (Berkeley) 06/11/93 1755111Storek * 1859195Storek * from: $Header: fpu_arith.h,v 1.3 92/11/26 01:30:50 torek Exp $ 1955111Storek */ 2055111Storek 2155111Storek /* 2255111Storek * Extended-precision arithmetic. 2355111Storek * 2455111Storek * We hold the notion of a `carry register', which may or may not be a 2555111Storek * machine carry bit or register. On the SPARC, it is just the machine's 2655111Storek * carry bit. 2755111Storek * 2855111Storek * In the worst case, you can compute the carry from x+y as 2955111Storek * (unsigned)(x + y) < (unsigned)x 3055111Storek * and from x+y+c as 3155111Storek * ((unsigned)(x + y + c) <= (unsigned)x && (y|c) != 0) 3255111Storek * for example. 3355111Storek */ 3455111Storek 3555111Storek /* set up for extended-precision arithemtic */ 3655111Storek #define FPU_DECL_CARRY 3755111Storek 3855111Storek /* 3955111Storek * We have three kinds of add: 4055111Storek * add with carry: r = x + y + c 4155111Storek * add (ignoring current carry) and set carry: c'r = x + y + 0 4255111Storek * add with carry and set carry: c'r = x + y + c 4355111Storek * The macros use `C' for `use carry' and `S' for `set carry'. 4455111Storek * Note that the state of the carry is undefined after ADDC and SUBC, 4555111Storek * so if all you have for these is `add with carry and set carry', 4655111Storek * that is OK. 4755111Storek * 4855111Storek * The same goes for subtract, except that we compute x - y - c. 4955111Storek * 5055111Storek * Finally, we have a way to get the carry into a `regular' variable, 5155111Storek * or set it from a value. SET_CARRY turns 0 into no-carry, nonzero 5255111Storek * into carry; GET_CARRY sets its argument to 0 or 1. 5355111Storek */ 5455111Storek #define FPU_ADDC(r, x, y) \ 5555111Storek asm volatile("addx %1,%2,%0" : "=r"(r) : "r"(x), "r"(y)) 5655111Storek #define FPU_ADDS(r, x, y) \ 5755111Storek asm volatile("addcc %1,%2,%0" : "=r"(r) : "r"(x), "r"(y)) 5855111Storek #define FPU_ADDCS(r, x, y) \ 5955111Storek asm volatile("addxcc %1,%2,%0" : "=r"(r) : "r"(x), "r"(y)) 6055111Storek #define FPU_SUBC(r, x, y) \ 6155111Storek asm volatile("subx %1,%2,%0" : "=r"(r) : "r"(x), "r"(y)) 6255111Storek #define FPU_SUBS(r, x, y) \ 6355111Storek asm volatile("subcc %1,%2,%0" : "=r"(r) : "r"(x), "r"(y)) 6455111Storek #define FPU_SUBCS(r, x, y) \ 6555111Storek asm volatile("subxcc %1,%2,%0" : "=r"(r) : "r"(x), "r"(y)) 6655111Storek 6755111Storek #define FPU_GET_CARRY(r) asm volatile("addx %%g0,%%g0,%0" : "=r"(r)) 6855111Storek #define FPU_SET_CARRY(v) asm volatile("addcc %0,-1,%%g0" : : "r"(v)) 6955111Storek 7055111Storek #define FPU_SHL1_BY_ADD /* shift left 1 faster by ADDC than (a<<1)|(b>>31) */ 71