stop printf from using mmx and sse registers
-
Hello,
I encounter the following problem:
my code contains the following printf statement:
long long a,b,c,d; printf("\n a: (%016llx) b: %d c: %ld d: %lld",a,b,c,d);Always printf changes sse-registers (xmm0-xmm3)
How can I disable printf to use mmx, sse, sse2 ?
I also tried compiling like this:
g++ -mno-mmx -mno-sse2 -mno-sse -m64 -mcmodel=medium -ggdb in.cpp -o out.obut to no avail

the sse registers are still changed.Could anyone please help?
Many thanks
Bj
-
Ok, I found one workaround:
Printing hex and dec values with
cout << hex << a << dec << b;However, I don't want to change all printf statements in my code....
Any better solutions ?
Thanks.
-
printf-grrr schrieb:
Ok, I found one workaround:
Printing hex and dec values with
cout << hex << a << dec << b;However, I don't want to change all printf statements in my code....
Any better solutions ?
Thanks.
You could implement your own Version of printf that uses cout. That would be a lot of work to do but depending on the number of printfs in your code it might be worth the effort.
Regarding your problem with the registers: This is quite odd. I wonder if it is a compiler error. Can you test your code with a different compiler? Or post a minimal example so that other readers can try other compilers?
-
Compiled with:
g++ -mno-mmx -mno-sse2 -mno-sse -m64 -mcmodel=medium -ggdb printf.cpp -o out.oVersion:
g++ (SUSE Linux) 4.4.1 [gcc-4_4-branch revision 150839]#include <stdio.h> using namespace std; main() { long long a,b,c,d; a=1;b=0xfffffff;c=4;d=5; printf("a: %lld, b: %lld, c: %lld",a,b,c); // decomment line below for comparison purposes... // cout << hex << b << endl; };An "dedicated" version of printf's too much work; alternatively I could
implement a routine that save's the registers before calling printf.I am not such a C/C++ fan and not very happy with this buggy behaviour.
If the compile option is to stop using mmx, sse and sse2 the final
program should not do otherwise.Originally my programs are in assembly language and for speeding up
development returned to a high level language in between.This does not seem to be rewarding till now

But a solution for this printf-bug should already be available, no ?
-
Apparently your glibc uses sse. Rebuild that library accordingly.
-
That's not a solution.
Compiling with -nommx -nosse options was just trying to workaround the
issue.1. I don't know how to rebuild that lib (and actually I do not want to know,
there are more important issues pressing on time).
It should work on other platforms too, without having to rebuild
every lib from scratch. There should be an easier solution wo
having to dive into all compiler details.2a. I just do not want printf to use sse, etc.
2b. or stop it from changing sse, mmx registers.3. My current fix is to save sse before calling printf and restore
afterwards. But it's wearisome to change all line's in the code and cost's cpu-speed.