-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add forgotten file & improve README.md
- Loading branch information
Henri-Pierre CHARLES
authored and
Henri-Pierre CHARLES
committed
Dec 5, 2023
1 parent
7025b8b
commit 653c6a6
Showing
7 changed files
with
112 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// -*- c -*- | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
typedef int (*pifii)(int, int); | ||
|
||
/* C compilette prototype */ | ||
h2_insn_t * genPlusOrMul(h2_insn_t * ptr) | ||
{ | ||
#[ | ||
int 32 1 PlusOrMul(int 32 1 plus, int 32 1 LoopValue) | ||
{ | ||
int 32 1 tmp, i, reste; | ||
|
||
tmp = 1; // 1 = loop with addition, multiplication otherwise | ||
if (plus == tmp) | ||
{ | ||
tmp = 1; | ||
for (i = 1; i <= LoopValue; i = i + 1) | ||
{ | ||
tmp = tmp * i; | ||
} | ||
} | ||
else | ||
{ | ||
tmp = 0; | ||
for (i = 1; i <= LoopValue; i = i + 1) | ||
{ | ||
tmp = tmp + i; | ||
} | ||
|
||
} | ||
return tmp; | ||
} | ||
]# | ||
return (h2_insn_t *)ptr; | ||
} | ||
|
||
|
||
int main(int argc, char * argv[]) | ||
{ | ||
h2_insn_t * ptr; | ||
int plus, loopValue, res; | ||
int i, tmp; | ||
pifii iPtr; | ||
|
||
if (argc < 2) | ||
{ | ||
printf("Give 2 values (Plus LoopValue)\n"); | ||
exit(-1); | ||
} | ||
plus = atoi (argv[1]); // Get operator + = 1, other = * | ||
loopValue = atoi (argv[2]); // Get threshold value | ||
ptr = h2_malloc (1024); // Allocate memory for 1024 instructions | ||
iPtr = (pifii) genPlusOrMul(ptr); // Generate instructions | ||
res = iPtr(plus, loopValue); // Call generated code | ||
if (plus == 1) | ||
for (tmp = 1, i = 1; i <= loopValue; i = i + 1) | ||
{ | ||
tmp *= i; | ||
} | ||
else | ||
for (tmp = 0, i = 1; i <= loopValue; i = i + 1) | ||
{ | ||
tmp += i; | ||
} | ||
printf ("Result plus = %d, loopValue %d : %d (%d)\n", plus, loopValue, res, tmp); | ||
return tmp != res; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters