Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lab/interactiune-c-assembly: Add inline exercises #193

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

andreia-oca
Copy link
Contributor

This PR adds the following exercises for interactiunea-c-assembly lab:

  • 1-inline-for
  • 2-inline-rotate + solution
  • 3-inline-rtdscp
  • Rename all folders to maintain the correct order of the exercises

@andreia-oca andreia-oca requested a review from teodutu May 3, 2024 11:42
@andreia-oca andreia-oca force-pushed the lab_interactiune_c_assembly branch 2 times, most recently from 48a637f to 8f802ec Compare May 3, 2024 11:52
Adding 1-inline-for, 2-inline-rotate and 3-inline-rtdscp
and reordering the exercises accordingly.

Signed-off-by: Andreia Ocanoaia <[email protected]>
@andreia-oca andreia-oca force-pushed the lab_interactiune_c_assembly branch from 8f802ec to 75a7501 Compare May 3, 2024 11:54
Comment on lines +2 to +3
include ../../utils/Makefile.generic

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
include ../../utils/Makefile.generic
include ../../utils/Makefile.generic

You have 2 trailing newlines at the end of each Makefile. Remove one of them.

@@ -0,0 +1 @@
/inline_for.asm
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/inline_for.asm
/inline_for

Why .asm?

@@ -0,0 +1 @@
/inline_rotate.asm
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/inline_rotate.asm
/inline_rotate

@@ -0,0 +1 @@
/inline_cpuid.asm
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/inline_cpuid.asm
/inline_rdtscp

@@ -0,0 +1,3 @@
PROGNAME := inline_rtdscp
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
PROGNAME := inline_rtdscp
PROGNAME := inline_rdtscp

@@ -0,0 +1 @@
/inline_rotate.asm
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/inline_rotate.asm
/inline_rotate

> **NOTE:** Nu are sens să declarăm ca fiind inline funcțiile recursive. De ce?
Acum este ușor să ghicim la ce se referă expresia “inline assembly”: un set de instrucțiuni assembly scrise ca funcții inline. Inline assembly este folosit ca o metoda de optimizare și este foarte des întâlnit în system programming.

În programele C/C++ se pot insera instrucțiuni în limbaje de asamblare folosing cuvântul cheie “asm”.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
În programele C/C++ se pot insera instrucțiuni în limbaje de asamblare folosing cuvântul cheie asm.
În programele C/C++ se pot insera instrucțiuni în limbaje de asamblare folosing cuvântul cheie "asm".

Use ASCII quotes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rdtscp places the timestamp counter in edx:eax as a 64-bit number, not a string. In addition, it places the CPU number in ecx, but since students aren't used to multicore operations yet, I think we should ignore this register and focus on edx:eax. Change this exercise so that it uses rdtscp to calculate the time spent on some operations, like a for loop doing whatever.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two variants to the operation - rdtsc and rdtscp, where rdtscp also adds the processor type, but more importantly also acts as a barrier, so measuring time should be more correct using it. However, measuring time using the TSC is non-trivial, since you also need to account for the increment frequency.

You will need to explain what the numbers actually mean, since they don't translate directly to either seconds (you need to extract the increment frequency from somewhere - e.g., the system's journal using something like journalctl -xe -n 10000 | grep clocksource), nor processor clock cycles (most modern CPUs have invariant TSC, which means that the TSC is incremented at a frequency near the CPU's maximum frequency without turbo boosts, regardless of C/P/T states, which especially on laptops will rarely be the same as the actual CPU frequency).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants