Add wasm tacle-bench targets
This commit is contained in:
25
targets/wasm-tacle/kernel/st/CMakeLists.txt
Normal file
25
targets/wasm-tacle/kernel/st/CMakeLists.txt
Normal file
@ -0,0 +1,25 @@
|
||||
# ~~~
|
||||
# SPDX-License-Identifier: MIT
|
||||
# SPDX-FileCopyrightText: 2026, Friedrich-Alexander-Universität Erlangen-Nürnberg (FAU)
|
||||
# ~~~
|
||||
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
project(st)
|
||||
|
||||
set(TACLEBENCH_ROOT_PATH "${CMAKE_CURRENT_LIST_DIR}/../../..")
|
||||
set(REPOSITORY_ROOT_PATH "${CMAKE_CURRENT_LIST_DIR}/../../../..")
|
||||
|
||||
set(APP_TARGET_NAME "${CMAKE_PROJECT_NAME}")
|
||||
|
||||
if(DEFINED TACLEBENCH_VARIANT AND "${TACLEBENCH_VARIANT}" STREQUAL "inline")
|
||||
set(APP_SOURCE_FILE_PATH
|
||||
"generated/modified_sources/inline/st.c")
|
||||
else()
|
||||
set(APP_SOURCE_FILE_PATH
|
||||
"generated/modified_sources/default/st.c")
|
||||
endif()
|
||||
|
||||
include(${REPOSITORY_ROOT_PATH}/cmake/taclebench_wasm.cmake)
|
||||
|
||||
|
||||
96
targets/wasm-tacle/kernel/st/ChangeLog.txt
Executable file
96
targets/wasm-tacle/kernel/st/ChangeLog.txt
Executable file
@ -0,0 +1,96 @@
|
||||
File: st.c
|
||||
Original provenience: Mälardalen benchmark suite, www.mrtc.....
|
||||
|
||||
2015-06-08:
|
||||
- Removed comment "/* stats.c */" from line 1
|
||||
- Added generic TACLeBench header to line 1
|
||||
- Replaced all occurrences of preprocessor macro MAX by value 1000
|
||||
(lines 75, 78, 95, 98, 111, 139)
|
||||
- Removed obsolete preprocessor macro MAX from line 3
|
||||
- Removed comment describing purpose of benchmark from lines 6-10
|
||||
- Renamed global variable Seed to st_Seed, declared st_Seed as volatile
|
||||
- Renamed global variable ArrayA to st_ArrayA
|
||||
- Renamed global variable ArrayB to st_ArrayB
|
||||
- Renamed global variable SumA to st_SumA
|
||||
- Renamed global variable SumB to st_SumB
|
||||
- Removed global variable Coef, reinserted previous local variable Coef that
|
||||
was commented out in function main and elsewhere in order to keep the
|
||||
argument lists of some functions smaller than 6
|
||||
- Replaced Coef by *Coef in last line of function Calc_LinCorrCoef due to
|
||||
previous change
|
||||
- Removed comment "/* Coef used globally */" from function Calc_LinCorrCoef
|
||||
- Removed comment "/* Coef will have to be used globally in Calc_LinCorrCoef
|
||||
since it would be beyond the 6 registers used for passing parameters */" from
|
||||
function main
|
||||
- Renamed function my_fabs to st_fabs
|
||||
- Renamed function my_sqrtf to st_sqrtf
|
||||
- Renamed function InitSeed to st_InitSeed
|
||||
- Renamed function Calc_Sum_Mean to st_Calc_Sum_Mean
|
||||
- Renamed function Square to st_Square
|
||||
- Renamed function Calc_Var_Stddev to st_Calc_Var_Stddev
|
||||
- Renamed function Calc_LinCorrCoef to st_Calc_LinCorrCoef
|
||||
- Renamed function RandomInteger to st_RandomInteger
|
||||
- Renamed function Initialize to st_Initialize
|
||||
- Added new function st_Init completely encapsulating all initialization-
|
||||
related issues according to TACLeBench guidelines. st_Init by itself only
|
||||
calls st_InitSeed and invokes st_Initialize on global arrays st_ArrayA and
|
||||
st_ArrayB
|
||||
- Removed both calls to st_Initialize from function main
|
||||
- Replaced call of st_InitSeed in main by call of st_Init
|
||||
- Replaced string "8095" by "8094" in the comment documenting function
|
||||
st_RandomInteger
|
||||
- Removed the division by 8095.0f from line
|
||||
"array[ i ] = i + st_randomInteger() / 8095.0f" in function st_initialize.
|
||||
i ranges from 0 to 999, values returned by st_randomInteger range from 0 to
|
||||
8094. The sum of i and st_randomInteger thus ranges from 0 to 9093. Dividing
|
||||
numbers from this interval by 8095.0f has the effect that array[ i ] is
|
||||
initialized only with values 0.0f or 1.0f which is way too limited.
|
||||
- Added new function st_main according to TACLeBench guidelines. st_main
|
||||
contains the declaration of local variables MeanA, MeanB, VarA, VarB,
|
||||
StddevA, StddevB and Coef and calls st_calc_Sum_Mean, st_Calc_Var_Stddev
|
||||
and st_Calc_LinCorrCoef as the original main did.
|
||||
st_main is annotated as entry-point for timing analysis.
|
||||
- Removed declaration of local variables from function main, replaced calls
|
||||
of st_Calc_Sum_Mean, st_Calc_Var_Stddev and st_Calc_LinCorrCoef in main by
|
||||
a call to st_main
|
||||
- Removed local variables meanA, meanB, varA, varB, stddevA, stddevB, coef from
|
||||
function st_main, added them as global variables st_meanA, st_meanB, st_varA,
|
||||
st_varB, st_stddevA, st_stddevB, st_coef
|
||||
Adjusted function st_main such that the new global variables are used, in
|
||||
order to enable explicit return value computation of the entire benchmark
|
||||
- Added new function st_return computing a checksum as return value
|
||||
- Adjusted function main such that it calls st_return to produce a return value
|
||||
for testing
|
||||
- Added forward declarations of all functions before the declarations of global
|
||||
variables
|
||||
- Reordered functions in source code: initialization- and return-value-related
|
||||
functions first, followed by arithmetic math functions, followed by algorithm
|
||||
core functions, followed by main functions
|
||||
- Applied code formatting according to the following rules
|
||||
(incomplete, to be discussed; I basically used astyle with the attached
|
||||
options file):
|
||||
- Lines shall not be wider than 80 characters; whenever possible, appropriate
|
||||
line breaks shall be inserted to keep lines below 80 characters
|
||||
- Indentation is done using whitespaces only, no tabs. Code is indented by
|
||||
two whitespaces
|
||||
- Two empty lines are put between any two functions
|
||||
- In non-empty lists or index expressions, opening '(' and '[' are followed by
|
||||
one whitespace, closing ')' and ']' are preceded by one whitespace
|
||||
- In comma- or colon-separated argument lists, one whitespace is put after
|
||||
each comma/colon
|
||||
- Names of functions and global variables all start with a benchmark-specific
|
||||
prefix (here: st_) followed by lowercase letter (e.g., st_square)
|
||||
- For pointer types, one whitespace is put before the '*'
|
||||
- Operators within expressions shall be preceded and followed by one
|
||||
whitespace
|
||||
- Code of then- and else-parts of if-then-else statements shall be put in
|
||||
separate lines, not in the same lines as the if-condition or the keyword
|
||||
"else"
|
||||
- Opening braces '{' denoting the beginning of code for some if-else or loop
|
||||
body shall be put at the end of the same line where the keywords "if",
|
||||
"else", "for", "while" etc. occur
|
||||
- Added general TACLeBench header to beginning of source code
|
||||
|
||||
2016-03-15:
|
||||
- Return 0 if checksum is as expected, -1 otherwise
|
||||
- Fix function prototypes of functions without arguments
|
||||
BIN
targets/wasm-tacle/kernel/st/generated/default/st.wasm
Executable file
BIN
targets/wasm-tacle/kernel/st/generated/default/st.wasm
Executable file
Binary file not shown.
754
targets/wasm-tacle/kernel/st/generated/default/st.wat
Normal file
754
targets/wasm-tacle/kernel/st/generated/default/st.wat
Normal file
@ -0,0 +1,754 @@
|
||||
(module $st.wasm
|
||||
(type (;0;) (func (param i32 i32)))
|
||||
(type (;1;) (func))
|
||||
(type (;2;) (func (param i32 i32 f32 f32 i32)))
|
||||
(type (;3;) (func (result i32)))
|
||||
(import "__pragma" "loopbound" (func $__pragma_loopbound (type 0)))
|
||||
(func $__wasm_apply_data_relocs (type 1))
|
||||
(func $st_calc_LinCorrCoef (type 2) (param i32 i32 f32 f32 i32)
|
||||
(local f32 i32 f32 f32 i32 f32 i32 f32 f32 f32)
|
||||
i32.const 1000
|
||||
i32.const 1000
|
||||
call $__pragma_loopbound
|
||||
f32.const 0x0p+0 (;=0;)
|
||||
local.set 5
|
||||
i32.const 0
|
||||
local.set 6
|
||||
f32.const 0x0p+0 (;=0;)
|
||||
local.set 7
|
||||
f32.const 0x0p+0 (;=0;)
|
||||
local.set 8
|
||||
loop ;; label = @1
|
||||
local.get 0
|
||||
local.get 6
|
||||
i32.add
|
||||
local.tee 9
|
||||
i32.const 4
|
||||
i32.add
|
||||
f32.load
|
||||
local.get 2
|
||||
f32.sub
|
||||
local.tee 10
|
||||
local.get 1
|
||||
local.get 6
|
||||
i32.add
|
||||
local.tee 11
|
||||
i32.const 4
|
||||
i32.add
|
||||
f32.load
|
||||
local.get 3
|
||||
f32.sub
|
||||
local.tee 12
|
||||
f32.mul
|
||||
local.get 9
|
||||
f32.load
|
||||
local.get 2
|
||||
f32.sub
|
||||
local.tee 13
|
||||
local.get 11
|
||||
f32.load
|
||||
local.get 3
|
||||
f32.sub
|
||||
local.tee 14
|
||||
f32.mul
|
||||
local.get 8
|
||||
f32.add
|
||||
f32.add
|
||||
local.set 8
|
||||
local.get 5
|
||||
local.get 14
|
||||
local.get 14
|
||||
f32.mul
|
||||
f32.add
|
||||
local.get 12
|
||||
local.get 12
|
||||
f32.mul
|
||||
f32.add
|
||||
local.set 5
|
||||
local.get 7
|
||||
local.get 13
|
||||
local.get 13
|
||||
f32.mul
|
||||
f32.add
|
||||
local.get 10
|
||||
local.get 10
|
||||
f32.mul
|
||||
f32.add
|
||||
local.set 7
|
||||
local.get 6
|
||||
i32.const 8
|
||||
i32.add
|
||||
local.tee 6
|
||||
i32.const 4000
|
||||
i32.ne
|
||||
br_if 0 (;@1;)
|
||||
end
|
||||
f32.const 0x0p+0 (;=0;)
|
||||
local.set 10
|
||||
f32.const 0x0p+0 (;=0;)
|
||||
local.set 12
|
||||
block ;; label = @1
|
||||
local.get 7
|
||||
f32.const 0x0p+0 (;=0;)
|
||||
f32.eq
|
||||
br_if 0 (;@1;)
|
||||
i32.const 19
|
||||
local.set 9
|
||||
i32.const 19
|
||||
i32.const 19
|
||||
call $__pragma_loopbound
|
||||
local.get 7
|
||||
f32.const 0x1.4p+3 (;=10;)
|
||||
f32.div
|
||||
local.set 12
|
||||
i32.const 0
|
||||
local.set 6
|
||||
loop ;; label = @2
|
||||
block ;; label = @3
|
||||
block ;; label = @4
|
||||
local.get 6
|
||||
br_if 0 (;@4;)
|
||||
i32.const 0
|
||||
local.set 6
|
||||
local.get 7
|
||||
local.get 12
|
||||
local.get 7
|
||||
local.get 12
|
||||
local.get 12
|
||||
f32.mul
|
||||
f32.sub
|
||||
local.get 12
|
||||
local.get 12
|
||||
f32.add
|
||||
f32.div
|
||||
f32.add
|
||||
local.tee 12
|
||||
local.get 12
|
||||
f32.mul
|
||||
f32.sub
|
||||
local.tee 13
|
||||
local.get 13
|
||||
f32.neg
|
||||
local.get 13
|
||||
f32.const 0x0p+0 (;=0;)
|
||||
f32.ge
|
||||
select
|
||||
f32.const 0x1.4f8b58p-17 (;=1e-05;)
|
||||
f32.le
|
||||
i32.eqz
|
||||
br_if 1 (;@3;)
|
||||
end
|
||||
i32.const 1
|
||||
local.set 6
|
||||
end
|
||||
local.get 9
|
||||
i32.const -1
|
||||
i32.add
|
||||
local.tee 9
|
||||
br_if 0 (;@2;)
|
||||
end
|
||||
end
|
||||
block ;; label = @1
|
||||
local.get 5
|
||||
f32.const 0x0p+0 (;=0;)
|
||||
f32.eq
|
||||
br_if 0 (;@1;)
|
||||
i32.const 19
|
||||
local.set 9
|
||||
i32.const 19
|
||||
i32.const 19
|
||||
call $__pragma_loopbound
|
||||
local.get 5
|
||||
f32.const 0x1.4p+3 (;=10;)
|
||||
f32.div
|
||||
local.set 10
|
||||
i32.const 0
|
||||
local.set 6
|
||||
loop ;; label = @2
|
||||
block ;; label = @3
|
||||
block ;; label = @4
|
||||
local.get 6
|
||||
br_if 0 (;@4;)
|
||||
i32.const 0
|
||||
local.set 6
|
||||
local.get 5
|
||||
local.get 10
|
||||
local.get 5
|
||||
local.get 10
|
||||
local.get 10
|
||||
f32.mul
|
||||
f32.sub
|
||||
local.get 10
|
||||
local.get 10
|
||||
f32.add
|
||||
f32.div
|
||||
f32.add
|
||||
local.tee 10
|
||||
local.get 10
|
||||
f32.mul
|
||||
f32.sub
|
||||
local.tee 13
|
||||
local.get 13
|
||||
f32.neg
|
||||
local.get 13
|
||||
f32.const 0x0p+0 (;=0;)
|
||||
f32.ge
|
||||
select
|
||||
f32.const 0x1.4f8b58p-17 (;=1e-05;)
|
||||
f32.le
|
||||
i32.eqz
|
||||
br_if 1 (;@3;)
|
||||
end
|
||||
i32.const 1
|
||||
local.set 6
|
||||
end
|
||||
local.get 9
|
||||
i32.const -1
|
||||
i32.add
|
||||
local.tee 9
|
||||
br_if 0 (;@2;)
|
||||
end
|
||||
end
|
||||
local.get 4
|
||||
local.get 8
|
||||
local.get 12
|
||||
local.get 10
|
||||
f32.mul
|
||||
f32.div
|
||||
f32.store)
|
||||
(func $st_main (type 1)
|
||||
(local f32 i32 f32 f32 i32)
|
||||
i32.const 0
|
||||
i32.const 0
|
||||
i32.store offset=9060
|
||||
i32.const 1000
|
||||
i32.const 1000
|
||||
call $__pragma_loopbound
|
||||
i32.const 0
|
||||
f32.load offset=9060
|
||||
local.set 0
|
||||
i32.const -4000
|
||||
local.set 1
|
||||
loop ;; label = @1
|
||||
local.get 0
|
||||
local.get 1
|
||||
i32.const 5040
|
||||
i32.add
|
||||
f32.load
|
||||
f32.add
|
||||
local.get 1
|
||||
i32.const 5044
|
||||
i32.add
|
||||
f32.load
|
||||
f32.add
|
||||
local.get 1
|
||||
i32.const 5048
|
||||
i32.add
|
||||
f32.load
|
||||
f32.add
|
||||
local.get 1
|
||||
i32.const 5052
|
||||
i32.add
|
||||
f32.load
|
||||
f32.add
|
||||
local.get 1
|
||||
i32.const 5056
|
||||
i32.add
|
||||
f32.load
|
||||
f32.add
|
||||
local.set 0
|
||||
local.get 1
|
||||
i32.const 20
|
||||
i32.add
|
||||
local.tee 1
|
||||
br_if 0 (;@1;)
|
||||
end
|
||||
i32.const 0
|
||||
local.get 0
|
||||
f32.store offset=9060
|
||||
i32.const 0
|
||||
local.get 0
|
||||
f32.const 0x1.f4p+9 (;=1000;)
|
||||
f32.div
|
||||
local.tee 0
|
||||
f32.store offset=9040
|
||||
i32.const 1000
|
||||
i32.const 1000
|
||||
call $__pragma_loopbound
|
||||
f32.const 0x0p+0 (;=0;)
|
||||
local.set 2
|
||||
i32.const -4000
|
||||
local.set 1
|
||||
loop ;; label = @1
|
||||
local.get 2
|
||||
local.get 1
|
||||
i32.const 5040
|
||||
i32.add
|
||||
f32.load
|
||||
local.get 0
|
||||
f32.sub
|
||||
local.tee 3
|
||||
local.get 3
|
||||
f32.mul
|
||||
f32.add
|
||||
local.get 1
|
||||
i32.const 5044
|
||||
i32.add
|
||||
f32.load
|
||||
local.get 0
|
||||
f32.sub
|
||||
local.tee 2
|
||||
local.get 2
|
||||
f32.mul
|
||||
f32.add
|
||||
local.get 1
|
||||
i32.const 5048
|
||||
i32.add
|
||||
f32.load
|
||||
local.get 0
|
||||
f32.sub
|
||||
local.tee 2
|
||||
local.get 2
|
||||
f32.mul
|
||||
f32.add
|
||||
local.get 1
|
||||
i32.const 5052
|
||||
i32.add
|
||||
f32.load
|
||||
local.get 0
|
||||
f32.sub
|
||||
local.tee 2
|
||||
local.get 2
|
||||
f32.mul
|
||||
f32.add
|
||||
local.set 2
|
||||
local.get 1
|
||||
i32.const 16
|
||||
i32.add
|
||||
local.tee 1
|
||||
br_if 0 (;@1;)
|
||||
end
|
||||
i32.const 0
|
||||
local.set 1
|
||||
i32.const 0
|
||||
local.get 2
|
||||
f32.const 0x1.f4p+9 (;=1000;)
|
||||
f32.div
|
||||
local.tee 3
|
||||
f32.store offset=9064
|
||||
f32.const 0x0p+0 (;=0;)
|
||||
local.set 0
|
||||
block ;; label = @1
|
||||
local.get 3
|
||||
f32.const 0x0p+0 (;=0;)
|
||||
f32.eq
|
||||
br_if 0 (;@1;)
|
||||
i32.const 19
|
||||
local.set 4
|
||||
i32.const 19
|
||||
i32.const 19
|
||||
call $__pragma_loopbound
|
||||
local.get 3
|
||||
f32.const 0x1.4p+3 (;=10;)
|
||||
f32.div
|
||||
local.set 0
|
||||
loop ;; label = @2
|
||||
block ;; label = @3
|
||||
block ;; label = @4
|
||||
local.get 1
|
||||
br_if 0 (;@4;)
|
||||
i32.const 0
|
||||
local.set 1
|
||||
local.get 3
|
||||
local.get 0
|
||||
local.get 3
|
||||
local.get 0
|
||||
local.get 0
|
||||
f32.mul
|
||||
f32.sub
|
||||
local.get 0
|
||||
local.get 0
|
||||
f32.add
|
||||
f32.div
|
||||
f32.add
|
||||
local.tee 0
|
||||
local.get 0
|
||||
f32.mul
|
||||
f32.sub
|
||||
local.tee 2
|
||||
local.get 2
|
||||
f32.neg
|
||||
local.get 2
|
||||
f32.const 0x0p+0 (;=0;)
|
||||
f32.ge
|
||||
select
|
||||
f32.const 0x1.4f8b58p-17 (;=1e-05;)
|
||||
f32.le
|
||||
i32.eqz
|
||||
br_if 1 (;@3;)
|
||||
end
|
||||
i32.const 1
|
||||
local.set 1
|
||||
end
|
||||
local.get 4
|
||||
i32.const -1
|
||||
i32.add
|
||||
local.tee 4
|
||||
br_if 0 (;@2;)
|
||||
end
|
||||
end
|
||||
i32.const 0
|
||||
local.get 0
|
||||
f32.store offset=9048
|
||||
i32.const 0
|
||||
i32.const 0
|
||||
i32.store offset=9068
|
||||
i32.const 1000
|
||||
i32.const 1000
|
||||
call $__pragma_loopbound
|
||||
i32.const 0
|
||||
f32.load offset=9068
|
||||
local.set 0
|
||||
i32.const -4000
|
||||
local.set 1
|
||||
loop ;; label = @1
|
||||
local.get 0
|
||||
local.get 1
|
||||
i32.const 9040
|
||||
i32.add
|
||||
f32.load
|
||||
f32.add
|
||||
local.get 1
|
||||
i32.const 9044
|
||||
i32.add
|
||||
f32.load
|
||||
f32.add
|
||||
local.get 1
|
||||
i32.const 9048
|
||||
i32.add
|
||||
f32.load
|
||||
f32.add
|
||||
local.get 1
|
||||
i32.const 9052
|
||||
i32.add
|
||||
f32.load
|
||||
f32.add
|
||||
local.get 1
|
||||
i32.const 9056
|
||||
i32.add
|
||||
f32.load
|
||||
f32.add
|
||||
local.set 0
|
||||
local.get 1
|
||||
i32.const 20
|
||||
i32.add
|
||||
local.tee 1
|
||||
br_if 0 (;@1;)
|
||||
end
|
||||
i32.const 0
|
||||
local.get 0
|
||||
f32.store offset=9068
|
||||
i32.const 0
|
||||
local.get 0
|
||||
f32.const 0x1.f4p+9 (;=1000;)
|
||||
f32.div
|
||||
local.tee 0
|
||||
f32.store offset=9044
|
||||
i32.const 1000
|
||||
i32.const 1000
|
||||
call $__pragma_loopbound
|
||||
f32.const 0x0p+0 (;=0;)
|
||||
local.set 2
|
||||
i32.const -4000
|
||||
local.set 1
|
||||
loop ;; label = @1
|
||||
local.get 2
|
||||
local.get 1
|
||||
i32.const 9040
|
||||
i32.add
|
||||
f32.load
|
||||
local.get 0
|
||||
f32.sub
|
||||
local.tee 3
|
||||
local.get 3
|
||||
f32.mul
|
||||
f32.add
|
||||
local.get 1
|
||||
i32.const 9044
|
||||
i32.add
|
||||
f32.load
|
||||
local.get 0
|
||||
f32.sub
|
||||
local.tee 2
|
||||
local.get 2
|
||||
f32.mul
|
||||
f32.add
|
||||
local.get 1
|
||||
i32.const 9048
|
||||
i32.add
|
||||
f32.load
|
||||
local.get 0
|
||||
f32.sub
|
||||
local.tee 2
|
||||
local.get 2
|
||||
f32.mul
|
||||
f32.add
|
||||
local.get 1
|
||||
i32.const 9052
|
||||
i32.add
|
||||
f32.load
|
||||
local.get 0
|
||||
f32.sub
|
||||
local.tee 2
|
||||
local.get 2
|
||||
f32.mul
|
||||
f32.add
|
||||
local.set 2
|
||||
local.get 1
|
||||
i32.const 16
|
||||
i32.add
|
||||
local.tee 1
|
||||
br_if 0 (;@1;)
|
||||
end
|
||||
i32.const 0
|
||||
local.set 1
|
||||
i32.const 0
|
||||
local.get 2
|
||||
f32.const 0x1.f4p+9 (;=1000;)
|
||||
f32.div
|
||||
local.tee 3
|
||||
f32.store offset=9072
|
||||
f32.const 0x0p+0 (;=0;)
|
||||
local.set 0
|
||||
block ;; label = @1
|
||||
local.get 3
|
||||
f32.const 0x0p+0 (;=0;)
|
||||
f32.eq
|
||||
br_if 0 (;@1;)
|
||||
i32.const 19
|
||||
local.set 4
|
||||
i32.const 19
|
||||
i32.const 19
|
||||
call $__pragma_loopbound
|
||||
local.get 3
|
||||
f32.const 0x1.4p+3 (;=10;)
|
||||
f32.div
|
||||
local.set 0
|
||||
loop ;; label = @2
|
||||
block ;; label = @3
|
||||
block ;; label = @4
|
||||
local.get 1
|
||||
br_if 0 (;@4;)
|
||||
i32.const 0
|
||||
local.set 1
|
||||
local.get 3
|
||||
local.get 0
|
||||
local.get 3
|
||||
local.get 0
|
||||
local.get 0
|
||||
f32.mul
|
||||
f32.sub
|
||||
local.get 0
|
||||
local.get 0
|
||||
f32.add
|
||||
f32.div
|
||||
f32.add
|
||||
local.tee 0
|
||||
local.get 0
|
||||
f32.mul
|
||||
f32.sub
|
||||
local.tee 2
|
||||
local.get 2
|
||||
f32.neg
|
||||
local.get 2
|
||||
f32.const 0x0p+0 (;=0;)
|
||||
f32.ge
|
||||
select
|
||||
f32.const 0x1.4f8b58p-17 (;=1e-05;)
|
||||
f32.le
|
||||
i32.eqz
|
||||
br_if 1 (;@3;)
|
||||
end
|
||||
i32.const 1
|
||||
local.set 1
|
||||
end
|
||||
local.get 4
|
||||
i32.const -1
|
||||
i32.add
|
||||
local.tee 4
|
||||
br_if 0 (;@2;)
|
||||
end
|
||||
end
|
||||
i32.const 0
|
||||
local.get 0
|
||||
f32.store offset=9052
|
||||
i32.const 1040
|
||||
i32.const 5040
|
||||
i32.const 0
|
||||
f32.load offset=9040
|
||||
i32.const 0
|
||||
f32.load offset=9044
|
||||
i32.const 9056
|
||||
call $st_calc_LinCorrCoef)
|
||||
(func $__original_main (type 3) (result i32)
|
||||
(local i32 i32 i32)
|
||||
i32.const 0
|
||||
i32.const 0
|
||||
i32.store offset=1024
|
||||
i32.const 1000
|
||||
i32.const 1000
|
||||
call $__pragma_loopbound
|
||||
i32.const 1
|
||||
local.set 0
|
||||
i32.const 1040
|
||||
local.set 1
|
||||
loop ;; label = @1
|
||||
i32.const 0
|
||||
i32.const 0
|
||||
i32.load offset=1024
|
||||
i32.const 133
|
||||
i32.mul
|
||||
i32.const 81
|
||||
i32.add
|
||||
i32.const 8095
|
||||
i32.rem_s
|
||||
i32.store offset=1024
|
||||
i32.const 0
|
||||
i32.load offset=1024
|
||||
local.set 2
|
||||
i32.const 0
|
||||
i32.const 0
|
||||
i32.load offset=1024
|
||||
i32.const 133
|
||||
i32.mul
|
||||
i32.const 81
|
||||
i32.add
|
||||
i32.const 8095
|
||||
i32.rem_s
|
||||
i32.store offset=1024
|
||||
local.get 1
|
||||
local.get 0
|
||||
local.get 2
|
||||
i32.add
|
||||
i32.const -1
|
||||
i32.add
|
||||
f32.convert_i32_s
|
||||
f32.store
|
||||
local.get 1
|
||||
i32.const 4
|
||||
i32.add
|
||||
local.get 0
|
||||
i32.const 0
|
||||
i32.load offset=1024
|
||||
i32.add
|
||||
f32.convert_i32_s
|
||||
f32.store
|
||||
local.get 1
|
||||
i32.const 8
|
||||
i32.add
|
||||
local.set 1
|
||||
local.get 0
|
||||
i32.const 2
|
||||
i32.add
|
||||
local.tee 0
|
||||
i32.const 1001
|
||||
i32.ne
|
||||
br_if 0 (;@1;)
|
||||
end
|
||||
i32.const 1000
|
||||
i32.const 1000
|
||||
call $__pragma_loopbound
|
||||
i32.const 1
|
||||
local.set 0
|
||||
i32.const 5040
|
||||
local.set 1
|
||||
loop ;; label = @1
|
||||
i32.const 0
|
||||
i32.const 0
|
||||
i32.load offset=1024
|
||||
i32.const 133
|
||||
i32.mul
|
||||
i32.const 81
|
||||
i32.add
|
||||
i32.const 8095
|
||||
i32.rem_s
|
||||
i32.store offset=1024
|
||||
i32.const 0
|
||||
i32.load offset=1024
|
||||
local.set 2
|
||||
i32.const 0
|
||||
i32.const 0
|
||||
i32.load offset=1024
|
||||
i32.const 133
|
||||
i32.mul
|
||||
i32.const 81
|
||||
i32.add
|
||||
i32.const 8095
|
||||
i32.rem_s
|
||||
i32.store offset=1024
|
||||
local.get 1
|
||||
local.get 0
|
||||
local.get 2
|
||||
i32.add
|
||||
i32.const -1
|
||||
i32.add
|
||||
f32.convert_i32_s
|
||||
f32.store
|
||||
local.get 1
|
||||
i32.const 4
|
||||
i32.add
|
||||
local.get 0
|
||||
i32.const 0
|
||||
i32.load offset=1024
|
||||
i32.add
|
||||
f32.convert_i32_s
|
||||
f32.store
|
||||
local.get 1
|
||||
i32.const 8
|
||||
i32.add
|
||||
local.set 1
|
||||
local.get 0
|
||||
i32.const 2
|
||||
i32.add
|
||||
local.tee 0
|
||||
i32.const 1001
|
||||
i32.ne
|
||||
br_if 0 (;@1;)
|
||||
end
|
||||
call $st_main
|
||||
i32.const 0
|
||||
i32.const -1
|
||||
i32.const 0
|
||||
f32.load offset=9040
|
||||
i32.const 0
|
||||
f32.load offset=9044
|
||||
f32.add
|
||||
i32.const 0
|
||||
f32.load offset=9048
|
||||
f32.add
|
||||
i32.const 0
|
||||
f32.load offset=9052
|
||||
f32.add
|
||||
i32.const 0
|
||||
f32.load offset=9056
|
||||
f32.add
|
||||
f64.promote_f32
|
||||
f64.const -0x1.abffe3ffef391p+13 (;=-13696;)
|
||||
f64.add
|
||||
f32.demote_f64
|
||||
f32.abs
|
||||
f64.promote_f32
|
||||
f64.const 0x1.0c6f7a0b5ed8dp-20 (;=1e-06;)
|
||||
f64.lt
|
||||
select)
|
||||
(table (;0;) 1 1 funcref)
|
||||
(memory (;0;) 1)
|
||||
(global $__stack_pointer (mut i32) (i32.const 13184))
|
||||
(global (;1;) i32 (i32.const 9076))
|
||||
(global (;2;) i32 (i32.const 13184))
|
||||
(export "memory" (memory 0))
|
||||
(export "__wasm_apply_data_relocs" (func $__wasm_apply_data_relocs))
|
||||
(export "entrypoint" (func $st_main))
|
||||
(export "main" (func $__original_main))
|
||||
(export "__data_end" (global 1))
|
||||
(export "__heap_base" (global 2)))
|
||||
@ -0,0 +1,217 @@
|
||||
/*
|
||||
|
||||
This program is part of the TACLeBench benchmark suite.
|
||||
Version V 2.0
|
||||
|
||||
Name: st
|
||||
|
||||
Author: unknown
|
||||
|
||||
Function: st is a statistics program.
|
||||
This program computes for two arrays of numbers the sum, the mean,
|
||||
the variance, and standard deviation. It then determines the
|
||||
correlation coefficient between the two arrays.
|
||||
|
||||
Source: MRTC
|
||||
http://www.mrtc.mdh.se/projects/wcet/wcet_bench/st/st.c
|
||||
|
||||
Changes: No major functional changes.
|
||||
|
||||
License: May be used, modified, and re-distributed freely
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
Forward declaration of functions
|
||||
*/
|
||||
|
||||
// Wasm loop bounds
|
||||
|
||||
__attribute__((import_module("__pragma"), import_name("loopbound"))) extern void
|
||||
__pragma_loopbound(unsigned int min_bound, unsigned int max_bound);
|
||||
|
||||
void st_initSeed(void);
|
||||
long st_randomInteger();
|
||||
void st_initialize(float *);
|
||||
void st_init(void);
|
||||
int st_return(void);
|
||||
float st_fabs(float);
|
||||
float st_sqrtf(float);
|
||||
float st_square(float);
|
||||
void st_calc_Sum_Mean(float *, float *, float *);
|
||||
void st_calc_Var_Stddev(float *, float, float *, float *);
|
||||
void st_calc_LinCorrCoef(float *, float *, float, float, float *);
|
||||
__attribute__((noinline)) __attribute__((export_name("entrypoint"))) void
|
||||
st_main(void);
|
||||
__attribute__((noinline)) __attribute__((export_name("main"))) int main(void);
|
||||
|
||||
/*
|
||||
Declaration of global variables
|
||||
*/
|
||||
|
||||
volatile int st_seed;
|
||||
float st_arrayA[1000], st_arrayB[1000];
|
||||
float st_sumA, st_sumB;
|
||||
float st_meanA, st_meanB, st_varA, st_varB, st_stddevA, st_stddevB, st_coef;
|
||||
|
||||
/*
|
||||
Initialization- and return-value-related functions
|
||||
*/
|
||||
|
||||
/*
|
||||
st_initSeed initializes the seed used in the "random" number generator.
|
||||
*/
|
||||
void
|
||||
st_initSeed() {
|
||||
st_seed = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
st_RandomInteger generates random integers between 0 and 8094.
|
||||
*/
|
||||
long
|
||||
st_randomInteger() {
|
||||
st_seed = ((st_seed * 133) + 81) % 8095;
|
||||
return (st_seed);
|
||||
}
|
||||
|
||||
void
|
||||
st_initialize(float *array) {
|
||||
register int i;
|
||||
|
||||
__pragma_loopbound(1000, 1000);
|
||||
for (i = 0; i < 1000; i++)
|
||||
array[i] = i + st_randomInteger();
|
||||
}
|
||||
|
||||
void
|
||||
st_init() {
|
||||
st_initSeed();
|
||||
st_initialize(st_arrayA);
|
||||
st_initialize(st_arrayB);
|
||||
}
|
||||
|
||||
int
|
||||
st_return() {
|
||||
float checksum = st_meanA + st_meanB + st_stddevA + st_stddevB + st_coef;
|
||||
/* allow rounding errors for the checksum */
|
||||
checksum -= 13695.986328;
|
||||
return ((checksum < 0.000001 && checksum > -0.000001) ? 0 : -1);
|
||||
}
|
||||
|
||||
/*
|
||||
Arithmetic math functions
|
||||
*/
|
||||
|
||||
float
|
||||
st_fabs(float n) {
|
||||
float f;
|
||||
|
||||
if (n >= 0)
|
||||
f = n;
|
||||
else
|
||||
f = -n;
|
||||
|
||||
return (f);
|
||||
}
|
||||
|
||||
float
|
||||
st_sqrtf(float val) {
|
||||
float x = val / 10;
|
||||
float dx;
|
||||
float diff;
|
||||
float min_tol = 0.00001f;
|
||||
|
||||
int i, flag = 0;
|
||||
|
||||
if (val == 0)
|
||||
x = 0;
|
||||
else {
|
||||
__pragma_loopbound(19, 19);
|
||||
for (i = 1; i < 20; i++) {
|
||||
if (!flag) {
|
||||
dx = (val - (x * x)) / (2.0f * x);
|
||||
x = x + dx;
|
||||
diff = val - (x * x);
|
||||
|
||||
if (st_fabs(diff) <= min_tol)
|
||||
flag = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (x);
|
||||
}
|
||||
|
||||
float
|
||||
st_square(float x) {
|
||||
return (x * x);
|
||||
}
|
||||
|
||||
/*
|
||||
Algorithm core functions
|
||||
*/
|
||||
|
||||
void
|
||||
st_calc_Sum_Mean(float *array, float *sum, float *mean) {
|
||||
int i;
|
||||
|
||||
*sum = 0;
|
||||
|
||||
__pragma_loopbound(1000, 1000);
|
||||
for (i = 0; i < 1000; i++)
|
||||
*sum += array[i];
|
||||
*mean = *sum / 1000;
|
||||
}
|
||||
|
||||
void
|
||||
st_calc_Var_Stddev(float *array, float mean, float *var, float *stddev) {
|
||||
int i;
|
||||
float diffs = 0.0f;
|
||||
|
||||
__pragma_loopbound(1000, 1000);
|
||||
for (i = 0; i < 1000; i++)
|
||||
diffs += st_square(array[i] - mean);
|
||||
|
||||
*var = diffs / 1000;
|
||||
*stddev = st_sqrtf(*var);
|
||||
}
|
||||
|
||||
void
|
||||
st_calc_LinCorrCoef(float *arrayA, float *arrayB, float meanA, float meanB,
|
||||
float *coef) {
|
||||
int i;
|
||||
float numerator = 0.0f, Aterm = 0.0f, Bterm = 0.0f;
|
||||
|
||||
__pragma_loopbound(1000, 1000);
|
||||
for (i = 0; i < 1000; i++) {
|
||||
numerator += (arrayA[i] - meanA) * (arrayB[i] - meanB);
|
||||
Aterm += st_square(arrayA[i] - meanA);
|
||||
Bterm += st_square(arrayB[i] - meanB);
|
||||
}
|
||||
|
||||
*coef = numerator / (st_sqrtf(Aterm) * st_sqrtf(Bterm));
|
||||
}
|
||||
|
||||
/*
|
||||
Main functions
|
||||
*/
|
||||
|
||||
__attribute__((noinline)) __attribute__((export_name("entrypoint"))) void
|
||||
st_main(void) {
|
||||
st_calc_Sum_Mean(st_arrayA, &st_sumA, &st_meanA);
|
||||
st_calc_Var_Stddev(st_arrayA, st_meanA, &st_varA, &st_stddevA);
|
||||
|
||||
st_calc_Sum_Mean(st_arrayB, &st_sumB, &st_meanB);
|
||||
st_calc_Var_Stddev(st_arrayB, st_meanB, &st_varB, &st_stddevB);
|
||||
|
||||
st_calc_LinCorrCoef(st_arrayA, st_arrayB, st_meanA, st_meanB, &st_coef);
|
||||
}
|
||||
|
||||
__attribute__((noinline)) __attribute__((export_name("main"))) int
|
||||
main(void) {
|
||||
st_init();
|
||||
st_main();
|
||||
|
||||
return (st_return());
|
||||
}
|
||||
@ -0,0 +1,228 @@
|
||||
/*
|
||||
|
||||
This program is part of the TACLeBench benchmark suite.
|
||||
Version V 2.0
|
||||
|
||||
Name: st
|
||||
|
||||
Author: unknown
|
||||
|
||||
Function: st is a statistics program.
|
||||
This program computes for two arrays of numbers the sum, the mean,
|
||||
the variance, and standard deviation. It then determines the
|
||||
correlation coefficient between the two arrays.
|
||||
|
||||
Source: MRTC
|
||||
http://www.mrtc.mdh.se/projects/wcet/wcet_bench/st/st.c
|
||||
|
||||
Changes: No major functional changes.
|
||||
|
||||
License: May be used, modified, and re-distributed freely
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
Forward declaration of functions
|
||||
*/
|
||||
|
||||
// Wasm loop bounds
|
||||
|
||||
|
||||
|
||||
|
||||
__attribute__((import_module("__pragma"), import_name("loopbound"))) extern void
|
||||
__pragma_loopbound(unsigned int min_bound, unsigned int max_bound);
|
||||
|
||||
__attribute__((always_inline)) static inline void st_initSeed(void);
|
||||
__attribute__((always_inline)) static inline long st_randomInteger();
|
||||
__attribute__((always_inline)) static inline void st_initialize(float *);
|
||||
__attribute__((always_inline)) static inline void st_init(void);
|
||||
__attribute__((always_inline)) static inline int st_return(void);
|
||||
__attribute__((always_inline)) static inline float st_fabs(float);
|
||||
__attribute__((always_inline)) static inline float st_sqrtf(float);
|
||||
__attribute__((always_inline)) static inline float st_square(float);
|
||||
__attribute__((always_inline)) static inline void
|
||||
st_calc_Sum_Mean(float *, float *, float *);
|
||||
__attribute__((always_inline)) static inline void
|
||||
st_calc_Var_Stddev(float *, float, float *, float *);
|
||||
__attribute__((always_inline)) static inline void
|
||||
st_calc_LinCorrCoef(float *, float *, float, float, float *);
|
||||
__attribute__((noinline)) __attribute__((export_name("entrypoint")))
|
||||
__attribute__((noinline)) __attribute__((export_name("entrypoint"))) void
|
||||
st_main(void);
|
||||
__attribute__((noinline)) __attribute__((export_name("main")))
|
||||
__attribute__((noinline)) __attribute__((export_name("main"))) int
|
||||
main(void);
|
||||
|
||||
/*
|
||||
Declaration of global variables
|
||||
*/
|
||||
|
||||
volatile int st_seed;
|
||||
float st_arrayA[1000], st_arrayB[1000];
|
||||
float st_sumA, st_sumB;
|
||||
float st_meanA, st_meanB, st_varA, st_varB, st_stddevA, st_stddevB, st_coef;
|
||||
|
||||
/*
|
||||
Initialization- and return-value-related functions
|
||||
*/
|
||||
|
||||
/*
|
||||
st_initSeed initializes the seed used in the "random" number generator.
|
||||
*/
|
||||
__attribute__((always_inline)) static inline void
|
||||
st_initSeed() {
|
||||
st_seed = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
st_RandomInteger generates random integers between 0 and 8094.
|
||||
*/
|
||||
__attribute__((always_inline)) static inline long
|
||||
st_randomInteger() {
|
||||
st_seed = ((st_seed * 133) + 81) % 8095;
|
||||
return (st_seed);
|
||||
}
|
||||
|
||||
__attribute__((always_inline)) static inline void
|
||||
st_initialize(float *array) {
|
||||
register int i;
|
||||
|
||||
__pragma_loopbound(1000, 1000);
|
||||
for (i = 0; i < 1000; i++)
|
||||
array[i] = i + st_randomInteger();
|
||||
}
|
||||
|
||||
__attribute__((always_inline)) static inline void
|
||||
st_init() {
|
||||
st_initSeed();
|
||||
st_initialize(st_arrayA);
|
||||
st_initialize(st_arrayB);
|
||||
}
|
||||
|
||||
__attribute__((always_inline)) static inline int
|
||||
st_return() {
|
||||
float checksum = st_meanA + st_meanB + st_stddevA + st_stddevB + st_coef;
|
||||
/* allow rounding errors for the checksum */
|
||||
checksum -= 13695.986328;
|
||||
return ((checksum < 0.000001 && checksum > -0.000001) ? 0 : -1);
|
||||
}
|
||||
|
||||
/*
|
||||
Arithmetic math functions
|
||||
*/
|
||||
|
||||
__attribute__((always_inline)) static inline float
|
||||
st_fabs(float n) {
|
||||
float f;
|
||||
|
||||
if (n >= 0)
|
||||
f = n;
|
||||
else
|
||||
f = -n;
|
||||
|
||||
return (f);
|
||||
}
|
||||
|
||||
__attribute__((always_inline)) static inline float
|
||||
st_sqrtf(float val) {
|
||||
float x = val / 10;
|
||||
float dx;
|
||||
float diff;
|
||||
float min_tol = 0.00001f;
|
||||
|
||||
int i, flag = 0;
|
||||
|
||||
if (val == 0)
|
||||
x = 0;
|
||||
else {
|
||||
__pragma_loopbound(19, 19);
|
||||
for (i = 1; i < 20; i++) {
|
||||
if (!flag) {
|
||||
dx = (val - (x * x)) / (2.0f * x);
|
||||
x = x + dx;
|
||||
diff = val - (x * x);
|
||||
|
||||
if (st_fabs(diff) <= min_tol)
|
||||
flag = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (x);
|
||||
}
|
||||
|
||||
__attribute__((always_inline)) static inline float
|
||||
st_square(float x) {
|
||||
return (x * x);
|
||||
}
|
||||
|
||||
/*
|
||||
Algorithm core functions
|
||||
*/
|
||||
|
||||
__attribute__((always_inline)) static inline void
|
||||
st_calc_Sum_Mean(float *array, float *sum, float *mean) {
|
||||
int i;
|
||||
|
||||
*sum = 0;
|
||||
|
||||
__pragma_loopbound(1000, 1000);
|
||||
for (i = 0; i < 1000; i++)
|
||||
*sum += array[i];
|
||||
*mean = *sum / 1000;
|
||||
}
|
||||
|
||||
__attribute__((always_inline)) static inline void
|
||||
st_calc_Var_Stddev(float *array, float mean, float *var, float *stddev) {
|
||||
int i;
|
||||
float diffs = 0.0f;
|
||||
|
||||
__pragma_loopbound(1000, 1000);
|
||||
for (i = 0; i < 1000; i++)
|
||||
diffs += st_square(array[i] - mean);
|
||||
|
||||
*var = diffs / 1000;
|
||||
*stddev = st_sqrtf(*var);
|
||||
}
|
||||
|
||||
__attribute__((always_inline)) static inline void
|
||||
st_calc_LinCorrCoef(float *arrayA, float *arrayB, float meanA, float meanB,
|
||||
float *coef) {
|
||||
int i;
|
||||
float numerator = 0.0f, Aterm = 0.0f, Bterm = 0.0f;
|
||||
|
||||
__pragma_loopbound(1000, 1000);
|
||||
for (i = 0; i < 1000; i++) {
|
||||
numerator += (arrayA[i] - meanA) * (arrayB[i] - meanB);
|
||||
Aterm += st_square(arrayA[i] - meanA);
|
||||
Bterm += st_square(arrayB[i] - meanB);
|
||||
}
|
||||
|
||||
*coef = numerator / (st_sqrtf(Aterm) * st_sqrtf(Bterm));
|
||||
}
|
||||
|
||||
/*
|
||||
Main functions
|
||||
*/
|
||||
|
||||
__attribute__((noinline)) __attribute__((export_name("entrypoint")))
|
||||
__attribute__((noinline)) __attribute__((export_name("entrypoint"))) void
|
||||
st_main(void) {
|
||||
st_calc_Sum_Mean(st_arrayA, &st_sumA, &st_meanA);
|
||||
st_calc_Var_Stddev(st_arrayA, st_meanA, &st_varA, &st_stddevA);
|
||||
|
||||
st_calc_Sum_Mean(st_arrayB, &st_sumB, &st_meanB);
|
||||
st_calc_Var_Stddev(st_arrayB, st_meanB, &st_varB, &st_stddevB);
|
||||
|
||||
st_calc_LinCorrCoef(st_arrayA, st_arrayB, st_meanA, st_meanB, &st_coef);
|
||||
}
|
||||
|
||||
__attribute__((noinline)) __attribute__((export_name("main")))
|
||||
__attribute__((noinline)) __attribute__((export_name("main"))) int
|
||||
main(void) {
|
||||
st_init();
|
||||
st_main();
|
||||
|
||||
return (st_return());
|
||||
}
|
||||
226
targets/wasm-tacle/kernel/st/st.c
Executable file
226
targets/wasm-tacle/kernel/st/st.c
Executable file
@ -0,0 +1,226 @@
|
||||
/*
|
||||
|
||||
This program is part of the TACLeBench benchmark suite.
|
||||
Version V 2.0
|
||||
|
||||
Name: st
|
||||
|
||||
Author: unknown
|
||||
|
||||
Function: st is a statistics program.
|
||||
This program computes for two arrays of numbers the sum, the mean,
|
||||
the variance, and standard deviation. It then determines the
|
||||
correlation coefficient between the two arrays.
|
||||
|
||||
Source: MRTC
|
||||
http://www.mrtc.mdh.se/projects/wcet/wcet_bench/st/st.c
|
||||
|
||||
Changes: No major functional changes.
|
||||
|
||||
License: May be used, modified, and re-distributed freely
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
Forward declaration of functions
|
||||
*/
|
||||
|
||||
void st_initSeed( void );
|
||||
long st_randomInteger();
|
||||
void st_initialize( float * );
|
||||
void st_init( void );
|
||||
int st_return( void );
|
||||
float st_fabs( float );
|
||||
float st_sqrtf( float );
|
||||
float st_square( float );
|
||||
void st_calc_Sum_Mean( float *, float *, float * );
|
||||
void st_calc_Var_Stddev( float *, float, float *, float * );
|
||||
void st_calc_LinCorrCoef( float *, float *, float, float, float * );
|
||||
void st_main( void );
|
||||
int main( void );
|
||||
|
||||
|
||||
/*
|
||||
Declaration of global variables
|
||||
*/
|
||||
|
||||
volatile int st_seed;
|
||||
float st_arrayA[ 1000 ], st_arrayB[ 1000 ];
|
||||
float st_sumA, st_sumB;
|
||||
float st_meanA, st_meanB, st_varA, st_varB, st_stddevA, st_stddevB, st_coef;
|
||||
|
||||
|
||||
/*
|
||||
Initialization- and return-value-related functions
|
||||
*/
|
||||
|
||||
/*
|
||||
st_initSeed initializes the seed used in the "random" number generator.
|
||||
*/
|
||||
void st_initSeed()
|
||||
{
|
||||
st_seed = 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
st_RandomInteger generates random integers between 0 and 8094.
|
||||
*/
|
||||
long st_randomInteger()
|
||||
{
|
||||
st_seed = ( ( st_seed * 133 ) + 81 ) % 8095;
|
||||
return ( st_seed );
|
||||
}
|
||||
|
||||
|
||||
void st_initialize( float *array )
|
||||
{
|
||||
register int i;
|
||||
|
||||
_Pragma( "loopbound min 1000 max 1000" )
|
||||
for ( i = 0; i < 1000; i++ )
|
||||
array[ i ] = i + st_randomInteger();
|
||||
}
|
||||
|
||||
|
||||
void st_init()
|
||||
{
|
||||
st_initSeed();
|
||||
st_initialize( st_arrayA );
|
||||
st_initialize( st_arrayB );
|
||||
}
|
||||
|
||||
|
||||
int st_return()
|
||||
{
|
||||
float checksum = st_meanA + st_meanB + st_stddevA + st_stddevB + st_coef;
|
||||
/* allow rounding errors for the checksum */
|
||||
checksum -= 13695.986328;
|
||||
return ( ( checksum < 0.000001 && checksum > -0.000001 ) ? 0 : -1 );
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Arithmetic math functions
|
||||
*/
|
||||
|
||||
float st_fabs( float n )
|
||||
{
|
||||
float f;
|
||||
|
||||
if ( n >= 0 )
|
||||
f = n;
|
||||
else
|
||||
f = -n;
|
||||
|
||||
return ( f );
|
||||
}
|
||||
|
||||
|
||||
float st_sqrtf( float val )
|
||||
{
|
||||
float x = val / 10;
|
||||
float dx;
|
||||
float diff;
|
||||
float min_tol = 0.00001f;
|
||||
|
||||
int i, flag = 0;
|
||||
|
||||
if ( val == 0 )
|
||||
x = 0;
|
||||
else {
|
||||
_Pragma( "loopbound min 19 max 19" )
|
||||
for ( i = 1; i < 20; i++ ) {
|
||||
if ( !flag ) {
|
||||
dx = ( val - ( x * x ) ) / ( 2.0f * x );
|
||||
x = x + dx;
|
||||
diff = val - ( x * x );
|
||||
|
||||
if ( st_fabs( diff ) <= min_tol )
|
||||
flag = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ( x );
|
||||
}
|
||||
|
||||
|
||||
float st_square( float x )
|
||||
{
|
||||
return ( x * x );
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Algorithm core functions
|
||||
*/
|
||||
|
||||
void st_calc_Sum_Mean( float *array, float *sum, float *mean )
|
||||
{
|
||||
int i;
|
||||
|
||||
*sum = 0;
|
||||
|
||||
_Pragma( "loopbound min 1000 max 1000" )
|
||||
for ( i = 0; i < 1000; i++ )
|
||||
*sum += array[ i ];
|
||||
*mean = *sum / 1000;
|
||||
}
|
||||
|
||||
|
||||
void st_calc_Var_Stddev( float *array, float mean, float *var, float *stddev )
|
||||
{
|
||||
int i;
|
||||
float diffs = 0.0f;
|
||||
|
||||
_Pragma( "loopbound min 1000 max 1000" )
|
||||
for ( i = 0; i < 1000; i++ )
|
||||
diffs += st_square( array[ i ] - mean );
|
||||
|
||||
*var = diffs / 1000;
|
||||
*stddev = st_sqrtf( *var );
|
||||
}
|
||||
|
||||
|
||||
void st_calc_LinCorrCoef( float *arrayA, float *arrayB, float meanA,
|
||||
float meanB, float *coef )
|
||||
{
|
||||
int i;
|
||||
float numerator = 0.0f, Aterm = 0.0f, Bterm = 0.0f;
|
||||
|
||||
_Pragma( "loopbound min 1000 max 1000" )
|
||||
for ( i = 0; i < 1000; i++ ) {
|
||||
numerator += ( arrayA[ i ] - meanA ) * ( arrayB[ i ] - meanB );
|
||||
Aterm += st_square( arrayA[ i ] - meanA );
|
||||
Bterm += st_square( arrayB[ i ] - meanB );
|
||||
}
|
||||
|
||||
*coef = numerator / ( st_sqrtf( Aterm ) * st_sqrtf( Bterm ) );
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Main functions
|
||||
*/
|
||||
|
||||
void _Pragma( "entrypoint" ) st_main( void )
|
||||
{
|
||||
st_calc_Sum_Mean( st_arrayA, &st_sumA, &st_meanA );
|
||||
st_calc_Var_Stddev( st_arrayA, st_meanA, &st_varA, &st_stddevA );
|
||||
|
||||
st_calc_Sum_Mean( st_arrayB, &st_sumB, &st_meanB );
|
||||
st_calc_Var_Stddev( st_arrayB, st_meanB, &st_varB, &st_stddevB );
|
||||
|
||||
st_calc_LinCorrCoef( st_arrayA, st_arrayB, st_meanA, st_meanB, &st_coef );
|
||||
}
|
||||
|
||||
|
||||
int main( void )
|
||||
{
|
||||
st_init();
|
||||
st_main();
|
||||
|
||||
return ( st_return() );
|
||||
}
|
||||
Reference in New Issue
Block a user