473,385 Members | 1,593 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,385 software developers and data experts.

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_SIGN_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 1247

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

Similar topics

7
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...
3
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...
22
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...
2
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...
9
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...
0
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...
8
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...
44
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...
13
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.. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.