Skip to content
Open
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
39 changes: 27 additions & 12 deletions cmake/FastMathOptimizations.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,37 @@
# visible artifacts, but may be undesirable in some uses. In this case, disable the ENABLE_FAST_MATH option
# and specify the safe set of flags via the CMAKE_C_FLAGS and CMAKE_CXX_FLAGS variables.

if(ENABLE_FAST_MATH)
if (ENABLE_FAST_MATH)
include(CheckCCompilerFlag)
if(MSVC)
if (CMAKE_C_COMPILER_ID STREQUAL "MSVC")
check_c_compiler_flag("/fp:fast" FAST_MATH_OPTIMIZATION_SUPPORTED)
if(FAST_MATH_OPTIMIZATION_SUPPORTED)
if (FAST_MATH_OPTIMIZATION_SUPPORTED)
add_compile_options($<$<CONFIG:Release,RelWithDebInfo>:/fp:fast>)
endif()
else()
endif ()
elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang" OR CMAKE_C_COMPILER_ID STREQUAL "AppleClang")
check_c_compiler_flag("-O3" ALL_OPTIMIZATIONS_FLAG_SUPPORTED)
if (ALL_OPTIMIZATIONS_FLAG_SUPPORTED)
add_compile_options($<$<CONFIG:Release,RelWithDebInfo>:-O3>)
endif ()

# Clang has deprecated -Ofast, use -ffast-math instead.
check_c_compiler_flag("-ffast-math" FAST_MATH_OPTIMIZATION_SUPPORTED)
if (FAST_MATH_OPTIMIZATION_SUPPORTED)
add_compile_options($<$<CONFIG:Release,RelWithDebInfo>:-ffast-math>)
endif ()
elseif (CMAKE_C_COMPILER_ID STREQUAL "GNU")
check_c_compiler_flag("-Ofast" FAST_MATH_OPTIMIZATION_SUPPORTED)
if(FAST_MATH_OPTIMIZATION_SUPPORTED)
if (FAST_MATH_OPTIMIZATION_SUPPORTED)
add_compile_options($<$<CONFIG:Release,RelWithDebInfo>:-Ofast>)
else()
else ()
check_c_compiler_flag("-O3" ALL_OPTIMIZATIONS_FLAG_SUPPORTED)
if(ALL_OPTIMIZATIONS_FLAG_SUPPORTED)
if (ALL_OPTIMIZATIONS_FLAG_SUPPORTED)
add_compile_options($<$<CONFIG:Release,RelWithDebInfo>:-O3>)
endif()
endif()
endif()
endif()
endif ()
endif ()
else ()
message(AUTHOR_WARNING
"ENABLE_FAST_MATH was requested, but compiler is not supported: ${CMAKE_C_COMPILER_ID}. "
"Please use CMAKE_C_FLAGS to pass the correct optimization flags manually.")
endif ()
endif ()
12 changes: 7 additions & 5 deletions projectm-eval/CompileContext.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "Scanner.h"
#include "Compiler.h"
#include "ExpressionTree.h"
#include "MemoryBuffer.h"
#include "TreeFunctions.h"

Expand All @@ -10,19 +11,19 @@
#include <string.h>

prjm_eval_compiler_context_t* prjm_eval_create_compile_context(projectm_eval_mem_buffer global_memory,
PRJM_EVAL_F (* global_variables)[100])
PRJM_EVAL_F (*global_variables)[100])
{
prjm_eval_compiler_context_t* cctx = calloc(1, sizeof(prjm_eval_compiler_context_t));

prjm_eval_intrinsic_function_list intrinsics;
int intrinsics_count = 0;
uint32_t intrinsics_count = 0;
prjm_eval_intrinsic_functions(&intrinsics, &intrinsics_count);

assert(intrinsics);
assert(intrinsics_count);

prjm_eval_function_list_item_t* last_func = NULL;
for (int index = intrinsics_count - 1; index >= 0; --index)
for (int32_t index = (int32_t)intrinsics_count - 1; index >= 0; --index)
{
assert(&intrinsics[index]);
prjm_eval_function_list_item_t* func = malloc(sizeof(prjm_eval_function_list_item_t));
Expand Down Expand Up @@ -137,7 +138,8 @@ void prjm_eval_reset_context_vars(prjm_eval_compiler_context_t* cctx)
}
}

const char* prjm_eval_compiler_get_error(prjm_eval_compiler_context_t* cctx, int* line, int* column_start, int* column_end)
const char* prjm_eval_compiler_get_error(prjm_eval_compiler_context_t* cctx, int* line, int* column_start,
int* column_end)
{
assert(cctx);

Expand All @@ -157,4 +159,4 @@ const char* prjm_eval_compiler_get_error(prjm_eval_compiler_context_t* cctx, int
}

return cctx->error.error;
}
}
1 change: 1 addition & 0 deletions projectm-eval/CompilerFunctions.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "CompilerFunctions.h"

