2013/4/18 Hendrik Greving <hendrik.greving.intel@xxxxxxxxx>: > Nevermind, I've found it. The compiler checks whether the provided div > pattern returns a quotient and otherwise falls back to a library call. > > Thanks, > Hendrik > > On Wed, Apr 17, 2013 at 9:26 AM, Hendrik Greving > <hendrik.greving.intel@xxxxxxxxx> wrote: >> Hi, >> >> this might apply to older GCC versions only (not sure). I am using GCC >> 3.2.x. My question is, how do I configure and re-target GCC to expand >> a divide (e.g. divdi3) with define_expand("divdi3") instead of >> generating a libgcc library call to __divdi3? Any help tips >> appreciated. >> >> Thanks, Regards, >> Hendrik Greving Yes, and you can also enable/disable divdi3 pattern at configure time. Here are the steps to do that: Step 1: Add new option -mdiv-di into target.opt + mdiv + Target Report Mask(DIV_DI) + Use hardware double words div instructions. After that, you will have -mdiv-di and -mno-div-di options supported in your target. It creates a bit mask MASK_DIV_DI for particular use and you can check TARGET_DIV_DI to determine whether -mdiv-di is issued. Step 2: Use MASK_DIV_DI in your config.gcc Assume that your target supports --with-arch=[v2|v3] in your configure options where the double words div instructions are only enabled under v3 architecture. You should add following content in config.gcc file. + target*-*-*) + supported_defaults="arch" + + # process --with-arch + case "${with_arch}" in + v2) + target_cpu_default="${target_cpu_default}" + ;; + v3) + target_cpu_default="${target_cpu_default}|MASK_DIV_DI" + ;; + *) + echo "Available values are: v2 v3" 1>&2 + exit 1 + ;; + esac Step 3: Use TARGET_DIV_DI in your machine description There should be and (define_insn "divdi3" ...) in your target.md with following pattern. (Or 'define_expand' if you would like to expand it for some purposes.) +(define_expand "divdi3" + [(set (match_operand:DI 0 ...) + (div:DI (match_operand:DI 1 ...) + (match_operand:DI 2 ...)))] + "TARGET_DIV_DI" + "div_di %0,%1,%2" + [(set_attr "type" "alu") + (set_attr "length" "4")]) After these three steps, you are able to enable/disable double word div instructions at configure time. Using 'configure --with-arch=v3 ...' to build your compiler with divdi by default. Using 'configure --with-arch=v2 ...' to build your compiler without divdi by default. Hope it helps. :) Best regards, jasonwucj