gitee.com/quant1x/num@v0.3.2/asm/c2goasm/constants_test.go (about)

     1  /*
     2   * Minio Cloud Storage, (C) 2017 Minio, Inc.
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package main
    18  
    19  import (
    20  	"strings"
    21  	"testing"
    22  )
    23  
    24  func testConstant(t *testing.T, constants, expected string) {
    25  
    26  	table := defineTable(strings.Split(constants, "\n"), "LCTABLE")
    27  
    28  	if table.Constants != expected {
    29  		t.Errorf("TestConstants(): \nexpected %s\ngot      %s", expected, table.Constants)
    30  	}
    31  }
    32  
    33  func TestConstants(t *testing.T) {
    34  
    35  	constant1 := `LCPI0_0:
    36          .byte   255                     ## 0xff
    37          .byte   0                       ## 0x0
    38          .byte   255                     ## 0xff
    39          .byte   0                       ## 0x0
    40          .byte   255                     ## 0xff
    41          .byte   0                       ## 0x0
    42          .byte   255                     ## 0xff
    43          .byte   0                       ## 0x0
    44          .byte   255                     ## 0xff
    45          .byte   0                       ## 0x0
    46          .byte   255                     ## 0xff
    47          .byte   0                       ## 0x0
    48          .byte   255                     ## 0xff
    49          .byte   0                       ## 0x0
    50          .byte   255                     ## 0xff
    51          .byte   0                       ## 0x0
    52          .byte   255                     ## 0xff
    53          .byte   0                       ## 0x0
    54          .byte   255                     ## 0xff
    55          .byte   0                       ## 0x0
    56          .byte   255                     ## 0xff
    57          .byte   0                       ## 0x0
    58          .byte   255                     ## 0xff
    59          .byte   0                       ## 0x0
    60          .byte   255                     ## 0xff
    61          .byte   0                       ## 0x0
    62          .byte   255                     ## 0xff
    63          .byte   0                       ## 0x0
    64          .byte   255                     ## 0xff
    65          .byte   0                       ## 0x0
    66          .byte   255                     ## 0xff
    67          .byte   0                       ## 0x0
    68  LCPI0_1:
    69          .short  9617                    ## 0x2591
    70          .short  0                       ## 0x0
    71          .short  9617                    ## 0x2591
    72          .short  0                       ## 0x0
    73          .short  9617                    ## 0x2591
    74          .short  0                       ## 0x0
    75          .short  9617                    ## 0x2591
    76          .short  0                       ## 0x0
    77          .short  9617                    ## 0x2591
    78          .short  0                       ## 0x0
    79          .short  9617                    ## 0x2591
    80          .short  0                       ## 0x0
    81          .short  9617                    ## 0x2591
    82          .short  0                       ## 0x0
    83          .short  9617                    ## 0x2591
    84          .short  0                       ## 0x0
    85  LCPI0_2:
    86          .short  1868                    ## 0x74c
    87          .short  4899                    ## 0x1323
    88          .short  1868                    ## 0x74c
    89          .short  4899                    ## 0x1323
    90          .short  1868                    ## 0x74c
    91          .short  4899                    ## 0x1323
    92          .short  1868                    ## 0x74c
    93          .short  4899                    ## 0x1323
    94          .short  1868                    ## 0x74c
    95          .short  4899                    ## 0x1323
    96          .short  1868                    ## 0x74c
    97          .short  4899                    ## 0x1323
    98          .short  1868                    ## 0x74c
    99          .short  4899                    ## 0x1323
   100          .short  1868                    ## 0x74c
   101          .short  4899                    ## 0x1323
   102          .section        __TEXT,__literal4,4byte_literals
   103          .align  1
   104  LCPI0_3:
   105          .long   8192                    ## 0x2000`
   106  
   107  	table1 := `DATA LCTABLE<>+0x000(SB)/8, $0x00ff00ff00ff00ff
   108  DATA LCTABLE<>+0x008(SB)/8, $0x00ff00ff00ff00ff
   109  DATA LCTABLE<>+0x010(SB)/8, $0x00ff00ff00ff00ff
   110  DATA LCTABLE<>+0x018(SB)/8, $0x00ff00ff00ff00ff
   111  DATA LCTABLE<>+0x020(SB)/8, $0x0000259100002591
   112  DATA LCTABLE<>+0x028(SB)/8, $0x0000259100002591
   113  DATA LCTABLE<>+0x030(SB)/8, $0x0000259100002591
   114  DATA LCTABLE<>+0x038(SB)/8, $0x0000259100002591
   115  DATA LCTABLE<>+0x040(SB)/8, $0x1323074c1323074c
   116  DATA LCTABLE<>+0x048(SB)/8, $0x1323074c1323074c
   117  DATA LCTABLE<>+0x050(SB)/8, $0x1323074c1323074c
   118  DATA LCTABLE<>+0x058(SB)/8, $0x1323074c1323074c
   119  DATA LCTABLE<>+0x060(SB)/8, $0x0000000000002000
   120  GLOBL LCTABLE<>(SB), 8, $104`
   121  
   122  	testConstant(t, constant1, table1)
   123  
   124  	constant2 := `LCPI0_0:
   125          .quad   72340172838076673       ## 0x101010101010101
   126  LCPI0_2:
   127          .quad   4294967297              ## 0x100000001
   128          .section        __TEXT,__const
   129          .align  32
   130  LCPI0_1:
   131          .long   0                       ## 0x0
   132          .long   2                       ## 0x2
   133          .long   4                       ## 0x4
   134          .long   6                       ## 0x6
   135          .long   1                       ## 0x1
   136          .long   3                       ## 0x3
   137          .long   5                       ## 0x5
   138          .long   7                       ## 0x7
   139          .section        __TEXT,__literal4,4byte_literals
   140          .align  2
   141  LCPI0_3:
   142          .long   1065353216              ## 0x3f800000`
   143  
   144  	table2 := `DATA LCTABLE<>+0x000(SB)/8, $0x0101010101010101
   145  DATA LCTABLE<>+0x008(SB)/8, $0x0000000100000001
   146  DATA LCTABLE<>+0x010(SB)/8, $0x0000000000000000
   147  DATA LCTABLE<>+0x018(SB)/8, $0x0000000000000000
   148  DATA LCTABLE<>+0x020(SB)/8, $0x0000000200000000
   149  DATA LCTABLE<>+0x028(SB)/8, $0x0000000600000004
   150  DATA LCTABLE<>+0x030(SB)/8, $0x0000000300000001
   151  DATA LCTABLE<>+0x038(SB)/8, $0x0000000700000005
   152  DATA LCTABLE<>+0x040(SB)/8, $0x000000003f800000
   153  GLOBL LCTABLE<>(SB), 8, $72`
   154  
   155  	testConstant(t, constant2, table2)
   156  
   157  	constant3 := `LCPI0_0:
   158  	.space	32,1
   159  LCPI0_1:
   160  	.short	2                       ## 0x2
   161  	.short	2                       ## 0x2
   162  	.short	2                       ## 0x2
   163  	.short	2                       ## 0x2
   164  	.short	2                       ## 0x2
   165  	.short	2                       ## 0x2
   166  	.short	2                       ## 0x2
   167  	.short	2                       ## 0x2
   168  	.short	2                       ## 0x2
   169  	.short	2                       ## 0x2
   170  	.short	2                       ## 0x2
   171  	.short	2                       ## 0x2
   172  	.short	2                       ## 0x2
   173  	.short	2                       ## 0x2
   174  	.short	2                       ## 0x2
   175  	.short	2                       ## 0x2`
   176  
   177  	table3 := `DATA LCTABLE<>+0x000(SB)/8, $0x0101010101010101
   178  DATA LCTABLE<>+0x008(SB)/8, $0x0101010101010101
   179  DATA LCTABLE<>+0x010(SB)/8, $0x0101010101010101
   180  DATA LCTABLE<>+0x018(SB)/8, $0x0101010101010101
   181  DATA LCTABLE<>+0x020(SB)/8, $0x0002000200020002
   182  DATA LCTABLE<>+0x028(SB)/8, $0x0002000200020002
   183  DATA LCTABLE<>+0x030(SB)/8, $0x0002000200020002
   184  DATA LCTABLE<>+0x038(SB)/8, $0x0002000200020002
   185  GLOBL LCTABLE<>(SB), 8, $64`
   186  
   187  	testConstant(t, constant3, table3)
   188  
   189  	constant4 := `.LCPI1_0:
   190  	.byte	255                     # 0xff
   191  	.byte	0                       # 0x0
   192  	.byte	255                     # 0xff
   193  	.byte	0                       # 0x0
   194  	.byte	255                     # 0xff
   195  	.byte	0                       # 0x0
   196  	.byte	255                     # 0xff
   197  	.byte	0                       # 0x0
   198  	.byte	255                     # 0xff
   199  	.byte	0                       # 0x0
   200  	.byte	255                     # 0xff
   201  	.byte	0                       # 0x0
   202  	.byte	255                     # 0xff
   203  	.byte	0                       # 0x0
   204  	.byte	255                     # 0xff
   205  	.byte	0                       # 0x0
   206  .LCPI1_2:
   207  	.quad	281474976776192         # 0x1000000010000
   208  	.quad	281474976776192         # 0x1000000010000
   209  .LCPI1_3:
   210  	.short	1606                    # 0x646
   211  	.short	4211                    # 0x1073
   212  	.short	1606                    # 0x646
   213  	.short	4211                    # 0x1073
   214  	.short	1606                    # 0x646
   215  	.short	4211                    # 0x1073
   216  	.short	1606                    # 0x646
   217  	.short	4211                    # 0x1073
   218  .LCPI1_12:
   219  	.zero	16`
   220  
   221  	table4 := `DATA LCTABLE<>+0x000(SB)/8, $0x00ff00ff00ff00ff
   222  DATA LCTABLE<>+0x008(SB)/8, $0x00ff00ff00ff00ff
   223  DATA LCTABLE<>+0x010(SB)/8, $0x0001000000010000
   224  DATA LCTABLE<>+0x018(SB)/8, $0x0001000000010000
   225  DATA LCTABLE<>+0x020(SB)/8, $0x1073064610730646
   226  DATA LCTABLE<>+0x028(SB)/8, $0x1073064610730646
   227  DATA LCTABLE<>+0x030(SB)/8, $0x0000000000000000
   228  DATA LCTABLE<>+0x038(SB)/8, $0x0000000000000000
   229  GLOBL LCTABLE<>(SB), 8, $64`
   230  
   231  	testConstant(t, constant4, table4)
   232  
   233  	constant5 := `        .p2align        4
   234  .LCPI0_0:
   235          .long   1127219200              # 0x43300000
   236          .long   1160773632              # 0x45300000
   237          .long   0                       # 0x0
   238          .long   0                       # 0x0
   239  .LCPI0_1:
   240          .quad   4841369599423283200     # double 4503599627370496
   241          .quad   4985484787499139072     # double 1.9342813113834067E+25
   242          .section        .rodata.cst8,"aM",@progbits,8
   243          .p2align        3
   244  .LCPI0_2:
   245          .quad   4602678819172646912     # double 0.5
   246  .LCPI0_3:
   247          .quad   -4620693217682128896    # double -0.5
   248          .section        .rodata.cst4,"aM",@progbits,4
   249          .p2align        5, 0x12
   250  .LCPI0_4:
   251          .long   1098907648              # float 16`
   252  
   253  	table5 := `DATA LCTABLE<>+0x000(SB)/8, $0x4530000043300000
   254  DATA LCTABLE<>+0x008(SB)/8, $0x0000000000000000
   255  DATA LCTABLE<>+0x010(SB)/8, $0x4330000000000000
   256  DATA LCTABLE<>+0x018(SB)/8, $0x4530000000000000
   257  DATA LCTABLE<>+0x020(SB)/8, $0x3fe0000000000000
   258  DATA LCTABLE<>+0x028(SB)/8, $0xbfe0000000000000
   259  DATA LCTABLE<>+0x030(SB)/8, $0x1212121212121212
   260  DATA LCTABLE<>+0x038(SB)/8, $0x1212121212121212
   261  DATA LCTABLE<>+0x040(SB)/8, $0x0000000041800000
   262  GLOBL LCTABLE<>(SB), 8, $72`
   263  
   264  	testConstant(t, constant5, table5)
   265  
   266  	constant6 := `        .p2align        4
   267  .LCPI1_0:
   268          .zero   16,1
   269  .LCPI1_1:
   270          .short  4                       # 0x4
   271          .short  4                       # 0x4
   272          .short  4                       # 0x4
   273          .short  4                       # 0x4
   274          .short  4                       # 0x4
   275          .short  4                       # 0x4
   276          .short  4                       # 0x4
   277          .short  4                       # 0x4`
   278  
   279  	table6 := `DATA LCTABLE<>+0x000(SB)/8, $0x0101010101010101
   280  DATA LCTABLE<>+0x008(SB)/8, $0x0101010101010101
   281  DATA LCTABLE<>+0x010(SB)/8, $0x0004000400040004
   282  DATA LCTABLE<>+0x018(SB)/8, $0x0004000400040004
   283  GLOBL LCTABLE<>(SB), 8, $32`
   284  
   285  	testConstant(t, constant6, table6)
   286  }