Re: how to generate x86 "narrowing" divide instruction

2011-03-07 Thread Ian Lance Taylor
Jay Foad writes: > This source code: > > $ cat rand.c > #include > uint32_t rand(uint32_t x) { return (uint64_t)x * 16807 % 0x7FFF; } > > compiles to this optimised x86 code: > > $ gcc -S -O3 -m32 -fomit-frame-pointer -o - rand.c > ... > rand: > subl$28, %esp > movl$16807

Re: how to generate x86 "narrowing" divide instruction

2011-03-07 Thread Uros Bizjak
Hello! > $ cat rand.c > #include > uint32_t rand(uint32_t x) { return (uint64_t)x * 16807 % 0x7FFF; } > > compiles to this optimised x86 code: > > $ gcc -S -O3 -m32 -fomit-frame-pointer -o - rand.c > ... > rand: > subl$28, %esp > movl$16807, %eax > mull32(%esp) >