NewsWhat's New

Morphing Attributes

Morphing Attributes There is a possibility to select a subset of functions to be processed by Morpher. Such selection is ...

Articles, Oct. 24, 2011

ABI: problems of C++ programs compatibility at the binary interface level

Introduction The C++ language standard strictly defines semantics of all language constructs. However, it does not specify how these constructs ...

Articles, June 14, 2011

CFG arches meshing

features, March 15, 2010

Appendix A. Demo

demo

Description

This is a demo used for the feature descriptions in other articles.

Original Code

#include <stdio.h>

void InputArray(double Matrix[5][10], size_t rows, size_t cols);
void Process(double Matrix[5][10], double *out, size_t rows, size_t cols);
void OutArray(double *out, size_t N);

void InputArray(double Matrix[5][10], size_t rows, size_t cols) {
for (size_t R = 0; R < rows; R++) {
for (size_t C = 0; C < cols; C++) {
printf("Matrix[%d, %d] = ", R+1, C+1);
scanf("%lg", &Matrix[R][C]);
}
}
}

void Process(double Matrix[5][10], double *out,
size_t rows, size_t cols) {
for (size_t C = 0; C < cols; C++) {
int min = Matrix[0][C], max = Matrix[0][C];
for (size_t R = 1; R < rows; R++) {
if (Matrix[R][C] < min) {
min = Matrix[R][C];
}
if (Matrix[R][C] > max) {
max = Matrix[R][C];
}
}
out[C] = max - min;
}
}

void PrintArray(double *out, size_t N) {
for (size_t i = 0; i < N; i++) {
printf("out[%d] = %lg\n", i, out[i]);
}
}

int main(int argc, char **argv) {
size_t rows, cols;
double Matrix[5][10];
double out[10];

printf("rows: N = ");
scanf("%d", &rows);
if (rows > 5)
printf("\nNumber of rows must be 5 or less");

printf("cols: N = ");
scanf("%d", &cols);
if (cols > 10)
printf("\nNumber of columns must be 10 or less");

printf("\n");
InputArray(Matrix, rows, cols);
Process(Matrix, out, rows, cols);
PrintArray(out, cols);

printf("sizeof(void*) = %d\n", sizeof(void*));
return 0;
}

Compiled Code

	public _Process
.align 16
_Process proc near
push EBP
push EBX
push EDI
push ESI
sub ESP, 4
mov EAX, DWORD PTR [ESP + 36]
mov DWORD PTR [ESP], EAX
test EAX, EAX
jle .LBB2_10
.LBB2_1:
mov EAX, DWORD PTR [ESP + 24]
lea EAX, DWORD PTR [EAX + 80]
mov ECX, DWORD PTR [ESP + 32]
lea ECX, DWORD PTR [ECX - 1]
xor EDX, EDX
.LBB2_2:
mov ESI, DWORD PTR [ESP + 24]
cvttsd2si ESI, QWORD PTR [ESI + EDX]
lea EDI, DWORD PTR [EAX + EDX]
cmp DWORD PTR [ESP + 32], 1
jle .LBB2_11
.LBB2_3:
mov EBP, ECX
mov EBX, ESI
.align 16
.LBB2_4:
movsd XMM0, QWORD PTR [EDI]
cvtsi2sd XMM1, ESI
ucomisd XMM1, XMM0
jbe .LBB2_6
.LBB2_5:
cvttsd2si ESI, XMM0
.LBB2_6:
cvtsi2sd XMM1, EBX
ucomisd XMM0, XMM1
jbe .LBB2_8
.LBB2_7:
cvttsd2si EBX, XMM0
.LBB2_8:
add EDI, 80
dec EBP
jne .LBB2_4
.LBB2_9:
sub EBX, ESI
cvtsi2sd XMM0, EBX
mov ESI, DWORD PTR [ESP + 28]
movsd QWORD PTR [EDX + ESI], XMM0
add EDX, 8
dec DWORD PTR [ESP]
jne .LBB2_2
.LBB2_10:
add ESP, 4
pop ESI
pop EDI
pop EBX
pop EBP
ret
.LBB2_11:
mov EBX, ESI
jmp .LBB2_9
_Process endp