diff --git a/MultiSource/Applications/CMakeLists.txt b/MultiSource/Applications/CMakeLists.txt index a73acd567..b008394f1 100644 --- a/MultiSource/Applications/CMakeLists.txt +++ b/MultiSource/Applications/CMakeLists.txt @@ -1,44 +1,47 @@ -add_subdirectory(JM) +if(NOT TARGET_OS STREQUAL "OpenBSD") + add_subdirectory(JM) +endif() + add_subdirectory(SIBsim4) add_subdirectory(aha) add_subdirectory(d) if(NOT ARCH STREQUAL "PowerPC") # This test has problems running on powerpc starting with r295538 and should # be restored when the issue is corrected. add_subdirectory(oggenc) endif() add_subdirectory(sgefa) add_subdirectory(spiff) add_subdirectory(viterbi) add_subdirectory(ALAC) add_subdirectory(hbd) add_subdirectory(lambda-0.1.3) add_subdirectory(minisat) if(NOT TARGET_OS STREQUAL "SunOS") add_subdirectory(hexxagon) endif() if(NOT DEFINED SMALL_PROBLEM_SIZE) add_subdirectory(lua) endif() if((TARGET_OS STREQUAL "Linux" OR TARGET_OS STREQUAL "Darwin") AND (NOT ARCH STREQUAL "XCore")) add_subdirectory(obsequi) endif() if(NOT TARGET_OS STREQUAL "SunOS") add_subdirectory(kimwitu++) endif() if(NOT TARGET_OS STREQUAL "SunOS") add_subdirectory(SPASS) endif() if(NOT ARCH STREQUAL "XCore") add_subdirectory(ClamAV) add_subdirectory(lemon) add_subdirectory(siod) endif() if((NOT ARCH STREQUAL "PowerPC") AND (NOT ARCH STREQUAL "XCore")) add_subdirectory(sqlite3) endif() if(NOT TEST_SUITE_BENCHMARKING_ONLY) add_subdirectory(Burg) add_subdirectory(treecc) endif() diff --git a/MultiSource/Applications/SPASS/clock.c b/MultiSource/Applications/SPASS/clock.c index 1166782b4..d8380c9bd 100644 --- a/MultiSource/Applications/SPASS/clock.c +++ b/MultiSource/Applications/SPASS/clock.c @@ -1,215 +1,217 @@ /**************************************************************/ /* ********************************************************** */ /* * * */ /* * CLOCK * */ /* * * */ /* * $Module: CLOCK * */ /* * * */ /* * Copyright (C) 1996, 1999, 2000, 2001 * */ /* * MPI fuer Informatik * */ /* * * */ /* * This program is free software; you can redistribute * */ /* * it and/or modify it under the terms of the GNU * */ /* * General Public License as published by the Free * */ /* * Software Foundation; either version 2 of the License, * */ /* * or (at your option) any later version. * */ /* * * */ /* * This program is distributed in the hope that it will * */ /* * be useful, but WITHOUT ANY WARRANTY; without even * */ /* * the implied warranty of MERCHANTABILITY or FITNESS * */ /* * FOR A PARTICULAR PURPOSE. See the GNU General Public * */ /* * License for more details. * */ /* * * */ /* * You should have received a copy of the GNU General * */ /* * Public License along with this program; if not, write * */ /* * to the Free Software Foundation, Inc., 59 Temple * */ /* * Place, Suite 330, Boston, MA 02111-1307 USA * */ /* * * */ /* * * */ /* $Revision$ * */ /* $State$ * */ /* $Date$ * */ /* $Author$ * */ /* * * */ /* * Contact: * */ /* * Christoph Weidenbach * */ /* * MPI fuer Informatik * */ /* * Stuhlsatzenhausweg 85 * */ /* * 66123 Saarbruecken * */ /* * Email: weidenb@mpi-sb.mpg.de * */ /* * Germany * */ /* * * */ /* ********************************************************** */ /**************************************************************/ /* $RCSfile$ */ #include "clock.h" /**************************************************************/ /* Global Variables */ /**************************************************************/ float clock_Akku[clock_TYPESIZE]; +#ifndef CLOCK_NO_TIMING CLOCK_TMS clock_Counters[clock_TYPESIZE]; +#endif #ifdef WIN float clock_Ping; #endif /**************************************************************/ /* Functions */ /**************************************************************/ void clock_Init(void) /********************************************************* INPUT: None. EFFECT: Initializes the clock Module. RETURNS: None. MEMORY: None. **********************************************************/ { int i; for (i=0;i is initialized. RETURNS: None. MEMORY: None. **********************************************************/ { clock_Akku[ClockCounter] = 0; } void clock_StartCounter(CLOCK_CLOCKS ClockCounter) /********************************************************* INPUT: A clock counter. EFFECT: The clock counter is started. RETURNS: None. MEMORY: None. **********************************************************/ { #ifndef CLOCK_NO_TIMING ftime(&(clock_Counters[ClockCounter])); #endif } void clock_StopPassedTime(CLOCK_CLOCKS ClockCounter) /********************************************************* INPUT: A clock counter. EFFECT: Stores the number of seconds passed since given counter was started in the according accumulator. RETURNS: None. MEMORY: None. **********************************************************/ { #ifndef CLOCK_NO_TIMING CLOCK_TMS newtime; ftime(&newtime); clock_Akku[ClockCounter] = clock_GetSeconds(ClockCounter); #endif } void clock_StopAddPassedTime(CLOCK_CLOCKS ClockCounter) /********************************************************* INPUT: A clock counter. EFFECT: Adds the number of seconds passed since given counter was started to the according accumulator. RETURNS: None. MEMORY: None. **********************************************************/ { #ifndef CLOCK_NO_TIMING CLOCK_TMS newtime; ftime(&newtime); clock_Akku[ClockCounter] += clock_GetSeconds(ClockCounter); #endif } float clock_GetSeconds(CLOCK_CLOCKS ClockCounter) /********************************************************* INPUT: A clock counter. EFFECT: Computes the number of seconds spent by the counter. RETURNS: The number of seconds spent by the counter as a float. MEMORY: None. **********************************************************/ { #ifndef CLOCK_NO_TIMING CLOCK_TMS newtime; ftime(&newtime); return ((float) (newtime.time - clock_Counters[ClockCounter].time) + (((newtime.millitm - clock_Counters[ClockCounter].millitm)) /(float)1000)); #else return 0; #endif } #ifdef WIN void clock_PingOneSecond(void) /********************************************************* INPUT: None but assumes the clock_OVERALL to be properly initialized. EFFECT: If between the previous call to this function or to clock_Init more one second is passed, the function prints a "PING" to stdout. Needed only for the windows implementation. CAUTION: Only needed to get around Windows95/98 scheduling problems. **********************************************************/ { if (clock_GetSeconds(clock_OVERALL) > clock_Ping + 1) { clock_Ping++; puts("\n PING "); } } #endif void clock_PrintTime(CLOCK_CLOCKS ClockCounter) /********************************************************* INPUT: A clock counter. EFFECT: The time is printed in format hh:mm:ss.dd to stdout RETURNS: None. MEMORY: None. **********************************************************/ { #ifndef CLOCK_NO_TIMING NAT hours, minutes; float seconds; seconds = clock_Akku[ClockCounter]; hours = (NAT)seconds/3600; seconds -= hours*3600; minutes = (NAT)seconds/60; seconds -= (minutes*60); if (seconds >= 10.0) printf("%u:%02u:%2.2f",hours,minutes,seconds); else printf("%u:%02u:0%2.2f",hours,minutes,seconds); #else fputs(" No Timing on this machine. ",stdout); #endif } diff --git a/MultiSource/Applications/SPASS/clock.h b/MultiSource/Applications/SPASS/clock.h index f643de2cb..1e208f5e4 100644 --- a/MultiSource/Applications/SPASS/clock.h +++ b/MultiSource/Applications/SPASS/clock.h @@ -1,78 +1,82 @@ /**************************************************************/ /* ********************************************************** */ /* * * */ /* * CLOCK * */ /* * * */ /* * $Module: CLOCK * */ /* * * */ /* * Copyright (C) 1996, 1997, 1999, 2001 * */ /* * MPI fuer Informatik * */ /* * * */ /* * This program is free software; you can redistribute * */ /* * it and/or modify it under the terms of the GNU * */ /* * General Public License as published by the Free * */ /* * Software Foundation; either version 2 of the License, * */ /* * or (at your option) any later version. * */ /* * * */ /* * This program is distributed in the hope that it will * */ /* * be useful, but WITHOUT ANY WARRANTY; without even * */ /* * the implied warranty of MERCHANTABILITY or FITNESS * */ /* * FOR A PARTICULAR PURPOSE. See the GNU General Public * */ /* * License for more details. * */ /* * * */ /* * You should have received a copy of the GNU General * */ /* * Public License along with this program; if not, write * */ /* * to the Free Software Foundation, Inc., 59 Temple * */ /* * Place, Suite 330, Boston, MA 02111-1307 USA * */ /* * * */ /* * * */ /* $Revision$ * */ /* $State$ * */ /* $Date$ * */ /* $Author$ * */ /* * * */ /* * Contact: * */ /* * Christoph Weidenbach * */ /* * MPI fuer Informatik * */ /* * Stuhlsatzenhausweg 85 * */ /* * 66123 Saarbruecken * */ /* * Email: weidenb@mpi-sb.mpg.de * */ /* * Germany * */ /* * * */ /* ********************************************************** */ /**************************************************************/ /* $RCSfile$ */ #ifndef _CLOCK_ #define _CLOCK_ #include "misc.h" #include +#ifndef CLOCK_NO_TIMING #include +#endif typedef enum { clock_BACKTRACK, clock_OVERALL, clock_INPUT, clock_CNF, clock_REDUCTION, clock_INFERENCE, clock_TYPESIZE } CLOCK_CLOCKS; +#ifndef CLOCK_NO_TIMING typedef struct timeb CLOCK_TMS; +#endif void clock_Init(void); void clock_InitCounter(CLOCK_CLOCKS); void clock_StartCounter(CLOCK_CLOCKS); void clock_StopPassedTime(CLOCK_CLOCKS); void clock_StopAddPassedTime(CLOCK_CLOCKS); float clock_GetSeconds(CLOCK_CLOCKS); void clock_PrintTime(CLOCK_CLOCKS); #ifdef WIN void clock_PingOneSecond(void); #endif #endif diff --git a/MultiSource/Applications/minisat/Main.cpp b/MultiSource/Applications/minisat/Main.cpp index 135e6fb4a..1ff41cdb8 100644 --- a/MultiSource/Applications/minisat/Main.cpp +++ b/MultiSource/Applications/minisat/Main.cpp @@ -1,337 +1,337 @@ /******************************************************************************************[Main.C] MiniSat -- Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. **************************************************************************************************/ #include #include #include #include #include #include "Solver.h" /*************************************************************************************/ #if defined(_MSC_VER) || defined(__XS1B__) #include static inline double cpuTime(void) { return (double)clock() / CLOCKS_PER_SEC; } #else #include #include #include static inline double cpuTime(void) { struct rusage ru; getrusage(RUSAGE_SELF, &ru); return (double)ru.ru_utime.tv_sec + (double)ru.ru_utime.tv_usec / 1000000; } #endif #if defined(__XS1B__) #include #endif #if defined(__linux__) static inline int memReadStat(int field) { char name[256]; pid_t pid = getpid(); sprintf(name, "/proc/%d/statm", pid); FILE* in = fopen(name, "rb"); if (in == NULL) return 0; int value; for (; field >= 0; field--) fscanf(in, "%d", &value); fclose(in); return value; } static inline uint64_t memUsed() { return (uint64_t)memReadStat(0) * (uint64_t)getpagesize(); } -#elif defined(__FreeBSD__) || defined(__NetBSD__) +#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) static inline uint64_t memUsed(void) { struct rusage ru; getrusage(RUSAGE_SELF, &ru); return ru.ru_maxrss*1024; } #else static inline uint64_t memUsed() { return 0; } #endif #if defined(__GLIBC__) && defined(__linux__) #include #endif //================================================================================================= // DIMACS Parser: #define CHUNK_LIMIT 1048576 class StreamBuffer { FILE *in; char buf[CHUNK_LIMIT]; int pos; int size; void assureLookahead() { if (pos >= size) { pos = 0; size = read(fileno(in), buf, sizeof(buf)); } } public: StreamBuffer(FILE *i) : in(i), pos(0), size(0) { assureLookahead(); } int operator * () { return (pos >= size) ? EOF : buf[pos]; } void operator ++ () { pos++; assureLookahead(); } }; //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - template static void skipWhitespace(B& in) { while ((*in >= 9 && *in <= 13) || *in == 32) ++in; } template static void skipLine(B& in) { for (;;){ if (*in == EOF || *in == '\0') return; if (*in == '\n') { ++in; return; } ++in; } } template static int parseInt(B& in) { int val = 0; bool neg = false; skipWhitespace(in); if (*in == '-') neg = true, ++in; else if (*in == '+') ++in; if (*in < '0' || *in > '9') reportf("PARSE ERROR! Unexpected char: %c\n", *in), exit(3); while (*in >= '0' && *in <= '9') val = val*10 + (*in - '0'), ++in; return neg ? -val : val; } template static void readClause(B& in, Solver& S, vec& lits) { int parsed_lit, var; lits.clear(); for (;;){ parsed_lit = parseInt(in); if (parsed_lit == 0) break; var = abs(parsed_lit)-1; while (var >= S.nVars()) S.newVar(); lits.push( (parsed_lit > 0) ? Lit(var) : ~Lit(var) ); } } template static bool match(B& in, char* str) { for (; *str != 0; ++str, ++in) if (*str != *in) return false; return true; } template static void parse_DIMACS_main(B& in, Solver& S) { vec lits; for (;;){ skipWhitespace(in); if (*in == EOF) break; else if (*in == 'p'){ if (match(in, "p cnf")){ int vars = parseInt(in); int clauses = parseInt(in); reportf("| Number of variables: %-12d |\n", vars); reportf("| Number of clauses: %-12d |\n", clauses); }else{ reportf("PARSE ERROR! Unexpected char: %c\n", *in), exit(3); } } else if (*in == 'c' || *in == 'p') skipLine(in); else readClause(in, S, lits), S.addClause(lits); } } // Inserts problem into solver. // static void parse_DIMACS(FILE *input_stream, Solver& S) { // LLVM: Allocate StreamBuffer on the heap instead of the stack so that // this test can run on systems with limited stack size. StreamBuffer *in = new StreamBuffer(input_stream); parse_DIMACS_main(*in, S); delete in; } //================================================================================================= void printStats(Solver& solver) { double cpu_time = cpuTime(); uint64_t mem_used = memUsed(); reportf("restarts : %lld\n", solver.starts); reportf("conflicts : %-12lld\n", solver.conflicts); reportf("decisions : %-12lld (%4.2f %% random)\n", solver.decisions, (float)solver.rnd_decisions*100 / (float)solver.decisions); reportf("propagations : %-12lld\n", solver.propagations); reportf("conflict literals : %-12lld (%4.2f %% deleted)\n", solver.tot_literals, (solver.max_literals - solver.tot_literals)*100 / (double)solver.max_literals); } Solver* solver; //================================================================================================= // Main: void printUsage(char** argv) { reportf("USAGE: %s [options] \n\n where input may be either in plain or gzipped DIMACS.\n\n", argv[0]); reportf("OPTIONS:\n\n"); reportf(" -polarity-mode = {true,false,rnd}\n"); reportf(" -decay = [ 0 - 1 ]\n"); reportf(" -rnd-freq = [ 0 - 1 ]\n"); reportf(" -verbosity = {0,1,2}\n"); reportf("\n"); } const char* hasPrefix(const char* str, const char* prefix) { int len = strlen(prefix); if (strncmp(str, prefix, len) == 0) return strdup(str + len); else return NULL; } int main(int argc, char** argv) { Solver S; S.verbosity = 1; int i, j; const char* value; for (i = j = 0; i < argc; i++){ if ((value = hasPrefix(argv[i], "-polarity-mode="))){ if (strcmp(value, "true") == 0) S.polarity_mode = Solver::polarity_true; else if (strcmp(value, "false") == 0) S.polarity_mode = Solver::polarity_false; else if (strcmp(value, "rnd") == 0) S.polarity_mode = Solver::polarity_rnd; else{ reportf("ERROR! unknown polarity-mode %s\n", value); exit(0); } }else if ((value = hasPrefix(argv[i], "-rnd-freq="))){ double rnd; if (sscanf(value, "%lf", &rnd) <= 0 || rnd < 0 || rnd > 1){ reportf("ERROR! illegal rnd-freq constant %s\n", value); exit(0); } S.random_var_freq = rnd; }else if ((value = hasPrefix(argv[i], "-decay="))){ double decay; if (sscanf(value, "%lf", &decay) <= 0 || decay <= 0 || decay > 1){ reportf("ERROR! illegal decay constant %s\n", value); exit(0); } S.var_decay = 1 / decay; }else if ((value = hasPrefix(argv[i], "-verbosity="))){ char *end; int verbosity = (int)strtol(value, &end, 10); if (end == value || *end != 0){ reportf("ERROR! illegal verbosity level %s\n", value); exit(0); } S.verbosity = verbosity; }else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-help") == 0 || strcmp(argv[i], "--help") == 0){ printUsage(argv); exit(0); }else if (strncmp(argv[i], "-", 1) == 0){ reportf("ERROR! unknown flag %s\n", argv[i]); exit(0); }else argv[j++] = argv[i]; } argc = j; reportf("This is MiniSat 2.0 beta\n"); #if defined(__linux__) && defined(_FPU_EXTENDED) && defined(_FPU_DOUBLE) fpu_control_t oldcw, newcw; _FPU_GETCW(oldcw); newcw = (oldcw & ~_FPU_EXTENDED) | _FPU_DOUBLE; _FPU_SETCW(newcw); #endif double cpu_time = cpuTime(); solver = &S; if (argc == 1) reportf("Reading from standard input... Use '-h' or '--help' for help.\n"); FILE *in = (argc == 1) ? stdin : fopen(argv[1], "rb"); if (in == NULL) reportf("ERROR! Could not open file: %s\n", argc == 1 ? "" : argv[1]), exit(1); reportf("============================[ Problem Statistics ]=============================\n"); reportf("| |\n"); parse_DIMACS(in, S); fclose(in); FILE* res = (argc >= 3) ? fopen(argv[2], "wb") : NULL; if (!S.simplify()){ reportf("Solved by unit propagation\n"); if (res != NULL) fprintf(res, "UNSAT\n"), fclose(res); printf("UNSATISFIABLE\n"); exit(20); } bool ret = S.solve(); printStats(S); reportf("\n"); printf(ret ? "SATISFIABLE\n" : "UNSATISFIABLE\n"); if (res != NULL){ if (ret){ fprintf(res, "SAT\n"); for (int i = 0; i < S.nVars(); i++) if (S.model[i] != l_Undef) fprintf(res, "%s%s%d", (i==0)?"":" ", (S.model[i]==l_True)?"":"-", i+1); fprintf(res, " 0\n"); }else fprintf(res, "UNSAT\n"); fclose(res); } #ifdef NDEBUG exit(ret ? 10 : 20); // (faster than "return", which will invoke the destructor for 'Solver') #endif } diff --git a/MultiSource/Benchmarks/MiBench/office-ispell/term.c b/MultiSource/Benchmarks/MiBench/office-ispell/term.c index c241a46b9..5fc7401b7 100644 --- a/MultiSource/Benchmarks/MiBench/office-ispell/term.c +++ b/MultiSource/Benchmarks/MiBench/office-ispell/term.c @@ -1,649 +1,650 @@ #ifndef lint static char Rcs_Id[] = "$Id$"; #endif /* * term.c - deal with termcap, and unix terminal mode settings * * Pace Willisson, 1983 * * Copyright 1987, 1988, 1989, 1992, 1993, Geoff Kuenning, Granada Hills, CA * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All modifications to the source code must be clearly marked as * such. Binary redistributions based on modified source code * must be clearly marked as modified versions in the documentation * and/or other materials provided with the distribution. * 4. All advertising materials mentioning features or use of this software * must display the following acknowledgment: * This product includes software developed by Geoff Kuenning and * other unpaid contributors. * 5. The name of Geoff Kuenning may not be used to endorse or promote * products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED BY GEOFF KUENNING AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL GEOFF KUENNING OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /* * $Log$ * * Revision 1.2 2020/03/23 12:59:43 stevenwan * Add IBM AIX workaround. * * Revision 1.1 2007/01/09 23:57:18 lattner * initial recheckin of mibench * * Revision 1.1.1.1 2007/01/09 02:59:05 evancheng * Add selected tests from MiBench 1.0 to LLVM test suite. * * Revision 1.48 1994/10/25 05:46:11 geoff * Fix a couple of places where ifdefs were omitted, though apparently * harmlessly. * * Revision 1.47 1994/09/01 06:06:32 geoff * Change erasechar/killchar to uerasechar/ukillchar to avoid * shared-library problems on HP systems. * * Revision 1.46 1994/01/25 07:12:11 geoff * Get rid of all old RCS log lines in preparation for the 3.1 release. * */ #include "config.h" #include "ispell.h" #include "proto.h" #include "msgs.h" #include -#if defined(__GLIBC__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__) || (defined(__sun__) && defined(__svr4__)) -/* Use termios under at least glibc */ +#if defined(__GLIBC__) || defined(__FreeBSD__) || defined(__NetBSD__) || \ + defined(__OpenBSD__) || defined(__APPLE__) || \ + (defined(__sun__) && defined(__svr4__)) #include #define USE_TERMIOS #ifndef USG #define USG #endif #else #ifdef USG #include #else #include #endif #endif #if _AIX && !defined(_ALL_SOURCE) #ifdef TIOCGWINSZ #undef TIOCGWINSZ #endif #endif void erase P ((void)); void move P ((int row, int col)); void inverse P ((void)); void normal P ((void)); void backup P ((void)); static int putch P ((int c)); void terminit P ((void)); SIGNAL_TYPE done P ((int signo)); #ifdef SIGTSTP static SIGNAL_TYPE onstop P ((int signo)); #endif /* SIGTSTP */ void stop P ((void)); int shellescape P ((char * buf)); #ifdef USESH void shescape P ((char * buf)); #endif /* USESH */ void erase () { #ifdef FIXME if (cl) tputs (cl, li, putch); else { if (ho) tputs (ho, 100, putch); else if (cm) tputs (tgoto (cm, 0, 0), 100, putch); tputs (cd, li, putch); } #endif } void move (row, col) int row; int col; { #ifdef FIXME tputs (tgoto (cm, col, row), 100, putch); #endif } void inverse () { #ifdef FIXME tputs (so, 10, putch); #endif } void normal () { #ifdef FIXME tputs (se, 10, putch); #endif } void backup () { #ifdef FIXME if (BC) tputs (BC, 1, putch); else (void) putchar ('\b'); #endif } static int putch (c) int c; { return putchar (c); } #ifdef USE_TERMIOS static struct termios sbuf; static struct termios osbuf; #else #ifdef USG static struct termio sbuf; static struct termio osbuf; #else static struct sgttyb sbuf; static struct sgttyb osbuf; #ifdef TIOCSLTC static struct ltchars ltc; static struct ltchars oltc; #endif #endif #endif static int termchanged = 0; static SIGNAL_TYPE (*oldint) (); static SIGNAL_TYPE (*oldterm) (); #ifdef SIGTSTP static SIGNAL_TYPE (*oldttin) (); static SIGNAL_TYPE (*oldttou) (); static SIGNAL_TYPE (*oldtstp) (); #endif void terminit () { #ifdef TIOCPGRP int tpgrp; #else #ifdef TIOCGPGRP int tpgrp; #endif #endif #ifdef TIOCGWINSZ struct winsize wsize; #endif /* TIOCGWINSZ */ #ifdef FIXME tgetent (termcap, getenv ("TERM")); termptr = termstr; BC = tgetstr ("bc", &termptr); cd = tgetstr ("cd", &termptr); cl = tgetstr ("cl", &termptr); cm = tgetstr ("cm", &termptr); ho = tgetstr ("ho", &termptr); nd = tgetstr ("nd", &termptr); so = tgetstr ("so", &termptr); /* inverse video on */ se = tgetstr ("se", &termptr); /* inverse video off */ if ((sg = tgetnum ("sg")) < 0) /* space taken by so/se */ sg = 0; ti = tgetstr ("ti", &termptr); /* terminal initialization */ te = tgetstr ("te", &termptr); /* terminal termination */ co = tgetnum ("co"); li = tgetnum ("li"); #endif #ifdef TIOCGWINSZ if (ioctl (0, TIOCGWINSZ, (char *) &wsize) >= 0) { if (wsize.ws_col != 0) co = wsize.ws_col; if (wsize.ws_row != 0) li = wsize.ws_row; } #endif /* TIOCGWINSZ */ /* * Let the variables "LINES" and "COLUMNS" override the termcap * entry. Technically, this is a terminfo-ism, but I think the * vast majority of users will find it pretty handy. */ if (getenv ("COLUMNS") != NULL) co = atoi (getenv ("COLUMNS")); if (getenv ("LINES") != NULL) li = atoi (getenv ("LINES")); #if MAX_SCREEN_SIZE > 0 if (li > MAX_SCREEN_SIZE) li = MAX_SCREEN_SIZE; #endif /* MAX_SCREEN_SIZE > 0 */ #if MAXCONTEXT == MINCONTEXT contextsize = MINCONTEXT; #else /* MAXCONTEXT == MINCONTEXT */ if (contextsize == 0) #ifdef CONTEXTROUNDUP contextsize = (li * CONTEXTPCT + 99) / 100; #else /* CONTEXTROUNDUP */ contextsize = (li * CONTEXTPCT) / 100; #endif /* CONTEXTROUNDUP */ if (contextsize > MAXCONTEXT) contextsize = MAXCONTEXT; else if (contextsize < MINCONTEXT) contextsize = MINCONTEXT; #endif /* MAX_CONTEXT == MIN_CONTEXT */ /* * Insist on 2 lines for the screen header, 2 for blank lines * separating areas of the screen, 2 for word choices, and 2 for * the minimenu, plus however many are needed for context. If * possible, make the context smaller to fit on the screen. */ if (li < contextsize + 8 && contextsize > MINCONTEXT) { contextsize = li - 8; if (contextsize < MINCONTEXT) contextsize = MINCONTEXT; } if (li < MINCONTEXT + 8) (void) fprintf (stderr, TERM_C_SMALL_SCREEN, MINCONTEXT + 8); #ifdef SIGTSTP #ifdef TIOCPGRP retry: #endif /* SIGTSTP */ #endif /* TIOCPGRP */ #ifdef USG if (!isatty (0)) { (void) fprintf (stderr, TERM_C_NO_BATCH); exit (1); } #ifdef USE_TERMIOS (void) tcgetattr (0, &osbuf); #else (void) ioctl (0, TCGETA, (char *) &osbuf); #endif termchanged = 1; sbuf = osbuf; sbuf.c_lflag &= ~(ECHO | ECHOK | ECHONL | ICANON); sbuf.c_oflag &= ~(OPOST); sbuf.c_iflag &= ~(INLCR | IGNCR | ICRNL); sbuf.c_cc[VMIN] = 1; sbuf.c_cc[VTIME] = 1; #ifdef USE_TERMIOS (void) tcsetattr (0, TCSANOW, &sbuf); #else (void) ioctl (0, TCSETAW, (char *) &sbuf); #endif uerasechar = osbuf.c_cc[VERASE]; ukillchar = osbuf.c_cc[VKILL]; #endif #ifdef SIGTSTP #ifndef USG (void) sigsetmask (1<<(SIGTSTP-1) | 1<<(SIGTTIN-1) | 1<<(SIGTTOU-1)); #endif #endif #ifdef TIOCGPGRP if (ioctl (0, TIOCGPGRP, (char *) &tpgrp) != 0) { (void) fprintf (stderr, TERM_C_NO_BATCH); exit (1); } #endif #ifdef SIGTSTP #ifdef TIOCPGRP if (tpgrp != getpgrp(0)) /* not in foreground */ { #ifndef USG (void) sigsetmask (1 << (SIGTSTP - 1) | 1 << (SIGTTIN - 1)); #endif (void) signal (SIGTTOU, SIG_DFL); (void) kill (0, SIGTTOU); /* job stops here waiting for SIGCONT */ goto retry; } #endif #endif #ifndef USG (void) ioctl (0, TIOCGETP, (char *) &osbuf); #ifdef TIOCGLTC (void) ioctl (0, TIOCGLTC, (char *) &oltc); #endif termchanged = 1; sbuf = osbuf; sbuf.sg_flags &= ~ECHO; sbuf.sg_flags |= TERM_MODE; (void) ioctl (0, TIOCSETP, (char *) &sbuf); uerasechar = sbuf.sg_erase; ukillchar = sbuf.sg_kill; #ifdef TIOCSLTC ltc = oltc; ltc.t_suspc = -1; (void) ioctl (0, TIOCSLTC, (char *) <c); #endif #endif /* USG */ if ((oldint = signal (SIGINT, SIG_IGN)) != SIG_IGN) (void) signal (SIGINT, done); if ((oldterm = signal (SIGTERM, SIG_IGN)) != SIG_IGN) (void) signal (SIGTERM, done); #ifdef SIGTSTP #ifndef USG (void) sigsetmask (0); #endif if ((oldttin = signal (SIGTTIN, SIG_IGN)) != SIG_IGN) (void) signal (SIGTTIN, onstop); if ((oldttou = signal (SIGTTOU, SIG_IGN)) != SIG_IGN) (void) signal (SIGTTOU, onstop); if ((oldtstp = signal (SIGTSTP, SIG_IGN)) != SIG_IGN) (void) signal (SIGTSTP, onstop); #endif #ifdef FIXME if (ti) tputs (ti, 1, putch); #endif } /* ARGSUSED */ SIGNAL_TYPE done (signo) int signo; { if (tempfile[0] != '\0') (void) unlink (tempfile); if (termchanged) { #ifdef FIXME if (te) tputs (te, 1, putch); #ifdef USE_TERMIOS (void) tcsetattr (0, TCSADRAIN, &osbuf); #else #ifdef USG (void) ioctl (0, TCSETAW, (char *) &osbuf); #else (void) ioctl (0, TIOCSETP, (char *) &osbuf); #ifdef TIOCSLTC (void) ioctl (0, TIOCSLTC, (char *) &oltc); #endif #endif #endif #endif } exit (0); } #ifdef SIGTSTP static SIGNAL_TYPE onstop (signo) int signo; { #ifdef USE_TERMIOS (void) tcsetattr (0, TCSANOW, &osbuf); #else #ifdef USG (void) ioctl (0, TCSETAW, (char *) &osbuf); #else (void) ioctl (0, TIOCSETP, (char *) &osbuf); #ifdef TIOCSLTC (void) ioctl (0, TIOCSLTC, (char *) &oltc); #endif #endif #endif (void) signal (signo, SIG_DFL); #ifndef USG (void) sigsetmask (sigblock (0) & ~(1 << (signo - 1))); #endif (void) kill (0, signo); /* stop here until continued */ (void) signal (signo, onstop); #ifdef USE_TERMIOS (void) tcsetattr (0, TCSANOW, &sbuf); #else #ifdef USG (void) ioctl (0, TCSETAW, (char *) &sbuf); #else (void) ioctl (0, TIOCSETP, (char *) &sbuf); #ifdef TIOCSLTC (void) ioctl (0, TIOCSLTC, (char *) <c); #endif #endif #endif } #endif void stop () { #ifdef SIGTSTP onstop (SIGTSTP); #else /* for System V */ move (li - 1, 0); (void) fflush (stdout); if (getenv ("SHELL")) (void) shellescape (getenv ("SHELL")); else (void) shellescape ("sh"); #endif } /* Fork and exec a process. Returns NZ if command found, regardless of ** command's return status. Returns zero if command was not found. ** Doesn't use a shell. */ #ifndef USESH #define NEED_SHELLESCAPE #endif /* USESH */ #ifndef REGEX_LOOKUP #define NEED_SHELLESCAPE #endif /* REGEX_LOOKUP */ #ifdef NEED_SHELLESCAPE int shellescape (buf) char * buf; { char * argv[100]; char * cp = buf; int i = 0; int termstat; /* parse buf to args (destroying it in the process) */ while (*cp != '\0') { while (*cp == ' ' || *cp == '\t') ++cp; if (*cp == '\0') break; argv[i++] = cp; while (*cp != ' ' && *cp != '\t' && *cp != '\0') ++cp; if (*cp != '\0') *cp++ = '\0'; } argv[i] = NULL; #ifdef USE_TERMIOS (void) tcsetattr (0, TCSANOW, &osbuf); #else #ifdef USG (void) ioctl (0, TCSETAW, (char *) &osbuf); #else (void) ioctl (0, TIOCSETP, (char *) &osbuf); #ifdef TIOCSLTC (void) ioctl (0, TIOCSLTC, (char *) &oltc); #endif /* TIOCSLTC */ #endif #endif (void) signal (SIGINT, oldint); (void) signal (SIGTERM, oldterm); #ifdef SIGTSTP (void) signal (SIGTTIN, oldttin); (void) signal (SIGTTOU, oldttou); (void) signal (SIGTSTP, oldtstp); #endif if ((i = fork ()) == 0) { (void) execvp (argv[0], (char **) argv); _exit (123); /* Command not found */ } else if (i > 0) { while (wait (&termstat) != i) ; termstat = (termstat == (123 << 8)) ? 0 : -1; } else { (void) printf (TERM_C_CANT_FORK); termstat = -1; /* Couldn't fork */ } if (oldint != SIG_IGN) (void) signal (SIGINT, done); if (oldterm != SIG_IGN) (void) signal (SIGTERM, done); #ifdef SIGTSTP if (oldttin != SIG_IGN) (void) signal (SIGTTIN, onstop); if (oldttou != SIG_IGN) (void) signal (SIGTTOU, onstop); if (oldtstp != SIG_IGN) (void) signal (SIGTSTP, onstop); #endif #ifdef USE_TERMIOS (void) tcsetattr (0, TCSANOW, &sbuf); #else #ifdef USG (void) ioctl (0, TCSETAW, (char *) &sbuf); #else (void) ioctl (0, TIOCSETP, (char *) &sbuf); #ifdef TIOCSLTC (void) ioctl (0, TIOCSLTC, (char *) <c); #endif /* TIOCSLTC */ #endif #endif if (termstat) { (void) printf (TERM_C_TYPE_SPACE); (void) fflush (stdout); #ifdef COMMANDFORSPACE i = GETKEYSTROKE (); if (i != ' ' && i != '\n' && i != '\r') (void) ungetc (i, stdin); #else while (GETKEYSTROKE () != ' ') ; #endif } return (termstat); } #endif /* NEED_SHELLESCAPE */ #ifdef USESH void shescape (buf) char * buf; { #ifdef COMMANDFORSPACE int ch; #endif #ifdef USE_TERMIOS (void) tcsetattr (0, TCSANOW, &osbuf); #else #ifdef USG (void) ioctl (0, TCSETAW, (char *) &osbuf); #else (void) ioctl (0, TIOCSETP, (char *) &osbuf); #ifdef TIOCSLTC (void) ioctl (0, TIOCSLTC, (char *) &oltc); #endif #endif #endif (void) signal (SIGINT, oldint); (void) signal (SIGTERM, oldterm); #ifdef SIGTSTP (void) signal (SIGTTIN, oldttin); (void) signal (SIGTTOU, oldttou); (void) signal (SIGTSTP, oldtstp); #endif (void) system (buf); if (oldint != SIG_IGN) (void) signal (SIGINT, done); if (oldterm != SIG_IGN) (void) signal (SIGTERM, done); #ifdef SIGTSTP if (oldttin != SIG_IGN) (void) signal (SIGTTIN, onstop); if (oldttou != SIG_IGN) (void) signal (SIGTTOU, onstop); if (oldtstp != SIG_IGN) (void) signal (SIGTSTP, onstop); #endif #ifdef USE_TERMIOS (void) tcsetattr (0, TCSANOW, &sbuf); #else #ifdef USG (void) ioctl (0, TCSETAW, (char *) &sbuf); #else (void) ioctl (0, TIOCSETP, (char *) &sbuf); #ifdef TIOCSLTC (void) ioctl (0, TIOCSLTC, (char *) <c); #endif #endif #endif (void) printf (TERM_C_TYPE_SPACE); (void) fflush (stdout); #ifdef COMMANDFORSPACE ch = GETKEYSTROKE (); if (ch != ' ' && ch != '\n' && ch != '\r') (void) ungetc (ch, stdin); #else while (GETKEYSTROKE () != ' ') ; #endif } #endif diff --git a/SingleSource/Benchmarks/Misc/oourafft.c b/SingleSource/Benchmarks/Misc/oourafft.c index bcc2895e2..f7f1967d6 100644 --- a/SingleSource/Benchmarks/Misc/oourafft.c +++ b/SingleSource/Benchmarks/Misc/oourafft.c @@ -1,759 +1,763 @@ #include #include #include #include -#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(_AIX) // memalign +/* memalign */ +#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__NetBSD__) && \ + !defined(__OpenBSD__) && !defined(_AIX) #include #endif /* random number generator, 0 <= RND < 1 */ #define RND(p) ((*(p) = (*(p) * 7141 + 54773) % 259200) * (1.0 / 259200.0)) #define MAX(x,y) ((x) > (y) ? (x) : (y)) void makewt(int nw, int *ip, double *w); void cdft(int, int, double *, int *, double *); void putdata(int nini, int nend, double *a); double errorcheck(int nini, int nend, double scale, double *a); double get_time(void); #define N 1024 #ifdef SMALL_PROBLEM_SIZE #define TRIES 5000 #else #define TRIES 150000 #endif int main() { int i, j; int *ip; double *ref, *cmp, *src, *w; double t_start, t_end, t_overhead, t_total = 0, err_val; /* Measure overhead of get_time() call */ t_start = get_time(); t_end = get_time(); t_overhead = t_end - t_start; /* Prepare aux data */ -#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(_AIX) /* Darwin always 16-byte aligns malloc data */ + /* Darwin always 16-byte aligns malloc data */ +#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__NetBSD__) && \ + !defined(__OpenBSD__) && !defined(_AIX) ip = memalign(16, sqrt(N)*sizeof(int)); w = memalign(16, 2*N*5/4*sizeof(double)); #else ip = malloc(sqrt(N)*sizeof(int)); w = malloc(2*N*5/4*sizeof(double)); #endif makewt(N >> 1, ip, w); /* Allocate buffers */ -#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(_AIX) /* Darwin always 16-byte aligns malloc data */ + /* Darwin always 16-byte aligns malloc data */ +#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__NetBSD__) && \ + !defined(__OpenBSD__) && !defined(_AIX) ref = memalign(16, 2*N*sizeof(double)); cmp = memalign(16, 2*N*sizeof(double)); src = memalign(16, 2*N*sizeof(double)); #else ref = malloc(2*N*sizeof(double)); cmp = malloc(2*N*sizeof(double)); src = malloc(2*N*sizeof(double)); #endif /* Perform sanity check of FFT */ putdata(0, 2*N - 1, ref); cdft(2*N, 1, ref, ip, w); cdft(2*N, -1, ref, ip, w); err_val = errorcheck(0, 2*N - 1, 1.0/N, ref); if (fabs(err_val) > 1e-10) { printf("FFT sanity check failed! Difference is: %le\n", err_val); abort(); } /* Prepare reference sequence */ memset(ref, 0, 2*N*sizeof(double)); putdata(0, N-1, ref); cdft(2*N, 1, ref, ip, w); for (j=0; j 1e-9 ? cmp[2*j] : 0), (fabs(cmp[2*j+1]) > 1e-9 ? cmp[2*j+1] : 0)); } /*printf("Overall time: %le, for single correlation: %le\n", t_total, t_total/TRIES);*/ free(ref); free(w); free(ip); free(cmp); free(src); return 0; } void putdata(int nini, int nend, double *a) { int j, seed = 0; for (j = nini; j <= nend; j++) a[j] = RND(&seed); } double errorcheck(int nini, int nend, double scale, double *a) { int j, seed = 0; double err = 0, e; for (j = nini; j <= nend; j++) { e = RND(&seed) - a[j] * scale; err = MAX(err, fabs(e)); } return err; } #ifdef WIN32 #include static LARGE_INTEGER t = {0, 0}; double get_time(void) { LARGE_INTEGER l; if (t.QuadPart == 0) QueryPerformanceFrequency(&t); QueryPerformanceCounter(&l); return (double)l.QuadPart / (double)t.QuadPart; } #else #include double get_time(void) { struct timeval tv; gettimeofday(&tv, NULL); return (double)tv.tv_sec + (double)tv.tv_usec * 0.000001; } #endif void makewt(int nw, int *ip, double *w); static void bitrv2(int n, int *ip, double *a); static void bitrv2conj(int n, int *ip, double *a); static void cftfsub(int n, double *a, double *w); static void cftbsub(int n, double *a, double *w); static inline void cft1st(int n, double *a, double *w); static inline void cftmdl(int n, int l, double *a, double *w); void cdft(int n, int isgn, double *a, int *ip, double *w) { if (n > 4) { if (isgn >= 0) { bitrv2(n, ip, a); cftfsub(n, a, w); } else { bitrv2conj(n, ip, a); cftbsub(n, a, w); } } else if (n == 4) { cftfsub(n, a, w); } } /* -------- initializing routines -------- */ -#include - void makewt(int nw, int *ip, double *w) { int j, nwh; double delta, x, y; if (nw > 2) { nwh = nw >> 1; delta = atan(1.0) / nwh; w[0] = 1; w[1] = 0; w[nwh] = cos(delta * nwh); w[nwh + 1] = w[nwh]; if (nwh > 2) { for (j = 2; j < nwh; j += 2) { x = cos(delta * j); y = sin(delta * j); w[j] = x; w[j + 1] = y; w[nw - j] = y; w[nw - j + 1] = x; } bitrv2(nw, ip, w); } } } /* -------- child routines -------- */ void bitrv2(int n, int *ip, double *a) { int j, j1, k, k1, l, m, m2; double xr, xi, yr, yi; ip[0] = 0; l = n; m = 1; while ((m << 3) < l) { l >>= 1; for (j = 0; j < m; j++) { ip[m + j] = ip[j] + l; } m <<= 1; } m2 = 2 * m; if ((m << 3) == l) { for (k = 0; k < m; k++) { for (j = 0; j < k; j++) { j1 = 2 * j + ip[k]; k1 = 2 * k + ip[j]; xr = a[j1]; xi = a[j1 + 1]; yr = a[k1]; yi = a[k1 + 1]; a[j1] = yr; a[j1 + 1] = yi; a[k1] = xr; a[k1 + 1] = xi; j1 += m2; k1 += 2 * m2; xr = a[j1]; xi = a[j1 + 1]; yr = a[k1]; yi = a[k1 + 1]; a[j1] = yr; a[j1 + 1] = yi; a[k1] = xr; a[k1 + 1] = xi; j1 += m2; k1 -= m2; xr = a[j1]; xi = a[j1 + 1]; yr = a[k1]; yi = a[k1 + 1]; a[j1] = yr; a[j1 + 1] = yi; a[k1] = xr; a[k1 + 1] = xi; j1 += m2; k1 += 2 * m2; xr = a[j1]; xi = a[j1 + 1]; yr = a[k1]; yi = a[k1 + 1]; a[j1] = yr; a[j1 + 1] = yi; a[k1] = xr; a[k1 + 1] = xi; } j1 = 2 * k + m2 + ip[k]; k1 = j1 + m2; xr = a[j1]; xi = a[j1 + 1]; yr = a[k1]; yi = a[k1 + 1]; a[j1] = yr; a[j1 + 1] = yi; a[k1] = xr; a[k1 + 1] = xi; } } else { for (k = 1; k < m; k++) { for (j = 0; j < k; j++) { j1 = 2 * j + ip[k]; k1 = 2 * k + ip[j]; xr = a[j1]; xi = a[j1 + 1]; yr = a[k1]; yi = a[k1 + 1]; a[j1] = yr; a[j1 + 1] = yi; a[k1] = xr; a[k1 + 1] = xi; j1 += m2; k1 += m2; xr = a[j1]; xi = a[j1 + 1]; yr = a[k1]; yi = a[k1 + 1]; a[j1] = yr; a[j1 + 1] = yi; a[k1] = xr; a[k1 + 1] = xi; } } } } static void bitrv2conj(int n, int *ip, double *a) { int j, j1, k, k1, l, m, m2; double xr, xi, yr, yi; ip[0] = 0; l = n; m = 1; while ((m << 3) < l) { l >>= 1; for (j = 0; j < m; j++) { ip[m + j] = ip[j] + l; } m <<= 1; } m2 = 2 * m; if ((m << 3) == l) { for (k = 0; k < m; k++) { for (j = 0; j < k; j++) { j1 = 2 * j + ip[k]; k1 = 2 * k + ip[j]; xr = a[j1]; xi = -a[j1 + 1]; yr = a[k1]; yi = -a[k1 + 1]; a[j1] = yr; a[j1 + 1] = yi; a[k1] = xr; a[k1 + 1] = xi; j1 += m2; k1 += 2 * m2; xr = a[j1]; xi = -a[j1 + 1]; yr = a[k1]; yi = -a[k1 + 1]; a[j1] = yr; a[j1 + 1] = yi; a[k1] = xr; a[k1 + 1] = xi; j1 += m2; k1 -= m2; xr = a[j1]; xi = -a[j1 + 1]; yr = a[k1]; yi = -a[k1 + 1]; a[j1] = yr; a[j1 + 1] = yi; a[k1] = xr; a[k1 + 1] = xi; j1 += m2; k1 += 2 * m2; xr = a[j1]; xi = -a[j1 + 1]; yr = a[k1]; yi = -a[k1 + 1]; a[j1] = yr; a[j1 + 1] = yi; a[k1] = xr; a[k1 + 1] = xi; } k1 = 2 * k + ip[k]; a[k1 + 1] = -a[k1 + 1]; j1 = k1 + m2; k1 = j1 + m2; xr = a[j1]; xi = -a[j1 + 1]; yr = a[k1]; yi = -a[k1 + 1]; a[j1] = yr; a[j1 + 1] = yi; a[k1] = xr; a[k1 + 1] = xi; k1 += m2; a[k1 + 1] = -a[k1 + 1]; } } else { a[1] = -a[1]; a[m2 + 1] = -a[m2 + 1]; for (k = 1; k < m; k++) { for (j = 0; j < k; j++) { j1 = 2 * j + ip[k]; k1 = 2 * k + ip[j]; xr = a[j1]; xi = -a[j1 + 1]; yr = a[k1]; yi = -a[k1 + 1]; a[j1] = yr; a[j1 + 1] = yi; a[k1] = xr; a[k1 + 1] = xi; j1 += m2; k1 += m2; xr = a[j1]; xi = -a[j1 + 1]; yr = a[k1]; yi = -a[k1 + 1]; a[j1] = yr; a[j1 + 1] = yi; a[k1] = xr; a[k1 + 1] = xi; } k1 = 2 * k + ip[k]; a[k1 + 1] = -a[k1 + 1]; a[k1 + m2 + 1] = -a[k1 + m2 + 1]; } } } void cftfsub(int n, double *a, double *w) { int j, j1, j2, j3, l; double x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i; l = 2; if (n > 8) { cft1st(n, a, w); l = 8; while ((l << 2) < n) { cftmdl(n, l, a, w); l <<= 2; } } if ((l << 2) == n) { for (j = 0; j < l; j += 2) { j1 = j + l; j2 = j1 + l; j3 = j2 + l; x0r = a[j] + a[j1]; x0i = a[j + 1] + a[j1 + 1]; x1r = a[j] - a[j1]; x1i = a[j + 1] - a[j1 + 1]; x2r = a[j2] + a[j3]; x2i = a[j2 + 1] + a[j3 + 1]; x3r = a[j2] - a[j3]; x3i = a[j2 + 1] - a[j3 + 1]; a[j] = x0r + x2r; a[j + 1] = x0i + x2i; a[j2] = x0r - x2r; a[j2 + 1] = x0i - x2i; a[j1] = x1r - x3i; a[j1 + 1] = x1i + x3r; a[j3] = x1r + x3i; a[j3 + 1] = x1i - x3r; } } else { for (j = 0; j < l; j += 2) { j1 = j + l; x0r = a[j] - a[j1]; x0i = a[j + 1] - a[j1 + 1]; a[j] += a[j1]; a[j + 1] += a[j1 + 1]; a[j1] = x0r; a[j1 + 1] = x0i; } } } void cftbsub(int n, double *a, double *w) { int j, j1, j2, j3, l; double x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i; l = 2; if (n > 8) { cft1st(n, a, w); l = 8; while ((l << 2) < n) { cftmdl(n, l, a, w); l <<= 2; } } if ((l << 2) == n) { for (j = 0; j < l; j += 2) { j1 = j + l; j2 = j1 + l; j3 = j2 + l; x0r = a[j] + a[j1]; x0i = -a[j + 1] - a[j1 + 1]; x1r = a[j] - a[j1]; x1i = -a[j + 1] + a[j1 + 1]; x2r = a[j2] + a[j3]; x2i = a[j2 + 1] + a[j3 + 1]; x3r = a[j2] - a[j3]; x3i = a[j2 + 1] - a[j3 + 1]; a[j] = x0r + x2r; a[j + 1] = x0i - x2i; a[j2] = x0r - x2r; a[j2 + 1] = x0i + x2i; a[j1] = x1r - x3i; a[j1 + 1] = x1i - x3r; a[j3] = x1r + x3i; a[j3 + 1] = x1i + x3r; } } else { for (j = 0; j < l; j += 2) { j1 = j + l; x0r = a[j] - a[j1]; x0i = -a[j + 1] + a[j1 + 1]; a[j] += a[j1]; a[j + 1] = -a[j + 1] - a[j1 + 1]; a[j1] = x0r; a[j1 + 1] = x0i; } } } void cft1st(int n, double *a, double *w) { int j, k1, k2; double wk1r, wk1i, wk2r, wk2i, wk3r, wk3i; double x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i; x0r = a[0] + a[2]; x0i = a[1] + a[3]; x1r = a[0] - a[2]; x1i = a[1] - a[3]; x2r = a[4] + a[6]; x2i = a[5] + a[7]; x3r = a[4] - a[6]; x3i = a[5] - a[7]; a[0] = x0r + x2r; a[1] = x0i + x2i; a[4] = x0r - x2r; a[5] = x0i - x2i; a[2] = x1r - x3i; a[3] = x1i + x3r; a[6] = x1r + x3i; a[7] = x1i - x3r; wk1r = w[2]; x0r = a[8] + a[10]; x0i = a[9] + a[11]; x1r = a[8] - a[10]; x1i = a[9] - a[11]; x2r = a[12] + a[14]; x2i = a[13] + a[15]; x3r = a[12] - a[14]; x3i = a[13] - a[15]; a[8] = x0r + x2r; a[9] = x0i + x2i; a[12] = x2i - x0i; a[13] = x0r - x2r; x0r = x1r - x3i; x0i = x1i + x3r; a[10] = wk1r * (x0r - x0i); a[11] = wk1r * (x0r + x0i); x0r = x3i + x1r; x0i = x3r - x1i; a[14] = wk1r * (x0i - x0r); a[15] = wk1r * (x0i + x0r); k1 = 0; for (j = 16; j < n; j += 16) { k1 += 2; k2 = 2 * k1; wk2r = w[k1]; wk2i = w[k1 + 1]; wk1r = w[k2]; wk1i = w[k2 + 1]; wk3r = wk1r - 2 * wk2i * wk1i; wk3i = 2 * wk2i * wk1r - wk1i; x0r = a[j] + a[j + 2]; x0i = a[j + 1] + a[j + 3]; x1r = a[j] - a[j + 2]; x1i = a[j + 1] - a[j + 3]; x2r = a[j + 4] + a[j + 6]; x2i = a[j + 5] + a[j + 7]; x3r = a[j + 4] - a[j + 6]; x3i = a[j + 5] - a[j + 7]; a[j] = x0r + x2r; a[j + 1] = x0i + x2i; x0r -= x2r; x0i -= x2i; a[j + 4] = wk2r * x0r - wk2i * x0i; a[j + 5] = wk2r * x0i + wk2i * x0r; x0r = x1r - x3i; x0i = x1i + x3r; a[j + 2] = wk1r * x0r - wk1i * x0i; a[j + 3] = wk1r * x0i + wk1i * x0r; x0r = x1r + x3i; x0i = x1i - x3r; a[j + 6] = wk3r * x0r - wk3i * x0i; a[j + 7] = wk3r * x0i + wk3i * x0r; wk1r = w[k2 + 2]; wk1i = w[k2 + 3]; wk3r = wk1r - 2 * wk2r * wk1i; wk3i = 2 * wk2r * wk1r - wk1i; x0r = a[j + 8] + a[j + 10]; x0i = a[j + 9] + a[j + 11]; x1r = a[j + 8] - a[j + 10]; x1i = a[j + 9] - a[j + 11]; x2r = a[j + 12] + a[j + 14]; x2i = a[j + 13] + a[j + 15]; x3r = a[j + 12] - a[j + 14]; x3i = a[j + 13] - a[j + 15]; a[j + 8] = x0r + x2r; a[j + 9] = x0i + x2i; x0r -= x2r; x0i -= x2i; a[j + 12] = -wk2i * x0r - wk2r * x0i; a[j + 13] = -wk2i * x0i + wk2r * x0r; x0r = x1r - x3i; x0i = x1i + x3r; a[j + 10] = wk1r * x0r - wk1i * x0i; a[j + 11] = wk1r * x0i + wk1i * x0r; x0r = x1r + x3i; x0i = x1i - x3r; a[j + 14] = wk3r * x0r - wk3i * x0i; a[j + 15] = wk3r * x0i + wk3i * x0r; } } void cftmdl(int n, int l, double *a, double *w) { int j, j1, j2, j3, k, k1, k2, m, m2; double wk1r, wk1i, wk2r, wk2i, wk3r, wk3i; double x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i; m = l << 2; for (j = 0; j < l; j += 2) { j1 = j + l; j2 = j1 + l; j3 = j2 + l; x0r = a[j] + a[j1]; x0i = a[j + 1] + a[j1 + 1]; x1r = a[j] - a[j1]; x1i = a[j + 1] - a[j1 + 1]; x2r = a[j2] + a[j3]; x2i = a[j2 + 1] + a[j3 + 1]; x3r = a[j2] - a[j3]; x3i = a[j2 + 1] - a[j3 + 1]; a[j] = x0r + x2r; a[j + 1] = x0i + x2i; a[j2] = x0r - x2r; a[j2 + 1] = x0i - x2i; a[j1] = x1r - x3i; a[j1 + 1] = x1i + x3r; a[j3] = x1r + x3i; a[j3 + 1] = x1i - x3r; } wk1r = w[2]; for (j = m; j < l + m; j += 2) { j1 = j + l; j2 = j1 + l; j3 = j2 + l; x0r = a[j] + a[j1]; x0i = a[j + 1] + a[j1 + 1]; x1r = a[j] - a[j1]; x1i = a[j + 1] - a[j1 + 1]; x2r = a[j2] + a[j3]; x2i = a[j2 + 1] + a[j3 + 1]; x3r = a[j2] - a[j3]; x3i = a[j2 + 1] - a[j3 + 1]; a[j] = x0r + x2r; a[j + 1] = x0i + x2i; a[j2] = x2i - x0i; a[j2 + 1] = x0r - x2r; x0r = x1r - x3i; x0i = x1i + x3r; a[j1] = wk1r * (x0r - x0i); a[j1 + 1] = wk1r * (x0r + x0i); x0r = x3i + x1r; x0i = x3r - x1i; a[j3] = wk1r * (x0i - x0r); a[j3 + 1] = wk1r * (x0i + x0r); } k1 = 0; m2 = 2 * m; for (k = m2; k < n; k += m2) { k1 += 2; k2 = 2 * k1; wk2r = w[k1]; wk2i = w[k1 + 1]; wk1r = w[k2]; wk1i = w[k2 + 1]; wk3r = wk1r - 2 * wk2i * wk1i; wk3i = 2 * wk2i * wk1r - wk1i; for (j = k; j < l + k; j += 2) { j1 = j + l; j2 = j1 + l; j3 = j2 + l; x0r = a[j] + a[j1]; x0i = a[j + 1] + a[j1 + 1]; x1r = a[j] - a[j1]; x1i = a[j + 1] - a[j1 + 1]; x2r = a[j2] + a[j3]; x2i = a[j2 + 1] + a[j3 + 1]; x3r = a[j2] - a[j3]; x3i = a[j2 + 1] - a[j3 + 1]; a[j] = x0r + x2r; a[j + 1] = x0i + x2i; x0r -= x2r; x0i -= x2i; a[j2] = wk2r * x0r - wk2i * x0i; a[j2 + 1] = wk2r * x0i + wk2i * x0r; x0r = x1r - x3i; x0i = x1i + x3r; a[j1] = wk1r * x0r - wk1i * x0i; a[j1 + 1] = wk1r * x0i + wk1i * x0r; x0r = x1r + x3i; x0i = x1i - x3r; a[j3] = wk3r * x0r - wk3i * x0i; a[j3 + 1] = wk3r * x0i + wk3i * x0r; } wk1r = w[k2 + 2]; wk1i = w[k2 + 3]; wk3r = wk1r - 2 * wk2r * wk1i; wk3i = 2 * wk2r * wk1r - wk1i; for (j = k + m; j < l + (k + m); j += 2) { j1 = j + l; j2 = j1 + l; j3 = j2 + l; x0r = a[j] + a[j1]; x0i = a[j + 1] + a[j1 + 1]; x1r = a[j] - a[j1]; x1i = a[j + 1] - a[j1 + 1]; x2r = a[j2] + a[j3]; x2i = a[j2 + 1] + a[j3 + 1]; x3r = a[j2] - a[j3]; x3i = a[j2 + 1] - a[j3 + 1]; a[j] = x0r + x2r; a[j + 1] = x0i + x2i; x0r -= x2r; x0i -= x2i; a[j2] = -wk2i * x0r - wk2r * x0i; a[j2 + 1] = -wk2i * x0i + wk2r * x0r; x0r = x1r - x3i; x0i = x1i + x3r; a[j1] = wk1r * x0r - wk1i * x0i; a[j1 + 1] = wk1r * x0i + wk1i * x0r; x0r = x1r + x3i; x0i = x1i - x3r; a[j3] = wk3r * x0r - wk3i * x0i; a[j3 + 1] = wk3r * x0i + wk3i * x0r; } } } diff --git a/SingleSource/UnitTests/2005-05-11-Popcount-ffs-fls.c b/SingleSource/UnitTests/2005-05-11-Popcount-ffs-fls.c index b0e9877cc..8fbd73b69 100644 --- a/SingleSource/UnitTests/2005-05-11-Popcount-ffs-fls.c +++ b/SingleSource/UnitTests/2005-05-11-Popcount-ffs-fls.c @@ -1,116 +1,121 @@ /* these first three reference functions were taken from * http://www.hackersdelight.org/HDcode/nlz.cc and * http://www.hackersdelight.org/HDcode/ntz.cc */ #if defined(__NetBSD__) #include #endif #include #include #include #if defined(__XS1B__) #include "xcoretestsuite.h" #endif #define u 99 int nlz10b(unsigned x) { static char table[64] = {32,20,19, u, u,18, u, 7, 10,17, u, u,14, u, 6, u, u, 9, u,16, u, u, 1,26, u,13, u, u,24, 5, u, u, u,21, u, 8,11, u,15, u, u, u, u, 2,27, 0,25, u, 22, u,12, u, u, 3,28, u, 23, u, 4,29, u, u,30,31}; x = x | (x >> 1); // Propagate leftmost x = x | (x >> 2); // 1-bit to the right. x = x | (x >> 4); x = x | (x >> 8); x = x & ~(x >> 16); x = (x << 9) - x; // Multiply by 511. x = (x << 11) - x; // Multiply by 2047. x = (x << 14) - x; // Multiply by 16383. return table[x >> 26]; } int nlzll(unsigned long long x) { if ((x >> 32) == 0) return nlz10b(x)+32; return nlz10b(x>>32); } int pop(unsigned x) { x = x - ((x >> 1) & 0x55555555); x = (x & 0x33333333) + ((x >> 2) & 0x33333333); x = (x + (x >> 4)) & 0x0F0F0F0F; x = x + (x << 8); x = x + (x << 16); return x >> 24; } int popll(unsigned long long x) { return pop(x) + pop(x >> 32); } int ntz8(unsigned x) { static char table[64] = {32, 0, 1,12, 2, 6, u,13, 3, u, 7, u, u, u, u,14, 10, 4, u, u, 8, u, u,25, u, u, u, u, u,21,27,15, 31,11, 5, u, u, u, u, u, 9, u, u,24, u, u,20,26, 30, u, u, u, u,23, u,19, 29, u,22,18,28,17,16, u}; x = (x & -x)*0x0450FBAF; return table[x >> 26]; } /* Work with non-gcc compilers and GCC before 4.0 */ #if !defined(__GNUC__) || __GNUC__ < 4 #define __builtin_clz nlz10b #define __builtin_popcount pop #define __builtin_ctz ntz8 #define __builtin_clzll nlzll #define __builtin_popcountll popll #define __builtin_ffsl __builtin_ffs #define ffsl ffs #endif #if defined(__NetBSD__) #define ffsl ffs64 #endif +/* XXX */ +#if defined(__OpenBSD__) +#define ffsl ffs +#endif + int i; int main(void) { long long l; /* note: we don't test zero, because the _native_ test will get it * wrong (GCC returns garbage for ctz/clz of 0), and the nightly tester * will wrongly conclude that LLC is failing. */ for(i=10; i<139045193; i*=-3) { printf("LLVM: n: %d, clz(n): %d, popcount(n): %d, ctz(n): %d\n", i, __builtin_clz(i), __builtin_popcount(i), __builtin_ctz(i)); printf("REF : n: %d, clz(n): %d, popcount(n): %d, ctz(n): %d\n", i, nlz10b(i), pop(i), ntz8(i)); printf(" *** \n"); i++; } for(l=-10000; l<139045193*10000LL; l*=-3) { printf("LLVM: n: %lld, clz(n): %d, popcount(n): %d, ctz(n): %d\n", l, __builtin_clzll(l), __builtin_popcountll(l), __builtin_ctz(l)); printf("REF LO BITS : n: %lld, clz(n): %d, popcount(n): %d, ctz(n): %d\n", l, nlzll(l), popll(l), ntz8(l)); printf(" *** \n"); l++; } // Check some boundary and other cases for FFS call printf("FFS: 0:%d, 1:%d, 2:%d, 7:%d, 1024:%d, 1234:%d i:%d, l:%d\n", ffs(0), ffs(1), ffs(2), ffs(7), ffs(1024), ffs(1234), ffs(i), ffsl(l)); printf("__builtin_ffs: 0:%d, 1:%d, 2:%d, 7:%d, 1024:%d, 1234:%d i:%d l:%d\n", __builtin_ffs(0), __builtin_ffs(1), __builtin_ffs(2), __builtin_ffs(7), __builtin_ffs(1024), __builtin_ffs(1234), __builtin_ffs(i), __builtin_ffsl(l)); return(0); }