Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oracle Developer Studio 12.6 fixes #201

Merged
merged 8 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 17 additions & 37 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ endif()
include(CheckIncludeFile)
include(CheckCCompilerFlag)
include(CheckCSourceCompiles)
include(CheckSymbolExists)
include(GenerateExportHeader)
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
Expand Down Expand Up @@ -167,14 +168,27 @@ target_include_directories(
target_link_libraries(zone-bench PRIVATE zone)

check_include_file(endian.h HAVE_ENDIAN_H)

check_include_file(unistd.h HAVE_UNISTD_H)
if(NOT HAVE_UNISTD_H)

set(CMAKE_REQUIRED_DEFINITIONS "-D_DEFAULT_SOURCE=1")
check_symbol_exists(getopt "stdlib.h;unistd.h" HAVE_GETOPT)
unset(CMAKE_REQUIRED_DEFINITIONS)
if(NOT HAVE_GETOPT)
target_include_directories(
zone-bench PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/compat>)
target_sources(zone-bench PRIVATE compat/getopt.c)
endif()

if(NOT WIN32)
# _fullpath is used on Microsoft Windows.
set(CMAKE_REQUIRED_DEFINITIONS "-D_DEFAULT_SOURCE=1")
check_symbol_exists(realpath "stdlib.h" HAVE_REALPATH)
unset(CMAKE_REQUIRED_DEFINITIONS)
if(NOT HAVE_REALPATH)
message(FATAL_ERROR "realpath is not available")
endif()
endif()

# Multiple instruction sets may be supported by a specific architecture.
# e.g. x86_64 may (or may not) support any of SSE42, AVX2 and AVX-512. The
# best instruction set is automatically selected at runtime, but the compiler
Expand Down Expand Up @@ -221,41 +235,7 @@ if(architecture STREQUAL "x86_64" OR architecture STREQUAL "amd64")
endif()


# Autoconf is supported for easy inclusion of simdzone in NSD. To avoid having
# to maintain multiple configuration headers, instead of using configure_file,
# read configure.ac and replace occurences of "AC_SUBST([<define>])". If an
# instance of AC_SUBST does not match expectations, throw an error.
file(READ configure.ac template)

set(pattern "(^|\n)[ \t]*AC_SUBST\([^\n]*)[ \t]*(\n|$)")
string(REGEX MATCHALL "${pattern}" matches "${template}")
foreach(match ${matches})
if (match MATCHES "[ \t]*AC_SUBST\\(\\[([a-zA-Z0-9_]+)\\]\\)[ \t]*")
set(variable "${CMAKE_MATCH_1}")
# Ignore any variables that do not start with HAVE_
if (variable MATCHES "^HAVE_")
if(NOT DEFINED ${variable} OR NOT ${variable} OR
${variable} MATCHES "^[Ff][Aa][Ll][Ss][Ee]$" OR
${variable} MATCHES "^[Oo][Ff][Ff]")
string(APPEND header "/* #undef ${variable} */\n")
elseif(${variable} MATCHES "^[Tt][Rr][Uu][Ee]$" OR
${variable} MATCHES "^[Oo][Nn]$")
string(APPEND header "#define ${variable} 1\n")
elseif(${variable} MATCHES "^[01234567890]+$")
string(APPEND header "#define ${variable} ${${variable}}\n")
else()
string(APPEND header "#define ${variable} \"${${variable}}\"\n")
endif()
else()
continue()
endif()

else()
message(FATAL_ERROR "Found AC_SUBST that not match expression")
endif()
endforeach()

file(GENERATE OUTPUT config.h CONTENT "${header}")
configure_file(src/config.h.in config.h)

if(BUILD_TESTING)
add_subdirectory(tests)
Expand Down
2 changes: 1 addition & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ HASWELL = @HAVE_HASWELL@
CC = @CC@
CPPFLAGS = @CPPFLAGS@ -I$(SOURCE)/include -I$(SOURCE)/src -I.
CFLAGS = @CFLAGS@
DEPFLAGS = -MT $@ -MMD -MP -MF $(@:.o=.d)
DEPFLAGS = @DEPFLAGS@
VPATH = @srcdir@

SOURCE = @srcdir@
Expand Down
18 changes: 17 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ AC_CONFIG_FILES([Makefile])
m4_include(m4/ax_check_compile_flag.m4)
m4_version_prereq([2.70], [AC_PROG_CC], [AC_PROG_CC_STDC])

AC_CHECK_HEADER(endian.h, AC_DEFINE(HAVE_ENDIAN_H, 1, [Wether or not have the <endian.h> header file]))
AC_CHECK_HEADER(endian.h, AC_DEFINE(HAVE_ENDIAN_H, 1, [Define to 1 if you have the <endian.h> header file.]))

AC_ARG_ENABLE(westmere, AS_HELP_STRING([--disable-westmere],[Disable Westmere (SSE4.2) kernel]))
case "$enable_westmere" in
Expand All @@ -32,6 +32,13 @@ case "$enable_haswell" in
yes|*) enable_haswell=yes ;;
esac

