Commit 8060a9fb221a919f024a6fadc1fd4bdaa1adfc7a
1 parent
010ee26a
This is the complement for the previous revision. This one should be running
Showing
1 changed file
with
18 additions
and
28 deletions
Show diff stats
anubis_dev/compiler/src/vminstr.c
| ... | ... | @@ -343,15 +343,18 @@ int instruction_size(Expr instr, int offset) |
| 343 | 343 | case load_int_big: /* (load_int_big 256-bigit ... 256-bigit) */ |
| 344 | 344 | case load_int_big_push: |
| 345 | 345 | { |
| 346 | + /* This instruction stored as follows: | |
| 347 | + instruction: 1 byte | |
| 348 | + number of bigits: 4 bytes | |
| 349 | + bigits: 4*(number of 2^32-bigits) bytes | |
| 350 | + ------------------------------------------------------------ | |
| 351 | + total: 5 + 4*(number of 2^32-bigits) bytes | |
| 352 | + | |
| 353 | + The number of 2^32-bigits is 4 times the number of 256-bigits. | |
| 354 | + */ | |
| 346 | 355 | U32 n = length(cdr(instr)); /* number of 256-bigits */ |
| 347 | 356 | while (n&3) n++; /* compute number of bytes in 2^32-bigits */ |
| 348 | - return 13 + n; /* 1 instruction | |
| 349 | - 1 number of alignment bytes before the number | |
| 350 | - 3 alignment bytes (total is always 3) | |
| 351 | - 4 counter (= 0, i.e. permanent datum) | |
| 352 | - 4 number of 2^32-bigits | |
| 353 | - n number of bytes in 2^32-bigits | |
| 354 | - total: 13 + n */ | |
| 357 | + return 5 + n; | |
| 355 | 358 | } |
| 356 | 359 | |
| 357 | 360 | case type_mixed_switch: |
| ... | ... | @@ -477,7 +480,7 @@ int instruction_size(Expr instr, int offset) |
| 477 | 480 | |
| 478 | 481 | /* system calls */ |
| 479 | 482 | |
| 480 | -#define sc_item(n,f) case n: | |
| 483 | +#define sc_item(n,a,f) case n: | |
| 481 | 484 | syscall_list |
| 482 | 485 | #undef sc_item |
| 483 | 486 | return 1+2; /* 'syscall' byte + index of function (2 bytes) */ |
| ... | ... | @@ -1616,29 +1619,19 @@ void translate_instruction(U8 *code_addr, |
| 1616 | 1619 | case load_int_big_push: |
| 1617 | 1620 | { |
| 1618 | 1621 | Expr aux; |
| 1619 | - Expr bigits256 = cdr(instr); | |
| 1620 | - int n = length(bigits256); | |
| 1621 | - U32 dec; | |
| 1622 | + Expr bigits256 = cdr(instr); // the bigits in basis 256 | |
| 1623 | + int n = length(bigits256); // the number of bigits in basis 256s | |
| 1622 | 1624 | |
| 1623 | 1625 | /* add nul bigits, so as to have a number of bigits (in basis 256) divisible by 4 */ |
| 1624 | 1626 | while (n&3) { n++; bigits256 = cons(new_integer(0),bigits256); } |
| 1625 | 1627 | |
| 1626 | - /* the instruction */ | |
| 1628 | + /* put the instruction */ | |
| 1627 | 1629 | *((*ptr)++) = car(instr) == load_int_big ? i_load_int_big : i_load_int_big_push; |
| 1628 | - /* compute the number of alignment bytes */ | |
| 1629 | - dec = ((((U32)(*ptr))+1)&3) ? 4-((((U32)(*ptr))+1)&3) : 0; /* number of alignment bytes */ | |
| 1630 | - //dec = ((((U32)(*ptr)))&3) ? 4-((((U32)(*ptr)))&3) : 0; /* number of alignment bytes */ | |
| 1631 | - /* store the number of alignment bytes */ | |
| 1632 | - *((*ptr)++) = dec; | |
| 1633 | - /* write the alignment bytes */ | |
| 1634 | - for (i = 0; i < dec; i++) *((*ptr)++) = 0; | |
| 1635 | - | |
| 1636 | - /* put the counter (aligned on 0 mod 4) */ | |
| 1637 | - *(((U32 *)(*ptr))) = 0; /* counter = 0 for permanent datum */ | |
| 1638 | - *ptr += sizeof(U32); | |
| 1639 | - /* and the number of bigits (in basis 2^32) */ | |
| 1630 | + | |
| 1631 | + /* put the number of bigits (in basis 2^32) */ | |
| 1640 | 1632 | *(((U32 *)(*ptr))) = n>>2; /* number of bigits (bytes/4) */ |
| 1641 | 1633 | *ptr += sizeof(U32); |
| 1634 | + | |
| 1642 | 1635 | /* put the bigits (most significant first) */ |
| 1643 | 1636 | while(consp(bigits256)) |
| 1644 | 1637 | { |
| ... | ... | @@ -1647,9 +1640,6 @@ void translate_instruction(U8 *code_addr, |
| 1647 | 1640 | *(((U32 *)(*ptr))) = word32_value(aux); |
| 1648 | 1641 | *ptr += sizeof(U32); |
| 1649 | 1642 | } |
| 1650 | - | |
| 1651 | - /* write remaining alignement bytes (total is always 3) */ | |
| 1652 | - for (i = 0; i < 3 - dec; i++) *((*ptr)++) = 0; /* write the alignment bytes */ | |
| 1653 | 1643 | } |
| 1654 | 1644 | break; |
| 1655 | 1645 | |
| ... | ... | @@ -1968,7 +1958,7 @@ void translate_instruction(U8 *code_addr, |
| 1968 | 1958 | /* system calls */ |
| 1969 | 1959 | |
| 1970 | 1960 | |
| 1971 | -#define sc_item(n,f) case n: *module_flags |= f; \ | |
| 1961 | +#define sc_item(n,a,f) case n: *module_flags |= f; \ | |
| 1972 | 1962 | *((*ptr)++) = i_syscall; *(((U16 *)(*ptr))) = sc_##n; *ptr += sizeof(U16); break; |
| 1973 | 1963 | syscall_list |
| 1974 | 1964 | #undef sc_item | ... | ... |