qbe

Internal scc patchset buffer for QBE
Log | Files | Refs | README | LICENSE

mandel.ssa (5328B)


      1 # Print the Mandelbrot set on the
      2 # terminal line output.
      3 
      4 function w $mandel(d %x, d %y) {
      5 @mandel
      6 	%cr =d sub %y, d_0.5
      7 	%ci =d copy %x
      8 @loop
      9 	%i =w phi @mandel 0, @loop1 %i1
     10 	%zr =d phi @mandel d_0, @loop1 %zr1
     11 	%zi =d phi @mandel d_0, @loop1 %zi1
     12 	%i1 =w add 1, %i
     13 	%tmp =d mul %zr, %zi
     14 	%zr2 =d mul %zr, %zr
     15 	%zi2 =d mul %zi, %zi
     16 	%zrx =d sub %zr2, %zi2
     17 	%zr1 =d add %zrx, %cr
     18 	%zix =d add %tmp, %tmp
     19 	%zi1 =d add %zix, %ci
     20 	%sum =d add %zi2, %zr2
     21 	%cmp1 =w cgtd %sum, d_16
     22 	jnz %cmp1, @reti, @loop1
     23 @loop1
     24 	%cmp2 =w csgtw %i1, 1000
     25 	jnz %cmp2, @ret0, @loop
     26 @reti
     27 	ret %i1
     28 @ret0
     29 	ret 0
     30 }
     31 
     32 export
     33 function w $main() {
     34 @main
     35 @loopy
     36 	%y =d phi @main d_-1, @loopy1 %y1
     37 @loopx
     38 	%x =d phi @loopy d_-1, @loopx1 %x1
     39 	%i =w call $mandel(d %x, d %y)
     40 	jnz %i, @out, @in
     41 @in
     42 	%r0 =w call $putchar(w 42)   # '*'
     43 	jmp @loopx1
     44 @out
     45 	%r1 =w call $putchar(w 32)   # ' '
     46 	jmp @loopx1
     47 @loopx1
     48 	%x1 =d add %x, d_0.032
     49 	%cmp1 =w cgtd %x1, d_1
     50 	jnz %cmp1, @loopy1, @loopx
     51 @loopy1
     52 	%r2 =w call $putchar(w 10)   # '\n'
     53 	%y1 =d add %y, d_0.032
     54 	%cmp2 =w cgtd %y1, d_1
     55 	jnz %cmp2, @ret, @loopy
     56 @ret
     57 	ret 0
     58 }
     59 
     60 # >>> output
     61 #                                                                #
     62 #                                                                #
     63 #                                                                #
     64 #                                                                #
     65 #                                *                               #
     66 #                               ****                             #
     67 #                               ****                             #
     68 #                               ***                              #
     69 #                              *****                             #
     70 #                             *********                          #
     71 #                           ************                         #
     72 #                        *****************                       #
     73 #                         ****************                       #
     74 #                         ***************                        #
     75 #                         ****************                       #
     76 #                         ****************                       #
     77 #                        *****************                       #
     78 #                         ****************                       #
     79 #                         ****************                       #
     80 #                          **************                        #
     81 #                          *************                         #
     82 #                           ************                         #
     83 #                            *********                           #
     84 #                              *****                             #
     85 #                            ***********                         #
     86 #                         *****************                      #
     87 #                      **********************                    #
     88 #                   * *********************** **                 #
     89 #                   ***************************                  #
     90 #                  *****************************                 #
     91 #               * *******************************  **            #
     92 #              ** ***********************************            #
     93 #              *********************************** *             #
     94 #               ***********************************              #
     95 #              *************************************             #
     96 #              *************************************             #
     97 #             ***************************************            #
     98 #             ***************************************            #
     99 #             ***************************************            #
    100 #             ****************************************           #
    101 #       *     ****************************************           #
    102 #       ********************************************** ****      #
    103 #       ****************************************************     #
    104 #     * *****************************************************    #
    105 #     * *****************************************************    #
    106 #       ***** **************************************** ****      #
    107 #         *   ****************************************    *      #
    108 #             ****************************************           #
    109 #             ***************************************            #
    110 #            ****************************************            #
    111 #              ***************************************           #
    112 #             ****************************************           #
    113 #               ************************************             #
    114 #               ***********************************              #
    115 #                *********************************               #
    116 #               ************************************             #
    117 #               *** ************* ************** ***             #
    118 #                    ***********   ************   **             #
    119 #                      ********      ********                    #
    120 #                     **                *   *                    #
    121 #                                                                #
    122 #                                                                #
    123 #                                                                #
    124 # <<<