# GCC and Clang
AX_CHECK_COMPILE_FLAG([-MMD],DEPFLAGS="-MMD -MP")
# Oracle Developer Studio (no -MP)
AX_CHECK_COMPILE_FLAG([-xMMD],DEPFLAGS="-xMMD")

AC_SUBST([DEPFLAGS])

# Figure out the canonical target architecture.
AC_CANONICAL_TARGET

Expand Down Expand Up @@ -88,8 +95,17 @@ if test $x86_64 = "yes"; then
fi
fi

AC_CHECK_FUNCS([realpath],,[AC_MSG_ERROR([realpath is not available])])

AC_SUBST([HAVE_ENDIAN_H])
AC_SUBST([HAVE_WESTMERE])
AC_SUBST([HAVE_HASWELL])

AH_BOTTOM([
/* Defines _XOPEN_SOURCE and _POSIX_C_SOURCE implicitly in features.h */
#ifndef _DEFAULT_SOURCE
# define _DEFAULT_SOURCE 1
#endif
])

AC_OUTPUT
17 changes: 14 additions & 3 deletions src/attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
# define unlikely(params) (params)

#else // _MSC_VER
#if defined __has_builtin
# define has_builtin(params) __has_builtin(params)
#else
# define has_builtin(params) (0)
#endif

# if (zone_has_attribute(always_inline) || zone_has_gnuc(3, 1)) && ! defined __NO_INLINE__
// Compilation using GCC 4.2.1 without optimizations fails.
// sorry, unimplemented: inlining failed in call to ...
Expand Down Expand Up @@ -52,14 +58,19 @@
# define no_sanitize_undefined __attribute__((no_sanitize("undefined")))
# elif zone_has_attribute(no_sanitize_undefined)
// GCC 4.9.0 added the UndefinedBehaviorSanitizer (ubsan) and the
// no_sanitize_undefined function attribute.
// no_sanitize_undefined function attribute.
# define no_sanitize_undefined
# else
# define no_sanitize_undefined
# endif

# define likely(params) __builtin_expect(!!(params), 1)
# define unlikely(params) __builtin_expect(!!(params), 0)
# if has_builtin(__builtin_expect)
# define likely(params) __builtin_expect(!!(params), 1)
# define unlikely(params) __builtin_expect(!!(params), 0)
# else
# define likely(params) (params)
# define unlikely(params) (params)
# endif
#endif

#endif // ATTRIBUTES_H
5 changes: 3 additions & 2 deletions src/bench.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if _WIN32
#if !defined(HAVE_GETOPT)
# include "getopt.h"
#else
# include <unistd.h>
# include <strings.h>
#endif

#include "zone.h"
Expand All @@ -26,6 +25,8 @@
#if _MSC_VER
#define strcasecmp(s1, s2) _stricmp(s1, s2)
#define strncasecmp(s1, s2, n) _strnicmp(s1, s2, n)
#else
#include <strings.h>
#endif

typedef zone_parser_t parser_t;
Expand Down
29 changes: 29 additions & 0 deletions src/config.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* config.h.in -- configuration header template
*
* Copyright (c) 2024, NLnet Labs. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
#ifndef CONFIG_H
#define CONFIG_H

