summaryrefslogtreecommitdiff
path: root/dviware/beebe/src/00arit.c
blob: 91fa6ccda344d9c7a9e4fa69cd63df6c988ff87d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/***********************************************************************
Test properties  of the  host arithmetic,  and determine  whether  right
shifts propagate the sign bit.  This should be run three times:

	cc -DSIZE=short 00arit.c
	cc -DSIZE=int   00arit.c
	cc -DSIZE=long  00arit.c

[11-Apr-87]
***********************************************************************/
#include <stdio.h>

#ifndef SIZE
#define SIZE int
#endif

typedef          SIZE  INT;
typedef unsigned SIZE UINT;

UINT store();
void store2();

main()
{
    int wordsize;
    int k;
    UINT mask;
    INT s;
    UINT u;

    s = ~0;
    if (s == 0)
	(void)printf("One's complement host arithmetic\n\n");
    else if (s == -1)
	(void)printf("Two's complement host arithmetic\n\n");
    else
	(void)printf("Unrecognized host arithmetic architecture\n\n");

    mask = 1;
    wordsize = 1;
    s = (INT)mask;
    while ((store(mask << 1) != 0) && (wordsize < 129))
    {
	 mask = store(mask << 1);
	 s = (INT)mask;
	 wordsize++;
    }
    if (wordsize > 128)
    {
	(void)printf(
	"Something looks wrong--host has more than %d bits in an integer!\n\n",
	    wordsize);
	exit(1);
    }
    else
	(void)printf("There are %d bits in an integer\n\n",wordsize);

    (void)printf("Test of right-shift of signed integer\n");
    s = (INT)mask;
    for (k = 0; k <= wordsize; ++k)
    {
	(void)printf("      (int)0x%lx >> %2d = %lx\n",
		(long)mask,k,(long)((INT)(s>>k)));
    }
    (void)printf("\n\n\n");

    (void)printf("Test of right-shift of unsigned integer\n");
    u = (UINT)mask;
    for (k = 0; k <= wordsize; ++k)
    {
	(void)printf(" (unsigned)0x%lx >> %2d = %lx\n",
		(long)((unsigned)mask),k,(long)((UINT)(u>>k)));
    }
    exit(0);
}

static INT word;

UINT
store(u)				/* force memory store */
UINT u;
{
    word = u;				/* store k globally */
    store2();				/* possibly change it */
    return (word);			/* return changed value */
}

void
store2()
{
    word = word;
}