Skip to content
Snippets Groups Projects
Commit 4a9ef9c2 authored by Lazar Cristian-Stefan's avatar Lazar Cristian-Stefan
Browse files

Merge branch 'master' of gitlab.cs.pub.ro:iocla/tema3-2024-private

parents 8baf662d 37252e5e
No related branches found
No related tags found
No related merge requests found
...@@ -26,6 +26,7 @@ tasksNo = 3 ...@@ -26,6 +26,7 @@ tasksNo = 3
runExec = "./" runExec = "./"
checker = "checker" checker = "checker"
taskDir = "../src/task-" taskDir = "../src/task-"
bonusDir = "../src/bonus"
zipName = "VMChecker_Homework_2" zipName = "VMChecker_Homework_2"
...@@ -58,6 +59,30 @@ def test_task(taskNo): ...@@ -58,6 +59,30 @@ def test_task(taskNo):
rc = subprocess.call(f"make -C {taskString} clean > /dev/null 2> /dev/null", shell=useShell) rc = subprocess.call(f"make -C {taskString} clean > /dev/null 2> /dev/null", shell=useShell)
def test_bonus():
global points
taskString = f"{bonusDir}/"
procString = runExec + taskString + checker
rc = subprocess.call(f"make -C {taskString} > /dev/null 2> /dev/null", shell=useShell)
if rc != 0:
sys.stderr.write("make failed with status %d\n" % rc)
return
if not os.path.exists(procString):
sys.stderr.write("The file %s is missing and could not be created with \'make\'" % (taskString + checker))
return
checkerOutput = str(subprocess.check_output(f"cd {taskString} && ./checker", shell=useShell), encoding='utf-8')
print(checkerOutput)
taskScore = re.findall(r'\d+\.\d+', re.findall(fr'TASK BONUS SCORE: \d+\.\d+', checkerOutput)[0])[0]
points += float(taskScore)
rc = subprocess.call(f"make -C {taskString} clean > /dev/null 2> /dev/null", shell=useShell)
#=======================================================================# #=======================================================================#
if args.zip: if args.zip:
...@@ -73,6 +98,9 @@ points = 0 ...@@ -73,6 +98,9 @@ points = 0
if args.task == None and args.all: if args.task == None and args.all:
for task in range(1, tasksNo + 1): for task in range(1, tasksNo + 1):
test_task(task) test_task(task)
test_bonus()
elif args.task == 'b':
test_bonus()
elif args.task != None: elif args.task != None:
test_task(re.findall(r'\d', args.task)[0]) test_task(re.findall(r'\d', args.task)[0])
......
build: main.o functional.o
gcc -g -m64 -no-pie -fno-PIC -o functional main.o functional.o
main.o: main.c
gcc -g -no-pie -fno-PIC -c -m64 -o $@ $<
functional.o: functional.asm
nasm -g -f elf64 -o $@ $<
clean:
rm -f *.o functional out/*.out
# Bonus - x64 assembly
Acum ca Zoly si-a scris sistemul de detectie a intruziunilor
si isi poate apara toti prietenii pe care si i-a facut in tema 2,
se poate intoarce la marea ei pasiune: programarea functionala.
Totodata, spre deosebire de echipa de PCLP2, ea a inteles ca in
prezent se folosesc sisteme pe 64 de biti, iar cele pe 32 de biti
sunt foarte rare. Astfel, ea doreste sa implementeze functiile
`map` si `reduce` in assembly pe 64 de biti si folosin si numere
pe 64 de biti. Stiti de la
(tema 1)[https://gitlab.cs.pub.ro/iocla/tema-1-2024] ce sunt fiecare.
## Map
Antet map:
```
void map(int64_t *destination_array, int64_t *source_array, int64_t array_size, int64_t(*f)(int64_t));
```
Antet functie ce poate fi folosita pentru map:
```
int64_t map_func1(int64_t curr_elem);
```
Pseudocod map:
```
map(dst, src, n, to_apply):
for i de la 0 la n:
dst[i] = to_apply(src[i])
```
## Reduce
Antet reduce:
```
int64_t fold(int64_t *destination_array, int64_t *source_array, int64_t array_size, int64_t accumulator_initial_value, int64_t(*f)(int64_t, int64_t));
```
Antet functie ce poate fi folosita pentru reduce:
```
int64_t reduce_func1(int64_t accumulator, int64_t current_elem);
```
Pseudocod reduce:
```
reduce(src, n, accumulator_initial, to_apply):
acc = accumulator_initial
for i de la 0 la n:
acc = to_apply(acc, src[i])
```
TOTAL_POINTS=0
mkdir -p out
check_one() {
./functional < in/$1.in > out/$1.out
if cmp --silent -- out/$1.out ref/$1.ref; then
printf "Test %02d ................. PASSED: 1.0p\n" $1
TOTAL_POINTS=$(($TOTAL_POINTS + 1))
else
printf "Test %02d ................. FAILED: 0.0p\n" $1
fi
}
#if [[ -z "$1" ]]; then
echo "---------------TASK BONUS---------------"
for i in $(seq 1 20); do
check_one $i
done
printf "\nTASK BONUS SCORE: %.2f / 20.00\n\n" $TOTAL_POINTS
#else
# check_one $1
#fi
[BITS 64]
; nu uitati sa scrieti in feedback ca voiati
; assembly pe 64 de biti
section .text
global map
global reduce
map:
push rbp ; look at these fancy registers
mov rbp, rsp
; sa-nceapa turneu'
leave
ret
; int reduce(int *dst, int *src, int n, int acc_init, int(*f)(int, int));
; int f(int acc, int curr_elem);
reduce:
push rbp ; look at these fancy registers
mov rbp, rsp
; sa-nceapa festivalu'
leave
ret
map map_func1 5 979 884 971 870 58
map map_func2 50 350 744 9 930 835 196 763 109 61 589 669 51 280 606 233 699 897 938 109 773 535 140 875 273 251 845 216 967 902 62 434 920 735 778 33 59 372 369 177 256 689 25 85 118 978 70 26 42 747 941
reduce reduce_func1 5 22 383 262 131 833
reduce reduce_func1 10 959 161 753 189 536 709 2 395 604 45
reduce reduce_func1 15 814 254 156 995 38 5 353 961 631 643 761 766 116 293 346
reduce reduce_func1 25 501 32 316 460 565 785 620 758 47 924 271 774 412 884 637 723 158 485 982 231 96 677 704 324 859
reduce reduce_func1 50 105 25 459 808 896 971 131 531 599 800 403 499 528 336 148 896 983 350 266 269 621 994 430 669 19 717 572 983 144 687 59 260 35 135 166 175 99 465 651 238 521 939 726 957 33 253 239 732 456 76
reduce reduce_func2 5 257 83 606 234 640
reduce reduce_func2 10 811 820 639 727 369 263 701 434 286 539
reduce reduce_func2 15 769 5 155 37 394 419 165 114 525 742 90 247 105 103 21
reduce reduce_func2 25 187 769 238 108 223 26 534 686 476 465 318 549 658 390 218 702 929 779 987 216 747 826 445 436 524
map map_func1 10 94 87 370 856 174 754 829 686 875 316
reduce reduce_func2 50 22 596 606 53 903 429 952 538 596 186 943 97 680 822 492 375 20 532 984 944 122 626 376 297 707 955 382 316 20 896 702 423 104 108 314 204 861 794 689 846 17 832 463 62 421 653 498 475 214 911
map map_func1 15 258 621 218 622 37 596 698 163 442 654 403 823 741 881 522
map map_func1 25 973 381 558 959 456 515 275 923 37 892 29 373 477 955 327 930 390 434 914 906 539 169 574 182 242
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment