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