/* Define to 1 if you have the <endian.h> header file. */
#cmakedefine HAVE_ENDIAN_H 1

/* Define to 1 if you have the `getopt' function. */
#cmakedefine HAVE_GETOPT 1

/* Wether or not to compile support for AVX2 */
#cmakedefine HAVE_HASWELL 1

/* Wether or not to compile support for SSE4.2 */
#cmakedefine HAVE_WESTMERE 1

/* Defines _XOPEN_SOURCE and _POSIX_C_SOURCE implicitly in features.h */
#ifndef _DEFAULT_SOURCE
# define _DEFAULT_SOURCE 1
#endif

#endif // CONFIG_H
45 changes: 45 additions & 0 deletions src/fallback/bits.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,60 @@ static really_inline uint64_t leading_zeroes(uint64_t mask)
else
return 64;
}

#else

static really_inline uint64_t trailing_zeroes(uint64_t mask)
{
#if has_builtin(__builtin_ctzll)
return (uint64_t)__builtin_ctzll(mask);
#else
// Code by Kim Walish from https://www.chessprogramming.org/BitScan.
// Distributed under CC BY-SA 3.0.
static const uint64_t magic = 0x03f79d71b4cb0a89ull;
const int magictable[64] = {
0, 47, 1, 56, 48, 27, 2, 60,
57, 49, 41, 37, 28, 16, 3, 61,
54, 58, 35, 52, 50, 42, 21, 44,
38, 32, 29, 23, 17, 11, 4, 62,
46, 55, 26, 59, 40, 36, 15, 53,
34, 51, 20, 43, 31, 22, 10, 45,
25, 39, 14, 33, 19, 30, 9, 24,
13, 18, 8, 12, 7, 6, 5, 63
};

return magictable[((mask ^ (mask - 1)) * magic) >> 58];
#endif
}

static really_inline uint64_t leading_zeroes(uint64_t mask)
{
#if has_builtin(__builtin_clzll)
return (uint64_t)__builtin_clzll(mask);
#else
// Code by Kim Walish from https://www.chessprogramming.org/BitScan.
// Distributed under CC BY-SA 3.0.
static const uint64_t magic = 0x03f79d71b4cb0a89ull;
const int magictable[64] = {
63, 16, 62, 7, 15, 36, 61, 3,
6, 14, 22, 26, 35, 47, 60, 2,
9, 5, 28, 11, 13, 21, 42, 19,
25, 31, 34, 40, 46, 52, 59, 1,
17, 8, 37, 4, 23, 27, 48, 10,
29, 12, 43, 20, 32, 41, 53, 18,
38, 24, 49, 30, 44, 33, 54, 39,
50, 45, 55, 51, 56, 57, 58, 0
};

mask |= mask >> 1;
mask |= mask >> 2;
mask |= mask >> 4;
mask |= mask >> 8;
mask |= mask >> 16;
mask |= mask >> 32;

return magictable[(mask * magic) >> 58];
#endif
}
#endif // _MSC_VER
#endif // BITS_H
6 changes: 6 additions & 0 deletions src/generic/base16.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,13 @@ static really_inline int base16_stream_decode(
// Duff's device again:
switch (st.bytes)
{
#if defined(__SUNPRO_C)
#pragma error_messages(off, E_STATEMENT_NOT_REACHED)
#endif
for (;;)
#if defined(__SUNPRO_C)
#pragma error_messages(default, E_STATEMENT_NOT_REACHED)
#endif
{
case 0:
base16_dec_loop_generic_32(&s, &slen, &o, &olen);
Expand Down
6 changes: 6 additions & 0 deletions src/generic/base64.h
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,13 @@ static really_inline int base64_stream_decode(
// Duff's device again:
switch (st.bytes)
{
#if defined(__SUNPRO_C)
#pragma error_messages(off, E_STATEMENT_NOT_REACHED)
#endif
for (;;)
#if defined(__SUNPRO_C)
#pragma error_messages(default, E_STATEMENT_NOT_REACHED)
#endif
{
case 0:
dec_loop_generic_32(&s, &slen, &o, &olen);
Expand Down
Loading