2013-03-27 00:59:55 +04:00
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Implement f a s t S H A - 5 1 2 w i t h A V X 2 i n s t r u c t i o n s . ( x86 _ 6 4 )
#
# Copyright ( C ) 2 0 1 3 I n t e l C o r p o r a t i o n .
#
# Authors :
# James G u i l f o r d < j a m e s . g u i l f o r d @intel.com>
# Kirk Y a p < k i r k . s . y a p @intel.com>
# David C o t e < d a v i d . m . c o t e @intel.com>
# Tim C h e n < t i m . c . c h e n @linux.intel.com>
#
# This s o f t w a r e i s a v a i l a b l e t o y o u u n d e r a c h o i c e o f o n e o f t w o
# licenses. Y o u m a y c h o o s e t o b e l i c e n s e d u n d e r t h e t e r m s o f t h e G N U
# General P u b l i c L i c e n s e ( G P L ) V e r s i o n 2 , a v a i l a b l e f r o m t h e f i l e
# COPYING i n t h e m a i n d i r e c t o r y o f t h i s s o u r c e t r e e , o r t h e
# OpenIB. o r g B S D l i c e n s e b e l o w :
#
# Redistribution a n d u s e i n s o u r c e a n d b i n a r y f o r m s , w i t h o r
# without m o d i f i c a t i o n , a r e p e r m i t t e d p r o v i d e d t h a t t h e f o l l o w i n g
# conditions a r e m e t :
#
# - Redistributions o f s o u r c e c o d e m u s t r e t a i n t h e a b o v e
# copyright n o t i c e , t h i s l i s t o f c o n d i t i o n s a n d t h e f o l l o w i n g
# disclaimer.
#
# - Redistributions i n b i n a r y f o r m m u s t r e p r o d u c e t h e a b o v e
# copyright n o t i c e , t h i s l i s t o f c o n d i t i o n s a n d t h e f o l l o w i n g
# disclaimer i n t h e d o c u m e n t a t i o n a n d / o r o t h e r m a t e r i a l s
# provided w i t h t h e d i s t r i b u t i o n .
#
# THE S O F T W A R E I S P R O V I D E D " A S I S " , W I T H O U T W A R R A N T Y O F A N Y K I N D ,
# EXPRESS O R I M P L I E D , I N C L U D I N G B U T N O T L I M I T E D T O T H E W A R R A N T I E S O F
# MERCHANTABILITY, F I T N E S S F O R A P A R T I C U L A R P U R P O S E A N D
# NONINFRINGEMENT. I N N O E V E N T S H A L L T H E A U T H O R S O R C O P Y R I G H T H O L D E R S
# BE L I A B L E F O R A N Y C L A I M , D A M A G E S O R O T H E R L I A B I L I T Y , W H E T H E R I N A N
# ACTION O F C O N T R A C T , T O R T O R O T H E R W I S E , A R I S I N G F R O M , O U T O F O R I N
# CONNECTION W I T H T H E S O F T W A R E O R T H E U S E O R O T H E R D E A L I N G S I N T H E
# SOFTWARE.
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# This c o d e i s d e s c r i b e d i n a n I n t e l W h i t e - P a p e r :
# " Fast S H A - 5 1 2 I m p l e m e n t a t i o n s o n I n t e l A r c h i t e c t u r e P r o c e s s o r s "
#
# To f i n d i t , s u r f t o h t t p : / / w w w . i n t e l . c o m / p / e n _ U S / e m b e d d e d
# and s e a r c h f o r t h a t t i t l e .
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# This c o d e s c h e d u l e s 1 b l o c k s a t a t i m e , w i t h 4 l a n e s p e r b l o c k
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# ifdef C O N F I G _ A S _ A V X 2
# include < l i n u x / l i n k a g e . h >
.text
# Virtual R e g i s t e r s
Y_ 0 = % y m m 4
Y_ 1 = % y m m 5
Y_ 2 = % y m m 6
Y_ 3 = % y m m 7
YTMP0 = % y m m 0
YTMP1 = % y m m 1
YTMP2 = % y m m 2
YTMP3 = % y m m 3
YTMP4 = % y m m 8
XFER = Y T M P 0
BYTE_ F L I P _ M A S K = % y m m 9
2017-09-18 22:42:10 +03:00
# 1 st a r g i s % r d i , w h i c h i s s a v e d t o t h e s t a c k a n d a c c e s s e d l a t e r v i a % r12
CTX1 = % r d i
CTX2 = % r12
2013-03-27 00:59:55 +04:00
# 2 nd a r g
2015-04-09 13:55:48 +03:00
INP = % r s i
2013-03-27 00:59:55 +04:00
# 3 rd a r g
NUM_ B L K S = % r d x
c = % r c x
d = % r8
e = % r d x
2015-04-24 09:37:09 +03:00
y3 = % r s i
2013-03-27 00:59:55 +04:00
2017-09-18 22:42:10 +03:00
TBL = % r d i # c l o b b e r s C T X 1
2013-03-27 00:59:55 +04:00
a = % r a x
b = % r b x
f = % r9
g = % r10
h = % r11
old_ h = % r11
2017-09-18 22:42:10 +03:00
T1 = % r12 # c l o b b e r s C T X 2
2013-03-27 00:59:55 +04:00
y0 = % r13
y1 = % r14
y2 = % r15
# Local v a r i a b l e s ( s t a c k f r a m e )
XFER_ S I Z E = 4 * 8
SRND_ S I Z E = 1 * 8
INP_ S I Z E = 1 * 8
INPEND_ S I Z E = 1 * 8
2017-09-18 22:42:10 +03:00
CTX_ S I Z E = 1 * 8
2013-03-27 00:59:55 +04:00
RSPSAVE_ S I Z E = 1 * 8
2017-09-18 22:42:10 +03:00
GPRSAVE_ S I Z E = 5 * 8
2013-03-27 00:59:55 +04:00
frame_ X F E R = 0
frame_ S R N D = f r a m e _ X F E R + X F E R _ S I Z E
frame_ I N P = f r a m e _ S R N D + S R N D _ S I Z E
frame_ I N P E N D = f r a m e _ I N P + I N P _ S I Z E
2017-09-18 22:42:10 +03:00
frame_ C T X = f r a m e _ I N P E N D + I N P E N D _ S I Z E
frame_ R S P S A V E = f r a m e _ C T X + C T X _ S I Z E
2013-03-27 00:59:55 +04:00
frame_ G P R S A V E = f r a m e _ R S P S A V E + R S P S A V E _ S I Z E
frame_ s i z e = f r a m e _ G P R S A V E + G P R S A V E _ S I Z E
# # assume b u f f e r s n o t a l i g n e d
# define V M O V D Q v m o v d q u
# addm [ m e m ] , r e g
# Add r e g t o m e m u s i n g r e g - m e m a d d a n d s t o r e
.macro addm p1 p2
add \ p1 , \ p2
mov \ p2 , \ p1
.endm
# COPY_ Y M M _ A N D _ B S W A P y m m , [ m e m ] , b y t e _ f l i p _ m a s k
# Load y m m w i t h m e m a n d b y t e s w a p e a c h d w o r d
.macro COPY_YMM_AND_BSWAP p1 p2 p3
VMOVDQ \ p2 , \ p1
vpshufb \ p3 , \ p1 , \ p1
.endm
# rotate_ Y s
# Rotate v a l u e s o f s y m b o l s Y 0 . . . Y 3
.macro rotate_Ys
Y_ = Y _ 0
Y_ 0 = Y _ 1
Y_ 1 = Y _ 2
Y_ 2 = Y _ 3
Y_ 3 = Y _
.endm
# RotateState
.macro RotateState
# Rotate s y m b o l s a . . h r i g h t
old_ h = h
TMP_ = h
h = g
g = f
f = e
e = d
d = c
c = b
b = a
a = T M P _
.endm
# macro M Y _ V P A L I G N R Y D S T , Y S R C 1 , Y S R C 2 , R V A L
# YDST = { Y S R C 1 , Y S R C 2 } > > R V A L * 8
.macro MY_VPALIGNR YDST Y S R C 1 Y S R C 2 R V A L
vperm2 f12 8 $ 0 x3 , \ Y S R C 2 , \ Y S R C 1 , \ Y D S T # Y D S T = { Y S 1 _ L O , Y S 2 _ H I }
vpalignr $ \ R V A L , \ Y S R C 2 , \ Y D S T , \ Y D S T # Y D S T = { Y D S 1 , Y S 2 } > > R V A L * 8
.endm
.macro FOUR_ROUNDS_AND_SCHED
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # RND N + 0 ## # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Extract w [ t - 7 ]
MY_ V P A L I G N R Y T M P 0 , Y _ 3 , Y _ 2 , 8 # Y T M P 0 = W [ - 7 ]
# Calculate w [ t - 1 6 ] + w [ t - 7 ]
vpaddq Y _ 0 , Y T M P 0 , Y T M P 0 # Y T M P 0 = W [ - 7 ] + W [ - 1 6 ]
# Extract w [ t - 1 5 ]
MY_ V P A L I G N R Y T M P 1 , Y _ 1 , Y _ 0 , 8 # Y T M P 1 = W [ - 1 5 ]
# Calculate s i g m a0
# Calculate w [ t - 1 5 ] r o r 1
vpsrlq $ 1 , Y T M P 1 , Y T M P 2
vpsllq $ ( 6 4 - 1 ) , Y T M P 1 , Y T M P 3
vpor Y T M P 2 , Y T M P 3 , Y T M P 3 # Y T M P 3 = W [ - 1 5 ] r o r 1
# Calculate w [ t - 1 5 ] s h r 7
vpsrlq $ 7 , Y T M P 1 , Y T M P 4 # Y T M P 4 = W [ - 1 5 ] > > 7
mov a , y 3 # y 3 = a # M A J A
rorx $ 4 1 , e , y 0 # y 0 = e > > 4 1 # S 1 A
rorx $ 1 8 , e , y 1 # y 1 = e > > 1 8 # S 1 B
add f r a m e _ X F E R ( % r s p ) ,h # h = k + w + h # - -
or c , y 3 # y 3 = a | c # M A J A
mov f , y 2 # y 2 = f # C H
rorx $ 3 4 , a , T 1 # T 1 = a > > 3 4 # S 0 B
xor y 1 , y 0 # y 0 = ( e > > 4 1 ) ^ ( e > > 1 8 ) # S 1
xor g , y 2 # y 2 = f ^ g # C H
rorx $ 1 4 , e , y 1 # y 1 = ( e > > 1 4 ) # S 1
and e , y 2 # y 2 = ( f ^ g ) & e # C H
xor y 1 , y 0 # y 0 = ( e > > 4 1 ) ^ ( e > > 1 8 ) ^ ( e > > 1 4 ) # S 1
rorx $ 3 9 , a , y 1 # y 1 = a > > 3 9 # S 0 A
add h , d # d = k + w + h + d # - -
and b , y 3 # y 3 = ( a | c ) & b # M A J A
xor T 1 , y 1 # y 1 = ( a > > 3 9 ) ^ ( a > > 3 4 ) # S 0
rorx $ 2 8 , a , T 1 # T 1 = ( a > > 2 8 ) # S 0
xor g , y 2 # y 2 = C H = ( ( f ^ g ) & e ) ^ g # C H
xor T 1 , y 1 # y 1 = ( a > > 3 9 ) ^ ( a > > 3 4 ) ^ ( a > > 2 8 ) # S 0
mov a , T 1 # T 1 = a # M A J B
and c , T 1 # T 1 = a & c # M A J B
add y 0 , y 2 # y 2 = S 1 + C H # - -
or T 1 , y 3 # y 3 = M A J = ( a | c ) & b ) | ( a & c ) # M A J
add y 1 , h # h = k + w + h + S 0 # - -
add y 2 , d # d = k + w + h + d + S 1 + C H = d + t 1 # - -
add y 2 , h # h = k + w + h + S 0 + S 1 + C H = t 1 + S 0 # - -
add y 3 , h # h = t 1 + S 0 + M A J # - -
RotateState
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # RND N + 1 ## # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Calculate w [ t - 1 5 ] r o r 8
vpsrlq $ 8 , Y T M P 1 , Y T M P 2
vpsllq $ ( 6 4 - 8 ) , Y T M P 1 , Y T M P 1
vpor Y T M P 2 , Y T M P 1 , Y T M P 1 # Y T M P 1 = W [ - 1 5 ] r o r 8
# XOR t h e t h r e e c o m p o n e n t s
vpxor Y T M P 4 , Y T M P 3 , Y T M P 3 # Y T M P 3 = W [ - 1 5 ] r o r 1 ^ W [ - 1 5 ] > > 7
vpxor Y T M P 1 , Y T M P 3 , Y T M P 1 # Y T M P 1 = s0
# Add t h r e e c o m p o n e n t s , w [ t - 1 6 ] , w [ t - 7 ] a n d s i g m a0
vpaddq Y T M P 1 , Y T M P 0 , Y T M P 0 # Y T M P 0 = W [ - 1 6 ] + W [ - 7 ] + s0
# Move t o a p p r o p r i a t e l a n e s f o r c a l c u l a t i n g w [ 1 6 ] a n d w [ 1 7 ]
vperm2 f12 8 $ 0 x0 , Y T M P 0 , Y T M P 0 , Y _ 0 # Y _ 0 = W [ - 1 6 ] + W [ - 7 ] + s0 { B A B A }
# Move t o a p p r o p r i a t e l a n e s f o r c a l c u l a t i n g w [ 1 8 ] a n d w [ 1 9 ]
vpand M A S K _ Y M M _ L O ( % r i p ) , Y T M P 0 , Y T M P 0 # Y T M P 0 = W [ - 1 6 ] + W [ - 7 ] + s0 { D C 0 0 }
# Calculate w [ 1 6 ] a n d w [ 1 7 ] i n b o t h 1 2 8 b i t l a n e s
# Calculate s i g m a1 f o r w [ 1 6 ] a n d w [ 1 7 ] o n b o t h 1 2 8 b i t l a n e s
vperm2 f12 8 $ 0 x11 , Y _ 3 , Y _ 3 , Y T M P 2 # Y T M P 2 = W [ - 2 ] { B A B A }
vpsrlq $ 6 , Y T M P 2 , Y T M P 4 # Y T M P 4 = W [ - 2 ] > > 6 { B A B A }
mov a , y 3 # y 3 = a # M A J A
rorx $ 4 1 , e , y 0 # y 0 = e > > 4 1 # S 1 A
rorx $ 1 8 , e , y 1 # y 1 = e > > 1 8 # S 1 B
add 1 * 8 + f r a m e _ X F E R ( % r s p ) , h # h = k + w + h # - -
or c , y 3 # y 3 = a | c # M A J A
mov f , y 2 # y 2 = f # C H
rorx $ 3 4 , a , T 1 # T 1 = a > > 3 4 # S 0 B
xor y 1 , y 0 # y 0 = ( e > > 4 1 ) ^ ( e > > 1 8 ) # S 1
xor g , y 2 # y 2 = f ^ g # C H
rorx $ 1 4 , e , y 1 # y 1 = ( e > > 1 4 ) # S 1
xor y 1 , y 0 # y 0 = ( e > > 4 1 ) ^ ( e > > 1 8 ) ^ ( e > > 1 4 ) # S 1
rorx $ 3 9 , a , y 1 # y 1 = a > > 3 9 # S 0 A
and e , y 2 # y 2 = ( f ^ g ) & e # C H
add h , d # d = k + w + h + d # - -
and b , y 3 # y 3 = ( a | c ) & b # M A J A
xor T 1 , y 1 # y 1 = ( a > > 3 9 ) ^ ( a > > 3 4 ) # S 0
rorx $ 2 8 , a , T 1 # T 1 = ( a > > 2 8 ) # S 0
xor g , y 2 # y 2 = C H = ( ( f ^ g ) & e ) ^ g # C H
xor T 1 , y 1 # y 1 = ( a > > 3 9 ) ^ ( a > > 3 4 ) ^ ( a > > 2 8 ) # S 0
mov a , T 1 # T 1 = a # M A J B
and c , T 1 # T 1 = a & c # M A J B
add y 0 , y 2 # y 2 = S 1 + C H # - -
or T 1 , y 3 # y 3 = M A J = ( a | c ) & b ) | ( a & c ) # M A J
add y 1 , h # h = k + w + h + S 0 # - -
add y 2 , d # d = k + w + h + d + S 1 + C H = d + t 1 # - -
add y 2 , h # h = k + w + h + S 0 + S 1 + C H = t 1 + S 0 # - -
add y 3 , h # h = t 1 + S 0 + M A J # - -
RotateState
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # RND N + 2 ## # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
vpsrlq $ 1 9 , Y T M P 2 , Y T M P 3 # Y T M P 3 = W [ - 2 ] > > 1 9 { B A B A }
vpsllq $ ( 6 4 - 1 9 ) , Y T M P 2 , Y T M P 1 # Y T M P 1 = W [ - 2 ] < < 1 9 { B A B A }
vpor Y T M P 1 , Y T M P 3 , Y T M P 3 # Y T M P 3 = W [ - 2 ] r o r 1 9 { B A B A }
vpxor Y T M P 3 , Y T M P 4 , Y T M P 4 # Y T M P 4 = W [ - 2 ] r o r 1 9 ^ W [ - 2 ] > > 6 { B A B A }
vpsrlq $ 6 1 , Y T M P 2 , Y T M P 3 # Y T M P 3 = W [ - 2 ] > > 6 1 { B A B A }
vpsllq $ ( 6 4 - 6 1 ) , Y T M P 2 , Y T M P 1 # Y T M P 1 = W [ - 2 ] < < 6 1 { B A B A }
vpor Y T M P 1 , Y T M P 3 , Y T M P 3 # Y T M P 3 = W [ - 2 ] r o r 6 1 { B A B A }
vpxor Y T M P 3 , Y T M P 4 , Y T M P 4 # Y T M P 4 = s1 = ( W [ - 2 ] r o r 1 9 ) ^
# ( W[ - 2 ] r o r 6 1 ) ^ ( W [ - 2 ] > > 6 ) { B A B A }
# Add s i g m a1 t o t h e o t h e r c o m p u n e n t s t o g e t w [ 1 6 ] a n d w [ 1 7 ]
vpaddq Y T M P 4 , Y _ 0 , Y _ 0 # Y _ 0 = { W [ 1 ] , W [ 0 ] , W [ 1 ] , W [ 0 ] }
# Calculate s i g m a1 f o r w [ 1 8 ] a n d w [ 1 9 ] f o r u p p e r 1 2 8 b i t l a n e
vpsrlq $ 6 , Y _ 0 , Y T M P 4 # Y T M P 4 = W [ - 2 ] > > 6 { D C - - }
mov a , y 3 # y 3 = a # M A J A
rorx $ 4 1 , e , y 0 # y 0 = e > > 4 1 # S 1 A
add 2 * 8 + f r a m e _ X F E R ( % r s p ) , h # h = k + w + h # - -
rorx $ 1 8 , e , y 1 # y 1 = e > > 1 8 # S 1 B
or c , y 3 # y 3 = a | c # M A J A
mov f , y 2 # y 2 = f # C H
xor g , y 2 # y 2 = f ^ g # C H
rorx $ 3 4 , a , T 1 # T 1 = a > > 3 4 # S 0 B
xor y 1 , y 0 # y 0 = ( e > > 4 1 ) ^ ( e > > 1 8 ) # S 1
and e , y 2 # y 2 = ( f ^ g ) & e # C H
rorx $ 1 4 , e , y 1 # y 1 = ( e > > 1 4 ) # S 1
add h , d # d = k + w + h + d # - -
and b , y 3 # y 3 = ( a | c ) & b # M A J A
xor y 1 , y 0 # y 0 = ( e > > 4 1 ) ^ ( e > > 1 8 ) ^ ( e > > 1 4 ) # S 1
rorx $ 3 9 , a , y 1 # y 1 = a > > 3 9 # S 0 A
xor g , y 2 # y 2 = C H = ( ( f ^ g ) & e ) ^ g # C H
xor T 1 , y 1 # y 1 = ( a > > 3 9 ) ^ ( a > > 3 4 ) # S 0
rorx $ 2 8 , a , T 1 # T 1 = ( a > > 2 8 ) # S 0
xor T 1 , y 1 # y 1 = ( a > > 3 9 ) ^ ( a > > 3 4 ) ^ ( a > > 2 8 ) # S 0
mov a , T 1 # T 1 = a # M A J B
and c , T 1 # T 1 = a & c # M A J B
add y 0 , y 2 # y 2 = S 1 + C H # - -
or T 1 , y 3 # y 3 = M A J = ( a | c ) & b ) | ( a & c ) # M A J
add y 1 , h # h = k + w + h + S 0 # - -
add y 2 , d # d = k + w + h + d + S 1 + C H = d + t 1 # - -
add y 2 , h # h = k + w + h + S 0 + S 1 + C H = t 1 + S 0 # - -
add y 3 , h # h = t 1 + S 0 + M A J # - -
RotateState
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # RND N + 3 ## # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
vpsrlq $ 1 9 , Y _ 0 , Y T M P 3 # Y T M P 3 = W [ - 2 ] > > 1 9 { D C - - }
vpsllq $ ( 6 4 - 1 9 ) , Y _ 0 , Y T M P 1 # Y T M P 1 = W [ - 2 ] < < 1 9 { D C - - }
vpor Y T M P 1 , Y T M P 3 , Y T M P 3 # Y T M P 3 = W [ - 2 ] r o r 1 9 { D C - - }
vpxor Y T M P 3 , Y T M P 4 , Y T M P 4 # Y T M P 4 = W [ - 2 ] r o r 1 9 ^ W [ - 2 ] > > 6 { D C - - }
vpsrlq $ 6 1 , Y _ 0 , Y T M P 3 # Y T M P 3 = W [ - 2 ] > > 6 1 { D C - - }
vpsllq $ ( 6 4 - 6 1 ) , Y _ 0 , Y T M P 1 # Y T M P 1 = W [ - 2 ] < < 6 1 { D C - - }
vpor Y T M P 1 , Y T M P 3 , Y T M P 3 # Y T M P 3 = W [ - 2 ] r o r 6 1 { D C - - }
vpxor Y T M P 3 , Y T M P 4 , Y T M P 4 # Y T M P 4 = s1 = ( W [ - 2 ] r o r 1 9 ) ^
# ( W[ - 2 ] r o r 6 1 ) ^ ( W [ - 2 ] > > 6 ) { D C - - }
# Add t h e s i g m a0 + w [ t - 7 ] + w [ t - 1 6 ] f o r w [ 1 8 ] a n d w [ 1 9 ]
# to n e w l y c a l c u l a t e d s i g m a1 t o g e t w [ 1 8 ] a n d w [ 1 9 ]
vpaddq Y T M P 4 , Y T M P 0 , Y T M P 2 # Y T M P 2 = { W [ 3 ] , W [ 2 ] , - - , - - }
# Form w [ 1 9 , w [ 1 8 ] , w17 ] , w [ 1 6 ]
vpblendd $ 0 x F 0 , Y T M P 2 , Y _ 0 , Y _ 0 # Y _ 0 = { W [ 3 ] , W [ 2 ] , W [ 1 ] , W [ 0 ] }
mov a , y 3 # y 3 = a # M A J A
rorx $ 4 1 , e , y 0 # y 0 = e > > 4 1 # S 1 A
rorx $ 1 8 , e , y 1 # y 1 = e > > 1 8 # S 1 B
add 3 * 8 + f r a m e _ X F E R ( % r s p ) , h # h = k + w + h # - -
or c , y 3 # y 3 = a | c # M A J A
mov f , y 2 # y 2 = f # C H
rorx $ 3 4 , a , T 1 # T 1 = a > > 3 4 # S 0 B
xor y 1 , y 0 # y 0 = ( e > > 4 1 ) ^ ( e > > 1 8 ) # S 1
xor g , y 2 # y 2 = f ^ g # C H
rorx $ 1 4 , e , y 1 # y 1 = ( e > > 1 4 ) # S 1
and e , y 2 # y 2 = ( f ^ g ) & e # C H
add h , d # d = k + w + h + d # - -
and b , y 3 # y 3 = ( a | c ) & b # M A J A
xor y 1 , y 0 # y 0 = ( e > > 4 1 ) ^ ( e > > 1 8 ) ^ ( e > > 1 4 ) # S 1
xor g , y 2 # y 2 = C H = ( ( f ^ g ) & e ) ^ g # C H
rorx $ 3 9 , a , y 1 # y 1 = a > > 3 9 # S 0 A
add y 0 , y 2 # y 2 = S 1 + C H # - -
xor T 1 , y 1 # y 1 = ( a > > 3 9 ) ^ ( a > > 3 4 ) # S 0
add y 2 , d # d = k + w + h + d + S 1 + C H = d + t 1 # - -
rorx $ 2 8 , a , T 1 # T 1 = ( a > > 2 8 ) # S 0
xor T 1 , y 1 # y 1 = ( a > > 3 9 ) ^ ( a > > 3 4 ) ^ ( a > > 2 8 ) # S 0
mov a , T 1 # T 1 = a # M A J B
and c , T 1 # T 1 = a & c # M A J B
or T 1 , y 3 # y 3 = M A J = ( a | c ) & b ) | ( a & c ) # M A J
add y 1 , h # h = k + w + h + S 0 # - -
add y 2 , h # h = k + w + h + S 0 + S 1 + C H = t 1 + S 0 # - -
add y 3 , h # h = t 1 + S 0 + M A J # - -
RotateState
rotate_ Y s
.endm
.macro DO_4ROUNDS
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # RND N + 0 ## # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
mov f , y 2 # y 2 = f # C H
rorx $ 4 1 , e , y 0 # y 0 = e > > 4 1 # S 1 A
rorx $ 1 8 , e , y 1 # y 1 = e > > 1 8 # S 1 B
xor g , y 2 # y 2 = f ^ g # C H
xor y 1 , y 0 # y 0 = ( e > > 4 1 ) ^ ( e > > 1 8 ) # S 1
rorx $ 1 4 , e , y 1 # y 1 = ( e > > 1 4 ) # S 1
and e , y 2 # y 2 = ( f ^ g ) & e # C H
xor y 1 , y 0 # y 0 = ( e > > 4 1 ) ^ ( e > > 1 8 ) ^ ( e > > 1 4 ) # S 1
rorx $ 3 4 , a , T 1 # T 1 = a > > 3 4 # S 0 B
xor g , y 2 # y 2 = C H = ( ( f ^ g ) & e ) ^ g # C H
rorx $ 3 9 , a , y 1 # y 1 = a > > 3 9 # S 0 A
mov a , y 3 # y 3 = a # M A J A
xor T 1 , y 1 # y 1 = ( a > > 3 9 ) ^ ( a > > 3 4 ) # S 0
rorx $ 2 8 , a , T 1 # T 1 = ( a > > 2 8 ) # S 0
add f r a m e _ X F E R ( % r s p ) , h # h = k + w + h # - -
or c , y 3 # y 3 = a | c # M A J A
xor T 1 , y 1 # y 1 = ( a > > 3 9 ) ^ ( a > > 3 4 ) ^ ( a > > 2 8 ) # S 0
mov a , T 1 # T 1 = a # M A J B
and b , y 3 # y 3 = ( a | c ) & b # M A J A
and c , T 1 # T 1 = a & c # M A J B
add y 0 , y 2 # y 2 = S 1 + C H # - -
add h , d # d = k + w + h + d # - -
or T 1 , y 3 # y 3 = M A J = ( a | c ) & b ) | ( a & c ) # M A J
add y 1 , h # h = k + w + h + S 0 # - -
add y 2 , d # d = k + w + h + d + S 1 + C H = d + t 1 # - -
RotateState
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # RND N + 1 ## # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
add y 2 , o l d _ h # h = k + w + h + S 0 + S 1 + C H = t 1 + S 0 # - -
mov f , y 2 # y 2 = f # C H
rorx $ 4 1 , e , y 0 # y 0 = e > > 4 1 # S 1 A
rorx $ 1 8 , e , y 1 # y 1 = e > > 1 8 # S 1 B
xor g , y 2 # y 2 = f ^ g # C H
xor y 1 , y 0 # y 0 = ( e > > 4 1 ) ^ ( e > > 1 8 ) # S 1
rorx $ 1 4 , e , y 1 # y 1 = ( e > > 1 4 ) # S 1
and e , y 2 # y 2 = ( f ^ g ) & e # C H
add y 3 , o l d _ h # h = t 1 + S 0 + M A J # - -
xor y 1 , y 0 # y 0 = ( e > > 4 1 ) ^ ( e > > 1 8 ) ^ ( e > > 1 4 ) # S 1
rorx $ 3 4 , a , T 1 # T 1 = a > > 3 4 # S 0 B
xor g , y 2 # y 2 = C H = ( ( f ^ g ) & e ) ^ g # C H
rorx $ 3 9 , a , y 1 # y 1 = a > > 3 9 # S 0 A
mov a , y 3 # y 3 = a # M A J A
xor T 1 , y 1 # y 1 = ( a > > 3 9 ) ^ ( a > > 3 4 ) # S 0
rorx $ 2 8 , a , T 1 # T 1 = ( a > > 2 8 ) # S 0
add 8 * 1 + f r a m e _ X F E R ( % r s p ) , h # h = k + w + h # - -
or c , y 3 # y 3 = a | c # M A J A
xor T 1 , y 1 # y 1 = ( a > > 3 9 ) ^ ( a > > 3 4 ) ^ ( a > > 2 8 ) # S 0
mov a , T 1 # T 1 = a # M A J B
and b , y 3 # y 3 = ( a | c ) & b # M A J A
and c , T 1 # T 1 = a & c # M A J B
add y 0 , y 2 # y 2 = S 1 + C H # - -
add h , d # d = k + w + h + d # - -
or T 1 , y 3 # y 3 = M A J = ( a | c ) & b ) | ( a & c ) # M A J
add y 1 , h # h = k + w + h + S 0 # - -
add y 2 , d # d = k + w + h + d + S 1 + C H = d + t 1 # - -
RotateState
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # RND N + 2 ## # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
add y 2 , o l d _ h # h = k + w + h + S 0 + S 1 + C H = t 1 + S 0 # - -
mov f , y 2 # y 2 = f # C H
rorx $ 4 1 , e , y 0 # y 0 = e > > 4 1 # S 1 A
rorx $ 1 8 , e , y 1 # y 1 = e > > 1 8 # S 1 B
xor g , y 2 # y 2 = f ^ g # C H
xor y 1 , y 0 # y 0 = ( e > > 4 1 ) ^ ( e > > 1 8 ) # S 1
rorx $ 1 4 , e , y 1 # y 1 = ( e > > 1 4 ) # S 1
and e , y 2 # y 2 = ( f ^ g ) & e # C H
add y 3 , o l d _ h # h = t 1 + S 0 + M A J # - -
xor y 1 , y 0 # y 0 = ( e > > 4 1 ) ^ ( e > > 1 8 ) ^ ( e > > 1 4 ) # S 1
rorx $ 3 4 , a , T 1 # T 1 = a > > 3 4 # S 0 B
xor g , y 2 # y 2 = C H = ( ( f ^ g ) & e ) ^ g # C H
rorx $ 3 9 , a , y 1 # y 1 = a > > 3 9 # S 0 A
mov a , y 3 # y 3 = a # M A J A
xor T 1 , y 1 # y 1 = ( a > > 3 9 ) ^ ( a > > 3 4 ) # S 0
rorx $ 2 8 , a , T 1 # T 1 = ( a > > 2 8 ) # S 0
add 8 * 2 + f r a m e _ X F E R ( % r s p ) , h # h = k + w + h # - -
or c , y 3 # y 3 = a | c # M A J A
xor T 1 , y 1 # y 1 = ( a > > 3 9 ) ^ ( a > > 3 4 ) ^ ( a > > 2 8 ) # S 0
mov a , T 1 # T 1 = a # M A J B
and b , y 3 # y 3 = ( a | c ) & b # M A J A
and c , T 1 # T 1 = a & c # M A J B
add y 0 , y 2 # y 2 = S 1 + C H # - -
add h , d # d = k + w + h + d # - -
or T 1 , y 3 # y 3 = M A J = ( a | c ) & b ) | ( a & c ) # M A J
add y 1 , h # h = k + w + h + S 0 # - -
add y 2 , d # d = k + w + h + d + S 1 + C H = d + t 1 # - -
RotateState
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # RND N + 3 ## # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
add y 2 , o l d _ h # h = k + w + h + S 0 + S 1 + C H = t 1 + S 0 # - -
mov f , y 2 # y 2 = f # C H
rorx $ 4 1 , e , y 0 # y 0 = e > > 4 1 # S 1 A
rorx $ 1 8 , e , y 1 # y 1 = e > > 1 8 # S 1 B
xor g , y 2 # y 2 = f ^ g # C H
xor y 1 , y 0 # y 0 = ( e > > 4 1 ) ^ ( e > > 1 8 ) # S 1
rorx $ 1 4 , e , y 1 # y 1 = ( e > > 1 4 ) # S 1
and e , y 2 # y 2 = ( f ^ g ) & e # C H
add y 3 , o l d _ h # h = t 1 + S 0 + M A J # - -
xor y 1 , y 0 # y 0 = ( e > > 4 1 ) ^ ( e > > 1 8 ) ^ ( e > > 1 4 ) # S 1
rorx $ 3 4 , a , T 1 # T 1 = a > > 3 4 # S 0 B
xor g , y 2 # y 2 = C H = ( ( f ^ g ) & e ) ^ g # C H
rorx $ 3 9 , a , y 1 # y 1 = a > > 3 9 # S 0 A
mov a , y 3 # y 3 = a # M A J A
xor T 1 , y 1 # y 1 = ( a > > 3 9 ) ^ ( a > > 3 4 ) # S 0
rorx $ 2 8 , a , T 1 # T 1 = ( a > > 2 8 ) # S 0
add 8 * 3 + f r a m e _ X F E R ( % r s p ) , h # h = k + w + h # - -
or c , y 3 # y 3 = a | c # M A J A
xor T 1 , y 1 # y 1 = ( a > > 3 9 ) ^ ( a > > 3 4 ) ^ ( a > > 2 8 ) # S 0
mov a , T 1 # T 1 = a # M A J B
and b , y 3 # y 3 = ( a | c ) & b # M A J A
and c , T 1 # T 1 = a & c # M A J B
add y 0 , y 2 # y 2 = S 1 + C H # - -
add h , d # d = k + w + h + d # - -
or T 1 , y 3 # y 3 = M A J = ( a | c ) & b ) | ( a & c ) # M A J
add y 1 , h # h = k + w + h + S 0 # - -
add y 2 , d # d = k + w + h + d + S 1 + C H = d + t 1 # - -
add y 2 , h # h = k + w + h + S 0 + S 1 + C H = t 1 + S 0 # - -
add y 3 , h # h = t 1 + S 0 + M A J # - -
RotateState
.endm
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
2020-01-15 06:57:29 +03:00
# void s h a51 2 _ t r a n s f o r m _ r o r x ( s h a51 2 _ s t a t e * s t a t e , c o n s t u 8 * d a t a , i n t b l o c k s )
# Purpose : Updates t h e S H A 5 1 2 d i g e s t s t o r e d a t " s t a t e " w i t h t h e m e s s a g e
# stored i n " d a t a " .
# The s i z e o f t h e m e s s a g e p o i n t e d t o b y " d a t a " m u s t b e a n i n t e g e r m u l t i p l e
# of S H A 5 1 2 m e s s a g e b l o c k s .
# " blocks" i s t h e m e s s a g e l e n g t h i n S H A 5 1 2 b l o c k s
2013-03-27 00:59:55 +04:00
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
2019-10-11 14:51:04 +03:00
SYM_ F U N C _ S T A R T ( s h a51 2 _ t r a n s f o r m _ r o r x )
2013-03-27 00:59:55 +04:00
# Allocate S t a c k S p a c e
mov % r s p , % r a x
sub $ f r a m e _ s i z e , % r s p
and $ ~ ( 0 x20 - 1 ) , % r s p
mov % r a x , f r a m e _ R S P S A V E ( % r s p )
# Save G P R s
2017-09-18 22:42:10 +03:00
mov % r b x , 8 * 0 + f r a m e _ G P R S A V E ( % r s p )
mov % r12 , 8 * 1 + f r a m e _ G P R S A V E ( % r s p )
mov % r13 , 8 * 2 + f r a m e _ G P R S A V E ( % r s p )
mov % r14 , 8 * 3 + f r a m e _ G P R S A V E ( % r s p )
mov % r15 , 8 * 4 + f r a m e _ G P R S A V E ( % r s p )
2013-03-27 00:59:55 +04:00
shl $ 7 , N U M _ B L K S # c o n v e r t t o b y t e s
jz d o n e _ h a s h
add I N P , N U M _ B L K S # p o i n t e r t o e n d o f d a t a
mov N U M _ B L K S , f r a m e _ I N P E N D ( % r s p )
# # load i n i t i a l d i g e s t
2017-09-18 22:42:10 +03:00
mov 8 * 0 ( C T X 1 ) , a
mov 8 * 1 ( C T X 1 ) , b
mov 8 * 2 ( C T X 1 ) , c
mov 8 * 3 ( C T X 1 ) , d
mov 8 * 4 ( C T X 1 ) , e
mov 8 * 5 ( C T X 1 ) , f
mov 8 * 6 ( C T X 1 ) , g
mov 8 * 7 ( C T X 1 ) , h
# save % r d i ( C T X ) b e f o r e i t g e t s c l o b b e r e d
mov % r d i , f r a m e _ C T X ( % r s p )
2013-03-27 00:59:55 +04:00
vmovdqa P S H U F F L E _ B Y T E _ F L I P _ M A S K ( % r i p ) , B Y T E _ F L I P _ M A S K
loop0 :
lea K 5 1 2 ( % r i p ) , T B L
# # byte s w a p f i r s t 1 6 d w o r d s
COPY_ Y M M _ A N D _ B S W A P Y _ 0 , ( I N P ) , B Y T E _ F L I P _ M A S K
COPY_ Y M M _ A N D _ B S W A P Y _ 1 , 1 * 3 2 ( I N P ) , B Y T E _ F L I P _ M A S K
COPY_ Y M M _ A N D _ B S W A P Y _ 2 , 2 * 3 2 ( I N P ) , B Y T E _ F L I P _ M A S K
COPY_ Y M M _ A N D _ B S W A P Y _ 3 , 3 * 3 2 ( I N P ) , B Y T E _ F L I P _ M A S K
mov I N P , f r a m e _ I N P ( % r s p )
# # schedule 6 4 i n p u t d w o r d s , b y d o i n g 1 2 r o u n d s o f 4 e a c h
movq $ 4 , f r a m e _ S R N D ( % r s p )
.align 16
loop1 :
vpaddq ( T B L ) , Y _ 0 , X F E R
vmovdqa X F E R , f r a m e _ X F E R ( % r s p )
FOUR_ R O U N D S _ A N D _ S C H E D
vpaddq 1 * 3 2 ( T B L ) , Y _ 0 , X F E R
vmovdqa X F E R , f r a m e _ X F E R ( % r s p )
FOUR_ R O U N D S _ A N D _ S C H E D
vpaddq 2 * 3 2 ( T B L ) , Y _ 0 , X F E R
vmovdqa X F E R , f r a m e _ X F E R ( % r s p )
FOUR_ R O U N D S _ A N D _ S C H E D
vpaddq 3 * 3 2 ( T B L ) , Y _ 0 , X F E R
vmovdqa X F E R , f r a m e _ X F E R ( % r s p )
add $ ( 4 * 3 2 ) , T B L
FOUR_ R O U N D S _ A N D _ S C H E D
subq $ 1 , f r a m e _ S R N D ( % r s p )
jne l o o p1
movq $ 2 , f r a m e _ S R N D ( % r s p )
loop2 :
vpaddq ( T B L ) , Y _ 0 , X F E R
vmovdqa X F E R , f r a m e _ X F E R ( % r s p )
DO_ 4 R O U N D S
vpaddq 1 * 3 2 ( T B L ) , Y _ 1 , X F E R
vmovdqa X F E R , f r a m e _ X F E R ( % r s p )
add $ ( 2 * 3 2 ) , T B L
DO_ 4 R O U N D S
vmovdqa Y _ 2 , Y _ 0
vmovdqa Y _ 3 , Y _ 1
subq $ 1 , f r a m e _ S R N D ( % r s p )
jne l o o p2
2017-09-18 22:42:10 +03:00
mov f r a m e _ C T X ( % r s p ) , C T X 2
addm 8 * 0 ( C T X 2 ) , a
addm 8 * 1 ( C T X 2 ) , b
addm 8 * 2 ( C T X 2 ) , c
addm 8 * 3 ( C T X 2 ) , d
addm 8 * 4 ( C T X 2 ) , e
addm 8 * 5 ( C T X 2 ) , f
addm 8 * 6 ( C T X 2 ) , g
addm 8 * 7 ( C T X 2 ) , h
2013-03-27 00:59:55 +04:00
mov f r a m e _ I N P ( % r s p ) , I N P
add $ 1 2 8 , I N P
cmp f r a m e _ I N P E N D ( % r s p ) , I N P
jne l o o p0
done_hash :
# Restore G P R s
2017-09-18 22:42:10 +03:00
mov 8 * 0 + f r a m e _ G P R S A V E ( % r s p ) , % r b x
mov 8 * 1 + f r a m e _ G P R S A V E ( % r s p ) , % r12
mov 8 * 2 + f r a m e _ G P R S A V E ( % r s p ) , % r13
mov 8 * 3 + f r a m e _ G P R S A V E ( % r s p ) , % r14
mov 8 * 4 + f r a m e _ G P R S A V E ( % r s p ) , % r15
2013-03-27 00:59:55 +04:00
# Restore S t a c k P o i n t e r
mov f r a m e _ R S P S A V E ( % r s p ) , % r s p
ret
2019-10-11 14:51:04 +03:00
SYM_ F U N C _ E N D ( s h a51 2 _ t r a n s f o r m _ r o r x )
2013-03-27 00:59:55 +04:00
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # Binary D a t a
crypto: x86 - make constants readonly, allow linker to merge them
A lot of asm-optimized routines in arch/x86/crypto/ keep its
constants in .data. This is wrong, they should be on .rodata.
Mnay of these constants are the same in different modules.
For example, 128-bit shuffle mask 0x000102030405060708090A0B0C0D0E0F
exists in at least half a dozen places.
There is a way to let linker merge them and use just one copy.
The rules are as follows: mergeable objects of different sizes
should not share sections. You can't put them all in one .rodata
section, they will lose "mergeability".
GCC puts its mergeable constants in ".rodata.cstSIZE" sections,
or ".rodata.cstSIZE.<object_name>" if -fdata-sections is used.
This patch does the same:
.section .rodata.cst16.SHUF_MASK, "aM", @progbits, 16
It is important that all data in such section consists of
16-byte elements, not larger ones, and there are no implicit
use of one element from another.
When this is not the case, use non-mergeable section:
.section .rodata[.VAR_NAME], "a", @progbits
This reduces .data by ~15 kbytes:
text data bss dec hex filename
11097415 2705840 2630712 16433967 fac32f vmlinux-prev.o
11112095 2690672 2630712 16433479 fac147 vmlinux.o
Merged objects are visible in System.map:
ffffffff81a28810 r POLY
ffffffff81a28810 r POLY
ffffffff81a28820 r TWOONE
ffffffff81a28820 r TWOONE
ffffffff81a28830 r PSHUFFLE_BYTE_FLIP_MASK <- merged regardless of
ffffffff81a28830 r SHUF_MASK <------------- the name difference
ffffffff81a28830 r SHUF_MASK
ffffffff81a28830 r SHUF_MASK
..
ffffffff81a28d00 r K512 <- merged three identical 640-byte tables
ffffffff81a28d00 r K512
ffffffff81a28d00 r K512
Use of object names in section name suffixes is not strictly necessary,
but might help if someday link stage will use garbage collection
to eliminate unused sections (ld --gc-sections).
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
CC: Herbert Xu <herbert@gondor.apana.org.au>
CC: Josh Poimboeuf <jpoimboe@redhat.com>
CC: Xiaodong Liu <xiaodong.liu@intel.com>
CC: Megha Dey <megha.dey@intel.com>
CC: linux-crypto@vger.kernel.org
CC: x86@kernel.org
CC: linux-kernel@vger.kernel.org
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-01-20 00:33:04 +03:00
# Mergeable 6 4 0 - b y t e r o d a t a s e c t i o n . T h i s a l l o w s l i n k e r t o m e r g e t h e t a b l e
# with o t h e r , e x a c t l y t h e s a m e 6 4 0 - b y t e f r a g m e n t o f a n o t h e r r o d a t a s e c t i o n
# ( if s u c h s e c t i o n e x i s t s ) .
.section .rodata .cst640 .K512 , " aM" , @progbits, 640
2013-03-27 00:59:55 +04:00
.align 64
# K[ t ] u s e d i n S H A 5 1 2 h a s h i n g
K512 :
.quad 0 x4 2 8 a2 f98 d72 8 a e 2 2 ,0 x71 3 7 4 4 9 1 2 3 e f65 c d
.quad 0 xb5 c0 f b c f e c4 d3 b2 f ,0 x e 9 b5 d b a58 1 8 9 d b b c
.quad 0 x3 9 5 6 c25 b f34 8 b53 8 ,0 x59 f11 1 f1 b60 5 d01 9
.quad 0 x9 2 3 f82 a4 a f19 4 f9 b ,0 x a b1 c5 e d5 d a6 d81 1 8
.quad 0 xd8 0 7 a a98 a30 3 0 2 4 2 ,0 x12 8 3 5 b01 4 5 7 0 6 f b e
.quad 0 x2 4 3 1 8 5 b e 4 e e 4 b28 c ,0 x55 0 c7 d c3 d5 f f b4 e 2
.quad 0 x7 2 b e 5 d74 f27 b89 6 f ,0 x80 d e b1 f e 3 b16 9 6 b1
.quad 0 x9 b d c06 a72 5 c71 2 3 5 ,0 x c19 b f17 4 c f69 2 6 9 4
.quad 0 xe4 9 b69 c19 e f14 a d2 ,0 x e f b e 4 7 8 6 3 8 4 f25 e 3
.quad 0 x0 f c19 d c68 b8 c d5 b5 ,0 x24 0 c a1 c c77 a c9 c65
.quad 0 x2 d e 9 2 c6 f59 2 b02 7 5 ,0 x4 a74 8 4 a a6 e a6 e 4 8 3
.quad 0 x5 c b0 a9 d c b d41 f b d4 ,0 x76 f98 8 d a83 1 1 5 3 b5
.quad 0 x9 8 3 e 5 1 5 2 e e 6 6 d f a b ,0 x a83 1 c66 d2 d b43 2 1 0
.quad 0 xb0 0 3 2 7 c89 8 f b21 3 f ,0 x b f59 7 f c7 b e e f0 e e 4
.quad 0 xc6 e 0 0 b f33 d a88 f c2 ,0 x d5 a79 1 4 7 9 3 0 a a72 5
.quad 0 x0 6 c a63 5 1 e 0 0 3 8 2 6 f ,0 x14 2 9 2 9 6 7 0 a0 e 6 e 7 0
.quad 0 x2 7 b70 a85 4 6 d22 f f c ,0 x2 e 1 b21 3 8 5 c26 c92 6
.quad 0 x4 d2 c6 d f c5 a c42 a e d ,0 x53 3 8 0 d13 9 d95 b3 d f
.quad 0 x6 5 0 a73 5 4 8 b a f63 d e ,0 x76 6 a0 a b b3 c77 b2 a8
.quad 0 x8 1 c2 c92 e 4 7 e d a e e 6 ,0 x92 7 2 2 c85 1 4 8 2 3 5 3 b
.quad 0 xa2 b f e 8 a14 c f10 3 6 4 ,0 x a81 a66 4 b b c42 3 0 0 1
.quad 0 xc2 4 b8 b70 d0 f89 7 9 1 ,0 x c76 c51 a30 6 5 4 b e 3 0
.quad 0 xd1 9 2 e 8 1 9 d6 e f52 1 8 ,0 x d69 9 0 6 2 4 5 5 6 5 a91 0
.quad 0 xf4 0 e 3 5 8 5 5 7 7 1 2 0 2 a ,0 x10 6 a a07 0 3 2 b b d1 b8
.quad 0 x1 9 a4 c11 6 b8 d2 d0 c8 ,0 x1 e 3 7 6 c08 5 1 4 1 a b53
.quad 0 x2 7 4 8 7 7 4 c d f8 e e b99 ,0 x34 b0 b c b5 e 1 9 b48 a8
.quad 0 x3 9 1 c0 c b3 c5 c95 a63 ,0 x4 e d8 a a4 a e 3 4 1 8 a c b
.quad 0 x5 b9 c c a4 f77 6 3 e 3 7 3 ,0 x68 2 e 6 f f3 d6 b2 b8 a3
.quad 0 x7 4 8 f82 e e 5 d e f b2 f c ,0 x78 a56 3 6 f43 1 7 2 f60
.quad 0 x8 4 c87 8 1 4 a1 f0 a b72 ,0 x8 c c70 2 0 8 1 a64 3 9 e c
.quad 0 x9 0 b e f f f a23 6 3 1 e 2 8 ,0 x a45 0 6 c e b d e 8 2 b d e 9
.quad 0 xbef9 a3 f7 b2 c67 9 1 5 ,0 x c67 1 7 8 f2 e 3 7 2 5 3 2 b
.quad 0 xca2 7 3 e c e e a26 6 1 9 c ,0 x d18 6 b8 c72 1 c0 c20 7
.quad 0 xeada7 d d6 c d e 0 e b1 e ,0 x f57 d4 f7 f e e 6 e d17 8
.quad 0 x0 6 f06 7 a a72 1 7 6 f b a ,0 x0 a63 7 d c5 a2 c89 8 a6
.quad 0 x1 1 3 f98 0 4 b e f90 d a e ,0 x1 b71 0 b35 1 3 1 c47 1 b
.quad 0 x2 8 d b77 f52 3 0 4 7 d84 ,0 x32 c a a b7 b40 c72 4 9 3
.quad 0 x3 c9 e b e 0 a15 c9 b e b c ,0 x43 1 d67 c49 c10 0 d4 c
.quad 0 x4 c c5 d4 b e c b3 e 4 2 b6 ,0 x59 7 f29 9 c f c65 7 e 2 a
.quad 0 x5 f c b6 f a b3 a d6 f a e c ,0 x6 c44 1 9 8 c4 a47 5 8 1 7
crypto: x86 - make constants readonly, allow linker to merge them
A lot of asm-optimized routines in arch/x86/crypto/ keep its
constants in .data. This is wrong, they should be on .rodata.
Mnay of these constants are the same in different modules.
For example, 128-bit shuffle mask 0x000102030405060708090A0B0C0D0E0F
exists in at least half a dozen places.
There is a way to let linker merge them and use just one copy.
The rules are as follows: mergeable objects of different sizes
should not share sections. You can't put them all in one .rodata
section, they will lose "mergeability".
GCC puts its mergeable constants in ".rodata.cstSIZE" sections,
or ".rodata.cstSIZE.<object_name>" if -fdata-sections is used.
This patch does the same:
.section .rodata.cst16.SHUF_MASK, "aM", @progbits, 16
It is important that all data in such section consists of
16-byte elements, not larger ones, and there are no implicit
use of one element from another.
When this is not the case, use non-mergeable section:
.section .rodata[.VAR_NAME], "a", @progbits
This reduces .data by ~15 kbytes:
text data bss dec hex filename
11097415 2705840 2630712 16433967 fac32f vmlinux-prev.o
11112095 2690672 2630712 16433479 fac147 vmlinux.o
Merged objects are visible in System.map:
ffffffff81a28810 r POLY
ffffffff81a28810 r POLY
ffffffff81a28820 r TWOONE
ffffffff81a28820 r TWOONE
ffffffff81a28830 r PSHUFFLE_BYTE_FLIP_MASK <- merged regardless of
ffffffff81a28830 r SHUF_MASK <------------- the name difference
ffffffff81a28830 r SHUF_MASK
ffffffff81a28830 r SHUF_MASK
..
ffffffff81a28d00 r K512 <- merged three identical 640-byte tables
ffffffff81a28d00 r K512
ffffffff81a28d00 r K512
Use of object names in section name suffixes is not strictly necessary,
but might help if someday link stage will use garbage collection
to eliminate unused sections (ld --gc-sections).
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
CC: Herbert Xu <herbert@gondor.apana.org.au>
CC: Josh Poimboeuf <jpoimboe@redhat.com>
CC: Xiaodong Liu <xiaodong.liu@intel.com>
CC: Megha Dey <megha.dey@intel.com>
CC: linux-crypto@vger.kernel.org
CC: x86@kernel.org
CC: linux-kernel@vger.kernel.org
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-01-20 00:33:04 +03:00
.section .rodata .cst32 .PSHUFFLE_BYTE_FLIP_MASK , " aM" , @progbits, 32
2013-03-27 00:59:55 +04:00
.align 32
# Mask f o r b y t e - s w a p p i n g a c o u p l e o f q w o r d s i n a n X M M r e g i s t e r u s i n g ( v ) p s h u f b .
PSHUFFLE_BYTE_FLIP_MASK :
.octa 0x08090a0b0c0d0e0f0001020304050607
.octa 0x18191a1b1c1d1e1f1011121314151617
crypto: x86 - make constants readonly, allow linker to merge them
A lot of asm-optimized routines in arch/x86/crypto/ keep its
constants in .data. This is wrong, they should be on .rodata.
Mnay of these constants are the same in different modules.
For example, 128-bit shuffle mask 0x000102030405060708090A0B0C0D0E0F
exists in at least half a dozen places.
There is a way to let linker merge them and use just one copy.
The rules are as follows: mergeable objects of different sizes
should not share sections. You can't put them all in one .rodata
section, they will lose "mergeability".
GCC puts its mergeable constants in ".rodata.cstSIZE" sections,
or ".rodata.cstSIZE.<object_name>" if -fdata-sections is used.
This patch does the same:
.section .rodata.cst16.SHUF_MASK, "aM", @progbits, 16
It is important that all data in such section consists of
16-byte elements, not larger ones, and there are no implicit
use of one element from another.
When this is not the case, use non-mergeable section:
.section .rodata[.VAR_NAME], "a", @progbits
This reduces .data by ~15 kbytes:
text data bss dec hex filename
11097415 2705840 2630712 16433967 fac32f vmlinux-prev.o
11112095 2690672 2630712 16433479 fac147 vmlinux.o
Merged objects are visible in System.map:
ffffffff81a28810 r POLY
ffffffff81a28810 r POLY
ffffffff81a28820 r TWOONE
ffffffff81a28820 r TWOONE
ffffffff81a28830 r PSHUFFLE_BYTE_FLIP_MASK <- merged regardless of
ffffffff81a28830 r SHUF_MASK <------------- the name difference
ffffffff81a28830 r SHUF_MASK
ffffffff81a28830 r SHUF_MASK
..
ffffffff81a28d00 r K512 <- merged three identical 640-byte tables
ffffffff81a28d00 r K512
ffffffff81a28d00 r K512
Use of object names in section name suffixes is not strictly necessary,
but might help if someday link stage will use garbage collection
to eliminate unused sections (ld --gc-sections).
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
CC: Herbert Xu <herbert@gondor.apana.org.au>
CC: Josh Poimboeuf <jpoimboe@redhat.com>
CC: Xiaodong Liu <xiaodong.liu@intel.com>
CC: Megha Dey <megha.dey@intel.com>
CC: linux-crypto@vger.kernel.org
CC: x86@kernel.org
CC: linux-kernel@vger.kernel.org
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-01-20 00:33:04 +03:00
.section .rodata .cst32 .MASK_YMM_LO , " aM" , @progbits, 32
.align 32
2013-03-27 00:59:55 +04:00
MASK_YMM_LO :
.octa 0x00000000000000000000000000000000
.octa 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
crypto: x86 - make constants readonly, allow linker to merge them
A lot of asm-optimized routines in arch/x86/crypto/ keep its
constants in .data. This is wrong, they should be on .rodata.
Mnay of these constants are the same in different modules.
For example, 128-bit shuffle mask 0x000102030405060708090A0B0C0D0E0F
exists in at least half a dozen places.
There is a way to let linker merge them and use just one copy.
The rules are as follows: mergeable objects of different sizes
should not share sections. You can't put them all in one .rodata
section, they will lose "mergeability".
GCC puts its mergeable constants in ".rodata.cstSIZE" sections,
or ".rodata.cstSIZE.<object_name>" if -fdata-sections is used.
This patch does the same:
.section .rodata.cst16.SHUF_MASK, "aM", @progbits, 16
It is important that all data in such section consists of
16-byte elements, not larger ones, and there are no implicit
use of one element from another.
When this is not the case, use non-mergeable section:
.section .rodata[.VAR_NAME], "a", @progbits
This reduces .data by ~15 kbytes:
text data bss dec hex filename
11097415 2705840 2630712 16433967 fac32f vmlinux-prev.o
11112095 2690672 2630712 16433479 fac147 vmlinux.o
Merged objects are visible in System.map:
ffffffff81a28810 r POLY
ffffffff81a28810 r POLY
ffffffff81a28820 r TWOONE
ffffffff81a28820 r TWOONE
ffffffff81a28830 r PSHUFFLE_BYTE_FLIP_MASK <- merged regardless of
ffffffff81a28830 r SHUF_MASK <------------- the name difference
ffffffff81a28830 r SHUF_MASK
ffffffff81a28830 r SHUF_MASK
..
ffffffff81a28d00 r K512 <- merged three identical 640-byte tables
ffffffff81a28d00 r K512
ffffffff81a28d00 r K512
Use of object names in section name suffixes is not strictly necessary,
but might help if someday link stage will use garbage collection
to eliminate unused sections (ld --gc-sections).
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
CC: Herbert Xu <herbert@gondor.apana.org.au>
CC: Josh Poimboeuf <jpoimboe@redhat.com>
CC: Xiaodong Liu <xiaodong.liu@intel.com>
CC: Megha Dey <megha.dey@intel.com>
CC: linux-crypto@vger.kernel.org
CC: x86@kernel.org
CC: linux-kernel@vger.kernel.org
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-01-20 00:33:04 +03:00
2013-03-27 00:59:55 +04:00
# endif