From dd60caa3f51c5117c0193f8f3272e1c7f5230eb7 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Tue, 15 Jun 2021 21:50:13 -0700 Subject: . --- html/mandelbrot-fixed.mu.html | 146 ++++++++++++++++++++++-------------------- 1 file changed, 76 insertions(+), 70 deletions(-) (limited to 'html/mandelbrot-fixed.mu.html') diff --git a/html/mandelbrot-fixed.mu.html b/html/mandelbrot-fixed.mu.html index 3e4b205e..14e423d1 100644 --- a/html/mandelbrot-fixed.mu.html +++ b/html/mandelbrot-fixed.mu.html @@ -14,14 +14,20 @@ pre { white-space: pre-wrap; font-family: monospace; color: #000000; background- body { font-size:12pt; font-family: monospace; color: #000000; background-color: #a8a8a8; } a { color:inherit; } * { font-size:12pt; font-size: 1em; } -.PreProc { color: #c000c0; } -.Special { color: #ff6060; } .LineNr { } -.Constant { color: #008787; } .Delimiter { color: #c000c0; } +.muRegEdx { color: #878700; } +.muRegEbx { color: #8787af; } +.muRegEsi { color: #87d787; } +.muRegEdi { color: #87ffd7; } +.Constant { color: #008787; } +.Special { color: #ff6060; } +.PreProc { color: #c000c0; } .muFunction { color: #af5f00; text-decoration: underline; } .muTest { color: #5f8700; } .muComment { color: #005faf; } +.muRegEax { color: #875f00; } +.muRegEcx { color: #af875f; } --> @@ -79,11 +85,11 @@ if ('onhashchange' in window) { 20 { 21 mandelbrot screen scene-cx-f, scene-cy-f, scene-width-f 22 # move at an angle slowly towards the edge - 23 var adj-f/eax: int <- multiply-fixed scene-width-f, 0x12/0.07 + 23 var adj-f/eax: int <- multiply-fixed scene-width-f, 0x12/0.07 24 subtract-from scene-cx-f, adj-f 25 add-to scene-cy-f, adj-f 26 # slowly shrink the scene width to zoom in - 27 var tmp-f/eax: int <- multiply-fixed scene-width-f, 0x80/0.5 + 27 var tmp-f/eax: int <- multiply-fixed scene-width-f, 0x80/0.5 28 copy-to scene-width-f, tmp-f 29 loop 30 } @@ -92,8 +98,8 @@ if ('onhashchange' in window) { 33 # Since they still look like int types, we'll append a '-f' suffix to variable 34 # names to designate fixed-point numbers. 35 - 36 fn int-to-fixed in: int -> _/eax: int { - 37 var result-f/eax: int <- copy in + 36 fn int-to-fixed in: int -> _/eax: int { + 37 var result-f/eax: int <- copy in 38 result-f <- shift-left 8/fixed-precision 39 { 40 break-if-not-overflow @@ -102,8 +108,8 @@ if ('onhashchange' in window) { 43 return result-f 44 } 45 - 46 fn fixed-to-int in-f: int -> _/eax: int { - 47 var result/eax: int <- copy in-f + 46 fn fixed-to-int in-f: int -> _/eax: int { + 47 var result/eax: int <- copy in-f 48 result <- shift-right-signed 8/fixed-precision 49 return result 50 } @@ -111,53 +117,53 @@ if ('onhashchange' in window) { 52 # The process of throwing bits away always adjusts a number towards -infinity. 53 fn test-fixed-conversion { 54 # 0 - 55 var f/eax: int <- int-to-fixed 0 - 56 var result/eax: int <- fixed-to-int f + 55 var f/eax: int <- int-to-fixed 0 + 56 var result/eax: int <- fixed-to-int f 57 check-ints-equal result, 0, "F - test-fixed-conversion - 0" 58 # 1 - 59 var f/eax: int <- int-to-fixed 1 - 60 var result/eax: int <- fixed-to-int f + 59 var f/eax: int <- int-to-fixed 1 + 60 var result/eax: int <- fixed-to-int f 61 check-ints-equal result, 1, "F - test-fixed-conversion - 1" 62 # -1 - 63 var f/eax: int <- int-to-fixed -1 - 64 var result/eax: int <- fixed-to-int f + 63 var f/eax: int <- int-to-fixed -1 + 64 var result/eax: int <- fixed-to-int f 65 check-ints-equal result, -1, "F - test-fixed-conversion - -1" 66 # 0.5 = 1/2 - 67 var f/eax: int <- int-to-fixed 1 + 67 var f/eax: int <- int-to-fixed 1 68 f <- shift-right-signed 1 - 69 var result/eax: int <- fixed-to-int f + 69 var result/eax: int <- fixed-to-int f 70 check-ints-equal result, 0, "F - test-fixed-conversion - 0.5" 71 # -0.5 = -1/2 - 72 var f/eax: int <- int-to-fixed -1 + 72 var f/eax: int <- int-to-fixed -1 73 f <- shift-right-signed 1 - 74 var result/eax: int <- fixed-to-int f + 74 var result/eax: int <- fixed-to-int f 75 check-ints-equal result, -1, "F - test-fixed-conversion - -0.5" 76 # 1.5 = 3/2 - 77 var f/eax: int <- int-to-fixed 3 + 77 var f/eax: int <- int-to-fixed 3 78 f <- shift-right-signed 1 - 79 var result/eax: int <- fixed-to-int f + 79 var result/eax: int <- fixed-to-int f 80 check-ints-equal result, 1, "F - test-fixed-conversion - 1.5" 81 # -1.5 = -3/2 - 82 var f/eax: int <- int-to-fixed -3 + 82 var f/eax: int <- int-to-fixed -3 83 f <- shift-right-signed 1 - 84 var result/eax: int <- fixed-to-int f + 84 var result/eax: int <- fixed-to-int f 85 check-ints-equal result, -2, "F - test-fixed-conversion - -1.5" 86 # 1.25 = 5/4 - 87 var f/eax: int <- int-to-fixed 5 + 87 var f/eax: int <- int-to-fixed 5 88 f <- shift-right-signed 2 - 89 var result/eax: int <- fixed-to-int f + 89 var result/eax: int <- fixed-to-int f 90 check-ints-equal result, 1, "F - test-fixed-conversion - 1.25" 91 # -1.25 = -5/4 - 92 var f/eax: int <- int-to-fixed -5 + 92 var f/eax: int <- int-to-fixed -5 93 f <- shift-right-signed 2 - 94 var result/eax: int <- fixed-to-int f + 94 var result/eax: int <- fixed-to-int f 95 check-ints-equal result, -2, "F - test-fixed-conversion - -1.25" 96 } 97 98 # special routines for multiplying and dividing fixed-point numbers 99 -100 fn multiply-fixed a-f: int, b-f: int -> _/eax: int { -101 var result/eax: int <- copy a-f +100 fn multiply-fixed a-f: int, b-f: int -> _/eax: int { +101 var result/eax: int <- copy a-f 102 result <- multiply b-f 103 { 104 break-if-not-overflow @@ -167,14 +173,14 @@ if ('onhashchange' in window) { 108 return result 109 } 110 -111 fn divide-fixed a-f: int, b-f: int -> _/eax: int { -112 var result-f/eax: int <- copy a-f +111 fn divide-fixed a-f: int, b-f: int -> _/eax: int { +112 var result-f/eax: int <- copy a-f 113 result-f <- shift-left 8/fixed-precision 114 { 115 break-if-not-overflow 116 abort "divide-fixed: overflow" 117 } -118 var dummy-remainder/edx: int <- copy 0 +118 var dummy-remainder/edx: int <- copy 0 119 result-f, dummy-remainder <- integer-divide result-f, b-f 120 return result-f 121 } @@ -184,32 +190,32 @@ if ('onhashchange' in window) { 125 # adding and subtracting two fixed-point numbers can use existing instructions. 126 127 fn mandelbrot screen: (addr screen), scene-cx-f: int, scene-cy-f: int, scene-width-f: int { -128 var a/eax: int <- copy 0 -129 var b/ecx: int <- copy 0 -130 a, b <- screen-size screen -131 var width/esi: int <- copy a +128 var a/eax: int <- copy 0 +129 var b/ecx: int <- copy 0 +130 a, b <- screen-size screen +131 var width/esi: int <- copy a 132 width <- shift-left 3/log2-font-width -133 var height/edi: int <- copy b +133 var height/edi: int <- copy b 134 height <- shift-left 4/log2-font-height -135 var y/ecx: int <- copy 0 +135 var y/ecx: int <- copy 0 136 { 137 compare y, height 138 break-if->= -139 var imaginary-f/ebx: int <- viewport-to-imaginary-f y, width, height, scene-cy-f, scene-width-f -140 var x/eax: int <- copy 0 +139 var imaginary-f/ebx: int <- viewport-to-imaginary-f y, width, height, scene-cy-f, scene-width-f +140 var x/eax: int <- copy 0 141 { 142 compare x, width 143 break-if->= -144 var real-f/edx: int <- viewport-to-real-f x, width, scene-cx-f, scene-width-f -145 var iterations/esi: int <- mandelbrot-iterations-for-point real-f, imaginary-f, 0x400/max +144 var real-f/edx: int <- viewport-to-real-f x, width, scene-cx-f, scene-width-f +145 var iterations/esi: int <- mandelbrot-iterations-for-point real-f, imaginary-f, 0x400/max 146 iterations <- shift-right 3 -147 var color/edx: int <- copy 0 +147 var color/edx: int <- copy 0 148 { -149 var dummy/eax: int <- copy 0 +149 var dummy/eax: int <- copy 0 150 dummy, color <- integer-divide iterations, 0x18/24/size-of-cycle-0 151 color <- add 0x20/cycle-0 152 } -153 pixel screen, x, y, color +153 pixel screen, x, y, color 154 x <- increment 155 loop 156 } @@ -218,18 +224,18 @@ if ('onhashchange' in window) { 159 } 160 } 161 -162 fn mandelbrot-iterations-for-point real-f: int, imaginary-f: int, max: int -> _/esi: int { -163 var x-f/esi: int <- copy 0 -164 var y-f/edi: int <- copy 0 -165 var iterations/ecx: int <- copy 0 +162 fn mandelbrot-iterations-for-point real-f: int, imaginary-f: int, max: int -> _/esi: int { +163 var x-f/esi: int <- copy 0 +164 var y-f/edi: int <- copy 0 +165 var iterations/ecx: int <- copy 0 166 { -167 var done?/eax: boolean <- mandelbrot-done? x-f, y-f +167 var done?/eax: boolean <- mandelbrot-done? x-f, y-f 168 compare done?, 0/false 169 break-if-!= 170 compare iterations, max 171 break-if->= -172 var x2-f/edx: int <- mandelbrot-x x-f, y-f, real-f -173 var y2-f/ebx: int <- mandelbrot-y x-f, y-f, imaginary-f +172 var x2-f/edx: int <- mandelbrot-x x-f, y-f, real-f +173 var y2-f/ebx: int <- mandelbrot-y x-f, y-f, imaginary-f 174 x-f <- copy x2-f 175 y-f <- copy y2-f 176 iterations <- increment @@ -238,10 +244,10 @@ if ('onhashchange' in window) { 179 return iterations 180 } 181 -182 fn mandelbrot-done? x-f: int, y-f: int -> _/eax: boolean { +182 fn mandelbrot-done? x-f: int, y-f: int -> _/eax: boolean { 183 # x*x + y*y > 4 -184 var tmp-f/eax: int <- multiply-fixed x-f, x-f -185 var result-f/ecx: int <- copy tmp-f +184 var tmp-f/eax: int <- multiply-fixed x-f, x-f +185 var result-f/ecx: int <- copy tmp-f 186 tmp-f <- multiply-fixed y-f, y-f 187 result-f <- add tmp-f 188 compare result-f, 0x400/4 @@ -252,19 +258,19 @@ if ('onhashchange' in window) { 193 return 1/true 194 } 195 -196 fn mandelbrot-x x-f: int, y-f: int, real-f: int -> _/edx: int { +196 fn mandelbrot-x x-f: int, y-f: int, real-f: int -> _/edx: int { 197 # x*x - y*y + real -198 var tmp-f/eax: int <- multiply-fixed x-f, x-f -199 var result-f/ecx: int <- copy tmp-f +198 var tmp-f/eax: int <- multiply-fixed x-f, x-f +199 var result-f/ecx: int <- copy tmp-f 200 tmp-f <- multiply-fixed y-f, y-f 201 result-f <- subtract tmp-f 202 result-f <- add real-f 203 return result-f 204 } 205 -206 fn mandelbrot-y x-f: int, y-f: int, imaginary-f: int -> _/ebx: int { +206 fn mandelbrot-y x-f: int, y-f: int, imaginary-f: int -> _/ebx: int { 207 # 2*x*y + imaginary -208 var result-f/eax: int <- copy x-f +208 var result-f/eax: int <- copy x-f 209 result-f <- shift-left 1/log2 210 result-f <- multiply-fixed result-f, y-f 211 result-f <- add imaginary-f @@ -275,42 +281,42 @@ if ('onhashchange' in window) { 216 # ranges from -2 to +2. Viewport height just follows the viewport's aspect 217 # ratio. 218 -219 fn viewport-to-real-f x: int, width: int, scene-cx-f: int, scene-width-f: int -> _/edx: int { +219 fn viewport-to-real-f x: int, width: int, scene-cx-f: int, scene-width-f: int -> _/edx: int { 220 # 0 in the viewport goes to scene-cx - scene-width/2 221 # width in the viewport goes to scene-cx + scene-width/2 222 # Therefore: 223 # x in the viewport goes to (scene-cx - scene-width/2) + x*scene-width/width 224 # At most two numbers being multiplied before a divide, so no risk of overflow. -225 var result-f/eax: int <- int-to-fixed x +225 var result-f/eax: int <- int-to-fixed x 226 result-f <- multiply-fixed result-f, scene-width-f -227 var width-f/ecx: int <- copy width +227 var width-f/ecx: int <- copy width 228 width-f <- shift-left 8/fixed-precision 229 result-f <- divide-fixed result-f, width-f 230 result-f <- add scene-cx-f -231 var half-scene-width-f/ecx: int <- copy scene-width-f +231 var half-scene-width-f/ecx: int <- copy scene-width-f 232 half-scene-width-f <- shift-right 1 233 result-f <- subtract half-scene-width-f 234 return result-f 235 } 236 -237 fn viewport-to-imaginary-f y: int, width: int, height: int, scene-cy-f: int, scene-width-f: int -> _/ebx: int { +237 fn viewport-to-imaginary-f y: int, width: int, height: int, scene-cy-f: int, scene-width-f: int -> _/ebx: int { 238 # 0 in the viewport goes to scene-cy - scene-width/2*height/width 239 # height in the viewport goes to scene-cy + scene-width/2*height/width 240 # Therefore: 241 # y in the viewport goes to (scene-cy - scene-width/2*height/width) + y*scene-width/width 242 # scene-cy - scene-width/width * (height/2 + y) 243 # At most two numbers being multiplied before a divide, so no risk of overflow. -244 var result-f/eax: int <- int-to-fixed y +244 var result-f/eax: int <- int-to-fixed y 245 result-f <- multiply-fixed result-f, scene-width-f -246 var width-f/ecx: int <- copy width +246 var width-f/ecx: int <- copy width 247 width-f <- shift-left 8/fixed-precision 248 result-f <- divide-fixed result-f, width-f 249 result-f <- add scene-cy-f -250 var second-term-f/edx: int <- copy 0 +250 var second-term-f/edx: int <- copy 0 251 { -252 var _second-term-f/eax: int <- copy scene-width-f +252 var _second-term-f/eax: int <- copy scene-width-f 253 _second-term-f <- shift-right 1 -254 var height-f/ebx: int <- copy height +254 var height-f/ebx: int <- copy height 255 height-f <- shift-left 8/fixed-precision 256 _second-term-f <- multiply-fixed _second-term-f, height-f 257 _second-term-f <- divide-fixed _second-term-f, width-f -- cgit 1.4.1-2-gfad0