Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float temp;
- asm volatile("fld %2 n"
- "fld %3 n"
- "fcomi n"
- "fcmovbe %%st(1), %%st n"
- "fstp %0 n"
- "fstp %1 n"
- :"=m"(maxval), "=m"(temp)
- :"m"(val), "m"(maxval));
- if(val>maxval)
- maxval=val;
- if(val>maxval)
- val2=maxval;
- float findmax_asm(const float *arr, size_t len)
- {
- float maxval = -INFINITY;
- for (size_t i=0 ; i<len ; i++) {
- float val = arr[i];
- float temp;
- asm volatile("fld %2 n"
- "fld %3 n"
- "fcomi n"
- "fcmovbe %%st(1), %%st n"
- "fstp %0 n"
- "fstp %1 n"
- :"=m"(maxval), "=m"(temp)
- :"m"(val), "m"(maxval));
- }
- return maxval;
- }
- .L20:
- flds (%eax) # MEM[base: _18, offset: 0B]
- fstps 8(%esp) # val
- ## inline asm starts here
- fld 8(%esp) # val
- fld 4(%esp) # maxval # st(0) = maxval, st(1) = val
- fcomi # implicitly %st(1), %st i.e. fcomi val, maxval
- fcmovbe %st(1), %st # copy if maxval<=val
- fstp 4(%esp) # maxval # store updated maxval back to memory
- fstp 12(%esp) # temp # and uselessly store temp = val
- ## and ends here
- addl $4, %eax #, ivtmp.25
- cmpl %edx, %eax # _25, ivtmp.25 # induction-variable temporary pointers invented by the compiler to turn arr[i] into a pointer-increment
- jne .L20 #, # }while(p != endp);
- # loop ends with maxval in memory.
- flds 4(%esp) # maxval
- .L23:
- addl $16, %esp #,
- ret # with %st = maxval return value
- maxval = (val < maxval) ? maxval : val;
- #include <stdint.h>
- #include <stdlib.h>
- #include <math.h>
- float findmax_c(const float *arr, size_t len)
- {
- float maxval = -INFINITY;
- for (size_t i=0 ; i<len ; i++) {
- float val = arr[i];
- maxval = (val < maxval) ? maxval : val; // maxss (mem), reg
- }
- return maxval;
- }
- .L4:
- flds (%eax) # MEM[base: _1, offset: 0B]
- fxch %st(1) #
- fcomi %st(1), %st #,
- fcmovbe %st(1), %st #,,
- fstp %st(1) #
- addl $4, %eax #, ivtmp.9
- cmpl %eax, %edx # ivtmp.9, _5
- jne .L4 #,
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement