sean041 / libfixmath

Automatically exported from code.google.com/p/libfixmath
0 stars 0 forks source link

Problem with sdiv.. #14

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.used sdiv(0xfffe0000,0xffff0000) (ie -2/-1) = 2; but we get 0x0000ffff
2.No flags has been set 
3.I am using the 32bit division

What is the expected output? What do you see instead?
Ans should be 2 = 0x0002000; I get 0x0000ffff 

What version of the product are you using? On what operating system?
I am working on Arm Cortex m3 lpc1768, Compiler code sorcery 

Please provide any additional information below.
I tried (-1/-2) == (0xffff0000/0xfffe0000) the code hangs here
Kindly help. I am unable to work ahead. 

Original issue reported on code.google.com by SHAGGYNE...@gmail.com on 3 May 2012 at 9:48

GoogleCodeExporter commented 8 years ago
I've not had a chance to test these recent changes but I can confirm that the 
r49 code works just fine, so you're best bet on a quick solution is to revert 
your copy of fix16.c to revision 49 and work with that until this can be solved.

Sorry for the inconvenience.

Original comment by ben.bre...@codethink.co.uk on 3 May 2012 at 10:01

GoogleCodeExporter commented 8 years ago

Original comment by Flatmush@googlemail.com on 3 May 2012 at 10:04

GoogleCodeExporter commented 8 years ago
Could not reproduce bug on x86 using the attached test.c. I'll try with 
cortex-m3 later today.

Original comment by Petteri.Aimonen on 3 May 2012 at 10:17

Attachments:

GoogleCodeExporter commented 8 years ago
@SHAGGYNEMISIS

Can you provide the compiler options you are using, and also the exact compiler 
version?

Original comment by Petteri.Aimonen on 3 May 2012 at 10:22

GoogleCodeExporter commented 8 years ago
Some other temporary replacement code you could use is this fast-newton-raphson 
algorithm:

fix16_t rcp(fix16_t b)
{
    bool n = (b < 0);
    if (n) b = -b;

    int s = 0;
    for (; b > fix16_one; b >>= 1, s--);
    for (; b < (fix16_one >> 1); b <<= 1, s++);

    fix16_t x
        = 185043 - fix16_mul(b, 123362);

    unsigned i;
    for (i = 0; i < 3; i++)
        x = fix16_mul(x, (0x00020000 - fix16_mul(b, x)));
    x <<= s;
    return (n ? -x : x);
}

fix16_t fdiv(fix16_t a, fix16_t b)
{
    return fix16_mul(a, rcp(b));
}

Original comment by Flatmush@googlemail.com on 3 May 2012 at 10:36

GoogleCodeExporter commented 8 years ago
@Flatmush

Fails for 15.0 / 5.0 etc. I don't think such temporary hacks are necessary, I 
can fix the bug as soon as I can reproduce it. It is most probably some 
compiler-specific issue, because the unittests would catch it otherwise.

Original comment by Petteri.Aimonen on 3 May 2012 at 10:45

GoogleCodeExporter commented 8 years ago
gimme me few mins ill provide the makefile and the code 

Original comment by SHAGGYNE...@gmail.com on 3 May 2012 at 10:49

GoogleCodeExporter commented 8 years ago
the fpArith.c contains the part of the code that i need for my working..

Original comment by SHAGGYNE...@gmail.com on 3 May 2012 at 10:51

Attachments:

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Nope this didn't give  the desired result  
Div (-2) 0xfffe0000, (-1)0xffff0000 = 0x80000000

Original comment by SHAGGYNE...@gmail.com on 3 May 2012 at 11:01

GoogleCodeExporter commented 8 years ago
Try the test.c I attached in comment 3. Your code is too messy and I can't get 
it easily to compile.

I tried the test.c on Cortex-M3 simulator also, the division works just fine.

Original comment by Petteri.Aimonen on 3 May 2012 at 12:05

GoogleCodeExporter commented 8 years ago
Yes i did try the test.c file the result is the same.. i.e. incorrect answer.
I will post the cleaned up test file soon.. Sorry to keep you waiting

Original comment by SHAGGYNE...@gmail.com on 4 May 2012 at 5:18

GoogleCodeExporter commented 8 years ago
Ok, good to know that test.c gives incorrect answer. Can you still give the gcc 
version, you can get it with "arm-none-eabi-gcc --version".

Original comment by Petteri.Aimonen on 4 May 2012 at 5:32

GoogleCodeExporter commented 8 years ago
arm-none-eabi-gcc (Sourcery G++ Lite 2010q1-188) 4.4.1
Copyright (C) 2009 Free Software Foundation, Inc.

Original comment by SHAGGYNE...@gmail.com on 4 May 2012 at 5:35

GoogleCodeExporter commented 8 years ago
Hmm, I cannot repeat the bug using that compiler version either. Could you post 
also the .elf file from your test.c compilation?

Original comment by Petteri.Aimonen on 4 May 2012 at 5:41

GoogleCodeExporter commented 8 years ago
Might take a while will try asap.. :)

Original comment by SHAGGYNE...@gmail.com on 4 May 2012 at 5:44

GoogleCodeExporter commented 8 years ago
fyi this is compilation command ...
arm-none-eabi-g++ -mcpu=cortex-m3 -mthumb -mfpu=vfp -msoft-float 
-mfloat-abi=soft -O0 -Wl,-Map=main.map,--cref,--gc-sect
ions -lc -lm -lgcc -lstdc++  -T..//Common/LPC17xx.ld  
I will post the elf.. soon 

Original comment by SHAGGYNE...@gmail.com on 4 May 2012 at 5:47

GoogleCodeExporter commented 8 years ago
If there's nothing new on this thread then I'm going to close it since the bug 
can't be reproduced and is very likely a compiler/code issue.

Original comment by Flatmush@googlemail.com on 29 May 2012 at 3:14

GoogleCodeExporter commented 8 years ago

Original comment by Flatmush@googlemail.com on 26 Jul 2012 at 4:00