main
test-branch
| Line | |
|---|
| 1 | /* Commandline execution:
|
|---|
| 2 | * civl verify duffs.cvl
|
|---|
| 3 | * */
|
|---|
| 4 | #include <civlc.cvh>
|
|---|
| 5 |
|
|---|
| 6 | $input int a[8];
|
|---|
| 7 |
|
|---|
| 8 | // This is Stroustrup's version of Duff's device.
|
|---|
| 9 | void send(int *to, int *from, int count)
|
|---|
| 10 | {
|
|---|
| 11 | int n = (count + 7) / 8;
|
|---|
| 12 | switch(count % 8) {
|
|---|
| 13 | case 0: do { *to++ = *from++;
|
|---|
| 14 | case 7: *to++ = *from++;
|
|---|
| 15 | case 6: *to++ = *from++;
|
|---|
| 16 | case 5: *to++ = *from++;
|
|---|
| 17 | case 4: *to++ = *from++;
|
|---|
| 18 | case 3: *to++ = *from++;
|
|---|
| 19 | case 2: *to++ = *from++;
|
|---|
| 20 | case 1: *to++ = *from++;
|
|---|
| 21 | --n;
|
|---|
| 22 | } while(n > 0);
|
|---|
| 23 | }
|
|---|
| 24 | }
|
|---|
| 25 |
|
|---|
| 26 | void main() {
|
|---|
| 27 | int b[8];
|
|---|
| 28 | send(b, a, 8);
|
|---|
| 29 | for (int i = 0; i < 8; i++) {
|
|---|
| 30 | $assert(a[i] == b[i]);
|
|---|
| 31 | }
|
|---|
| 32 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.