github.com/emmansun/gmsm@v0.29.1/sm9/bn256/select_ppc64x.s (about)

     1  // Copyright 2024 Sun Yimin. All rights reserved.
     2  // Use of this source code is governed by a MIT-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build (ppc64 || ppc64le) && !purego
     6  
     7  #include "textflag.h"
     8  
     9  #define res_ptr R3
    10  #define a_ptr R4
    11  #define b_ptr R5
    12  
    13  // func gfpCopy(res, a *gfP)
    14  TEXT ·gfpCopy(SB),NOSPLIT,$0
    15  	MOVD res+0(FP), res_ptr
    16  	MOVD a+8(FP), a_ptr
    17  	MOVD $16, R10
    18  
    19  	LXVD2X (a_ptr)(R0), V0
    20  	LXVD2X (a_ptr)(R10), V1
    21  
    22  	STXVD2X V0, (res_ptr)(R0)
    23  	STXVD2X V1, (res_ptr)(R10)
    24  	RET
    25  
    26  #define copyFirst64 \
    27  	LXVD2X (a_ptr)(R0), V0     \
    28  	LXVD2X (a_ptr)(R6), V1     \
    29  	LXVD2X (a_ptr)(R7), V2     \
    30  	LXVD2X (a_ptr)(R8), V3     \
    31  	STXVD2X V0, (res_ptr)(R0)     \
    32  	STXVD2X V1, (res_ptr)(R6)     \
    33  	STXVD2X V2, (res_ptr)(R7)     \
    34  	STXVD2X V3, (res_ptr)(R8)
    35  
    36  #define copyNext64 \
    37  	LXVD2X (a_ptr)(R6), V0     \
    38  	LXVD2X (a_ptr)(R7), V1     \
    39  	LXVD2X (a_ptr)(R8), V2     \
    40  	LXVD2X (a_ptr)(R9), V3     \
    41  	STXVD2X V0, (res_ptr)(R6)     \
    42  	STXVD2X V1, (res_ptr)(R7)     \
    43  	STXVD2X V2, (res_ptr)(R8)     \
    44  	STXVD2X V3, (res_ptr)(R9)     \
    45  
    46  // func gfp2Copy(res, a *gfP2)
    47  TEXT ·gfp2Copy(SB),NOSPLIT,$0
    48  	MOVD res+0(FP), res_ptr
    49  	MOVD a+8(FP), a_ptr
    50  	MOVD $16, R6
    51  	MOVD $32, R7
    52  	MOVD $48, R8
    53  
    54  	copyFirst64
    55  	RET
    56  
    57  /* ---------------------------------------*/
    58  // func gfp4Copy(res, a *gfP4)
    59  TEXT ·gfp4Copy(SB),NOSPLIT,$0
    60  	MOVD res+0(FP), res_ptr
    61  	MOVD a+8(FP), a_ptr
    62  	MOVD $16, R6
    63  	MOVD $32, R7
    64  	MOVD $48, R8
    65  
    66  	copyFirst64
    67  
    68  	MOVD $0x40, R6
    69  	MOVD $0x50, R7
    70  	MOVD $0x60, R8
    71  	MOVD $0x70, R9
    72  
    73  	copyNext64
    74  
    75  	RET
    76  
    77  // func gfp6Copy(res, a *gfP6)
    78  TEXT ·gfp6Copy(SB),NOSPLIT,$0
    79  	MOVD res+0(FP), res_ptr
    80  	MOVD a+8(FP), a_ptr
    81  	MOVD $16, R6
    82  	MOVD $32, R7
    83  	MOVD $48, R8
    84  	copyFirst64
    85  
    86  	MOVD $0x40, R6
    87  	MOVD $0x50, R7
    88  	MOVD $0x60, R8
    89  	MOVD $0x70, R9
    90  	copyNext64
    91  
    92  	MOVD $0x80, R6
    93  	MOVD $0x90, R7
    94  	MOVD $0xa0, R8
    95  	MOVD $0xb0, R9
    96  	copyNext64
    97  	RET
    98  
    99  // func gfp12Copy(res, a *gfP12)
   100  TEXT ·gfp12Copy(SB),NOSPLIT,$0
   101  	MOVD res+0(FP), res_ptr
   102  	MOVD a+8(FP), a_ptr
   103  	MOVD $16, R6
   104  	MOVD $32, R7
   105  	MOVD $48, R8
   106  	copyFirst64
   107  
   108  	MOVD $0x40, R6
   109  	MOVD $0x50, R7
   110  	MOVD $0x60, R8
   111  	MOVD $0x70, R9
   112  	copyNext64
   113  
   114  	MOVD $0x80, R6
   115  	MOVD $0x90, R7
   116  	MOVD $0xa0, R8
   117  	MOVD $0xb0, R9
   118  	copyNext64
   119  
   120  	MOVD $0xc0, R6
   121  	MOVD $0xd0, R7
   122  	MOVD $0xe0, R8
   123  	MOVD $0xf0, R9
   124  	copyNext64
   125  
   126  	MOVD $0x0100, R6
   127  	MOVD $0x0110, R7
   128  	MOVD $0x0120, R8
   129  	MOVD $0x0130, R9
   130  	copyNext64
   131  
   132  	MOVD $0x0140, R6
   133  	MOVD $0x0150, R7
   134  	MOVD $0x0160, R8
   135  	MOVD $0x0170, R9
   136  	copyNext64	
   137  	RET
   138  
   139  #define ZER V10
   140  #define SEL V11
   141  
   142  #define moveFirst64 \
   143  	LXVD2X (a_ptr)(R0), V0     \
   144  	LXVD2X (a_ptr)(R6), V1     \
   145  	LXVD2X (a_ptr)(R7), V2     \
   146  	LXVD2X (a_ptr)(R8), V3     \
   147  	LXVD2X (b_ptr)(R0), V4     \
   148  	LXVD2X (b_ptr)(R6), V5     \
   149  	LXVD2X (b_ptr)(R7), V6     \
   150  	LXVD2X (b_ptr)(R8), V7     \
   151  	VSEL V0, V4, SEL, V0     \
   152  	VSEL V1, V5, SEL, V1     \
   153  	VSEL V2, V6, SEL, V2     \
   154  	VSEL V3, V7, SEL, V3     \
   155  	STXVD2X V0, (res_ptr)(R0)     \
   156  	STXVD2X V1, (res_ptr)(R6)     \
   157  	STXVD2X V2, (res_ptr)(R7)     \
   158  	STXVD2X V3, (res_ptr)(R8)
   159  
   160  #define moveNext64 \
   161  	LXVD2X (a_ptr)(R6), V0     \
   162  	LXVD2X (a_ptr)(R7), V1     \
   163  	LXVD2X (a_ptr)(R8), V2     \
   164  	LXVD2X (a_ptr)(R9), V3     \
   165  	LXVD2X (b_ptr)(R6), V4     \
   166  	LXVD2X (b_ptr)(R7), V5     \
   167  	LXVD2X (b_ptr)(R8), V6     \
   168  	LXVD2X (b_ptr)(R9), V7     \
   169  	VSEL V0, V4, SEL, V0     \
   170  	VSEL V1, V5, SEL, V1     \
   171  	VSEL V2, V6, SEL, V2     \
   172  	VSEL V3, V7, SEL, V3     \	
   173  	STXVD2X V0, (res_ptr)(R6)     \
   174  	STXVD2X V1, (res_ptr)(R7)     \
   175  	STXVD2X V2, (res_ptr)(R8)     \
   176  	STXVD2X V3, (res_ptr)(R9)     \
   177  
   178  // func gfP12MovCond(res, a, b *gfP12, cond int)
   179  // If cond == 0 res=b, else res=a
   180  TEXT ·gfP12MovCond(SB),NOSPLIT,$0
   181  	MOVD	res+0(FP), res_ptr
   182  	MOVD	a+8(FP), a_ptr
   183  	MOVD	b+16(FP), b_ptr
   184  	MOVD $56, R21
   185  	// cond is R1 + 24 (cond offset) + 32
   186  	LXVDSX (R1)(R21), SEL
   187  	VSPLTISB $0, ZER
   188  	// SEL controls whether to store a or b
   189  	VCMPEQUD SEL, ZER, SEL
   190  
   191  	MOVD $16, R6
   192  	MOVD $32, R7
   193  	MOVD $48, R8
   194  	moveFirst64
   195  
   196  	MOVD $0x40, R6
   197  	MOVD $0x50, R7
   198  	MOVD $0x60, R8
   199  	MOVD $0x70, R9
   200  	moveNext64
   201  
   202  	MOVD $0x80, R6
   203  	MOVD $0x90, R7
   204  	MOVD $0xa0, R8
   205  	MOVD $0xb0, R9
   206  	moveNext64
   207  
   208  	MOVD $0xc0, R6
   209  	MOVD $0xd0, R7
   210  	MOVD $0xe0, R8
   211  	MOVD $0xf0, R9
   212  	moveNext64
   213  
   214  	MOVD $0x0100, R6
   215  	MOVD $0x0110, R7
   216  	MOVD $0x0120, R8
   217  	MOVD $0x0130, R9
   218  	moveNext64
   219  
   220  	MOVD $0x0140, R6
   221  	MOVD $0x0150, R7
   222  	MOVD $0x0160, R8
   223  	MOVD $0x0170, R9
   224  	moveNext64
   225  	RET
   226  
   227  // func curvePointMovCond(res, a, b *curvePoint, cond int)
   228  // If cond == 0 res=b, else res=a
   229  TEXT ·curvePointMovCond(SB),NOSPLIT,$0
   230  	MOVD	res+0(FP), res_ptr
   231  	MOVD	a+8(FP), a_ptr
   232  	MOVD	b+16(FP), b_ptr
   233  	MOVD $56, R21
   234  	// cond is R1 + 24 (cond offset) + 32
   235  	LXVDSX (R1)(R21), SEL
   236  	VSPLTISB $0, ZER
   237  	// SEL controls whether to store a or b
   238  	VCMPEQUD SEL, ZER, SEL
   239  
   240  	MOVD $16, R6
   241  	MOVD $32, R7
   242  	MOVD $48, R8
   243  	moveFirst64
   244  
   245  	MOVD $0x40, R6
   246  	MOVD $0x50, R7
   247  	MOVD $0x60, R8
   248  	MOVD $0x70, R9
   249  	moveNext64	
   250  	RET
   251  
   252  // func twistPointMovCond(res, a, b *twistPoint, cond int)
   253  // If cond == 0 res=b, else res=a
   254  TEXT ·twistPointMovCond(SB),NOSPLIT,$0
   255  	MOVD	res+0(FP), res_ptr
   256  	MOVD	a+8(FP), a_ptr
   257  	MOVD	b+16(FP), b_ptr
   258  	MOVD $56, R21
   259  	// cond is R1 + 24 (cond offset) + 32
   260  	LXVDSX (R1)(R21), SEL
   261  	VSPLTISB $0, ZER
   262  	// SEL controls whether to store a or b
   263  	VCMPEQUD SEL, ZER, SEL
   264  
   265  	MOVD $16, R6
   266  	MOVD $32, R7
   267  	MOVD $48, R8
   268  	moveFirst64
   269  
   270  	MOVD $0x40, R6
   271  	MOVD $0x50, R7
   272  	MOVD $0x60, R8
   273  	MOVD $0x70, R9
   274  	moveNext64
   275  
   276  	MOVD $0x80, R6
   277  	MOVD $0x90, R7
   278  	MOVD $0xa0, R8
   279  	MOVD $0xb0, R9
   280  	moveNext64
   281  
   282  	MOVD $0xc0, R6
   283  	MOVD $0xd0, R7
   284  	MOVD $0xe0, R8
   285  	MOVD $0xf0, R9
   286  	moveNext64
   287  
   288  	RET