Add even more of the source
This should be about everything needed to build so far?
This commit is contained in:
parent
af3619d4fa
commit
849723c9cf
547 changed files with 149239 additions and 0 deletions
139
AtomicLib/README
Normal file
139
AtomicLib/README
Normal file
|
@ -0,0 +1,139 @@
|
|||
/* --- Version 4.0 --- 12-Feb-1999 --- */
|
||||
/*
|
||||
* Include the following routines :
|
||||
* atomic_or()
|
||||
* scaledtimestamp()
|
||||
*
|
||||
* Updated the copyright.
|
||||
*/
|
||||
|
||||
/*
|
||||
* unsigned int atomic_or(unsigned int *area, unsigned int mask)
|
||||
*
|
||||
* Atomically or the mask into *area.
|
||||
* Returns the old value.
|
||||
*/
|
||||
/*
|
||||
* long long scaledtimestamp(double scale)
|
||||
*
|
||||
* Read the PPC timebase. Convert the time base value based on
|
||||
* scale.
|
||||
*
|
||||
* Caveat: scale can not be 0, NaN, Inf. It's upto the caller
|
||||
* to validate scale before calling this.
|
||||
*/
|
||||
|
||||
/* --- Version 3.0 --- 23-Oct-1998 --- */
|
||||
/*
|
||||
* Made the headers c++ friendly
|
||||
* Build a static library with dynamic code generation.
|
||||
* If you make a copy of the libatomic.a do not forget to run "ranlib".
|
||||
*/
|
||||
|
||||
/* --- Version 2.0 --- 23-Oct-1998 --- */
|
||||
/*
|
||||
* Added routines described in timestamp.h
|
||||
* Test program for these is in hmi.c
|
||||
*/
|
||||
|
||||
/* --- Version 1.0 --- 12-Oct-1998 --- */
|
||||
/*
|
||||
* void spin_lock_init(spin_lock_t)
|
||||
*
|
||||
* Initialize a spin lock.
|
||||
* These locks should be cache aligned and a multiple of cache size.
|
||||
*/
|
||||
|
||||
/*
|
||||
* void spin_lock_unlock(spin_lock_t)
|
||||
*
|
||||
* Unconditionally release lock.
|
||||
*/
|
||||
|
||||
/*
|
||||
* unsigned int spin_lock_lock(spin_lock_t)
|
||||
*
|
||||
* Try to acquire spin-lock. Return success (1).
|
||||
*/
|
||||
|
||||
/*
|
||||
* unsigned int spin_lock_bit(spin_lock_t, unsigned int bits)
|
||||
*
|
||||
* Try to acquire spin-lock. The second parameter is the bit mask to
|
||||
* test and set. multiple bits may be set.
|
||||
* Return success (1).
|
||||
*/
|
||||
|
||||
/*
|
||||
* unsigned int spin_unlock_bit(spin_lock_t, unsigned int bits)
|
||||
*
|
||||
* Release bit based spin-lock. The second parameter is the bit mask to
|
||||
* clear. Multiple bits may be cleared.
|
||||
*/
|
||||
|
||||
/*
|
||||
* unsigned int spin_lock_try(spin_lock_t)
|
||||
*
|
||||
* Try to acquire spin-lock. Return success (1) or failure (0).
|
||||
*/
|
||||
|
||||
/*
|
||||
* unsigned int spin_lock_held(spin_lock_t)
|
||||
*
|
||||
* Return 1 if lock is held
|
||||
* N.B. Racy, of course.
|
||||
*/
|
||||
|
||||
/*
|
||||
* unsigned int compare_and_store(unsigned int oval,
|
||||
* unsigned int nval, unsigned int *area)
|
||||
*
|
||||
* Compare oval to area if equal, store nval, and return true
|
||||
* else return false and no store
|
||||
* This is an atomic operation
|
||||
*/
|
||||
|
||||
/*
|
||||
* unsigned int atomic_add(unsigned int *area, int val)
|
||||
*
|
||||
* Atomically add the second parameter to the first.
|
||||
* Returns the result.
|
||||
*/
|
||||
|
||||
/*
|
||||
* unsigned int atomic_sub(unsigned int *area, int val)
|
||||
*
|
||||
* Atomically subtract the second parameter from the first.
|
||||
* Returns the result.
|
||||
*/
|
||||
|
||||
/*
|
||||
* void queue_atomic(unsigned int * anchor,
|
||||
* unsigned int * elem, unsigned int disp)
|
||||
*
|
||||
* Atomically inserts the element at the head of the list
|
||||
* anchor is the pointer to the first element
|
||||
* element is the pointer to the element to insert
|
||||
* disp is the displacement into the element to the chain pointer
|
||||
*/
|
||||
|
||||
/*
|
||||
* void queue_atomic_list(unsigned int * anchor,
|
||||
* unsigned int * first, unsigned int * last,
|
||||
* unsigned int disp)
|
||||
*
|
||||
* Atomically inserts the list of elements at the head of the list
|
||||
* anchor is the pointer to the first element
|
||||
* first is the pointer to the first element to insert
|
||||
* last is the pointer to the last element to insert
|
||||
* disp is the displacement into the element to the chain pointer
|
||||
*/
|
||||
|
||||
/*
|
||||
* unsigned int *dequeue_atomic(unsigned int *anchor, unsigned int disp)
|
||||
*
|
||||
* Atomically removes the first element in a list and returns it.
|
||||
* anchor is the pointer to the first element
|
||||
* disp is the displacement into the element to the chain pointer
|
||||
* Returns element if found, 0 if empty.
|
||||
*/
|
97
AtomicLib/atomic.h
Normal file
97
AtomicLib/atomic.h
Normal file
|
@ -0,0 +1,97 @@
|
|||
/*
|
||||
* Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
|
||||
*
|
||||
* @APPLE_LICENSE_HEADER_START@
|
||||
*
|
||||
* Copyright (c) 1999-2008 Apple Inc. All Rights Reserved.
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original Code
|
||||
* as defined in and that are subject to the Apple Public Source License
|
||||
* Version 2.0 (the 'License'). You may not use this file except in
|
||||
* compliance with the License. Please obtain a copy of the License at
|
||||
* http://www.opensource.apple.com/apsl/ and read it before using this
|
||||
* file.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
|
||||
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
|
||||
* Please see the License for the specific language governing rights and
|
||||
* limitations under the License.
|
||||
*
|
||||
* @APPLE_LICENSE_HEADER_END@
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* History:
|
||||
* 11-Feb-1999 Umesh Vaishampayan (umeshv@apple.com)
|
||||
* Added atomic_or().
|
||||
*
|
||||
* 26-Oct-1998 Umesh Vaishampayan (umeshv@apple.com)
|
||||
* Made the header c++ friendly.
|
||||
*
|
||||
* 12-Oct-1998 Umesh Vaishampayan (umeshv@apple.com)
|
||||
* Changed simple_ to spin_ so as to coexist with cthreads till
|
||||
* the merge to the system framework.
|
||||
*
|
||||
* 8-Oct-1998 Umesh Vaishampayan (umeshv@apple.com)
|
||||
* Created from the kernel code to be in a dynamic shared library.
|
||||
* Kernel code created by: Bill Angell (angell@apple.com)
|
||||
*/
|
||||
|
||||
#ifndef _ATOMIC_H_
|
||||
#define _ATOMIC_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Locking routines */
|
||||
|
||||
struct spin_lock { /* sizeof cache line */
|
||||
unsigned int lock_data;
|
||||
unsigned int pad[7];
|
||||
};
|
||||
|
||||
typedef struct spin_lock *spin_lock_t;
|
||||
|
||||
extern void spin_lock_init(spin_lock_t);
|
||||
|
||||
extern void spin_lock_unlock(spin_lock_t);
|
||||
|
||||
extern unsigned int spin_lock_lock(spin_lock_t);
|
||||
|
||||
extern unsigned int spin_lock_bit(spin_lock_t, unsigned int bits);
|
||||
|
||||
extern unsigned int spin_unlock_bit(spin_lock_t, unsigned int bits);
|
||||
|
||||
extern unsigned int spin_lock_try(spin_lock_t);
|
||||
|
||||
extern unsigned int spin_lock_held(spin_lock_t);
|
||||
|
||||
/* Other atomic routines */
|
||||
|
||||
extern unsigned int compare_and_store(unsigned int oval,
|
||||
unsigned int nval, unsigned int *area);
|
||||
|
||||
extern unsigned int atomic_add(unsigned int *area, int val);
|
||||
|
||||
extern unsigned int atomic_or(unsigned int *area, unsigned int mask);
|
||||
|
||||
extern unsigned int atomic_sub(unsigned int *area, int val);
|
||||
|
||||
extern void queue_atomic(unsigned int *anchor,
|
||||
unsigned int *elem, unsigned int disp);
|
||||
|
||||
extern void queue_atomic_list(unsigned int *anchor,
|
||||
unsigned int *first, unsigned int *last,
|
||||
unsigned int disp);
|
||||
|
||||
extern unsigned int *dequeue_atomic(unsigned int *anchor, unsigned int disp);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _ATOMIC_H_ */
|
304
AtomicLib/atomic_subr.s
Normal file
304
AtomicLib/atomic_subr.s
Normal file
|
@ -0,0 +1,304 @@
|
|||
/*
|
||||
*
|
||||
* @APPLE_LICENSE_HEADER_START@
|
||||
*
|
||||
* Copyright (c) 1999-2008 Apple Inc. All Rights Reserved.
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original Code
|
||||
* as defined in and that are subject to the Apple Public Source License
|
||||
* Version 2.0 (the 'License'). You may not use this file except in
|
||||
* compliance with the License. Please obtain a copy of the License at
|
||||
* http://www.opensource.apple.com/apsl/ and read it before using this
|
||||
* file.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
|
||||
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
|
||||
* Please see the License for the specific language governing rights and
|
||||
* limitations under the License.
|
||||
*
|
||||
* @APPLE_LICENSE_HEADER_END@
|
||||
*
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* File: atomic_subr.s
|
||||
*
|
||||
* History:
|
||||
* 11-Feb-1999 Umesh Vaishampayan (umeshv@apple.com)
|
||||
* Added atomic_or().
|
||||
*
|
||||
* 12-Oct-1998 Umesh Vaishampayan (umeshv@apple.com)
|
||||
* Changed simple_ to spin_ so as to coexist with cthreads till
|
||||
* the merge to the system framework.
|
||||
*
|
||||
* 8-Oct-1998 Umesh Vaishampayan (umeshv@apple.com)
|
||||
* Created from the kernel code to be in a dynamic shared library.
|
||||
* Kernel code created by: Bill Angell (angell@apple.com)
|
||||
*/
|
||||
|
||||
#include <architecture/ppc/asm_help.h>
|
||||
|
||||
/*
|
||||
* void spin_lock_init(spin_lock_t)
|
||||
*
|
||||
* Initialize a spin lock.
|
||||
* These locks should be cache aligned and a multiple of cache size.
|
||||
*/
|
||||
LEAF(_spin_lock_init)
|
||||
li r0, 0 /* set lock to free == 0 */
|
||||
stw r0, 0(r3) /* Initialize the lock */
|
||||
blr
|
||||
|
||||
/*
|
||||
* void spin_lock_unlock(spin_lock_t)
|
||||
*
|
||||
* Unconditionally release lock.
|
||||
*/
|
||||
LEAF(_spin_lock_unlock)
|
||||
sync /* Flush writes done under lock */
|
||||
li r0, 0 /* set lock to free */
|
||||
stw r0, 0(r3)
|
||||
blr
|
||||
|
||||
/*
|
||||
* unsigned int spin_lock_lock(spin_lock_t)
|
||||
*
|
||||
* Try to acquire spin-lock. Return success (1).
|
||||
*/
|
||||
LEAF(_spin_lock_lock)
|
||||
mr r5,r3 /* Get the address of the lock */
|
||||
|
||||
Lcktry:
|
||||
lwarx r6,0,r5 /* Grab the lock value */
|
||||
li r3,1 /* Set the return value */
|
||||
mr. r6,r6 /* Is it locked? */
|
||||
bne- Lcksniff /* Yeah, wait for it to clear... */
|
||||
stwcx. r3,0,r5 /* Try to sieze that darn lock */
|
||||
beq+ Lckgot /* We got it, yahoo... */
|
||||
b Lcktry /* Try again if the store failed... */
|
||||
|
||||
Lcksniff:
|
||||
lwz r3,0(r5) /* Get that lock in here */
|
||||
mr. r3,r3 /* Is it free yet? */
|
||||
beq+ Lcktry /* Yeah, try for it again... */
|
||||
b Lcksniff /* keep trying... */
|
||||
|
||||
Lckgot:
|
||||
isync /* Make sure we don't use a */
|
||||
/* speculativily loaded value */
|
||||
blr
|
||||
|
||||
/*
|
||||
* unsigned int spin_lock_bit(spin_lock_t, unsigned int bits)
|
||||
*
|
||||
* Try to acquire spin-lock. The second parameter is the bit mask to
|
||||
* test and set. multiple bits may be set.
|
||||
* Return success (1).
|
||||
*/
|
||||
LEAF(_spin_lock_bit)
|
||||
Lbittry:
|
||||
lwarx r6,0,r3 /* Grab the lock value */
|
||||
and. r0,r6,r4 /* See if any of the lock bits are on */
|
||||
or r6,r6,r4 /* Turn on the lock bits */
|
||||
bne- Lbitsniff /* Yeah, wait for it to clear... */
|
||||
stwcx. r6,0,r3 /* Try to sieze that there durn lock */
|
||||
beq+ Lbitgot /* We got it, yahoo... */
|
||||
b Lbittry /* Try again if the store failed... */
|
||||
|
||||
Lbitsniff:
|
||||
lwz r6,0(r3) /* Get that lock in here */
|
||||
and. r0,r6,r4 /* See if any of the lock bits are on */
|
||||
beq+ Lbittry /* Yeah, try for it again... */
|
||||
b Lbitsniff /* keep trying... */
|
||||
|
||||
Lbitgot:
|
||||
li r3,1 /* Set good return code */
|
||||
isync /* Make sure we don't use a */
|
||||
/* speculativily loaded value */
|
||||
blr
|
||||
|
||||
|
||||
/*
|
||||
* unsigned int spin_unlock_bit(spin_lock_t, unsigned int bits)
|
||||
*
|
||||
* Release bit based spin-lock. The second parameter is the bit mask to
|
||||
* clear. Multiple bits may be cleared.
|
||||
*/
|
||||
LEAF(_spin_unlock_bit)
|
||||
Lubittry:
|
||||
lwarx r0,0,r3 /* Grab the lock value */
|
||||
andc r0,r0,r4 /* Clear the lock bits */
|
||||
stwcx. r0,0,r3 /* Try to clear that there durn lock */
|
||||
bne- Lubittry /* Try again, couldn't save it... */
|
||||
blr /* Leave... */
|
||||
|
||||
/*
|
||||
* unsigned int spin_lock_try(spin_lock_t)
|
||||
*
|
||||
* Try to acquire spin-lock. Return success (1) or failure (0).
|
||||
*/
|
||||
LEAF(_spin_lock_try)
|
||||
li r4, 1 /* value to be stored... 1==taken */
|
||||
|
||||
L_lock_try_loop:
|
||||
lwarx r5, 0,r3 /* Ld from addr of arg and reserve */
|
||||
cmpwi r5, 0 /* TEST... */
|
||||
bne- L_lock_try_failed /* branch if taken. Predict free */
|
||||
|
||||
stwcx. r4, 0,r3 /* And SET (if still reserved) */
|
||||
bne- L_lock_try_loop /* If set failed, loop back */
|
||||
|
||||
isync
|
||||
li r3,1 /* Set that the lock was free */
|
||||
blr
|
||||
|
||||
L_lock_try_failed:
|
||||
li r3,0 /* FAILURE - lock was taken */
|
||||
blr
|
||||
|
||||
/*
|
||||
* unsigned int spin_lock_held(spin_lock_t)
|
||||
*
|
||||
* Return 1 if lock is held
|
||||
* N.B. Racy, of course.
|
||||
*/
|
||||
LEAF(_spin_lock_held)
|
||||
isync /* Make sure we don't use a */
|
||||
/* speculativily fetched lock */
|
||||
lwz r3, 0(r3) /* Return value of lock */
|
||||
blr
|
||||
|
||||
/*
|
||||
* unsigned int compare_and_store(unsigned int oval,
|
||||
* unsigned int nval, unsigned int *area)
|
||||
*
|
||||
* Compare oval to area if equal, store nval, and return true
|
||||
* else return false and no store
|
||||
* This is an atomic operation
|
||||
*/
|
||||
LEAF(_compare_and_store)
|
||||
mr r6,r3 /* Save the old value */
|
||||
|
||||
Lcstry:
|
||||
lwarx r9,0,r5 /* Grab the area value */
|
||||
li r3,1 /* Assume it works */
|
||||
cmplw cr0,r9,r6 /* Does it match the old value? */
|
||||
bne- Lcsfail /* No, it must have changed... */
|
||||
stwcx. r4,0,r5 /* Try to save the new value */
|
||||
bne- Lcstry /* Didn't get it, try again... */
|
||||
isync /* Just hold up prefetch */
|
||||
blr /* Return... */
|
||||
|
||||
Lcsfail:
|
||||
li r3,0 /* Set failure */
|
||||
blr
|
||||
|
||||
/*
|
||||
* unsigned int atomic_add(unsigned int *area, int val)
|
||||
*
|
||||
* Atomically add the second parameter to the first.
|
||||
* Returns the result.
|
||||
*/
|
||||
LEAF(_atomic_add)
|
||||
mr r6,r3 /* Save the area */
|
||||
|
||||
Laddtry:
|
||||
lwarx r3,0,r6 /* Grab the area value */
|
||||
add r3,r3,r4 /* Add the value */
|
||||
stwcx. r3,0,r6 /* Try to save the new value */
|
||||
bne- Laddtry /* Didn't get it, try again... */
|
||||
blr /* Return... */
|
||||
|
||||
|
||||
/*
|
||||
* unsigned int atomic_or(unsigned int *area, unsigned int mask)
|
||||
*
|
||||
* Atomically or the mask into *area.
|
||||
* Returns the old value.
|
||||
*/
|
||||
LEAF(_atomic_or)
|
||||
mr r6,r3 /* Save the area */
|
||||
|
||||
Lortry:
|
||||
lwarx r3,0,r6 /* Grab the area value */
|
||||
or r5,r3,r4 /* or the mask */
|
||||
stwcx. r5,0,r6 /* Try to save the new value */
|
||||
bne- Lortry /* Didn't get it, try again... */
|
||||
blr /* Return the old value... */
|
||||
|
||||
|
||||
/*
|
||||
* unsigned int atomic_sub(unsigned int *area, int val)
|
||||
*
|
||||
* Atomically subtract the second parameter from the first.
|
||||
* Returns the result.
|
||||
*/
|
||||
LEAF(_atomic_sub)
|
||||
mr r6,r3 /* Save the area */
|
||||
|
||||
Lsubtry:
|
||||
lwarx r3,0,r6 /* Grab the area value */
|
||||
sub r3,r3,r4 /* Subtract the value */
|
||||
stwcx. r3,0,r6 /* Try to save the new value */
|
||||
bne- Lsubtry /* Didn't get it, try again... */
|
||||
blr /* Return... */
|
||||
|
||||
/*
|
||||
* void queue_atomic(unsigned int * anchor,
|
||||
* unsigned int * elem, unsigned int disp)
|
||||
*
|
||||
* Atomically inserts the element at the head of the list
|
||||
* anchor is the pointer to the first element
|
||||
* element is the pointer to the element to insert
|
||||
* disp is the displacement into the element to the chain pointer
|
||||
*/
|
||||
LEAF(_queue_atomic)
|
||||
mr r7,r4 /* Make end point the same as start */
|
||||
mr r8,r5 /* Copy the displacement also */
|
||||
b Lqueue_comm /* Join common code... */
|
||||
|
||||
/*
|
||||
* void queue_atomic_list(unsigned int * anchor,
|
||||
* unsigned int * first, unsigned int * last,
|
||||
* unsigned int disp)
|
||||
*
|
||||
* Atomically inserts the list of elements at the head of the list
|
||||
* anchor is the pointer to the first element
|
||||
* first is the pointer to the first element to insert
|
||||
* last is the pointer to the last element to insert
|
||||
* disp is the displacement into the element to the chain pointer
|
||||
*/
|
||||
LEAF(_queue_atomic_list)
|
||||
mr r7,r5 /* Make end point the same as start */
|
||||
mr r8,r6 /* Copy the displacement also */
|
||||
|
||||
Lqueue_comm:
|
||||
lwarx r9,0,r3 /* Pick up the anchor */
|
||||
stwx r9,r8,r7 /* Chain that to the end of the new stuff */
|
||||
stwcx. r4,0,r3 /* Try to chain into the front */
|
||||
bne- Lqueue_comm /* Didn't make it, try again... */
|
||||
blr /* Return... */
|
||||
|
||||
/*
|
||||
* unsigned int *dequeue_atomic(unsigned int *anchor, unsigned int disp)
|
||||
*
|
||||
* Atomically removes the first element in a list and returns it.
|
||||
* anchor is the pointer to the first element
|
||||
* disp is the displacement into the element to the chain pointer
|
||||
* Returns element if found, 0 if empty.
|
||||
*/
|
||||
LEAF(_dequeue_atomic)
|
||||
mr r5,r3 /* Save the anchor */
|
||||
|
||||
Ldequeue_comm:
|
||||
lwarx r3,0,r5 /* Pick up the anchor */
|
||||
mr. r3,r3 /* Is the list empty? */
|
||||
beqlr- /* Leave it list empty... */
|
||||
lwzx r9,r4,r3 /* Get the next in line */
|
||||
stwcx. r9,0,r5 /* Try to chain into the front */
|
||||
bne- Ldequeue_comm /* Didn't make it, try again... */
|
||||
blr /* Return... */
|
||||
|
84
AtomicLib/hmi.c
Normal file
84
AtomicLib/hmi.c
Normal file
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
|
||||
*
|
||||
* @APPLE_LICENSE_HEADER_START@
|
||||
*
|
||||
* Copyright (c) 1999-2008 Apple Inc. All Rights Reserved.
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original Code
|
||||
* as defined in and that are subject to the Apple Public Source License
|
||||
* Version 2.0 (the 'License'). You may not use this file except in
|
||||
* compliance with the License. Please obtain a copy of the License at
|
||||
* http://www.opensource.apple.com/apsl/ and read it before using this
|
||||
* file.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
|
||||
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
|
||||
* Please see the License for the specific language governing rights and
|
||||
* limitations under the License.
|
||||
*
|
||||
* @APPLE_LICENSE_HEADER_END@
|
||||
*/
|
||||
/*
|
||||
* to test use of timestamp()
|
||||
*/
|
||||
|
||||
/* cc hmi.c -o hmi libatomic.a */
|
||||
|
||||
#include <stdio.h>
|
||||
#include "timestamp.h"
|
||||
|
||||
void
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int i, j;
|
||||
SInt64 ts1, ts2;
|
||||
SInt64 ts3, ts4;
|
||||
struct timescale tsc;
|
||||
double scale;
|
||||
|
||||
if (argc <= 1) {
|
||||
qtss_fprintf(stderr, "Usage: %s loop-count\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
j = atoi(argv[1]);
|
||||
|
||||
ts1 = timestamp(); /* START */
|
||||
|
||||
/* Loop for the given loop-count */
|
||||
for (i=0; i < j; i++) {
|
||||
;
|
||||
}
|
||||
|
||||
ts2 = timestamp(); /* END */
|
||||
|
||||
qtss_printf("ts1 = %qd, ts2 = %qd\n", ts1, ts2);
|
||||
|
||||
utimescale(&tsc);
|
||||
scale = (double)tsc.tsc_numerator / (double)tsc.tsc_denominator;
|
||||
|
||||
ts1 = (SInt64)((double)ts1 * scale);
|
||||
ts2 = (SInt64)((double)ts2 * scale);
|
||||
|
||||
qtss_printf("ts1 = %qd, ts2 = %qd, micro seconds = %qd\n",
|
||||
ts1, ts2, (ts2 - ts1));
|
||||
|
||||
/* Use the scaledtimestamp() now */
|
||||
|
||||
ts3 = scaledtimestamp(scale); /* START */
|
||||
|
||||
/* Loop for the given loop-count */
|
||||
for (i=0; i < j; i++) {
|
||||
;
|
||||
}
|
||||
|
||||
ts4 = scaledtimestamp(scale); /* END */
|
||||
|
||||
qtss_printf("ts3 = %qd, ts4 = %qd, micro seconds = %qd\n",
|
||||
ts3, ts4, (ts4 - ts3));
|
||||
|
||||
}
|
55
AtomicLib/timescale.c
Normal file
55
AtomicLib/timescale.c
Normal file
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
|
||||
*
|
||||
* @APPLE_LICENSE_HEADER_START@
|
||||
*
|
||||
* Copyright (c) 1999-2008 Apple Inc. All Rights Reserved.
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original Code
|
||||
* as defined in and that are subject to the Apple Public Source License
|
||||
* Version 2.0 (the 'License'). You may not use this file except in
|
||||
* compliance with the License. Please obtain a copy of the License at
|
||||
* http://www.opensource.apple.com/apsl/ and read it before using this
|
||||
* file.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
|
||||
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
|
||||
* Please see the License for the specific language governing rights and
|
||||
* limitations under the License.
|
||||
*
|
||||
* @APPLE_LICENSE_HEADER_END@
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* File: timescale.c
|
||||
*
|
||||
* History:
|
||||
* 23-Oct-1998 Umesh Vaishampayan (umeshv@apple.com)
|
||||
* Created.
|
||||
*/
|
||||
|
||||
#include "timestamp.h"
|
||||
#include <stdlib.h>
|
||||
#include "SafeStdLib.h"
|
||||
void
|
||||
utimescale(struct timescale *tscp)
|
||||
{
|
||||
// stop not supported
|
||||
char *death = 0;
|
||||
*death = 0;
|
||||
exit (-1);
|
||||
#if 0 // old code
|
||||
unsigned int theNanosecondNumerator = 0;
|
||||
unsigned int theNanosecondDenominator = 0;
|
||||
|
||||
MKGetTimeBaseInfo(NULL, &theNanosecondNumerator, &theNanosecondDenominator, NULL, NULL);
|
||||
tscp->tsc_numerator = theNanosecondNumerator / 1000; /* PPC magic number */
|
||||
tscp->tsc_denominator = theNanosecondDenominator;
|
||||
return;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
67
AtomicLib/timestamp.h
Normal file
67
AtomicLib/timestamp.h
Normal file
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
|
||||
*
|
||||
* @APPLE_LICENSE_HEADER_START@
|
||||
*
|
||||
* Copyright (c) 1999-2008 Apple Inc. All Rights Reserved.
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original Code
|
||||
* as defined in and that are subject to the Apple Public Source License
|
||||
* Version 2.0 (the 'License'). You may not use this file except in
|
||||
* compliance with the License. Please obtain a copy of the License at
|
||||
* http://www.opensource.apple.com/apsl/ and read it before using this
|
||||
* file.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
|
||||
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
|
||||
* Please see the License for the specific language governing rights and
|
||||
* limitations under the License.
|
||||
*
|
||||
* @APPLE_LICENSE_HEADER_END@
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* History:
|
||||
* 08-Feb-1999 Umesh Vaishampayan (umeshv@apple.com)
|
||||
* Added scaledtimestamp().
|
||||
*
|
||||
* 26-Oct-1998 Umesh Vaishampayan (umeshv@apple.com)
|
||||
* Made the header c++ friendly.
|
||||
*
|
||||
* 23-Oct-1998 Umesh Vaishampayan (umeshv@apple.com)
|
||||
* Created.
|
||||
*/
|
||||
|
||||
#ifndef _TIMESTAMP_H_
|
||||
#define _TIMESTAMP_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "OSHeaders.h"
|
||||
|
||||
/* Get a 64 bit timestamp */
|
||||
extern SInt64 timestamp(void);
|
||||
|
||||
struct timescale {
|
||||
SInt64 tsc_numerator;
|
||||
SInt64 tsc_denominator;
|
||||
};
|
||||
|
||||
/*
|
||||
* Get numerator and denominator to convert value returned
|
||||
* by timestamp() to microseconds
|
||||
*/
|
||||
extern void utimescale(struct timescale *tscp);
|
||||
|
||||
extern SInt64 scaledtimestamp(double scale);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _TIMESTAMP_H_ */
|
133
AtomicLib/timestamp.s
Normal file
133
AtomicLib/timestamp.s
Normal file
|
@ -0,0 +1,133 @@
|
|||
/*
|
||||
*
|
||||
* @APPLE_LICENSE_HEADER_START@
|
||||
*
|
||||
* Copyright (c) 1999-2008 Apple Inc. All Rights Reserved.
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original Code
|
||||
* as defined in and that are subject to the Apple Public Source License
|
||||
* Version 2.0 (the 'License'). You may not use this file except in
|
||||
* compliance with the License. Please obtain a copy of the License at
|
||||
* http://www.opensource.apple.com/apsl/ and read it before using this
|
||||
* file.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
|
||||
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
|
||||
* Please see the License for the specific language governing rights and
|
||||
* limitations under the License.
|
||||
*
|
||||
* @APPLE_LICENSE_HEADER_END@
|
||||
*
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* File: timestamp.s
|
||||
*
|
||||
* History:
|
||||
* 12-Feb-1999 Umesh Vaishampayan (umeshv@apple.com)
|
||||
* Integrated scaledtimestamp() written by
|
||||
* Joe Sokol (sokol1@apple.com)
|
||||
*
|
||||
* 23-Oct-1998 Umesh Vaishampayan (umeshv@apple.com)
|
||||
* Created.
|
||||
*/
|
||||
|
||||
#include <architecture/ppc/asm_help.h>
|
||||
|
||||
/*
|
||||
* long long timestamp(void)
|
||||
*
|
||||
* Read the PPC timebase.
|
||||
*/
|
||||
LEAF(_timestamp)
|
||||
Lagain:
|
||||
mftbu r3
|
||||
mftb r4
|
||||
mftbu r6
|
||||
cmpw r6, r3
|
||||
bne- Lagain
|
||||
blr
|
||||
|
||||
|
||||
/*
|
||||
* long long scaledtimestamp(double scale)
|
||||
*
|
||||
* Read the PPC timebase. Convert the time base value based on
|
||||
* scale.
|
||||
*
|
||||
* Caveat: scale can not be 0, NaN, Inf. It's upto the caller
|
||||
* to validate scale before calling this.
|
||||
*/
|
||||
|
||||
LEAF(_scaledtimestamp)
|
||||
Lagain1:
|
||||
mftbu r3
|
||||
mftb r4
|
||||
mftbu r6
|
||||
cmpw r6,r3
|
||||
bne- Lagain1
|
||||
|
||||
; r3 and r4 have the time base.
|
||||
; convert the long long value to double
|
||||
L_LLtoD:
|
||||
cntlzw r0,r3
|
||||
cmplwi cr0,r0,31
|
||||
bc 12,1,L2
|
||||
subfic r10,r0,63
|
||||
subfic r11,r10,52
|
||||
subfic r0,r11,32
|
||||
srw r0,r4,r0
|
||||
slw r9,r3,r11
|
||||
or r3,r9,r0
|
||||
b L6
|
||||
L2:
|
||||
cntlzw r0,r4
|
||||
subfic r10,r0,31
|
||||
subfic r11,r10,52
|
||||
cmplwi cr0,r11,31
|
||||
bc 4,1,L4
|
||||
addi r0,r11,-32
|
||||
slw r3,r4,r0
|
||||
li r4,0
|
||||
b L3
|
||||
L4:
|
||||
subfic r0,r11,32
|
||||
srw r3,r4,r0
|
||||
L6:
|
||||
slw r4,r4,r11
|
||||
L3:
|
||||
addi r0,r10,1023
|
||||
slwi r0,r0,20
|
||||
rlwimi r3,r0,0,0,11
|
||||
stw r3,-8(r1)
|
||||
stw r4,-4(r1)
|
||||
lfd f0,-8(r1) ; load the double representation of time base
|
||||
|
||||
fmul f0,f0,f1 ; f1 has scale to convert timestamp
|
||||
|
||||
; convert the double to long long
|
||||
L_DtoLL:
|
||||
stfd f0,-8(r1)
|
||||
lwz r3,-8(r1)
|
||||
lwz r4,-4(r1)
|
||||
srwi r0,r3,20
|
||||
rlwinm r9,r3,0,12,31
|
||||
subfic r8,r0,1075
|
||||
cmplwi cr0,r8,31
|
||||
oris r3,r9,0x10
|
||||
bc 4,1,L8
|
||||
addi r0,r8,-32
|
||||
srw r4,r3,r0
|
||||
li r3,0
|
||||
blr
|
||||
L8:
|
||||
subfic r0,r8,32
|
||||
slw r0,r3,r0
|
||||
srw r9,r4,r8
|
||||
or r4,r9,r0
|
||||
srw r3,r3,r8
|
||||
blr
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue