📄 gnulib2.c
字号:
/* More subroutines needed by GCC output code on some machines. *//* Compile this one with gcc. */#include "config.h"#include <stddef.h>/* Don't use `fancy_abort' here even if config.h says to use it. */#ifdef abort#undef abort#endif#ifndef SItype#define SItype long int#endif/* long long ints are pairs of long ints in the order determined by WORDS_BIG_ENDIAN. */#ifdef WORDS_BIG_ENDIAN struct longlong {long high, low;};#else struct longlong {long low, high;};#endif/* We need this union to unpack/pack longlongs, since we don't have any arithmetic yet. Incoming long long parameters are stored into the `ll' field, and the unpacked result is read from the struct longlong. */typedef union{ struct longlong s; long long ll; SItype i[2]; unsigned SItype ui[2];} long_long;/* Internally, long long ints are strings of unsigned shorts in the order determined by BYTES_BIG_ENDIAN. */#define B 0x10000#define low16 (B - 1)#ifdef BYTES_BIG_ENDIAN/* Note that HIGH and LOW do not describe the order of words in a long long. They describe the order of words in vectors ordered according to the byte order. */#define HIGH 0#define LOW 1#define big_end(n) 0 #define little_end(n) ((n) - 1)#define next_msd(i) ((i) - 1)#define next_lsd(i) ((i) + 1)#define is_not_msd(i,n) ((i) >= 0)#define is_not_lsd(i,n) ((i) < (n))#else#define LOW 0#define HIGH 1#define big_end(n) ((n) - 1)#define little_end(n) 0 #define next_msd(i) ((i) + 1)#define next_lsd(i) ((i) - 1)#define is_not_msd(i,n) ((i) < (n))#define is_not_lsd(i,n) ((i) >= 0)#endif/* These algorithms are all straight out of Knuth, vol. 2, sec. 4.3.1. */static int badd ();static int bsub ();static void bmul ();static int bneg ();static int bshift ();#ifdef L_adddi3long long __adddi3 (u, v) long long u, v;{ long a[2], b[2], c[2]; long_long w; long_long uu, vv; uu.ll = u; vv.ll = v; a[HIGH] = uu.s.high; a[LOW] = uu.s.low; b[HIGH] = vv.s.high; b[LOW] = vv.s.low; badd (a, b, c, sizeof c); w.s.high = c[HIGH]; w.s.low = c[LOW]; return w.ll;}static int badd (a, b, c, n) unsigned short *a, *b, *c; size_t n;{ unsigned long acc; int i; n /= sizeof *c; acc = 0; for (i = little_end (n); is_not_msd (i, n); i = next_msd (i)) { /* Widen before adding to avoid loss of high bits. */ acc += (unsigned long) a[i] + b[i]; c[i] = acc & low16; acc = acc >> 16; } return acc;}#endif#ifdef L_anddi3long long __anddi3 (u, v) long long u, v;{ long_long w; long_long uu, vv; uu.ll = u; vv.ll = v; w.s.high = uu.s.high & vv.s.high; w.s.low = uu.s.low & vv.s.low; return w.ll;}#endif#ifdef L_iordi3long long __iordi3 (u, v) long long u, v;{ long_long w; long_long uu, vv; uu.ll = u; vv.ll = v; w.s.high = uu.s.high | vv.s.high; w.s.low = uu.s.low | vv.s.low; return w.ll;}#endif#ifdef L_xordi3long long __xordi3 (u, v) long long u, v;{ long_long w; long_long uu, vv; uu.ll = u; vv.ll = v; w.s.high = uu.s.high ^ vv.s.high; w.s.low = uu.s.low ^ vv.s.low; return w.ll;}#endif#ifdef L_one_cmpldi2long long__one_cmpldi2 (u) long long u;{ long_long w; long_long uu; uu.ll = u; w.s.high = ~uu.s.high; w.s.low = ~uu.s.low; return w.ll;}#endif#ifdef L_lshldi3long long__lshldi3 (u, b1) long long u; long long b1;{ long_long w; unsigned long carries; int bm; long_long uu; int b = b1; if (b == 0) return u; uu.ll = u; bm = (sizeof (int) * BITS_PER_UNIT) - b; if (bm <= 0) { w.s.low = 0; w.s.high = (unsigned long)uu.s.low << -bm; } else { carries = (unsigned long)uu.s.low >> bm; w.s.low = (unsigned long)uu.s.low << b; w.s.high = ((unsigned long)uu.s.high << b) | carries; } return w.ll;}#endif#ifdef L_lshrdi3long long__lshrdi3 (u, b1) long long u; long long b1;{ long_long w; unsigned long carries; int bm; long_long uu; int b = b1; if (b == 0) return u; uu.ll = u; bm = (sizeof (int) * BITS_PER_UNIT) - b; if (bm <= 0) { w.s.high = 0; w.s.low = (unsigned long)uu.s.high >> -bm; } else { carries = (unsigned long)uu.s.high << bm; w.s.high = (unsigned long)uu.s.high >> b; w.s.low = ((unsigned long)uu.s.low >> b) | carries; } return w.ll;}#endif#ifdef L_ashldi3long long__ashldi3 (u, b1) long long u; long long b1;{ long_long w; unsigned long carries; int bm; long_long uu; int b = b1; if (b == 0) return u; uu.ll = u; bm = (sizeof (int) * BITS_PER_UNIT) - b; if (bm <= 0) { w.s.low = 0; w.s.high = (unsigned long)uu.s.low << -bm; } else { carries = (unsigned long)uu.s.low >> bm; w.s.low = (unsigned long)uu.s.low << b; w.s.high = ((unsigned long)uu.s.high << b) | carries; } return w.ll;}#endif#ifdef L_ashrdi3long long__ashrdi3 (u, b1) long long u; long long b1;{ long_long w; unsigned long carries; int bm; long_long uu; int b = b1; if (b == 0) return u; uu.ll = u; bm = (sizeof (int) * BITS_PER_UNIT) - b; if (bm <= 0) { w.s.high = uu.s.high >> 31; /* just to make w.s.high 1..1 or 0..0 */ w.s.low = uu.s.high >> -bm; } else { carries = (unsigned long)uu.s.high << bm; w.s.high = uu.s.high >> b; w.s.low = ((unsigned long)uu.s.low >> b) | carries; } return w.ll;}#endif#ifdef L_subdi3long long __subdi3 (u, v) long long u, v;{ long a[2], b[2], c[2]; long_long w; long_long uu, vv; uu.ll = u; vv.ll = v; a[HIGH] = uu.s.high; a[LOW] = uu.s.low; b[HIGH] = vv.s.high; b[LOW] = vv.s.low; bsub (a, b, c, sizeof c); w.s.high = c[HIGH]; w.s.low = c[LOW]; return w.ll;}static int bsub (a, b, c, n) unsigned short *a, *b, *c; size_t n;{ signed long acc; int i; n /= sizeof *c; acc = 0; for (i = little_end (n); is_not_msd (i, n); i = next_msd (i)) { /* Widen before subtracting to avoid loss of high bits. */ acc += (long) a[i] - b[i]; c[i] = acc & low16; acc = acc >> 16; } return acc;}#endif#ifdef L_muldi3long long __muldi3 (u, v) long long u, v;{ long a[2], b[2], c[2][2]; long_long w; long_long uu, vv; uu.ll = u; vv.ll = v; a[HIGH] = uu.s.high; a[LOW] = uu.s.low; b[HIGH] = vv.s.high; b[LOW] = vv.s.low; bmul (a, b, c, sizeof a, sizeof b); w.s.high = c[LOW][HIGH]; w.s.low = c[LOW][LOW]; return w.ll;}static void bmul (a, b, c, m, n) unsigned short *a, *b, *c; size_t m, n;{ int i, j; unsigned long acc; bzero (c, m + n); m /= sizeof *a; n /= sizeof *b; for (j = little_end (n); is_not_msd (j, n); j = next_msd (j)) { unsigned short *c1 = c + j + little_end (2); acc = 0; for (i = little_end (m); is_not_msd (i, m); i = next_msd (i)) { /* Widen before arithmetic to avoid loss of high bits. */ acc += (unsigned long) a[i] * b[j] + c1[i]; c1[i] = acc & low16; acc = acc >> 16; } c1[i] = acc; }}#endif#ifdef L_divdi3long long__divdi3 (u, v) long long u, v;{ if (u < 0) if (v < 0) return (unsigned long long) -u / (unsigned long long) -v; else return - ((unsigned long long) -u / (unsigned long long) v); else if (v < 0) return - ((unsigned long long) u / (unsigned long long) -v); else return (unsigned long long) u / (unsigned long long) v;}#endif#ifdef L_moddi3long long__moddi3 (u, v) long long u, v;{ if (u < 0) if (v < 0) return - ((unsigned long long) -u % (unsigned long long) -v); else return - ((unsigned long long) -u % (unsigned long long) v); else if (v < 0) return (unsigned long long) u % (unsigned long long) -v; else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -