-
Notifications
You must be signed in to change notification settings - Fork 39
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
unify memory printing functions #311
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include "util.h" | ||
|
||
c3_w | ||
_c3_printcap_mem_w(FILE *fil_u, c3_w wor_w, const c3_c *cap_c) | ||
{ | ||
return _c3_printcap_mem_z(fil_u, (c3_z)wor_w << 2, cap_c) >> 2; | ||
} | ||
|
||
c3_z | ||
_c3_printcap_mem_z(FILE *fil_u, c3_z byt_z, const c3_c *cap_c) | ||
{ | ||
c3_assert( 0 != fil_u ); /* ;;: I assume this is important from commit | ||
f975ca908b143fb76c104ecc32cb59317ea5b198: | ||
threads output file pointer through memory | ||
marking and printing. | ||
|
||
If not necessary, we can get rid of | ||
c3_maid_w */ | ||
|
||
c3_z gib_z = (byt_z / (1 << 30)); | ||
c3_z mib_z = (byt_z % (1 << 30)) / (1 << 20); | ||
c3_z kib_z = (byt_z % (1 << 20)) / (1 << 10); | ||
c3_z bib_z = (byt_z % (1 << 10)); | ||
|
||
if ( gib_z ) { | ||
fprintf(fil_u, "%s" "GiB/%" PRIc3_z ".%03" PRIc3_z ".%03" PRIc3_z ".%03" PRIc3_z "\r\n", | ||
cap_c, gib_z, mib_z, kib_z, bib_z); | ||
} | ||
else if ( mib_z ) { | ||
fprintf(fil_u, "%s" "MiB/%" PRIc3_z ".%03" PRIc3_z ".%03" PRIc3_z "\r\n", | ||
cap_c, mib_z, kib_z, bib_z); | ||
} | ||
else if ( kib_z ) { | ||
fprintf(fil_u, "%s" "KiB/%" PRIc3_z ".%03" PRIc3_z "\r\n", | ||
cap_c, kib_z, bib_z); | ||
} | ||
else { | ||
fprintf(fil_u, "%s" "B/%" PRIc3_z "\r\n", | ||
cap_c, bib_z); | ||
} | ||
return byt_z; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#ifndef C3_UTIL_H | ||
#define C3_UTIL_H | ||
|
||
#include <stdio.h> | ||
|
||
#include "types.h" | ||
#include "defs.h" | ||
|
||
c3_w _c3_printcap_mem_w (FILE *fil_u, c3_w wor_w, const c3_c *cap_c); | ||
c3_z _c3_printcap_mem_z(FILE *fil_u, c3_z byt_z, const c3_c *cap_c); | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are some Form Feed (U+000C) characters interspersed here and in other places. We should get rid of them. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Form feed characters are good and make code easier to navigate There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh ok, I just haven't seen them elsewhere in our codebase. Feel free to disregard. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They certainly might not be anywhere else, but I don't think they hurt. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and fyi, I mainly put them here to bracket the pairs of macros which function more as single logical units. I also don't mind their usage to page code into logical sections with header comments |
||
/* | ||
c3_print_mem_w( | ||
FILE * FILE - file. must not be NULL, | ||
c3_w WOR - size in words, | ||
? c3_c * q_CAP - caption, | ||
) | ||
|
||
Print word-sized quantity, WOR, in typical format: | ||
[Caption: ][GiB|MiB|KiB|B]/QUANTITY | ||
*/ | ||
#define c3_print_mem_w( ... ) \ | ||
c3_print_mem_w_0( __VA_ARGS__, "" ) | ||
#define c3_print_mem_w_0( FILE, WOR, q_CAP, ... ) \ | ||
((q_CAP[0]) \ | ||
? _c3_printcap_mem_w((FILE), (WOR), q_CAP ": ") \ | ||
: _c3_printcap_mem_w((FILE), (WOR), "")) | ||
|
||
|
||
/* | ||
c3_print_mem_z( | ||
FILE * FILE - file. must not be NULL, | ||
c3_w BYT - size in bytes, | ||
? c3_c * q_CAP - caption, | ||
) | ||
|
||
Print byte-sized quantity, BYT like c3_print_mem_w | ||
*/ | ||
#define c3_print_mem_z( ... ) \ | ||
c3_print_mem_z_0( __VA_ARGS__, "" ) | ||
#define c3_print_mem_z_0( FILE, BYT, q_CAP, ... ) \ | ||
((q_CAP[0]) \ | ||
? _c3_printcap_mem_z((FILE), (BYT), q_CAP ": ") \ | ||
: _c3_printcap_mem_z((FILE), (BYT), "")) | ||
|
||
|
||
/* | ||
c3_print_mem_w( | ||
FILE * FILE - file may be NULL, | ||
c3_w WOR - size in words, | ||
? c3_c * q_CAP - caption, | ||
) | ||
|
||
Just like c3_print_mem_w with the exception that FILE may be null. In which | ||
case, this is a NOP. | ||
*/ | ||
#define c3_maid_w( ... ) \ | ||
c3_maid_w_0( __VA_ARGS__, "" ) | ||
#define c3_maid_w_0( FILE, WOR, ... ) \ | ||
((0 == (FILE)) \ | ||
? (WOR) \ | ||
: c3_print_mem_w( FILE, WOR, __VA_ARGS__ )) | ||
|
||
|
||
/* | ||
c3_print_memdiff_w( | ||
FILE * FILE - file, | ||
c3_w WOR0 - size in words, | ||
c3_w WOR1 - size in words, | ||
? c3_c * q_CAP - caption, | ||
) | ||
|
||
Prints absolute value of WOR0 - WOR1 using c3_print_mem_w | ||
*/ | ||
#define c3_print_memdiff_w( ... ) \ | ||
c3_print_memdiff_w_0( __VA_ARGS__, "" ) | ||
|
||
#define c3_print_memdiff_w_0( FILE, WOR0, WOR1, ... ) \ | ||
c3_print_mem_w(FILE, ((0+WOR0) > (0+WOR1) ? WOR0 - WOR1 : WOR1 - WOR0), __VA_ARGS__ ) | ||
|
||
#endif /* ifndef C3_UTIL_H */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The interface is even simpler if we can get rid of the null file assert in
_c3_printcap_mem_z
. I think we might be able to, but not sure. See inline comment.If we can get rid of this, all calls to
c3_maid_w
can just callc3_print_mem_w
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the question is... when do we want a call to
c3_print_mem_w
to crash the process when the output file is null (rather than ignore the print). I would guess never