short function returns int sized values

J S Hammond jshammond@my-Deja.com
Thu Jun 29 17:51:00 GMT 2000


I am working on a machine description file for
a new processor.  We have been using it to
create a cross-compiler that generates 
assembly code (we have our own assembler and
linker).

The problem is that when I have a function that
is supposed to return a short value (16 bit)
it returns a 32 bit value instead.  However,
the part of the program that calls the function
is expecting a 16 bit value and treats the
return value as one.  With 16 bit registers,
the short functions return a value in 2 regs
but the caller only looks at the first one (most
significant).  At runtime all the short 
functions appear to return 0.

One of the odd things about this processor is that
#define BITS_PER_UNIT 16
instead of the more common value of 8. 
We also have
#define SHORT_TYPE_SIZE 16
which should be one 'byte' and use QImode.

Here is an example function:
short testfunc1()
{
   short a=1;
   return a;
}

and here is the rtl output for it:
;; Function testfunc1
(note 1 0 2 ("test.c") 2)
(note 2 1 3 "" NOTE_INSN_DELETED)
(note 3 2 4 "" NOTE_INSN_FUNCTION_BEG)
(note 4 3 5 "" NOTE_INSN_DELETED)
(note 5 4 6 ("test.c") 3)
(note 6 5 8 0 NOTE_INSN_BLOCK_BEG)
(insn 8 6 9 (set (reg:QI 20)
        (const_int 1)) -1 (nil)
    (expr_list:REG_EQUAL (const_int 1)
        (nil)))
(insn 9 8 10 (set (mem:QI (reg:HI 17))
        (reg:QI 20)) -1 (nil)
    (nil))
(note 10 9 11 ("test.c") 4)
(insn 11 10 13 (set (reg:HI 21)
        (sign_extend:HI (mem:QI (reg:HI 17)))) -1 (nil)
    (nil))
(insn 13 11 14 (set (reg/i:HI 2 2)
        (reg:HI 21)) -1 (nil)
    (nil))
(insn 14 13 15 (use (reg/i:HI 2 2)) -1 (nil)
    (nil))
(jump_insn 15 14 16 (return) -1 (nil)
    (nil))
(barrier 16 15 17)
(note 17 16 18 ("test.c") 5)
(note 18 17 19 0 NOTE_INSN_BLOCK_END)
(note 19 18 20 "" NOTE_INSN_FUNCTION_END)
(note 20 19 21 ("test.c") 5)
(jump_insn 21 20 22 (return) -1 (nil)
    (nil))
(barrier 22 21 0)

It uses QImode, as expected, for initializing
the short variable.  However, when it is
time to return the value, it gets converted
to HImode and then returned.

Which setting(s) did I mess up to get this
behavior?  I have been rereading the section
on target description macros but I haven't
found anything that seems like it would cause
this.

Thanks,

Jeff Hammond


--== Sent via Deja.com http://www.deja.com/ ==--
Before you buy.


More information about the Gcc mailing list