diff example/renew_task/spe/SpeProfile.cc @ 192:4f5c64e713c7

add example/renew_task
author gongo@localhost.localdomain
date Tue, 13 Jan 2009 10:41:05 +0900
parents
children 58fd16298954
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/renew_task/spe/SpeProfile.cc	Tue Jan 13 10:41:05 2009 +0900
@@ -0,0 +1,35 @@
+/**
+ * SPU Decrementerを用いた処理時間計測
+ */
+
+#include "SpeProfile.h"
+/* DMA転送に関する関数を使用するために必要なインクルードファイル */
+#include <spu_intrinsics.h>
+#include <stdio.h>
+
+/* SPU Decrementerの初期値 */
+#define SPU_DECREMENTER_INITIAL_VALUE 0x7FFFFFFFU
+
+SpeProfile::SpeProfile(void): profile(0) {}
+
+void SpeProfile::ProfStart(void)
+{
+    /* SPU Decrementerに初期値を設定 */
+    spu_writech(SPU_WrDec, SPU_DECREMENTER_INITIAL_VALUE);
+
+    /* 計測開始時間をSPU Decrementerから読み取る */
+    profile = spu_readch(SPU_RdDec);    
+}
+
+void SpeProfile::ProfStop(void)
+{
+    /* 計測終了時間をSPU Decrementerから読み取り, 計測開始時間との差を計算 */
+    profile -= spu_readch(SPU_RdDec);    
+}
+
+void SpeProfile::ProfPrint(void)
+{
+    /* 処理時間を出力 */
+    printf("SPE time by SPU Decrementer: %f\n",
+	   profile / 79800000.0f * 1000.0f);
+}