0N/A/*
0N/A * CDDL HEADER START
0N/A *
0N/A * The contents of this file are subject to the terms
0N/A * of the Common Development and Distribution License
0N/A * (the "License"). You may not use this file except
0N/A * in compliance with the License.
0N/A *
0N/A * You can obtain a copy of the license at
0N/A * src/OPENSOLARIS.LICENSE
0N/A * or http://www.opensolaris.org/os/licensing.
0N/A * See the License for the specific language governing
0N/A * permissions and limitations under the License.
0N/A *
0N/A * When distributing Covered Code, include this CDDL
0N/A * HEADER in each file and include the License file at
0N/A * usr/src/OPENSOLARIS.LICENSE. If applicable,
0N/A * add the following below this CDDL HEADER, with the
0N/A * fields enclosed by brackets "[]" replaced with your
0N/A * own identifying information: Portions Copyright [yyyy]
0N/A * [name of copyright owner]
0N/A *
0N/A * CDDL HEADER END
0N/A */
0N/A
0N/A/*
0N/A * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
0N/A * Use is subject to license terms.
0N/A */
0N/A
0N/A#include <unistd.h>
0N/A#include <stdio.h>
0N/A#include <stdlib.h>
0N/A#include <string.h>
0N/A#include <sys/time.h>
0N/A#include <time.h>
0N/A#include <tattle.h>
0N/A#include "libmicro.h"
0N/A#include <math.h>
0N/A
0N/A
0N/A#ifdef USE_RDTSC
0N/A#ifdef __GNUC__
0N/A#define ENABLE_RDTSC 1
0N/A#endif
0N/A#endif
0N/A
0N/A/*
0N/A * dummy so we can link w/ libmicro
0N/A */
0N/A
0N/A/*ARGSUSED*/
0N/Aint
0N/Abenchmark(void *tsd, result_t *res)
0N/A{
0N/A return (0);
0N/A}
0N/A
0N/Astatic void
0N/Acleanup(char *s)
0N/A{
0N/A char *o = s;
0N/A char *e;
0N/A
0N/A while (*s == ' ')
0N/A s++;
0N/A
0N/A if (o != s)
0N/A (void) strcpy(o, s);
0N/A
0N/A e = o;
0N/A
0N/A while (*e != 0)
0N/A e++;
0N/A
0N/A e--;
0N/A
0N/A while (*e == ' ' && e > o)
0N/A *e-- = 0;
0N/A
0N/A}
0N/A
0N/A
0N/Aint
0N/Amain(int argc, char *argv[])
0N/A{
0N/A int c;
0N/A
0N/A if (strlen(compiler_version) > 30)
0N/A compiler_version[30] = 0;
0N/A
0N/A cleanup(compiler_version);
0N/A cleanup(extra_compiler_flags);
0N/A
0N/A while ((c = getopt(argc, argv, "vcfrsVTR")) != -1) {
0N/A switch (c) {
0N/A case 'V':
0N/A (void) printf("%s\n", LIBMICRO_VERSION);
0N/A break;
0N/A case 'v':
0N/A (void) printf("%s\n", compiler_version);
0N/A break;
0N/A case 'c':
0N/A (void) printf("%s\n", CC);
0N/A break;
0N/A case 'f':
0N/A if (strlen(extra_compiler_flags) == 0)
0N/A (void) printf("[none]\n");
0N/A else
0N/A (void) printf("%s\n", extra_compiler_flags);
0N/A break;
0N/A
0N/A case 's':
0N/A (void) printf("%d\n", sizeof (long));
0N/A break;
0N/A
0N/A case 'r':
0N/A
0N/A (void) printf("%lld nsecs\n", get_nsecs_resolution());
0N/A break;
0N/A
0N/A case 'R':
0N/A#ifdef ENABLE_RDTSC
0N/A {
0N/A struct timeval s;
0N/A struct timeval f;
0N/A long long start_nsecs;
0N/A long long end_nsecs;
0N/A long elapsed_usecs;
0N/A
0N/A gettimeofday(&s, NULL);
0N/A start_nsecs = rdtsc();
0N/A for (;;) {
0N/A gettimeofday(&f, NULL);
0N/A elapsed_usecs = (f.tv_sec - s.tv_sec) *
0N/A 1000000 + (f.tv_usec - s.tv_usec);
0N/A if (elapsed_usecs > 1000000)
0N/A break;
0N/A }
0N/A end_nsecs = rdtsc();
0N/A (void) printf("LIBMICRO_HZ=%lld\n",
0N/A (long long)elapsed_usecs *
0N/A (end_nsecs - start_nsecs) / 1000000LL);
0N/A }
0N/A#else
0N/A (void) printf("\n");
0N/A#endif
0N/A break;
0N/A }
0N/A }
0N/A
0N/A exit(0);
0N/A}