Create new helper compiler_barrier to prevent compiler from over-optimizing bench.

This commit is contained in:
Patrick Pelissier committed 2019-02-18 10:46:21 +01:00
1 parent af2fe9ccf9
commit a36efcd888
2 files changed
+48 -7

No files matched your search

+32
View File
@@ -0,0 +1,32 @@
/*
* M*LIB - common functions for bench module
*
* Copyright (c) 2017-2019, Patrick Pelissier
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* + Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* + 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.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 THE REGENTS AND 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.
*/
#include "common.h"
void compiler_barrier(void *p)
{
// Do nothing, but let the compiler thinks that we did.
(void) p;
}
+16 -7
View File
@@ -25,11 +25,14 @@
#ifndef __COMMON_BENCH__H
#define __COMMON_BENCH__H
#include <stdio.h>
#include <stdlib.h>
#if defined(_WIN32)
/* WINDOWS variant */
#include <windows.h>
static unsigned long long
static inline unsigned long long
cputime (void)
{
LARGE_INTEGER freq, val;
@@ -44,7 +47,7 @@ cputime (void)
#include <sys/resource.h>
#include <sys/time.h>
static unsigned long long
static inline unsigned long long
cputime (void)
{
#if defined(MULTI_THREAD_MEASURE)
@@ -62,23 +65,24 @@ cputime (void)
#endif
unsigned long g_result;
static unsigned long g_result;
#if defined(MULTI_THREAD_MEASURE)
M_THREAD_ATTR
#endif
unsigned int randValue = 0;
static unsigned int randValue = 0;
static void rand_init(void)
static inline void rand_init(void)
{
randValue = 0;
}
static unsigned int rand_get(void)
static inline unsigned int rand_get(void)
{
randValue = randValue * 31421U + 6927U;
return randValue;
}
static void test_function(const char str[], size_t n, void (*func)(size_t))
static inline void test_function(const char str[], size_t n, void (*func)(size_t))
{
unsigned long long start, end;
rand_init();
@@ -123,4 +127,9 @@ static inline int get_cpu_count(void)
#endif
}
#ifdef __cplusplus
extern "C"
#endif
void compiler_barrier(void *p);
#endif