xref: /onnv-gate/usr/src/lib/libc/sparc/sys/gettimeofday.s (revision 7298:b69e27387f74)
10Sstevel@tonic-gate/*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
56812Sraf * Common Development and Distribution License (the "License").
66812Sraf * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
216812Sraf
226812Sraf/*
236812Sraf * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
246812Sraf * Use is subject to license terms.
256812Sraf */
266812Sraf
270Sstevel@tonic-gate/*	Copyright (c) 1988 AT&T	*/
280Sstevel@tonic-gate/*	  All Rights Reserved	*/
290Sstevel@tonic-gate
30*7298SMark.J.Nelson@Sun.COM	.file	"gettimeofday.s"
310Sstevel@tonic-gate
320Sstevel@tonic-gate/*
330Sstevel@tonic-gate * C library -- gettimeofday
340Sstevel@tonic-gate * int gettimeofday (struct timeval *tp);
350Sstevel@tonic-gate */
360Sstevel@tonic-gate
376812Sraf#include "SYS.h"
380Sstevel@tonic-gate
390Sstevel@tonic-gate	ANSI_PRAGMA_WEAK(gettimeofday,function)
400Sstevel@tonic-gate
410Sstevel@tonic-gate/*
420Sstevel@tonic-gate * The interface below calls the trap (0x27) to get the timestamp in
430Sstevel@tonic-gate * secs and nsecs. It than converts the nsecs value into usecs before
440Sstevel@tonic-gate * it returns.
450Sstevel@tonic-gate *
460Sstevel@tonic-gate * The algorithm used to perform the division by 1000 is based upon
470Sstevel@tonic-gate * algorithms for division based upon multiplication by invariant
480Sstevel@tonic-gate * integers.  Relevant sources for these algorithms are:
490Sstevel@tonic-gate *
500Sstevel@tonic-gate * Granlund, T.; Montgomery, P.L.: "Division by Invariant Integers using
510Sstevel@tonic-gate * Multiplication". SIGPLAN Notices, Vol. 29, June 1994, page 61.
520Sstevel@tonic-gate *
530Sstevel@tonic-gate * Magenheimer, D.J.; et al: "Integer Multiplication and Division on the HP
540Sstevel@tonic-gate * Precision Architecture". IEEE Transactions on Computers, Vol 37, No. 8,
550Sstevel@tonic-gate * August 1988, page 980.
560Sstevel@tonic-gate *
570Sstevel@tonic-gate * Steele G.; Warren H.: Hacker's Delight. 2002 Pearson Education, Ch 10
580Sstevel@tonic-gate *
590Sstevel@tonic-gate */
600Sstevel@tonic-gate
616812Sraf	ENTRY(gettimeofday)
620Sstevel@tonic-gate	brz,pn	%o0, 1f
630Sstevel@tonic-gate	mov	%o0, %o5
640Sstevel@tonic-gate	SYSFASTTRAP(GETHRESTIME)
650Sstevel@tonic-gate	stn	%o0, [%o5]
660Sstevel@tonic-gate	sethi	%hi(0x10624DD3), %o2
670Sstevel@tonic-gate	or	%o2, %lo(0x10624DD3), %o2
680Sstevel@tonic-gate	mulx	%o1, %o2, %o2
690Sstevel@tonic-gate	srlx	%o2, 38, %o2
700Sstevel@tonic-gate	stn	%o2, [%o5 + CLONGSIZE]
710Sstevel@tonic-gate1:	RETC
726812Sraf	SET_SIZE(gettimeofday)
73