diff --git a/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/FreeRTOSConfig.h b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/FreeRTOSConfig.h index c95e3b2a..b74d9c79 100644 --- a/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/FreeRTOSConfig.h +++ b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/FreeRTOSConfig.h @@ -131,5 +131,5 @@ extern void vLoggingPrintf( const char * pcFormatString, #endif #define configUSE_TASK_NOTIFICATIONS 1 -#define configTASK_NOTIFICATION_ARRAY_ENTRIES 4 +#define configTASK_NOTIFICATION_ARRAY_ENTRIES 10 #endif /* FREERTOS_CONFIG_H */ diff --git a/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/Makefile b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/Makefile index f179b6cd..46e112bb 100644 --- a/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/Makefile +++ b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/Makefile @@ -159,6 +159,16 @@ ifeq ($(RELEASE_DEMO), 1) SOURCE_FILES += main_release.c CFLAGS := -DmainCREATE_RELEASE_DEMO=1 +else +ifeq ($(WATERSGEN_DEMO), 1) + SOURCE_FILES += main_watersgen$(SEED).c + + CFLAGS := -DmainCREATE_WATERSGEN_DEMO=1 +else +ifeq ($(TEST_DEMO), 1) + SOURCE_FILES += main_test.c + + CFLAGS := -DmainCREATE_TEST_DEMO=1 else SOURCE_FILES += main_blinky.c @@ -184,6 +194,8 @@ endif endif endif endif +endif +endif ifeq ($(IGNORE_BYTES), 1) CFLAGS += -D IGNORE_BYTES=1 diff --git a/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/arbitrary_loads.c b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/arbitrary_loads.c index d0d0f2c1..c1164a80 100644 --- a/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/arbitrary_loads.c +++ b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/arbitrary_loads.c @@ -3,6 +3,7 @@ #include #include +#include "util_macros.h" // Time wasters ===== volatile long _NONSENSE_VAR = 0; @@ -24,149 +25,9 @@ volatile long _NONSENSE_VAR = 0; #define PRINT_MSEC(X,Y) PRINT_NSEC(X*1000000,Y) // #define PRINT_TIME(X,Y) WASTE_TIME(X) -// Clamps =========== -#define CLAMP_FLOOR(X,LB) ((((X)>(LB))*(X))+(((X)<=(LB))*(LB))) -#define CLAMP_CEILING(X,UB) (((X)>(UB))*(UB)+((X)<=(UB))*(X)) -#define CLAMP(X,LB,UB) CLAMP_CEILING((CLAMP_FLOOR(X,LB)),UB) // branch-less clamping -// Random numbers === -// glibc -// https://en.wikipedia.org/wiki/Linear_congruential_generator -#define A 1103515245ull -#define M 0x80000000ull -#define C 12345ull +// Random state ====== static unsigned long long rng_seed = 2345745ull; -#define RNG rng_seed=((A*rng_seed+C) % M) -#define RNG_FROM(X) ((A*(X)+C) % M) - -// Challanges ======= -#define CHANCE_1_IN_POWOF2(X,Y) (RNG_FROM(X)<(M>>Y)) // assume the type of x has more than y bits - - -// polynomes -#define IF_ELSE(X,Y,Z) ((X) ? (Y) : (Z)) -// #define IF_ELSE(X,Y,Z) (((X)*(Y))+((!(X))*(Z))) // branchless, takes a huge hit on performance -#define SADD(X,Y) IF_ELSE(((int32_t)(Y))<0, IF_ELSE(((int32_t)(X))INT_MAX-((int32_t)(Y)), INT_MAX, ((int32_t)(X))+((int32_t)(Y)))) -#define SSUB(X,Y) IF_ELSE(((int32_t)(Y))<0, IF_ELSE(((int32_t)(X))INT_MIN+((int32_t)(Y)), ((int32_t)(X))-((int32_t)(Y)), INT_MIN)) -#define ABS_DIFF(X,Y) (IF_ELSE(((int32_t)(X)<(int32_t)(Y)),(SSUB(Y,X)),(SSUB(X,Y)))) -#define SQUARE(X) ((X)*(X)) -#define AVG(X,Y) (((X)/2)+((Y)/2)) -#define U_ABS_DIFF(X,Y) (__uint32_t)(((__uint32_t)X<(__uint32_t)Y)*((__uint32_t)Y-(__uint32_t)X)+((__uint32_t)X>=(__uint32_t)Y)*((__uint32_t)X-(__uint32_t)Y)) -#define CHECKED_SQUARE(X) IF_ELSE((X)<=0x0000B504,SQUARE(X), INT_MAX) // int32_t safe -#define LIN(X,N,D,C) (C+((N)*((X)/(D)))) - -int32_t hill(int32_t x, int32_t off, int32_t h, int32_t w) { - return CLAMP_FLOOR(SSUB(h,CHECKED_SQUARE(ABS_DIFF(x,off)/w)),0); -} -int32_t valley(int32_t x, int32_t off, int32_t h, int32_t w) { - return CLAMP_CEILING(SADD(h,CHECKED_SQUARE(ABS_DIFF(x,off)/w)),0); -} - -#define HILL(X, OFF, H, W) hill(X, OFF, H, W) -#define VALLEY(X, OFF, H, W) valley(X, OFF, H, W) - -// #define HILL(X, OFF, H, W) CLAMP_FLOOR(SSUB(H,CHECKED_SQUARE(ABS_DIFF(X,OFF)/W)),0) -// #define VALLEY(X, OFF, H, W) CLAMP_CEILING(SADD(H,CHECKED_SQUARE(ABS_DIFF(X,OFF)/W)),0) - -#define STRETCH_i32(X) (X<<(8*(sizeof(int32_t)-sizeof(X)))) // stretch any integer to 32 bits - -#define JITTER(X, B) (RNG_FROM(X+B)%B) - -#define TRANSLATE_BOUNDS(X, FLB, FUB, TLB, TUB) (CLAMP(X,FLB,FUB)-FLB) / ((FUB-FLB)/(TUB-TLB)) + TLB - - - - - - - -#define FUNCTION_1(X) \ - HILL(X, 0, 200000, 800000) \ - + HILL(X, (INT_MIN/4)*3, 400000, 1500000) \ - + HILL(X, INT_MAX/2, 800000, 200000) \ - + CLAMP_FLOOR(LIN(SSUB(X, INT_MAX/4),5,100000,0),0) \ - + CLAMP_FLOOR(LIN(-X,5,100000,0),0) \ - + 200000 \ - - JITTER(X, 30000) - -#define FUNCTION_2(X) \ - VALLEY(X, 0, -200000, 800000) \ - + VALLEY(X, (INT_MIN/4)*3, -400000, 1500000) \ - + VALLEY(X, INT_MAX/2, -800000, 200000) \ - + CLAMP_FLOOR(LIN(SSUB(X, INT_MAX/4),5,100000,0),0) \ - + CLAMP_FLOOR(LIN(-X,5,-100000,0),0) \ - + 200000 \ - - JITTER(X, 30000) - -#define FUNCTION_3(X) \ - LIN(SADD(X, INT_MAX/2),5,100000,0) \ - + LIN(-X,2,100000,0) \ - - JITTER(X, 10000) - -#define FUNCTION_4(X) \ - LIN(SADD(X, 3*(INT_MAX/8)),-30,100000,0) \ - + LIN(SSUB(X, 3*(INT_MAX/8)),30,100000,0) \ - - JITTER(X, 10000) - -#define FUNCTION_5(X) \ - VALLEY(X, 0, -200000, 10000000) \ - + HILL(X, 0, 42000, 5000000) \ - - JITTER(X, 1000) - -#define FUNCTION_6(X) \ - LIN(X,1,2,0) \ - + HILL(X, -1500000000, 1000000000, 50000) \ - + VALLEY(X, 1500000000, -1000000000, 50000) \ - - JITTER(X, 1000) - -#define FUNCTION_7(X) \ - LIN(X,1,100000,0) \ - + HILL(X, 7*(INT_MIN/8), 140000, 200000) \ - + HILL(X, 6*(INT_MIN/8), 100000, 200000) \ - + HILL(X, 5*(INT_MIN/8), 80000, 200000) \ - + HILL(X, 4*(INT_MIN/8), 60000, 200000) \ - + HILL(X, 3*(INT_MIN/8), 70000, 200000) \ - + HILL(X, 2*(INT_MIN/8), 80000, 200000) \ - + HILL(X, 1*(INT_MIN/8), 90000, 200000) \ - + HILL(X, 1*(INT_MAX/8), 90000, 200000) \ - + HILL(X, 2*(INT_MAX/8), 80000, 200000) \ - + HILL(X, 3*(INT_MAX/8), 70000, 200000) \ - + HILL(X, 4*(INT_MAX/8), 60000, 200000) \ - + HILL(X, 5*(INT_MAX/8), 50000, 200000) \ - + HILL(X, 6*(INT_MAX/8), 40000, 200000) \ - + HILL(X, 7*(INT_MAX/8), 30000, 200000) \ - - JITTER(X, 1000) - -#define FUNCTION_8(X) \ - (X>INT_MIN/2)*HILL((X%(INT_MAX/3)), 0, 10000000, 50000) * (ABS_DIFF(X,0)/100000000) \ - + LIN(X, -1, 100, 0) \ - - JITTER(X, 1000) - -#define FUNCTION_9(X) \ - HILL(X, 3*(INT_MIN/4), 200000, 800000) \ - + HILL(X, 1*(INT_MIN/4), 200000, 800000) \ - + HILL(X, 3*(INT_MAX/4), 400000, 400000) \ - + (X<0)*LIN(X, 1, 10000, 0) \ - + (X>0)*LIN(X, -1, 10000, 0) \ - - JITTER(X, 1000) - -#define FUNCTION_10(X) \ - + (X<=0)*LIN(X, 1, 10000, 0) \ - + (X>0)*LIN(X, -1, 10000, 0) \ - + VALLEY(X, 0, -200000, 1000000) \ - + 200000 \ - - JITTER(X, 1000) - - -#define TRANSLATE_1(I, LB,UB) TRANSLATE_BOUNDS((I), 180000, 1000000, LB, UB) // FN 1 -#define TRANSLATE_2(I, LB,UB) TRANSLATE_BOUNDS((I), -500000, 390000, LB, UB) // FN 2 -#define TRANSLATE_3(I, LB,UB) TRANSLATE_BOUNDS((I), -8000, 80000, LB, UB) // FN 3 -#define TRANSLATE_4(I, LB,UB) TRANSLATE_BOUNDS((I), -480000, -250000, LB, UB) // FN 4 -#define TRANSLATE_5(I, LB,UB) TRANSLATE_BOUNDS((I), -193000, -155000, LB, UB) // FN 5 -#define TRANSLATE_6(I, LB,UB) TRANSLATE_BOUNDS((I), -400000000, 400000000, LB, UB) // FN 6 -#define TRANSLATE_7(I, LB,UB) TRANSLATE_BOUNDS((I), -20000, 120000, LB, UB) // FN 7 -#define TRANSLATE_8(I, LB,UB) TRANSLATE_BOUNDS((I), -20000000, 120000000, LB, UB) // FN 8 -#define TRANSLATE_9(I, LB,UB) TRANSLATE_BOUNDS((I), -200000, 220000, LB, UB) // FN 9 -#define TRANSLATE_10(I, LB,UB) TRANSLATE_BOUNDS((I), -10000, 150000, LB, UB) // FN 10 +#define RNG rng_seed=RNG_FROM(rng_seed); #endif \ No newline at end of file diff --git a/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/bindings/bindings.rs b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/bindings/bindings.rs new file mode 100644 index 00000000..364bb160 --- /dev/null +++ b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/bindings/bindings.rs @@ -0,0 +1,184 @@ +#![allow(non_camel_case_types,non_snake_case,non_upper_case_globals,deref_nullptr,unused)] +use serde::{Deserialize, Serialize}; + +/*========== Start of generated Code =============*/ +pub type char_ptr = ::std::os::raw::c_uint; +pub type void_ptr = ::std::os::raw::c_uint; +pub type ListItem_t_ptr = ::std::os::raw::c_uint; +pub type QueueDefinition_ptr = ::std::os::raw::c_uint; +pub type StackType_t_ptr = ::std::os::raw::c_uint; +pub type i_ptr8 = ::std::os::raw::c_uint; +pub type tskTaskControlBlock_ptr = ::std::os::raw::c_uint; +pub type xLIST_ptr = ::std::os::raw::c_uint; +pub type xLIST_ITEM_ptr = ::std::os::raw::c_uint; +/* automatically generated by rust-bindgen 0.71.1 */ + +pub const configASSERT_DEFINED: u32 = 1; +pub const configQUEUE_REGISTRY_SIZE: u32 = 20; +pub const configUSE_PREEMPTION: u32 = 1; +pub const configUSE_TIME_SLICING: u32 = 0; +pub const configUSE_PORT_OPTIMISED_TASK_SELECTION: u32 = 0; +pub const configUSE_IDLE_HOOK: u32 = 1; +pub const configUSE_TICK_HOOK: u32 = 1; +pub const configUSE_DAEMON_TASK_STARTUP_HOOK: u32 = 0; +pub const configMAX_TASK_NAME_LEN: u32 = 10; +pub const configUSE_TRACE_FACILITY: u32 = 0; +pub const configUSE_STATS_FORMATTING_FUNCTIONS: u32 = 0; +pub const configUSE_16_BIT_TICKS: u32 = 0; +pub const configIDLE_SHOULD_YIELD: u32 = 1; +pub const configUSE_CO_ROUTINES: u32 = 0; +pub const configMAX_PRIORITIES: u32 = 15; +pub const configMAX_CO_ROUTINE_PRIORITIES: u32 = 2; +pub const configTIMER_QUEUE_LENGTH: u32 = 20; +pub const configTIMER_TASK_PRIORITY: u32 = 14; +pub const configUSE_COUNTING_SEMAPHORES: u32 = 1; +pub const configSUPPORT_DYNAMIC_ALLOCATION: u32 = 1; +pub const configSUPPORT_STATIC_ALLOCATION: u32 = 1; +pub const configNUM_TX_DESCRIPTORS: u32 = 15; +pub const configSTREAM_BUFFER_TRIGGER_LEVEL_TEST_MARGIN: u32 = 2; +pub const configUSE_QUEUE_SETS: u32 = 1; +pub const configUSE_MALLOC_FAILED_HOOK: u32 = 1; +pub const configUSE_MUTEXES: u32 = 1; +pub const configUSE_RECURSIVE_MUTEXES: u32 = 1; +pub const configUSE_TIMERS: u32 = 1; +pub const INCLUDE_vTaskPrioritySet: u32 = 1; +pub const INCLUDE_uxTaskPriorityGet: u32 = 1; +pub const INCLUDE_vTaskDelete: u32 = 1; +pub const INCLUDE_vTaskCleanUpResources: u32 = 0; +pub const INCLUDE_vTaskSuspend: u32 = 1; +pub const INCLUDE_vTaskDelayUntil: u32 = 1; +pub const INCLUDE_vTaskDelay: u32 = 1; +pub const INCLUDE_uxTaskGetStackHighWaterMark: u32 = 1; +pub const INCLUDE_uxTaskGetStackHighWaterMark2: u32 = 1; +pub const INCLUDE_xTaskGetSchedulerState: u32 = 1; +pub const INCLUDE_xTimerGetTimerDaemonTaskHandle: u32 = 1; +pub const INCLUDE_xTaskGetIdleTaskHandle: u32 = 1; +pub const INCLUDE_xTaskGetHandle: u32 = 1; +pub const INCLUDE_eTaskGetState: u32 = 1; +pub const INCLUDE_xSemaphoreGetMutexHolder: u32 = 1; +pub const INCLUDE_xTimerPendFunctionCall: u32 = 1; +pub const INCLUDE_xTaskAbortDelay: u32 = 1; +pub const projCOVERAGE_TEST: u32 = 0; +pub const configKERNEL_INTERRUPT_PRIORITY: u32 = 255; +pub const configMAX_SYSCALL_INTERRUPT_PRIORITY: u32 = 191; +pub const configMAC_INTERRUPT_PRIORITY: u32 = 5; +pub const configUSE_TASK_NOTIFICATIONS: u32 = 1; +pub const configTASK_NOTIFICATION_ARRAY_ENTRIES: u32 = 10; +/* automatically generated by rust-bindgen 0.71.1 */ + +pub type StackType_t = u32; +pub type UBaseType_t = ::std::os::raw::c_uint; +pub type TickType_t = u32; +#[repr(C)] +#[derive(Debug, Copy, Clone, Default, Serialize, Deserialize)] +pub struct xLIST_ITEM { + pub xItemValue: TickType_t, + pub pxNext: xLIST_ITEM_ptr, + pub pxPrevious: xLIST_ITEM_ptr, + pub pvOwner: void_ptr, + pub pvContainer: xLIST_ptr, +} +pub type ListItem_t = xLIST_ITEM; +#[repr(C)] +#[derive(Debug, Copy, Clone, Default, Serialize, Deserialize)] +pub struct xMINI_LIST_ITEM { + pub xItemValue: TickType_t, + pub pxNext: xLIST_ITEM_ptr, + pub pxPrevious: xLIST_ITEM_ptr, +} +pub type MiniListItem_t = xMINI_LIST_ITEM; +#[repr(C)] +#[derive(Debug, Copy, Clone, Default, Serialize, Deserialize)] +pub struct xLIST { + pub uxNumberOfItems: UBaseType_t, + pub pxIndex: ListItem_t_ptr, + pub xListEnd: MiniListItem_t, +} +pub type List_t = xLIST; +pub type TaskHandle_t = tskTaskControlBlock_ptr; +pub const eTaskState_eRunning: eTaskState = 0; +pub const eTaskState_eReady: eTaskState = 1; +pub const eTaskState_eBlocked: eTaskState = 2; +pub const eTaskState_eSuspended: eTaskState = 3; +pub const eTaskState_eDeleted: eTaskState = 4; +pub const eTaskState_eInvalid: eTaskState = 5; +pub type eTaskState = ::std::os::raw::c_uint; +#[repr(C)] +#[derive(Debug, Copy, Clone, Default, Serialize, Deserialize)] +pub struct xTASK_STATUS { + pub xHandle: TaskHandle_t, + pub pcTaskName: char_ptr, + pub xTaskNumber: UBaseType_t, + pub eCurrentState: eTaskState, + pub uxCurrentPriority: UBaseType_t, + pub uxBasePriority: UBaseType_t, + pub ulRunTimeCounter: u32, + pub pxStackBase: StackType_t_ptr, + pub usStackHighWaterMark: u16, +} +pub type TaskStatus_t = xTASK_STATUS; +pub type QueueHandle_t = QueueDefinition_ptr; +#[repr(C)] +#[derive(Debug, Copy, Clone, Default, Serialize, Deserialize)] +pub struct QueuePointers { + pub pcTail: i_ptr8, + pub pcReadFrom: i_ptr8, +} +pub type QueuePointers_t = QueuePointers; +#[repr(C)] +#[derive(Debug, Copy, Clone, Default, Serialize, Deserialize)] +pub struct SemaphoreData { + pub xMutexHolder: TaskHandle_t, + pub uxRecursiveCallCount: UBaseType_t, +} +pub type SemaphoreData_t = SemaphoreData; +#[repr(C)] +#[derive(Copy, Clone)] +pub struct QueueDefinition { + pub pcHead: i_ptr8, + pub pcWriteTo: i_ptr8, + pub u: QueueDefinition__bindgen_ty_1, + pub xTasksWaitingToSend: List_t, + pub xTasksWaitingToReceive: List_t, + pub uxMessagesWaiting: UBaseType_t, + pub uxLength: UBaseType_t, + pub uxItemSize: UBaseType_t, + pub cRxLock: i8, + pub cTxLock: i8, + pub ucStaticallyAllocated: u8, + pub pxQueueSetContainer: QueueDefinition_ptr, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub union QueueDefinition__bindgen_ty_1 { + pub xQueue: QueuePointers_t, + pub xSemaphore: SemaphoreData_t, +} +pub type xQUEUE = QueueDefinition; +pub type Queue_t = xQUEUE; +#[repr(C)] +#[derive(Debug, Copy, Clone, Default, Serialize, Deserialize)] +pub struct QUEUE_REGISTRY_ITEM { + pub pcQueueName: char_ptr, + pub xHandle: QueueHandle_t, +} +pub type xQueueRegistryItem = QUEUE_REGISTRY_ITEM; +pub type QueueRegistryItem_t = xQueueRegistryItem; +#[repr(C)] +#[derive(Debug, Copy, Clone, Default, Serialize, Deserialize)] +pub struct tskTaskControlBlock { + pub pxTopOfStack: StackType_t_ptr, + pub xStateListItem: ListItem_t, + pub xEventListItem: ListItem_t, + pub uxPriority: UBaseType_t, + pub pxStack: StackType_t_ptr, + pub pcTaskName: [::std::os::raw::c_char; 10usize], + pub uxBasePriority: UBaseType_t, + pub uxMutexesHeld: UBaseType_t, + pub ulNotifiedValue: [u32; 10usize], + pub ucNotifyState: [u8; 10usize], + pub ucStaticallyAllocated: u8, + pub ucDelayAborted: u8, +} +pub type tskTCB = tskTaskControlBlock; +pub type TCB_t = tskTCB; diff --git a/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main.c b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main.c index cb7078f8..2af24750 100644 --- a/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main.c +++ b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main.c @@ -127,6 +127,14 @@ int main() { main_osek(); } + #elif ( mainCREATE_WATERSGEN_DEMO == 1 ) + { + main_waters(); + } + #elif ( mainCREATE_TEST_DEMO == 1 ) + { + main_test(); + } #else { diff --git a/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main_polycopter.c b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main_polycopter.c index 137c9c5b..a713ae80 100644 --- a/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main_polycopter.c +++ b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main_polycopter.c @@ -9,6 +9,7 @@ // tight and force preemptions #define NUM_TASKS 15 #include "fuzzhelper.c" +#include "polynomic_functions.h" // #ifdef INSERT_WC // #include "wcinput.h" diff --git a/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main_watersgen1.c b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main_watersgen1.c new file mode 100644 index 00000000..cb538009 --- /dev/null +++ b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main_watersgen1.c @@ -0,0 +1,1157 @@ + +#include "FreeRTOS.h" +#include "task.h" +#include "semphr.h" +#include "timers.h" +#include +#include + +#include "util_macros.h" +#define MAX_INPUT_BYTES 40960 +#include "fuzzhelper.c" +#include "arbitrary_loads.c" +#include "polynomic_functions.h" + +#ifdef INSERT_WC + #define WC_SWITCH(X,D) ((X)*0+(D)*1) +#else + #define WC_SWITCH(X,D) ((X)*1+(D)*0) +#endif + +// Supervisor task +#define HYPER_PERIOD 100 +#define SIMULATE_PERIODS 2 +static TickType_t initial_release_time = 0; +static TaskHandle_t xTaskTimeSupervisor = NULL; +static void timing_supervisor_task( void * pvParameters ) { + initial_release_time = xTaskGetTickCount(); // The highest priority task sets the initial time + TickType_t xLastWakeTime = initial_release_time; + const TickType_t xFrequency = HYPER_PERIOD / portTICK_PERIOD_MS; + for ( int i = SIMULATE_PERIODS; i > 0; i-- ) { + trigger_job_done(); + xTaskDelayUntil( &xLastWakeTime, xFrequency ); + } + trigger_job_done(); + trigger_Qemu_break(); + for( ;; ){} +} +static void task_0_fn(void *pvParameters); +static TaskHandle_t xTask_0_Handle = NULL; +static void task_1_fn(void *pvParameters); +static TaskHandle_t xTask_1_Handle = NULL; +static void task_2_fn(void *pvParameters); +static TaskHandle_t xTask_2_Handle = NULL; +static void task_3_fn(void *pvParameters); +static TaskHandle_t xTask_3_Handle = NULL; +static void task_4_fn(void *pvParameters); +static TaskHandle_t xTask_4_Handle = NULL; +static void task_5_fn(void *pvParameters); +static TaskHandle_t xTask_5_Handle = NULL; +static void task_6_fn(void *pvParameters); +static TaskHandle_t xTask_6_Handle = NULL; +static void task_7_fn(void *pvParameters); +static TaskHandle_t xTask_7_Handle = NULL; +static void task_8_fn(void *pvParameters); +static TaskHandle_t xTask_8_Handle = NULL; +static void task_9_fn(void *pvParameters); +static TaskHandle_t xTask_9_Handle = NULL; +static void task_10_fn(void *pvParameters); +static TaskHandle_t xTask_10_Handle = NULL; +static void task_11_fn(void *pvParameters); +static TaskHandle_t xTask_11_Handle = NULL; +static void task_12_fn(void *pvParameters); +static TaskHandle_t xTask_12_Handle = NULL; +static void task_13_fn(void *pvParameters); +static TaskHandle_t xTask_13_Handle = NULL; +static void task_14_fn(void *pvParameters); +static TaskHandle_t xTask_14_Handle = NULL; +static void task_15_fn(void *pvParameters); +static TaskHandle_t xTask_15_Handle = NULL; +static void task_16_fn(void *pvParameters); +static TaskHandle_t xTask_16_Handle = NULL; +static void task_17_fn(void *pvParameters); +static TaskHandle_t xTask_17_Handle = NULL; +static void task_18_fn(void *pvParameters); +static TaskHandle_t xTask_18_Handle = NULL; +static void task_19_fn(void *pvParameters); +static TaskHandle_t xTask_19_Handle = NULL; +static void task_20_fn(void *pvParameters); +static TaskHandle_t xTask_20_Handle = NULL; +static void task_21_fn(void *pvParameters); +static TaskHandle_t xTask_21_Handle = NULL; +static void task_22_fn(void *pvParameters); +static TaskHandle_t xTask_22_Handle = NULL; +static void task_23_fn(void *pvParameters); +static TaskHandle_t xTask_23_Handle = NULL; +static void task_24_fn(void *pvParameters); +static TaskHandle_t xTask_24_Handle = NULL; +static void task_25_fn(void *pvParameters); +static TaskHandle_t xTask_25_Handle = NULL; +static void task_26_fn(void *pvParameters); +static TaskHandle_t xTask_26_Handle = NULL; + +void main_waters(void) { + for (int i = 0; i < NUM_TASKS; i++) { + RNG_STATES[i] = i; // Each task starts with a different seed + } + xTaskCreate( timing_supervisor_task, + "supervisor", + configMINIMAL_STACK_SIZE, + NULL, + configMAX_PRIORITIES - 1, + &xTaskTimeSupervisor ); + xTaskCreate(task_0_fn, "T_0", + configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1 + 4, + &xTask_0_Handle); + xTaskCreate(task_1_fn, "T_1", + configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1 + 3, + &xTask_1_Handle); + xTaskCreate(task_2_fn, "T_2", + configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1 + 3, + &xTask_2_Handle); + xTaskCreate(task_3_fn, "T_3", + configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1 + 3, + &xTask_3_Handle); + xTaskCreate(task_4_fn, "T_4", + configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1 + 3, + &xTask_4_Handle); + xTaskCreate(task_5_fn, "T_5", + configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1 + 3, + &xTask_5_Handle); + xTaskCreate(task_6_fn, "T_6", + configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1 + 3, + &xTask_6_Handle); + xTaskCreate(task_7_fn, "T_7", + configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1 + 3, + &xTask_7_Handle); + xTaskCreate(task_8_fn, "T_8", + configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1 + 2, + &xTask_8_Handle); + xTaskCreate(task_9_fn, "T_9", + configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1 + 2, + &xTask_9_Handle); + xTaskCreate(task_10_fn, "T_10", + configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1 + 2, + &xTask_10_Handle); + xTaskCreate(task_11_fn, "T_11", + configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1 + 2, + &xTask_11_Handle); + xTaskCreate(task_12_fn, "T_12", + configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1 + 2, + &xTask_12_Handle); + xTaskCreate(task_13_fn, "T_13", + configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1 + 2, + &xTask_13_Handle); + xTaskCreate(task_14_fn, "T_14", + configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1 + 2, + &xTask_14_Handle); + xTaskCreate(task_15_fn, "T_15", + configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1 + 2, + &xTask_15_Handle); + xTaskCreate(task_16_fn, "T_16", + configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1 + 1, + &xTask_16_Handle); + xTaskCreate(task_17_fn, "T_17", + configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1 + 0, + &xTask_17_Handle); + xTaskCreate(task_18_fn, "T_18", + configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1 + 0, + &xTask_18_Handle); + xTaskCreate(task_19_fn, "T_19", + configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1 + 0, + &xTask_19_Handle); + xTaskCreate(task_20_fn, "T_20", + configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1 + 0, + &xTask_20_Handle); + xTaskCreate(task_21_fn, "T_21", + configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1 + 0, + &xTask_21_Handle); + xTaskCreate(task_22_fn, "T_22", + configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1 + 0, + &xTask_22_Handle); + xTaskCreate(task_23_fn, "T_23", + configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1 + 0, + &xTask_23_Handle); + xTaskCreate(task_24_fn, "T_24", + configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1 + 0, + &xTask_24_Handle); + xTaskCreate(task_25_fn, "T_25", + configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1 + 0, + &xTask_25_Handle); + xTaskCreate(task_26_fn, "T_26", + configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1 + 0, + &xTask_26_Handle); + vTaskStartScheduler(); + for( ; ; ) + { + } +} + +static void task_0_fn(void *pvParameters) { + const int task_id = 0; + TickType_t xLastWakeTime = initial_release_time; + const TickType_t xFrequency = 2.0 / portTICK_PERIOD_MS; + uint8_t chaininp = 0; + uint16_t byteinp = 0; + volatile int tmp=0; + trigger_job_done(); + while(1) { + RNG_RESET + + + chaininp = (INPUT_CHAR_NEXT); + byteinp = INPUT_SHORT_NEXT; + tmp = STRETCH_i32(chaininp) + byteinp; + tmp = FUNCTION_5(tmp); + tmp = TRANSLATE_5(tmp, ((int)7632.0), 76320); + tmp = WC_SWITCH(tmp, 76320); + WASTE_NSEC(tmp); + + trigger_job_done(); + xTaskDelayUntil(&xLastWakeTime, xFrequency ); + } +} +static void task_1_fn(void *pvParameters) { + const int task_id = 1; + // TickType_t xLastWakeTime = initial_release_time; + // const TickType_t xFrequency = 10.0 / portTICK_PERIOD_MS; + uint8_t chaininp = 0; + uint16_t byteinp = 0; + volatile int tmp=0; + trigger_job_done(); + while(1) { + ulTaskNotifyTakeIndexed(9,pdTRUE,portMAX_DELAY); + RNG_RESET + int input_c27 = ulTaskNotifyTakeIndexed(0,pdTRUE,0); + int input_c32 = ulTaskNotifyTakeIndexed(1,pdTRUE,0); + int input_c34 = ulTaskNotifyTakeIndexed(2,pdTRUE,0); + int input_c42 = ulTaskNotifyTakeIndexed(3,pdTRUE,0); + int input_c44 = ulTaskNotifyTakeIndexed(4,pdTRUE,0); + + int32_t cond_27 = RNG_FROM(input_c27) % 16>=(INPUT_CHAR_NEXT % 16 ) || ! (input_c42!=(INPUT_CHAR_NEXT % 16 )) && ! (input_c27<=(INPUT_CHAR_NEXT % 16 )); + int32_t cond_32 = input_c32==4; + int32_t cond_34 = input_c34>=(INPUT_CHAR_NEXT % 16 ) && (input_c32>(INPUT_CHAR_NEXT % 16 )); + int32_t cond_42 = input_c42>=(INPUT_CHAR_NEXT % 16 ) && ! (input_c27<=9) || (input_c44>(INPUT_CHAR_NEXT % 16 )) || (input_c34<=12); + int32_t cond_44 = input_c44>=6; + + chaininp = (uint8_t)(cond_34 | cond_27<<1 | cond_32<<2 | cond_42<<3 | cond_44<<4 | cond_34<<5 | cond_32<<6 | cond_27<<7); + byteinp = INPUT_SHORT_NEXT; + tmp = STRETCH_i32(chaininp) + byteinp; + tmp = FUNCTION_6(tmp); + tmp = TRANSLATE_6(tmp, ((int)180482.0), 1804820); + tmp = WC_SWITCH(tmp, 1804820); + WASTE_NSEC(tmp); + + int output_c13 = (cond_42 | cond_44<<1 | cond_32<<2 || cond_44<<3); + int output_c32 = (cond_27 | cond_34<<1 | cond_42<<2 || cond_32<<3); + int output_c34 = (cond_44 | cond_27<<1 | cond_27<<2 || cond_44<<3); + int output_c44 = (cond_42 | cond_27<<1 | cond_44<<2 || cond_27<<3); + xTaskNotifyIndexed(xTask_7_Handle,0,output_c13+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_6_Handle,1,output_c32+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_7_Handle,2,output_c34+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_6_Handle,4,output_c44+1,eSetValueWithOverwrite); + trigger_job_done(); + // xTaskDelayUntil(&xLastWakeTime, xFrequency ); + } +} +static void task_2_fn(void *pvParameters) { + const int task_id = 2; + // TickType_t xLastWakeTime = initial_release_time; + // const TickType_t xFrequency = 10.0 / portTICK_PERIOD_MS; + uint8_t chaininp = 0; + uint16_t byteinp = 0; + volatile int tmp=0; + trigger_job_done(); + while(1) { + ulTaskNotifyTakeIndexed(9,pdTRUE,portMAX_DELAY); + RNG_RESET + int input_c20 = ulTaskNotifyTakeIndexed(0,pdTRUE,0); + int input_c22 = ulTaskNotifyTakeIndexed(1,pdTRUE,0); + int input_c27 = ulTaskNotifyTakeIndexed(2,pdTRUE,0); + int input_c34 = ulTaskNotifyTakeIndexed(3,pdTRUE,0); + int input_c42 = ulTaskNotifyTakeIndexed(4,pdTRUE,0); + + int32_t cond_20 = RNG_FROM(input_c20) % 16!=(INPUT_CHAR_NEXT % 16 ); + int32_t cond_22 = input_c22<8 || (input_c34!=10) || ! (input_c20>14); + int32_t cond_27 = input_c27>=(INPUT_CHAR_NEXT % 16 ) || ! (input_c34<(INPUT_CHAR_NEXT % 16 )) || (input_c34==input_c42); + int32_t cond_34 = input_c34==16 && (input_c20>=2); + int32_t cond_42 = input_c42<=4 || (input_c42>input_c20) && (input_c34!=(INPUT_CHAR_NEXT % 16 )) && ! (input_c27>(INPUT_CHAR_NEXT % 16 )); + + chaininp = (uint8_t)(cond_27 | cond_34<<1 | cond_42<<2 | cond_22<<3 | cond_20<<4 | cond_22<<5 | cond_42<<6 | cond_42<<7); + byteinp = INPUT_SHORT_NEXT; + tmp = STRETCH_i32(chaininp) + byteinp; + tmp = FUNCTION_2(tmp); + tmp = TRANSLATE_2(tmp, ((int)52546.4), 525464); + tmp = WC_SWITCH(tmp, 525464); + WASTE_NSEC(tmp); + + int output_c20 = (cond_27 | cond_20<<1 | cond_22<<2 || cond_20<<3); + int output_c22 = (cond_22 | cond_20<<1 | cond_27<<2 || cond_22<<3); + int output_c27 = (cond_20 | cond_42<<1 | cond_42<<2 || cond_42<<3); + int output_c42 = (cond_34 | cond_22<<1 | cond_20<<2 || cond_42<<3); + xTaskNotifyIndexed(xTask_5_Handle,0,output_c20+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_7_Handle,1,output_c22+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_1_Handle,0,output_c27+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_1_Handle,3,output_c42+1,eSetValueWithOverwrite); + trigger_job_done(); + // xTaskDelayUntil(&xLastWakeTime, xFrequency ); + } +} +static void task_3_fn(void *pvParameters) { + const int task_id = 3; + // TickType_t xLastWakeTime = initial_release_time; + // const TickType_t xFrequency = 10.0 / portTICK_PERIOD_MS; + uint8_t chaininp = 0; + uint16_t byteinp = 0; + volatile int tmp=0; + trigger_job_done(); + while(1) { + ulTaskNotifyTakeIndexed(9,pdTRUE,portMAX_DELAY); + RNG_RESET + + + chaininp = (INPUT_CHAR_NEXT); + byteinp = INPUT_SHORT_NEXT; + tmp = STRETCH_i32(chaininp) + byteinp; + tmp = FUNCTION_8(tmp); + tmp = TRANSLATE_8(tmp, ((int)61613.7), 616137); + tmp = WC_SWITCH(tmp, 616137); + WASTE_NSEC(tmp); + + int output_c7 = (INPUT_CHAR_NEXT % 16); + int output_c34 = (INPUT_CHAR_NEXT % 16); + xTaskNotifyIndexed(xTask_4_Handle,1,output_c7+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_1_Handle,2,output_c34+1,eSetValueWithOverwrite); + trigger_job_done(); + // xTaskDelayUntil(&xLastWakeTime, xFrequency ); + } +} +static void task_4_fn(void *pvParameters) { + const int task_id = 4; + TickType_t xLastWakeTime = initial_release_time; + const TickType_t xFrequency = 10.0 / portTICK_PERIOD_MS; + uint8_t chaininp = 0; + uint16_t byteinp = 0; + volatile int tmp=0; + while(1) { + RNG_RESET + int input_c1 = ulTaskNotifyTakeIndexed(0,pdTRUE,0); + int input_c7 = ulTaskNotifyTakeIndexed(1,pdTRUE,0); + int input_c27 = ulTaskNotifyTakeIndexed(2,pdTRUE,0); + + int32_t cond_1 = input_c1<=16 || ! (input_c7>(INPUT_CHAR_NEXT % 16 )); + int32_t cond_7 = input_c7=(INPUT_CHAR_NEXT % 16 ) || ! (input_c50<=input_c20); + int32_t cond_50 = input_c50!=input_c20 || ! (input_c20>=input_c50); + + chaininp = (uint8_t)(input_c20 << 4 | input_c50); + byteinp = INPUT_SHORT_NEXT; + tmp = STRETCH_i32(chaininp) + byteinp; + tmp = FUNCTION_8(tmp); + tmp = TRANSLATE_8(tmp, ((int)79674.9), 796749); + tmp = WC_SWITCH(tmp, 796749); + WASTE_NSEC(tmp); + + trigger_job_done(); + xTaskDelayUntil(&xLastWakeTime, xFrequency ); + } +} +static void task_6_fn(void *pvParameters) { + const int task_id = 6; + TickType_t xLastWakeTime = initial_release_time; + const TickType_t xFrequency = 10.0 / portTICK_PERIOD_MS; + uint8_t chaininp = 0; + uint16_t byteinp = 0; + volatile int tmp=0; + while(1) { + RNG_RESET + int input_c13 = ulTaskNotifyTakeIndexed(0,pdTRUE,0); + int input_c32 = ulTaskNotifyTakeIndexed(1,pdTRUE,0); + int input_c34 = ulTaskNotifyTakeIndexed(2,pdTRUE,0); + int input_c42 = ulTaskNotifyTakeIndexed(3,pdTRUE,0); + int input_c44 = ulTaskNotifyTakeIndexed(4,pdTRUE,0); + int input_c50 = ulTaskNotifyTakeIndexed(5,pdTRUE,0); + + int32_t cond_13 = input_c13=4; + int32_t cond_34 = input_c34==(INPUT_CHAR_NEXT % 16 ) || ! (input_c44>input_c32) && (input_c42<3); + int32_t cond_42 = input_c42<=13 || ! (input_c13==14) && ! (input_c50<(INPUT_CHAR_NEXT % 16 )); + int32_t cond_44 = RNG_FROM(input_c44) % 16!=(INPUT_CHAR_NEXT % 16 ); + int32_t cond_50 = RNG_FROM(input_c50) % 16<=(INPUT_CHAR_NEXT % 16 ) || ! (input_c13>=input_c34); + + chaininp = (uint8_t)(cond_34 | cond_32<<1 | cond_44<<2 | cond_42<<3 | cond_13<<4 | cond_50<<5 | cond_13<<6 | cond_34<<7); + byteinp = INPUT_SHORT_NEXT; + tmp = STRETCH_i32(chaininp) + byteinp; + tmp = FUNCTION_1(tmp); + tmp = TRANSLATE_1(tmp, ((int)10619.7), 106197); + tmp = WC_SWITCH(tmp, 106197); + WASTE_NSEC(tmp); + + int output_c27 = (cond_44 | cond_44<<1 | cond_50<<2 || cond_34<<3); + int output_c34 = (cond_13 | cond_32<<1 | cond_13<<2 || cond_50<<3); + int output_c42 = (cond_32 | cond_34<<1 | cond_44<<2 || cond_34<<3); + int output_c44 = (cond_50 | cond_42<<1 | cond_32<<2 || cond_13<<3); + int output_c50 = (cond_34 | cond_50<<1 | cond_13<<2 || cond_13<<3); + xTaskNotifyIndexed(xTask_4_Handle,2,output_c27+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_2_Handle,3,output_c34+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_19_Handle,1,output_c42+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_24_Handle,3,output_c44+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_5_Handle,1,output_c50+1,eSetValueWithOverwrite); + trigger_job_done(); + xTaskDelayUntil(&xLastWakeTime, xFrequency ); + } +} +static void task_7_fn(void *pvParameters) { + const int task_id = 7; + TickType_t xLastWakeTime = initial_release_time; + const TickType_t xFrequency = 10.0 / portTICK_PERIOD_MS; + uint8_t chaininp = 0; + uint16_t byteinp = 0; + volatile int tmp=0; + while(1) { + RNG_RESET + int input_c13 = ulTaskNotifyTakeIndexed(0,pdTRUE,0); + int input_c22 = ulTaskNotifyTakeIndexed(1,pdTRUE,0); + int input_c34 = ulTaskNotifyTakeIndexed(2,pdTRUE,0); + + int32_t cond_13 = input_c13>=(INPUT_CHAR_NEXT % 16 ) || ! (input_c13<3) && (input_c34>(INPUT_CHAR_NEXT % 16 )); + int32_t cond_22 = input_c22>=9 && (input_c13<=9) && ! (input_c22>(INPUT_CHAR_NEXT % 16 )); + int32_t cond_34 = input_c34<=(INPUT_CHAR_NEXT % 16 ) && (input_c22<=(INPUT_CHAR_NEXT % 16 )); + + chaininp = (uint8_t)(input_c13 << 4 | input_c22); + byteinp = INPUT_SHORT_NEXT; + tmp = STRETCH_i32(chaininp) + byteinp; + tmp = FUNCTION_10(tmp); + tmp = TRANSLATE_10(tmp, ((int)56231.7), 562317); + tmp = WC_SWITCH(tmp, 562317); + WASTE_NSEC(tmp); + + int output_c1 = (cond_22 | cond_22<<1 | cond_13<<2 || cond_22<<3); + int output_c13 = (cond_34 | cond_34<<1 | cond_34<<2 || cond_22<<3); + int output_c22 = (cond_13 | cond_13<<1 | cond_13<<2 || cond_22<<3); + int output_c32 = (cond_34 | cond_13<<1 | cond_34<<2 || cond_22<<3); + int output_c34 = (cond_22 | cond_13<<1 | cond_22<<2 || cond_13<<3); + xTaskNotifyIndexed(xTask_4_Handle,0,output_c1+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_6_Handle,0,output_c13+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_21_Handle,0,output_c22+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_1_Handle,1,output_c32+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_6_Handle,2,output_c34+1,eSetValueWithOverwrite); + trigger_job_done(); + xTaskDelayUntil(&xLastWakeTime, xFrequency ); + } +} +static void task_8_fn(void *pvParameters) { + const int task_id = 8; + // TickType_t xLastWakeTime = initial_release_time; + // const TickType_t xFrequency = 20.0 / portTICK_PERIOD_MS; + uint8_t chaininp = 0; + uint16_t byteinp = 0; + volatile int tmp=0; + trigger_job_done(); + while(1) { + ulTaskNotifyTakeIndexed(9,pdTRUE,portMAX_DELAY); + RNG_RESET + int input_c15 = ulTaskNotifyTakeIndexed(0,pdTRUE,0); + int input_c44 = ulTaskNotifyTakeIndexed(1,pdTRUE,0); + + int32_t cond_15 = input_c15<0; + int32_t cond_44 = input_c44<=(INPUT_CHAR_NEXT % 16 ) && (input_c44==15); + + chaininp = (uint8_t)(input_c15 << 4 | input_c44); + byteinp = INPUT_SHORT_NEXT; + tmp = STRETCH_i32(chaininp) + byteinp; + tmp = FUNCTION_10(tmp); + tmp = TRANSLATE_10(tmp, ((int)43715.0), 437150); + tmp = WC_SWITCH(tmp, 437150); + WASTE_NSEC(tmp); + + int output_c39 = (cond_44 | cond_44<<1 | cond_44<<2 || cond_15<<3); + int output_c41 = (cond_15 | cond_15<<1 | cond_44<<2 || cond_15<<3); + xTaskNotifyIndexed(xTask_11_Handle,3,output_c39+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_10_Handle,1,output_c41+1,eSetValueWithOverwrite); + trigger_job_done(); + // xTaskDelayUntil(&xLastWakeTime, xFrequency ); + } +} +static void task_9_fn(void *pvParameters) { + const int task_id = 9; + TickType_t xLastWakeTime = initial_release_time; + const TickType_t xFrequency = 20.0 / portTICK_PERIOD_MS; + uint8_t chaininp = 0; + uint16_t byteinp = 0; + volatile int tmp=0; + while(1) { + RNG_RESET + int input_c39 = ulTaskNotifyTakeIndexed(0,pdTRUE,0); + int input_c41 = ulTaskNotifyTakeIndexed(1,pdTRUE,0); + int input_c47 = ulTaskNotifyTakeIndexed(2,pdTRUE,0); + + int32_t cond_39 = input_c39<=10 && ! (input_c39>(INPUT_CHAR_NEXT % 16 )); + int32_t cond_41 = input_c41input_c39 || (RNG_FROM(input_c39) % 16<(INPUT_CHAR_NEXT % 16 )) || ! (input_c39==11); + + chaininp = (uint8_t)(input_c39 << 4 | input_c41); + byteinp = INPUT_SHORT_NEXT; + tmp = STRETCH_i32(chaininp) + byteinp; + tmp = FUNCTION_3(tmp); + tmp = TRANSLATE_3(tmp, ((int)37534.5), 375345); + tmp = WC_SWITCH(tmp, 375345); + WASTE_NSEC(tmp); + + int output_c5 = (cond_47 | cond_39<<1 | cond_39<<2 || cond_39<<3); + int output_c39 = (cond_47 | cond_47<<1 | cond_41<<2 || cond_41<<3); + int output_c41 = (cond_41 | cond_39<<1 | cond_41<<2 || cond_41<<3); + int output_c47 = (cond_39 | cond_39<<1 | cond_41<<2 || cond_41<<3); + xTaskNotifyIndexed(xTask_12_Handle,0,output_c5+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_15_Handle,4,output_c39+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_15_Handle,5,output_c41+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_12_Handle,2,output_c47+1,eSetValueWithOverwrite); + trigger_job_done(); + xTaskDelayUntil(&xLastWakeTime, xFrequency ); + } +} +static void task_10_fn(void *pvParameters) { + const int task_id = 10; + TickType_t xLastWakeTime = initial_release_time; + const TickType_t xFrequency = 20.0 / portTICK_PERIOD_MS; + uint8_t chaininp = 0; + uint16_t byteinp = 0; + volatile int tmp=0; + while(1) { + RNG_RESET + int input_c15 = ulTaskNotifyTakeIndexed(0,pdTRUE,0); + int input_c41 = ulTaskNotifyTakeIndexed(1,pdTRUE,0); + int input_c44 = ulTaskNotifyTakeIndexed(2,pdTRUE,0); + + int32_t cond_15 = input_c15==(INPUT_CHAR_NEXT % 16 ) || (input_c15<(INPUT_CHAR_NEXT % 16 )); + int32_t cond_41 = input_c41>10 && (input_c41!=(INPUT_CHAR_NEXT % 16 )); + int32_t cond_44 = input_c44>=4 || (input_c44!=input_c41) && ! (input_c15>(INPUT_CHAR_NEXT % 16 )); + + chaininp = (uint8_t)(input_c15 << 4 | input_c41); + byteinp = INPUT_SHORT_NEXT; + tmp = STRETCH_i32(chaininp) + byteinp; + tmp = FUNCTION_8(tmp); + tmp = TRANSLATE_8(tmp, ((int)4132.9), 41329); + tmp = WC_SWITCH(tmp, 41329); + WASTE_NSEC(tmp); + + int output_c15 = (cond_15 | cond_44<<1 | cond_44<<2 || cond_41<<3); + int output_c33 = (cond_44 | cond_44<<1 | cond_15<<2 || cond_15<<3); + int output_c41 = (cond_15 | cond_41<<1 | cond_41<<2 || cond_44<<3); + int output_c44 = (cond_15 | cond_41<<1 | cond_44<<2 || cond_44<<3); + xTaskNotifyIndexed(xTask_8_Handle,0,output_c15+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_13_Handle,0,output_c33+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_11_Handle,4,output_c41+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_17_Handle,0,output_c44+1,eSetValueWithOverwrite); + trigger_job_done(); + xTaskDelayUntil(&xLastWakeTime, xFrequency ); + } +} +static void task_11_fn(void *pvParameters) { + const int task_id = 11; + TickType_t xLastWakeTime = initial_release_time; + const TickType_t xFrequency = 20.0 / portTICK_PERIOD_MS; + uint8_t chaininp = 0; + uint16_t byteinp = 0; + volatile int tmp=0; + while(1) { + RNG_RESET + int input_c5 = ulTaskNotifyTakeIndexed(0,pdTRUE,0); + int input_c12 = ulTaskNotifyTakeIndexed(1,pdTRUE,0); + int input_c33 = ulTaskNotifyTakeIndexed(2,pdTRUE,0); + int input_c39 = ulTaskNotifyTakeIndexed(3,pdTRUE,0); + int input_c41 = ulTaskNotifyTakeIndexed(4,pdTRUE,0); + + int32_t cond_5 = input_c5<(INPUT_CHAR_NEXT % 16 ) || (input_c12<(INPUT_CHAR_NEXT % 16 )) && ! (input_c33==input_c5) && (RNG_FROM(input_c5) % 16!=1); + int32_t cond_12 = input_c12<=8 && ! (input_c12=10; + int32_t cond_39 = input_c39<(INPUT_CHAR_NEXT % 16 ) && (input_c41<=11) || (input_c12==15) && (input_c41<2); + int32_t cond_41 = input_c41>=9 && ! (input_c12<14); + + chaininp = (uint8_t)(cond_12 | cond_39<<1 | cond_33<<2 | cond_41<<3 | cond_5<<4 | cond_12<<5 | cond_41<<6 | cond_5<<7); + byteinp = INPUT_SHORT_NEXT; + tmp = STRETCH_i32(chaininp) + byteinp; + tmp = FUNCTION_10(tmp); + tmp = TRANSLATE_10(tmp, ((int)33574.8), 335748); + tmp = WC_SWITCH(tmp, 335748); + WASTE_NSEC(tmp); + + int output_c5 = (cond_41 | cond_5<<1 | cond_33<<2 || cond_39<<3); + int output_c11 = (cond_12 | cond_41<<1 | cond_12<<2 || cond_39<<3); + int output_c39 = (cond_12 | cond_41<<1 | cond_12<<2 || cond_12<<3); + int output_c41 = (cond_41 | cond_33<<1 | cond_5<<2 || cond_12<<3); + xTaskNotifyIndexed(xTask_15_Handle,0,output_c5+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_15_Handle,1,output_c11+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_9_Handle,0,output_c39+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_9_Handle,1,output_c41+1,eSetValueWithOverwrite); + trigger_job_done(); + xTaskDelayUntil(&xLastWakeTime, xFrequency ); + } +} +static void task_12_fn(void *pvParameters) { + const int task_id = 12; + TickType_t xLastWakeTime = initial_release_time; + const TickType_t xFrequency = 20.0 / portTICK_PERIOD_MS; + uint8_t chaininp = 0; + uint16_t byteinp = 0; + volatile int tmp=0; + while(1) { + RNG_RESET + int input_c5 = ulTaskNotifyTakeIndexed(0,pdTRUE,0); + int input_c18 = ulTaskNotifyTakeIndexed(1,pdTRUE,0); + int input_c47 = ulTaskNotifyTakeIndexed(2,pdTRUE,0); + + int32_t cond_5 = input_c5>=input_c18 || ! (input_c47<=(INPUT_CHAR_NEXT % 16 )) && (input_c47>(INPUT_CHAR_NEXT % 16 )); + int32_t cond_18 = input_c18==2; + int32_t cond_47 = input_c47>(INPUT_CHAR_NEXT % 16 ) || ! (input_c47>=4); + + chaininp = (uint8_t)(input_c5 << 4 | input_c18); + byteinp = INPUT_SHORT_NEXT; + tmp = STRETCH_i32(chaininp) + byteinp; + tmp = FUNCTION_5(tmp); + tmp = TRANSLATE_5(tmp, ((int)118933.0), 1189330); + tmp = WC_SWITCH(tmp, 1189330); + WASTE_NSEC(tmp); + + int output_c5 = (cond_5 | cond_18<<1 | cond_18<<2 || cond_5<<3); + int output_c18 = (cond_47 | cond_5<<1 | cond_5<<2 || cond_47<<3); + int output_c47 = (cond_47 | cond_47<<1 | cond_18<<2 || cond_18<<3); + xTaskNotifyIndexed(xTask_11_Handle,0,output_c5+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_15_Handle,3,output_c18+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_24_Handle,4,output_c47+1,eSetValueWithOverwrite); + trigger_job_done(); + xTaskDelayUntil(&xLastWakeTime, xFrequency ); + } +} +static void task_13_fn(void *pvParameters) { + const int task_id = 13; + TickType_t xLastWakeTime = initial_release_time; + const TickType_t xFrequency = 20.0 / portTICK_PERIOD_MS; + uint8_t chaininp = 0; + uint16_t byteinp = 0; + volatile int tmp=0; + while(1) { + RNG_RESET + int input_c33 = ulTaskNotifyTakeIndexed(0,pdTRUE,0); + int input_c44 = ulTaskNotifyTakeIndexed(1,pdTRUE,0); + + int32_t cond_33 = input_c33!=6; + int32_t cond_44 = RNG_FROM(input_c44) % 16>(INPUT_CHAR_NEXT % 16 ) && ! (input_c44<=4); + + chaininp = (uint8_t)(input_c33 << 4 | input_c44); + byteinp = INPUT_SHORT_NEXT; + tmp = STRETCH_i32(chaininp) + byteinp; + tmp = FUNCTION_7(tmp); + tmp = TRANSLATE_7(tmp, ((int)85798.0), 857980); + tmp = WC_SWITCH(tmp, 857980); + WASTE_NSEC(tmp); + + int output_c12 = (cond_44 | cond_33<<1 | cond_33<<2 || cond_44<<3); + int output_c33 = (cond_44 | cond_33<<1 | cond_44<<2 || cond_44<<3); + int output_c44 = (cond_44 | cond_44<<1 | cond_44<<2 || cond_44<<3); + xTaskNotifyIndexed(xTask_15_Handle,2,output_c12+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_11_Handle,2,output_c33+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_10_Handle,2,output_c44+1,eSetValueWithOverwrite); + trigger_job_done(); + xTaskDelayUntil(&xLastWakeTime, xFrequency ); + } +} +static void task_14_fn(void *pvParameters) { + const int task_id = 14; + TickType_t xLastWakeTime = initial_release_time; + const TickType_t xFrequency = 20.0 / portTICK_PERIOD_MS; + uint8_t chaininp = 0; + uint16_t byteinp = 0; + volatile int tmp=0; + while(1) { + RNG_RESET + int input_c39 = ulTaskNotifyTakeIndexed(0,pdTRUE,0); + + int32_t cond_39 = input_c39==9; + + chaininp = (uint8_t)(input_c39 << 4 | 0xFF); + byteinp = INPUT_SHORT_NEXT; + tmp = STRETCH_i32(chaininp) + byteinp; + tmp = FUNCTION_2(tmp); + tmp = TRANSLATE_2(tmp, ((int)181050.2), 1810502); + tmp = WC_SWITCH(tmp, 1810502); + WASTE_NSEC(tmp); + + int output_c15 = (cond_39 | cond_39<<1 | cond_39<<2 || cond_39<<3); + int output_c18 = (cond_39 | cond_39<<1 | cond_39<<2 || cond_39<<3); + int output_c47 = (cond_39 | cond_39<<1 | cond_39<<2 || cond_39<<3); + xTaskNotifyIndexed(xTask_24_Handle,0,output_c15+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_12_Handle,1,output_c18+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_9_Handle,2,output_c47+1,eSetValueWithOverwrite); + trigger_job_done(); + xTaskDelayUntil(&xLastWakeTime, xFrequency ); + } +} +static void task_15_fn(void *pvParameters) { + const int task_id = 15; + TickType_t xLastWakeTime = initial_release_time; + const TickType_t xFrequency = 20.0 / portTICK_PERIOD_MS; + uint8_t chaininp = 0; + uint16_t byteinp = 0; + volatile int tmp=0; + while(1) { + RNG_RESET + int input_c5 = ulTaskNotifyTakeIndexed(0,pdTRUE,0); + int input_c11 = ulTaskNotifyTakeIndexed(1,pdTRUE,0); + int input_c12 = ulTaskNotifyTakeIndexed(2,pdTRUE,0); + int input_c18 = ulTaskNotifyTakeIndexed(3,pdTRUE,0); + int input_c39 = ulTaskNotifyTakeIndexed(4,pdTRUE,0); + int input_c41 = ulTaskNotifyTakeIndexed(5,pdTRUE,0); + + int32_t cond_5 = input_c5<=14 || ! (input_c12<(INPUT_CHAR_NEXT % 16 )) && (input_c11<=(INPUT_CHAR_NEXT % 16 )); + int32_t cond_11 = input_c11>(INPUT_CHAR_NEXT % 16 ) || ! (RNG_FROM(input_c39) % 16=input_c18); + int32_t cond_12 = input_c12!=input_c11 && ! (input_c5<=15) && (input_c5<=(INPUT_CHAR_NEXT % 16 )) || (RNG_FROM(input_c39) % 16==0); + int32_t cond_18 = input_c18!=(INPUT_CHAR_NEXT % 16 ) && ! (input_c11<=11) || (input_c12>input_c41) || ! (input_c39!=4); + int32_t cond_39 = input_c39>11; + int32_t cond_41 = RNG_FROM(input_c41) % 16>=(INPUT_CHAR_NEXT % 16 ) || ! (input_c12<=(INPUT_CHAR_NEXT % 16 )); + + chaininp = (uint8_t)(cond_39 | cond_5<<1 | cond_18<<2 | cond_12<<3 | cond_41<<4 | cond_11<<5 | cond_39<<6 | cond_18<<7); + byteinp = INPUT_SHORT_NEXT; + tmp = STRETCH_i32(chaininp) + byteinp; + tmp = FUNCTION_5(tmp); + tmp = TRANSLATE_5(tmp, ((int)45921.5), 459215); + tmp = WC_SWITCH(tmp, 459215); + WASTE_NSEC(tmp); + + int output_c12 = (cond_41 | cond_18<<1 | cond_11<<2 || cond_11<<3); + int output_c39 = (cond_41 | cond_11<<1 | cond_41<<2 || cond_11<<3); + xTaskNotifyIndexed(xTask_11_Handle,1,output_c12+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_14_Handle,0,output_c39+1,eSetValueWithOverwrite); + trigger_job_done(); + xTaskDelayUntil(&xLastWakeTime, xFrequency ); + } +} +static void task_16_fn(void *pvParameters) { + const int task_id = 16; + TickType_t xLastWakeTime = initial_release_time; + const TickType_t xFrequency = 50.0 / portTICK_PERIOD_MS; + uint8_t chaininp = 0; + uint16_t byteinp = 0; + volatile int tmp=0; + while(1) { + RNG_RESET + + + chaininp = (INPUT_CHAR_NEXT); + byteinp = INPUT_SHORT_NEXT; + tmp = STRETCH_i32(chaininp) + byteinp; + tmp = FUNCTION_8(tmp); + tmp = TRANSLATE_8(tmp, ((int)2467.5), 24675); + tmp = WC_SWITCH(tmp, 24675); + WASTE_NSEC(tmp); + + trigger_job_done(); + xTaskDelayUntil(&xLastWakeTime, xFrequency ); + } +} +static void task_17_fn(void *pvParameters) { + const int task_id = 17; + TickType_t xLastWakeTime = initial_release_time; + const TickType_t xFrequency = 100.0 / portTICK_PERIOD_MS; + uint8_t chaininp = 0; + uint16_t byteinp = 0; + volatile int tmp=0; + while(1) { + RNG_RESET + int input_c44 = ulTaskNotifyTakeIndexed(0,pdTRUE,0); + int input_c49 = ulTaskNotifyTakeIndexed(1,pdTRUE,0); + + int32_t cond_44 = input_c44==2 && ! (input_c49>=(INPUT_CHAR_NEXT % 16 )); + int32_t cond_49 = input_c49<=9 && ! (input_c49>=input_c44); + + chaininp = (uint8_t)(input_c44 << 4 | input_c49); + byteinp = INPUT_SHORT_NEXT; + tmp = STRETCH_i32(chaininp) + byteinp; + tmp = FUNCTION_1(tmp); + tmp = TRANSLATE_1(tmp, ((int)55368.2), 553682); + tmp = WC_SWITCH(tmp, 553682); + WASTE_NSEC(tmp); + + int output_c44 = (cond_44 | cond_49<<1 | cond_49<<2 || cond_44<<3); + int output_c49 = (cond_44 | cond_49<<1 | cond_49<<2 || cond_49<<3); + xTaskNotifyIndexed(xTask_25_Handle,2,output_c44+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_20_Handle,2,output_c49+1,eSetValueWithOverwrite); + trigger_job_done(); + xTaskDelayUntil(&xLastWakeTime, xFrequency ); + } +} +static void task_18_fn(void *pvParameters) { + const int task_id = 18; + TickType_t xLastWakeTime = initial_release_time; + const TickType_t xFrequency = 100.0 / portTICK_PERIOD_MS; + uint8_t chaininp = 0; + uint16_t byteinp = 0; + volatile int tmp=0; + while(1) { + RNG_RESET + int input_c9 = ulTaskNotifyTakeIndexed(0,pdTRUE,0); + int input_c30 = ulTaskNotifyTakeIndexed(1,pdTRUE,0); + int input_c49 = ulTaskNotifyTakeIndexed(2,pdTRUE,0); + + int32_t cond_9 = input_c9!=7 && ! (input_c30>=input_c9) || ! (input_c49>=(INPUT_CHAR_NEXT % 16 )); + int32_t cond_30 = input_c30<=7; + int32_t cond_49 = input_c49>=input_c9 && ! (RNG_FROM(input_c9) % 16<8); + + chaininp = (uint8_t)(input_c9 << 4 | input_c30); + byteinp = INPUT_SHORT_NEXT; + tmp = STRETCH_i32(chaininp) + byteinp; + tmp = FUNCTION_10(tmp); + tmp = TRANSLATE_10(tmp, ((int)423.9), 4239); + tmp = WC_SWITCH(tmp, 4239); + WASTE_NSEC(tmp); + + int output_c22 = (cond_9 | cond_9<<1 | cond_49<<2 || cond_30<<3); + int output_c30 = (cond_9 | cond_49<<1 | cond_30<<2 || cond_30<<3); + int output_c49 = (cond_30 | cond_9<<1 | cond_30<<2 || cond_30<<3); + xTaskNotifyIndexed(xTask_24_Handle,1,output_c22+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_23_Handle,2,output_c30+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_17_Handle,1,output_c49+1,eSetValueWithOverwrite); + trigger_job_done(); + xTaskDelayUntil(&xLastWakeTime, xFrequency ); + } +} +static void task_19_fn(void *pvParameters) { + const int task_id = 19; + TickType_t xLastWakeTime = initial_release_time; + const TickType_t xFrequency = 100.0 / portTICK_PERIOD_MS; + uint8_t chaininp = 0; + uint16_t byteinp = 0; + volatile int tmp=0; + while(1) { + RNG_RESET + int input_c35 = ulTaskNotifyTakeIndexed(0,pdTRUE,0); + int input_c42 = ulTaskNotifyTakeIndexed(1,pdTRUE,0); + + int32_t cond_35 = input_c35>(INPUT_CHAR_NEXT % 16 ) && (input_c42==12); + int32_t cond_42 = RNG_FROM(input_c42) % 16<(INPUT_CHAR_NEXT % 16 ) && (input_c35<=3); + + chaininp = (uint8_t)(input_c35 << 4 | input_c42); + byteinp = INPUT_SHORT_NEXT; + tmp = STRETCH_i32(chaininp) + byteinp; + tmp = FUNCTION_2(tmp); + tmp = TRANSLATE_2(tmp, ((int)4884.6), 48846); + tmp = WC_SWITCH(tmp, 48846); + WASTE_NSEC(tmp); + + int output_c23 = (cond_35 | cond_35<<1 | cond_35<<2 || cond_42<<3); + int output_c42 = (cond_35 | cond_35<<1 | cond_42<<2 || cond_35<<3); + xTaskNotifyIndexed(xTask_25_Handle,1,output_c23+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_2_Handle,4,output_c42+1,eSetValueWithOverwrite); + trigger_job_done(); + xTaskDelayUntil(&xLastWakeTime, xFrequency ); + } +} +static void task_20_fn(void *pvParameters) { + const int task_id = 20; + TickType_t xLastWakeTime = initial_release_time; + const TickType_t xFrequency = 100.0 / portTICK_PERIOD_MS; + uint8_t chaininp = 0; + uint16_t byteinp = 0; + volatile int tmp=0; + while(1) { + RNG_RESET + int input_c35 = ulTaskNotifyTakeIndexed(0,pdTRUE,0); + int input_c42 = ulTaskNotifyTakeIndexed(1,pdTRUE,0); + int input_c49 = ulTaskNotifyTakeIndexed(2,pdTRUE,0); + + int32_t cond_35 = input_c35>6; + int32_t cond_42 = input_c42>=(INPUT_CHAR_NEXT % 16 ) && (input_c35>input_c42); + int32_t cond_49 = input_c49>input_c35; + + chaininp = (uint8_t)(input_c35 << 4 | input_c42); + byteinp = INPUT_SHORT_NEXT; + tmp = STRETCH_i32(chaininp) + byteinp; + tmp = FUNCTION_3(tmp); + tmp = TRANSLATE_3(tmp, ((int)35951.2), 359512); + tmp = WC_SWITCH(tmp, 359512); + WASTE_NSEC(tmp); + + int output_c35 = (cond_49 | cond_42<<1 | cond_42<<2 || cond_42<<3); + int output_c42 = (cond_49 | cond_49<<1 | cond_42<<2 || cond_49<<3); + int output_c49 = (cond_49 | cond_35<<1 | cond_42<<2 || cond_35<<3); + xTaskNotifyIndexed(xTask_19_Handle,0,output_c35+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_6_Handle,3,output_c42+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_25_Handle,3,output_c49+1,eSetValueWithOverwrite); + trigger_job_done(); + xTaskDelayUntil(&xLastWakeTime, xFrequency ); + } +} +static void task_21_fn(void *pvParameters) { + const int task_id = 21; + TickType_t xLastWakeTime = initial_release_time; + const TickType_t xFrequency = 100.0 / portTICK_PERIOD_MS; + uint8_t chaininp = 0; + uint16_t byteinp = 0; + volatile int tmp=0; + while(1) { + RNG_RESET + int input_c22 = ulTaskNotifyTakeIndexed(0,pdTRUE,0); + int input_c44 = ulTaskNotifyTakeIndexed(1,pdTRUE,0); + + int32_t cond_22 = input_c22>5; + int32_t cond_44 = input_c44<=5; + + chaininp = (uint8_t)(input_c22 << 4 | input_c44); + byteinp = INPUT_SHORT_NEXT; + tmp = STRETCH_i32(chaininp) + byteinp; + tmp = FUNCTION_5(tmp); + tmp = TRANSLATE_5(tmp, ((int)97043.5), 970435); + tmp = WC_SWITCH(tmp, 970435); + WASTE_NSEC(tmp); + + int output_c44 = (cond_44 | cond_44<<1 | cond_22<<2 || cond_22<<3); + xTaskNotifyIndexed(xTask_13_Handle,1,output_c44+1,eSetValueWithOverwrite); + trigger_job_done(); + xTaskDelayUntil(&xLastWakeTime, xFrequency ); + } +} +static void task_22_fn(void *pvParameters) { + const int task_id = 22; + TickType_t xLastWakeTime = initial_release_time; + const TickType_t xFrequency = 100.0 / portTICK_PERIOD_MS; + uint8_t chaininp = 0; + uint16_t byteinp = 0; + volatile int tmp=0; + while(1) { + RNG_RESET + int input_c9 = ulTaskNotifyTakeIndexed(0,pdTRUE,0); + int input_c30 = ulTaskNotifyTakeIndexed(1,pdTRUE,0); + int input_c47 = ulTaskNotifyTakeIndexed(2,pdTRUE,0); + + int32_t cond_9 = input_c9!=10 || ! (input_c47>=1) || ! (input_c47>=(INPUT_CHAR_NEXT % 16 )); + int32_t cond_30 = input_c30>=(INPUT_CHAR_NEXT % 16 ); + int32_t cond_47 = input_c47<13 && (input_c30>=(INPUT_CHAR_NEXT % 16 )) || ! (input_c47<16); + + chaininp = (uint8_t)(input_c9 << 4 | input_c30); + byteinp = INPUT_SHORT_NEXT; + tmp = STRETCH_i32(chaininp) + byteinp; + tmp = FUNCTION_9(tmp); + tmp = TRANSLATE_9(tmp, ((int)33427.1), 334271); + tmp = WC_SWITCH(tmp, 334271); + WASTE_NSEC(tmp); + + int output_c9 = (cond_9 | cond_47<<1 | cond_9<<2 || cond_47<<3); + int output_c26 = (cond_9 | cond_47<<1 | cond_9<<2 || cond_47<<3); + xTaskNotifyIndexed(xTask_18_Handle,0,output_c9+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_26_Handle,0,output_c26+1,eSetValueWithOverwrite); + trigger_job_done(); + xTaskDelayUntil(&xLastWakeTime, xFrequency ); + } +} +static void task_23_fn(void *pvParameters) { + const int task_id = 23; + TickType_t xLastWakeTime = initial_release_time; + const TickType_t xFrequency = 100.0 / portTICK_PERIOD_MS; + uint8_t chaininp = 0; + uint16_t byteinp = 0; + volatile int tmp=0; + while(1) { + RNG_RESET + int input_c15 = ulTaskNotifyTakeIndexed(0,pdTRUE,0); + int input_c26 = ulTaskNotifyTakeIndexed(1,pdTRUE,0); + int input_c30 = ulTaskNotifyTakeIndexed(2,pdTRUE,0); + + int32_t cond_15 = input_c15!=input_c26 && (input_c15==input_c30); + int32_t cond_26 = input_c26>(INPUT_CHAR_NEXT % 16 ) || (input_c15!=0) && (input_c26!=(INPUT_CHAR_NEXT % 16 )); + int32_t cond_30 = RNG_FROM(input_c30) % 16!=2; + + chaininp = (uint8_t)(input_c15 << 4 | input_c26); + byteinp = INPUT_SHORT_NEXT; + tmp = STRETCH_i32(chaininp) + byteinp; + tmp = FUNCTION_9(tmp); + tmp = TRANSLATE_9(tmp, ((int)35262.6), 352626); + tmp = WC_SWITCH(tmp, 352626); + WASTE_NSEC(tmp); + + int output_c15 = (cond_15 | cond_30<<1 | cond_26<<2 || cond_26<<3); + int output_c30 = (cond_30 | cond_30<<1 | cond_15<<2 || cond_26<<3); + xTaskNotifyIndexed(xTask_10_Handle,0,output_c15+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_24_Handle,2,output_c30+1,eSetValueWithOverwrite); + trigger_job_done(); + xTaskDelayUntil(&xLastWakeTime, xFrequency ); + } +} +static void task_24_fn(void *pvParameters) { + const int task_id = 24; + TickType_t xLastWakeTime = initial_release_time; + const TickType_t xFrequency = 100.0 / portTICK_PERIOD_MS; + uint8_t chaininp = 0; + uint16_t byteinp = 0; + volatile int tmp=0; + while(1) { + RNG_RESET + int input_c15 = ulTaskNotifyTakeIndexed(0,pdTRUE,0); + int input_c22 = ulTaskNotifyTakeIndexed(1,pdTRUE,0); + int input_c30 = ulTaskNotifyTakeIndexed(2,pdTRUE,0); + int input_c44 = ulTaskNotifyTakeIndexed(3,pdTRUE,0); + int input_c47 = ulTaskNotifyTakeIndexed(4,pdTRUE,0); + + int32_t cond_15 = input_c15<(INPUT_CHAR_NEXT % 16 ) && (input_c15>=10) || ! (RNG_FROM(input_c22) % 16!=input_c44); + int32_t cond_22 = input_c22>(INPUT_CHAR_NEXT % 16 ) && ! (RNG_FROM(input_c44) % 16==0) && (input_c44>=4) || ! (input_c47>(INPUT_CHAR_NEXT % 16 )); + int32_t cond_30 = input_c30<=9 && (input_c47==8) && (input_c44=(INPUT_CHAR_NEXT % 16 )); + int32_t cond_44 = input_c44==input_c15 || (input_c47<=10) || (input_c44<=input_c15) || (input_c22>6); + int32_t cond_47 = input_c47!=(INPUT_CHAR_NEXT % 16 ) || ! (input_c47>=input_c44) || ! (input_c44!=(INPUT_CHAR_NEXT % 16 )) && (input_c47>=5); + + chaininp = (uint8_t)(cond_47 | cond_22<<1 | cond_15<<2 | cond_44<<3 | cond_30<<4 | cond_47<<5 | cond_30<<6 | cond_44<<7); + byteinp = INPUT_SHORT_NEXT; + tmp = STRETCH_i32(chaininp) + byteinp; + tmp = FUNCTION_2(tmp); + tmp = TRANSLATE_2(tmp, ((int)7860.9), 78609); + tmp = WC_SWITCH(tmp, 78609); + WASTE_NSEC(tmp); + + int output_c15 = (cond_30 | cond_47<<1 | cond_47<<2 || cond_22<<3); + int output_c22 = (cond_44 | cond_47<<1 | cond_22<<2 || cond_30<<3); + int output_c30 = (cond_30 | cond_47<<1 | cond_15<<2 || cond_22<<3); + int output_c42 = (cond_22 | cond_47<<1 | cond_15<<2 || cond_30<<3); + int output_c44 = (cond_44 | cond_30<<1 | cond_47<<2 || cond_22<<3); + int output_c47 = (cond_44 | cond_47<<1 | cond_44<<2 || cond_47<<3); + xTaskNotifyIndexed(xTask_23_Handle,0,output_c15+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_25_Handle,0,output_c22+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_22_Handle,1,output_c30+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_20_Handle,1,output_c42+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_8_Handle,1,output_c44+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_22_Handle,2,output_c47+1,eSetValueWithOverwrite); + trigger_job_done(); + xTaskDelayUntil(&xLastWakeTime, xFrequency ); + } +} +static void task_25_fn(void *pvParameters) { + const int task_id = 25; + TickType_t xLastWakeTime = initial_release_time; + const TickType_t xFrequency = 100.0 / portTICK_PERIOD_MS; + uint8_t chaininp = 0; + uint16_t byteinp = 0; + volatile int tmp=0; + while(1) { + RNG_RESET + int input_c22 = ulTaskNotifyTakeIndexed(0,pdTRUE,0); + int input_c23 = ulTaskNotifyTakeIndexed(1,pdTRUE,0); + int input_c44 = ulTaskNotifyTakeIndexed(2,pdTRUE,0); + int input_c49 = ulTaskNotifyTakeIndexed(3,pdTRUE,0); + + int32_t cond_22 = input_c22<4 && ! (input_c23>(INPUT_CHAR_NEXT % 16 )); + int32_t cond_23 = input_c23!=3 || (RNG_FROM(input_c44) % 16!=(INPUT_CHAR_NEXT % 16 )) && (input_c23=14); + int32_t cond_49 = input_c49<=input_c23 || ! (input_c44<=(INPUT_CHAR_NEXT % 16 )) || (RNG_FROM(input_c49) % 16<=12); + + chaininp = (uint8_t)(cond_23 | cond_22<<1 | cond_44<<2 | cond_49<<3 | cond_22<<4 | cond_22<<5 | cond_49<<6 | cond_23<<7); + byteinp = INPUT_SHORT_NEXT; + tmp = STRETCH_i32(chaininp) + byteinp; + tmp = FUNCTION_1(tmp); + tmp = TRANSLATE_1(tmp, ((int)72668.5), 726685); + tmp = WC_SWITCH(tmp, 726685); + WASTE_NSEC(tmp); + + int output_c9 = (cond_23 | cond_22<<1 | cond_49<<2 || cond_49<<3); + int output_c22 = (cond_23 | cond_23<<1 | cond_44<<2 || cond_44<<3); + int output_c30 = (cond_49 | cond_49<<1 | cond_49<<2 || cond_49<<3); + int output_c35 = (cond_44 | cond_23<<1 | cond_23<<2 || cond_22<<3); + int output_c44 = (cond_22 | cond_23<<1 | cond_22<<2 || cond_44<<3); + xTaskNotifyIndexed(xTask_22_Handle,0,output_c9+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_2_Handle,1,output_c22+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_18_Handle,1,output_c30+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_20_Handle,0,output_c35+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_1_Handle,4,output_c44+1,eSetValueWithOverwrite); + trigger_job_done(); + xTaskDelayUntil(&xLastWakeTime, xFrequency ); + } +} +static void task_26_fn(void *pvParameters) { + const int task_id = 26; + TickType_t xLastWakeTime = initial_release_time; + const TickType_t xFrequency = 100.0 / portTICK_PERIOD_MS; + uint8_t chaininp = 0; + uint16_t byteinp = 0; + volatile int tmp=0; + while(1) { + RNG_RESET + int input_c26 = ulTaskNotifyTakeIndexed(0,pdTRUE,0); + + int32_t cond_26 = input_c26>=16; + + chaininp = (uint8_t)(input_c26 << 4 | 0xFF); + byteinp = INPUT_SHORT_NEXT; + tmp = STRETCH_i32(chaininp) + byteinp; + tmp = FUNCTION_2(tmp); + tmp = TRANSLATE_2(tmp, ((int)96338.4), 963384); + tmp = WC_SWITCH(tmp, 963384); + WASTE_NSEC(tmp); + + int output_c26 = (cond_26 | cond_26<<1 | cond_26<<2 || cond_26<<3); + int output_c44 = (cond_26 | cond_26<<1 | cond_26<<2 || cond_26<<3); + int output_c49 = (cond_26 | cond_26<<1 | cond_26<<2 || cond_26<<3); + xTaskNotifyIndexed(xTask_23_Handle,1,output_c26+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_21_Handle,1,output_c44+1,eSetValueWithOverwrite); + xTaskNotifyIndexed(xTask_18_Handle,2,output_c49+1,eSetValueWithOverwrite); + trigger_job_done(); + xTaskDelayUntil(&xLastWakeTime, xFrequency ); + } +} + + +void ISR_0_Handler(void) { + BaseType_t xHigherPriorityTaskWoken = pdFALSE; + if (xTask_0_Handle != NULL) { + xTaskNotifyFromISR(xTask_0_Handle, 9, eNoAction, &xHigherPriorityTaskWoken); + portYIELD_FROM_ISR( xHigherPriorityTaskWoken ); + } +} +void ISR_1_Handler(void) { + BaseType_t xHigherPriorityTaskWoken = pdFALSE; + if (xTask_1_Handle != NULL) { + xTaskNotifyFromISR(xTask_1_Handle, 9, eNoAction, &xHigherPriorityTaskWoken); + portYIELD_FROM_ISR( xHigherPriorityTaskWoken ); + } +} +void ISR_2_Handler(void) { + BaseType_t xHigherPriorityTaskWoken = pdFALSE; + if (xTask_2_Handle != NULL) { + xTaskNotifyFromISR(xTask_2_Handle, 9, eNoAction, &xHigherPriorityTaskWoken); + portYIELD_FROM_ISR( xHigherPriorityTaskWoken ); + } +} +void ISR_3_Handler(void) { + BaseType_t xHigherPriorityTaskWoken = pdFALSE; + if (xTask_8_Handle != NULL) { + xTaskNotifyFromISR(xTask_8_Handle, 9, eNoAction, &xHigherPriorityTaskWoken); + portYIELD_FROM_ISR( xHigherPriorityTaskWoken ); + } +} \ No newline at end of file diff --git a/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/polynomic_functions.h b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/polynomic_functions.h new file mode 100644 index 00000000..0dea1f1b --- /dev/null +++ b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/polynomic_functions.h @@ -0,0 +1,94 @@ +#ifndef __POLYNOMIC_FUNCTIONS_H__ +#define __POLYNOMIC_FUNCTIONS_H__ +#include "util_macros.h" + +#define FUNCTION_1(X) \ + HILL(X, 0, 200000, 800000) \ + + HILL(X, (INT_MIN/4)*3, 400000, 1500000) \ + + HILL(X, INT_MAX/2, 800000, 200000) \ + + CLAMP_FLOOR(LIN(SSUB(X, INT_MAX/4),5,100000,0),0) \ + + CLAMP_FLOOR(LIN(-X,5,100000,0),0) \ + + 200000 \ + - JITTER(X, 30000) + +#define FUNCTION_2(X) \ + VALLEY(X, 0, -200000, 800000) \ + + VALLEY(X, (INT_MIN/4)*3, -400000, 1500000) \ + + VALLEY(X, INT_MAX/2, -800000, 200000) \ + + CLAMP_FLOOR(LIN(SSUB(X, INT_MAX/4),5,100000,0),0) \ + + CLAMP_FLOOR(LIN(-X,5,-100000,0),0) \ + + 200000 \ + - JITTER(X, 30000) + +#define FUNCTION_3(X) \ + LIN(SADD(X, INT_MAX/2),5,100000,0) \ + + LIN(-X,2,100000,0) \ + - JITTER(X, 10000) + +#define FUNCTION_4(X) \ + LIN(SADD(X, 3*(INT_MAX/8)),-30,100000,0) \ + + LIN(SSUB(X, 3*(INT_MAX/8)),30,100000,0) \ + - JITTER(X, 10000) + +#define FUNCTION_5(X) \ + VALLEY(X, 0, -200000, 10000000) \ + + HILL(X, 0, 42000, 5000000) \ + - JITTER(X, 1000) + +#define FUNCTION_6(X) \ + LIN(X,1,2,0) \ + + HILL(X, -1500000000, 1000000000, 50000) \ + + VALLEY(X, 1500000000, -1000000000, 50000) \ + - JITTER(X, 1000) + +#define FUNCTION_7(X) \ + LIN(X,1,100000,0) \ + + HILL(X, 7*(INT_MIN/8), 140000, 200000) \ + + HILL(X, 6*(INT_MIN/8), 100000, 200000) \ + + HILL(X, 5*(INT_MIN/8), 80000, 200000) \ + + HILL(X, 4*(INT_MIN/8), 60000, 200000) \ + + HILL(X, 3*(INT_MIN/8), 70000, 200000) \ + + HILL(X, 2*(INT_MIN/8), 80000, 200000) \ + + HILL(X, 1*(INT_MIN/8), 90000, 200000) \ + + HILL(X, 1*(INT_MAX/8), 90000, 200000) \ + + HILL(X, 2*(INT_MAX/8), 80000, 200000) \ + + HILL(X, 3*(INT_MAX/8), 70000, 200000) \ + + HILL(X, 4*(INT_MAX/8), 60000, 200000) \ + + HILL(X, 5*(INT_MAX/8), 50000, 200000) \ + + HILL(X, 6*(INT_MAX/8), 40000, 200000) \ + + HILL(X, 7*(INT_MAX/8), 30000, 200000) \ + - JITTER(X, 1000) + +#define FUNCTION_8(X) \ + (X>INT_MIN/2)*HILL((X%(INT_MAX/3)), 0, 10000000, 50000) * (ABS_DIFF(X,0)/100000000) \ + + LIN(X, -1, 100, 0) \ + - JITTER(X, 1000) + +#define FUNCTION_9(X) \ + HILL(X, 3*(INT_MIN/4), 200000, 800000) \ + + HILL(X, 1*(INT_MIN/4), 200000, 800000) \ + + HILL(X, 3*(INT_MAX/4), 400000, 400000) \ + + (X<0)*LIN(X, 1, 10000, 0) \ + + (X>0)*LIN(X, -1, 10000, 0) \ + - JITTER(X, 1000) + +#define FUNCTION_10(X) \ + + (X<=0)*LIN(X, 1, 10000, 0) \ + + (X>0)*LIN(X, -1, 10000, 0) \ + + VALLEY(X, 0, -200000, 1000000) \ + + 200000 \ + - JITTER(X, 1000) + + +#define TRANSLATE_1(I, LB,UB) TRANSLATE_BOUNDS((I), 180000, 1000000, LB, UB) // FN 1 +#define TRANSLATE_2(I, LB,UB) TRANSLATE_BOUNDS((I), -500000, 390000, LB, UB) // FN 2 +#define TRANSLATE_3(I, LB,UB) TRANSLATE_BOUNDS((I), -8000, 80000, LB, UB) // FN 3 +#define TRANSLATE_4(I, LB,UB) TRANSLATE_BOUNDS((I), -480000, -250000, LB, UB) // FN 4 +#define TRANSLATE_5(I, LB,UB) TRANSLATE_BOUNDS((I), -193000, -155000, LB, UB) // FN 5 +#define TRANSLATE_6(I, LB,UB) TRANSLATE_BOUNDS((I), -400000000, 400000000, LB, UB) // FN 6 +#define TRANSLATE_7(I, LB,UB) TRANSLATE_BOUNDS((I), -20000, 120000, LB, UB) // FN 7 +#define TRANSLATE_8(I, LB,UB) TRANSLATE_BOUNDS((I), -20000000, 120000000, LB, UB) // FN 8 +#define TRANSLATE_9(I, LB,UB) TRANSLATE_BOUNDS((I), -200000, 220000, LB, UB) // FN 9 +#define TRANSLATE_10(I, LB,UB) TRANSLATE_BOUNDS((I), -10000, 150000, LB, UB) // FN 10 + +#endif \ No newline at end of file diff --git a/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/util_macros.h b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/util_macros.h new file mode 100644 index 00000000..35f3b350 --- /dev/null +++ b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/util_macros.h @@ -0,0 +1,131 @@ +#ifndef __UTIL_MACROS_H__ +#define __UTIL_MACROS_H__ + +#include +#include + +// Veriadic macros == +#define REP_VA0(...) +#define REP_VA1(...) __VA_ARGS__ +#define REP_VA2(...) REP_VA1(__VA_ARGS__),__VA_ARGS__ +#define REP_VA3(...) REP_VA2(__VA_ARGS__),__VA_ARGS__ +#define REP_VA4(...) REP_VA3(__VA_ARGS__),__VA_ARGS__ +#define REP_VA5(...) REP_VA4(__VA_ARGS__),__VA_ARGS__ +#define REP_VA6(...) REP_VA5(__VA_ARGS__),__VA_ARGS__ +#define REP_VA7(...) REP_VA6(__VA_ARGS__),__VA_ARGS__ +#define REP_VA8(...) REP_VA7(__VA_ARGS__),__VA_ARGS__ +#define REP_VA9(...) REP_VA8(__VA_ARGS__),__VA_ARGS__ +#define REP_VA10(...) REP_VA9(__VA_ARGS__),__VA_ARGS__ + +#define REP_VA(HUNDREDS,TENS,ONES,...) \ + REP_VA##HUNDREDS(REP_VA10(REP_VA10(__VA_ARGS__))) \ + REP_VA##TENS(REP_VA10(__VA_ARGS__)) \ + REP_VA##ONES(__VA_ARGS__) + +// Random numbers === +// glibc +// https://en.wikipedia.org/wiki/Linear_congruential_generator +#define __UTIL_RNG_A 1103515245ull +#define __UTIL_RNG_M 0x80000000ull +#define __UTIL_RNG_C 12345ull +#define RNG_FROM(X) ((__UTIL_RNG_A*(X)+__UTIL_RNG_C) % __UTIL_RNG_M) + +#define IF_ELSE(X,Y,Z) ((X) ? (Y) : (Z)) + +// Challanges ======= +#define CHANCE_1_IN_POWOF2(X,Y) (RNG_FROM(X)<(M>>Y)) // assume the type of x has more than y bits + +// branchless, takes a large hit on performance +#ifdef BRANCHLESS_TERNARY +#define IF_ELSE(X,Y,Z) (((X)*(Y))+((!(X))*(Z))) +#else +#define IF_ELSE(X,Y,Z) ((X) ? (Y) : (Z)) +#endif + + +// Arithmetic ======= +static inline int32_t sadd_i32(int32_t a, int32_t b) { + return IF_ELSE((b>=0), + IF_ELSE((a > INT32_MAX - b), INT32_MAX, a + b), + IF_ELSE((a < INT32_MIN - b), INT32_MIN, a + b)); +} +static inline int32_t ssub_i32(int32_t a, int32_t b) { + return IF_ELSE((b>=0), + IF_ELSE((a < INT32_MIN + b), INT32_MIN, a - b), + IF_ELSE((a > INT32_MAX + b), INT32_MAX, a - b)); +} +static inline int32_t ssquare_i32(int32_t a) { + return IF_ELSE((a <= 0x0000B504 ), a*a, INT32_MAX); +} +static inline int32_t abs_i32(int32_t a) { + return IF_ELSE((a > 0), a, IF_ELSE((a == INT32_MIN), INT32_MAX, -a)); +} +static inline int32_t abs_diff_i32(int32_t a, int32_t b) { + return IF_ELSE((a > b), (a-b), (b-a)); +} +static inline int32_t min_i32(int32_t a, int32_t b) { + return IF_ELSE((a > b), b, a); +} +static inline int32_t max_i32(int32_t a, int32_t b) { + return IF_ELSE((a > b), b, a); +} +static inline int32_t clamp_i32(int32_t x, int32_t lb, int32_t ub) { + return IF_ELSE((x < lb), lb, IF_ELSE((x > ub), ub, x)); +} +static inline int32_t lin_i32(int32_t x, int32_t nom, int32_t den, int32_t c) { + int64_t tmp = ((int64_t)x * nom) / den + c; + return IF_ELSE((tmp < (int64_t)INT32_MAX), (int32_t)tmp, INT32_MAX); +} +static inline int32_t hill_i32(int32_t x, int32_t off, int32_t h, int32_t w) { + return max_i32(ssub_i32(h,ssquare_i32(abs_diff_i32(x,off)/w)),0); +} +static inline int32_t valley_i32(int32_t x, int32_t off, int32_t h, int32_t w) { + return min_i32(sadd_i32(h,ssquare_i32(abs_diff_i32(x,off)/w)),0); +} + +//#define MACRO_ONLY +#ifdef MACRO_ONLY +// macros only increses the code size exponentially + +// Branchless clamps =========== +#define CLAMP_FLOOR(X,LB) ((((X)>(LB))*(X))+(((X)<=(LB))*(LB))) +#define CLAMP_CEILING(X,UB) (((X)>(UB))*(UB)+((X)<=(UB))*(X)) +#define CLAMP(X,LB,UB) CLAMP_CEILING((CLAMP_FLOOR(X,LB)),UB) + +#define SADD(X,Y) IF_ELSE(((int32_t)(Y))<0, IF_ELSE(((int32_t)(X))INT_MAX-((int32_t)(Y)), INT_MAX, ((int32_t)(X))+((int32_t)(Y)))) +#define SSUB(X,Y) IF_ELSE(((int32_t)(Y))<0, IF_ELSE(((int32_t)(X))INT_MIN+((int32_t)(Y)), ((int32_t)(X))-((int32_t)(Y)), INT_MIN)) +#define ABS_DIFF(X,Y) (IF_ELSE(((int32_t)(X)<(int32_t)(Y)),(SSUB(Y,X)),(SSUB(X,Y)))) +#define AVG(X,Y) (((X)/2)+((Y)/2)) +#define SQUARE(X) ((X)*(X)) +#define CHECKED_SQUARE(X) IF_ELSE((X)<=0x0000B504,SQUARE(X), INT_MAX) // int32_t safe + +#define LIN(X,N,D,C) (C+((N)*((X)/(D)))) +#define HILL(X, OFF, H, W) (CLAMP_FLOOR(SSUB(h,CHECKED_SQUARE(ABS_DIFF(x,off)/w)),0)) +#define VALLEY(X, OFF, H, W) (CLAMP_CEILING(SADD(h,CHECKED_SQUARE(ABS_DIFF(x,off)/w)),0)) + +#else + +#define CLAMP_FLOOR(X,LB) max_i32(X, LB) +#define CLAMP_CEILING(X,UB) min_i32(X, UB) +#define CLAMP(X,LB,UB) clamp_i32(X, LB, UB) + +#define SADD(X,Y) sadd_i32(X, Y) +#define SSUB(X,Y) ssub_i32(X, Y) +#define ABS_DIFF(X,Y) abs_diff_i32(X,Y) +#define AVG(X,Y) (((X)/2)+((Y)/2)) +#define SQUARE(X) ((X)*(X)) +#define CHECKED_SQUARE(X) ssquare_i32(X) + +#define LIN(X,N,D,C) lin_i32(X,N,D,C) +#define HILL(X, OFF, H, W) hill_i32(X, OFF, H, W) +#define VALLEY(X, OFF, H, W) valley_i32(X, OFF, H, W) + +#endif + +// Input handling == +#define STRETCH_i32(X) (X<<(8*(sizeof(int32_t)-sizeof(X)))) // stretch any integer to 32 bits +#define JITTER(X, B) (RNG_FROM(X+B)%B) +//#define TRANSLATE_BOUNDS(X, FLB, FUB, TLB, TUB) (CLAMP(X,FLB,FUB)-FLB) / ((FUB-FLB)/(TUB-TLB)) + TLB +#define TRANSLATE_BOUNDS(X, FLB, FUB, TLB, TUB) ( ((CLAMP(X,FLB,FUB)-FLB)*(TUB-TLB)) / ((FUB-FLB)) + TLB ) + +#endif // __UTIL_MACROS_H__ \ No newline at end of file