Difference between revisions of "Optimization Topics/Exercise 02"

From Wiki**3

< Optimization Topics
(Created page with "Considere a seguinte função em C: # Que optimizações independentes da máquina são possíveis? # Traduza-a para Postfix optimizado. <c> int *fun(int *a, int *b, int len) { ...")
 
Line 3: Line 3:
 
# Traduza-a para Postfix optimizado.
 
# Traduza-a para Postfix optimizado.
  
<c>
+
<source lang="c">
 
int *fun(int *a, int *b, int len) {
 
int *fun(int *a, int *b, int len) {
 
   int *c = (int *)malloc(2 * 4), i;
 
   int *c = (int *)malloc(2 * 4), i;
Line 10: Line 10:
 
   return c;
 
   return c;
 
}
 
}
</c>
+
</source>
  
 
Instruções Postfix:
 
Instruções Postfix:
  
<text>
+
<source lang="text">
 
directivas: text data rodata bss align label extrn globl const str char id byte double
 
directivas: text data rodata bss align label extrn globl const str char id byte double
 
acesso: addr addra addrv local loca locv load load2 ldchr store store2 stchr  
 
acesso: addr addra addrv local loca locv load load2 ldchr store store2 stchr  
Line 21: Line 21:
 
bit a bit: rotl rotr shtl shtru shtrs and or not xor
 
bit a bit: rotl rotr shtl shtru shtrs and or not xor
 
funções/saltos: call ret start enter leave trash jmp jz jnz branch leap
 
funções/saltos: call ret start enter leave trash jmp jz jnz branch leap
</text>
+
</source>

Revision as of 13:57, 12 February 2019

Considere a seguinte função em C:

  1. Que optimizações independentes da máquina são possíveis?
  2. Traduza-a para Postfix optimizado.
int *fun(int *a, int *b, int len) {
  int *c = (int *)malloc(2 * 4), i;
  for (i = 0; i < (len < 2 ? len : 2); i++)
    c[i] = a[i] + b[i];
  return c;
}

Instruções Postfix:

directivas: text data rodata bss align label extrn globl const str char id byte double
acesso: addr addra addrv local loca locv load load2 ldchr store store2 stchr 
          alloc dup swap push pop int sp
aritmética/lógica: add dadd sub dsub mul dmul div ddiv mod neg gt ge lt le eq ne cmp
bit a bit: rotl rotr shtl shtru shtrs and or not xor
funções/saltos: call ret start enter leave trash jmp jz jnz branch leap