Last change
on this file since 775 was
536,
checked in by meunier, 11 years ago
|
Added a tool which generates tests for the LL/SC table, in the soft/ directory.
|
File size:
837 bytes
|
Rev | Line | |
---|
[536] | 1 | |
---|
| 2 | #ifndef _functions_h_ |
---|
| 3 | #define _functions_h_ |
---|
| 4 | |
---|
| 5 | #include <math.h> |
---|
| 6 | #include <stdlib.h> |
---|
| 7 | #include <stdio.h> |
---|
| 8 | |
---|
| 9 | static int mylog2(size_t v) { |
---|
| 10 | static const size_t b[] = { 0x2, 0xC, 0xF0, 0xFF00, 0xFFFF0000 }; |
---|
| 11 | static const size_t S[] = { 1, 2, 4, 8, 16 }; |
---|
| 12 | int i; |
---|
| 13 | register size_t r = 0; |
---|
| 14 | for (i = 4; i >= 0; i--) { |
---|
| 15 | if (v & b[i]) { |
---|
| 16 | v >>= S[i]; |
---|
| 17 | r |= S[i]; |
---|
| 18 | } |
---|
| 19 | } |
---|
| 20 | return r + 1; |
---|
| 21 | } |
---|
| 22 | |
---|
| 23 | /*int randint(int a,int b){ |
---|
| 24 | int range = b - a + 1; |
---|
| 25 | int length = (int) ceil(log2(range)); |
---|
| 26 | int mask = (int) pow(2,length) - 1; |
---|
| 27 | printf("mask : %d\n",mask); |
---|
| 28 | int res; |
---|
| 29 | do { |
---|
| 30 | res = rand() & mask; |
---|
| 31 | } |
---|
| 32 | while (res >= range); |
---|
| 33 | return (res + a); |
---|
| 34 | }*/ |
---|
| 35 | |
---|
| 36 | int randint(int a, int b){ |
---|
| 37 | int range = b - a + 1; |
---|
| 38 | int res = rand() % range; |
---|
| 39 | return res + a; |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | |
---|
| 43 | #endif |
---|
Note: See
TracBrowser
for help on using the repository browser.