Skip to content
This repository was archived by the owner on Sep 2, 2018. It is now read-only.

Support 32-bit and bigger division #149

Closed
dylanmckay opened this issue Jul 21, 2015 · 6 comments
Closed

Support 32-bit and bigger division #149

dylanmckay opened this issue Jul 21, 2015 · 6 comments

Comments

@dylanmckay
Copy link
Member

We support 8 and 16-bit division through the use of custom lowering.

We cannot custom lower an illegal type (greater than 16-bits).

LLVM will use its existing libcall infrastructure, leading to the rtlib function being called incorrectly (with a broken calling convention), producing incorrect results.

@dylanmckay
Copy link
Member Author

This blocks Arduino - the following files use 32-bit division:

  • WMath.cpp (for the map() function)
  • Tone.cpp (for the tone generator frequency calculations)
  • Print.cpp (for integer printing routines)
  • HardwareSerial.cpp (for baud-rate calculations in Serial.begin())

If these features are not used, Arduino is likely to work.

@dylanmckay
Copy link
Member Author

Fixed in 9724f1d.

@agnat Could you write an on-target test for 32-bit and 64-bit div/rem? I'm sure the generated is correct, but it never hurts :) Don't worry, I'm working on it.

@4ntoine
Copy link

4ntoine commented Aug 19, 2015

I'm having this build error:

[ 37%] Building CXX object lib/Target/AVR/CMakeFiles/LLVMAVRCodeGen.dir/AVRISelLowering.cpp.o
/Users/asmirnov/Documents/dev/src/avr-llvm/llvm/lib/Target/AVR/AVRISelLowering.cpp:691:3: error: 
      multiple default labels in one switch
  default:
  ^
/Users/asmirnov/Documents/dev/src/avr-llvm/llvm/lib/Target/AVR/AVRISelLowering.cpp:707:3: note: 
      previous case defined here
  default: {
  ^
1 error generated.

Not sure if it relates to this issue fix or not.
Fixed locally by removing default handler at line 693.

@agnat
Copy link

agnat commented Aug 19, 2015

Don't worry, I'm working on it.

Hehe... That's the spirit! :-D

@dylanmckay
Copy link
Member Author

@4ntoine: Whoops, fixed in 9546f71.

@dylanmckay
Copy link
Member Author

Reproduction code:

define i64 @do_thing(i64 %a, i64 %b) {
    %1 = udiv i64 %a, %b
    ret i64 %1
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants