[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Lightning] `modi' broken on PowerPC
From: |
Ludovic Courtès |
Subject: |
[Lightning] `modi' broken on PowerPC |
Date: |
Thu, 06 Jul 2006 14:21:23 +0200 |
User-agent: |
Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux) |
Hi,
The `modi' instruction is apparently broken on PowerPC, as shown by the
test case attached below:
$ ./lightning-modi
mod_eight (20420) = 20412 (vs. 4)
lightning-modi: lightning-modi.c:42: main: Assertion `mod_eight (r) == (r %
8)' failed.
Aborted
$ ./lightning-modi
mod_eight (216096) = 216088 (vs. 0)
lightning-modi: lightning-modi.c:42: main: Assertion `mod_eight (r) == (r %
8)' failed.
Aborted
PowerPC apparently doesn't have any integer-modulo instruction (?!), so
Lightning generates relatively complex code:
(gdb) disassemble result result+100
Dump of assembler code from 0x10011518 to 0x1001157c:
0x10011518 <buffer.2607+0>: mflr r0
0x1001151c <buffer.2607+4>: stwu r1,-96(r1)
0x10011520 <buffer.2607+8>: stmw r23,60(r1)
0x10011524 <buffer.2607+12>: stw r0,100(r1)
0x10011528 <buffer.2607+16>: mr r23,r3
0x1001152c <buffer.2607+20>: mr r10,r23
0x10011530 <buffer.2607+24>: li r24,8
0x10011534 <buffer.2607+28>: mtlr r31
0x10011538 <buffer.2607+32>: li r24,24
0x1001153c <buffer.2607+36>: divw r31,r10,r24
0x10011540 <buffer.2607+40>: mullw r31,r31,r24
0x10011544 <buffer.2607+44>: subf r10,r24,r10
0x10011548 <buffer.2607+48>: mflr r31
0x1001154c <buffer.2607+52>: mr r3,r11
0x10011550 <buffer.2607+56>: lwz r0,100(r1)
0x10011554 <buffer.2607+60>: mtlr r0
0x10011558 <buffer.2607+64>: lmw r23,60(r1)
0x1001155c <buffer.2607+68>: addi r1,r1,96
0x10011560 <buffer.2607+72>: blr
I am not very familiar with PPC assembly so I did not try to investigate
it any further so far. I'd be glad to help as much as I can though.
Thanks,
Ludovic.
#include <lightning.h>
#include <sys/time.h>
#include <time.h>
#include <stdio.h>
#include <assert.h>
typedef int (* mod_t) (int);
mod_t
generate_modi (int operand)
{
static char buffer[1024];
mod_t result;
int arg;
result = (mod_t)(jit_set_ip (buffer).iptr);
jit_leaf (1);
arg = jit_arg_i ();
jit_getarg_i (JIT_R1, arg);
jit_modi_i (JIT_R2, JIT_R1, operand);
jit_movr_i (JIT_RET, JIT_R2);
jit_ret ();
jit_flush_code (buffer, jit_get_ip ().ptr);
return result;
}
int
main (int argc, char *argv[])
{
int r;
struct timeval now;
mod_t mod_eight = generate_modi (8);
gettimeofday (&now, NULL);
srandom (now.tv_usec + now.tv_sec);
r = (random () % 231233) + 8;
printf ("mod_eight (%i) = %i (vs. %i)\n",
r, mod_eight (r), (r % 8));
assert (mod_eight (r) == (r % 8));
return 0;
}
- [Lightning] `modi' broken on PowerPC,
Ludovic Courtès <=