xref: /titanic_44/usr/src/lib/libc/sparc/sys/gettimeofday.s (revision 1e49577a7fcde812700ded04431b49d67cc57d6d)
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	.file	"gettimeofday.s"
31
32/*
33 * C library -- gettimeofday
34 * int gettimeofday (struct timeval *tp);
35 */
36
37#include "SYS.h"
38
39	ANSI_PRAGMA_WEAK(gettimeofday,function)
40
41/*
42 * The interface below calls the trap (0x27) to get the timestamp in
43 * secs and nsecs. It than converts the nsecs value into usecs before
44 * it returns.
45 *
46 * The algorithm used to perform the division by 1000 is based upon
47 * algorithms for division based upon multiplication by invariant
48 * integers.  Relevant sources for these algorithms are:
49 *
50 * Granlund, T.; Montgomery, P.L.: "Division by Invariant Integers using
51 * Multiplication". SIGPLAN Notices, Vol. 29, June 1994, page 61.
52 *
53 * Magenheimer, D.J.; et al: "Integer Multiplication and Division on the HP
54 * Precision Architecture". IEEE Transactions on Computers, Vol 37, No. 8,
55 * August 1988, page 980.
56 *
57 * Steele G.; Warren H.: Hacker's Delight. 2002 Pearson Education, Ch 10
58 *
59 */
60
61	ENTRY(gettimeofday)
62	brz,pn	%o0, 1f
63	mov	%o0, %o5
64	SYSFASTTRAP(GETHRESTIME)
65	stn	%o0, [%o5]
66	sethi	%hi(0x10624DD3), %o2
67	or	%o2, %lo(0x10624DD3), %o2
68	mulx	%o1, %o2, %o2
69	srlx	%o2, 38, %o2
70	stn	%o2, [%o5 + CLONGSIZE]
711:	RETC
72	SET_SIZE(gettimeofday)
73