153444Sbostic /*- 253444Sbostic * Copyright (c) 1992 The Regents of the University of California. 353444Sbostic * All rights reserved. 453444Sbostic * 553444Sbostic * %sccs.include.redist.c% 653444Sbostic */ 753444Sbostic 853444Sbostic #if defined(LIBC_SCCS) && !defined(lint) 9*53458Sbostic static char sccsid[] = "@(#)subdi3.c 5.2 (Berkeley) 05/12/92"; 1053444Sbostic #endif /* LIBC_SCCS and not lint */ 1153444Sbostic 1253444Sbostic #include "longlong.h" 1353444Sbostic 1453444Sbostic static int bsub (); 1553444Sbostic 1653444Sbostic long long 1753444Sbostic __subdi3 (u, v) 1853444Sbostic long long u, v; 1953444Sbostic { 2053444Sbostic long a[2], b[2], c[2]; 2153444Sbostic long_long w; 2253444Sbostic long_long uu, vv; 2353444Sbostic 2453444Sbostic uu.ll = u; 2553444Sbostic vv.ll = v; 2653444Sbostic 2753444Sbostic a[HIGH] = uu.s.high; 2853444Sbostic a[LOW] = uu.s.low; 2953444Sbostic b[HIGH] = vv.s.high; 3053444Sbostic b[LOW] = vv.s.low; 3153444Sbostic 3253444Sbostic bsub (a, b, c, sizeof c); 3353444Sbostic 3453444Sbostic w.s.high = c[HIGH]; 3553444Sbostic w.s.low = c[LOW]; 3653444Sbostic return w.ll; 3753444Sbostic } 3853444Sbostic 3953444Sbostic static int 4053444Sbostic bsub (a, b, c, n) 4153444Sbostic unsigned short *a, *b, *c; 42*53458Sbostic unsigned long n; 4353444Sbostic { 4453444Sbostic signed long acc; 4553444Sbostic int i; 4653444Sbostic 4753444Sbostic n /= sizeof *c; 4853444Sbostic 4953444Sbostic acc = 0; 5053444Sbostic for (i = little_end (n); is_not_msd (i, n); i = next_msd (i)) 5153444Sbostic { 5253444Sbostic /* Widen before subtracting to avoid loss of high bits. */ 5353444Sbostic acc += (long) a[i] - b[i]; 5453444Sbostic c[i] = acc & low16; 5553444Sbostic acc = acc >> 16; 5653444Sbostic } 5753444Sbostic return acc; 5853444Sbostic } 59