umx

UMX VM implementation (ifcfc '06)
git clone git://bsandro.tech/umx
Log | Files | Refs

commit 124203be25137f81cf9ee460ef7b2e44281750ac
Author: bsandro <brian.drosan@gmail.com>
Date:   Sun,  9 Jan 2022 22:06:15 +0200

reset author

Diffstat:
ACODEX.UMZ | 0
ADECR_KEY.TXT | 1+
AICFPC06/._codex.umz | 0
AICFPC06/._sandmark.umz | 0
AICFPC06/CODEX.UMZ | 0
AICFPC06/SANDMARK.UMZ | 0
ASANDMARK.UMZ | 0
Acarb.r | 2++
Amain.c | 2++
Asandmark-output.txt | 123+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aumx | 0
11 files changed, 128 insertions(+), 0 deletions(-)

diff --git a/CODEX.UMZ b/CODEX.UMZ Binary files differ. diff --git a/DECR_KEY.TXT b/DECR_KEY.TXT @@ -0,0 +1 @@ +(\b.bb)(\v.vv)06FHPVboundvarHRAk diff --git a/ICFPC06/._codex.umz b/ICFPC06/._codex.umz Binary files differ. diff --git a/ICFPC06/._sandmark.umz b/ICFPC06/._sandmark.umz Binary files differ. diff --git a/ICFPC06/CODEX.UMZ b/ICFPC06/CODEX.UMZ Binary files differ. diff --git a/ICFPC06/SANDMARK.UMZ b/ICFPC06/SANDMARK.UMZ Binary files differ. diff --git a/SANDMARK.UMZ b/SANDMARK.UMZ Binary files differ. diff --git a/carb.r b/carb.r @@ -0,0 +1 @@ +/* * Permit this Carbon application to launch on OS X * * Copyright © 1997-2002 Metrowerks Corporation. All Rights Reserved. * * Questions and comments to: * <mailto:support@metrowerks.com> * <http://www.metrowerks.com/> *//*----------------------------carb ¥ Carbon on OS X launch information --------------------------*/type 'carb' {};resource 'carb'(0) {}; +\ No newline at end of file diff --git a/main.c b/main.c @@ -0,0 +1 @@ +#pragma gcc_extensions on #include <stdio.h>#include <assert.h>#include <stdint.h>#include <stdlib.h>#include <sys/stat.h>#define FILENAME ":um.um"#define PLATTER_SIZE 4struct array_t { uint32_t *data; size_t size;};struct arena_t { struct array_t *arrays; uint32_t size;};struct state_t { struct arena_t arena; uint32_t registers[8];};enum opcode_t { CMOV = 0, ARRI = 1, ARRA = 2, ADD = 3, MUL = 4, DIV = 5, NOTA = 6, HALT = 7, ALLO = 8, ABAN = 9, OUTP = 10, INP = 11, LOAD = 12, ORTH = 13};struct instruction_t { enum opcode_t opcode; uint8_t reg_a, reg_b, reg_c; uint32_t value;};char * int2bin(uint32_t num);void print_instruction(struct instruction_t instruction);void exec_instruction(struct state_t *state, struct instruction_t in);uint32_t array_add(struct arena_t *arena, uint32_t size);int main(void){ FILE *f = fopen(FILENAME, "r"); uint32_t finger = 0; struct stat fileinfo; size_t read_platters = 0; struct state_t state = {0}; state.arena.arrays = NULL; state.arena.size = 0; assert(f != NULL); stat(FILENAME, &fileinfo); assert(fileinfo.st_size % PLATTER_SIZE == 0); printf("%s (%lu bytes):\n", FILENAME, fileinfo.st_size); array_add(&state.arena, fileinfo.st_size); // Initial array #0 read_platters = fread(state.arena.arrays[0].data, PLATTER_SIZE, fileinfo.st_size / PLATTER_SIZE, f); assert(fileinfo.st_size == read_platters * PLATTER_SIZE); printf("read ok, %lu platters (%lu bytes)\n", read_platters, state.arena.arrays[0].size); while (1) { uint32_t platter; struct instruction_t instruction = {0}; platter = state.arena.arrays[0].data[finger]; instruction.opcode = platter >> 28; if (instruction.opcode == ORTH) { instruction.reg_a = ((platter >> 25) & 7); instruction.value = platter & 0x1FFFFFF; } else { instruction.reg_a = (platter & 448) >> 6; // mask 111 000 000 = 448 instruction.reg_b = (platter & 56) >> 3; // mask 000 111 000 = 56 instruction.reg_c = platter & 7; // mask 000 000 111 = 7 } print_instruction(instruction); exec_instruction(&state, instruction); finger++; if (finger >= state.arena.arrays[0].size / PLATTER_SIZE) { break; } } fclose(f); //getchar(); // in case SIOUX starts closing the window after exec again return 0;}char * int2bin(uint32_t num) { static char str[33] = {'\0'}; int cnt = 0; uint32_t i; for (i = 1 << 31; i > 0; i >>= 1) { str[cnt++] = ((num & i) == i) ? '1' : '0'; assert(cnt < 34); } str[32] = '\0'; return str;}void print_instruction(struct instruction_t instruction) { printf("%2d: A:%d B:%d C:%d\n value:%lu", instruction.opcode, instruction.reg_a, instruction.reg_b, instruction.reg_c, instruction.value);}void exec_instruction(struct state_t *state, struct instruction_t in) { }uint32_t array_add(struct arena_t *arena, uint32_t size) { uint32_t array_index = arena->size++; assert(size != NULL); arena->arrays = (struct array_t *)realloc(arena->arrays, arena->size * sizeof(struct array_t)); arena->arrays[array_index].data = (uint32_t *)malloc(size); arena->arrays[array_index].size = size; assert(arena->arrays[array_index].data != NULL); return array_index;} +\ No newline at end of file diff --git a/sandmark-output.txt b/sandmark-output.txt @@ -0,0 +1,123 @@ +trying to Allocate array of size 0.. +trying to Abandon size 0 allocation.. +trying to Allocate size 11.. +trying Array Index on allocated array.. +trying Amendment of allocated array.. +checking Amendment of allocated array.. +trying Alloc(a,a) and amending it.. +comparing multiple allocations.. +pointer arithmetic.. +check old allocation.. +simple tests ok! +about to load program from some allocated array.. +success. +verifying that the array and its copy are the same... +success. +testing aliasing.. +success. +free after loadprog.. +success. +loadprog ok. + == SANDmark 19106 beginning stress test / benchmark.. == +100. 12345678.09abcdef +99. 6d58165c.2948d58d +98. 0f63b9ed.1d9c4076 +97. 8dba0fc0.64af8685 +96. 583e02ae.490775c0 +95. 0353a77b.2f02685c +94. aa25a8d7.51cb07e5 +93. e13149f5.53a9ae5d +92. abbbd460.86cf279c +91. 2c25e8d8.a71883a9 +90. dccf7b71.475e0715 +89. 49b398a7.f293a13d +88. 9116f443.2d29be37 +87. 5c79ba31.71e7e592 +86. 19537c73.0797380a +85. f46a7339.fe37b85a +84. 99c71532.729e2864 +83. f3455289.b84ced3d +82. c90c81a9.b66fcd61 +81. 087e9eef.fc1c13a6 +80. e933e2f5.3567082f +79. 25af849e.16290d7b +78. 57af9504.c76e7ded +77. 68cf6c69.6055d00c +76. 8e920fbd.02369722 +75. eb06e2de.03c46fda +74. f9c40240.f1290b2a +73. 7f484f97.bc15610b +72. 1dabb00e.61e7b75b +71. dceb40f5.207a75ca +70. c3ed44f5.db631e81 +69. b7addb67.90460bf5 +68. ae710a90.04b433ef +67. 9ca2d5f0.05d3b631 +66. 4f38abe0.4287cc05 +65. 10d8691d.a5c934f8 +64. 27c68255.52881eaa +63. a0695283.110266b7 +62. 336aa5dd.57287a9b +61. b04fe494.d741ddbd +60. 2baf3654.9e33305a +59. fd82095d.683efb19 +58. d0bac37f.badff9d7 +57. 3be33fcc.d76b127e +56. 7f964f18.8b118ee1 +55. 37aeddc8.26a8f840 +54. d71d55ff.6994c78f +53. bf175396.f960cc54 +52. f6c9d8e1.44b81fd5 +51. 6a9b4d86.fe7c66cb +50. 06bceb64.d5106aad +49. 237183b6.49c15b01 +48. 4ec10756.6936136f +47. 9d1855a7.1e929fe8 +46. a641ede3.36bff422 +45. 7bbf5ad4.dd129538 +44. 732b385e.39fadce7 +43. b7f50285.e7f54c39 +42. 42e3754c.da741dc1 +41. 5dc42265.928ea0bb +40. 623fb352.3f25bc5b +39. 491f33d9.409bca87 +38. f0943bc7.89f512be +37. 80cdbc9d.8ad93517 +36. c1a8da99.32d37f3f +35. 91a0b15c.6df2cf4e +34. 50cf7a7a.f0466dc8 +33. 02df4c13.14eb615d +32. 2963bf25.d9f06dfe +31. c493d2db.f39ce804 +30. 3b6e5a8e.5cf63bd7 +29. 4c5c2fbe.8d881c00 +28. 9b7354a6.81181438 +27. ae0fe8c6.ec436274 +26. e786b98d.f5a4111d +25. a7719df1.d989d0b6 +24. beb9ebc0.6c56750d +23. edf41fcb.e4cba003 +22. 97268c46.713025f1 +21. deb087db.1349eb6a +20. fc5221f0.3b4241bf +19. 3fa4370d.8fa16752 +18. 044af7de.87b44b11 +17. 2e86e437.c4cdbc54 +16. fd7cd8aa.63b6ca23 +15. 631ceaad.e093a9d5 +14. 01ca9732.52962532 +13. 86d8bcf5.45bdf474 +12. 8d07855b.0224e80f +11. 0f9d2bee.94d86c38 +10. 5e6a685d.26597494 +9. 24825ea1.72008775 +8. 73f9c0b5.1480e7a3 +7. a30735ec.a49b5dad +6. a7b6666b.509e5338 +5. d0e8236e.8b0e9826 +4. 4d20f3ac.a25d05a8 +3. 7c7394b2.476c1ee5 +2. f3a52453.19cc755d +1. 2c80b43d.5646302f +0. a8d1619e.5540e6cf +SANDmark complete. diff --git a/umx b/umx Binary files differ.