473,396 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Optimisation problems when mixing asm with C++

Hi,
I have a function which I make use of assembler in order to do a bit scan
search on 64 bit numbers (Ie.. find the first 1 bit). It's used as a static
c++ function.

It works all the time without compiler optimisations. It seems to work
all of the time when I test it with optimisations (-O1 to -O3) on but
fails somewhere in practical use.

I've played around with __attribute__ ((noinline)) and some seem to help a
little but all fail for -O2 upward etc..
I've searched around and see no simple answer - gcc seems to have no way of
turning off optimisations for the function..

Has anyone ideas about how this sort of thing can be solved? (I've chucked
the code below)

Thanks,
Oliver Batchelor

Here's the code I'm using:

static int firstSet (bitboard &b) {

int position = 0;
asm volatile (

"bsf (%%edx), %%eax \n"
"jnz 1f \n"

"bsf 4(%%edx), %%eax \n"
"add $32, %%eax \n"
"jnz 1f \n"

"mov $0, %%eax \n"
"1: \n"

: "=a" (position)
: "d" (&b));

return position;
}
Jul 19 '05 #1
1 1916
Oliver Batchelor <owb13@.student.canterbury.ac.nz> writes:
Hi,
I have a function which I make use of assembler in order to do a bit scan
search on 64 bit numbers (Ie.. find the first 1 bit). It's used as a static
c++ function.

It works all the time without compiler optimisations. It seems to work
all of the time when I test it with optimisations (-O1 to -O3) on but
fails somewhere in practical use.


Please don't repost within 2 hours - Usenet isn't instant messaging, answers
can take hours or days to reach you.

Your question is OT in comp.lang.c++, you should try one of the gcc groups
or perhaps comp.lang.asm.x86

HTH & kind regards
frank

--
Frank Schmitt
4SC AG phone: +49 89 700763-0
e-mail: frank DOT schmitt AT 4sc DOT com
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: OPQ | last post by:
Hi all, I'd happy to have you share some thougts about ultimate optimisations on those 2 topics: (1)- adding one caractere at the end of a string (may be long) (2)- in a dict mapping a key...
2
by: Simon Elliott | last post by:
What optimisation do compilers typically provide when passing STL containers around? For example, if I do something like this: struct Tbloggs { std::string s1; }; typedef...
13
by: SpaceCowboy | last post by:
I recently got into a discussion with a co-worker about using enums across a dll interface. He wanted to use chars instead, argueing that depending on compiler settings the size of an enum could...
16
by: simonwittber | last post by:
Hello People. I've have a very tight inner loop (in a game app, so every millisecond counts) which I have optimised below: def loop(self): self_pool = self.pool self_call_exit_funcs =...
19
by: Jim | last post by:
I have spent the past few weeks designing a database for my company. The problem is I have started running into what I believe are stack overflow problems. There are two tab controls on the form...
17
by: EC-AKD | last post by:
Hi All, I am new to the concept of optimising codes in C. I was wondering if C level inlining of code is any way comparable to macros. I believe that inlining is equivalent to writing macros....
8
by: Jon Maz | last post by:
Hi, I'm facing a code-optimisation issue on an asp.net/vb.net/SQL Server 2000 project. A web page containing not much more than 3 DropDownLists is taking nigh on 6 seconds to load, because each...
1
by: David Welch | last post by:
Hi, I have a bit of code where I am relying on empty base member optimisation. The bit of code is below: template<typename Enum> struct EncodePrefix { template<Enum e> struct Apply
2
by: =?Utf-8?B?cmljaGFyZCBzYW5jZW5vdA==?= | last post by:
When calling the DrawSomething function, i get an access violation in release mode. This error happens when "Increase speed (/02)" is enabled (Preferences->C/C++ -Optimisation -Increase speed...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.