This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: another compiler better than gcj ?
Anthony Green wrote:
>Bryce wrote:
>
>>Wouldn't the best solution for x86 integer divides be to just emit
>>something like:
>>
>>if (__builtin_expect (divisor== 0), false)
>> _Jv_ThrowDivideByZero()
>>else
>> .. do divide ..
>>
>
>Well, there's usually another goofy case we need to watch for. See _Jv_divI
>and friends in prims.cc. Do we want to put all of these tests inline?
>
On x86 at least, I don't think the special case is neccessary because
the CPU's behaviour matches the Java spec anyway. Here's a test case
which seems to show that:
#include <gcj/cni.h>
#include <java/lang/System.h>
#include <java/io/PrintStream.h>
#include <java/lang/Integer.h>
#include <java/lang/Long.h>
int main(int argc, char *argv)
{
using namespace java::lang;
_Jv_CreateJavaVM (NULL);
_Jv_AttachCurrentThread (NULL, NULL);
jint i = Integer::MIN_VALUE;
jlong j = Long::MIN_VALUE;
System::out->println(i / (jint) -1);
System::out->println(j / (jlong) -1);
}
I don't know about other hardware though. I'll try it on my Powerbook
tonight. If there is hardware that doesn't match the spec, maybe it
would be nice to be able to tell the back-end that we want a
divide-with-java-semantics, and let it deal with it?
regards
Bryce.