Use @llvm.readcyclecounter to implement stdlib clock() function.

Also added a test for the clock builtin.
This commit is contained in:
Matt Pharr
2013-07-23 17:11:01 -07:00
parent c14659c675
commit 15a3ef370a
2 changed files with 18 additions and 10 deletions

View File

@@ -2891,17 +2891,11 @@ m4exit(`1')
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; read hw clock
declare i64 @llvm.readcyclecounter()
define i64 @__clock() nounwind {
entry:
tail call void asm sideeffect "xorl %eax,%eax \0A cpuid", "~{rax},~{rbx},~{rcx},~{rdx},~{dirflag},~{fpsr},~{flags}"() nounwind
%0 = tail call { i32, i32 } asm sideeffect "rdtsc", "={ax},={dx},~{dirflag},~{fpsr},~{flags}"() nounwind
%asmresult = extractvalue { i32, i32 } %0, 0
%asmresult1 = extractvalue { i32, i32 } %0, 1
%conv = zext i32 %asmresult1 to i64
%shl = shl nuw i64 %conv, 32
%conv2 = zext i32 %asmresult to i64
%or = or i64 %shl, %conv2
ret i64 %or
%r = call i64 @llvm.readcyclecounter()
ret i64 %r
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

14
tests/clock.ispc Normal file
View File

@@ -0,0 +1,14 @@
export uniform int width() { return programCount; }
export void f_f(uniform float RET[], uniform float aFOO[]) {
unsigned uniform int64 a = clock();
float x = pow(sqrt(aFOO[programIndex]), 5.5);
unsigned uniform int64 b = clock();
RET[programIndex] = (b - a) > 0 ? 1 : 0;
}
export void result(uniform float RET[]) {
RET[programIndex] = 1;
}