1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/liboil/src/liboilcpu-misc.c Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,143 @@
1.4 +/*
1.5 + * LIBOIL - Library of Optimized Inner Loops
1.6 + * Copyright (c) 2003,2004 David A. Schleef <ds@schleef.org>
1.7 + * All rights reserved.
1.8 + *
1.9 + * Redistribution and use in source and binary forms, with or without
1.10 + * modification, are permitted provided that the following conditions
1.11 + * are met:
1.12 + * 1. Redistributions of source code must retain the above copyright
1.13 + * notice, this list of conditions and the following disclaimer.
1.14 + * 2. Redistributions in binary form must reproduce the above copyright
1.15 + * notice, this list of conditions and the following disclaimer in the
1.16 + * documentation and/or other materials provided with the distribution.
1.17 + *
1.18 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1.19 + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1.20 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1.21 + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
1.22 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
1.23 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
1.24 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1.25 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
1.26 + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
1.27 + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1.28 + * POSSIBILITY OF SUCH DAMAGE.
1.29 + */
1.30 +
1.31 +#ifdef HAVE_CONFIG_H
1.32 +#include "config.h"
1.33 +#endif
1.34 +#include <liboil/liboilfunction.h>
1.35 +#include <liboil/liboildebug.h>
1.36 +#include <liboil/liboilcpu.h>
1.37 +#include <liboil/liboilfault.h>
1.38 +#include <liboil/liboilutils.h>
1.39 +
1.40 +#include <unistd.h>
1.41 +#include <fcntl.h>
1.42 +#include <stdlib.h>
1.43 +#include <string.h>
1.44 +#include <stdio.h>
1.45 +#include <setjmp.h>
1.46 +#include <signal.h>
1.47 +#include <sys/time.h>
1.48 +#include <time.h>
1.49 +
1.50 +/***** alpha *****/
1.51 +
1.52 +#if defined(__alpha__)
1.53 +static unsigned long
1.54 +oil_profile_stamp_alpha(void)
1.55 +{
1.56 + unsigned int ts;
1.57 + __asm__ __volatile__ ("rpcc %0\n" : "=r"(ts));
1.58 + return ts;
1.59 +}
1.60 +
1.61 +static void
1.62 +oil_cpu_detect_alpha(void)
1.63 +{
1.64 + _oil_profile_stamp = oil_profile_stamp_alpha;
1.65 +}
1.66 +#endif
1.67 +
1.68 +/***** ia64 *****/
1.69 +
1.70 +#if defined(__ia64__)
1.71 +static unsigned long
1.72 +oil_profile_stamp_ia64(void)
1.73 +{
1.74 + unsigned int ts;
1.75 + __asm__ __volatile__("mov %0=ar.itc\n" : "=r"(ts) :: "memory");
1.76 + return ts;
1.77 +}
1.78 +
1.79 +static void
1.80 +oil_cpu_detect_ia64(void)
1.81 +{
1.82 + _oil_profile_stamp = oil_profile_stamp_ia64;
1.83 +}
1.84 +#endif
1.85 +
1.86 +/***** s390 *****/
1.87 +
1.88 +#if defined(__s390__)
1.89 +static unsigned long
1.90 +oil_profile_stamp_s390(void)
1.91 +{
1.92 + uint64_t ts;
1.93 + __asm__ __volatile__ ("STCK %0(%0)\n" : : "r" (&ts));
1.94 + return ts;
1.95 +}
1.96 +
1.97 +static void
1.98 +oil_cpu_detect_s390(void)
1.99 +{
1.100 + _oil_profile_stamp = oil_profile_stamp_s390;
1.101 +}
1.102 +#endif
1.103 +
1.104 +/***** mips *****/
1.105 +
1.106 +#if defined(__mips__)
1.107 +#if 0
1.108 +/* broken */
1.109 +static unsigned long
1.110 +oil_profile_stamp_mips(void)
1.111 +{
1.112 + unsigned int ts;
1.113 + __asm__ __volatile__ (
1.114 + " .set push \n"
1.115 + " .set reorder \n"
1.116 + " mfc0 %0,$9 \n"
1.117 + " .set pop \n"
1.118 + : "=m" (ts));
1.119 + return ts;
1.120 +}
1.121 +#endif
1.122 +
1.123 +static void
1.124 +oil_cpu_detect_mips(void)
1.125 +{
1.126 + //_oil_profile_stamp = oil_profile_stamp_mips;
1.127 +}
1.128 +#endif
1.129 +
1.130 +void
1.131 +oil_cpu_detect_arch(void)
1.132 +{
1.133 +#ifdef __alpha__
1.134 + oil_cpu_detect_alpha();
1.135 +#endif
1.136 +#ifdef __ia64__
1.137 + oil_cpu_detect_ia64();
1.138 +#endif
1.139 +#ifdef __s390__
1.140 + oil_cpu_detect_s390();
1.141 +#endif
1.142 +#ifdef __mips__
1.143 + oil_cpu_detect_mips();
1.144 +#endif
1.145 +}
1.146 +