From fe519a93f2638c01662b48aa7f25fcbebf19c544 Mon Sep 17 00:00:00 2001 From: ppodds Date: Fri, 31 Dec 2021 03:16:46 +0800 Subject: [PATCH] Fix: enable O2 when building solution cause the do-nothing loop be optimized --- AAAAnimation/AAAAnimation.vcxproj | 2 ++ AAAAnimation/AAAAnimation.vcxproj.filters | 6 ++++++ AAAAnimation/player/ascii_player_thread.cpp | 3 ++- AAAAnimation/utils.asm | 20 ++++++++++++++++++++ AAAAnimation/utils.h | 3 +++ 5 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 AAAAnimation/utils.asm create mode 100644 AAAAnimation/utils.h diff --git a/AAAAnimation/AAAAnimation.vcxproj b/AAAAnimation/AAAAnimation.vcxproj index 677b4e0..0e5029a 100644 --- a/AAAAnimation/AAAAnimation.vcxproj +++ b/AAAAnimation/AAAAnimation.vcxproj @@ -119,6 +119,7 @@ + Document @@ -128,6 +129,7 @@ + diff --git a/AAAAnimation/AAAAnimation.vcxproj.filters b/AAAAnimation/AAAAnimation.vcxproj.filters index c4a6cbe..55e1102 100644 --- a/AAAAnimation/AAAAnimation.vcxproj.filters +++ b/AAAAnimation/AAAAnimation.vcxproj.filters @@ -57,11 +57,17 @@ Source Files + + Header Files + Source Files + + Source Files + diff --git a/AAAAnimation/player/ascii_player_thread.cpp b/AAAAnimation/player/ascii_player_thread.cpp index d01ca5c..6754c51 100644 --- a/AAAAnimation/player/ascii_player_thread.cpp +++ b/AAAAnimation/player/ascii_player_thread.cpp @@ -3,6 +3,7 @@ #include "../ffmpeg/video_decoder.h" #include "../console/console_controller.h" #include "../transform.h" +#include "../utils.h" #include AsciiPlayerThread::AsciiPlayerThread() @@ -41,7 +42,7 @@ void AsciiPlayerThread::run() transform(frame->data[0], arr, width, height, frame->linesize[0]); // check time again // wait until the proper time and play this frame - while (play_time - 150 > position); // 150ms offset to avoid drop too many frames + wait_until_smaller(play_time - 150, &position); // 150ms offset to avoid drop too many frames std::cout << arr; console_controller.top(); } diff --git a/AAAAnimation/utils.asm b/AAAAnimation/utils.asm new file mode 100644 index 0000000..9a1b7a2 --- /dev/null +++ b/AAAAnimation/utils.asm @@ -0,0 +1,20 @@ +wait_until_smaller PROTO +; arguments +; xmm0: REAL4 a REAL4 variable need to be compared +; rdx: SQWORD PTR a SQWORD pointer which value be pointed would increase +; this procedure would block the thread until the condition is fulfilled +; Caution: it may cause the thread is blocked by a infinite loop +.CODE +wait_until_smaller PROC + push rbp + mov rbp, rsp +compare: + cvtsi2ss xmm1, SQWORD PTR [rdx] ; convert rdx to REAL4 type and store it in xmm1 + comiss xmm0,xmm1 ; compare xmm0 with xmm1 + jbe fufilled ; jump to fufilled if xmm0 <= xmm1 + jmp compare ; jump to compare if xmm0 > xmm1 +fufilled: + leave + ret +wait_until_smaller ENDP +END \ No newline at end of file diff --git a/AAAAnimation/utils.h b/AAAAnimation/utils.h new file mode 100644 index 0000000..9ffb53c --- /dev/null +++ b/AAAAnimation/utils.h @@ -0,0 +1,3 @@ +#pragma once +#include +extern "C" void wait_until_smaller(float, qint64*); \ No newline at end of file