Amardeep reddy
Amardeep reddy

Reputation: 127

How to turn on Fused Multiply Add in GCC for ARM processor

In my C program, I want the processor to compute a*b +c using FMADD instruction rather than MUL and ADD. How do I specify this to the compiler to do this. Also I would like to see FMADD instruction in the assembly code after compile.

gcc version 4.9.2 ARM v7 Processor

Upvotes: 0

Views: 1536

Answers (1)

artless-noise-bye-due2AI
artless-noise-bye-due2AI

Reputation: 22420

You need to have one of the following FPUs,

  • vfpv4
  • vfpv4-d16
  • fpv4-sp-d16
  • fpv5-sp-d16
  • fpv5-d16
  • neon-vfpv4
  • fp-armv8
  • neon-fp-armv8
  • crypto-neon-fp-armv8

You must use the hard-float ABI option.

An example with integers.
An example with floats.

You shouldn't need to specify any special function calls; the compiler will use the instruction if it finds they are beneficial.


The code in arm.c responsible for generation is,

case FMA:
  if (TARGET_32BIT && TARGET_HARD_FLOAT && TARGET_FMA)

With TARGET_FMA being a version '4' or better FPU.

Upvotes: 0

Related Questions