1*eb7c1594Sagc /* $NetBSD: mul.c,v 1.4 2003/08/07 16:43:19 agc Exp $ */
2d48964d4Scgd
3edfa8336Scgd /*-
4edfa8336Scgd * Copyright (c) 1992, 1993
5edfa8336Scgd * The Regents of the University of California. All rights reserved.
6edfa8336Scgd *
7edfa8336Scgd * This software was developed by the Computer Systems Engineering group
8edfa8336Scgd * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9edfa8336Scgd * contributed to Berkeley.
10edfa8336Scgd *
11edfa8336Scgd * Redistribution and use in source and binary forms, with or without
12edfa8336Scgd * modification, are permitted provided that the following conditions
13edfa8336Scgd * are met:
14edfa8336Scgd * 1. Redistributions of source code must retain the above copyright
15edfa8336Scgd * notice, this list of conditions and the following disclaimer.
16edfa8336Scgd * 2. Redistributions in binary form must reproduce the above copyright
17edfa8336Scgd * notice, this list of conditions and the following disclaimer in the
18edfa8336Scgd * documentation and/or other materials provided with the distribution.
19*eb7c1594Sagc * 3. Neither the name of the University nor the names of its contributors
20edfa8336Scgd * may be used to endorse or promote products derived from this software
21edfa8336Scgd * without specific prior written permission.
22edfa8336Scgd *
23edfa8336Scgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24edfa8336Scgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25edfa8336Scgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26edfa8336Scgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27edfa8336Scgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28edfa8336Scgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29edfa8336Scgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30edfa8336Scgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31edfa8336Scgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32edfa8336Scgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33edfa8336Scgd * SUCH DAMAGE.
34edfa8336Scgd */
35edfa8336Scgd
36edfa8336Scgd #ifndef lint
37edfa8336Scgd static char copyright[] =
38edfa8336Scgd "@(#) Copyright (c) 1992, 1993\n\
39edfa8336Scgd The Regents of the University of California. All rights reserved.\n";
40edfa8336Scgd #endif /* not lint */
41edfa8336Scgd
42edfa8336Scgd #ifndef lint
43d48964d4Scgd #if 0
44edfa8336Scgd static char sccsid[] = "@(#)mul.c 8.1 (Berkeley) 6/4/93";
45d48964d4Scgd #else
46*eb7c1594Sagc static char rcsid[] = "$NetBSD: mul.c,v 1.4 2003/08/07 16:43:19 agc Exp $";
47d48964d4Scgd #endif
48edfa8336Scgd #endif /* not lint */
49edfa8336Scgd
50edfa8336Scgd #include <stdio.h>
51edfa8336Scgd
main()52edfa8336Scgd main()
53edfa8336Scgd {
5437b34d51Sscw union { long long q; unsigned int v[2]; } a, b, m;
55edfa8336Scgd char buf[300];
56edfa8336Scgd extern long long __muldi3(long long, long long);
57edfa8336Scgd
58edfa8336Scgd for (;;) {
59edfa8336Scgd printf("> ");
60edfa8336Scgd if (fgets(buf, sizeof buf, stdin) == NULL)
61edfa8336Scgd break;
6237b34d51Sscw if (sscanf(buf, "%u:%u %u:%u",
63edfa8336Scgd &a.v[0], &a.v[1], &b.v[0], &b.v[1]) != 4 &&
6437b34d51Sscw sscanf(buf, "0x%x:%x 0x%x:%x",
65edfa8336Scgd &a.v[0], &a.v[1], &b.v[0], &b.v[1]) != 4) {
66edfa8336Scgd printf("eh?\n");
67edfa8336Scgd continue;
68edfa8336Scgd }
69edfa8336Scgd m.q = __muldi3(a.q, b.q);
7037b34d51Sscw printf("%x:%x * %x:%x => %x:%x\n",
71edfa8336Scgd a.v[0], a.v[1], b.v[0], b.v[1], m.v[0], m.v[1]);
7237b34d51Sscw printf(" = %X%08X * %X%08X => %X%08X\n",
73edfa8336Scgd a.v[0], a.v[1], b.v[0], b.v[1], m.v[0], m.v[1]);
74edfa8336Scgd }
75edfa8336Scgd exit(0);
76edfa8336Scgd }
77