From e30d779c30559e7ba73074a66a02398df9cd486f Mon Sep 17 00:00:00 2001 From: Erki Date: Wed, 24 Feb 2021 17:45:27 +0200 Subject: [PATCH] Testcases and executable rename --- op-finder/CMakeLists.txt | 11 ++-- testcases/assignment.c | 24 ++++++++ testcases/dump-ast | 3 + testcases/fir.c | 46 +++++++++++++++ testcases/gauss_blur.c | 123 +++++++++++++++++++++++++++++++++++++++ testcases/matrix.c | 33 +++++++++++ testcases/stuff.h | 17 ++++++ 7 files changed, 253 insertions(+), 4 deletions(-) create mode 100644 testcases/assignment.c create mode 100755 testcases/dump-ast create mode 100644 testcases/fir.c create mode 100644 testcases/gauss_blur.c create mode 100644 testcases/matrix.c create mode 100644 testcases/stuff.h diff --git a/op-finder/CMakeLists.txt b/op-finder/CMakeLists.txt index 84c37ce..183ddea 100644 --- a/op-finder/CMakeLists.txt +++ b/op-finder/CMakeLists.txt @@ -17,18 +17,21 @@ endif () llvm_map_components_to_libnames(llvm_libs support option core) -add_executable(llvm_proto main.cpp OperationFinder.cpp) +add_executable(op-finder + main.cpp + OperationFinder.cpp +) -target_include_directories(llvm_proto +target_include_directories(op-finder PRIVATE ${LLVM_INCLUDE_DIRS} ) -target_compile_definitions(llvm_proto +target_compile_definitions(op-finder PRIVATE ${LLVM_DEFINITIONS} ) -target_link_libraries(llvm_proto +target_link_libraries(op-finder PRIVATE ${llvm_libs} clangTooling diff --git a/testcases/assignment.c b/testcases/assignment.c new file mode 100644 index 0000000..52cbcd6 --- /dev/null +++ b/testcases/assignment.c @@ -0,0 +1,24 @@ +#define A (unsigned long)4 +#define STUFF int c = a + b + +#warning butts + +#include "stuff.h" + +void g() +{ + int a = 4; + int b = 6; + + int c = a + b; + (void)c; +} + +int main() +{ + short a = A; + char b = 3; + + STUFF; + int c2 = a + A; +} diff --git a/testcases/dump-ast b/testcases/dump-ast new file mode 100755 index 0000000..9bbe714 --- /dev/null +++ b/testcases/dump-ast @@ -0,0 +1,3 @@ +#!/bin/bash + +clang -Xclang -ast-dump -fsyntax-only $1 diff --git a/testcases/fir.c b/testcases/fir.c new file mode 100644 index 0000000..0cb2de5 --- /dev/null +++ b/testcases/fir.c @@ -0,0 +1,46 @@ +/******************************************************************************* +* +* Name : FIR Filter +* Purpose : Benchmark an FIR filter. The input values for the filter +* is an array of 51 16-bit values. The order of the filter is +* 17. +* +*******************************************************************************/ +#ifdef MSP430 +#include "msp430x14x.h" +#endif +#include +#define FIR_LENGTH 17 +const float COEFF[FIR_LENGTH] = +{ +-0.000091552734, 0.000305175781, 0.004608154297, 0.003356933594, -0.025939941406, +-0.044006347656, 0.063079833984, 0.290313720703, 0.416748046875, 0.290313720703, +0.063079833984, -0.044006347656, -0.025939941406, 0.003356933594, 0.004608154297, +0.000305175781, -0.000091552734}; +/* The following array simulates input A/D converted values */ +const unsigned int INPUT[] = +{ +0x0000, 0x0000, 0x0000, 0x0000,0x0000, 0x0000, 0x0000, 0x0000, +0x0000, 0x0000, 0x0000, 0x0000,0x0000, 0x0000, 0x0000, 0x0000, +0x0400, 0x0800, 0x0C00, 0x1000, 0x1400, 0x1800, 0x1C00, 0x2000, +0x2400, 0x2000, 0x1C00, 0x1800, 0x1400, 0x1000, 0x0C00, 0x0800, +0x0400, 0x0400, 0x0800, 0x0C00, 0x1000, 0x1400, 0x1800, 0x1C00, +0x2000, 0x2400, 0x2000, 0x1C00, 0x1800, 0x1400, 0x1000, 0x0C00, +0x0800, 0x0400, 0x0400, 0x0800, 0x0C00, 0x1000, 0x1400, 0x1800, +0x1C00, 0x2000, 0x2400, 0x2000, 0x1C00, 0x1800, 0x1400, 0x1000, +0x0C00, 0x0800, 0x0400}; +void main(void) +{ +int i, y; /* Loop counters */ +volatile float OUTPUT[36],sum; +for(y = 0; y < 36; y++) +{ +sum=0; +for(i = 0; i < FIR_LENGTH/2; i++) +{ +sum = sum+COEFF[i] * ( INPUT[y + 16 - i] + INPUT[y + i] ); +} +OUTPUT[y] = sum + (INPUT[y + FIR_LENGTH/2] * COEFF[FIR_LENGTH/2] ); +} +return; +} \ No newline at end of file diff --git a/testcases/gauss_blur.c b/testcases/gauss_blur.c new file mode 100644 index 0000000..f39f707 --- /dev/null +++ b/testcases/gauss_blur.c @@ -0,0 +1,123 @@ + +#include + +int gauss_blur(){ + + + + + char Gauss[] = {99, 68, 35, 10}; + int g_acc; + int tot = 0; + int i, k = 0, l, x, y; + + unsigned char** g_tmp_image; + unsigned char * gauss_image; + unsigned char * outputImage; + unsigned char * inputImage; + + int pictureHight = 50; + int pictureWidth = 50; + + const int GB = 1; + const int NB = 1; + + char maxdiff, val; + + gauss_image = (unsigned char*) malloc(pictureHight * pictureWidth * sizeof (unsigned char)); + outputImage = (unsigned char*) malloc(pictureHight * pictureWidth * sizeof (unsigned char)); + g_tmp_image = (unsigned char **) malloc(pictureWidth * sizeof (unsigned char*)); + inputImage = (unsigned char*) malloc(pictureHight * pictureWidth * sizeof (unsigned char)); + + + for (i = 0; i < pictureHight * pictureWidth; i++) { + inputImage[i] = k; + k++; + if (k == 256) { + k = 0; + } + } + + //Perform Gauss operations on image + for (i = 0; i < pictureWidth; i++) { + *(g_tmp_image + i) = (unsigned char*) malloc(pictureHight * sizeof (unsigned char)); + } + + for (k = -GB; k <= GB; k++) { + tot += Gauss[abs(k)]; + } + + /* + Horizontal Gauss blur*/ + for (x = 0; x < pictureWidth; x++) { + for (y = 0; y < pictureHight; y++) { + *(*(g_tmp_image + x) + y) = 0; + } + } + + for (x = GB; x < pictureWidth - GB; x++) { + for (y = GB; y < pictureHight - GB; y++) { + g_acc = 0; + + for (k = -GB; k <= GB; k++) { + g_acc += inputImage[x + k + pictureWidth * y] * Gauss[abs(k)]; + } + *(*(g_tmp_image + x) + y) = g_acc / tot; + } + } + + //Vertival Gauss blur + for (i = 0; i < pictureWidth * pictureHight; i++) { + gauss_image[i] = 0; + } + + for (x = GB; x < pictureWidth - GB; x++) { + for (y = GB; y < pictureHight - GB; y++) { + g_acc = 0; + for (k = -GB; k < GB; k++) { + g_acc += (*(*(g_tmp_image + x) + y + k)) * Gauss[abs(k)]; + + } + gauss_image[x + y * pictureWidth] = g_acc / tot; + } + } + + + for (i = 0; i < pictureWidth * pictureHight; i++) { + outputImage[i] = 0; + } + + for (x = NB; x < pictureWidth - NB; x++) { + for (y = NB; y < pictureHight - NB; y++) { + maxdiff = 0; + for (k = -NB; k <= NB; k++) { + for (l = -NB; l <= NB; l++) { + if (k != 0 || l != 0) { + val = abs(((int) gauss_image[x + k + pictureWidth * (y + 1)] - + gauss_image[x + pictureWidth * y])); + if (val > maxdiff) { + maxdiff = val; + } + } + } + } + + outputImage[x + pictureWidth * y] = maxdiff; + } + } + + /*Memory deallocation*/ + free(gauss_image); + free(outputImage); + free(inputImage); + + for (i = 0; i < pictureWidth; i++) { + free(*(g_tmp_image + i)); + } + + free(g_tmp_image); + + + return 0; +} + diff --git a/testcases/matrix.c b/testcases/matrix.c new file mode 100644 index 0000000..bd9832a --- /dev/null +++ b/testcases/matrix.c @@ -0,0 +1,33 @@ +typedef unsigned short UInt16; + +const UInt16 m1[3][4] = { +{0x01, 0x02, 0x03, 0x04}, +{0x05, 0x06, 0x07, 0x08}, +{0x09, 0x0A, 0x0B, 0x0C} +}; + +const UInt16 m2[4][5] = { +{0x01, 0x02, 0x03, 0x04, 0x05}, +{0x06, 0x07, 0x08, 0x09, 0x0A}, +{0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, +{0x10, 0x11, 0x12, 0x13, 0x14} +}; + +int main(void) +{ +int m, n, p; +volatile UInt16 m3[3][5]; +for(m = 0; m < 3; m++) +{ +for(p = 0; p < 5; p++) +{ +m3[m][p] = 0; +for(n = 0; n < 4; n++) +{ +m3[m][p] += m1[m][n] * m2[n][p]; +} +} +} +return 0; +} + diff --git a/testcases/stuff.h b/testcases/stuff.h new file mode 100644 index 0000000..649f645 --- /dev/null +++ b/testcases/stuff.h @@ -0,0 +1,17 @@ +// +// Created by erki on 23.02.21. +// + +#ifndef C_ANALYZER_STUFF_H +#define C_ANALYZER_STUFF_H + +void f() +{ + int a = 4; + int b = 6; + + int c = a + b; + (void)c; +} + +#endif //C_ANALYZER_STUFF_H