#include "ExpressionTree.h"
#include "TreeFunctions.h"
#include "TreeVariables.h"

Expand Down
23 changes: 12 additions & 11 deletions projectm-eval/MemoryBuffer.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "MemoryBuffer.h"

#include <stdint.h>
#include <stdlib.h>
#include <string.h>

Expand Down Expand Up @@ -61,7 +62,7 @@ void prjm_eval_memory_free(projectm_eval_mem_buffer buffer)
projectm_eval_memory_host_unlock_mutex();
}

void prjm_eval_memory_free_block(projectm_eval_mem_buffer buffer, int block)
void prjm_eval_memory_free_block(projectm_eval_mem_buffer buffer, int32_t block)
{
if (block < 0)
{
Expand All @@ -75,7 +76,7 @@ void prjm_eval_memory_free_block(projectm_eval_mem_buffer buffer, int block)
}
}

PRJM_EVAL_F* prjm_eval_memory_allocate(projectm_eval_mem_buffer buffer, int index)
PRJM_EVAL_F* prjm_eval_memory_allocate(projectm_eval_mem_buffer buffer, int32_t index)
{
int block;
if (!buffer)
Expand Down Expand Up @@ -115,9 +116,9 @@ PRJM_EVAL_F* prjm_eval_memory_copy(projectm_eval_mem_buffer buffer,
PRJM_EVAL_F* len)
{
// Add 0.0001 to avoid using the wrong index due to tiny float rounding errors.
int offset_dest = (int) (*dest + 0.0001);
int offset_src = (int) (*src + 0.0001);
int count = (int) (*len + 0.0001);
int32_t offset_dest = (int32_t) (*dest + 0.0001);
int32_t offset_src = (int32_t) (*src + 0.0001);
int32_t count = (int32_t) (*len + 0.0001);

// Trim to front if an offset is less than zero.
if (offset_src < 0)
Expand All @@ -138,10 +139,10 @@ PRJM_EVAL_F* prjm_eval_memory_copy(projectm_eval_mem_buffer buffer,

while (count > 0)
{
int copy_length = count;
int32_t copy_length = count;

int max_dst_len = PRJM_EVAL_MEM_ITEMSPERBLOCK - (offset_dest & (PRJM_EVAL_MEM_ITEMSPERBLOCK - 1));
int max_src_len = PRJM_EVAL_MEM_ITEMSPERBLOCK - (offset_src & (PRJM_EVAL_MEM_ITEMSPERBLOCK - 1));
int32_t max_dst_len = PRJM_EVAL_MEM_ITEMSPERBLOCK - (offset_dest & (PRJM_EVAL_MEM_ITEMSPERBLOCK - 1));
int32_t max_src_len = PRJM_EVAL_MEM_ITEMSPERBLOCK - (offset_src & (PRJM_EVAL_MEM_ITEMSPERBLOCK - 1));

if (offset_dest >= PRJM_EVAL_MEM_BLOCKS * PRJM_EVAL_MEM_ITEMSPERBLOCK ||
offset_src >= PRJM_EVAL_MEM_BLOCKS * PRJM_EVAL_MEM_ITEMSPERBLOCK)
Expand Down Expand Up @@ -185,8 +186,8 @@ PRJM_EVAL_F* prjm_eval_memory_set(projectm_eval_mem_buffer buffer,
PRJM_EVAL_F* len)
{
// Add 0.0001 to avoid using the wrong index due to tiny float rounding errors.
int offset_dest = (int) (*dest + 0.0001);
int count = (int) (*len + 0.0001);
int32_t offset_dest = (int32_t) (*dest + 0.0001);
int32_t count = (int32_t) (*len + 0.0001);

// Trim to front
if (offset_dest < 0)
Expand Down Expand Up @@ -219,7 +220,7 @@ PRJM_EVAL_F* prjm_eval_memory_set(projectm_eval_mem_buffer buffer,
break;
}

int block_count = PRJM_EVAL_MEM_ITEMSPERBLOCK - (offset_dest & (PRJM_EVAL_MEM_ITEMSPERBLOCK - 1));
int32_t block_count = PRJM_EVAL_MEM_ITEMSPERBLOCK - (offset_dest & (PRJM_EVAL_MEM_ITEMSPERBLOCK - 1));
if (block_count > count)
{
block_count = count;
Expand Down
Loading
Loading