1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 /* Copyright (c) 1988 AT&T */
28 /* All Rights Reserved */
29
30 /*
31 * This set of routines used to be implemented mostly in assembler.
32 *
33 * Since the purpose they have is now rather vestigial, and 64-bit
34 * machines can do operations on 64-bit quantities pretty efficiently,
35 * a C implementation seems quite adequate and much more maintainable.
36 */
37
38 #include "lint.h"
39 #include <sys/types.h>
40 #include <sys/dl.h>
41
42 typedef union {
43 long xword;
44 dl_t dl;
45 } dlx_t;
46
47 dl_t
ladd(dl_t lop,dl_t rop)48 ladd(dl_t lop, dl_t rop)
49 {
50 dlx_t r;
51 /* LINTED pointer cast may result in improper alignment */
52 r.xword = *(long *)&lop + *(long *)&rop;
53 return (r.dl);
54 }
55
56 dl_t
lshiftl(dl_t op,int cnt)57 lshiftl(dl_t op, int cnt)
58 {
59 dlx_t r;
60 if (cnt < 0)
61 /* LINTED pointer cast may result in improper alignment */
62 r.xword = (long)(*(ulong_t *)&op >> (-cnt));
63 else
64 /* LINTED pointer cast may result in improper alignment */
65 r.xword = *(long *)&op << cnt;
66 return (r.dl);
67 }
68
69 int
lsign(dl_t op)70 lsign(dl_t op)
71 {
72 /* LINTED pointer cast may result in improper alignment */
73 return ((*(long *)&op) >> 63);
74 }
75
76 dl_t
lsub(dl_t lop,dl_t rop)77 lsub(dl_t lop, dl_t rop)
78 {
79 dlx_t r;
80 /* LINTED pointer cast may result in improper alignment */
81 r.xword = *(long *)&lop - *(long *)&rop;
82 return (r.dl);
83 }
84
85 dl_t
lmul(dl_t lop,dl_t rop)86 lmul(dl_t lop, dl_t rop)
87 {
88 dlx_t r;
89 /* LINTED pointer cast may result in improper alignment */
90 r.xword = *(long *)&lop * *(long *)&rop;
91 return (r.dl);
92 }
93