compiler construction - ARB Fragment If/Else -


i have problem , can't seem wrap head around it, hoping someon here might able me out.

i'm writing compiler miniglsl, , far good. i'm @ point need output arb fragment program, problem is, arb have target doesn't support branching. (a full list of supported instructions can found here http://petewarden.com/notes/archives/2005/05/fragment_progra_2.html ).

in order simulate if/else, i've been making use of cmp program follows (assuming 0 or greater = true, otherwise, false. // represents comments # causes bad formatting on here):

if (a < b)   = 1 + 1;   if (f < g)     c = 2 + 3; else   if (h < i)     b = 1 + 2;   else     d = 2 + 3; 

into arb fragment:

temp cond1, cond2, cond3, tempvar1, tempvar2, tempvar3, tempvar4, a, b, c, d, e, f, g; //top if //condition < b slt a, b, cond1; sub cond1, 1.0, cond1;  //assign if true add 1.0, 1.0, tempvar1; cmp cond1, a, tempvar1, a;  //condition f < g slt f, g, cond2; sub cond2, 1.0, cond2; //if top level if false, assign false, otherwise assign cmp cond1, -1.0, cond2, cond2; //assignment add 2.0, 3.0, tempvar2; cmp cond2, c, tempvar2, c;  //top else //if h < slt h, i, cond2; sub cond2, 1.0, cond2; //if top level if true, make false cmp cond1, cond2, -1.0, cond2; cmp cond2, tempvar3, b, b; //else //if top level if true, , previous if false, make true 

this before realize code going start getting ugly. each level of if/else going introduce continually stacking compares, , additionally, last else requires me re-evaluate cond2, or use register. know i'm doing wrong here, i'm not sure what. i've tried using counters, tried adding result of previous stages of if/else block, anding, oring, etc. can't find solution how convert if/else blocks arb fragment assembly doesn't on increasingly large stacks of cmp statements. 1 have idea how make simpler compiler can output programmatically? i'm not worried optimization @ point, want work.

thanks

are taking csc467 @ uoft cause if im in class lol.

so how think should implemented , thought not sure if corrext.

example: if (a < b) = 1 + 1; if (f < g) c = 2 + 3; else if (h < i) b = 1 + 2; else d = 2 + 3;

and read here http://www.cs.uaf.edu/~olawlor/ref/gl/glfp/ can flip sign of input if not case idea garbage

firstif:

//calculate condition slt a, b, condition1;

// calculate expression 1+1 doesnt change of registers add 1 ,1 , temp; cmp -condition , temp , ,a // if condition true -(condition) = -1 <0 //so store 1+1 in else store in a

secondif:

//calculate condition slt f , g , condition2;

//now because had previus condition1 need add them if both true //only execute cod

temp combinedcon1 ; temp temp2 = {2.0}; add condition1, condition2, combinedcon1;
sge combinedcon1 , temp2, combinedcon1 // if 2 subexpresiions added == 2 //then 1 else 0

//calculate 2+3 add 2, 3, temp;

//perform assignment if combinecon1 ==1 cmp -combinecon1 , temp , c ,c ;

//now can else cmp instruction follow same steps interchange few things,

so example if have ("else = 2" ); cmp -condition1 , , temp ,a ; instead of cmp -condition1 , temp, ,a ;

// works every time have nested condition have && them , use result in cmp instruction..

i think should work , not sure


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -