| 1 | // +build ignore |
| 2 | |
| 3 | /* |
| 4 | Redistribution and use in source and binary forms, with or without |
| 5 | modification, are permitted provided that the following conditions are met: |
| 6 | |
| 7 | * Redistributions of source code must retain the above copyright |
| 8 | notice, this list of conditions and the following disclaimer. |
| 9 | |
| 10 | * Redistributions in binary form must reproduce the above copyright |
| 11 | notice, this list of conditions and the following disclaimer in the |
| 12 | documentation and/or other materials provided with the distribution. |
| 13 | |
| 14 | * Neither the name of "The Computer Language Benchmarks Game" nor the |
| 15 | name of "The Computer Language Shootout Benchmarks" nor the names of |
| 16 | its contributors may be used to endorse or promote products derived |
| 17 | from this software without specific prior written permission. |
| 18 | |
| 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 29 | POSSIBILITY OF SUCH DAMAGE. |
| 30 | */ |
| 31 | |
| 32 | /* The Computer Language Shootout |
| 33 | http://shootout.alioth.debian.org/ |
| 34 | |
| 35 | contributed by Greg Buchholz |
| 36 | |
| 37 | for the debian (AMD) machine... |
| 38 | compile flags: -O3 -ffast-math -march=athlon-xp -funroll-loops |
| 39 | |
| 40 | for the gp4 (Intel) machine... |
| 41 | compile flags: -O3 -ffast-math -march=pentium4 -funroll-loops |
| 42 | */ |
| 43 | |
| 44 | #include<stdio.h> |
| 45 | |
| 46 | int main (int argc, char **argv) |
| 47 | { |
| 48 | int w, h, bit_num = 0; |
| 49 | char byte_acc = 0; |
| 50 | int i, iter = 50; |
| 51 | double x, y, limit = 2.0; |
| 52 | double Zr, Zi, Cr, Ci, Tr, Ti; |
| 53 | |
| 54 | w = h = atoi(argv[1]); |
| 55 | |
| 56 | printf("P4\n%d %d\n",w,h); |
| 57 | |
| 58 | for(y=0;y<h;++y) |
| 59 | { |
| 60 | for(x=0;x<w;++x) |
| 61 | { |
| 62 | Zr = Zi = Tr = Ti = 0.0; |
| 63 | Cr = (2.0*x/w - 1.5); Ci=(2.0*y/h - 1.0); |
| 64 | |
| 65 | for (i=0;i<iter && (Tr+Ti <= limit*limit);++i) |
| 66 | { |
| 67 | Zi = 2.0*Zr*Zi + Ci; |
| 68 | Zr = Tr - Ti + Cr; |
| 69 | Tr = Zr * Zr; |
| 70 | Ti = Zi * Zi; |
| 71 | } |
| 72 | |
| 73 | byte_acc <<= 1; |
| 74 | if(Tr+Ti <= limit*limit) byte_acc |= 0x01; |
| 75 | |
| 76 | ++bit_num; |
| 77 | |
| 78 | if(bit_num == 8) |
| 79 | { |
| 80 | putc(byte_acc,stdout); |
| 81 | byte_acc = 0; |
| 82 | bit_num = 0; |
| 83 | } |
| 84 | else if(x == w-1) |
| 85 | { |
| 86 | byte_acc <<= (8-w%8); |
| 87 | putc(byte_acc,stdout); |
| 88 | byte_acc = 0; |
| 89 | bit_num = 0; |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | } |