mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-02-26 07:49:05 +00:00
Make further progress on non-x86 support
This commit is contained in:
parent
aef9a69a60
commit
036b9a0002
155 changed files with 2307 additions and 653 deletions
examples
libc
calls
fmt
intrin
nexgen32e
runtime
str
tinymath
LICENSE.fdlibmLICENSE.freebsdLICENSE.muslLICENSE.openbsdLICENSE.optimized-routinesREADME.cosmoacoshl.cacosl.casinhl.casinl.catan2f.catan2l.catanhl.catanl.ccacoshl.ccacosl.ccasinhl.ccasinl.ccatanhl.ccbrtl.cccosh.cccoshl.cccosl.cceil.cceilf.cceill.ccexpl.cclogl.ccopysignl.ccoshl.ccosl.ccpowl.ccsinhf.ccsinhl.ccsinl.ccsqrtl.cctanhl.cctanl.cexp10l.cexp2l.cexpl.cexpm1l.cf2ld2.Sfabs.cfabsf.cfabsl.cfloor.cfloorf.cfloorl.cfma.cfmaf.cfmodl.cfrexpl.chypotl.cilogbl.cktanl.cllrint.cllrintf.clog10f.clog10l.clog1pl.clog2l.clogl.clrint.clrintf.clround.clroundf.cmodfl.cnearbyint.cnearbyintf.cnearbyintl.cnextafterl.cpowl.crempio2.c
300
examples/cescapec.c
Normal file
300
examples/cescapec.c
Normal file
|
@ -0,0 +1,300 @@
|
||||||
|
#if 0
|
||||||
|
/*─────────────────────────────────────────────────────────────────╗
|
||||||
|
│ To the extent possible under law, Justine Tunney has waived │
|
||||||
|
│ all copyright and related or neighboring rights to this file, │
|
||||||
|
│ as it is written in the following disclaimers: │
|
||||||
|
│ • http://unlicense.org/ │
|
||||||
|
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
||||||
|
╚─────────────────────────────────────────────────────────────────*/
|
||||||
|
#endif
|
||||||
|
#include "libc/stdio/stdio.h"
|
||||||
|
#include "libc/str/str.h"
|
||||||
|
|
||||||
|
int _cescapec2(int);
|
||||||
|
|
||||||
|
uint32_t kCescapeC[256] = {
|
||||||
|
[0] = '\\' | '0' << 8 | '0' << 16 | '0' << 24,
|
||||||
|
[1] = '\\' | '0' << 8 | '0' << 16 | '1' << 24,
|
||||||
|
[2] = '\\' | '0' << 8 | '0' << 16 | '2' << 24,
|
||||||
|
[3] = '\\' | '0' << 8 | '0' << 16 | '3' << 24,
|
||||||
|
[4] = '\\' | '0' << 8 | '0' << 16 | '4' << 24,
|
||||||
|
[5] = '\\' | '0' << 8 | '0' << 16 | '5' << 24,
|
||||||
|
[6] = '\\' | '0' << 8 | '0' << 16 | '6' << 24,
|
||||||
|
[7] = '\\' | 'a' << 8,
|
||||||
|
[8] = '\\' | 'b' << 8,
|
||||||
|
[9] = '\\' | 't' << 8,
|
||||||
|
[10] = '\\' | 'n' << 8,
|
||||||
|
[11] = '\\' | 'v' << 8,
|
||||||
|
[12] = '\\' | 'f' << 8,
|
||||||
|
[13] = '\\' | 'r' << 8,
|
||||||
|
[14] = '\\' | '0' << 8 | '1' << 16 | '6' << 24,
|
||||||
|
[15] = '\\' | '0' << 8 | '1' << 16 | '7' << 24,
|
||||||
|
[16] = '\\' | '0' << 8 | '2' << 16 | '0' << 24,
|
||||||
|
[17] = '\\' | '0' << 8 | '2' << 16 | '1' << 24,
|
||||||
|
[18] = '\\' | '0' << 8 | '2' << 16 | '2' << 24,
|
||||||
|
[19] = '\\' | '0' << 8 | '2' << 16 | '3' << 24,
|
||||||
|
[20] = '\\' | '0' << 8 | '2' << 16 | '4' << 24,
|
||||||
|
[21] = '\\' | '0' << 8 | '2' << 16 | '5' << 24,
|
||||||
|
[22] = '\\' | '0' << 8 | '2' << 16 | '6' << 24,
|
||||||
|
[23] = '\\' | '0' << 8 | '2' << 16 | '7' << 24,
|
||||||
|
[24] = '\\' | '0' << 8 | '3' << 16 | '0' << 24,
|
||||||
|
[25] = '\\' | '0' << 8 | '3' << 16 | '1' << 24,
|
||||||
|
[26] = '\\' | '0' << 8 | '3' << 16 | '2' << 24,
|
||||||
|
[27] = '\\' | '0' << 8 | '3' << 16 | '3' << 24,
|
||||||
|
[28] = '\\' | '0' << 8 | '3' << 16 | '4' << 24,
|
||||||
|
[29] = '\\' | '0' << 8 | '3' << 16 | '5' << 24,
|
||||||
|
[30] = '\\' | '0' << 8 | '3' << 16 | '6' << 24,
|
||||||
|
[31] = '\\' | '0' << 8 | '3' << 16 | '7' << 24,
|
||||||
|
[32] = ' ',
|
||||||
|
[33] = '!',
|
||||||
|
[34] = '\\' | '"' << 8,
|
||||||
|
[35] = '#',
|
||||||
|
[36] = '$',
|
||||||
|
[37] = '%',
|
||||||
|
[38] = '&',
|
||||||
|
[39] = '\\' | '\'' << 8,
|
||||||
|
[40] = '(',
|
||||||
|
[41] = ')',
|
||||||
|
[42] = '*',
|
||||||
|
[43] = '+',
|
||||||
|
[44] = ',',
|
||||||
|
[45] = '-',
|
||||||
|
[46] = '.',
|
||||||
|
[47] = '/',
|
||||||
|
[48] = '0',
|
||||||
|
[49] = '1',
|
||||||
|
[50] = '2',
|
||||||
|
[51] = '3',
|
||||||
|
[52] = '4',
|
||||||
|
[53] = '5',
|
||||||
|
[54] = '6',
|
||||||
|
[55] = '7',
|
||||||
|
[56] = '8',
|
||||||
|
[57] = '9',
|
||||||
|
[58] = ':',
|
||||||
|
[59] = ';',
|
||||||
|
[60] = '<',
|
||||||
|
[61] = '=',
|
||||||
|
[62] = '>',
|
||||||
|
[63] = '?',
|
||||||
|
[64] = '@',
|
||||||
|
[65] = 'A',
|
||||||
|
[66] = 'B',
|
||||||
|
[67] = 'C',
|
||||||
|
[68] = 'D',
|
||||||
|
[69] = 'E',
|
||||||
|
[70] = 'F',
|
||||||
|
[71] = 'G',
|
||||||
|
[72] = 'H',
|
||||||
|
[73] = 'I',
|
||||||
|
[74] = 'J',
|
||||||
|
[75] = 'K',
|
||||||
|
[76] = 'L',
|
||||||
|
[77] = 'M',
|
||||||
|
[78] = 'N',
|
||||||
|
[79] = 'O',
|
||||||
|
[80] = 'P',
|
||||||
|
[81] = 'Q',
|
||||||
|
[82] = 'R',
|
||||||
|
[83] = 'S',
|
||||||
|
[84] = 'T',
|
||||||
|
[85] = 'U',
|
||||||
|
[86] = 'V',
|
||||||
|
[87] = 'W',
|
||||||
|
[88] = 'X',
|
||||||
|
[89] = 'Y',
|
||||||
|
[90] = 'Z',
|
||||||
|
[91] = '[',
|
||||||
|
[92] = '\\' | '\\' << 8,
|
||||||
|
[93] = ']',
|
||||||
|
[94] = '^',
|
||||||
|
[95] = '_',
|
||||||
|
[96] = '`',
|
||||||
|
[97] = 'a',
|
||||||
|
[98] = 'b',
|
||||||
|
[99] = 'c',
|
||||||
|
[100] = 'd',
|
||||||
|
[101] = 'e',
|
||||||
|
[102] = 'f',
|
||||||
|
[103] = 'g',
|
||||||
|
[104] = 'h',
|
||||||
|
[105] = 'i',
|
||||||
|
[106] = 'j',
|
||||||
|
[107] = 'k',
|
||||||
|
[108] = 'l',
|
||||||
|
[109] = 'm',
|
||||||
|
[110] = 'n',
|
||||||
|
[111] = 'o',
|
||||||
|
[112] = 'p',
|
||||||
|
[113] = 'q',
|
||||||
|
[114] = 'r',
|
||||||
|
[115] = 's',
|
||||||
|
[116] = 't',
|
||||||
|
[117] = 'u',
|
||||||
|
[118] = 'v',
|
||||||
|
[119] = 'w',
|
||||||
|
[120] = 'x',
|
||||||
|
[121] = 'y',
|
||||||
|
[122] = 'z',
|
||||||
|
[123] = '{',
|
||||||
|
[124] = '|',
|
||||||
|
[125] = '}',
|
||||||
|
[126] = '~',
|
||||||
|
[127] = '\\' | '1' << 8 | '7' << 16 | '7' << 24,
|
||||||
|
[128] = '\\' | '2' << 8 | '0' << 16 | '0' << 24,
|
||||||
|
[129] = '\\' | '2' << 8 | '0' << 16 | '1' << 24,
|
||||||
|
[130] = '\\' | '2' << 8 | '0' << 16 | '2' << 24,
|
||||||
|
[131] = '\\' | '2' << 8 | '0' << 16 | '3' << 24,
|
||||||
|
[132] = '\\' | '2' << 8 | '0' << 16 | '4' << 24,
|
||||||
|
[133] = '\\' | '2' << 8 | '0' << 16 | '5' << 24,
|
||||||
|
[134] = '\\' | '2' << 8 | '0' << 16 | '6' << 24,
|
||||||
|
[135] = '\\' | '2' << 8 | '0' << 16 | '7' << 24,
|
||||||
|
[136] = '\\' | '2' << 8 | '1' << 16 | '0' << 24,
|
||||||
|
[137] = '\\' | '2' << 8 | '1' << 16 | '1' << 24,
|
||||||
|
[138] = '\\' | '2' << 8 | '1' << 16 | '2' << 24,
|
||||||
|
[139] = '\\' | '2' << 8 | '1' << 16 | '3' << 24,
|
||||||
|
[140] = '\\' | '2' << 8 | '1' << 16 | '4' << 24,
|
||||||
|
[141] = '\\' | '2' << 8 | '1' << 16 | '5' << 24,
|
||||||
|
[142] = '\\' | '2' << 8 | '1' << 16 | '6' << 24,
|
||||||
|
[143] = '\\' | '2' << 8 | '1' << 16 | '7' << 24,
|
||||||
|
[144] = '\\' | '2' << 8 | '2' << 16 | '0' << 24,
|
||||||
|
[145] = '\\' | '2' << 8 | '2' << 16 | '1' << 24,
|
||||||
|
[146] = '\\' | '2' << 8 | '2' << 16 | '2' << 24,
|
||||||
|
[147] = '\\' | '2' << 8 | '2' << 16 | '3' << 24,
|
||||||
|
[148] = '\\' | '2' << 8 | '2' << 16 | '4' << 24,
|
||||||
|
[149] = '\\' | '2' << 8 | '2' << 16 | '5' << 24,
|
||||||
|
[150] = '\\' | '2' << 8 | '2' << 16 | '6' << 24,
|
||||||
|
[151] = '\\' | '2' << 8 | '2' << 16 | '7' << 24,
|
||||||
|
[152] = '\\' | '2' << 8 | '3' << 16 | '0' << 24,
|
||||||
|
[153] = '\\' | '2' << 8 | '3' << 16 | '1' << 24,
|
||||||
|
[154] = '\\' | '2' << 8 | '3' << 16 | '2' << 24,
|
||||||
|
[155] = '\\' | '2' << 8 | '3' << 16 | '3' << 24,
|
||||||
|
[156] = '\\' | '2' << 8 | '3' << 16 | '4' << 24,
|
||||||
|
[157] = '\\' | '2' << 8 | '3' << 16 | '5' << 24,
|
||||||
|
[158] = '\\' | '2' << 8 | '3' << 16 | '6' << 24,
|
||||||
|
[159] = '\\' | '2' << 8 | '3' << 16 | '7' << 24,
|
||||||
|
[160] = '\\' | '2' << 8 | '4' << 16 | '0' << 24,
|
||||||
|
[161] = '\\' | '2' << 8 | '4' << 16 | '1' << 24,
|
||||||
|
[162] = '\\' | '2' << 8 | '4' << 16 | '2' << 24,
|
||||||
|
[163] = '\\' | '2' << 8 | '4' << 16 | '3' << 24,
|
||||||
|
[164] = '\\' | '2' << 8 | '4' << 16 | '4' << 24,
|
||||||
|
[165] = '\\' | '2' << 8 | '4' << 16 | '5' << 24,
|
||||||
|
[166] = '\\' | '2' << 8 | '4' << 16 | '6' << 24,
|
||||||
|
[167] = '\\' | '2' << 8 | '4' << 16 | '7' << 24,
|
||||||
|
[168] = '\\' | '2' << 8 | '5' << 16 | '0' << 24,
|
||||||
|
[169] = '\\' | '2' << 8 | '5' << 16 | '1' << 24,
|
||||||
|
[170] = '\\' | '2' << 8 | '5' << 16 | '2' << 24,
|
||||||
|
[171] = '\\' | '2' << 8 | '5' << 16 | '3' << 24,
|
||||||
|
[172] = '\\' | '2' << 8 | '5' << 16 | '4' << 24,
|
||||||
|
[173] = '\\' | '2' << 8 | '5' << 16 | '5' << 24,
|
||||||
|
[174] = '\\' | '2' << 8 | '5' << 16 | '6' << 24,
|
||||||
|
[175] = '\\' | '2' << 8 | '5' << 16 | '7' << 24,
|
||||||
|
[176] = '\\' | '2' << 8 | '6' << 16 | '0' << 24,
|
||||||
|
[177] = '\\' | '2' << 8 | '6' << 16 | '1' << 24,
|
||||||
|
[178] = '\\' | '2' << 8 | '6' << 16 | '2' << 24,
|
||||||
|
[179] = '\\' | '2' << 8 | '6' << 16 | '3' << 24,
|
||||||
|
[180] = '\\' | '2' << 8 | '6' << 16 | '4' << 24,
|
||||||
|
[181] = '\\' | '2' << 8 | '6' << 16 | '5' << 24,
|
||||||
|
[182] = '\\' | '2' << 8 | '6' << 16 | '6' << 24,
|
||||||
|
[183] = '\\' | '2' << 8 | '6' << 16 | '7' << 24,
|
||||||
|
[184] = '\\' | '2' << 8 | '7' << 16 | '0' << 24,
|
||||||
|
[185] = '\\' | '2' << 8 | '7' << 16 | '1' << 24,
|
||||||
|
[186] = '\\' | '2' << 8 | '7' << 16 | '2' << 24,
|
||||||
|
[187] = '\\' | '2' << 8 | '7' << 16 | '3' << 24,
|
||||||
|
[188] = '\\' | '2' << 8 | '7' << 16 | '4' << 24,
|
||||||
|
[189] = '\\' | '2' << 8 | '7' << 16 | '5' << 24,
|
||||||
|
[190] = '\\' | '2' << 8 | '7' << 16 | '6' << 24,
|
||||||
|
[191] = '\\' | '2' << 8 | '7' << 16 | '7' << 24,
|
||||||
|
[192] = '\\' | '3' << 8 | '0' << 16 | '0' << 24,
|
||||||
|
[193] = '\\' | '3' << 8 | '0' << 16 | '1' << 24,
|
||||||
|
[194] = '\\' | '3' << 8 | '0' << 16 | '2' << 24,
|
||||||
|
[195] = '\\' | '3' << 8 | '0' << 16 | '3' << 24,
|
||||||
|
[196] = '\\' | '3' << 8 | '0' << 16 | '4' << 24,
|
||||||
|
[197] = '\\' | '3' << 8 | '0' << 16 | '5' << 24,
|
||||||
|
[198] = '\\' | '3' << 8 | '0' << 16 | '6' << 24,
|
||||||
|
[199] = '\\' | '3' << 8 | '0' << 16 | '7' << 24,
|
||||||
|
[200] = '\\' | '3' << 8 | '1' << 16 | '0' << 24,
|
||||||
|
[201] = '\\' | '3' << 8 | '1' << 16 | '1' << 24,
|
||||||
|
[202] = '\\' | '3' << 8 | '1' << 16 | '2' << 24,
|
||||||
|
[203] = '\\' | '3' << 8 | '1' << 16 | '3' << 24,
|
||||||
|
[204] = '\\' | '3' << 8 | '1' << 16 | '4' << 24,
|
||||||
|
[205] = '\\' | '3' << 8 | '1' << 16 | '5' << 24,
|
||||||
|
[206] = '\\' | '3' << 8 | '1' << 16 | '6' << 24,
|
||||||
|
[207] = '\\' | '3' << 8 | '1' << 16 | '7' << 24,
|
||||||
|
[208] = '\\' | '3' << 8 | '2' << 16 | '0' << 24,
|
||||||
|
[209] = '\\' | '3' << 8 | '2' << 16 | '1' << 24,
|
||||||
|
[210] = '\\' | '3' << 8 | '2' << 16 | '2' << 24,
|
||||||
|
[211] = '\\' | '3' << 8 | '2' << 16 | '3' << 24,
|
||||||
|
[212] = '\\' | '3' << 8 | '2' << 16 | '4' << 24,
|
||||||
|
[213] = '\\' | '3' << 8 | '2' << 16 | '5' << 24,
|
||||||
|
[214] = '\\' | '3' << 8 | '2' << 16 | '6' << 24,
|
||||||
|
[215] = '\\' | '3' << 8 | '2' << 16 | '7' << 24,
|
||||||
|
[216] = '\\' | '3' << 8 | '3' << 16 | '0' << 24,
|
||||||
|
[217] = '\\' | '3' << 8 | '3' << 16 | '1' << 24,
|
||||||
|
[218] = '\\' | '3' << 8 | '3' << 16 | '2' << 24,
|
||||||
|
[219] = '\\' | '3' << 8 | '3' << 16 | '3' << 24,
|
||||||
|
[220] = '\\' | '3' << 8 | '3' << 16 | '4' << 24,
|
||||||
|
[221] = '\\' | '3' << 8 | '3' << 16 | '5' << 24,
|
||||||
|
[222] = '\\' | '3' << 8 | '3' << 16 | '6' << 24,
|
||||||
|
[223] = '\\' | '3' << 8 | '3' << 16 | '7' << 24,
|
||||||
|
[224] = '\\' | '3' << 8 | '4' << 16 | '0' << 24,
|
||||||
|
[225] = '\\' | '3' << 8 | '4' << 16 | '1' << 24,
|
||||||
|
[226] = '\\' | '3' << 8 | '4' << 16 | '2' << 24,
|
||||||
|
[227] = '\\' | '3' << 8 | '4' << 16 | '3' << 24,
|
||||||
|
[228] = '\\' | '3' << 8 | '4' << 16 | '4' << 24,
|
||||||
|
[229] = '\\' | '3' << 8 | '4' << 16 | '5' << 24,
|
||||||
|
[230] = '\\' | '3' << 8 | '4' << 16 | '6' << 24,
|
||||||
|
[231] = '\\' | '3' << 8 | '4' << 16 | '7' << 24,
|
||||||
|
[232] = '\\' | '3' << 8 | '5' << 16 | '0' << 24,
|
||||||
|
[233] = '\\' | '3' << 8 | '5' << 16 | '1' << 24,
|
||||||
|
[234] = '\\' | '3' << 8 | '5' << 16 | '2' << 24,
|
||||||
|
[235] = '\\' | '3' << 8 | '5' << 16 | '3' << 24,
|
||||||
|
[236] = '\\' | '3' << 8 | '5' << 16 | '4' << 24,
|
||||||
|
[237] = '\\' | '3' << 8 | '5' << 16 | '5' << 24,
|
||||||
|
[238] = '\\' | '3' << 8 | '5' << 16 | '6' << 24,
|
||||||
|
[239] = '\\' | '3' << 8 | '5' << 16 | '7' << 24,
|
||||||
|
[240] = '\\' | '3' << 8 | '6' << 16 | '0' << 24,
|
||||||
|
[241] = '\\' | '3' << 8 | '6' << 16 | '1' << 24,
|
||||||
|
[242] = '\\' | '3' << 8 | '6' << 16 | '2' << 24,
|
||||||
|
[243] = '\\' | '3' << 8 | '6' << 16 | '3' << 24,
|
||||||
|
[244] = '\\' | '3' << 8 | '6' << 16 | '4' << 24,
|
||||||
|
[245] = '\\' | '3' << 8 | '6' << 16 | '5' << 24,
|
||||||
|
[246] = '\\' | '3' << 8 | '6' << 16 | '6' << 24,
|
||||||
|
[247] = '\\' | '3' << 8 | '6' << 16 | '7' << 24,
|
||||||
|
[248] = '\\' | '3' << 8 | '7' << 16 | '0' << 24,
|
||||||
|
[249] = '\\' | '3' << 8 | '7' << 16 | '1' << 24,
|
||||||
|
[250] = '\\' | '3' << 8 | '7' << 16 | '2' << 24,
|
||||||
|
[251] = '\\' | '3' << 8 | '7' << 16 | '3' << 24,
|
||||||
|
[252] = '\\' | '3' << 8 | '7' << 16 | '4' << 24,
|
||||||
|
[253] = '\\' | '3' << 8 | '7' << 16 | '5' << 24,
|
||||||
|
[254] = '\\' | '3' << 8 | '7' << 16 | '6' << 24,
|
||||||
|
[255] = '\\' | '3' << 8 | '7' << 16 | '7' << 24,
|
||||||
|
};
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < 256; ++i) {
|
||||||
|
printf("[%d] = ", i);
|
||||||
|
int j = 0;
|
||||||
|
uint32_t x = _cescapec(i);
|
||||||
|
do {
|
||||||
|
if (j) {
|
||||||
|
printf(" | ");
|
||||||
|
}
|
||||||
|
if (isprint(x & 255)) {
|
||||||
|
if ((x & 255) == '\\') {
|
||||||
|
printf("'\\\\'");
|
||||||
|
} else {
|
||||||
|
printf("'%c'", x & 255);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
printf("%d", x & 255);
|
||||||
|
}
|
||||||
|
if (j) {
|
||||||
|
printf(" << %d", j);
|
||||||
|
}
|
||||||
|
j += 8;
|
||||||
|
} while ((x >>= 8));
|
||||||
|
printf(",\n");
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,152 +0,0 @@
|
||||||
#if 0
|
|
||||||
/*─────────────────────────────────────────────────────────────────╗
|
|
||||||
│ To the extent possible under law, Justine Tunney has waived │
|
|
||||||
│ all copyright and related or neighboring rights to this file, │
|
|
||||||
│ as it is written in the following disclaimers: │
|
|
||||||
│ • http://unlicense.org/ │
|
|
||||||
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
|
||||||
╚─────────────────────────────────────────────────────────────────*/
|
|
||||||
#endif
|
|
||||||
#include "dsp/core/core.h"
|
|
||||||
#include "libc/calls/calls.h"
|
|
||||||
#include "libc/calls/struct/itimerval.h"
|
|
||||||
#include "libc/calls/struct/sigaction.h"
|
|
||||||
#include "libc/fmt/nf32.h"
|
|
||||||
#include "libc/intrin/bits.h"
|
|
||||||
#include "libc/log/check.h"
|
|
||||||
#include "libc/macros.internal.h"
|
|
||||||
#include "libc/mem/mem.h"
|
|
||||||
#include "libc/runtime/runtime.h"
|
|
||||||
#include "libc/stdio/append.h"
|
|
||||||
#include "libc/stdio/stdio.h"
|
|
||||||
#include "libc/str/str.h"
|
|
||||||
#include "libc/sysv/consts/itimer.h"
|
|
||||||
#include "libc/sysv/consts/sig.h"
|
|
||||||
#include "libc/time/time.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @fileoverview experimental way to play audio in terminals
|
|
||||||
*
|
|
||||||
* This is an stdio application that prints audio samples. The terminal
|
|
||||||
* on the other end, needs to be able to understand the Nf sequences we
|
|
||||||
* use here, which should be invisible to the terminal sort of like out
|
|
||||||
* of band signalling.
|
|
||||||
*
|
|
||||||
* To play audio with a supporting terminal:
|
|
||||||
*
|
|
||||||
* make -j8 o//examples/ttyaudio.com
|
|
||||||
* wget https://justine.lol/numbers.s16
|
|
||||||
* o//examples/ttyaudio.com numbers.s16
|
|
||||||
*
|
|
||||||
* To reveal the inband ansi audio transmission:
|
|
||||||
*
|
|
||||||
* o//examples/ttyaudio.com numbers.s16 2>/dev/null |
|
|
||||||
* o//tool/viz/bing.com |
|
|
||||||
* o//tool/viz/fold.com
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define CSI "s"
|
|
||||||
#define SGR1 "?80"
|
|
||||||
#define SGR2 "?81"
|
|
||||||
|
|
||||||
struct Ring {
|
|
||||||
int i; // read index
|
|
||||||
int j; // write index
|
|
||||||
int n; // total samples
|
|
||||||
short* p; // samples
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Speaker {
|
|
||||||
int rate; // in hertz, e.g. 8000
|
|
||||||
int codec; // 0 = s16, 2 = µ-Law
|
|
||||||
int channels; // 1 = mono, 2 = stereo
|
|
||||||
struct Ring buf; // audio playback buffer
|
|
||||||
};
|
|
||||||
|
|
||||||
const int maxar = 31;
|
|
||||||
const int ptime = 20;
|
|
||||||
|
|
||||||
struct Speaker s;
|
|
||||||
|
|
||||||
void OnAlrm(int sig) {
|
|
||||||
}
|
|
||||||
|
|
||||||
void LoadAudioFile(struct Speaker* s, const char* path) {
|
|
||||||
int rc;
|
|
||||||
FILE* f;
|
|
||||||
short buf[1024];
|
|
||||||
if (!(f = fopen(path, "rb"))) {
|
|
||||||
fprintf(stderr, "failed to open file\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
for (;;) {
|
|
||||||
rc = fread(buf, sizeof(short), sizeof(buf) / sizeof(short), f);
|
|
||||||
if (rc) {
|
|
||||||
s->buf.p = (short*)realloc(s->buf.p, (s->buf.n + rc) * sizeof(short));
|
|
||||||
memcpy(s->buf.p + s->buf.n, buf, rc * sizeof(short));
|
|
||||||
s->buf.n += rc;
|
|
||||||
} else if (ferror(f)) {
|
|
||||||
fprintf(stderr, "read error: %s\n", strerror(ferror(f)));
|
|
||||||
exit(2);
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fclose(f);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
|
||||||
if (argc < 2) return 1;
|
|
||||||
if (!isatty(0)) exit(1);
|
|
||||||
|
|
||||||
s.rate = 8000;
|
|
||||||
s.channels = 1;
|
|
||||||
s.codec = 0;
|
|
||||||
LoadAudioFile(&s, argv[1]);
|
|
||||||
|
|
||||||
char nf[21];
|
|
||||||
char* obuf = 0;
|
|
||||||
appendw(&obuf, READ16LE("\e%"));
|
|
||||||
appendd(&obuf, nf, EncodeNf32(nf, s.rate) - nf);
|
|
||||||
appendw(&obuf, '/');
|
|
||||||
appendd(&obuf, nf, EncodeNf32(nf, s.channels) - nf);
|
|
||||||
appendw(&obuf, '/');
|
|
||||||
appendd(&obuf, nf, EncodeNf32(nf, s.codec) - nf);
|
|
||||||
appendw(&obuf, '0');
|
|
||||||
write(1, obuf, appendz(obuf).i);
|
|
||||||
free(obuf);
|
|
||||||
|
|
||||||
struct sigaction sa = {.sa_handler = OnAlrm};
|
|
||||||
struct itimerval it = {{0, ptime * 1000}, {0, ptime * 1000}};
|
|
||||||
CHECK_NE(-1, sigaction(SIGALRM, &sa, 0));
|
|
||||||
CHECK_NE(-1, setitimer(ITIMER_REAL, &it, 0));
|
|
||||||
|
|
||||||
for (;;) {
|
|
||||||
char* p;
|
|
||||||
int count;
|
|
||||||
char nf[22];
|
|
||||||
int i, j, x;
|
|
||||||
char* obuf = 0;
|
|
||||||
int samps = s.rate / (1000 / ptime);
|
|
||||||
appendw(&obuf, READ16LE("\e "));
|
|
||||||
for (i = 0; i < samps; ++i) {
|
|
||||||
if (s.codec == 1) {
|
|
||||||
x = mulaw(s.buf.p[s.buf.i++]);
|
|
||||||
} else {
|
|
||||||
x = s.buf.p[s.buf.i++] & 0xffff;
|
|
||||||
}
|
|
||||||
*(p = EncodeNf32(nf, x)) = '/';
|
|
||||||
appendd(&obuf, nf, p + 1 - nf);
|
|
||||||
if (s.buf.i == s.buf.n) break;
|
|
||||||
}
|
|
||||||
appendw(&obuf, '0');
|
|
||||||
write(1, obuf, appendz(obuf).i);
|
|
||||||
free(obuf);
|
|
||||||
fprintf(stderr, "\r\e[K%d / %d", s.buf.i, s.buf.n);
|
|
||||||
fflush(stderr);
|
|
||||||
pause();
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
|
@ -34,6 +34,8 @@
|
||||||
#include "libc/sysv/errfuns.h"
|
#include "libc/sysv/errfuns.h"
|
||||||
#include "libc/thread/tls.h"
|
#include "libc/thread/tls.h"
|
||||||
|
|
||||||
|
#ifdef __x86_64__
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allocates piece of memory for storing pending signal.
|
* Allocates piece of memory for storing pending signal.
|
||||||
* @assume lock is held
|
* @assume lock is held
|
||||||
|
@ -304,3 +306,5 @@ textwindows void __sig_check_ignore(const int sig, const unsigned rva) {
|
||||||
__sig_unlock();
|
__sig_unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* __x86_64__ */
|
||||||
|
|
|
@ -23,6 +23,8 @@
|
||||||
#include "libc/sysv/errfuns.h"
|
#include "libc/sysv/errfuns.h"
|
||||||
#include "libc/thread/tls.h"
|
#include "libc/thread/tls.h"
|
||||||
|
|
||||||
|
#ifdef __x86_64__
|
||||||
|
|
||||||
#define GetSigBit(x) (1ull << (((x)-1) & 63))
|
#define GetSigBit(x) (1ull << (((x)-1) & 63))
|
||||||
|
|
||||||
textwindows int __sig_mask(int how, const sigset_t *neu, sigset_t *old) {
|
textwindows int __sig_mask(int how, const sigset_t *neu, sigset_t *old) {
|
||||||
|
@ -58,3 +60,5 @@ textwindows int __sig_mask(int how, const sigset_t *neu, sigset_t *old) {
|
||||||
return einval();
|
return einval();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* __x86_64__ */
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
#include "libc/calls/state.internal.h"
|
#include "libc/calls/state.internal.h"
|
||||||
#include "libc/calls/struct/sigset.h"
|
#include "libc/calls/struct/sigset.h"
|
||||||
|
|
||||||
|
#ifdef __x86_64__
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines the pending signals on New Technology.
|
* Determines the pending signals on New Technology.
|
||||||
*
|
*
|
||||||
|
@ -41,3 +43,5 @@ textwindows void __sig_pending(sigset_t *pending) {
|
||||||
__sig_unlock();
|
__sig_unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* __x86_64__ */
|
||||||
|
|
|
@ -2,17 +2,22 @@
|
||||||
#define COSMOPOLITAN_LIBC_CALLS_ASAN_INTERNAL_H_
|
#define COSMOPOLITAN_LIBC_CALLS_ASAN_INTERNAL_H_
|
||||||
#include "libc/calls/struct/timespec.h"
|
#include "libc/calls/struct/timespec.h"
|
||||||
#include "libc/calls/struct/timeval.h"
|
#include "libc/calls/struct/timeval.h"
|
||||||
|
#include "libc/intrin/asan.internal.h"
|
||||||
#include "libc/intrin/asmflag.h"
|
#include "libc/intrin/asmflag.h"
|
||||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||||
COSMOPOLITAN_C_START_
|
COSMOPOLITAN_C_START_
|
||||||
|
|
||||||
forceinline bool __asan_is_valid_timespec(const struct timespec *ts) {
|
forceinline bool __asan_is_valid_timespec(const struct timespec *ts) {
|
||||||
|
#ifdef __x86_64__
|
||||||
bool zf;
|
bool zf;
|
||||||
asm(ZFLAG_ASM("cmpw\t$0,0x7fff8000(%1)")
|
asm(ZFLAG_ASM("cmpw\t$0,0x7fff8000(%1)")
|
||||||
: ZFLAG_CONSTRAINT(zf)
|
: ZFLAG_CONSTRAINT(zf)
|
||||||
: "r"((intptr_t)ts >> 3)
|
: "r"((intptr_t)ts >> 3)
|
||||||
: "memory");
|
: "memory");
|
||||||
return zf;
|
return zf;
|
||||||
|
#else
|
||||||
|
return __asan_is_valid(ts, sizeof(*ts));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
forceinline bool __asan_is_valid_timeval(const struct timeval *tv) {
|
forceinline bool __asan_is_valid_timeval(const struct timeval *tv) {
|
||||||
|
|
|
@ -1,75 +0,0 @@
|
||||||
#include "libc/macros.internal.h"
|
|
||||||
|
|
||||||
// generated by:
|
|
||||||
// o/tool/build/xlat.com -s kNfcimal -inx -1 -I ' ,.-+*#%&$'
|
|
||||||
//
|
|
||||||
// present absent
|
|
||||||
// ──────────────── ────────────────
|
|
||||||
// ∅☺☻♥♦♣♠•◘○◙♂♀♪♫☼ 0x00
|
|
||||||
// ►◄↕‼¶§▬↨↑↓→←∟↔▲▼ 0x10
|
|
||||||
// ␠ #§%& *+,-. !“ ‘() / 0x20
|
|
||||||
// 0123456789:;<=>⁇ 0x30
|
|
||||||
// @ABCDEFGHIJKLMNO 0x40
|
|
||||||
// PQRSTUVWXYZ[⭝]^_ 0x50
|
|
||||||
// `abcdefghijklmno 0x60
|
|
||||||
// pqrstuvwxyz{|}~⌂ 0x70
|
|
||||||
// ÇüéâäàåçêëèïîìÄÅ 0x80
|
|
||||||
// ÉæÆôöòûùÿÖÜ¢£¥€ƒ 0x90
|
|
||||||
// áíóúñѪº¿⌐¬½¼¡«» 0xa0
|
|
||||||
// ░▒▓│┤╡╢╖╕╣║╗╝╜╛┐ 0xb0
|
|
||||||
// └┴┬├─┼╞╟╚╔╩╦╠═╬╧ 0xc0
|
|
||||||
// ╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀ 0xd0
|
|
||||||
// αßΓπΣσμτΦΘΩδ∞φε∩ 0xe0
|
|
||||||
// ≡±≥≤⌠⌡÷≈°∙×√ⁿ²■λ 0xf0
|
|
||||||
//
|
|
||||||
// const char kNfcimal[256] = {
|
|
||||||
// -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 0x00
|
|
||||||
// -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 0x10
|
|
||||||
// 0,-1,-1, 6, 9, 7, 8,-1,-1,-1, 5, 4, 1, 3, 2,-1, // 0x20
|
|
||||||
// -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 0x30
|
|
||||||
// -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 0x40
|
|
||||||
// -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 0x50
|
|
||||||
// -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 0x60
|
|
||||||
// -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 0x70
|
|
||||||
// -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 0x80
|
|
||||||
// -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 0x90
|
|
||||||
// -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 0xa0
|
|
||||||
// -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 0xb0
|
|
||||||
// -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 0xc0
|
|
||||||
// -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 0xd0
|
|
||||||
// -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 0xe0
|
|
||||||
// -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 0xf0
|
|
||||||
// };
|
|
||||||
|
|
||||||
.initbss 300,_init_kNfcimal
|
|
||||||
kNfcimal:
|
|
||||||
.zero 256
|
|
||||||
.endobj kNfcimal,globl
|
|
||||||
.previous
|
|
||||||
|
|
||||||
.initro 300,_init_kNfcimal
|
|
||||||
kNfcimal.rom:
|
|
||||||
.byte 32,255 # 00-1f ∅-▼
|
|
||||||
.byte 1,0 # 20-20 ␠-␠
|
|
||||||
.byte 2,255 # 21-22 !-“
|
|
||||||
.byte 1,6 # 23-23 #-#
|
|
||||||
.byte 1,9 # 24-24 §-§
|
|
||||||
.byte 1,7 # 25-25 %-%
|
|
||||||
.byte 1,8 # 26-26 &-&
|
|
||||||
.byte 3,255 # 27-29 ‘-)
|
|
||||||
.byte 1,5 # 2a-2a *-*
|
|
||||||
.byte 1,4 # 2b-2b +-+
|
|
||||||
.byte 1,1 # 2c-2c ,-,
|
|
||||||
.byte 1,3 # 2d-2d ---
|
|
||||||
.byte 1,2 # 2e-2e .-.
|
|
||||||
.byte 209,255 # 2f-ff /-λ
|
|
||||||
.byte 0,0 # terminator
|
|
||||||
.byte 0,0 # padding
|
|
||||||
.endobj kNfcimal.rom,globl
|
|
||||||
|
|
||||||
.init.start 300,_init_kNfcimal
|
|
||||||
call rldecode
|
|
||||||
lodsw
|
|
||||||
.init.end 300,_init_kNfcimal
|
|
||||||
|
|
||||||
// 39 bytes total (15% original size)
|
|
|
@ -1,13 +0,0 @@
|
||||||
#ifndef COSMOPOLITAN_LIBC_FMT_NF32_H_
|
|
||||||
#define COSMOPOLITAN_LIBC_FMT_NF32_H_
|
|
||||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
|
||||||
COSMOPOLITAN_C_START_
|
|
||||||
|
|
||||||
extern const char kNfcimal[256];
|
|
||||||
|
|
||||||
uint32_t DecodeNf32(const char *, char **);
|
|
||||||
char *EncodeNf32(char[hasatleast 12], uint32_t);
|
|
||||||
|
|
||||||
COSMOPOLITAN_C_END_
|
|
||||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
|
||||||
#endif /* COSMOPOLITAN_LIBC_FMT_NF32_H_ */
|
|
|
@ -26,7 +26,7 @@
|
||||||
typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(1)));
|
typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(1)));
|
||||||
typedef long long xmm_a __attribute__((__vector_size__(16), __aligned__(16)));
|
typedef long long xmm_a __attribute__((__vector_size__(16), __aligned__(16)));
|
||||||
|
|
||||||
static dontinline antiquity void bzero_sse(char *p, size_t n) {
|
static void bzero_sse(char *p, size_t n) {
|
||||||
xmm_t v = {0};
|
xmm_t v = {0};
|
||||||
if (IsAsan()) __asan_verify(p, n);
|
if (IsAsan()) __asan_verify(p, n);
|
||||||
if (n <= 32) {
|
if (n <= 32) {
|
||||||
|
|
|
@ -31,7 +31,7 @@ asm(".ident\t\"\\n\\n\
|
||||||
Musl libc (MIT License)\\n\
|
Musl libc (MIT License)\\n\
|
||||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||||
asm(".include \"libc/disclaimer.inc\"");
|
asm(".include \"libc/disclaimer.inc\"");
|
||||||
/* clang-format off */
|
// clang-format off
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns 𝑥 × 2ʸ.
|
* Returns 𝑥 × 2ʸ.
|
||||||
|
|
|
@ -18,6 +18,9 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/math.h"
|
#include "libc/math.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns 𝑥 × 2ʸ.
|
||||||
|
*/
|
||||||
long double ldexpl(long double x, int n) {
|
long double ldexpl(long double x, int n) {
|
||||||
return scalbnl(x, n);
|
return scalbnl(x, n);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(1)));
|
typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(1)));
|
||||||
typedef long long xmm_a __attribute__((__vector_size__(16), __aligned__(16)));
|
typedef long long xmm_a __attribute__((__vector_size__(16), __aligned__(16)));
|
||||||
|
|
||||||
static dontinline antiquity void *memset_sse(char *p, char c, size_t n) {
|
static void *memset_sse(char *p, char c, size_t n) {
|
||||||
xmm_t v = {c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c};
|
xmm_t v = {c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c};
|
||||||
if (IsAsan()) __asan_verify(p, n);
|
if (IsAsan()) __asan_verify(p, n);
|
||||||
if (n <= 32) {
|
if (n <= 32) {
|
||||||
|
|
|
@ -32,20 +32,16 @@ asm(".ident\t\"\\n\\n\
|
||||||
Musl libc (MIT License)\\n\
|
Musl libc (MIT License)\\n\
|
||||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||||
asm(".include \"libc/disclaimer.inc\"");
|
asm(".include \"libc/disclaimer.inc\"");
|
||||||
/* clang-format off */
|
// clang-format off
|
||||||
|
|
||||||
|
long double scalblnl(long double x, long n) {
|
||||||
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||||
long double scalblnl(long double x, long n)
|
|
||||||
{
|
|
||||||
return scalbln(x, n);
|
return scalbln(x, n);
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
long double scalblnl(long double x, long n)
|
|
||||||
{
|
|
||||||
if (n > INT_MAX)
|
if (n > INT_MAX)
|
||||||
n = INT_MAX;
|
n = INT_MAX;
|
||||||
else if (n < INT_MIN)
|
else if (n < INT_MIN)
|
||||||
n = INT_MIN;
|
n = INT_MIN;
|
||||||
return scalbnl(x, n);
|
return scalbnl(x, n);
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
|
@ -32,18 +32,16 @@ asm(".ident\t\"\\n\\n\
|
||||||
Musl libc (MIT License)\\n\
|
Musl libc (MIT License)\\n\
|
||||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||||
asm(".include \"libc/disclaimer.inc\"");
|
asm(".include \"libc/disclaimer.inc\"");
|
||||||
/* clang-format off */
|
// clang-format off
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns 𝑥 × 2ʸ.
|
||||||
|
*/
|
||||||
|
long double scalbnl(long double x, int n) {
|
||||||
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||||
long double scalbnl(long double x, int n)
|
|
||||||
{
|
|
||||||
return scalbn(x, n);
|
return scalbn(x, n);
|
||||||
}
|
|
||||||
#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
|
#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
|
||||||
long double scalbnl(long double x, int n)
|
|
||||||
{
|
|
||||||
union ldshape u;
|
union ldshape u;
|
||||||
|
|
||||||
if (n > 16383) {
|
if (n > 16383) {
|
||||||
x *= 0x1p16383L;
|
x *= 0x1p16383L;
|
||||||
n -= 16383;
|
n -= 16383;
|
||||||
|
@ -66,5 +64,7 @@ long double scalbnl(long double x, int n)
|
||||||
u.f = 1.0;
|
u.f = 1.0;
|
||||||
u.i.se = 0x3fff + n;
|
u.i.se = 0x3fff + n;
|
||||||
return x * u.f;
|
return x * u.f;
|
||||||
}
|
#else
|
||||||
|
#error "architecture unsupported"
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
|
@ -20,8 +20,6 @@
|
||||||
#include "libc/intrin/asan.internal.h"
|
#include "libc/intrin/asan.internal.h"
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
|
|
||||||
typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(16)));
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns length of NUL-terminated string.
|
* Returns length of NUL-terminated string.
|
||||||
*
|
*
|
||||||
|
@ -30,16 +28,33 @@ typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(16)));
|
||||||
* @asyncsignalsafe
|
* @asyncsignalsafe
|
||||||
*/
|
*/
|
||||||
noasan size_t strlen(const char *s) {
|
noasan size_t strlen(const char *s) {
|
||||||
|
if (IsAsan()) __asan_verify_str(s);
|
||||||
#ifdef __x86_64__
|
#ifdef __x86_64__
|
||||||
size_t n;
|
typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(16)));
|
||||||
xmm_t z = {0};
|
xmm_t z = {0};
|
||||||
unsigned m, k = (uintptr_t)s & 15;
|
unsigned m, k = (uintptr_t)s & 15;
|
||||||
const xmm_t *p = (const xmm_t *)((uintptr_t)s & -16);
|
const xmm_t *p = (const xmm_t *)((uintptr_t)s & -16);
|
||||||
if (IsAsan()) __asan_verify_str(s);
|
|
||||||
m = __builtin_ia32_pmovmskb128(*p == z) >> k << k;
|
m = __builtin_ia32_pmovmskb128(*p == z) >> k << k;
|
||||||
while (!m) m = __builtin_ia32_pmovmskb128(*++p == z);
|
while (!m) m = __builtin_ia32_pmovmskb128(*++p == z);
|
||||||
n = (const char *)p + __builtin_ctzl(m) - s;
|
return (const char *)p + __builtin_ctzl(m) - s;
|
||||||
return n;
|
#elif defined(__GNUC__) || defined(__llvm__)
|
||||||
|
#define ONES ((word)-1 / 255)
|
||||||
|
#define BANE (ONES * (255 / 2 + 1))
|
||||||
|
typedef unsigned long mayalias word;
|
||||||
|
word w;
|
||||||
|
unsigned k;
|
||||||
|
const word *p;
|
||||||
|
k = (uintptr_t)s & (sizeof(word) - 1);
|
||||||
|
p = (const word *)((uintptr_t)s & -sizeof(word));
|
||||||
|
w = *p;
|
||||||
|
w = ~w & (w - ONES) & BANE;
|
||||||
|
w >>= k << 3;
|
||||||
|
w <<= k << 3;
|
||||||
|
while (!w) {
|
||||||
|
w = *++p;
|
||||||
|
w = ~w & (w - ONES) & BANE;
|
||||||
|
}
|
||||||
|
return (const char *)p + (__builtin_ctzl(w) >> 3) - s;
|
||||||
#else
|
#else
|
||||||
size_t n = 0;
|
size_t n = 0;
|
||||||
while (*s++) ++n;
|
while (*s++) ++n;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||||
│ Copyright 2022 Justine Alexandra Roberts Tunney │
|
│ Copyright 2023 Justine Alexandra Roberts Tunney │
|
||||||
│ │
|
│ │
|
||||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||||
│ any purpose with or without fee is hereby granted, provided that the │
|
│ any purpose with or without fee is hereby granted, provided that the │
|
||||||
|
@ -16,25 +16,7 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/fmt/fmt.h"
|
#include "libc/str/str.h"
|
||||||
#include "libc/fmt/nf32.h"
|
|
||||||
#include "libc/stdio/rand.h"
|
|
||||||
#include "libc/testlib/testlib.h"
|
|
||||||
|
|
||||||
TEST(EncodeNf32, test) {
|
int _cescapec2(int c) {
|
||||||
char b[21];
|
|
||||||
EncodeNf32(b, 31337);
|
|
||||||
ASSERT_STREQ("-,--%", b);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(EncodeNf32, roundTrip) {
|
|
||||||
int i;
|
|
||||||
char b[21];
|
|
||||||
uint32_t x, y;
|
|
||||||
for (i = 0; i < 1000; ++i) {
|
|
||||||
x = lemur64();
|
|
||||||
EncodeNf32(b, x);
|
|
||||||
y = DecodeNf32(b, 0);
|
|
||||||
ASSERT_EQ(x, y);
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -18,10 +18,13 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
.real
|
.real
|
||||||
.code16 # ∩ .code32 ∩ .code64
|
|
||||||
|
|
||||||
// Optional function stub.
|
// Optional function stub.
|
||||||
_missingno:
|
_missingno:
|
||||||
xor %ax,%ax
|
#ifdef __x86__
|
||||||
|
xor %eax,%eax
|
||||||
|
#elif defined(__aarch64__)
|
||||||
|
mov x0,#0
|
||||||
|
#endif
|
||||||
ret
|
ret
|
||||||
.endfn _missingno,globl,hidden
|
.endfn _missingno,globl,hidden
|
||||||
|
|
|
@ -64,6 +64,8 @@ o/$(MODE)/libc/nexgen32e/longjmp.o: libc/nexgen32e/longjmp.S
|
||||||
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
|
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
|
||||||
o/$(MODE)/libc/nexgen32e/setjmp.o: libc/nexgen32e/setjmp.S
|
o/$(MODE)/libc/nexgen32e/setjmp.o: libc/nexgen32e/setjmp.S
|
||||||
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
|
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
|
||||||
|
o/$(MODE)/libc/nexgen32e/missingno.o: libc/nexgen32e/missingno.S
|
||||||
|
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
|
||||||
|
|
||||||
LIBC_NEXGEN32E_LIBS = $(foreach x,$(LIBC_NEXGEN32E_ARTIFACTS),$($(x)))
|
LIBC_NEXGEN32E_LIBS = $(foreach x,$(LIBC_NEXGEN32E_ARTIFACTS),$($(x)))
|
||||||
LIBC_NEXGEN32E_SRCS = $(foreach x,$(LIBC_NEXGEN32E_ARTIFACTS),$($(x)_SRCS))
|
LIBC_NEXGEN32E_SRCS = $(foreach x,$(LIBC_NEXGEN32E_ARTIFACTS),$($(x)_SRCS))
|
||||||
|
|
|
@ -13,6 +13,10 @@
|
||||||
#define FE_DOWNWARD 0x0400
|
#define FE_DOWNWARD 0x0400
|
||||||
#define FE_UPWARD 0x0800
|
#define FE_UPWARD 0x0800
|
||||||
#define FE_TOWARDZERO 0x0c00
|
#define FE_TOWARDZERO 0x0c00
|
||||||
|
#define FE_DFL_ENV ((const fenv_t *)-1)
|
||||||
|
typedef void *fenv_t;
|
||||||
|
typedef uint16_t fexcept_t;
|
||||||
|
|
||||||
#elif defined(__aarch64__)
|
#elif defined(__aarch64__)
|
||||||
#define FE_INVALID 1
|
#define FE_INVALID 1
|
||||||
#define FE_DIVBYZERO 2
|
#define FE_DIVBYZERO 2
|
||||||
|
@ -24,7 +28,36 @@
|
||||||
#define FE_DOWNWARD 0x800000
|
#define FE_DOWNWARD 0x800000
|
||||||
#define FE_UPWARD 0x400000
|
#define FE_UPWARD 0x400000
|
||||||
#define FE_TOWARDZERO 0xc00000
|
#define FE_TOWARDZERO 0xc00000
|
||||||
#endif
|
#define FE_DFL_ENV ((const fenv_t *)-1)
|
||||||
|
typedef void *fenv_t;
|
||||||
|
typedef uint32_t fexcept_t;
|
||||||
|
|
||||||
|
#elif defined(__powerpc64__)
|
||||||
|
#define FE_TONEAREST 0
|
||||||
|
#define FE_TOWARDZERO 1
|
||||||
|
#define FE_UPWARD 2
|
||||||
|
#define FE_DOWNWARD 3
|
||||||
|
#define FE_INEXACT 0x02000000
|
||||||
|
#define FE_DIVBYZERO 0x04000000
|
||||||
|
#define FE_UNDERFLOW 0x08000000
|
||||||
|
#define FE_OVERFLOW 0x10000000
|
||||||
|
#define FE_INVALID 0x20000000
|
||||||
|
#define FE_ALL_EXCEPT 0x3e000000
|
||||||
|
#define FE_INVALID_SNAN 0x01000000
|
||||||
|
#define FE_INVALID_ISI 0x00800000
|
||||||
|
#define FE_INVALID_IDI 0x00400000
|
||||||
|
#define FE_INVALID_ZDZ 0x00200000
|
||||||
|
#define FE_INVALID_IMZ 0x00100000
|
||||||
|
#define FE_INVALID_COMPARE 0x00080000
|
||||||
|
#define FE_INVALID_SOFTWARE 0x00000400
|
||||||
|
#define FE_INVALID_SQRT 0x00000200
|
||||||
|
#define FE_INVALID_INTEGER_CONVERSION 0x00000100
|
||||||
|
#define FE_ALL_INVALID 0x01f80700
|
||||||
|
#define FE_DFL_ENV ((const fenv_t *)-1)
|
||||||
|
typedef unsigned fexcept_t;
|
||||||
|
typedef double fenv_t;
|
||||||
|
|
||||||
|
#endif /* __x86_64__ */
|
||||||
|
|
||||||
#ifdef __FLT_EVAL_METHOD__
|
#ifdef __FLT_EVAL_METHOD__
|
||||||
#define FLT_EVAL_METHOD __FLT_EVAL_METHOD__
|
#define FLT_EVAL_METHOD __FLT_EVAL_METHOD__
|
||||||
|
@ -36,10 +69,6 @@
|
||||||
COSMOPOLITAN_C_START_
|
COSMOPOLITAN_C_START_
|
||||||
|
|
||||||
#define FLT_ROUNDS (__flt_rounds())
|
#define FLT_ROUNDS (__flt_rounds())
|
||||||
#define FE_DFL_ENV ((const fenv_t *)-1)
|
|
||||||
|
|
||||||
typedef void *fenv_t;
|
|
||||||
typedef uint16_t fexcept_t;
|
|
||||||
|
|
||||||
int feclearexcept(int);
|
int feclearexcept(int);
|
||||||
int fegetenv(fenv_t *);
|
int fegetenv(fenv_t *);
|
||||||
|
|
|
@ -10,6 +10,12 @@ COSMOPOLITAN_C_START_
|
||||||
typedef long jmp_buf[8];
|
typedef long jmp_buf[8];
|
||||||
#elif defined(__aarch64__)
|
#elif defined(__aarch64__)
|
||||||
typedef long jmp_buf[22];
|
typedef long jmp_buf[22];
|
||||||
|
#elif defined(__powerpc64__)
|
||||||
|
typedef unsigned __int128 jmp_buf[32];
|
||||||
|
#elif defined(__s390x__)
|
||||||
|
typedef unsigned long jmp_buf[18];
|
||||||
|
#elif defined(__riscv)
|
||||||
|
typedef unsigned long jmp_buf[26];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef long sigjmp_buf[12];
|
typedef long sigjmp_buf[12];
|
||||||
|
|
|
@ -23,8 +23,7 @@
|
||||||
|
|
||||||
typedef uint64_t xmm_t __attribute__((__vector_size__(16), __aligned__(1)));
|
typedef uint64_t xmm_t __attribute__((__vector_size__(16), __aligned__(1)));
|
||||||
|
|
||||||
static dontinline antiquity int bcmp_sse(const char *p, const char *q,
|
static int bcmp_sse(const char *p, const char *q, size_t n) {
|
||||||
size_t n) {
|
|
||||||
xmm_t a;
|
xmm_t a;
|
||||||
while (n > 32) {
|
while (n > 32) {
|
||||||
a = *(const xmm_t *)p ^ *(const xmm_t *)q;
|
a = *(const xmm_t *)p ^ *(const xmm_t *)q;
|
||||||
|
|
|
@ -22,8 +22,6 @@
|
||||||
#include "libc/nexgen32e/x86feature.h"
|
#include "libc/nexgen32e/x86feature.h"
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
|
|
||||||
typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(16)));
|
|
||||||
|
|
||||||
static inline const unsigned char *rawmemchr_pure(const unsigned char *s,
|
static inline const unsigned char *rawmemchr_pure(const unsigned char *s,
|
||||||
unsigned char c) {
|
unsigned char c) {
|
||||||
for (;; ++s) {
|
for (;; ++s) {
|
||||||
|
@ -34,6 +32,7 @@ static inline const unsigned char *rawmemchr_pure(const unsigned char *s,
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __x86_64__
|
#ifdef __x86_64__
|
||||||
|
typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(16)));
|
||||||
noasan static inline const char *rawmemchr_sse(const char *s, unsigned char c) {
|
noasan static inline const char *rawmemchr_sse(const char *s, unsigned char c) {
|
||||||
unsigned k;
|
unsigned k;
|
||||||
unsigned m;
|
unsigned m;
|
||||||
|
@ -54,6 +53,12 @@ noasan static inline const char *rawmemchr_sse(const char *s, unsigned char c) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static inline noasan uint64_t UncheckedAlignedRead64(unsigned char *p) {
|
||||||
|
return (uint64_t)p[7] << 070 | (uint64_t)p[6] << 060 | (uint64_t)p[5] << 050 |
|
||||||
|
(uint64_t)p[4] << 040 | (uint64_t)p[3] << 030 | (uint64_t)p[2] << 020 |
|
||||||
|
(uint64_t)p[1] << 010 | (uint64_t)p[0] << 000;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns pointer to first instance of character.
|
* Returns pointer to first instance of character.
|
||||||
*
|
*
|
||||||
|
@ -72,6 +77,22 @@ void *rawmemchr(const void *s, int c) {
|
||||||
}
|
}
|
||||||
return (void *)r;
|
return (void *)r;
|
||||||
#else
|
#else
|
||||||
return rawmemchr_pure(s, c);
|
uint64_t v, w;
|
||||||
|
const unsigned char *p;
|
||||||
|
p = s;
|
||||||
|
c &= 255;
|
||||||
|
v = 0x0101010101010101ul * c;
|
||||||
|
for (; (uintptr_t)p & 7; ++p) {
|
||||||
|
if (*p == c) return p;
|
||||||
|
}
|
||||||
|
for (;; p += 8) {
|
||||||
|
w = UncheckedAlignedRead64(p);
|
||||||
|
if ((w = ~(w ^ v) & ((w ^ v) - 0x0101010101010101) & 0x8080808080808080)) {
|
||||||
|
p += (unsigned)__builtin_ctzll(w) >> 3;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert(*p == c);
|
||||||
|
return p;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,8 +22,6 @@
|
||||||
#include "libc/nexgen32e/x86feature.h"
|
#include "libc/nexgen32e/x86feature.h"
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
|
|
||||||
typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(16)));
|
|
||||||
|
|
||||||
static inline const char *strchr_pure(const char *s, int c) {
|
static inline const char *strchr_pure(const char *s, int c) {
|
||||||
for (;; ++s) {
|
for (;; ++s) {
|
||||||
if ((*s & 255) == (c & 255)) return s;
|
if ((*s & 255) == (c & 255)) return s;
|
||||||
|
@ -32,6 +30,7 @@ static inline const char *strchr_pure(const char *s, int c) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __x86_64__
|
#ifdef __x86_64__
|
||||||
|
typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(16)));
|
||||||
noasan static inline const char *strchr_sse(const char *s, unsigned char c) {
|
noasan static inline const char *strchr_sse(const char *s, unsigned char c) {
|
||||||
unsigned k;
|
unsigned k;
|
||||||
unsigned m;
|
unsigned m;
|
||||||
|
|
|
@ -22,8 +22,6 @@
|
||||||
#include "libc/nexgen32e/x86feature.h"
|
#include "libc/nexgen32e/x86feature.h"
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
|
|
||||||
typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(16)));
|
|
||||||
|
|
||||||
static inline const char *strchrnul_pure(const char *s, int c) {
|
static inline const char *strchrnul_pure(const char *s, int c) {
|
||||||
for (;; ++s) {
|
for (;; ++s) {
|
||||||
if ((*s & 255) == (c & 255)) return s;
|
if ((*s & 255) == (c & 255)) return s;
|
||||||
|
@ -32,6 +30,7 @@ static inline const char *strchrnul_pure(const char *s, int c) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __x86_64__
|
#ifdef __x86_64__
|
||||||
|
typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(16)));
|
||||||
noasan static inline const char *strchrnul_sse(const char *s, unsigned char c) {
|
noasan static inline const char *strchrnul_sse(const char *s, unsigned char c) {
|
||||||
unsigned k;
|
unsigned k;
|
||||||
unsigned m;
|
unsigned m;
|
||||||
|
@ -52,6 +51,36 @@ noasan static inline const char *strchrnul_sse(const char *s, unsigned char c) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
noasan static const char *strchrnul_x64(const char *p, uint64_t c) {
|
||||||
|
unsigned a, b;
|
||||||
|
uint64_t w, x, y;
|
||||||
|
for (c *= 0x0101010101010101;; p += 8) {
|
||||||
|
w = (uint64_t)(255 & p[7]) << 070 | (uint64_t)(255 & p[6]) << 060 |
|
||||||
|
(uint64_t)(255 & p[5]) << 050 | (uint64_t)(255 & p[4]) << 040 |
|
||||||
|
(uint64_t)(255 & p[3]) << 030 | (uint64_t)(255 & p[2]) << 020 |
|
||||||
|
(uint64_t)(255 & p[1]) << 010 | (uint64_t)(255 & p[0]) << 000;
|
||||||
|
if ((x = ~(w ^ c) & ((w ^ c) - 0x0101010101010101) & 0x8080808080808080) |
|
||||||
|
(y = ~w & (w - 0x0101010101010101) & 0x8080808080808080)) {
|
||||||
|
if (x) {
|
||||||
|
a = __builtin_ctzll(x);
|
||||||
|
if (y) {
|
||||||
|
b = __builtin_ctzll(y);
|
||||||
|
if (a <= b) {
|
||||||
|
return p + (a >> 3);
|
||||||
|
} else {
|
||||||
|
return p + (b >> 3);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return p + (a >> 3);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
b = __builtin_ctzll(y);
|
||||||
|
return p + (b >> 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns pointer to first instance of character.
|
* Returns pointer to first instance of character.
|
||||||
*
|
*
|
||||||
|
@ -74,6 +103,13 @@ char *strchrnul(const char *s, int c) {
|
||||||
_unassert((*r & 255) == (c & 255) || !*r);
|
_unassert((*r & 255) == (c & 255) || !*r);
|
||||||
return (char *)r;
|
return (char *)r;
|
||||||
#else
|
#else
|
||||||
return strchrnul_pure(s, c);
|
char *r;
|
||||||
|
for (c &= 255; (uintptr_t)s & 7; ++s) {
|
||||||
|
if ((*s & 0xff) == c) return s;
|
||||||
|
if (!*s) return s;
|
||||||
|
}
|
||||||
|
r = strchrnul_x64(s, c);
|
||||||
|
assert((*r & 255) == c || !*r);
|
||||||
|
return r;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,9 +24,8 @@
|
||||||
|
|
||||||
typedef uint64_t xmm_t __attribute__((__vector_size__(16), __aligned__(1)));
|
typedef uint64_t xmm_t __attribute__((__vector_size__(16), __aligned__(1)));
|
||||||
|
|
||||||
noasan static dontinline antiquity unsigned timingsafe_bcmp_sse(const char *p,
|
noasan static unsigned timingsafe_bcmp_sse(const char *p, const char *q,
|
||||||
const char *q,
|
size_t n) {
|
||||||
size_t n) {
|
|
||||||
uint64_t w;
|
uint64_t w;
|
||||||
xmm_t a = {0};
|
xmm_t a = {0};
|
||||||
while (n > 16 + 16) {
|
while (n > 16 + 16) {
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/intrin/likely.h"
|
#include "libc/intrin/likely.h"
|
||||||
|
#include "libc/str/str.h"
|
||||||
#include "libc/str/unicode.h"
|
#include "libc/str/unicode.h"
|
||||||
|
|
||||||
extern const uint8_t kEastAsianWidth[];
|
extern const uint8_t kEastAsianWidth[];
|
||||||
|
@ -28,6 +29,7 @@ extern const uint32_t kCombiningCharsBits;
|
||||||
* Returns cell width of monospace character.
|
* Returns cell width of monospace character.
|
||||||
*/
|
*/
|
||||||
int wcwidth(wchar_t c) {
|
int wcwidth(wchar_t c) {
|
||||||
|
#ifdef __x86_64__
|
||||||
if (LIKELY(32 <= c && c < 127)) {
|
if (LIKELY(32 <= c && c < 127)) {
|
||||||
return 1;
|
return 1;
|
||||||
} else if (!c) {
|
} else if (!c) {
|
||||||
|
@ -42,4 +44,16 @@ int wcwidth(wchar_t c) {
|
||||||
} else {
|
} else {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
if (!c) return 0;
|
||||||
|
if (c < 0 || iswcntrl(c)) return -1;
|
||||||
|
return 1 +
|
||||||
|
(c >= 0x1100 &&
|
||||||
|
(c <= 0x115f || c == 0x2329 || c == 0x232a ||
|
||||||
|
(c >= 0x2e80 && c <= 0xa4cf && c != 0x303f) ||
|
||||||
|
(c >= 0xac00 && c <= 0xd7a3) || (c >= 0xf900 && c <= 0xfaff) ||
|
||||||
|
(c >= 0xfe10 && c <= 0xfe19) || (c >= 0xfe30 && c <= 0xfe6f) ||
|
||||||
|
(c >= 0xff00 && c <= 0xff60) || (c >= 0xffe0 && c <= 0xffe6) ||
|
||||||
|
(c >= 0x20000 && c <= 0x2fffd) || (c >= 0x30000 && c <= 0x3fffd)));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
1
libc/tinymath/LICENSE.fdlibm
Normal file
1
libc/tinymath/LICENSE.fdlibm
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Q29weXJpZ2h0IChDKSAxOTkzLTIwMDQgYnkgU3VuIE1pY3Jvc3lzdGVtcywgSW5jLiBBbGwgcmlnaHRzIHJlc2VydmVkLgoKRGV2ZWxvcGVkIGF0IFN1blNvZnQsIGEgU3VuIE1pY3Jvc3lzdGVtcywgSW5jLiBidXNpbmVzcy4KUGVybWlzc2lvbiB0byB1c2UsIGNvcHksIG1vZGlmeSwgYW5kIGRpc3RyaWJ1dGUgdGhpcwpzb2Z0d2FyZSBpcyBmcmVlbHkgZ3JhbnRlZCwgcHJvdmlkZWQgdGhhdCB0aGlzIG5vdGljZQppcyBwcmVzZXJ2ZWQuCg==
|
125
libc/tinymath/LICENSE.freebsd
Normal file
125
libc/tinymath/LICENSE.freebsd
Normal file
|
@ -0,0 +1,125 @@
|
||||||
|
# @(#)COPYRIGHT 8.2 (Berkeley) 3/21/94
|
||||||
|
|
||||||
|
The compilation of software known as FreeBSD is distributed under the
|
||||||
|
following terms:
|
||||||
|
|
||||||
|
Copyright (c) 1992-2023 The FreeBSD Project.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in the
|
||||||
|
documentation and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||||
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGE.
|
||||||
|
|
||||||
|
The 4.4BSD and 4.4BSD-Lite software is distributed under the following
|
||||||
|
terms:
|
||||||
|
|
||||||
|
All of the documentation and software included in the 4.4BSD and 4.4BSD-Lite
|
||||||
|
Releases is copyrighted by The Regents of the University of California.
|
||||||
|
|
||||||
|
Copyright 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994
|
||||||
|
The Regents of the University of California. All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in the
|
||||||
|
documentation and/or other materials provided with the distribution.
|
||||||
|
3. All advertising materials mentioning features or use of this software
|
||||||
|
must display the following acknowledgement:
|
||||||
|
This product includes software developed by the University of
|
||||||
|
California, Berkeley and its contributors.
|
||||||
|
4. Neither the name of the University nor the names of its contributors
|
||||||
|
may be used to endorse or promote products derived from this software
|
||||||
|
without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGE.
|
||||||
|
|
||||||
|
The Institute of Electrical and Electronics Engineers and the American
|
||||||
|
National Standards Committee X3, on Information Processing Systems have
|
||||||
|
given us permission to reprint portions of their documentation.
|
||||||
|
|
||||||
|
In the following statement, the phrase ``this text'' refers to portions
|
||||||
|
of the system documentation.
|
||||||
|
|
||||||
|
Portions of this text are reprinted and reproduced in electronic form in
|
||||||
|
the second BSD Networking Software Release, from IEEE Std 1003.1-1988, IEEE
|
||||||
|
Standard Portable Operating System Interface for Computer Environments
|
||||||
|
(POSIX), copyright C 1988 by the Institute of Electrical and Electronics
|
||||||
|
Engineers, Inc. In the event of any discrepancy between these versions
|
||||||
|
and the original IEEE Standard, the original IEEE Standard is the referee
|
||||||
|
document.
|
||||||
|
|
||||||
|
In the following statement, the phrase ``This material'' refers to portions
|
||||||
|
of the system documentation.
|
||||||
|
|
||||||
|
This material is reproduced with permission from American National
|
||||||
|
Standards Committee X3, on Information Processing Systems. Computer and
|
||||||
|
Business Equipment Manufacturers Association (CBEMA), 311 First St., NW,
|
||||||
|
Suite 500, Washington, DC 20001-2178. The developmental work of
|
||||||
|
Programming Language C was completed by the X3J11 Technical Committee.
|
||||||
|
|
||||||
|
The views and conclusions contained in the software and documentation are
|
||||||
|
those of the authors and should not be interpreted as representing official
|
||||||
|
policies, either expressed or implied, of the Regents of the University
|
||||||
|
of California.
|
||||||
|
|
||||||
|
|
||||||
|
NOTE: The copyright of UC Berkeley's Berkeley Software Distribution ("BSD")
|
||||||
|
source has been updated. The copyright addendum may be found at
|
||||||
|
ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change and is
|
||||||
|
included below.
|
||||||
|
|
||||||
|
July 22, 1999
|
||||||
|
|
||||||
|
To All Licensees, Distributors of Any Version of BSD:
|
||||||
|
|
||||||
|
As you know, certain of the Berkeley Software Distribution ("BSD") source
|
||||||
|
code files require that further distributions of products containing all or
|
||||||
|
portions of the software, acknowledge within their advertising materials
|
||||||
|
that such products contain software developed by UC Berkeley and its
|
||||||
|
contributors.
|
||||||
|
|
||||||
|
Specifically, the provision reads:
|
||||||
|
|
||||||
|
" * 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by the University of
|
||||||
|
* California, Berkeley and its contributors."
|
||||||
|
|
||||||
|
Effective immediately, licensees and distributors are no longer required to
|
||||||
|
include the acknowledgement within advertising materials. Accordingly, the
|
||||||
|
foregoing paragraph of those BSD Unix files containing it is hereby deleted
|
||||||
|
in its entirety.
|
||||||
|
|
||||||
|
William Hoskins
|
||||||
|
Director, Office of Technology Licensing
|
||||||
|
University of California, Berkeley
|
193
libc/tinymath/LICENSE.musl
Normal file
193
libc/tinymath/LICENSE.musl
Normal file
|
@ -0,0 +1,193 @@
|
||||||
|
musl as a whole is licensed under the following standard MIT license:
|
||||||
|
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
Copyright © 2005-2020 Rich Felker, et al.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
a copy of this software and associated documentation files (the
|
||||||
|
"Software"), to deal in the Software without restriction, including
|
||||||
|
without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be
|
||||||
|
included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||||
|
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||||
|
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||||
|
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
|
||||||
|
Authors/contributors include:
|
||||||
|
|
||||||
|
A. Wilcox
|
||||||
|
Ada Worcester
|
||||||
|
Alex Dowad
|
||||||
|
Alex Suykov
|
||||||
|
Alexander Monakov
|
||||||
|
Andre McCurdy
|
||||||
|
Andrew Kelley
|
||||||
|
Anthony G. Basile
|
||||||
|
Aric Belsito
|
||||||
|
Arvid Picciani
|
||||||
|
Bartosz Brachaczek
|
||||||
|
Benjamin Peterson
|
||||||
|
Bobby Bingham
|
||||||
|
Boris Brezillon
|
||||||
|
Brent Cook
|
||||||
|
Chris Spiegel
|
||||||
|
Clément Vasseur
|
||||||
|
Daniel Micay
|
||||||
|
Daniel Sabogal
|
||||||
|
Daurnimator
|
||||||
|
David Carlier
|
||||||
|
David Edelsohn
|
||||||
|
Denys Vlasenko
|
||||||
|
Dmitry Ivanov
|
||||||
|
Dmitry V. Levin
|
||||||
|
Drew DeVault
|
||||||
|
Emil Renner Berthing
|
||||||
|
Fangrui Song
|
||||||
|
Felix Fietkau
|
||||||
|
Felix Janda
|
||||||
|
Gianluca Anzolin
|
||||||
|
Hauke Mehrtens
|
||||||
|
He X
|
||||||
|
Hiltjo Posthuma
|
||||||
|
Isaac Dunham
|
||||||
|
Jaydeep Patil
|
||||||
|
Jens Gustedt
|
||||||
|
Jeremy Huntwork
|
||||||
|
Jo-Philipp Wich
|
||||||
|
Joakim Sindholt
|
||||||
|
John Spencer
|
||||||
|
Julien Ramseier
|
||||||
|
Justin Cormack
|
||||||
|
Kaarle Ritvanen
|
||||||
|
Khem Raj
|
||||||
|
Kylie McClain
|
||||||
|
Leah Neukirchen
|
||||||
|
Luca Barbato
|
||||||
|
Luka Perkov
|
||||||
|
M Farkas-Dyck (Strake)
|
||||||
|
Mahesh Bodapati
|
||||||
|
Markus Wichmann
|
||||||
|
Masanori Ogino
|
||||||
|
Michael Clark
|
||||||
|
Michael Forney
|
||||||
|
Mikhail Kremnyov
|
||||||
|
Natanael Copa
|
||||||
|
Nicholas J. Kain
|
||||||
|
orc
|
||||||
|
Pascal Cuoq
|
||||||
|
Patrick Oppenlander
|
||||||
|
Petr Hosek
|
||||||
|
Petr Skocik
|
||||||
|
Pierre Carrier
|
||||||
|
Reini Urban
|
||||||
|
Rich Felker
|
||||||
|
Richard Pennington
|
||||||
|
Ryan Fairfax
|
||||||
|
Samuel Holland
|
||||||
|
Segev Finer
|
||||||
|
Shiz
|
||||||
|
sin
|
||||||
|
Solar Designer
|
||||||
|
Stefan Kristiansson
|
||||||
|
Stefan O'Rear
|
||||||
|
Szabolcs Nagy
|
||||||
|
Timo Teräs
|
||||||
|
Trutz Behn
|
||||||
|
Valentin Ochs
|
||||||
|
Will Dietz
|
||||||
|
William Haddon
|
||||||
|
William Pitcock
|
||||||
|
|
||||||
|
Portions of this software are derived from third-party works licensed
|
||||||
|
under terms compatible with the above MIT license:
|
||||||
|
|
||||||
|
The TRE regular expression implementation (src/regex/reg* and
|
||||||
|
src/regex/tre*) is Copyright © 2001-2008 Ville Laurikari and licensed
|
||||||
|
under a 2-clause BSD license (license text in the source files). The
|
||||||
|
included version has been heavily modified by Rich Felker in 2012, in
|
||||||
|
the interests of size, simplicity, and namespace cleanliness.
|
||||||
|
|
||||||
|
Much of the math library code (src/math/* and src/complex/*) is
|
||||||
|
Copyright © 1993,2004 Sun Microsystems or
|
||||||
|
Copyright © 2003-2011 David Schultz or
|
||||||
|
Copyright © 2003-2009 Steven G. Kargl or
|
||||||
|
Copyright © 2003-2009 Bruce D. Evans or
|
||||||
|
Copyright © 2008 Stephen L. Moshier or
|
||||||
|
Copyright © 2017-2018 Arm Limited
|
||||||
|
and labelled as such in comments in the individual source files. All
|
||||||
|
have been licensed under extremely permissive terms.
|
||||||
|
|
||||||
|
The ARM memcpy code (src/string/arm/memcpy.S) is Copyright © 2008
|
||||||
|
The Android Open Source Project and is licensed under a two-clause BSD
|
||||||
|
license. It was taken from Bionic libc, used on Android.
|
||||||
|
|
||||||
|
The AArch64 memcpy and memset code (src/string/aarch64/*) are
|
||||||
|
Copyright © 1999-2019, Arm Limited.
|
||||||
|
|
||||||
|
The implementation of DES for crypt (src/crypt/crypt_des.c) is
|
||||||
|
Copyright © 1994 David Burren. It is licensed under a BSD license.
|
||||||
|
|
||||||
|
The implementation of blowfish crypt (src/crypt/crypt_blowfish.c) was
|
||||||
|
originally written by Solar Designer and placed into the public
|
||||||
|
domain. The code also comes with a fallback permissive license for use
|
||||||
|
in jurisdictions that may not recognize the public domain.
|
||||||
|
|
||||||
|
The smoothsort implementation (src/stdlib/qsort.c) is Copyright © 2011
|
||||||
|
Valentin Ochs and is licensed under an MIT-style license.
|
||||||
|
|
||||||
|
The x86_64 port was written by Nicholas J. Kain and is licensed under
|
||||||
|
the standard MIT terms.
|
||||||
|
|
||||||
|
The mips and microblaze ports were originally written by Richard
|
||||||
|
Pennington for use in the ellcc project. The original code was adapted
|
||||||
|
by Rich Felker for build system and code conventions during upstream
|
||||||
|
integration. It is licensed under the standard MIT terms.
|
||||||
|
|
||||||
|
The mips64 port was contributed by Imagination Technologies and is
|
||||||
|
licensed under the standard MIT terms.
|
||||||
|
|
||||||
|
The powerpc port was also originally written by Richard Pennington,
|
||||||
|
and later supplemented and integrated by John Spencer. It is licensed
|
||||||
|
under the standard MIT terms.
|
||||||
|
|
||||||
|
All other files which have no copyright comments are original works
|
||||||
|
produced specifically for use as part of this library, written either
|
||||||
|
by Rich Felker, the main author of the library, or by one or more
|
||||||
|
contibutors listed above. Details on authorship of individual files
|
||||||
|
can be found in the git version control history of the project. The
|
||||||
|
omission of copyright and license comments in each file is in the
|
||||||
|
interest of source tree size.
|
||||||
|
|
||||||
|
In addition, permission is hereby granted for all public header files
|
||||||
|
(include/* and arch/*/bits/*) and crt files intended to be linked into
|
||||||
|
applications (crt/*, ldso/dlstart.c, and arch/*/crt_arch.h) to omit
|
||||||
|
the copyright notice and permission notice otherwise required by the
|
||||||
|
license, and to use these files without any requirement of
|
||||||
|
attribution. These files include substantial contributions from:
|
||||||
|
|
||||||
|
Bobby Bingham
|
||||||
|
John Spencer
|
||||||
|
Nicholas J. Kain
|
||||||
|
Rich Felker
|
||||||
|
Richard Pennington
|
||||||
|
Stefan Kristiansson
|
||||||
|
Szabolcs Nagy
|
||||||
|
|
||||||
|
all of whom have explicitly granted such permission.
|
||||||
|
|
||||||
|
This file previously contained text expressing a belief that most of
|
||||||
|
the files covered by the above exception were sufficiently trivial not
|
||||||
|
to be subject to copyright, resulting in confusion over whether it
|
||||||
|
negated the permissions granted in the license. In the spirit of
|
||||||
|
permissive licensing, and of not having licensing issues being an
|
||||||
|
obstacle to adoption, that text has been removed.
|
394
libc/tinymath/LICENSE.openbsd
Normal file
394
libc/tinymath/LICENSE.openbsd
Normal file
|
@ -0,0 +1,394 @@
|
||||||
|
OpenBSD Copyright Policy
|
||||||
|
https://www.openbsd.org/policy.html
|
||||||
|
|
||||||
|
Goal
|
||||||
|
|
||||||
|
Copyright law is complex, OpenBSD policy is simple — OpenBSD
|
||||||
|
strives to provide code that can be freely used, copied, modified,
|
||||||
|
and distributed by anyone and for any purpose. This maintains the
|
||||||
|
spirit of the original Berkeley Software Distribution. The
|
||||||
|
preferred wording of a license to be applied to new code can be
|
||||||
|
found in the license template.
|
||||||
|
|
||||||
|
OpenBSD can exist as it does today because of the example set by
|
||||||
|
the Computer Systems Research Group at Berkeley and the battles
|
||||||
|
which they and others fought to create a Unix source distribution
|
||||||
|
un-encumbered by proprietary code and commercial licensing.
|
||||||
|
|
||||||
|
The ability of a freely redistributable "Berkeley" Unix to move
|
||||||
|
forward on a competitive basis with other operating systems
|
||||||
|
depends on the willingness of the various development groups to
|
||||||
|
exchange code amongst themselves and with other projects.
|
||||||
|
Understanding the legal issues surrounding copyright is
|
||||||
|
fundamental to the ability to exchange and re-distribute code,
|
||||||
|
while honoring the spirit of the copyright and concept of
|
||||||
|
attribution is fundamental to promoting the cooperation of the
|
||||||
|
people involved.
|
||||||
|
|
||||||
|
The Berkeley Copyright
|
||||||
|
|
||||||
|
The original Berkeley copyright poses no restrictions on private
|
||||||
|
or commercial use of the software and imposes only simple and
|
||||||
|
uniform requirements for maintaining copyright notices in
|
||||||
|
redistributed versions and crediting the originator of the
|
||||||
|
material only in advertising.
|
||||||
|
|
||||||
|
For instance:
|
||||||
|
|
||||||
|
* Copyright (c) 1982, 1986, 1990, 1991, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by the University of
|
||||||
|
* California, Berkeley and its contributors.
|
||||||
|
* 4. Neither the name of the University nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
|
||||||
|
Berkeley rescinded the 3rd term (the advertising term) on 22 July
|
||||||
|
1999. Verbatim copies of the Berkeley license in the OpenBSD tree
|
||||||
|
have that term removed. In addition, many 3rd-party BSD-style
|
||||||
|
licenses consist solely of the first two terms.
|
||||||
|
|
||||||
|
Because the OpenBSD copyright imposes no conditions beyond those
|
||||||
|
imposed by the Berkeley copyright, OpenBSD can hope to share the
|
||||||
|
same wide distribution and applicability as the Berkeley
|
||||||
|
distributions. It follows however, that OpenBSD cannot include
|
||||||
|
material which includes copyrights which are more restrictive than
|
||||||
|
the Berkeley copyright, or must relegate this material to a
|
||||||
|
secondary status, i.e. OpenBSD as a whole is freely
|
||||||
|
redistributable, but some optional components may not be.
|
||||||
|
|
||||||
|
Copyright Law
|
||||||
|
|
||||||
|
While the overall subject of copyright law is far beyond the scope
|
||||||
|
of this document, some basics are in order. Under the current
|
||||||
|
copyright law, copyrights are implicit in the creation of a new
|
||||||
|
work and reside with the creator. In general the copyright applies
|
||||||
|
only to the new work, not the material the work was derived from,
|
||||||
|
nor those portions of the derivative material included in the new
|
||||||
|
work.
|
||||||
|
|
||||||
|
Copyright law admits to three general categories of works:
|
||||||
|
|
||||||
|
Original Work
|
||||||
|
A new work that is not derived from an existing work.
|
||||||
|
|
||||||
|
Derivative Work
|
||||||
|
Work that is derived from, includes or amends existing
|
||||||
|
works.
|
||||||
|
|
||||||
|
Compilation
|
||||||
|
A work that is a compilation of existing new and
|
||||||
|
derivative works.
|
||||||
|
|
||||||
|
The fundamental concept is that there is primacy of the copyright,
|
||||||
|
that is a copyright of a derivative work does not affect the
|
||||||
|
rights held by the owner of the copyright of the original work,
|
||||||
|
rather only the part added. Likewise the copyright of a
|
||||||
|
compilation does not affect the rights of the owner of the
|
||||||
|
included works, only the compilation as an entity.
|
||||||
|
|
||||||
|
It is vitally important to understand that copyrights are broad
|
||||||
|
protections as defined by national and international copyright
|
||||||
|
law. The "copyright notices" usually included in source files are
|
||||||
|
not copyrights, but rather notices that a party asserts that they
|
||||||
|
hold copyright to the material or to part of the material.
|
||||||
|
Typically these notices are associated with license terms which
|
||||||
|
grant permissions subject to copyright law and with disclaimers
|
||||||
|
that state the position of the copyright holder/distributor with
|
||||||
|
respect to liability surrounding use of the material.
|
||||||
|
|
||||||
|
By international law, specifically the Berne Convention for the
|
||||||
|
Protection of Literary and Artistic Works, part of the author's
|
||||||
|
copyright, the so-called moral rights, are inalienable. This
|
||||||
|
includes the author's right "to claim authorship of the work and
|
||||||
|
to object to any distortion, mutilation or other modification of,
|
||||||
|
or other derogatory action in relation to, the said work, which
|
||||||
|
would be prejudicial to his honor or reputation". In some
|
||||||
|
countries, the law reserves additional inalienable moral rights to
|
||||||
|
the author. On the other hand, the author is free to transfer
|
||||||
|
other parts of his copyright, the so-called economic rights, in
|
||||||
|
particular the rights to use, copy, modify, distribute, and
|
||||||
|
license the work.
|
||||||
|
|
||||||
|
Permissions — the flip side
|
||||||
|
|
||||||
|
Because copyrights arise from the creation of a work, rather than
|
||||||
|
through a registration process, there needs to be a practical way
|
||||||
|
to extend permission to use a work beyond what might be allowed by
|
||||||
|
"fair use" provisions of the copyright laws.
|
||||||
|
|
||||||
|
This permission typically takes the form of a "release" or
|
||||||
|
"license" included in the work, which grants the additional uses
|
||||||
|
beyond those granted by copyright law, usually subject to a
|
||||||
|
variety of conditions. At one extreme sits "public domain" where
|
||||||
|
the originator asserts that he imposes no restrictions on use of
|
||||||
|
the material, at the other restrictive clauses that actually grant
|
||||||
|
no additional rights or impose restrictive, discriminatory or
|
||||||
|
impractical conditions on use of the work.
|
||||||
|
|
||||||
|
Note that a license is not to be confused with a copyright
|
||||||
|
transfer. While a transfer would give the new copyright holder
|
||||||
|
exclusive rights to use the code and take these rights away from
|
||||||
|
the author, a license typically grants additional people
|
||||||
|
non-exclusive rights to use the code, while the authors retain all
|
||||||
|
their rights.
|
||||||
|
|
||||||
|
The above observations regarding moral rights imply that putting
|
||||||
|
code under an ISC or two-clause BSD license essentially makes the
|
||||||
|
code as free as it can possibly get. Modifying the wording of
|
||||||
|
these licenses can only result in one of the three following
|
||||||
|
effects:
|
||||||
|
* making the code less free by adding additional restrictions
|
||||||
|
regarding its use, copying, modification or distribution;
|
||||||
|
* or effectively not changing anything by merely changing the
|
||||||
|
wording, but not changing anything substantial regarding the
|
||||||
|
legal content;
|
||||||
|
* or making the license illegal by attempting to deprive the
|
||||||
|
authors of rights they cannot legally give away.
|
||||||
|
|
||||||
|
Again, an important point to note is that the release and
|
||||||
|
conditions can only apply to the portion of the work that was
|
||||||
|
originated by the copyright holder—the holder of a copyright on a
|
||||||
|
derivative work can neither grant additional permissions for use
|
||||||
|
of the original work, nor impose more restrictive conditions for
|
||||||
|
use of that work.
|
||||||
|
|
||||||
|
Because copyright arises from the creation of a work and not the
|
||||||
|
text or a registration process, removing or altering a copyright
|
||||||
|
notice or associated release terms has no bearing on the existence
|
||||||
|
of the copyright, rather all that is accomplished is to cast doubt
|
||||||
|
upon whatever rights the person making the modifications had to
|
||||||
|
use the material in the first place. Likewise, adding terms and
|
||||||
|
conditions in conflict with the original terms and conditions does
|
||||||
|
not supersede them, rather it casts doubts on the rights of the
|
||||||
|
person making the amendments to use the material and creates
|
||||||
|
confusion as to whether anyone can use the amended version or
|
||||||
|
derivatives thereof.
|
||||||
|
|
||||||
|
Finally, releases are generally binding on the material that they
|
||||||
|
are distributed with. This means that if the originator of a work
|
||||||
|
distributes that work with a release granting certain permissions,
|
||||||
|
those permissions apply as stated, without discrimination, to all
|
||||||
|
persons legitimately possessing a copy of the work. That means
|
||||||
|
that having granted a permission, the copyright holder can not
|
||||||
|
retroactively say that an individual or class of individuals are
|
||||||
|
no longer granted those permissions. Likewise should the copyright
|
||||||
|
holder decide to "go commercial" he can not revoke permissions
|
||||||
|
already granted for the use of the work as distributed, though he
|
||||||
|
may impose more restrictive permissions in his future
|
||||||
|
distributions of that work.
|
||||||
|
|
||||||
|
Specific Cases
|
||||||
|
|
||||||
|
This section attempts to summarize the position of OpenBSD
|
||||||
|
relative to some commonly encountered copyrights.
|
||||||
|
|
||||||
|
Berkeley
|
||||||
|
|
||||||
|
The Berkeley copyright is the model for the OpenBSD
|
||||||
|
copyright. It retains the rights of the copyright holder,
|
||||||
|
while imposing minimal conditions on the use of the
|
||||||
|
copyrighted material. Material with Berkeley copyrights,
|
||||||
|
or copyrights closely adhering to the Berkeley model can
|
||||||
|
generally be included in OpenBSD.
|
||||||
|
|
||||||
|
AT&T
|
||||||
|
|
||||||
|
As part of its settlement with AT&T, Berkeley included an
|
||||||
|
AT&T copyright notice on some of the files in 4.4BSD lite
|
||||||
|
and lite2. The terms of this license are identical to the
|
||||||
|
standard Berkeley license.
|
||||||
|
|
||||||
|
Additionally, OpenBSD includes some other AT&T code with
|
||||||
|
non-restrictive copyrights, such as the reference
|
||||||
|
implementation of awk.
|
||||||
|
|
||||||
|
Caldera
|
||||||
|
|
||||||
|
The original Unix code (AT&T versions 1 through 7 UNIX,
|
||||||
|
including 32V) was freed by Caldera, Inc. on 23 January
|
||||||
|
2002 and is now available under a 4-term BSD-style
|
||||||
|
license. As a result, it would theoretically be possible
|
||||||
|
to incorporate original Unix code into OpenBSD. However,
|
||||||
|
that code is now so old that it does not satisfy today's
|
||||||
|
interface and quality standards.
|
||||||
|
|
||||||
|
DEC, Sun, other manufacturers/software houses.
|
||||||
|
|
||||||
|
In general OpenBSD does not include material copyrighted
|
||||||
|
by manufacturers or software houses. Material may be
|
||||||
|
included where the copyright owner has granted general
|
||||||
|
permission for reuse without conditions, with terms
|
||||||
|
similar to the Berkeley copyright, or where the material
|
||||||
|
is the product of an employee and the employer's copyright
|
||||||
|
notice effectively releases any rights they might have to
|
||||||
|
the work.
|
||||||
|
|
||||||
|
Carnegie-Mellon (CMU, Mach)
|
||||||
|
|
||||||
|
The Carnegie-Mellon copyright is similar to the Berkeley
|
||||||
|
copyright, except that it requests that derivative works
|
||||||
|
be made available to Carnegie-Mellon. Because this is only
|
||||||
|
a request and not a condition, such material can still be
|
||||||
|
included in OpenBSD. It should be noted that existing
|
||||||
|
versions of Mach are still subject to AT&T copyrights,
|
||||||
|
which prevents the general distribution of Mach sources.
|
||||||
|
|
||||||
|
Apache
|
||||||
|
|
||||||
|
The original Apache license was similar to the Berkeley
|
||||||
|
license, but source code published under version 2 of the
|
||||||
|
Apache license is subject to additional restrictions and
|
||||||
|
cannot be included into OpenBSD. In particular, if you use
|
||||||
|
code under the Apache 2 license, some of your rights will
|
||||||
|
terminate if you claim in court that the code violates a
|
||||||
|
patent.
|
||||||
|
|
||||||
|
A license can only be considered fully permissive if it
|
||||||
|
allows use by anyone for all the future without giving up
|
||||||
|
any of their rights. If there are conditions that might
|
||||||
|
terminate any rights in the future, or if you have to give
|
||||||
|
up a right that you would otherwise have, even if
|
||||||
|
exercising that right could reasonably be regarded as
|
||||||
|
morally objectionable, the code is not free.
|
||||||
|
|
||||||
|
In addition, the clause about the patent license is
|
||||||
|
problematic because a patent license cannot be granted
|
||||||
|
under Copyright law, but only under contract law, which
|
||||||
|
drags the whole license into the domain of contract law.
|
||||||
|
But while Copyright law is somewhat standardized by
|
||||||
|
international agreements, contract law differs wildly
|
||||||
|
among jurisdictions. So what the license means in
|
||||||
|
different jurisdictions may vary and is hard to predict.
|
||||||
|
|
||||||
|
ISC
|
||||||
|
|
||||||
|
The ISC copyright is functionally equivalent to a two-term
|
||||||
|
BSD copyright with language removed that is made
|
||||||
|
unnecessary by the Berne convention. This is the preferred
|
||||||
|
license for new code incorporated into OpenBSD. A sample
|
||||||
|
license is available in the file
|
||||||
|
/usr/share/misc/license.template.
|
||||||
|
|
||||||
|
GNU General Public License, GPL, LGPL, copyleft, etc.
|
||||||
|
|
||||||
|
The GNU Public License and licenses modeled on it impose
|
||||||
|
the restriction that source code must be distributed or
|
||||||
|
made available for all works that are derivatives of the
|
||||||
|
GNU copyrighted code.
|
||||||
|
|
||||||
|
While this may superficially look like a noble strategy,
|
||||||
|
it is a condition that is typically unacceptable for
|
||||||
|
commercial use of software. So in practice, it usually
|
||||||
|
ends up hindering free sharing and reuse of code and ideas
|
||||||
|
rather than encouraging it. As a consequence, no
|
||||||
|
additional software bound by the GPL terms will be
|
||||||
|
considered for inclusion into the OpenBSD base system.
|
||||||
|
|
||||||
|
For historical reasons, the OpenBSD base system still
|
||||||
|
includes the following GPL-licensed components: the GNU
|
||||||
|
compiler collection (GCC) with supporting binutils and
|
||||||
|
libraries, GNU CVS, GNU texinfo, the mkhybrid file system
|
||||||
|
creation tool, and the readline library. Replacement by
|
||||||
|
equivalent, more freely licensed tools is a long-term
|
||||||
|
desideratum.
|
||||||
|
|
||||||
|
NetBSD
|
||||||
|
|
||||||
|
Much of OpenBSD is originally based on and evolved from
|
||||||
|
NetBSD, since some of the OpenBSD developers were involved
|
||||||
|
in the NetBSD project. The general NetBSD license terms
|
||||||
|
are compatible with the Berkeley license and permit such
|
||||||
|
use. Material subject only to the general NetBSD license
|
||||||
|
can generally be included in OpenBSD.
|
||||||
|
|
||||||
|
In the past, NetBSD has included material copyrighted by
|
||||||
|
individuals who have imposed license conditions beyond
|
||||||
|
that of the general NetBSD license, but granted the NetBSD
|
||||||
|
Foundation license to distribute the material. Such
|
||||||
|
material can not be included in OpenBSD as long as the
|
||||||
|
conditions imposed are at odds with the OpenBSD license
|
||||||
|
terms or releases from those terms are offered on a
|
||||||
|
discriminatory basis.
|
||||||
|
|
||||||
|
FreeBSD
|
||||||
|
|
||||||
|
Most of FreeBSD is also based on Berkeley licensed
|
||||||
|
material or includes copyright notices based on the
|
||||||
|
Berkeley model. Such material can be included in OpenBSD,
|
||||||
|
while those parts that are subject to GPL or various
|
||||||
|
individual copyright terms that are at odds with the
|
||||||
|
OpenBSD license can not be included in OpenBSD.
|
||||||
|
|
||||||
|
Linux
|
||||||
|
|
||||||
|
Most of Linux is subject to GPL style licensing terms and
|
||||||
|
therefore can not be included in OpenBSD. Individual
|
||||||
|
components may be eligible, subject to the terms of the
|
||||||
|
originator's copyright notices. Note that Linux
|
||||||
|
"distributions" may also be subject to additional
|
||||||
|
copyright claims of the distributing organization, either
|
||||||
|
as a compilation or on material included that is not part
|
||||||
|
of the Linux core.
|
||||||
|
|
||||||
|
X.Org
|
||||||
|
|
||||||
|
The X.Org Foundation maintains and distributes the X
|
||||||
|
Window System under a modified MIT license, which is quite
|
||||||
|
similar to the BSD license and additionally allows
|
||||||
|
sublicensing. Under the name of Xenocara, the OpenBSD base
|
||||||
|
system includes an improved and actively maintained
|
||||||
|
version of the X.Org code.
|
||||||
|
|
||||||
|
Shareware, Charityware, Freeware, etc.
|
||||||
|
|
||||||
|
Most "shareware" copyright notices impose conditions for
|
||||||
|
redistribution, use or visibility that are at conflict
|
||||||
|
with the OpenBSD project goals. Review on a case-by-case
|
||||||
|
basis is required as to whether the wording of the
|
||||||
|
conditions is acceptable in terms of conditions being
|
||||||
|
requested vs. demanded and whether the spirit of the
|
||||||
|
conditions is compatible with goals of the OpenBSD
|
||||||
|
project.
|
||||||
|
|
||||||
|
Public Domain
|
||||||
|
|
||||||
|
While material that is truly entered into the "public
|
||||||
|
domain" can be included in OpenBSD, review is required on
|
||||||
|
a case by case basis. Frequently the "public domain"
|
||||||
|
assertion is made by someone who does not really hold all
|
||||||
|
rights under copyright law to grant that status or there
|
||||||
|
are a variety of conditions imposed on use. For a work to
|
||||||
|
be truly in the "public domain" all rights are abandoned
|
||||||
|
and the material is offered without restrictions.
|
||||||
|
|
||||||
|
In some jurisdictions, it is doubtful whether voluntarily
|
||||||
|
placing one's own work into the public domain is legally
|
||||||
|
possible. For that reason, to make any substantial body of
|
||||||
|
code free, it is preferable to state the copyright and put
|
||||||
|
it under an ISC or BSD license instead of attempting to
|
||||||
|
release it into the public domain.
|
249
libc/tinymath/LICENSE.optimized-routines
Normal file
249
libc/tinymath/LICENSE.optimized-routines
Normal file
|
@ -0,0 +1,249 @@
|
||||||
|
MIT OR Apache-2.0 WITH LLVM-exception
|
||||||
|
=====================================
|
||||||
|
|
||||||
|
|
||||||
|
MIT License
|
||||||
|
-----------
|
||||||
|
|
||||||
|
Copyright (c) 1999-2022, Arm Limited.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
|
||||||
|
|
||||||
|
Apache-2.0 WITH LLVM-exception
|
||||||
|
------------------------------
|
||||||
|
|
||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following
|
||||||
|
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||||
|
replaced with your own identifying information. (Don't include
|
||||||
|
the brackets!) The text should be enclosed in the appropriate
|
||||||
|
comment syntax for the file format. We also recommend that a
|
||||||
|
file or class name and description of purpose be included on the
|
||||||
|
same "printed page" as the copyright notice for easier
|
||||||
|
identification within third-party archives.
|
||||||
|
|
||||||
|
Copyright [yyyy] [name of copyright owner]
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
|
||||||
|
|
||||||
|
--- LLVM Exceptions to the Apache 2.0 License ----
|
||||||
|
|
||||||
|
As an exception, if, as a result of your compiling your source code, portions
|
||||||
|
of this Software are embedded into an Object form of such source code, you
|
||||||
|
may redistribute such embedded portions in such Object form without complying
|
||||||
|
with the conditions of Sections 4(a), 4(b) and 4(d) of the License.
|
||||||
|
|
||||||
|
In addition, if you combine or link compiled forms of this Software with
|
||||||
|
software that is licensed under the GPLv2 ("Combined Software") and if a
|
||||||
|
court of competent jurisdiction determines that the patent provision (Section
|
||||||
|
3), the indemnity provision (Section 9) or other Section of the License
|
||||||
|
conflicts with the conditions of the GPLv2, you may retroactively and
|
||||||
|
prospectively choose to deem waived or otherwise exclude such Section(s) of
|
||||||
|
the License, but only in their entirety and only with respect to the Combined
|
||||||
|
Software.
|
25
libc/tinymath/README.cosmo
Normal file
25
libc/tinymath/README.cosmo
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
README
|
||||||
|
|
||||||
|
This folder provides libm scalar math functions, sourced from Musl
|
||||||
|
Libc, FreeBSD, OpenBSD, and ARM's Optimized Routines project.
|
||||||
|
|
||||||
|
LICENSE
|
||||||
|
|
||||||
|
All code is covered by notice licenses (e.g. BSD, MIT) which are
|
||||||
|
documented on a file-by-file basis.
|
||||||
|
|
||||||
|
ORIGIN
|
||||||
|
|
||||||
|
git://git.musl-libc.org/musl
|
||||||
|
commit f5f55d6589940fd2c2188d76686efe3a530e64e0
|
||||||
|
Author: Rich Felker <dalias@aerifal.cx>
|
||||||
|
Date: Mon May 1 23:39:41 2023 -0400
|
||||||
|
|
||||||
|
release 1.2.4
|
||||||
|
|
||||||
|
git@github.com:ARM-software/optimized-routines.git
|
||||||
|
commit f9f58aa37edc3486f18b1dd8701b74b5e3873699
|
||||||
|
Author: Joe Ramsay <Joe.Ramsay@arm.com>
|
||||||
|
Date: Fri May 5 14:19:06 2023 +0100
|
||||||
|
|
||||||
|
math: Cleanup Neon cos and cosf
|
|
@ -32,17 +32,16 @@ asm(".ident\t\"\\n\\n\
|
||||||
Musl libc (MIT License)\\n\
|
Musl libc (MIT License)\\n\
|
||||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||||
asm(".include \"libc/disclaimer.inc\"");
|
asm(".include \"libc/disclaimer.inc\"");
|
||||||
/* clang-format off */
|
// clang-format off
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns inverse hyperbolic cosine of 𝑥.
|
||||||
|
* @define acosh(x) = log(x + sqrt(x*x-1))
|
||||||
|
*/
|
||||||
|
long double acoshl(long double x) {
|
||||||
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||||
long double acoshl(long double x)
|
|
||||||
{
|
|
||||||
return acosh(x);
|
return acosh(x);
|
||||||
}
|
|
||||||
#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
|
#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
|
||||||
/* acosh(x) = log(x + sqrt(x*x-1)) */
|
|
||||||
long double acoshl(long double x)
|
|
||||||
{
|
|
||||||
union ldshape u = {x};
|
union ldshape u = {x};
|
||||||
int e = u.i.se & 0x7fff;
|
int e = u.i.se & 0x7fff;
|
||||||
|
|
||||||
|
@ -53,11 +52,10 @@ long double acoshl(long double x)
|
||||||
/* |x| < 0x1p32 */
|
/* |x| < 0x1p32 */
|
||||||
return logl(2*x - 1/(x+sqrtl(x*x-1)));
|
return logl(2*x - 1/(x+sqrtl(x*x-1)));
|
||||||
return logl(x) + 0.693147180559945309417232121458176568L;
|
return logl(x) + 0.693147180559945309417232121458176568L;
|
||||||
}
|
|
||||||
#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384
|
#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384
|
||||||
// TODO: broken implementation to make things compile
|
// TODO: broken implementation to make things compile
|
||||||
long double acoshl(long double x)
|
|
||||||
{
|
|
||||||
return acosh(x);
|
return acosh(x);
|
||||||
}
|
#else
|
||||||
|
#error "architecture unsupported"
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ asm(".ident\t\"\\n\\n\
|
||||||
Musl libc (MIT License)\\n\
|
Musl libc (MIT License)\\n\
|
||||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||||
asm(".include \"libc/disclaimer.inc\"");
|
asm(".include \"libc/disclaimer.inc\"");
|
||||||
/* clang-format off */
|
// clang-format off
|
||||||
|
|
||||||
/* origin: FreeBSD /usr/src/lib/msun/src/e_acosl.c */
|
/* origin: FreeBSD /usr/src/lib/msun/src/e_acosl.c */
|
||||||
/*
|
/*
|
||||||
|
@ -54,11 +54,15 @@ asm(".include \"libc/disclaimer.inc\"");
|
||||||
* Converted to long double by David Schultz <das@FreeBSD.ORG>.
|
* Converted to long double by David Schultz <das@FreeBSD.ORG>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns arc cosine of 𝑥.
|
||||||
|
*
|
||||||
|
* @define atan2(fabs(sqrt((1-𝑥)*(1+𝑥))),𝑥)
|
||||||
|
* @domain -1 ≤ 𝑥 ≤ 1
|
||||||
|
*/
|
||||||
|
long double acosl(long double x) {
|
||||||
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||||
long double acosl(long double x)
|
|
||||||
{
|
|
||||||
return acos(x);
|
return acos(x);
|
||||||
}
|
|
||||||
#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
|
#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
|
||||||
#if LDBL_MANT_DIG == 64
|
#if LDBL_MANT_DIG == 64
|
||||||
#define CLEARBOTTOM(u) (u.i.m &= -1ULL << 32)
|
#define CLEARBOTTOM(u) (u.i.m &= -1ULL << 32)
|
||||||
|
@ -66,14 +70,6 @@ long double acosl(long double x)
|
||||||
#define CLEARBOTTOM(u) (u.i.lo = 0)
|
#define CLEARBOTTOM(u) (u.i.lo = 0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns arc cosine of 𝑥.
|
|
||||||
*
|
|
||||||
* @define atan2(fabs(sqrt((1-𝑥)*(1+𝑥))),𝑥)
|
|
||||||
* @domain -1 ≤ 𝑥 ≤ 1
|
|
||||||
*/
|
|
||||||
long double acosl(long double x)
|
|
||||||
{
|
|
||||||
union ldshape u = {x};
|
union ldshape u = {x};
|
||||||
long double z, s, c, f;
|
long double z, s, c, f;
|
||||||
uint16_t e = u.i.se & 0x7fff;
|
uint16_t e = u.i.se & 0x7fff;
|
||||||
|
@ -106,6 +102,8 @@ long double acosl(long double x)
|
||||||
f = u.f;
|
f = u.f;
|
||||||
c = (z - f*f)/(s + f);
|
c = (z - f*f)/(s + f);
|
||||||
return 2*(__invtrigl_R(z)*s + c + f);
|
return 2*(__invtrigl_R(z)*s + c + f);
|
||||||
}
|
|
||||||
|
|
||||||
|
#else
|
||||||
|
#error "architecture unsupported"
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
|
@ -34,21 +34,16 @@ asm(".ident\t\"\\n\\n\
|
||||||
Musl libc (MIT License)\\n\
|
Musl libc (MIT License)\\n\
|
||||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||||
asm(".include \"libc/disclaimer.inc\"");
|
asm(".include \"libc/disclaimer.inc\"");
|
||||||
/* clang-format off */
|
// clang-format off
|
||||||
|
|
||||||
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
|
||||||
long double asinhl(long double x)
|
|
||||||
{
|
|
||||||
return asinh(x);
|
|
||||||
}
|
|
||||||
#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns inverse hyperbolic sine of 𝑥.
|
* Returns inverse hyperbolic sine of 𝑥.
|
||||||
* @define asinh(x) = sign(x)*log(|x|+sqrt(x*x+1)) ~= x - x^3/6 + o(x^5)
|
* @define asinh(x) = sign(x)*log(|x|+sqrt(x*x+1)) ~= x - x^3/6 + o(x^5)
|
||||||
*/
|
*/
|
||||||
long double asinhl(long double x)
|
long double asinhl(long double x) {
|
||||||
{
|
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||||
|
return asinh(x);
|
||||||
|
#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
|
||||||
union ldshape u = {x};
|
union ldshape u = {x};
|
||||||
unsigned e = u.i.se & 0x7fff;
|
unsigned e = u.i.se & 0x7fff;
|
||||||
unsigned s = u.i.se >> 15;
|
unsigned s = u.i.se >> 15;
|
||||||
|
@ -71,12 +66,10 @@ long double asinhl(long double x)
|
||||||
FORCE_EVAL(x + 0x1p120f);
|
FORCE_EVAL(x + 0x1p120f);
|
||||||
}
|
}
|
||||||
return s ? -x : x;
|
return s ? -x : x;
|
||||||
}
|
|
||||||
|
|
||||||
#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384
|
#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384
|
||||||
// TODO: broken implementation to make things compile
|
// TODO: broken implementation to make things compile
|
||||||
long double asinhl(long double x)
|
|
||||||
{
|
|
||||||
return asinh(x);
|
return asinh(x);
|
||||||
}
|
#else
|
||||||
|
#error "architecture unsupported"
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ asm(".ident\t\"\\n\\n\
|
||||||
Musl libc (MIT License)\\n\
|
Musl libc (MIT License)\\n\
|
||||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||||
asm(".include \"libc/disclaimer.inc\"");
|
asm(".include \"libc/disclaimer.inc\"");
|
||||||
/* clang-format off */
|
// clang-format off
|
||||||
|
|
||||||
/* origin: FreeBSD /usr/src/lib/msun/src/e_asinl.c */
|
/* origin: FreeBSD /usr/src/lib/msun/src/e_asinl.c */
|
||||||
/*
|
/*
|
||||||
|
@ -55,11 +55,15 @@ asm(".include \"libc/disclaimer.inc\"");
|
||||||
* Converted to long double by David Schultz <das@FreeBSD.ORG>.
|
* Converted to long double by David Schultz <das@FreeBSD.ORG>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns arc sine of 𝑥.
|
||||||
|
*
|
||||||
|
* @define atan2(𝑥,sqrt((1-𝑥)*(1+𝑥)))
|
||||||
|
* @domain -1 ≤ 𝑥 ≤ 1
|
||||||
|
*/
|
||||||
|
long double asinl(long double x) {
|
||||||
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||||
long double asinl(long double x)
|
|
||||||
{
|
|
||||||
return asin(x);
|
return asin(x);
|
||||||
}
|
|
||||||
#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
|
#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
|
||||||
#if LDBL_MANT_DIG == 64
|
#if LDBL_MANT_DIG == 64
|
||||||
#define CLOSETO1(u) (u.i.m>>56 >= 0xf7)
|
#define CLOSETO1(u) (u.i.m>>56 >= 0xf7)
|
||||||
|
@ -69,14 +73,6 @@ long double asinl(long double x)
|
||||||
#define CLEARBOTTOM(u) (u.i.lo = 0)
|
#define CLEARBOTTOM(u) (u.i.lo = 0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns arc sine of 𝑥.
|
|
||||||
*
|
|
||||||
* @define atan2(𝑥,sqrt((1-𝑥)*(1+𝑥)))
|
|
||||||
* @domain -1 ≤ 𝑥 ≤ 1
|
|
||||||
*/
|
|
||||||
long double asinl(long double x)
|
|
||||||
{
|
|
||||||
union ldshape u = {x};
|
union ldshape u = {x};
|
||||||
long double z, r, s;
|
long double z, r, s;
|
||||||
uint16_t e = u.i.se & 0x7fff;
|
uint16_t e = u.i.se & 0x7fff;
|
||||||
|
@ -111,6 +107,8 @@ long double asinl(long double x)
|
||||||
x = 0.5*pio2_hi-(2*s*r - (pio2_lo-2*c) - (0.5*pio2_hi-2*f));
|
x = 0.5*pio2_hi-(2*s*r - (pio2_lo-2*c) - (0.5*pio2_hi-2*f));
|
||||||
}
|
}
|
||||||
return sign ? -x : x;
|
return sign ? -x : x;
|
||||||
}
|
|
||||||
|
|
||||||
|
#else
|
||||||
|
#error "architecture unsupported"
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ asm(".ident\t\"\\n\\n\
|
||||||
Optimized Routines (MIT License)\\n\
|
Optimized Routines (MIT License)\\n\
|
||||||
Copyright 2022 ARM Limited\"");
|
Copyright 2022 ARM Limited\"");
|
||||||
asm(".include \"libc/disclaimer.inc\"");
|
asm(".include \"libc/disclaimer.inc\"");
|
||||||
/* clang-format off */
|
// clang-format off
|
||||||
|
|
||||||
#define Pi (0x1.921fb6p+1f)
|
#define Pi (0x1.921fb6p+1f)
|
||||||
#define PiOver2 (0x1.921fb6p+0f)
|
#define PiOver2 (0x1.921fb6p+0f)
|
||||||
|
|
|
@ -37,7 +37,7 @@ asm(".ident\t\"\\n\\n\
|
||||||
Musl libc (MIT License)\\n\
|
Musl libc (MIT License)\\n\
|
||||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||||
asm(".include \"libc/disclaimer.inc\"");
|
asm(".include \"libc/disclaimer.inc\"");
|
||||||
/* clang-format off */
|
// clang-format off
|
||||||
|
|
||||||
/* origin: FreeBSD /usr/src/lib/msun/src/e_atan2l.c */
|
/* origin: FreeBSD /usr/src/lib/msun/src/e_atan2l.c */
|
||||||
/*
|
/*
|
||||||
|
@ -56,18 +56,13 @@ asm(".include \"libc/disclaimer.inc\"");
|
||||||
* Converted to long double by David Schultz <das@FreeBSD.ORG>.
|
* Converted to long double by David Schultz <das@FreeBSD.ORG>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
|
||||||
long double atan2l(long double y, long double x)
|
|
||||||
{
|
|
||||||
return atan2(y, x);
|
|
||||||
}
|
|
||||||
#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns arc tangent of 𝑦/𝑥.
|
* Returns arc tangent of 𝑦/𝑥.
|
||||||
*/
|
*/
|
||||||
long double atan2l(long double y, long double x)
|
long double atan2l(long double y, long double x) {
|
||||||
{
|
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||||
|
return atan2(y, x);
|
||||||
|
#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
|
||||||
#ifdef __x86__
|
#ifdef __x86__
|
||||||
|
|
||||||
long double res;
|
long double res;
|
||||||
|
@ -133,7 +128,9 @@ long double atan2l(long double y, long double x)
|
||||||
default: /* case 3 */
|
default: /* case 3 */
|
||||||
return (z-2*pio2_lo)-2*pio2_hi; /* atan(-,-) */
|
return (z-2*pio2_lo)-2*pio2_hi; /* atan(-,-) */
|
||||||
}
|
}
|
||||||
#endif /* __x86__ */
|
|
||||||
}
|
|
||||||
|
|
||||||
|
#endif /* __x86__ */
|
||||||
|
#else
|
||||||
|
#error "architecture unsupported"
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
|
@ -72,4 +72,6 @@ long double atanhl(long double x)
|
||||||
return s ? -x : x;
|
return s ? -x : x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
#error "architecture unsupported"
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -36,7 +36,7 @@ asm(".ident\t\"\\n\\n\
|
||||||
Musl libc (MIT License)\\n\
|
Musl libc (MIT License)\\n\
|
||||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||||
asm(".include \"libc/disclaimer.inc\"");
|
asm(".include \"libc/disclaimer.inc\"");
|
||||||
/* clang-format off */
|
// clang-format off
|
||||||
|
|
||||||
/* origin: FreeBSD /usr/src/lib/msun/src/s_atanl.c */
|
/* origin: FreeBSD /usr/src/lib/msun/src/s_atanl.c */
|
||||||
/*
|
/*
|
||||||
|
@ -231,4 +231,6 @@ long double atanl(long double x)
|
||||||
return sign ? -z : z;
|
return sign ? -z : z;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
#error "architecture unsupported"
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -27,16 +27,14 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/complex.h"
|
#include "libc/complex.h"
|
||||||
#include "libc/math.h"
|
#include "libc/math.h"
|
||||||
#include "libc/tinymath/complex.internal.h"
|
|
||||||
|
|
||||||
asm(".ident\t\"\\n\\n\
|
asm(".ident\t\"\\n\\n\
|
||||||
Musl libc (MIT License)\\n\
|
Musl libc (MIT License)\\n\
|
||||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||||
asm(".include \"libc/disclaimer.inc\"");
|
asm(".include \"libc/disclaimer.inc\"");
|
||||||
/* clang-format off */
|
// clang-format off
|
||||||
|
|
||||||
long double complex cacoshl(long double complex z)
|
long double complex cacoshl(long double complex z) {
|
||||||
{
|
|
||||||
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||||
return cacosh(z);
|
return cacosh(z);
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -26,13 +26,12 @@
|
||||||
│ │
|
│ │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/complex.h"
|
#include "libc/complex.h"
|
||||||
#include "libc/tinymath/complex.internal.h"
|
|
||||||
|
|
||||||
asm(".ident\t\"\\n\\n\
|
asm(".ident\t\"\\n\\n\
|
||||||
Musl libc (MIT License)\\n\
|
Musl libc (MIT License)\\n\
|
||||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||||
asm(".include \"libc/disclaimer.inc\"");
|
asm(".include \"libc/disclaimer.inc\"");
|
||||||
/* clang-format off */
|
// clang-format off
|
||||||
|
|
||||||
long double complex cacosl(long double complex z) {
|
long double complex cacosl(long double complex z) {
|
||||||
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||||
|
|
|
@ -26,26 +26,18 @@
|
||||||
│ │
|
│ │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/complex.h"
|
#include "libc/complex.h"
|
||||||
#include "libc/math.h"
|
|
||||||
#include "libc/tinymath/complex.internal.h"
|
|
||||||
|
|
||||||
asm(".ident\t\"\\n\\n\
|
asm(".ident\t\"\\n\\n\
|
||||||
Musl libc (MIT License)\\n\
|
Musl libc (MIT License)\\n\
|
||||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||||
asm(".include \"libc/disclaimer.inc\"");
|
asm(".include \"libc/disclaimer.inc\"");
|
||||||
/* clang-format off */
|
// clang-format off
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
long double complex casinhl(long double complex z) {
|
||||||
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||||
long double complex casinhl(long double complex z)
|
|
||||||
{
|
|
||||||
return casinh(z);
|
return casinh(z);
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
long double complex casinhl(long double complex z)
|
|
||||||
{
|
|
||||||
z = casinl(CMPLXL(-cimagl(z), creall(z)));
|
z = casinl(CMPLXL(-cimagl(z), creall(z)));
|
||||||
return CMPLXL(cimagl(z), -creall(z));
|
return CMPLXL(cimagl(z), -creall(z));
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
|
@ -26,8 +26,6 @@
|
||||||
│ │
|
│ │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/complex.h"
|
#include "libc/complex.h"
|
||||||
#include "libc/math.h"
|
|
||||||
#include "libc/tinymath/complex.internal.h"
|
|
||||||
|
|
||||||
asm(".ident\t\"\\n\\n\
|
asm(".ident\t\"\\n\\n\
|
||||||
Musl libc (MIT License)\\n\
|
Musl libc (MIT License)\\n\
|
||||||
|
|
|
@ -26,14 +26,12 @@
|
||||||
│ │
|
│ │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/complex.h"
|
#include "libc/complex.h"
|
||||||
#include "libc/math.h"
|
|
||||||
#include "libc/tinymath/complex.internal.h"
|
|
||||||
|
|
||||||
asm(".ident\t\"\\n\\n\
|
asm(".ident\t\"\\n\\n\
|
||||||
Musl libc (MIT License)\\n\
|
Musl libc (MIT License)\\n\
|
||||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||||
asm(".include \"libc/disclaimer.inc\"");
|
asm(".include \"libc/disclaimer.inc\"");
|
||||||
/* clang-format off */
|
// clang-format off
|
||||||
|
|
||||||
long double complex catanhl(long double complex z) {
|
long double complex catanhl(long double complex z) {
|
||||||
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||||
|
|
|
@ -165,4 +165,6 @@ long double cbrtl(long double x)
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
#error "architecture unsupported"
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -36,8 +36,7 @@ asm(".ident\t\"\\n\\n\
|
||||||
Musl libc (MIT License)\\n\
|
Musl libc (MIT License)\\n\
|
||||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||||
asm(".include \"libc/disclaimer.inc\"");
|
asm(".include \"libc/disclaimer.inc\"");
|
||||||
/* clang-format off */
|
// clang-format off
|
||||||
|
|
||||||
|
|
||||||
/* origin: FreeBSD /usr/src/lib/msun/src/s_ccosh.c */
|
/* origin: FreeBSD /usr/src/lib/msun/src/s_ccosh.c */
|
||||||
/*-
|
/*-
|
||||||
|
|
|
@ -26,16 +26,12 @@
|
||||||
│ │
|
│ │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/complex.h"
|
#include "libc/complex.h"
|
||||||
#include "libc/math.h"
|
|
||||||
#include "libc/tinymath/complex.internal.h"
|
|
||||||
|
|
||||||
asm(".ident\t\"\\n\\n\
|
asm(".ident\t\"\\n\\n\
|
||||||
Musl libc (MIT License)\\n\
|
Musl libc (MIT License)\\n\
|
||||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||||
asm(".include \"libc/disclaimer.inc\"");
|
asm(".include \"libc/disclaimer.inc\"");
|
||||||
/* clang-format off */
|
// clang-format off
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//FIXME
|
//FIXME
|
||||||
long double complex ccoshl(long double complex z)
|
long double complex ccoshl(long double complex z)
|
||||||
|
|
|
@ -26,19 +26,14 @@
|
||||||
│ │
|
│ │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/complex.h"
|
#include "libc/complex.h"
|
||||||
#include "libc/math.h"
|
|
||||||
#include "libc/tinymath/complex.internal.h"
|
|
||||||
|
|
||||||
asm(".ident\t\"\\n\\n\
|
asm(".ident\t\"\\n\\n\
|
||||||
Musl libc (MIT License)\\n\
|
Musl libc (MIT License)\\n\
|
||||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||||
asm(".include \"libc/disclaimer.inc\"");
|
asm(".include \"libc/disclaimer.inc\"");
|
||||||
/* clang-format off */
|
// clang-format off
|
||||||
|
|
||||||
|
long double complex ccosl(long double complex z) {
|
||||||
|
|
||||||
long double complex ccosl(long double complex z)
|
|
||||||
{
|
|
||||||
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||||
return ccos(z);
|
return ccos(z);
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -26,7 +26,9 @@
|
||||||
│ │
|
│ │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/math.h"
|
#include "libc/math.h"
|
||||||
|
#include "libc/runtime/fenv.h"
|
||||||
#include "libc/tinymath/internal.h"
|
#include "libc/tinymath/internal.h"
|
||||||
|
#include "third_party/intel/smmintrin.internal.h"
|
||||||
|
|
||||||
asm(".ident\t\"\\n\\n\
|
asm(".ident\t\"\\n\\n\
|
||||||
Musl libc (MIT License)\\n\
|
Musl libc (MIT License)\\n\
|
||||||
|
@ -41,8 +43,35 @@ asm(".include \"libc/disclaimer.inc\"");
|
||||||
#endif
|
#endif
|
||||||
static const double_t toint = 1/EPS;
|
static const double_t toint = 1/EPS;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns smallest integral value not less than 𝑥.
|
||||||
|
*/
|
||||||
double ceil(double x)
|
double ceil(double x)
|
||||||
{
|
{
|
||||||
|
#ifdef __aarch64__
|
||||||
|
|
||||||
|
asm("frintp\t%d0,%d1" : "=w"(x) : "w"(x));
|
||||||
|
return x;
|
||||||
|
|
||||||
|
#elif defined(__powerpc64__) && defined(_ARCH_PWR5X)
|
||||||
|
|
||||||
|
asm("frip\t%0,%1" : "=d"(x) : "d"(x));
|
||||||
|
return x;
|
||||||
|
|
||||||
|
#elif defined(__s390x__) && (defined(__HTM__) || __ARCH__ >= 9)
|
||||||
|
|
||||||
|
asm("fidbra\t%0,6,%1,4" : "=f"(x) : "f"(x));
|
||||||
|
return x;
|
||||||
|
|
||||||
|
#elif defined(__x86_64__) && defined(__SSE4_1__)
|
||||||
|
|
||||||
|
asm("roundsd\t%2,%1,%0"
|
||||||
|
: "=x"(x)
|
||||||
|
: "x"(x), "i"(_MM_FROUND_TO_POS_INF | _MM_FROUND_NO_EXC));
|
||||||
|
return x;
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
union {double f; uint64_t i;} u = {x};
|
union {double f; uint64_t i;} u = {x};
|
||||||
int e = u.i >> 52 & 0x7ff;
|
int e = u.i >> 52 & 0x7ff;
|
||||||
double_t y;
|
double_t y;
|
||||||
|
@ -62,4 +91,6 @@ double ceil(double x)
|
||||||
if (y < 0)
|
if (y < 0)
|
||||||
return x + y + 1;
|
return x + y + 1;
|
||||||
return x + y;
|
return x + y;
|
||||||
|
|
||||||
|
#endif /* __aarch64__ */
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/math.h"
|
#include "libc/math.h"
|
||||||
#include "libc/tinymath/internal.h"
|
#include "libc/tinymath/internal.h"
|
||||||
|
#include "third_party/intel/smmintrin.internal.h"
|
||||||
|
|
||||||
asm(".ident\t\"\\n\\n\
|
asm(".ident\t\"\\n\\n\
|
||||||
Musl libc (MIT License)\\n\
|
Musl libc (MIT License)\\n\
|
||||||
|
@ -34,8 +35,35 @@ Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||||
asm(".include \"libc/disclaimer.inc\"");
|
asm(".include \"libc/disclaimer.inc\"");
|
||||||
// clang-format off
|
// clang-format off
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns smallest integral value not less than 𝑥.
|
||||||
|
*/
|
||||||
float ceilf(float x)
|
float ceilf(float x)
|
||||||
{
|
{
|
||||||
|
#ifdef __aarch64__
|
||||||
|
|
||||||
|
asm("frintp\t%s0,%s1" : "=w"(x) : "w"(x));
|
||||||
|
return x;
|
||||||
|
|
||||||
|
#elif defined(__powerpc64__) && defined(_ARCH_PWR5X)
|
||||||
|
|
||||||
|
asm("frip\t%0,%1" : "=f"(x) : "f"(x));
|
||||||
|
return x;
|
||||||
|
|
||||||
|
#elif defined(__s390x__) && (defined(__HTM__) || __ARCH__ >= 9)
|
||||||
|
|
||||||
|
asm("fiebra\t%0,6,%1,4" : "=f"(x) : "f"(x));
|
||||||
|
return x;
|
||||||
|
|
||||||
|
#elif defined(__x86_64__) && defined(__SSE4_1__)
|
||||||
|
|
||||||
|
asm("roundss\t%2,%1,%0"
|
||||||
|
: "=x"(x)
|
||||||
|
: "x"(x), "i"(_MM_FROUND_TO_POS_INF | _MM_FROUND_NO_EXC));
|
||||||
|
return x;
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
union {float f; uint32_t i;} u = {x};
|
union {float f; uint32_t i;} u = {x};
|
||||||
int e = (int)(u.i >> 23 & 0xff) - 0x7f;
|
int e = (int)(u.i >> 23 & 0xff) - 0x7f;
|
||||||
uint32_t m;
|
uint32_t m;
|
||||||
|
@ -58,4 +86,6 @@ float ceilf(float x)
|
||||||
u.f = 1.0;
|
u.f = 1.0;
|
||||||
}
|
}
|
||||||
return u.f;
|
return u.f;
|
||||||
|
|
||||||
|
#endif /* __aarch64__ */
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,9 @@ Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||||
asm(".include \"libc/disclaimer.inc\"");
|
asm(".include \"libc/disclaimer.inc\"");
|
||||||
// clang-format off
|
// clang-format off
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns smallest integral value not less than 𝑥.
|
||||||
|
*/
|
||||||
long double ceill(long double x) {
|
long double ceill(long double x) {
|
||||||
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||||
return ceil(x);
|
return ceil(x);
|
||||||
|
@ -43,7 +46,6 @@ long double ceill(long double x) {
|
||||||
union ldshape u = {x};
|
union ldshape u = {x};
|
||||||
int e = u.i.se & 0x7fff;
|
int e = u.i.se & 0x7fff;
|
||||||
long double y;
|
long double y;
|
||||||
|
|
||||||
if (e >= 0x3fff+LDBL_MANT_DIG-1 || x == 0)
|
if (e >= 0x3fff+LDBL_MANT_DIG-1 || x == 0)
|
||||||
return x;
|
return x;
|
||||||
/* y = int(x) - x, where int(x) is an integer neighbor of x */
|
/* y = int(x) - x, where int(x) is an integer neighbor of x */
|
||||||
|
@ -59,5 +61,7 @@ long double ceill(long double x) {
|
||||||
if (y < 0)
|
if (y < 0)
|
||||||
return x + y + 1;
|
return x + y + 1;
|
||||||
return x + y;
|
return x + y;
|
||||||
|
#else
|
||||||
|
#error "architecture unsupported"
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,16 +26,12 @@
|
||||||
│ │
|
│ │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/complex.h"
|
#include "libc/complex.h"
|
||||||
#include "libc/math.h"
|
|
||||||
#include "libc/tinymath/complex.internal.h"
|
|
||||||
|
|
||||||
asm(".ident\t\"\\n\\n\
|
asm(".ident\t\"\\n\\n\
|
||||||
Musl libc (MIT License)\\n\
|
Musl libc (MIT License)\\n\
|
||||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||||
asm(".include \"libc/disclaimer.inc\"");
|
asm(".include \"libc/disclaimer.inc\"");
|
||||||
/* clang-format off */
|
// clang-format off
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//FIXME
|
//FIXME
|
||||||
long double complex cexpl(long double complex z)
|
long double complex cexpl(long double complex z)
|
||||||
|
|
|
@ -33,9 +33,7 @@ asm(".ident\t\"\\n\\n\
|
||||||
Musl libc (MIT License)\\n\
|
Musl libc (MIT License)\\n\
|
||||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||||
asm(".include \"libc/disclaimer.inc\"");
|
asm(".include \"libc/disclaimer.inc\"");
|
||||||
/* clang-format off */
|
// clang-format off
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||||
long double complex clogl(long double complex z)
|
long double complex clogl(long double complex z)
|
||||||
|
@ -47,7 +45,6 @@ long double complex clogl(long double complex z)
|
||||||
long double complex clogl(long double complex z)
|
long double complex clogl(long double complex z)
|
||||||
{
|
{
|
||||||
long double r, phi;
|
long double r, phi;
|
||||||
|
|
||||||
r = cabsl(z);
|
r = cabsl(z);
|
||||||
phi = cargl(z);
|
phi = cargl(z);
|
||||||
return CMPLXL(logl(r), phi);
|
return CMPLXL(logl(r), phi);
|
||||||
|
|
|
@ -30,5 +30,7 @@ long double copysignl(long double x, long double y) {
|
||||||
ux.i.se &= 0x7fff;
|
ux.i.se &= 0x7fff;
|
||||||
ux.i.se |= uy.i.se & 0x8000;
|
ux.i.se |= uy.i.se & 0x8000;
|
||||||
return ux.f;
|
return ux.f;
|
||||||
|
#else
|
||||||
|
#error "architecture unsupported"
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,5 +79,7 @@ long double coshl(long double x) {
|
||||||
#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384
|
#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384
|
||||||
// TODO: broken implementation to make things compile
|
// TODO: broken implementation to make things compile
|
||||||
return cosh(x);
|
return cosh(x);
|
||||||
|
#else
|
||||||
|
#error "architecture unsupported"
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,5 +68,7 @@ long double cosl(long double x) {
|
||||||
default:
|
default:
|
||||||
return __sinl(hi, lo, 1);
|
return __sinl(hi, lo, 1);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
#error "architecture unsupported"
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,16 +26,12 @@
|
||||||
│ │
|
│ │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/complex.h"
|
#include "libc/complex.h"
|
||||||
#include "libc/math.h"
|
|
||||||
#include "libc/tinymath/complex.internal.h"
|
|
||||||
|
|
||||||
asm(".ident\t\"\\n\\n\
|
asm(".ident\t\"\\n\\n\
|
||||||
Musl libc (MIT License)\\n\
|
Musl libc (MIT License)\\n\
|
||||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||||
asm(".include \"libc/disclaimer.inc\"");
|
asm(".include \"libc/disclaimer.inc\"");
|
||||||
/* clang-format off */
|
// clang-format off
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||||
long double complex cpowl(long double complex z, long double complex c)
|
long double complex cpowl(long double complex z, long double complex c)
|
||||||
|
|
|
@ -36,8 +36,7 @@ asm(".ident\t\"\\n\\n\
|
||||||
Musl libc (MIT License)\\n\
|
Musl libc (MIT License)\\n\
|
||||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||||
asm(".include \"libc/disclaimer.inc\"");
|
asm(".include \"libc/disclaimer.inc\"");
|
||||||
/* clang-format off */
|
// clang-format off
|
||||||
|
|
||||||
|
|
||||||
/* origin: FreeBSD /usr/src/lib/msun/src/s_csinhf.c */
|
/* origin: FreeBSD /usr/src/lib/msun/src/s_csinhf.c */
|
||||||
/*-
|
/*-
|
||||||
|
|
|
@ -26,16 +26,12 @@
|
||||||
│ │
|
│ │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/complex.h"
|
#include "libc/complex.h"
|
||||||
#include "libc/math.h"
|
|
||||||
#include "libc/tinymath/complex.internal.h"
|
|
||||||
|
|
||||||
asm(".ident\t\"\\n\\n\
|
asm(".ident\t\"\\n\\n\
|
||||||
Musl libc (MIT License)\\n\
|
Musl libc (MIT License)\\n\
|
||||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||||
asm(".include \"libc/disclaimer.inc\"");
|
asm(".include \"libc/disclaimer.inc\"");
|
||||||
/* clang-format off */
|
// clang-format off
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//FIXME
|
//FIXME
|
||||||
long double complex csinhl(long double complex z)
|
long double complex csinhl(long double complex z)
|
||||||
|
|
|
@ -26,16 +26,12 @@
|
||||||
│ │
|
│ │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/complex.h"
|
#include "libc/complex.h"
|
||||||
#include "libc/math.h"
|
|
||||||
#include "libc/tinymath/complex.internal.h"
|
|
||||||
|
|
||||||
asm(".ident\t\"\\n\\n\
|
asm(".ident\t\"\\n\\n\
|
||||||
Musl libc (MIT License)\\n\
|
Musl libc (MIT License)\\n\
|
||||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||||
asm(".include \"libc/disclaimer.inc\"");
|
asm(".include \"libc/disclaimer.inc\"");
|
||||||
/* clang-format off */
|
// clang-format off
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||||
long double complex csinl(long double complex z)
|
long double complex csinl(long double complex z)
|
||||||
|
|
|
@ -26,16 +26,12 @@
|
||||||
│ │
|
│ │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/complex.h"
|
#include "libc/complex.h"
|
||||||
#include "libc/math.h"
|
|
||||||
#include "libc/tinymath/complex.internal.h"
|
|
||||||
|
|
||||||
asm(".ident\t\"\\n\\n\
|
asm(".ident\t\"\\n\\n\
|
||||||
Musl libc (MIT License)\\n\
|
Musl libc (MIT License)\\n\
|
||||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||||
asm(".include \"libc/disclaimer.inc\"");
|
asm(".include \"libc/disclaimer.inc\"");
|
||||||
/* clang-format off */
|
// clang-format off
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//FIXME
|
//FIXME
|
||||||
long double complex csqrtl(long double complex z)
|
long double complex csqrtl(long double complex z)
|
||||||
|
|
|
@ -26,16 +26,12 @@
|
||||||
│ │
|
│ │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/complex.h"
|
#include "libc/complex.h"
|
||||||
#include "libc/math.h"
|
|
||||||
#include "libc/tinymath/complex.internal.h"
|
|
||||||
|
|
||||||
asm(".ident\t\"\\n\\n\
|
asm(".ident\t\"\\n\\n\
|
||||||
Musl libc (MIT License)\\n\
|
Musl libc (MIT License)\\n\
|
||||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||||
asm(".include \"libc/disclaimer.inc\"");
|
asm(".include \"libc/disclaimer.inc\"");
|
||||||
/* clang-format off */
|
// clang-format off
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//FIXME
|
//FIXME
|
||||||
long double complex ctanhl(long double complex z)
|
long double complex ctanhl(long double complex z)
|
||||||
|
|
|
@ -26,8 +26,6 @@
|
||||||
│ │
|
│ │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/complex.h"
|
#include "libc/complex.h"
|
||||||
#include "libc/math.h"
|
|
||||||
#include "libc/tinymath/complex.internal.h"
|
|
||||||
|
|
||||||
asm(".ident\t\"\\n\\n\
|
asm(".ident\t\"\\n\\n\
|
||||||
Musl libc (MIT License)\\n\
|
Musl libc (MIT License)\\n\
|
||||||
|
@ -35,8 +33,6 @@ Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||||
asm(".include \"libc/disclaimer.inc\"");
|
asm(".include \"libc/disclaimer.inc\"");
|
||||||
/* clang-format off */
|
/* clang-format off */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||||
long double complex ctanl(long double complex z)
|
long double complex ctanl(long double complex z)
|
||||||
{
|
{
|
||||||
|
|
|
@ -53,5 +53,7 @@ long double exp10l(long double x) {
|
||||||
return y * p10[(int)n+15];
|
return y * p10[(int)n+15];
|
||||||
}
|
}
|
||||||
return powl(10.0, x);
|
return powl(10.0, x);
|
||||||
|
#else
|
||||||
|
#error "architecture unsupported"
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,8 +30,8 @@
|
||||||
#include "libc/tinymath/ldshape.internal.h"
|
#include "libc/tinymath/ldshape.internal.h"
|
||||||
|
|
||||||
asm(".ident\t\"\\n\\n\
|
asm(".ident\t\"\\n\\n\
|
||||||
exp2l (BSD-2 License)\\n\
|
FreeBSD libm (BSD-2 License)\\n\
|
||||||
Copyright (c) 2005-2008 David Schultz <das@FreeBSD.ORG>\"");
|
Copyright (c) 2005-2011, Bruce D. Evans, Steven G. Kargl, David Schultz.\"");
|
||||||
asm(".ident\t\"\\n\\n\
|
asm(".ident\t\"\\n\\n\
|
||||||
Musl libc (MIT License)\\n\
|
Musl libc (MIT License)\\n\
|
||||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||||
|
@ -654,4 +654,6 @@ exp2l(long double x)
|
||||||
|
|
||||||
return scalbnl(r, k.i);
|
return scalbnl(r, k.i);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
#error "architecture unsupported"
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -162,4 +162,6 @@ long double expl(long double x)
|
||||||
{
|
{
|
||||||
return exp(x);
|
return exp(x);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
#error "architecture unsupported"
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -157,4 +157,6 @@ long double expm1l(long double x)
|
||||||
{
|
{
|
||||||
return expm1(x);
|
return expm1(x);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
#error "architecture unsupported"
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,41 +0,0 @@
|
||||||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
|
||||||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
|
||||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
|
||||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
|
||||||
│ │
|
|
||||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
|
||||||
│ any purpose with or without fee is hereby granted, provided that the │
|
|
||||||
│ above copyright notice and this permission notice appear in all copies. │
|
|
||||||
│ │
|
|
||||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
|
||||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
|
||||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
|
||||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
|
||||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
|
||||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
|
||||||
#include "libc/macros.internal.h"
|
|
||||||
|
|
||||||
// Thunks float(*fn)(float,float) -> long double fn.
|
|
||||||
//
|
|
||||||
// @param %xmm0[0] contains float param
|
|
||||||
// @return %xmm0[0] contains float result
|
|
||||||
// @note 100% negligible overhead
|
|
||||||
_f2ld2: push %rbp
|
|
||||||
mov %rsp,%rbp
|
|
||||||
.profilable
|
|
||||||
sub $32,%rsp
|
|
||||||
movss %xmm0,-32(%rbp)
|
|
||||||
flds -32(%rbp)
|
|
||||||
fstpt -32(%rbp)
|
|
||||||
movsd %xmm1,-16(%rbp)
|
|
||||||
flds -16(%rbp)
|
|
||||||
fstpt -16(%rbp)
|
|
||||||
call *%rax
|
|
||||||
fstps -16(%rbp)
|
|
||||||
movss -16(%rbp),%xmm0
|
|
||||||
leave
|
|
||||||
ret
|
|
||||||
.endfn _f2ld2,globl,hidden
|
|
|
@ -18,6 +18,9 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/math.h"
|
#include "libc/math.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns absolute value of floating point number.
|
||||||
|
*/
|
||||||
double fabs(double x) {
|
double fabs(double x) {
|
||||||
union {
|
union {
|
||||||
double f;
|
double f;
|
||||||
|
|
|
@ -18,6 +18,9 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "third_party/libcxx/math.h"
|
#include "third_party/libcxx/math.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns absolute value of floating point number.
|
||||||
|
*/
|
||||||
float fabsf(float x) {
|
float fabsf(float x) {
|
||||||
union {
|
union {
|
||||||
float f;
|
float f;
|
||||||
|
|
|
@ -19,6 +19,9 @@
|
||||||
#include "libc/math.h"
|
#include "libc/math.h"
|
||||||
#include "libc/tinymath/ldshape.internal.h"
|
#include "libc/tinymath/ldshape.internal.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns absolute value of floating point number.
|
||||||
|
*/
|
||||||
long double fabsl(long double x) {
|
long double fabsl(long double x) {
|
||||||
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||||
return fabs(x);
|
return fabs(x);
|
||||||
|
@ -26,5 +29,7 @@ long double fabsl(long double x) {
|
||||||
union ldshape u = {x};
|
union ldshape u = {x};
|
||||||
u.i.se &= 0x7fff;
|
u.i.se &= 0x7fff;
|
||||||
return u.f;
|
return u.f;
|
||||||
|
#else
|
||||||
|
#error "architecture unsupported"
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,9 @@
|
||||||
│ │
|
│ │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/math.h"
|
#include "libc/math.h"
|
||||||
|
#include "libc/runtime/fenv.h"
|
||||||
#include "libc/tinymath/internal.h"
|
#include "libc/tinymath/internal.h"
|
||||||
|
#include "third_party/intel/smmintrin.internal.h"
|
||||||
|
|
||||||
asm(".ident\t\"\\n\\n\
|
asm(".ident\t\"\\n\\n\
|
||||||
Musl libc (MIT License)\\n\
|
Musl libc (MIT License)\\n\
|
||||||
|
@ -41,8 +43,35 @@ asm(".include \"libc/disclaimer.inc\"");
|
||||||
#endif
|
#endif
|
||||||
static const double_t toint = 1/EPS;
|
static const double_t toint = 1/EPS;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns largest integral value not greater than 𝑥.
|
||||||
|
*/
|
||||||
double floor(double x)
|
double floor(double x)
|
||||||
{
|
{
|
||||||
|
#ifdef __aarch64__
|
||||||
|
|
||||||
|
asm("frintm\t%d0,%d1" : "=w"(x) : "w"(x));
|
||||||
|
return x;
|
||||||
|
|
||||||
|
#elif defined(__powerpc64__) && defined(_ARCH_PWR5X)
|
||||||
|
|
||||||
|
asm("frim\t%0,%1" : "=d"(x) : "d"(x));
|
||||||
|
return x;
|
||||||
|
|
||||||
|
#elif defined(__s390x__) && (defined(__HTM__) || __ARCH__ >= 9)
|
||||||
|
|
||||||
|
asm("fidbra\t%0,7,%1,4" : "=f"(x) : "f"(x));
|
||||||
|
return x;
|
||||||
|
|
||||||
|
#elif defined(__x86_64__) && defined(__SSE4_1__)
|
||||||
|
|
||||||
|
asm("roundsd\t%2,%1,%0"
|
||||||
|
: "=x"(x)
|
||||||
|
: "x"(x), "i"(_MM_FROUND_TO_NEG_INF | _MM_FROUND_NO_EXC));
|
||||||
|
return x;
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
union {double f; uint64_t i;} u = {x};
|
union {double f; uint64_t i;} u = {x};
|
||||||
int e = u.i >> 52 & 0x7ff;
|
int e = u.i >> 52 & 0x7ff;
|
||||||
double_t y;
|
double_t y;
|
||||||
|
@ -62,4 +91,6 @@ double floor(double x)
|
||||||
if (y > 0)
|
if (y > 0)
|
||||||
return x + y - 1;
|
return x + y - 1;
|
||||||
return x + y;
|
return x + y;
|
||||||
|
|
||||||
|
#endif /* __aarch64__ */
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
│ │
|
│ │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/tinymath/internal.h"
|
#include "libc/tinymath/internal.h"
|
||||||
|
#include "third_party/intel/smmintrin.internal.h"
|
||||||
#include "third_party/libcxx/math.h"
|
#include "third_party/libcxx/math.h"
|
||||||
|
|
||||||
asm(".ident\t\"\\n\\n\
|
asm(".ident\t\"\\n\\n\
|
||||||
|
@ -34,8 +35,35 @@ Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||||
asm(".include \"libc/disclaimer.inc\"");
|
asm(".include \"libc/disclaimer.inc\"");
|
||||||
// clang-format off
|
// clang-format off
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns largest integral value not greater than 𝑥.
|
||||||
|
*/
|
||||||
float floorf(float x)
|
float floorf(float x)
|
||||||
{
|
{
|
||||||
|
#ifdef __aarch64__
|
||||||
|
|
||||||
|
asm("frintm\t%s0,%s1" : "=w"(x) : "w"(x));
|
||||||
|
return x;
|
||||||
|
|
||||||
|
#elif defined(__powerpc64__) && defined(_ARCH_PWR5X)
|
||||||
|
|
||||||
|
asm("frim\t%0,%1" : "=f"(x) : "f"(x));
|
||||||
|
return x;
|
||||||
|
|
||||||
|
#elif defined(__s390x__) && (defined(__HTM__) || __ARCH__ >= 9)
|
||||||
|
|
||||||
|
asm("fiebra\t%0,7,%1,4" : "=f"(x) : "f"(x));
|
||||||
|
return x;
|
||||||
|
|
||||||
|
#elif defined(__x86_64__) && defined(__SSE4_1__)
|
||||||
|
|
||||||
|
asm("roundss\t%2,%1,%0"
|
||||||
|
: "=x"(x)
|
||||||
|
: "x"(x), "i"(_MM_FROUND_TO_NEG_INF | _MM_FROUND_NO_EXC));
|
||||||
|
return x;
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
union {float f; uint32_t i;} u = {x};
|
union {float f; uint32_t i;} u = {x};
|
||||||
int e = (int)(u.i >> 23 & 0xff) - 0x7f;
|
int e = (int)(u.i >> 23 & 0xff) - 0x7f;
|
||||||
uint32_t m;
|
uint32_t m;
|
||||||
|
@ -58,4 +86,6 @@ float floorf(float x)
|
||||||
u.f = -1.0;
|
u.f = -1.0;
|
||||||
}
|
}
|
||||||
return u.f;
|
return u.f;
|
||||||
|
|
||||||
|
#endif /* __aarch64__ */
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,9 @@ Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||||
asm(".include \"libc/disclaimer.inc\"");
|
asm(".include \"libc/disclaimer.inc\"");
|
||||||
// clang-format off
|
// clang-format off
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns largest integral value not greater than 𝑥.
|
||||||
|
*/
|
||||||
long double floorl(long double x) {
|
long double floorl(long double x) {
|
||||||
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||||
return floor(x);
|
return floor(x);
|
||||||
|
@ -60,5 +63,7 @@ long double floorl(long double x) {
|
||||||
if (y > 0)
|
if (y > 0)
|
||||||
return x + y - 1;
|
return x + y - 1;
|
||||||
return x + y;
|
return x + y;
|
||||||
|
#else
|
||||||
|
#error "architecture unsupported"
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,13 +31,17 @@ asm(".ident\t\"\\n\\n\
|
||||||
Musl libc (MIT License)\\n\
|
Musl libc (MIT License)\\n\
|
||||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||||
asm(".include \"libc/disclaimer.inc\"");
|
asm(".include \"libc/disclaimer.inc\"");
|
||||||
/* clang-format off */
|
// clang-format off
|
||||||
|
|
||||||
#define ASUINT64(x) ((union {double f; uint64_t i;}){x}).i
|
#define ASUINT64(x) ((union {double f; uint64_t i;}){x}).i
|
||||||
#define ZEROINFNAN (0x7ff-0x3ff-52-1)
|
#define ZEROINFNAN (0x7ff-0x3ff-52-1)
|
||||||
|
|
||||||
static inline int a_clz_64(uint64_t x)
|
static inline int a_clz_64(uint64_t x)
|
||||||
{
|
{
|
||||||
|
#ifdef __GNUC__
|
||||||
|
if (!x) return 63;
|
||||||
|
return __builtin_clzll(x);
|
||||||
|
#else
|
||||||
uint32_t y;
|
uint32_t y;
|
||||||
int r;
|
int r;
|
||||||
if (x>>32) y=x>>32, r=0; else y=x, r=32;
|
if (x>>32) y=x>>32, r=0; else y=x, r=32;
|
||||||
|
@ -46,6 +50,7 @@ static inline int a_clz_64(uint64_t x)
|
||||||
if (y>>4) y>>=4; else r |= 4;
|
if (y>>4) y>>=4; else r |= 4;
|
||||||
if (y>>2) y>>=2; else r |= 2;
|
if (y>>2) y>>=2; else r |= 2;
|
||||||
return r | !(y>>1);
|
return r | !(y>>1);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
struct num { uint64_t m; int e; int sign; };
|
struct num { uint64_t m; int e; int sign; };
|
||||||
|
@ -73,7 +78,6 @@ static void mul(uint64_t *hi, uint64_t *lo, uint64_t x, uint64_t y)
|
||||||
uint64_t t1,t2,t3;
|
uint64_t t1,t2,t3;
|
||||||
uint64_t xlo = (uint32_t)x, xhi = x>>32;
|
uint64_t xlo = (uint32_t)x, xhi = x>>32;
|
||||||
uint64_t ylo = (uint32_t)y, yhi = y>>32;
|
uint64_t ylo = (uint32_t)y, yhi = y>>32;
|
||||||
|
|
||||||
t1 = xlo*ylo;
|
t1 = xlo*ylo;
|
||||||
t2 = xlo*yhi + xhi*ylo;
|
t2 = xlo*yhi + xhi*ylo;
|
||||||
t3 = xhi*yhi;
|
t3 = xhi*yhi;
|
||||||
|
@ -81,8 +85,48 @@ static void mul(uint64_t *hi, uint64_t *lo, uint64_t x, uint64_t y)
|
||||||
*hi = t3 + (t2>>32) + (t1 > *lo);
|
*hi = t3 + (t2>>32) + (t1 > *lo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs fused multiply add.
|
||||||
|
*
|
||||||
|
* @return `𝑥 * 𝑦 + 𝑧` rounded as one ternary operation
|
||||||
|
*/
|
||||||
double fma(double x, double y, double z)
|
double fma(double x, double y, double z)
|
||||||
{
|
{
|
||||||
|
#if defined(__x86_64__) && defined(__FMA__)
|
||||||
|
|
||||||
|
// Intel Haswell+ (c. 2013)
|
||||||
|
// AMD Piledriver+ (c. 2011)
|
||||||
|
asm("vfmadd132sd\t%1,%2,%0" : "+x"(x) : "x"(y), "x"(z));
|
||||||
|
return x;
|
||||||
|
|
||||||
|
#elif defined(__x86_64__) && defined(__FMA4__)
|
||||||
|
|
||||||
|
// AMD Bulldozer+ (c. 2011)
|
||||||
|
asm("vfmaddsd\t%3,%2,%1,%0" : "=x"(x) : "x"(x), "x"(y), "x"(z));
|
||||||
|
return x;
|
||||||
|
|
||||||
|
#elif defined(__aarch64__)
|
||||||
|
|
||||||
|
asm("fmadd\t%d0,%d1,%d2,%d3" : "=w"(x) : "w"(x), "w"(y), "w"(z));
|
||||||
|
return x;
|
||||||
|
|
||||||
|
#elif defined(__powerpc64__)
|
||||||
|
|
||||||
|
asm("fmadd\t%0,%1,%2,%3" : "=d"(x) : "d"(x), "d"(y), "d"(z));
|
||||||
|
return x;
|
||||||
|
|
||||||
|
#elif defined(__riscv) && __riscv_flen >= 64
|
||||||
|
|
||||||
|
asm("fmadd.d\t%0,%1,%2,%3" : "=f"(x) : "f"(x), "f"(y), "f"(z));
|
||||||
|
return x;
|
||||||
|
|
||||||
|
#elif defined(__s390x__)
|
||||||
|
|
||||||
|
asm("madbr\t%0,\t%1,\t%2" : "+f"(z) : "f"(x), "f"(y));
|
||||||
|
return z;
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
/* normalize so top 10bits and last bit are 0 */
|
/* normalize so top 10bits and last bit are 0 */
|
||||||
struct num nx, ny, nz;
|
struct num nx, ny, nz;
|
||||||
nx = normalize(x);
|
nx = normalize(x);
|
||||||
|
@ -220,4 +264,6 @@ double fma(double x, double y, double z)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return scalbn(r, e);
|
return scalbn(r, e);
|
||||||
|
|
||||||
|
#endif /* __x86_64__ */
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ asm(".ident\t\"\\n\\n\
|
||||||
Musl libc (MIT License)\\n\
|
Musl libc (MIT License)\\n\
|
||||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||||
asm(".include \"libc/disclaimer.inc\"");
|
asm(".include \"libc/disclaimer.inc\"");
|
||||||
/* clang-format off */
|
// clang-format off
|
||||||
|
|
||||||
/* origin: FreeBSD /usr/src/lib/msun/src/s_fmaf.c */
|
/* origin: FreeBSD /usr/src/lib/msun/src/s_fmaf.c */
|
||||||
/*-
|
/*-
|
||||||
|
@ -64,16 +64,53 @@ asm(".include \"libc/disclaimer.inc\"");
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Fused multiply-add: Compute x * y + z with a single rounding error.
|
* Performs fused multiply add.
|
||||||
*
|
*
|
||||||
* A double has more than twice as much precision than a float, so
|
* @return `𝑥 * 𝑦 + 𝑧` with a single rounding error
|
||||||
* direct double-precision arithmetic suffices, except where double
|
|
||||||
* rounding occurs.
|
|
||||||
*/
|
*/
|
||||||
float fmaf(float x, float y, float z)
|
float fmaf(float x, float y, float z)
|
||||||
{
|
{
|
||||||
// #pragma STDC FENV_ACCESS ON
|
#if defined(__x86_64__) && defined(__FMA__)
|
||||||
|
|
||||||
|
// Intel Haswell+ (c. 2013)
|
||||||
|
// AMD Piledriver+ (c. 2011)
|
||||||
|
asm("vfmadd132ss\t%1,%2,%0" : "+x"(x) : "x"(y), "x"(z));
|
||||||
|
return x;
|
||||||
|
|
||||||
|
#elif defined(__x86_64__) && defined(__FMA4__)
|
||||||
|
|
||||||
|
// AMD Bulldozer+ (c. 2011)
|
||||||
|
asm("vfmaddss\t%3,%2,%1,%0" : "=x"(x) : "x"(x), "x"(y), "x"(z));
|
||||||
|
return x;
|
||||||
|
|
||||||
|
#elif defined(__aarch64__)
|
||||||
|
|
||||||
|
asm("fmadd\t%s0,%s1,%s2,%s3" : "=w"(x) : "w"(x), "w"(y), "w"(z));
|
||||||
|
return x;
|
||||||
|
|
||||||
|
#elif defined(__powerpc64__)
|
||||||
|
|
||||||
|
asm("fmadds\t%0,%1,%2,%3" : "=f"(x) : "f"(x), "f"(y), "f"(z));
|
||||||
|
return x;
|
||||||
|
|
||||||
|
#elif defined(__riscv) && __riscv_flen >= 32
|
||||||
|
|
||||||
|
asm("fmadd.s\t%0,%1,%2,%3" : "=f"(x) : "f"(x), "f"(y), "f"(z));
|
||||||
|
return x;
|
||||||
|
|
||||||
|
#elif defined(__s390x__)
|
||||||
|
|
||||||
|
asm("maebr\t%0,%1,%2" : "+f"(z) : "f"(x), "f"(y));
|
||||||
|
return z;
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
/* A double has more than twice as much precision than a float,
|
||||||
|
so direct double-precision arithmetic suffices, except where
|
||||||
|
double rounding occurs. */
|
||||||
|
|
||||||
|
/* #pragma STDC FENV_ACCESS ON */
|
||||||
double xy, result;
|
double xy, result;
|
||||||
union {double f; uint64_t i;} u;
|
union {double f; uint64_t i;} u;
|
||||||
int e;
|
int e;
|
||||||
|
@ -124,4 +161,6 @@ float fmaf(float x, float y, float z)
|
||||||
u.i--;
|
u.i--;
|
||||||
z = u.f;
|
z = u.f;
|
||||||
return z;
|
return z;
|
||||||
|
|
||||||
|
#endif /* __x86_64__ */
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,5 +131,7 @@ long double fmodl(long double x, long double y) {
|
||||||
} else
|
} else
|
||||||
ux.i.se = ex|sx;
|
ux.i.se = ex|sx;
|
||||||
return ux.f;
|
return ux.f;
|
||||||
|
#else
|
||||||
|
#error "architecture unsupported"
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,8 +37,7 @@ asm(".include \"libc/disclaimer.inc\"");
|
||||||
/**
|
/**
|
||||||
* Splits number normalized fraction and exponent.
|
* Splits number normalized fraction and exponent.
|
||||||
*/
|
*/
|
||||||
long double frexpl(long double x, int *e)
|
long double frexpl(long double x, int *e) {
|
||||||
{
|
|
||||||
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||||
return frexp(x, e);
|
return frexp(x, e);
|
||||||
#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
|
#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
|
||||||
|
@ -59,5 +58,7 @@ long double frexpl(long double x, int *e)
|
||||||
u.i.se &= 0x8000;
|
u.i.se &= 0x8000;
|
||||||
u.i.se |= 0x3ffe;
|
u.i.se |= 0x3ffe;
|
||||||
return u.f;
|
return u.f;
|
||||||
|
#else
|
||||||
|
#error "architecture unsupported"
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,4 +97,6 @@ long double hypotl(long double x, long double y)
|
||||||
sq(&hy, &ly, y);
|
sq(&hy, &ly, y);
|
||||||
return z*sqrtl(ly+lx+hy+hx);
|
return z*sqrtl(ly+lx+hy+hx);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
#error "architecture unsupported"
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -82,6 +82,8 @@ int ilogbl(long double x) {
|
||||||
return u.f ? FP_ILOGBNAN : INT_MAX;
|
return u.f ? FP_ILOGBNAN : INT_MAX;
|
||||||
}
|
}
|
||||||
return e - 0x3fff;
|
return e - 0x3fff;
|
||||||
|
#else
|
||||||
|
#error "architecture unsupported"
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -180,4 +180,6 @@ long double __tanl(long double x, long double y, int odd) {
|
||||||
s = 1.0 + t * z;
|
s = 1.0 + t * z;
|
||||||
return t + a * (s + t * v);
|
return t + a * (s + t * v);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
#error "architecture unsupported"
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||||
│ Copyright 2022 Justine Alexandra Roberts Tunney │
|
│ Copyright 2023 Justine Alexandra Roberts Tunney │
|
||||||
│ │
|
│ │
|
||||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||||
│ any purpose with or without fee is hereby granted, provided that the │
|
│ any purpose with or without fee is hereby granted, provided that the │
|
||||||
|
@ -16,26 +16,21 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/fmt/nf32.h"
|
#include "libc/tinymath/tinymath.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encodes u32 as ANSI Nf sequence content.
|
* Rounds to nearest integer.
|
||||||
*/
|
*/
|
||||||
char *EncodeNf32(char p[hasatleast 12], uint32_t x) {
|
long long llrint(double x) {
|
||||||
char t;
|
long long res;
|
||||||
size_t i, a, b;
|
#ifdef __x86_64__
|
||||||
i = 0;
|
asm("cvtsd2si\t%1,%0" : "=r"(res) : "x"(x));
|
||||||
do {
|
#elif defined(__aarch64__)
|
||||||
p[i++] = " ,.-+*#%&$"[x % 10];
|
asm("frintx\t%d1,%d1\n\t"
|
||||||
x = x / 10;
|
"fcvtzs\t%x0,%d1"
|
||||||
} while (x > 0);
|
: "=r"(res), "+w"(x));
|
||||||
p[i] = '\0';
|
#else
|
||||||
if (i) {
|
res = rint(x);
|
||||||
for (a = 0, b = i - 1; a < b; ++a, --b) {
|
#endif /* __x86_64__ */
|
||||||
t = p[a];
|
return res;
|
||||||
p[a] = p[b];
|
|
||||||
p[b] = t;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return p + i;
|
|
||||||
}
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||||
│ Copyright 2022 Justine Alexandra Roberts Tunney │
|
│ Copyright 2023 Justine Alexandra Roberts Tunney │
|
||||||
│ │
|
│ │
|
||||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||||
│ any purpose with or without fee is hereby granted, provided that the │
|
│ any purpose with or without fee is hereby granted, provided that the │
|
||||||
|
@ -16,26 +16,21 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/errno.h"
|
#include "libc/math.h"
|
||||||
#include "libc/fmt/nf32.h"
|
|
||||||
#include "libc/str/str.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decodes u32 from ANSI Nf sequence.
|
* Rounds to nearest integer.
|
||||||
*/
|
*/
|
||||||
uint32_t DecodeNf32(const char *s, char **e) {
|
long long llrintf(float x) {
|
||||||
int diglet;
|
long long res;
|
||||||
uint32_t x;
|
#ifdef __x86_64__
|
||||||
for (x = 0; (diglet = kNfcimal[*s & 255]) != -1; s++) {
|
asm("cvtss2si\t%1,%0" : "=res"(res) : "x"(x));
|
||||||
if (__builtin_mul_overflow(x, 10, &x) ||
|
#elif defined(__aarch64__)
|
||||||
__builtin_add_overflow(x, diglet, &x)) {
|
asm("frintx\t%s1,%s1\n\t"
|
||||||
errno = ERANGE;
|
"fcvtzs\t%x0,%s1"
|
||||||
x = -1;
|
: "=r"(res), "+w"(x));
|
||||||
break;
|
#else
|
||||||
}
|
res = rintf(x);
|
||||||
}
|
#endif /* __x86_64__ */
|
||||||
if (e) {
|
return res;
|
||||||
*e = (char *)s;
|
|
||||||
}
|
|
||||||
return x;
|
|
||||||
}
|
}
|
|
@ -34,7 +34,7 @@ asm(".ident\t\"\\n\\n\
|
||||||
Musl libc (MIT License)\\n\
|
Musl libc (MIT License)\\n\
|
||||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||||
asm(".include \"libc/disclaimer.inc\"");
|
asm(".include \"libc/disclaimer.inc\"");
|
||||||
/* clang-format off */
|
// clang-format off
|
||||||
|
|
||||||
/* origin: FreeBSD /usr/src/lib/msun/src/e_log10f.c */
|
/* origin: FreeBSD /usr/src/lib/msun/src/e_log10f.c */
|
||||||
/*
|
/*
|
||||||
|
@ -62,6 +62,9 @@ Lg2 = 0xccce13.0p-25, /* 0.40000972152 */
|
||||||
Lg3 = 0x91e9ee.0p-25, /* 0.28498786688 */
|
Lg3 = 0x91e9ee.0p-25, /* 0.28498786688 */
|
||||||
Lg4 = 0xf89e26.0p-26; /* 0.24279078841 */
|
Lg4 = 0xf89e26.0p-26; /* 0.24279078841 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculates log₁₀𝑥.
|
||||||
|
*/
|
||||||
float log10f(float x)
|
float log10f(float x)
|
||||||
{
|
{
|
||||||
union {float f; uint32_t i;} u = {x};
|
union {float f; uint32_t i;} u = {x};
|
||||||
|
|
|
@ -35,7 +35,7 @@ asm(".ident\t\"\\n\\n\
|
||||||
Musl libc (MIT License)\\n\
|
Musl libc (MIT License)\\n\
|
||||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||||
asm(".include \"libc/disclaimer.inc\"");
|
asm(".include \"libc/disclaimer.inc\"");
|
||||||
/* clang-format off */
|
// clang-format off
|
||||||
|
|
||||||
/* origin: OpenBSD /usr/src/lib/libm/src/ld80/e_log10l.c */
|
/* origin: OpenBSD /usr/src/lib/libm/src/ld80/e_log10l.c */
|
||||||
/*
|
/*
|
||||||
|
@ -152,8 +152,23 @@ static const long double S[4] = {
|
||||||
|
|
||||||
#define SQRTH 0.70710678118654752440L
|
#define SQRTH 0.70710678118654752440L
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculates log₁₀𝑥.
|
||||||
|
*/
|
||||||
long double log10l(long double x)
|
long double log10l(long double x)
|
||||||
{
|
{
|
||||||
|
#ifdef __x86__
|
||||||
|
|
||||||
|
long double lg2;
|
||||||
|
asm("fldlg2" : "=t"(lg2));
|
||||||
|
asm("fyl2x"
|
||||||
|
: "=t"(x)
|
||||||
|
: "0"(x), "u"(lg2)
|
||||||
|
: "st(1)");
|
||||||
|
return x;
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
long double y, z;
|
long double y, z;
|
||||||
int e;
|
int e;
|
||||||
|
|
||||||
|
@ -218,11 +233,16 @@ done:
|
||||||
z += x * (L10EA);
|
z += x * (L10EA);
|
||||||
z += e * (L102A);
|
z += e * (L102A);
|
||||||
return z;
|
return z;
|
||||||
|
|
||||||
|
#endif /* __x86__ */
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384
|
#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384
|
||||||
// TODO: broken implementation to make things compile
|
// TODO: broken implementation to make things compile
|
||||||
long double log10l(long double x)
|
long double log10l(long double x)
|
||||||
{
|
{
|
||||||
return log10(x);
|
return log10(x);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
#error "architecture unsupported"
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -215,4 +215,6 @@ long double log1pl(long double x)
|
||||||
{
|
{
|
||||||
return log1p(x);
|
return log1p(x);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
#error "architecture unsupported"
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -217,4 +217,6 @@ long double log2l(long double x)
|
||||||
{
|
{
|
||||||
return log2(x);
|
return log2(x);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
#error "architecture unsupported"
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -209,4 +209,6 @@ long double logl(long double x)
|
||||||
{
|
{
|
||||||
return log(x);
|
return log(x);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
#error "architecture unsupported"
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -25,7 +25,9 @@
|
||||||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||||
│ │
|
│ │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
|
#include "libc/limits.h"
|
||||||
#include "libc/math.h"
|
#include "libc/math.h"
|
||||||
|
#include "libc/runtime/fenv.h"
|
||||||
#include "libc/tinymath/expo.internal.h"
|
#include "libc/tinymath/expo.internal.h"
|
||||||
#include "libc/tinymath/feval.internal.h"
|
#include "libc/tinymath/feval.internal.h"
|
||||||
|
|
||||||
|
@ -33,7 +35,7 @@ asm(".ident\t\"\\n\\n\
|
||||||
Musl libc (MIT License)\\n\
|
Musl libc (MIT License)\\n\
|
||||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||||
asm(".include \"libc/disclaimer.inc\"");
|
asm(".include \"libc/disclaimer.inc\"");
|
||||||
/* clang-format off */
|
// clang-format off
|
||||||
|
|
||||||
/*
|
/*
|
||||||
If the result cannot be represented (overflow, nan), then
|
If the result cannot be represented (overflow, nan), then
|
||||||
|
@ -64,15 +66,9 @@ as a double.
|
||||||
#elif FLT_EVAL_METHOD==2
|
#elif FLT_EVAL_METHOD==2
|
||||||
#define EPS LDBL_EPSILON
|
#define EPS LDBL_EPSILON
|
||||||
#endif
|
#endif
|
||||||
#ifdef __GNUC__
|
static dontinline long lrint_slow(double x) {
|
||||||
/* avoid stack frame in lrint */
|
|
||||||
__attribute__((__noinline__))
|
|
||||||
#endif
|
|
||||||
static long lrint_slow(double x)
|
|
||||||
{
|
|
||||||
// #pragma STDC FENV_ACCESS ON
|
// #pragma STDC FENV_ACCESS ON
|
||||||
int e;
|
int e;
|
||||||
|
|
||||||
e = fetestexcept(FE_INEXACT);
|
e = fetestexcept(FE_INEXACT);
|
||||||
x = rint(x);
|
x = rint(x);
|
||||||
if (!e && (x > LONG_MAX || x < LONG_MIN))
|
if (!e && (x > LONG_MAX || x < LONG_MIN))
|
||||||
|
@ -80,12 +76,33 @@ static long lrint_slow(double x)
|
||||||
/* conversion */
|
/* conversion */
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
#define JUST_CALL_RINT
|
||||||
|
#endif
|
||||||
|
|
||||||
long lrint(double x)
|
/**
|
||||||
{
|
* Rounds to nearest integer.
|
||||||
|
*/
|
||||||
|
long lrint(double x) {
|
||||||
|
#ifdef __x86_64__
|
||||||
|
long res;
|
||||||
|
asm("cvtsd2si\t%1,%0" : "=r"(res) : "x"(x));
|
||||||
|
return res;
|
||||||
|
#elif defined(__aarch64__)
|
||||||
|
long res;
|
||||||
|
asm("frintx\t%d1,%d1\n\t"
|
||||||
|
"fcvtzs\t%x0,%d1"
|
||||||
|
: "=r"(res), "+w"(x));
|
||||||
|
return res;
|
||||||
|
#elif defined(__powerpc64__) && defined(_ARCH_PWR5X)
|
||||||
|
long res;
|
||||||
|
asm("fctid\t%0,%1" : "=d"(res) : "d"(x));
|
||||||
|
return res;
|
||||||
|
#elif defined(JUST_CALL_RINT)
|
||||||
|
return rint(x);
|
||||||
|
#else
|
||||||
uint32_t abstop = asuint64(x)>>32 & 0x7fffffff;
|
uint32_t abstop = asuint64(x)>>32 & 0x7fffffff;
|
||||||
uint64_t sign = asuint64(x) & (1ULL << 63);
|
uint64_t sign = asuint64(x) & (1ULL << 63);
|
||||||
|
|
||||||
if (abstop < 0x41dfffff) {
|
if (abstop < 0x41dfffff) {
|
||||||
/* |x| < 0x7ffffc00, no overflow */
|
/* |x| < 0x7ffffc00, no overflow */
|
||||||
double_t toint = asdouble(asuint64(1/EPS) | sign);
|
double_t toint = asdouble(asuint64(1/EPS) | sign);
|
||||||
|
@ -93,10 +110,5 @@ long lrint(double x)
|
||||||
return (long)y;
|
return (long)y;
|
||||||
}
|
}
|
||||||
return lrint_slow(x);
|
return lrint_slow(x);
|
||||||
|
#endif /* __x86_64__ */
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
long lrint(double x)
|
|
||||||
{
|
|
||||||
return rint(x);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -18,6 +18,21 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/math.h"
|
#include "libc/math.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rounds to nearest integer.
|
||||||
|
*/
|
||||||
long lrintf(float x) {
|
long lrintf(float x) {
|
||||||
return rintf(x);
|
long res;
|
||||||
|
#ifdef __x86_64__
|
||||||
|
asm("cvtss2si\t%1,%0" : "=res"(res) : "x"(x));
|
||||||
|
#elif defined(__aarch64__)
|
||||||
|
asm("frintx\t%s1,%s1\n\t"
|
||||||
|
"fcvtzs\t%x0,%s1"
|
||||||
|
: "=r"(res), "+w"(x));
|
||||||
|
#elif defined(__powerpc64__)
|
||||||
|
asm("fctid\t%0,%1" : "=d"(res) : "f"(x));
|
||||||
|
#else
|
||||||
|
res = rintf(x);
|
||||||
|
#endif /* __x86_64__ */
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,9 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/math.h"
|
#include "libc/math.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rounds 𝑥 to nearest integer, away from zero.
|
||||||
|
*/
|
||||||
long lround(double x) {
|
long lround(double x) {
|
||||||
return round(x);
|
return round(x);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,19 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/math.h"
|
#include "libc/math.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rounds 𝑥 to nearest integer, away from zero.
|
||||||
|
*/
|
||||||
long lroundf(float x) {
|
long lroundf(float x) {
|
||||||
return roundf(x);
|
long res;
|
||||||
|
#ifdef __aarch64__
|
||||||
|
asm("fcvtas\t%x0,%s1" : "=r"(res) : "w"(x));
|
||||||
|
#elif defined(__powerpc64__) && defined(__VSX__)
|
||||||
|
asm("xsrdpi\t%1,%1\n\t"
|
||||||
|
"fctid\t%0,%1"
|
||||||
|
: "=d"(res), "+f"(x));
|
||||||
|
#else
|
||||||
|
res = roundf(x);
|
||||||
|
#endif
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,19 @@ asm(".ident\t\"\\n\\n\
|
||||||
Musl libc (MIT License)\\n\
|
Musl libc (MIT License)\\n\
|
||||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||||
asm(".include \"libc/disclaimer.inc\"");
|
asm(".include \"libc/disclaimer.inc\"");
|
||||||
/* clang-format off */
|
// clang-format off
|
||||||
|
|
||||||
|
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||||
|
long double modfl(long double x, long double *iptr)
|
||||||
|
{
|
||||||
|
double d;
|
||||||
|
long double r;
|
||||||
|
|
||||||
|
r = modf(x, &d);
|
||||||
|
*iptr = d;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
|
||||||
|
|
||||||
static const long double toint = 1/LDBL_EPSILON;
|
static const long double toint = 1/LDBL_EPSILON;
|
||||||
|
|
||||||
|
@ -77,3 +89,7 @@ long double modfl(long double x, long double *iptr)
|
||||||
*iptr = x + y;
|
*iptr = x + y;
|
||||||
return -y;
|
return -y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
#error "architecture unsupported"
|
||||||
|
#endif
|
||||||
|
|
|
@ -19,7 +19,15 @@
|
||||||
#include "libc/math.h"
|
#include "libc/math.h"
|
||||||
#include "libc/runtime/fenv.h"
|
#include "libc/runtime/fenv.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rounds to nearest integer.
|
||||||
|
*/
|
||||||
double nearbyint(double x) {
|
double nearbyint(double x) {
|
||||||
|
#ifdef __aarch64__
|
||||||
|
asm("frinti\t%d0,%d1" : "=w"(x) : "w"(x));
|
||||||
|
#elif defined(__s390x__) && (defined(__HTM__) || __ARCH__ >= 9)
|
||||||
|
asm("fidbra\t%0,0,%1,4" : "=f"(x) : "f"(x));
|
||||||
|
#else
|
||||||
#ifdef FE_INEXACT
|
#ifdef FE_INEXACT
|
||||||
// #pragma STDC FENV_ACCESS ON
|
// #pragma STDC FENV_ACCESS ON
|
||||||
int e;
|
int e;
|
||||||
|
@ -29,5 +37,6 @@ double nearbyint(double x) {
|
||||||
#ifdef FE_INEXACT
|
#ifdef FE_INEXACT
|
||||||
if (!e) feclearexcept(FE_INEXACT);
|
if (!e) feclearexcept(FE_INEXACT);
|
||||||
#endif
|
#endif
|
||||||
|
#endif /* __aarch64__ */
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,9 @@
|
||||||
#include "libc/math.h"
|
#include "libc/math.h"
|
||||||
#include "libc/runtime/fenv.h"
|
#include "libc/runtime/fenv.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rounds to nearest integer.
|
||||||
|
*/
|
||||||
float nearbyintf(float x) {
|
float nearbyintf(float x) {
|
||||||
#ifdef FE_INEXACT
|
#ifdef FE_INEXACT
|
||||||
// #pragma STDC FENV_ACCESS ON
|
// #pragma STDC FENV_ACCESS ON
|
||||||
|
|
|
@ -19,6 +19,9 @@
|
||||||
#include "libc/math.h"
|
#include "libc/math.h"
|
||||||
#include "libc/runtime/fenv.h"
|
#include "libc/runtime/fenv.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rounds to nearest integer.
|
||||||
|
*/
|
||||||
long double nearbyintl(long double x) {
|
long double nearbyintl(long double x) {
|
||||||
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||||
return nearbyint(x);
|
return nearbyint(x);
|
||||||
|
|
|
@ -100,5 +100,7 @@ long double nextafterl(long double x, long double y) {
|
||||||
if ((ux.i.se & 0x7fff) == 0)
|
if ((ux.i.se & 0x7fff) == 0)
|
||||||
FORCE_EVAL(x*x + ux.f*ux.f);
|
FORCE_EVAL(x*x + ux.f*ux.f);
|
||||||
return ux.f;
|
return ux.f;
|
||||||
|
#else
|
||||||
|
#error "architecture unsupported"
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,9 @@ long double powl(long double x, long double y) {
|
||||||
if (x) {
|
if (x) {
|
||||||
if (y) {
|
if (y) {
|
||||||
if (x < 0 && y != truncl(y)) {
|
if (x < 0 && y != truncl(y)) {
|
||||||
|
#ifndef __NO_MATH_ERRNO__
|
||||||
errno = EDOM;
|
errno = EDOM;
|
||||||
|
#endif
|
||||||
return NAN;
|
return NAN;
|
||||||
}
|
}
|
||||||
asm("fyl2x" : "=t"(u) : "0"(fabsl(x)), "u"(y) : "st(1)");
|
asm("fyl2x" : "=t"(u) : "0"(fabsl(x)), "u"(y) : "st(1)");
|
||||||
|
@ -57,7 +59,9 @@ long double powl(long double x, long double y) {
|
||||||
} else if (!y) {
|
} else if (!y) {
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
|
#ifndef __NO_MATH_ERRNO__
|
||||||
errno = ERANGE;
|
errno = ERANGE;
|
||||||
|
#endif
|
||||||
if (y == truncl(y) && ((int64_t)y & 1)) {
|
if (y == truncl(y) && ((int64_t)y & 1)) {
|
||||||
return copysignl(INFINITY, x);
|
return copysignl(INFINITY, x);
|
||||||
} else {
|
} else {
|
||||||
|
@ -619,6 +623,8 @@ long double powl(long double x, long double y)
|
||||||
{
|
{
|
||||||
return pow(x, y);
|
return pow(x, y);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
#error "architecture unsupported"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* __x86_64__ */
|
#endif /* __x86_64__ */
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/intrin/likely.h"
|
#include "libc/intrin/likely.h"
|
||||||
#include "libc/math.h"
|
#include "libc/math.h"
|
||||||
|
#include "libc/runtime/fenv.h"
|
||||||
#include "libc/tinymath/kernel.internal.h"
|
#include "libc/tinymath/kernel.internal.h"
|
||||||
|
|
||||||
asm(".ident\t\"\\n\\n\
|
asm(".ident\t\"\\n\\n\
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue