]> git.sesse.net Git - stockfish/commitdiff
Allow build on HP-UX 11.X
authorMarco Costalba <mcostalba@gmail.com>
Fri, 12 Feb 2010 05:49:16 +0000 (06:49 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Fri, 12 Feb 2010 05:49:16 +0000 (06:49 +0100)
Patch from Richard Lloyd (slightly edited from me), following the list
of changes as described by the author:

src/Makefile:
- Added PREFIX and BINDIR for the install: rule.
- Added a "make hpux" line to the help: rule.
- Added "make test"/"make check" rule that runs the $(PGOBENCH) command.
- "make clean" now additionally removes core and bench.txt.
- Added an hpux: rule.
- Added an install: rule to mkdir $(BINDIR), copy $(EXE) to $(BINDIR) and
 then strip it.
- "make strip" now ensures that $(EXE) is built first before trying to
 strip it.
- Hide errors and output from the g++ command used by the .depend: rule and
 then touch .depend in case g++ isn't available.
- Hide errors from the "include .depend" in case .depend doesn't exist
 (e.g. directly after a "make clean").

src/book.cpp and src/book.h:
- HP-UX's aCC really didn't like the const keywords used for the
 Book::file_name() definitions, so they were removed. I checked that this
 didn't affect a Linux build and it was still fine.

src/misc.cpp:
- HP-UX uses <sys/pstat.h> and pstat_getdynamic() to determine the number of
 CPU cores, so added conditional code for that (if pstat_getdynamic() fails,
 set the number of cores to 1).

src/tt.cpp:
- <xmmintrin.h> and _mm_prefetch() seem highly specific to the Intel x86(_64)
 and gcc platforms - neither exist in HP-UX, so conditionally avoid that
 code in HP-UX's case. Perhaps some sort of define is needed here
 such as -DHAS_MM_PREFETCH that could be #ifdef'ed for instead?

Even after these changes, it's more convenient for HP-UX users to edit the
default: rule in the Makefile to run "$(MAKE) hpux" before they build
stockfish, but that's not a big deal if they're warned about that first (the
same applies to all other builds other than the standard "$(MAKE) gcc" one).

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/Makefile
src/book.cpp
src/book.h
src/misc.cpp
src/tt.cpp

index 3963e5589d6fdfc85a87dd230ff0d3ef048830fc..62a874d5d217e4e38b366faa798b6fa36ea15343 100644 (file)
 ### Executable name. Do not change
 EXE = stockfish
 
+### Installation dir definitions
+PREFIX = /usr/local
+BINDIR = $(PREFIX)/bin
+
 
 ### ==========================================================================
 ### Compiler speed switches for both GCC and ICC. These settings are generally
@@ -92,14 +96,18 @@ help:
        @echo "make osx-icc64      >  x86-Mac OS X 64 bit. Compiler = icpc"
        @echo "make osx-icc32-profile > OSX 32 bit. Compiler = icpc + automatic pgo-build"
        @echo "make osx-icc64-profile > OSX 64 bit. Compiler = icpc + automatic pgo-build"
+       @echo "make hpux           >  HP-UX. Compiler = aCC"
        @echo "make strip          >  Strip executable"
        @echo "make clean          >  Clean up"
        @echo ""
 
 all: $(EXE) .depend
 
+test check: default
+       @$(PGOBENCH)
+
 clean:
-       $(RM) *.o .depend *~ $(EXE)
+       $(RM) *.o .depend *~ $(EXE) core bench.txt
 
 
 ### Possible targets. You may add your own ones here
@@ -296,6 +304,12 @@ osx-icc64-profile:
        $(MAKE) osx-icc64-profile-use
        @rm -rf profdir bench.txt
 
+hpux:
+       $(MAKE) \
+       CXX='/opt/aCC/bin/aCC -AA +hpxstd98 -DBIGENDIAN -mt +O3 -DNDEBUG' \
+       CXXFLAGS="" \
+       LDFLAGS="" \
+       all
 
 
 strip:
@@ -306,9 +320,14 @@ strip:
 $(EXE): $(OBJS)
        $(CXX) $(LDFLAGS) -o $@ $(OBJS)
 
+### Installation
+install: default
+       -mkdir -p -m 755 $(BINDIR)
+       -cp $(EXE) $(BINDIR)
+       -strip $(BINDIR)/$(EXE)
 
 ### Dependencies. Do not change
 .depend:
-       $(CXX) -msse -MM $(OBJS:.o=.cpp) > $@
+       -@$(CXX) -msse -MM $(OBJS:.o=.cpp) > $@ 2> /dev/null
 
 include .depend
index d825477f6ab9bbb82d909f4568ba9272fc430e90..1e4c9cc088aa277f998e70889cc285e8da3e20ab 100644 (file)
@@ -390,7 +390,7 @@ void Book::close() {
 /// Book::file_name() returns the file name of the currently active book,
 /// or the empty string if no book is open.
 
-const string Book::file_name() const {
+const string Book::file_name() { // Not const to compile on HP-UX 11.X
 
   return is_open() ? fileName : "";
 }
index b68f7bfcadb8ad258c4a8a0da0182e9f8fd479d2..1b7b72c4d90c0f9b326c1657a9db891cc7e1337b 100644 (file)
@@ -60,7 +60,7 @@ public:
   ~Book();
   void open(const std::string& fName);
   void close();
-  const std::string file_name() const;
+  const std::string file_name();
   Move get_move(const Position& pos);
 
 private:
index c692e996f2ce2fa292e287119c4a9699086aacc4..bf8143a33462780ac15e61fb3b9ddd4b6b8bc420 100644 (file)
@@ -27,6 +27,9 @@
 #  include <sys/time.h>
 #  include <sys/types.h>
 #  include <unistd.h>
+#  if defined(__hpux)
+#     include <sys/pstat.h>
+#  endif
 
 #else
 
@@ -187,6 +190,14 @@ int get_system_time() {
 int cpu_count() {
   return Min(sysconf(_SC_NPROCESSORS_ONLN), 8);
 }
+#  elif defined(__hpux)
+int cpu_count() {
+  struct pst_dynamic psd;
+  if (pstat_getdynamic(&psd, sizeof(psd), (size_t)1, 0) == -1)
+      return 1;
+
+  return Min(psd.psd_proc_cnt, 8);
+}
 #  else
 int cpu_count() {
   return 1;
index 010bdc954e60b0b0a438fdf2bdc417b3a65c0cef..8da3ca75767755f0e4198f98125fd0e23da12dfb 100644 (file)
@@ -25,7 +25,9 @@
 #include <cassert>
 #include <cmath>
 #include <cstring>
-#include <xmmintrin.h>
+#if !defined(__hpux)
+#  include <xmmintrin.h>
+#endif
 
 #include "movegen.h"
 #include "tt.h"
@@ -167,11 +169,14 @@ TTEntry* TranspositionTable::retrieve(const Key posKey) const {
 /// to be loaded from RAM, that can be very slow. When we will
 /// subsequently call retrieve() the TT data will be already
 /// quickly accessible in L1/L2 CPU cache.
+#if defined(__hpux)
+void TranspositionTable::prefetch(const Key) const {} // Not supported on HP UX
+#else
 
 void TranspositionTable::prefetch(const Key posKey) const {
 
 #if defined(__INTEL_COMPILER) || defined(__ICL)
-   // This hack prevents prefetches to be optimized away by the
+   // This hack prevents prefetches to be optimized away by
    // Intel compiler. Both MSVC and gcc seems not affected.
    __asm__ ("");
 #endif
@@ -181,6 +186,7 @@ void TranspositionTable::prefetch(const Key posKey) const {
   _mm_prefetch(addr+64, _MM_HINT_T2); // 64 bytes ahead
 }
 
+#endif
 
 /// TranspositionTable::new_search() is called at the beginning of every new
 /// search. It increments the "generation" variable, which is used to