From de8a15e9f0070a445c9627da4da22f4fc37782de Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Tue, 17 Nov 2020 18:24:38 -0800 Subject: 7262 --- html/310copy-bytes.subx.html | 311 ++++++++++++++++++++++--------------------- 1 file changed, 156 insertions(+), 155 deletions(-) (limited to 'html/310copy-bytes.subx.html') diff --git a/html/310copy-bytes.subx.html b/html/310copy-bytes.subx.html index 4290fcba..26f10708 100644 --- a/html/310copy-bytes.subx.html +++ b/html/310copy-bytes.subx.html @@ -56,162 +56,163 @@ if ('onhashchange' in window) { https://github.com/akkartik/mu/blob/master/310copy-bytes.subx
-  1 # Fill a region of memory with zeroes.
-  2 
-  3 == code
-  4 
-  5 copy-bytes:  # src: (addr byte), dest: (addr byte), size: int
-  6     # pseudocode:
-  7     #   curr-src/esi = src
-  8     #   curr-dest/edi = dest
-  9     #   i/ecx = 0
- 10     #   while true
- 11     #     if (i >= size) break
- 12     #     *curr-dest = *curr-src
- 13     #     ++curr-src
- 14     #     ++curr-dest
- 15     #     ++i
- 16     #
- 17     # . prologue
- 18     55/push-ebp
- 19     89/<- %ebp 4/r32/esp
- 20     # . save registers
- 21     50/push-eax
- 22     51/push-ecx
- 23     52/push-edx
- 24     56/push-esi
- 25     57/push-edi
- 26     # curr-src/esi = src
- 27     8b/-> *(ebp+8) 6/r32/esi
- 28     # curr-dest/edi = dest
- 29     8b/-> *(ebp+0xc) 7/r32/edi
- 30     # var i/ecx: int = 0
- 31     b9/copy-to-ecx 0/imm32
- 32     # edx = size
- 33     8b/-> *(ebp+0x10) 2/r32/edx
- 34     {
- 35       # if (i >= size) break
- 36       39/compare %ecx 2/r32/edx
- 37       7d/jump-if->=  break/disp8
- 38       # *curr-dest = *curr-src
- 39       8a/byte-> *esi 0/r32/AL
- 40       88/byte<- *edi 0/r32/AL
- 41       # update
- 42       46/increment-esi
- 43       47/increment-edi
- 44       41/increment-ecx
- 45       eb/jump loop/disp8
- 46     }
- 47 $copy-bytes:end:
- 48     # . restore registers
- 49     5f/pop-to-edi
- 50     5e/pop-to-esi
- 51     5a/pop-to-edx
- 52     59/pop-to-ecx
- 53     58/pop-to-eax
- 54     # . epilogue
- 55     89/<- %esp 5/r32/ebp
- 56     5d/pop-to-ebp
- 57     c3/return
- 58 
- 59 stream-to-array:  # in: (addr stream _), out: (addr handle array _)
- 60     # . prologue
- 61     55/push-ebp
- 62     89/<- %ebp 4/r32/esp
- 63     # . save registers
- 64     50/push-eax
- 65     51/push-ecx
- 66     52/push-edx
- 67     56/push-esi
- 68     # esi = s
- 69     8b/-> *(ebp+8) 6/r32/esi
- 70     # var len/ecx: int = s->write - s->read
- 71     8b/-> *esi 1/r32/ecx
- 72     2b/subtract *(esi+4) 1/r32/ecx
- 73     # allocate
- 74     (allocate-array Heap %ecx *(ebp+0xc))
- 75     # var in/edx: (addr byte) = s->data + s->read
- 76     8b/-> *(esi+4) 2/r32/edx
- 77     8d/copy-address *(esi+edx+0xc) 2/r32/edx
- 78     # var dest/eax: (addr byte) = data for out
- 79     8b/-> *(ebp+0xc) 0/r32/eax
- 80     (lookup *eax *(eax+4))  # => eax
- 81     8d/copy-address *(eax+4) 0/r32/eax
- 82     #
- 83     (copy-bytes %edx %eax %ecx)
- 84 $stream-to-array:end:
- 85     # . restore registers
- 86     5e/pop-to-esi
- 87     5a/pop-to-edx
- 88     59/pop-to-ecx
- 89     58/pop-to-eax
- 90     # . epilogue
- 91     89/<- %esp 5/r32/ebp
- 92     5d/pop-to-ebp
- 93     c3/return
- 94 
- 95 test-stream-to-array:
- 96     # . prologue
- 97     55/push-ebp
- 98     89/<- %ebp 4/r32/esp
- 99     # setup
-100     (clear-stream _test-input-stream)
-101     (write _test-input-stream "abc")
-102     # skip something
-103     (read-byte _test-input-stream)  # => eax
-104     # var out/ecx: (handle array byte)
-105     68/push 0/imm32
+  1 # Some helpers for copying non-overlapping regions of memory.
+  2 # Really only intended to be called from code generated by mu.subx.
+  3 
+  4 == code
+  5 
+  6 copy-bytes:  # src: (addr byte), dest: (addr byte), size: int
+  7     # pseudocode:
+  8     #   curr-src/esi = src
+  9     #   curr-dest/edi = dest
+ 10     #   i/ecx = 0
+ 11     #   while true
+ 12     #     if (i >= size) break
+ 13     #     *curr-dest = *curr-src
+ 14     #     ++curr-src
+ 15     #     ++curr-dest
+ 16     #     ++i
+ 17     #
+ 18     # . prologue
+ 19     55/push-ebp
+ 20     89/<- %ebp 4/r32/esp
+ 21     # . save registers
+ 22     50/push-eax
+ 23     51/push-ecx
+ 24     52/push-edx
+ 25     56/push-esi
+ 26     57/push-edi
+ 27     # curr-src/esi = src
+ 28     8b/-> *(ebp+8) 6/r32/esi
+ 29     # curr-dest/edi = dest
+ 30     8b/-> *(ebp+0xc) 7/r32/edi
+ 31     # var i/ecx: int = 0
+ 32     b9/copy-to-ecx 0/imm32
+ 33     # edx = size
+ 34     8b/-> *(ebp+0x10) 2/r32/edx
+ 35     {
+ 36       # if (i >= size) break
+ 37       39/compare %ecx 2/r32/edx
+ 38       7d/jump-if->=  break/disp8
+ 39       # *curr-dest = *curr-src
+ 40       8a/byte-> *esi 0/r32/AL
+ 41       88/byte<- *edi 0/r32/AL
+ 42       # update
+ 43       46/increment-esi
+ 44       47/increment-edi
+ 45       41/increment-ecx
+ 46       eb/jump loop/disp8
+ 47     }
+ 48 $copy-bytes:end:
+ 49     # . restore registers
+ 50     5f/pop-to-edi
+ 51     5e/pop-to-esi
+ 52     5a/pop-to-edx
+ 53     59/pop-to-ecx
+ 54     58/pop-to-eax
+ 55     # . epilogue
+ 56     89/<- %esp 5/r32/ebp
+ 57     5d/pop-to-ebp
+ 58     c3/return
+ 59 
+ 60 stream-to-array:  # in: (addr stream _), out: (addr handle array _)
+ 61     # . prologue
+ 62     55/push-ebp
+ 63     89/<- %ebp 4/r32/esp
+ 64     # . save registers
+ 65     50/push-eax
+ 66     51/push-ecx
+ 67     52/push-edx
+ 68     56/push-esi
+ 69     # esi = s
+ 70     8b/-> *(ebp+8) 6/r32/esi
+ 71     # var len/ecx: int = s->write - s->read
+ 72     8b/-> *esi 1/r32/ecx
+ 73     2b/subtract *(esi+4) 1/r32/ecx
+ 74     # allocate
+ 75     (allocate-array Heap %ecx *(ebp+0xc))
+ 76     # var in/edx: (addr byte) = s->data + s->read
+ 77     8b/-> *(esi+4) 2/r32/edx
+ 78     8d/copy-address *(esi+edx+0xc) 2/r32/edx
+ 79     # var dest/eax: (addr byte) = data for out
+ 80     8b/-> *(ebp+0xc) 0/r32/eax
+ 81     (lookup *eax *(eax+4))  # => eax
+ 82     8d/copy-address *(eax+4) 0/r32/eax
+ 83     #
+ 84     (copy-bytes %edx %eax %ecx)
+ 85 $stream-to-array:end:
+ 86     # . restore registers
+ 87     5e/pop-to-esi
+ 88     5a/pop-to-edx
+ 89     59/pop-to-ecx
+ 90     58/pop-to-eax
+ 91     # . epilogue
+ 92     89/<- %esp 5/r32/ebp
+ 93     5d/pop-to-ebp
+ 94     c3/return
+ 95 
+ 96 test-stream-to-array:
+ 97     # . prologue
+ 98     55/push-ebp
+ 99     89/<- %ebp 4/r32/esp
+100     # setup
+101     (clear-stream _test-input-stream)
+102     (write _test-input-stream "abc")
+103     # skip something
+104     (read-byte _test-input-stream)  # => eax
+105     # var out/ecx: (handle array byte)
 106     68/push 0/imm32
-107     89/<- %ecx 4/r32/esp
-108     #
-109     (stream-to-array _test-input-stream %ecx)
-110     (lookup *ecx *(ecx+4))  # => eax
-111     (check-strings-equal %eax "bc")
-112     # . epilogue
-113     89/<- %esp 5/r32/ebp
-114     5d/pop-to-ebp
-115     c3/return
-116 
-117 # like stream-to-array but ignore surrounding quotes
-118 # we might do other stuff here later
-119 unquote-stream-to-array:  # in: (addr stream _), out: (addr handle array _)
-120     # . prologue
-121     55/push-ebp
-122     89/<- %ebp 4/r32/esp
-123     # . save registers
-124     50/push-eax
-125     51/push-ecx
-126     52/push-edx
-127     56/push-esi
-128     # esi = s
-129     8b/-> *(ebp+8) 6/r32/esi
-130     # var len/ecx: int = s->write - s->read - 2
-131     8b/-> *esi 1/r32/ecx
-132     2b/subtract *(esi+4) 1/r32/ecx
-133     81 7/subop/compare %ecx 2/imm32
-134     7c/jump-if-< $unquote-stream-to-array:end/disp8
-135     81 5/subop/subtract %ecx 2/imm32
-136     # allocate
-137     (allocate-array Heap %ecx *(ebp+0xc))
-138     # var in/edx: (addr byte) = s->data + s->read + 1
-139     8b/-> *(esi+4) 2/r32/edx
-140     8d/copy-address *(esi+edx+0xd) 2/r32/edx  # Stream-data + 1
-141     # var dest/eax: (addr byte) = data for out
-142     8b/-> *(ebp+0xc) 0/r32/eax
-143     (lookup *eax *(eax+4))  # => eax
-144     8d/copy-address *(eax+4) 0/r32/eax
-145     #
-146     (copy-bytes %edx %eax %ecx)
-147 $unquote-stream-to-array:end:
-148     # . restore registers
-149     5e/pop-to-esi
-150     5a/pop-to-edx
-151     59/pop-to-ecx
-152     58/pop-to-eax
-153     # . epilogue
-154     89/<- %esp 5/r32/ebp
-155     5d/pop-to-ebp
-156     c3/return
+107     68/push 0/imm32
+108     89/<- %ecx 4/r32/esp
+109     #
+110     (stream-to-array _test-input-stream %ecx)
+111     (lookup *ecx *(ecx+4))  # => eax
+112     (check-strings-equal %eax "bc")
+113     # . epilogue
+114     89/<- %esp 5/r32/ebp
+115     5d/pop-to-ebp
+116     c3/return
+117 
+118 # like stream-to-array but ignore surrounding quotes
+119 # we might do other stuff here later
+120 unquote-stream-to-array:  # in: (addr stream _), out: (addr handle array _)
+121     # . prologue
+122     55/push-ebp
+123     89/<- %ebp 4/r32/esp
+124     # . save registers
+125     50/push-eax
+126     51/push-ecx
+127     52/push-edx
+128     56/push-esi
+129     # esi = s
+130     8b/-> *(ebp+8) 6/r32/esi
+131     # var len/ecx: int = s->write - s->read - 2
+132     8b/-> *esi 1/r32/ecx
+133     2b/subtract *(esi+4) 1/r32/ecx
+134     81 7/subop/compare %ecx 2/imm32
+135     7c/jump-if-< $unquote-stream-to-array:end/disp8
+136     81 5/subop/subtract %ecx 2/imm32
+137     # allocate
+138     (allocate-array Heap %ecx *(ebp+0xc))
+139     # var in/edx: (addr byte) = s->data + s->read + 1
+140     8b/-> *(esi+4) 2/r32/edx
+141     8d/copy-address *(esi+edx+0xd) 2/r32/edx  # Stream-data + 1
+142     # var dest/eax: (addr byte) = data for out
+143     8b/-> *(ebp+0xc) 0/r32/eax
+144     (lookup *eax *(eax+4))  # => eax
+145     8d/copy-address *(eax+4) 0/r32/eax
+146     #
+147     (copy-bytes %edx %eax %ecx)
+148 $unquote-stream-to-array:end:
+149     # . restore registers
+150     5e/pop-to-esi
+151     5a/pop-to-edx
+152     59/pop-to-ecx
+153     58/pop-to-eax
+154     # . epilogue
+155     89/<- %esp 5/r32/ebp
+156     5d/pop-to-ebp
+157     c3/return
 
-- cgit 1.4.1-2-gfad0