Skip to content

Instantly share code, notes, and snippets.

@smikes
Last active August 29, 2015 14:09
Show Gist options
  • Save smikes/a016acb988e2832fa2b6 to your computer and use it in GitHub Desktop.
Save smikes/a016acb988e2832fa2b6 to your computer and use it in GitHub Desktop.
Extracted `idamax_` function from femscripten example `lapack`
Namespace: A-H: (REAL 4) I-N: (INTEGER 4) O-Z: (REAL 4)
procedure name = idamax
symtree: 'dabs' || symbol: 'dabs'
type spec : (REAL 8)
attributes: (PROCEDURE INTRINSIC FUNCTION)
result: dabs
Formal arglist: a
symtree: 'dmax' || symbol: 'dmax'
type spec : (REAL 8)
attributes: (VARIABLE )
symtree: 'dx' || symbol: 'dx'
type spec : (REAL 8)
attributes: (VARIABLE DIMENSION DUMMY)
Array spec:(1 [0] AS_ASSUMED_SIZE 1 () )
symtree: 'i' || symbol: 'i'
type spec : (INTEGER 4)
attributes: (VARIABLE )
symtree: 'idamax' || symbol: 'idamax'
type spec : (INTEGER 4)
attributes: (PROCEDURE FUNCTION)
result: idamax
Formal arglist: n dx incx
symtree: 'incx' || symbol: 'incx'
type spec : (INTEGER 4)
attributes: (VARIABLE DUMMY)
symtree: 'ix' || symbol: 'ix'
type spec : (INTEGER 4)
attributes: (VARIABLE )
symtree: 'n' || symbol: 'n'
type spec : (INTEGER 4)
attributes: (VARIABLE DUMMY)
code:
ASSIGN idamax:idamax 0
IF (OR (< idamax:n 1) (<= idamax:incx 0))
RETURN
ENDIF
ASSIGN idamax:idamax 1
IF (= idamax:n 1)
RETURN
ENDIF
IF (= idamax:incx 1)
ASSIGN idamax:dmax __abs_r8[[((idamax:dx(1)))]]
DO idamax:i=2 idamax:n 1
IF (> __abs_r8[[((idamax:dx(idamax:i)))]] idamax:dmax)
ASSIGN idamax:idamax idamax:i
ASSIGN idamax:dmax __abs_r8[[((idamax:dx(idamax:i)))]]
ENDIF
END DO ELSE
ASSIGN idamax:ix 1
ASSIGN idamax:dmax __abs_r8[[((idamax:dx(1)))]]
ASSIGN idamax:ix (+ idamax:ix idamax:incx)
DO idamax:i=2 idamax:n 1
IF (> __abs_r8[[((idamax:dx(idamax:ix)))]] idamax:dmax)
ASSIGN idamax:idamax idamax:i
ASSIGN idamax:dmax __abs_r8[[((idamax:dx(idamax:ix)))]]
ENDIF
ASSIGN idamax:ix (+ idamax:ix idamax:incx)
END DO
ENDIF
RETURN
------------------------------------------
function _idamax_($n,$dx,$incx) {
$n = $n|0;
$dx = $dx|0;
$incx = $incx|0;
var $$expand_i1_val = 0, $$expand_i1_val1 = 0, $$expand_i1_val2 = 0, $$expand_i1_val3 = 0, $$retval$3C3E = 0, $0 = 0, $1 = 0, $10 = 0, $2 = 0, $3 = 0, $4 = 0, $5 = 0, $6 = 0, $7 = 0, $8 = 0, $9 = 0, $D$1497_19 = 0, $D$1501_28 = 0, $D$1501_28$expand_i1_val = 0, $D$1502_35 = 0;
var $D$1506_46 = 0, $D$1506_46$expand_i1_val = 0, $D$1509_10 = 0, $D$1511_12 = 0, $D$1512_14 = 0, $D$1512_48 = 0, $D$1512_49 = 0, $D$1512_8 = 0, $D$1513_13 = 0, $D$1516_15 = 0, $D$1519_17 = 0.0, $D$1523_21 = 0, $D$1524_22 = 0.0, $D$1525_23 = 0.0, $D$1526_24 = 0, $D$1526_24$expand_i1_val = 0, $D$1529_25 = 0, $D$1530_26 = 0.0, $D$1534_31 = 0.0, $D$1535_33 = 0;
var $D$1539_37 = 0, $D$1540_38 = 0.0, $D$1541_39 = 0.0, $D$1542_40 = 0, $D$1542_40$expand_i1_val = 0, $D$1545_41 = 0, $D$1546_42 = 0.0, $D$1548_44 = 0, $__result_idamax = 0, $ar1 = 0, $ar2 = 0, $ar4 = 0, $ar5 = 0, $dmax_1 = 0.0, $dmax_18 = 0.0, $dmax_2 = 0.0, $dmax_27 = 0.0, $dmax_3 = 0.0, $dmax_32 = 0.0, $dmax_4 = 0.0;
var $dmax_43 = 0.0, $dx_16 = 0, $dx_addr = 0, $i_29 = 0, $i_47 = 0, $i_5 = 0, $i_6 = 0, $incx_11 = 0, $incx_addr = 0, $ix_34 = 0, $ix_45 = 0, $ix_7 = 0, $n_9 = 0, $n_addr = 0, label = 0, sp = 0;
sp = STACKTOP;
STACKTOP = STACKTOP + 32|0; if ((STACKTOP|0) >= (STACK_MAX|0)) abort();
$n_addr = $n;
$dx_addr = $dx;
$incx_addr = $incx;
$n_9 = $n_addr;
$incx_11 = $incx_addr;
$dx_16 = $dx_addr;
$__result_idamax = 0;
$D$1509_10 = HEAP32[$n_9>>2]|0;
$0 = ($D$1509_10|0)<=(0);
do {
if ($0) {
label = 4;
} else {
$D$1511_12 = HEAP32[$incx_11>>2]|0;
$1 = ($D$1511_12|0)<=(0);
if ($1) {
label = 4;
} else {
$__result_idamax = 1;
$D$1513_13 = HEAP32[$n_9>>2]|0;
$2 = ($D$1513_13|0)==(1);
if ($2) {
$D$1512_14 = $__result_idamax;
$D$1512_8 = $D$1512_14;
break;
}
$D$1516_15 = HEAP32[$incx_11>>2]|0;
$3 = ($D$1516_15|0)==(1);
L8: do {
if ($3) {
HEAP32[tempDoublePtr>>2]=HEAP32[$dx_16>>2];HEAP32[tempDoublePtr+4>>2]=HEAP32[$dx_16+4>>2];$D$1519_17 = +HEAPF64[tempDoublePtr>>3];
$dmax_18 = (+Math_abs((+$D$1519_17)));
$D$1497_19 = HEAP32[$n_9>>2]|0;
$4 = (2)<=($D$1497_19|0);
if ($4) {
$dmax_1 = $dmax_18;$i_5 = 2;
while(1) {
$D$1523_21 = (($i_5) + -1)|0;
$ar1 = (($dx_16) + ($D$1523_21<<3)|0);
HEAP32[tempDoublePtr>>2]=HEAP32[$ar1>>2];HEAP32[tempDoublePtr+4>>2]=HEAP32[$ar1+4>>2];$D$1524_22 = +HEAPF64[tempDoublePtr>>3];
$D$1525_23 = (+Math_abs((+$D$1524_22)));
$D$1526_24 = $D$1525_23 > $dmax_1;
$D$1526_24$expand_i1_val = $D$1526_24&1;
$$expand_i1_val = 0;
$5 = ($D$1526_24$expand_i1_val<<24>>24)!=($$expand_i1_val<<24>>24);
if ($5) {
$__result_idamax = $i_5;
$D$1529_25 = (($i_5) + -1)|0;
$ar2 = (($dx_16) + ($D$1529_25<<3)|0);
HEAP32[tempDoublePtr>>2]=HEAP32[$ar2>>2];HEAP32[tempDoublePtr+4>>2]=HEAP32[$ar2+4>>2];$D$1530_26 = +HEAPF64[tempDoublePtr>>3];
$dmax_27 = (+Math_abs((+$D$1530_26)));
$dmax_2 = $dmax_27;
} else {
$dmax_2 = $dmax_1;
}
$D$1501_28 = ($i_5|0)==($D$1497_19|0);
$i_29 = (($i_5) + 1)|0;
$D$1501_28$expand_i1_val = $D$1501_28&1;
$$expand_i1_val1 = 0;
$6 = ($D$1501_28$expand_i1_val<<24>>24)!=($$expand_i1_val1<<24>>24);
if ($6) {
break L8;
}
$dmax_1 = $dmax_2;$i_5 = $i_29;
}
}
} else {
HEAP32[tempDoublePtr>>2]=HEAP32[$dx_16>>2];HEAP32[tempDoublePtr+4>>2]=HEAP32[$dx_16+4>>2];$D$1534_31 = +HEAPF64[tempDoublePtr>>3];
$dmax_32 = (+Math_abs((+$D$1534_31)));
$D$1535_33 = HEAP32[$incx_11>>2]|0;
$ix_34 = (($D$1535_33) + 1)|0;
$D$1502_35 = HEAP32[$n_9>>2]|0;
$7 = (2)<=($D$1502_35|0);
if ($7) {
$dmax_3 = $dmax_32;$i_6 = 2;$ix_7 = $ix_34;
while(1) {
$D$1539_37 = (($ix_7) + -1)|0;
$ar4 = (($dx_16) + ($D$1539_37<<3)|0);
HEAP32[tempDoublePtr>>2]=HEAP32[$ar4>>2];HEAP32[tempDoublePtr+4>>2]=HEAP32[$ar4+4>>2];$D$1540_38 = +HEAPF64[tempDoublePtr>>3];
$D$1541_39 = (+Math_abs((+$D$1540_38)));
$D$1542_40 = $D$1541_39 > $dmax_3;
$D$1542_40$expand_i1_val = $D$1542_40&1;
$$expand_i1_val2 = 0;
$8 = ($D$1542_40$expand_i1_val<<24>>24)!=($$expand_i1_val2<<24>>24);
if ($8) {
$__result_idamax = $i_6;
$D$1545_41 = (($ix_7) + -1)|0;
$ar5 = (($dx_16) + ($D$1545_41<<3)|0);
HEAP32[tempDoublePtr>>2]=HEAP32[$ar5>>2];HEAP32[tempDoublePtr+4>>2]=HEAP32[$ar5+4>>2];$D$1546_42 = +HEAPF64[tempDoublePtr>>3];
$dmax_43 = (+Math_abs((+$D$1546_42)));
$dmax_4 = $dmax_43;
} else {
$dmax_4 = $dmax_3;
}
$D$1548_44 = HEAP32[$incx_11>>2]|0;
$ix_45 = (($D$1548_44) + ($ix_7))|0;
$D$1506_46 = ($i_6|0)==($D$1502_35|0);
$i_47 = (($i_6) + 1)|0;
$D$1506_46$expand_i1_val = $D$1506_46&1;
$$expand_i1_val3 = 0;
$9 = ($D$1506_46$expand_i1_val<<24>>24)!=($$expand_i1_val3<<24>>24);
if ($9) {
break L8;
}
$dmax_3 = $dmax_4;$i_6 = $i_47;$ix_7 = $ix_45;
}
}
}
} while(0);
$D$1512_48 = $__result_idamax;
$D$1512_8 = $D$1512_48;
}
}
} while(0);
if ((label|0) == 4) {
$D$1512_49 = $__result_idamax;
$D$1512_8 = $D$1512_49;
}
$$retval$3C3E = $D$1512_8;
$10 = $$retval$3C3E;
STACKTOP = sp;return ($10|0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment