ih264d: Small optimizations and experiments with multi-threading

Using the multi-threaded decoder doesn't seem to be worth it but at least we have a way to enable it now
This commit is contained in:
Exzap 2023-09-10 08:13:53 +02:00
parent f04c7575d7
commit fda5ec2697
4 changed files with 61 additions and 15 deletions

View file

@ -183,4 +183,10 @@ endif()
if(MSVC)
set_property(TARGET ih264d PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
# tune settings for slightly better performance
target_compile_options(ih264d PRIVATE $<$<CONFIG:Release,RelWithDebInfo>:/Oi>) # enable intrinsic functions
target_compile_options(ih264d PRIVATE $<$<CONFIG:Release,RelWithDebInfo>:/Ot>) # favor speed
target_compile_options(ih264d PRIVATE "/GS-") # disable runtime checks
endif()

View file

@ -85,28 +85,59 @@ UWORD32 ithread_get_mutex_lock_size(void)
return sizeof(CRITICAL_SECTION);
}
struct _ithread_launch_param
{
void (*startFunc)(void* argument);
void* argument;
};
DWORD WINAPI _ithread_WinThreadStartRoutine(LPVOID lpThreadParameter)
{
struct _ithread_launch_param* param = (struct _ithread_launch_param*)lpThreadParameter;
typedef void *(*ThreadStartRoutineType)(void *);
ThreadStartRoutineType pfnThreadRoutine = (ThreadStartRoutineType)param->startFunc;
void* arg = param->argument;
free(param);
pfnThreadRoutine(arg);
return 0;
}
WORD32 ithread_create(void* thread_handle, void* attribute, void* strt, void* argument)
{
//UNUSED(attribute);
//return pthread_create((pthread_t*)thread_handle, NULL, (void* (*)(void*)) strt, argument);
__debugbreak();
UNUSED(attribute);
struct _ithread_launch_param* param = malloc(sizeof(struct _ithread_launch_param));
param->startFunc = (void (*)(void*))strt;
param->argument = argument;
HANDLE *handle = (HANDLE*)thread_handle;
*handle = CreateThread(NULL, 0, _ithread_WinThreadStartRoutine, param, 0, NULL);
if(*handle == NULL)
{
return -1;
}
return 0;
}
WORD32 ithread_join(void* thread_handle, void** val_ptr)
{
//UNUSED(val_ptr);
//pthread_t* pthread_handle = (pthread_t*)thread_handle;
//return pthread_join(*pthread_handle, NULL);
__debugbreak();
return 0;
HANDLE *handle = (HANDLE*)thread_handle;
DWORD result = WaitForSingleObject(*handle, INFINITE);
if(result == WAIT_OBJECT_0)
{
CloseHandle(*handle);
return 0;
}
else
{
return -1;
}
}
WORD32 ithread_get_mutex_struct_size(void)
{
return sizeof(CRITICAL_SECTION);
}
WORD32 ithread_mutex_init(void* mutex)
{
InitializeCriticalSection((LPCRITICAL_SECTION)mutex);
@ -153,7 +184,6 @@ UWORD32 ithread_get_sem_struct_size(void)
//return(sizeof(sem_t));
}
WORD32 ithread_sem_init(void* sem, WORD32 pshared, UWORD32 value)
{
__debugbreak();
@ -168,7 +198,6 @@ WORD32 ithread_sem_post(void* sem)
//return sem_post((sem_t*)sem);
}
WORD32 ithread_sem_wait(void* sem)
{
__debugbreak();
@ -176,7 +205,6 @@ WORD32 ithread_sem_wait(void* sem)
//return sem_wait((sem_t*)sem);
}
WORD32 ithread_sem_destroy(void* sem)
{
__debugbreak();

View file

@ -79,10 +79,8 @@
static inline int __builtin_clz(unsigned x)
{
unsigned long n;
if (x == 0)
return 32;
_BitScanReverse(&n, x);
return 31 - n;
return n ^ 31;
}
static inline int __builtin_ctz(unsigned x) {