home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / sys / sgi / 11523 < prev    next >
Encoding:
Text File  |  1992-07-28  |  11.4 KB  |  498 lines

  1. Path: sparky!uunet!paladin.american.edu!darwin.sura.net!dtix!relay!afterlife!adm!news
  2. From: zsd@axe.drea.dnd.ca (Jim Diamond)
  3. Newsgroups: comp.sys.sgi
  4. Subject: YA optimizer bug
  5. Message-ID: <31561@adm.brl.mil>
  6. Date: 28 Jul 92 17:13:25 GMT
  7. Sender: news@adm.brl.mil
  8. Lines: 488
  9.  
  10. I'm sure there's some SGI guy who is interested, so...
  11.  
  12. The following program demonstrates a bug in 4.0.2 on an Indigo as well
  13. as on 4.0.4 on an R4000/50 (Elan and GTX graphics, respectively, altho
  14. I expect that is irrelevant).  (Profuse apologies for not chopping it
  15. down into a small program.)  The program works as expected with no
  16. optimization or -O1 optimization, but -O, -O3 and -O4 all have
  17. problems.  Specifically, choosing the "pastels" entry of the color
  18. sub-menu causes the "gold" colors to be chosen, and choosing the
  19. "gold" option kills the program.  Note that uncommenting the printf()
  20. near the end of do_color_set() causes the bug to go away... so much
  21. for debugging statements!
  22.  
  23. Is this fixed in the much-awaited 4.0.5?
  24.  
  25.         Jim Diamond
  26.         zsd@axe.drea.dnd.ca
  27.  
  28. ----------------------------------------------------------------------
  29.  
  30. /*
  31. From dave@ivem1.ucsd.edu 
  32. Article 1007 of comp.sys.sgi:
  33. Received: Mon, 29 Apr 91 17:01:55 ADT from vmb.brl.mil by pig.drea.dnd.ca (5.52/5.6)
  34. Received: from vmb.brl.mil by VMB.BRL.MIL id ab16762; 29 Apr 91 15:12 EDT
  35. Received: from ucsd.edu by VMB.BRL.MIL id aa16517; 29 Apr 91 14:57 EDT
  36. Received: from ivem1.ucsd.edu by ucsd.edu; id AA05497
  37.     sendmail 5.64/UCSD-2.1-sun via SMTP
  38.     Mon, 29 Apr 91 11:04:45 -0700 for info-iris@vmb.brl.mil
  39. Received: by ivem1.UCSD.EDU (4.1/UCSDGENERIC.3)
  40.     id AA11381 to info-iris@vmb.brl.mil; Mon, 29 Apr 91 11:01:00 PDT
  41. Date: Mon, 29 Apr 91 11:01:00 PDT
  42. >From: Dave <dave@ivem1.ucsd.edu>
  43. Message-Id: <9104291801.AA11381@ivem1.UCSD.EDU>
  44. To: info-iris@vmb.brl.mil
  45.  
  46. /*
  47.  *    macic_dust - magic dustles spew forth from the cursor
  48.  *
  49.  *    David Hessler 4/25/91
  50.  *
  51.  *      cc -O3 -o magic_dust magic_dust.c -lgl_s
  52.  */
  53.  
  54. #include "gl.h"
  55. #include "device.h"
  56.  
  57. #define DEF_N        1000    /* max number of dustles */
  58. int    N    = DEF_N;
  59. #define DEF_NDPC    3.    /* new dustles per cycle */
  60. float    NDPC = DEF_NDPC;
  61. #define DEF_GRAV    .3    /* gravitational acceleration */
  62. float    GRAV = DEF_GRAV;
  63. #define DEF_MVEL    -.1    /* amount of mouse vel imparted to new dustle */
  64. float    MVEL = DEF_MVEL;
  65. #define DEF_IVEL    4.    /* magnitude of initial random velocity */
  66. float    IVEL = DEF_IVEL;
  67. #define DEF_VODV    .2    /* vertical offset of dustle velocity */
  68. float    VODV = DEF_VODV;
  69. #define DEF_CMIN    90    /* index of minmum  dustle color */
  70. int    CMIN = DEF_CMIN;
  71. #define DEF_CMAX    94    /* index of maximum dustle color */
  72. int    CMAX = DEF_CMAX;
  73.  
  74. /* get a random float from -1. to 1. */
  75. #define frandom() (((random()%10001)-5000)/5000.)
  76.  
  77. void (*clear_fn)();    /* clear function pointer */
  78.  
  79. /*
  80.  * clear function to be used on personal iris -- clear() doesn't
  81.  * work right when a pi window is in background mode.
  82.  *
  83.  * !!! I don't have a pi so I don't know if this worx. !!!
  84.  *
  85.  */
  86. void pi_clear()
  87. {
  88.     rectfi(0, 0, XMAXSCREEN, YMAXSCREEN);
  89. }
  90.  
  91. /* one dustle */
  92. typedef struct {
  93.     float x, y;    /* it's location */
  94.     float dx, dy;    /* it's velocity */
  95.     int cidx;    /* it's color */
  96. } dustle;
  97.  
  98. /* dustle storage */
  99. dustle dustles[DEF_N];        /* the dustles */
  100. int ndustles = 0;        /* number of active dustles */
  101.  
  102. main()
  103. {
  104.     char gv_buf[80];
  105.     int back, control;
  106.     long dev; short val;
  107.  
  108.     srandom(time(0));
  109.  
  110.     /* set up control window */
  111.     noborder();
  112.     prefposition(0, 19, 0, 19);
  113.     control = winopen("magic dust");
  114.     prefsize(20, 20);
  115.     winconstraints();
  116.     draw_control_window();
  117.     init_menus();
  118.  
  119.     /* Be nice */
  120.     nice(19);
  121.  
  122.     /* set up background window */
  123.     prefposition(0, XMAXSCREEN, 0, YMAXSCREEN);
  124.     imakebackground();
  125.     back = winopen("magic dust");
  126.     doublebuffer();
  127.     linewidth(3);
  128.     gconfig();
  129.  
  130.     /*
  131.      * set up clear function appropriate for this machine
  132.      * gversion returnsa string of the form 'GL4DPI...'
  133.      * on a personal iris, and something else on non-p.i.s...
  134.      */
  135.     gversion(gv_buf);
  136.     if (gv_buf[4] == 'P')
  137.       clear_fn = pi_clear;
  138.     else
  139.       clear_fn = clear;
  140.  
  141.     /* go! */
  142.     qdevice(QKEY);
  143.     qdevice(REDRAW);
  144.     qdevice(WINTHAW);
  145.     qdevice(WINFREEZE);
  146.     qdevice(RIGHTMOUSE);
  147.     while(1) {
  148.  
  149.       while(qtest()) {
  150.         dev = qread(&val);
  151.  
  152.         switch(dev) {
  153.  
  154.           /* quit */
  155.           case(QKEY):
  156.         exit(0);
  157.  
  158.           /* re-do command window */
  159.           case(REDRAW):
  160.         if (val == control) {
  161.           winset(control);
  162.           draw_control_window();
  163.         }
  164.         break;
  165.  
  166.           /* do menus */
  167.           case(RIGHTMOUSE):
  168.         do_menus();
  169.         break;
  170.  
  171.         }
  172.       }
  173.  
  174.       winset(back);
  175.       color(BLACK);
  176.       clear_fn();
  177.       do_dustles();
  178.       swapbuffers();
  179.     }
  180. }
  181.  
  182. do_dustles()
  183. {
  184.     static int first=1;
  185.     static float ox, oy;    /* x & y from last time */
  186.     static float step=0.;
  187.     register dustle *dptr;
  188.     register int i;
  189.     static float x, y;
  190.  
  191.     /* where'z the cursor? */
  192.     x = getvaluator(MOUSEX);
  193.     y = getvaluator(MOUSEY);
  194.  
  195.     /*
  196.      * initially, we don't have ox & oy,
  197.      * so we just make 'em the same as x & y
  198.      */
  199.     if (first) {
  200.       ox = x;
  201.       oy = y;
  202.       first = 0;
  203.     }
  204.  
  205.     /* add new dustles */
  206.     step += NDPC;
  207.     while  ((ndustles<N) && (step>0.)) {
  208.       dptr = &dustles[ndustles++];
  209.  
  210.       dptr->x = x;
  211.       dptr->y = y;
  212.       dptr->dx = MVEL*(x-ox) + frandom()*IVEL;
  213.       dptr->dy = MVEL*(y-oy) + frandom()*IVEL + VODV*IVEL;
  214.       dptr->cidx = (random()%(CMAX-CMIN+1))+CMIN;
  215.  
  216.       step -= 1.;
  217.     }
  218.  
  219.     /* save cursor location */
  220.     ox = x;
  221.     oy = y;
  222.  
  223.     /* do dustles */
  224.     dptr = dustles;
  225.     for (i=0; i<ndustles;) {
  226.  
  227.       /* set color */
  228.       color(dptr->cidx);
  229.  
  230.       /* old location */
  231.       x = dptr->x;
  232.       y = dptr->y;
  233.       move2(x, y);
  234.  
  235.       /* new location */
  236.       dptr->x = (x += dptr->dx);
  237.       dptr->y = (y += dptr->dy);
  238.       draw2(x, y);
  239.  
  240.       /* gravitational acceleration */
  241.       dptr->dy -= GRAV;
  242.  
  243.       /* toss dustles that have left the screen */
  244.       if ((x<0)||(x>XMAXSCREEN)
  245.                ||((GRAV<=0.)&&(y>YMAXSCREEN))||((GRAV>=0.)&&(y<0)))
  246.         *dptr = dustles[--ndustles];
  247.       else {
  248.         dptr++;
  249.         i++;
  250.       }
  251.     }
  252. }
  253.  
  254. /* draw the control window : a box surrounding a wand w/sparx */
  255. draw_control_window()
  256. {
  257.     static Object o = -1;
  258.  
  259.     if (o == -1) {
  260.  
  261.       makeobj(o=genobj());
  262.  
  263.       /* clear it */
  264.       color(BLACK);
  265.       clear();
  266.  
  267.       /* some sparkles */
  268.       linewidth(1);
  269.       color(90);
  270.       move2i(9, 15); draw2i(7, 16);
  271.       move2i(16, 12); draw2i(17, 14);
  272.       color(92);
  273.       move2i(8, 12); draw2i(6, 12);
  274.       move2i(15, 9); draw2i(16, 7);
  275.       color(94);
  276.       move2i(12, 8); draw2i(12, 6);
  277.       move2i(12, 16); draw2i(14, 17);
  278.   
  279.       /* border */
  280.       color(16);
  281.       recti(0, 0, 19, 19);
  282.   
  283.       /* ball */
  284.       circfi(12, 12, 2);
  285.  
  286.       /* and stick */
  287.       linewidth(2);
  288.       move2i(3, 3);
  289.       draw2i(12, 12);
  290.  
  291.       closeobj();
  292.     }
  293.  
  294.     callobj(o);
  295.  
  296. }
  297.  
  298. /* menus to change operational parameters */
  299. static int main_menu;
  300. do_menus()
  301. {
  302.     switch(dopup(main_menu)) {
  303.  
  304.       /* quit */
  305.       case(1):
  306.         exit(0);
  307.  
  308.       /* reset parameters */
  309.       case(2):
  310.         N    = DEF_N;
  311.         NDPC = DEF_NDPC;
  312.         GRAV = DEF_GRAV;
  313.         MVEL = DEF_MVEL;
  314.         IVEL = DEF_IVEL;
  315.         VODV = DEF_VODV;
  316.         CMIN = DEF_CMIN;
  317.         CMAX = DEF_CMAX;
  318.         break;
  319.     }
  320. }
  321.  
  322. /* change number of dustles */
  323. do_num_dustles(op)
  324.     int op;
  325. {
  326.     N = op;
  327.  
  328.     if (N > DEF_N) N = DEF_N;
  329.     if (N < 1) N = 1;
  330.  
  331.     if (N < ndustles)
  332.       ndustles = N;
  333. }
  334.  
  335. /* change new dustle rate */
  336. do_new_dustle_rate(op)
  337.     int op;
  338. {
  339.     NDPC = op/10.;
  340. }
  341.  
  342. /* adjust gravity */
  343. do_gravity(op)
  344.     int op;
  345. {
  346.     GRAV = op/10.;
  347. }
  348.  
  349. /* change initial dustle velocity bound */
  350. do_initial_velocity(op)
  351.     int op;
  352. {
  353.     IVEL = op/10.;
  354. }
  355.  
  356. /* alter mouse's effect on inital dustle velovity */
  357. do_mvel(op)
  358.     int op;
  359. {
  360.     MVEL = op/10.;
  361. }
  362.  
  363. /* alter vertical offsert to inital dustle velocity */
  364. do_vodv(op)
  365.     int op;
  366. {
  367.     VODV = op/10.;
  368. }
  369.  
  370. /* select which colorz get used */
  371. do_color_set(op)
  372.     int op;
  373. {
  374. printf("do_color_set: op = %d\n", op);
  375.     switch(op) {
  376.       case(1): CMIN =  90; CMAX =  94; break; /* gold */
  377.       case(2): CMIN =   9; CMAX =  14; break; /* pastels */
  378.       case(3): CMIN =   1; CMAX =   7; break; /* primaries */
  379.       case(4): CMIN =  32; CMAX =  56; break; /* greys */
  380.       case(5): CMIN =  57; CMAX = 255; break; /* rainbow */
  381.       case(6): CMIN =   7; CMAX =   7; break; /* white */
  382.       case(7): CMIN = 512; CMAX = 767; break; /* 512-767 */
  383.     }
  384. /*printf("CMIN = %d,  CMAX = %d\n", CMIN,  CMAX);*/
  385. }
  386.  
  387. /* set up all them menus */
  388. init_menus()
  389. {
  390.     static int ndus_menu;
  391.     static int ndpc_menu;
  392.     static int grav_menu;
  393.     static int ivel_menu;
  394.     static int mvel_menu;
  395.     static int vodv_menu;
  396.     static int color_menu;
  397.  
  398.     ndus_menu = newpup();
  399.     addtopup(ndus_menu, "Number of Dustles %t %F", do_num_dustles);
  400.     addtopup(ndus_menu, "1000 %x1000");
  401.     addtopup(ndus_menu, "500 %x500");
  402.     addtopup(ndus_menu, "200 %x200");
  403.     addtopup(ndus_menu, "100 %x100");
  404.     addtopup(ndus_menu, "50 %x50");
  405.     addtopup(ndus_menu, "20 %x20");
  406.     addtopup(ndus_menu, "10 %x10");
  407.     addtopup(ndus_menu, "5 %x5");
  408.     addtopup(ndus_menu, "2 %x2");
  409.     addtopup(ndus_menu, "1 %x1");
  410.  
  411.     ndpc_menu = newpup();
  412.     addtopup(ndpc_menu, "New Dustle Rate %t %F", do_new_dustle_rate);
  413.     addtopup(ndpc_menu, "8 %x80");
  414.     addtopup(ndpc_menu, "4 %x40");
  415.     addtopup(ndpc_menu, "2 %x20");
  416.     addtopup(ndpc_menu, "1 %x10");
  417.     addtopup(ndpc_menu, "1/2 %x5");
  418.     addtopup(ndpc_menu, "1/5 %x2");
  419.     addtopup(ndpc_menu, "1/10 %x1");
  420.  
  421.     grav_menu = newpup();
  422.     addtopup(grav_menu, "Gravity %t %F", do_gravity);
  423.     addtopup(grav_menu, "5. %x50");
  424.     addtopup(grav_menu, "2. %x20");
  425.     addtopup(grav_menu, "1. %x10");
  426.     addtopup(grav_menu, ".7 %x7");
  427.     addtopup(grav_menu, ".5 %x5");
  428.     addtopup(grav_menu, ".3 %x3");
  429.     addtopup(grav_menu, ".1 %x1");
  430.     addtopup(grav_menu, "0. %x0");
  431.     addtopup(grav_menu, "-.1 %x-1");
  432.     addtopup(grav_menu, "-.3 %x-3");
  433.     addtopup(grav_menu, "-.5 %x-5");
  434.     addtopup(grav_menu, "-.7 %x-7");
  435.     addtopup(grav_menu, "-1. %x-10");
  436.     addtopup(grav_menu, "-2. %x-20");
  437.     addtopup(grav_menu, "-5. %x-50");
  438.  
  439.     ivel_menu = newpup();
  440.     addtopup(ivel_menu, "Initial Velocity %t %F", do_initial_velocity);
  441.     addtopup(ivel_menu, "20. %x200");
  442.     addtopup(ivel_menu, "10. %x100");
  443.     addtopup(ivel_menu, "6. %x60");
  444.     addtopup(ivel_menu, "4. %x40");
  445.     addtopup(ivel_menu, "3. %x30");
  446.     addtopup(ivel_menu, "2. %x20");
  447.     addtopup(ivel_menu, "1. %x10");
  448.     addtopup(ivel_menu, ".5 %x5");
  449.     addtopup(ivel_menu, "0. %x0");
  450.  
  451.     vodv_menu = newpup();
  452.     addtopup(vodv_menu, "Vertical Velocity Offset %t %F", do_vodv);
  453.     addtopup(vodv_menu, "2. %x20");
  454.     addtopup(vodv_menu, "1. %x10");
  455.     addtopup(vodv_menu, ".5 %x5");
  456.     addtopup(vodv_menu, ".2 %x2");
  457.     addtopup(vodv_menu, "0. %x0");
  458.     addtopup(vodv_menu, "-.2 %x-2");
  459.     addtopup(vodv_menu, "-.5 %x-5");
  460.     addtopup(vodv_menu, "-1. %x-10");
  461.     addtopup(vodv_menu, "-2. %x-20");
  462.  
  463.     mvel_menu = newpup();
  464.     addtopup(mvel_menu, "Mouse Throw %t %F", do_mvel);
  465.     addtopup(mvel_menu, "2. %x20");
  466.     addtopup(mvel_menu, "1. %x10");
  467.     addtopup(mvel_menu, ".5 %x5");
  468.     addtopup(mvel_menu, ".3 %x3");
  469.     addtopup(mvel_menu, ".1 %x1");
  470.     addtopup(mvel_menu, "0. %x0");
  471.     addtopup(mvel_menu, "-.1 %x-1");
  472.     addtopup(mvel_menu, "-.3 %x-3");
  473.     addtopup(mvel_menu, "-.5 %x-5");
  474.     addtopup(mvel_menu, "-1. %x-10");
  475.     addtopup(mvel_menu, "-2. %x-20");
  476.  
  477.     color_menu = newpup();
  478.     addtopup(color_menu, "Colors %t %F", do_color_set);
  479.     addtopup(color_menu, "Gold %x1");
  480.     addtopup(color_menu, "Pastels %x2");
  481.     addtopup(color_menu, "Primaries %x3");
  482.     addtopup(color_menu, "Greys %x4");
  483.     addtopup(color_menu, "Rainbow %x5");
  484.     addtopup(color_menu, "Boring White %x6");
  485.     addtopup(color_menu, "512-767 %x7");
  486.  
  487.     main_menu = newpup();
  488.     addtopup(main_menu, "Magic Dust %t");
  489.     addtopup(main_menu, "Quit|Reset %l");
  490.     addtopup(main_menu, "Number of Dustles %m", ndus_menu);
  491.     addtopup(main_menu, "New Dustle Rate %m", ndpc_menu);
  492.     addtopup(main_menu, "Gravity %m", grav_menu);
  493.     addtopup(main_menu, "Initial Velocity %m", ivel_menu);
  494.     addtopup(main_menu, "Mouse Throw %m", mvel_menu);
  495.     addtopup(main_menu, "Vertical Velocity Offset %m", vodv_menu);
  496.     addtopup(main_menu, "Colors %m", color_menu);
  497. }
  498.