473,883 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using C as target language

Generally C is well suited as target language for compilers.
I use C as target language for the Seed7 compiler. This
works good. There are just some things where the
behaviour of C is undefined:

The right shift operator (>>) of C may or may not sign
extend for signed negative numbers.

Since the right shift operation of Seed7 is defined as sign
extending shift, I have to check if the C compiler does
sign extend for signed negative numbers and to use the
following algorithm:

#ifdef RSHIFT_DOES_SIG N_EXTEND
(a >b)
#else
(a < 0 ? ~(~a >b) : a >b)
#endif

Does somebody know some algorithm which delivers more
performance when the C right shift does not sign extend than
(a < 0 ? ~(~a >b) : a >b)?

For the integer division I have a similar problem. The C
integer division may trunc towards 0 or towards minus infinite.

Seed7 has two integer divisions. One (the 'div' operator)
truncates towards 0 while the other (the 'mdiv' operator)
truncates towards minus infinite. This is explained with the
following example:

-4 div 3 = -1
-4 mdiv 3 = -2

Currently I assume that the C integer division rounds towards
zero and therefore I use the following algorithm for the
'a mdiv b' division (which truncates towards minus infinite):

if (a 0 && b < 0) {
return (a - 1) / b - 1;
} else if (a < 0 && b 0) {
return (a + 1) / b - 1;
} else {
return a / b;
} /* if */

Do you know some code which delivers more performance for
the 'a mdiv b' division (which truncates towards minus infinite)?
What is the fastest algorithm for the 'mdiv' division?

Before using this algorithm I used the following algorithm for
the 'a mdiv b' division:

long c=a / b;
if (((a 0 && b < 0) || (a < 0 && b 0)) && a % b != 0) {
return c - 1;
} else {
return c;
} /* if */

My benchmarks show that the first algorithm for 'mdiv' is
faster (it also uses only one division instead of two).
But maybe somebody can prove me wrong?

Greetings Thomas Mertes

Seed7 Homepage: http://seed7.sourceforge.net
Seed7 - The extensible programming language: User defined statements
and operators, abstract data types, templates without special
syntax, OO with interfaces and multiple dispatch, statically typed,
interpreted or compiled, portable, runs under linux/unix/windows.
Jun 27 '08 #1
0 1273

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

Similar topics

7
20942
by: Rui Pestana | last post by:
Hello all, I want to use the POST method to submit the form and then grab the parameters in the asp file with request.form("parm"). The problem is that I am using the _search target to open the asp page. When I use _blank target there is no problem, either I use GET or POST method. But when I use _search target, only GET method works.
3
9283
by: davidkarlsson74 | last post by:
Error: document.getElementById("folderMenu").cells has no properties File: http://www.volkswagen.se/tillbehor/js/foldermenu.js Rad: 49 The function activates different DIV:s, but doesn't seem to work on FireFox or Netscape. What could be wrong? The function: function setActiveTab(tabNo) {
22
2186
by: larry | last post by:
I was just looking at a demo training that mindleaders has on .net training: http://www.mindleaders.com/products/democourse3.asp And I don't believe this is correct or at least is misleading to me: "The search for an easy, productive, and very powerful programming language led to the birth of Visual C#. Visual C# incorporates the best features of Visual C++ and Visual Basic. Visual C# enables you to
2
1641
by: Gellert, Andre | last post by:
Hello, I have following problem: A user "xy" shouldn't have any rights to a table, but needs data from the content of the table. My idea was to setup a PL/PGSQL procedure to fetch the data from the table, so that the user only is allowed to access the procedure. I also tried using a SQL function, but this doesn't work, too. Working with views may be a solution - or are e.g. cursors
9
1404
by: Andy | last post by:
Hi there, I'm trying to do some predicting work over user input, here's my question: for pattern r'match me', the string 'no' will definitely fail to match, but 'ma' still has a chance if user keep on inputting characters after 'ma', so how do I mark 'ma' as a possible match string? Thanks a lot,
0
6757
by: celoftis | last post by:
Using VS2005, VB code behind, BACKGROUND I'm trying to set up a page with a TreeView of links on the left hand side of my page - when clicked I want the links to open in the remaining portion of the page. The best and easiest way I've found todo this is with using frames (any suggestions on other ways todo this I'd love to hear about it). PROBLEM
8
1589
by: v4vijayakumar | last post by:
Lot of changes are happening to c++, nowadays. Even after the standardization, we see many interesting things, like, threading, regex, rope, etc. I read some TR1 and TR2 proposals, and I am not very sure, we are going to get all this into c++. These are not brand-new concepts, but why these things took this many years to get into c++?. Is still the c++ target environment now same as the target environment before the standardization?
44
584
by: John Dann | last post by:
I'm unclear as to how best to use what I'm terming the top-level CSS selectors, by which I mean selectors like *, html and body. I'm coming at this from trying to understand how best to set font sizes but I seem to have strayed into a broader question. Some CSS guides seem to suggest that a * declaration is good practice for any style sheet, primarily I suppose to set zero defaults for margin and padding for all other relevant selectors...
13
26952
by: ramprakashjava | last post by:
hi, i hav "java.lang.NullPointerException" error while Deleting table records using checkbox in jsp here i enclosed files help quickly plzzz.. Regards Ramprakash /*Adminpage.jsp*/ <%@ page language="java" import="java.sql.*"%> <html> <head>...
0
9948
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9798
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10767
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10864
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9588
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7980
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7137
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6008
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3242
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.