Commit ff6d53df authored by Julian Nahuel Vidal's avatar Julian Nahuel Vidal
Browse files

.

parent 870e56b1
CC=c99
CFLAGS= -Wall -Wextra -pedantic -O0 -g -lm -Wno-unused-variable -Wno-unused-parameter
NASM=nasm
NASMFLAGS=-f elf64 -g -F DWARF
all: main tester
OBJS := checkpoint2_c.o checkpoint2_asm.o checkpoint3_c.o checkpoint3_asm.o checkpoint4_c.o checkpoint4_asm.o
tester: tester.c $(OBJS)
$(CC) $(CFLAGS) $^ -o $@
main: main.c $(OBJS)
$(CC) $(CFLAGS) $^ -o $@
checkpoint2_c.o: checkpoint2.c checkpoints.h
$(CC) $(CFLAGS) -c $< -o $@
checkpoint2_asm.o: checkpoint2.asm checkpoints.h
$(NASM) $(NASMFLAGS) $< -o $@
checkpoint3_c.o: checkpoint3.c checkpoints.h
$(CC) $(CFLAGS) -c $< -o $@
checkpoint3_asm.o: checkpoint3.asm checkpoints.h
$(NASM) $(NASMFLAGS) $< -o $@
checkpoint4_c.o: checkpoint4.c checkpoints.h
$(CC) $(CFLAGS) -c $< -o $@
checkpoint4_asm.o: checkpoint4.asm checkpoints.h
$(NASM) $(NASMFLAGS) $< -o $@
clean:
rm -f *.o
rm -f main tester
rm -f salida.propios.*
extern sumar_c
extern restar_c
;########### SECCION DE DATOS
section .data
;########### SECCION DE TEXTO (PROGRAMA)
section .text
;########### LISTA DE FUNCIONES EXPORTADAS
global alternate_sum_4
global alternate_sum_4_simplified
global alternate_sum_8
global product_2_f
global alternate_sum_4_using_c
;########### DEFINICION DE FUNCIONES
; uint32_t alternate_sum_4(uint32_t x1, uint32_t x2, uint32_t x3, uint32_t x4);
; registros: x1[rdi], x2[rsi], x3[rdx], x4[rcx]
alternate_sum_4:
;prologo
; COMPLETAR
;recordar que si la pila estaba alineada a 16 al hacer la llamada
;con el push de RIP como efecto del CALL queda alineada a 8
push rbp
mov rbp, rsp
mov rax, rdi
sub rax, rsi
add rax, rdx
sub rax, rcx
;epilogo
; COMPLETAR
pop rbp
ret
; uint32_t alternate_sum_4_using_c(uint32_t x1, uint32_t x2, uint32_t x3, uint32_t x4);
; registros: x1[rdi], x2[rsi], x3[rdx], x4[rcx]
alternate_sum_4_using_c:
;prologo
push rbp ; alineado a 16
mov rbp,rsp
call restar_c
mov rdi, rax
mov rsi, rdx
call sumar_c
mov rdi, rax
mov rsi, rcx
call restar_c
;epilogo
pop rbp
ret
; uint32_t alternate_sum_4_simplified(uint32_t x1, uint32_t x2, uint32_t x3, uint32_t x4);
; registros: x1[rdi], x2[rsi], x3[rdx], x4[rcx]
alternate_sum_4_simplified:
mov rax, rdi
sub rax, rsi
add rax, rdx
sub rax, rcx
ret
; uint32_t alternate_sum_8(uint32_t x1, uint32_t x2, uint32_t x3, uint32_t x4, uint32_t x5, uint32_t x6, uint32_t x7, uint32_t x8);
; registros y pila: x1[rdi], x2[rsi], x3[rdx], x4[rcx], x5[r8], x6[r9], x7[rbp + 0x10], x8[rbp + 0x18]
alternate_sum_8:
;prologo
push rbp
mov rbp, rsp
; COMPLETAR
mov rax, rdi
sub rax, rsi
add rax, rdx
sub rax, rcx
add rax, r8
sub rax, r9
add rax, [rbp + 0x10]
sub rax, [rbp + 0x18]
;epilogo
pop rbp
ret
; SUGERENCIA: investigar uso de instrucciones para convertir enteros a floats y viceversa
;void product_2_f(uint32_t * destination, uint32_t x1, float f1);
;registros: destination[rdi], x1[rsi], f1[xmm0]
product_2_f:
push rbp
mov rbp, rsp
cvtsi2sd xmm1, rsi ; Convierto el int a float de 64 bits
cvtps2pd xmm0, xmm0 ; Convierto el float de 32 bits a float de 64 bits
mulsd xmm0, xmm1 ; Multiplico y como el resultado es un float, lo guarda en xmm0.
cvttsd2si r8, xmm0 ; Trunco el resultado(lo convierto a entero de 64)
mov [rdi], r8d ; r8d son los 32 bits menos significativos del r8 (es decir, del 0 al 31)
pop rbp
ret
#include "checkpoints.h"
uint32_t sumar_c(uint32_t a,uint32_t b){
return a + b;
}
uint32_t restar_c(uint32_t a,uint32_t b){
return a - b;
}
/* Pueden programar alguna rutina auxiliar del checkpoint 2 acá */
;########### SECCION DE DATOS
section .data
;########### SECCION DE TEXTO (PROGRAMA)
section .text
;########### LISTA DE FUNCIONES EXPORTADAS
global complex_sum_z
global packed_complex_sum_z
global product_9_f
;########### DEFINICION DE FUNCIONES
;extern uint32_t complex_sum_z(complex_item *arr, uint32_t arr_length);
;registros: arr[rdi], arr_length[rsi]
complex_sum_z:
push rbp
mov rbp, rsp
xor rax, rax
.cycle:
add rax, [rdi+24]
add rdi, 32
dec rsi
cmp rsi, 0 ; si longitud = 0 salgo del ciclo
jne .cycle
pop rbp
ret
;extern uint32_t packed_complex_sum_z(packed_complex_item *arr, uint32_t arr_length);
;registros: arr[?], arr_length[?]
packed_complex_sum_z:
push rbp
mov rbp, rsp
xor rax, rax
.cycle:
add rax, [rdi+20]
add rdi, 24
dec rsi
cmp rsi, 0 ; si longitud = 0 salgo del ciclo
jne .cycle
pop rbp
ret
;extern void product_9_f(uint32_t * destination
;, uint32_t x1, float f1, uint32_t x2, float f2, uint32_t x3, float f3, uint32_t x4, float f4
;, uint32_t x5, float f5, uint32_t x6, float f6, uint32_t x7, float f7, uint32_t x8, float f8
;, uint32_t x9, float f9);
;registros y pila: destination[rdi], x1[rsi], f1[xmm0], x2[rdx], f2[xmm1], x3[rcx], f3[xmm2], x4[r8], f4[xmm3]
; , x5[r9], f5[xmm4], x6[rbp+0x10], f6[xmm5], x7[rbp+0x18], f7[xmm6], x8[rbp+0x20], f8[xmm7],
; , x9[rbp+0x28], f9[rbp+0x30]
product_9_f:
;prologo
push rbp
mov rbp, rsp
;convertimos los flotantes de cada registro xmm en doubles
cvtss2sd xmm0, xmm0 ; single precision to double precision float
cvtss2sd xmm1, xmm1
cvtss2sd xmm2, xmm2
cvtss2sd xmm3, xmm3
cvtss2sd xmm4, xmm4
cvtss2sd xmm5, xmm5
cvtss2sd xmm6, xmm6
cvtss2sd xmm7, xmm7
;multiplicamos los doubles en xmm0 <- xmm0 * xmm1, xmm0 * xmm2 , ...
mulsd xmm0, xmm1 ; multiplicacion de doubles
mulsd xmm0, xmm2
mulsd xmm0, xmm3
mulsd xmm0, xmm4
mulsd xmm0, xmm5
mulsd xmm0, xmm6
mulsd xmm0, xmm7
cvtss2sd xmm1, [rbp+0x30] ; xmm1 = double([rbp+0x30] = f9)
mulsd xmm0, xmm1
; convertimos los enteros en doubles y los multiplicamos por xmm0.
push rsi
cvtpi2pd xmm1, [rbp-0x08] ; int to double
mulsd xmm0, xmm1
pop rsi
push rdx
cvtpi2pd xmm1, [rbp-0x08]
mulsd xmm0, xmm1
pop rdx
push rcx
cvtpi2pd xmm1, [rbp-0x08]
mulsd xmm0, xmm1
pop rcx
push r8
cvtpi2pd xmm1, [rbp-0x08]
mulsd xmm0, xmm1
pop r8
push r9
cvtpi2pd xmm1, [rbp-0x08]
mulsd xmm0, xmm1
pop r9
cvtpi2pd xmm1, [rbp+0x10]
mulsd xmm0, xmm1
cvtpi2pd xmm1, [rbp+0x18]
mulsd xmm0, xmm1
cvtpi2pd xmm1, [rbp+0x20]
mulsd xmm0, xmm1
cvtpi2pd xmm1, [rbp+0x28]
mulsd xmm0, xmm1
movsd [rdi], xmm0
; epilogo
pop rbp
ret
#include "checkpoints.h"
/* Pueden programar alguna rutina auxiliar del checkpoint 3 acá */
extern malloc
extern free
extern fprintf
section .data
text db "NULL"
section .text
global strCmp
global strClone
global strDelete
global strPrint
global strLen
; ** String **
; int32_t strCmp(char* a, char* b)
strCmp:
push rbp
mov rbp, rsp
.cmpLoop:
mov al, byte [rsi]
cmp byte [rdi], al
jg .rdiMayor
jl .rsiMayor
cmp byte [rdi], 0x00
je .iguales
inc rdi
inc rsi
jmp .cmpLoop
.rdiMayor:
mov rax, -1
jmp .end
.rsiMayor:
mov rax, 1
jmp .end
.iguales:
mov rax, 0
jmp .end
.end:
pop rbp
ret
; char* strClone(char* a [rdi])
strClone:
push rbp
mov rbp, rsp
push r12
push r13
mov r12, rdi ; ---> r12 = char* a
call strLen ; ---> rax = lenght(char* a)
mov r13, rax ; ---> r13 = lenght(char* a)
mov rdi, rax
inc rdi ; ---> (ultimo byte)
call malloc wrt ..plt ; ---> rax = void* b (posicion 0)
xor rcx, rcx ; ---> rcx = 0
.copyLoop:
cmp rcx, r13 ; ---> comparo rcx con lenght(char* a)
je .end
mov dl, byte[r12]
mov byte [rax + rcx], dl ; ---> copio byte a byte
inc rcx
inc r12
jmp .copyLoop
.end:
mov byte [rax + rcx], 0x00
pop r13
pop r12
pop rbp
ret
; void strDelete(char* a [rdi])
strDelete:
push rbp
mov rbp, rsp
call free wrt ..plt
pop rbp
ret
; void strPrint(char* a [rdi], FILE* pFile [rsi])
strPrint:
push rbp
mov rbp, rsp
push r12
push r13
mov r12, rdi
mov r13, rsi
call strLen
cmp rax, 0x00 ; length(a) = 0?
je .printNULL
jmp .end
.printNULL:
mov r12, text ; r12 = "NULL"
.end:
mov rdi, r13 ; rdi = pFile
mov rsi, r12 ; rsi = char* a or "NULL"
xor rax, rax
call fprintf wrt ..plt
pop r13
pop r12
pop rbp
ret
; uint32_t strLen(char* a)
strLen:
push rbp
mov rbp, rsp
xor rax, rax
.lenLoop:
cmp byte [rdi], 0x00
je .end
inc rax
inc rdi
jmp .lenLoop
.end:
pop rbp
ret
#include "checkpoints.h"
/* Pueden programar alguna rutina auxiliar del checkpoint 4 acá */
#ifndef CHECKPOINTS_H
#define CHECKPOINTS_H
/*
Sobre Ifndef
======
ifndef es una construcción de pre compilación que sólo incorpora el texto entre "#ifndef SYMBOL ... #endif sólo si el símbolo SYMBOL aún no fue definido
se suele utilizar esta combinación de
#ifndef SYMBOL
#define SYMBOL
para que el pre-procesador sólo evalúe una vez los encabezados antes de comenzar la compilación
Sobre includes
==============
Recuerden que los include son directivas que incluyen,
en este caso, las definiciones y encabezados de las funciones de uso común que queremos
utilizar en nuestro programa
*/
#include <stdio.h> //encabezado de funciones de entrada y salida fopen, fclose, fgetc, printf, fprintf ...
#include <stdlib.h> //biblioteca estándar, atoi, atof, rand, srand, abort, exit, system, NULL, malloc, calloc, realloc...
#include <stdint.h> //contiene la definición de tipos enteros ligados a tamaños int8_t, int16_t, uint8_t,...
#include <ctype.h> //contiene funciones relacionadas a caracteres, isdigit, islower, tolower...
#include <string.h> //contiene las funciones relacionadas a strings, memcmp, strcat, memset, memmove, strlen,strstr...
#include <math.h> //define funciones matemáticas como cos, sin, abs, sqrt, log...
#include <stdbool.h> //contiene las definiciones de datos booleanos, true (1), false (0)
#include <unistd.h> //define constantes y tipos standard, NULL, R_OK, F_OK, STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO...
#include <assert.h> //provee la macro assert que evalúa una condición, y si no se cumple provee información diagnóstica y aborta la ejecución
//*************************************
//Declaración de estructuras
//*************************************
typedef struct complex_item_str{
uint64_t w;
uint32_t x;
uint64_t y;
uint32_t z;
} complex_item;
typedef struct __attribute__((__packed__)) packed_complex_item_str{
uint64_t w;
uint32_t x;
uint64_t y;
uint32_t z;
} packed_complex_item;
//****************************************
//Declaración de funciones de checkpoint 2
//****************************************
// devuelve el resultado de la operación x1 - x2 + x3 - x4
uint32_t alternate_sum_4(uint32_t x1, uint32_t x2, uint32_t x3, uint32_t x4);
// devuelve el resultado la operación x1 - x2 + x3 - x4, usando obligatoriamente para las operaciones
// las funciones provistas sumar_c y restar_c
int32_t alternate_sum_4_using_c(uint32_t x1,uint32_t x2,uint32_t x3,uint32_t x4);
// devuelve el resultado la operación x1 - x2 + x3 - x4. Esta función no crea ni el epílogo ni el prólogo
uint32_t alternate_sum_4_simplified(uint32_t x1, uint32_t x2, uint32_t x3, uint32_t x4);
// devuelve el resultado de la operación x1 - x2 + x3 - x4 + x5 - x6 + x7 - x8
uint32_t alternate_sum_8(uint32_t x1, uint32_t x2, uint32_t x3, uint32_t x4, uint32_t x5, uint32_t x6, uint32_t x7, uint32_t x8);
// Hace la multiplicación x1 * f1 y el resultado se almacena en destination. Los dígitos decimales del resultado se eliminan mediante truncado
void product_2_f(uint32_t * destination, uint32_t x1, float f1);
//****************************************
//Declaración de funciones de checkpoint 3
//****************************************
// Devuelve la suma del atributo z de todos los complex_item's del array
uint32_t complex_sum_z(complex_item *arr, uint32_t arr_length);
// Devuelve la suma del atributo z de todos los packed_complex_item's del array
uint32_t packed_complex_sum_z(packed_complex_item *arr, uint32_t arr_length);
// Convierte todos los parámetros a double, realiza la multiplicación de todos ellos y
// aloja el resultado en destination.
// Nota de implementación: Ir multiplicando todos los floats en primer lugar, luego,
// ir multiplicando ese resultado con cada entero, uno a uno.
void product_9_f(double * destination
, uint32_t x1, float f1, uint32_t x2, float f2, uint32_t x3, float f3, uint32_t x4, float f4
, uint32_t x5, float f5, uint32_t x6, float f6, uint32_t x7, float f7, uint32_t x8, float f8
, uint32_t x9, float f9);
//****************************************
//Declaración de funciones de checkpoint 4
//****************************************
/* String */
// Compara dos strings en orden lexicográfico. Ver https://es.wikipedia.org/wiki/Orden_lexicografico.
// Debe retornar:
// 0 si son iguales
// 1 si a < b
//-1 si a > b
int32_t strCmp(char* a, char* b);
// Genera una copia del string pasado por parámetro. El puntero pasado siempre es válido
// aunque podría corresponderse a la cadena vacía.
char* strClone(char* a);
// Borra el string pasado por parámetro. Esta función es equivalente a la función free.
void strDelete(char* a);
// Escribe el string en el stream indicado a través de pFile. Si el string es vacío debe escribir "NULL"
void strPrint(char* a, FILE* pFile);
// Retorna la cantidad de caracteres distintos de cero del \emph{string} pasado por parámetro.
uint32_t strLen(char* a);
//***********************************
//Declaración de funciones auxiliares
//***********************************
uint32_t sumar_c(uint32_t a, uint32_t b);
uint32_t restar_c(uint32_t a, uint32_t b);
#endif
File deleted
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <assert.h>
#include "checkpoints.h"
int main (void){
return 0;
}
#!/usr/bin/env bash
reset
command -v valgrind > /dev/null
if [ $? -ne 0 ]; then
echo "ERROR: No se encuentra valgrind."
exit 1
fi
make main
if [ $? -ne 0 ]; then
echo "ERROR: Error de compilacion."
exit 1
fi
valgrind --show-reachable=yes --leak-check=full --error-exitcode=1 ./main
if [ $? -ne 0 ]; then
echo " **Error de memoria"
exit 1
fi
#!/usr/bin/env bash
reset
echo " "
echo "**Compilando"
make tester
if [ $? -ne 0 ]; then
echo " **Error de compilacion"
exit 1
fi
echo " "
echo "**Corriendo Valgrind"
command -v valgrind > /dev/null
if [ $? -ne 0 ]; then
echo "ERROR: No se encuentra valgrind."
exit 1
fi
valgrind --show-reachable=yes --leak-check=full --error-exitcode=1 ./tester
if [ $? -ne 0 ]; then
echo " **Error de memoria"
exit 1
fi
echo " "
echo "**Corriendo diferencias con la catedra"
DIFFER="diff -d"
ERRORDIFF=0
$DIFFER salida.propios.chk2.txt salida.catedra.chk2.txt > /tmp/diff1
if [ $? -ne 0 ]; then
echo " **Discrepancia en el checkpoint 2"
ERRORDIFF=1
fi
$DIFFER salida.propios.chk3.txt salida.catedra.chk3.txt > /tmp/diff2
if [ $? -ne 0 ]; then
echo " **Discrepancia en el checkpoint 3"
ERRORDIFF=1
fi
$DIFFER salida.propios.chk4.txt salida.catedra.chk4.txt > /tmp/diff2
if [ $? -ne 0 ]; then
echo " **Discrepancia en el checkpoint 3"
ERRORDIFF=1
fi
echo " "
if [ $ERRORDIFF -eq 0 ]; then
echo "**Todos los tests pasan"
fi
echo " "
This diff is collapsed.
This diff is collapsed.
== String ==
Clonar
7 - Omega 4
0 - NULL
Comparar
strCmp(Omega 4,Omega 4) --> 0
strCmp(,) --> 0
strCmp(Palaven,Omega 4) --> -1
strCmp(Omega 4,Palaven) --> 1
strCmp(Feros,Omega 4) --> 1
strCmp(Palaven,Feros) --> -1
strCmp(Feros,Palaven) --> 1
strLen(sar) --> 3
strCmp(sar,sar) --> 0
strCmp(sar,23) --> -1
strCmp(sar,taaa) --> 1
strCmp(sar,tbb) --> 1
strCmp(sar,tix) --> 1
strCmp(sar,taaab) --> 1
strCmp(sar,taa0) --> 1
strCmp(sar,tbb) --> 1
strCmp(sar,) --> -1
strLen(23) --> 2
strCmp(23,sar) --> 1
strCmp(23,23) --> 0
strCmp(23,taaa) --> 1
strCmp(23,tbb) --> 1
strCmp(23,tix) --> 1
strCmp(23,taaab) --> 1
strCmp(23,taa0) --> 1
strCmp(23,tbb) --> 1
strCmp(23,) --> -1
strLen(taaa) --> 4
strCmp(taaa,sar) --> -1
strCmp(taaa,23) --> -1
strCmp(taaa,taaa) --> 0
strCmp(taaa,tbb) --> 1
strCmp(taaa,tix) --> 1
strCmp(taaa,taaab) --> 1
strCmp(taaa,taa0) --> -1
strCmp(taaa,tbb) --> 1
strCmp(taaa,) --> -1
strLen(tbb) --> 3
strCmp(tbb,sar) --> -1
strCmp(tbb,23) --> -1
strCmp(tbb,taaa) --> -1
strCmp(tbb,tbb) --> 0
strCmp(tbb,tix) --> 1
strCmp(tbb,taaab) --> -1
strCmp(tbb,taa0) --> -1
strCmp(tbb,tbb) --> 0
strCmp(tbb,) --> -1
strLen(tix) --> 3
strCmp(tix,sar) --> -1
strCmp(tix,23) --> -1
strCmp(tix,taaa) --> -1
strCmp(tix,tbb) --> -1
strCmp(tix,tix) --> 0
strCmp(tix,taaab) --> -1
strCmp(tix,taa0) --> -1
strCmp(tix,tbb) --> -1
strCmp(tix,) --> -1
strLen(taaab) --> 5
strCmp(taaab,sar) --> -1
strCmp(taaab,23) --> -1
strCmp(taaab,taaa) --> -1
strCmp(taaab,tbb) --> 1
strCmp(taaab,tix) --> 1
strCmp(taaab,taaab) --> 0
strCmp(taaab,taa0) --> -1
strCmp(taaab,tbb) --> 1
strCmp(taaab,) --> -1
strLen(taa0) --> 4
strCmp(taa0,sar) --> -1
strCmp(taa0,23) --> -1
strCmp(taa0,taaa) --> 1
strCmp(taa0,tbb) --> 1
strCmp(taa0,tix) --> 1
strCmp(taa0,taaab) --> 1
strCmp(taa0,taa0) --> 0
strCmp(taa0,tbb) --> 1
strCmp(taa0,) --> -1
strLen(tbb) --> 3
strCmp(tbb,sar) --> -1
strCmp(tbb,23) --> -1
strCmp(tbb,taaa) --> -1
strCmp(tbb,tbb) --> 0
strCmp(tbb,tix) --> 1
strCmp(tbb,taaab) --> -1
strCmp(tbb,taa0) --> -1
strCmp(tbb,tbb) --> 0
strCmp(tbb,) --> -1
strLen() --> 0
strCmp(,sar) --> 1
strCmp(,23) --> 1
strCmp(,taaa) --> 1
strCmp(,tbb) --> 1
strCmp(,tix) --> 1
strCmp(,taaab) --> 1
strCmp(,taa0) --> 1
strCmp(,tbb) --> 1
strCmp(,) --> 0
This diff is collapsed.
This diff is collapsed.
== String ==
Clonar
7 - Omega 4
0 - NULL
Comparar
strCmp(Omega 4,Omega 4) --> 0
strCmp(,) --> 0
strCmp(Palaven,Omega 4) --> -1
strCmp(Omega 4,Palaven) --> 1
strCmp(Feros,Omega 4) --> 1
strCmp(Palaven,Feros) --> -1
strCmp(Feros,Palaven) --> 1
strLen(sar) --> 3
strCmp(sar,sar) --> 0
strCmp(sar,23) --> -1
strCmp(sar,taaa) --> 1
strCmp(sar,tbb) --> 1
strCmp(sar,tix) --> 1
strCmp(sar,taaab) --> 1
strCmp(sar,taa0) --> 1
strCmp(sar,tbb) --> 1
strCmp(sar,) --> -1
strLen(23) --> 2
strCmp(23,sar) --> 1
strCmp(23,23) --> 0
strCmp(23,taaa) --> 1
strCmp(23,tbb) --> 1
strCmp(23,tix) --> 1
strCmp(23,taaab) --> 1
strCmp(23,taa0) --> 1
strCmp(23,tbb) --> 1
strCmp(23,) --> -1
strLen(taaa) --> 4
strCmp(taaa,sar) --> -1
strCmp(taaa,23) --> -1
strCmp(taaa,taaa) --> 0
strCmp(taaa,tbb) --> 1
strCmp(taaa,tix) --> 1
strCmp(taaa,taaab) --> 1
strCmp(taaa,taa0) --> -1
strCmp(taaa,tbb) --> 1
strCmp(taaa,) --> -1
strLen(tbb) --> 3
strCmp(tbb,sar) --> -1
strCmp(tbb,23) --> -1
strCmp(tbb,taaa) --> -1
strCmp(tbb,tbb) --> 0
strCmp(tbb,tix) --> 1
strCmp(tbb,taaab) --> -1
strCmp(tbb,taa0) --> -1
strCmp(tbb,tbb) --> 0
strCmp(tbb,) --> -1
strLen(tix) --> 3
strCmp(tix,sar) --> -1
strCmp(tix,23) --> -1
strCmp(tix,taaa) --> -1
strCmp(tix,tbb) --> -1
strCmp(tix,tix) --> 0
strCmp(tix,taaab) --> -1
strCmp(tix,taa0) --> -1
strCmp(tix,tbb) --> -1
strCmp(tix,) --> -1
strLen(taaab) --> 5
strCmp(taaab,sar) --> -1
strCmp(taaab,23) --> -1
strCmp(taaab,taaa) --> -1
strCmp(taaab,tbb) --> 1
strCmp(taaab,tix) --> 1
strCmp(taaab,taaab) --> 0
strCmp(taaab,taa0) --> -1
strCmp(taaab,tbb) --> 1
strCmp(taaab,) --> -1
strLen(taa0) --> 4
strCmp(taa0,sar) --> -1
strCmp(taa0,23) --> -1
strCmp(taa0,taaa) --> 1
strCmp(taa0,tbb) --> 1
strCmp(taa0,tix) --> 1
strCmp(taa0,taaab) --> 1
strCmp(taa0,taa0) --> 0
strCmp(taa0,tbb) --> 1
strCmp(taa0,) --> -1
strLen(tbb) --> 3
strCmp(tbb,sar) --> -1
strCmp(tbb,23) --> -1
strCmp(tbb,taaa) --> -1
strCmp(tbb,tbb) --> 0
strCmp(tbb,tix) --> 1
strCmp(tbb,taaab) --> -1
strCmp(tbb,taa0) --> -1
strCmp(tbb,tbb) --> 0
strCmp(tbb,) --> -1
strLen() --> 0
strCmp(,sar) --> 1
strCmp(,23) --> 1
strCmp(,taaa) --> 1
strCmp(,tbb) --> 1
strCmp(,tix) --> 1
strCmp(,taaab) --> 1
strCmp(,taa0) --> 1
strCmp(,tbb) --> 1
strCmp(,) --> 0
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <ctype.h>
#include <assert.h>
#include <math.h>
#include <stdbool.h>
#include <float.h>
#include "checkpoints.h"
#define ARR_LENGTH 4
#define ROLL_LENGTH 10
#define RUN(filename, action) pfile=fopen(filename,"a"); action; fclose(pfile);
#define NL(filename) pfile=fopen(filename,"a"); fprintf(pfile,"\n"); fclose(pfile);
char *filename_chk2 = "salida.propios.chk2.txt";
char *filename_chk3 = "salida.propios.chk3.txt";
char *filename_chk4 = "salida.propios.chk4.txt";
void test_checkpoint2(char* filename);
void test_checkpoint3(char* filename);
void test_checkpoint4(char* filename);
int main() {
srand(0);
remove(filename_chk2);
remove(filename_chk3);
remove(filename_chk4);
test_checkpoint2(filename_chk2);
test_checkpoint3(filename_chk3);
test_checkpoint4(filename_chk4);
return 0;
}
static uint32_t x[ROLL_LENGTH];
static float f[ROLL_LENGTH];
void shuffle(uint32_t max){
for(int i = 0; i < ROLL_LENGTH; i++){
x[i] = (uint32_t) rand() % max;
f[i] = ((float)rand()/(float)(RAND_MAX)) * max;
}
}
void test_checkpoint2(char* filename) {
FILE* pfile;
shuffle(1000);
RUN(filename, fprintf(pfile, "== Checkpoint 2 ==\n");) NL(filename)
RUN(filename, fprintf(pfile, "alternate_sum_4\n");) NL(filename)
for(int i = 0; i < 100; i++){
shuffle(1000);
RUN(filename, fprintf(pfile, "alternate_sum_4(%u,%u,%u,%u) -> %u", x[0],x[1],x[2],x[3], alternate_sum_4(x[0],x[1],x[2],x[3]));) NL(filename)
}
NL(filename) RUN(filename, fprintf(pfile, "alternate_sum_4_using_c\n");) NL(filename)
for(int i = 0; i < 100; i++){
shuffle(1000);
RUN(filename, fprintf(pfile, "alternate_sum_4_using_c(%u,%u,%u,%u) -> %u", x[0],x[1],x[2],x[3], alternate_sum_4_using_c(x[0],x[1],x[2],x[3]));) NL(filename)
}
NL(filename) RUN(filename, fprintf(pfile, "alternate_sum_4_simplified\n");) NL(filename)
for(int i = 0; i < 100; i++){
shuffle(1000);
RUN(filename, fprintf(pfile, "alternate_sum_4_simplified(%u,%u,%u,%u) -> %u", x[0],x[1],x[2],x[3], alternate_sum_4_simplified(x[0],x[1],x[2],x[3]));) NL(filename)
}
NL(filename) RUN(filename, fprintf(pfile, "alternate_sum_8\n");) NL(filename)
for(int i = 0; i < 100; i++){
shuffle(1000);
RUN(filename, fprintf(pfile, "alternate_sum_8(%u,%u,%u,%u,%u,%u,%u,%u) -> %u", x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7], alternate_sum_8(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7]));) NL(filename)
}
NL(filename) RUN(filename, fprintf(pfile, "product_2_f\n");) NL(filename)
for(int i = 0; i < 100; i++){
shuffle(1000);
uint32_t result;
product_2_f(&result, x[0], f[0]);
RUN(filename, fprintf(pfile, "product_2_f(&dest,%u,%.2f) -> dest: %u", x[0],f[0],result);) NL(filename)
}
}
void test_checkpoint3(char* filename) {
FILE* pfile;
RUN(filename, fprintf(pfile, "== Checkpoint 3 ==\n");) NL(filename)
RUN(filename, fprintf(pfile, "complex_sum_z\n");) NL(filename)
complex_item complex_arr[ARR_LENGTH];
for(int i=0; i< 100; i++){
shuffle(1000);
for(int j = 0; j < ARR_LENGTH; j++){
complex_arr[j].w = 0;
complex_arr[j].x = 0;
complex_arr[j].y = 0;
complex_arr[j].z = x[j];
}
RUN(filename, fprintf(pfile, "complex_sum_z(%u,%u,%u,%u) -> %u", x[0],x[1],x[2],x[3], complex_sum_z(complex_arr,ARR_LENGTH));) NL(filename)
}
NL(filename) RUN(filename, fprintf(pfile, "packed_complex_sum_z\n");) NL(filename)
packed_complex_item packed_complex_arr[ARR_LENGTH];
for(int i=0; i< 100; i++){
shuffle(1000);
for(int j = 0; j < ARR_LENGTH; j++){
packed_complex_arr[j].w = 0;
packed_complex_arr[j].x = 0;
packed_complex_arr[j].y = 0;
packed_complex_arr[j].z = x[j];
}
RUN(filename, fprintf(pfile, "packed_complex_sum_z(%u,%u,%u,%u) -> %u", x[0],x[1],x[2],x[3], packed_complex_sum_z(packed_complex_arr, ARR_LENGTH));) NL(filename)
}
NL(filename) RUN(filename, fprintf(pfile, "product_9_f\n");) NL(filename)
for(int i = 0; i < 100; i++){
shuffle(1000);
double result;
product_9_f(&result,x[0],f[0],x[1],f[1],x[2],f[2],x[3],f[3],x[4],f[4],x[5],f[5],x[6],f[6],x[7],f[7],x[8],f[8]);
RUN(filename, fprintf(pfile, "product_9_f(&dest,%u,%.2f,%u,%.2f,%u,%.2f,%u,%.2f,%u,%.2f,%u,%.2f,%u,%.2f,%u,%.2f,%u,%.2f) -> dest: %.2f",
x[0],f[0],x[1],f[1],x[2],f[2],x[3],f[3],x[4],f[4],x[5],f[5],x[6],f[6],x[7],f[7],x[8],f[8], result);) NL(filename)
}
}
void test_checkpoint4(char* filename) {
FILE* pfile;
char* a = "Omega 4";
char* b = "Palaven";
char* c = "Feros";
char* n = "";
RUN(filename, fprintf(pfile, "== String ==\n");) NL(filename)
// Clonar
RUN(filename, fprintf(pfile, "Clonar\n");) NL(filename)
char* ac = strClone(a);
assert(a != ac); assert(strCmp(a,ac) == 0);
RUN(filename, fprintf(pfile, "%i - ", strLen(ac));) RUN(filename, strPrint(ac,pfile);) NL(filename)
char* nc = strClone(n);
assert(n != nc); assert(strCmp(n,nc) == 0);
RUN(filename, fprintf(pfile, "%i - ", strLen(nc));) RUN(filename, strPrint(nc,pfile);) NL(filename)
NL(filename)
//Borrar
strDelete(ac);
strDelete(nc);
//Comparar
RUN(filename, fprintf(pfile, "Comparar\n");) NL(filename)
RUN(filename, fprintf(pfile,"strCmp(%s,%s) --> %d\n", a, a, strCmp(a,a));)
RUN(filename, fprintf(pfile,"strCmp(%s,%s) --> %d\n", n, n, strCmp(n,n));)
RUN(filename, fprintf(pfile,"strCmp(%s,%s) --> %d\n", b, a, strCmp(b,a));)
RUN(filename, fprintf(pfile,"strCmp(%s,%s) --> %d\n", a, b, strCmp(a,b));)
RUN(filename, fprintf(pfile,"strCmp(%s,%s) --> %d\n", c, a, strCmp(c,a));)
RUN(filename, fprintf(pfile,"strCmp(%s,%s) --> %d\n", b, c, strCmp(b,c));)
RUN(filename, fprintf(pfile,"strCmp(%s,%s) --> %d\n", c, b, strCmp(c,b));)
char* texts[9] = {"sar","23","taaa","tbb","tix", "taaab", "taa0", "tbb", ""};
for(int i=0; i<9; i++) {
RUN(filename, fprintf(pfile,"strLen(%s) --> %d\n",texts[i],strLen(texts[i])))
for(int j=0; j<9; j++) {
RUN(filename, fprintf(pfile,"strCmp(%s,%s) --> %d\n",texts[i],texts[j],strCmp(texts[i],texts[j])))
}
}
NL(filename)
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment