Add print statements to ranpi.c
MODIFY
test/riscv-tests/ranpi.c
test/riscv-tests/ranpi.c
* - Moves computation result to register x27
*/
+void printFloat(float value) {
+ asm("mv a0, %[v]\n"
+ "li a7, 2\n"
+ "ecall"
+ :
+ : [v]"r"(value)
+ :
+ );
+}
+
+void printInt(int value) {
+ asm("mv a0, %[v]\n"
+ "li a7, 1\n"
+ "ecall"
+ :
+ : [v]"r"(value)
+ :
+ );
+}
+
+void printString(void* str) {
+ asm("mv a0, %[v]\n"
+ "li a7, 4\n"
+ "ecall"
+ :
+ : [v]"r"(str)
+ :
+ );
+}
+
+void printStringFloat(void* str, float f){
+ printString(str);
+ printFloat(f);
+ printString("\n");
+}
+
+void printStringInt(void* str, int i){
+ printString(str);
+ printInt(i);
+ printString("\n");
+}
+
void myadd(float* sum, float* addend) {
/*
c Simple adding subroutine thrown in to allow subroutine
@@ -25,6 +67,8 @@ int main(int argc, char* argv[]) {
float ztot, yran, ymult, ymod, x, y, z, pi, prod;
long int low, ixran, itot, j, iprod;
+ printString("Running RanPI...\n");
+
ztot = 0.0;
low = 1;
ixran = 1907;
@@ -42,7 +86,9 @@ int main(int argc, char* argv[]) {
c integer overflow and to allow full precision even with a 23-bit
c mantissa.
*/
-
+ printString("\tIteration: ");
+ printInt(j);
+ printString("\n");
iprod = 27611 * ixran;
ixran = iprod - 74383 * (long int)(iprod / 74383);
x = (float)ixran / 74383.0;
@@ -55,8 +101,13 @@ int main(int argc, char* argv[]) {
low = low + 1;
}
}
+
pi = 4.0 * (float)low / (float)itot;
+ // Print result
+ printString("Result: ");
+ printFloat(pi);
+
// Move result to some pre-determined register
asm("mv x27, %[v]"
: /* Output registers */

Add print statements to ranpi.c