Print this page
patch keith-feedback
5291 x86 {high,low}bit rely on undefined behavior


2784         ret
2785         SET_SIZE(scan_memory)
2786 
2787 #endif  /* __i386 */
2788 #endif  /* __lint */
2789 
2790 
2791 #if defined(__lint)
2792 
2793 /*ARGSUSED */
2794 int
2795 lowbit(ulong_t i)
2796 { return (0); }
2797 
2798 #else   /* __lint */
2799 
2800 #if defined(__amd64)
2801 
2802         ENTRY(lowbit)
2803         movl    $-1, %eax
2804         bsfq    %rdi, %rax

2805         incl    %eax
2806         ret
2807         SET_SIZE(lowbit)
2808 
2809 #elif defined(__i386)
2810 
2811         ENTRY(lowbit)
2812         movl    $-1, %eax
2813         bsfl    4(%esp), %eax

2814         incl    %eax
2815         ret



2816         SET_SIZE(lowbit)
2817 
2818 #endif  /* __i386 */
2819 #endif  /* __lint */
2820 
2821 #if defined(__lint)
2822 
2823 /*ARGSUSED*/
2824 int
2825 highbit(ulong_t i)
2826 { return (0); }
2827 





2828 #else   /* __lint */
2829 
2830 #if defined(__amd64)
2831 
2832         ENTRY(highbit)

2833         movl    $-1, %eax
2834         bsrq    %rdi, %rax

2835         incl    %eax
2836         ret

2837         SET_SIZE(highbit)
2838 
2839 #elif defined(__i386)
2840 
2841         ENTRY(highbit)
2842         movl    $-1, %eax
2843         bsrl    4(%esp), %eax

2844         incl    %eax
2845         ret
2846         SET_SIZE(highbit)
2847 
2848 #endif  /* __i386 */
2849 #endif  /* __lint */
2850 
2851 #if defined(__lint)
2852 
2853 /*ARGSUSED*/
2854 int
2855 highbit64(uint64_t i)
2856 { return (0); }
2857 
2858 #else   /* __lint */
2859 
2860 #if defined(__amd64)
2861 
2862         ENTRY(highbit64)
2863         movl    $-1, %eax
2864         bsrq    %rdi, %rax
2865         incl    %eax
2866         ret
2867         SET_SIZE(highbit64)
2868 
2869 #elif defined(__i386)
2870 
2871         ENTRY(highbit64)
2872         bsrl    8(%esp), %eax
2873         jz      .lowbit
2874         addl    $32, %eax
2875         jmp     .done
2876 
2877 .lowbit:
2878         movl    $-1, %eax
2879         bsrl    4(%esp), %eax
2880 .done:
2881         incl    %eax
2882         ret
2883         SET_SIZE(highbit64)
2884 
2885 #endif  /* __i386 */
2886 #endif  /* __lint */
2887 
2888 #if defined(__lint)
2889 
2890 /*ARGSUSED*/
2891 uint64_t
2892 rdmsr(uint_t r)
2893 { return (0); }
2894 
2895 /*ARGSUSED*/
2896 void
2897 wrmsr(uint_t r, const uint64_t val)
2898 {}
2899 
2900 /*ARGSUSED*/
2901 uint64_t




2784         ret
2785         SET_SIZE(scan_memory)
2786 
2787 #endif  /* __i386 */
2788 #endif  /* __lint */
2789 
2790 
2791 #if defined(__lint)
2792 
2793 /*ARGSUSED */
2794 int
2795 lowbit(ulong_t i)
2796 { return (0); }
2797 
2798 #else   /* __lint */
2799 
2800 #if defined(__amd64)
2801 
2802         ENTRY(lowbit)
2803         movl    $-1, %eax
2804         bsfq    %rdi, %rdi
2805         cmovnz  %edi, %eax
2806         incl    %eax
2807         ret
2808         SET_SIZE(lowbit)
2809 
2810 #elif defined(__i386)
2811 
2812         ENTRY(lowbit)

2813         bsfl    4(%esp), %eax
2814         jz      0f
2815         incl    %eax
2816         ret
2817 0:
2818         xorl    %eax, %eax
2819         ret
2820         SET_SIZE(lowbit)
2821 
2822 #endif  /* __i386 */
2823 #endif  /* __lint */
2824 
2825 #if defined(__lint)
2826 
2827 /*ARGSUSED*/
2828 int
2829 highbit(ulong_t i)
2830 { return (0); }
2831 
2832 /*ARGSUSED*/
2833 int
2834 highbit64(uint64_t i)
2835 { return (0); }
2836 
2837 #else   /* __lint */
2838 
2839 #if defined(__amd64)
2840 
2841         ENTRY(highbit)
2842         ALTENTRY(highbit64)
2843         movl    $-1, %eax
2844         bsrq    %rdi, %rdi
2845         cmovnz  %edi, %eax
2846         incl    %eax
2847         ret
2848         SET_SIZE(highbit64)
2849         SET_SIZE(highbit)
2850 
2851 #elif defined(__i386)
2852 
2853         ENTRY(highbit)

2854         bsrl    4(%esp), %eax
2855         jz      0f
2856         incl    %eax
2857         ret
2858 0:
2859         xorl    %eax, %eax


















2860         ret    
2861         SET_SIZE(highbit)


2862 
2863         ENTRY(highbit64)
2864         bsrl    8(%esp), %eax
2865         jz      highbit
2866         addl    $33, %eax







2867         ret
2868         SET_SIZE(highbit64)
2869 
2870 #endif  /* __i386 */
2871 #endif  /* __lint */
2872 
2873 #if defined(__lint)
2874 
2875 /*ARGSUSED*/
2876 uint64_t
2877 rdmsr(uint_t r)
2878 { return (0); }
2879 
2880 /*ARGSUSED*/
2881 void
2882 wrmsr(uint_t r, const uint64_t val)
2883 {}
2884 
2885 /*ARGSUSED*/
2886 uint64_t