1 /* 2 * Copyright (c) 1992 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * This software was developed by the Computer Systems Engineering group 6 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 7 * contributed to Berkeley. 8 * 9 * %sccs.include.redist.c% 10 * 11 * @(#)fpu_arith.h 7.1 (Berkeley) 07/13/92 12 * 13 * from: $Header: fpu_arith.h,v 1.2 92/06/17 05:41:28 torek Exp $ 14 */ 15 16 /* 17 * Extended-precision arithmetic. 18 * 19 * We hold the notion of a `carry register', which may or may not be a 20 * machine carry bit or register. On the SPARC, it is just the machine's 21 * carry bit. 22 * 23 * In the worst case, you can compute the carry from x+y as 24 * (unsigned)(x + y) < (unsigned)x 25 * and from x+y+c as 26 * ((unsigned)(x + y + c) <= (unsigned)x && (y|c) != 0) 27 * for example. 28 */ 29 30 /* set up for extended-precision arithemtic */ 31 #define FPU_DECL_CARRY 32 33 /* 34 * We have three kinds of add: 35 * add with carry: r = x + y + c 36 * add (ignoring current carry) and set carry: c'r = x + y + 0 37 * add with carry and set carry: c'r = x + y + c 38 * The macros use `C' for `use carry' and `S' for `set carry'. 39 * Note that the state of the carry is undefined after ADDC and SUBC, 40 * so if all you have for these is `add with carry and set carry', 41 * that is OK. 42 * 43 * The same goes for subtract, except that we compute x - y - c. 44 * 45 * Finally, we have a way to get the carry into a `regular' variable, 46 * or set it from a value. SET_CARRY turns 0 into no-carry, nonzero 47 * into carry; GET_CARRY sets its argument to 0 or 1. 48 */ 49 #define FPU_ADDC(r, x, y) \ 50 asm volatile("addx %1,%2,%0" : "=r"(r) : "r"(x), "r"(y)) 51 #define FPU_ADDS(r, x, y) \ 52 asm volatile("addcc %1,%2,%0" : "=r"(r) : "r"(x), "r"(y)) 53 #define FPU_ADDCS(r, x, y) \ 54 asm volatile("addxcc %1,%2,%0" : "=r"(r) : "r"(x), "r"(y)) 55 #define FPU_SUBC(r, x, y) \ 56 asm volatile("subx %1,%2,%0" : "=r"(r) : "r"(x), "r"(y)) 57 #define FPU_SUBS(r, x, y) \ 58 asm volatile("subcc %1,%2,%0" : "=r"(r) : "r"(x), "r"(y)) 59 #define FPU_SUBCS(r, x, y) \ 60 asm volatile("subxcc %1,%2,%0" : "=r"(r) : "r"(x), "r"(y)) 61 62 #define FPU_GET_CARRY(r) asm volatile("addx %%g0,%%g0,%0" : "=r"(r)) 63 #define FPU_SET_CARRY(v) asm volatile("addcc %0,-1,%%g0" : : "r"(v)) 64 65 #define FPU_SHL1_BY_ADD /* shift left 1 faster by ADDC than (a<<1)|(b>>31) */ 66